From 42cfe9041150bb3601cc63aa28b624c5b86b2b52 Mon Sep 17 00:00:00 2001 From: donho Date: Mon, 21 Jul 2008 01:39:28 +0000 Subject: [PATCH] [NEW] URL highlighter highlights only the current view, it highlights : http, https, ftp and malto. git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository@298 f5eea248-9336-0410-98b8-ebc06183d4e3 --- PowerEditor/src/Notepad_plus.cpp | 192 ++++-------------- PowerEditor/src/Notepad_plus.h | 7 +- .../ScitillaComponent/ScintillaEditView.cpp | 5 + PowerEditor/src/langs.model.xml | 2 +- PowerEditor/visual.net/notepadPlus.vcproj | 8 + scintilla/src/Editor.cxx | 7 +- scintilla/src/Editor.h | 2 +- 7 files changed, 56 insertions(+), 167 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index f7c143449..9ceaafdba 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -42,7 +42,6 @@ #include "xmlMatchedTagsHighlighter.h" const char Notepad_plus::_className[32] = NOTEPAD_PP_CLASS_NAME; -const char *urlHttpRegExpr = "http://[a-z0-9_\\-\\+.:?&@=/%#]*"; int docTabIconIDs[] = {IDI_SAVED_ICON, IDI_UNSAVED_ICON, IDI_READONLY_ICON}; enum tb_stat {tb_saved, tb_unsaved, tb_ro}; @@ -72,8 +71,8 @@ struct SortTaskListPred Notepad_plus::Notepad_plus(): Window(), _mainWindowStatus(0), _pDocTab(NULL), _pEditView(NULL), _pMainSplitter(NULL), _isfullScreen(false), _recordingMacro(false), _pTrayIco(NULL), _isUDDocked(false), _isRTL(false), - _linkTriggered(true), _isDocModifing(false), _isHotspotDblClicked(false), _sysMenuEntering(false), - _autoCompleteMain(&_mainEditView), _autoCompleteSub(&_subEditView), _smartHighlighter(&_findReplaceDlg) + _isHotspotDblClicked(false), _isLinkTriggered(false), _sysMenuEntering(false), _smartHighlighter(&_findReplaceDlg), + _urlHighlighter(&_findReplaceDlg), _autoCompleteMain(&_mainEditView), _autoCompleteSub(&_subEditView) { ZeroMemory(&_prevSelectedRange, sizeof(_prevSelectedRange)); @@ -685,8 +684,6 @@ BufferID Notepad_plus::doOpen(const char *fileName, bool isReadOnly) } } PathRemoveFileSpec(longFileName); - _linkTriggered = true; - _isDocModifing = false; // Notify plugins that current file is just opened scnN.nmhdr.code = NPPN_FILEOPENED; @@ -1803,20 +1800,22 @@ BOOL Notepad_plus::notify(SCNotification *notification) if (notification->modificationType & (SC_MOD_DELETETEXT | SC_MOD_INSERTTEXT)) { prevWasEdit = true; - _linkTriggered = true; - _isDocModifing = true; + _isLinkTriggered = true; ::InvalidateRect(notifyView->getHSelf(), NULL, TRUE); } + if (notification->modificationType & (SC_MOD_CHANGESTYLE)) + { + _isLinkTriggered = true; + } if (notification->modificationType & SC_MOD_CHANGEFOLD) { - if (prevWasEdit) { - notifyView->foldChanged(notification->line, - notification->foldLevelNow, notification->foldLevelPrev); + if (prevWasEdit) + { + notifyView->foldChanged(notification->line, notification->foldLevelNow, notification->foldLevelPrev); prevWasEdit = false; } } - else - if (!(notification->modificationType & (SC_MOD_DELETETEXT | SC_MOD_INSERTTEXT))) + else if (!(notification->modificationType & (SC_MOD_DELETETEXT | SC_MOD_INSERTTEXT))) { prevWasEdit = false; } @@ -2206,7 +2205,10 @@ BOOL Notepad_plus::notify(SCNotification *notification) case SCN_DOUBLECLICK : { - if (_isHotspotDblClicked) + int pos = notifyView->execute(SCI_GETCURRENTPOS); + int idStyle = notifyView->execute(SCI_GETSTYLEAT, pos); + bool isHotspot = notifyView->execute(SCI_STYLEGETHOTSPOT, idStyle) != 0; + if (isHotspot) { int pos = notifyView->execute(SCI_GETCURRENTPOS); notifyView->execute(SCI_SETCURRENTPOS, pos); @@ -2227,6 +2229,7 @@ BOOL Notepad_plus::notify(SCNotification *notification) xmlTagMatchHiliter.tagMatch(nppGUI._enableTagAttrsHilite); } _smartHighlighter.highlightView(notifyView); + updateStatusBar(); AutoCompletion * autoC = isFromPrimary?&_autoCompleteMain:&_autoCompleteSub; autoC->update(0); @@ -2235,7 +2238,11 @@ BOOL Notepad_plus::notify(SCNotification *notification) case SCN_SCROLLED: { - _smartHighlighter.highlightView(notifyView); + if (notification->wParam) //scrolling vertically + { + _smartHighlighter.highlightView(notifyView); + _urlHighlighter.highlightView(notifyView); + } break; } @@ -2287,17 +2294,13 @@ BOOL Notepad_plus::notify(SCNotification *notification) case SCN_PAINTED: { - if (_syncInfo.doSync()) - doSynScorll(HWND(notification->nmhdr.hwndFrom)); - - if (_linkTriggered) + if (_isLinkTriggered) { - int urlAction = (NppParameters::getInstance())->getNppGUI()._styleURL; - if ((urlAction == 1) || (urlAction == 2)) - addHotSpot(_isDocModifing); - _linkTriggered = false; - _isDocModifing = false; + _urlHighlighter.highlightView(notifyView); + _isLinkTriggered = false; } + if (_syncInfo.doSync()) + doSynScorll(HWND(notification->nmhdr.hwndFrom)); break; } @@ -2312,19 +2315,22 @@ BOOL Notepad_plus::notify(SCNotification *notification) notifyView->execute(SCI_SETTARGETSTART, startPos); notifyView->execute(SCI_SETTARGETEND, endPos); - int posFound = notifyView->execute(SCI_SEARCHINTARGET, strlen(urlHttpRegExpr), (LPARAM)urlHttpRegExpr); + /*int posFound = notifyView->execute(SCI_SEARCHINTARGET, strlen(urlHttpRegExpr), (LPARAM)urlHttpRegExpr); if (posFound != -1) { startPos = int(notifyView->execute(SCI_GETTARGETSTART)); endPos = int(notifyView->execute(SCI_GETTARGETEND)); - } + }*/ - char currentWord[MAX_PATH*2]; + int length = endPos-startPos+1; + char * currentWord = new char[length]; notifyView->getText(currentWord, startPos, endPos); ::ShellExecute(_hSelf, "open", currentWord, NULL, NULL, SW_SHOW); - _isHotspotDblClicked = true; + //Disabled: This message comes after SCN_DOUBLECLICK, so this method fails and prevents the next doubleclick from working + //_isHotspotDblClicked = true; notifyView->execute(SCI_SETCHARSDEFAULT); + delete [] currentWord; break; } @@ -2451,133 +2457,6 @@ void Notepad_plus::charAdded(char chAdded) MaintainIndentation(chAdded); } -void Notepad_plus::addHotSpot(bool docIsModifing) -{ - //bool docIsModifing = true; - int posBegin2style = 0; - if (docIsModifing) - posBegin2style = _pEditView->execute(SCI_GETCURRENTPOS); - - int endStyle = _pEditView->execute(SCI_GETENDSTYLED); - if (docIsModifing) - { - - posBegin2style = _pEditView->execute(SCI_GETCURRENTPOS); - if (posBegin2style > 0) posBegin2style--; - unsigned char ch = (unsigned char)_pEditView->execute(SCI_GETCHARAT, posBegin2style); - - // determinating the type of EOF to make sure how many steps should we be back - if ((ch == 0x0A) || (ch == 0x0D)) - { - int eolMode = _pEditView->execute(SCI_GETEOLMODE); - - if ((eolMode == SC_EOL_CRLF) && (posBegin2style > 1)) - posBegin2style -= 2; - else if (posBegin2style > 0) - posBegin2style -= 1; - } - - ch = (unsigned char)_pEditView->execute(SCI_GETCHARAT, posBegin2style); - while ((posBegin2style > 0) && ((ch != 0x0A) && (ch != 0x0D))) - { - ch = (unsigned char)_pEditView->execute(SCI_GETCHARAT, posBegin2style--); - } - } - int style_hotspot = 30; - - int startPos = 0; - int endPos = _pEditView->execute(SCI_GETTEXTLENGTH); - - _pEditView->execute(SCI_SETSEARCHFLAGS, SCFIND_REGEXP|SCFIND_POSIX); - - _pEditView->execute(SCI_SETTARGETSTART, startPos); - _pEditView->execute(SCI_SETTARGETEND, endPos); - - vector > hotspotStylers; - - int posFound = _pEditView->execute(SCI_SEARCHINTARGET, strlen(urlHttpRegExpr), (LPARAM)urlHttpRegExpr); - - while (posFound != -1) - { - int start = int(_pEditView->execute(SCI_GETTARGETSTART)); - int end = int(_pEditView->execute(SCI_GETTARGETEND)); - int foundTextLen = end - start; - int idStyle = _pEditView->execute(SCI_GETSTYLEAT, posFound); - - if (end < posBegin2style - 1) - { - if (style_hotspot > 1) - style_hotspot--; - } - else - { - int fs = -1; - for (size_t i = 0 ; i < hotspotStylers.size() ; i++) - { - if (hotspotStylers[i].second == idStyle) - { - fs = hotspotStylers[i].first; - break; - } - } - - if (fs != -1) - { - _pEditView->execute(SCI_STARTSTYLING, start, 0xFF); - _pEditView->execute(SCI_SETSTYLING, foundTextLen, fs); - - } - else - { - pair p(style_hotspot, idStyle); - hotspotStylers.push_back(p); - int activeFG = 0xFF0000; - - char fontName[256]; - Style hotspotStyle; - - hotspotStyle._styleID = style_hotspot; - _pEditView->execute(SCI_STYLEGETFONT, idStyle, (LPARAM)fontName); - hotspotStyle._fgColor = _pEditView->execute(SCI_STYLEGETFORE, idStyle); - hotspotStyle._bgColor = _pEditView->execute(SCI_STYLEGETBACK, idStyle); - hotspotStyle._fontSize = _pEditView->execute(SCI_STYLEGETSIZE, idStyle); - - int isBold = _pEditView->execute(SCI_STYLEGETBOLD, idStyle); - int isItalic = _pEditView->execute(SCI_STYLEGETITALIC, idStyle); - int isUnderline = _pEditView->execute(SCI_STYLEGETUNDERLINE, idStyle); - hotspotStyle._fontStyle = (isBold?FONTSTYLE_BOLD:0) | (isItalic?FONTSTYLE_ITALIC:0) | (isUnderline?FONTSTYLE_UNDERLINE:0); - - int fontStyle = (isBold?FONTSTYLE_BOLD:0) | (isItalic?FONTSTYLE_ITALIC:0) | (isUnderline?FONTSTYLE_UNDERLINE:0); - int urlAction = (NppParameters::getInstance())->getNppGUI()._styleURL; - if (urlAction == 2) - hotspotStyle._fontStyle |= FONTSTYLE_UNDERLINE; - - _pEditView->setStyle(hotspotStyle); - - _pEditView->execute(SCI_STYLESETHOTSPOT, style_hotspot, TRUE); - _pEditView->execute(SCI_SETHOTSPOTACTIVEFORE, TRUE, activeFG); - _pEditView->execute(SCI_SETHOTSPOTSINGLELINE, style_hotspot, 0); - _pEditView->execute(SCI_STARTSTYLING, start, 0x1F); - _pEditView->execute(SCI_SETSTYLING, foundTextLen, style_hotspot); - if (style_hotspot > 1) - style_hotspot--; - } - } - - _pEditView->execute(SCI_SETTARGETSTART, posFound + foundTextLen); - _pEditView->execute(SCI_SETTARGETEND, endPos); - - - posFound = _pEditView->execute(SCI_SEARCHINTARGET, strlen(urlHttpRegExpr), (LPARAM)urlHttpRegExpr); - } - - - _pEditView->execute(SCI_STARTSTYLING, endStyle, 0xFF); - _pEditView->execute(SCI_SETSTYLING, 0, 0); -} - - - void Notepad_plus::MaintainIndentation(char ch) { int eolMode = int(_pEditView->execute(SCI_GETEOLMODE)); @@ -3987,7 +3866,6 @@ void Notepad_plus::command(int id) tld.doDialog(); } } - _linkTriggered = true; } break; @@ -6655,7 +6533,6 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa nbDoc += viewVisible(SUB_VIEW)?_subDocTab.nbItem():0; if (nbDoc > 1) activateNextDoc((GET_APPCOMMAND_LPARAM(lParam) == APPCOMMAND_BROWSER_FORWARD)?dirDown:dirUp); - _linkTriggered = true; } return ::DefWindowProc(hwnd, Message, wParam, lParam); } @@ -8204,10 +8081,9 @@ void Notepad_plus::notifyBufferActivated(BufferID bufid, int view) { setWorkingDir(dir); setTitle(); //Make sure the colors of the tab controls match + _isLinkTriggered = true; ::InvalidateRect(_mainDocTab.getHSelf(), NULL, FALSE); ::InvalidateRect(_subDocTab.getHSelf(), NULL, FALSE); - - _linkTriggered = true; } void Notepad_plus::loadCommandlineParams(const char * commandLine, CmdLineParams * pCmdParams) { diff --git a/PowerEditor/src/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h index 63adf06bd..3eedb9870 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -49,6 +49,7 @@ #include "AutoCompletion.h" #include "Buffer.h" #include "SmartHighlighter.h" +#include "UrlHighlighter.h" #define NOTEPAD_PP_CLASS_NAME "Notepad++" @@ -199,6 +200,7 @@ private: AutoCompletion _autoCompleteSub; //each Scintilla has its own autoComplete SmartHighlighter _smartHighlighter; + UrlHighlighter _urlHighlighter; TiXmlNode *_nativeLang, *_toolIcons; @@ -263,9 +265,8 @@ private: RunMacroDlg _runMacroDlg; // For hotspot - bool _linkTriggered; - bool _isDocModifing; bool _isHotspotDblClicked; + bool _isLinkTriggered; //For Dynamic selection highlight CharacterRange _prevSelectedRange; @@ -526,8 +527,6 @@ private: void charAdded(char chAdded); void MaintainIndentation(char ch); - void addHotSpot(bool docIsModifing = false); - void bookmarkAdd(int lineno) const { if (lineno == -1) lineno = _pEditView->getCurrentLineNumber(); diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp index 480cb9ee6..91581b6de 100644 --- a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp +++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp @@ -187,6 +187,11 @@ void ScintillaEditView::init(HINSTANCE hInst, HWND hPere) execute(SCI_INDICSETUNDER, SCE_UNIVERSAL_TAGMATCH, true); execute(SCI_INDICSETUNDER, SCE_UNIVERSAL_TAGATTR, true); + // URL highlighting + int activeFG = 0xFF0000; + execute(SCI_SETHOTSPOTACTIVEFORE, TRUE, activeFG); + execute(SCI_SETHOTSPOTSINGLELINE, FALSE); + _pParameter = NppParameters::getInstance(); _codepage = ::GetACP(); diff --git a/PowerEditor/src/langs.model.xml b/PowerEditor/src/langs.model.xml index ae050eb7c..b4bbd0d25 100644 --- a/PowerEditor/src/langs.model.xml +++ b/PowerEditor/src/langs.model.xml @@ -75,7 +75,7 @@ as case class data default deriving do else hiding if import in infix infixl infixr instance let module newtype of proc qualified rec then type where _ - !doctype a abbr accept-charset accept accesskey acronym action address align alink alt applet archive area axis b background base basefont bdo bgcolor big blockquote body border br button caption cellpadding cellspacing center char charoff charset checkbox checked cite class classid clear code codebase codetype col colgroup color cols colspan compact content coords data datafld dataformatas datapagesize datasrc datetime dd declare defer del dfn dir disabled div dl dt em enctype event face fieldset file font for form frame frameborder frameset h1 h2 h3 h4 h5 h6 head headers height hidden hr href hreflang hspace html http-equiv i id iframe image img input ins isindex ismap kbd label lang language leftmargin legend li link longdesc map marginwidth marginheight maxlength media menu meta method multiple name noframes nohref noresize noscript noshade nowrap object ol onblur onchange onclick ondblclick onfocus onkeydown onkeypress onkeyup onload onmousedown onmousemove onmouseover onmouseout onmouseup optgroup option onreset onselect onsubmit onunload p param password profile pre prompt public q radio readonly rel reset rev rows rowspan rules s samp scheme scope script select selected shape size small span src standby start strike strong style sub submit summary sup tabindex table target tbody td text textarea tfoot th thead title topmargin tr tt type u ul usemap valign value valuetype var version vlink vspace width xml xmlns + !doctype a abbr accept-charset accept accesskey acronym action address align alink alt applet archive area axis b background base basefont bdo bgcolor big blockquote body border br button caption cellpadding cellspacing center char charoff charset checkbox checked cite class classid clear code codebase codetype col colgroup color cols colspan comment compact content coords data datafld dataformatas datapagesize datasrc datetime dd declare defer del dfn dir disabled div dl dt em embed enctype event face fieldset file font for form frame frameborder frameset h1 h2 h3 h4 h5 h6 head headers height hidden hr href hreflang hspace html http-equiv i id iframe image img input ins isindex ismap kbd label lang language leftmargin legend li link longdesc map marginwidth marginheight maxlength media menu meta method multiple name noembed noframes nohref noresize noscript noshade nowrap object ol onblur onchange onclick ondblclick onfocus onkeydown onkeypress onkeyup onload onmousedown onmousemove onmouseover onmouseout onmouseup optgroup option onreset onselect onsubmit onunload p param password profile pre prompt public q radio readonly rel reset rev rows rowspan rules s samp scheme scope script select selected shape size small span src standby start strike strong style sub submit summary sup tabindex table target tbody td text textarea tfoot th thead title topmargin tr tt type u ul usemap valign value valuetype var version vlink vspace width xml xmlns diff --git a/PowerEditor/visual.net/notepadPlus.vcproj b/PowerEditor/visual.net/notepadPlus.vcproj index 6afba25d0..fa551851c 100644 --- a/PowerEditor/visual.net/notepadPlus.vcproj +++ b/PowerEditor/visual.net/notepadPlus.vcproj @@ -409,6 +409,10 @@ RelativePath="..\src\WinControls\AboutDlg\URLCtrl.cpp" > + + @@ -718,6 +722,10 @@ RelativePath="..\src\WinControls\AboutDlg\URLCtrl.h" > + + diff --git a/scintilla/src/Editor.cxx b/scintilla/src/Editor.cxx index a54d1632e..0de7ae587 100644 --- a/scintilla/src/Editor.cxx +++ b/scintilla/src/Editor.cxx @@ -898,7 +898,7 @@ void Editor::ScrollTo(int line, bool moveThumb) { if (moveThumb) { SetVerticalScrollPos(); } - NotifyScrolled(); + NotifyScrolled(true); } } @@ -917,7 +917,7 @@ void Editor::HorizontalScrollTo(int xPos) { RedrawRect(GetClientRectangle()); } - NotifyScrolled(); + NotifyScrolled(false); } void Editor::MoveCaretInsideView(bool ensureVisible) { @@ -3717,9 +3717,10 @@ void Editor::NotifyPainted() { NotifyParent(scn); } -void Editor::NotifyScrolled() { +void Editor::NotifyScrolled(bool vertical) { SCNotification scn = {0}; scn.nmhdr.code = SCN_SCROLLED; + scn.wParam = vertical; //true if vertical scrolling NotifyParent(scn); } diff --git a/scintilla/src/Editor.h b/scintilla/src/Editor.h index 03ae10715..08c676c65 100644 --- a/scintilla/src/Editor.h +++ b/scintilla/src/Editor.h @@ -370,7 +370,7 @@ protected: // ScintillaBase subclass needs access to much of Editor void NotifyHotSpotDoubleClicked(int position, bool shift, bool ctrl, bool alt); void NotifyUpdateUI(); void NotifyPainted(); - void NotifyScrolled(); + void NotifyScrolled(bool vertical); void NotifyIndicatorClick(bool click, int position, bool shift, bool ctrl, bool alt); bool NotifyMarginClick(Point pt, bool shift, bool ctrl, bool alt); void NotifyNeedShown(int pos, int len);