summaryrefslogtreecommitdiff
path: root/LiteEditor/context_cpp.cpp
diff options
context:
space:
mode:
authorChow Loong Jin <hyperair@gmail.com>2010-02-13 02:46:33 +0800
committerChow Loong Jin <hyperair@gmail.com>2010-02-13 02:46:33 +0800
commitab5bf5023dc0f25091831e11fd68bcf33bbeb4c3 (patch)
tree5eba75d8e730a4333182f8532e76623e8357f6bf /LiteEditor/context_cpp.cpp
parent5ec7ea8b2ec3db0551071242c80c4ce575dfde47 (diff)
Imported Upstream version 2.2.0.3681
Diffstat (limited to 'LiteEditor/context_cpp.cpp')
-rw-r--r--LiteEditor/context_cpp.cpp196
1 files changed, 59 insertions, 137 deletions
diff --git a/LiteEditor/context_cpp.cpp b/LiteEditor/context_cpp.cpp
index 12cdf4a0..7cc9d99b 100644
--- a/LiteEditor/context_cpp.cpp
+++ b/LiteEditor/context_cpp.cpp
@@ -25,6 +25,7 @@
#include "pluginmanager.h"
+#include "cl_editor_tip_window.h"
#include "implement_parent_virtual_functions.h"
#include "debuggerasciiviewer.h"
#include <wx/file.h>
@@ -174,7 +175,6 @@ ContextCpp::ContextCpp(LEditor *container)
: ContextBase(container)
, m_rclickMenu(NULL)
{
- ApplySettings();
Initialize();
}
@@ -319,15 +319,22 @@ void ContextCpp::AutoIndent(const wxChar &nChar)
{
LEditor &rCtrl = GetCtrl();
+ if(rCtrl.GetDisableSmartIndent()) {
+ ContextBase::AutoIndent(nChar);
+ return;
+ }
+
int curpos = rCtrl.GetCurrentPos();
if (IsComment(curpos) && nChar == wxT('\n')) {
AutoAddComment();
return;
}
+
if (IsCommentOrString(curpos)) {
ContextBase::AutoIndent(nChar);
return;
}
+
int line = rCtrl.LineFromPosition(curpos);
if (nChar == wxT('\n')) {
@@ -380,7 +387,9 @@ void ContextCpp::AutoIndent(const wxChar &nChar)
int prevLine = rCtrl.LineFromPosition(posWordBeforeColons);
// If we found one of the following keywords, un-indent their line by (foldLevel - 1)*indentSize
- if ( word == wxT("public") || word == wxT("private") || word == wxT("protected") || word == wxT("default") ) {
+ if ( word == wxT("public") || word == wxT("private") || word == wxT("protected")) {
+
+ ContextBase::AutoIndent(nChar);
// Indent this line according to the block indentation level
int foldLevel = (rCtrl.GetFoldLevel(prevLine) & wxSCI_FOLDLEVELNUMBERMASK) - wxSCI_FOLDLEVELBASE;
@@ -388,62 +397,14 @@ void ContextCpp::AutoIndent(const wxChar &nChar)
rCtrl.SetLineIndentation(prevLine, ((foldLevel-1)*rCtrl.GetIndent()) );
rCtrl.ChooseCaretX();
}
-
- } else {
-
- wxString lineString = rCtrl.GetLine(prevLine);
- // We are on a line with 'case ', un-indent its line to be: (foldLevel - 1)*indentSize
- if(lineString.Contains(wxT("case "))){
- // Indent this line according to the block indentation level
- int foldLevel = (rCtrl.GetFoldLevel(prevLine) & wxSCI_FOLDLEVELNUMBERMASK) - wxSCI_FOLDLEVELBASE;
- if (foldLevel) {
- rCtrl.SetLineIndentation(prevLine, ((foldLevel-1)*rCtrl.GetIndent()) );
- rCtrl.ChooseCaretX();
- }
- }
- }
- }
- }
-
- if ( prevpos != wxNOT_FOUND && ch == wxT('}') ) {
- // The next line should have the same indentation line as this one
- int prevLine = rCtrl.LineFromPosition(prevpos);
- rCtrl.SetLineIndentation(line, rCtrl.GetLineIndentation(prevLine));
- rCtrl.SetCaretAt(rCtrl.GetLineIndentPosition(line));
- rCtrl.ChooseCaretX();
- return;
- }
-
- if ( prevpos != wxNOT_FOUND && ch == wxT(';') ) {
-
- // check to see if this line contains '}' as well
- int tline = rCtrl.LineFromPosition(prevpos);
- int tlineStartPos = rCtrl.PositionFromLine(tline);
- int tlineEndPos = prevpos;
-
- if (tlineEndPos > tlineStartPos && tlineStartPos > 0) {
- for (int i=tlineStartPos; i<tlineEndPos; i++) {
- if (rCtrl.GetCharAt(i) == wxT('}')) {
- // The next line should have the same indentation line as this one
- int prevLine = rCtrl.LineFromPosition(prevpos);
- rCtrl.SetLineIndentation(line, rCtrl.GetLineIndentation(prevLine));
- rCtrl.SetCaretAt(rCtrl.GetLineIndentPosition(line));
- rCtrl.ChooseCaretX();
- return;
- }
+ return;
}
}
}
+ // use the previous line indentation level
if (prevpos == wxNOT_FOUND || ch != wxT('{') || IsCommentOrString(prevpos)) {
-
- // Indent this line according to the block indentation level
- int foldLevel = (rCtrl.GetFoldLevel(line) & wxSCI_FOLDLEVELNUMBERMASK) - wxSCI_FOLDLEVELBASE;
- if (foldLevel) {
- rCtrl.SetLineIndentation(line, rCtrl.GetIndent() * foldLevel);
- rCtrl.SetCaretAt(rCtrl.GetLineIndentPosition(line));
- rCtrl.ChooseCaretX();
- }
+ ContextBase::AutoIndent(nChar);
return;
}
@@ -453,6 +414,7 @@ void ContextCpp::AutoIndent(const wxChar &nChar)
rCtrl.SetCaretAt(rCtrl.GetLineIndentPosition(line));
} else if (nChar == wxT('}')) {
+
long matchPos = wxNOT_FOUND;
if (!rCtrl.MatchBraceBack(wxT('}'), rCtrl.PositionBefore(curpos), matchPos))
return;
@@ -460,8 +422,23 @@ void ContextCpp::AutoIndent(const wxChar &nChar)
if (secondLine == line)
return;
rCtrl.SetLineIndentation(line, rCtrl.GetLineIndentation(secondLine));
+
+ } else if (nChar == wxT('{')) {
+ wxString lineString = rCtrl.GetLine(line);
+ lineString.Trim().Trim(false);
+
+ int matchPos = wxNOT_FOUND;
+ wxChar previousChar = rCtrl.PreviousChar(rCtrl.PositionBefore(curpos), matchPos);
+ if(previousChar != wxT('{') && lineString == wxT("{")) {
+ // indent this line accroding to the previous line
+ int line = rCtrl.LineFromPosition(rCtrl.GetCurrentPos());
+ rCtrl.SetLineIndentation(line, rCtrl.GetLineIndentation(line-1));
+ rCtrl.ChooseCaretX();
+ }
}
- rCtrl.ChooseCaretX(); // set new column as "current" column
+
+ // set new column as "current" column
+ rCtrl.ChooseCaretX();
}
bool ContextCpp::IsCommentOrString(long pos)
@@ -1306,37 +1283,15 @@ void ContextCpp::OnGenerateSettersGetters(wxCommandEvent &event)
void ContextCpp::OnKeyDown(wxKeyEvent &event)
{
LEditor &ctrl = GetCtrl();
- int pos = ctrl.GetCurrentPos();
-
- if (m_ct && m_ct->Count() && ctrl.CallTipActive() && ctrl.GetCalltipType() == ct_function_proto) {
-
+ if (ctrl.GetFunctionTip()->IsActive()) {
switch (event.GetKeyCode()) {
-
- case WXK_UP: {
- int index = DoGetCalltipParamterIndex();
- int start(wxNOT_FOUND), len(wxNOT_FOUND);
- wxString tip = m_ct->Prev();
-
- if (index != wxNOT_FOUND) {
- m_ct->GetHighlightPos(index, start, len);
- }
- ctrl.CallTipCancel();
- ctrl.DoShowCalltip(pos, tip, ct_function_proto, start, len);
- }
- return;
-
- case WXK_DOWN: {
- int index = DoGetCalltipParamterIndex();
- int start(wxNOT_FOUND), len(wxNOT_FOUND);
- wxString tip = m_ct->Next();
-
- if (index != wxNOT_FOUND) {
- m_ct->GetHighlightPos(index, start, len);
- }
- ctrl.CallTipCancel();
- ctrl.DoShowCalltip(pos, tip, ct_function_proto, start, len);
- }
- return;
+ case WXK_UP:
+ ctrl.GetFunctionTip()->SelectPrev(DoGetCalltipParamterIndex());
+ return;
+
+ case WXK_DOWN:
+ ctrl.GetFunctionTip()->SelectNext(DoGetCalltipParamterIndex());
+ return;
}
}
event.Skip();
@@ -1998,7 +1953,7 @@ void ContextCpp::ApplySettings()
// Update the control
LEditor &rCtrl = GetCtrl();
- rCtrl.SetLexer(lexPtr->GetLexerId());
+ rCtrl.SetLexer((int)lexPtr->GetLexerId());
wxString keyWords = lexPtr->GetKeyWords(0);
keyWords.Replace(wxT("\n"), wxT(" "));
@@ -2059,6 +2014,7 @@ void ContextCpp::ApplySettings()
//delete uneeded commands
rCtrl.CmdKeyClear('/', wxSCI_SCMOD_CTRL);
+ rCtrl.CmdKeyClear('/', wxSCI_SCMOD_CTRL|wxSCI_SCMOD_SHIFT);
// update word characters to allow '~' as valid word character
rCtrl.SetWordChars(wxT("~_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"));
@@ -2456,11 +2412,12 @@ void ContextCpp::MakeCppKeywordsTags(const wxString &word, std::vector<TagEntryP
wxString ContextCpp::CallTipContent()
{
// if we have an active call tip, return its content
- if (GetCtrl().CallTipActive() && m_ct && m_ct->Count() > 0) {
- return m_ct->All();
- }
+ if (GetCtrl().GetFunctionTip()->IsActive())
+ return GetCtrl().GetFunctionTip()->GetText();
+
return wxEmptyString;
}
+
void ContextCpp::DoCodeComplete(long pos)
{
long currentPosition = pos;
@@ -2571,18 +2528,19 @@ void ContextCpp::DoCodeComplete(long pos)
expr = GetExpression(rCtrl.PositionBefore(currentPosition), false);
//display function tooltip
- int word_end = rCtrl.WordEndPosition(end, true);
+ int word_end = rCtrl.WordEndPosition(end, true);
int word_start = rCtrl.WordStartPosition(end, true);
// get the token
wxString word = rCtrl.GetTextRange(word_start, word_end);
- m_ct = TagsManagerST::Get()->GetFunctionTip(rCtrl.GetFileName(), line, expr, text, word);
- if (m_ct && m_ct->Count() > 0) {
- rCtrl.CallTipCancel();
- int start(wxNOT_FOUND), len(wxNOT_FOUND);
- m_ct->GetHighlightPos(DoGetCalltipParamterIndex(), start, len);
- rCtrl.DoShowCalltip(currentPosition, m_ct->First(), ct_function_proto, start, len);
- }
+ rCtrl.GetFunctionTip()->Add( TagsManagerST::Get()->GetFunctionTip(rCtrl.GetFileName(), line, expr, text, word) );
+ rCtrl.GetFunctionTip()->Highlight(DoGetCalltipParamterIndex());
+
+ // In an ideal world, we would like our tooltip to be placed
+ // on top of the caret.
+ wxPoint pt = rCtrl.PointFromPosition(currentPosition);
+ rCtrl.GetFunctionTip()->Activate(pt, rCtrl.GetCurrLineHeight(), rCtrl.StyleGetBackground(wxSCI_C_DEFAULT));
+
} else {
if (TagsManagerST::Get()->AutoCompleteCandidates(rCtrl.GetFileName(), line, expr, text, candidates)) {
@@ -2626,7 +2584,7 @@ void ContextCpp::DoOpenWorkspaceFile()
wxString tmpName(m_selectedWord);
tmpName.Replace(wxT("\\"), wxT("/"));
- if(tmpName.Contains(wxT("..")))
+ if (tmpName.Contains(wxT("..")))
tmpName = fileName.GetFullName();
std::vector<wxFileName> files, files2;
@@ -2721,37 +2679,7 @@ void ContextCpp::OnGotoNextFunction(wxCommandEvent& event)
void ContextCpp::OnCallTipClick(wxScintillaEvent& e)
{
- int pos = GetCtrl().GetCurrentPos();
- switch (e.GetPosition()) {
- case 1: // Up
- if (m_ct) {
- int index = DoGetCalltipParamterIndex();
- int start(wxNOT_FOUND), len(wxNOT_FOUND);
- wxString tip = m_ct->Next();
-
- if (index != wxNOT_FOUND) {
- m_ct->GetHighlightPos(index, start, len);
- }
- GetCtrl().CallTipCancel();
- GetCtrl().DoShowCalltip(pos, tip, ct_function_proto, start, len);
- }
- break;
- case 2: // down arrow
- if (m_ct) {
- int index = DoGetCalltipParamterIndex();
- int start(wxNOT_FOUND), len(wxNOT_FOUND);
- wxString tip = m_ct->Prev();
- if (index != wxNOT_FOUND) {
- m_ct->GetHighlightPos(index, start, len);
- }
- GetCtrl().CallTipCancel();
- GetCtrl().DoShowCalltip(pos, tip, ct_function_proto, start, len);
- }
- break;
- case 0: // elsewhere
- GetCtrl().DoCancelCalltip();
- break;
- }
+ wxUnusedVar(e);
}
void ContextCpp::OnCalltipCancel()
@@ -2815,14 +2743,8 @@ int ContextCpp::DoGetCalltipParamterIndex()
void ContextCpp::DoUpdateCalltipHighlight()
{
LEditor &ctrl = GetCtrl();
- if (ctrl.CallTipActive() && m_ct && m_ct->Count() && ctrl.GetCalltipType() == ct_function_proto) {
- int index = DoGetCalltipParamterIndex();
- int start(wxNOT_FOUND), len(wxNOT_FOUND);
-
- if (index != wxNOT_FOUND) {
- m_ct->GetHighlightPos(index, start, len);
- ctrl.CallTipSetHighlight(start, start + len);
- }
+ if (ctrl.GetFunctionTip()->IsActive()) {
+ ctrl.GetFunctionTip()->Highlight(DoGetCalltipParamterIndex());
}
}
@@ -2853,7 +2775,7 @@ void ContextCpp::SemicolonShift()
ctrl.SetCurrentPos(semiColonPos);
ctrl.InsertText(semiColonPos, wxT(";"));
ctrl.SetCaretAt(semiColonPos+1);
- ctrl.CallTipCancel();
+ ctrl.GetFunctionTip()->Deactivate();
}
}
}