[gtkmm-documentation] Application examples: Add an AppMenu example.



commit 87bbeb4cbea30beb7f7ed9f9c3afbb280855cc87
Author: Murray Cumming <murrayc murrayc com>
Date:   Thu Mar 22 21:27:41 2012 +0100

    Application examples: Add an AppMenu example.
    
    	* examples/Makefile.am:
    	* examples/book/application/app_menu/: This is based on the simple
    	example, without the document handling, and is meant to show the
    	use of set_app_menu(), using Gio::Menu, Gio::SimpleAction, and the
    	base Gio::ActionMap API.
    	However, I just get lots of these errors:
    	GLib-GIO-CRITICAL **: g_dbus_connection_register_object: assertion `G_IS_DBUS_CONNECTION (connection)' failed

 ChangeLog                                          |   12 +++
 examples/Makefile.am                               |    8 ++
 .../application/app_menu/exampleapplication.cc     |   72 ++++++++++++++++++++
 .../book/application/app_menu/exampleapplication.h |   44 ++++++++++++
 .../book/application/app_menu/examplewindow.cc     |   24 +++++++
 examples/book/application/app_menu/examplewindow.h |   31 +++++++++
 examples/book/application/app_menu/main.cc         |   33 +++++++++
 7 files changed, 224 insertions(+), 0 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index df636da..2f09139 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2012-03-22  Murray Cumming  <murrayc murrayc com>
+
+	Application examples: Add an AppMenu example.
+
+	* examples/Makefile.am:
+	* examples/book/application/app_menu/: This is based on the simple
+	example, without the document handling, and is meant to show the 
+	use of set_app_menu(), using Gio::Menu, Gio::SimpleAction, and the
+	base Gio::ActionMap API.
+	However, I just get lots of these errors:
+	GLib-GIO-CRITICAL **: g_dbus_connection_register_object: assertion `G_IS_DBUS_CONNECTION (connection)' failed
+
 3.3.18:
 
 2012-03-03  Murray Cumming  <murrayc murrayc com>
diff --git a/examples/Makefile.am b/examples/Makefile.am
index f556144..d82731a 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -10,6 +10,7 @@ check_PROGRAMS =					\
 	book/alignment/example				\
 	book/application/simple/example \
 	book/application/command_line_handling/example \
+	book/application/app_menu/example \
 	book/aspectframe/example			\
 	book/assistant/example				\
 	book/base/base					\
@@ -150,6 +151,13 @@ book_application_command_line_handling_example_SOURCES =		\
 	book/application/command_line_handling/examplewindow.h	\
 	book/application/command_line_handling/main.cc
 
+book_application_app_menu_example_SOURCES =		\
+	book/application/app_menu/exampleapplication.cc	\
+	book/application/app_menu/exampleapplication.h	\
+	book/application/app_menu/examplewindow.cc	\
+	book/application/app_menu/examplewindow.h	\
+	book/application/app_menu/main.cc
+
 book_alignment_example_SOURCES =		\
 	book/alignment/examplewindow.cc		\
 	book/alignment/examplewindow.h		\
