Merge branch 'master' of http://git.roojs.com/roobuilder
[roobuilder] / src / Application.vala
index 9eb45bd..340a70d 100644 (file)
@@ -1,5 +1,5 @@
 
+ /*
        public class AppSettings : Object
        {
 
@@ -46,7 +46,7 @@
 
                
        }
-       
+       */
        
        public static BuilderApplication application = null;
        
                    { "application/x-rootwindow-drop", 0, Target.ROOTWIN }
                };
                */
-               public AppSettings settings = null;
+               //public AppSettings settings = null;
 
 
 
                                flags: ApplicationFlags.FLAGS_NONE
                        );
                        BuilderApplication.windows = new        Gee.ArrayList<Xcls_MainWindow>();
+                       BuilderApplication.windowlist = new GLib.ListStore(typeof(WindowState));
                        //BuilderApplication.valacompilequeue = new Palete.ValaCompileQueue();
                        
                        
                        configDirectory();
-                       this.settings = AppSettings.factory();  
+               //      this.settings = AppSettings.factory();  
                        var opt_context = new OptionContext ("Application Builder");
                        
                        try {
 
                }
 
+               public static Settings settings;
 
+               protected override void activate () 
+               {
+                       var css = new Gtk.CssProvider();
+                       css.load_from_resource("/css/roobuilder.css");
+                       
+                       Gtk.StyleContext.add_provider_for_display(
+                               Gdk.Display.get_default(),
+                               css     ,
+                               Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
+                       );
+                       BuilderApplication.settings = new Settings();
+               
+                       var w = new Xcls_MainWindow();
+                   w.initChildren();
+                       BuilderApplication.addWindow(w);
+                       
+                       // it looks like showall after children causes segfault on ubuntu 14.4
+                       w.windowstate.init();
+               //      w.windowstate.showPopoverFiles(w.open_projects_btn.el, null, false);
+                       w.show();
+               
+               }
                
                public static BuilderApplication  singleton(  string[]? args)
                {
                                                var oldfn = file.targetName();
                                                
                                                print("\n\n\n\nFile : %s\n", oldfn);
-                                               //GLib.FileUtils.get_contents(oldfn, out oldstr);
+                                               
                                                                                
                                                var outstr = file.toSourceCode();
+                                               
+                                               /* line number checking
                                                var bad = false;
                                                // check line numbers:
                                                var bits = outstr.split("\n");
                                                var end = bits.length;
                                                for(var i = 0;i < end; i++) {
                                                        print("%i : %s\n", i+1 , bits[i]);
-                                                       if (!bad && bits[i].has_prefix("/*") && !bits[i].has_prefix("/*%d*/".printf(i+1))) {
+                                                       if (!bad && bits[i].has_prefix("/*") && !bits[i].has_prefix(("/*%d*" +"/").printf(i+1))) {
                                                                end = i + 5 > bits.length ? bits.length: (i + 5);
                                                                print ("^^^^ mismatch\null");
                                                                bad = true;
                                                if (bad) {
                                                        GLib.error("got bad file");
                                                }
-                                               /*
+                                               */
+                                               // compare files. 
+                                               string oldstr;
+                                               GLib.FileUtils.get_contents(oldfn, out oldstr);
                                                if (outstr != oldstr) { 
                                                        
                                                        GLib.FileUtils.set_contents("/tmp/" + file.name   + ".out",   outstr);
                                                        print("meld   %s /tmp/%s\n", oldfn,  file.name + ".out");
                                                        //GLib.Process.exit(Posix.EXIT_SUCCESS);                
-                                               }
-*.*                                            */
+                                               }                                               
                                                //print("# Files match %s\n", file.name);
                                        }               
                                } catch (FileError e) {
                        if (ls == null) {
                                GLib.error("No langauge server returned for file:%s", file.relpath);
                        }
+                       
+                       //GLib.debug("started server - sleep 30 secs so you can gdb attach");
+                       //Posix.sleep( 30 );
                        var loop = new MainLoop();
                        GLib.Timeout.add_seconds(1, () => {
-                               if (!ls.isReady()) {
-                                       GLib.debug("waiting for server to be ready");
-                                       return true;
-                               }
+                        
                                GLib.debug("Sending document_open");
                                // it's ready..
                                 
                                ls.document_open(file);
+                               ls.document_save.begin( file, (o,res) => {
+                                       ls.document_save.end(res);
+                                });
+                               
+                               //ls.syntax.begin(file, (obj,res) => {
+                               //      ls.syntax.end(res);
+                               
+                               //});
                                
-                               ls.syntax.begin(file, (obj,res) => {
-                                       ls.syntax.end(res);
                                
-                               });
                                return false;
                                
                        });
@@ -618,12 +651,14 @@ flutter-project  -  was try and read flutter data (but desnt work.)
                
                // move to 'window colletction?
                public static Gee.ArrayList<Xcls_MainWindow> windows;
+               public static GLib.ListStore windowlist;
                
                public static void addWindow(Xcls_MainWindow w)
                {
                         
+               windowlist.append(w.windowstate);
                        BuilderApplication.windows.add(w);
-                       BuilderApplication.updateWindows();
+
   
                        
                }
@@ -632,7 +667,15 @@ flutter-project  -  was try and read flutter data (but desnt work.)
                {
                        //GLib.debug("remove window before = %d", BuilderApplication.windows.size);
                        BuilderApplication.windows.remove(w);
-                       BuilderApplication.updateWindows();
+                       for(var i = 0 ; i < windowlist.get_n_items(); i++) {
+                               var ws = windowlist.get_item(i) as WindowState;
+                               if (ws.file.path == w.windowstate.file.path && ws.project.path == w.windowstate.project.path) {
+                                       windowlist.remove(i);
+                                       break;
+                               }
+                       }
+                       
+
                                
                        w.el.hide();
                        w.el.close();
@@ -641,12 +684,7 @@ flutter-project  -  was try and read flutter data (but desnt work.)
                        
                        
                }
-               public static void updateWindows()
-               {
-                       foreach(var ww in BuilderApplication.windows) {
-                               ww.windowbtn.updateMenu();
-                       }
-               }
+        
                public static Xcls_MainWindow? getWindow(JsRender.JsRender file)
                {
                        foreach(var ww in BuilderApplication.windows) {
@@ -662,8 +700,9 @@ flutter-project  -  was try and read flutter data (but desnt work.)
                {
                    var w = new Xcls_MainWindow();
                        w.ref();
-                       BuilderApplication.addWindow(w);
                        w.initChildren();
+                       BuilderApplication.addWindow(w);
+                       w.windowstate.init();
                        w.windowstate.fileViewOpen(file, false, line);
                        w.el.present();
                         
@@ -675,9 +714,9 @@ flutter-project  -  was try and read flutter data (but desnt work.)
                
                public static void updateCompileResults( )
                {
-                       queue_update_compile_countdown = 4; // 1 second after last call.
+                       queue_update_compile_countdown = 2; // 1 second after last call.
                        if (queue_update_compile_id == 0) {
-                               queue_update_compile_id = GLib.Timeout.add(250, () => {
+                               queue_update_compile_id = GLib.Timeout.add(100, () => {
                                        if (queue_update_compile_countdown < 0) {
                                                return true;
                                        }
@@ -701,12 +740,14 @@ flutter-project  -  was try and read flutter data (but desnt work.)
                                if (ww == null || ww.windowstate == null || ww.windowstate.project ==null) {
                                        continue;
                                }
+                               
 
                                ww.windowstate.updateErrorMarksAll();
                                 
-                               GLib.debug("calling udate Errors of window %s", ww.windowstate.file.targetName());
+                               //GLib.debug("calling udate Errors of window %s", ww.windowstate.file.targetName());
                                ww.updateErrors();
-                               
+                               ww.windowstate.left_tree.updateErrors();
+                               ww.windowstate.left_props.updateErrors();
                                
                        }
                
@@ -727,6 +768,10 @@ flutter-project  -  was try and read flutter data (but desnt work.)
                                                BuilderApplication.showSpinner( "format-justify-fill", msg);                                    
                                                return;
 
+                                       case Palete.LanguageClientAction.DIAG_END:
+                                               BuilderApplication.showSpinner( "", "");
+                                               return;
+
                                        case Palete.LanguageClientAction.OPEN:
                                                BuilderApplication.showSpinner( "document-open", msg);                                  
                                                return;
@@ -794,5 +839,4 @@ flutter-project  -  was try and read flutter data (but desnt work.)
                
 
  
-