Developer forums (C::B DEVELOPMENT STRICTLY!) > CodeCompletion redesign
Patch for auto cancel indent when type 'public:' or 'protected:' or 'private:'
Loaden:
--- Code: ---Index: src/plugins/codecompletion/codecompletion.cpp
===================================================================
--- src/plugins/codecompletion/codecompletion.cpp (revision 6196)
+++ src/plugins/codecompletion/codecompletion.cpp (working copy)
@@ -2106,6 +2106,29 @@
}
}
}
+
+ if (event.GetEventType() == wxEVT_SCI_CHARADDED)
+ {
+ wxChar ch = event.GetKey();
+ if (ch == _T(':'))
+ {
+ if (control->AutoCompActive()) control->AutoCompCancel();
+ int origPos = control->GetCurrentPos() - 1;
+ int start = control->WordStartPosition(origPos, true);
+ int end = control->WordEndPosition(origPos, true);
+ const wxString text = control->GetTextRange(start, end);
+ if (text == _T("public") || text == _T("protected") || text == _T("private"))
+ {
+ control->CharLeft();
+ control->WordLeft();
+ control->BackTab();
+ control->WordRight();
+ control->CharRight();
+ control->NewLine();
+ control->Tab();
+ }
+ }
+ }
Parser* parser = m_NativeParser.GetParserPtr();
if ( parser && parser->Options().whileTyping
--- End code ---
OLD:
--- Code: ---class A
{
public:
void test()
{
int i = 0;
}
private:
int good()
{
}
protected:
};
--- End code ---
AFTER PATCH:
--- Code: ---class A
{
public:
void test()
{
int i = 0;
}
private:
int good()
{
}
protected:
};
--- End code ---
EDIT: support 'case'/ 'default'.
[attachment deleted by admin]
Loaden:
A better implementation, to prevent mistaken judgments.
--- Code: ---Index: src/plugins/codecompletion/codecompletion.cpp
===================================================================
--- src/plugins/codecompletion/codecompletion.cpp (revision 6195)
+++ src/plugins/codecompletion/codecompletion.cpp (working copy)
@@ -2106,6 +2106,26 @@
}
}
}
+
+ if (event.GetEventType() == wxEVT_SCI_CHARADDED)
+ {
+ if (event.GetKey() == _T(':'))
+ {
+ if (control->AutoCompActive()) control->AutoCompCancel();
+ wxString text = control->GetCurLine().Trim(false);
+ text = text.Remove(text.Find(_T(':'), true));
+ text = text.Trim();
+ if (text == _T("public") || text == _T("protected") || text == _T("private"))
+ {
+ int curLine = control->GetCurrentLine();
+ control->GotoPos(control->GetLineIndentPosition(curLine));
+ control->BackTab();
+ control->GotoPos(control->GetLineEndPosition(curLine));
+ control->NewLine();
+ control->Tab();
+ }
+ }
+ }
Parser* parser = m_NativeParser.GetParserPtr();
if ( parser && parser->Options().whileTyping
--- End code ---
[attachment deleted by admin]
killerbot:
I like this, but I guess some people do want the indent ?
Should it therefor be configurable ?
MortenMacFly:
--- Quote from: killerbot on March 24, 2010, 07:09:30 am ---Should it therefor be configurable ?
--- End quote ---
Yes, every such option should be configurable. Because basically by experience I can tell that a lot people won't like it (most likely including Thomas btw...). I also can tell that a lot people will need to modify this because it's in conflict with certain coding styles.
Loaden:
I agree with configurable.
As far as I know, VS, Eclipse CDT, Qt Creator and CodeLite handled this way by default.
And a lot of people are using the VS, CDT ...
When them trying Code::Blocks...
Navigation
[0] Message Index
[#] Next page
Go to full version