File: externaltooldlg.cpp

package info (click to toggle)
codelite 6.1.1%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 48,992 kB
  • ctags: 43,502
  • sloc: cpp: 334,263; ansic: 18,441; xml: 4,713; yacc: 2,653; lex: 2,449; python: 1,188; sh: 385; makefile: 40
file content (211 lines) | stat: -rw-r--r-- 6,494 bytes parent folder | download
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright            : (C) 2008 by Eran Ifrah
// file name            : externaltooldlg.cpp
//
// -------------------------------------------------------------------------
// A
//              _____           _      _     _ _
//             /  __ \         | |    | |   (_) |
//             | /  \/ ___   __| | ___| |    _| |_ ___
//             | |    / _ \ / _  |/ _ \ |   | | __/ _ )
//             | \__/\ (_) | (_| |  __/ |___| | ||  __/
//              \____/\___/ \__,_|\___\_____/_|\__\___|
//
//                                                  F i l e
//
//    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.
//
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////

#include "globals.h"
#include <wx/clntdata.h>
#include <wx/msgdlg.h>
#include "externaltoolsdata.h"
#include "newtooldlg.h"
#include "externaltooldlg.h"


ExternalToolDlg::ExternalToolDlg( wxWindow* parent, IManager *mgr )
		: ExternalToolBaseDlg( parent )
		, m_item(wxNOT_FOUND)
		, m_mgr(mgr)
{
	Initialize();
	m_listCtrlTools->SetFocus();
}

void ExternalToolDlg::OnItemActivated( wxListEvent& event )
{
	m_item = event.m_itemIndex;
	DoEditEntry(event.m_itemIndex);
}

void ExternalToolDlg::OnItemDeSelected( wxListEvent& event )
{
	wxUnusedVar(event);
	m_item = wxNOT_FOUND;
}

void ExternalToolDlg::OnItemSelected( wxListEvent& event )
{
	m_item = event.m_itemIndex;
}

void ExternalToolDlg::OnButtonNew( wxCommandEvent& event )
{
	NewToolDlg dlg(this, m_mgr, NULL);
	if (dlg.ShowModal() == wxID_OK) {
		DoUpdateEntry( dlg.GetToolId(),
		               dlg.GetToolName(),
		               dlg.GetPath(),
		               dlg.GetWorkingDirectory(),
		               dlg.GetArguments(),
		               dlg.GetIcon16(),
		               dlg.GetIcon24(),
		               dlg.GetCaptureProcessOutput(),
		               dlg.GetSaveAllFiles());
	}
}

void ExternalToolDlg::OnButtonNewUI( wxUpdateUIEvent& event )
{
	// maximum of 10 items
	event.Enable(m_listCtrlTools->GetItemCount() < MAX_TOOLS);
}

void ExternalToolDlg::OnButtonEdit( wxCommandEvent& event )
{
	wxUnusedVar(event);
	DoEditEntry(m_item);
}

void ExternalToolDlg::OnButtonEditUI( wxUpdateUIEvent& event )
{
	event.Enable(m_item != wxNOT_FOUND);
}

void ExternalToolDlg::OnButtonDelete( wxCommandEvent& event )
{
	if (wxMessageBox(_("Are you sure you want to delete this tool?"), _("CodeLite"), wxYES_NO|wxCANCEL) == wxYES) {
		m_listCtrlTools->DeleteItem(m_item);
	}
}

void ExternalToolDlg::OnButtonDeleteUI( wxUpdateUIEvent& event )
{
	event.Enable(m_item != wxNOT_FOUND);
}

void ExternalToolDlg::Initialize()
{
	m_listCtrlTools->InsertColumn(0, _("ID"));
	m_listCtrlTools->InsertColumn(1, _("Name"));
	m_listCtrlTools->InsertColumn(2, _("Path"));

	m_listCtrlTools->SetColumnWidth(0, 200);
	m_listCtrlTools->SetColumnWidth(1, 200);
	m_listCtrlTools->SetColumnWidth(2, 200);
}

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)
{
	// try to see if 'id' already exist in the list control
	long item(wxNOT_FOUND);
	for (size_t i=0; i<(size_t)m_listCtrlTools->GetItemCount(); i++) {
		if (GetColumnText(m_listCtrlTools, i, 0) == id) {
			item = i;

			// Delete old data
			ExternalToolData* data = (ExternalToolData*)m_listCtrlTools->GetItemData(item);
			if ( data )
				delete data;

			break;
		}
	}

	// append new row
	if (item == wxNOT_FOUND) {
		item = AppendListCtrlRow(m_listCtrlTools);
	}

	SetColumnText(m_listCtrlTools, item, 0, id);
	SetColumnText(m_listCtrlTools, item, 1, name);
	SetColumnText(m_listCtrlTools, item, 2, path);

	ExternalToolData* data = new ExternalToolData(id, name, path, workingDirectory, arguments, icon16, icon24, captureOutput, saveAllFiles);
	m_listCtrlTools->SetItemPtrData(item, wxUIntPtr(data));
}

void ExternalToolDlg::DoEditEntry(long item)
{
	ExternalToolData* data = (ExternalToolData*)m_listCtrlTools->GetItemData(item);
	NewToolDlg dlg(this, m_mgr, data);
	if (dlg.ShowModal() == wxID_OK) {
		DoUpdateEntry(	dlg.GetToolId(),
		               dlg.GetToolName(),
		               dlg.GetPath(),
		               dlg.GetWorkingDirectory(),
		               dlg.GetArguments(),
		               dlg.GetIcon16(),
		               dlg.GetIcon24(),
		               dlg.GetCaptureProcessOutput(),
		               dlg.GetSaveAllFiles());
	}
}

std::vector<ToolInfo> ExternalToolDlg::GetTools()
{
	std::vector<ToolInfo> tools;
	for (size_t i=0; i<(size_t)m_listCtrlTools->GetItemCount(); i++) {

		ToolInfo ti;
		ExternalToolData* data = (ExternalToolData*)m_listCtrlTools->GetItemData(i);

		if(data) {
			ti.SetId(data->m_id);
			ti.SetName(data->m_name);
			ti.SetPath(data->m_path);
			ti.SetArguments(data->m_args);
			ti.SetWd(data->m_workingDirectory);
			ti.SetIcon16(data->m_icon16);
			ti.SetIcon24(data->m_icon24);
			ti.SetCaptureOutput(data->m_captureOutput);
			ti.SetSaveAllFiles(data->m_saveAllFiles);
			tools.push_back(ti);
		}
	}
	return tools;
}

void ExternalToolDlg::SetTools(const std::vector<ToolInfo>& tools)
{
	m_listCtrlTools->Freeze();
	for(size_t i=0; i<(size_t)m_listCtrlTools->GetItemCount(); i++) {
		ExternalToolData* data = (ExternalToolData*)m_listCtrlTools->GetItemData(i);
		if(data) {
			delete data;
		}
	}
	m_listCtrlTools->DeleteAllItems();

	for (size_t i=0; i<tools.size(); i++) {
		ToolInfo ti = tools.at(i);
		long item = AppendListCtrlRow(m_listCtrlTools);

		ExternalToolData *data = new ExternalToolData(ti);
		m_listCtrlTools->SetItemPtrData(item, wxUIntPtr(data));

		SetColumnText(m_listCtrlTools, item, 0, ti.GetId());
		SetColumnText(m_listCtrlTools, item, 1, ti.GetName());
		SetColumnText(m_listCtrlTools, item, 2, ti.GetPath());
	}

	m_listCtrlTools->Thaw();
}