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
pull/11714/head
Don Ho 2022-05-19 16:45:17 +02:00
parent e701c208a6
commit 05dae4a720
11 changed files with 67 additions and 24 deletions

View File

@ -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 #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 #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 #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("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("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.") }, {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.") },

View File

@ -702,8 +702,8 @@ BEGIN
MENUITEM "Focus on Another View", IDM_VIEW_SWITCHTO_OTHER_VIEW MENUITEM "Focus on Another View", IDM_VIEW_SWITCHTO_OTHER_VIEW
MENUITEM "Hide Lines", IDM_VIEW_HIDELINES MENUITEM "Hide Lines", IDM_VIEW_HIDELINES
MENUITEM SEPARATOR MENUITEM SEPARATOR
MENUITEM "Fold All", IDM_VIEW_TOGGLE_FOLDALL MENUITEM "Fold All", IDM_VIEW_FOLDALL
MENUITEM "Unfold All", IDM_VIEW_TOGGLE_UNFOLDALL MENUITEM "Unfold All", IDM_VIEW_UNFOLDALL
MENUITEM "Collapse Current Level", IDM_VIEW_FOLD_CURRENT MENUITEM "Collapse Current Level", IDM_VIEW_FOLD_CURRENT
MENUITEM "Uncollapse Current Level", IDM_VIEW_UNFOLD_CURRENT MENUITEM "Uncollapse Current Level", IDM_VIEW_UNFOLD_CURRENT
POPUP "Collapse Level" POPUP "Collapse Level"

View File

