]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - tools/src/tools/configtool/standalone/wxwin/mainwin.cpp
Cleanup CVS ipmorted branch
[karo-tx-redboot.git] / tools / src / tools / configtool / standalone / wxwin / mainwin.cpp
1 //####COPYRIGHTBEGIN####
2 //
3 // ----------------------------------------------------------------------------
4 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
5 // Copyright (C) 2003 John Dallaway
6 //
7 // This program is part of the eCos host tools.
8 //
9 // This program is free software; you can redistribute it and/or modify it
10 // under the terms of the GNU General Public License as published by the Free
11 // Software Foundation; either version 2 of the License, or (at your option)
12 // any later version.
13 //
14 // This program is distributed in the hope that it will be useful, but WITHOUT
15 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
17 // more details.
18 //
19 // You should have received a copy of the GNU General Public License along with
20 // this program; if not, write to the Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22 //
23 // ----------------------------------------------------------------------------
24 //
25 //####COPYRIGHTEND####
26 // mainwin.cpp :
27 //
28 //===========================================================================
29 //#####DESCRIPTIONBEGIN####
30 //
31 // Author(s):   julians, jld
32 // Contact(s):  julians, jld
33 // Date:        2000/08/24
34 // Version:     $Id: mainwin.cpp,v 1.57 2002/02/28 18:30:35 julians Exp $
35 // Purpose:
36 // Description: Implementation file for the ConfigTool main window
37 // Requires:
38 // Provides:
39 // See also:
40 // Known bugs:
41 // Usage:
42 //
43 //####DESCRIPTIONEND####
44 //
45 //===========================================================================
46
47 // ============================================================================
48 // declarations
49 // ============================================================================
50
51 // ----------------------------------------------------------------------------
52 // headers
53 // ----------------------------------------------------------------------------
54 #ifdef __GNUG__
55 #pragma implementation "mainwin.h"
56 #endif
57
58 // Includes other headers for precompiled compilation
59 #include "ecpch.h"
60
61 #ifdef __BORLANDC__
62 #pragma hdrstop
63 #endif
64
65 #include "wx/cshelp.h"
66 #include "wx/wxhtml.h"
67 #include "wx/filedlg.h"
68 #include "wx/wfstream.h"
69
70 #include "mainwin.h"
71 #include "configtool.h"
72 #include "configtree.h"
73 #include "propertywin.h"
74 #include "conflictwin.h"
75 #include "mltwin.h"
76 #include "outputwin.h"
77 #include "shortdescrwin.h"
78 #include "conflictsdlg.h"
79 #include "aboutdlg.h"
80 #include "finddlg.h"
81 #include "settingsdlg.h"
82 #include "platformsdlg.h"
83 #include "buildoptionsdlg.h"
84 #include "templatesdlg.h"
85 #include "admindlg.h"
86 #include "packagesdlg.h"
87 #include "configtooldoc.h"
88 #include "configtoolview.h"
89 #include "folderdlg.h"
90 #include "reposdlg.h"
91 #include "docsystem.h"
92
93 #ifdef __WXMSW__
94 #include "wx/msw/winundef.h"
95 #endif
96
97 // ----------------------------------------------------------------------------
98 // resources
99 // ----------------------------------------------------------------------------
100 // the application icon
101 #if defined(__WXGTK__) || defined(__WXMOTIF__)
102 #include "bitmaps/configtool.xpm"
103 #include "bitmaps/new.xpm"
104 #include "bitmaps/open.xpm"
105 #include "bitmaps/save.xpm"
106 #include "bitmaps/copy.xpm"
107 #include "bitmaps/paste.xpm"
108 #include "bitmaps/cut.xpm"
109 #include "bitmaps/delete.xpm"
110 #include "bitmaps/help.xpm"
111 #include "bitmaps/cshelp.xpm"
112 #include "bitmaps/search.xpm"
113 #include "bitmaps/stopbuild.xpm"
114 #include "bitmaps/buildlibrary.xpm"
115 #include "bitmaps/newregion.xpm"
116 #include "bitmaps/newsection.xpm"
117 #include "bitmaps/properties.xpm"
118 #endif
119
120 // ----------------------------------------------------------------------------
121 // event tables and other macros for wxWindows
122 // ----------------------------------------------------------------------------
123
124 BEGIN_EVENT_TABLE(ecMainFrame, wxDocParentFrame)
125     EVT_MENU(wxID_EXIT,  ecMainFrame::OnQuit)
126     EVT_MENU(wxID_ABOUT, ecMainFrame::OnAbout)
127     EVT_MENU(ecID_REPOSITORY_INFO, ecMainFrame::OnRepositoryInfo)
128     EVT_MENU(wxID_FIND, ecMainFrame::OnFind)
129     EVT_MENU(ecID_FIND_NEXT, ecMainFrame::OnFindNext)
130     EVT_SASH_DRAGGED_RANGE(ecID_CONFIG_SASH_WINDOW, ecID_OUTPUT_SASH_WINDOW, ecMainFrame::OnSashDrag)
131     EVT_SIZE(ecMainFrame::OnSize)
132     EVT_IDLE(ecMainFrame::OnIdle)
133     EVT_CLOSE(ecMainFrame::OnCloseWindow)
134     EVT_MENU(ecID_TOGGLE_CONFLICTS, ecMainFrame::OnToggleWindow)
135     EVT_MENU(ecID_TOGGLE_PROPERTIES, ecMainFrame::OnToggleWindow)
136     EVT_MENU(ecID_TOGGLE_MEMORY, ecMainFrame::OnToggleWindow)
137     EVT_MENU(ecID_TOGGLE_SHORT_DESCR, ecMainFrame::OnToggleWindow)
138     EVT_MENU(ecID_TOGGLE_OUTPUT, ecMainFrame::OnToggleWindow)
139     EVT_MENU(ecID_TOOLBARS, ecMainFrame::OnToggleToolbar)
140     EVT_MENU(ecID_CONFIGTOOL_HELP, ecMainFrame::OnHelpConfigtool)
141     EVT_MENU(ecID_ECOS_HELP, ecMainFrame::OnHelpEcos)
142     EVT_MENU(ecID_CONTEXT_HELP, ecMainFrame::OnHelpContext)
143     EVT_MENU(ecID_RESOLVE_CONFLICTS, ecMainFrame::OnResolveConflicts)
144     EVT_UPDATE_UI(ecID_RESOLVE_CONFLICTS, ecMainFrame::OnUpdateResolveConflicts)
145     EVT_MENU(ecID_SETTINGS, ecMainFrame::OnSettings)
146     EVT_MENU(ecID_PLATFORMS, ecMainFrame::OnPlatforms)
147     EVT_MENU(ecID_BUILD_OPTIONS, ecMainFrame::OnBuildOptions)
148     EVT_MENU(ecID_PATHS_BUILD_TOOLS, ecMainFrame::OnBuildToolsPath)
149     EVT_MENU(ecID_PATHS_USER_TOOLS, ecMainFrame::OnUserToolsPath)
150     EVT_MENU(ecID_BUILD_TEMPLATES, ecMainFrame::OnTemplates)
151     EVT_MENU(ecID_ADMINISTRATION, ecMainFrame::OnAdmin)
152     EVT_MENU(ecID_BUILD_PACKAGES, ecMainFrame::OnPackages)
153     EVT_MENU(ecID_RUN_TESTS, ecMainFrame::OnRunTests)
154     EVT_MENU(ecID_BUILD_REPOSITORY, ecMainFrame::OnChooseRepository)
155     EVT_MENU(ecID_WHATS_THIS, ecMainFrame::OnWhatsThis)
156     EVT_MENU(ecID_SAVE_OUTPUT, ecMainFrame::OnSaveOutput)
157     EVT_MENU(ecID_IMPORT, ecMainFrame::OnImport)
158     EVT_MENU(ecID_EXPORT, ecMainFrame::OnExport)
159     EVT_MENU(ecID_REDHAT_WEB_HOME, ecMainFrame::OnWebRedHatHome)
160     EVT_MENU(ecID_REDHAT_WEB_ECOS, ecMainFrame::OnWebEcos)
161     EVT_MENU(ecID_REDHAT_WEB_NET_RELEASE, ecMainFrame::OnWebNetRelease)
162     EVT_MENU(ecID_REDHAT_WEB_UITRON, ecMainFrame::OnWebUitron)
163     EVT_MENU(ecID_STOP_BUILD, ecMainFrame::OnStopBuild)
164     EVT_MENU(ecID_BUILD_LIBRARY, ecMainFrame::OnBuildLibrary)
165     EVT_MENU(ecID_BUILD_TESTS, ecMainFrame::OnBuildTests)
166     EVT_MENU(ecID_CLEAN, ecMainFrame::OnClean)
167     EVT_MENU(ecID_SHELL, ecMainFrame::OnShell)
168     EVT_MENU(ecID_INDEX_DOCS, ecMainFrame::OnIndexDocs)
169     EVT_MENU(ecID_GENERATE_BUILD_TREE, ecMainFrame::OnGenerateBuildTree)
170
171     EVT_UPDATE_UI(ecID_PLATFORMS, ecMainFrame::OnUpdatePlatforms)
172     EVT_UPDATE_UI(ecID_BUILD_OPTIONS, ecMainFrame::OnUpdateBuildOptions)
173     EVT_UPDATE_UI(ecID_PATHS_BUILD_TOOLS, ecMainFrame::OnUpdateBuildToolsPath)
174     EVT_UPDATE_UI(ecID_PATHS_USER_TOOLS, ecMainFrame::OnUpdateUserToolsPath)
175     EVT_UPDATE_UI(ecID_BUILD_TEMPLATES, ecMainFrame::OnUpdateTemplates)
176     EVT_UPDATE_UI(ecID_ADMINISTRATION, ecMainFrame::OnUpdateAdmin)
177     EVT_UPDATE_UI(ecID_BUILD_PACKAGES, ecMainFrame::OnUpdatePackages)
178     EVT_UPDATE_UI(ecID_RUN_TESTS, ecMainFrame::OnUpdateRunTests)
179     EVT_UPDATE_UI(ecID_BUILD_REPOSITORY, ecMainFrame::OnUpdateChooseRepository)
180     EVT_UPDATE_UI(ecID_CLEAN, ecMainFrame::OnUpdateClean)
181     EVT_UPDATE_UI(ecID_REPOSITORY_INFO, ecMainFrame::OnUpdateRepositoryInfo)  
182     EVT_UPDATE_UI(ecID_INDEX_DOCS, ecMainFrame::OnUpdateIndexDocs)
183
184     EVT_UPDATE_UI(ecID_TOGGLE_CONFLICTS, ecMainFrame::OnUpdateToggleWindow)
185     EVT_UPDATE_UI(ecID_TOGGLE_PROPERTIES, ecMainFrame::OnUpdateToggleWindow)
186     EVT_UPDATE_UI(ecID_TOGGLE_MEMORY, ecMainFrame::OnUpdateToggleWindow)
187     EVT_UPDATE_UI(ecID_TOGGLE_SHORT_DESCR, ecMainFrame::OnUpdateToggleWindow)
188     EVT_UPDATE_UI(ecID_TOGGLE_OUTPUT, ecMainFrame::OnUpdateToggleWindow)
189     EVT_UPDATE_UI(ecID_TOOLBARS, ecMainFrame::OnUpdateToggleToolbar)
190
191     // Disable commands that don't make sense immediately or are not yet implemented.
192     // Also, for text controls, disable if they are not being enabled by currently-focussed controls.
193     EVT_UPDATE_UI(wxID_COPY, ecMainFrame::OnUpdateDisable)
194     EVT_UPDATE_UI(wxID_CUT, ecMainFrame::OnUpdateDisable)
195     EVT_UPDATE_UI(wxID_PASTE, ecMainFrame::OnUpdateDisable)
196     EVT_UPDATE_UI(wxID_SELECTALL, ecMainFrame::OnUpdateSelectAll)
197     EVT_UPDATE_UI(wxID_CLEAR, ecMainFrame::OnUpdateClear)
198
199     EVT_UPDATE_UI(wxID_FIND, ecMainFrame::OnUpdateFind)
200     EVT_UPDATE_UI(ecID_FIND_NEXT, ecMainFrame::OnUpdateFindNext)
201
202     EVT_MENU(ecID_NEW_REGION, ecMainFrame::OnNewRegion)
203     EVT_MENU(ecID_NEW_SECTION, ecMainFrame::OnNewSection)
204     EVT_MENU(ecID_DELETE, ecMainFrame::OnDeleteRegionOrSection)
205     EVT_MENU(ecID_PROPERTIES, ecMainFrame::OnRegionOrSectionProperties)
206
207     EVT_UPDATE_UI(ecID_STOP_BUILD, ecMainFrame::OnUpdateStopBuild)
208     EVT_UPDATE_UI(ecID_BUILD_LIBRARY, ecMainFrame::OnUpdateBuildLibrary)
209     EVT_UPDATE_UI(ecID_BUILD_TESTS, ecMainFrame::OnUpdateBuildTests)
210     EVT_UPDATE_UI(ecID_GENERATE_BUILD_TREE, ecMainFrame::OnUpdateGenerateBuildTree)
211
212     EVT_UPDATE_UI(ecID_SHELL, ecMainFrame::OnUpdateShell)
213
214     EVT_UPDATE_UI(ecID_NEW_REGION, ecMainFrame::OnUpdateNewRegion)
215     EVT_UPDATE_UI(ecID_NEW_SECTION, ecMainFrame::OnUpdateNewSection)
216     EVT_UPDATE_UI(ecID_DELETE, ecMainFrame::OnUpdateDeleteRegionOrSection)
217     EVT_UPDATE_UI(ecID_PROPERTIES, ecMainFrame::OnUpdateRegionOrSectionProperties)
218
219     EVT_UPDATE_UI(ecID_IMPORT, ecMainFrame::OnUpdateImport)
220     EVT_UPDATE_UI(ecID_EXPORT, ecMainFrame::OnUpdateExport)
221 END_EVENT_TABLE()
222
223 // ----------------------------------------------------------------------------
224 // main frame
225 // ----------------------------------------------------------------------------
226
227 // Frame constructor
228 ecMainFrame::ecMainFrame(wxDocManager *manager, const wxString& title, const wxPoint& pos, const wxSize& size):
229     wxDocParentFrame(manager, (wxFrame *)NULL, ecID_MAIN_FRAME, title, pos, size, wxDEFAULT_FRAME_STYLE|wxCLIP_CHILDREN|wxNO_FULL_REPAINT_ON_RESIZE )
230 {
231     m_splitter = NULL;
232     m_scrolledWindow = NULL;
233     m_tree = NULL;
234     m_configSashWindow = NULL;
235     m_valueWindow = NULL;
236     m_outputWindow = NULL;
237     m_shortDescrWindow = NULL;
238     m_conflictsSashWindow = NULL;
239     m_propertiesSashWindow = NULL;
240     m_memorySashWindow = NULL;
241     m_shortDescrSashWindow = NULL;
242     m_outputSashWindow = NULL;
243     m_propertyListWindow = NULL;
244     m_findDialog = NULL;
245     m_mltWindow = NULL;
246     
247 #ifdef __WXMAC__
248     // we need this in order to allow the about menu relocation, since ABOUT is
249     // not the default id of the about menu
250     wxApp::s_macAboutMenuItemId = wxID_EXIT;
251 #endif
252     
253     CreateWindows();
254
255     wxIcon mainIcon(wxICON(configtool));
256     wxGetApp().SetMainIcon(mainIcon);
257     
258     // set the frame icon
259     SetIcon(mainIcon);
260     
261     // create a menu bar
262
263     // File menu
264     wxMenu *fileMenu = new wxMenu(wxT(""), wxMENU_TEAROFF);
265     
266     fileMenu->Append(wxID_NEW, _("&New\tCtrl+N"), _("Creates a new document"));
267 #if 0
268     wxMenuItem* menuItem = new wxMenuItem(fileMenu, wxID_NEW, _("&New\tCtrl+N"), _("Creates a new document"));
269     menuItem->SetBitmaps(wxBITMAP(new));
270     fileMenu->Append(menuItem);
271 #endif
272     
273     fileMenu->Append(wxID_OPEN, _("&Open\tCtrl+O"), _("Opens an existing document"));
274     fileMenu->Append(wxID_SAVE, _("&Save\tCtrl+S"), _("Saves the active document"));
275     fileMenu->Append(wxID_SAVEAS, _("Save &As..."), _("Saves the active document with a new name"));
276     fileMenu->AppendSeparator();
277     fileMenu->Append(ecID_IMPORT, _("&Import..."), _("Imports a minimal configuration exported from another configuration"));
278     fileMenu->Append(ecID_EXPORT, _("&Export..."), _("Exports a minimal configuration for importing into another configuration"));
279     fileMenu->AppendSeparator();   
280     fileMenu->Append(wxID_EXIT, _("E&xit\tAlt+X"), _("Quits the application"));
281
282     // A history of files visited. Use this menu.
283     wxGetApp().GetDocManager()->FileHistoryUseMenu(fileMenu);
284     // Load file history
285     {
286         wxConfig config(wxGetApp().GetSettings().GetConfigAppName());
287         config.SetPath(wxT("FileHistory/"));
288         wxGetApp().GetDocManager()->FileHistoryLoad(config);
289     }
290     
291     // Edit menu
292     wxMenu* editMenu = new wxMenu(wxT(""), wxMENU_TEAROFF);
293     
294     editMenu->Append(wxID_CUT, _("Cu&t\tCtrl+X"), _("Cuts the output pane selection and moves it to the Clipboard"));
295     editMenu->Append(wxID_COPY, _("&Copy\tCtrl+C"), _("Copies the output pane selection to the clipboard"));
296     editMenu->Append(wxID_PASTE, _("&Paste\tCtrl+V"), _("Inserts Clipboard contents"));
297     editMenu->Append(wxID_CLEAR, _("&Clear"), _("Erases everything in the output pane"));
298     editMenu->AppendSeparator();
299     editMenu->Append(wxID_SELECTALL, _("&Select All\tCtrl+A"), _("Selects the entire output pane"));
300     editMenu->AppendSeparator();
301     editMenu->Append(wxID_FIND, _("&Find...\tCtrl+F"), _("Finds the specified text"));
302     editMenu->Append(ecID_FIND_NEXT, _("Find &Next\tF3"), _("Finds the next item matching the Find text"));
303     editMenu->AppendSeparator();
304     editMenu->Append(ecID_SAVE_OUTPUT, _("Sa&ve Output..."), _("Saves the contents of the output pane"));
305     
306     // View menu
307     wxMenu* viewMenu = new wxMenu(wxT(""), wxMENU_TEAROFF);
308     
309     viewMenu->Append(ecID_SETTINGS, _("&Settings...\tCtrl+T"), _("Shows the application settings dialog"));
310     viewMenu->AppendSeparator();
311     viewMenu->Append(ecID_TOOLBARS, _("&Toolbar"), _("Shows or hides the toolbar"), TRUE);
312     viewMenu->Append(ecID_TOGGLE_PROPERTIES, _("&Properties\tAlt+1"), _("Shows or hides the properties window"), TRUE);
313     viewMenu->Append(ecID_TOGGLE_OUTPUT, _("&Output\tAlt+2"), _("Shows the output window"), TRUE);
314     viewMenu->Append(ecID_TOGGLE_SHORT_DESCR, _("&Short Description\tAlt+3"), _("Shows or hides the short description window"), TRUE);
315
316     viewMenu->Append(ecID_TOGGLE_CONFLICTS, _("&Conflicts\tAlt+4"), _("Shows or hides the conflicts window"), TRUE);
317 #if ecUSE_MLT
318     viewMenu->Append(ecID_TOGGLE_MEMORY, _("&Memory Layout\tAlt+5"), _("Shows or hides the memory layout window"), TRUE);
319     //viewMenu->Enable(ecID_TOGGLE_MEMORY, FALSE);
320 #endif
321
322     // Not clear what these do, so let's not have them.
323     //viewMenu->Append(ecID_VIEW_NEXT, _("&Next\tAlt+F6"), _("Selects the next visible pane"));
324     //viewMenu->Append(ecID_VIEW_PREVIOUS, _("&Previous\tShift+Alt+F6"), _("Selects the previous visible pane"));
325     
326     // Build menu
327     wxMenu* buildMenu = new wxMenu(wxT(""), wxMENU_TEAROFF);
328     
329     buildMenu->Append(ecID_BUILD_LIBRARY, _("&Library\tF7"), _("Builds the library"));
330     buildMenu->Append(ecID_BUILD_TESTS, _("&Tests\tShift+F7"), _("Builds the tests"));
331     buildMenu->Append(ecID_CLEAN, _("&Clean"), _("Deletes intermediate and output files"));
332     buildMenu->Append(ecID_STOP_BUILD, _("&Stop"), _("Stops the build"));
333     buildMenu->AppendSeparator();
334     buildMenu->Append(ecID_GENERATE_BUILD_TREE, _("&Generate Build Tree"), _("Explicitly recreates the build tree"));
335     buildMenu->AppendSeparator();
336     buildMenu->Append(ecID_BUILD_OPTIONS, _("&Options..."), _("Changes build options"));
337     buildMenu->Append(ecID_BUILD_REPOSITORY, _("&Repository..."), _("Selects repository"));
338     buildMenu->Append(ecID_BUILD_TEMPLATES, _("&Templates..."), _("Selects the package templates"));
339     buildMenu->Append(ecID_BUILD_PACKAGES, _("&Packages..."), _("Selects individual packages"));
340     
341     // Tools menu
342     wxMenu* toolsMenu = new wxMenu(wxT(""), wxMENU_TEAROFF);
343     
344     wxMenu* pathMenu = new wxMenu;
345     pathMenu->Append(ecID_PATHS_BUILD_TOOLS, _("&Build Tools..."), _("Specifies the folder containing the build tools"));
346     pathMenu->Append(ecID_PATHS_USER_TOOLS, _("&User Tools..."), _("Specifies the folder containing the user tools"));
347     toolsMenu->Append(ecID_PATHS, _("&Paths"), pathMenu);
348
349     toolsMenu->Append(ecID_SHELL, _("&Shell..."), _("Invokes a command shell"));
350     toolsMenu->Append(ecID_RUN_TESTS, _("&Run Tests...\tCtrl+F5"), _("Runs the configuration tests"));
351     toolsMenu->Append(ecID_PLATFORMS, _("&Platforms..."), _("Edits the platforms list"));
352     toolsMenu->Append(ecID_RESOLVE_CONFLICTS, _("Resolve &Conflicts..."), _("Resolves conflicts"));
353     toolsMenu->Append(ecID_ADMINISTRATION, _("&Administration..."), _("Performs repository administration tasks"));
354 #if 0
355     toolsMenu->AppendSeparator();
356     toolsMenu->Append(ecID_TOOLS_OPTIONS, _("&Options..."), _("Changes configuration options"));
357 #endif
358     toolsMenu->Append(ecID_INDEX_DOCS, _("Regenerate Help &Index"), _("Regenerates the online help contents"));
359     
360     // Help menu
361     wxMenu* helpMenu = new wxMenu;
362     helpMenu->Append(ecID_CONFIGTOOL_HELP, _("&Configuration Tool Help\tShift+F1"), _("Displays help"));
363     helpMenu->Append(ecID_ECOS_HELP, _("&eCos Documentation"), _("Displays the documentation home page"));
364     helpMenu->Append(ecID_CONTEXT_HELP, _("&Help On..."), _("Displays help for clicked-on windows"));
365     helpMenu->AppendSeparator();
366     
367     wxMenu* webMenu = new wxMenu;
368     webMenu->Append(ecID_REDHAT_WEB_HOME, _("&Red Hat Home Page"), _("Opens the Red Hat home page"));
369     webMenu->Append(ecID_REDHAT_WEB_ECOS, _("&eCos Product Page"), _("Opens the eCos product page"));
370     webMenu->Append(ecID_REDHAT_WEB_NET_RELEASE, _("eCos &Net Release Page"), _("Opens the eCos net release page"));
371     webMenu->AppendSeparator();
372     webMenu->Append(ecID_REDHAT_WEB_UITRON, _("&ITRON"), _("Opens the ITRON specification page"));
373     
374 //    helpMenu->Append(ecID_REDHAT_WEB, _("&Red Hat on the Web"), webMenu);
375 //    helpMenu->AppendSeparator();
376     helpMenu->Append(ecID_REPOSITORY_INFO, _("Repository &Information...\tCtrl+I"), _("Displays information about the current repository"));
377     helpMenu->Append(wxID_ABOUT, _("&About the Configuration Tool..."), _("Displays program information, version and copyright"));
378     
379     wxMenuBar *menuBar = new wxMenuBar();
380     menuBar->Append(fileMenu, _("&File"));
381     menuBar->Append(editMenu, _("&Edit"));
382     menuBar->Append(viewMenu, _("&View"));
383     menuBar->Append(buildMenu, _("&Build"));
384     menuBar->Append(toolsMenu, _("&Tools"));
385     menuBar->Append(helpMenu, _("&Help"));
386     
387     // ... and attach this menu bar to the frame
388     SetMenuBar(menuBar);
389     
390     // Create the toolbar
391     RecreateToolbar();
392     
393     if (!wxGetApp().GetSettings().m_showToolBar)
394         GetToolBar()->Show( FALSE );
395     
396     // Create the status bar
397     CreateStatusBar(4, wxST_SIZEGRIP);
398     
399     int* widths = new int[4];
400     widths[0] = -1; widths[1] = 100; widths[2] = 40; widths[3] = 80;
401     SetStatusWidths(4, widths);
402     delete[] widths;
403     
404     SetStatusText(_("No conflicts"), ecFailRulePane);
405     SetStatusText(_("Ready"), ecStatusPane);
406 }
407
408 // Create the windows
409 void ecMainFrame::CreateWindows()
410 {
411     ecSettings& stg = wxGetApp().GetSettings();
412     
413     // Create the sash layout windows first
414     
415     // Sash window for the output window
416     m_outputSashWindow = new wxSashLayoutWindow(this, ecID_OUTPUT_SASH_WINDOW, wxDefaultPosition, wxDefaultSize, wxNO_BORDER|wxCLIP_SIBLINGS);
417     m_outputSashWindow->SetDefaultSize(stg.m_outputSashSize);
418     m_outputSashWindow->SetOrientation(wxLAYOUT_HORIZONTAL);
419     m_outputSashWindow->SetAlignment(wxLAYOUT_BOTTOM);
420     m_outputSashWindow->SetSashVisible(wxSASH_TOP, TRUE);
421     m_outputWindow = new ecOutputWindow(m_outputSashWindow, ecID_OUTPUT_WINDOW, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxCLIP_CHILDREN|wxTE_READONLY|wxTE_RICH);
422     m_outputWindow->SetHelpText(_("The output window displays various warning and informational messages."));
423     
424     // Sash window for the memory window
425     m_memorySashWindow = new wxSashLayoutWindow(this, ecID_MEMORY_SASH_WINDOW, wxDefaultPosition, wxDefaultSize, wxNO_BORDER|wxSW_3D|wxCLIP_SIBLINGS);
426     m_memorySashWindow->SetDefaultSize(stg.m_memorySashSize);
427     m_memorySashWindow->SetOrientation(wxLAYOUT_HORIZONTAL);
428     m_memorySashWindow->SetAlignment(wxLAYOUT_BOTTOM);
429     m_memorySashWindow->SetSashVisible(wxSASH_TOP, TRUE);
430     //wxTextCtrl* memoryWindow = new wxTextCtrl(m_memorySashWindow, ecID_MEMORY_WINDOW, wxT("This will be the memory layout window."), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxCLIP_CHILDREN|wxTE_NO_VSCROLL|wxTE_READONLY);
431     m_mltWindow = new ecMemoryLayoutWindow(m_memorySashWindow, ecID_MEMORY_WINDOW, wxDefaultPosition, wxDefaultSize, wxCLIP_CHILDREN|wxSUNKEN_BORDER);
432     m_mltWindow->SetHelpText(_("The memory layout window presents a graphical view of the memory layout of the currently selected\ncombination of target architecture, platform and start-up type."));
433     
434     // Sash window for the config tree
435     m_configSashWindow = new wxSashLayoutWindow(this, ecID_CONFIG_SASH_WINDOW, wxDefaultPosition, wxDefaultSize, wxNO_BORDER|wxCLIP_CHILDREN/*|wxCLIP_SIBLINGS*/);
436     m_configSashWindow->SetDefaultSize(stg.m_treeSashSize);
437     m_configSashWindow->SetOrientation(wxLAYOUT_VERTICAL);
438     m_configSashWindow->SetAlignment(wxLAYOUT_LEFT);
439     m_configSashWindow->SetSashVisible(wxSASH_RIGHT, TRUE);
440     
441     // Sash window for the conflicts window
442     m_conflictsSashWindow = new wxSashLayoutWindow(this, ecID_CONFLICTS_SASH_WINDOW, wxDefaultPosition, wxDefaultSize, wxNO_BORDER|wxCLIP_SIBLINGS);
443     m_conflictsSashWindow->SetDefaultSize(stg.m_conflictsSashSize);
444     m_conflictsSashWindow->SetOrientation(wxLAYOUT_HORIZONTAL);
445     m_conflictsSashWindow->SetAlignment(wxLAYOUT_TOP);
446     m_conflictsSashWindow->SetSashVisible(wxSASH_BOTTOM, TRUE);
447     m_conflictsWindow = new ecConflictListCtrl(m_conflictsSashWindow, ecID_CONFLICTS_WINDOW, wxDefaultPosition, wxDefaultSize, wxLC_REPORT|wxCLIP_CHILDREN|wxSUNKEN_BORDER);
448     m_conflictsWindow->SetHelpText(_("The conflicts window lists any outstanding conflicts in the configuration."));
449     
450     // Sash window for the properties window
451     m_propertiesSashWindow = new wxSashLayoutWindow(this, ecID_PROPERTIES_SASH_WINDOW, wxDefaultPosition, wxDefaultSize, wxNO_BORDER|wxCLIP_SIBLINGS);
452     m_propertiesSashWindow->SetDefaultSize(stg.m_propertiesSashSize);
453     m_propertiesSashWindow->SetOrientation(wxLAYOUT_HORIZONTAL);
454     m_propertiesSashWindow->SetAlignment(wxLAYOUT_TOP);
455     m_propertiesSashWindow->SetSashVisible(wxSASH_BOTTOM, TRUE);
456 //    wxTextCtrl* propertiesWindow = new wxTextCtrl(m_propertiesSashWindow, ecID_PROPERTIES_WINDOW, wxT("This will be the properties window."), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxCLIP_CHILDREN|wxTE_NO_VSCROLL|wxTE_READONLY);
457     m_propertyListWindow = new ecPropertyListCtrl(m_propertiesSashWindow, ecID_PROPERTIES_WINDOW, wxDefaultPosition, wxDefaultSize, wxLC_REPORT|wxCLIP_CHILDREN|wxLC_VRULES|wxLC_HRULES|wxSUNKEN_BORDER);
458     m_propertyListWindow->SetHelpText(_("The properties window shows the properties of the selected configuration item."));
459     
460     // Sash window for the short description window
461     m_shortDescrSashWindow = new wxSashLayoutWindow(this, ecID_SHORT_DESCR_SASH_WINDOW, wxDefaultPosition, wxDefaultSize, wxNO_BORDER|wxCLIP_SIBLINGS);
462     m_shortDescrSashWindow->SetDefaultSize(stg.m_shortDescrSashSize);
463     m_shortDescrSashWindow->SetOrientation(wxLAYOUT_HORIZONTAL);
464     m_shortDescrSashWindow->SetAlignment(wxLAYOUT_TOP);
465     //m_shortDescrSashWindow->SetSashVisible(wxSASH_TOP, TRUE);
466     m_shortDescrWindow = new ecShortDescriptionWindow(m_shortDescrSashWindow, ecID_SHORT_DESCR_WINDOW, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxCLIP_CHILDREN/*|wxTE_NO_VSCROLL*/|wxTE_READONLY);
467     m_shortDescrWindow->SetBackgroundColour(wxColour(255, 255, 225));
468     m_shortDescrWindow->SetHelpText(_("The short description window displays brief help on a selected configuration item."));
469     
470     // Create a composite widget to represent the scrolling config window
471     m_scrolledWindow = new ecSplitterScrolledWindow(m_configSashWindow, ecID_SCROLLED_WINDOW, wxDefaultPosition,
472         wxSize(400, 100), wxNO_BORDER | wxCLIP_CHILDREN | wxVSCROLL);
473     m_splitter = new wxThinSplitterWindow(m_scrolledWindow, ecID_SPLITTER_WINDOW, wxDefaultPosition,
474         wxSize(400, 100), wxSP_3DBORDER | wxCLIP_CHILDREN /* | wxSP_LIVE_UPDATE */);
475     m_splitter->SetSashSize(2);
476     m_tree = new ecConfigTreeCtrl(m_splitter, ecID_TREE_CTRL, wxDefaultPosition,
477         wxSize(200, 100), wxTR_HAS_BUTTONS | wxTR_NO_LINES | wxNO_BORDER );
478     m_valueWindow = new ecValueWindow(m_splitter, ecID_VALUE_WINDOW, wxDefaultPosition,
479         wxSize(200, 100), wxNO_BORDER);
480     m_splitter->SplitVertically(m_tree, m_valueWindow);
481     m_splitter->SetMinimumPaneSize(100);
482     //m_splitter->AdjustScrollbars();
483     m_splitter->SetSashPosition(wxGetApp().GetSettings().m_configPaneWidth);
484     m_scrolledWindow->SetTargetWindow(m_tree);  
485     m_scrolledWindow->EnableScrolling(FALSE, FALSE);
486     m_tree->SetHelpText(_("The configuration window is the principal window used to configure eCos.\nIt takes the form of a tree-based representation of the configuration items within the currently loaded eCos packages."));
487     m_valueWindow->SetHelpText(m_tree->GetHelpText());
488     
489     // Let the two controls know about each other
490     m_valueWindow->SetTreeCtrl(m_tree);
491     m_tree->SetCompanionWindow(m_valueWindow);
492
493     // Set visibility according to config settings
494     if (!wxGetApp().GetSettings().m_showConflictsWindow)
495         m_conflictsSashWindow->Show(FALSE);
496     if (!wxGetApp().GetSettings().m_showPropertiesWindow)
497         m_propertiesSashWindow->Show(FALSE);
498     if (!wxGetApp().GetSettings().m_showShortDescrWindow)
499         m_shortDescrSashWindow->Show(FALSE);
500     if (!wxGetApp().GetSettings().m_showOutputWindow)
501         m_outputSashWindow->Show(FALSE);
502     if (!wxGetApp().GetSettings().m_showMemoryWindow)
503         m_memorySashWindow->Show(FALSE);
504 }
505 // event handlers
506
507 void ecMainFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
508 {
509     Close();
510 }
511
512 void ecMainFrame::OnFind(wxCommandEvent& event)
513 {
514     if (m_findDialog)
515     {
516         m_findDialog->Raise();
517         return;
518     }
519
520     m_findDialog = new ecFindDialog (this, ecID_FIND_DIALOG, _("Find in configuration"));
521     m_findDialog->Show(TRUE);
522
523     // For some reason, under Windows, the text control doesn't get the focus if we set the focus
524     // and then call Show. We have to set the focus afterwards instead.
525     m_findDialog->FindWindow(ecID_FIND_DIALOG_WHAT)->SetFocus();
526 }
527
528 void ecMainFrame::OnFindNext(wxCommandEvent& event)
529 {
530     if (wxGetApp().GetConfigToolDoc())
531     {
532         ecConfigToolView* view = (ecConfigToolView*) wxGetApp().GetConfigToolDoc()->GetFirstView() ;
533
534         view->DoFind(wxGetApp().GetSettings().m_findText, this);
535     }
536 }
537
538 void ecMainFrame::OnUpdateFind(wxUpdateUIEvent& event)
539 {
540     event.Enable( wxGetApp().GetConfigToolDoc() != NULL );
541 }
542
543 void ecMainFrame::OnUpdateFindNext(wxUpdateUIEvent& event)
544 {
545     event.Enable( (wxGetApp().GetConfigToolDoc() != NULL) && !wxGetApp().GetSettings().m_findText.IsEmpty() );
546 }
547
548 void ecMainFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
549 {
550 //    ecAboutDialog dialog(this, ecID_ABOUT_DIALOG, _("About eCos Configuration Tool"));
551 //    dialog.ShowModal();
552     wxMessageBox(_("eCos Configuration Tool 2.12.net (eCos 2.0b1)\n\nCopyright (c) Red Hat, Inc. 1998-2002\nCopyright (c) John Dallaway 2003"), _("About eCos Configuration Tool"), wxICON_INFORMATION | wxOK);
553 }
554
555 void ecMainFrame::OnSize(wxSizeEvent& WXUNUSED(event))
556 {
557     // First, we need to resize the sash windows proportionately,
558     // or we may end up with negative sizes, etc.
559     wxRect rect = GetRect();
560     if (rect != wxGetApp().GetSettings().m_frameSize)
561     {
562         double factorX = ((double) rect.GetWidth() / (double) wxGetApp().GetSettings().m_frameSize.GetWidth());
563         double factorY = ((double) rect.GetHeight() / (double) wxGetApp().GetSettings().m_frameSize.GetHeight());
564         
565         wxNode* node = GetChildren().First();
566         while (node)
567         {
568             wxWindow* win = (wxWindow*) node->Data();
569             if (win->IsKindOf(CLASSINFO(wxSashLayoutWindow)))
570             {
571                 wxSashLayoutWindow* sashWin = (wxSashLayoutWindow*) win;
572                 wxSize sz = sashWin->GetSize();
573                 sashWin->SetDefaultSize(wxSize((int) ((double) sz.x * factorX), (int) ((double) sz.y * factorY)));
574             }
575             node = node->Next();
576         }
577     }
578     
579     wxLayoutAlgorithm layout;
580     layout.LayoutFrame(this);
581     
582     wxGetApp().GetSettings().m_frameSize = rect;
583 }
584
585 void ecMainFrame::RecreateToolbar()
586 {
587     // delete and recreate the toolbar
588     wxToolBarBase *toolBar = GetToolBar();
589     if (toolBar)
590     {
591         delete toolBar;
592         SetToolBar(NULL);
593     }
594     
595     long style = wxNO_BORDER | wxTB_FLAT | wxTB_HORIZONTAL | wxTB_DOCKABLE;
596     
597     toolBar = CreateToolBar(style, ecID_TOOLBAR);
598     
599     toolBar->SetMargins( 4, 4 );
600     
601     // Set up toolbar
602     wxBitmap toolBarBitmaps[20];
603     
604     toolBarBitmaps[0] = wxBITMAP(new);
605     toolBarBitmaps[1] = wxBITMAP(open);
606     toolBarBitmaps[2] = wxBITMAP(save);
607     toolBarBitmaps[3] = wxBITMAP(copy);
608     toolBarBitmaps[4] = wxBITMAP(cut);
609     toolBarBitmaps[5] = wxBITMAP(paste);
610     toolBarBitmaps[6] = wxBITMAP(search);
611     toolBarBitmaps[7] = wxBITMAP(stopbuild);
612     toolBarBitmaps[8] = wxBITMAP(buildlibrary);
613     toolBarBitmaps[9] = wxBITMAP(help);
614     toolBarBitmaps[10] = wxBITMAP(newregion);
615     toolBarBitmaps[11] = wxBITMAP(newsection);
616     toolBarBitmaps[12] = wxBITMAP(delete);
617     toolBarBitmaps[13] = wxBITMAP(properties);
618     toolBarBitmaps[14] = wxBITMAP(cshelp);
619     
620     toolBar->AddTool(wxID_NEW, toolBarBitmaps[0], wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, wxT("New file"));
621     toolBar->AddTool(wxID_OPEN, toolBarBitmaps[1], wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, wxT("Open file"));
622     toolBar->AddTool(wxID_SAVE, toolBarBitmaps[2], wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, wxT("Save file"));
623     
624     toolBar->AddSeparator();
625     
626     toolBar->AddTool(wxID_CUT, toolBarBitmaps[4], wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, "Cut");
627     toolBar->AddTool(wxID_COPY, toolBarBitmaps[3], wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, "Copy");
628     toolBar->AddTool(wxID_PASTE, toolBarBitmaps[5], wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, "Paste");
629     toolBar->AddTool(wxID_FIND, toolBarBitmaps[6], wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, "Search");
630     
631     toolBar->AddSeparator();
632     
633     toolBar->AddTool(ecID_STOP_BUILD, toolBarBitmaps[7], wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, "Stop build");
634     toolBar->AddTool(ecID_BUILD_LIBRARY, toolBarBitmaps[8], wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, "Build library");
635 #if ecUSE_MLT
636     toolBar->AddSeparator();
637     toolBar->AddTool(ecID_NEW_REGION, toolBarBitmaps[10], wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, "New region");
638     toolBar->AddTool(ecID_NEW_SECTION, toolBarBitmaps[11], wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, "New section");
639     toolBar->AddTool(ecID_DELETE, toolBarBitmaps[12], wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, "Delete");
640     toolBar->AddTool(ecID_PROPERTIES, toolBarBitmaps[13], wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, "Properties");
641 #endif
642     toolBar->AddSeparator();
643     toolBar->AddTool(ecID_CONTEXT_HELP, toolBarBitmaps[14], wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, "Show help for clicked-on windows");
644     toolBar->AddTool(ecID_ECOS_HELP, toolBarBitmaps[9], wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, "Show help");
645     
646     // after adding the buttons to the toolbar, must call Realize() to reflect
647     // the changes
648     toolBar->Realize();
649
650     toolBar->SetHelpText(_("The toolbar allows quick access to commonly-used commands."));
651 }
652
653 // Toggle one of the windows
654 void ecMainFrame::OnToggleWindow(wxCommandEvent& event)
655 {
656     ToggleWindow(event.GetId());
657 }
658
659 // Toggle the given window on or off
660 void ecMainFrame::ToggleWindow(int windowId)
661 {
662     wxWindow* win = NULL;
663     bool *configSetting = NULL;
664     switch (windowId)
665     {
666     case ecID_TOGGLE_CONFLICTS:
667         win = m_conflictsSashWindow;
668         configSetting = & wxGetApp().GetSettings().m_showConflictsWindow;
669         break;
670     case ecID_TOGGLE_PROPERTIES:
671         win = m_propertiesSashWindow;
672         configSetting = & wxGetApp().GetSettings().m_showPropertiesWindow;
673         break;
674     case ecID_TOGGLE_MEMORY:
675         win = m_memorySashWindow;
676         configSetting = & wxGetApp().GetSettings().m_showMemoryWindow;
677         break;
678     case ecID_TOGGLE_SHORT_DESCR:
679         win = m_shortDescrSashWindow;
680         configSetting = & wxGetApp().GetSettings().m_showShortDescrWindow;
681         break;
682     case ecID_TOGGLE_OUTPUT:
683         win = m_outputSashWindow;
684         configSetting = & wxGetApp().GetSettings().m_showOutputWindow;
685         break;
686     }
687     if (win)
688     {
689         bool showing = !win->IsShown();
690
691         win->Show(showing);
692         * configSetting = showing;
693
694         // Make sure we don't have ridiculous sizes
695         if (showing && (windowId == ecID_TOGGLE_CONFLICTS || windowId == ecID_TOGGLE_PROPERTIES || windowId == ecID_TOGGLE_SHORT_DESCR))
696         {
697             m_conflictsSashWindow->SetDefaultSize(wxSize(2000, 50));
698             m_propertiesSashWindow->SetDefaultSize(wxSize(2000, 50));
699             m_shortDescrSashWindow->SetDefaultSize(wxSize(2000, 50));
700
701             wxSize frameSize = GetClientSize();
702             wxSize configSize = m_configSashWindow->GetSize();
703
704             if ((frameSize.x - configSize.x) < 5)
705             {
706                 // We must resize the config window
707                 m_configSashWindow->SetDefaultSize(wxSize(frameSize.x/2, configSize.y));
708             }
709         }
710         
711         wxLayoutAlgorithm layout;
712         layout.LayoutFrame(this);
713     }
714 }
715
716 void ecMainFrame::OnUpdateToggleWindow(wxUpdateUIEvent& event)
717 {
718     wxWindow* win = NULL;
719     switch (event.GetId())
720     {
721     case ecID_TOGGLE_CONFLICTS:
722         win = m_conflictsSashWindow;
723         break;
724     case ecID_TOGGLE_PROPERTIES:
725         win = m_propertiesSashWindow;
726         break;
727     case ecID_TOGGLE_MEMORY:
728         win = m_memorySashWindow;
729         break;
730     case ecID_TOGGLE_SHORT_DESCR:
731         win = m_shortDescrSashWindow;
732         break;
733     case ecID_TOGGLE_OUTPUT:
734         win = m_outputSashWindow;
735         break;
736     }
737     if (win)
738     {
739         event.Enable( TRUE );
740         event.Check( win->IsShown() );
741
742         // Not implemented
743 #if !ecUSE_MLT
744         if (event.GetId() == ecID_TOGGLE_MEMORY)
745             event.Enable( FALSE );
746 #endif
747     }
748 }
749
750 void ecMainFrame::OnUpdateDisable(wxUpdateUIEvent& event)
751 {
752     event.Enable( FALSE );
753 }
754
755 void ecMainFrame::OnToggleToolbar(wxCommandEvent& event)
756 {
757     GetToolBar()->Show( ! GetToolBar()->IsShown() );
758     
759     wxSizeEvent sizeEvent(GetSize(), GetId());
760     GetEventHandler()->ProcessEvent(sizeEvent);
761 #ifdef __WXGTK__
762     GtkOnSize( GetPosition().x, GetPosition().y, GetSize().x, GetSize().y);
763 #endif
764 }
765
766 void ecMainFrame::OnUpdateToggleToolbar(wxUpdateUIEvent& event)
767 {
768     event.Check( GetToolBar()->IsShown() );
769 }
770
771 // Respond to a sash drag operation, by setting the new size
772 // for this window and then recalculating the layout.
773 void ecMainFrame::OnSashDrag(wxSashEvent& event)
774 {
775     if (event.GetDragStatus() == wxSASH_STATUS_OUT_OF_RANGE)
776         return;
777     
778     switch (event.GetId())
779     {
780     case ecID_CONFIG_SASH_WINDOW:
781         {
782             m_configSashWindow->SetDefaultSize(wxSize(event.GetDragRect().width, 2000));
783             break;
784         }
785     case ecID_CONFLICTS_SASH_WINDOW:
786         {
787             // Change the height of the properties window so we don't affect the
788             // short description window
789             int deltaY = event.GetDragRect().height - m_conflictsSashWindow->GetSize().y;
790             int propertiesHeight = 0;
791             if (m_propertiesSashWindow->IsShown())
792             {
793                 propertiesHeight = m_propertiesSashWindow->GetSize().y - deltaY ;
794                 if (propertiesHeight <= 0)
795                     return;
796                 else
797                     m_propertiesSashWindow->SetDefaultSize(wxSize(2000, propertiesHeight));
798             }
799             m_conflictsSashWindow->SetDefaultSize(wxSize(2000, event.GetDragRect().height));
800             break;
801         }
802     case ecID_PROPERTIES_SASH_WINDOW:
803         {
804             m_propertiesSashWindow->SetDefaultSize(wxSize(2000, event.GetDragRect().height));
805             break;
806         }
807     case ecID_SHORT_DESCR_SASH_WINDOW:
808         {
809             m_shortDescrSashWindow->SetDefaultSize(wxSize(2000, event.GetDragRect().height));
810             break;
811         }
812     case ecID_MEMORY_SASH_WINDOW:
813         {
814             m_memorySashWindow->SetDefaultSize(wxSize(2000, event.GetDragRect().height));
815             break;
816         }
817     case ecID_OUTPUT_SASH_WINDOW:
818         {
819             m_outputSashWindow->SetDefaultSize(wxSize(2000, event.GetDragRect().height));
820             break;
821         }
822     default:
823         {
824             wxFAIL_MSG( _("Shouldn't get here.") );
825             break;
826         }
827     }
828
829     if (event.GetId() == ecID_MEMORY_SASH_WINDOW || event.GetId() == ecID_OUTPUT_SASH_WINDOW)
830     {
831         // Special processing so we don't spoil the layout of the
832         // conflicts/properties/short description windows
833         wxList minorWindows;
834         GetMinorWindows(minorWindows);
835
836         int memoryLayoutHeight = m_memorySashWindow->IsShown() ? m_memorySashWindow->GetSize().y : 0;
837         int outputHeight = m_memorySashWindow->IsShown() ? m_outputSashWindow->GetSize().y : 0;
838         int cx, cy;
839         GetClientSize(& cx, & cy);
840
841         // Calculate how much space will be left after this drag operation.
842         int heightLeft;
843         if (event.GetId() == ecID_MEMORY_SASH_WINDOW)
844             heightLeft = cy - outputHeight - event.GetDragRect().height;
845         else
846             heightLeft = cy - memoryLayoutHeight - event.GetDragRect().height;
847
848         DivideSpaceEvenly(minorWindows, wxSize(0, heightLeft), wxVERTICAL);
849         RestoreDefaultWindowSizes(minorWindows);
850     }
851
852     wxLayoutAlgorithm layout;
853     if (!layout.LayoutFrame(this))
854     {
855         // If layout failed, restored default sizes.
856         wxNode* node = GetChildren().First();
857         while (node)
858         {
859             wxWindow* win = (wxWindow*) node->Data();
860             if (win->IsKindOf(CLASSINFO(wxSashLayoutWindow)))
861             {
862                 wxSashLayoutWindow* sashWin = (wxSashLayoutWindow*) win;
863                 wxSize sz = sashWin->GetSize();
864                 sashWin->SetDefaultSize(sz);
865             }
866             node = node->Next();
867         }
868     }
869     
870 }
871
872 void ecMainFrame::OnIdle(wxIdleEvent& event)
873 {
874     // Normal idle processing
875     wxFrame::OnIdle(event);
876
877     wxString text;
878     if (GetStatusBar())
879         text = GetStatusBar()->GetStatusText(0);
880
881     // Set the title if we have no document
882     if (!wxGetApp().GetConfigToolDoc() && GetTitle() != wxGetApp().GetSettings().GetAppName())
883         SetTitle(wxGetApp().GetSettings().GetAppName());
884     
885     if ( wxGetApp().m_pipedProcess && wxGetApp().m_pipedProcess->HasInput() )
886     {
887         event.RequestMore();
888     }
889
890     if ( wxGetApp().m_pipedProcess )
891     {
892         if (text != _("Building..."))
893             SetStatusText(_("Building..."), 0);
894     }
895     else if (text != _("Ready"))
896         SetStatusText(_("Ready"), 0);
897 }
898
899 void ecMainFrame::OnCloseWindow(wxCloseEvent& event)
900 {
901     wxBusyCursor busy;
902
903     if (!wxGetApp().GetDocManager()->Clear(FALSE) && event.CanVeto())
904     {
905         event.Veto();
906         return;
907     }
908     if (wxGetApp().m_pipedProcess)
909         wxGetApp().m_pipedProcess->Detach();
910
911     if (m_findDialog)
912         m_findDialog->Close(TRUE);
913
914     wxGetApp().DestroyHelpController();
915     
916     if (IsMaximized())
917         wxGetApp().GetSettings().m_frameStatus = ecSHOW_STATUS_MAXIMIZED ;
918     else if (IsIconized())
919         wxGetApp().GetSettings().m_frameStatus = ecSHOW_STATUS_MINIMIZED ;
920     else
921         wxGetApp().GetSettings().m_frameStatus = ecSHOW_STATUS_NORMAL ;
922     
923     if (!IsMaximized() && !IsIconized())
924         wxGetApp().GetSettings().m_frameSize = GetRect();
925     
926     wxGetApp().GetSettings().m_showToolBar = GetToolBar()->IsShown();
927     
928     wxGetApp().GetSettings().m_treeSashSize = m_configSashWindow->GetSize();
929     wxGetApp().GetSettings().m_propertiesSashSize = m_propertiesSashWindow->GetSize();
930     wxGetApp().GetSettings().m_conflictsSashSize = m_conflictsSashWindow->GetSize();
931     wxGetApp().GetSettings().m_shortDescrSashSize = m_shortDescrSashWindow->GetSize();
932     wxGetApp().GetSettings().m_memorySashSize = m_memorySashWindow->GetSize();
933     wxGetApp().GetSettings().m_outputSashSize = m_outputSashWindow->GetSize();
934     wxGetApp().GetSettings().m_configPaneWidth = m_splitter->GetSashPosition();
935     
936     event.Skip();
937 }
938
939 // Enumerate the visible 'minor' sash windows,
940 // i.e. those in the top-right segment of the frame
941 void ecMainFrame::GetMinorWindows(wxList& list)
942 {
943     if (m_conflictsSashWindow->IsShown())
944         list.Append(m_conflictsSashWindow);
945     if (m_propertiesSashWindow->IsShown())
946         list.Append(m_propertiesSashWindow);
947     if (m_shortDescrSashWindow->IsShown())
948         list.Append(m_shortDescrSashWindow);
949 }
950
951 // Get all visible sash windows
952 void ecMainFrame::GetSashWindows(wxList& list)
953 {
954     wxNode* node = GetChildren().First();
955     while (node)
956     {
957         wxWindow* win = (wxWindow*) node->Data();
958         if (win->IsKindOf(CLASSINFO(wxSashLayoutWindow)) && win->IsShown())
959         {
960             list.Append(win);
961         }
962         node = node->Next();
963     }
964 }
965
966 // Divide the given space evenly amongst some windows
967 void ecMainFrame::DivideSpaceEvenly(wxList& list, const wxSize& space, int orient)
968 {
969     if (list.Number() == 0)
970         return;
971
972     // Find total size first
973     int totalSize = 0;
974     double proportion = 0.0;
975     wxNode* node = list.First();
976     while (node)
977     {
978         wxWindow* win = (wxWindow*) node->Data();
979         wxSize sz = win->GetSize();
980         if (orient == wxHORIZONTAL)
981             totalSize += sz.x;
982         else
983             totalSize += sz.y;
984         node = node->Next();
985     }
986     if (orient == wxHORIZONTAL)
987     {
988         if (totalSize == 0)
989             return;
990
991         proportion = ((double) space.x / (double) totalSize);
992     }
993     else
994     {
995         if (totalSize == 0)
996             return;
997
998         proportion = ((double) space.y / (double) totalSize);
999     }
1000     node = list.First();
1001     while (node)
1002     {
1003         wxWindow* win = (wxWindow*) node->Data();
1004         wxSize sz = win->GetSize();
1005         if (orient == wxHORIZONTAL)
1006             sz.x = (int) (sz.x * proportion);
1007         else
1008             sz.y = (int) (sz.y * proportion);
1009         win->SetSize(sz);
1010         node = node->Next();
1011     }
1012 }
1013
1014 // Restore the sash window default size from the actual window size
1015 void ecMainFrame::RestoreDefaultWindowSizes(wxList& list)
1016 {
1017     wxNode* node = list.First();
1018     while (node)
1019     {
1020         wxSashLayoutWindow* sashWin = (wxSashLayoutWindow*) node->Data();
1021         wxSize sz = sashWin->GetSize();
1022         sashWin->SetDefaultSize(sz);
1023         node = node->Next();
1024     }
1025 }
1026
1027 void ecMainFrame::OnHelpEcos(wxCommandEvent& event)
1028 {
1029     ecConfigToolDoc* doc = wxGetApp().GetConfigToolDoc();
1030     if (doc)
1031     {
1032         wxString strURL(wxT("index.html"));
1033         doc->QualifyDocURL(strURL, FALSE);
1034         switch (wxGetApp().GetSettings().m_eUseCustomBrowser)
1035         {
1036         case ecInternal:
1037             {
1038                 if (wxGetApp().HasHelpController())
1039                     wxGetApp().GetHelpController().DisplayContents();
1040                 break;
1041             }
1042         default:
1043             {
1044                 doc->ShowURL(strURL);
1045             }
1046         }
1047     }
1048 }
1049
1050 void ecMainFrame::OnHelpConfigtool(wxCommandEvent& event)
1051 {
1052     //wxString strURL(wxT("redirect/the-ecos-configuration-tool.html"));
1053     wxString strURL(wxGetApp().GetFullAppPath(wxT("manual/user-guides.2.html")));
1054     if (!wxFileExists(strURL))
1055         strURL = wxT("user-guide/the-ecos-configuration-tool.html");
1056
1057     if (wxGetApp().GetConfigToolDoc())
1058     {
1059         wxGetApp().GetConfigToolDoc()->ShowURL(strURL);
1060     }
1061 }
1062
1063 void ecMainFrame::OnHelpContext(wxCommandEvent& event)
1064 {
1065     wxContextHelp contextHelp;
1066 }
1067
1068 void ecMainFrame::OnResolveConflicts(wxCommandEvent& event)
1069 {
1070 /*
1071     ecResolveConflictsDialog dialog(this);
1072     dialog.ShowModal();
1073 */
1074     if ( ecConfigToolDoc::NotDone == wxGetApp().GetConfigToolDoc()->ResolveGlobalConflicts() )
1075     {
1076         // Global inference handler was never invoked.  Say something
1077         wxString msg;
1078         msg.Printf(_("No solutions can be automatically determined for the current set of conflicts."));
1079         wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK);
1080     }    
1081 }
1082
1083 void ecMainFrame::OnUpdateResolveConflicts(wxUpdateUIEvent& event)
1084 {
1085     if (!wxGetApp().GetConfigToolDoc() || !wxGetApp().GetConfigToolDoc()->GetCdlInterpreter())
1086     {
1087         event.Enable(FALSE);
1088         return;
1089     }
1090
1091     event.Enable(wxGetApp().GetConfigToolDoc()->GetCdlInterpreter()->get_toplevel()->get_all_conflicts().size()>0);
1092 }
1093
1094 void ecMainFrame::OnSettings(wxCommandEvent& event)
1095 {
1096     ecSettingsDialog dialog(this);
1097     dialog.ShowModal();
1098 }
1099
1100 void ecMainFrame::OnPlatforms(wxCommandEvent& event)
1101 {
1102     ecPlatformsDialog dialog(this);
1103     if (dialog.ShowModal() == wxID_OK)
1104     {
1105         CeCosTestPlatform::RemoveAllPlatforms();
1106         unsigned int i ;
1107         for(i=0; i < dialog.PlatformCount();i++){
1108             CeCosTestPlatform::Add(*dialog.Platform(i));
1109         }
1110         CeCosTestPlatform::Save();
1111     }
1112 }
1113
1114 void ecMainFrame::OnBuildOptions(wxCommandEvent& event)
1115 {
1116     ecBuildOptionsDialog dialog(this);
1117     dialog.ShowModal();
1118 }
1119
1120 void ecMainFrame::OnTemplates(wxCommandEvent& event)
1121 {
1122     ecTemplatesDialog dialog(this);
1123     if (dialog.ShowModal() == wxID_OK)
1124         {
1125 #ifdef __WXMSW__
1126         // Ensure display gets updated
1127         ::UpdateWindow((HWND) GetHWND());
1128         //wxYield();
1129 #endif
1130         ecConfigToolDoc* doc = wxGetApp().GetConfigToolDoc();
1131
1132                 doc->SelectHardware(dialog.GetSelectedHardware());
1133                 doc->SelectTemplate(dialog.GetSelectedTemplate(), dialog.GetSelectedTemplateVersion());
1134         }
1135 }
1136
1137 void ecMainFrame::OnAdmin(wxCommandEvent& event)
1138 {
1139     ecConfigToolDoc* doc = wxGetApp().GetConfigToolDoc();
1140
1141     wxASSERT (doc) ;
1142
1143     if (wxYES == wxMessageBox(_("This command will close the current document.\n\nDo you wish to continue?"),
1144         wxGetApp().GetAppName(), wxYES_NO, this))
1145     {
1146         wxString shellCommands;
1147         // ensure that the user tools are on the path for use by ecosadmin.tcl
1148         // TODO: need to something else for Linux (since it returns settings in shellCommands)
1149         if (wxGetApp().PrepareEnvironment(FALSE, & shellCommands))
1150         {
1151             // make sure we use doc data before the doc is destroyed
1152
1153             ecAdminDialog dlg(this, doc->GetPackagesDir(), wxGetApp().GetSettings().GetUserToolsDir());
1154
1155             if (dlg.ShowModal() == wxID_OK)
1156             {
1157                 // Create new document
1158                 wxGetApp().GetDocManager()->CreateDocument(wxEmptyString, wxDOC_NEW);
1159             }
1160         }
1161     }
1162 }
1163
1164 void ecMainFrame::OnPackages(wxCommandEvent& event)
1165 {
1166     ecConfigToolDoc* doc = wxGetApp().GetConfigToolDoc();
1167     if (doc)
1168         doc->SelectPackages();
1169 }
1170
1171 void ecMainFrame::OnRunTests(wxCommandEvent& event)
1172 {
1173     ecConfigToolDoc* doc = wxGetApp().GetConfigToolDoc();
1174     if (doc)
1175         doc->RunTests();
1176 }
1177
1178 void ecMainFrame::OnChooseRepository(wxCommandEvent& event)
1179 {
1180     ecConfigToolDoc* doc = wxGetApp().GetConfigToolDoc();
1181     if (doc && !doc->OnSaveModified())
1182         return;
1183
1184     if (!doc)
1185     {
1186         doc = (ecConfigToolDoc*) wxGetApp().GetDocManager()->CreateDocument(wxString(""), wxDOC_NEW|ecDOC_PROMPT_FOR_REPOSITORY);
1187         return;
1188     }
1189
1190     if (doc)
1191         doc->m_bRepositoryOpen = FALSE;
1192
1193     if (wxGetApp().GetConfigToolDoc()->OpenRepository(wxEmptyString, TRUE))
1194     {
1195         // TODO
1196 #if 0
1197         // reset the document title as shown in the frame window
1198         GetDocTemplate ()->SetDefaultTitle (this);
1199         
1200         // load the memory layout for the default target-platform-startup from the new repository
1201         NewMemoryLayout (CFileName (m_strPackagesDir, m_strMemoryLayoutFolder, _T("include\\pkgconf")));
1202 #endif
1203
1204         doc->UpdateAllViews(NULL);
1205         doc->UpdateFailingRuleCount();
1206     }
1207     else
1208     {
1209         if (doc)
1210             doc->m_bRepositoryOpen = TRUE;
1211     }
1212 }
1213
1214 void ecMainFrame::OnBuildToolsPath(wxCommandEvent& event)
1215 {
1216     ecConfigToolDoc* doc = wxGetApp().GetConfigToolDoc();
1217     if (!doc)
1218         return;
1219
1220     // Add all the paths from the bin dirs to the path array,
1221     // making the default path the appropriate target prefix
1222     wxString defaultPath;
1223     const wxString strPrefix(doc->GetCurrentTargetPrefix());
1224     wxArrayString arstrPaths;
1225
1226     wxStringToStringMap& map = wxGetApp().GetSettings().GetBinDirs();
1227     map.BeginFind();
1228     wxString key, value;
1229     bool hasDefaultDir = FALSE;
1230     while (map.Next(key, value))
1231     {
1232         arstrPaths.Add(value);
1233         if (key == strPrefix)
1234             defaultPath = value;
1235         if (value == wxGetApp().GetSettings().m_buildToolsDir)
1236             hasDefaultDir = TRUE;
1237     }
1238     if (!wxGetApp().GetSettings().m_buildToolsDir.IsEmpty() && !hasDefaultDir)
1239     {
1240         arstrPaths.Add(wxGetApp().GetSettings().m_buildToolsDir);
1241     }
1242     
1243     wxString msg;
1244     msg.Printf(_("Enter the location of the %s build tools\n"
1245           "folder, which should contain %sgcc. You can\n"
1246           "type in a path or use the Browse button to\n"
1247           "navigate to a folder."),
1248           (const wxChar*) (strPrefix.IsEmpty() ? wxString(wxT("native")) : strPrefix),
1249           (const wxChar*) (strPrefix.IsEmpty() ? wxString(wxT("")) : strPrefix + wxT("-"))
1250           );
1251     wxString caption(_("Build Tools Path"));
1252
1253     ecFolderDialog dialog(defaultPath, arstrPaths, msg, this, ecID_BUILD_TOOLS_DIALOG, caption);
1254     if (dialog.ShowModal() == wxID_OK)
1255     {
1256         ecFileName strExe;
1257
1258 #ifdef __WXMSW__
1259         wxString exeSuffix(wxT(".exe"));
1260 #else
1261         wxString exeSuffix(wxEmptyString);
1262 #endif
1263         wxString path(dialog.GetPath());
1264         strExe.Printf(wxT("%s%c%s%sgcc%s"), (const wxChar*) path, wxFILE_SEP_PATH, (const wxChar*) strPrefix,
1265             (const wxChar*) strPrefix.IsEmpty() ? wxT("") : wxT("-"), (const wxChar*) exeSuffix);
1266
1267         wxString msg;
1268         msg.Printf(wxT("%s does not appear to contain the build tools - use this folder anyway?"), (const wxChar*) path);
1269
1270         if(strExe.Exists() ||
1271             (wxID_YES == wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_QUESTION|wxYES_NO)))
1272         {
1273             map.Set(strPrefix, path);
1274             if (!hasDefaultDir)
1275                 wxGetApp().GetSettings().m_buildToolsDir = path;
1276         }
1277     }
1278 }
1279
1280 void ecMainFrame::OnUserToolsPath(wxCommandEvent& event)
1281 {
1282     ecConfigToolDoc* doc = wxGetApp().GetConfigToolDoc();
1283     if (!doc)
1284         return;
1285
1286     wxArrayString paths = wxGetApp().GetSettings().m_userToolPaths;
1287     if (!wxGetApp().GetSettings().m_userToolsDir.IsEmpty())
1288         paths.Add(wxGetApp().GetSettings().m_userToolsDir);
1289
1290     wxString msg(_("Enter the location of the user tools folder,\n"
1291           "which should contain cat and ls. You can type in\n"
1292           "a path or use the Browse button to navigate to a\n"
1293           "folder."));
1294
1295     wxString caption(_("User Tools Path"));
1296     wxString defaultPath(wxGetApp().GetSettings().m_userToolsDir);
1297
1298     ecFolderDialog dialog(defaultPath, paths, msg, this, ecID_USER_TOOLS_DIALOG, caption);
1299     if (dialog.ShowModal() == wxID_OK)
1300     {
1301         wxString path(dialog.GetPath());
1302         ecFileName strFile(path);
1303
1304 #ifdef __WXMSW__
1305         wxString exeSuffix(wxT(".exe"));
1306 #else
1307         wxString exeSuffix(wxEmptyString);
1308 #endif
1309         wxString prog(wxString(wxT("ls")) + exeSuffix);
1310
1311         strFile += (const wxChar*) prog;
1312
1313         wxString msg;
1314         msg.Printf(wxT("%s does not appear to contain the user tools - use this folder anyway?"), (const wxChar*) path);
1315
1316         if(strFile.Exists() ||
1317             (wxID_YES == wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_QUESTION|wxYES_NO)))
1318         {
1319             wxGetApp().GetSettings().m_userToolsDir = path;
1320         }
1321     }
1322 }
1323
1324 // Process events for the window with the focus first.
1325 bool ecMainFrame::ProcessEvent(wxEvent& event)
1326 {
1327     static wxEvent* s_lastEvent = NULL;
1328
1329     if (& event == s_lastEvent)
1330         return FALSE;
1331
1332     if (event.IsCommandEvent())
1333     {
1334         s_lastEvent = & event;
1335         
1336         wxWindow* focusWin = wxFindFocusDescendant(this);
1337         bool success = FALSE;
1338         if (focusWin)
1339         {
1340             //long windowId = focusWin->GetId();
1341             //wxLogDebug("Found focus window %d", windowId);
1342             success = focusWin->GetEventHandler()->ProcessEvent(event);
1343         }
1344         if (!success)
1345             success = wxDocParentFrame::ProcessEvent(event);
1346         
1347         s_lastEvent = NULL;
1348         return success;
1349     }
1350     else
1351     {
1352         return wxDocParentFrame::ProcessEvent(event);
1353     }
1354 }
1355
1356 void ecMainFrame::SetFailRulePane(int nCount)
1357 {
1358     wxString strCount;
1359     switch (nCount)
1360     {
1361     case 0:
1362         strCount = wxT("No conflicts");
1363         break;
1364     case 1:
1365         strCount = wxT("1 conflict");
1366         break;
1367     default:
1368         strCount.Printf (_("%d conflicts"), nCount);
1369         break;
1370     }
1371     if (GetStatusBar())
1372     {
1373         GetStatusBar()->SetStatusText(strCount, ecFailRulePane);
1374     }
1375 }
1376
1377 // Update the title, either via the document's view or explicitly if no doc
1378 void ecMainFrame::UpdateFrameTitle()
1379 {
1380     if (wxGetApp().GetConfigToolDoc())
1381         wxGetApp().GetConfigToolDoc()->GetFirstView()->OnChangeFilename();
1382     else
1383         SetTitle(wxGetApp().GetSettings().GetAppName());
1384 }
1385
1386 void ecMainFrame::OnUpdatePlatforms(wxUpdateUIEvent& event)
1387 {
1388     event.Enable(TRUE);
1389 }
1390
1391 void ecMainFrame::OnUpdateBuildOptions(wxUpdateUIEvent& event)
1392 {
1393     event.Enable(wxGetApp().GetConfigToolDoc() != NULL);
1394 }
1395
1396 void ecMainFrame::OnUpdateBuildToolsPath(wxUpdateUIEvent& event)
1397 {
1398     event.Enable(wxGetApp().GetConfigToolDoc() != NULL);
1399 }
1400
1401 void ecMainFrame::OnUpdateUserToolsPath(wxUpdateUIEvent& event)
1402 {
1403     event.Enable(wxGetApp().GetConfigToolDoc() != NULL);
1404 }
1405
1406 void ecMainFrame::OnUpdateTemplates(wxUpdateUIEvent& event)
1407 {
1408     event.Enable(wxGetApp().GetConfigToolDoc() != NULL);
1409 }
1410
1411 void ecMainFrame::OnUpdateAdmin(wxUpdateUIEvent& event)
1412 {
1413     event.Enable(wxGetApp().GetConfigToolDoc() != NULL);
1414 }
1415
1416 void ecMainFrame::OnUpdatePackages(wxUpdateUIEvent& event)
1417 {
1418     event.Enable(wxGetApp().GetConfigToolDoc() != NULL);
1419 }
1420
1421 void ecMainFrame::OnUpdateRunTests(wxUpdateUIEvent& event)
1422 {
1423     event.Enable(wxGetApp().GetConfigToolDoc() != NULL && !wxGetApp().GetConfigToolDoc()->GetInstallTree().IsEmpty() && (wxGetApp().m_pipedProcess == NULL));
1424 }
1425
1426 void ecMainFrame::OnUpdateChooseRepository(wxUpdateUIEvent& event)
1427 {
1428     event.Enable(TRUE);
1429 }
1430
1431 void ecMainFrame::OnWhatsThis(wxCommandEvent& event)
1432 {
1433     wxGetApp().OnWhatsThis(event);
1434 }
1435
1436 void ecMainFrame::OnSaveOutput(wxCommandEvent& event)
1437 {
1438     ecOutputWindow* win = GetOutputWindow();
1439     if (!win)
1440         return;
1441
1442     wxFileDialog dialog(this, _("Choose a file for saving the output window contents"),
1443         wxT(""), wxT("output.txt"), wxT("*.txt"), wxSAVE|wxOVERWRITE_PROMPT);
1444     if (dialog.ShowModal() == wxID_OK)
1445     {
1446         if (!win->SaveFile(dialog.GetPath()))
1447         {
1448             wxMessageBox(_("Sorry, there was a problem saving the file."), wxGetApp().GetSettings().GetAppName(),
1449                 wxICON_EXCLAMATION|wxID_OK);
1450         }
1451     }
1452 }
1453
1454 void ecMainFrame::OnUpdateSelectAll(wxUpdateUIEvent& event)
1455 {
1456     wxWindow* win = wxWindow::FindFocus();
1457     event.Enable (win && win->IsKindOf(CLASSINFO(wxTextCtrl)) );
1458 }
1459
1460 void ecMainFrame::OnUpdateClear(wxUpdateUIEvent& event)
1461 {
1462     wxWindow* win = wxWindow::FindFocus();
1463     event.Enable (win && win->IsKindOf(CLASSINFO(wxTextCtrl)) );
1464 }
1465
1466 void ecMainFrame::OnImport(wxCommandEvent& event)
1467 {
1468     if (wxGetApp().GetConfigToolDoc())
1469     {
1470         wxGetApp().GetConfigToolDoc()->ImportFile();
1471     }
1472 }
1473
1474 void ecMainFrame::OnExport(wxCommandEvent& event)
1475 {
1476     if (wxGetApp().GetConfigToolDoc())
1477     {
1478         wxGetApp().GetConfigToolDoc()->ExportFile();
1479     }
1480 }
1481
1482 void ecMainFrame::OnUpdateImport(wxUpdateUIEvent& event)
1483 {
1484     event.Enable ( wxGetApp().GetConfigToolDoc() != NULL );
1485 }
1486
1487 void ecMainFrame::OnUpdateExport(wxUpdateUIEvent& event)
1488 {
1489     event.Enable ( wxGetApp().GetConfigToolDoc() != NULL );
1490 }
1491
1492 void ecMainFrame::OnWebRedHatHome(wxCommandEvent& event)
1493 {
1494     wxString strURL(wxT("http://www.redhat.com"));
1495     if (wxGetApp().GetConfigToolDoc())
1496         wxGetApp().GetConfigToolDoc()->ShowURL(strURL);
1497 }
1498
1499 void ecMainFrame::OnWebEcos(wxCommandEvent& event)
1500 {
1501     wxString strURL(wxT("http://www.redhat.com/products/ecos"));
1502     if (wxGetApp().GetConfigToolDoc())
1503         wxGetApp().GetConfigToolDoc()->ShowURL(strURL);
1504 }
1505
1506 void ecMainFrame::OnWebNetRelease(wxCommandEvent& event)
1507 {
1508     wxString strURL(wxT("http://sources.redhat.com/ecos"));
1509     if (wxGetApp().GetConfigToolDoc())
1510         wxGetApp().GetConfigToolDoc()->ShowURL(strURL);
1511 }
1512
1513 void ecMainFrame::OnWebUitron(wxCommandEvent& event)
1514 {
1515     wxString strURL(wxT("http://www.itron.gr.jp/"));
1516     if (wxGetApp().GetConfigToolDoc())
1517         wxGetApp().GetConfigToolDoc()->ShowURL(strURL);
1518 }
1519
1520 void ecMainFrame::OnBuildLibrary(wxCommandEvent& event)
1521 {
1522     // TODO: possibly add wxT("clean build") to ensure library is
1523     // cleanly built. No, can't do that because it would clean
1524     // out any user code too :-(
1525
1526     bool regenerateBuildTree = FALSE;
1527
1528     if (wxGetApp().GetSettings().m_editSaveFileOnly)
1529     {
1530         int ans = wxMessageBox(wxT("Running in --edit-only mode so there may not be an up-to-date build tree.\nBuild the tree now?"), wxGetApp().GetSettings().GetAppName(), wxICON_QUESTION|wxYES_NO|wxCANCEL);
1531
1532         if (ans == wxYES)
1533         {
1534             regenerateBuildTree = TRUE;
1535         }
1536         else if (ans == wxCANCEL)
1537             return;
1538     }
1539
1540     if (regenerateBuildTree)
1541     {
1542         ecConfigToolDoc* pDoc = wxGetApp().GetConfigToolDoc();
1543         if (!pDoc)
1544             return;
1545
1546         if (!pDoc->GenerateBuildTree())
1547             return ;
1548     }
1549
1550     wxGetApp().Build();
1551 }
1552
1553 void ecMainFrame::OnBuildTests(wxCommandEvent& event)
1554 {
1555     bool regenerateBuildTree = FALSE;
1556
1557     if (wxGetApp().GetSettings().m_editSaveFileOnly)
1558     {
1559         int ans = wxMessageBox(wxT("Running in --edit-only mode so there may not be an up-to-date build tree.\nBuild the tree now?"), wxGetApp().GetSettings().GetAppName(), wxICON_QUESTION|wxYES_NO|wxCANCEL);
1560
1561         if (ans == wxYES)
1562         {
1563             regenerateBuildTree = TRUE;
1564         }
1565         else if (ans == wxCANCEL)
1566             return;
1567     }
1568
1569     if (regenerateBuildTree)
1570     {
1571         ecConfigToolDoc* pDoc = wxGetApp().GetConfigToolDoc();
1572         if (!pDoc)
1573             return;
1574
1575         if (!pDoc->GenerateBuildTree())
1576             return ;
1577     }
1578
1579     wxGetApp().Build(wxT("tests"));
1580 }
1581
1582 void ecMainFrame::OnStopBuild(wxCommandEvent& event)
1583 {
1584     if (wxGetApp().m_pipedProcess)
1585     {
1586         long pid = wxGetApp().m_pipedProcess->GetPid();
1587         wxGetApp().m_pipedProcess->Detach();
1588
1589         wxProcessKiller pKiller(pid);
1590         pKiller.Kill(TRUE);
1591     }
1592 }
1593
1594 void ecMainFrame::OnClean(wxCommandEvent& event)
1595 {
1596     wxGetApp().Build(wxT("clean"));
1597 }
1598
1599 void ecMainFrame::OnShell(wxCommandEvent& event)
1600 {
1601     ecConfigToolDoc *pDoc=wxGetApp().GetConfigToolDoc();
1602     if (!pDoc)
1603         return;
1604
1605     wxString variableSettings;
1606     if (wxGetApp().PrepareEnvironment(TRUE, & variableSettings))
1607     {
1608 #ifdef __WXMSW__
1609         wxString currentDir = wxGetCwd();
1610         wxSetWorkingDirectory(pDoc->GetBuildTree());
1611
1612         wxExecute("bash.exe");
1613
1614         if (!currentDir.IsEmpty()) // if the current directory was changed
1615         { 
1616             wxSetWorkingDirectory(currentDir); // restore the previous current directory
1617         }
1618 #else
1619         wxString cmdLine = wxString(wxT("xterm"));
1620
1621         // TODO: query an appropriate variable, and/or have a setting for this
1622         wxExecute(cmdLine);
1623 #endif
1624     }
1625 }
1626
1627 void ecMainFrame::OnUpdateBuildLibrary(wxUpdateUIEvent& event)
1628 {
1629     event.Enable( (wxGetApp().GetConfigToolDoc() != NULL) && (wxGetApp().m_pipedProcess == NULL ));
1630 }
1631
1632 void ecMainFrame::OnUpdateBuildTests(wxUpdateUIEvent& event)
1633 {
1634     event.Enable( (wxGetApp().GetConfigToolDoc() != NULL) && (wxGetApp().m_pipedProcess == NULL ));
1635 }
1636
1637 void ecMainFrame::OnUpdateStopBuild(wxUpdateUIEvent& event)
1638 {
1639     event.Enable( (wxGetApp().GetConfigToolDoc() != NULL) && (wxGetApp().m_pipedProcess != NULL ));
1640 }
1641
1642 void ecMainFrame::OnUpdateClean(wxUpdateUIEvent& event)
1643 {
1644     event.Enable( (wxGetApp().GetConfigToolDoc() != NULL) && (wxGetApp().m_pipedProcess == NULL ));
1645 }
1646
1647 void ecMainFrame::OnRepositoryInfo(wxCommandEvent& event)
1648 {
1649     ecRepositoryInfoDialog dialog(this, ecID_REPOSITORY_INFO, _("Repository Information"));
1650     dialog.ShowModal();
1651 }
1652
1653 void ecMainFrame::OnUpdateShell(wxUpdateUIEvent& event)
1654 {
1655     event.Enable( (wxGetApp().GetConfigToolDoc() != NULL) );
1656 }
1657
1658 void ecMainFrame::OnUpdateRepositoryInfo(wxUpdateUIEvent& event)
1659 {
1660     event.Enable( (wxGetApp().GetConfigToolDoc() != NULL) );
1661 }
1662
1663 void ecMainFrame::OnNewRegion(wxCommandEvent& event)
1664 {
1665 #if ecUSE_MLT
1666 #endif
1667 }
1668
1669 void ecMainFrame::OnNewSection(wxCommandEvent& event)
1670 {
1671 #if ecUSE_MLT
1672 #endif
1673 }
1674
1675 void ecMainFrame::OnDeleteRegionOrSection(wxCommandEvent& event)
1676 {
1677 #if ecUSE_MLT
1678 #endif
1679 }
1680
1681 void ecMainFrame::OnRegionOrSectionProperties(wxCommandEvent& event)
1682 {
1683 #if ecUSE_MLT
1684 #endif
1685 }
1686
1687 void ecMainFrame::OnUpdateNewRegion(wxUpdateUIEvent& event)
1688 {
1689 #if ecUSE_MLT
1690 #else
1691     event.Enable( FALSE );
1692 #endif
1693 }
1694
1695 void ecMainFrame::OnUpdateNewSection(wxUpdateUIEvent& event)
1696 {
1697 #if ecUSE_MLT
1698 #else
1699     event.Enable( FALSE );
1700 #endif
1701 }
1702
1703 void ecMainFrame::OnUpdateDeleteRegionOrSection(wxUpdateUIEvent& event)
1704 {
1705 #if ecUSE_MLT
1706 #else
1707     event.Enable( FALSE );
1708 #endif
1709 }
1710
1711 void ecMainFrame::OnUpdateRegionOrSectionProperties(wxUpdateUIEvent& event)
1712 {
1713 #if ecUSE_MLT
1714 #else
1715     event.Enable( FALSE );
1716 #endif
1717 }
1718
1719 void ecMainFrame::OnIndexDocs(wxCommandEvent& event)
1720 {
1721     ecConfigToolDoc* doc = wxGetApp().GetConfigToolDoc();
1722     if (doc)
1723     {
1724         doc->RebuildHelpIndex(TRUE) ;
1725     }
1726 }
1727
1728 void ecMainFrame::OnUpdateIndexDocs(wxUpdateUIEvent& event)
1729 {
1730     event.Enable( wxGetApp().GetConfigToolDoc() != NULL );
1731 }
1732
1733 void ecMainFrame::OnGenerateBuildTree(wxCommandEvent& event)
1734 {
1735     if (wxGetApp().GetConfigToolDoc() && wxGetApp().GetConfigToolDoc()->CanGenerateBuildTree())
1736     {
1737         if (!wxGetApp().GetConfigToolDoc()->GenerateBuildTree())
1738         {
1739             // Error probably already reported
1740         }
1741     }
1742 }
1743
1744 void ecMainFrame::OnUpdateGenerateBuildTree(wxUpdateUIEvent& event)
1745 {
1746     event.Enable( (wxGetApp().GetConfigToolDoc() != NULL) && wxGetApp().GetConfigToolDoc()->CanGenerateBuildTree());
1747 }