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