[NEW_FEATURE] Set extension automatically (according to set document language) in save as dialog.
git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@542 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
parent
ea2caf3d1d
commit
dfaed129b5
@ -983,7 +983,7 @@ generic_string exts2Filters(generic_string exts) {
|
||||
return filters;
|
||||
};
|
||||
|
||||
void Notepad_plus::setFileOpenSaveDlgFilters(FileDialog & fDlg)
|
||||
int Notepad_plus::setFileOpenSaveDlgFilters(FileDialog & fDlg, int langType)
|
||||
{
|
||||
NppParameters *pNppParam = NppParameters::getInstance();
|
||||
NppGUI & nppGUI = (NppGUI & )pNppParam->getNppGUI();
|
||||
@ -991,6 +991,8 @@ void Notepad_plus::setFileOpenSaveDlgFilters(FileDialog & fDlg)
|
||||
int i = 0;
|
||||
Lang *l = NppParameters::getInstance()->getLangFromIndex(i++);
|
||||
|
||||
int ltIndex = 0;
|
||||
bool ltFound = false;
|
||||
while (l)
|
||||
{
|
||||
LangType lid = l->getLangID();
|
||||
@ -1032,10 +1034,27 @@ void Notepad_plus::setFileOpenSaveDlgFilters(FileDialog & fDlg)
|
||||
if (filters[0])
|
||||
{
|
||||
fDlg.setExtsFilter(getLangDesc(lid, true).c_str(), filters);
|
||||
|
||||
//
|
||||
// Get index of lang type to find
|
||||
//
|
||||
if (langType != -1 && !ltFound)
|
||||
{
|
||||
ltFound = langType == lid;
|
||||
}
|
||||
|
||||
if (langType != -1 && !ltFound)
|
||||
{
|
||||
ltIndex++;
|
||||
}
|
||||
}
|
||||
}
|
||||
l = (NppParameters::getInstance())->getLangFromIndex(i++);
|
||||
}
|
||||
|
||||
if (!ltFound)
|
||||
return -1;
|
||||
return ltIndex;
|
||||
}
|
||||
|
||||
void Notepad_plus::fileOpen()
|
||||
@ -1198,9 +1217,10 @@ bool Notepad_plus::fileSaveAs(BufferID id, bool isSaveCopy)
|
||||
FileDialog fDlg(_hSelf, _hInst);
|
||||
|
||||
fDlg.setExtFilter(TEXT("All types"), TEXT(".*"), NULL);
|
||||
setFileOpenSaveDlgFilters(fDlg);
|
||||
|
||||
int langTypeIndex = setFileOpenSaveDlgFilters(fDlg, buf->getLangType());
|
||||
fDlg.setDefFileName(buf->getFileName());
|
||||
|
||||
fDlg.setExtIndex(langTypeIndex+1); // +1 for "All types"
|
||||
TCHAR *pfn = fDlg.doSaveDlg();
|
||||
|
||||
if (pfn)
|
||||
|
@ -557,7 +557,7 @@ private:
|
||||
int getLangFromMenuName(const TCHAR * langName);
|
||||
generic_string getLangFromMenu(const Buffer * buf);
|
||||
|
||||
void setFileOpenSaveDlgFilters(FileDialog & fDlg);
|
||||
int setFileOpenSaveDlgFilters(FileDialog & fDlg, int langType = -1);
|
||||
void markSelectedTextInc(bool enable);
|
||||
Style * getStyleFromName(const TCHAR *styleName);
|
||||
bool dumpFiles(const TCHAR * outdir, const TCHAR * fileprefix = TEXT("")); //helper func
|
||||
|
@ -24,7 +24,7 @@ FileDialog *FileDialog::staticThis = NULL;
|
||||
//int FileDialog::_dialogFileBoxId = (NppParameters::getInstance())->getWinVersion() < WV_W2K?edt1:cmb13;
|
||||
|
||||
FileDialog::FileDialog(HWND hwnd, HINSTANCE hInst)
|
||||
: _nbCharFileExt(0), _nbExt(0), _fileExt(NULL)
|
||||
: _nbCharFileExt(0), _nbExt(0), _fileExt(NULL), _extTypeIndex(-1)
|
||||
{
|
||||
staticThis = this;
|
||||
//for (int i = 0 ; i < nbExtMax ; i++)
|
||||
@ -374,13 +374,25 @@ BOOL APIENTRY FileDialog::run(HWND hWnd, UINT uMsg, WPARAM, LPARAM lParam)
|
||||
LPNMHDR pNmhdr = (LPNMHDR)lParam;
|
||||
switch(pNmhdr->code)
|
||||
{
|
||||
case CDN_INITDONE :
|
||||
{
|
||||
if (_extTypeIndex == -1)
|
||||
return TRUE;
|
||||
|
||||
HWND fnControl = ::GetDlgItem(::GetParent(hWnd), _dialogFileBoxId);
|
||||
HWND typeControl = ::GetDlgItem(::GetParent(hWnd), cmb1);
|
||||
::SendMessage(typeControl, CB_SETCURSEL, _extTypeIndex, 0);
|
||||
|
||||
currentExt = addExt(fnControl, typeControl);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
case CDN_TYPECHANGE :
|
||||
{
|
||||
HWND fnControl = ::GetDlgItem(::GetParent(hWnd), _dialogFileBoxId);
|
||||
HWND typeControl = ::GetDlgItem(::GetParent(hWnd), cmb1);
|
||||
currentExt = addExt(fnControl, typeControl);
|
||||
return TRUE;
|
||||
//break;
|
||||
}
|
||||
|
||||
case CDN_FILEOK :
|
||||
@ -390,7 +402,6 @@ BOOL APIENTRY FileDialog::run(HWND hWnd, UINT uMsg, WPARAM, LPARAM lParam)
|
||||
NppParameters *pNppParam = NppParameters::getInstance();
|
||||
pNppParam->setFileSaveDlgFilterIndex(index);
|
||||
return TRUE;
|
||||
//break;
|
||||
}
|
||||
|
||||
default :
|
||||
|
@ -70,6 +70,7 @@ public:
|
||||
stringVector * doOpenMultiFilesDlg();
|
||||
TCHAR * doOpenSingleFileDlg();
|
||||
bool isReadOnly() {return _ofn.Flags & OFN_READONLY;};
|
||||
void setExtIndex(int extTypeIndex) {_extTypeIndex = extTypeIndex;};
|
||||
|
||||
static int _dialogFileBoxId;
|
||||
protected :
|
||||
@ -90,7 +91,7 @@ private:
|
||||
|
||||
//TCHAR _extArray[nbExtMax][extLenMax];
|
||||
int _nbExt;
|
||||
|
||||
int _extTypeIndex;
|
||||
static FileDialog *staticThis;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user