Menu

[r109]: / src / commandpanel.cpp  Maximize  Restore  History

Download this file

287 lines (242 with data), 8.2 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
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
/*
* Copyright 2005-2007 Gerald Schmidt.
*
* This file is part of Xml Copy Editor.
*
* Xml Copy Editor 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; version 2 of the License.
*
* Xml Copy Editor 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 Xml Copy Editor; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <wx/utils.h>
#include "commandpanel.h"
#include "xmlcopyeditor.h"
#include "wraptempfilename.h"
#include "readfile.h"
BEGIN_EVENT_TABLE ( CommandPanel, wxPanel )
EVT_BUTTON ( ID_RUN, CommandPanel::OnRun )
EVT_IDLE ( CommandPanel::OnIdle )
EVT_BUTTON ( ID_BUTTON_NAME, CommandPanel::OnVariableButton )
EVT_BUTTON ( ID_BUTTON_PATH, CommandPanel::OnVariableButton )
EVT_BUTTON ( ID_BUTTON_EXTENSION, CommandPanel::OnVariableButton )
EVT_BUTTON ( ID_BUTTON_FULLPATH, CommandPanel::OnVariableButton )
END_EVENT_TABLE()
CommandPanel::CommandPanel (
wxWindow *parentParameter,
int id,
const wxString& cmd,
bool sync,
int output,
const wxString& command ) : wxPanel ( parentParameter, id )
{
parent = ( MyFrame * ) parentParameter;
path = _ ( "{path}" );
name = _ ( "{name}" );
extension = _ ( "{extension}" );
fullpath = _ ( "{fullpath}" );
int sizerOffset = 2;
wxButton *pathButton = new wxButton ( this, ID_BUTTON_PATH, path, wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT | wxNO_BORDER );
wxButton *nameButton = new wxButton ( this, ID_BUTTON_NAME, name, wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT | wxNO_BORDER );
wxButton *extensionButton = new wxButton ( this, ID_BUTTON_EXTENSION, extension, wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT | wxNO_BORDER );
wxButton *fullpathButton = new wxButton ( this, ID_BUTTON_FULLPATH, fullpath, wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT | wxNO_BORDER );
int editWidth, editHeight;
parent->GetSize( &editWidth, &editHeight);
editWidth -= sizerOffset * 2;
commandEdit = new wxTextCtrl (
this,
wxID_ANY,
_T ( "" ),
wxDefaultPosition,
wxSize ( editWidth, -1 )
);
commandEdit->SetValue ( cmd );
runButton = new wxButton (
this,
ID_RUN,
_ ( "&Run" ),
wxDefaultPosition,
wxDefaultSize,
wxBU_EXACTFIT | wxNO_BORDER );
syncBox = new wxCheckBox (
this,
ID_SYNC,
_ ( "&Wait" ) );
syncBox->SetValue ( sync );
wxStaticBox *outputBox = new wxStaticBox (
this,
wxID_ANY,
_ ( "Output options" ) );
outputIgnore = new wxRadioButton (
this,
ID_COMMAND_OUTPUT_IGNORE,
_ ( "I&gnore" ) );
outputIgnore->SetValue ( true );
outputInsert = new wxRadioButton (
this,
ID_COMMAND_OUTPUT_IGNORE,
_ ( "I&nsert" ) );
outputNewDocument = new wxRadioButton (
this,
ID_COMMAND_OUTPUT_IGNORE,
_ ( "New &document" ) );
switch ( output )
{
case ID_COMMAND_OUTPUT_IGNORE:
outputIgnore->SetValue ( true );
break;
case ID_COMMAND_OUTPUT_INSERT:
outputInsert->SetValue ( true );
break;
case ID_COMMAND_OUTPUT_NEW_DOCUMENT:
outputNewDocument->SetValue ( true );
break;
default:
outputIgnore->SetValue ( true );
break;
}
wxStaticBox *variablesBox = new wxStaticBox (
this,
wxID_ANY,
_ ( "Variables" ) );
wxStaticBoxSizer *outputSizer = new wxStaticBoxSizer ( outputBox, wxHORIZONTAL );
outputSizer->Add ( outputIgnore, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, sizerOffset );
outputSizer->Add ( outputInsert, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, sizerOffset );
outputSizer->Add ( outputNewDocument, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, sizerOffset );
wxStaticBoxSizer *variablesSizer = new wxStaticBoxSizer ( variablesBox, wxHORIZONTAL );
//variablesSizer->Add(label, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, sizerOffset);
variablesSizer->Add ( pathButton, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, sizerOffset );
variablesSizer->Add ( nameButton, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, sizerOffset );
variablesSizer->Add ( extensionButton, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, sizerOffset );
variablesSizer->Add ( fullpathButton, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, sizerOffset );
topSizer = new wxBoxSizer ( wxHORIZONTAL );
topSizer->Add ( commandEdit, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL | wxEXPAND, sizerOffset );
topSizer->Layout();
bottomSizer = new wxBoxSizer ( wxHORIZONTAL );
bottomSizer->Add ( runButton, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, sizerOffset );
bottomSizer->Add ( syncBox, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, sizerOffset );
bottomSizer->Add ( variablesSizer, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, sizerOffset );
bottomSizer->Add ( outputSizer, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, sizerOffset );
bottomSizer->Layout();
mainSizer = new wxBoxSizer ( wxVERTICAL );
mainSizer->Add ( topSizer );
mainSizer->Add ( bottomSizer );
mainSizer->Layout();
this->SetSizer ( mainSizer );
this->SetSize ( -1, ( runButton->GetSize().GetHeight() * 2 ) + 25 );
}
CommandPanel::~CommandPanel()
{}
void CommandPanel::OnRun ( wxCommandEvent& event )
{
parent->statusProgress ( wxEmptyString );
wxString command = commandEdit->GetValue();
if ( command.empty() )
return;
// need to test for NULL ptr doc for each use
XmlDoc *doc = parent->getActiveDocument();
wxString fullPath = ( doc ) ? doc->getFullFileName() : _T ( "" );
wxString path, name, extension;
wxFileName::SplitPath ( fullPath, &path, &name, &extension );
command.Replace ( _ ( "{fullpath}" ), fullPath, true );
command.Replace ( _ ( "{path}" ), path, true );
command.Replace ( _ ( "{name}" ), name, true );
command.Replace ( _ ( "{extension}" ), extension, true );
bool redirect = ( getSync() && !outputIgnore->GetValue() );
if ( !redirect )
{
wxExecute ( command, ( getSync() ) ? wxEXEC_SYNC : wxEXEC_ASYNC );
return;
}
wxArrayString stringArray;
wxExecute ( command, stringArray, wxEXEC_NOHIDE );
if ( stringArray.empty() )
{
parent->statusProgress ( _T ( "No output" ) );
return;
}
size_t count = stringArray.GetCount();
wxString outputBuffer;
for ( size_t i = 0 ; i < count; i++ )
{
outputBuffer += stringArray[i];
outputBuffer += L"\n";
}
if ( outputInsert->GetValue() )
{
if ( doc )
{
doc->ReplaceSelection ( outputBuffer );
}
}
else if ( outputNewDocument->GetValue() )
parent->newDocument ( outputBuffer );
XmlDoc *newActiveDoc = parent->getActiveDocument();
if ( newActiveDoc )
newActiveDoc->SetFocus();
}
void CommandPanel::OnVariableButton ( wxCommandEvent& event )
{
int id = event.GetId();
wxString label;
switch ( id )
{
case ID_BUTTON_NAME:
label = name;
break;
case ID_BUTTON_PATH:
label = path;
break;
case ID_BUTTON_EXTENSION:
label = extension;
break;
case ID_BUTTON_FULLPATH:
label = fullpath;
break;
default:
label = wxEmptyString;
return;
}
long to, from;
commandEdit->GetSelection ( &from, &to );
commandEdit->Replace ( from, to, label );
commandEdit->SetFocus();
}
void CommandPanel::focusOnCommand()
{
commandEdit->SelectAll();
commandEdit->SetFocus();
}
bool CommandPanel::getSync()
{
return syncBox->GetValue();
}
int CommandPanel::getOutput()
{
if ( outputIgnore->GetValue() )
return ID_COMMAND_OUTPUT_IGNORE;
else if ( outputInsert->GetValue() )
return ID_COMMAND_OUTPUT_INSERT;
else if ( outputNewDocument->GetValue() )
return ID_COMMAND_OUTPUT_NEW_DOCUMENT;
else
return ID_COMMAND_OUTPUT_IGNORE; // default
}
wxString CommandPanel::getCommand()
{
return commandEdit->GetValue();
}
void CommandPanel::OnIdle ( wxIdleEvent& event )
{
bool b = getSync();
outputIgnore->Enable ( b );
outputInsert->Enable ( b );
outputNewDocument->Enable ( b );
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.