Skip to content

Commit

Permalink
Merge pull request #1401 from KeyWorksRW/popup_menu
Browse files Browse the repository at this point in the history
Update Navigation panel Popup menu
  • Loading branch information
Randalphwa authored Feb 6, 2024
2 parents 7892314 + e58ef01 commit 005b23d
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 53 deletions.
2 changes: 1 addition & 1 deletion src/generate/base_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class BaseGenerator
// Return true to automatically add submenu command to add child sizers.
//
// You will need to Bind to any commands you add.
virtual bool PopupMenuAddCommands(NavPopupMenu*, Node*) { return false; }
virtual bool PopupMenuAddCommands(NavPopupMenu*, Node*) { return true; }

// Call this to retrieve any warning text when generating code for the specific language.
virtual std::optional<tt_string> GetWarning(Node*, int /* language */) { return {}; }
Expand Down
7 changes: 4 additions & 3 deletions src/generate/gen_project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ bool ProjectGenerator::PopupMenuAddCommands(NavPopupMenu* menu, Node* /* node */
},
NavPopupMenu::MenuPROJECT_ADD_WIZARD);

return true;
// Return false to indicate no sizer sub commands should be added
return false;
}

bool ProjectGenerator::AllowPropertyChange(wxPropertyGridEvent* event, NodeProperty* prop, Node* /* node */)
Expand Down Expand Up @@ -169,7 +170,7 @@ bool FolderGenerator::PopupMenuAddCommands(NavPopupMenu* menu, Node* /* node */)
},
NavPopupMenu::MenuPROJECT_ADD_WIZARD);

return true;
return false;
}

