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(); child_0.init(_this);
54         this.el.add (  child_0.el  );
55         _this.LeftTreeMenu = new Xcls_LeftTreeMenu();
56                 _this.LeftTreeMenu.init();
57
58         // init method 
59          
60          
61     }
62  
63
64     // skip xvala_id - not pipe 
65     public class Xcls_button : Object 
66     {
67         public Gtk.Button el;
68         private Xcls_WindowLeftTree  _this;
69  
70             // ctor 
71         public void init(Xcls_WindowLeftTree _owner)
72         {
73                         
74                         this.el = new Gtk.Button.with_label ("Click me (0)");
75             _this = _owner;
76             _this.button = this;
77
78              
79
80             // listeners 
81             this.el.button_press_event.connect(   ( ev) => {
82                 //console.log("button press?");
83             
84                 
85  
86                   if (ev.type != Gdk.EventType.BUTTON_PRESS  || ev.button != 3) {
87                     //print("click" + ev.type);
88                     return false;
89                 }
90  
91                     
92                  //_this.LeftTreeMenu.el.set_screen(Gdk.Screen.get_default());
93                  
94                  _this.LeftTreeMenu.el.popup(null, null, null,  ev.button, ev.time);
95                         
96                                 //   print("click:" + res.path.to_string());
97                   return true;
98             } );
99             
100         }
101
102          
103     }
104
105
106
107         
108     public class Xcls_LeftTreeMenu : Object 
109     {
110         public Gtk.Menu el;
111         private Xcls_WindowLeftTree  _this;
112
113
114             // my vars
115
116             // ctor 
117         public void init(Xcls_WindowLeftTree _owner)
118         {
119                         
120                         print("Xcls_LeftTreeMenu:Ctor called\n");
121             _this = _owner;
122                  
123                         
124                         this.el = new Gtk.Menu();
125             _this.LeftTreeMenu = this;
126
127             // my vars
128
129             // set gobject values
130             var child_0 = new Xcls_MenuItem7();
131                         child_0.init(_this);
132                         this.el.append (  child_0.el  );
133                         
134             var child_1 = new Xcls_MenuItem8(_this);
135                         child_1.init(_this);
136             this.el.append (  child_1.el  );
137                         this.el.show_all();
138         }
139
140         
141     }
142     public class Xcls_MenuItem7 : Object 
143     {
144         public Gtk.MenuItem el;
145         private Xcls_WindowLeftTree  _this;
146
147
148             // my vars
149
150             // ctor 
151         
152                 public void init(Xcls_WindowLeftTree  _owner) {
153                         base();
154             _this = _owner;
155                  
156                         this.el = new Gtk.MenuItem.with_label("Delete Element");
157             // my vars
158
159             // set gobject values
160             //this.el.label = "Delete Element";
161                         
162             // listeners 
163
164                         print("add activate\n");
165             this.el.activate.connect(   ( ) => {
166                 
167                 print("SELECT?");
168                 
169                                 return  ;
170             } );
171         }
172  
173     }
174     public class Xcls_MenuItem8 : Object 
175     {
176         public Gtk.MenuItem el;
177         private Xcls_WindowLeftTree  _this;
178
179
180             // my vars
181
182             // ctor 
183         public Xcls_MenuItem8(Xcls_WindowLeftTree _owner)
184         {
185                         base();
186                         this.el = new Gtk.MenuItem();
187             _this = _owner;
188
189             // my vars
190
191             // set gobject values
192             this.el.label = "Save as Template";
193
194             // listeners 
195             this.el.activate.connect(   () => {
196             
197                 print("connect");  
198                 
199             } );
200         }
201
202          
203     }
204 }