Skip to content

Commit

Permalink
Merge pull request #1334 from KeyWorksRW/recent_files
Browse files Browse the repository at this point in the history
Add new Different Project menu item/tool
  • Loading branch information
Randalphwa authored Dec 13, 2023
2 parents 61e339d + b0d2544 commit 8492ef2
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 33 deletions.
68 changes: 67 additions & 1 deletion src/mainframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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;
}
}
}
3 changes: 2 additions & 1 deletion src/mainframe.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
22 changes: 19 additions & 3 deletions src/ui/startup_dlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@

#include "../wxui/ui_images.h"

#include <wx/display.h>

#include "startup_dlg.h"

#include "../mainframe.h"

#include <wx/mstream.h> // memory stream classes
#include <wx/zstream.h> // zlib stream classes

Expand Down Expand Up @@ -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);
Expand All @@ -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
// ***********************************************

/////////////////////////////////////////////////////////////////////////////
Expand All @@ -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();
Expand Down
24 changes: 13 additions & 11 deletions src/wxui/mainframe_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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&)
{
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/wxui/mainframe_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class MainFrameBase : public wxFrame
id_BorderLeft,
id_BorderRight,
id_BorderTop,
id_DifferentProject,
id_Expand,
id_GenerateCode,
id_Magnify,
Expand Down Expand Up @@ -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(); }
Expand Down
42 changes: 25 additions & 17 deletions src/wxui/wxUiEditor.wxui
Original file line number Diff line number Diff line change
Expand Up @@ -214,17 +214,11 @@
class="toolSeparator" />
<node
class="tool"
bitmap="SVG;new-project.svg;[24,24]"
id="id_NewProject"
label="New"
tooltip="New Project (Ctrl+N)" />
<node
class="tool"
bitmap="Art;wxART_FILE_OPEN|wxART_TOOLBAR"
id="id_OpenProject"
label="Open"
tooltip="Open Project (Ctrl+O)"
var_name="tool2" />
bitmap="SVG;wxUiEditor.svg;[24,24]"
id="id_DifferentProject"
label="Different Project..."
tooltip="Different Project... (Ctrl+D)"
var_name="tool4" />
<node
class="tool"
bitmap="SVG;save.svg;[24,24]"
Expand All @@ -236,8 +230,8 @@
class="tool"
bitmap="SVG;generate.svg;[24,24]"
id="id_GenerateCode"
label=""
tooltip="Generate code"
label="Generate..."
tooltip="Generate code..."
var_name="Generate"
wxEVT_TOOL="OnGenerateCode" />
<node
Expand Down Expand Up @@ -446,20 +440,31 @@
class="wxMenu"
label="&amp;File"
var_name="m_menuFile">
<node
class="wxMenuItem"
bitmap="SVG;wxUiEditor.svg;[16,16]"
help="Open a project"
id="id_DifferentProject"
label="&amp;Different Project..."
shortcut="Ctrl+D"
var_name="menuItem3"
wxEVT_MENU="OnDifferentProject" />
<node
class="wxMenuItem"
bitmap="SVG;new-project.svg;[16,16]"
help="Create an empty project"
id="id_NewProject"
label="&amp;New Project...&#09;Ctrl+N"
label="&amp;New Project..."
shortcut="Ctrl+N"
var_name="menuItem"
wxEVT_MENU="[](wxCommandEvent&amp;)@@{@@Project.NewProject(true);@@}" />
<node
class="wxMenuItem"
bitmap="Art;wxART_FILE_OPEN|wxART_OTHER"
bitmap="Art;wxART_FILE_OPEN|wxART_MENU"
help="Open a project"
id="id_OpenProject"
label="&amp;Open Project...&#09;Ctrl+O"
label="&amp;Open Project..."
shortcut="Ctrl+O"
var_name="menuItem2"
wxEVT_MENU="OnOpenProject" />
<node
Expand All @@ -470,7 +475,7 @@
<node
class="wxMenuItem"
bitmap="SVG;import.svg;[16,16]"
label="&amp;Import..."
label="&amp;Import Project..."
var_name="menu_import"
wxEVT_MENU="[](wxCommandEvent&amp;)@@{@@// Specifying false tells NewProject to import@@Project.NewProject(false);@@}" />
<node
Expand Down Expand Up @@ -5168,10 +5173,13 @@
</node>
<node
class="wxDialog"
center="no"
class_name="StartupDlg"
icon="SVG;wxUiEditor.svg;[16,16]"
title="Open, Import, or Create Project"
base_file="..\ui\startup_dlg"
local_src_includes="../mainframe.h"
system_src_includes="wx/display.h"
no_closing_brace="1"
private_members="1"
use_derived_class="0"
Expand Down

0 comments on commit 8492ef2

Please # to comment.