[NEW] (Author: Pavel Nedev) Add notification for plugins : NPPN_BEFORESHUTDOWN NPPN_CANCELSHUTDOWN NPPN_FILEBEFORERENAME NPPN_FILERENAMECANCEL NPPN_FILERENAMED NPPN_FILEBEFOREDELETE NPPN_FILEDELETEFAILED NPPN_FILEDELETED

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@1346 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
Don Ho 2015-02-21 18:20:50 +00:00
parent d9299e644f
commit f224c673bf
7 changed files with 401 additions and 325 deletions

View File

@ -541,4 +541,44 @@ enum winVer{WV_UNKNOWN, WV_WIN32S, WV_95, WV_98, WV_ME, WV_NT, WV_W2K, WV_XP, WV
//scnNotification->nmhdr.hwndFrom = NULL;
//scnNotification->nmhdr.idFrom = BufferID;
#define NPPN_BEFORESHUTDOWN (NPPN_FIRST + 19) // To notify plugins that Npp shutdown has been triggered, files have not been closed yet
//scnNotification->nmhdr.code = NPPN_BEFORESHUTDOWN;
//scnNotification->nmhdr.hwndFrom = hwndNpp;
//scnNotification->nmhdr.idFrom = 0;
#define NPPN_CANCELSHUTDOWN (NPPN_FIRST + 20) // To notify plugins that Npp shutdown has been cancelled
//scnNotification->nmhdr.code = NPPN_CANCELSHUTDOWN;
//scnNotification->nmhdr.hwndFrom = hwndNpp;
//scnNotification->nmhdr.idFrom = 0;
#define NPPN_FILEBEFORERENAME (NPPN_FIRST + 21) // To notify plugins that file is to be renamed
//scnNotification->nmhdr.code = NPPN_FILEBEFORERENAME;
//scnNotification->nmhdr.hwndFrom = hwndNpp;
//scnNotification->nmhdr.idFrom = BufferID;
#define NPPN_FILERENAMECANCEL (NPPN_FIRST + 22) // To notify plugins that file rename has been cancelled
//scnNotification->nmhdr.code = NPPN_FILERENAMECANCEL;
//scnNotification->nmhdr.hwndFrom = hwndNpp;
//scnNotification->nmhdr.idFrom = BufferID;
#define NPPN_FILERENAMED (NPPN_FIRST + 23) // To notify plugins that file has been renamed
//scnNotification->nmhdr.code = NPPN_FILERENAMED;
//scnNotification->nmhdr.hwndFrom = hwndNpp;
//scnNotification->nmhdr.idFrom = BufferID;
#define NPPN_FILEBEFOREDELETE (NPPN_FIRST + 24) // To notify plugins that file is to be deleted
//scnNotification->nmhdr.code = NPPN_FILEBEFOREDELETE;
//scnNotification->nmhdr.hwndFrom = hwndNpp;
//scnNotification->nmhdr.idFrom = BufferID;
#define NPPN_FILEDELETEFAILED (NPPN_FIRST + 25) // To notify plugins that file deletion has failed
//scnNotification->nmhdr.code = NPPN_FILEDELETEFAILED;
//scnNotification->nmhdr.hwndFrom = hwndNpp;
//scnNotification->nmhdr.idFrom = BufferID;
#define NPPN_FILEDELETED (NPPN_FIRST + 26) // To notify plugins that file has been deleted
//scnNotification->nmhdr.code = NPPN_FILEDELETED;
//scnNotification->nmhdr.hwndFrom = hwndNpp;
//scnNotification->nmhdr.idFrom = BufferID;
#endif //NOTEPAD_PLUS_MSGS_H

View File

@ -400,7 +400,7 @@ void PluginsManager::runPluginCommand(const TCHAR *pluginName, int commandID)
}
}
void PluginsManager::notify(SCNotification *notification)
void PluginsManager::notify(const SCNotification *notification)
{
for (size_t i = 0, len = _pluginInfos.size() ; i < len ; ++i)
{

View File

@ -109,7 +109,7 @@ public:
HMENU setMenu(HMENU hMenu, const TCHAR *menuName);
bool getShortcutByCmdID(int cmdID, ShortcutKey *sk);
void notify(SCNotification *notification);
void notify(const SCNotification *notification);
void relayNppMessages(UINT Message, WPARAM wParam, LPARAM lParam);
bool relayPluginMessages(UINT Message, WPARAM wParam, LPARAM lParam);

View File

@ -4688,6 +4688,12 @@ void Notepad_plus::notifyBufferChanged(Buffer * buffer, int mask)
}
case DOC_DELETED: //ask for keep
{
SCNotification scnN;
scnN.nmhdr.code = NPPN_FILEDELETED;
scnN.nmhdr.hwndFrom = _pPublicInterface->getHSelf();
scnN.nmhdr.idFrom = (uptr_t)buffer->getID();
_pluginsManager.notify(&scnN);
int index = _pDocTab->getIndexByBuffer(buffer->getID());
int iView = currentView();
if (index == -1)

View File

@ -1489,6 +1489,12 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
}
else
{
SCNotification scnN;
scnN.nmhdr.code = NPPN_BEFORESHUTDOWN;
scnN.nmhdr.hwndFrom = _pPublicInterface->getHSelf();
scnN.nmhdr.idFrom = 0;
_pluginsManager.notify(&scnN);
if (_pTrayIco)
_pTrayIco->doTrayIcon(REMOVE);
@ -1516,6 +1522,9 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
if (!allClosed)
{
//User cancelled the shutdown
scnN.nmhdr.code = NPPN_CANCELSHUTDOWN;
_pluginsManager.notify(&scnN);
return FALSE;
}
@ -1527,10 +1536,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
if (_configStyleDlg.isCreated() && ::IsWindowVisible(_configStyleDlg.getHSelf()))
_configStyleDlg.restoreGlobalOverrideValues();
SCNotification scnN;
scnN.nmhdr.code = NPPN_SHUTDOWN;
scnN.nmhdr.hwndFrom = _pPublicInterface->getHSelf();
scnN.nmhdr.idFrom = 0;
_pluginsManager.notify(&scnN);
saveFindHistory(); //writeFindHistory

View File

@ -1085,6 +1085,12 @@ bool Notepad_plus::fileRename(BufferID id)
bufferID = _pEditView->getCurrentBufferID();
Buffer * buf = MainFileManager->getBufferByID(bufferID);
SCNotification scnN;
scnN.nmhdr.code = NPPN_FILEBEFORERENAME;
scnN.nmhdr.hwndFrom = _pPublicInterface->getHSelf();
scnN.nmhdr.idFrom = (uptr_t)bufferID;
_pluginsManager.notify(&scnN);
FileDialog fDlg(_pPublicInterface->getHSelf(), _pPublicInterface->getHinst());
fDlg.setExtFilter(TEXT("All types"), TEXT(".*"), NULL);
@ -1093,11 +1099,14 @@ bool Notepad_plus::fileRename(BufferID id)
fDlg.setDefFileName(buf->getFileName());
TCHAR *pfn = fDlg.doSaveDlg();
bool success = false;
if (pfn)
{
MainFileManager->moveFile(bufferID, pfn);
}
return false;
success = MainFileManager->moveFile(bufferID, pfn);
scnN.nmhdr.code = success ? NPPN_FILERENAMED : NPPN_FILERENAMECANCEL;
_pluginsManager.notify(&scnN);
return success;
}
@ -1120,6 +1129,12 @@ bool Notepad_plus::fileDelete(BufferID id)
if (goAhead)
{
SCNotification scnN;
scnN.nmhdr.code = NPPN_FILEBEFOREDELETE;
scnN.nmhdr.hwndFrom = _pPublicInterface->getHSelf();
scnN.nmhdr.idFrom = (uptr_t)bufferID;
_pluginsManager.notify(&scnN);
if (!MainFileManager->deleteFile(bufferID))
{
_nativeLangSpeaker.messageBox("DeleteFileFailed",
@ -1127,11 +1142,20 @@ bool Notepad_plus::fileDelete(BufferID id)
TEXT("Delete File failed"),
TEXT("Delete File"),
MB_OK);
scnN.nmhdr.code = NPPN_FILEDELETEFAILED;
_pluginsManager.notify(&scnN);
return false;
}
bool isSnapshotMode = NppParameters::getInstance()->getNppGUI().isSnapshotMode();
doClose(bufferID, MAIN_VIEW, isSnapshotMode);
doClose(bufferID, SUB_VIEW, isSnapshotMode);
scnN.nmhdr.code = NPPN_FILEDELETED;
scnN.nmhdr.idFrom = (uptr_t)-1;
_pluginsManager.notify(&scnN);
return true;
}
return false;