Skip to content

Commit

Permalink
Add smart highlighting extension to anothe view option
Browse files Browse the repository at this point in the history
Add new option to enable smat highlighting extension to anothe view,
while both views are visible side by side.
  • Loading branch information
donho committed Oct 28, 2016
1 parent a82d9f9 commit 3924190
Show file tree
Hide file tree
Showing 13 changed files with 186 additions and 90 deletions.
1 change: 1 addition & 0 deletions PowerEditor/installer/nativeLang/chinese.xml
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,7 @@
<Item id="6332" name="區別大小寫"/>
<Item id="6338" name="僅符合整個單字"/>
<Item id="6339" name="使用搜尋對話框的設定"/>
<Item id="6340" name="高亮度延伸至另一視窗"/>
<Item id="6329" name="高亮度顯示相契合的 xml/html 標示 (tag)"/>
<Item id="6327" name="啟動"/>
<Item id="6328" name="高亮度顯示屬性 (tag attributes)"/>
Expand Down
1 change: 1 addition & 0 deletions PowerEditor/installer/nativeLang/english.xml
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,7 @@
<Item id="6332" name="Match case"/>
<Item id="6338" name="Match whole word only"/>
<Item id="6339" name="Use Find dialog settings"/>
<Item id="6340" name="Highlight another view"/>
<Item id="6329" name="Highlight Matching Tags"/>
<Item id="6327" name="Enable"/>
<Item id="6328" name="Highlight tag attributes"/>
Expand Down
1 change: 1 addition & 0 deletions PowerEditor/installer/nativeLang/french.xml
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,7 @@
<Item id="6332" name="Case sensible"/>
<Item id="6338" name="Mot entier uniquement"/>
<Item id="6339" name="Utiliser les paramètres de Recherche"/>
<Item id="6340" name="Sur l'autre vue également"/>
<Item id="6329" name="Surligner les tags ouverture/fermeture"/>
<Item id="6327" name="Activer"/>
<Item id="6328" name="Les attributs de tag"/>
Expand Down
42 changes: 32 additions & 10 deletions PowerEditor/src/NppNotification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,21 @@
using namespace std;





