Author: miguel
Date: 2008-01-02 18:21:24 -0500 (Wed, 02 Jan 2008)
New Revision: 92138

Modified:
   trunk/mono-tools/gui-compare/ChangeLog
   trunk/mono-tools/gui-compare/Config.cs
   trunk/mono-tools/gui-compare/InfoManager.cs
   trunk/mono-tools/gui-compare/MainWindow.cs
Log:
* MainWindow.cs: Load defauls from the configuration file
* InfoManager.cs: Track recently used comparisons
* Config.cs: Add new API to manage our recently used list

Modified: trunk/mono-tools/gui-compare/ChangeLog
===================================================================
--- trunk/mono-tools/gui-compare/ChangeLog      2008-01-02 23:08:52 UTC (rev 
92137)
+++ trunk/mono-tools/gui-compare/ChangeLog      2008-01-02 23:21:24 UTC (rev 
92138)
@@ -1,5 +1,11 @@
 2008-01-02  Miguel de Icaza <[EMAIL PROTECTED]> 
 
+       * MainWindow.cs: Load defauls from the configuration file
+       * InfoManager.cs: Track recently used comparisons
+       * Config.cs: Add new API to manage our recently used list
+
+2008-01-02  Miguel de Icaza <[EMAIL PROTECTED]> 
+
        
 
 2008-01-02  Miguel de Icaza <[EMAIL PROTECTED]> 

Modified: trunk/mono-tools/gui-compare/Config.cs
===================================================================
--- trunk/mono-tools/gui-compare/Config.cs      2008-01-02 23:08:52 UTC (rev 
92137)
+++ trunk/mono-tools/gui-compare/Config.cs      2008-01-02 23:21:24 UTC (rev 
92138)
@@ -91,17 +91,35 @@
                        } catch {}
                        
                        try {
+                               File.Delete (settings_file);
+                       } catch {}
+                       
+                       try {
                                using (FileStream fs = File.Create 
(settings_file)){
                                        serializer.Serialize (fs, this);
                                }
-                       } catch {
+                       } catch  (Exception e){
+                               Console.WriteLine ("Saving {0}", e);
                        }
                }
                
