Author Topic: Enhance our cc debug tool dialog  (Read 9631 times)

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6034
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Enhance our cc debug tool dialog
« on: January 25, 2015, 07:50:31 am »
The patch adds two "Go" button in the "CC debug info" dialog, so that user can click on the buttons to go to the token's declaration or definition position.

The bad thing is that the dialog is model, not non-model.

Another question is: Is the file location "src/wxsmith/CCDebugInfo.wxs" correct? Why not inside the "src/plugins/codecompletion/wxSmith"?


Code
e8fe6b92f149af5e7b206a3f4a61a1b0cbce40f6
 src/plugins/codecompletion/parser/ccdebuginfo.cpp | 66 ++++++++++++++++++++++-
 src/plugins/codecompletion/parser/ccdebuginfo.h   |  6 +++
 src/wxsmith/CCDebugInfo.wxs                       | 40 +++++++++++---
 3 files changed, 104 insertions(+), 8 deletions(-)

diff --git a/src/plugins/codecompletion/parser/ccdebuginfo.cpp b/src/plugins/codecompletion/parser/ccdebuginfo.cpp
index 42779f2..6454790 100644
--- a/src/plugins/codecompletion/parser/ccdebuginfo.cpp
+++ b/src/plugins/codecompletion/parser/ccdebuginfo.cpp
@@ -115,7 +115,9 @@ const long CCDebugInfo::ID_BUTTON3 = wxNewId();
 const long CCDebugInfo::ID_COMBOBOX1 = wxNewId();
 const long CCDebugInfo::ID_BUTTON2 = wxNewId();
 const long CCDebugInfo::ID_STATICTEXT26 = wxNewId();
+const long CCDebugInfo::ID_BUTTON7 = wxNewId();
 const long CCDebugInfo::ID_STATICTEXT28 = wxNewId();
+const long CCDebugInfo::ID_BUTTON8 = wxNewId();
 const long CCDebugInfo::ID_STATICTEXT35 = wxNewId();
 const long CCDebugInfo::ID_PANEL1 = wxNewId();
 const long CCDebugInfo::ID_LISTBOX1 = wxNewId();
@@ -149,6 +151,7 @@ CCDebugInfo::CCDebugInfo(wxWindow* parent, ParserBase* parser, Token* token) :
     wxBoxSizer* BoxSizer7;
     wxStaticText* lblName;
     wxBoxSizer* BoxSizer8;
+    wxButton* btnGoImpl;
     wxStaticText* lblIsConst;
     wxStaticText* lblTemplateArg;
     wxButton* btnGoAsc;
@@ -160,6 +163,7 @@ CCDebugInfo::CCDebugInfo(wxWindow* parent, ParserBase* parser, Token* token) :
     wxButton* btnGoParent;
     wxPanel* Panel1;
     wxBoxSizer* BoxSizer2;
+    wxButton* btnGoDecl;
     wxPanel* Panel3;
     wxStaticLine* StaticLine2;
     wxStaticText* lblNameSpace;
@@ -294,12 +298,20 @@ CCDebugInfo::CCDebugInfo(wxWindow* parent, ParserBase* parser, Token* token) :
     FlexGridSizer1->Add(BoxSizer5, 0, wxEXPAND|wxALIGN_LEFT|wxALIGN_TOP, 0);
     lblDeclFile = new wxStaticText(Panel1, wxID_ANY, _("Decl. filename:"), wxDefaultPosition, wxDefaultSize, 0, _T("wxID_ANY"));
     FlexGridSizer1->Add(lblDeclFile, 0, wxALIGN_LEFT|wxALIGN_TOP, 0);