// Only for 2 main Scintilla editors
BOOL Notepad_plus::notify(SCNotification *notification)
{
//Important, keep track of which element generated the message
bool isFromPrimary = (_mainEditView.getHSelf() == notification->nmhdr.hwndFrom || _mainDocTab.getHSelf() == notification->nmhdr.hwndFrom);
bool isFromSecondary = !isFromPrimary && (_subEditView.getHSelf() == notification->nmhdr.hwndFrom || _subDocTab.getHSelf() == notification->nmhdr.hwndFrom);
ScintillaEditView * notifyView = isFromPrimary?&_mainEditView:&_subEditView;

ScintillaEditView * notifyView = nullptr;
if (isFromPrimary)
notifyView = &_mainEditView;
else if (isFromSecondary)
notifyView = &_subEditView;
else
return FALSE;

DocTabView *notifyDocTab = isFromPrimary?&_mainDocTab:&_subDocTab;
TBHDR * tabNotification = (TBHDR*) notification;
switch (notification->nmhdr.code)
Expand Down Expand Up @@ -485,7 +491,10 @@ BOOL Notepad_plus::notify(SCNotification *notification)
_pEditView->marginClick(notification->position, notification->modifiers);
if (_pDocMap)
_pDocMap->fold(lineClick, _pEditView->isFolded(lineClick));
_smartHighlighter.highlightView(_pEditView);

ScintillaEditView * unfocusView = isFromPrimary ? &_subEditView : &_mainEditView;

_smartHighlighter.highlightView(_pEditView, unfocusView);
}
else if ((notification->margin == ScintillaEditView::_SC_MARGE_SYBOLE) && !notification->modifiers)
{
Expand Down Expand Up @@ -692,6 +701,7 @@ BOOL Notepad_plus::notify(SCNotification *notification)
case SCN_UPDATEUI:
{
NppParameters *nppParam = NppParameters::getInstance();
NppGUI & nppGui = const_cast<NppGUI &>(nppParam->getNppGUI());

// replacement for obsolete custom SCN_SCROLLED
if (notification->updated & SC_UPDATE_V_SCROLL)
Expand All @@ -705,13 +715,21 @@ BOOL Notepad_plus::notify(SCNotification *notification)
if (nppParam->_isFindReplacing)
break;

if (notification->nmhdr.hwndFrom != _pEditView->getHSelf())
if (notification->nmhdr.hwndFrom != _pEditView->getHSelf()) // notification come from unfocus view - both views ae visible
{
//ScintillaEditView * unfocusView = isFromPrimary ? &_subEditView : &_mainEditView;
if (nppGui._smartHiliteOnAnotherView &&
_pEditView->getCurrentBufferID() != notifyView->getCurrentBufferID())
{
TCHAR selectedText[1024];
_pEditView->getGenericSelectedText(selectedText, sizeof(selectedText)/sizeof(TCHAR), false);
_smartHighlighter.highlightViewWithWord(notifyView, selectedText);
}
break;
}

braceMatch();

NppGUI & nppGui = const_cast<NppGUI &>(nppParam->getNppGUI());

if (nppGui._enableTagsMatchHilite)
{
XmlMatchedTagsHighlighter xmlTagMatchHiliter(_pEditView);
Expand All @@ -723,7 +741,10 @@ BOOL Notepad_plus::notify(SCNotification *notification)
if (nppGui._disableSmartHiliteTmp)
nppGui._disableSmartHiliteTmp = false;
else
_smartHighlighter.highlightView(notifyView);
{
ScintillaEditView * anbotherView = isFromPrimary ? &_subEditView : &_mainEditView;
_smartHighlighter.highlightView(notifyView, anbotherView);
}
}

updateStatusBar();
Expand Down Expand Up @@ -799,7 +820,8 @@ BOOL Notepad_plus::notify(SCNotification *notification)

case SCN_ZOOM:
{
_smartHighlighter.highlightView(notifyView);
ScintillaEditView * unfocusView = isFromPrimary ? &_subEditView : &_mainEditView;
_smartHighlighter.highlightView(notifyView, unfocusView);
break;
}

Expand Down
12 changes: 11 additions & 1 deletion PowerEditor/src/Parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4031,6 +4031,15 @@ void NppParameters::feedGUIParameters(TiXmlNode *node)
else if (!lstrcmp(val, TEXT("no")))
_nppGUI._smartHiliteUseFindSettings = false;
}

val = element->Attribute(TEXT("onAnotherView"));
if (val)
{
if (!lstrcmp(val, TEXT("yes")))
_nppGUI._smartHiliteOnAnotherView = true;
else if (!lstrcmp(val, TEXT("no")))
_nppGUI._smartHiliteOnAnotherView = false;
}
}
}

Expand Down Expand Up @@ -5438,12 +5447,13 @@ void NppParameters::createXmlTreeFromGUIParams()
GUIConfigElement->SetAttribute(TEXT("searchEngineCustom"), _nppGUI._searchEngineCustom);
}

// <GUIConfig name="SmartHighLight" matchCase="no" wholeWordOnly="yes" useFindSettings="no">yes</GUIConfig>
// <GUIConfig name="SmartHighLight" matchCase="no" wholeWordOnly="yes" useFindSettings="no" onAnotherView="no">yes</GUIConfig>
{
TiXmlElement *GUIConfigElement = insertGUIConfigBoolNode(newGUIRoot, TEXT("SmartHighLight"), _nppGUI._enableSmartHilite);
GUIConfigElement->SetAttribute(TEXT("matchCase"), _nppGUI._smartHiliteCaseSensitive ? TEXT("yes") : TEXT("no"));
GUIConfigElement->SetAttribute(TEXT("wholeWordOnly"), _nppGUI._smartHiliteWordOnly ? TEXT("yes") : TEXT("no"));
GUIConfigElement->SetAttribute(TEXT("useFindSettings"), _nppGUI._smartHiliteUseFindSettings ? TEXT("yes") : TEXT("no"));
GUIConfigElement->SetAttribute(TEXT("onAnotherView"), _nppGUI._smartHiliteOnAnotherView ? TEXT("yes") : TEXT("no"));
}

