Developer forums (C::B DEVELOPMENT STRICTLY!) > CodeCompletion redesign
BraceCompletion patch to improve Code Completion
ollydbg:
Hi, blueshake has just built a patch to do BraceCompletion. I have applied in my local copy and tested it. It works Great! Thanks blueshake for your patch. (He has some difficulty to post these code, So, I wrote this post instead).
Here is his patch:
--- Code: ---Index: src/plugins/codecompletion/codecompletion.cpp
===================================================================
--- src/plugins/codecompletion/codecompletion.cpp (revision 5519)
+++ src/plugins/codecompletion/codecompletion.cpp (working copy)
@@ -1876,6 +1876,17 @@
// else if (event.GetEventType() == wxEVT_SCI_MODIFIED)
// Manager::Get()->GetLogManager()->DebugLog(_T("wxEVT_SCI_MODIFIED"));
+//do this when the [ { ( " ' were typed
+
+ if (event.GetEventType() == wxEVT_SCI_CHARADDED)
+ {
+ m_timerCodeCompletion.Stop();
+ wxChar ch = event.GetKey();
+ DoBraceCompletion(control, ch);
+ //event.Skip();
+ }
+/////////////////////////////////
+
if (event.GetEventType() == wxEVT_SCI_CHARADDED &&
!control->AutoCompActive()) // not already active autocompletion
{
@@ -1886,9 +1897,10 @@
int wordstart = control->WordStartPosition(pos, true);
// if more than two chars have been typed, invoke CC
+ ////////////////////////////////
int autoCCchars = cfg->ReadInt(_T("/auto_launch_chars"), 4);
bool autoCC = cfg->ReadBool(_T("/auto_launch"), true) &&
- pos - wordstart >= autoCCchars;
+ pos - wordstart >= autoCCchars;
// update calltip highlight while we type
if (control->CallTipActive())
@@ -2008,3 +2020,77 @@
{
// nothing for now
}
+
+void CodeCompletion::DoBraceCompletion(cbStyledTextCtrl* control, const wxChar& ch)
+{
+ int pos = control->GetCurrentPos();
+ int style = control->GetStyleAt(pos);
+ if (style == wxSCI_C_COMMENT || style == wxSCI_C_COMMENTLINE)
+ {
+ return;
+ }
+ if (ch == _T('\'') )//&& style != || ch == _T('"') )
+ {
+ if (control->GetCharAt(pos) == ch)
+ {
+ control->DeleteBack();
+ control->GotoPos(pos);
+ return;
+ }
+ else
+ {
+ if (style == wxSCI_C_STRING)
+ return;
+ control->AddText(ch);
+ control->GotoPos(pos);
+ return;
+ }
+ }
+ if (ch == _T('"'))
+ {
+ if (control->GetCharAt(pos) == ch)
+ {
+ control->DeleteBack();
+ control->GotoPos(pos);
+ return;
+ }
+ else
+ {
+ if (style == wxSCI_C_CHARACTER)
+ return;
+ control->AddText(ch);
+ control->GotoPos(pos);
+ return;
+ }
+ }
+ if (style == wxSCI_C_STRING || style == wxSCI_C_CHARACTER)
+ return;
+ wxString leftBrace(_T("([{"));
+ wxString rightBrace(_T(")]}"));
+ int index = leftBrace.find(ch);
+ if (index != wxNOT_FOUND)
+ {
+ control->AddText(rightBrace.GetChar(index));
+ control->GotoPos(pos);
+ if (ch == _T('{'))
+ {
+ control->NewLine();
+ control->GotoPos(pos);
+ return;
+ }
+ }
+ else
+ {
+ index = rightBrace.find(ch);
+ if (index != wxNOT_FOUND)
+ {
+ if (control->GetCharAt(pos) == ch)
+ {
+ control->DeleteBack();
+ control->GotoPos(pos);
+ return;
+ }
+
+ }
+ }
+}
Index: src/plugins/codecompletion/codecompletion.h
===================================================================
--- src/plugins/codecompletion/codecompletion.h (revision 5519)
+++ src/plugins/codecompletion/codecompletion.h (working copy)
@@ -115,7 +115,7 @@
void OnStartParsingFunctions(wxTimerEvent& event);
void OnFunction(wxCommandEvent& event);
void ParseFunctionsAndFillToolbar(bool force = false);
-
+ void DoBraceCompletion(cbStyledTextCtrl* control, const wxChar& ch);
int m_PageIndex;
bool m_InitDone;
--- End code ---
Thanks for testing! :D See the screen shot.
After enter "{", another "}" will be automatically added. So does ( [ "
[attachment deleted by admin]
killerbot:
I have applied it in my local copy, a little bit modified (indentation issues in the patch, not in the meaning of the new code ;-) ).
Seems to work nice.
I will test it a in my production system, when I don't find any shot term issues, I will commit this.
Thanks for the contribution !!!!!!!!!!!!
danselmi:
I also applied is on my local copy.
1.: It works great as long as you edit c/c++ sources. I also use cb to edit other sources, where the ' is used to access attributes. I think, we have to check which lexer is configured.
2.: I believe that this code better suits to "smart indenting" (as Ceniza mentioned int this post http://forums.codeblocks.org/index.php/topic,9820.0.html) than to cc.
regards danselmi
killerbot:
to have all references together (see also) : http://forums.codeblocks.org/index.php/topic,8803.0.html
Though I think that adding to CC could be the first step until a more fundamental refactoring can be done.
mandrav:
--- Quote from: killerbot on April 05, 2009, 09:35:00 pm ---Though I think that adding to CC could be the first step until a more fundamental refactoring can be done.
--- End quote ---
Agreed for the refactoring but until then, smart-indenting is the place to put it in.
Navigation
[0] Message Index
[#] Next page
Go to full version