[gnome-devel-docs] Vala dialog sample: update to use GtkApplicationWindow
- From: Tiffany Antopolski <antopolski src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-devel-docs] Vala dialog sample: update to use GtkApplicationWindow
- Date: Fri, 4 May 2012 00:47:30 +0000 (UTC)
commit 4f492558023f9f6b1eb52a49ba4524e1476a8deb
Author: Tiffany Antopolski <tiffany antopolski gmail com>
Date: Thu May 3 20:46:51 2012 -0400
Vala dialog sample: update to use GtkApplicationWindow
platform-demos/C/dialog.vala.page | 3 +-
platform-demos/C/samples/dialog.vala | 70 ++++++++++++++++++----------------
2 files changed, 38 insertions(+), 35 deletions(-)
---
diff --git a/platform-demos/C/dialog.vala.page b/platform-demos/C/dialog.vala.page
index 970f355..c3e2ba3 100644
--- a/platform-demos/C/dialog.vala.page
+++ b/platform-demos/C/dialog.vala.page
@@ -20,8 +20,7 @@
<p>A dialog with the response signal hooked up to a callback function.</p>
<code mime="text/x-vala" style="numbered">
-<xi:include href="samples/dialog.vala" parse="text"><xi:fallback/></xi:include>
-</code>
+<xi:include href="samples/dialog.vala" parse="text"><xi:fallback/></xi:include></code>
<p>
In this sample we used the following:
diff --git a/platform-demos/C/samples/dialog.vala b/platform-demos/C/samples/dialog.vala
index 6daca2a..11435d3 100644
--- a/platform-demos/C/samples/dialog.vala
+++ b/platform-demos/C/samples/dialog.vala
@@ -1,45 +1,49 @@
-//This is the application
-public class MyApplication : Gtk.Application {
- public MyApplication () {
- Object (application_id: "org.example.dialog");
- }
-
- void on_response (Gtk.Dialog dialog, int response_id) {
- /*To see the int value of the ResponseType*/
- print ("response is %d\n", response_id);
+public class MyWindow : Gtk.ApplicationWindow {
- dialog.destroy ();
- }
+ void on_response (Gtk.Dialog dialog, int response_id) {
+ /*To see the int value of the ResponseType*/
+ print ("response is %d\n", response_id);
+
+ dialog.destroy ();
+ }
void on_button_click (Gtk.Button button) {
- var window = button.get_toplevel () as Gtk.Window;
- var dialog = new Gtk.Dialog.with_buttons ("A Gtk+ Dialog", window,
- Gtk.DialogFlags.MODAL,
- Gtk.Stock.OK,
- Gtk.ResponseType.OK, null);
- var content_area = dialog.get_content_area ();
- var label = new Gtk.Label ("This demonstrates a dialog with a label");
-
- content_area.add (label);
- dialog.response.connect (on_response);
- dialog.show_all ();
+ var dialog = new Gtk.Dialog.with_buttons ("A Gtk+ Dialog", this,
+ Gtk.DialogFlags.MODAL,
+ Gtk.Stock.OK,
+ Gtk.ResponseType.OK, null);
+
+ var content_area = dialog.get_content_area ();
+ var label = new Gtk.Label ("This demonstrates a dialog with a label");
+
+ content_area.add (label);
+ dialog.response.connect (on_response);
+ dialog.show_all ();
}
- public override void activate () {
- var window = new Gtk.Window ();
- window.set_default_size (200, 50);
+ internal MyWindow (MyApplication app) {
+ Object (application: app, title: "GNOME Button");
- var button = new Gtk.Button.from_stock (Gtk.Stock.OK);
+ var button = new Gtk.Button.with_label ("Click Me");
button.clicked.connect (on_button_click);
- window.add (button);
+ button.show ();
+
+ this.window_position = Gtk.WindowPosition.CENTER;
+ this.set_default_size (250,50);
+ this.add (button);
+ }
+}
+
+public class MyApplication : Gtk.Application {
+ protected override void activate () {
+ new MyWindow (this).show ();
+ }
- this.add_window (window);
- window.show_all ();
+ internal MyApplication () {
+ Object (application_id: "org.example.MyApplication");
}
}
-//The main function creates the application and runs it.
-int main (string[] args) {
- var app = new MyApplication ();
- return app.run (args);
+public int main (string[] args) {
+ return new MyApplication ().run (args);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]