]> Creatis software - crea.git/blob - lib/creaDevManagerLib/wxCreaDevManagerMainFrame.cxx
Feature #1711
[crea.git] / lib / creaDevManagerLib / wxCreaDevManagerMainFrame.cxx
1 #include "wxCreaDevManagerMainFrame.h"
2 #include "creaDevManagerIds.h"
3
4 #include "wxCreaDevManagerTreeCtrl.h"
5
6 #include "wxCreaDevManagerDescriptionPanel.h"
7 #include "wxCreaDevManagerProjectActionsPanel.h"
8 #include "wxCreaDevManagerNewProjectDialog.h"
9 #include "ControlCreaDevManagerMain.h"
10
11 #include <wx/dirdlg.h>
12
13 #include <iostream>
14 #include <cstdio>
15 #include <iterator>
16 #include <fstream>
17 #include <string>
18 #include <algorithm>
19
20
21 BEGIN_EVENT_TABLE(wxCreaDevManagerMainFrame, wxFrame)
22   EVT_MENU(ID_MENU_NEW_PROJECT, wxCreaDevManagerMainFrame::OnMenuNewProject)
23   EVT_MENU(ID_MENU_OPEN_PROJECT, wxCreaDevManagerMainFrame::OnMenuOpenProject)
24   EVT_MENU(ID_MENU_OPEN_RECENT, wxCreaDevManagerMainFrame::OnMenuOpenRecent)
25   EVT_MENU(ID_MENU_CLOSE_PROJECT, wxCreaDevManagerMainFrame::OnMenuCloseProject)
26   EVT_MENU(ID_MENU_CLOSE_ALL_PROJECTS, wxCreaDevManagerMainFrame::OnMenuCloseAllProjects)
27   EVT_MENU(ID_MENU_EXPORT_HIERARCHY, wxCreaDevManagerMainFrame::OnMenuExportHierarchy)
28   EVT_MENU(ID_MENU_EXIT, wxCreaDevManagerMainFrame::OnMenuExit)
29   EVT_MENU(ID_MENU_REFRESH_PROJECT, wxCreaDevManagerMainFrame::OnMenuRefreshProject)
30   EVT_MENU(ID_MENU_CUT, wxCreaDevManagerMainFrame::OnMenuMenuCut)
31   EVT_MENU(ID_MENU_COPY, wxCreaDevManagerMainFrame::OnMenuMenuCopy)
32   EVT_MENU(ID_MENU_PASTE, wxCreaDevManagerMainFrame::OnMenuMenuPaste)
33   EVT_MENU(ID_MENU_DELETE, wxCreaDevManagerMainFrame::OnMenuMenuDelete)
34   EVT_MENU(ID_MENU_SELECT_ALL, wxCreaDevManagerMainFrame::OnMenuSelectAll)
35   EVT_MENU(ID_MENU_SELECT_NONE, wxCreaDevManagerMainFrame::OnMenuSelectNone)
36   EVT_MENU(ID_MENU_EVENT_LOG, wxCreaDevManagerMainFrame::OnMenuEventLog)
37   EVT_MENU(ID_MENU_BBTK_GRAPHICAL_EDITOR, wxCreaDevManagerMainFrame::OnMenuBBTKGraphicalEditor)
38   EVT_MENU(ID_MENU_MINITOOLS, wxCreaDevManagerMainFrame::OnMenuMiniTools)
39   EVT_MENU(ID_MENU_CODE_EDITOR, wxCreaDevManagerMainFrame::OnMenuCodeEditor)
40   EVT_MENU(ID_MENU_COMMAND_LINE, wxCreaDevManagerMainFrame::OnMenuCommandLine)
41   EVT_MENU(ID_MENU_HELP, wxCreaDevManagerMainFrame::OnMenuHelp)
42   EVT_MENU(ID_MENU_REPORT_BUG, wxCreaDevManagerMainFrame::OnMenuReportBug)
43   EVT_MENU(ID_MENU_ABOUT_CREADEVMANAGER, wxCreaDevManagerMainFrame::OnMenuAboutCreaDevManager)
44   EVT_MENU(ID_MENU_ABOUT_CREATIS, wxCreaDevManagerMainFrame::OnMenuAboutCreatis)
45 END_EVENT_TABLE()
46
47 wxCreaDevManagerMainFrame::wxCreaDevManagerMainFrame(
48   wxWindow* parent,
49   wxWindowID id,
50   const wxString& caption,
51   const wxPoint& pos,
52   const wxSize& size,
53   long style
54 )
55 {
56   Create(parent, id, caption, pos, size, style);
57 }
58
59 wxCreaDevManagerMainFrame::~wxCreaDevManagerMainFrame()
60 {
61   auiManager.UnInit();
62 }
63
64 void wxCreaDevManagerMainFrame::UpdateVisual()
65 {
66   auiManager.Update();
67   this->Update();
68 }
69
70 bool wxCreaDevManagerMainFrame::Create(
71   wxWindow* parent,
72   wxWindowID id,
73   const wxString& caption,
74   const wxPoint& pos,
75   const wxSize& size,
76   long style
77 )
78 {
79   wxFrame::Create(parent, id, caption, pos, size, style);
80   this->controller = new ControlCreaDevManagerMain();
81   this->controller->LoadActiveProjects();
82   CreateMenus();
83   CreateControls();
84   return TRUE;
85 }
86
87 void wxCreaDevManagerMainFrame::CreateMenus()
88 {
89   wxMenuBar* menuBar = new wxMenuBar;
90
91   //FileMenu
92   menu_File = new wxMenu();
93   menu_File->Append(ID_MENU_NEW_PROJECT, wxString("&New Project..."));
94   menu_File->Append(ID_MENU_OPEN_PROJECT, wxString("&Open Project..."));
95   menu_File->Append(ID_MENU_OPEN_RECENT, wxString("Open &Recent"));
96   menu_File->AppendSeparator();
97   menu_File->Append(ID_MENU_CLOSE_PROJECT, wxString("&Close Project"));
98   menu_File->Append(ID_MENU_CLOSE_ALL_PROJECTS, wxString("C&lose All Projects"));
99   menu_File->AppendSeparator();
100   menu_File->Append(ID_MENU_EXPORT_HIERARCHY, wxString("&Export Project Hierarchy..."));
101   menu_File->AppendSeparator();
102   menu_File->Append(ID_MENU_EXIT, wxString("E&xit"));
103
104   menuBar->Append(menu_File, wxString("&File"));
105
106   //EditMenu
107   menu_Edit = new wxMenu();
108   menu_Edit->Append(ID_MENU_REFRESH_PROJECT, wxString("&Refresh Project"));
109   menu_Edit->AppendSeparator();
110   menu_Edit->Append(ID_MENU_CUT, wxString("Cu&t"));
111   menu_Edit->Append(ID_MENU_COPY, wxString("&Copy"));
112   menu_Edit->Append(ID_MENU_PASTE, wxString("&Paste"));
113   menu_Edit->AppendSeparator();
114   menu_Edit->Append(ID_MENU_DELETE, wxString("&Delete"));
115   menu_Edit->Append(ID_MENU_SELECT_ALL, wxString("Select &All"));
116   menu_Edit->Append(ID_MENU_SELECT_NONE, wxString("Ca&ncel Selection"));
117
118   menuBar->Append(menu_Edit, wxString("&Edit"));
119
120   //ToolsMenu
121   menu_Tools = new wxMenu();
122   menu_Tools->Append(ID_MENU_EVENT_LOG, wxString("Event &Log"));
123   menu_Tools->Append(ID_MENU_BBTK_GRAPHICAL_EDITOR, wxString("BBTK &Graphical Editor"));
124   menu_Tools->Append(ID_MENU_MINITOOLS, wxString("&MiniTools"));
125   menu_Tools->Append(ID_MENU_CODE_EDITOR, wxString("&Code Editor"));
126   menu_Tools->Append(ID_MENU_COMMAND_LINE, wxString("&Command Line"));
127
128   menuBar->Append(menu_Tools, wxString("&Tools"));
129
130   //HelpMenu
131   menu_Help = new wxMenu();
132   menu_Help->Append(ID_MENU_HELP, wxString("&Help"));
133   menu_Help->Append(ID_MENU_REPORT_BUG, wxString("Report &Bug"));
134   menu_Help->Append(ID_MENU_ABOUT_CREADEVMANAGER, wxString("&About CreaDevManager"));
135   menu_Help->Append(ID_MENU_ABOUT_CREATIS, wxString("A&bout CREATIS"));
136
137   menuBar->Append(menu_Help, wxString("&Help"));
138
139   //Set Bar
140   SetMenuBar(menuBar);
141
142   wxStatusBar* statusBar = new wxStatusBar(this, ID_STATUS_BAR, wxST_SIZEGRIP);
143   statusBar->SetFieldsCount(1);
144   SetStatusBar(statusBar);
145
146 }
147
148 void wxCreaDevManagerMainFrame::CreateControls()
149 {
150
151   auiManager.SetManagedWindow(this);
152
153
154   tree_Projects = new wxCreaDevManagerTreeCtrl(
155     this,
156     ID_TREE_PROJECTS,
157     wxDefaultPosition,
158     wxDefaultSize,
159     wxTR_HAS_BUTTONS | wxTR_AQUA_BUTTONS
160   );
161   tree_Projects->SetSize(400,100);
162   tree_Projects->SetMinSize(wxSize(300,100));
163
164   panel_Properties = new wxCreaDevManagerDescriptionPanel(
165     this,
166     ID_WINDOW_PROPERTIES,
167     wxString("Description Panel"),
168     wxDefaultPosition,
169     wxDefaultSize,
170     0
171   );
172
173
174
175   panel_ProjectActions = new wxCreaDevManagerProjectActionsPanel(
176     this,
177     ID_WINDOW_PROJ_ACTIONS,
178     wxString("Project Actions Panel"),
179     wxDefaultPosition,
180     wxDefaultSize,
181     0
182   );
183   panel_ProjectActions->SetMinSize(wxSize(500, 150));
184
185   auiManager.AddPane(tree_Projects, wxLEFT, wxString("Projects Tree"));
186   auiManager.AddPane(panel_ProjectActions, wxBOTTOM, wxString("Project Actions"));
187   auiManager.AddPane(panel_Properties, wxCENTER, wxString("Properties"));
188
189   auiManager.Update();
190   auiManager.GetPane(tree_Projects).CloseButton(false).MaximizeButton(true);
191   auiManager.GetPane(panel_Properties).CloseButton(false);
192 }
193
194 //Event Handlers
195 //File menu
196 void wxCreaDevManagerMainFrame::OnMenuNewProject(wxCommandEvent& event)
197 {
198   wxCreaDevManagerNewProjectDialog* dialog = new wxCreaDevManagerNewProjectDialog(this, this->controller);
199   long userResponse;
200   userResponse = dialog->ShowModal();
201
202   ((wxCreaDevManagerTreeCtrl*)tree_Projects)->BuildTree(this->controller->GetActiveProjects());
203
204   this->UpdateVisual();
205
206   event.Skip();
207 }
208 void wxCreaDevManagerMainFrame::OnMenuOpenProject(wxCommandEvent& event)
209 {
210   long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
211   wxDirDialog* FD = new wxDirDialog(this, wxString("Select the project directory"), wxString(""), style);
212   long userResponse;
213   userResponse = FD->ShowModal();
214   if(userResponse == wxID_OK)
215   {
216     switch(this->controller->OpenProject(crea::wx2std (FD->GetPath())))
217     {
218     case 1:
219       wxMessageBox( wxT("No project selected."), wxT("Open Project - Error"), wxICON_ERROR);
220       event.Skip();
221       break;
222     case 2:
223       wxMessageBox( wxString("Sources not found."), wxString("Open Project - Error"), wxICON_ERROR);
224       event.Skip();
225       break;
226     case 0:
227       break;
228     };
229
230     ((wxCreaDevManagerTreeCtrl*)tree_Projects)->BuildTree(this->controller->GetActiveProjects());
231
232     auiManager.Update();
233   }
234   event.Skip();
235 }
236 void wxCreaDevManagerMainFrame::OnMenuOpenRecent(wxCommandEvent& event)
237 {
238   std::cerr << "Event OnMenuOpenRecent not implemented" << std::endl;
239   event.Skip();
240 }
241 void wxCreaDevManagerMainFrame::OnMenuCloseProject(wxCommandEvent& event)
242 {
243   std::cerr << "Event OnMenuCloseProject not implemented" << std::endl;
244   event.Skip();
245 }
246 void wxCreaDevManagerMainFrame::OnMenuCloseAllProjects(wxCommandEvent& event)
247 {
248   std::cerr << "Event OnMenuCloseAllProjects not implemented" << std::endl;
249   event.Skip();
250 }
251 void wxCreaDevManagerMainFrame::OnMenuExportHierarchy(wxCommandEvent& event)
252 {
253   std::cerr << "Event OnMenuExportHierarchy not implemented" << std::endl;
254   event.Skip();
255 }
256 void wxCreaDevManagerMainFrame::OnMenuExit(wxCommandEvent& event)
257 {
258   std::cout << "Closing CreaDevManager..." << std::endl;
259   Close();
260   event.Skip();
261 }
262
263 //Edit Menu
264 void wxCreaDevManagerMainFrame::OnMenuRefreshProject(wxCommandEvent& event)
265 {
266   std::cerr << "Event OnMenuRefreshProject not implemented" << std::endl;
267   event.Skip();
268 }
269 void wxCreaDevManagerMainFrame::OnMenuMenuCut(wxCommandEvent& event)
270 {
271   std::cerr << "Event OnMenuMenuCut not implemented" << std::endl;
272   event.Skip();
273 }
274 void wxCreaDevManagerMainFrame::OnMenuMenuCopy(wxCommandEvent& event)
275 {
276   std::cerr << "Event OnMenuMenuCopy not implemented" << std::endl;
277   event.Skip();
278 }
279 void wxCreaDevManagerMainFrame::OnMenuMenuPaste(wxCommandEvent& event)
280 {
281   std::cerr << "Event OnMenuMenuPaste not implemented" << std::endl;
282   event.Skip();
283 }
284 void wxCreaDevManagerMainFrame::OnMenuMenuDelete(wxCommandEvent& event)
285 {
286   std::cerr << "Event OnMenuMenuDelete not implemented" << std::endl;
287   event.Skip();
288 }
289 void wxCreaDevManagerMainFrame::OnMenuSelectAll(wxCommandEvent& event)
290 {
291   std::cerr << "Event OnMenuSelectAll not implemented" << std::endl;
292   event.Skip();
293 }
294 void wxCreaDevManagerMainFrame::OnMenuSelectNone(wxCommandEvent& event)
295 {
296   std::cerr << "Event OnMenuSelectNone not implemented" << std::endl;
297   event.Skip();
298 }
299
300 //Tools Menu
301 void wxCreaDevManagerMainFrame::OnMenuEventLog(wxCommandEvent& event)
302 {
303   std::cerr << "Event OnMenuEventLog not implemented" << std::endl;
304   event.Skip();
305 }
306 void wxCreaDevManagerMainFrame::OnMenuBBTKGraphicalEditor(wxCommandEvent& event)
307 {
308   std::cerr << "Event OnMenuBBTKGraphicalEditor not implemented" << std::endl;
309   event.Skip();
310 }
311 void wxCreaDevManagerMainFrame::OnMenuMiniTools(wxCommandEvent& event)
312 {
313   std::cerr << "Event OnMenuMiniTools not implemented" << std::endl;
314   event.Skip();
315 }
316 void wxCreaDevManagerMainFrame::OnMenuCodeEditor(wxCommandEvent& event)
317 {
318   std::cerr << "Event OnMenuCodeEditor not implemented" << std::endl;
319   event.Skip();
320 }
321 void wxCreaDevManagerMainFrame::OnMenuCommandLine(wxCommandEvent& event)
322 {
323   std::cerr << "Event OnMenuCommandLine not implemented" << std::endl;
324   event.Skip();
325 }
326
327 //Help Menu
328 void wxCreaDevManagerMainFrame::OnMenuHelp(wxCommandEvent& event)
329 {
330   std::cerr << "Event OnMenuHelp not implemented" << std::endl;
331   event.Skip();
332 }
333 void wxCreaDevManagerMainFrame::OnMenuReportBug(wxCommandEvent& event)
334 {
335   std::cerr << "Event OnMenuReportBug not implemented" << std::endl;
336   event.Skip();
337 }
338 void wxCreaDevManagerMainFrame::OnMenuAboutCreaDevManager(wxCommandEvent& event)
339 {
340   std::cerr << "Event OnMenuAboutCreaDevManager not implemented" << std::endl;
341   event.Skip();
342 }
343 void wxCreaDevManagerMainFrame::OnMenuAboutCreatis(wxCommandEvent& event)
344 {
345   std::cerr << "Event OnMenuAboutCreatis not implemented" << std::endl;
346   event.Skip();
347 }