1
//////////////////////////////////////////////////////////////////////////////
2
//////////////////////////////////////////////////////////////////////////////
4
// copyright : (C) 2008 by Eran Ifrah
5
// file name : externaltooldlg.cpp
7
// -------------------------------------------------------------------------
10
// / __ \ | | | | (_) |
11
// | / \/ ___ __| | ___| | _| |_ ___
12
// | | / _ \ / _ |/ _ \ | | | __/ _ )
13
// | \__/\ (_) | (_| | __/ |___| | || __/
14
// \____/\___/ \__,_|\___\_____/_|\__\___|
18
// This program is free software; you can redistribute it and/or modify
19
// it under the terms of the GNU General Public License as published by
20
// the Free Software Foundation; either version 2 of the License, or
21
// (at your option) any later version.
23
//////////////////////////////////////////////////////////////////////////////
24
//////////////////////////////////////////////////////////////////////////////
27
#include <wx/msgdlg.h>
28
#include "externaltoolsdata.h"
29
#include "newtooldlg.h"
30
#include "externaltooldlg.h"
32
ExternalToolDlg::ExternalToolDlg( wxWindow* parent, IManager *mgr )
33
: ExternalToolBaseDlg( parent )
38
m_listCtrlTools->SetFocus();
41
void ExternalToolDlg::OnItemActivated( wxListEvent& event )
43
m_item = event.m_itemIndex;
44
DoEditEntry(event.m_itemIndex);
47
void ExternalToolDlg::OnItemDeSelected( wxListEvent& event )
53
void ExternalToolDlg::OnItemSelected( wxListEvent& event )
55
m_item = event.m_itemIndex;
58
void ExternalToolDlg::OnButtonNew( wxCommandEvent& event )
60
NewToolDlg dlg(this, m_mgr, wxEmptyString, wxEmptyString, wxEmptyString, wxEmptyString, wxEmptyString, wxEmptyString, wxEmptyString, false, false);
61
if (dlg.ShowModal() == wxID_OK) {
62
DoUpdateEntry( dlg.GetToolId(),
65
dlg.GetWorkingDirectory(),
69
dlg.GetCaptureProcessOutput(),
70
dlg.GetSaveAllFiles());
74
void ExternalToolDlg::OnButtonNewUI( wxUpdateUIEvent& event )
76
// maximum of 10 items
77
event.Enable(m_listCtrlTools->GetItemCount() < MAX_TOOLS);
80
void ExternalToolDlg::OnButtonEdit( wxCommandEvent& event )
86
void ExternalToolDlg::OnButtonEditUI( wxUpdateUIEvent& event )
88
event.Enable(m_item != wxNOT_FOUND);
91
void ExternalToolDlg::OnButtonDelete( wxCommandEvent& event )
93
if(wxMessageBox(_("Are you sure you want to delete this tool?"), wxT("CodeLite"), wxYES_NO|wxCANCEL) == wxYES){
94
m_listCtrlTools->DeleteItem(m_item);
98
void ExternalToolDlg::OnButtonDeleteUI( wxUpdateUIEvent& event )
100
event.Enable(m_item != wxNOT_FOUND);
103
void ExternalToolDlg::Initialize()
105
m_listCtrlTools->InsertColumn(0, wxT("ID"));
106
m_listCtrlTools->InsertColumn(1, wxT("Name"));
107
m_listCtrlTools->InsertColumn(2, wxT("Path"));
108
m_listCtrlTools->InsertColumn(3, wxT("Arguments"));
109
m_listCtrlTools->InsertColumn(4, wxT("Working directory"));
110
m_listCtrlTools->InsertColumn(5, wxT("Small Icon"));
111
m_listCtrlTools->InsertColumn(6, wxT("Large Icon"));
112
m_listCtrlTools->InsertColumn(7, wxT("Capture Output"));
113
m_listCtrlTools->InsertColumn(8, wxT("Save All Files"));
115
// TODO: populate the list from the settings
116
m_listCtrlTools->SetColumnWidth(0, 100);
117
m_listCtrlTools->SetColumnWidth(1, 100);
118
m_listCtrlTools->SetColumnWidth(2, 100);
119
m_listCtrlTools->SetColumnWidth(3, 100);
120
m_listCtrlTools->SetColumnWidth(4, 100);
121
m_listCtrlTools->SetColumnWidth(5, 100);
122
m_listCtrlTools->SetColumnWidth(6, 100);
123
m_listCtrlTools->SetColumnWidth(7, 100);
124
m_listCtrlTools->SetColumnWidth(8, 100);
127
void ExternalToolDlg::DoUpdateEntry(const wxString& id, const wxString& name, const wxString& path, const wxString& workingDirectory, const wxString& arguments, const wxString &icon16, const wxString &icon24, bool captureOutput, bool saveAllFiles)
129
// try to see if 'id' already exist in the list control
130
long item(wxNOT_FOUND);
131
for(size_t i=0; i<(size_t)m_listCtrlTools->GetItemCount(); i++){
132
if(GetColumnText(m_listCtrlTools, i, 0) == id){
139
if(item == wxNOT_FOUND){
140
item = AppendListCtrlRow(m_listCtrlTools);
143
SetColumnText(m_listCtrlTools, item, 0, id);
144
SetColumnText(m_listCtrlTools, item, 1, name);
145
SetColumnText(m_listCtrlTools, item, 2, path);
146
SetColumnText(m_listCtrlTools, item, 3, arguments);
147
SetColumnText(m_listCtrlTools, item, 4, workingDirectory);
148
SetColumnText(m_listCtrlTools, item, 5, icon16);
149
SetColumnText(m_listCtrlTools, item, 6, icon24);
150
SetColumnText(m_listCtrlTools, item, 7, captureOutput ? wxT("Yes") : wxT("No"));
151
SetColumnText(m_listCtrlTools, item, 8, saveAllFiles ? wxT("Yes") : wxT("No"));
153
m_listCtrlTools->SetColumnWidth(0, 150);
154
m_listCtrlTools->SetColumnWidth(1, wxLIST_AUTOSIZE);
155
m_listCtrlTools->SetColumnWidth(2, wxLIST_AUTOSIZE);
156
m_listCtrlTools->SetColumnWidth(3, wxLIST_AUTOSIZE);
157
m_listCtrlTools->SetColumnWidth(4, wxLIST_AUTOSIZE);
158
m_listCtrlTools->SetColumnWidth(5, wxLIST_AUTOSIZE);
159
m_listCtrlTools->SetColumnWidth(6, wxLIST_AUTOSIZE);
160
m_listCtrlTools->SetColumnWidth(7, wxLIST_AUTOSIZE);
161
m_listCtrlTools->SetColumnWidth(8, wxLIST_AUTOSIZE);
164
void ExternalToolDlg::DoEditEntry(long item)
166
wxString id = GetColumnText(m_listCtrlTools, m_item, 0);
167
wxString name = GetColumnText(m_listCtrlTools, m_item, 1);
168
wxString path = GetColumnText(m_listCtrlTools, m_item, 2);
169
wxString args = GetColumnText(m_listCtrlTools, m_item, 3);
170
wxString wd = GetColumnText(m_listCtrlTools, m_item, 4);
171
wxString icon16 = GetColumnText(m_listCtrlTools, m_item, 5);
172
wxString icon24 = GetColumnText(m_listCtrlTools, m_item, 6);
173
bool captureOutput = GetColumnText(m_listCtrlTools, m_item, 7) == wxT("Yes") ? true : false;
174
bool saveAllFiles = GetColumnText(m_listCtrlTools, m_item, 8) == wxT("Yes") ? true : false;
176
NewToolDlg dlg(this, m_mgr, id, name, path, wd, args, icon16, icon24, captureOutput, saveAllFiles);
177
if (dlg.ShowModal() == wxID_OK) {
178
DoUpdateEntry( dlg.GetToolId(),
181
dlg.GetWorkingDirectory(),
185
dlg.GetCaptureProcessOutput(),
186
dlg.GetSaveAllFiles());
190
std::vector<ToolInfo> ExternalToolDlg::GetTools()
192
std::vector<ToolInfo> tools;
193
for(size_t i=0; i<(size_t)m_listCtrlTools->GetItemCount(); i++){
195
ti.SetId(GetColumnText(m_listCtrlTools, i, 0));
196
ti.SetName(GetColumnText(m_listCtrlTools, i, 1));
197
ti.SetPath(GetColumnText(m_listCtrlTools, i, 2));
198
ti.SetArguments(GetColumnText(m_listCtrlTools, i, 3));
199
ti.SetWd(GetColumnText(m_listCtrlTools, i, 4));
200
ti.SetIcon16(GetColumnText(m_listCtrlTools, i, 5));
201
ti.SetIcon24(GetColumnText(m_listCtrlTools, i, 6));
202
ti.SetCaptureOutput(GetColumnText(m_listCtrlTools, i, 7) == wxT("Yes") ? true : false);
203
ti.SetSaveAllFiles(GetColumnText(m_listCtrlTools, i, 8) == wxT("Yes") ? true : false);
209
void ExternalToolDlg::SetTools(const std::vector<ToolInfo>& tools)
211
m_listCtrlTools->Freeze();
212
m_listCtrlTools->DeleteAllItems();
214
for(size_t i=0; i<tools.size(); i++){
215
ToolInfo ti = tools.at(i);
216
long item = AppendListCtrlRow(m_listCtrlTools);
217
SetColumnText(m_listCtrlTools, item, 0, ti.GetId());
218
SetColumnText(m_listCtrlTools, item, 1, ti.GetName());
219
SetColumnText(m_listCtrlTools, item, 2, ti.GetPath());
220
SetColumnText(m_listCtrlTools, item, 3, ti.GetArguments());
221
SetColumnText(m_listCtrlTools, item, 4, ti.GetWd());
222
SetColumnText(m_listCtrlTools, item, 5, ti.GetIcon16());
223
SetColumnText(m_listCtrlTools, item, 6, ti.GetIcon24());
224
SetColumnText(m_listCtrlTools, item, 7, ti.GetCaptureOutput() ? wxT("Yes") : wxT("No"));
225
SetColumnText(m_listCtrlTools, item, 8, ti.GetSaveAllFiles() ? wxT("Yes") : wxT("No"));
228
m_listCtrlTools->SetColumnWidth(0, 150);
229
m_listCtrlTools->SetColumnWidth(1, wxLIST_AUTOSIZE);
230
m_listCtrlTools->SetColumnWidth(2, wxLIST_AUTOSIZE);
231
m_listCtrlTools->SetColumnWidth(3, wxLIST_AUTOSIZE);
232
m_listCtrlTools->SetColumnWidth(4, wxLIST_AUTOSIZE);
233
m_listCtrlTools->SetColumnWidth(5, wxLIST_AUTOSIZE);
234
m_listCtrlTools->SetColumnWidth(6, wxLIST_AUTOSIZE);
235
m_listCtrlTools->SetColumnWidth(7, wxLIST_AUTOSIZE);
236
m_listCtrlTools->SetColumnWidth(8, wxLIST_AUTOSIZE);
238
m_listCtrlTools->Thaw();