Skip to content

Commit

Permalink
Make fold/unfold current line commads togglable
Browse files Browse the repository at this point in the history
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
  • Loading branch information
donho committed May 21, 2022
1 parent e701c20 commit 05dae4a
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 24 deletions.
1 change: 1 addition & 0 deletions PowerEditor/src/Notepad_plus.cpp
Expand Up @@ -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.") },
Expand Down
4 changes: 2 additions & 2 deletions PowerEditor/src/Notepad_plus.rc
Expand Up @@ -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"
Expand Down
29 changes: 20 additions & 9 deletions PowerEditor/src/NppCommands.cpp
Expand Up @@ -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;

if (isToggleEnabled)
{
bool isFolded = _pEditView->isCurrentLineFolded();
mode = isFolded ? fold_uncollapse : fold_collapse;
}

_pEditView->foldCurrentPos(mode);
}
break;

case IDM_VIEW_TOGGLE_FOLDALL:
case IDM_VIEW_TOGGLE_UNFOLDALL:
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)
{
Expand Down Expand Up @@ -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:
Expand Down
9 changes: 7 additions & 2 deletions PowerEditor/src/Parameters.cpp
Expand Up @@ -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") },
Expand Down Expand Up @@ -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")))
{
Expand Down Expand Up @@ -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"));
}

// <GUIConfig name="Searching" "monospacedFontFindDlg"="no" stopFillingFindField="no" findDlgAlwaysVisible="no" confirmReplaceOpenDocs="yes" confirmMacroReplaceOpenDocs="yes" confirmReplaceInFiles="yes" confirmMacroReplaceInFiles="yes" replaceStopsWithoutFindingNext="no"/>
Expand Down
1 change: 1 addition & 0 deletions PowerEditor/src/Parameters.h
Expand Up @@ -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;
Expand Down
20 changes: 20 additions & 0 deletions PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion PowerEditor/src/ScintillaComponent/ScintillaEditView.h
Expand Up @@ -508,9 +508,10 @@ friend class Finder;
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;};

Expand Down
13 changes: 5 additions & 8 deletions PowerEditor/src/WinControls/Preference/preference.rc
Expand Up @@ -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


Expand Down
5 changes: 5 additions & 0 deletions PowerEditor/src/WinControls/Preference/preferenceDlg.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions PowerEditor/src/WinControls/Preference/preference_rc.h
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions PowerEditor/src/menuCmdID.h
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

6 comments on commit 05dae4a

@GOLEM777
Copy link
Contributor

@GOLEM777 GOLEM777 commented on 05dae4a May 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'm wrong, but there is one typo and one inaccuracy.

Make current line folding/unfolding commands togg**la**ble

must be

Make current level folding/unfolding commands toggleable


ps
Very lacking option Unhide All Lines and Inverse for IDM_VIEW_HIDELINES

@donho
Copy link
Member Author

@donho donho commented on 05dae4a May 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GOLEM777

must be
Make current level folding/unfolding commands toggleable

Done. Thank you for your heads up.

Very lacking option Unhide All Lines and Inverse for IDM_VIEW_HIDELINES

Sorry, I don't follow you. What do you mean exactly?

@GOLEM777
Copy link
Contributor

@GOLEM777 GOLEM777 commented on 05dae4a May 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@donho
This is an unpopular feature.
Simple function to hide (selected) lines! Alt+H
But, without the Unhide All feature or inverse, it's pointless.
You have to use your mouse for each line every time.
It's easier to just remove it feature.
ps
Sry for my bad english! ))
capture_05252022_212152

@donho
Copy link
Member Author

@donho donho commented on 05dae4a May 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GOLEM777
"Don't laugh at people who have accent when they speak your language - it mean they can speak another language that you can't."
No need to apology for your English. It's not my native language either - you can tell it by the typo :)

Please create a PR - I may consider to make it toggleable.

@alankilborn
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please create a PR - I may consider to make it toggleable.

You probably mean to create an "issue" in the form of a feature request.
But hidden lines as a feature needs much more work than simply and unhide all.
So perhaps @GOLEM777's request could be a general hidden lines feature improvement list.

@GOLEM777
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alankilborn
Thanks for info, I just mention this feature.
Its presence is logical (i about Unhide All). )))

It's easier to just remove it feature.

Due to lack of demand.

Please sign in to comment.