Patch #2074 2007-06-22 15:23

dmoore

keybinder/main menu options for CC options
Download
2074-keybinder_main.patch (5.9 KB)
Category
Application::FeatureAdd
Status
Open
Close date
 
Assigned to
dmoore
Index: src/plugins/codecompletion/codecompletion.cpp
===================================================================
--- src/plugins/codecompletion/codecompletion.cpp    (revision 4149)
+++ src/plugins/codecompletion/codecompletion.cpp    (working copy)
@@ -109,6 +109,9 @@
 int idGotoDeclaration = wxNewId();
 int idGotoImplementation = wxNewId();
 int idOpenIncludeFile = wxNewId();
+int idGotoDeclarationMenu = wxNewId();
+int idGotoImplementationMenu = wxNewId();
+int idOpenIncludeFileMenu = wxNewId();
 int idStartParsingProjects = wxNewId();
 int idCodeCompleteTimer = wxNewId();
 int idFunctionsParsingTimer = wxNewId();
@@ -128,7 +131,10 @@
     EVT_MENU(idUnimplementedClassMethods, CodeCompletion::OnUnimplementedClassMethods)
     EVT_MENU(idGotoDeclaration, CodeCompletion::OnGotoDeclaration)
     EVT_MENU(idGotoImplementation, CodeCompletion::OnGotoDeclaration)
+    EVT_MENU(idGotoDeclarationMenu, CodeCompletion::OnGotoDeclarationMenu)
+    EVT_MENU(idGotoImplementationMenu, CodeCompletion::OnGotoDeclarationMenu)
     EVT_MENU(idOpenIncludeFile, CodeCompletion::OnOpenIncludeFile)
+    EVT_MENU(idOpenIncludeFileMenu, CodeCompletion::OnOpenIncludeFileMenu)

     EVT_MENU(idViewClassBrowser, CodeCompletion::OnViewClassBrowser)

@@ -237,6 +243,8 @@
         m_EditMenu->AppendSeparator();
         m_EditMenu->Append(idMenuCodeComplete, _("Complete code\tCtrl-Space"));
         m_EditMenu->Append(idMenuShowCallTip, _("Show call tip\tCtrl-Shift-Space"));
+        m_EditMenu->Append(idClassMethod, _("Insert class method declaration/implementation"));
+        m_EditMenu->Append(idUnimplementedClassMethods, _("Insert unimplemented class methods"));
     }
     else
         Manager::Get()->GetMessageManager()->DebugLog(_T("Could not find Edit menu!"));
@@ -247,6 +255,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(idGotoDeclarationMenu, _("Goto declaration"));
+        m_SearchMenu->Append(idGotoImplementationMenu, _("Goto implementation"));
+        m_SearchMenu->Append(idOpenIncludeFileMenu, _("Open include file"));
     }
     else
         Manager::Get()->GetMessageManager()->DebugLog(_T("Could not find Search menu!"));
@@ -402,12 +415,17 @@
     {
         m_EditMenu->Delete(idMenuCodeComplete);
         m_EditMenu->Delete(idMenuShowCallTip);
+        m_EditMenu->Delete(idClassMethod);
+        m_EditMenu->Delete(idUnimplementedClassMethods);
     }
     if (m_SearchMenu)
     {
         m_SearchMenu->Delete(idMenuGotoFunction);
         m_SearchMenu->Delete(idMenuGotoPrevFunction);
         m_SearchMenu->Delete(idMenuGotoNextFunction);
+        m_SearchMenu->Delete(idGotoDeclarationMenu);
+        m_SearchMenu->Delete(idGotoImplementationMenu);
+        m_SearchMenu->Delete(idOpenIncludeFileMenu);
     }
 }

@@ -1364,6 +1382,8 @@
     {
         m_EditMenu->Enable(idMenuCodeComplete, hasEd);
         m_EditMenu->Enable(idMenuShowCallTip, hasEd);
+        m_EditMenu->Enable(idClassMethod, hasEd);
+        m_EditMenu->Enable(idUnimplementedClassMethods, hasEd);
     }

     if (m_SearchMenu)
@@ -1371,6 +1391,9 @@
         m_SearchMenu->Enable(idMenuGotoFunction,     hasEd);
         m_SearchMenu->Enable(idMenuGotoPrevFunction, hasEd);
         m_SearchMenu->Enable(idMenuGotoNextFunction, hasEd);
+        m_SearchMenu->Enable(idGotoDeclarationMenu, hasEd);
+        m_SearchMenu->Enable(idGotoImplementationMenu, hasEd);
+        m_SearchMenu->Enable(idOpenIncludeFileMenu, hasEd);
     }

     if (m_ViewMenu)
@@ -1463,11 +1486,57 @@
     DoAllMethodsImpl();
 }

