]> 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
9 #include <wx/dirdlg.h>
10
11 #include <iostream>
12 #include <cstdio>
13 #include <iterator>
14 #include <fstream>
15 #include <string>
16 #include <algorithm>
17
18
19 using namespace std;
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 bool wxCreaDevManagerMainFrame::Create(
65   wxWindow* parent,
66   wxWindowID id,
67   const wxString& caption,
68   const wxPoint& pos,
69   const wxSize& size,
70   long style
71 )
72 {
73   wxFrame::Create(parent, id, caption, pos, size, style);
74   CreateMenus();
75   CreateControls();
76   return TRUE;
77 }
78
79 void wxCreaDevManagerMainFrame::CreateMenus()
80 {
81   wxMenuBar* menuBar = new wxMenuBar;
82
83   //FileMenu
84   menu_File = new wxMenu();
85   menu_File->Append(ID_MENU_NEW_PROJECT, _("&New Project..."));
86   menu_File->Append(ID_MENU_OPEN_PROJECT, _("&Open Project..."));
87   menu_File->Append(ID_MENU_OPEN_RECENT, _("Open &Recent"));
88   menu_File->AppendSeparator();
89   menu_File->Append(ID_MENU_CLOSE_PROJECT, _("&Close Project"));
90   menu_File->Append(ID_MENU_CLOSE_ALL_PROJECTS, _("C&lose All Projects"));
91   menu_File->AppendSeparator();
92   menu_File->Append(ID_MENU_EXPORT_HIERARCHY, _("&Export Project Hierarchy..."));
93   menu_File->AppendSeparator();
94   menu_File->Append(ID_MENU_EXIT, _("E&xit"));
95
96   menuBar->Append(menu_File, _("&File"));
97
98   //EditMenu
99   menu_Edit = new wxMenu();
100   menu_Edit->Append(ID_MENU_REFRESH_PROJECT, _("&Refresh Project"));
101   menu_Edit->AppendSeparator();
102   menu_Edit->Append(ID_MENU_CUT, _("Cu&t"));
103   menu_Edit->Append(ID_MENU_COPY, _("&Copy"));
104   menu_Edit->Append(ID_MENU_PASTE, _("&Paste"));
105   menu_Edit->AppendSeparator();
106   menu_Edit->Append(ID_MENU_DELETE, _("&Delete"));
107   menu_Edit->Append(ID_MENU_SELECT_ALL, _("Select &All"));
108   menu_Edit->Append(ID_MENU_SELECT_NONE, _("Ca&ncel Selection"));
109
110   menuBar->Append(menu_Edit, _("&Edit"));
111
112   //ToolsMenu
113   menu_Tools = new wxMenu();
114   menu_Tools->Append(ID_MENU_EVENT_LOG, _("Event &Log"));
115   menu_Tools->Append(ID_MENU_BBTK_GRAPHICAL_EDITOR, _("BBTK &Graphical Editor"));
116   menu_Tools->Append(ID_MENU_MINITOOLS, _("&MiniTools"));
117   menu_Tools->Append(ID_MENU_CODE_EDITOR, _("&Code Editor"));
118   menu_Tools->Append(ID_MENU_COMMAND_LINE, _("&Command Line"));
119
120   menuBar->Append(menu_Tools, _("&Tools"));
121
122   //HelpMenu
123   menu_Help = new wxMenu();
124   menu_Help->Append(ID_MENU_HELP, _("&Help"));
125   menu_Help->Append(ID_MENU_REPORT_BUG, _("Report &Bug"));
126   menu_Help->Append(ID_MENU_ABOUT_CREADEVMANAGER, _("&About CreaDevManager"));
127   menu_Help->Append(ID_MENU_ABOUT_CREATIS, _("A&bout CREATIS"));
128
129   menuBar->Append(menu_Help, _("&Help"));
130
131   //Set Bar
132   SetMenuBar(menuBar);
133
134   wxStatusBar* statusBar = new wxStatusBar(this, ID_STATUS_BAR, wxST_SIZEGRIP);
135   statusBar->SetFieldsCount(1);
136   SetStatusBar(statusBar);
137
138 }
139
140 void wxCreaDevManagerMainFrame::CreateControls()
141 {
142
143   auiManager.SetManagedWindow(this);
144
145
146   tree_Projects = new wxCreaDevManagerTreeCtrl(
147     this,
148     ID_TREE_PROJECTS,
149     wxDefaultPosition,
150     wxDefaultSize,
151     wxTR_HAS_BUTTONS | wxTR_AQUA_BUTTONS
152   );
153   tree_Projects->SetSize(400,100);
154   tree_Projects->SetMinSize(wxSize(300,100));
155
156   panel_Properties = new wxCreaDevManagerDescriptionPanel(
157     this,
158     ID_WINDOW_PROPERTIES,
159     _("Description Panel"),
160     wxDefaultPosition,
161     wxDefaultSize,
162     0
163   );
164
165
166
167   panel_ProjectActions = new wxCreaDevManagerProjectActionsPanel(
168     this,
169     ID_WINDOW_PROJ_ACTIONS,
170     _("Project Actions Panel"),
171     wxDefaultPosition,
172     wxDefaultSize,
173     0
174   );
175   panel_ProjectActions->SetMinSize(wxSize(500, 150));
176
177   auiManager.AddPane(tree_Projects, wxLEFT, wxT("Projects Tree"));
178   auiManager.AddPane(panel_ProjectActions, wxBOTTOM, wxT("Project Actions"));
179   auiManager.AddPane(panel_Properties, wxCENTER, wxT("Properties"));
180
181   auiManager.Update();
182   auiManager.GetPane(tree_Projects).CloseButton(false).MaximizeButton(true);
183     auiManager.GetPane(panel_Properties).CloseButton(false);
184 }
185
186 //Event Handlers
187 //File menu
188 void wxCreaDevManagerMainFrame::OnMenuNewProject(wxCommandEvent& event)
189 {
190   cerr << "Event OnMenuNewProject not implemented yet" << endl;
191   event.Skip();
192 }
193 void wxCreaDevManagerMainFrame::OnMenuOpenProject(wxCommandEvent& event)
194 {
195   cerr << "Event OnMenuOpenProject not implemented" << endl;
196
197   long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
198   wxDirDialog* FD = new wxDirDialog(this, crea::std2wx("Select the project directory"), crea::std2wx(""), style);
199   long userResponse;
200   userResponse = FD->ShowModal();
201   if(userResponse == wxID_OK)
202   {
203     string path = crea::wx2std (FD->GetPath());
204     cout << "selection path: "<< path << endl;
205     string path1 = path + "/Makefile";
206
207     FILE* pFile = fopen(path1.c_str(), "r");
208     if(pFile == NULL) // not the binary folder
209     {
210       cerr << path1 << ": file not found..." << endl;
211       path1 = path + "/CMakeLists.txt";
212       pFile = fopen(path1.c_str(), "r");
213       if(pFile == NULL) //not the source folder
214       {
215         cerr << path1 << ": file not found..." << endl;
216         wxMessageBox( wxT("No project selected."), wxT("Open Project - Error"), wxICON_ERROR);
217         event.Skip();
218         return;
219       }else{//source folder
220         cout << "sources folder found..." << endl;
221         fclose(pFile);
222       }
223     }else{//binary folder
224       cout << "binary folder found..." << endl;
225       fclose(pFile);
226
227       ifstream readFile;
228       readFile.open(path1.c_str());
229       string word;
230       bool found = false;
231       while(!found && readFile >> word)
232       {
233         //cout << word << endl;
234         if(word == "CMAKE_SOURCE_DIR")
235         {
236           readFile >> word;
237           readFile.ignore();
238           getline(readFile, word, '\n');
239           path = word;
240           found = true;
241         }
242       }
243       readFile.close();
244
245       if(!found)
246       {
247           cerr << "sources not found..." << endl;
248           wxMessageBox( wxT("Sources not found."), wxT("Open Project - Error"), wxICON_ERROR);
249           event.Skip();
250           return;
251       }else{
252           pFile = fopen(path.c_str(), "r");
253           cout << "sources at " << path << " open = " << (pFile != NULL) << endl;
254           cout.flush();
255       }
256     }
257
258
259     this->projectTree.addRoot(path);
260     this->projectTree.populateNode(path);
261
262     ((wxCreaDevManagerTreeCtrl*)tree_Projects)->BuildTree(this->projectTree);
263
264     auiManager.Update();
265   }
266   event.Skip();
267 }
268 void wxCreaDevManagerMainFrame::OnMenuOpenRecent(wxCommandEvent& event)
269 {
270   cerr << "Event OnMenuOpenRecent not implemented" << endl;
271   event.Skip();
272 }
273 void wxCreaDevManagerMainFrame::OnMenuCloseProject(wxCommandEvent& event)
274 {
275   cerr << "Event OnMenuCloseProject not implemented" << endl;
276   event.Skip();
277 }
278 void wxCreaDevManagerMainFrame::OnMenuCloseAllProjects(wxCommandEvent& event)
279 {
280   cerr << "Event OnMenuCloseAllProjects not implemented" << endl;
281   event.Skip();
282 }
283 void wxCreaDevManagerMainFrame::OnMenuExportHierarchy(wxCommandEvent& event)
284 {
285   cerr << "Event OnMenuExportHierarchy not implemented" << endl;
286   event.Skip();
287 }
288 void wxCreaDevManagerMainFrame::OnMenuExit(wxCommandEvent& event)
289 {
290   cout << "Closing CreaDevManager..." << endl;
291   Close();
292   event.Skip();
293 }
294
295 //Edit Menu
296 void wxCreaDevManagerMainFrame::OnMenuRefreshProject(wxCommandEvent& event)
297 {
298   cerr << "Event OnMenuRefreshProject not implemented" << endl;
299   event.Skip();
300 }
301 void wxCreaDevManagerMainFrame::OnMenuMenuCut(wxCommandEvent& event)
302 {
303   cerr << "Event OnMenuMenuCut not implemented" << endl;
304   event.Skip();
305 }
306 void wxCreaDevManagerMainFrame::OnMenuMenuCopy(wxCommandEvent& event)
307 {
308   cerr << "Event OnMenuMenuCopy not implemented" << endl;
309   event.Skip();
310 }
311 void wxCreaDevManagerMainFrame::OnMenuMenuPaste(wxCommandEvent& event)
312 {
313   cerr << "Event OnMenuMenuPaste not implemented" << endl;
314   event.Skip();
315 }
316 void wxCreaDevManagerMainFrame::OnMenuMenuDelete(wxCommandEvent& event)
317 {
318   cerr << "Event OnMenuMenuDelete not implemented" << endl;
319   event.Skip();
320 }
321 void wxCreaDevManagerMainFrame::OnMenuSelectAll(wxCommandEvent& event)
322 {
323   cerr << "Event OnMenuSelectAll not implemented" << endl;
324   event.Skip();
325 }
326 void wxCreaDevManagerMainFrame::OnMenuSelectNone(wxCommandEvent& event)
327 {
328   cerr << "Event OnMenuSelectNone not implemented" << endl;
329   event.Skip();
330 }
331
332 //Tools Menu
333 void wxCreaDevManagerMainFrame::OnMenuEventLog(wxCommandEvent& event)
334 {
335   cerr << "Event OnMenuEventLog not implemented" << endl;
336   event.Skip();
337 }
338 void wxCreaDevManagerMainFrame::OnMenuBBTKGraphicalEditor(wxCommandEvent& event)
339 {
340   cerr << "Event OnMenuBBTKGraphicalEditor not implemented" << endl;
341   event.Skip();
342 }
343 void wxCreaDevManagerMainFrame::OnMenuMiniTools(wxCommandEvent& event)
344 {
345   cerr << "Event OnMenuMiniTools not implemented" << endl;
346   event.Skip();
347 }
348 void wxCreaDevManagerMainFrame::OnMenuCodeEditor(wxCommandEvent& event)
349 {
350   cerr << "Event OnMenuCodeEditor not implemented" << endl;
351   event.Skip();
352 }
353 void wxCreaDevManagerMainFrame::OnMenuCommandLine(wxCommandEvent& event)
354 {
355   cerr << "Event OnMenuCommandLine not implemented" << endl;
356   event.Skip();
357 }
358
359 //Help Menu
360 void wxCreaDevManagerMainFrame::OnMenuHelp(wxCommandEvent& event)
361 {
362   cerr << "Event OnMenuHelp not implemented" << endl;
363   event.Skip();
364 }
365 void wxCreaDevManagerMainFrame::OnMenuReportBug(wxCommandEvent& event)
366 {
367   cerr << "Event OnMenuReportBug not implemented" << endl;
368   event.Skip();
369 }
370 void wxCreaDevManagerMainFrame::OnMenuAboutCreaDevManager(wxCommandEvent& event)
371 {
372   cerr << "Event OnMenuAboutCreaDevManager not implemented" << endl;
373   event.Skip();
374 }
375 void wxCreaDevManagerMainFrame::OnMenuAboutCreatis(wxCommandEvent& event)
376 {
377   cerr << "Event OnMenuAboutCreatis not implemented" << endl;
378   event.Skip();
379 }