@ -1977,16 +1977,27 @@ void Notepad_plus::command(int id)
break; break;
case IDM_VIEW_FOLD_CURRENT : case IDM_VIEW_FOLD_CURRENT:
case IDM_VIEW_UNFOLD_CURRENT : case IDM_VIEW_UNFOLD_CURRENT:
_pEditView->foldCurrentPos((id==IDM_VIEW_FOLD_CURRENT)?fold_collapse:fold_uncollapse); {
bool isToggleEnabled = NppParameters::getInstance().getNppGUI()._enableFoldCmdToggable;
bool mode = id == IDM_VIEW_FOLD_CURRENT ? fold_collapse : fold_uncollapse;
if (isToggleEnabled)
{
bool isFolded = _pEditView->isCurrentLineFolded();
mode = isFolded ? fold_uncollapse : fold_collapse;
}
_pEditView->foldCurrentPos(mode);
}
break; break;
case IDM_VIEW_TOGGLE_FOLDALL: case IDM_VIEW_FOLDALL:
case IDM_VIEW_TOGGLE_UNFOLDALL: case IDM_VIEW_UNFOLDALL:
{ {
_isFolding = true; // So we can ignore events while folding is taking place _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); _pEditView->foldAll(doCollapse);
if (_pDocMap) if (_pDocMap)
{ {
@ -3930,8 +3941,8 @@ void Notepad_plus::command(int id)
case IDM_VIEW_WRAP : case IDM_VIEW_WRAP :
case IDM_VIEW_FOLD_CURRENT : case IDM_VIEW_FOLD_CURRENT :
case IDM_VIEW_UNFOLD_CURRENT : case IDM_VIEW_UNFOLD_CURRENT :
case IDM_VIEW_TOGGLE_FOLDALL: case IDM_VIEW_FOLDALL:
case IDM_VIEW_TOGGLE_UNFOLDALL: case IDM_VIEW_UNFOLDALL:
case IDM_VIEW_FOLD_1: case IDM_VIEW_FOLD_1:
case IDM_VIEW_FOLD_2: case IDM_VIEW_FOLD_2:
case IDM_VIEW_FOLD_3: case IDM_VIEW_FOLD_3:

View File

@ -284,8 +284,8 @@ static const WinMenuKeyDefinition winKeyDefs[] =
{ VK_H, IDM_VIEW_HIDELINES, false, true, false, nullptr }, { VK_H, IDM_VIEW_HIDELINES, false, true, false, nullptr },
{ VK_F8, IDM_VIEW_SWITCHTO_OTHER_VIEW, false, false, 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_FOLDALL, false, true, false, nullptr },
{ VK_0, IDM_VIEW_TOGGLE_UNFOLDALL, false, true, true, nullptr }, { VK_0, IDM_VIEW_UNFOLDALL, false, true, true, nullptr },
{ VK_F, IDM_VIEW_FOLD_CURRENT, true, true, false, nullptr }, { VK_F, IDM_VIEW_FOLD_CURRENT, true, true, false, nullptr },
{ VK_F, IDM_VIEW_UNFOLD_CURRENT, true, true, true, nullptr }, { VK_F, IDM_VIEW_UNFOLD_CURRENT, true, true, true, nullptr },
{ VK_1, IDM_VIEW_FOLD_1, false, true, false, TEXT("Collapse Level 1") }, { 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")); const TCHAR * optMuteSounds = element->Attribute(TEXT("muteSounds"));
if (optMuteSounds) if (optMuteSounds)
_nppGUI._muteSounds = lstrcmp(optMuteSounds, TEXT("yes")) == 0; _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"))) 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("sortFunctionList"), _nppGUI._shouldSortFunctionList ? TEXT("yes") : TEXT("no"));
GUIConfigElement->SetAttribute(TEXT("saveDlgExtFilterToAllTypes"), _nppGUI._setSaveDlgExtFiltToAllTypes ? 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("muteSounds"), _nppGUI._muteSounds ? TEXT("yes") : TEXT("no"));
GUIConfigElement->SetAttribute(TEXT("enableFoldCmdToggable"), _nppGUI._enableFoldCmdToggable ? TEXT("yes") : TEXT("no"));
} }
// <GUIConfig name="Searching" "monospacedFontFindDlg"="no" stopFillingFindField="no" findDlgAlwaysVisible="no" confirmReplaceOpenDocs="yes" confirmMacroReplaceOpenDocs="yes" confirmReplaceInFiles="yes" confirmMacroReplaceInFiles="yes" replaceStopsWithoutFindingNext="no"/> // <GUIConfig name="Searching" "monospacedFontFindDlg"="no" stopFillingFindField="no" findDlgAlwaysVisible="no" confirmReplaceOpenDocs="yes" confirmMacroReplaceOpenDocs="yes" confirmReplaceInFiles="yes" confirmMacroReplaceInFiles="yes" replaceStopsWithoutFindingNext="no"/>

View File

@ -803,6 +803,7 @@ struct NppGUI final
bool _confirmReplaceInAllOpenDocs = true; bool _confirmReplaceInAllOpenDocs = true;
bool _replaceStopsWithoutFindingNext = false; bool _replaceStopsWithoutFindingNext = false;
bool _muteSounds = false; bool _muteSounds = false;
bool _enableFoldCmdToggable = false;
writeTechnologyEngine _writeTechnologyEngine = defaultTechnology; writeTechnologyEngine _writeTechnologyEngine = defaultTechnology;
bool _isWordCharDefault = true; bool _isWordCharDefault = true;
std::string _customWordChars; std::string _customWordChars;

View File

@ -2132,6 +2132,26 @@ void ScintillaEditView::foldCurrentPos(bool mode)
fold(currentLine, 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) void ScintillaEditView::fold(size_t line, bool mode)
{ {
auto endStyled = execute(SCI_GETENDSTYLED); auto endStyled = execute(SCI_GETENDSTYLED);

View File

@ -508,9 +508,10 @@ public:
void collapse(int level2Collapse, bool mode); void collapse(int level2Collapse, bool mode);
void foldAll(bool mode); void foldAll(bool mode);
void fold(size_t line, 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); return (execute(SCI_GETFOLDEXPANDED, line) != 0);
}; };
bool isCurrentLineFolded() const;
void foldCurrentPos(bool mode); void foldCurrentPos(bool mode);
int getCodepage() const {return _codepage;}; int getCodepage() const {return _codepage;};

View File

@ -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 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 LTEXT "1",IDC_CARETLINEFRAME_WIDTH_DISPLAY,396,67,12,8
CONTROL "Enable Multi-Editing (Ctrl+Mouse click/selection)",IDC_CHECK_MULTISELECTION, CONTROL "Make current line folding/unfolding commands togglable",IDC_CHECK_FOLDINGTOGGLE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,26,103,270,10
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,26,114,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 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 virtual space",IDC_CHECK_VIRTUALSPACE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,26,142,270,10
CONTROL "Enable scrolling beyond last line",IDC_CHECK_SCROLLBEYONDLASTLINE, CONTROL "Enable scrolling beyond last line",IDC_CHECK_SCROLLBEYONDLASTLINE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,26,155,270,10
"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 "Keep selection when right-click outside of selection",IDC_CHECK_RIGHTCLICKKEEPSSELECTION, CONTROL "Disable advanced scrolling feature due to touchpad issue",IDC_CHECK_DISABLEADVANCEDSCROLL,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,26,181,270,10
"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 END

View File

@ -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); ::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); ::SendDlgItemMessage(_hSelf, IDC_CHECK_MULTISELECTION, BM_SETCHECK, nppGUI._enableMultiSelection, 0);
::SendMessage(::GetDlgItem(_hSelf, IDC_CARETBLINKRATE_SLIDER),TBM_SETRANGEMIN, TRUE, BLINKRATE_FASTEST); ::SendMessage(::GetDlgItem(_hSelf, IDC_CARETBLINKRATE_SLIDER),TBM_SETRANGEMIN, TRUE, BLINKRATE_FASTEST);
@ -901,6 +902,10 @@ intptr_t CALLBACK EditingSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
case IDC_CHECK_MULTISELECTION : case IDC_CHECK_MULTISELECTION :
nppGUI._enableMultiSelection = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_CHECK_MULTISELECTION, BM_GETCHECK, 0, 0)); nppGUI._enableMultiSelection = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_CHECK_MULTISELECTION, BM_GETCHECK, 0, 0));
::SendMessage(::GetParent(_hParent), NPPM_INTERNAL_SETMULTISELCTION, 0, 0); ::SendMessage(::GetParent(_hParent), NPPM_INTERNAL_SETMULTISELCTION, 0, 0);
return TRUE;
case IDC_CHECK_FOLDINGTOGGLE:
nppGUI._enableFoldCmdToggable = isCheckedOrNot(IDC_CHECK_FOLDINGTOGGLE);
return TRUE; return TRUE;
case IDC_RADIO_LWDEF: case IDC_RADIO_LWDEF:

