From 71705b5aa493d969e153a88bc5e1168abc1eb65e Mon Sep 17 00:00:00 2001 From: Ykkrosh Date: Sun, 27 Mar 2005 18:07:01 +0000 Subject: [PATCH] Actor Editor: Most-recently-used files list. 'New' menu item. Shuffled some header inclusions around. This was SVN commit r2069. --- .../atlas/AtlasUI/ActorEditor/ActorEditor.cpp | 12 ++++-- .../EditableListCtrl/EditableListCtrl.h | 1 - .../EditableListCtrl/FieldEditCtrl.cpp | 3 +- .../EditableListCtrl/ListCtrlValidator.h | 3 -- .../EditableListCtrl/QuickComboBox.h | 2 - .../EditableListCtrl/QuickFileCtrl.cpp | 1 + .../EditableListCtrl/QuickFileCtrl.h | 2 + .../EditableListCtrl/QuickTextCtrl.h | 2 - .../CustomControls/Windows/AtlasWindow.cpp | 42 ++++++++++++++++--- .../CustomControls/Windows/AtlasWindow.h | 13 +++--- .../General/AtlasWindowCommandProc.cpp | 2 + .../AtlasUI/General/AtlasWindowCommandProc.h | 1 - .../tools/atlas/AtlasUI/General/Datafile.cpp | 1 + source/tools/atlas/AtlasUI/Misc/actored.cpp | 6 ++- source/tools/atlas/AtlasUI/Misc/stdafx.h | 11 +++++ source/tools/atlas/AtlasUI/TODO.txt | 24 ++++++++--- 16 files changed, 93 insertions(+), 33 deletions(-) diff --git a/source/tools/atlas/AtlasUI/ActorEditor/ActorEditor.cpp b/source/tools/atlas/AtlasUI/ActorEditor/ActorEditor.cpp index 4bfd8da60d..90ea8ce83e 100644 --- a/source/tools/atlas/AtlasUI/ActorEditor/ActorEditor.cpp +++ b/source/tools/atlas/AtlasUI/ActorEditor/ActorEditor.cpp @@ -3,12 +3,8 @@ #include "ActorEditor.h" #include "ActorEditorListCtrl.h" - #include "AtlasObject/AtlasObject.h" -#include "wx/panel.h" -#include "wx/sizer.h" - ActorEditor::ActorEditor(wxWindow* parent) : AtlasWindow(parent, _("Actor Editor"), wxSize(1024, 450)) { @@ -67,6 +63,14 @@ ActorEditor::ActorEditor(wxWindow* parent) void ActorEditor::Import(AtObj& in) { + if (! in.defined()) + { + // 'Importing' a new blank file. Fill it in with default values: + AtObj actor; + actor.add("@version", L"1"); + in.add("actor", actor); + } + // Determine the file format version long version; diff --git a/source/tools/atlas/AtlasUI/CustomControls/EditableListCtrl/EditableListCtrl.h b/source/tools/atlas/AtlasUI/CustomControls/EditableListCtrl/EditableListCtrl.h index dd26ddd839..2c3995955a 100644 --- a/source/tools/atlas/AtlasUI/CustomControls/EditableListCtrl/EditableListCtrl.h +++ b/source/tools/atlas/AtlasUI/CustomControls/EditableListCtrl/EditableListCtrl.h @@ -2,7 +2,6 @@ #define EDITABLELISTCTRL_H__ #include "wx/listctrl.h" -#include "wx/arrstr.h" #include "IAtlasExporter.h" diff --git a/source/tools/atlas/AtlasUI/CustomControls/EditableListCtrl/FieldEditCtrl.cpp b/source/tools/atlas/AtlasUI/CustomControls/EditableListCtrl/FieldEditCtrl.cpp index 21abd9bf24..a9411f60ec 100644 --- a/source/tools/atlas/AtlasUI/CustomControls/EditableListCtrl/FieldEditCtrl.cpp +++ b/source/tools/atlas/AtlasUI/CustomControls/EditableListCtrl/FieldEditCtrl.cpp @@ -36,8 +36,7 @@ void FieldEditCtrl_List::StartEdit(wxWindow* parent, wxRect rect, long row, int wxArrayString choices; AtObj list (Datafile::ReadList(m_ListType)); - AtIter items (list["item"]); - for (AtIter it = items; it.defined(); ++it) + for (AtIter it = list["item"]; it.defined(); ++it) choices.Add(it); new QuickComboBox(parent, rect, choices, ListCtrlValidator((EditableListCtrl*)parent, row, col)); diff --git a/source/tools/atlas/AtlasUI/CustomControls/EditableListCtrl/ListCtrlValidator.h b/source/tools/atlas/AtlasUI/CustomControls/EditableListCtrl/ListCtrlValidator.h index fc79f7742c..3891d7d913 100644 --- a/source/tools/atlas/AtlasUI/CustomControls/EditableListCtrl/ListCtrlValidator.h +++ b/source/tools/atlas/AtlasUI/CustomControls/EditableListCtrl/ListCtrlValidator.h @@ -1,6 +1,3 @@ -#include "wx/validate.h" -#include "wx/listctrl.h" - class EditableListCtrl; class ListCtrlValidator : public wxValidator diff --git a/source/tools/atlas/AtlasUI/CustomControls/EditableListCtrl/QuickComboBox.h b/source/tools/atlas/AtlasUI/CustomControls/EditableListCtrl/QuickComboBox.h index 523a8dc041..a0816201bf 100644 --- a/source/tools/atlas/AtlasUI/CustomControls/EditableListCtrl/QuickComboBox.h +++ b/source/tools/atlas/AtlasUI/CustomControls/EditableListCtrl/QuickComboBox.h @@ -1,5 +1,3 @@ -#include "wx/combobox.h" - class QuickComboBox : public wxComboBox { public: diff --git a/source/tools/atlas/AtlasUI/CustomControls/EditableListCtrl/QuickFileCtrl.cpp b/source/tools/atlas/AtlasUI/CustomControls/EditableListCtrl/QuickFileCtrl.cpp index d7c903856e..350dfe0272 100644 --- a/source/tools/atlas/AtlasUI/CustomControls/EditableListCtrl/QuickFileCtrl.cpp +++ b/source/tools/atlas/AtlasUI/CustomControls/EditableListCtrl/QuickFileCtrl.cpp @@ -1,6 +1,7 @@ #include "stdafx.h" #include "QuickFileCtrl.h" + #include "wx/filename.h" const int verticalPadding = 2; diff --git a/source/tools/atlas/AtlasUI/CustomControls/EditableListCtrl/QuickFileCtrl.h b/source/tools/atlas/AtlasUI/CustomControls/EditableListCtrl/QuickFileCtrl.h index f36ad6af1e..75b5ab0cbc 100644 --- a/source/tools/atlas/AtlasUI/CustomControls/EditableListCtrl/QuickFileCtrl.h +++ b/source/tools/atlas/AtlasUI/CustomControls/EditableListCtrl/QuickFileCtrl.h @@ -1,3 +1,5 @@ +#include "wx/panel.h" + class QuickFileCtrl : public wxPanel { DECLARE_DYNAMIC_CLASS(QuickFileCtrl); diff --git a/source/tools/atlas/AtlasUI/CustomControls/EditableListCtrl/QuickTextCtrl.h b/source/tools/atlas/AtlasUI/CustomControls/EditableListCtrl/QuickTextCtrl.h index 2e163681af..da81358e5d 100644 --- a/source/tools/atlas/AtlasUI/CustomControls/EditableListCtrl/QuickTextCtrl.h +++ b/source/tools/atlas/AtlasUI/CustomControls/EditableListCtrl/QuickTextCtrl.h @@ -1,5 +1,3 @@ -#include "wx/textctrl.h" - class QuickTextCtrl : public wxTextCtrl { public: diff --git a/source/tools/atlas/AtlasUI/CustomControls/Windows/AtlasWindow.cpp b/source/tools/atlas/AtlasUI/CustomControls/Windows/AtlasWindow.cpp index 96dcf44f65..16dff8beb1 100644 --- a/source/tools/atlas/AtlasUI/CustomControls/Windows/AtlasWindow.cpp +++ b/source/tools/atlas/AtlasUI/CustomControls/Windows/AtlasWindow.cpp @@ -4,9 +4,8 @@ #include "AtlasObject/AtlasObject.h" -#include "wx/intl.h" -#include "wx/menu.h" #include "wx/artprov.h" +#include "wx/config.h" ////////////////////////////////////////////////////////////////////////// @@ -57,6 +56,7 @@ IMPLEMENT_CLASS(AtlasWindow, wxFrame); enum { ID_Quit = 1, + ID_New, // ID_Import, // ID_Export, ID_Open, @@ -65,20 +65,24 @@ enum }; BEGIN_EVENT_TABLE(AtlasWindow, wxFrame) - EVT_MENU(ID_Quit, AtlasWindow::OnQuit) + EVT_MENU(ID_New, AtlasWindow::OnNew) // EVT_MENU(ID_Import, AtlasWindow::OnImport) // EVT_MENU(ID_Export, AtlasWindow::OnExport) EVT_MENU(ID_Open, AtlasWindow::OnOpen) EVT_MENU(ID_Save, AtlasWindow::OnSave) EVT_MENU(ID_SaveAs, AtlasWindow::OnSaveAs) + EVT_MENU_RANGE(wxID_FILE1, wxID_FILE9, AtlasWindow::OnMRUFile) + EVT_MENU(ID_Quit, AtlasWindow::OnQuit) + EVT_MENU(wxID_UNDO, AtlasWindow::OnUndo) EVT_MENU(wxID_REDO, AtlasWindow::OnRedo) + EVT_CLOSE(AtlasWindow::OnClose) END_EVENT_TABLE() AtlasWindow::AtlasWindow(wxWindow* parent, const wxString& title, const wxSize& size) - : wxFrame(parent, wxID_ANY, _T(""), wxDefaultPosition, size) - , m_WindowTitle(title) + : wxFrame(parent, wxID_ANY, _T(""), wxDefaultPosition, size), + m_WindowTitle(title), m_FileHistory(9) { wxMenuBar *menuBar = new wxMenuBar; @@ -87,6 +91,7 @@ AtlasWindow::AtlasWindow(wxWindow* parent, const wxString& title, const wxSize& wxMenu *menuFile = new wxMenu; menuBar->Append(menuFile, _("&File")); { + menuFile->Append(ID_New, _("&New")); // menuFile->Append(ID_Import, _("&Import...")); // menuFile->Append(ID_Export, _("&Export...")); menuFile->Append(ID_Open, _("&Open...")); @@ -94,6 +99,8 @@ AtlasWindow::AtlasWindow(wxWindow* parent, const wxString& title, const wxSize& menuFile->Append(ID_SaveAs, _("Save &As...")); menuFile->AppendSeparator();//----------- menuFile->Append(ID_Quit, _("E&xit")); + m_FileHistory.UseMenu(menuFile);//------- + m_FileHistory.AddFilesToMenu(); } m_menuItem_Save = menuFile->FindItem(ID_Save); // to let it be greyed out @@ -109,6 +116,8 @@ AtlasWindow::AtlasWindow(wxWindow* parent, const wxString& title, const wxSize& m_CommandProc.SetEditMenu(menuEdit); m_CommandProc.Initialize(); + m_FileHistory.Load(*wxConfigBase::Get()); + CreateStatusBar(); //SetStatusText(_("Welcome to wxWidgets!")); @@ -142,6 +151,9 @@ void AtlasWindow::OnClose(wxCloseEvent& event) assert(ret == wxID_CANCEL); event.Veto(); } + + if (event.GetSkipped()) + m_FileHistory.Save(*wxConfigBase::Get()); } void AtlasWindow::OnUndo(wxCommandEvent& WXUNUSED(event)) @@ -165,6 +177,12 @@ void AtlasWindow::OnRedo(wxCommandEvent& WXUNUSED(event)) // ... //} +void AtlasWindow::OnNew(wxCommandEvent& WXUNUSED(event)) +{ + AtObj blank; + Import(blank); + SetCurrentFilename(); +} void AtlasWindow::OnOpen(wxCommandEvent& WXUNUSED(event)) { @@ -186,6 +204,14 @@ void AtlasWindow::OnSaveAs(wxCommandEvent& WXUNUSED(event)) SaveChanges(true); } +void AtlasWindow::OnMRUFile(wxCommandEvent& event) +{ + wxString file (m_FileHistory.GetHistoryFile(event.GetId() - wxID_FILE1)); + if (file.Length()) + OpenFile(file); +} + + void AtlasWindow::SetCurrentFilename(wxFileName filename) { @@ -213,7 +239,10 @@ bool AtlasWindow::SaveChanges(bool forceSaveAs) if (dlg.ShowModal() != wxID_OK) return false; - SetCurrentFilename(dlg.GetPath()); + wxString filename(dlg.GetPath()); + + m_FileHistory.AddFileToHistory(filename); + SetCurrentFilename(filename); } if (! GetCurrentFilename().IsOk()) @@ -237,6 +266,7 @@ bool AtlasWindow::OpenFile(wxString filename) Import(file); + m_FileHistory.AddFileToHistory(filename); SetCurrentFilename(filename); return true; diff --git a/source/tools/atlas/AtlasUI/CustomControls/Windows/AtlasWindow.h b/source/tools/atlas/AtlasUI/CustomControls/Windows/AtlasWindow.h index 80461b4971..195d9e5bb0 100644 --- a/source/tools/atlas/AtlasUI/CustomControls/Windows/AtlasWindow.h +++ b/source/tools/atlas/AtlasUI/CustomControls/Windows/AtlasWindow.h @@ -2,8 +2,8 @@ #include "IAtlasExporter.h" -#include "wx/frame.h" #include "wx/filename.h" +#include "wx/docview.h" class AtObj; @@ -16,22 +16,23 @@ class AtlasWindow : public wxFrame, public IAtlasExporter public: AtlasWindow(wxWindow* parent, const wxString& title, const wxSize& size); - void OnQuit(wxCommandEvent& event); - + void OnNew(wxCommandEvent& event); // void OnImport(wxCommandEvent& event); // void OnExport(wxCommandEvent& event); - // TODO: import/export vs open/save/saveas - how should it decide which to do? void OnOpen(wxCommandEvent& event); void OnSave(wxCommandEvent& event); void OnSaveAs(wxCommandEvent& event); + void OnQuit(wxCommandEvent& event); + + void OnMRUFile(wxCommandEvent& event); + void OnUndo(wxCommandEvent& event); void OnRedo(wxCommandEvent& event); void OnClose(wxCloseEvent& event); - protected: void SetCurrentFilename(wxFileName filename = wxString()); wxFileName GetCurrentFilename() { return m_CurrentFilename; } @@ -48,5 +49,7 @@ private: wxFileName m_CurrentFilename; wxString m_WindowTitle; + wxFileHistory m_FileHistory; + DECLARE_EVENT_TABLE(); }; diff --git a/source/tools/atlas/AtlasUI/General/AtlasWindowCommandProc.cpp b/source/tools/atlas/AtlasUI/General/AtlasWindowCommandProc.cpp index a5470437c3..4856202935 100644 --- a/source/tools/atlas/AtlasUI/General/AtlasWindowCommandProc.cpp +++ b/source/tools/atlas/AtlasUI/General/AtlasWindowCommandProc.cpp @@ -1,5 +1,7 @@ #include "stdafx.h" +#include "AtlasWindowCommandProc.h" + #include "AtlasWindow.h" #include "AtlasWindowCommand.h" #include "AtlasDialog.h" diff --git a/source/tools/atlas/AtlasUI/General/AtlasWindowCommandProc.h b/source/tools/atlas/AtlasUI/General/AtlasWindowCommandProc.h index 67edb68b55..3e1a357b70 100644 --- a/source/tools/atlas/AtlasUI/General/AtlasWindowCommandProc.h +++ b/source/tools/atlas/AtlasUI/General/AtlasWindowCommandProc.h @@ -2,7 +2,6 @@ #define ATLASWINDOWCOMMANDPROC_H__ #include "wx/cmdproc.h" -#include "wx/window.h" class AtlasWindowCommandProc : public wxCommandProcessor { diff --git a/source/tools/atlas/AtlasUI/General/Datafile.cpp b/source/tools/atlas/AtlasUI/General/Datafile.cpp index 05a997844b..ef8b2db003 100644 --- a/source/tools/atlas/AtlasUI/General/Datafile.cpp +++ b/source/tools/atlas/AtlasUI/General/Datafile.cpp @@ -1,6 +1,7 @@ #include "stdafx.h" #include "Datafile.h" + #include "wx/filename.h" AtObj Datafile::ReadList(const char* section) diff --git a/source/tools/atlas/AtlasUI/Misc/actored.cpp b/source/tools/atlas/AtlasUI/Misc/actored.cpp index fafe56005f..cdfb69a0a6 100644 --- a/source/tools/atlas/AtlasUI/Misc/actored.cpp +++ b/source/tools/atlas/AtlasUI/Misc/actored.cpp @@ -5,13 +5,16 @@ #include "ActorEditor/ActorEditor.h" #include "Datafile.h" -#include "wx/app.h" #include "wx/file.h" +#include "wx/config.h" class MyApp: public wxApp { bool OnInit() { + // Initialise the global config file + wxConfigBase::Set(new wxConfig(_T("Atlas Editor"), _T("Wildfire Games"))); + // Display the Actor Editor window AtlasWindow *frame = new ActorEditor(NULL); frame->Show(); @@ -35,6 +38,7 @@ class MyApp: public wxApp return true; } + }; IMPLEMENT_APP(MyApp) diff --git a/source/tools/atlas/AtlasUI/Misc/stdafx.h b/source/tools/atlas/AtlasUI/Misc/stdafx.h index 161d728dae..2108e81970 100644 --- a/source/tools/atlas/AtlasUI/Misc/stdafx.h +++ b/source/tools/atlas/AtlasUI/Misc/stdafx.h @@ -12,8 +12,14 @@ // Include useful wx headers #include "wx/wxprec.h" #include "wx/listctrl.h" +#include "wx/docview.h" +#include "wx/cmdproc.h" +#include "wx/dialog.h" +#include "wx/filename.h" +#include "wx/artprov.h" #include +#include // Nicer memory-leak detection: #ifdef _DEBUG @@ -22,3 +28,8 @@ #endif #endif // HAVE_PCH + +#ifndef HAVE_PCH +// If no PCH, just include a load of common headers anyway +# include "wx/wx.h" +#endif diff --git a/source/tools/atlas/AtlasUI/TODO.txt b/source/tools/atlas/AtlasUI/TODO.txt index 27dd52e3de..c341f6a7ed 100644 --- a/source/tools/atlas/AtlasUI/TODO.txt +++ b/source/tools/atlas/AtlasUI/TODO.txt @@ -1,5 +1,7 @@ * Open from prop-actor selection +* Make import undo work with multi-control windows, and update the title bar + === * 'Create entity' button (take name, parent) @@ -16,14 +18,16 @@ * Better colouring in test_dude.xml, where some variants have no data +* Tab to move between fields + === +* Correct undo menu entry when selecting 'New' (so it's not 'Import') + * Save on exit: don't ask if no changes * Browse for meshes/actors/etc, in a more nice/correct/unbuggy way -* Make import undo work with multi-control windows, and update the title bar - * Window size memory * Column width memory @@ -36,8 +40,6 @@ * Customised AtObj->string conversion -* Import/export filter, for validation(?) and for handling attributes - * Undo in text-editing boxes * AtlasObjectXML error handling @@ -46,13 +48,23 @@ * Fix Escape in combo boxes inside dialogs -=== +* Make wxFileHistory work when not at the very end of a menu +=== * Document lots -* wxListItemAttr* OnGetItemAttr(long item) >>>const<<< - wx documentation?? +* wxListItemAttr* OnGetItemAttr(long item) >>>const<<< - wx documentation wrong? * Better column widths / window sizes * Don't create a row when editing a blank one then removing focus without typing anything + + +====== + +Done: + +* MRU file list +* 'New' menu item +* Import/export filter, for validation(?) and for handling attributes