diff --git a/src/mainframe.cpp b/src/mainframe.cpp index e8634e1b0..a1f3b4587 100644 --- a/src/mainframe.cpp +++ b/src/mainframe.cpp @@ -52,6 +52,7 @@ #include "panels/ribbon_tools.h" // RibbonPanel -- Displays component tools in a wxRibbonBar #include "preferences_dlg.h" // PreferencesDlg -- Dialog for setting user preferences +#include "startup_dlg.h" // StartupDlg -- Dialog to display if wxUE is launched with no arguments #include "wxui/ui_images.h" // This is generated from the Images List @@ -642,7 +643,6 @@ void MainFrame::OnOpenRecentProject(wxCommandEvent& event) { if (!SaveWarning()) return; - tt_string file = m_FileHistory.GetHistoryFile(event.GetId() - wxID_FILE1).utf8_string(); if (file.file_exists()) @@ -2137,3 +2137,69 @@ void MainFrame::OnPreferencesDlg(wxCommandEvent& WXUNUSED(event)) PreferencesDlg dlg(this); dlg.ShowModal(); } + +void MainFrame::OnDifferentProject(wxCommandEvent& WXUNUSED(event)) +{ + if (!SaveWarning()) + return; + + StartupDlg start_dlg(m_nav_panel); + if (auto result = start_dlg.ShowModal(); result == wxID_OK) + { + switch (start_dlg.GetCommandType()) + { + case StartupDlg::START_MRU: + if (!start_dlg.GetProjectFile().extension().is_sameas(".wxui", tt::CASE::either) && + !start_dlg.GetProjectFile().extension().is_sameas(".wxue", tt::CASE::either)) + { + Project.ImportProject(start_dlg.GetProjectFile()); + } + else + { + Project.LoadProject(start_dlg.GetProjectFile()); + } + break; + + case StartupDlg::START_EMPTY: + Project.NewProject(true); + break; + + case StartupDlg::START_CONVERT: + Project.NewProject(false); + break; + + case StartupDlg::START_OPEN: + { + // TODO: [KeyWorks - 02-21-2021] A CodeBlocks file will contain all of the wxSmith resources -- so it + // would actually make sense to process it since we can combine all of those resources into our + // single project file. + + wxFileDialog dialog(nullptr, "Open or Import Project", wxEmptyString, wxEmptyString, + "wxUiEditor Project File (*.wxui)|*.wxui" + "|wxCrafter Project File (*.wxcp)|*.wxcp" + "|DialogBlocks Project File (*.fjd)|*.fjd" + "|wxFormBuilder Project File (*.fbp)|*.fbp" + "|wxGlade File (*.wxg)|*.wxg" + "|wxSmith File (*.wxs)|*.wxs" + "|XRC File (*.xrc)|*.xrc" + "|Windows Resource File (*.rc)|*.rc||", + wxFD_OPEN); + + if (dialog.ShowModal() == wxID_OK) + { + tt_string filename = dialog.GetPath().utf8_string(); + if (!filename.extension().is_sameas(".wxui", tt::CASE::either) && + !filename.extension().is_sameas(".wxue", tt::CASE::either)) + { + Project.ImportProject(filename); + } + else + { + Project.LoadProject(dialog.GetPath()); + } + } + } + break; + } + } +} diff --git a/src/mainframe.h b/src/mainframe.h index 59338954f..acefb1156 100644 --- a/src/mainframe.h +++ b/src/mainframe.h @@ -268,6 +268,7 @@ class MainFrame : public MainFrameBase void OnCopy(wxCommandEvent& event) override; void OnCut(wxCommandEvent& event) override; void OnDelete(wxCommandEvent& event) override; + void OnDifferentProject(wxCommandEvent& event) override; void OnDuplicate(wxCommandEvent& event) override; void OnEditCustomIds(wxCommandEvent& event) override; void OnFindDialog(wxCommandEvent& event) override; @@ -277,8 +278,8 @@ class MainFrame : public MainFrameBase void OnInsertWidget(wxCommandEvent&) override; void OnNewProject(wxCommandEvent& event); void OnOpenRecentProject(wxCommandEvent& event); - void OnPreferencesDlg(wxCommandEvent& event) override; void OnPaste(wxCommandEvent& event) override; + void OnPreferencesDlg(wxCommandEvent& event) override; void OnSaveAsProject(wxCommandEvent& event) override; void OnToggleExpandLayout(wxCommandEvent&) override; void OnUpdateBrowseDocs(wxUpdateUIEvent& event) override; diff --git a/src/ui/startup_dlg.cpp b/src/ui/startup_dlg.cpp index 21574fd18..a35734358 100644 --- a/src/ui/startup_dlg.cpp +++ b/src/ui/startup_dlg.cpp @@ -18,8 +18,12 @@ #include "../wxui/ui_images.h" +#include + #include "startup_dlg.h" +#include "../mainframe.h" + #include // memory stream classes #include // zlib stream classes @@ -163,7 +167,6 @@ bool StartupDlg::Create(wxWindow* parent, wxWindowID id, const wxString& title, dlg_sizer->Add(box_sizer_7, wxSizerFlags().Expand().Border(wxALL)); SetSizerAndFit(dlg_sizer); - Centre(wxBOTH); // Event handlers hyperlink_2->Bind(wxEVT_HYPERLINK, &StartupDlg::OnOpen, this); @@ -180,7 +183,6 @@ bool StartupDlg::Create(wxWindow* parent, wxWindowID id, const wxString& title, // Code below this comment block will be preserved // if the code for this class is re-generated. // -// clang-format on // *********************************************** ///////////////////////////////////////////////////////////////////////////// @@ -190,10 +192,24 @@ bool StartupDlg::Create(wxWindow* parent, wxWindowID id, const wxString& title, // License: Apache License -- see ../LICENSE ///////////////////////////////////////////////////////////////////////////// -#include "mainframe.h" // MainFrame -- Main window frame +// clang-format on void StartupDlg::OnInit(wxInitDialogEvent& event) { + if (!GetParent()) + { + wxDisplay desktop(this); + wxRect rect_parent(desktop.GetClientArea()); + wxRect rect_this(GetSize()); + rect_this.x = rect_parent.x + (rect_parent.width - rect_this.width) / 2; + rect_this.y = rect_parent.y + (rect_parent.height - rect_this.height) / 3; + SetSize(rect_this, wxSIZE_ALLOW_MINUS_ONE); + } + else + { + Center(wxHORIZONTAL); + } + m_name_version->SetLabel(txtVersion); auto& history = wxGetMainFrame()->getFileHistory(); diff --git a/src/wxui/mainframe_base.cpp b/src/wxui/mainframe_base.cpp index 1d32208d8..f0fa1b264 100644 --- a/src/wxui/mainframe_base.cpp +++ b/src/wxui/mainframe_base.cpp @@ -77,17 +77,14 @@ bool MainFrameBase::Create(wxWindow* parent, wxWindowID id, const wxString& titl m_toolbar = new wxToolBar(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTB_FLAT|wxTB_HORIZONTAL|wxTB_NODIVIDER); m_toolbar->AddSeparator(); - m_toolbar->AddTool(id_NewProject, "New", - wxueBundleSVG(wxue_img::new_project_svg, 921, 2208, FromDIP(wxSize(24, 24))), "New Project (Ctrl+N)"); - - m_toolbar->AddTool(id_OpenProject, "Open", wxArtProvider::GetBitmapBundle(wxART_FILE_OPEN, wxART_TOOLBAR), - "Open Project (Ctrl+O)"); + m_toolbar->AddTool(id_DifferentProject, "Different Project...", + wxue_img::bundle_wxUiEditor_svg(FromDIP(24), FromDIP(24)), "Different Project... (Ctrl+D)"); m_toolbar->AddTool(wxID_SAVE, "Save", wxueBundleSVG(wxue_img::save_svg, 717, 2603, FromDIP(wxSize(24, 24))), "Save current project"); - m_toolbar->AddTool(id_GenerateCode, wxEmptyString, - wxueBundleSVG(wxue_img::generate_svg, 780, 2716, FromDIP(wxSize(24, 24))), "Generate code"); + m_toolbar->AddTool(id_GenerateCode, "Generate...", + wxueBundleSVG(wxue_img::generate_svg, 780, 2716, FromDIP(wxSize(24, 24))), "Generate code..."); m_toolbar->AddSeparator(); m_toolbar->AddTool(wxID_UNDO, wxEmptyString, @@ -176,19 +173,23 @@ bool MainFrameBase::Create(wxWindow* parent, wxWindowID id, const wxString& titl m_menubar = new wxMenuBar(); m_menuFile = new wxMenu(); + auto* menuItem3 = new wxMenuItem(m_menuFile, id_DifferentProject, "&Different Project...\tCtrl+D", "Open a project", + wxITEM_NORMAL); + menuItem3->SetBitmap(wxue_img::bundle_wxUiEditor_svg(16, 16)); + m_menuFile->Append(menuItem3); auto* menuItem = new wxMenuItem(m_menuFile, id_NewProject, "&New Project...\tCtrl+N", "Create an empty project", wxITEM_NORMAL); menuItem->SetBitmap(wxueBundleSVG(wxue_img::new_project_svg, 921, 2208, wxSize(16, 16))); m_menuFile->Append(menuItem); auto* menuItem2 = new wxMenuItem(m_menuFile, id_OpenProject, "&Open Project...\tCtrl+O", "Open a project", wxITEM_NORMAL); - menuItem2->SetBitmap(wxArtProvider::GetBitmapBundle(wxART_FILE_OPEN, wxART_OTHER)); + menuItem2->SetBitmap(wxArtProvider::GetBitmapBundle(wxART_FILE_OPEN, wxART_MENU)); m_menuFile->Append(menuItem2); m_submenu_recent = new wxMenu(); m_menuFile->AppendSubMenu(m_submenu_recent, "Open &Recent"); - auto* menu_import = new wxMenuItem(m_menuFile, wxID_ANY, "&Import..."); + auto* menu_import = new wxMenuItem(m_menuFile, wxID_ANY, "&Import Project..."); menu_import->SetBitmap(wxue_img::bundle_import_svg(16, 16)); m_menuFile->Append(menu_import); m_menuFile->AppendSeparator(); @@ -404,6 +405,7 @@ bool MainFrameBase::Create(wxWindow* parent, wxWindowID id, const wxString& titl Bind(wxEVT_CLOSE_WINDOW, &MainFrameBase::OnClose, this); Bind(wxEVT_MENU, &MainFrameBase::OnToggleExpandLayout, this, id_Expand); Bind(wxEVT_MENU, &MainFrameBase::OnGenerateCode, this, id_GenerateCode); + Bind(wxEVT_MENU, &MainFrameBase::OnDifferentProject, this, id_DifferentProject); Bind(wxEVT_MENU, [](wxCommandEvent&) { @@ -419,14 +421,14 @@ bool MainFrameBase::Create(wxWindow* parent, wxWindowID id, const wxString& titl }, menu_import->GetId()); Bind(wxEVT_MENU, &MainFrameBase::OnSaveProject, this, wxID_SAVE); - Bind(wxEVT_MENU, &MainFrameBase::OnImportWindowsResource, this, id_AppendWinRes); + Bind(wxEVT_MENU, &MainFrameBase::OnPreviewXrc, this, id_PreviewForm); Bind(wxEVT_MENU, &MainFrameBase::OnSaveAsProject, this, id_SaveProjectAs); Bind(wxEVT_MENU, &MainFrameBase::OnAppendCrafter, this, id_AppendCrafter); Bind(wxEVT_MENU, &MainFrameBase::OnAppendFormBuilder, this, id_AppendFormBuilder); Bind(wxEVT_MENU, &MainFrameBase::OnAppendGlade, this, id_AppendGlade); Bind(wxEVT_MENU, &MainFrameBase::OnAppendSmith, this, id_AppendSmith); Bind(wxEVT_MENU, &MainFrameBase::OnAppendDialogBlocks, this, id_AppendCrafter); - Bind(wxEVT_MENU, &MainFrameBase::OnPreviewXrc, this, id_PreviewForm); + Bind(wxEVT_MENU, &MainFrameBase::OnImportWindowsResource, this, id_AppendWinRes); Bind(wxEVT_MENU, &MainFrameBase::OnAppendXRC, this, id_AppendXRC); Bind(wxEVT_MENU, &MainFrameBase::OnPreferencesDlg, this, id_PreferencesDlg); Bind(wxEVT_MENU, diff --git a/src/wxui/mainframe_base.h b/src/wxui/mainframe_base.h index 68e27790f..1bea0380d 100644 --- a/src/wxui/mainframe_base.h +++ b/src/wxui/mainframe_base.h @@ -68,6 +68,7 @@ class MainFrameBase : public wxFrame id_BorderLeft, id_BorderRight, id_BorderTop, + id_DifferentProject, id_Expand, id_GenerateCode, id_Magnify, @@ -116,6 +117,7 @@ class MainFrameBase : public wxFrame virtual void OnCopy(wxCommandEvent& event) { event.Skip(); } virtual void OnCut(wxCommandEvent& event) { event.Skip(); } virtual void OnDelete(wxCommandEvent& event) { event.Skip(); } + virtual void OnDifferentProject(wxCommandEvent& event) { event.Skip(); } virtual void OnDuplicate(wxCommandEvent& event) { event.Skip(); } virtual void OnEditCustomIds(wxCommandEvent& event) { event.Skip(); } virtual void OnFindDialog(wxCommandEvent& event) { event.Skip(); } diff --git a/src/wxui/wxUiEditor.wxui b/src/wxui/wxUiEditor.wxui index 05ba2ea44..6f002db08 100644 --- a/src/wxui/wxUiEditor.wxui +++ b/src/wxui/wxUiEditor.wxui @@ -214,17 +214,11 @@ class="toolSeparator" /> - + bitmap="SVG;wxUiEditor.svg;[24,24]" + id="id_DifferentProject" + label="Different Project..." + tooltip="Different Project... (Ctrl+D)" + var_name="tool4" /> +