[gtkmm-documentation] Gtk::Application example: Minor cleanip.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtkmm-documentation] Gtk::Application example: Minor cleanip.
- Date: Thu, 23 Dec 2010 21:10:08 +0000 (UTC)
commit 76af8491c4c080a93d65b610eab07681a79a228f
Author: Murray Cumming <murrayc murrayc com>
Date: Thu Dec 23 22:07:51 2010 +0100
Gtk::Application example: Minor cleanip.
* examples/book/application/exampleapplication.[h|cc]:
* examples/book/application/examplewindow.cc:
* examples/book/application/main.cc:
Minor formatting changes and some extra comments.
on_open(): Call the base class's implementation, which is generally a good
idea.
ChangeLog | 17 +++++++++++++----
examples/book/application/exampleapplication.cc | 21 +++++++++++++++++----
examples/book/application/exampleapplication.h | 13 ++++++++-----
examples/book/application/examplewindow.cc | 14 +++++++-------
examples/book/application/main.cc | 12 +++++++-----
5 files changed, 52 insertions(+), 25 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index de03250..cedae5b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
2010-12-23 Murray Cumming <murrayc murrayc com>
+ Gtk::Application example: Minor cleanip.
+
+ * examples/book/application/exampleapplication.[h|cc]:
+ * examples/book/application/examplewindow.cc:
+ * examples/book/application/main.cc:
+ Minor formatting changes and some extra comments.
+ on_open(): Call the base class's implementation, which is generally a good
+ idea.
+
+2010-12-23 Murray Cumming <murrayc murrayc com>
+
Fix the build with --enable-warnings=fatal.
* configure.ac: Use -no-long-long to avoid an (apparently new) compiler
@@ -10,11 +21,9 @@
Add Gtk::Application example
- * examples/book/application/exampleapplication.cc: new
- * examples/book/application/examplewindow.cc: new
+ * examples/book/application/exampleapplication.[h|cc]: new
+ * examples/book/application/examplewindow.[h|cc]: new
* examples/book/application/main.cc: new
- * examples/book/application/exampleapplication.h: new
- * examples/book/application/examplewindow.h: new
* examples/Makefile.am: Adapted.
2010-12-23 Chris Kühl <chrisk openismus com>
diff --git a/examples/book/application/exampleapplication.cc b/examples/book/application/exampleapplication.cc
index bc24e3f..d0ac30c 100644
--- a/examples/book/application/exampleapplication.cc
+++ b/examples/book/application/exampleapplication.cc
@@ -16,18 +16,23 @@
#include "exampleapplication.h"
#include "examplewindow.h"
+#include <iostream>
ExampleApplication::ExampleApplication(const Glib::ustring& appid, Gio::ApplicationFlags flags)
: Gtk::Application(appid, flags)
{
}
-void ExampleApplication::new_window(const Glib::RefPtr<Gio::File>& file)
+void ExampleApplication::create_window(const Glib::RefPtr<Gio::File>& file)
{
Gtk::Window* window = new ExampleWindow(file);
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();
}
@@ -38,14 +43,22 @@ void ExampleApplication::on_window_hide(Gtk::Window* window)
void ExampleApplication::on_activate()
{
- new_window(Glib::RefPtr<Gio::File>());
+ // 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_open(const Gio::Application::type_vec_files& files,
const Glib::ustring& hint)
{
- for (unsigned int i = 0; i < files.size(); i++)
+ // The application has been asked to open some files,
+ // so let's open a new window for each one.
+ std::cout << "debug: files.size()=" << files.size() << std::endl;
+ for(guint i = 0; i < files.size(); i++)
{
- new_window(files[i]);
+ create_window(files[i]);
}
+
+ Application::on_open(files, hint);
}
diff --git a/examples/book/application/exampleapplication.h b/examples/book/application/exampleapplication.h
index 115f10a..3841c86 100644
--- a/examples/book/application/exampleapplication.h
+++ b/examples/book/application/exampleapplication.h
@@ -22,15 +22,18 @@
class ExampleApplication: public Gtk::Application
{
public:
- explicit ExampleApplication(const Glib::ustring& appid, Gio::ApplicationFlags flags =
- Gio::APPLICATION_FLAGS_NONE);
- void new_window(const Glib::RefPtr<Gio::File>& file);
+ explicit ExampleApplication(const Glib::ustring& appid,
+ Gio::ApplicationFlags flags = Gio::APPLICATION_FLAGS_NONE);
protected:
- void on_activate();
- void on_open(const Gio::Application::type_vec_files& files,
+ //Overrides of default signal handlers:
+ virtual void on_activate();
+ virtual void on_open(const Gio::Application::type_vec_files& files,
const Glib::ustring& hint);
+private:
+ void create_window(const Glib::RefPtr<Gio::File>& file = Glib::RefPtr<Gio::File>());
+
void on_window_hide(Gtk::Window* window);
};
diff --git a/examples/book/application/examplewindow.cc b/examples/book/application/examplewindow.cc
index b2f6443..01d81c1 100644
--- a/examples/book/application/examplewindow.cc
+++ b/examples/book/application/examplewindow.cc
@@ -25,7 +25,7 @@ ExampleWindow::ExampleWindow(const Glib::RefPtr<Gio::File>& file)
add(scrolled);
scrolled.add(view);
- if (!file)
+ if(!file)
return;
try
@@ -33,21 +33,21 @@ ExampleWindow::ExampleWindow(const Glib::RefPtr<Gio::File>& file)
char* contents = 0;
gsize length = 0;
- if (file->load_contents(contents, length))
+ if(file->load_contents(contents, length))
{
if(contents && length)
{
const Glib::ustring text(contents);
- Glib::RefPtr<Gtk::TextBuffer> buffer;
- buffer = view.get_buffer();
+ Glib::RefPtr<Gtk::TextBuffer> buffer = view.get_buffer();
buffer->set_text(text);
}
g_free(contents);
}
- } catch (const Glib::Error& e)
+ }
+ catch (const Glib::Error& ex)
{
- std::cerr << e.what() << std::endl;
- };
+ std::cerr << ex.what() << std::endl;
+ }
show_all_children();
}
diff --git a/examples/book/application/main.cc b/examples/book/application/main.cc
index fbd3d57..afa0fab 100644
--- a/examples/book/application/main.cc
+++ b/examples/book/application/main.cc
@@ -19,19 +19,21 @@
#include "exampleapplication.h"
-void open(const Gio::Application::type_vec_files &files, const Glib::ustring& hint)
+void on_open(const Gio::Application::type_vec_files& /* files */,
+ const Glib::ustring& /* hint */)
{
- std::cout << "signal open received" << std::endl;
+ std::cout << "open signal received" << std::endl;
}
int main(int argc, char *argv[])
{
Gtk::Main kit(argc, argv);
- ExampleApplication application("org.gtkmm.Test.bloatpad",
+ ExampleApplication application(
+ "org.gtkmm.examples.application",
Gio::APPLICATION_HANDLES_OPEN);
- application.signal_open().connect(sigc::ptr_fun(open));
- int status = application.run(argc, argv);
+ application.signal_open().connect( sigc::ptr_fun(on_open) );
+ const int status = application.run(argc, argv);
return status;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]