tests/menu.vala
[app.Builder.js] / tests / menu.vala
1 /* -- to compile
2 valac  --pkg gio-2.0  --pkg posix  --pkg gtk+-3.0  \
3     menu.vala  -o /tmp/menutest
4 */
5
6
7 /* -- to test class
8 static int main (string[] args) {
9     Gtk.init (ref args);
10     new Xcls_WindowLeftTree();
11     WindowLeftTree.show_all();
12      Gtk.main ();
13     return 0;
14 }
15 */
16         
17 int main (string[] args) {
18     Gtk.init (ref args);
19     
20         GLib.Log.set_always_fatal(LogLevelFlags.LEVEL_ERROR | LogLevelFlags.LEVEL_CRITICAL); 
21         
22         var a  = new Xcls_WindowLeftTree();
23         a.el.show_all();
24         
25         Gtk.main();
26
27     
28         
29         return 0;
30 }
31
32 public static Xcls_WindowLeftTree  WindowLeftTree;
33
34 public class Xcls_WindowLeftTree : Object 
35 {
36     public Gtk.Window el;
37     private Xcls_WindowLeftTree  _this;
38         public Xcls_button button;
39     public Xcls_LeftTreeMenu LeftTreeMenu;
40
41         // ctor 
42     public void init()
43     {
44                 base();
45                 this.el = new Gtk.Window(  );
46         _this = this;
47         WindowLeftTree = this;
48
49         // my vars
50
51         // set gobject values
52         
53         var child_0 = new Xcls_button(_this);
54         this.el.add (  child_0.el  );
55         _this.LeftTreeMenu = new Xcls_LeftTreeMenu(_this);
56
57         // init method 
58          
59          
60     }
61  
62
63     // skip xvala_id - not pipe 
64     public class Xcls_button : Object 
65     {
66         public Gtk.Button el;
67         private Xcls_WindowLeftTree  _this;
68  
69             // ctor 
70         public void init(Xcls_WindowLeftTree _owner)
71         {
72                         base();
73                         this.el = new Gtk.Button.with_label ("Click me (0)");
74             _this = _owner;
75             _this.button = this;
76
77              
78
79             // listeners 
80             this.el.button_press_event.connect(   ( ev) => {
81                 //console.log("button press?");
82             
83                 
84  
85                   if (ev.type != Gdk.EventType.BUTTON_PRESS  || ev.button != 3) {
86                     //print("click" + ev.type);
87                     return false;
88                 }
89  
90                     
91                  //_this.LeftTreeMenu.el.set_screen(Gdk.Screen.get_default());
92                  
93                  _this.LeftTreeMenu.el.popup(null, null, null,  ev.button, ev.time);
94                         
95                                 //   print("click:" + res.path.to_string());
96                   return true;
97             } );
98             
99         }
100
101          
102     }
103
104
105
106         
107     public class Xcls_LeftTreeMenu : Object 
108     {
109         public Gtk.Menu el;
110         private Xcls_WindowLeftTree  _this;
111
112
113             // my vars
114
115             // ctor 
116         public void init(Xcls_WindowLeftTree _owner)
117         {
118                         base();
119                         print("Xcls_LeftTreeMenu:Ctor called\n");
120             _this = _owner;
121                  
122                         
123                         this.el = new Gtk.Menu();
124             _this.LeftTreeMenu = this;
125
126             // my vars
127
128             // set gobject values
129             var child_0 = new Xcls_MenuItem7(_this);
130                         child_0.initListeners();
131                         this.el.append (  child_0.el  );
132                         
133             var child_1 = new Xcls_MenuItem8(_this);
134             this.el.append (  child_1.el  );
135                         this.el.show_all();
136         }
137
138         
139     }
140     public class Xcls_MenuItem7 : Object 
141     {
142         public Gtk.MenuItem el;
143         private Xcls_WindowLeftTree  _this;
144
145
146             // my vars
147
148             // ctor 
149         
150                 public void init(Xcls_WindowLeftTree  _owner) {
151                         base();
152             _this = _owner;
153                  
154                         this.el = new Gtk.MenuItem.with_label("Delete Element");
155             // my vars
156
157             // set gobject values
158             //this.el.label = "Delete Element";
159                         
160             // listeners 
161
162                         print("add activate\n");
163             this.el.activate.connect(   ( ) => {
164                 
165                 print("SELECT?");
166                 
167                                 return  ;
168             } );
169         }
170  
171     }
172     public class Xcls_MenuItem8 : Object 
173     {
174         public Gtk.MenuItem el;
175         private Xcls_WindowLeftTree  _this;
176
177
178             // my vars
179
180             // ctor 
181         public Xcls_MenuItem8(Xcls_WindowLeftTree _owner)
182         {
183                         base();
184                         this.el = new Gtk.MenuItem();
185             _this = _owner;
186
187             // my vars
188
189             // set gobject values
190             this.el.label = "Save as Template";
191
192             // listeners 
193             this.el.activate.connect(   () => {
194             
195                 print("connect");  
196                 
197             } );
198         }
199
200          
201     }
202 }