+    BoxSizer11 = new wxBoxSizer(wxHORIZONTAL);
     txtDeclFile = new wxStaticText(Panel1, ID_STATICTEXT26, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT26"));
-    FlexGridSizer1->Add(txtDeclFile, 0, wxALIGN_LEFT|wxALIGN_TOP, 0);
+    BoxSizer11->Add(txtDeclFile, 1, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 0);
+    btnGoDecl = new wxButton(Panel1, ID_BUTTON7, _("Go"), wxDefaultPosition, wxSize(36,23), 0, wxDefaultValidator, _T("ID_BUTTON7"));
+    BoxSizer11->Add(btnGoDecl, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 0);
+    FlexGridSizer1->Add(BoxSizer11, 0, wxEXPAND|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 0);
     lblImplfile = new wxStaticText(Panel1, wxID_ANY, _("Impl. filename:"), wxDefaultPosition, wxDefaultSize, 0, _T("wxID_ANY"));
     FlexGridSizer1->Add(lblImplfile, 0, wxALIGN_LEFT|wxALIGN_TOP, 0);
+    BoxSizer12 = new wxBoxSizer(wxHORIZONTAL);
     txtImplFile = new wxStaticText(Panel1, ID_STATICTEXT28, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT28"));
-    FlexGridSizer1->Add(txtImplFile, 0, wxALIGN_LEFT|wxALIGN_TOP, 0);
+    BoxSizer12->Add(txtImplFile, 1, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 0);
+    btnGoImpl = new wxButton(Panel1, ID_BUTTON8, _("Go"), wxDefaultPosition, wxSize(36,23), 0, wxDefaultValidator, _T("ID_BUTTON8"));
+    BoxSizer12->Add(btnGoImpl, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 0);
+    FlexGridSizer1->Add(BoxSizer12, 0, wxEXPAND|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 0);
     lblUserData = new wxStaticText(Panel1, wxID_ANY, _("User data:"), wxDefaultPosition, wxDefaultSize, 0, _T("wxID_ANY"));
     FlexGridSizer1->Add(lblUserData, 0, wxALIGN_LEFT|wxALIGN_TOP, 0);
     txtUserData = new wxStaticText(Panel1, ID_STATICTEXT35, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT35"));
@@ -348,6 +360,8 @@ CCDebugInfo::CCDebugInfo(wxWindow* parent, ParserBase* parser, Token* token) :
     Connect(ID_BUTTON5,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&CCDebugInfo::OnGoChildrenClick);
     Connect(ID_BUTTON3,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&CCDebugInfo::OnGoAscClick);
     Connect(ID_BUTTON2,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&CCDebugInfo::OnGoDescClick);
+    Connect(ID_BUTTON7,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&CCDebugInfo::OnGoDeclClick);
+    Connect(ID_BUTTON8,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&CCDebugInfo::OnGoImplClick);
     Connect(ID_BUTTON6,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&CCDebugInfo::OnSave);
     Connect(wxID_ANY,wxEVT_INIT_DIALOG,(wxObjectEventFunction)&CCDebugInfo::OnInit);
     //*)
@@ -761,3 +775,51 @@ void CCDebugInfo::OnSave(cb_unused wxCommandEvent& event)
             cbMessageBox(_("Invalid selection."), _("CC Debug Info"));
     }
 }
+
+void CCDebugInfo::OnGoDeclClick(wxCommandEvent& event)
+{
+    wxString file;
+    int line;
+
+    if (m_Token && !m_Token->GetFilename().IsEmpty())
+    {
+        file = m_Token->GetFilename();
+        line = m_Token->m_Line;
+    }
+    else
+        return;
+
+    cbEditor* ed = (cbEditor*)Manager::Get()->GetEditorManager()->IsBuiltinOpen(file);
+    if (!ed)
+        ed = Manager::Get()->GetEditorManager()->Open(file);
+
+    if (ed)
+    {
+        ed->Activate();
+        ed->GotoLine(line);
+    }
+}
+
+void CCDebugInfo::OnGoImplClick(wxCommandEvent& event)
+{
+    wxString file;
+    int line;
+
+    if (m_Token && !m_Token->GetImplFilename().IsEmpty())
+    {
+        file = m_Token->GetImplFilename();
+        line = m_Token->m_ImplLine;
+    }
+    else
+        return;
+
+    cbEditor* ed = (cbEditor*)Manager::Get()->GetEditorManager()->IsBuiltinOpen(file);
+    if (!ed)
+        ed = Manager::Get()->GetEditorManager()->Open(file);
+
+    if (ed)
+    {
+        ed->Activate();
+        ed->GotoLine(line);
+    }
+}
diff --git a/src/plugins/codecompletion/parser/ccdebuginfo.h b/src/plugins/codecompletion/parser/ccdebuginfo.h
index 810104d..2d3f460 100644
--- a/src/plugins/codecompletion/parser/ccdebuginfo.h
+++ b/src/plugins/codecompletion/parser/ccdebuginfo.h
@@ -70,7 +70,9 @@ public:
     static const long ID_COMBOBOX1;
     static const long ID_BUTTON2;
     static const long ID_STATICTEXT26;
+    static const long ID_BUTTON7;
     static const long ID_STATICTEXT28;
+    static const long ID_BUTTON8;
     static const long ID_STATICTEXT35;
     static const long ID_PANEL1;
     static const long ID_LISTBOX1;
@@ -90,6 +92,8 @@ protected:
     void OnGoParentClick(wxCommandEvent& event);
     void OnGoChildrenClick(wxCommandEvent& event);
     void OnSave(wxCommandEvent& event);
+    void OnGoDeclClick(wxCommandEvent& event);
+    void OnGoImplClick(wxCommandEvent& event);
     //*)
 
     //(*Declarations(CCDebugInfo)
@@ -105,7 +109,9 @@ protected:
     wxStaticText* txtIsNoExcept;
     wxStaticText* txtImplFile;
     wxStaticText* txtScope;
+    wxBoxSizer* BoxSizer11;
     wxStaticText* txtID;
+    wxBoxSizer* BoxSizer12;
     wxListBox* lstDirs;
     wxStaticText* txtIsOp;
     wxStaticText* txtDeclFile;
diff --git a/src/wxsmith/CCDebugInfo.wxs b/src/wxsmith/CCDebugInfo.wxs
index a0f3388..85fe2cd 100644
--- a/src/wxsmith/CCDebugInfo.wxs
+++ b/src/wxsmith/CCDebugInfo.wxs
@@ -349,10 +349,24 @@
  <flag>wxALIGN_LEFT|wxALIGN_TOP</flag>
  </object>
  <object class="sizeritem">
- <object class="wxStaticText" name="ID_STATICTEXT26" variable="txtDeclFile" member="yes">
- <label></label>
+ <object class="wxBoxSizer" variable="BoxSizer11" member="yes">
+ <object class="sizeritem">
+ <object class="wxStaticText" name="ID_STATICTEXT26" variable="txtDeclFile" member="yes">
+ <label></label>
+ </object>
+ <flag>wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL</flag>
+ <option>1</option>
+ </object>
+ <object class="sizeritem">
+ <object class="wxButton" name="ID_BUTTON7" variable="btnGoDecl" member="no">
+ <label>Go</label>
+ <size>36,23</size>
+ <handler function="OnGoDeclClick" entry="EVT_BUTTON" />
+ </object>
+ <flag>wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL</flag>
+ </object>
  </object>
- <flag>wxALIGN_LEFT|wxALIGN_TOP</flag>
+ <flag>wxEXPAND|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL</flag>
  </object>
  <object class="sizeritem">
  <object class="wxStaticText" name="wxID_ANY" variable="lblImplfile" member="no">
@@ -361,10 +375,24 @@
  <flag>wxALIGN_LEFT|wxALIGN_TOP</flag>
  </object>
  <object class="sizeritem">
- <object class="wxStaticText" name="ID_STATICTEXT28" variable="txtImplFile" member="yes">
- <label></label>
+ <object class="wxBoxSizer" variable="BoxSizer12" member="yes">
+ <object class="sizeritem">
+ <object class="wxStaticText" name="ID_STATICTEXT28" variable="txtImplFile" member="yes">
+ <label></label>
+ </object>
+ <flag>wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL</flag>
+ <option>1</option>
+ </object>
+ <object class="sizeritem">
+ <object class="wxButton" name="ID_BUTTON8" variable="btnGoImpl" member="no">
+ <label>Go</label>
+ <size>36,23</size>
+ <handler function="OnGoImplClick" entry="EVT_BUTTON" />
+ </object>
+ <flag>wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL</flag>
+ </object>
  </object>
- <flag>wxALIGN_LEFT|wxALIGN_TOP</flag>
+ <flag>wxEXPAND|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL</flag>
  </object>
  <object class="sizeritem">
  <object class="wxStaticText" name="wxID_ANY" variable="lblUserData" member="no">
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: Enhance our cc debug tool dialog
« Reply #1 on: January 25, 2015, 10:47:19 am »
Another question is: Is the file location "src/wxsmith/CCDebugInfo.wxs" correct? Why not inside the "src/plugins/codecompletion/wxSmith"?
Nope it is not correct...
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9693
Re: Enhance our cc debug tool dialog
« Reply #2 on: January 25, 2015, 12:18:36 pm »
It is a limitation of wxsmith. Because the cc plugin is a target of the cb project all wxsmith items are stored it that folder. The other wxsmith files in the cc folder do not belong to the cb project.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