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
OLD:
class A
{
public:
void test()
{
int i = 0;
}
private:
int good()
{
}
protected:
};
AFTER PATCH:
class A
{
public:
void test()
{
int i = 0;
}
private:
int good()
{
}
protected:
};
EDIT: support 'case'/ 'default'.
[attachment deleted by admin]
A better implementation, to prevent mistaken judgments.
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
[attachment deleted by admin]
I like this, but I guess some people do want the indent ?
Should it therefor be configurable ?
Quote from: killerbot on March 24, 2010, 07:09:30 AM
Should it therefor be configurable ?
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.
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...
I believe this code fits better somewhere in void cbEditor::OnEditorCharAdded(wxScintillaEvent& event) since all other indent related code is there too.
Additionally it should check the currently set lexer and needs to be configurable.
Isnt this already handled by Astyle ?
Quote from: Seronis on March 25, 2010, 02:06:02 AM
Isnt this already handled by Astyle ?
AStyle reformats already written code. This patch would make the behaviour apply (optionally) while typing the code. I wouldn't mind having the option, I should say.
Quote from: ptDev on March 25, 2010, 08:18:04 AM
Quote from: Seronis on March 25, 2010, 02:06:02 AM
Isnt this already handled by Astyle ?
AStyle reformats already written code. This patch would make the behaviour apply (optionally) while typing the code. I wouldn't mind having the option, I should say.
Gotcha. In that case shouldnt any of these options be set to inherit the users astyle preferences and let that be the point of configuration ?
Quote from: Seronis on March 26, 2010, 12:26:55 AM
Gotcha. In that case shouldnt any of these options be set to inherit the users astyle preferences and let that be the point of configuration ?
As the astyle plugin is... erm... a plugin and therefore might not be available / disabled / installed you cannot rely on these settings.
When type ':', determine whether the need to add a new line.
Index: src/plugins/codecompletion/codecompletion.cpp
===================================================================
--- src/plugins/codecompletion/codecompletion.cpp (revision 6204)
+++ src/plugins/codecompletion/codecompletion.cpp (working copy)
@@ -2080,6 +2080,33 @@
}
}
+ 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->PositionFromLine(curLine));
+ control->BackTab();
+ const int column = control->GetColumn(control->GetCurrentPos());
+ control->GotoPos(control->GetLineEndPosition(curLine));
+ if (control->GetLineCount() > curLine)
+ {
+ if (control->GetColumn(control->GetLineIndentPosition(curLine + 1)) == column)
+ {
+ control->NewLine();
+ control->Tab();
+ }
+ }
+ }
+ }
+ }
+
Parser* parser = m_NativeParser.GetParserPtr();
if ( parser && parser->Options().whileTyping
&& ( (event.GetModificationType() & wxSCI_MOD_INSERTTEXT)
[attachment deleted by admin]
In my opinion, a label(included'public:', 'private:' and 'protected')should not be indented to keep it easy to be find.
I think the parser could do it like this way: when the ENTER is pressed, check the prev line, if there is just a label, then cancel indent.
BTW, I think when we typed a '{' or '}', the indent should be adjusted automatically. For example, when we may write
for(vector<int>::iterator i = v.begin();
i != v.end();
++i)
Then we would type ENTER, and the CodeBlocks will generate '{' and '}' for us, but it looks like that:
for(vector<int>::iterator i = v.begin();
i != v.end();
++i)
{
}
This is not what we want. Could someone solve this problem?
Quote from: thynson on May 29, 2010, 01:08:56 PM
In my opinion, a label(included'public:', 'private:' and 'protected')should not be indented to keep it easy to be find.
I think the parser could do it like this way: when the ENTER is pressed, check the prev line, if there is just a label, then cancel indent.
BTW, I think when we typed a '{' or '}', the indent should be adjusted automatically. For example, when we may write
for(vector<int>::iterator i = v.begin();
i != v.end();
++i)
Then we would type ENTER, and the CodeBlocks will generate '{' and '}' for us, but it looks like that:
for(vector<int>::iterator i = v.begin();
i != v.end();
++i)
{
}
This is not what we want. Could someone solve this problem?
The feature added in cc_branch. :lol:
I still believe that this code should go to cbEditor, to where the other indent related code resides! Am I wrong?
Quote from: danselmi on May 31, 2010, 08:40:00 PM
I still believe that this code should go to cbEditor, to where the other indent related code resides!
That is actually true. I'd second that.
Quote from: MortenMacFly on May 31, 2010, 08:42:37 PM
Quote from: danselmi on May 31, 2010, 08:40:00 PM
I still believe that this code should go to cbEditor, to where the other indent related code resides!
That is actually true. I'd second that.
OK, I will do that.