Skip to content

Commit

Permalink
Add hide/show ability of Control Characters (C0 & C1) and Unicode EOL
Browse files Browse the repository at this point in the history
Fix #8111, close #13324
  • Loading branch information
ozone10 authored and donho committed Apr 11, 2023
1 parent 81802e7 commit 0cad36d
Show file tree
Hide file tree
Showing 16 changed files with 355 additions and 146 deletions.
5 changes: 3 additions & 2 deletions PowerEditor/installer/nativeLang/english.xml
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ The comments are here for explanation, it's not necessary to translate them.
<Item id="44114" name="Apply Color 4"/>
<Item id="44115" name="Apply Color 5"/>
<Item id="44130" name="Show Non-Printing Characters"/>
<Item id="44131" name="Show Control Characters &amp; Unicode EOL"/>
<Item id="44032" name="Toggle Full Screen Mode"/>
<Item id="44033" name="Restore Default Zoom"/>
<Item id="44034" name="Always on Top"/>
Expand Down Expand Up @@ -956,6 +957,7 @@ The comments are here for explanation, it's not necessary to translate them.
<Item id="6254" name="Abbreviation"/>
<Item id="6255" name="Codepoint"/>
<Item id="6256" name="Custom Color"/>
<Item id="6258" name="Apply to C0, C1 &amp; Unicode EOL"/>

This comment has been minimized.

Copy link
@rddim

rddim Apr 12, 2023

Contributor

This string needs more room for Bulgarian localization. Sorry, I can not short it.
In Bulgarian it is Прилагане за C0, C1 и Unicode край на ред

Image-2023-04-12-22-11-23

</Scintillas>

<DarkMode title="Dark Mode">
Expand Down Expand Up @@ -1683,8 +1685,6 @@ NOTE:
<npcNote-tip value="Representation of selected &quot;non-ASCII&quot; whitespace and non-printing (control) characters.
NOTE:
Some characters might already have some representation and are thus visible. Line separator and paragraph separator are already represented by abbreviation by default.
Using representation will disable character effects on text.
For the full list of selected whitespace and non-printing characters check User Manual.
Expand All @@ -1707,6 +1707,7 @@ Click on &quot;?&quot; button on right to open website with User Manual." />

<!-- Don't translate "(&quot;Non-printing characters custom color&quot;)" -->
<npcCustomColor-tip value="Go to Style Configurator to change the default custom color for selected whitespace and non-printing characters (&quot;Non-printing characters custom color&quot;)." />
<npcIncludeCcUniEol-tip value="Apply non-printing characters appearance settings to C0, C1 control and Unicode EOL (next line, line separator and paragraph separator) characters." />
</MiscStrings>
</Native-Langue>
</NotepadPlus>
Expand Down
5 changes: 3 additions & 2 deletions PowerEditor/installer/nativeLang/english_customizable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ The comments are here for explanation, it's not necessary to translate them.
<Item id="44114" name="Apply Color 4"/>
<Item id="44115" name="Apply Color 5"/>
<Item id="44130" name="Show Non-Printing Characters"/>
<Item id="44131" name="Show Control Characters &amp; Unicode EOL"/>
<Item id="44032" name="Toggle Full Screen Mode"/>
<Item id="44033" name="Restore Default Zoom"/>
<Item id="44034" name="Always on Top"/>
Expand Down Expand Up @@ -951,6 +952,7 @@ The comments are here for explanation, it's not necessary to translate them.
<Item id="6254" name="Abbreviation"/>
<Item id="6255" name="Codepoint"/>
<Item id="6256" name="Custom Color"/>
<Item id="6258" name="Apply to C0, C1 &amp; Unicode EOL"/>
</Scintillas>

<DarkMode title="Dark Mode">
Expand Down Expand Up @@ -1672,8 +1674,6 @@ NOTE:
<npcNote-tip value="Representation of selected &quot;non-ASCII&quot; whitespace and non-printing (control) characters.
NOTE:
Some characters might already have some representation and are thus visible. Line separator and paragraph separator are already represented by abbreviation by default.
Using representation will disable character effects on text.
For the full list of selected whitespace and non-printing characters check User Manual.
Expand All @@ -1696,6 +1696,7 @@ Click on &quot;?&quot; button on right to open website with User Manual." />