// <GUIConfig name="ScintillaPrimaryView" lineNumberMargin="show" bookMarkMargin="show" indentGuideLine="show" folderMarkStyle="box" lineWrapMethod="aligned" currentLineHilitingShow="show" scrollBeyondLastLine="no" disableAdvancedScrolling="no" wrapSymbolShow="hide" Wrap="no" borderEdge="yes" edge="no" edgeNbColumn="80" zoom="0" zoom2="0" whiteSpaceShow="hide" eolShow="hide" borderWidth="2" smoothFont="no" />
Expand Down
1 change: 1 addition & 0 deletions PowerEditor/src/Parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,7 @@ struct NppGUI final
bool _smartHiliteCaseSensitive = false;
bool _smartHiliteWordOnly = true;
bool _smartHiliteUseFindSettings = false;
bool _smartHiliteOnAnotherView = false;

bool _disableSmartHiliteTmp = false;
bool _enableTagsMatchHilite = true;
Expand Down
60 changes: 32 additions & 28 deletions PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1631,14 +1631,18 @@ int FindReplaceDlg::processAll(ProcessOperation op, const FindOption *opt, bool
return processRange(op, findReplaceInfo, pFindersInfo, pOptions, colourStyleID);
}

int FindReplaceDlg::processRange(ProcessOperation op, FindReplaceInfo & findReplaceInfo, const FindersInfo * pFindersInfo, const FindOption *opt, int colourStyleID)
int FindReplaceDlg::processRange(ProcessOperation op, FindReplaceInfo & findReplaceInfo, const FindersInfo * pFindersInfo, const FindOption *opt, int colourStyleID, ScintillaEditView *view2Process)
{
int nbProcessed = 0;

if (!isCreated() && not findReplaceInfo._txt2find)
return nbProcessed;

if ((op == ProcessReplaceAll) && (*_ppEditView)->getCurrentBuffer()->isReadOnly())
ScintillaEditView *pEditView = *_ppEditView;
if (view2Process)
pEditView = view2Process;

if ((op == ProcessReplaceAll) && pEditView->getCurrentBuffer()->isReadOnly())
return nbProcessed;

if (findReplaceInfo._startRange == findReplaceInfo._endRange)
Expand Down Expand Up @@ -1710,30 +1714,30 @@ int FindReplaceDlg::processRange(ProcessOperation op, FindReplaceInfo & findRepl
if (op == ProcessMarkAll && colourStyleID == -1) //if marking, check if purging is needed
{
if (_env->_doPurge) {
(*_ppEditView)->clearIndicator(SCE_UNIVERSAL_FOUND_STYLE);
pEditView->clearIndicator(SCE_UNIVERSAL_FOUND_STYLE);
if (_env->_doMarkLine)
(*_ppEditView)->execute(SCI_MARKERDELETEALL, MARK_BOOKMARK);
pEditView->execute(SCI_MARKERDELETEALL, MARK_BOOKMARK);
}
}

int targetStart = 0;
int targetEnd = 0;

//Initial range for searching
(*_ppEditView)->execute(SCI_SETSEARCHFLAGS, flags);
pEditView->execute(SCI_SETSEARCHFLAGS, flags);


bool findAllFileNameAdded = false;

while (targetStart != -1 && targetStart != -2)
{
targetStart = (*_ppEditView)->searchInTarget(pTextFind, stringSizeFind, findReplaceInfo._startRange, findReplaceInfo._endRange);
targetStart = pEditView->searchInTarget(pTextFind, stringSizeFind, findReplaceInfo._startRange, findReplaceInfo._endRange);

// If we've not found anything, just break out of the loop
if (targetStart == -1 || targetStart == -2)
break;

targetEnd = int((*_ppEditView)->execute(SCI_GETTARGETEND));
targetEnd = int(pEditView->execute(SCI_GETTARGETEND));

if (targetEnd > findReplaceInfo._endRange) { //we found a result but outside our range, therefore do not process it
break;
Expand All @@ -1757,9 +1761,9 @@ int FindReplaceDlg::processRange(ProcessOperation op, FindReplaceInfo & findRepl
findAllFileNameAdded = true;
}

auto lineNumber = (*_ppEditView)->execute(SCI_LINEFROMPOSITION, targetStart);
int lend = static_cast<int32_t>((*_ppEditView)->execute(SCI_GETLINEENDPOSITION, lineNumber));
int lstart = static_cast<int32_t>((*_ppEditView)->execute(SCI_POSITIONFROMLINE, lineNumber));
auto lineNumber = pEditView->execute(SCI_LINEFROMPOSITION, targetStart);
int lend = static_cast<int32_t>(pEditView->execute(SCI_GETLINEENDPOSITION, lineNumber));
int lstart = static_cast<int32_t>(pEditView->execute(SCI_POSITIONFROMLINE, lineNumber));
int nbChar = lend - lstart;

// use the static buffer
Expand All @@ -1771,7 +1775,7 @@ int FindReplaceDlg::processRange(ProcessOperation op, FindReplaceInfo & findRepl
int start_mark = targetStart - lstart;
int end_mark = targetEnd - lstart;

(*_ppEditView)->getGenericText(lineBuf, 1024, lstart, lend, &start_mark, &end_mark);
pEditView->getGenericText(lineBuf, 1024, lstart, lend, &start_mark, &end_mark);

generic_string line = lineBuf;
line += TEXT("\r\n");
Expand All @@ -1796,9 +1800,9 @@ int FindReplaceDlg::processRange(ProcessOperation op, FindReplaceInfo & findRepl
findAllFileNameAdded = true;
}

auto lineNumber = (*_ppEditView)->execute(SCI_LINEFROMPOSITION, targetStart);
int lend = static_cast<int32_t>((*_ppEditView)->execute(SCI_GETLINEENDPOSITION, lineNumber));
int lstart = static_cast<int32_t>((*_ppEditView)->execute(SCI_POSITIONFROMLINE, lineNumber));
auto lineNumber = pEditView->execute(SCI_LINEFROMPOSITION, targetStart);
int lend = static_cast<int32_t>(pEditView->execute(SCI_GETLINEENDPOSITION, lineNumber));
int lstart = static_cast<int32_t>(pEditView->execute(SCI_POSITIONFROMLINE, lineNumber));
int nbChar = lend - lstart;

// use the static buffer
Expand All @@ -1810,7 +1814,7 @@ int FindReplaceDlg::processRange(ProcessOperation op, FindReplaceInfo & findRepl
int start_mark = targetStart - lstart;
int end_mark = targetEnd - lstart;

(*_ppEditView)->getGenericText(lineBuf, 1024, lstart, lend, &start_mark, &end_mark);
pEditView->getGenericText(lineBuf, 1024, lstart, lend, &start_mark, &end_mark);

generic_string line = lineBuf;
line += TEXT("\r\n");
Expand All @@ -1834,9 +1838,9 @@ int FindReplaceDlg::processRange(ProcessOperation op, FindReplaceInfo & findRepl
{
int replacedLength;
if (isRegExp)
replacedLength = (*_ppEditView)->replaceTargetRegExMode(pTextReplace);
replacedLength = pEditView->replaceTargetRegExMode(pTextReplace);
else
replacedLength = (*_ppEditView)->replaceTarget(pTextReplace);
replacedLength = pEditView->replaceTarget(pTextReplace);

replaceDelta = replacedLength - foundTextLen;
break;
Expand All @@ -1850,17 +1854,17 @@ int FindReplaceDlg::processRange(ProcessOperation op, FindReplaceInfo & findRepl
// on the same line would simply not be shown. This may have been fixed in later version of Scintilla.
if (foundTextLen > 0)
{
(*_ppEditView)->execute(SCI_SETINDICATORCURRENT, SCE_UNIVERSAL_FOUND_STYLE);
(*_ppEditView)->execute(SCI_INDICATORFILLRANGE, targetStart, foundTextLen);
pEditView->execute(SCI_SETINDICATORCURRENT, SCE_UNIVERSAL_FOUND_STYLE);
pEditView->execute(SCI_INDICATORFILLRANGE, targetStart, foundTextLen);
}

if (_env->_doMarkLine)
{
auto lineNumber = (*_ppEditView)->execute(SCI_LINEFROMPOSITION, targetStart);
auto state = (*_ppEditView)->execute(SCI_MARKERGET, lineNumber);
auto lineNumber = pEditView->execute(SCI_LINEFROMPOSITION, targetStart);
auto state = pEditView->execute(SCI_MARKERGET, lineNumber);

if (!(state & (1 << MARK_BOOKMARK)))
(*_ppEditView)->execute(SCI_MARKERADD, lineNumber, MARK_BOOKMARK);
pEditView->execute(SCI_MARKERADD, lineNumber, MARK_BOOKMARK);
}
break;
}
Expand All @@ -1870,8 +1874,8 @@ int FindReplaceDlg::processRange(ProcessOperation op, FindReplaceInfo & findRepl
// See comment by ProcessMarkAll
if (foundTextLen > 0)
{
(*_ppEditView)->execute(SCI_SETINDICATORCURRENT, colourStyleID);
(*_ppEditView)->execute(SCI_INDICATORFILLRANGE, targetStart, foundTextLen);
pEditView->execute(SCI_SETINDICATORCURRENT, colourStyleID);
pEditView->execute(SCI_INDICATORFILLRANGE, targetStart, foundTextLen);
}
break;
}
Expand All @@ -1881,8 +1885,8 @@ int FindReplaceDlg::processRange(ProcessOperation op, FindReplaceInfo & findRepl
// See comment by ProcessMarkAll
if (foundTextLen > 0)
{
(*_ppEditView)->execute(SCI_SETINDICATORCURRENT, SCE_UNIVERSAL_FOUND_STYLE_SMART);
(*_ppEditView)->execute(SCI_INDICATORFILLRANGE, targetStart, foundTextLen);
pEditView->execute(SCI_SETINDICATORCURRENT, SCE_UNIVERSAL_FOUND_STYLE_SMART);
pEditView->execute(SCI_INDICATORFILLRANGE, targetStart, foundTextLen);
}
break;
}
Expand All @@ -1892,8 +1896,8 @@ int FindReplaceDlg::processRange(ProcessOperation op, FindReplaceInfo & findRepl
// See comment by ProcessMarkAll
if (foundTextLen > 0)
{
(*_ppEditView)->execute(SCI_SETINDICATORCURRENT, SCE_UNIVERSAL_FOUND_STYLE_INC);
(*_ppEditView)->execute(SCI_INDICATORFILLRANGE, targetStart, foundTextLen);
pEditView->execute(SCI_SETINDICATORCURRENT, SCE_UNIVERSAL_FOUND_STYLE_INC);
pEditView->execute(SCI_INDICATORFILLRANGE, targetStart, foundTextLen);
}
break;
}
Expand Down
2 changes: 1 addition & 1 deletion PowerEditor/src/ScitillaComponent/FindReplaceDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public :


int processAll(ProcessOperation op, const FindOption *opt, bool isEntire = false, const FindersInfo *pFindersInfo = nullptr, int colourStyleID = -1);
int processRange(ProcessOperation op, FindReplaceInfo & findReplaceInfo, const FindersInfo *pFindersInfo, const FindOption *opt = NULL, int colourStyleID = -1);
int processRange(ProcessOperation op, FindReplaceInfo & findReplaceInfo, const FindersInfo *pFindersInfo, const FindOption *opt = nullptr, int colourStyleID = -1, ScintillaEditView *view2Process = nullptr);

void replaceAllInOpenedDocs();
void findAllIn(InWhat op);
Expand Down
Loading

0 comments on commit 3924190

Please sign in to comment.