diff --git a/PowerEditor/src/MISC/Common/Common.cpp b/PowerEditor/src/MISC/Common/Common.cpp index 823cd3d67..c17f61d58 100644 --- a/PowerEditor/src/MISC/Common/Common.cpp +++ b/PowerEditor/src/MISC/Common/Common.cpp @@ -462,3 +462,25 @@ TCHAR *BuildMenuFileName(TCHAR *buffer, int len, int pos, const TCHAR *filename) } return buffer; } + +generic_string PathRemoveFileSpec(generic_string & path) +{ + generic_string::size_type lastBackslash = path.find_last_of(TEXT('\\')); + if (lastBackslash == generic_string::npos) + { + if (path.size() >= 2 && path[1] == TEXT(':')) // "C:foo.bar" becomes "C:" + path.erase(2); + else + path.erase(); + } + else + { + if (lastBackslash == 2 && path[1] == TEXT(':') && path.size() >= 3) // "C:\foo.exe" becomes "C:\" + path.erase(3); + else if (lastBackslash == 0 && path.size() > 1) // "\foo.exe" becomes "\" + path.erase(1); + else + path.erase(lastBackslash); + } + return path; +} diff --git a/PowerEditor/src/MISC/Common/Common.h b/PowerEditor/src/MISC/Common/Common.h index 623325b80..b907115b7 100644 --- a/PowerEditor/src/MISC/Common/Common.h +++ b/PowerEditor/src/MISC/Common/Common.h @@ -138,5 +138,7 @@ private: #define REBARBAND_SIZE sizeof(REBARBANDINFO) #endif +generic_string PathRemoveFileSpec(generic_string & path); + #endif //M30_IDE_COMMUN_H diff --git a/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h b/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h index aa53e1986..49725fdec 100644 --- a/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h +++ b/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h @@ -267,6 +267,7 @@ enum winVer{WV_UNKNOWN, WV_WIN32S, WV_95, WV_98, WV_ME, WV_NT, WV_W2K, WV_XP, WV // BOOL NPPM_ADDREBAR(INT ID, 0) //Use ID assigned with NPPM_ADDREBAR */ + #define NPPM_HIDETOOLBAR (NPPMSG + 70) // BOOL NPPM_HIDETOOLBAR(0, BOOL hideOrNot) // if hideOrNot is set as TRUE then tool bar will be hidden @@ -435,4 +436,9 @@ enum winVer{WV_UNKNOWN, WV_WIN32S, WV_95, WV_98, WV_ME, WV_NT, WV_W2K, WV_XP, WV #define DOCSTAUS_READONLY 1 #define DOCSTAUS_BUFFERDIRTY 2 + #define NPPN_DOCORDERCHANGED (NPPN_FIRST + 16) // To notify plugins that document order is changed + //scnNotification->nmhdr.code = NPPN_DOCORDERCHANGED; + //scnNotification->nmhdr.hwndFrom = newIndex; + //scnNotification->nmhdr.idFrom = BufferID; + #endif //NOTEPAD_PLUS_MSGS_H diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 75feb4134..4f0b6f722 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -271,10 +271,6 @@ void Notepad_plus::init(HINSTANCE hInst, HWND parent, const TCHAR *cmdLine, CmdL else ::MoveWindow(_hSelf, newUpperLeft.x, newUpperLeft.y, nppGUI._appPos.right, nppGUI._appPos.bottom, TRUE); - TCHAR nppBinPath[MAX_PATH*4]; - ::GetModuleFileName(NULL, nppBinPath, MAX_PATH*4); - _nppPath = nppBinPath; - if (nppGUI._tabStatus & TAB_MULTILINE) ::SendMessage(_hSelf, WM_COMMAND, IDM_VIEW_DRAWTABBAR_MULTILINE, 0); @@ -305,12 +301,12 @@ void Notepad_plus::init(HINSTANCE hInst, HWND parent, const TCHAR *cmdLine, CmdL vector patterns; patterns.push_back(TEXT("*.xml")); - generic_string nppDir(_nppPath); - ::PathRemoveFileSpec((TCHAR *)nppDir.c_str()); // <- nppDir is modified via the string pointer + generic_string nppDir(pNppParams->getNppPath()); + ::PathRemoveFileSpec(nppDir); #ifdef UNICODE LocalizationSwitcher & localizationSwitcher = pNppParams->getLocalizationSwitcher(); - wstring localizationDir = nppDir.c_str(); // <- should use the pointer to avoid the constructor of copy + wstring localizationDir = nppDir.c_str(); localizationDir += TEXT("\\localization\\"); getMatchedFileNames(localizationDir.c_str(), patterns, fileNames, false, false); @@ -720,7 +716,7 @@ BufferID Notepad_plus::doOpen(const TCHAR *fileName, bool isReadOnly) { TCHAR str2display[MAX_PATH*2]; generic_string longFileDir(longFileName); - PathRemoveFileSpec((TCHAR *)longFileDir.c_str()); // <- Modify std::string via pointer + PathRemoveFileSpec(longFileDir); if (PathFileExists(longFileDir.c_str())) { @@ -1146,8 +1142,8 @@ bool Notepad_plus::fileSave(BufferID id) // std::string path should be a temp throwable variable generic_string path = fn; - ::PathRemoveFileSpec((LPTSTR)path.c_str()); // <- here we modify its data w/o using its interface - fn_dateTime_bak = path.c_str(); // <- here it must be path.c_str() but not path. Because the constructor of copy processes differently string and char * + ::PathRemoveFileSpec(path); + fn_dateTime_bak = path.c_str(); fn_dateTime_bak += TEXT("\\"); @@ -3091,7 +3087,7 @@ void Notepad_plus::specialCmd(int id, int param) void Notepad_plus::command(int id) { - NppParameters *pNppParam = NppParameters::getInstance(); + //NppParameters *pNppParam = NppParameters::getInstance(); switch (id) { case IDM_FILE_NEW: @@ -3286,7 +3282,7 @@ void Notepad_plus::command(int id) else if (id == IDM_EDIT_CURRENTDIRTOCLIP) { generic_string dir(buf->getFullPathName()); - PathRemoveFileSpec((TCHAR *)dir.c_str()); + PathRemoveFileSpec(dir); str2Cliboard(dir.c_str()); } else if (id == IDM_EDIT_FILENAMETOCLIP) @@ -4131,7 +4127,7 @@ void Notepad_plus::command(int id) case IDM_SETTING_TAB_REPLCESPACE: { - NppGUI & nppgui = (NppGUI &)(pNppParam->getNppGUI()); + NppGUI & nppgui = (NppGUI &)((NppParameters::getInstance())->getNppGUI()); nppgui._tabReplacedBySpace = !nppgui._tabReplacedBySpace; _pEditView->execute(SCI_SETUSETABS, !nppgui._tabReplacedBySpace); //checkMenuItem(IDM_SETTING_TAB_REPLCESPACE, nppgui._tabReplacedBySpace); @@ -4141,7 +4137,7 @@ void Notepad_plus::command(int id) case IDM_SETTING_TAB_SIZE: { ValueDlg tabSizeDlg; - NppGUI & nppgui = (NppGUI &)(pNppParam->getNppGUI()); + NppGUI & nppgui = (NppGUI &)((NppParameters::getInstance())->getNppGUI()); tabSizeDlg.init(_hInst, _preference.getHSelf(), nppgui._tabSize, TEXT("Tab Size : ")); POINT p; ::GetCursorPos(&p); @@ -4290,8 +4286,8 @@ void Notepad_plus::command(int id) case IDM_HELP : { - generic_string tmp(_nppPath); - ::PathRemoveFileSpec((TCHAR *)tmp.c_str()); + generic_string tmp((NppParameters::getInstance())->getNppPath()); + ::PathRemoveFileSpec(tmp); generic_string nppHelpPath = tmp.c_str(); nppHelpPath += TEXT("\\NppHelp.chm"); @@ -4343,7 +4339,7 @@ void Notepad_plus::command(int id) case IDM_UPDATE_NPP : { - generic_string updaterDir = _nppPath; + generic_string updaterDir = (NppParameters::getInstance())->getNppPath(); updaterDir += TEXT("\\updater\\"); generic_string updaterFullPath = updaterDir + TEXT("gup.exe"); generic_string param = TEXT("-verbose -v"); @@ -4520,7 +4516,7 @@ void Notepad_plus::command(int id) else if ((id >= ID_MACRO) && (id < ID_MACRO_LIMIT)) { int i = id - ID_MACRO; - vector & theMacros = pNppParam->getMacroList(); + vector & theMacros = (NppParameters::getInstance())->getMacroList(); Macro macro = theMacros[i].getMacro(); _pEditView->execute(SCI_BEGINUNDOACTION); @@ -4533,7 +4529,7 @@ void Notepad_plus::command(int id) else if ((id >= ID_USER_CMD) && (id < ID_USER_CMD_LIMIT)) { int i = id - ID_USER_CMD; - vector & theUserCommands = pNppParam->getUserCommandList(); + vector & theUserCommands = (NppParameters::getInstance())->getUserCommandList(); UserCommand ucmd = theUserCommands[i]; Command cmd(ucmd.getCmd()); @@ -7690,6 +7686,20 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa } break; + case NPPM_INTERNAL_DOCORDERCHANGED : + { + BufferID id = _pEditView->getCurrentBufferID(); + + // Notify plugins that current file is about to be closed + SCNotification scnN; + scnN.nmhdr.code = NPPN_DOCORDERCHANGED; + scnN.nmhdr.hwndFrom = (void *)lParam; + scnN.nmhdr.idFrom = (uptr_t)id; + _pluginsManager.notify(&scnN); + return TRUE; + } + break; + case WM_SIZE: { RECT rc; @@ -8833,7 +8843,7 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa generic_string pluginsConfigDirPrefix = pNppParam->getAppDataNppDir(); if (pluginsConfigDirPrefix == TEXT("")) - pluginsConfigDirPrefix = _nppPath; + pluginsConfigDirPrefix = pNppParam->getNppPath(); const TCHAR *secondPart = TEXT("plugins\\Config"); @@ -9759,7 +9769,7 @@ void Notepad_plus::notifyBufferChanged(Buffer * buffer, int mask) { checkDocState(); setTitle(); generic_string dir(buffer->getFullPathName()); - PathRemoveFileSpec((TCHAR *)dir.c_str()); + PathRemoveFileSpec(dir); setWorkingDir(dir.c_str()); } @@ -9812,7 +9822,7 @@ void Notepad_plus::notifyBufferActivated(BufferID bufid, int view) { setDisplayFormat(buf->getFormat()); enableConvertMenuItems(buf->getFormat()); generic_string dir(buf->getFullPathName()); - PathRemoveFileSpec((TCHAR *)dir.c_str()); + PathRemoveFileSpec(dir); setWorkingDir(dir.c_str()); setTitle(); //Make sure the colors of the tab controls match diff --git a/PowerEditor/src/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h index 5f9c3181f..446f33ba8 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -66,6 +66,7 @@ enum WindowStatus { //bitwise mask WindowMask = 0x07 }; + /* //Plugins rely on #define's enum Views { @@ -223,7 +224,6 @@ public: static HWND gNppHWND; //static handle to Notepad++ window, NULL if non-existant private: static const TCHAR _className[32]; - generic_string _nppPath; Window *_pMainWindow; DockingManager _dockingManager; diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index 5ba083c7f..d17c3fd28 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -630,6 +630,10 @@ const int NB_MAX_FINDHISTORY_REPLACE = 30; const int NB_MAX_FINDHISTORY_PATH = 30; const int NB_MAX_FINDHISTORY_FILTER = 20; + +const int MASK_ReplaceBySpc = 0x80; +const int MASK_TabSize = 0x7F; + struct Lang { LangType _langID; @@ -640,8 +644,16 @@ struct Lang const TCHAR *_pCommentStart; const TCHAR *_pCommentEnd; - Lang() {for (int i = 0 ; i < NB_LIST ; _langKeyWordList[i] = NULL ,i++);}; - Lang(LangType langID, const TCHAR *name) : _langID(langID), _langName(name?name:TEXT("")){ + bool _isTabReplacedBySpace; + int _tabSize; + + Lang(): _langID(L_TXT), _langName(TEXT("")), _defaultExtList(NULL), _pCommentLineSymbol(NULL), _pCommentStart(NULL), + _pCommentEnd(NULL), _isTabReplacedBySpace(false), _tabSize(-1) { + for (int i = 0 ; i < NB_LIST ; _langKeyWordList[i] = NULL ,i++); + }; + Lang(LangType langID, const TCHAR *name) : _langID(langID), _langName(name?name:TEXT("")),\ + _defaultExtList(NULL), _pCommentLineSymbol(NULL), _pCommentStart(NULL),\ + _pCommentEnd(NULL), _isTabReplacedBySpace(false), _tabSize(-1) { for (int i = 0 ; i < NB_LIST ; _langKeyWordList[i] = NULL ,i++); }; ~Lang() {}; @@ -661,6 +673,12 @@ struct Lang _pCommentEnd = commentEnd; }; + void setTabInfo(int tabInfo) { + if (tabInfo == -1 || tabInfo == 0) return; + _isTabReplacedBySpace = (tabInfo & MASK_ReplaceBySpc) != 0; + _tabSize = tabInfo & MASK_TabSize; + }; + const TCHAR * getDefaultExtList() const { return _defaultExtList; }; @@ -675,6 +693,11 @@ struct Lang LangType getLangID() const {return _langID;}; const TCHAR * getLangName() const {return _langName.c_str();}; + + int getTabInfo() const { + if (_tabSize == -1) return -1; + return _isTabReplacedBySpace?0x80:0x00 | _tabSize; + }; }; class UserLangContainer diff --git a/PowerEditor/src/ScitillaComponent/Buffer.h b/PowerEditor/src/ScitillaComponent/Buffer.h index 1769268f7..001da07ff 100644 --- a/PowerEditor/src/ScitillaComponent/Buffer.h +++ b/PowerEditor/src/ScitillaComponent/Buffer.h @@ -333,6 +333,7 @@ public : return _pManager->docLength(_id); }; + Lang * getCurrentLang() const; private : FileManager * _pManager; bool _canNotify; @@ -368,7 +369,6 @@ private : static long _recentTagCtr; void updateTimeStamp(); - Lang * getCurrentLang() const; int indexOfReference(ScintillaEditView * identifier) const; diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp index 83e3ca824..1dc649963 100644 --- a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp +++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp @@ -1447,6 +1447,7 @@ void ScintillaEditView::activateBuffer(BufferID buffer) // Due to execute(SCI_CLEARDOCUMENTSTYLE); in defineDocType() function // defineDocType() function should be called here, but not be after the fold info loop defineDocType(_currentBuffer->getLangType()); + setTabSettings(_currentBuffer->getCurrentLang()); if (_currentBuffer->getNeedsLexing()) { restyleBuffer(); @@ -2579,3 +2580,19 @@ void ScintillaEditView::runMarkers(bool doHide, int searchStart, bool endOfDoc, } } } + + +void ScintillaEditView::setTabSettings(Lang *lang) +{ + if (lang->_tabSize != -1 && lang->_tabSize != 0) + { + execute(SCI_SETTABWIDTH, lang->_tabSize); + execute(SCI_SETUSETABS, lang->_isTabReplacedBySpace); + } + else + { + const NppGUI & nppgui = (NppParameters::getInstance())->getNppGUI(); + execute(SCI_SETTABWIDTH, nppgui._tabSize); + execute(SCI_SETUSETABS, nppgui._tabReplacedBySpace); + } +} diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.h b/PowerEditor/src/ScitillaComponent/ScintillaEditView.h index 19790c79a..ec0cd0b7d 100644 --- a/PowerEditor/src/ScitillaComponent/ScintillaEditView.h +++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.h @@ -805,6 +805,7 @@ protected: } }; + void setTabSettings(Lang *lang); bool expandWordSelection(); }; diff --git a/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.cpp b/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.cpp index 2d520bc32..210906fee 100644 --- a/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.cpp +++ b/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.cpp @@ -594,18 +594,20 @@ void WordStyleDlg::switchToTheme() _themeName.clear(); _themeName.assign( (TCHAR *)::SendMessage(_hSwitch2ThemeCombo, CB_GETITEMDATA, iSel, 0) ); - if ( _isThemeDirty ) { + if (_isThemeDirty) + { TCHAR themeFileName[MAX_PATH]; lstrcpy(themeFileName, prevThemeName.c_str()); - PathStripPath( themeFileName ); - PathRemoveExtension( themeFileName ); + PathStripPath(themeFileName); + PathRemoveExtension(themeFileName); int mb_response = ::MessageBox( _hSelf, TEXT(" Unsaved changes are about to be discarded!\n") TEXT(" Do you want to save your changes before switching themes?"), themeFileName, MB_ICONWARNING | MB_YESNO | MB_APPLMODAL | MB_SETFOREGROUND ); - if ( mb_response == IDYES ) (NppParameters::getInstance())->writeStyles(_lsArray, _globalStyles); + if ( mb_response == IDYES ) + (NppParameters::getInstance())->writeStyles(_lsArray, _globalStyles); } diff --git a/PowerEditor/src/WinControls/DockingWnd/DockingDlgInterface.h b/PowerEditor/src/WinControls/DockingWnd/DockingDlgInterface.h index 214fa795b..acab57f70 100644 --- a/PowerEditor/src/WinControls/DockingWnd/DockingDlgInterface.h +++ b/PowerEditor/src/WinControls/DockingWnd/DockingDlgInterface.h @@ -36,14 +36,16 @@ public: virtual void init(HINSTANCE hInst, HWND parent) { StaticDialog::init(hInst, parent); - ::GetModuleFileName((HMODULE)hInst, (TCHAR *)_moduleName.c_str(), MAX_PATH); - _moduleName = PathFindFileName(_moduleName.c_str()); + TCHAR temp[MAX_PATH]; + ::GetModuleFileName((HMODULE)hInst, temp, MAX_PATH); + _moduleName = PathFindFileName(temp); } void create(tTbData * data, bool isRTL = false){ StaticDialog::create(_dlgID, isRTL); - ::GetWindowText(_hSelf, (LPTSTR)_pluginName.c_str(), MAX_PATH); - + TCHAR temp[MAX_PATH]; + ::GetWindowText(_hSelf, temp, MAX_PATH); + _pluginName = temp; // user information data->hClient = _hSelf; data->pszName = (TCHAR *)_pluginName.c_str(); diff --git a/PowerEditor/src/WinControls/SplitterContainer/SplitterContainer.h b/PowerEditor/src/WinControls/SplitterContainer/SplitterContainer.h index 92d29c0fb..3c87e7792 100644 --- a/PowerEditor/src/WinControls/SplitterContainer/SplitterContainer.h +++ b/PowerEditor/src/WinControls/SplitterContainer/SplitterContainer.h @@ -62,8 +62,8 @@ public : _splitter.display(toShow); }; virtual void redraw() const { - _pWin0->redraw(); - _pWin1->redraw(); + _pWin0->redraw(true); + _pWin1->redraw(true); }; void setWin0(Window *pWin) { diff --git a/PowerEditor/src/WinControls/TabBar/TabBar.cpp b/PowerEditor/src/WinControls/TabBar/TabBar.cpp index 35957efe0..bd0ae182f 100644 --- a/PowerEditor/src/WinControls/TabBar/TabBar.cpp +++ b/PowerEditor/src/WinControls/TabBar/TabBar.cpp @@ -17,6 +17,7 @@ #include "TabBar.h" #include "Common.h" +//#include "Notepad_plus_msgs.h" const COLORREF blue = RGB(0, 0, 0xFF); const COLORREF black = RGB(0, 0, 0); @@ -798,12 +799,13 @@ void TabBarPlus::exchangeItemData(POINT point) ::SendMessage(_hSelf, TCM_SETITEM, i, reinterpret_cast(&itemData_shift)); } } - // ::SendMessage(_hSelf, TCM_SETITEM, nTab, reinterpret_cast(&itemData_nDraggedTab)); //3. update the current index _nTabDragged = nTab; - + + // Tell Notepad_plus to notifiy plugins that a D&D operation was done (so doc index has been changed) + ::SendMessage(_hParent, NPPM_INTERNAL_DOCORDERCHANGED, 0, _nTabDragged); } } else diff --git a/PowerEditor/src/WinControls/Window.h b/PowerEditor/src/WinControls/Window.h index 7bd64cbd6..2c0affcfb 100644 --- a/PowerEditor/src/WinControls/Window.h +++ b/PowerEditor/src/WinControls/Window.h @@ -50,9 +50,10 @@ public: redraw(); }; - virtual void redraw() const { + virtual void redraw(bool forceUpdate = false) const { ::InvalidateRect(_hSelf, NULL, TRUE); - ::UpdateWindow(_hSelf); + if (forceUpdate) + ::UpdateWindow(_hSelf); }; virtual void getClientRect(RECT & rc) const { diff --git a/PowerEditor/src/resource.h b/PowerEditor/src/resource.h index b84ec7539..ee9572a65 100644 --- a/PowerEditor/src/resource.h +++ b/PowerEditor/src/resource.h @@ -309,7 +309,10 @@ #define NPPM_INTERNAL_SEARCH_GOTOPREVFOUND (NOTEPADPLUS_USER_INTERNAL + 29) #define NPPM_INTERNAL_FOCUS_ON_FOUND_RESULTS (NOTEPADPLUS_USER_INTERNAL + 30) #define NPPM_INTERNAL_RELOADSTYLERS (NOTEPADPLUS_USER_INTERNAL + 31) + #define NPPM_INTERNAL_DOCORDERCHANGED (NOTEPADPLUS_USER_INTERNAL + 32) + //wParam: 0 + //lParam: document new index // See Notepad_plus_msgs.h //#define NOTEPADPLUS_USER (WM_USER + 1000) @@ -342,6 +345,8 @@ //lParam: name to set (TCHAR*) //Buffer must have been previously unnamed (eg "new 1" document types) + + #define SCINTILLA_USER (WM_USER + 2000) diff --git a/PowerEditor/visual.net/notepadPlus.vcproj b/PowerEditor/visual.net/notepadPlus.vcproj index fbabb2cad..925b71ee6 100644 --- a/PowerEditor/visual.net/notepadPlus.vcproj +++ b/PowerEditor/visual.net/notepadPlus.vcproj @@ -633,14 +633,6 @@ RelativePath="..\src\resource.h" > - - - -