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