bool SubFolderGenerator::PopupMenuAddCommands(NavPopupMenu* menu, Node* /* node */)
Expand Down Expand Up @@ -231,5 +232,5 @@ bool SubFolderGenerator::PopupMenuAddCommands(NavPopupMenu* menu, Node* /* node
},
NavPopupMenu::MenuPROJECT_ADD_WIZARD);

return true;
return false;
}
2 changes: 1 addition & 1 deletion src/generate/gen_wizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ bool WizardFormGenerator::PopupMenuAddCommands(NavPopupMenu* menu, Node* node)
},
NavPopupMenu::MenuADD_WIZARD_PAGE);

return true;
return false;
}

// ../../wxSnapShot/src/xrc/xh_wizrd.cpp
Expand Down
159 changes: 111 additions & 48 deletions src/panels/navpopupmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ void NavPopupMenu::CreateSizerMenu(Node* node)
AppendSubMenu(sub_menu, "Change Sizer To");
}

AppendSeparator();
AddSeparatorIfNeeded();
MenuAddStandardCommands(node);
}

Expand All @@ -485,11 +485,6 @@ void NavPopupMenu::CreateCommonMenu(Node* node)

MenuAddCommands(node);
MenuAddMoveCommands(node);
if (!node->isGen(gen_Images) && !node->isGen(gen_embedded_image) && !node->isGen(gen_Data) &&
!node->isGen(gen_data_string))
{
AppendSeparator();
}
MenuAddStandardCommands(node);
}

Expand All @@ -507,8 +502,7 @@ void NavPopupMenu::MenuAddCommands(Node* node)
}
#endif

if (node->isForm() || node->isGen(gen_Images) || node->isGen(gen_embedded_image) || node->isGen(gen_Data) ||
node->isGen(gen_data_string))
if (node->isForm() || node->isGen(gen_Images) || node->isGen(gen_embedded_image))
{
if (node->isGen(gen_wxPropertySheetDialog))
{
Expand All @@ -522,7 +516,27 @@ void NavPopupMenu::MenuAddCommands(Node* node)
MenuADD_PAGE);
return;
}
if (!node->isGen(gen_wxWizard) && !node->isToolBar())
else if (node->isGen(gen_Data))
{
Append(MenuADD_DATA_STRING, "Add File");
Append(MenuADD_DATA_XML, "Add XML File");
Bind(
wxEVT_MENU,
[](wxCommandEvent&)
{
wxGetFrame().createToolNode(gen_data_string);
},
MenuADD_DATA_STRING);
Bind(
wxEVT_MENU,
[](wxCommandEvent&)
{
wxGetFrame().createToolNode(gen_data_xml);
},
MenuADD_DATA_XML);
return;
}
else if (!node->isGen(gen_wxWizard) && !node->isToolBar())
{
return;
}
Expand All @@ -535,11 +549,14 @@ void NavPopupMenu::MenuAddCommands(Node* node)

if (auto gen = node->getGenerator(); gen)
{
if (gen->PopupMenuAddCommands(this, node))
if (!gen->PopupMenuAddCommands(this, node))
{
AppendSeparator();
return;
}
else
{
AddSeparatorIfNeeded();
}
}

bool add_sizer = true;
Expand Down Expand Up @@ -769,6 +786,28 @@ void NavPopupMenu::MenuAddCommands(Node* node)
MenuADD_PROPGRID_ITEM);
break;

case gen_data_string:
case gen_data_xml:
case gen_data_folder:
add_sizer = false;
Append(MenuADD_DATA_STRING, "Add File");
Append(MenuADD_DATA_XML, "Add XML File");
Bind(
wxEVT_MENU,
[](wxCommandEvent&)
{
wxGetFrame().createToolNode(gen_data_string);
},
MenuADD_DATA_STRING);
Bind(
wxEVT_MENU,
[](wxCommandEvent&)
{
wxGetFrame().createToolNode(gen_data_xml);
},
MenuADD_DATA_XML);
break;

default:
if (m_is_parent_toolbar)
{
Expand All @@ -789,7 +828,7 @@ void NavPopupMenu::MenuAddCommands(Node* node)

if (!node->isGen(gen_Project))
{
AppendSeparator();
AddSeparatorIfNeeded();
}
}

Expand Down Expand Up @@ -824,15 +863,15 @@ void NavPopupMenu::MenuAddChildSizerCommands(Node* child)

void NavPopupMenu::MenuAddMoveCommands(Node* node)
{
if (node->isGen(gen_Project) || node->isGen(gen_Images) || node->isGen(gen_embedded_image) || node->isGen(gen_Data) ||
node->isGen(gen_data_string))
if (node->isGen(gen_Project) || node->isGen(gen_Images) || node->isGen(gen_Data))
{
return;
}

wxMenuItem* menu_item;
wxMenu* sub_menu;
auto dpi_size = wxGetFrame().FromDIP(wxSize(16, 16));
AddSeparatorIfNeeded();

sub_menu = new wxMenu;
menu_item = sub_menu->Append(MenuMOVE_UP, "Up\tAlt+Up", "Moves selected item up");
Expand All @@ -850,6 +889,12 @@ void NavPopupMenu::MenuAddMoveCommands(Node* node)
}
AppendSubMenu(sub_menu, "Move");

if (node->isGen(gen_folder) || node->isGen(gen_sub_folder) || node->isGen(gen_data_folder))
{
// Folders can only move up, down, left or right. No other move operations can be done on a folder.
return;
}

if (!m_is_parent_toolbar && gen && gen->CanChangeParent(node))
{
sub_menu = new wxMenu;
Expand Down Expand Up @@ -993,62 +1038,68 @@ void NavPopupMenu::MenuAddMoveCommands(Node* node)
menu_item->SetBitmap(GetInternalImage("wxNotebook"));
AppendSubMenu(sub_menu, "&Change widget to");
}
return;
}

void NavPopupMenu::MenuAddStandardCommands(Node* node)
{
if (node->isGen(gen_Images) || node->isGen(gen_embedded_image) || node->isGen(gen_Data) || node->isGen(gen_data_string))
AddSeparatorIfNeeded();
m_isPasteAllowed = false;
if (node->isGen(gen_embedded_image))
{
auto* menu_item = Append(wxID_DELETE);
menu_item->SetBitmap(wxArtProvider::GetBitmapBundle(wxART_DELETE, wxART_MENU));
return;
}
else if (node->isGen(gen_wxStatusBar))
{
auto* menu_item = Append(wxID_CUT);
menu_item->SetBitmap(wxArtProvider::GetBitmapBundle(wxART_CUT, wxART_MENU));

menu_item = Append(wxID_COPY);
menu_item->SetBitmap(wxArtProvider::GetBitmapBundle(wxART_COPY, wxART_MENU));

m_isPasteAllowed = false;
menu_item = Append(wxID_DELETE);
menu_item->SetBitmap(wxArtProvider::GetBitmapBundle(wxART_DELETE, wxART_MENU));
return;
}

m_isPasteAllowed = false;
auto clip_node = GetClipboardNode(false);
if (!clip_node)
{
clip_node = wxGetFrame().getClipboardPtr();
}
m_isPasteAllowed = (clip_node ? true : false);

if (!node->isGen(gen_wxStatusBar))
if (node->isGen(gen_Project))
{
auto clip_node = GetClipboardNode(false);
if (!clip_node)
auto paste_menu_item = Append(wxID_PASTE);
paste_menu_item->SetBitmap(wxArtProvider::GetBitmapBundle(wxART_PASTE, wxART_MENU));
if (!clip_node || !clip_node->isForm())
{
clip_node = wxGetFrame().getClipboardPtr();
paste_menu_item->Enable(false);
m_isPasteAllowed = false;
}

if (node->isGen(gen_Project))
{
auto paste_menu_item = Append(wxID_PASTE);
paste_menu_item->SetBitmap(wxArtProvider::GetBitmapBundle(wxART_PASTE, wxART_MENU));
if (!clip_node || !clip_node->isForm())
{
paste_menu_item->Enable(false);
m_isPasteAllowed = false;
}

// There are no other standard commands for a project
return;
}
m_isPasteAllowed = (clip_node ? true : false);
// There are no other standard commands for a project
return;
}

wxMenuItem* menu_item;
menu_item = Append(wxID_CUT);
menu_item->SetBitmap(wxArtProvider::GetBitmapBundle(wxART_CUT, wxART_MENU));

menu_item = Append(wxID_COPY);
menu_item->SetBitmap(wxArtProvider::GetBitmapBundle(wxART_COPY, wxART_MENU));
if (!node->isGen(gen_wxStatusBar))
{
auto paste_menu_item = Append(wxID_PASTE);
paste_menu_item->SetBitmap(wxArtProvider::GetBitmapBundle(wxART_PASTE, wxART_MENU));
if (!m_isPasteAllowed)
{
paste_menu_item->Enable(false);
}
}

auto paste_menu_item = Append(wxID_PASTE);
paste_menu_item->SetBitmap(wxArtProvider::GetBitmapBundle(wxART_PASTE, wxART_MENU));
paste_menu_item->Enable((clip_node ? true : false));

menu_item = Append(wxID_DELETE);
menu_item->SetBitmap(wxArtProvider::GetBitmapBundle(wxART_DELETE, wxART_MENU));
if (!node->isGen(gen_wxStatusBar))

if (!node->isGen(gen_Images) && !node->isGen(gen_Data))
{
Append(MenuDUPLICATE, "Duplicate");
}
Expand Down Expand Up @@ -1098,9 +1149,9 @@ void NavPopupMenu::CreateSizerParent(Node* node, tt_string_view widget)
undo_string << "sizer";
wxGetFrame().PushUndoAction(std::make_shared<InsertNodeAction>(new_parent.get(), parent, undo_string, childPos));

// InsertNodeAction does not fire the creation event since that's usually handled by the caller as needed. We don't
// want to fire an event because we don't want the Mockup or Code panels to update until we have changed the parent.
// However we *do* need to let the navigation panel know that a new node has been added.
// InsertNodeAction does not fire the creation event since that's usually handled by the caller as needed. We
// don't want to fire an event because we don't want the Mockup or Code panels to update until we have changed
// the parent. However we *do* need to let the navigation panel know that a new node has been added.

wxGetFrame().getNavigationPanel()->InsertNode(new_parent.get());

Expand Down Expand Up @@ -1255,3 +1306,15 @@ void NavPopupMenu::AddToolbarCommands(Node* node)
MenuADD_TOOL_STRETCHABLE_SPACER);
}
}

void NavPopupMenu::AddSeparatorIfNeeded()
{
if (auto count = GetMenuItemCount(); count)
{
auto* menu_item = FindItemByPosition(count - 1);
if (menu_item->GetKind() != wxITEM_SEPARATOR)
{
AppendSeparator();
}
}
}
6 changes: 6 additions & 0 deletions src/panels/navpopupmenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ class NavPopupMenu : public wxMenu

MenuEXPAND_ALL,

// Data List commands
MenuADD_DATA_STRING,
MenuADD_DATA_XML,

// These are for Internal builds only
MenuSingleGenCpp,
MenuSingleGenPython,
Expand Down Expand Up @@ -187,6 +191,8 @@ class NavPopupMenu : public wxMenu
void ChangeSizer(GenEnum::GenName new_sizer_gen);
void CreateSizerParent(Node* node, tt_string_view widget);

void AddSeparatorIfNeeded();

private:
Node* m_node { nullptr };
Node* m_child { nullptr };
Expand Down

0 comments on commit 005b23d

Please # to comment.