+               public void MoveToTop (CompareDefinition cd)
+               {
+                       CompareDefinition [] copy = new CompareDefinition 
[Recent.Length];
+                       copy [0] = cd;
+                       for (int i = 0, j = 0; j < Recent.Length; j++){
+                               if (Recent [j] == cd)
+                                       continue;
+                               i++;
+                               copy [i] = Recent [j];
+                       }
+                       Recent = copy;
+               }
+                       
                public void AddRecent (CompareDefinition cd)
                {
                        if (Recent == null || Recent.Length < 15){
-                               CompareDefinition [] copy = new 
CompareDefinition [Recent.Length+1];
+                               CompareDefinition [] copy = new 
CompareDefinition [Recent == null ? 1 : Recent.Length+1];
                                copy [0] = cd;
                                if (Recent != null)
                                        Recent.CopyTo (copy, 1);

Modified: trunk/mono-tools/gui-compare/InfoManager.cs
===================================================================
--- trunk/mono-tools/gui-compare/InfoManager.cs 2008-01-02 23:08:52 UTC (rev 
92137)
+++ trunk/mono-tools/gui-compare/InfoManager.cs 2008-01-02 23:21:24 UTC (rev 
92138)
@@ -45,6 +45,9 @@
                // A handle to our container window
                MainWindow main;
                
+               // The handle to the Recent Comparisons Menu
+               Menu recentmenu;
+               
                string [] api_1_1 = {
                        "mscorlib",
                        "System",
@@ -326,6 +329,10 @@
                void StartPresetCompare (string assemblyfile, string profile, 
string assemblyname)
                {
                        Ensure (profile, assemblyname, delegate (string 
masterinfo){
+                               main.Config.AddRecent (new CompareDefinition 
(true, masterinfo, false, assemblyfile));
+                               PopulateRecent ();
+                               main.Config.Save ();
+                               
                                main.SetReference (delegate {
                                        Console.WriteLine ("Doing it for the 
{0}-{1}-{2}", assemblyfile, profile, assemblyname);
                                                return new MasterAssembly 
(masterinfo);
@@ -375,6 +382,50 @@
                        container.Add (item);
                }
                
+               /// <summary>
+               ///   Populates the "RecentComparison" sub menu from File
+               /// </summary>
+               public void PopulateRecent ()
+               {
+                       foreach (MenuItem mi in recentmenu.AllChildren)
+                               recentmenu.Remove (mi);
+                       
+                       if (main.Config.Recent == null || 
main.Config.Recent.Length == 0){
+                               MenuItem empty = new MenuItem ("(Empty)");
+                               empty.Sensitive = false;
+                               recentmenu.Add (empty);                         
+                       } else {
+                               foreach (CompareDefinition cdd in 
main.Config.Recent){
+                                       CompareDefinition cd = cdd;
+                                       if (cd == null)
+                                               throw new Exception ("FGGG");
+                                       string title = String.Format ("{0} -> 
{1}",
+                                                                     
Path.GetFileName (cd.ReferencePath),
+                                                                     
Path.GetFileName (cd.TargetPath));
+                                       MenuItem c = new MenuItem (title);
+                                       c.Activated += delegate {
+                                               if (cd.ReferenceIsInfo)
+                                                       main.SetReference 
(delegate { return new MasterAssembly (cd.ReferencePath); });
+                                               else
+                                                       main.SetReference 
(delegate { return new CecilAssembly (cd.ReferencePath); });
+                                               
+                                               if (cd.TargetIsInfo)
+                                                       main.SetTarget 
(delegate { return new MasterAssembly (cd.TargetPath); });
+                                               else
+                                                       main.SetTarget 
(delegate { return new CecilAssembly (cd.TargetPath); });
+                                               main.StartCompare (delegate {
+                                                       main.Title = title; });
+                                               main.Config.MoveToTop (cd);
+                                               PopulateRecent ();
+                                               main.Config.Save ();
+                                       };
+                                       
+                                       recentmenu.Add (c);
+                               }
+                       }
+                       recentmenu.ShowAll ();
+               }
+               
                // 
                // Constructor
                //
@@ -388,15 +439,34 @@
                        // Work around limitation in Stetic, there is no way
                        // of getting a handle on the menu (!!!)
                        
+                       // Populate File/Recent Comparisons, this would be so 
much
+                       // easier if Stetic had any support for this.
+                       recentmenu = new Menu ();
+                       
+                       MenuItem filemenuitem = (main.MenuBar.Children [0]) as 
MenuItem;
+                       Menu filesub = (Menu) filemenuitem.Submenu;
+                       MenuItem recentmenuitem = new MenuItem ("Recent 
Comparisons");
+                       recentmenuitem.Submenu = recentmenu;
+                       recentmenuitem.ShowAll ();
+                       filesub.Insert (recentmenuitem, 0);
+                       MenuItem sep = new MenuItem ();
+                       sep.ShowAll ();
+                       filesub.Insert (sep, 1);
+
+                       PopulateRecent ();
+                       
+                       
+                       // Populate the list of profile comparisons
                        Menu sub = null;
                        
                        foreach (MenuItem mi in main.MenuBar.AllChildren){
                                AccelLabel a = mi.Child as AccelLabel;
-                               if (a != null)
-                                       Console.WriteLine (a.LabelProp);
+       
                                if (a == null || a.LabelProp != "_Compare")
                                        continue;
                                
+                               if (a.LabelProp == "Recent Comparisons"){
+                               }
                                sub = (Menu) mi.Submenu;
                                break;
                        }

Modified: trunk/mono-tools/gui-compare/MainWindow.cs
===================================================================
--- trunk/mono-tools/gui-compare/MainWindow.cs  2008-01-02 23:08:52 UTC (rev 
92137)
+++ trunk/mono-tools/gui-compare/MainWindow.cs  2008-01-02 23:21:24 UTC (rev 
92138)
@@ -85,10 +85,25 @@
                Build ();
                notebook1.Page = 1;
                
+               //
+               // Load configuration
+               //
+               Config = GuiCompare.Config.GetConfig ();
+               ShowMissing.Active = Config.ShowMissing;
+               ShowErrors.Active = Config.ShowErrors;
+               ShowExtra.Active = Config.ShowExtra;
+               ShowPresent.Active = Config.ShowPresent;
+               ShowTodo.Active = Config.ShowTodo;
+
+               //
+               // Configure the GUI
+               //
+               info_manager = new InfoManager (this);
+                               
                progressbar1.Adjustment.Lower = 0;
                progressbar1.Adjustment.Upper = 100;
-               info_manager = new InfoManager (this);
                
+               
                treeStore = new Gtk.TreeStore (typeof (string), typeof 
(Gdk.Pixbuf), typeof (Gdk.Pixbuf),
                                               typeof (Gdk.Pixbuf), typeof 
(string),
                                               typeof (Gdk.Pixbuf), typeof 
(string),
@@ -153,16 +168,6 @@
                countsColumn.AddAttribute (errorTextCell, "text", 8);
                countsColumn.AddAttribute (todoPixbufCell, "pixbuf", 9);
                countsColumn.AddAttribute (todoTextCell, "text", 10);
-
-               //
-               // Load configuration
-               //
-               Config = GuiCompare.Config.GetConfig ();
-               ShowMissing.Active = Config.ShowMissing;
-               ShowErrors.Active = Config.ShowErrors;
-               ShowExtra.Active = Config.ShowExtra;
-               ShowPresent.Active = Config.ShowPresent;
-               ShowTodo.Active = Config.ShowTodo;
                
                tree.Selection.Changed += delegate (object sender, EventArgs e) 
{
                        Gtk.TreeIter iter;

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to