From 05dae4a720bee9e8ec295d01104a60e05301eb44 Mon Sep 17 00:00:00 2001 From: Don Ho Date: Thu, 19 May 2022 16:45:17 +0200 Subject: [PATCH] Make fold/unfold current line commads togglable Add an option "Make current line folding/unfolding commands togglable" in Editing section of Preference dialog to make both Collapse/Uncollapse Current level commands togglable. Fix #11529, fix #9196, close 11699 --- PowerEditor/src/Notepad_plus.cpp | 1 + PowerEditor/src/Notepad_plus.rc | 4 +-- PowerEditor/src/NppCommands.cpp | 29 +++++++++++++------ PowerEditor/src/Parameters.cpp | 9 ++++-- PowerEditor/src/Parameters.h | 1 + .../ScintillaComponent/ScintillaEditView.cpp | 20 +++++++++++++ .../ScintillaComponent/ScintillaEditView.h | 3 +- .../src/WinControls/Preference/preference.rc | 13 ++++----- .../WinControls/Preference/preferenceDlg.cpp | 5 ++++ .../WinControls/Preference/preference_rc.h | 2 ++ PowerEditor/src/menuCmdID.h | 4 +-- 11 files changed, 67 insertions(+), 24 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index abe189d56..86ae59844 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -7286,6 +7286,7 @@ static const QuoteParams quotes[] = {TEXT("Anonymous #190"), QuoteParams::slow, false, SC_CP_UTF8, L_TEXT, TEXT("The greatest security vulnerability in any computer system is located between the keyboard and the chair.\n") }, {TEXT("Anonymous #191"), QuoteParams::slow, false, SC_CP_UTF8, L_TEXT, TEXT("My biggest talent is always being able to tell what's in a wrapped present.\n\nIt's a gift.\n") }, {TEXT("Anonymous #192"), QuoteParams::rapid, false, SC_CP_UTF8, L_TEXT, TEXT("You can't force someone to love you.\nBut you can lock this person in the basement and wait for him/her to develop Stockholm syndrome.\n") }, + {TEXT("Anonymous #193"), QuoteParams::rapid, false, SC_CP_UTF8, L_TEXT, TEXT("Do you know:\nthere are more airplanes in the oceans, than submarines in the sky?\n") }, {TEXT("xkcd"), QuoteParams::rapid, false, SC_CP_UTF8, L_TEXT, TEXT("Never have I felt so close to another soul\nAnd yet so helplessly alone\nAs when I Google an error\nAnd there's one result\nA thread by someone with the same problem\nAnd no answer\nLast posted to in 2003\n\n\"Who were you, DenverCoder9?\"\n\"What did you see?!\"\n\n(ref: https://xkcd.com/979/)") }, {TEXT("A developer"), QuoteParams::slow, false, SC_CP_UTF8, L_TEXT, TEXT("No hugs & kisses.\nOnly bugs & fixes.") }, {TEXT("Elon Musk"), QuoteParams::rapid, false, SC_CP_UTF8, L_TEXT, TEXT("Don't set your password as your child's name.\nName your child after your password.") }, diff --git a/PowerEditor/src/Notepad_plus.rc b/PowerEditor/src/Notepad_plus.rc index 68b0a2b80..e6f15104e 100644 --- a/PowerEditor/src/Notepad_plus.rc +++ b/PowerEditor/src/Notepad_plus.rc @@ -702,8 +702,8 @@ BEGIN MENUITEM "Focus on Another View", IDM_VIEW_SWITCHTO_OTHER_VIEW MENUITEM "Hide Lines", IDM_VIEW_HIDELINES MENUITEM SEPARATOR - MENUITEM "Fold All", IDM_VIEW_TOGGLE_FOLDALL - MENUITEM "Unfold All", IDM_VIEW_TOGGLE_UNFOLDALL + MENUITEM "Fold All", IDM_VIEW_FOLDALL + MENUITEM "Unfold All", IDM_VIEW_UNFOLDALL MENUITEM "Collapse Current Level", IDM_VIEW_FOLD_CURRENT MENUITEM "Uncollapse Current Level", IDM_VIEW_UNFOLD_CURRENT POPUP "Collapse Level" diff --git a/PowerEditor/src/NppCommands.cpp b/PowerEditor/src/NppCommands.cpp index 9bf024b6b..0ead097b0 100644 --- a/PowerEditor/src/NppCommands.cpp +++ b/PowerEditor/src/NppCommands.cpp @@ -1977,16 +1977,27 @@ void Notepad_plus::command(int id) break; - case IDM_VIEW_FOLD_CURRENT : - case IDM_VIEW_UNFOLD_CURRENT : - _pEditView->foldCurrentPos((id==IDM_VIEW_FOLD_CURRENT)?fold_collapse:fold_uncollapse); - break; + case IDM_VIEW_FOLD_CURRENT: + case IDM_VIEW_UNFOLD_CURRENT: + { + bool isToggleEnabled = NppParameters::getInstance().getNppGUI()._enableFoldCmdToggable; + bool mode = id == IDM_VIEW_FOLD_CURRENT ? fold_collapse : fold_uncollapse; - case IDM_VIEW_TOGGLE_FOLDALL: - case IDM_VIEW_TOGGLE_UNFOLDALL: + if (isToggleEnabled) + { + bool isFolded = _pEditView->isCurrentLineFolded(); + mode = isFolded ? fold_uncollapse : fold_collapse; + } + + _pEditView->foldCurrentPos(mode); + } + break; + + case IDM_VIEW_FOLDALL: + case IDM_VIEW_UNFOLDALL: { _isFolding = true; // So we can ignore events while folding is taking place - bool doCollapse = (id==IDM_VIEW_TOGGLE_FOLDALL)?fold_collapse:fold_uncollapse; + bool doCollapse = (id==IDM_VIEW_FOLDALL)?fold_collapse:fold_uncollapse; _pEditView->foldAll(doCollapse); if (_pDocMap) { @@ -3930,8 +3941,8 @@ void Notepad_plus::command(int id) case IDM_VIEW_WRAP : case IDM_VIEW_FOLD_CURRENT : case IDM_VIEW_UNFOLD_CURRENT : - case IDM_VIEW_TOGGLE_FOLDALL: - case IDM_VIEW_TOGGLE_UNFOLDALL: + case IDM_VIEW_FOLDALL: + case IDM_VIEW_UNFOLDALL: case IDM_VIEW_FOLD_1: case IDM_VIEW_FOLD_2: case IDM_VIEW_FOLD_3: diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index 1bbc99f9b..645df7692 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -284,8 +284,8 @@ static const WinMenuKeyDefinition winKeyDefs[] = { VK_H, IDM_VIEW_HIDELINES, false, true, false, nullptr }, { VK_F8, IDM_VIEW_SWITCHTO_OTHER_VIEW, false, false, false, nullptr }, - { VK_0, IDM_VIEW_TOGGLE_FOLDALL, false, true, false, nullptr }, - { VK_0, IDM_VIEW_TOGGLE_UNFOLDALL, false, true, true, nullptr }, + { VK_0, IDM_VIEW_FOLDALL, false, true, false, nullptr }, + { VK_0, IDM_VIEW_UNFOLDALL, false, true, true, nullptr }, { VK_F, IDM_VIEW_FOLD_CURRENT, true, true, false, nullptr }, { VK_F, IDM_VIEW_UNFOLD_CURRENT, true, true, true, nullptr }, { VK_1, IDM_VIEW_FOLD_1, false, true, false, TEXT("Collapse Level 1") }, @@ -5516,6 +5516,10 @@ void NppParameters::feedGUIParameters(TiXmlNode *node) const TCHAR * optMuteSounds = element->Attribute(TEXT("muteSounds")); if (optMuteSounds) _nppGUI._muteSounds = lstrcmp(optMuteSounds, TEXT("yes")) == 0; + + const TCHAR * optEnableFoldCmdToggable = element->Attribute(TEXT("enableFoldCmdToggable")); + if (optEnableFoldCmdToggable) + _nppGUI._enableFoldCmdToggable = lstrcmp(optEnableFoldCmdToggable, TEXT("yes")) == 0; } else if (!lstrcmp(nm, TEXT("commandLineInterpreter"))) { @@ -6619,6 +6623,7 @@ void NppParameters::createXmlTreeFromGUIParams() GUIConfigElement->SetAttribute(TEXT("sortFunctionList"), _nppGUI._shouldSortFunctionList ? TEXT("yes") : TEXT("no")); GUIConfigElement->SetAttribute(TEXT("saveDlgExtFilterToAllTypes"), _nppGUI._setSaveDlgExtFiltToAllTypes ? TEXT("yes") : TEXT("no")); GUIConfigElement->SetAttribute(TEXT("muteSounds"), _nppGUI._muteSounds ? TEXT("yes") : TEXT("no")); + GUIConfigElement->SetAttribute(TEXT("enableFoldCmdToggable"), _nppGUI._enableFoldCmdToggable ? TEXT("yes") : TEXT("no")); } // diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index e0ca9a199..aa07af6db 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -803,6 +803,7 @@ struct NppGUI final bool _confirmReplaceInAllOpenDocs = true; bool _replaceStopsWithoutFindingNext = false; bool _muteSounds = false; + bool _enableFoldCmdToggable = false; writeTechnologyEngine _writeTechnologyEngine = defaultTechnology; bool _isWordCharDefault = true; std::string _customWordChars; diff --git a/PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp b/PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp index 1ae0104e4..e57a5f92b 100644 --- a/PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp +++ b/PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp @@ -2132,6 +2132,26 @@ void ScintillaEditView::foldCurrentPos(bool mode) fold(currentLine, mode); } +bool ScintillaEditView::isCurrentLineFolded() const +{ + auto currentLine = this->getCurrentLineNumber(); + + intptr_t headerLine; + auto level = execute(SCI_GETFOLDLEVEL, currentLine); + + if (level & SC_FOLDLEVELHEADERFLAG) + headerLine = currentLine; + else + { + headerLine = execute(SCI_GETFOLDPARENT, currentLine); + if (headerLine == -1) + return false; + } + + bool isExpanded = execute(SCI_GETFOLDEXPANDED, headerLine); + return !isExpanded; +} + void ScintillaEditView::fold(size_t line, bool mode) { auto endStyled = execute(SCI_GETENDSTYLED); diff --git a/PowerEditor/src/ScintillaComponent/ScintillaEditView.h b/PowerEditor/src/ScintillaComponent/ScintillaEditView.h index 935d6e2c8..87bab3721 100644 --- a/PowerEditor/src/ScintillaComponent/ScintillaEditView.h +++ b/PowerEditor/src/ScintillaComponent/ScintillaEditView.h @@ -508,9 +508,10 @@ public: void collapse(int level2Collapse, bool mode); void foldAll(bool mode); void fold(size_t line, bool mode); - bool isFolded(size_t line) { + bool isFolded(size_t line) const { return (execute(SCI_GETFOLDEXPANDED, line) != 0); }; + bool isCurrentLineFolded() const; void foldCurrentPos(bool mode); int getCodepage() const {return _codepage;}; diff --git a/PowerEditor/src/WinControls/Preference/preference.rc b/PowerEditor/src/WinControls/Preference/preference.rc index 2d5c44a1d..64586bb0d 100644 --- a/PowerEditor/src/WinControls/Preference/preference.rc +++ b/PowerEditor/src/WinControls/Preference/preference.rc @@ -93,16 +93,13 @@ BEGIN CONTROL "",IDC_CARETLINEFRAME_WIDTH_SLIDER,"msctls_trackbar32",TBS_AUTOTICKS | TBS_BOTH | TBS_NOTICKS | TBS_TRANSPARENTBKGND | WS_TABSTOP,337,67,57,13 LTEXT "1",IDC_CARETLINEFRAME_WIDTH_DISPLAY,396,67,12,8 - CONTROL "Enable Multi-Editing (Ctrl+Mouse click/selection)",IDC_CHECK_MULTISELECTION, - "Button",BS_AUTOCHECKBOX | WS_TABSTOP,26,114,270,10 + CONTROL "Make current line folding/unfolding commands togglable",IDC_CHECK_FOLDINGTOGGLE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,26,103,270,10 + CONTROL "Enable Multi-Editing (Ctrl+Mouse click/selection)",IDC_CHECK_MULTISELECTION,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,26,116,270,10 CONTROL "Enable smooth font",IDC_CHECK_SMOOTHFONT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,26,129,250,10 CONTROL "Enable virtual space",IDC_CHECK_VIRTUALSPACE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,26,142,270,10 - CONTROL "Enable scrolling beyond last line",IDC_CHECK_SCROLLBEYONDLASTLINE, - "Button",BS_AUTOCHECKBOX | WS_TABSTOP,26,155,270,10 - CONTROL "Keep selection when right-click outside of selection",IDC_CHECK_RIGHTCLICKKEEPSSELECTION, - "Button",BS_AUTOCHECKBOX | WS_TABSTOP,26,168,270,10 - CONTROL "Disable advanced scrolling feature due to touchpad issue",IDC_CHECK_DISABLEADVANCEDSCROLL, - "Button",BS_AUTOCHECKBOX | WS_TABSTOP,26,181,270,10 + CONTROL "Enable scrolling beyond last line",IDC_CHECK_SCROLLBEYONDLASTLINE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,26,155,270,10 + CONTROL "Keep selection when right-click outside of selection",IDC_CHECK_RIGHTCLICKKEEPSSELECTION,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,26,168,270,10 + CONTROL "Disable advanced scrolling feature due to touchpad issue",IDC_CHECK_DISABLEADVANCEDSCROLL,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,26,181,270,10 END diff --git a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp index 437c9c384..3989e29d6 100644 --- a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp +++ b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp @@ -768,6 +768,7 @@ intptr_t CALLBACK EditingSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM ::SendMessage(::GetDlgItem(_hSelf, IDC_WIDTH_COMBO), CB_SETCURSEL, nppGUI._caretWidth, 0); + ::SendDlgItemMessage(_hSelf, IDC_CHECK_FOLDINGTOGGLE, BM_SETCHECK, nppGUI._enableFoldCmdToggable, 0); ::SendDlgItemMessage(_hSelf, IDC_CHECK_MULTISELECTION, BM_SETCHECK, nppGUI._enableMultiSelection, 0); ::SendMessage(::GetDlgItem(_hSelf, IDC_CARETBLINKRATE_SLIDER),TBM_SETRANGEMIN, TRUE, BLINKRATE_FASTEST); @@ -903,6 +904,10 @@ intptr_t CALLBACK EditingSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM ::SendMessage(::GetParent(_hParent), NPPM_INTERNAL_SETMULTISELCTION, 0, 0); return TRUE; + case IDC_CHECK_FOLDINGTOGGLE: + nppGUI._enableFoldCmdToggable = isCheckedOrNot(IDC_CHECK_FOLDINGTOGGLE); + return TRUE; + case IDC_RADIO_LWDEF: svp._lineWrapMethod = LINEWRAP_DEFAULT; ::SendMessage(_hParent, WM_COMMAND, IDM_VIEW_LWDEF, 0); diff --git a/PowerEditor/src/WinControls/Preference/preference_rc.h b/PowerEditor/src/WinControls/Preference/preference_rc.h index dbe9c12ea..b505a14c7 100644 --- a/PowerEditor/src/WinControls/Preference/preference_rc.h +++ b/PowerEditor/src/WinControls/Preference/preference_rc.h @@ -136,6 +136,8 @@ #define IDC_CHECK_VIRTUALSPACE (IDD_PREFERENCE_SUB_EDITING + 45) + #define IDC_CHECK_FOLDINGTOGGLE (IDD_PREFERENCE_SUB_EDITING + 46) + #define IDD_PREFERENCE_SUB_DELIMITER 6250 //(IDD_PREFERENCE_BOX + 250) #define IDC_DELIMITERSETTINGS_GB_STATIC (IDD_PREFERENCE_SUB_DELIMITER + 1) diff --git a/PowerEditor/src/menuCmdID.h b/PowerEditor/src/menuCmdID.h index b5618f140..d4b245ddb 100644 --- a/PowerEditor/src/menuCmdID.h +++ b/PowerEditor/src/menuCmdID.h @@ -265,7 +265,7 @@ #define IDM_VIEW_DRAWTABBAR_TOPBAR (IDM_VIEW + 7) #define IDM_VIEW_DRAWTABBAR_INACIVETAB (IDM_VIEW + 8) #define IDM_VIEW_POSTIT (IDM_VIEW + 9) - #define IDM_VIEW_TOGGLE_FOLDALL (IDM_VIEW + 10) + #define IDM_VIEW_FOLDALL (IDM_VIEW + 10) #define IDM_VIEW_DISTRACTIONFREE (IDM_VIEW + 11) #define IDM_VIEW_LINENUMBER (IDM_VIEW + 12) #define IDM_VIEW_SYMBOLMARGIN (IDM_VIEW + 13) @@ -284,7 +284,7 @@ #define IDM_VIEW_EOL (IDM_VIEW + 26) #define IDM_VIEW_TOOLBAR_REDUCE_SET2 (IDM_VIEW + 27) #define IDM_VIEW_TOOLBAR_ENLARGE_SET2 (IDM_VIEW + 28) - #define IDM_VIEW_TOGGLE_UNFOLDALL (IDM_VIEW + 29) + #define IDM_VIEW_UNFOLDALL (IDM_VIEW + 29) #define IDM_VIEW_FOLD_CURRENT (IDM_VIEW + 30) #define IDM_VIEW_UNFOLD_CURRENT (IDM_VIEW + 31) #define IDM_VIEW_FULLSCREENTOGGLE (IDM_VIEW + 32)