+void CodeCompletion::OnOpenIncludeFileMenu(wxCommandEvent& event)
+{
+    cbEditor* ed = Manager::Get()->GetEditorManager()->GetBuiltinActiveEditor();
+    if (ed)
+    {
+        m_LastIncludeFileFrom = ed->GetFilename();
+        cbStyledTextCtrl* control = ed->GetControl();
+        int pos = control->GetCurrentPos();
+        wxString line = control->GetLine(control->LineFromPosition(pos));
+
+        wxRegEx reg(_T("^[ \t]*#[ \t]*include[ \t]+[\"<]([^\">]+)[\">]"));
+        wxString inc;
+        if (reg.Matches(line))
+            inc = reg.GetMatch(line, 1);
+        m_LastIncludeFile.Clear();
+        if (!inc.IsEmpty())
+        {
+            m_LastIncludeFile = inc;
+            OnOpenIncludeFile(event);
+        }
+    }
+}
+
+void CodeCompletion::OnGotoDeclarationMenu(wxCommandEvent& event)
+{
+    cbEditor* ed = Manager::Get()->GetEditorManager()->GetBuiltinActiveEditor();
+    if (ed)
+    {
+        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.Clea
download for full patch...
dmoore 2007-06-22 15:23
dmoore 2007-06-22 15:25

title should of this patch should have read "... for CC commands"

mandrav 2007-06-25 11:53

I am not sure these are valid items to add to the menus. They are very content-specific (i.e. what the text under the cursor is).

From what I understand, you did this patch just to be able to configure the shortcuts for these options through keybinder, no?

If that's the case, maybe we should just think of a better way to handle shortcuts. Cluttering the application menus just so keybinder can change the various shortcuts is the wrong approach IMO.

We will have to think of a way to "register" commands (or actions if you prefer) to a central place so their shortcuts can also be configured centrally.

I did start writing an actions-manager once for this very reason but I stopped working on it at some point and now I can't even find the sources... No big deal though as that was a fairly complcated piece of code (managed the creation of menus/toolbars too), while we 're after something simpler.

So, unless someone has a different opinion/proposition, I suggest that this patch is rejected and a discussion be started (at the forums) for managing the shortcuts issue centrally.

dmoore 2007-06-25 13:51

Personally, I don't care whether this patch is accepted or not, I was just responding to a user request (and I'd just spent a bunch of time working with the CC plugin so it was a minor effort).

Everything on the edit menu is context specific (also some of the search menu). I agree it's a little clumsy and that it would be very nice to have the SDK provide some sort of key/menu registry. the only problem is that context menus are dynamic so I think there will be quite a bit of work involved: a right click gives plugins the opportunity to tell the app what actions are appropriate for this context (at the same time the app sends data about the item clicked). With keystrokes, there is no opportunity to pre-fetch so you will need to send the data to the plugin after the keystroke.

IMO you should wait until post 1.0 and re-implement the more complicated "action-manager" you referred to, so action registration, menus, toolbars and keyboard shortcuts can be handled in a consistent, graceful way.

mandrav 2007-06-27 07:23

>>> IMO you should wait until post 1.0 and re-implement the more complicated "action-manager" you referred to, so action registration, menus, toolbars and keyboard shortcuts can be handled in a consistent, graceful way.

That was the plan. But with the sources gone, I don't think I 'm going to re-implement the "complex" action manager :).

I was merely talking about a "shortucts registry" of sorts...

dmoore 2007-07-18 23:55

>>> But with the sources gone, I don't think I 'm going to re-implement the "complex" action manager :).

Mandrav: I wouldn't mind taking a shot at this (for post v1.0). I'm thinking every plugin (plus the main app) should register all of its commands with a "MenuMgr" with details for each item including

* name

* icon

* id and/or callback

* default sub menu it appears in if it is a main menu command (need to be flexible enough to offer nested menu structures)

* list (bit-field) of context menu it appears in if it is a context driven command (should allow plugins to register their own context menus as candidates? e.g. my file explorer plugin)

* default keystroke

* supported states (enable/disable, check/uncheck etc)

MenuMgr will provide methods to enable/disable commands, move commands to different menus, change the ordering of context menu commands (including creation of context menu submenus), change keystroke etc.

For context menu commands, BuildModuleMenu will still be called, but it will ask plugins to _confirm_ whether their registered commands will be shown (or in the case of keystrokes, reject the keystroke if certain conditions aren't met)

The benefit of this will be a more user customisable experience (with respect to menu placement and keystrokes) but the cost will be quite a lot of changes to existing menuing code.

killerbot 2008-06-18 20:00

all parts except the classwizard has been implemented (that means : find decleration/implementation and open include file)

dmoore 2012-10-23 11:14

Indeed, I have started working on this. Still figuring out what is required, so will probably take a few more weeks. (Cringes at sight of 5 year old bug.)