OpenASIP  2.0
ProximCmdHistoryWindow.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 ProximCmdHistoryWindow.cc
26  *
27  * Implementation of ProximCmdHistoryWindow class.
28  *
29  * @author Veli-Pekka Jääskeläinen 2005 (vjaaskel-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
33 #include <fstream>
34 #include <wx/statline.h>
36 #include "ProximLineReader.hh"
37 #include "WxConversion.hh"
38 #include "SimulatorEvent.hh"
39 #include "ErrorDialog.hh"
40 
41 #if wxCHECK_VERSION(3, 0, 0)
42  #define wxSAVE wxFD_SAVE
43 #endif
44 
49  EVT_LISTBOX_DCLICK(ID_LIST, ProximCmdHistoryWindow::onCommandDClick)
51 
52 /**
53  * The Constructor.
54  *
55  * @param parent Proxim main frame.
56  * @param lineReader Line reader handling the command history.
57  */
59  ProximMainFrame* parent, wxWindowID id, ProximLineReader& lineReader):
60  ProximSimulatorWindow(parent, id),
61  lineReader_(lineReader) {
62 
63  createContents(this, true, true);
64  cmdList_ = dynamic_cast<wxListBox*>(FindWindow(ID_LIST));
65 
66  updateCommandList();
67 }
68 
69 
70 /**
71  * The Destructor.
72  */
74 }
75 
76 
77 /**
78  * Updates the command history list.
79  */
80 void
82  cmdList_->Clear();
83  for (size_t i = 0; i < lineReader_.inputsInHistory(); i++) {
84  std::string command = lineReader_.inputHistoryEntry(i);
85  cmdList_->Insert(WxConversion::toWxString(command), 0);
86  }
87  if (cmdList_->GetCount() > 0) {
88  FindWindow(ID_SAVE)->Enable();
89  } else {
90  FindWindow(ID_SAVE)->Disable();
91  }
92 }
93 
94 /**
95  * Calls history list update when a simulator event of a completed command
96  * is received.
97  */
98 void
101  event.Skip();
102 }
103 
104 
105 /**
106  * Handles the Close button events.
107  *
108  * Closes the window.
109  */
110 void
112  GetParent()->Close();
113 }
114 
115 /**
116  * Event handler for the command list double clicks.
117  *
118  * Sends the double clicked command to the linereader input.
119  *
120  * @param event Event of the item dclick.
121  */
122 void
124  std::string command = WxConversion::toString(event.GetString());
125  lineReader_.input(command);
126 }
127 
128 /**
129  * Displays dialog for saving command history to a file.
130  */
131 void
133 
134  wxString title = _T("Save Command History");
135  wxString filters = _T("Command history logs (*.log)|*.log|All files|*.*");
136  wxFileDialog dialog(
137  this, title, _T(""), _T("commands.log"), filters, wxSAVE);
138 
139  if (dialog.ShowModal() == wxID_CANCEL) {
140  return;
141  }
142 
143  std::string filename = WxConversion::toString(dialog.GetPath());
144 
145  std::ofstream file(filename.c_str());
146  if (file.bad()) {
147  wxString message = _T("Error saving file '.");
148  message.Append(dialog.GetPath());
149  message.Append(_T("'."));
150  ErrorDialog dialog(this, message);
151  dialog.ShowModal();
152  return;
153  }
154 
155  size_t cmdCount = lineReader_.inputsInHistory();
156  for (size_t i = 0; i < cmdCount; i++) {
157  std::string command =
158  lineReader_.inputHistoryEntry(cmdCount - 1 - i);
159  file << command << std::endl;
160  }
161 
162  file.close();
163 }
164 
165 
166 /**
167  * Creates the window widgets.
168  *
169  * Code generated by wxDesigner. Do not edit manually.
170  *
171  * @param parent Parent window of the window contents.
172  * @param call_fit If true, resize the parent window to fit the created
173  * contents.
174  * @param set_sizer If true, sets the created sizer as parent window contents.
175  */
176 wxSizer*
178  wxWindow *parent, bool call_fit, bool set_sizer) {
179 
180  wxFlexGridSizer *item0 = new wxFlexGridSizer( 1, 0, 0 );
181  item0->AddGrowableCol( 0 );
182  item0->AddGrowableRow( 0 );
183 
184  wxString *strs1 = (wxString*) NULL;
185  wxListBox *item1 = new wxListBox( parent, ID_LIST, wxDefaultPosition, wxSize(300,300), 0, strs1, wxLB_SINGLE );
186  item0->Add( item1, 0, wxGROW|wxALL, 5 );
187 
188  wxStaticLine *item2 = new wxStaticLine( parent, ID_LINE, wxDefaultPosition, wxSize(20,-1), wxLI_HORIZONTAL );
189  item0->Add( item2, 0, wxGROW|wxALL, 5 );
190 
191  wxBoxSizer *item3 = new wxBoxSizer( wxHORIZONTAL );
192 
193  wxButton *item4 = new wxButton( parent, ID_SAVE, wxT("&Save"), wxDefaultPosition, wxDefaultSize, 0 );
194  item3->Add( item4, 0, wxALIGN_CENTER|wxALL, 5 );
195 
196  wxStaticLine *item5 = new wxStaticLine( parent, ID_LINE, wxDefaultPosition, wxSize(-1,20), wxLI_VERTICAL );
197  item3->Add( item5, 0, wxGROW|wxALL, 5 );
198 
199  wxButton *item6 = new wxButton( parent, ID_CLOSE, wxT("&Close"), wxDefaultPosition, wxDefaultSize, 0 );
200  item3->Add( item6, 0, wxALIGN_CENTER|wxALL, 5 );
201 
202  item0->Add( item3, 0, wxALIGN_CENTER|wxALL, 5 );
203 
204  if (set_sizer)
205  {
206  parent->SetSizer( item0 );
207  if (call_fit)
208  item0->SetSizeHints( parent );
209  }
210 
211  return item0;
212 }
ProximMainFrame
Definition: ProximMainFrame.hh:58
ProximCmdHistoryWindow::onClose
void onClose(wxCommandEvent &event)
Definition: ProximCmdHistoryWindow.cc:111
WxConversion::toWxString
static wxString toWxString(const std::string &source)
SimulatorEvent.hh
EVT_SIMULATOR_COMMAND_DONE
EVT_SIMULATOR_COMMAND_DONE(0, ProximDisassemblyWindow::onSimulatorCommand) EVT_MENU_RANGE(MENU_ID_FIRST_MAPPED
ProximLineReader.hh
FindWindow
Definition: FindWindow.hh:49
ProximCmdHistoryWindow::onSave
void onSave(wxCommandEvent &event)
Definition: ProximCmdHistoryWindow.cc:132
ProximLineReader::input
void input(std::string command)
Definition: ProximLineReader.cc:131
ProximCmdHistoryWindow::ID_LINE
@ ID_LINE
Definition: ProximCmdHistoryWindow.hh:69
ProximCmdHistoryWindow::onSimulatorCommand
void onSimulatorCommand(SimulatorEvent &event)
Definition: ProximCmdHistoryWindow.cc:99
ProximCmdHistoryWindow.hh
ProximSimulatorWindow
Definition: ProximSimulatorWindow.hh:47
ProximCmdHistoryWindow::lineReader_
ProximLineReader & lineReader_
Line reader storing the command history.
Definition: ProximCmdHistoryWindow.hh:73
ErrorDialog
Definition: ErrorDialog.hh:42
ErrorDialog.hh
LineReader::inputsInHistory
virtual std::size_t inputsInHistory() const
Definition: LineReader.cc:150
ProximCmdHistoryWindow::cmdList_
wxListBox * cmdList_
ListBox widget displaying the command history.
Definition: ProximCmdHistoryWindow.hh:75
ProximCmdHistoryWindow::createContents
wxSizer * createContents(wxWindow *parent, bool set_sizer, bool call_fit)
Definition: ProximCmdHistoryWindow.cc:177
ProximLineReader
Definition: ProximLineReader.hh:60
LineReader::inputHistoryEntry
virtual std::string inputHistoryEntry(std::size_t age) const
Definition: LineReader.cc:165
ProximCmdHistoryWindow::ID_LIST
@ ID_LIST
Definition: ProximCmdHistoryWindow.hh:66
ProximCmdHistoryWindow::onCommandDClick
void onCommandDClick(wxCommandEvent &event)
Definition: ProximCmdHistoryWindow.cc:123
EVT_BUTTON
EVT_BUTTON(ID_EDIT_ARCH_PORT, FUImplementationDialog::onEditArchitecturePort) EVT_BUTTON(ID_ADD_EXTERNAL_PORT
ProximCmdHistoryWindow::updateCommandList
void updateCommandList()
Definition: ProximCmdHistoryWindow.cc:81
ProximCmdHistoryWindow
Definition: ProximCmdHistoryWindow.hh:47
ProximCmdHistoryWindow::ID_SAVE
@ ID_SAVE
Definition: ProximCmdHistoryWindow.hh:67
ProximCmdHistoryWindow::ID_CLOSE
@ ID_CLOSE
Definition: ProximCmdHistoryWindow.hh:68
WxConversion.hh
SimulatorEvent
Definition: SimulatorEvent.hh:42
ProximCmdHistoryWindow::~ProximCmdHistoryWindow
virtual ~ProximCmdHistoryWindow()
Definition: ProximCmdHistoryWindow.cc:73
WxConversion::toString
static std::string toString(const wxString &source)
END_EVENT_TABLE
END_EVENT_TABLE() using namespace IDF