diff --git a/examples/book/application/app_menu/exampleapplication.cc b/examples/book/application/app_menu/exampleapplication.cc
new file mode 100644
index 0000000..851ed2d
--- /dev/null
+++ b/examples/book/application/app_menu/exampleapplication.cc
@@ -0,0 +1,72 @@
+/* gtkmm example Copyright (C) 2002 gtkmm development team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "exampleapplication.h"
+#include "examplewindow.h"
+#include <iostream>
+
+ExampleApplication::ExampleApplication()
+: Gtk::Application("org.gtkmm.examples.application")
+{
+  m_action = Gio::SimpleAction::create("app.something");
+  m_action->signal_activate().connect(
+    sigc::mem_fun(*this, &ExampleApplication::on_action_something) );
+  add_action(m_action);
+
+  m_menu = Gio::Menu::create();
+  m_menu->append("Something", "app.something");
+
+  set_app_menu(m_menu);
+}
+
+Glib::RefPtr<ExampleApplication> ExampleApplication::create()
+{
+  return Glib::RefPtr<ExampleApplication>( new ExampleApplication() );
+}
+
+void ExampleApplication::create_window()
+{
+  ExampleWindow* window = new ExampleWindow();
+
+  //Make sure that the application runs for as long this window is still open:
+  add_window(*window);
+
+  //Delete the window when it is hidden.
+  //That's enough for this simple example.
+  window->signal_hide().connect(sigc::bind<Gtk::Window*>(sigc::mem_fun(*this,
+    &ExampleApplication::on_window_hide), window));
+
+  window->show();
+}
+
+void ExampleApplication::on_window_hide(Gtk::Window* window)
+{
+  delete window;
+}
+
+void ExampleApplication::on_activate()
+{
+  //std::cout << "debug1: " << G_STRFUNC << std::endl;
+  // The application has been started, so let's show a window.
+  // A real application might want to reuse this "empty" window in on_open(),
+  // when asked to open a file, if no changes have been made yet.
+  create_window();
+}
+
+void ExampleApplication::on_action_something(const Glib::VariantBase& /* parameter */)
+{
+  std::cout << G_STRFUNC << std::endl;
+}
diff --git a/examples/book/application/app_menu/exampleapplication.h b/examples/book/application/app_menu/exampleapplication.h
new file mode 100644
index 0000000..fbeb7b8
--- /dev/null
+++ b/examples/book/application/app_menu/exampleapplication.h
@@ -0,0 +1,44 @@
+/* gtkmm example Copyright (C) 2002 gtkmm development team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef GTKMM_EXAMPLEAPPLICATION_H
+#define GTKMM_EXAMPLEAPPLICATION_H
+
+#include <gtkmm.h>
+
+class ExampleApplication: public Gtk::Application
+{
+protected:
+  ExampleApplication();
+
+public:
+  static Glib::RefPtr<ExampleApplication> create();
+    
+protected:
+  //Overrides of default signal handlers:
+  virtual void on_activate();
+
+private:
+  void create_window();
+
+  void on_window_hide(Gtk::Window* window);
+  void on_action_something(const Glib::VariantBase& parameter);
+
+  Glib::RefPtr<Gio::Menu> m_menu;
+  Glib::RefPtr<Gio::SimpleAction> m_action;
+};
+
+#endif /* GTKMM_EXAMPLEAPPLICATION_H */
diff --git a/examples/book/application/app_menu/examplewindow.cc b/examples/book/application/app_menu/examplewindow.cc
new file mode 100644
index 0000000..4c2caeb
--- /dev/null
+++ b/examples/book/application/app_menu/examplewindow.cc
@@ -0,0 +1,24 @@
+/* gtkmm example Copyright (C) 2002 gtkmm development team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <iostream>
+
+#include "examplewindow.h"
+
+ExampleWindow::ExampleWindow()
+{
+  set_title("Gio::Application example");
+}
diff --git a/examples/book/application/app_menu/examplewindow.h b/examples/book/application/app_menu/examplewindow.h
new file mode 100644
index 0000000..52be41a
--- /dev/null
+++ b/examples/book/application/app_menu/examplewindow.h
@@ -0,0 +1,31 @@
+/* gtkmm example Copyright (C) 2002 gtkmm development team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef GTKMM_EXAMPLEWINDOW_H_
+#define GTKMM_EXAMPLEWINDOW_H_
+
+#include <gtkmm.h>
+
+class ExampleWindow: public Gtk::ApplicationWindow
+{
+public:
+
+  explicit ExampleWindow();
+  
+private:
+};
+
+#endif /* GTKMM_EXAMPLEWINDOW_H */
diff --git a/examples/book/application/app_menu/main.cc b/examples/book/application/app_menu/main.cc
new file mode 100644
index 0000000..21f253b
--- /dev/null
+++ b/examples/book/application/app_menu/main.cc
@@ -0,0 +1,33 @@
+/* gtkmm example Copyright (C) 2010 gtkmm development team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <gtkmm.h>
+#include <iostream>
+
+#include "exampleapplication.h"
+
+int main(int argc, char *argv[])
+{
+  Glib::RefPtr<ExampleApplication> application = 
+    ExampleApplication::create();
+
+  // Start the application, showing the initial window, 
+  // and opening extra windows for any files that it is asked to open,
+  // for instance as a command-line parameter.
+  // run() will return when the last window has been closed by the user.
+  const int status = application->run(argc, argv);
+  return status;
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]