Feature #4532 2009-03-16 18:43
bozo_le_fou
Codecompletion Keyboard code Goto Impl
It could be interesting to have a keyboard shortcut that allow to follow declaration or implementation of a keyword.
- Category
- Plugins
- Status
- Open
- Close date
- Assigned to
History
bozo_le_fou 2009-03-16 18:45
I don't know how to do on this site but i made the patch for this ------ Index: codecompletion/codecompletion.cpp =================================================================== --- codecompletion/codecompletion.cpp (rvision 1) +++ codecompletion/codecompletion.cpp (copie de travail) @@ -120,6 +120,10 @@ int idEditorSubMenu = wxNewId(); int idClassMethod = wxNewId(); int idUnimplementedClassMethods = wxNewId(); +//DeclTmp +int idGotoImplDecl = wxNewId(); +int idComefromImplDecl = wxNewId(); + int idGotoDeclaration = wxNewId(); int idGotoImplementation = wxNewId(); int idOpenIncludeFile = wxNewId(); @@ -140,6 +144,10 @@ EVT_MENU(idMenuGotoNextFunction, CodeCompletion::OnGotoNextFunction) EVT_MENU(idClassMethod, CodeCompletion::OnClassMethod) EVT_MENU(idUnimplementedClassMethods, CodeCompletion::OnUnimplementedClassMethods) + //DeclTmp + EVT_MENU(idGotoImplDecl, CodeCompletion::OnGotoImplDeclRecursive) + EVT_MENU(idComefromImplDecl, CodeCompletion::OnComefromImplDeclRecursive) + EVT_MENU(idGotoDeclaration, CodeCompletion::OnGotoDeclaration) EVT_MENU(idGotoImplementation, CodeCompletion::OnGotoDeclaration) EVT_MENU(idOpenIncludeFile, CodeCompletion::OnOpenIncludeFile) @@ -263,6 +271,9 @@ m_SearchMenu->Append(idMenuGotoFunction, _("Goto function...\tCtrl-Alt-G")); m_SearchMenu->Append(idMenuGotoPrevFunction, _("Goto previous function\tCtrl-PgUp")); m_SearchMenu->Append(idMenuGotoNextFunction, _("Goto next function\tCtrl-PgDn")); + m_SearchMenu->Append(idGotoImplDecl, _("Goto impl/decl...\tF6")); + m_SearchMenu->Append(idComefromImplDecl, _("Comefrom decl/impl...\tShift+F6")); + } else Manager::Get()->GetLogManager()->DebugLog(_T("Could not find Search menu!")); @@ -1007,7 +1018,7 @@ m_InitDone = true; // Dreaded DDE-open bug related: do not touch the following lines unless for a good reason - + // parse any projects opened through DDE or the command-line ParseActiveProjects(); ProjectManager* prjMan = Manager::Get()->GetProjectManager(); @@ -1595,6 +1606,63 @@ DoAllMethodsImpl(); } +void CodeCompletion::OnGotoImplDeclRecursive(wxCommandEvent& event) +{ + + cbEditor* ed = Manager::Get()->GetEditorManager()->GetBuiltinActiveEditor(); + cbStyledTextCtrl* control = ed->GetControl(); + + int pos = control->GetCurrentPos(); + int ws = control->WordStartPosition(pos, true); + int we = control->WordEndPosition(pos, true); + wxString txt = control->GetTextRange(ws, we); + m_LastKeyword=txt; + m_listLastKeyword.push_back(txt); + + FunctionScope fs; + fs.Name=txt; + fs.StartLine=ed->GetControl()->GetCurrentLine(); + fs.Scope=ed->GetFilename(); + m_listLastPositions.push_back(fs); + + + if (m_listLastPositions.size()>=2) + { + FunctionsScopeVec::reverse_iterator rii; + rii=m_listLastPositions.rbegin(); + rii++; + if(fs.Name==(rii->Name)) + { + event.SetId(idGotoDeclaration); + + if ((m_listLastPositions.size()>2)) + { + ++rii; + if ((rii)->Name == (m_listLastPositions.back().Name)) + m_listLastPositions.pop_back(); + } + } + } + + OnGotoDeclaration(event); +} + +void CodeCompletion::OnComefromImplDeclRecursive(wxCommandEvent& event) +{ + + + if (m_listLastPositions.size()>0) + { + + FunctionScope fs=m_listLastPositions.back(); + EditorManager* edMan = Manager::Get()->GetEditorManager(); + cbEditor* ed =edMan->Open(fs.Scope); + ed->GotoLine(fs.StartLine); + + m_listLastPositions.pop_back(); + } + +} void CodeCompletion::OnGotoDeclaration(wxCommandEvent& event) { EditorManager* edMan = Manager::Get()->GetEditorManager(); @@ -1632,7 +1700,9 @@ { // only match tokens that have filename info if ((event.GetId() == idGotoImplementation && !sel->GetImplFilename().IsEmpty()) || - (event.GetId() == idGotoDeclaration && !sel->GetFilename().IsEmpty())) + (event.GetId() == idGotoDeclaration && !sel->GetFilename().IsEmpty()) || + (event.GetId() == idGotoImplDecl && !sel->GetImplFilename().IsEmpty()) || + (event.GetId() == idComefromImplDecl && !sel->GetImplFilename().IsEmpty())) { selections.Add(sel->DisplayName()); int_selections.Add(*it); @@ -1656,13 +1726,33 @@ // do we have a token? if (token) { - if(event.GetId() == idGotoImplementation) + if(event.GetId() == idGotoImplementation || event.GetId() == idGotoImplDecl || event.GetId() == idComefromImplDecl) { cbEditor* ed = edMan->Open(token->GetImplFilename()); if (ed) + { ed->GotoLine(token->m_ImplLine - 1); + + } + else if (event.GetId() == idGotoImplDecl || event.GetId() == idComefromImplDecl) + { + ed = edMan->Open(token->GetFilename()); + if (ed) + { + ed->GotoLine(token->m_Line - 1); + + } + else + { + cbMessageBox(wxString::Format(_("Impl/Declaration not found: %s"), txt.c_str()), _("Warning"), wxICON_WARNING); + } + } else - cbMessageBox(wxString::Format(_("Implementation not found: %s"), txt.c_str()), _("Warning"), wxICON_WARNING); + { + //If no Implementation Goto Declaration + cbMessageBox(wxString::Format(_("Implementation not found: %s"), txt.c_str()), _("Warning"), wxICON_WARNING); + + } } else { Index: codecompletion/codecompletion.h =================================================================== --- codecompletion/codecompletion.h (rvision 1) +++ codecompletion/codecompletion.h (copie de travail) @@ -40,9 +40,11 @@ wxString Name; }; + typedef std::vector<FunctionScope> FunctionsScopeVec; typedef std::vector<NameSpace> NameSpaceVec; + struct FunctionsScopePerFile { FunctionsScopeVec m_FunctionsScope; @@ -87,6 +89,10 @@ void OnGotoNextFunction(wxCommandEvent& event); void OnClassMethod(wxCommandEvent& event); void OnUnimplementedClassMethods(wxCommandEvent& event); + //DeclTmp + void OnGotoImplDeclRecursive(wxCommandEvent& event); + void OnComefromImplDeclRecursive(wxCommandEvent& event); + void OnGotoDeclaration(wxCommandEvent& event); void OnOpenIncludeFile(wxCommandEvent& event); void OnAppDoneStartup(CodeBlocksEvent& event); @@ -121,6 +127,8 @@ wxString m_LastIncludeFileFrom; wxString m_LastIncludeFile; wxString m_LastKeyword; + list<wxString> m_listLastKeyword; + FunctionsScopeVec m_listLastPositions; wxMenu* m_EditMenu; wxMenu* m_SearchMenu; @@ -148,7 +156,7 @@ wxString m_LastFile; wxTimer m_FunctionsParsingTimer; - + bool m_LexerKeywordsToInclude[9]; DECLARE_EVENT_TABLE()
ollydbg 2009-06-09 16:16
Do you mean that you want to add a short-cut key to "Goto impl" instead of the context menu?
You can open a thread in the CB's forum, so that people can discuss this issue.