Skip to content

Commit

Permalink
MyFrameMain: wire up context menu to bookmarks
Browse files Browse the repository at this point in the history
Closes #148
  • Loading branch information
bk138 committed Dec 16, 2024
1 parent aea7565 commit 9f88dde
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
57 changes: 28 additions & 29 deletions src/gui/MyFrameMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ MyFrameMain::MyFrameMain(wxWindow* parent, int id, const wxString& title,
frame_main_menubar->Enable(ID_INPUT_REPLAY, false);
// bookmarks
frame_main_menubar->Enable(wxID_ADD, false);
frame_main_menubar->Enable(wxID_EDIT, false);
frame_main_menubar->Enable(wxID_DELETE, false);
// window sharing
frame_main_menubar->Enable(wxID_UP, false);
frame_main_menubar->Enable(wxID_CANCEL, false);
Expand Down Expand Up @@ -209,6 +207,9 @@ MyFrameMain::MyFrameMain(wxWindow* parent, int id, const wxString& title,

// finally, our mdns service scanner
servscan = new wxServDisc(this, wxT("_rfb._tcp.local."), QTYPE_PTR);

// right click handler for bookmarks
list_box_bookmarks->Bind(wxEVT_CONTEXT_MENU, &MyFrameMain::listbox_bookmarks_context, this);
}


Expand Down Expand Up @@ -1108,21 +1109,6 @@ void MyFrameMain::splitwinlayout()

splitwin_main->SetSashPosition(w * 0.1);
splitwin_left->SetSashPosition(h * 0.4);

// finally if not shown, disable menu items
if(!show_bookmarks)
{
frame_main_menubar->Enable(wxID_EDIT, false);
frame_main_menubar->Enable(wxID_DELETE, false);
}
else
{
if(list_box_bookmarks->GetSelection() >= 0)
{
frame_main_menubar->Enable(wxID_EDIT, true);
frame_main_menubar->Enable(wxID_DELETE, true);
}
}
}


Expand All @@ -1149,7 +1135,7 @@ bool MyFrameMain::loadbookmarks()
// clean up
bookmarks.Clear();
wxMenu* bm_menu = frame_main_menubar->GetMenu(frame_main_menubar->FindMenu(_("Bookmarks")));
for(int i = bm_menu->GetMenuItemCount()-1; i > 3; --i)
for(int i = bm_menu->GetMenuItemCount()-1; i > 0; --i)
bm_menu->Destroy(bm_menu->FindItemByPosition(i));
bm_menu->AppendSeparator();

Expand Down Expand Up @@ -1967,18 +1953,8 @@ void MyFrameMain::listbox_bookmarks_select(wxCommandEvent &event)
{
int sel = event.GetInt();

if(sel < 0) //nothing selected
if(sel >= 0) // something selected
{
frame_main_menubar->Enable(wxID_EDIT, false);
frame_main_menubar->Enable(wxID_DELETE, false);

return;
}
else
{
frame_main_menubar->Enable(wxID_EDIT, true);
frame_main_menubar->Enable(wxID_DELETE, true);

wxLogStatus(_("Bookmark %s"), bookmarks[sel]);
}
}
Expand All @@ -2000,6 +1976,29 @@ void MyFrameMain::listbox_bookmarks_dclick(wxCommandEvent &event)
}


void MyFrameMain::listbox_bookmarks_context(wxContextMenuEvent &event)
{
wxPoint clientPosition =
list_box_bookmarks->ScreenToClient(event.GetPosition());

int itemIndex = list_box_bookmarks->HitTest(clientPosition);

if (itemIndex != wxNOT_FOUND) {
// Programmatically select the item. This is for UX purposes and,
// more important, so that edit and delete function work on the
// correct item.
list_box_bookmarks->SetSelection(itemIndex);

// and show the context menu
wxMenu menu;
menu.Append(wxID_EDIT, _("&Edit Bookmark"));
menu.Bind(wxEVT_MENU, &MyFrameMain::bookmarks_edit, this, wxID_EDIT);
menu.Append(wxID_DELETE, _("&Delete Bookmark"));
menu.Bind(wxEVT_MENU, &MyFrameMain::bookmarks_delete, this, wxID_DELETE);
PopupMenu(&menu);
}
}

void MyFrameMain::notebook_connections_pagechanged(wxNotebookEvent &event)
{
ConnBlob* cb;
Expand Down
1 change: 1 addition & 0 deletions src/gui/MyFrameMain.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class MyFrameMain: public FrameMain
void listbox_services_dclick(wxCommandEvent &event);
void listbox_bookmarks_select(wxCommandEvent &event);
void listbox_bookmarks_dclick(wxCommandEvent &event);
void listbox_bookmarks_context(wxContextMenuEvent &event);

void notebook_connections_pagechanged(wxNotebookEvent &event);

Expand Down

0 comments on commit 9f88dde

Please sign in to comment.