[NEW_FEATURE] Add NPPN_FILESAVED and NPPN_FILEBEFORESAVE notifications.

Enhance the File save Dialog (add ext).

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository@50 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
donho 2007-10-08 01:00:13 +00:00
parent 5b4eae3332
commit a088bf7f0f
6 changed files with 102 additions and 26 deletions

View File

@ -211,7 +211,7 @@ enum winVer{WV_UNKNOWN, WV_WIN32S, WV_95, WV_98, WV_ME, WV_NT, WV_W2K, WV_XP, WV
//scnNotification->nmhdr.hwndFrom = hwndNpp;
//scnNotification->nmhdr.idFrom = 0;
#define NPPN_FILECLOSED (NPPN_FIRST + 5) // To notify plugins that the current file is about to be closed
#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;
@ -221,4 +221,14 @@ enum winVer{WV_UNKNOWN, WV_WIN32S, WV_95, WV_98, WV_ME, WV_NT, WV_W2K, WV_XP, WV
//scnNotification->nmhdr.hwndFrom = hwndNpp;
//scnNotification->nmhdr.idFrom = 0;
#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;
#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;
#endif //NOTEPAD_PLUS_MSGS_H

View File

@ -524,12 +524,8 @@ string exts2Filters(string exts) {
return filters;
};
void Notepad_plus::fileOpen()
void Notepad_plus::setFileOpenSaveDlgFilters(FileDialog & fDlg)
{
FileDialog fDlg(_hSelf, _hInst);
fDlg.setExtFilter("All types", ".*", NULL);
NppParameters *pNppParam = NppParameters::getInstance();
NppGUI & nppGUI = (NppGUI & )pNppParam->getNppGUI();
@ -578,6 +574,14 @@ void Notepad_plus::fileOpen()
}
l = (NppParameters::getInstance())->getLangFromIndex(i++);
}
}
void Notepad_plus::fileOpen()
{
FileDialog fDlg(_hSelf, _hInst);
fDlg.setExtFilter("All types", ".*", NULL);
setFileOpenSaveDlgFilters(fDlg);
if (stringVector *pfns = fDlg.doOpenMultiFilesDlg())
{
@ -645,6 +649,13 @@ bool Notepad_plus::doSave(const char *filename, UniMode mode)
if (fp)
{
// Notify plugins that current file is about to be saved
SCNotification scnN;
scnN.nmhdr.code = NPPN_FILEBEFORESAVE;
scnN.nmhdr.hwndFrom = _hSelf;
scnN.nmhdr.idFrom = 0;
_pluginsManager.notify(&scnN);
char data[blockSize + 1];
int lengthDoc = _pEditView->getCurrentDocLen();
for (int i = 0; i < lengthDoc; i += blockSize)
@ -666,6 +677,9 @@ bool Notepad_plus::doSave(const char *filename, UniMode mode)
if (isSys)
::SetFileAttributes(filename, attrib | FILE_ATTRIBUTE_SYSTEM);
scnN.nmhdr.code = NPPN_FILESAVED;
_pluginsManager.notify(&scnN);
return true;
}
::MessageBox(_hSelf, "Please check whether if this file is opened in another program", "Save failed", MB_OK);
@ -1010,18 +1024,8 @@ bool Notepad_plus::fileSaveAs()
FileDialog fDlg(_hSelf, _hInst);
fDlg.setExtFilter("All types", ".*", NULL);
setFileOpenSaveDlgFilters(fDlg);
fDlg.setExtFilter("c src file", ".c", NULL);
fDlg.setExtFilter("c++ src file", ".cpp", NULL);
fDlg.setExtFilter("Window Resource File", ".rc", NULL);
fDlg.setExtFilter("c/c++ header file", ".h", NULL);
fDlg.setExtFilter("Java src file", ".java", NULL);
fDlg.setExtFilter("HTML file", ".html", NULL);
fDlg.setExtFilter("XML file", ".xml", NULL);
fDlg.setExtFilter("php file", ".php",NULL);
fDlg.setExtFilter("ini file", ".ini", NULL);
fDlg.setExtFilter("bat file", ".bat", NULL);
fDlg.setExtFilter("Normal text file", ".txt", NULL);
char str[MAX_PATH];
strcpy(str, _pEditView->getCurrentTitle());

View File

@ -74,6 +74,8 @@ struct iconLocator {
: listIndex(iList), iconIndex(iIcon), iconLocation(iconLoc){};
};
class FileDialog;
class Notepad_plus : public Window {
public:
Notepad_plus();
@ -926,6 +928,8 @@ private:
hideLinesMarkDelete(_hideLinesMarks[i].second, MARK_HIDELINESEND);
}
};
void setFileOpenSaveDlgFilters(FileDialog & fDlg);
};
#endif //NOTEPAD_PLUS_H

View File

@ -376,13 +376,14 @@ BEGIN
END
MENUITEM "Unfold all\tAlt+Shift+0", IDM_VIEW_TOGGLE_UNFOLDALL
MENUITEM SEPARATOR
MENUITEM "Hide lines", IDM_VIEW_HIDELINES
MENUITEM "Hide lines\tAlt+H", IDM_VIEW_HIDELINES
MENUITEM SEPARATOR
MENUITEM "Go to another view", IDM_VIEW_GOTO_ANOTHER_VIEW
MENUITEM "Clone to another view", IDM_VIEW_CLONE_TO_ANOTHER_VIEW
MENUITEM "Synchronize Vertical Scrolling", IDM_VIEW_SYNSCROLLV
MENUITEM "Synchronize Horizontal Scrolling", IDM_VIEW_SYNSCROLLH
END
POPUP "For&mat"
BEGIN
MENUITEM "Convert to Windows Format", IDM_FORMAT_TODOS
@ -604,6 +605,7 @@ BEGIN
"L", IDM_EDIT_LTR, VIRTKEY, CONTROL, ALT
"R", IDM_EDIT_RTL, VIRTKEY, CONTROL, ALT
"C", IDM_EDIT_COLUMNMODE, VIRTKEY, ALT
"H", IDM_VIEW_HIDELINES, VIRTKEY, ALT
VK_HOME, IDC_KEY_HOME, VIRTKEY
VK_END, IDC_KEY_END, VIRTKEY

