Code::Blocks  SVN r11506
configuretoolsdlg.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the Code::Blocks IDE and licensed under the GNU Lesser General Public License, version 3
3  * http://www.gnu.org/licenses/lgpl-3.0.html
4  *
5  * $Revision: 10912 $
6  * $Id: configuretoolsdlg.cpp 10912 2016-09-25 16:10:13Z fuscated $
7  * $HeadURL: https://svn.code.sf.net/p/codeblocks/code/trunk/src/sdk/configuretoolsdlg.cpp $
8  */
9 
10 #include "sdk_precomp.h"
11 
12 #ifndef CB_PRECOMP
13  #include <wx/button.h>
14  #include <wx/intl.h>
15  #include <wx/listbox.h>
16  #include <wx/string.h>
17  #include <wx/xrc/xmlres.h>
18 
19  #include "manager.h"
20  #include "cbtool.h"
21  #include "toolsmanager.h"
22  #include "globals.h"
23 #endif
24 
25 #include "configuretoolsdlg.h"
26 #include "edittooldlg.h"
27 
28 BEGIN_EVENT_TABLE(ConfigureToolsDlg, wxScrollingDialog)
29  EVT_BUTTON(XRCID("btnAdd"), ConfigureToolsDlg::OnAdd)
30  EVT_BUTTON(XRCID("btnEdit"), ConfigureToolsDlg::OnEdit)
31  EVT_BUTTON(XRCID("btnRemove"), ConfigureToolsDlg::OnRemove)
32  EVT_BUTTON(XRCID("btnAddSeparator"), ConfigureToolsDlg::OnAddSeparator)
33  EVT_BUTTON(XRCID("btnUp"), ConfigureToolsDlg::OnUp)
34  EVT_BUTTON(XRCID("btnDown"), ConfigureToolsDlg::OnDown)
35  EVT_UPDATE_UI(-1, ConfigureToolsDlg::OnUpdateUI)
36 END_EVENT_TABLE()
37 
39 {
40  wxXmlResource::Get()->LoadObject(this, parent, _T("dlgConfigureTools"),_T("wxScrollingDialog"));
41  XRCCTRL(*this, "wxID_OK", wxButton)->SetDefault();
42  DoFillList();
43 } // end of constructor
44 
46 {
47 }
48 
50 {
51  wxListBox* list = XRCCTRL(*this, "lstTools", wxListBox);
52  list->Clear();
54  int count = toolMan->GetToolsCount();
55  for (int i = 0; i < count; ++i)
56  {
57  if(const cbTool* tool = toolMan->GetToolByIndex(i))
58  {
59  list->Append(tool->GetName());
60  }
61  }
62 } // end of DoFillList
63 
65 {
66  if (!tool)
67  return false;
68  EditToolDlg dlg(this, tool);
69  PlaceWindow(&dlg);
70  return dlg.ShowModal() == wxID_OK;
71 } // end of DoEditTool
72 
73 // events
74 
76 {
77  const wxListBox* list = XRCCTRL(*this, "lstTools", wxListBox);
78  bool hasSel = list->GetSelection() != -1;
79  bool notFirst = list->GetSelection() > 0;
80  bool notLast = (list->GetSelection() < (int)(list->GetCount()) -1) && hasSel;
81  bool notSeparator = true;
82 
83  if(hasSel)
84  notSeparator = Manager::Get()->GetToolsManager()->GetToolByIndex(list->GetSelection())->GetName() != CB_TOOLS_SEPARATOR;
85 
86  XRCCTRL(*this, "btnEdit", wxButton)->Enable(hasSel && notSeparator);
87  XRCCTRL(*this, "btnRemove", wxButton)->Enable(hasSel);
88  XRCCTRL(*this, "btnUp", wxButton)->Enable(notFirst);
89  XRCCTRL(*this, "btnDown", wxButton)->Enable(notLast);
90 } // end of OnUpdateUI
91 
93 {
94  cbTool tool;
95  if (DoEditTool(&tool))
96  {
98  DoFillList();
99  }
100 } // end of OnAdd
101 
103 {
104  const wxListBox* list = XRCCTRL(*this, "lstTools", wxListBox);
105  cbTool* tool = Manager::Get()->GetToolsManager()->GetToolByIndex(list->GetSelection());
106  DoEditTool(tool);
107  DoFillList();
108 } // end of OnEdit
109 
111 {
112  const wxListBox* list = XRCCTRL(*this, "lstTools", wxListBox);
113  int sel = list->GetSelection();
114  if (Manager::Get()->GetToolsManager()->GetToolByIndex(sel)->GetName() == CB_TOOLS_SEPARATOR
115  || cbMessageBox(_("Are you sure you want to remove this tool?"),
116  _("Remove tool?"),
118  {
120  DoFillList();
121  }
122 } // end of OnRemove
123 
125 {
126  cbTool tool;
129  Manager::Get()->GetToolsManager()->AddTool(&tool);
130  DoFillList();
131 } // end of OnAddSeparator
132 
134 {
135  wxListBox* list = XRCCTRL(*this, "lstTools", wxListBox);
136  int sel = list->GetSelection();
137 
138  cbTool tool(*(Manager::Get()->GetToolsManager()->GetToolByIndex(sel)));
140  Manager::Get()->GetToolsManager()->InsertTool(sel - 1, &tool);
141  DoFillList();
142  list->SetSelection(sel - 1);
143 } // end of OnUp
144 
146 {
147  wxListBox* list = XRCCTRL(*this, "lstTools", wxListBox);
148  int sel = list->GetSelection();
149 
150  cbTool tool(*(Manager::Get()->GetToolsManager()->GetToolByIndex(sel)));
152  Manager::Get()->GetToolsManager()->InsertTool(sel + 1, &tool);
153  DoFillList();
154  list->SetSelection(sel + 1);
155 }// end of OnDown
void RemoveToolByIndex(int index)
void OnAddSeparator(wxCommandEvent &event)
#define wxICON_QUESTION
void OnUpdateUI(wxUpdateUIEvent &event)
static Manager * Get()
Use Manager::Get() to get a pointer to its instance Manager::Get() is guaranteed to never return an i...
Definition: manager.cpp:182
Definition: cbtool.h:13
void OnEdit(wxCommandEvent &event)
void OnUp(wxCommandEvent &event)
void OnRemove(wxCommandEvent &event)
bool DoEditTool(cbTool *tool)
#define wxNO_DEFAULT
#define _T(string)
#define wxYES_NO
int GetToolsCount() const
Definition: toolsmanager.h:35
void AddTool(const cbTool *tool, bool save=true)
void OnAdd(wxCommandEvent &event)
ToolsManager * GetToolsManager() const
Definition: manager.cpp:449
virtual int ShowModal()
const wxString & _(const wxString &string)
void InsertTool(int position, const cbTool *tool, bool save=true)
DLLIMPORT void PlaceWindow(wxTopLevelWindow *w, cbPlaceDialogMode mode=pdlBest, bool enforce=false)
Definition: globals.cpp:1177
#define CB_TOOLS_SEPARATOR
Definition: cbtool.h:11
void SetCommand(const wxString &Command)
Definition: cbtool.h:34
void OnDown(wxCommandEvent &event)
static wxXmlResource * Get()
cbTool * GetToolByIndex(int index)
void SetName(const wxString &Name)
Definition: cbtool.h:33
wxObject * LoadObject(wxWindow *parent, const wxString &name, const wxString &classname)
DLLIMPORT int cbMessageBox(const wxString &message, const wxString &caption=wxEmptyString, int style=wxOK, wxWindow *parent=NULL, int x=-1, int y=-1)
wxMessageBox wrapper.
Definition: globals.cpp:1395
~ConfigureToolsDlg() override