View File

@ -136,6 +136,8 @@
#define IDC_CHECK_VIRTUALSPACE (IDD_PREFERENCE_SUB_EDITING + 45) #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 IDD_PREFERENCE_SUB_DELIMITER 6250 //(IDD_PREFERENCE_BOX + 250)
#define IDC_DELIMITERSETTINGS_GB_STATIC (IDD_PREFERENCE_SUB_DELIMITER + 1) #define IDC_DELIMITERSETTINGS_GB_STATIC (IDD_PREFERENCE_SUB_DELIMITER + 1)

View File

@ -265,7 +265,7 @@
#define IDM_VIEW_DRAWTABBAR_TOPBAR (IDM_VIEW + 7) #define IDM_VIEW_DRAWTABBAR_TOPBAR (IDM_VIEW + 7)
#define IDM_VIEW_DRAWTABBAR_INACIVETAB (IDM_VIEW + 8) #define IDM_VIEW_DRAWTABBAR_INACIVETAB (IDM_VIEW + 8)
#define IDM_VIEW_POSTIT (IDM_VIEW + 9) #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_DISTRACTIONFREE (IDM_VIEW + 11)
#define IDM_VIEW_LINENUMBER (IDM_VIEW + 12) #define IDM_VIEW_LINENUMBER (IDM_VIEW + 12)
#define IDM_VIEW_SYMBOLMARGIN (IDM_VIEW + 13) #define IDM_VIEW_SYMBOLMARGIN (IDM_VIEW + 13)
@ -284,7 +284,7 @@
#define IDM_VIEW_EOL (IDM_VIEW + 26) #define IDM_VIEW_EOL (IDM_VIEW + 26)
#define IDM_VIEW_TOOLBAR_REDUCE_SET2 (IDM_VIEW + 27) #define IDM_VIEW_TOOLBAR_REDUCE_SET2 (IDM_VIEW + 27)
#define IDM_VIEW_TOOLBAR_ENLARGE_SET2 (IDM_VIEW + 28) #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_FOLD_CURRENT (IDM_VIEW + 30)
#define IDM_VIEW_UNFOLD_CURRENT (IDM_VIEW + 31) #define IDM_VIEW_UNFOLD_CURRENT (IDM_VIEW + 31)
#define IDM_VIEW_FULLSCREENTOGGLE (IDM_VIEW + 32) #define IDM_VIEW_FULLSCREENTOGGLE (IDM_VIEW + 32)