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;
Though I think that adding to CC could be the first step until a more fundamental refactoring can be done.
Index: sdk/cbeditor.cpp
===================================================================
--- sdk/cbeditor.cpp (revision 5539)
+++ sdk/cbeditor.cpp (working copy)
@@ -221,6 +221,135 @@
return -1;
}
+ bool IsComment( int style )
+ {
+ cbStyledTextCtrl* control = m_pOwner->GetControl();
+ switch ( control->GetLexer() )
+ {
+ case wxSCI_LEX_CPP:
+ return style == wxSCI_C_COMMENT ||
+ style == wxSCI_C_COMMENTLINE ||
+ style == wxSCI_C_COMMENTDOC ||
+ style == wxSCI_C_COMMENTDOCKEYWORD ||
+ style == wxSCI_C_COMMENTDOCKEYWORDERROR ||
+ style == wxSCI_C_COMMENTLINEDOC;
+ case wxSCI_LEX_D:
+ return style == wxSCI_D_COMMENT ||
+ style == wxSCI_D_COMMENTLINE ||
+ style == wxSCI_D_COMMENTDOC ||
+ style == wxSCI_D_COMMENTDOCKEYWORD ||
+ style == wxSCI_D_COMMENTDOCKEYWORDERROR ||
+ style == wxSCI_D_COMMENTLINEDOC;
+ default:
+ return false;
+ }
+ return false;
+ }
+ bool IsPreprocessor( int style )
+ {
+ cbStyledTextCtrl* control = m_pOwner->GetControl();
+ if ( control->GetLexer() == wxSCI_LEX_CPP )
+ return style == wxSCI_C_PREPROCESSOR;
+ return false;
+ }
+ bool IsCharacterOrString( int style )
+ {
+ cbStyledTextCtrl* control = m_pOwner->GetControl();
+ switch ( control->GetLexer() )
+ {
+ case wxSCI_LEX_CPP:
+ return style == wxSCI_C_STRING || style == wxSCI_C_CHARACTER;
+ case wxSCI_LEX_D:
+ return style == wxSCI_D_STRING || style == wxSCI_D_CHARACTER;
+ default:
+ return false;
+ }
+ return false;
+ }
+ bool IsCharacter( int style )
+ {
+ cbStyledTextCtrl* control = m_pOwner->GetControl();
+ switch ( control->GetLexer() )
+ {
+ case wxSCI_LEX_CPP:
+ return style == wxSCI_C_CHARACTER;
+ case wxSCI_LEX_D:
+ return style == wxSCI_D_CHARACTER;
+ default:
+ return false;
+ }
+ return false;
+ }
+ void DoBraceCompletion(const wxChar& ch)
+ {
+ cbStyledTextCtrl* control = m_pOwner->GetControl();
+ int pos = control->GetCurrentPos();
+ int style = control->GetStyleAt(pos);
+ if ( IsComment(style) || IsPreprocessor(style) )
+ return;
+ if ( ch == _T('\'') )
+ {
+ if ( control->GetCharAt(pos) == ch && pos > 1 && control->GetCharAt(pos-2) != _T('\\') )
+ {
+ control->DeleteBack();
+ control->GotoPos(pos);
+ }
+ else
+ {
+ if ( control->GetCharAt(pos-2) == _T('\\') || IsCharacterOrString(style) )
+ return;
+ control->AddText(ch);
+ control->GotoPos(pos);
+ }
+ return;
+ }
+ if ( ch == _T('"') )
+ {
+ if (control->GetCharAt(pos) == ch && pos > 1 && control->GetCharAt(pos-2) != _T('\\') )
+ {
+ control->DeleteBack();
+ control->GotoPos(pos);
+ }
+ else
+ {
+ if ( control->GetCharAt(pos-2) == _T('\\') || IsCharacter(style) )
+ return;
+ control->AddText(ch);
+ control->GotoPos(pos);
+ }
+ return;
+ }
+ if ( IsCharacterOrString(style) )
+ 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;
+ }
+ }
+ }
+ }
+
/** Strip Trailing Blanks before saving */
void StripTrailingSpaces()
{
@@ -2787,6 +2916,13 @@
}
}
+ bool braceCompletion = Manager::Get()->GetConfigManager(_T("editor"))->ReadBool(_T("/brace_completion"), true);
+ if ( braceCompletion )
+ {
+ if ( control->GetLexer() == wxSCI_LEX_CPP || control->GetLexer() == wxSCI_LEX_D )
+ m_pData->DoBraceCompletion( ch );
+ }
+
OnScintillaEvent(event);
}
Index: sdk/editorconfigurationdlg.cpp
===================================================================
--- sdk/editorconfigurationdlg.cpp (revision 5539)
+++ sdk/editorconfigurationdlg.cpp (working copy)
@@ -106,6 +106,7 @@
XRCCTRL(*this, "chkAutoIndent", wxCheckBox)->SetValue(cfg->ReadBool(_T("/auto_indent"), true));
XRCCTRL(*this, "chkSmartIndent", wxCheckBox)->SetValue(cfg->ReadBool(_T("/smart_indent"), true));
+ XRCCTRL(*this, "chkBraceCompletion", wxCheckBox)->SetValue(cfg->ReadBool(_T("/brace_completion"), true));
XRCCTRL(*this, "chkUseTab", wxCheckBox)->SetValue(cfg->ReadBool(_T("/use_tab"), false));
m_EnableScrollWidthTracking = cfg->ReadBool(_T("/margin/scroll_width_tracking"), false);
XRCCTRL(*this, "chkScrollWidthTracking", wxCheckBox)->SetValue(m_EnableScrollWidthTracking);
@@ -863,6 +864,7 @@
cfg->Write(_T("/auto_indent"), XRCCTRL(*this, "chkAutoIndent", wxCheckBox)->GetValue());
cfg->Write(_T("/smart_indent"), XRCCTRL(*this, "chkSmartIndent", wxCheckBox)->GetValue());
+ cfg->Write(_T("/brace_completion"), XRCCTRL(*this, "chkBraceCompletion", wxCheckBox)->GetValue());
cfg->Write(_T("/use_tab"), XRCCTRL(*this, "chkUseTab", wxCheckBox)->GetValue());
cfg->Write(_T("/show_indent_guides"), XRCCTRL(*this, "chkShowIndentGuides", wxCheckBox)->GetValue());
cfg->Write(_T("/tab_indents"), XRCCTRL(*this, "chkTabIndents", wxCheckBox)->GetValue());
Index: sdk/resources/editor_configuration.xrc
===================================================================
--- sdk/resources/editor_configuration.xrc (revision 5539)
+++ sdk/resources/editor_configuration.xrc (working copy)
@@ -275,6 +275,13 @@
<flag>wxALIGN_LEFT|wxALIGN_TOP</flag>
</object>
<object class="sizeritem">
+ <object class="wxCheckBox" name="chkBraceCompletion">
+ <label>Brace completion</label>
+ <checked>1</checked>
+ </object>
+ <flag>wxALIGN_LEFT|wxALIGN_TOP</flag>
+ </object>
+ <object class="sizeritem">
<object class="wxCheckBox" name="chkBackspaceUnindents">
<label>Backspace unindents</label>
<checked>1</checked>
ok, this modification is even better I thinkkudos to blueshake! I only moved the code around.
PS : I think it should also be active for :Yes, C language is part of C++. Scintilla has no special lexer for java so the cpp lexer can be used to highlight java sources (adjust the lexer configuration "lexer_cpp.xml"). If scintilla is configured to use the cpp lexer for java sources then BraceCompletion will also work for that.
- C language (or is that part of the CPP lexer)
However I stumbled already on 1 issue !!I tried to correct that (and updated my previous post).
std::string Test = "This is \"my\" test"; <--- ok : syntax correct
Now let's add also \"\" around the is (so not extending the ones around 'my') :
When I type the first part of it I get :
std::string Test = "This \""is \"my\" test"
where it should have been : std::string Test = "This \"is \"my\" test"
and when I type the end part the same thing occurs
std::string Test = "This \""is\"" \"my\" test"
the character in front should be checked, and when that is a '\' the code should stop issuing the completion part.I updated my previous post and submitted the patch at berlios. patch id: 2746.