Menu

[r130]: / src / associatedialog.cpp  Maximize  Restore  History

Download this file

185 lines (170 with data), 5.4 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
/*
* 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 <memory>
#include "associatedialog.h"
BEGIN_EVENT_TABLE ( AssociateDialog, wxDialog )
EVT_BUTTON ( wxID_OK, AssociateDialog::OnOk )
EVT_BUTTON ( ID_BROWSE, AssociateDialog::OnBrowse )
EVT_HELP_RANGE ( ID_URL, ID_AUX, AssociateDialog::OnContextHelp )
EVT_HELP ( wxID_OK, AssociateDialog::OnContextHelp )
EVT_HELP ( wxID_CANCEL, AssociateDialog::OnContextHelp )
EVT_UPDATE_UI ( wxID_OK, AssociateDialog::OnUpdateOk )
END_EVENT_TABLE()
AssociateDialog::AssociateDialog (
wxWindow *parent,
const wxString& titleParameter,
const wxString& labelParameter,
const wxString& typeParameter,
const wxString& extensionParameter,
const wxString& urlParameter,
bool auxNeededParameter,
const wxString& auxLabelTextParameter,
const wxString& auxParameter ) :
wxDialog(),
title ( titleParameter ),
label ( labelParameter ),
type ( typeParameter ),
extension ( extensionParameter ),
url ( urlParameter ),
auxNeeded ( auxNeededParameter ),
auxLabelText ( auxLabelTextParameter ),
aux ( auxParameter )
{
SetExtraStyle ( wxDIALOG_EX_CONTEXTHELP );
Create (
parent,
wxID_ANY,
title,
wxDefaultPosition,
wxSize ( -1, -1 ),
wxDEFAULT_DIALOG_STYLE );
wxBoxSizer *dialogSizer = new wxBoxSizer ( wxVERTICAL );
wxBoxSizer *horizontalSizer = new wxBoxSizer ( wxHORIZONTAL );
auxCtrl = NULL; // may or may not be used
urlLabel = new wxStaticText ( this, ID_URL, label );
urlCtrl = new wxTextCtrl (
this,
ID_URL,
url,
wxDefaultPosition,
wxSize ( 240, -1 ) );
browseButton = new wxButton (
this,
ID_BROWSE,
_ ( "Browse" ) );
horizontalSizer->Add ( urlCtrl, 0, wxLEFT, 0 );
horizontalSizer->Add ( browseButton, 0, wxLEFT, 5 );
if ( auxNeeded )
{
auxLabel = new wxStaticText ( this, ID_AUX, auxLabelText );
auxCtrl = new wxTextCtrl (
this,
ID_AUX,
aux,
wxDefaultPosition,
wxSize ( 240, -1 ) );
dialogSizer->Add ( auxLabel, 0, wxLEFT | wxTOP | wxALIGN_LEFT, 10 );
dialogSizer->Add ( auxCtrl, 0, wxALL, 5 );
}
dialogSizer->Add ( urlLabel, 0, wxTOP | wxLEFT | wxALIGN_LEFT, 10 );
dialogSizer->Add ( horizontalSizer, 0, wxALL, 5 );
dialogSizer->Add (
CreateButtonSizer ( wxOK | wxCANCEL ), 0, wxTOP | wxBOTTOM | wxALIGN_RIGHT, 10 );
this->SetSizer ( dialogSizer );
dialogSizer->SetSizeHints ( this );
if ( auxNeeded )
auxCtrl->SetFocus();
else
urlCtrl->SetFocus();
}
AssociateDialog::~AssociateDialog()
{ }
void AssociateDialog::OnOk ( wxCommandEvent& e )
{
url = urlCtrl->GetValue();
if ( auxCtrl )
aux = auxCtrl->GetValue();
e.Skip();
}
void AssociateDialog::OnContextHelp ( wxHelpEvent& e )
{
wxTipWindow *tw;
int id = e.GetId();
if ( id == ID_URL )
tw = new wxTipWindow (
this,
_ ( "Provides a space for you to type the path of the file" ) );
else if ( id == ID_BROWSE )
tw = new wxTipWindow (
this,
_ ( "Opens a standard file dialog" ) );
else if ( id == ID_AUX )
tw = new wxTipWindow (
this,
_ ( "Provides a space for you to type additional information" ) );
else if ( id == wxID_CANCEL )
tw = new wxTipWindow (
this,
_ ( "Closes this dialog without making any changes" ) );
else if ( id == wxID_OK )
tw = new wxTipWindow (
this,
_ ( "Selects the file specified" ) );
else
{ }
e.Skip();
}
void AssociateDialog::OnUpdateOk ( wxUpdateUIEvent& e )
{
e.Enable ( !urlCtrl->GetValue().empty() );
}
wxString AssociateDialog::getUrl()
{
return url;
}
wxString AssociateDialog::getAux()
{
return aux;
}
void AssociateDialog::OnBrowse ( wxCommandEvent& e )
{
wxString extensionArgument;
extensionArgument =
type +
_T ( " (" ) +
extension +
_T ( ")|" ) +
extension +
_ ( "|All files (*.*)|*.*" );
std::auto_ptr<wxFileDialog> fd ( new wxFileDialog (
this,
_ ( "Select " ) + type,
_T ( "" ),
_T ( "" ),
extensionArgument,
wxOPEN | wxFILE_MUST_EXIST | wxCHANGE_DIR
) );
if ( fd->ShowModal() == wxID_OK )
{
wxString newValue = fd->GetPath();
newValue.Replace ( _T ( "\\" ), _T ( "/" ), true );
newValue.Replace ( _T ( " " ), _T ( "%20" ), true );
urlCtrl->SetValue ( newValue );
}
}
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.