OpenASIP 2.2
Loading...
Searching...
No Matches
OSEdOptionsDialog.cc
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2009 Tampere University.
3
4 This file is part of TTA-Based Codesign Environment (TCE).
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23 */
24/**
25 * @file src/codesign/osal/OSEd/OSEdOptionsDialog.cc
26 *
27 * Definition of OSEdOptionsDialog class.
28 *
29 * @author Jussi Nykänen 2004 (nykanen-no.spam-cs.tut.fi)
30 * @note rating: red
31 */
32
33#include <wx/valgen.h>
34#include <wx/filedlg.h>
35#include <boost/format.hpp>
36#include <string>
37
38#include "OSEdOptionsDialog.hh"
39#include "WxConversion.hh"
40#include "GUITextGenerator.hh"
41#include "OSEdTextGenerator.hh"
42#include "WidgetTools.hh"
43#include "OSEd.hh"
45#include "ErrorDialog.hh"
46#include "OSEdConstants.hh"
47#include "DialogPosition.hh"
48#include "Environment.hh"
49#include "FileSystem.hh"
50#include "OSEdOptions.hh"
51
52using boost::format;
53using std::string;
54
55BEGIN_EVENT_TABLE(OSEdOptionsDialog, wxDialog)
56
59
61
62/**
63 * Constructor.
64 *
65 * @param parent The parent window.
66 */
68 wxDialog(parent, -1, _T(""),
69 DialogPosition::getPosition(DialogPosition::DIALOG_OPTIONS),
70 wxSize(400, 200)) {
71
72 createContents(this, true, true);
73
74 FindWindow(ID_EDITOR)->
75 SetValidator(wxTextValidator(wxFILTER_ASCII, &editor_));
76
77 setTexts();
78}
79
80/**
81 * Destructor.
82 */
84 int x, y;
85 GetPosition(&x, &y);
86 wxPoint point(x, y);
88}
89
90/**
91 * Set texts to all widgets.
92 */
93void
115
116/**
117 * Transfers data to window.
118 *
119 * @return True if all is successful.
120 */
121bool
123 OSEdOptions* options = wxGetApp().options();
125 return wxWindow::TransferDataToWindow();
126}
127
128/**
129 * Handles the event when Save button is pushed.
130 */
131void
133 TransferDataFromWindow();
134 wxGetApp().options()->setEditor(WxConversion::toString(editor_));
135 OSEdOptionsSerializer serializer;
137 serializer.setDestinationFile(confFile);
138 try {
139 serializer.writeState(wxGetApp().options()->saveState());
140 } catch (const Exception& e) {
143 ErrorDialog dialog(this, WxConversion::toWxString(fmt.str()));
144 dialog.ShowModal();
145 }
146 EndModal(wxID_OK);
147}
148
149/**
150 * Handles the event when Browse button is pushed.
151 */
152void
154
156 wxFileDialog dialog(this, _T("Choose a file"),
158 if (dialog.ShowModal() == wxID_OK) {
159 editor_ = dialog.GetPath();
160 wxWindow::TransferDataToWindow();
161 }
162}
163
164/**
165 * Creates the contents of the dialog.
166 *
167 * @param parent Parent window.
168 * @param call_fit If true fits the contents inside the dialog.
169 * @param set_sizer If true sets the main sizer as dialog contents.
170 * @return The created sizer.
171 */
172wxSizer*
174 wxWindow *parent,
175 bool call_fit,
176 bool set_sizer) {
177
178 wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
179
180 item0->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 5 );
181
182 wxBoxSizer *item1 = new wxBoxSizer( wxHORIZONTAL );
183
184 wxStaticText *item2 = new wxStaticText( parent, ID_TEXT, wxT("Source code editor:"), wxDefaultPosition, wxDefaultSize, 0 );
185 item1->Add( item2, 0, wxALIGN_CENTER|wxALL, 5 );
186
187 wxTextCtrl *item3 = new wxTextCtrl( parent, ID_EDITOR, wxT(""), wxDefaultPosition, wxSize(150,-1), 0 );
188 item1->Add( item3, 0, wxALIGN_CENTER|wxALL, 5 );
189
190 wxButton *item4 = new wxButton( parent, ID_BUTTON_BROWSE, wxT("Browse"), wxDefaultPosition, wxDefaultSize, 0 );
191 item1->Add( item4, 0, wxALIGN_CENTER|wxALL, 5 );
192
193 item0->Add( item1, 0, wxALIGN_CENTER|wxALL, 5 );
194
195 item0->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 5 );
196
197 wxBoxSizer *item5 = new wxBoxSizer( wxHORIZONTAL );
198
199 wxButton *item6 = new wxButton( parent, ID_BUTTON_SAVE, wxT("&Save"), wxDefaultPosition, wxDefaultSize, 0 );
200 item5->Add( item6, 0, wxALIGN_CENTER|wxALL, 5 );
201
202 wxButton *item7 = new wxButton( parent, wxID_CANCEL, wxT("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
203 item5->Add( item7, 0, wxALIGN_CENTER|wxALL, 5 );
204
205 item0->Add( item5, 0, wxALIGN_CENTER|wxALL, 5 );
206
207 if (set_sizer)
208 {
209 parent->SetSizer( item0 );
210 if (call_fit)
211 item0->SetSizeHints( parent );
212 }
213
214 return item0;
215}
END_EVENT_TABLE() using namespace IDF
EVT_BUTTON(ID_EDIT_ARCH_PORT, FUImplementationDialog::onEditArchitecturePort) EVT_BUTTON(ID_ADD_EXTERNAL_PORT
static MachInfoCmdLineOptions options
Definition MachInfo.cc:46
static void setPosition(Dialogs dialog, wxPoint point)
@ DIALOG_OPTIONS
Options dialog.
static TCEString userConfPath(const std::string &fileName)
static std::string directoryOfPath(const std::string fileName)
Definition FileSystem.cc:79
@ TXT_BUTTON_CANCEL
Label for cancel button.
static GUITextGenerator * instance()
static const std::string CONF_FILE_NAME
Configuration file name.
void onBrowse(wxCommandEvent &event)
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
void onSave(wxCommandEvent &event)
wxString editor_
The name of the editor.
virtual void writeState(const ObjectState *state)
void setDestinationFile(const std::string &fileName)
static OSEdTextGenerator & instance()
@ TXT_ERROR_CAN_NOT_SAVE
Error when options can not be saved.
@ TXT_BUTTON_SAVE
Save button label.
@ TXT_BUTTON_BROWSE
Browse button label.
@ TXT_OPTIONS_DIALOG_TITLE
Options dialog title.
@ TXT_LABEL_EDITOR
Editor label.
virtual boost::format text(int textId)
static void setLabel(Texts::TextGenerator *generator, wxWindow *widget, int textID)
static wxString toWxString(const std::string &source)
static std::string toString(const wxString &source)