From 1c84051d999d09cdd2422b99e8bca50e4b7f7e6b Mon Sep 17 00:00:00 2001 From: dail8859 Date: Sat, 13 Jun 2015 11:10:02 -0400 Subject: [PATCH] Allows user defined extension to associate workspace files Closes #209; Close #169 Files ending in the defined extension will be opened in the project panel instead of as a normal file to edit (much like how the session file extension works). --- PowerEditor/src/Notepad_plus.h | 1 + PowerEditor/src/NppIO.cpp | 38 +++++++++++++++++-- PowerEditor/src/Parameters.cpp | 28 ++++++++++++++ PowerEditor/src/Parameters.h | 2 + .../src/WinControls/Preference/preference.rc | 2 + .../WinControls/Preference/preferenceDlg.cpp | 8 ++++ .../WinControls/Preference/preference_rc.h | 2 + 7 files changed, 77 insertions(+), 4 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h index 4626b757b..1d4a66595 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -250,6 +250,7 @@ public: //@} bool isFileSession(const TCHAR * filename); + bool isFileWorkspace(const TCHAR * filename); void filePrint(bool showDialog); bool saveScintillaParams(); diff --git a/PowerEditor/src/NppIO.cpp b/PowerEditor/src/NppIO.cpp index bedc48f28..c20d7f602 100644 --- a/PowerEditor/src/NppIO.cpp +++ b/PowerEditor/src/NppIO.cpp @@ -113,6 +113,13 @@ BufferID Notepad_plus::doOpen(const generic_string& fileName, bool isRecursive, return BUFFER_INVALID; } + if (isFileWorkspace(longFileName) && PathFileExists(longFileName)) + { + pNppParam->setWorkSpaceFilePath(0, longFileName); + command(IDM_VIEW_PROJECT_PANEL_1); + return BUFFER_INVALID; + } + bool isWow64Off = false; if (!PathFileExists(longFileName)) { @@ -1335,6 +1342,29 @@ bool Notepad_plus::isFileSession(const TCHAR * filename) { return false; } +bool Notepad_plus::isFileWorkspace(const TCHAR * filename) { + // if filename matches the ext of user defined workspace file ext, then it'll be opened as a workspace + const TCHAR *definedWorkspaceExt = NppParameters::getInstance()->getNppGUI()._definedWorkspaceExt.c_str(); + if (*definedWorkspaceExt != '\0') + { + generic_string fncp = filename; + TCHAR *pExt = PathFindExtension(fncp.c_str()); + + generic_string usrWorkspaceExt = TEXT(""); + if (*definedWorkspaceExt != '.') + { + usrWorkspaceExt += TEXT("."); + } + usrWorkspaceExt += definedWorkspaceExt; + + if (!generic_stricmp(pExt, usrWorkspaceExt.c_str())) + { + return true; + } + } + return false; +} + void Notepad_plus::loadLastSession() { NppParameters *nppParams = NppParameters::getInstance(); @@ -1359,11 +1389,11 @@ bool Notepad_plus::loadSession(Session & session, bool isSnapshotMode) { const TCHAR *pFn = session._mainViewFiles[i]._fileName.c_str(); - if (isFileSession(pFn)) + if (isFileSession(pFn) || isFileWorkspace(pFn)) { vector::iterator posIt = session._mainViewFiles.begin() + i; session._mainViewFiles.erase(posIt); - continue; //skip session files, not supporting recursive sessions + continue; //skip session files, not supporting recursive sessions or embedded workspace files } bool isWow64Off = false; @@ -1454,10 +1484,10 @@ bool Notepad_plus::loadSession(Session & session, bool isSnapshotMode) { const TCHAR *pFn = session._subViewFiles[k]._fileName.c_str(); - if (isFileSession(pFn)) { + if (isFileSession(pFn) || isFileWorkspace(pFn)) { vector::iterator posIt = session._subViewFiles.begin() + k; session._subViewFiles.erase(posIt); - continue; //skip session files, not supporting recursive sessions + continue; //skip session files, not supporting recursive sessions or embedded workspace files } bool isWow64Off = false; diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index 793a3025a..c423afcc1 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -4506,6 +4506,17 @@ void NppParameters::feedGUIParameters(TiXmlNode *node) _nppGUI._definedSessionExt = val; } } + else if (!lstrcmp(nm, TEXT("workspaceExt"))) + { + TiXmlNode *n = childNode->FirstChild(); + if (n) + { + const TCHAR* val = n->Value(); + val = n->Value(); + if (val) + _nppGUI._definedWorkspaceExt = val; + } + } else if (!lstrcmp(nm, TEXT("noUpdate"))) { TiXmlNode *n = childNode->FirstChild(); @@ -4953,6 +4964,7 @@ bool NppParameters::writeGUIParams() bool autocExist = false; bool autocInsetExist = false; bool sessionExtExist = false; + bool workspaceExtExist = false; bool noUpdateExist = false; bool menuBarExist = false; bool smartHighLightExist = false; @@ -5370,6 +5382,15 @@ bool NppParameters::writeGUIParams() else childNode->InsertEndChild(TiXmlText(_nppGUI._definedSessionExt.c_str())); } + else if (!lstrcmp(nm, TEXT("workspaceExt"))) + { + workspaceExtExist = true; + TiXmlNode *n = childNode->FirstChild(); + if (n) + n->SetValue(_nppGUI._definedWorkspaceExt.c_str()); + else + childNode->InsertEndChild(TiXmlText(_nppGUI._definedWorkspaceExt.c_str())); + } else if (!lstrcmp(nm, TEXT("noUpdate"))) { noUpdateExist = true; @@ -5607,6 +5628,13 @@ bool NppParameters::writeGUIParams() GUIConfigElement->InsertEndChild(TiXmlText(_nppGUI._definedSessionExt.c_str())); } + if (!workspaceExtExist) + { + TiXmlElement *GUIConfigElement = (GUIRoot->InsertEndChild(TiXmlElement(TEXT("GUIConfig"))))->ToElement(); + GUIConfigElement->SetAttribute(TEXT("name"), TEXT("workspaceExt")); + GUIConfigElement->InsertEndChild(TiXmlText(_nppGUI._definedWorkspaceExt.c_str())); + } + if (!menuBarExist) { TiXmlElement *GUIConfigElement = (GUIRoot->InsertEndChild(TiXmlElement(TEXT("GUIConfig"))))->ToElement(); diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index 84bfd5717..e4ca80635 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -812,6 +812,8 @@ struct NppGUI final MatchedPairConf _matchedPairConf; generic_string _definedSessionExt; + generic_string _definedWorkspaceExt; + diff --git a/PowerEditor/src/WinControls/Preference/preference.rc b/PowerEditor/src/WinControls/Preference/preference.rc index cc5a61da9..b4d46a561 100644 --- a/PowerEditor/src/WinControls/Preference/preference.rc +++ b/PowerEditor/src/WinControls/Preference/preference.rc @@ -144,12 +144,14 @@ BEGIN CONTROL "Highlight comment/php/asp zone",IDC_CHECK_HIGHLITENONEHTMLZONE, "Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP,267,136,140,10 EDITTEXT IDC_EDIT_SESSIONFILEEXT,381,157,34,14,ES_AUTOHSCROLL + EDITTEXT IDC_EDIT_WORKSPACEFILEEXT,381,174,34,14,ES_AUTOHSCROLL GROUPBOX "Document Switcher (Ctrl+TAB)",IDC_DOCUMENTSWITCHER_STATIC,37,4,155,39,BS_CENTER GROUPBOX "Smart Highlighting",IDC_SMARTHILITING_STATIC,37,47,155,39,BS_CENTER GROUPBOX "Clickable Link Settings",IDC_CLICKABLELINK_STATIC,259,4,155,39,BS_CENTER GROUPBOX "File Status Auto-Detection",IDC_FILEAUTODETECTION_STATIC,259,47,155,50,BS_CENTER GROUPBOX "Highlight Matching Tags",IDC_TAGMATCHEDHILITE_STATIC,259,101,155,50,BS_CENTER RTEXT "Session file ext.:",IDC_SESSIONFILEEXT_STATIC,271,160,108,8 + RTEXT "Workspace file ext.:",IDC_WORKSPACEFILEEXT_STATIC,271,177,108,8 END IDD_PREFERENCE_NEWDOCSETTING_BOX DIALOGEX 0, 0, 455, 185 diff --git a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp index 8d390db7d..c95c22255 100644 --- a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp +++ b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp @@ -875,6 +875,7 @@ INT_PTR CALLBACK SettingsDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM) ::EnableWindow(::GetDlgItem(_hSelf, IDC_CHECK_CLICKABLELINK_NOUNDERLINE), dontUnderlineState); ::SendDlgItemMessage(_hSelf, IDC_EDIT_SESSIONFILEEXT, WM_SETTEXT, 0, (LPARAM)nppGUI._definedSessionExt.c_str()); + ::SendDlgItemMessage(_hSelf, IDC_EDIT_WORKSPACEFILEEXT, WM_SETTEXT, 0, (LPARAM)nppGUI._definedWorkspaceExt.c_str()); ::SendDlgItemMessage(_hSelf, IDC_CHECK_ENABLEDOCSWITCHER, BM_SETCHECK, nppGUI._doTaskList, 0); ::SendDlgItemMessage(_hSelf, IDC_CHECK_MAINTAININDENT, BM_SETCHECK, nppGUI._maitainIndent, 0); @@ -911,6 +912,13 @@ INT_PTR CALLBACK SettingsDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM) nppGUI._definedSessionExt = sessionExt; return TRUE; } + case IDC_EDIT_WORKSPACEFILEEXT: + { + TCHAR workspaceExt[MAX_PATH]; + ::SendDlgItemMessage(_hSelf, IDC_EDIT_WORKSPACEFILEEXT, WM_GETTEXT, MAX_PATH, (LPARAM)workspaceExt); + nppGUI._definedWorkspaceExt = workspaceExt; + return TRUE; + } } } diff --git a/PowerEditor/src/WinControls/Preference/preference_rc.h b/PowerEditor/src/WinControls/Preference/preference_rc.h index a3e1ecebe..dfc23eaaf 100644 --- a/PowerEditor/src/WinControls/Preference/preference_rc.h +++ b/PowerEditor/src/WinControls/Preference/preference_rc.h @@ -171,6 +171,8 @@ #define IDC_SMARTHILITING_STATIC (IDD_PREFERENCE_SETTING_BOX + 33) #define IDC_CHECK_DETECTENCODING (IDD_PREFERENCE_SETTING_BOX + 34) #define IDC_CHECK_BACKSLASHISESCAPECHARACTERFORSQL (IDD_PREFERENCE_SETTING_BOX + 35) + #define IDC_EDIT_WORKSPACEFILEEXT (IDD_PREFERENCE_SETTING_BOX + 36) + #define IDC_WORKSPACEFILEEXT_STATIC (IDD_PREFERENCE_SETTING_BOX + 37) //-- FLS: xFileEditViewHistoryParameterGUI: Additional Checkbox for enabling the history for restoring the edit view per file. #define IDC_PREFERENCE_OFFSET_FLS 40 #define IDC_CHECK_REMEMBEREDITVIEWPERFILE (IDD_PREFERENCE_SETTING_BOX + IDC_PREFERENCE_OFFSET_FLS + 1)