<!-- Don't translate "(&quot;Non-printing characters custom color&quot;)" -->
<npcCustomColor-tip value="Go to Style Configurator to change the default custom color for selected whitespace and non-printing characters (&quot;Non-printing characters custom color&quot;)." />
<npcIncludeCcUniEol-tip value="Apply non-printing characters appearance settings to C0, C1 control and Unicode EOL (next line, line separator and paragraph separator) characters." />
</MiscStrings>
</Native-Langue>
</NotepadPlus>
Expand Down
10 changes: 9 additions & 1 deletion PowerEditor/src/Notepad_plus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4738,12 +4738,14 @@ void Notepad_plus::staticCheckMenuAndTB() const
const bool wsTabShow = _pEditView->isShownSpaceAndTab();
const bool eolShow = _pEditView->isShownEol();
const bool npcShow = _pEditView->isShownNpc();
const bool ccUniEolShow = _pEditView->isShownCcUniEol();

const bool allShow = wsTabShow && eolShow && npcShow;
const bool allShow = wsTabShow && eolShow && npcShow && ccUniEolShow;

checkMenuItem(IDM_VIEW_TAB_SPACE, wsTabShow);
checkMenuItem(IDM_VIEW_EOL, eolShow);
checkMenuItem(IDM_VIEW_NPC, npcShow);
checkMenuItem(IDM_VIEW_NPC_CCUNIEOL, ccUniEolShow);
checkMenuItem(IDM_VIEW_ALL_CHARACTERS, allShow);
_toolBar.setCheck(IDM_VIEW_ALL_CHARACTERS, allShow);

Expand Down Expand Up @@ -6340,6 +6342,12 @@ void Notepad_plus::notifyBufferChanged(Buffer * buffer, int mask)
setDisplayFormat(buffer->getEolFormat());
enableConvertMenuItems(buffer->getEolFormat());
}

if (mask & (BufferChangeUnicode))
{
_mainEditView.maintainStateForNpc();
_subEditView.maintainStateForNpc();
}
}

void Notepad_plus::notifyBufferActivated(BufferID bufid, int view)
Expand Down
13 changes: 7 additions & 6 deletions PowerEditor/src/Notepad_plus.rc
Original file line number Diff line number Diff line change
Expand Up @@ -668,13 +668,14 @@ BEGIN
MENUITEM SEPARATOR
POPUP "Show Symbol"
BEGIN
MENUITEM "Show Space and Tab", IDM_VIEW_TAB_SPACE
MENUITEM "Show End of Line", IDM_VIEW_EOL
MENUITEM "Show Non-Printing Characters", IDM_VIEW_NPC
MENUITEM "Show All Characters", IDM_VIEW_ALL_CHARACTERS
MENUITEM "Show Space and Tab", IDM_VIEW_TAB_SPACE
MENUITEM "Show End of Line", IDM_VIEW_EOL
MENUITEM "Show Non-Printing Characters", IDM_VIEW_NPC
MENUITEM "Show Control Characters && Unicode EOL", IDM_VIEW_NPC_CCUNIEOL
MENUITEM "Show All Characters", IDM_VIEW_ALL_CHARACTERS
MENUITEM SEPARATOR
MENUITEM "Show Indent Guide", IDM_VIEW_INDENT_GUIDE
MENUITEM "Show Wrap Symbol", IDM_VIEW_WRAP_SYMBOL
MENUITEM "Show Indent Guide", IDM_VIEW_INDENT_GUIDE
MENUITEM "Show Wrap Symbol", IDM_VIEW_WRAP_SYMBOL
END
POPUP "Zoom"
BEGIN
Expand Down
32 changes: 23 additions & 9 deletions PowerEditor/src/NppBigSwitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1759,10 +1759,23 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa

