~ubuntu-branches/ubuntu/lucid/codelite/lucid

« back to all changes in this revision

Viewing changes to ExternalTools/externaltooldlg.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Chow Loong Jin
  • Date: 2009-01-12 15:46:55 UTC
  • Revision ID: james.westby@ubuntu.com-20090112154655-sdynrljcb6u167yw
Tags: upstream-1.0.2674+dfsg
ImportĀ upstreamĀ versionĀ 1.0.2674+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//////////////////////////////////////////////////////////////////////////////
 
2
//////////////////////////////////////////////////////////////////////////////
 
3
//
 
4
// copyright            : (C) 2008 by Eran Ifrah                            
 
5
// file name            : externaltooldlg.cpp              
 
6
//                                                                          
 
7
// -------------------------------------------------------------------------
 
8
// A                                                                        
 
9
//              _____           _      _     _ _                            
 
10
//             /  __ \         | |    | |   (_) |                           
 
11
//             | /  \/ ___   __| | ___| |    _| |_ ___                      
 
12
//             | |    / _ \ / _  |/ _ \ |   | | __/ _ )                     
 
13
//             | \__/\ (_) | (_| |  __/ |___| | ||  __/                     
 
14
//              \____/\___/ \__,_|\___\_____/_|\__\___|                     
 
15
//                                                                          
 
16
//                                                  F i l e                 
 
17
//                                                                          
 
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.                                   
 
22
//                                                                          
 
23
//////////////////////////////////////////////////////////////////////////////
 
24
//////////////////////////////////////////////////////////////////////////////
 
25
 
 
26
#include "globals.h"
 
27
#include <wx/msgdlg.h>
 
28
#include "externaltoolsdata.h"
 
29
#include "newtooldlg.h"
 
30
#include "externaltooldlg.h"
 
31
 
 
32
ExternalToolDlg::ExternalToolDlg( wxWindow* parent, IManager *mgr )
 
33
                : ExternalToolBaseDlg( parent )
 
34
                , m_item(wxNOT_FOUND)
 
35
                , m_mgr(mgr)
 
36
{
 
37
        Initialize();
 
38
        m_listCtrlTools->SetFocus();
 
39
}
 
40
 
 
41
void ExternalToolDlg::OnItemActivated( wxListEvent& event )
 
42
{
 
43
        m_item = event.m_itemIndex;
 
44
        DoEditEntry(event.m_itemIndex);
 
45
}
 
46
 
 
47
void ExternalToolDlg::OnItemDeSelected( wxListEvent& event )
 
48
{
 
49
        wxUnusedVar(event);
 
50
        m_item = wxNOT_FOUND;
 
51
}
 
52
 
 
53
void ExternalToolDlg::OnItemSelected( wxListEvent& event )
 
54
{
 
55
        m_item = event.m_itemIndex;
 
56
}
 
57
 
 
58
void ExternalToolDlg::OnButtonNew( wxCommandEvent& event )
 
59
{
 
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(), 
 
63
                                                dlg.GetToolName(), 
 
64
                                                dlg.GetPath(), 
 
65
                                                dlg.GetWorkingDirectory(), 
 
66
                                                dlg.GetArguments(), 
 
67
                                                dlg.GetIcon16(), 
 
68
                                                dlg.GetIcon24(), 
 
69
                                                dlg.GetCaptureProcessOutput(),
 
70
                                                dlg.GetSaveAllFiles());
 
71
        }
 
72
}
 
73
 
 
74
void ExternalToolDlg::OnButtonNewUI( wxUpdateUIEvent& event )
 
75
{
 
76
        // maximum of 10 items
 
77
        event.Enable(m_listCtrlTools->GetItemCount() < MAX_TOOLS);
 
78
}
 
79
 
 
80
void ExternalToolDlg::OnButtonEdit( wxCommandEvent& event )
 
81
{
 
82
        wxUnusedVar(event);
 
83
        DoEditEntry(m_item);
 
84
}
 
85
 
 
86
void ExternalToolDlg::OnButtonEditUI( wxUpdateUIEvent& event )
 
87
{
 
88
        event.Enable(m_item != wxNOT_FOUND);
 
89
}
 
90
 
 
91
void ExternalToolDlg::OnButtonDelete( wxCommandEvent& event )
 
92
{
 
93
        if(wxMessageBox(_("Are you sure you want to delete this tool?"), wxT("CodeLite"), wxYES_NO|wxCANCEL) == wxYES){
 
94
                m_listCtrlTools->DeleteItem(m_item);
 
95
        }
 
96
}
 
97
 
 
98
void ExternalToolDlg::OnButtonDeleteUI( wxUpdateUIEvent& event )
 
99
{
 
100
        event.Enable(m_item != wxNOT_FOUND);
 
101
}
 
102
 
 
103
void ExternalToolDlg::Initialize()
 
104
{
 
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"));
 
114
 
 
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);
 
125
}
 
126
 
 
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)
 
128
{
 
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){
 
133
                        item = i;
 
134
                        break;
 
135
                }
 
136
        }
 
137
        
 
138
        // append new row
 
139
        if(item == wxNOT_FOUND){
 
140
                item = AppendListCtrlRow(m_listCtrlTools);
 
141
        }
 
142
        
 
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"));
 
152
        
 
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);
 
162
}
 
163
 
 
164
void ExternalToolDlg::DoEditEntry(long item)
 
165
{
 
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;
 
175
        
 
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(), 
 
179
                                                dlg.GetToolName(), 
 
180
                                                dlg.GetPath(), 
 
181
                                                dlg.GetWorkingDirectory(), 
 
182
                                                dlg.GetArguments(), 
 
183
                                                dlg.GetIcon16(), 
 
184
                                                dlg.GetIcon24(), 
 
185
                                                dlg.GetCaptureProcessOutput(),
 
186
                                                dlg.GetSaveAllFiles());
 
187
        }
 
188
}
 
189
 
 
190
std::vector<ToolInfo> ExternalToolDlg::GetTools()
 
191
{
 
192
        std::vector<ToolInfo> tools;
 
193
        for(size_t i=0; i<(size_t)m_listCtrlTools->GetItemCount(); i++){
 
194
                ToolInfo ti;
 
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);
 
204
                tools.push_back(ti);
 
205
        }
 
206
        return tools;
 
207
}
 
208
 
 
209
void ExternalToolDlg::SetTools(const std::vector<ToolInfo>& tools)
 
210
{
 
211
        m_listCtrlTools->Freeze();
 
212
        m_listCtrlTools->DeleteAllItems();
 
213
        
 
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"));
 
226
        }
 
227
        
 
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);
 
237
        
 
238
        m_listCtrlTools->Thaw();
 
239
}