src/Builder4/MainWindow.vala
[app.Builder.js] / src / Builder4 / MainWindow.vala
index 1ae1444..83382ef 100644 (file)
@@ -106,6 +106,26 @@ public class Xcls_MainWindow : Object
             Resources.singleton().checkResources();
         
         });
+        this.el.key_release_event.connect( (event) => {
+            
+            if (this.search_entry.el.is_visible()) {
+                       if (event.keyval == Gdk.Key.f && (event.state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
+                           print("SAVE: ctrl-f  pressed");
+                               this.search_entry.el.grab_focus();
+                           return false;
+                       }
+                       
+                         if (event.keyval == Gdk.Key.g && (event.state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
+                           print("SAVE: ctrl-g  pressed");
+                               this.search_entry.forwardSearch(true);
+                           return false;
+                       }
+               }    
+           // print(event.key.keyval)
+            
+            return false;
+        
+        });
     }
 
     // user defined functions
@@ -2302,7 +2322,7 @@ public class Xcls_MainWindow : Object
 
     public class Xcls_search_entry : Object
     {
-        public Gtk.Entry el;
+        public Gtk.SearchEntry el;
         private Xcls_MainWindow  _this;
 
 
@@ -2313,7 +2333,7 @@ public class Xcls_MainWindow : Object
         {
             _this = _owner;
             _this.search_entry = this;
-            this.el = new Gtk.Entry();
+            this.el = new Gtk.SearchEntry();
 
             // my vars (dec)
 
@@ -2326,15 +2346,71 @@ public class Xcls_MainWindow : Object
                 this.el.override_font(description);
 
             //listeners
+            this.el.key_press_event.connect( (event) => {
+                
+               if (event.keyval == Gdk.Key.Return) {
+                       this.forwardSearch(false);
+                   return true;
+            
+               }    
+               // print(event.key.keyval)
+                
+                return false;
+            
+            });
             this.el.changed.connect( () => {
-               if (this.el.text != "") {
+               if (this.el.text == "") {
+                       return;
+               }
+               var res = 0;
+               switch(_this.windowstate.state) {
+                       case WindowState.State.CODEONLY:
+                       case WindowState.State.CODE:
+                               // search the code being edited..
+                               res = _this.windowstate.code_editor.search(this.el.text);
+                               
+                               break;
+                       case WindowState.State.PREVIEW:
+                               if (_this.windowstate.file.xtype == "Gtk") {
+                                        res = _this.windowstate.window_gladeview.search(this.el.text);
+                               } else { 
+                                        res = _this.windowstate.window_rooview.search(this.el.text);                   
+                               }
                        
-               
+                       
+                               break;
+               }
+               if (res > 0) {
+                       _this.search_results.el.label = "%d Matches".printf(res);
+               } else {
+                       _this.search_results.el.label = "No Matches";
                }
+                       
+               
+               
             });
         }
 
         // user defined functions
+        public void forwardSearch (bool change_focus) {
+               switch(_this.windowstate.state) {
+                       case WindowState.State.CODEONLY:
+                       case WindowState.State.CODE:
+                               // search the code being edited..
+                               _this.windowstate.code_editor.forwardSearch(change_focus);
+                               
+                               break;
+                       case WindowState.State.PREVIEW:
+                               if (_this.windowstate.file.xtype == "Gtk") {
+                                       _this.windowstate.window_gladeview.forwardSearch(change_focus);
+                               } else { 
+                                        _this.windowstate.window_rooview.forwardSearch(change_focus);
+                               }
+                       
+                               break;
+               }
+               
+        }
     }
 
     public class Xcls_MenuBar70 : Object