case NPPM_INTERNAL_SETNPC:
{
const bool isShown = nppParam.getSVP()._npcShow;
_mainEditView.showNpc(isShown);
_subEditView.showNpc(isShown);
_findReplaceDlg.updateFinderScintillaForNpc();
const auto& svp = nppParam.getSVP();
const bool isFromIncCcUniEolCtrl = wParam == IDC_CHECK_NPC_INCLUDECCUNIEOL;
if (isFromIncCcUniEolCtrl || svp._npcIncludeCcUniEol)
{
const bool isShown = svp._ccUniEolShow;
_mainEditView.showCcUniEol(isShown);
_subEditView.showCcUniEol(isShown);
}

if (!isFromIncCcUniEolCtrl)
{
const bool isShown = svp._npcShow;
_mainEditView.showNpc(isShown);
_subEditView.showNpc(isShown);
_findReplaceDlg.updateFinderScintillaForNpc();
}

return TRUE;
}

Expand Down Expand Up @@ -2945,14 +2958,15 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa

case NPPM_INTERNAL_NPCFORMCHANGED:
{
NppParameters& nppParam = NppParameters::getInstance();
const bool isShown = nppParam.getSVP()._npcShow;
if (isShown)
_mainEditView.setNpcAndCcUniEOL();
_subEditView.setNpcAndCcUniEOL();

const auto& svp = NppParameters::getInstance().getSVP();
if (svp._npcShow)
{
_mainEditView.setNPC();
_subEditView.setNPC();
_findReplaceDlg.updateFinderScintillaForNpc(true);
}

return TRUE;
}

Expand Down
77 changes: 42 additions & 35 deletions PowerEditor/src/NppCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2317,96 +2317,103 @@ void Notepad_plus::command(int id)

case IDM_VIEW_TAB_SPACE:
{
auto setCheckMenuItem = [this](int id, bool check) -> DWORD {
return ::CheckMenuItem(_mainMenuHandle, id, MF_BYCOMMAND | (check ? MF_CHECKED : MF_UNCHECKED));
};

const bool isChecked = !(::GetMenuState(_mainMenuHandle, id, MF_BYCOMMAND) == MF_CHECKED);
setCheckMenuItem(id, isChecked);
checkMenuItem(id, isChecked);

_mainEditView.showWSAndTab(isChecked);
_subEditView.showWSAndTab(isChecked);

auto& svp1 = const_cast<ScintillaViewParams&>(NppParameters::getInstance().getSVP());
svp1._whiteSpaceShow = isChecked;

const bool allChecked = svp1._whiteSpaceShow && svp1._eolShow && svp1._npcShow;
const bool allChecked = svp1._whiteSpaceShow && svp1._eolShow && svp1._npcShow && svp1._ccUniEolShow;

setCheckMenuItem(IDM_VIEW_ALL_CHARACTERS, allChecked);
checkMenuItem(IDM_VIEW_ALL_CHARACTERS, allChecked);
_toolBar.setCheck(IDM_VIEW_ALL_CHARACTERS, allChecked);

break;
}

case IDM_VIEW_EOL:
{
auto setCheckMenuItem = [this](int id, bool check) -> DWORD {
return ::CheckMenuItem(_mainMenuHandle, id, MF_BYCOMMAND | (check ? MF_CHECKED : MF_UNCHECKED));
};

const bool isChecked = !(::GetMenuState(_mainMenuHandle, id, MF_BYCOMMAND) == MF_CHECKED);
setCheckMenuItem(id, isChecked);
checkMenuItem(id, isChecked);

_mainEditView.showEOL(isChecked);
_subEditView.showEOL(isChecked);

auto& svp1 = const_cast<ScintillaViewParams&>(NppParameters::getInstance().getSVP());
svp1._eolShow = isChecked;

const bool allChecked = svp1._whiteSpaceShow && svp1._eolShow && svp1._npcShow;
const bool allChecked = svp1._whiteSpaceShow && svp1._eolShow && svp1._npcShow && svp1._ccUniEolShow;

setCheckMenuItem(IDM_VIEW_ALL_CHARACTERS, allChecked);
checkMenuItem(IDM_VIEW_ALL_CHARACTERS, allChecked);
_toolBar.setCheck(IDM_VIEW_ALL_CHARACTERS, allChecked);

break;
}

