From 97ab1062d603a6ee9e7501fa5e54ffd8eb09b4f1 Mon Sep 17 00:00:00 2001 From: donho Date: Thu, 26 Jun 2008 00:13:43 +0000 Subject: [PATCH] [NEW] Add 2 plugin message for v5 : NPPM_GETFULLPATHFROMBUFFERID and NPPM_GETPOSFROMBUFFERID. git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository@258 f5eea248-9336-0410-98b8-ebc06183d4e3 --- .../MISC/PluginsManager/Notepad_plus_msgs.h | 37 ++++++++++++++++--- PowerEditor/src/Notepad_plus.cpp | 31 ++++++++++++++-- PowerEditor/src/ScitillaComponent/Buffer.cpp | 9 +++++ PowerEditor/src/ScitillaComponent/Buffer.h | 4 +- 4 files changed, 70 insertions(+), 11 deletions(-) diff --git a/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h b/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h index e9602afd9..8ee2f403d 100644 --- a/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h +++ b/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h @@ -206,6 +206,31 @@ enum winVer{WV_UNKNOWN, WV_WIN32S, WV_95, WV_98, WV_ME, WV_NT, WV_W2K, WV_XP, WV #define NPPM_SETCHECKDOCOPT (NPPMSG + 56) // INT NPPM_SETCHECKDOCOPT(OPT, 0) + #define NPPM_GETPOSFROMBUFFERID (NPPMSG + 57) + // INT NPPM_GETPOSFROMBUFFERID(INT bufferID, 0) + // Return VIEW|INDEX from a buffer ID. -1 if the bufferID non existing + // + // VIEW takes 2 highest bits and INDEX (0 based) takes the rest (30 bits) + // Here's the values for the view : + // MAIN_VIEW 0 + // SUB_VIEW 1 + + #define NPPM_GETFULLPATHFROMBUFFERID (NPPMSG + 58) + // INT NPPM_GETFULLPATHFROMBUFFERID(INT bufferID, CHAR *fullFilePath) + // Get full path file name from a bufferID. + // Return -1 if the bufferID non existing, otherwise the number of char copied/to copy + // User should call it with fullFilePath be NULL to get the number of char (not including the nul character), + // allocate fullFilePath with the return values + 1, then call it again to get full path file name + + #define NPPM_GETBUFFERIDFROMPOS (NPPMSG + 59) + // TODO + + #define NPPM_GETCURRENTBUFFERID (NPPMSG + 60) + // TODO + + #define NPPM_RELOADBUFFERID (NPPMSG + 61) + // TODO + /* #define NPPM_ADDREBAR (NPPMSG + 57) // BOOL NPPM_ADDREBAR(0, REBARBANDINFO *) @@ -268,32 +293,32 @@ enum winVer{WV_UNKNOWN, WV_WIN32S, WV_95, WV_98, WV_ME, WV_NT, WV_W2K, WV_XP, WV #define NPPN_FILEBEFORECLOSE (NPPN_FIRST + 3) // To notify plugins that the current file is about to be closed //scnNotification->nmhdr.code = NPPN_FILEBEFORECLOSE; //scnNotification->nmhdr.hwndFrom = hwndNpp; - //scnNotification->nmhdr.idFrom = 0; + //scnNotification->nmhdr.idFrom = BufferID; #define NPPN_FILEOPENED (NPPN_FIRST + 4) // To notify plugins that the current file is just opened //scnNotification->nmhdr.code = NPPN_FILEOPENED; //scnNotification->nmhdr.hwndFrom = hwndNpp; - //scnNotification->nmhdr.idFrom = 0; + //scnNotification->nmhdr.idFrom = BufferID; #define NPPN_FILECLOSED (NPPN_FIRST + 5) // To notify plugins that the current file is just closed //scnNotification->nmhdr.code = NPPN_FILECLOSED; //scnNotification->nmhdr.hwndFrom = hwndNpp; - //scnNotification->nmhdr.idFrom = 0; + //scnNotification->nmhdr.idFrom = BufferID; #define NPPN_FILEBEFOREOPEN (NPPN_FIRST + 6) // To notify plugins that the current file is about to be opened //scnNotification->nmhdr.code = NPPN_FILEBEFOREOPEN; //scnNotification->nmhdr.hwndFrom = hwndNpp; - //scnNotification->nmhdr.idFrom = 0; + //scnNotification->nmhdr.idFrom = BufferID; #define NPPN_FILEBEFORESAVE (NPPN_FIRST + 7) // To notify plugins that the current file is about to be saved //scnNotification->nmhdr.code = NPPN_FILEBEFOREOPEN; //scnNotification->nmhdr.hwndFrom = hwndNpp; - //scnNotification->nmhdr.idFrom = 0; + //scnNotification->nmhdr.idFrom = BufferID; #define NPPN_FILESAVED (NPPN_FIRST + 8) // To notify plugins that the current file is just saved //scnNotification->nmhdr.code = NPPN_FILECLOSED; //scnNotification->nmhdr.hwndFrom = hwndNpp; - //scnNotification->nmhdr.idFrom = 0; + //scnNotification->nmhdr.idFrom = BufferID; #define NPPN_SHUTDOWN (NPPN_FIRST + 9) // To notify plugins that Notepad++ is about to be shutdowned. diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 9a39d5c6a..ddc788461 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -671,7 +671,7 @@ BufferID Notepad_plus::doOpen(const char *fileName, bool isReadOnly) SCNotification scnN; scnN.nmhdr.code = NPPN_FILEBEFOREOPEN; scnN.nmhdr.hwndFrom = _hSelf; - scnN.nmhdr.idFrom = 0; + scnN.nmhdr.idFrom = (uptr_t)buffer; _pluginsManager.notify(&scnN); loadBufferIntoView(buffer, currentView()); @@ -689,7 +689,6 @@ BufferID Notepad_plus::doOpen(const char *fileName, bool isReadOnly) _linkTriggered = true; _isDocModifing = false; - //_pEditView->getFocus(); //needed? // Notify plugins that current file is just opened scnN.nmhdr.code = NPPN_FILEOPENED; _pluginsManager.notify(&scnN); @@ -761,7 +760,7 @@ bool Notepad_plus::doSave(BufferID id, const char * filename, bool isCopy) scnN.nmhdr.code = NPPN_FILEBEFORESAVE; scnN.nmhdr.hwndFrom = _hSelf; - scnN.nmhdr.idFrom = 0; + scnN.nmhdr.idFrom = (uptr_t)id; _pluginsManager.notify(&scnN); } @@ -785,7 +784,7 @@ void Notepad_plus::doClose(BufferID id, int whichOne) { SCNotification scnN; scnN.nmhdr.code = NPPN_FILEBEFORECLOSE; scnN.nmhdr.hwndFrom = _hSelf; - scnN.nmhdr.idFrom = 0; + scnN.nmhdr.idFrom = (uptr_t)id; _pluginsManager.notify(&scnN); //add to recent files if its an existing file @@ -7248,6 +7247,30 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa ((NppGUI &)(pNppParam->getNppGUI()))._fileAutoDetection = (ChangeDetect)wParam; return TRUE; } + + case NPPM_GETPOSFROMBUFFERID : + { + int i; + + if ((i = _mainDocTab.getIndexByBuffer((BufferID)wParam)) != -1) + { + long view = MAIN_VIEW; + view <<= 30; + return view|i; + } + if ((i = _subDocTab.getIndexByBuffer((BufferID)wParam)) != -1) + { + long view = SUB_VIEW; + view <<= 30; + return view|i; + } + return -1; + } + + case NPPM_GETFULLPATHFROMBUFFERID : + { + return MainFileManager->getFileNameFromBuffer((BufferID)wParam, (char *)lParam); + } case NPPM_ENABLECHECKDOCOPT: { diff --git a/PowerEditor/src/ScitillaComponent/Buffer.cpp b/PowerEditor/src/ScitillaComponent/Buffer.cpp index b9495dc41..8e403321a 100644 --- a/PowerEditor/src/ScitillaComponent/Buffer.cpp +++ b/PowerEditor/src/ScitillaComponent/Buffer.cpp @@ -614,3 +614,12 @@ bool FileManager::createEmptyFile(const char * path) { fclose(file); return true; } + +int FileManager::getFileNameFromBuffer(BufferID id, char * fn2copy) { + if (getBufferIndexByID(id) == -1) + return -1; + Buffer * buf = getBufferByID(id); + if (fn2copy) + strcpy(fn2copy, buf->_fileName); + return strlen(buf->_fileName); +} \ No newline at end of file diff --git a/PowerEditor/src/ScitillaComponent/Buffer.h b/PowerEditor/src/ScitillaComponent/Buffer.h index 7861f7094..9e30f632f 100644 --- a/PowerEditor/src/ScitillaComponent/Buffer.h +++ b/PowerEditor/src/ScitillaComponent/Buffer.h @@ -95,7 +95,9 @@ public: static FileManager * getInstance() {return _pSelf;}; void destroyInstance() { delete _pSelf; }; - void increaseDocNr() { _nextNewNumber++; }; + void increaseDocNr() {_nextNewNumber++;}; + + int getFileNameFromBuffer(BufferID id, char * fn2copy); private: FileManager(); ~FileManager();