[gtkmm-documentation] Update the PlacesSidebar example
- From: Kjell Ahlstedt <kjellahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtkmm-documentation] Update the PlacesSidebar example
- Date: Thu, 12 Jan 2017 17:42:19 +0000 (UTC)
commit f6a70a15be1227aef980e9cba4891d64cc2c9745
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date: Thu Jan 12 18:39:45 2017 +0100
Update the PlacesSidebar example
The signal_populate_popup() handlers now get a Container* and the container
is not always a menu.
examples/book/placessidebar/examplewindow.cc | 28 +++++++++++++++++++++----
examples/book/placessidebar/examplewindow.h | 2 +-
2 files changed, 24 insertions(+), 6 deletions(-)
---
diff --git a/examples/book/placessidebar/examplewindow.cc b/examples/book/placessidebar/examplewindow.cc
index 8677c5e..a8d77c6 100644
--- a/examples/book/placessidebar/examplewindow.cc
+++ b/examples/book/placessidebar/examplewindow.cc
@@ -38,6 +38,7 @@ ExampleWindow::ExampleWindow()
m_show_enter_location.signal_toggled().connect(sigc::mem_fun(*this,
&ExampleWindow::on_show_enter_location_toggled));
m_show_enter_location.set_active(false);
+ m_places_sidebar.property_populate_all() = true;
m_places_sidebar.signal_open_location().connect(sigc::mem_fun(*this,
&ExampleWindow::on_placessidebar_open_location));
m_places_sidebar.signal_populate_popup().connect(sigc::mem_fun(*this,
&ExampleWindow::on_placessidebar_populate_popup));
//m_places_sidebar.signal_drag_action_requested().connect(sigc::mem_fun(*this,
&ExampleWindow::on_placessidebar_drag_action_requested));
@@ -116,14 +117,31 @@ void ExampleWindow::on_placessidebar_open_location(const Glib::RefPtr<Gio::File>
dialog.run();
}
-void ExampleWindow::on_placessidebar_populate_popup(Gtk::Menu* menu, const Glib::RefPtr<Gio::File>& /*
selected_item */, const Glib::RefPtr<Gio::Volume>& /* selected_volume */)
+void ExampleWindow::on_placessidebar_populate_popup(Gtk::Container* container, const
Glib::RefPtr<Gio::File>& /* selected_item */, const Glib::RefPtr<Gio::Volume>& /* selected_volume */)
{
- auto properties_menu_item = new Gtk::MenuItem("Properties...");
+ if (auto menu = dynamic_cast<Gtk::Menu*>(container))
+ {
+ auto properties_menu_item = Gtk::manage(new Gtk::MenuItem("Properties..."));
+
+ properties_menu_item->signal_activate().connect(sigc::mem_fun(*this,
&ExampleWindow::on_menu_properties_activate));
+ properties_menu_item->show();
+
+ menu->attach(*properties_menu_item, 0, 1, 0, 1);
+ }
+ else if (auto box = dynamic_cast<Gtk::Box*>(container))
+ {
+ auto properties_button = Gtk::manage(new Gtk::ModelButton());
+ properties_button->property_text() = "Properties...";
- properties_menu_item->signal_activate().connect(sigc::mem_fun(*this,
&ExampleWindow::on_menu_properties_activate));
- properties_menu_item->show();
+ properties_button->signal_clicked().connect(sigc::mem_fun(*this,
&ExampleWindow::on_menu_properties_activate));
+ properties_button->show();
- menu->attach(*properties_menu_item, 0, 1, 0, 1);
+ box->pack_end(*properties_button);
+ }
+ else
+ {
+ std::cout << "on_placessidebar_populate_popup(): Unknown type of container." << std::endl;
+ }
}
void ExampleWindow::on_menu_properties_activate()
diff --git a/examples/book/placessidebar/examplewindow.h b/examples/book/placessidebar/examplewindow.h
index 88c1b22..f0d4db6 100644
--- a/examples/book/placessidebar/examplewindow.h
+++ b/examples/book/placessidebar/examplewindow.h
@@ -32,7 +32,7 @@ protected:
void on_show_desktop_toggled();
void on_show_enter_location_toggled();
void on_placessidebar_open_location(const Glib::RefPtr<Gio::File>& location, Gtk::PlacesOpenFlags
open_flags);
- void on_placessidebar_populate_popup(Gtk::Menu* menu, const Glib::RefPtr<Gio::File>& selected_item, const
Glib::RefPtr<Gio::Volume>& selected_volume);
+ void on_placessidebar_populate_popup(Gtk::Container* container, const Glib::RefPtr<Gio::File>&
selected_item, const Glib::RefPtr<Gio::Volume>& selected_volume);
int on_placessidebar_drag_action_requested(const Glib::RefPtr<Gdk::DragContext>& context, const
Glib::RefPtr<Gio::File>& dest_file, const std::vector< Glib::RefPtr<Gio::File> >& source_file_list);
void on_menu_properties_activate();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]