From bbde64c30845761377d063afa7750ec7ce0659a6 Mon Sep 17 00:00:00 2001 From: Scott Sumner <30118311+sasumner@users.noreply.github.com> Date: Sun, 4 Oct 2020 07:38:11 -0400 Subject: [PATCH] Add preference for save type of normal text files Fix #8866, close #8948 --- PowerEditor/installer/nativeLang/english.xml | 1 + PowerEditor/src/NppIO.cpp | 15 ++++++++++++--- PowerEditor/src/Parameters.cpp | 7 ++++++- PowerEditor/src/Parameters.h | 1 + .../src/WinControls/Preference/preference.rc | 5 +++-- .../src/WinControls/Preference/preferenceDlg.cpp | 7 ++++++- .../src/WinControls/Preference/preference_rc.h | 3 ++- 7 files changed, 31 insertions(+), 8 deletions(-) diff --git a/PowerEditor/installer/nativeLang/english.xml b/PowerEditor/installer/nativeLang/english.xml index 359f2d5e..3f64f21c 100644 --- a/PowerEditor/installer/nativeLang/english.xml +++ b/PowerEditor/installer/nativeLang/english.xml @@ -1020,6 +1020,7 @@ You can define several column markers by using white space to separate the diffe + diff --git a/PowerEditor/src/NppIO.cpp b/PowerEditor/src/NppIO.cpp index c3e7ddf9..16979228 100644 --- a/PowerEditor/src/NppIO.cpp +++ b/PowerEditor/src/NppIO.cpp @@ -1647,11 +1647,20 @@ 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, false, buf->getLangType()); + fDlg.setExtFilter(TEXT("All types"), TEXT(".*"), NULL); + + LangType langType = buf->getLangType(); + + int langTypeIndex = 0; + if (!((NppParameters::getInstance()).getNppGUI()._setSaveDlgExtFiltToAllTypesForNormText && + buf->isUntitled() && langType == L_TEXT)) + { + langTypeIndex = setFileOpenSaveDlgFilters(fDlg, false, langType); + } + fDlg.setDefFileName(buf->getFileName()); - fDlg.setExtIndex(langTypeIndex + 1); // +1 for "All types" + fDlg.setExtIndex(langTypeIndex + 1); // +1 for "All types" // Disable file autodetection before opening save dialog to prevent use-after-delete bug. NppParameters& nppParam = NppParameters::getInstance(); diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index 9b7b98fe..203ada3c 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -5220,6 +5220,10 @@ void NppParameters::feedGUIParameters(TiXmlNode *node) const TCHAR * optDocPeekOnMap = element->Attribute(TEXT("docPeekOnMap")); if (optDocPeekOnMap) _nppGUI._isDocPeekOnMap = (lstrcmp(optDocPeekOnMap, TEXT("yes")) == 0); + + const TCHAR* saveDlgExtFilterToAllTypesForNormText = element->Attribute(TEXT("saveDlgExtFilterToAllTypesForNormalText")); + if (saveDlgExtFilterToAllTypesForNormText) + _nppGUI._setSaveDlgExtFiltToAllTypesForNormText = (lstrcmp(saveDlgExtFilterToAllTypesForNormText, TEXT("yes")) == 0); } else if (!lstrcmp(nm, TEXT("commandLineInterpreter"))) { @@ -5989,7 +5993,7 @@ void NppParameters::createXmlTreeFromGUIParams() GUIConfigElement->SetAttribute(TEXT("setting"), _nppGUI._multiInstSetting); } - // + // { TiXmlElement *GUIConfigElement = (newGUIRoot->InsertEndChild(TiXmlElement(TEXT("GUIConfig"))))->ToElement(); GUIConfigElement->SetAttribute(TEXT("name"), TEXT("MISC")); @@ -6001,6 +6005,7 @@ void NppParameters::createXmlTreeFromGUIParams() GUIConfigElement->SetAttribute(TEXT("isFolderDroppedOpenFiles"), _nppGUI._isFolderDroppedOpenFiles ? TEXT("yes") : TEXT("no")); GUIConfigElement->SetAttribute(TEXT("docPeekOnTab"), _nppGUI._isDocPeekOnTab ? TEXT("yes") : TEXT("no")); GUIConfigElement->SetAttribute(TEXT("docPeekOnMap"), _nppGUI._isDocPeekOnMap ? TEXT("yes") : TEXT("no")); + GUIConfigElement->SetAttribute(TEXT("saveDlgExtFilterToAllTypesForNormalText"), _nppGUI._setSaveDlgExtFiltToAllTypesForNormText ? TEXT("yes") : TEXT("no")); } // diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index 5d7d03d3..553213dc 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -822,6 +822,7 @@ struct NppGUI final bool _rememberLastSession = true; // remember next session boolean will be written in the settings bool _isCmdlineNosessionActivated = false; // used for if -nosession is indicated on the launch time bool _detectEncoding = true; + bool _setSaveDlgExtFiltToAllTypesForNormText = false; bool _doTaskList = true; bool _maitainIndent = true; bool _enableSmartHilite = true; diff --git a/PowerEditor/src/WinControls/Preference/preference.rc b/PowerEditor/src/WinControls/Preference/preference.rc index 87ceaf29..becba63a 100644 --- a/PowerEditor/src/WinControls/Preference/preference.rc +++ b/PowerEditor/src/WinControls/Preference/preference.rc @@ -122,9 +122,10 @@ BEGIN CONTROL "Enable MRU behaviour",IDC_CHECK_STYLEMRU,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,45,28,140,10 CONTROL "Peek on tab",IDC_CHECK_ENABLEDOCPEEKER,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,45,58,140,10 CONTROL "Peek on document map", IDC_CHECK_ENABLEDOCPEEKONMAP,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,45,71,140,10 - + // "Enable Notepad++ auto-updater" should be always the 1st item, because it'll be hidden if GUP.exe is absent - CONTROL "Enable Notepad++ auto-updater",IDC_CHECK_AUTOUPDATE, "Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP,37,128,217,10 + CONTROL "Enable Notepad++ auto-updater",IDC_CHECK_AUTOUPDATE, "Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP,37,113,217,10 + CONTROL "Set Save dialog file extension filter to .* instead of .txt for Normal Text",IDC_CHECK_SAVEDLGEXTFILTALLTYPESFORNORMTEXT, "Button",BS_AUTOCHECKBOX | WS_TABSTOP,37,128,267,10 CONTROL "Autodetect character encoding",IDC_CHECK_DETECTENCODING, "Button",BS_AUTOCHECKBOX | WS_TABSTOP,37,143,217,10 CONTROL "Minimize to system tray",IDC_CHECK_MIN2SYSTRAY,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,37,158,217,10 CONTROL "Show only filename in title bar",IDC_CHECK_SHORTTITLE, "Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP,37,173,217,10 diff --git a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp index 64cb630b..aa0250ca 100644 --- a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp +++ b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp @@ -922,7 +922,8 @@ INT_PTR CALLBACK SettingsDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM) ::SendDlgItemMessage(_hSelf, IDC_CHECK_MIN2SYSTRAY, BM_SETCHECK, nppGUI._isMinimizedToTray, 0); ::SendDlgItemMessage(_hSelf, IDC_CHECK_DETECTENCODING, BM_SETCHECK, nppGUI._detectEncoding, 0); - ::SendDlgItemMessage(_hSelf, IDC_CHECK_AUTOUPDATE, BM_SETCHECK, nppGUI._autoUpdateOpt._doAutoUpdate, 0); + ::SendDlgItemMessage(_hSelf, IDC_CHECK_AUTOUPDATE, BM_SETCHECK, nppGUI._autoUpdateOpt._doAutoUpdate, 0); + ::SendDlgItemMessage(_hSelf, IDC_CHECK_SAVEDLGEXTFILTALLTYPESFORNORMTEXT, BM_SETCHECK, nppGUI._setSaveDlgExtFiltToAllTypesForNormText, 0); ::SendDlgItemMessage(_hSelf, IDC_CHECK_DIRECTWRITE_ENABLE, BM_SETCHECK, nppGUI._writeTechnologyEngine == directWriteTechnology, 0); ::SendDlgItemMessage(_hSelf, IDC_CHECK_ENABLEDOCPEEKER, BM_SETCHECK, nppGUI._isDocPeekOnTab ? BST_CHECKED : BST_UNCHECKED, 0); ::SendDlgItemMessage(_hSelf, IDC_CHECK_ENABLEDOCPEEKONMAP, BM_SETCHECK, nppGUI._isDocPeekOnMap ? BST_CHECKED : BST_UNCHECKED, 0); @@ -1040,6 +1041,10 @@ INT_PTR CALLBACK SettingsDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM) nppGUI._autoUpdateOpt._doAutoUpdate = isCheckedOrNot(static_cast(wParam)); return TRUE; + case IDC_CHECK_SAVEDLGEXTFILTALLTYPESFORNORMTEXT: + nppGUI._setSaveDlgExtFiltToAllTypesForNormText = isCheckedOrNot(static_cast(wParam)); + return TRUE; + case IDC_CHECK_MIN2SYSTRAY: nppGUI._isMinimizedToTray = isCheckedOrNot(static_cast(wParam)); return TRUE; diff --git a/PowerEditor/src/WinControls/Preference/preference_rc.h b/PowerEditor/src/WinControls/Preference/preference_rc.h index c37b3dff..11e43427 100644 --- a/PowerEditor/src/WinControls/Preference/preference_rc.h +++ b/PowerEditor/src/WinControls/Preference/preference_rc.h @@ -199,7 +199,8 @@ #define IDC_CHECK_SMARTHILITEWHOLEWORDONLY (IDD_PREFERENCE_SETTING_BOX + 38) #define IDC_CHECK_SMARTHILITEUSEFINDSETTINGS (IDD_PREFERENCE_SETTING_BOX + 39) #define IDC_CHECK_SMARTHILITEANOTHERRVIEW (IDD_PREFERENCE_SETTING_BOX + 40) - + #define IDC_CHECK_SAVEDLGEXTFILTALLTYPESFORNORMTEXT (IDD_PREFERENCE_SETTING_BOX + 51) + //-- xFileEditViewHistoryParameterGUI: Additional Checkbox for enabling the history for restoring the edit view per file. #define IDC_CHECK_REMEMBEREDITVIEWPERFILE (IDD_PREFERENCE_SETTING_BOX + 41) #define IDC_REMEMBEREDITVIEWPERFILE_STATIC (IDD_PREFERENCE_SETTING_BOX + 42)