Menu

[r1967]: / trunk / src / sdk / configuretoolsdlg.cpp  Maximize  Restore  History

Download this file

157 lines (136 with data), 4.5 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*
* This file is part of Code::Blocks Studio, an open-source cross-platform IDE
* Copyright (C) 2003 Yiannis An. Mandravellos
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact e-mail: Yiannis An. Mandravellos <mandrav@codeblocks.org>
* Program URL : http://www.codeblocks.org
*
* $Revision$
* $Id$
* $HeadURL$
*/
#include "sdk_precomp.h"
#ifndef CB_PRECOMP
#include <wx/intl.h>
#include <wx/xrc/xmlres.h>
#include <wx/button.h>
#include <wx/msgdlg.h>
#include <wx/listbox.h>
#include "manager.h"
#include "toolsmanager.h"
#include "globals.h"
#endif
#include "configuretoolsdlg.h"
#include "edittooldlg.h"
BEGIN_EVENT_TABLE(ConfigureToolsDlg, wxDialog)
EVT_BUTTON(XRCID("btnAdd"), ConfigureToolsDlg::OnAdd)
EVT_BUTTON(XRCID("btnEdit"), ConfigureToolsDlg::OnEdit)
EVT_BUTTON(XRCID("btnRemove"), ConfigureToolsDlg::OnRemove)
EVT_BUTTON(XRCID("btnUp"), ConfigureToolsDlg::OnUp)
EVT_BUTTON(XRCID("btnDown"), ConfigureToolsDlg::OnDown)
EVT_UPDATE_UI(-1, ConfigureToolsDlg::OnUpdateUI)
END_EVENT_TABLE()
ConfigureToolsDlg::ConfigureToolsDlg(wxWindow* parent)
{
wxXmlResource::Get()->LoadDialog(this, parent, _T("dlgConfigureTools"));
DoFillList();
}
ConfigureToolsDlg::~ConfigureToolsDlg()
{
}
void ConfigureToolsDlg::DoFillList()
{
wxListBox* list = XRCCTRL(*this, "lstTools", wxListBox);
list->Clear();
ToolsManager* toolMan = Manager::Get()->GetToolsManager();
int count = toolMan->GetToolsCount();
for (int i = 0; i < count; ++i)
{
Tool* tool = toolMan->GetToolByIndex(i);
if (tool)
list->Append(tool->name);
}
}
bool ConfigureToolsDlg::DoEditTool(Tool* tool)
{
if (!tool)
return false;
EditToolDlg dlg(this, tool);
DoFillList();
PlaceWindow(&dlg);
return dlg.ShowModal() == wxID_OK;
}
// events
void ConfigureToolsDlg::OnUpdateUI(wxUpdateUIEvent& event)
{
wxListBox* list = XRCCTRL(*this, "lstTools", wxListBox);
bool hasSel = list->GetSelection() != -1;
bool notFirst = list->GetSelection() > 0;
bool notLast = (list->GetSelection() < list->GetCount() -1) && hasSel;
XRCCTRL(*this, "btnEdit", wxButton)->Enable(hasSel);
XRCCTRL(*this, "btnRemove", wxButton)->Enable(hasSel);
XRCCTRL(*this, "btnUp", wxButton)->Enable(notFirst);
XRCCTRL(*this, "btnDown", wxButton)->Enable(notLast);
}
void ConfigureToolsDlg::OnAdd(wxCommandEvent& event)
{
Tool tool;
if (DoEditTool(&tool))
{
Manager::Get()->GetToolsManager()->AddTool(&tool);
DoFillList();
}
}
void ConfigureToolsDlg::OnEdit(wxCommandEvent& event)
{
wxListBox* list = XRCCTRL(*this, "lstTools", wxListBox);
Tool* tool = Manager::Get()->GetToolsManager()->GetToolByIndex(list->GetSelection());
DoEditTool(tool);
DoFillList();
}
void ConfigureToolsDlg::OnRemove(wxCommandEvent& event)
{
wxListBox* list = XRCCTRL(*this, "lstTools", wxListBox);
int sel = list->GetSelection();
if (wxMessageBox(_("Are you sure you want to remove this tool?"),
_("Remove tool?"),
wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION) == wxYES)
{
Manager::Get()->GetToolsManager()->RemoveToolByIndex(sel);
DoFillList();
}
}
void ConfigureToolsDlg::OnUp(wxCommandEvent& event)
{
wxListBox* list = XRCCTRL(*this, "lstTools", wxListBox);
int sel = list->GetSelection();
Tool tool(*(Manager::Get()->GetToolsManager()->GetToolByIndex(sel)));
Manager::Get()->GetToolsManager()->RemoveToolByIndex(sel);
Manager::Get()->GetToolsManager()->InsertTool(sel - 1, &tool);
DoFillList();
list->SetSelection(sel - 1);
}
void ConfigureToolsDlg::OnDown(wxCommandEvent& event)
{
wxListBox* list = XRCCTRL(*this, "lstTools", wxListBox);
int sel = list->GetSelection();
Tool tool(*(Manager::Get()->GetToolsManager()->GetToolByIndex(sel)));
Manager::Get()->GetToolsManager()->RemoveToolByIndex(sel);
Manager::Get()->GetToolsManager()->InsertTool(sel + 1, &tool);
DoFillList();
list->SetSelection(sel + 1);
}