case IDM_VIEW_NPC:
{
auto setCheckMenuItem = [this](int id, bool check) -> DWORD {
return ::CheckMenuItem(_mainMenuHandle, id, MF_BYCOMMAND | (check ? MF_CHECKED : MF_UNCHECKED));
};

const bool isChecked = !(::GetMenuState(_mainMenuHandle, id, MF_BYCOMMAND) == MF_CHECKED);
setCheckMenuItem(id, isChecked);

_mainEditView.showNpc(isChecked);
_subEditView.showNpc(isChecked);
checkMenuItem(id, isChecked);

auto& svp1 = const_cast<ScintillaViewParams&>(NppParameters::getInstance().getSVP());
svp1._npcShow = isChecked;

const bool allChecked = svp1._whiteSpaceShow && svp1._eolShow && svp1._npcShow;
// setNpcAndCcUniEOL() in showNpc() uses svp1._npcShow
_mainEditView.showNpc(isChecked);
_subEditView.showNpc(isChecked);

const bool allChecked = svp1._whiteSpaceShow && svp1._eolShow && svp1._npcShow && svp1._ccUniEolShow;

setCheckMenuItem(IDM_VIEW_ALL_CHARACTERS, allChecked);
checkMenuItem(IDM_VIEW_ALL_CHARACTERS, allChecked);
_toolBar.setCheck(IDM_VIEW_ALL_CHARACTERS, allChecked);

_findReplaceDlg.updateFinderScintillaForNpc();

break;
}

case IDM_VIEW_ALL_CHARACTERS:
case IDM_VIEW_NPC_CCUNIEOL:
{
auto setCheckMenuItem = [this](int id, bool check) -> DWORD {
return ::CheckMenuItem(_mainMenuHandle, id, MF_BYCOMMAND | (check ? MF_CHECKED : MF_UNCHECKED));
};
const bool isChecked = !(::GetMenuState(_mainMenuHandle, id, MF_BYCOMMAND) == MF_CHECKED);
checkMenuItem(id, isChecked);

auto& svp1 = const_cast<ScintillaViewParams&>(NppParameters::getInstance().getSVP());
svp1._ccUniEolShow = isChecked;

// setNpcAndCcUniEOL() in showCcUniEol() uses svp1._ccUniEolShow
_mainEditView.showCcUniEol(isChecked);
_subEditView.showCcUniEol(isChecked);

const bool allChecked = svp1._whiteSpaceShow && svp1._eolShow && svp1._npcShow && svp1._ccUniEolShow;

checkMenuItem(IDM_VIEW_ALL_CHARACTERS, allChecked);
_toolBar.setCheck(IDM_VIEW_ALL_CHARACTERS, allChecked);

break;
}

case IDM_VIEW_ALL_CHARACTERS:
{
const bool isChecked = !(::GetMenuState(_mainMenuHandle, id, MF_BYCOMMAND) == MF_CHECKED);
setCheckMenuItem(id, isChecked);
setCheckMenuItem(IDM_VIEW_TAB_SPACE, isChecked);
setCheckMenuItem(IDM_VIEW_EOL, isChecked);
setCheckMenuItem(IDM_VIEW_NPC, isChecked);
checkMenuItem(id, isChecked);
checkMenuItem(IDM_VIEW_TAB_SPACE, isChecked);
checkMenuItem(IDM_VIEW_EOL, isChecked);
checkMenuItem(IDM_VIEW_NPC, isChecked);
checkMenuItem(IDM_VIEW_NPC_CCUNIEOL, isChecked);
_toolBar.setCheck(id, isChecked);

_mainEditView.showInvisibleChars(isChecked);
_subEditView.showInvisibleChars(isChecked);

auto& svp1 = const_cast<ScintillaViewParams&>(NppParameters::getInstance().getSVP());

svp1._whiteSpaceShow = isChecked;
svp1._eolShow = isChecked;
svp1._npcShow = isChecked;
svp1._ccUniEolShow = isChecked;

_mainEditView.showInvisibleChars(isChecked);
_subEditView.showInvisibleChars(isChecked);

_findReplaceDlg.updateFinderScintillaForNpc();

Expand Down
21 changes: 8 additions & 13 deletions PowerEditor/src/Parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ static const WinMenuKeyDefinition winKeyDefs[] =
{ VK_NULL, IDM_VIEW_EOL, false, false, false, nullptr },
{ VK_NULL, IDM_VIEW_ALL_CHARACTERS, false, false, false, nullptr },
{ VK_NULL, IDM_VIEW_NPC, false, false, false, nullptr },
{ VK_NULL, IDM_VIEW_NPC_CCUNIEOL, false, false, false, nullptr },
{ VK_NULL, IDM_VIEW_INDENT_GUIDE, false, false, false, nullptr },
{ VK_NULL, IDM_VIEW_WRAP_SYMBOL, false, false, false, nullptr },
// { VK_NULL, IDM_VIEW_ZOOMIN, false, false, false, nullptr },
Expand Down Expand Up @@ -5923,18 +5924,6 @@ void NppParameters::feedGUIParameters(TiXmlNode *node)
}
else if (!lstrcmp(nm, TEXT("DarkMode")))
{
auto parseYesNoBoolAttribute = [&element](const TCHAR* name, bool defaultValue = false)->bool {
const TCHAR* val = element->Attribute(name);
if (val)
{
if (!lstrcmp(val, TEXT("yes")))
return true;
else if (!lstrcmp(val, TEXT("no")))
return false;
}
return defaultValue;
};

_nppGUI._darkmode._isEnabled = parseYesNoBoolAttribute(TEXT("enable"));

//_nppGUI._darkmode._isEnabledPlugin = parseYesNoBoolAttribute(TEXT("enablePlugin", true));
Expand Down Expand Up @@ -6359,7 +6348,7 @@ void NppParameters::feedScintillaParam(TiXmlNode *node)
_svp._eolMode = static_cast<ScintillaViewParams::crlfMode>(val);
}

