[seed] examples: Cleanup actions example
- From: Robert Carr <racarr src gnome org>
- To: svn-commits-list gnome org
- Subject: [seed] examples: Cleanup actions example
- Date: Fri, 29 May 2009 06:00:56 -0400 (EDT)
commit d75e22e723ce94f901295bd6edb54a65b9f9219e
Author: Robert Carr <racarr svn gnome org>
Date: Fri May 29 05:38:17 2009 -0400
examples: Cleanup actions example
---
examples/actions.js | 62 +++++++++++++++++++++-----------------------------
1 files changed, 26 insertions(+), 36 deletions(-)
diff --git a/examples/actions.js b/examples/actions.js
index 4b844db..a673ced 100755
--- a/examples/actions.js
+++ b/examples/actions.js
@@ -12,45 +12,35 @@ window.add(vbox);
var actions = new Gtk.ActionGroup({name: "toolbar"});
var accels = new Gtk.AccelGroup();
+function make_action(def){
+ var action = new Gtk.Action(def);
+ action.set_accel_group(accels);
+ actions.add_action_with_accel(action);
+ //Could pass string, but this makes it use default accelerator for STOCK_NEW
+ action.connect_accelerator();
+ action.signal.activate.connect(
+ function (){
+ print(def.tooltip);
+ });
+ return action;
+}
+
window.add_accel_group(accels);
-new_action = new Gtk.Action({name:"new", label: "New",
- tooltip:"New File",
- stock_id:Gtk.STOCK_NEW});
-new_action.set_accel_group(accels);
-actions.add_action_with_accel(new_action);
-//Could pass string, but this makes it use default accelerator for STOCK_NEW
-new_action.connect_accelerator();
-new_action.signal.activate.connect(
- function (){
- print("New file");
- });
-open_action = new Gtk.Action({name:"open", label: "Open",
+new_action = make_action({name:"new", label: "New",
+ tooltip:"New File",
+ stock_id:Gtk.STOCK_NEW});
+open_action = make_action({name:"open", label: "Open",
tooltip:"Open File",
stock_id:Gtk.STOCK_OPEN});
-open_action.set_accel_group(accels);
-actions.add_action_with_accel(open_action);
-open_action.connect_accelerator();
-open_action.signal.activate.connect(
- function (){
- print("Open file");
- });
-
-save_action = new Gtk.Action({name:"save", label: "Save",
- tooltip:"Save File",
- stock_id:Gtk.STOCK_SAVE});
-save_action.set_accel_group(accels);
-actions.add_action_with_accel(save_action);
-save_action.connect_accelerator();
-save_action.signal.activate.connect(
- function () {
- print("Save file");
- });
+save_action = make_action({name:"save", label: "Save",
+ tooltip:"Save File",
+ stock_id:Gtk.STOCK_SAVE});
-toolbar.insert(save_action.create_tool_item());
-toolbar.insert(open_action.create_tool_item());
-toolbar.insert(new_action.create_tool_item());
+[new_action, open_action, save_action].forEach(function(action){
+ toolbar.insert(action.create_tool_item());
+});
var menu = new Gtk.MenuBar();
var file = new Gtk.MenuItem({"child": new Gtk.Label({"label": "File"})});
@@ -58,9 +48,9 @@ file_menu = new Gtk.Menu();
file.submenu = file_menu;
menu.append(file);
-file_menu.append(new_action.create_menu_item(), -1);
-file_menu.append(open_action.create_menu_item(), -1);
-file_menu.append(save_action.create_menu_item(), -1);
+[new_action, open_action, save_action].forEach(function(action){
+ file_menu.append(action.create_menu_item(), -1);
+});
vbox.pack_start(menu);
vbox.pack_start(toolbar);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]