From 91b9b03ff77f1ba5a94c18b082d4df236afd454c Mon Sep 17 00:00:00 2001 From: donho Date: Sun, 5 Apr 2009 23:52:01 +0000 Subject: [PATCH] [NEW] Add NPPN_FILEBEFORELOAD and NPPN_FILELOADFAILED messages. [BUG_FIXED] Fix New document not be switched while db clicking in Find in files result panel. git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository@446 f5eea248-9336-0410-98b8-ebc06183d4e3 --- .../MISC/PluginsManager/Notepad_plus_msgs.h | 11 +++- PowerEditor/src/Notepad_plus.cpp | 50 ++++++++++++++----- PowerEditor/src/ScitillaComponent/Buffer.cpp | 2 - PowerEditor/src/ScitillaComponent/Buffer.h | 1 + 4 files changed, 49 insertions(+), 15 deletions(-) diff --git a/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h b/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h index 3781e455..22812aae 100644 --- a/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h +++ b/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h @@ -329,7 +329,6 @@ enum winVer{WV_UNKNOWN, WV_WIN32S, WV_95, WV_98, WV_ME, WV_NT, WV_W2K, WV_XP, WV // INT NPPM_GETCURRENTCOLUMN(0, 0) // return the caret current position column - #define VAR_NOT_RECOGNIZED 0 #define FULL_CURRENT_PATH 1 #define CURRENT_DIRECTORY 2 @@ -416,4 +415,14 @@ enum winVer{WV_UNKNOWN, WV_WIN32S, WV_95, WV_98, WV_ME, WV_NT, WV_W2K, WV_XP, WV // UCHAR _key; //}; + #define NPPN_FILEBEFORELOAD (NPPN_FIRST + 14) // To notify plugins that the current file is about to be loaded + //scnNotification->nmhdr.code = NPPN_FILEBEFOREOPEN; + //scnNotification->nmhdr.hwndFrom = hwndNpp; + //scnNotification->nmhdr.idFrom = NULL; + + #define NPPN_FILELOADFAILED (NPPN_FIRST + 15) // To notify plugins that file open operation failed + //scnNotification->nmhdr.code = NPPN_FILEOPENFAILED; + //scnNotification->nmhdr.hwndFrom = hwndNpp; + //scnNotification->nmhdr.idFrom = BufferID; + #endif //NOTEPAD_PLUS_MSGS_H diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index c8a1d742..c87a68ce 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -633,12 +633,26 @@ bool Notepad_plus::loadSession(Session & session) BufferID Notepad_plus::doOpen(const TCHAR *fileName, bool isReadOnly) { TCHAR longFileName[MAX_PATH]; + ::GetFullPathName(fileName, MAX_PATH, longFileName, NULL); ::GetLongPathName(longFileName, longFileName, MAX_PATH); _lastRecentFileList.remove(longFileName); - BufferID test = MainFileManager->getBufferFromName(longFileName); + const TCHAR * fileName2Find; + generic_string gs_fileName = fileName; + size_t res = gs_fileName.find_first_of(UNTITLED_STR); + + if (res != string::npos && res == 0) + { + fileName2Find = fileName; + } + else + { + fileName2Find = longFileName; + } + + BufferID test = MainFileManager->getBufferFromName(fileName2Find); if (test != BUFFER_INVALID) { //switchToFile(test); @@ -655,10 +669,13 @@ BufferID Notepad_plus::doOpen(const TCHAR *fileName, bool isReadOnly) return test; } - if (isFileSession(longFileName) && PathFileExists(longFileName)) { + if (isFileSession(longFileName) && PathFileExists(longFileName)) + { fileLoadSession(longFileName); return BUFFER_INVALID; } + + if (!PathFileExists(longFileName)) { @@ -693,6 +710,14 @@ BufferID Notepad_plus::doOpen(const TCHAR *fileName, bool isReadOnly) } } + // Notify plugins that current file is about to load + // Plugins can should use this notification to filter SCN_MODIFIED + SCNotification scnN; + scnN.nmhdr.code = NPPN_FILEBEFORELOAD; + scnN.nmhdr.hwndFrom = _hSelf; + scnN.nmhdr.idFrom = NULL; + _pluginsManager.notify(&scnN); + BufferID buffer = MainFileManager->loadFile(longFileName); if (buffer != BUFFER_INVALID) { @@ -703,10 +728,8 @@ BufferID Notepad_plus::doOpen(const TCHAR *fileName, bool isReadOnly) if (isReadOnly) buf->setUserReadOnly(true); - // Notify plugins that current file is just opened - SCNotification scnN; + // Notify plugins that current file is about to open scnN.nmhdr.code = NPPN_FILEBEFOREOPEN; - scnN.nmhdr.hwndFrom = _hSelf; scnN.nmhdr.idFrom = (uptr_t)buffer; _pluginsManager.notify(&scnN); @@ -756,13 +779,16 @@ BufferID Notepad_plus::doOpen(const TCHAR *fileName, bool isReadOnly) } else { - TCHAR msg[MAX_PATH + 100]; - lstrcpy(msg, TEXT("Can not open file \"")); - //lstrcat(msg, fullPath); - lstrcat(msg, longFileName); - lstrcat(msg, TEXT("\".")); - ::MessageBox(_hSelf, msg, TEXT("ERR"), MB_OK); - _isFileOpening = false; + TCHAR msg[MAX_PATH + 100]; + lstrcpy(msg, TEXT("Can not open file \"")); + //lstrcat(msg, fullPath); + lstrcat(msg, longFileName); + lstrcat(msg, TEXT("\".")); + ::MessageBox(_hSelf, msg, TEXT("ERR"), MB_OK); + _isFileOpening = false; + + scnN.nmhdr.code = NPPN_FILELOADFAILED; + _pluginsManager.notify(&scnN); } return BUFFER_INVALID; } diff --git a/PowerEditor/src/ScitillaComponent/Buffer.cpp b/PowerEditor/src/ScitillaComponent/Buffer.cpp index 65017771..3877314a 100644 --- a/PowerEditor/src/ScitillaComponent/Buffer.cpp +++ b/PowerEditor/src/ScitillaComponent/Buffer.cpp @@ -13,7 +13,6 @@ FileManager * FileManager::_pSelf = new FileManager(); const int blockSize = 128 * 1024 + 4; -const TCHAR UNTITLED_STR[] = TEXT("new "); // Ordre important!! Ne le changes pas! //SC_EOL_CRLF (0), SC_EOL_CR (1), or SC_EOL_LF (2). @@ -173,7 +172,6 @@ bool Buffer::checkFileState() { //returns true if the status has been changed (i doNotify(BufferChangeStatus | BufferChangeReadonly | BufferChangeTimestamp); return true; } - } if (!generic_stat(_fullPathName, &buf)) diff --git a/PowerEditor/src/ScitillaComponent/Buffer.h b/PowerEditor/src/ScitillaComponent/Buffer.h index 6e0bca5c..14c5eea7 100644 --- a/PowerEditor/src/ScitillaComponent/Buffer.h +++ b/PowerEditor/src/ScitillaComponent/Buffer.h @@ -55,6 +55,7 @@ struct HeaderLineState { }; const int userLangNameMax = 16; +const TCHAR UNTITLED_STR[] = TEXT("new "); //File manager class maintains all buffers class Buffer;