// Unicode non-printable characters visibility State
// Unicode control and ws characters visibility state
_svp._npcShow = parseShowHideBoolAttribute(TEXT("npcShow"), true);

nm = element->Attribute(TEXT("npcMode"), &val);
Expand All @@ -6370,6 +6359,10 @@ void NppParameters::feedScintillaParam(TiXmlNode *node)
}

_svp._npcCustomColor = parseYesNoBoolAttribute(TEXT("npcCustomColor"));
_svp._npcIncludeCcUniEol = parseYesNoBoolAttribute(TEXT("npcIncludeCcUniEOL"));

// C0, C1 control and Unicode EOL visibility state
_svp._ccUniEolShow = parseYesNoBoolAttribute(TEXT("ccShow"), true);

nm = element->Attribute(TEXT("borderWidth"), &val);
if (nm)
Expand Down Expand Up @@ -6676,6 +6669,8 @@ bool NppParameters::writeScintillaParams()
setShowHideBoolAttribute(TEXT("npcShow"), _svp._npcShow);
(scintNode->ToElement())->SetAttribute(TEXT("npcMode"), static_cast<int>(_svp._npcMode));
setYesNoBoolAttribute(TEXT("npcCustomColor"), _svp._npcCustomColor);
setYesNoBoolAttribute(TEXT("npcIncludeCcUniEOL"), _svp._npcIncludeCcUniEol);
setYesNoBoolAttribute(TEXT("ccShow"), _svp._ccUniEolShow);
(scintNode->ToElement())->SetAttribute(TEXT("borderWidth"), _svp._borderWidth);
(scintNode->ToElement())->SetAttribute(TEXT("smoothFont"), _svp._doSmoothFont ? TEXT("yes") : TEXT("no"));
(scintNode->ToElement())->SetAttribute(TEXT("paddingLeft"), _svp._paddingLeft);
Expand Down
2 changes: 2 additions & 0 deletions PowerEditor/src/Parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,8 @@ struct ScintillaViewParams
enum npcMode { identity = 0, abbreviation = 1, codepoint = 2 };
npcMode _npcMode = abbreviation;
bool _npcCustomColor = false;
bool _npcIncludeCcUniEol = false;
bool _ccUniEolShow = true;

int _borderWidth = 2;
bool _virtualSpace = false;
Expand Down
2 changes: 1 addition & 1 deletion PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4958,7 +4958,7 @@ void Finder::setFinderStyleForNpc(bool onlyColor)
}
else if (isShown)
{
_scintView.setNPC();
_scintView.setNpcAndCcUniEOL();
}
}

Expand Down
Loading

0 comments on commit 0cad36d

Please sign in to comment.