From d4124108bc5eabdfb04cdfc546ca884f5b8a54f5 Mon Sep 17 00:00:00 2001 From: Don HO Date: Sat, 30 May 2020 16:50:59 +0200 Subject: [PATCH] Enhance Save file dialog Make file extensions shorter in the file extension list for Save file dialog, so it displays more nicely while user clicking the drop down commbobox. --- PowerEditor/src/Notepad_plus.h | 4 ++-- PowerEditor/src/NppIO.cpp | 19 +++++++++++++------ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h index 9aef0676c..d966247a0 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -583,8 +583,8 @@ private: int getLangFromMenuName(const TCHAR * langName); generic_string getLangFromMenu(const Buffer * buf); - generic_string exts2Filters(const generic_string& exts) const; - int setFileOpenSaveDlgFilters(FileDialog & fDlg, int langType = -1); + generic_string exts2Filters(const generic_string& exts, int maxExtsLen = -1) const; // maxExtsLen default value -1 makes no limit of whole exts length + int setFileOpenSaveDlgFilters(FileDialog & fDlg, bool showAllExt, int langType = -1); // showAllExt should be true if it's used for open file dialog - all set exts should be used for filtering files Style * getStyleFromName(const TCHAR *styleName); bool dumpFiles(const TCHAR * outdir, const TCHAR * fileprefix = TEXT("")); //helper func void drawTabbarColoursFromStylerArray(); diff --git a/PowerEditor/src/NppIO.cpp b/PowerEditor/src/NppIO.cpp index 29db16629..14ff4b5a3 100644 --- a/PowerEditor/src/NppIO.cpp +++ b/PowerEditor/src/NppIO.cpp @@ -739,7 +739,7 @@ void Notepad_plus::doClose(BufferID id, int whichOne, bool doDeleteBackup) return; } -generic_string Notepad_plus::exts2Filters(const generic_string& exts) const +generic_string Notepad_plus::exts2Filters(const generic_string& exts, int maxExtsLen) const { const TCHAR *extStr = exts.c_str(); TCHAR aExt[MAX_PATH]; @@ -747,6 +747,7 @@ generic_string Notepad_plus::exts2Filters(const generic_string& exts) const int j = 0; bool stop = false; + for (size_t i = 0, len = exts.length(); i < len && j < MAX_PATH - 1; ++i) { if (extStr[i] == ' ') @@ -763,6 +764,12 @@ generic_string Notepad_plus::exts2Filters(const generic_string& exts) const filters += TEXT(";"); } j = 0; + + if (maxExtsLen != -1 && i >= maxExtsLen) + { + filters += TEXT(" ... "); + break; + } } } else @@ -789,7 +796,7 @@ generic_string Notepad_plus::exts2Filters(const generic_string& exts) const return filters; } -int Notepad_plus::setFileOpenSaveDlgFilters(FileDialog & fDlg, int langType) +int Notepad_plus::setFileOpenSaveDlgFilters(FileDialog & fDlg, bool showAllExt, int langType) { NppParameters& nppParam = NppParameters::getInstance(); NppGUI & nppGUI = (NppGUI & )nppParam.getNppGUI(); @@ -835,7 +842,7 @@ int Notepad_plus::setFileOpenSaveDlgFilters(FileDialog & fDlg, int langType) list += userList; } - generic_string stringFilters = exts2Filters(list); + generic_string stringFilters = exts2Filters(list, showAllExt ? -1 : 40); const TCHAR *filters = stringFilters.c_str(); if (filters[0]) { @@ -1583,7 +1590,7 @@ bool Notepad_plus::fileSaveAs(BufferID id, bool isSaveCopy) FileDialog fDlg(_pPublicInterface->getHSelf(), _pPublicInterface->getHinst()); fDlg.setExtFilter(TEXT("All types"), TEXT(".*"), NULL); - int langTypeIndex = setFileOpenSaveDlgFilters(fDlg, buf->getLangType()); + int langTypeIndex = setFileOpenSaveDlgFilters(fDlg, false, buf->getLangType()); fDlg.setDefFileName(buf->getFileName()); fDlg.setExtIndex(langTypeIndex+1); // +1 for "All types" @@ -1649,7 +1656,7 @@ bool Notepad_plus::fileRename(BufferID id) FileDialog fDlg(_pPublicInterface->getHSelf(), _pPublicInterface->getHinst()); fDlg.setExtFilter(TEXT("All types"), TEXT(".*"), NULL); - setFileOpenSaveDlgFilters(fDlg); + setFileOpenSaveDlgFilters(fDlg, false); fDlg.setDefFileName(buf->getFileName()); TCHAR *pfn = fDlg.doSaveDlg(); @@ -1759,7 +1766,7 @@ void Notepad_plus::fileOpen() FileDialog fDlg(_pPublicInterface->getHSelf(), _pPublicInterface->getHinst()); fDlg.setExtFilter(TEXT("All types"), TEXT(".*"), NULL); - setFileOpenSaveDlgFilters(fDlg); + setFileOpenSaveDlgFilters(fDlg, true); BufferID lastOpened = BUFFER_INVALID; if (stringVector *pfns = fDlg.doOpenMultiFilesDlg())