View File

@ -17,11 +17,11 @@
#include <stdarg.h>
#include "FileDialog.h"
//FileDialog *FileDialog::staticThis = NULL;
FileDialog *FileDialog::staticThis = NULL;
FileDialog::FileDialog(HWND hwnd, HINSTANCE hInst)
: _nbCharFileExt(0), _nbExt(0)
{//staticThis = this;
{staticThis = this;
for (int i = 0 ; i < nbExtMax ; i++)
_extArray[i][0] = '\0';
@ -43,6 +43,7 @@ FileDialog::FileDialog(HWND hwnd, HINSTANCE hInst)
_ofn.lpstrTitle = NULL;
_ofn.nFileOffset = 0;
_ofn.nFileExtension = 0;
_ofn.lpfnHook = NULL;
_ofn.lpstrDefExt = NULL; // No default extension
_ofn.lCustData = 0;
_ofn.Flags = OFN_PATHMUSTEXIST | OFN_EXPLORER | OFN_LONGNAMES | DS_CENTER | OFN_HIDEREADONLY;
@ -186,6 +187,9 @@ char * FileDialog::doSaveDlg()
_ofn.Flags |= OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY;
_ofn.Flags |= OFN_ENABLEHOOK;
_ofn.lpfnHook = OFNHookProc;
char *fn = NULL;
try {
fn = ::GetSaveFileName(&_ofn)?_fileName:NULL;
@ -196,7 +200,7 @@ char * FileDialog::doSaveDlg()
return (fn);
}
/*
UINT_PTR CALLBACK FileDialog::OFNHookProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
@ -204,8 +208,9 @@ UINT_PTR CALLBACK FileDialog::OFNHookProc(HWND hWnd, UINT uMsg, WPARAM wParam, L
case WM_INITDIALOG :
{
::SetWindowLong(hWnd, GWL_USERDATA, (long)staticThis);
//printStr("en train");
//pStaticDlg->run_dlgProc(message, wParam, lParam);
return TRUE;
return FALSE;
}
default :
@ -219,4 +224,4 @@ UINT_PTR CALLBACK FileDialog::OFNHookProc(HWND hWnd, UINT uMsg, WPARAM wParam, L
//::OFNHookProc(hWnd, uMsg, wParam, lParam);
return FALSE;
}
*/

View File

@ -24,11 +24,14 @@
#include <vector>
#include <string>
#include "SysMsg.h"
const int nbExtMax = 10;
const int extLenMax = 10;
typedef std::vector<std::string> stringVector;
using namespace std;
typedef vector<string> stringVector;
//const bool styleOpen = true;
//const bool styleSave = false;
@ -45,7 +48,7 @@ public:
stringVector * doOpenMultiFilesDlg();
char * doOpenSingleFileDlg();
bool isReadOnly() {return _ofn.Flags & OFN_READONLY;};
/*
protected :
static UINT APIENTRY OFNHookProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
BOOL APIENTRY run(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
@ -58,13 +61,51 @@ protected :
{
case CDN_FILEOK :
{
printStr("CDN_FILEOK");
if ((_fileName)&&(!strrchr(_extArray[_ofn.nFilterIndex - 1], '*'))
&& (strcmp(_extArray[_ofn.nFilterIndex - 1], _fileName + _ofn.nFileExtension - 1)))
{
strcat(_fileName, _extArray[_ofn.nFilterIndex - 1]);
}
break;
}
case CDN_TYPECHANGE :
{
HWND fnControl = ::GetDlgItem(::GetParent(hWnd), edt1);
char fn[256];
::GetWindowText(fnControl, fn, sizeof(fn));
if (*fn == '\0')
return TRUE;
HWND typeControl = ::GetDlgItem(::GetParent(hWnd), cmb1);
int i = ::SendMessage(typeControl, CB_GETCURSEL, 0, 0);
char ext[256];
::SendMessage(typeControl, CB_GETLBTEXT, i, (LPARAM)ext);
//printInt(i);
//
char *pExt = get1stExt(ext);
if (*pExt == '\0')
return TRUE;
//::SendMessage(::GetParent(hWnd), CDM_SETDEFEXT, 0, (LPARAM)pExt);
string fnExt = fn;
int index = fnExt.find_last_of(".");
string extension = ".";
extension += pExt;
if (index == string::npos)
{
fnExt += extension;
}
else
{
int len = (extension.length() > fnExt.length() - index + 1)?extension.length():fnExt.length() - index + 1;
fnExt.replace(index, len, extension);
}
::SetWindowText(fnControl, fnExt.c_str());
break;
}
default :
return FALSE;
}
@ -74,7 +115,7 @@ protected :
return FALSE;
}
};
*/
private:
char _fileName[MAX_PATH*8];
@ -87,6 +128,16 @@ private:
char _extArray[nbExtMax][extLenMax];
int _nbExt;
char * get1stExt(char *ext) { // precondition : ext should be under the format : Batch (*.bat;*.cmd;*.nt)
char *begin = ext;
for ( ; *begin != '.' ; begin++);
char *end = ++begin;
for ( ; *end != ';' && *end != ')' ; end++);
*end = '\0';
if (*begin == '*')
*begin = '\0';
return begin;
};
static FileDialog *staticThis;
};