1
//////////////////////////////////////////////////////////////////////////////
2
//////////////////////////////////////////////////////////////////////////////
4
// copyright : (C) 2008 by Eran Ifrah
5
// file name : open_resouce_dlg.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
//////////////////////////////////////////////////////////////////////////////
25
///////////////////////////////////////////////////////////////////////////
26
// C++ code generated with wxFormBuilder (version May 5 2007)
27
// http://www.wxformbuilder.org/
29
// PLEASE DO "NOT" EDIT THIS FILE!
30
///////////////////////////////////////////////////////////////////////////
31
#include "editor_config.h"
35
#include "wx/wxprec.h"
45
#include "open_resouce_dlg.h"
49
///////////////////////////////////////////////////////////////////////////
50
BEGIN_EVENT_TABLE(OpenResourceDlg, wxDialog)
51
EVT_CHAR_HOOK(OpenResourceDlg::OnCharHook)
54
OpenResourceDlg::OpenResourceDlg( wxWindow* parent, int id, wxString title, wxPoint pos, wxSize size, int style )
55
: wxDialog( parent, id, title, pos, size, style )
57
m_timer = new wxTimer(this);
60
//load all files from the workspace
61
ManagerST::Get()->GetWorkspaceFiles(m_files, true);
63
this->SetSizeHints( wxDefaultSize, wxDefaultSize );
65
wxBoxSizer* mainSizer;
66
mainSizer = new wxBoxSizer( wxVERTICAL );
68
mainPanel = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
69
wxBoxSizer* panelSizer;
70
panelSizer = new wxBoxSizer( wxVERTICAL );
72
m_staticTitle = new wxStaticText( mainPanel, wxID_ANY, wxT("Find Resource (wildcards are allowed):"), wxDefaultPosition, wxDefaultSize, 0 );
73
panelSizer->Add( m_staticTitle, 0, wxALL, 5 );
75
m_textResourceName = new wxTextCtrl(mainPanel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER);
76
panelSizer->Add( m_textResourceName, 0, wxALL|wxEXPAND, 5 );
78
wxStaticText *label = new wxStaticText( mainPanel, wxID_ANY, wxT("Matched resources:"), wxDefaultPosition, wxDefaultSize, 0 );
79
panelSizer->Add( label, 0, wxALL, 5 );
81
m_listShortNames = new wxListBox( mainPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0, NULL, 0 );
82
panelSizer->Add( m_listShortNames, 1, wxALL|wxEXPAND, 5 );
84
m_fullText = new wxStaticText( mainPanel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
85
panelSizer->Add( m_fullText, 0, wxALL, 5 );
87
m_checkBoxPartialMatching = new wxCheckBox( mainPanel, wxID_ANY, wxT("Allow partial matching"), wxDefaultPosition, wxDefaultSize, 0 );
88
panelSizer->Add( m_checkBoxPartialMatching, 0, wxALL|wxEXPAND, 5 );
91
EditorConfigST::Get()->GetLongValue(wxT("OpenResourceAllowsPartialMatch"), v);
92
m_checkBoxPartialMatching->SetValue(v == 1 ? true : false);
94
mainPanel->SetSizer( panelSizer );
96
panelSizer->Fit( mainPanel );
97
mainSizer->Add( mainPanel, 1, wxEXPAND | wxALL, 5 );
99
m_staticline1 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
100
mainSizer->Add( m_staticline1, 0, wxEXPAND | wxALL, 5 );
102
wxBoxSizer* btnSizer;
103
btnSizer = new wxBoxSizer( wxHORIZONTAL );
105
m_btnOk = new wxButton( this, wxID_OK, wxT("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
106
btnSizer->Add( m_btnOk, 0, wxALL, 5 );
108
m_button2 = new wxButton( this, wxID_CANCEL, wxT("Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
109
btnSizer->Add( m_button2, 0, wxALL, 5 );
111
mainSizer->Add( btnSizer, 0, wxALIGN_RIGHT, 5 );
113
this->SetSizer( mainSizer );
117
m_textResourceName->SetFocus();
120
OpenResourceDlg::~OpenResourceDlg()
126
void OpenResourceDlg::ConnectEvents()
128
ConnectButton(m_button2, OpenResourceDlg::OnButtonCancel);
129
ConnectButton(m_btnOk, OpenResourceDlg::OnButtonOK);
130
m_listShortNames->Connect(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, wxCommandEventHandler(OpenResourceDlg::OnItemActivated), NULL, this);
131
Connect(m_timer->GetId(), wxEVT_TIMER, wxTimerEventHandler(OpenResourceDlg::OnTimer), NULL, this);
134
void OpenResourceDlg::OnTimer(wxTimerEvent &event)
137
wxArrayString tmpArr;
138
wxString curSel = m_textResourceName->GetValue();
139
if (!curSel.Trim().Trim(false).IsEmpty()) {
141
curSel = curSel.MakeLower().Trim().Trim(false);
143
for (size_t i=0; i<m_files.size(); i++) {
144
wxString fileName(m_files.at(i).GetFullName());
145
fileName= fileName.MakeLower();
147
//append wildcard at the end
148
if (!curSel.EndsWith(wxT("*"))) {
153
if (m_checkBoxPartialMatching->IsChecked() && !curSel.StartsWith(wxT("*"))) {
154
curSel.Prepend(wxT("*"));
157
if (wxMatchWild(curSel, fileName)) {
158
tmpArr.Add(m_files[i].GetFullPath());
163
// actValues represents the list of files as they appear in the ListBox
164
// we need to loop over the list box, since the actual full file names
165
// are stored as ClientObject
166
wxArrayString actValues;
167
for (unsigned int i=0; i<m_listShortNames->GetCount(); i++) {
168
wxStringClientData *data = (wxStringClientData *)m_listShortNames->GetClientObject(i);
169
actValues.Add(data->GetData());
171
// we need to sort the array
174
// tmpArr contains the list of files (full paths) after filtering the typed pattern
177
if (tmpArr == actValues)
180
//change was done, update the file list
182
m_listShortNames->Clear();
183
for (size_t i=0; i<tmpArr.GetCount(); i++) {
184
wxFileName fn(tmpArr.Item(i));
185
m_listShortNames->Append(fn.GetFullName(), new wxStringClientData(tmpArr.Item(i)));
188
if (m_listShortNames->GetCount() > 0) {
189
m_listShortNames->Select(0);
190
// display the full name at the bottom static text control
191
wxStringClientData *data = (wxStringClientData *)m_listShortNames->GetClientObject(0);
192
m_fullText->SetLabel(data->GetData());
196
void OpenResourceDlg::OnButtonCancel(wxCommandEvent &event)
199
EndModal(wxID_CANCEL);
202
void OpenResourceDlg::OnButtonOK(wxCommandEvent &event)
205
if (UpdateFileName()) {
210
void OpenResourceDlg::OnItemActivated(wxCommandEvent &event)
214
if (UpdateFileName()) {
219
bool OpenResourceDlg::UpdateFileName()
221
int idx = m_listShortNames->GetSelection();
222
if (idx == wxNOT_FOUND) {
226
m_fileName = m_fullText->GetLabelText();
228
// save the checkbox value into the settings
229
EditorConfigST::Get()->SaveLongValue(wxT("OpenResourceAllowsPartialMatch"), m_checkBoxPartialMatching->IsChecked() ? 1 : 0);
234
void OpenResourceDlg::OnCharHook(wxKeyEvent &event)
236
if (event.GetKeyCode() == WXK_RETURN || event.GetKeyCode() == WXK_NUMPAD_ENTER) {
237
if (m_listShortNames->GetSelection() != wxNOT_FOUND) {
238
if (UpdateFileName()) {
242
} else if (m_listShortNames->GetCount() == 1) {
243
m_listShortNames->SetSelection(0);
244
if (UpdateFileName()) {
249
} else if (event.GetKeyCode() == WXK_DOWN && m_listShortNames->GetCount() > 0) {
251
int cursel = m_listShortNames->GetSelection();
252
if (cursel != wxNOT_FOUND) {
253
//there is a selection in the listbox
255
if (cursel >= (int)m_listShortNames->GetCount()) {
256
//already at last item, cant scroll anymore
259
m_listShortNames->SetSelection(cursel);
260
m_listShortNames->Select(cursel);
261
m_listShortNames->SetFirstItem(cursel);
263
// display the full name at the bottom static text control
264
wxStringClientData *data = (wxStringClientData *)m_listShortNames->GetClientObject(cursel);
265
m_fullText->SetLabel(data->GetData());
268
//no selection is made
269
m_listShortNames->SetSelection(0);
270
m_listShortNames->Select(0);
272
// display the full name at the bottom static text control
273
wxStringClientData *data = (wxStringClientData *)m_listShortNames->GetClientObject(0);
274
m_fullText->SetLabel(data->GetData());
276
m_listShortNames->SetFirstItem(0);
279
} else if (event.GetKeyCode() == WXK_UP && m_listShortNames->GetCount() > 0) {
281
int cursel = m_listShortNames->GetSelection();
282
if (cursel != wxNOT_FOUND) {
283
//there is a selection in the listbox
286
//already at first item, cant scroll anymore
289
m_listShortNames->SetSelection(cursel);
290
m_listShortNames->SetFirstItem(cursel);
292
// display the full name at the bottom static text control
293
wxStringClientData *data = (wxStringClientData *)m_listShortNames->GetClientObject(cursel);
294
m_fullText->SetLabel(data->GetData());
296
//no selection is made
297
m_listShortNames->SetSelection(0);
298
m_listShortNames->SetFirstItem(0);
300
// display the full name at the bottom static text control
301
wxStringClientData *data = (wxStringClientData *)m_listShortNames->GetClientObject(0);
302
m_fullText->SetLabel(data->GetData());
1
//////////////////////////////////////////////////////////////////////////////
2
//////////////////////////////////////////////////////////////////////////////
4
// copyright : (C) 2008 by Eran Ifrah
5
// file name : open_resouce_dlg.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
//////////////////////////////////////////////////////////////////////////////
25
///////////////////////////////////////////////////////////////////////////
26
// C++ code generated with wxFormBuilder (version May 5 2007)
27
// http://www.wxformbuilder.org/
29
// PLEASE DO "NOT" EDIT THIS FILE!
30
///////////////////////////////////////////////////////////////////////////
31
#include "editor_config.h"
35
#include "wx/wxprec.h"
45
#include "open_resouce_dlg.h"
49
///////////////////////////////////////////////////////////////////////////
50
BEGIN_EVENT_TABLE(OpenResourceDlg, wxDialog)
51
EVT_CHAR_HOOK(OpenResourceDlg::OnCharHook)
54
OpenResourceDlg::OpenResourceDlg( wxWindow* parent, int id, wxString title, wxPoint pos, wxSize size, int style )
55
: wxDialog( parent, id, title, pos, size, style )
57
m_timer = new wxTimer(this);
60
//load all files from the workspace
61
ManagerST::Get()->GetWorkspaceFiles(m_files, true);
63
this->SetSizeHints( wxDefaultSize, wxDefaultSize );
65
wxBoxSizer* mainSizer;
66
mainSizer = new wxBoxSizer( wxVERTICAL );
68
mainPanel = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
69
wxBoxSizer* panelSizer;
70
panelSizer = new wxBoxSizer( wxVERTICAL );
72
m_staticTitle = new wxStaticText( mainPanel, wxID_ANY, wxT("Find Resource (wildcards are allowed):"), wxDefaultPosition, wxDefaultSize, 0 );
73
panelSizer->Add( m_staticTitle, 0, wxALL, 5 );
75
m_textResourceName = new wxTextCtrl(mainPanel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER);
76
panelSizer->Add( m_textResourceName, 0, wxALL|wxEXPAND, 5 );
78
wxStaticText *label = new wxStaticText( mainPanel, wxID_ANY, wxT("Matched resources:"), wxDefaultPosition, wxDefaultSize, 0 );
79
panelSizer->Add( label, 0, wxALL, 5 );
81
m_listShortNames = new wxListBox( mainPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0, NULL, 0 );
82
panelSizer->Add( m_listShortNames, 1, wxALL|wxEXPAND, 5 );
84
m_fullText = new wxStaticText( mainPanel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
85
panelSizer->Add( m_fullText, 0, wxALL, 5 );
87
m_checkBoxPartialMatching = new wxCheckBox( mainPanel, wxID_ANY, wxT("Allow partial matching"), wxDefaultPosition, wxDefaultSize, 0 );
88
panelSizer->Add( m_checkBoxPartialMatching, 0, wxALL|wxEXPAND, 5 );
91
EditorConfigST::Get()->GetLongValue(wxT("OpenResourceAllowsPartialMatch"), v);
92
m_checkBoxPartialMatching->SetValue(v == 1 ? true : false);
94
mainPanel->SetSizer( panelSizer );
96
panelSizer->Fit( mainPanel );
97
mainSizer->Add( mainPanel, 1, wxEXPAND | wxALL, 5 );
99
m_staticline1 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
100
mainSizer->Add( m_staticline1, 0, wxEXPAND | wxALL, 5 );
102
wxBoxSizer* btnSizer;
103
btnSizer = new wxBoxSizer( wxHORIZONTAL );
105
m_btnOk = new wxButton( this, wxID_OK, wxT("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
106
btnSizer->Add( m_btnOk, 0, wxALL, 5 );
108
m_button2 = new wxButton( this, wxID_CANCEL, wxT("Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
109
btnSizer->Add( m_button2, 0, wxALL, 5 );
111
mainSizer->Add( btnSizer, 0, wxALIGN_RIGHT, 5 );
113
this->SetSizer( mainSizer );
117
m_textResourceName->SetFocus();
120
OpenResourceDlg::~OpenResourceDlg()
126
void OpenResourceDlg::ConnectEvents()
128
ConnectButton(m_button2, OpenResourceDlg::OnButtonCancel);
129
ConnectButton(m_btnOk, OpenResourceDlg::OnButtonOK);
130
m_listShortNames->Connect(wxEVT_COMMAND_LISTBOX_SELECTED, wxCommandEventHandler(OpenResourceDlg::OnItemSelected), NULL, this);
131
m_listShortNames->Connect(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, wxCommandEventHandler(OpenResourceDlg::OnItemActivated), NULL, this);
132
Connect(m_timer->GetId(), wxEVT_TIMER, wxTimerEventHandler(OpenResourceDlg::OnTimer), NULL, this);
135
void OpenResourceDlg::OnTimer(wxTimerEvent &event)
138
wxArrayString tmpArr;
139
wxString curSel = m_textResourceName->GetValue();
140
if (!curSel.Trim().Trim(false).IsEmpty()) {
142
curSel = curSel.MakeLower().Trim().Trim(false);
144
for (size_t i=0; i<m_files.size(); i++) {
145
wxString fileName(m_files.at(i).GetFullName());
146
fileName= fileName.MakeLower();
148
//append wildcard at the end
149
if (!curSel.EndsWith(wxT("*"))) {
154
if (m_checkBoxPartialMatching->IsChecked() && !curSel.StartsWith(wxT("*"))) {
155
curSel.Prepend(wxT("*"));
158
if (wxMatchWild(curSel, fileName)) {
159
tmpArr.Add(m_files[i].GetFullPath());
164
// actValues represents the list of files as they appear in the ListBox
165
// we need to loop over the list box, since the actual full file names
166
// are stored as ClientObject
167
wxArrayString actValues;
168
for (unsigned int i=0; i<m_listShortNames->GetCount(); i++) {
169
wxStringClientData *data = (wxStringClientData *)m_listShortNames->GetClientObject(i);
170
actValues.Add(data->GetData());
172
// we need to sort the array
175
// tmpArr contains the list of files (full paths) after filtering the typed pattern
178
if (tmpArr == actValues)
181
//change was done, update the file list
183
m_listShortNames->Clear();
184
for (size_t i=0; i<tmpArr.GetCount(); i++) {
185
wxFileName fn(tmpArr.Item(i));
186
m_listShortNames->Append(fn.GetFullName(), new wxStringClientData(tmpArr.Item(i)));
189
if (m_listShortNames->GetCount() > 0) {
190
m_listShortNames->Select(0);
191
// display the full name at the bottom static text control
192
wxStringClientData *data = (wxStringClientData *)m_listShortNames->GetClientObject(0);
193
m_fullText->SetLabel(data->GetData());
197
void OpenResourceDlg::OnButtonCancel(wxCommandEvent &event)
200
EndModal(wxID_CANCEL);
203
void OpenResourceDlg::OnButtonOK(wxCommandEvent &event)
206
if (UpdateFileName()) {
211
void OpenResourceDlg::OnItemSelected(wxCommandEvent &event)
213
wxStringClientData *data = (wxStringClientData *)m_listShortNames->GetClientObject(event.GetSelection());
215
m_fullText->SetLabel(data->GetData());
220
void OpenResourceDlg::OnItemActivated(wxCommandEvent &event)
224
if (UpdateFileName()) {
229
bool OpenResourceDlg::UpdateFileName()
231
int idx = m_listShortNames->GetSelection();
232
if (idx == wxNOT_FOUND) {
236
m_fileName = m_fullText->GetLabelText();
238
// save the checkbox value into the settings
239
EditorConfigST::Get()->SaveLongValue(wxT("OpenResourceAllowsPartialMatch"), m_checkBoxPartialMatching->IsChecked() ? 1 : 0);
244
void OpenResourceDlg::OnCharHook(wxKeyEvent &event)
246
if (event.GetKeyCode() == WXK_RETURN || event.GetKeyCode() == WXK_NUMPAD_ENTER) {
247
if (m_listShortNames->GetSelection() != wxNOT_FOUND) {
248
if (UpdateFileName()) {
252
} else if (m_listShortNames->GetCount() == 1) {
253
m_listShortNames->SetSelection(0);
254
if (UpdateFileName()) {
259
} else if (event.GetKeyCode() == WXK_DOWN && m_listShortNames->GetCount() > 0) {
261
int cursel = m_listShortNames->GetSelection();
262
if (cursel != wxNOT_FOUND) {
263
//there is a selection in the listbox
265
if (cursel >= (int)m_listShortNames->GetCount()) {
266
//already at last item, cant scroll anymore
269
m_listShortNames->SetSelection(cursel);
270
m_listShortNames->Select(cursel);
271
m_listShortNames->SetFirstItem(cursel);
273
// display the full name at the bottom static text control
274
wxStringClientData *data = (wxStringClientData *)m_listShortNames->GetClientObject(cursel);
275
m_fullText->SetLabel(data->GetData());
278
//no selection is made
279
m_listShortNames->SetSelection(0);
280
m_listShortNames->Select(0);
282
// display the full name at the bottom static text control
283
wxStringClientData *data = (wxStringClientData *)m_listShortNames->GetClientObject(0);
284
m_fullText->SetLabel(data->GetData());
286
m_listShortNames->SetFirstItem(0);
289
} else if (event.GetKeyCode() == WXK_UP && m_listShortNames->GetCount() > 0) {
291
int cursel = m_listShortNames->GetSelection();
292
if (cursel != wxNOT_FOUND) {
293
//there is a selection in the listbox
296
//already at first item, cant scroll anymore
299
m_listShortNames->SetSelection(cursel);
300
m_listShortNames->SetFirstItem(cursel);
302
// display the full name at the bottom static text control
303
wxStringClientData *data = (wxStringClientData *)m_listShortNames->GetClientObject(cursel);
304
m_fullText->SetLabel(data->GetData());
306
//no selection is made
307
m_listShortNames->SetSelection(0);
308
m_listShortNames->SetFirstItem(0);
310
// display the full name at the bottom static text control
311
wxStringClientData *data = (wxStringClientData *)m_listShortNames->GetClientObject(0);
312
m_fullText->SetLabel(data->GetData());