diff options
author | nyamatongwe <unknown> | 2005-03-09 03:34:46 +0000 |
---|---|---|
committer | nyamatongwe <unknown> | 2005-03-09 03:34:46 +0000 |
commit | afc7afe13b6eb49984e1c9c66eef3cebc1392a09 (patch) | |
tree | 526577481daf6dbee2aeb0142d9baa8c3b97e117 | |
parent | b64920976eb1ddc19630f435c2aee7788b6b6815 (diff) | |
download | scintilla-mirror-afc7afe13b6eb49984e1c9c66eef3cebc1392a09.tar.gz |
Patch from Blair McGlashan to send a notification before accepting an autocompletion.
-rw-r--r-- | doc/ScintillaDoc.html | 51 | ||||
-rw-r--r-- | include/Scintilla.h | 3 | ||||
-rw-r--r-- | include/Scintilla.iface | 1 | ||||
-rw-r--r-- | src/AutoComplete.cxx | 7 | ||||
-rw-r--r-- | src/AutoComplete.h | 2 | ||||
-rw-r--r-- | src/ScintillaBase.cxx | 36 | ||||
-rw-r--r-- | src/ScintillaBase.h | 2 |
7 files changed, 74 insertions, 28 deletions
diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html index 7c4637c33..e075df0b1 100644 --- a/doc/ScintillaDoc.html +++ b/doc/ScintillaDoc.html @@ -38,7 +38,7 @@ <h1>Scintilla Documentation</h1> - <p>Last edited 29/May/2004 NH</p> + <p>Last edited 9/March/2005 NH</p> <p>There is <a class="jump" href="Design.html">an overview of the internal design of Scintilla</a>.<br /> @@ -2876,7 +2876,7 @@ struct TextToFind { <h2 id="Autocompletion">Autocompletion</h2> - <p>Autocompletion displays a list box showing likely identifiers based upon the users typing. + <p>Autocompletion displays a list box showing likely identifiers based upon the user's typing. The user chooses the currently selected item by pressing the tab character or another character that is a member of the fillup character set defined with <code>SCI_AUTOCSETFILLUPS</code>. Autocompletion is triggered by your application. For example, in C if you detect that the user @@ -2886,6 +2886,12 @@ struct TextToFind { the choice to a reasonable list. As yet another alternative, you could define a key code to activate the list.</p> + <p>When the user makes a selection from the list the container is sent a <code><a class="message" + href="#SCN_AUTOCSELECTION">SCN_AUTOCSELECTION</a></code> <a class="jump" + href="#Notifications">notification message</a>. On return from the notification Scintilla will insert + the selected text unless the autocompletion list has been cancelled, for example by the container sending + <code><a class="message" href="#SCI_AUTOCCANCEL">SCI_AUTOCCANCEL</a></code>.</p> + <p>To make use of autocompletion you must monitor each character added to the document. See <code>SciTEBase::CharAdded()</code> in SciTEBase.cxx for an example of autocompletion.</p> <code><a class="message" href="#SCI_AUTOCSHOW">SCI_AUTOCSHOW(int lenEntered, const char @@ -3042,7 +3048,8 @@ struct TextToFind { effect.<br /> o When the user makes a selection you are sent a <code><a class="message" href="#SCN_USERLISTSELECTION">SCN_USERLISTSELECTION</a></code> <a class="jump" - href="#Notifications">notification message</a>.</p> + href="#Notifications">notification message</a> rather than <code><a class="message" + href="#SCN_AUTOCSELECTION">SCN_AUTOCSELECTION</a></code>.</p> <p>BEWARE: if you have set fillup characters or stop characters, these will still be active with the user list, and may result in items being selected or the user list cancelled due to @@ -4315,7 +4322,7 @@ struct SCNotification { int ch; // SCN_CHARADDED, SCN_KEY int modifiers; // SCN_KEY, SCN_HOTSPOTCLICK, SCN_HOTSPOTDOUBLECLICK int modificationType; // SCN_MODIFIED - const char *text; // SCN_MODIFIED + const char *text; // SCN_MODIFIED, SCN_USERLISTSELECTION, SCN_AUTOCSELECTION int length; // SCN_MODIFIED int linesAdded; // SCN_MODIFIED int message; // SCN_MACRORECORD @@ -4325,7 +4332,7 @@ struct SCNotification { int foldLevelNow; // SCN_MODIFIED int foldLevelPrev; // SCN_MODIFIED int margin; // SCN_MARGINCLICK - int listType; // SCN_USERLISTSELECTION + int listType; // SCN_USERLISTSELECTION, SCN_AUTOCSELECTION int x; // SCN_DWELLSTART, SCN_DWELLEND int y; // SCN_DWELLSTART, SCN_DWELLEND }; @@ -4354,6 +4361,7 @@ struct SCNotification { <a class="message" href="#SCN_HOTSPOTCLICK">SCN_HOTSPOTCLICK</a><br /> <a class="message" href="#SCN_HOTSPOTDOUBLECLICK">SCN_HOTSPOTDOUBLECLICK</a><br /> <a class="message" href="#SCN_CALLTIPCLICK">SCN_CALLTIPCLICK</a><br /> + <a class="message" href="#SCN_AUTOCSELECTION">SCN_AUTOCSELECTION</a><br /> </code> <p>The following <code>SCI_*</code> messages are associated with these notifications:</p> @@ -4478,8 +4486,8 @@ href="#SCI_POSITIONFROMLINE">SCI_POSITIONFROMLINE</a>(lineNumber); <td align="left">Valid for text changes, not for style changes. If we are collecting undo information this holds a pointer to the text that is handed to the Undo system, otherwise it is zero. For user performed SC_MOD_BEFOREDELETE the text field is 0 and - for user performed SC_MOD_BEFOREINSERT the text field points to an array of cells, - not bytes.</td> + for user performed SC_MOD_BEFOREINSERT the text field points to an array of cells, + not bytes.</td> </tr> <tr> @@ -4890,6 +4898,35 @@ for line = lineStart to lineEnd do SCI_ENSUREVISIBLE(line) next The <code>position</code> field is set to 1 if the click is in an up arrow, 2 if in a down arrow, and 0 if elsewhere.</p> + <p><b id="SCN_AUTOCSELECTION">SCN_AUTOCSELECTION</b><br /> + The user has selected an item in an <a class="jump" href="#Autocompletion">autocompletion list</a>. The + notification is sent before the selection is inserted. Automatic insertion can be cancelled by sending a + <code><a class="message" href="#SCI_AUTOCCANCEL">SCI_AUTOCCANCEL</a></code> message + before returning from the notification. The <code>SCNotification</code> fields used are:</p> + + <table cellpadding="1" cellspacing="2" border="0" summary="Autocompletion list notification"> + <tbody> + <tr> + <th align="left">Field</th> + + <th align="left">Usage</th> + </tr> + </tbody> + + <tbody valign="top"> + <tr> + <td align="left"><code>lParam</code></td> + + <td align="left">The start position of the word being completed.</td> + </tr> + <tr> + <td align="left"><code>text</code></td> + + <td align="left">The text of the selection.</td> + </tr> + </tbody> + </table> + <h2 id="DeprecatedMessages">Deprecated messages and notifications</h2> <p>The following messages are currently supported to emulate existing Windows controls, but diff --git a/include/Scintilla.h b/include/Scintilla.h index d02ea54b8..cd1dbd77f 100644 --- a/include/Scintilla.h +++ b/include/Scintilla.h @@ -658,6 +658,7 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCN_HOTSPOTCLICK 2019 #define SCN_HOTSPOTDOUBLECLICK 2020 #define SCN_CALLTIPCLICK 2021 +#define SCN_AUTOCSELECTION 2022 //--Autogenerated -- end of section automatically generated from Scintilla.iface // These structures are defined to be exactly the same shape as the Win32 @@ -710,7 +711,7 @@ struct SCNotification { int ch; // SCN_CHARADDED, SCN_KEY int modifiers; // SCN_KEY int modificationType; // SCN_MODIFIED - const char *text; // SCN_MODIFIED + const char *text; // SCN_MODIFIED, SCN_USERLISTSELECTION, SCN_AUTOCSELECTION int length; // SCN_MODIFIED int linesAdded; // SCN_MODIFIED int message; // SCN_MACRORECORD diff --git a/include/Scintilla.iface b/include/Scintilla.iface index bf4af856f..5436fced4 100644 --- a/include/Scintilla.iface +++ b/include/Scintilla.iface @@ -2633,6 +2633,7 @@ evt void Zoom=2018(void) evt void HotSpotClick=2019(int modifiers, int position) evt void HotSpotDoubleClick=2020(int modifiers, int position) evt void CallTipClick=2021(int position) +evt void AutoCSelection=2022(string text) cat Deprecated diff --git a/src/AutoComplete.cxx b/src/AutoComplete.cxx index b4d14944f..65b1788bb 100644 --- a/src/AutoComplete.cxx +++ b/src/AutoComplete.cxx @@ -118,9 +118,10 @@ void AutoComplete::SetList(const char *list) { } } -void AutoComplete::Show() { - lb->Show(); - lb->Select(0); +void AutoComplete::Show(bool show) { + lb->Show(show); + if (show) + lb->Select(0); } void AutoComplete::Cancel() { diff --git a/src/AutoComplete.h b/src/AutoComplete.h index 981fb44c0..ee5a2de4c 100644 --- a/src/AutoComplete.h +++ b/src/AutoComplete.h @@ -57,7 +57,7 @@ public: /// The list string contains a sequence of words separated by the separator character void SetList(const char *list); - void Show(); + void Show(bool show); void Cancel(); /// Move the current list element by delta, scrolling appropriately diff --git a/src/ScintillaBase.cxx b/src/ScintillaBase.cxx index 78c15f7d7..7735d35db 100644 --- a/src/ScintillaBase.cxx +++ b/src/ScintillaBase.cxx @@ -262,7 +262,7 @@ void ScintillaBase::AutoCompleteStart(int lenEntered, const char *list) { } rcList.bottom = rcList.top + heightAlloced; ac.lb->SetPositionRelative(rcList, wMain); - ac.Show(); + ac.Show(true); if (lenEntered != 0) { AutoCompleteMoveToCurrentWord(); } @@ -312,25 +312,31 @@ void ScintillaBase::AutoCompleteCompleted() { selected[0] = '\0'; if (item != -1) { ac.lb->GetValue(item, selected, sizeof(selected)); + } else { + ac.Cancel(); + return; } - ac.Cancel(); - if (item == -1) + + ac.Show(false); + + listSelected = selected; + SCNotification scn; + scn.nmhdr.code = listType > 0 ? SCN_USERLISTSELECTION : SCN_AUTOCSELECTION; + scn.message = 0; + scn.wParam = listType; + scn.listType = listType; + Position firstPos = ac.posStart - ac.startLen; + scn.lParam = firstPos; + scn.text = listSelected.c_str(); + NotifyParent(scn); + + if (!ac.Active()) return; + ac.Cancel(); - if (listType > 0) { - userListSelected = selected; - SCNotification scn; - scn.nmhdr.code = SCN_USERLISTSELECTION; - scn.message = 0; - scn.wParam = listType; - scn.listType = listType; - scn.lParam = 0; - scn.text = userListSelected.c_str(); - NotifyParent(scn); + if (listType > 0) return; - } - Position firstPos = ac.posStart - ac.startLen; Position endPos = currentPos; if (ac.dropRestOfWord) endPos = pdoc->ExtendWordSelect(endPos, 1, true); diff --git a/src/ScintillaBase.h b/src/ScintillaBase.h index 6ea23ab5a..362231148 100644 --- a/src/ScintillaBase.h +++ b/src/ScintillaBase.h @@ -37,7 +37,7 @@ protected: CallTip ct; int listType; ///< 0 is an autocomplete list - SString userListSelected; ///< Receives listbox selected string + SString listSelected; ///< Receives listbox selected string #ifdef SCI_LEXER int lexLanguage; |