Author: lluis
Date: 2006-09-22 17:51:17 -0400 (Fri, 22 Sep 2006)
New Revision: 65825

Modified:
   trunk/stetic/ChangeLog
   trunk/stetic/libstetic/ItemDescriptor.cs
   trunk/stetic/libstetic/Registry.cs
   trunk/stetic/libstetic/wrapper/Action.cs
   trunk/stetic/libsteticui/ActionGroupDesigner.cs
   trunk/stetic/libsteticui/ActionGroupEditSession.cs
   trunk/stetic/libsteticui/Application.cs
   trunk/stetic/libsteticui/ApplicationBackend.cs
   trunk/stetic/libsteticui/ApplicationBackendController.cs
   trunk/stetic/libsteticui/Component.cs
   trunk/stetic/libsteticui/GuiDispatchServerSink.cs
   trunk/stetic/libsteticui/Palette.cs
   trunk/stetic/libsteticui/PluggableWidget.cs
   trunk/stetic/libsteticui/Project.cs
   trunk/stetic/libsteticui/ProjectBackend.cs
   trunk/stetic/libsteticui/ProjectView.cs
   trunk/stetic/libsteticui/SignalsEditor.cs
   trunk/stetic/libsteticui/WidgetDesigner.cs
   trunk/stetic/libsteticui/WidgetDesignerBackend.cs
   trunk/stetic/libsteticui/WidgetEditSession.cs
   trunk/stetic/libsteticui/WidgetPropertyTree.cs
   trunk/stetic/stetic/DesignerView.cs
   trunk/stetic/stetic/Stetic.cs
Log:
2006-09-22  Lluis Sanchez Gual  <[EMAIL PROTECTED]> 

        * libsteticui/WidgetEditSession.cs:
        * libsteticui/Palette.cs:
        * libsteticui/ProjectView.cs:
        * libsteticui/SignalsEditor.cs:
        * libsteticui/ApplicationBackend.cs: Reconnect the plug when the socket
          is unrealized.
          
        * libsteticui/WidgetDesignerBackend.cs: Added null check.
        
        * libsteticui/WidgetDesigner.cs:
        * libsteticui/ActionGroupEditSession.cs:
        * libsteticui/PluggableWidget.cs:
        * libsteticui/WidgetPropertyTree.cs:
        * libsteticui/ActionGroupDesigner.cs:
        * libstetic/Registry.cs:
        * stetic/Stetic.cs:
        * libsteticui/Application.cs: Fixed process restart workflow, to make
          the process switch faster.
        
        * libsteticui/GuiDispatchServerSink.cs:
        * libsteticui/Component.cs:
        * libsteticui/ApplicationBackendController.cs:
        * libsteticui/Project.cs:
        * libsteticui/ProjectBackend.cs: Misc bug fixes.
        
        * libstetic/ItemDescriptor.cs: Made it serializable.
        * libstetic/wrapper/Action.cs (CopyFrom): Clear the signals list before
          adding the new signals.
        * stetic/DesignerView.cs: Added getter for the root component.



Modified: trunk/stetic/ChangeLog
===================================================================
--- trunk/stetic/ChangeLog      2006-09-22 18:00:01 UTC (rev 65824)
+++ trunk/stetic/ChangeLog      2006-09-22 21:51:17 UTC (rev 65825)
@@ -1,3 +1,35 @@
+2006-09-22  Lluis Sanchez Gual  <[EMAIL PROTECTED]> 
+
+       * libsteticui/WidgetEditSession.cs:
+       * libsteticui/Palette.cs:
+       * libsteticui/ProjectView.cs:
+       * libsteticui/SignalsEditor.cs:
+       * libsteticui/ApplicationBackend.cs: Reconnect the plug when the socket
+         is unrealized.
+         
+       * libsteticui/WidgetDesignerBackend.cs: Added null check.
+       
+       * libsteticui/WidgetDesigner.cs:
+       * libsteticui/ActionGroupEditSession.cs:
+       * libsteticui/PluggableWidget.cs:
+       * libsteticui/WidgetPropertyTree.cs:
+       * libsteticui/ActionGroupDesigner.cs:
+       * libstetic/Registry.cs:
+       * stetic/Stetic.cs:
+       * libsteticui/Application.cs: Fixed process restart workflow, to make
+         the process switch faster.
+       
+       * libsteticui/GuiDispatchServerSink.cs:
+       * libsteticui/Component.cs:
+       * libsteticui/ApplicationBackendController.cs:
+       * libsteticui/Project.cs:
+       * libsteticui/ProjectBackend.cs: Misc bug fixes.
+       
+       * libstetic/ItemDescriptor.cs: Made it serializable.
+       * libstetic/wrapper/Action.cs (CopyFrom): Clear the signals list before
+         adding the new signals.
+       * stetic/DesignerView.cs: Added getter for the root component.
+
 2006-09-21  Lluis Sanchez Gual  <[EMAIL PROTECTED]> 
 
        * stetic/UIManager.cs:

Modified: trunk/stetic/libstetic/ItemDescriptor.cs
===================================================================
--- trunk/stetic/libstetic/ItemDescriptor.cs    2006-09-22 18:00:01 UTC (rev 
65824)
+++ trunk/stetic/libstetic/ItemDescriptor.cs    2006-09-22 21:51:17 UTC (rev 
65825)
@@ -5,6 +5,7 @@
 
 namespace Stetic
 {
+       [Serializable]
        public abstract class ItemDescriptor
        {
                [NonSerialized]

Modified: trunk/stetic/libstetic/Registry.cs
===================================================================
--- trunk/stetic/libstetic/Registry.cs  2006-09-22 18:00:01 UTC (rev 65824)
+++ trunk/stetic/libstetic/Registry.cs  2006-09-22 21:51:17 UTC (rev 65825)
@@ -62,26 +62,35 @@
                
                public static bool ReloadWidgetLibraries ()
                {
-                       bool res = true;
-                       bool changing = false;
+                       bool needsReload = false;
 
-                       foreach (WidgetLibrary lib in libraries)
+                       // If there is a lib which can't be reloaded, 
+                       // there is no need to start the reloading process
+                       
+                       foreach (WidgetLibrary lib in libraries) {
                                if (lib != coreLib && lib.NeedsReload) {
-                                       if (!changing) {
-                                               changing = true;
-                                               NotifyChanging ();
-                                       }
                                        if (!lib.CanReload)
-                                               res = false;
-                                       else
-                                               lib.Reload ();
+                                               return false;
+                                       needsReload = true;
                                }
+                       }
+                       
+                       if (!needsReload)
+                               return true;
 
-                       if (changing) {
+                       try {
+                               NotifyChanging ();
+                               
+                               foreach (WidgetLibrary lib in libraries)
+                                       if (lib != coreLib && lib.NeedsReload)
+                                               lib.Reload ();
+
                                InternalUpdate ();
+                       } finally {
                                NotifyChanged ();
                        }
-                       return res;
+                       
+                       return true;
                }
                
                public static bool IsRegistered (WidgetLibrary library)

Modified: trunk/stetic/libstetic/wrapper/Action.cs
===================================================================
--- trunk/stetic/libstetic/wrapper/Action.cs    2006-09-22 18:00:01 UTC (rev 
65824)
+++ trunk/stetic/libstetic/wrapper/Action.cs    2006-09-22 21:51:17 UTC (rev 
65825)
@@ -204,6 +204,7 @@
                        GtkAction.VisibleHorizontal = 
action.GtkAction.VisibleHorizontal;
                        GtkAction.VisibleVertical = 
action.GtkAction.VisibleVertical;
                        
+                       Signals.Clear ();
                        foreach (Signal s in action.Signals)
                                Signals.Add (new Signal (s.SignalDescriptor, 
s.Handler, s.After));
                        

Modified: trunk/stetic/libsteticui/ActionGroupDesigner.cs
===================================================================
--- trunk/stetic/libsteticui/ActionGroupDesigner.cs     2006-09-22 18:00:01 UTC 
(rev 65824)
+++ trunk/stetic/libsteticui/ActionGroupDesigner.cs     2006-09-22 21:51:17 UTC 
(rev 65825)
@@ -7,10 +7,9 @@
        {
                ActionGroupEditSession editSession;
                ActionGroupDesignerFrontend frontend;
-               string sessionData;
                Project project;
                string componentName;
-               ActionGroupComponent actionGroup;
+               string actionGroupName;
                bool autoCommitChanges;
                
                public event EventHandler BindField;
@@ -21,7 +20,7 @@
                internal ActionGroupDesigner (Project project, string 
componentName, ActionGroupComponent actionGroup, bool autoCommitChanges): base 
(project.App)
                {
                        this.componentName = componentName;
-                       this.actionGroup = actionGroup;
+                       this.actionGroupName = actionGroup.Name;
                        this.autoCommitChanges = autoCommitChanges;
                        this.project = project;
                        
@@ -83,8 +82,11 @@
                
                public void Save ()
                {
-                       if (editSession != null)
+                       if (editSession != null) {
                                editSession.Save ();
+                               if (!autoCommitChanges && componentName != null)
+                                       componentName = editSession.ActiveGroup;
+                       }
                }
                
                public void CopySelection ()
@@ -116,6 +118,11 @@
                        editSession.CreateBackendWidgetPlug (socketId);
                }
                
+               protected override void OnDestroyPlug (uint socketId)
+               {
+                       editSession.DestroyBackendWidgetPlug ();
+               }
+               
                protected override Gtk.Widget OnCreateWidget ()
                {
                        return editSession.Backend;
@@ -124,8 +131,8 @@
                void CreateSession ()
                {
                        try {
-                               if (actionGroup != null)
-                                       editSession = 
project.ProjectBackend.CreateGlobalActionGroupDesignerSession (frontend, 
actionGroup.Name, autoCommitChanges);
+                               if (actionGroupName != null)
+                                       editSession = 
project.ProjectBackend.CreateGlobalActionGroupDesignerSession (frontend, 
actionGroupName, autoCommitChanges);
                                else
                                        editSession = 
project.ProjectBackend.CreateLocalActionGroupDesignerSession (frontend, 
componentName, autoCommitChanges);
                                ResetCustomWidget ();
@@ -144,24 +151,23 @@
                        base.Dispose ();
                }
                
-               protected override void OnBackendChanging ()
+               internal override void OnBackendChanged (ApplicationBackend 
oldBackend)
                {
-                       if (!autoCommitChanges)
-                               sessionData = editSession.SaveState ();
-                       if (editSession != null)
-                               editSession.Dispose ();
-                       editSession = null;
-                       base.OnBackendChanging ();
-               }
+                       object[] sessionData = null;
+                       
+                       if (oldBackend != null) {
+                               if (!autoCommitChanges)
+                                       sessionData = editSession.SaveState ();
+                               if (editSession != null)
+                                       editSession.Dispose ();
+                       }
                
-               protected override void OnBackendChanged ()
-               {
                        CreateSession ();
 
                        if (sessionData != null && editSession != null)
                                editSession.RestoreState (sessionData);
                        
-                       base.OnBackendChanged ();
+                       base.OnBackendChanged (oldBackend);
                }
                
                internal void NotifyBindField ()

Modified: trunk/stetic/libsteticui/ActionGroupEditSession.cs
===================================================================
--- trunk/stetic/libsteticui/ActionGroupEditSession.cs  2006-09-22 18:00:01 UTC 
(rev 65824)
+++ trunk/stetic/libsteticui/ActionGroupEditSession.cs  2006-09-22 21:51:17 UTC 
(rev 65825)
@@ -1,5 +1,6 @@
 
 using System;
+using System.Xml;
 using System.Collections;
 
 namespace Stetic
@@ -37,7 +38,7 @@
                        }
                        else {
                                if (!autoCommitChanges)
-                                       throw new InvalidOperationException ();
+                                       throw new System.NotSupportedException 
();
                                Stetic.Wrapper.Container container = 
project.GetTopLevelWrapper (containerName, true);
                                groupToolbar = new ActionGroupToolbar 
(frontend, container.LocalActionGroups);
                        }
@@ -201,6 +202,13 @@
                        Gdk.Threads.Leave ();
                }
                
+               public void DestroyBackendWidgetPlug ()
+               {
+                       Gtk.Plug plug = (Gtk.Plug) Backend.Parent;
+                       plug.Remove (Backend);
+                       plug.Destroy ();
+               }
+               
                public bool AllowActionBinding {
                        get { return designer.Toolbar.AllowActionBinding; }
                        set { designer.Toolbar.AllowActionBinding = value; }
@@ -219,13 +227,42 @@
                        return null;
                }
                
-               public string SaveState ()
+               public object[] SaveState ()
                {
-                       return null;
+                       if (autoCommitChanges)
+                               return null;
+
+                       XmlDocument doc = new XmlDocument ();
+                       doc.AppendChild (groupCopy.Write (doc, 
FileFormat.Native));
+                       
+                       Hashtable nameMap = new Hashtable ();
+                       foreach (DictionaryEntry e in actionCopyMap)
+                               nameMap [((Wrapper.Action)e.Key).Name] = 
((Wrapper.Action)e.Value).Name;
+                       
+                       return new object[] { groupCopy.Name, nameMap, 
doc.OuterXml };
                }
                
-               public void RestoreState (string state)
+               public void RestoreState (object[] data)
                {
+                       if (data == null)
+                               return;
+                       
+                       groupCopy = new Stetic.Wrapper.ActionGroup ();
+                       groupCopy.Name = (string) data [0];
+                       
+                       XmlDocument doc = new XmlDocument ();
+                       doc.LoadXml ((string) data [2]);
+                       
+                       // Create the map which links edited action with source 
actions
+                       actionCopyMap.Clear ();
+                       foreach (DictionaryEntry e in (Hashtable) data [1]) {
+                               Wrapper.Action dupaction = groupCopy.GetAction 
((string)e.Key);
+                               Wrapper.Action action = group.GetAction 
((string)e.Value);
+                               actionCopyMap [dupaction] = action;
+                       }
+                       
+                       groupCopy.SignalAdded += new Stetic.SignalEventHandler 
(OnSignalAdded);
+                       groupCopy.SignalChanged += new 
Stetic.SignalChangedEventHandler (OnSignalChanged);
                }
                
                void OnSignalAdded (object s, Stetic.SignalEventArgs a)

Modified: trunk/stetic/libsteticui/Application.cs
===================================================================
--- trunk/stetic/libsteticui/Application.cs     2006-09-22 18:00:01 UTC (rev 
65824)
+++ trunk/stetic/libsteticui/Application.cs     2006-09-22 21:51:17 UTC (rev 
65825)
@@ -41,8 +41,8 @@
                ProjectView projectWidget;
                SignalsEditor signalsWidget;
                
-               internal event EventHandler BackendChanging;
-               internal event EventHandler BackendChanged;
+               internal event BackendChangingHandler BackendChanging;
+               internal event BackendChangedHandler BackendChanged;
                
                public Application (IsolationMode mode)
                {
@@ -124,6 +124,7 @@
                void OnBackendStopped (object ob, EventArgs args)
                {
                        // The backend process crashed, try to restart it
+                       backend = null;
                        backendController = new ApplicationBackendController 
(channelId);
                        backendController.StartBackend ();
                        OnBackendChanged (true);
@@ -131,6 +132,8 @@
                
                void OnBackendChanged (bool notify)
                {
+                       ApplicationBackend oldBackend = backend;
+                       
                        backend = backendController.Backend;
                        backendController.Stopped += OnBackendStopped;
                        UpdateWidgetLibraries (false, false);
@@ -147,7 +150,7 @@
                        }
 
                        if (notify && BackendChanged != null)
-                               BackendChanged (this, EventArgs.Empty);
+                               BackendChanged (oldBackend);
 
                        backend.ActiveProject = activeProject != null ? 
activeProject.ProjectBackend : null;
                }
@@ -156,7 +159,7 @@
                {
                        backend.GlobalWidgetLibraries = widgetLibraries;
                        if (BackendChanging != null)
-                               BackendChanging (this, EventArgs.Empty);
+                               BackendChanging ();
                }
                
                internal string RegisterRemotingChannel (IsolationMode mode)
@@ -342,26 +345,36 @@
                
                internal Component GetComponent (object cbackend, string name, 
string type)
                {
-                       Component c = (Component) components [cbackend];
-                       if (c != null)
-                               return c;
+                       try {
+                               Component c = (Component) components [cbackend];
+                               if (c != null)
+                                       return c;
 
-                       if (cbackend is Wrapper.Action) {
-                               c = new ActionComponent (this, cbackend, name);
-                               ((ObjectWrapper)cbackend).Frontend = c;
-                       } else if (cbackend is Wrapper.ActionGroup) {
-                               c = new ActionGroupComponent (this, cbackend, 
name);
-                               ((Wrapper.ActionGroup)cbackend).Frontend = c;
-                       } else if (cbackend is ObjectWrapper) {
-                               c = new WidgetComponent (this, cbackend, name, 
type != null ? GetComponentType (type) : null);
-                               ((ObjectWrapper)cbackend).Frontend = c;
-                       } else if (cbackend == null)
-                               throw new System.ArgumentNullException 
("cbackend");
-                       else
-                               throw new System.InvalidOperationException 
("Invalid component type: " + cbackend.GetType ());
+                               if (cbackend is Wrapper.Action) {
+                                       c = new ActionComponent (this, 
cbackend, name);
+                                       ((ObjectWrapper)cbackend).Frontend = c;
+                               } else if (cbackend is Wrapper.ActionGroup) {
+                                       c = new ActionGroupComponent (this, 
cbackend, name);
+                                       
((Wrapper.ActionGroup)cbackend).Frontend = c;
+                               } else if (cbackend is ObjectWrapper) {
+                                       c = new WidgetComponent (this, 
cbackend, name, type != null ? GetComponentType (type) : null);
+                                       ((ObjectWrapper)cbackend).Frontend = c;
+                               } else if (cbackend == null)
+                                       throw new System.ArgumentNullException 
("cbackend");
+                               else
+                                       throw new 
System.InvalidOperationException ("Invalid component type: " + cbackend.GetType 
());
 
-                       components [cbackend] = c;
-                       return c;
+                               components [cbackend] = c;
+                               return c;
+                       }
+                       catch (System.Runtime.Remoting.RemotingException ex)
+                       {
+                               // There may be a remoting exception if the 
remote wrapper
+                               // has already been disconnected when trying to 
create the
+                               // component frontend. This may happen since 
calls are
+                               // dispatched in the GUI thread, so they may be 
delayed.
+                               return null;
+                       }
                }
                
                internal void DisposeComponent (Component c)
@@ -369,4 +382,7 @@
                        components.Remove (c.Backend);
                }
        }
+
+       internal delegate void BackendChangingHandler ();
+       internal delegate void BackendChangedHandler (ApplicationBackend 
oldBackend);
 }

Modified: trunk/stetic/libsteticui/ApplicationBackend.cs
===================================================================
--- trunk/stetic/libsteticui/ApplicationBackend.cs      2006-09-22 18:00:01 UTC 
(rev 65824)
+++ trunk/stetic/libsteticui/ApplicationBackend.cs      2006-09-22 21:51:17 UTC 
(rev 65825)
@@ -245,6 +245,15 @@
                        plug.Show ();
                }
                
+               public void DestroyPaletteWidgetPlug ()
+               {
+                       if (paletteWidget != null) {
+                               Gtk.Plug plug = (Gtk.Plug)paletteWidget.Parent;
+                               plug.Remove (paletteWidget);
+                               plug.Destroy ();
+                       }
+               }
+               
                public WidgetPropertyTreeBackend GetPropertiesWidget ()
                {
                        if (propertiesWidget == null) {
@@ -264,6 +273,15 @@
                        plug.Show ();
                }
                
+               public void DestroyPropertiesWidgetPlug ()
+               {
+                       if (propertiesWidget != null) {
+                               Gtk.Plug plug = (Gtk.Plug) 
propertiesWidget.Parent;
+                               plug.Remove (propertiesWidget);
+                               plug.Destroy ();
+                       }
+               }
+               
                public SignalsEditorEditSession GetSignalsWidget 
(SignalsEditorFrontend frontend)
                {
                        if (signalsWidget == null) {
@@ -285,6 +303,15 @@
                        return session;
                }
                
+               public void DestroySignalsWidgetPlug ()
+               {
+                       if (signalsWidget != null) {
+                               Gtk.Plug plug = (Gtk.Plug) 
signalsWidget.Editor.Parent;
+                               plug.Remove (signalsWidget.Editor);
+                               plug.Destroy ();
+                       }
+               }
+               
                public ProjectViewBackend GetProjectWidget (ProjectViewFrontend 
frontend)
                {
                        if (projectWidget == null) {
@@ -303,6 +330,15 @@
                        plug.Show ();
                }
                
+               public void DestroyProjectWidgetPlug ()
+               {
+                       if (projectWidget != null) {
+                               Gtk.Plug plug = (Gtk.Plug)projectWidget.Parent;
+                               plug.Remove (projectWidget);
+                               plug.Destroy ();
+                       }
+               }
+               
                public bool GetClassDescriptorInfo (string name, out string 
desc, out string className, out byte[] icon)
                {
                        ClassDescriptor cls = Registry.LookupClassByName (name);

Modified: trunk/stetic/libsteticui/ApplicationBackendController.cs
===================================================================
--- trunk/stetic/libsteticui/ApplicationBackendController.cs    2006-09-22 
18:00:01 UTC (rev 65824)
+++ trunk/stetic/libsteticui/ApplicationBackendController.cs    2006-09-22 
21:51:17 UTC (rev 65825)
@@ -42,7 +42,7 @@
                        string sref = Convert.ToBase64String (ms.ToArray ());
                
                        Process process = new Process ();
-                       process.StartInfo = new ProcessStartInfo ("sh", "-c 
\"mono " + asm + "\"");
+                       process.StartInfo = new ProcessStartInfo ("sh", "-c 
\"mono --debug " + asm + "\"");
                        process.StartInfo.WorkingDirectory = 
AppDomain.CurrentDomain.BaseDirectory;
                        process.StartInfo.UseShellExecute = false;
                        process.StartInfo.RedirectStandardInput = true;
@@ -63,7 +63,7 @@
                        runningEvent.Reset ();
                        backend.Dispose ();
                        if (waitUntilDone)
-                               runningEvent.WaitOne (5000, false);
+                               runningEvent.WaitOne (9000, false);
                }
                
                void OnExited (object o, EventArgs args)

Modified: trunk/stetic/libsteticui/Component.cs
===================================================================
--- trunk/stetic/libsteticui/Component.cs       2006-09-22 18:00:01 UTC (rev 
65824)
+++ trunk/stetic/libsteticui/Component.cs       2006-09-22 21:51:17 UTC (rev 
65825)
@@ -116,7 +116,9 @@
                {
                        // Make sure we don't leak the wrapper type to the 
frontend process
                        
-                       if (ob is Wrapper.Container) {
+                       if (ob is Wrapper.Window) {
+                               
System.Runtime.Remoting.RemotingServices.Marshal (ob, null, 
typeof(Wrapper.Window));
+                       } else if (ob is Wrapper.Container) {
                                
System.Runtime.Remoting.RemotingServices.Marshal (ob, null, 
typeof(Wrapper.Container));
                        } else if (ob is Wrapper.Widget) {
                                
System.Runtime.Remoting.RemotingServices.Marshal (ob, null, 
typeof(Wrapper.Widget));

Modified: trunk/stetic/libsteticui/GuiDispatchServerSink.cs
===================================================================
--- trunk/stetic/libsteticui/GuiDispatchServerSink.cs   2006-09-22 18:00:01 UTC 
(rev 65824)
+++ trunk/stetic/libsteticui/GuiDispatchServerSink.cs   2006-09-22 21:51:17 UTC 
(rev 65825)
@@ -45,6 +45,7 @@
                                                        out IMessage 
responseMsg, out ITransportHeaders responseHeaders, out Stream responseStream)
                {
                        IMethodCallMessage msg = (IMethodCallMessage) 
requestMsg;
+//                     Console.WriteLine ("MESSAGE: " + msg.MethodName);
                        
                        sinkStack.Push (this, null);
 
@@ -93,8 +94,8 @@
                        public void Dispatch (object o, EventArgs a)
                        {
                                IMessage responseMsg;
-                               ITransportHeaders responseHeaders;
-                               Stream responseStream;
+                               ITransportHeaders responseHeaders = null;
+                               Stream responseStream = null;
                                
                                try {
                                        nextSink.ProcessMessage (sinkStack,
@@ -104,13 +105,12 @@
                                                                         out 
responseMsg,
                                                                         out 
responseHeaders,
                                                                         out 
responseStream);
-
-                                       sinkStack.AsyncProcessResponse 
(responseMsg, responseHeaders, responseStream);
                                }
                                catch (Exception ex) {
                                        responseMsg = new ReturnMessage (ex, 
(IMethodCallMessage)requestMsg);
-                                       sinkStack.AsyncProcessResponse 
(responseMsg, null, null);
                                }
+                               
+                               sinkStack.AsyncProcessResponse (responseMsg, 
responseHeaders, responseStream);
                        }
                }
        }

Modified: trunk/stetic/libsteticui/Palette.cs
===================================================================
--- trunk/stetic/libsteticui/Palette.cs 2006-09-22 18:00:01 UTC (rev 65824)
+++ trunk/stetic/libsteticui/Palette.cs 2006-09-22 21:51:17 UTC (rev 65825)
@@ -18,6 +18,11 @@
                        Update ();
                }
                
+               protected override void OnDestroyPlug (uint socketId)
+               {
+                       app.Backend.DestroyPaletteWidgetPlug ();
+               }
+               
                protected override Gtk.Widget OnCreateWidget ()
                {
                        Update ();

Modified: trunk/stetic/libsteticui/PluggableWidget.cs
===================================================================
--- trunk/stetic/libsteticui/PluggableWidget.cs 2006-09-22 18:00:01 UTC (rev 
65824)
+++ trunk/stetic/libsteticui/PluggableWidget.cs 2006-09-22 21:51:17 UTC (rev 
65825)
@@ -50,6 +50,15 @@
                        }
                }
                
+               protected override void OnUnrealized ()
+               {
+                       if (app.UseExternalBackend && initialized) {
+                               OnDestroyPlug (socket.Id);
+                               initialized = false;
+                       }
+                       base.OnUnrealized ();
+               }
+               
                protected void UpdateWidget ()
                {
                        if (initialized) {
@@ -62,6 +71,7 @@
                }
                
                protected abstract void OnCreatePlug (uint socketId);
+               protected abstract void OnDestroyPlug (uint socketId);
                
                protected abstract Gtk.Widget OnCreateWidget ();
                
@@ -74,18 +84,8 @@
                        }
                }
                
-               void OnBackendChanging (object ob, EventArgs args)
+               internal virtual void OnBackendChanged (ApplicationBackend 
oldBackend)
                {
-                       OnBackendChanging ();
-               }
-               
-               void OnBackendChanged (object ob, EventArgs args)
-               {
-                       OnBackendChanged ();
-               }
-               
-               protected virtual void OnBackendChanged ()
-               {
                        if (initialized && app.UseExternalBackend && 
!customWidget) {
                                Remove (Child);
                                socket.Dispose ();
@@ -93,7 +93,7 @@
                        }
                }
                
-               protected virtual void OnBackendChanging ()
+               internal virtual void OnBackendChanging ()
                {
                }
                

Modified: trunk/stetic/libsteticui/Project.cs
===================================================================
--- trunk/stetic/libsteticui/Project.cs 2006-09-22 18:00:01 UTC (rev 65824)
+++ trunk/stetic/libsteticui/Project.cs 2006-09-22 21:51:17 UTC (rev 65825)
@@ -18,8 +18,8 @@
                string tmpProjectFile;
                WidgetLibrarySet widgetLibraries = new WidgetLibrarySet ();
                
-               internal event EventHandler BackendChanging;
-               internal event EventHandler BackendChanged;
+               internal event BackendChangingHandler BackendChanging;
+               internal event BackendChangedHandler BackendChanged;
 
                public event ComponentEventHandler ComponentAdded;
                public event ComponentEventHandler ComponentRemoved;
@@ -60,12 +60,16 @@
                
                public void Dispose ()
                {
+                       app.BackendChanging -= OnBackendChanging;
+                       app.BackendChanged -= OnBackendChanged;
+                       
                        if (tmpProjectFile != null && File.Exists 
(tmpProjectFile)) {
                                File.Delete (tmpProjectFile);
                                tmpProjectFile = null;
                        }
                        backend.Dispose ();
                        app.DisposeProject (this);
+                       widgetLibraries.Dispose ();
                        System.Runtime.Remoting.RemotingServices.Disconnect 
(this);
                }
 
@@ -271,7 +275,7 @@
                                Gtk.Application.Invoke (
                                        delegate {
                                                Component c = App.GetComponent 
(obj, name, typeName);
-                                               if (ComponentAdded != null)
+                                               if (c != null && ComponentAdded 
!= null)
                                                        ComponentAdded (this, 
new ComponentEventArgs (this, c));
                                        }
                                );
@@ -284,7 +288,7 @@
                                Gtk.Application.Invoke (
                                        delegate {
                                                Component c = App.GetComponent 
(obj, name, typeName);
-                                               if (ComponentRemoved != null)
+                                               if (c != null && 
ComponentRemoved != null)
                                                        ComponentRemoved (this, 
new ComponentEventArgs (this, c));
                                        }
                                );
@@ -324,8 +328,10 @@
                                delegate {
                                        if (ComponentNameChanged != null) {
                                                WidgetComponent c = 
(WidgetComponent) App.GetComponent (obj, null, null);
-                                               c.UpdateName (newName);
-                                               ComponentNameChanged (this, new 
ComponentNameEventArgs (this, c, oldName));
+                                               if (c != null) {
+                                                       c.UpdateName (newName);
+                                                       ComponentNameChanged 
(this, new ComponentNameEventArgs (this, c, oldName));
+                                               }
                                        }
                                }
                        );
@@ -352,7 +358,8 @@
                        Gtk.Application.Invoke (delegate {
                                if (SignalAdded != null) {
                                        Component c = App.GetComponent (obj, 
name, null);
-                                       SignalAdded (this, new 
ComponentSignalEventArgs (this, c, null, signal));
+                                       if (c != null)
+                                               SignalAdded (this, new 
ComponentSignalEventArgs (this, c, null, signal));
                                }
                        });
                }
@@ -362,7 +369,8 @@
                        Gtk.Application.Invoke (delegate {
                                if (SignalRemoved != null) {
                                        Component c = App.GetComponent (obj, 
name, null);
-                                       SignalRemoved (this, new 
ComponentSignalEventArgs (this, c, null, signal));
+                                       if (c != null)
+                                               SignalRemoved (this, new 
ComponentSignalEventArgs (this, c, null, signal));
                                }
                        });
                }
@@ -372,7 +380,8 @@
                        Gtk.Application.Invoke (delegate {
                                if (SignalChanged != null) {
                                        Component c = App.GetComponent (obj, 
name, null);
-                                       SignalChanged (this, new 
ComponentSignalEventArgs (this, c, oldSignal, signal));
+                                       if (c != null)
+                                               SignalChanged (this, new 
ComponentSignalEventArgs (this, c, oldSignal, signal));
                                }
                        });
                }
@@ -385,21 +394,23 @@
                        });
                }
                
-               void OnBackendChanging (object ob, EventArgs args)
+               void OnBackendChanging ()
                {
                        selection = null;
                        if (SelectionChanged != null)
                                SelectionChanged (this, new ComponentEventArgs 
(this, selection));
                                
-                       tmpProjectFile = Path.GetTempFileName ();
-                       backend.Save (tmpProjectFile);
-                       
                        if (BackendChanging != null)
-                               BackendChanging (this, args);
+                               BackendChanging ();
                }
                
-               void OnBackendChanged (object ob, EventArgs args)
+               void OnBackendChanged (ApplicationBackend oldBackend)
                {
+                       if (oldBackend != null) {
+                               tmpProjectFile = Path.GetTempFileName ();
+                               backend.Save (tmpProjectFile);
+                       }
+                       
                        backend = app.Backend.CreateProject ();
                        backend.SetFrontend (this);
                        backend.WidgetLibraries = widgetLibraries;
@@ -417,7 +428,10 @@
                                backend.ResourceProvider = resourceProvider;
 
                        if (BackendChanged != null)
-                               BackendChanged (this, args);
+                               BackendChanged (oldBackend);
+                               
+                       if (ProjectReloaded != null)
+                               ProjectReloaded (this, EventArgs.Empty);
                }
        }
        
@@ -441,5 +455,16 @@
                {
                        return (string[]) widgetLibraries.ToArray 
(typeof(string));
                }
+
+               public override object InitializeLifetimeService ()
+               {
+                       // Will be disconnected when calling Dispose
+                       return null;
+               }
+               
+               public void Dispose ()
+               {
+                       System.Runtime.Remoting.RemotingServices.Disconnect 
(this);
+               }
        }
 }

Modified: trunk/stetic/libsteticui/ProjectBackend.cs
===================================================================
--- trunk/stetic/libsteticui/ProjectBackend.cs  2006-09-22 18:00:01 UTC (rev 
65824)
+++ trunk/stetic/libsteticui/ProjectBackend.cs  2006-09-22 21:51:17 UTC (rev 
65825)
@@ -350,6 +350,7 @@
                        doc.LoadXml (template);
                        Stetic.Wrapper.ActionGroup group = new 
Stetic.Wrapper.ActionGroup ();
                        group.Read (this, doc.DocumentElement);
+                       ActionGroups.Add (group);
                        return group;
                }
                
@@ -570,7 +571,7 @@
                void OnSignalRemoved (object sender, SignalEventArgs args)
                {
                        if (frontend != null)
-                               frontend.NotifySignalRemoved 
(Component.GetSafeReference (args.Wrapper), 
((Gtk.Widget)args.Wrapper.Wrapped).Name, args.Signal);
+                               frontend.NotifySignalRemoved 
(Component.GetSafeReference (args.Wrapper), null, args.Signal);
                        OnSignalRemoved (args);
                }
 

Modified: trunk/stetic/libsteticui/ProjectView.cs
===================================================================
--- trunk/stetic/libsteticui/ProjectView.cs     2006-09-22 18:00:01 UTC (rev 
65824)
+++ trunk/stetic/libsteticui/ProjectView.cs     2006-09-22 21:51:17 UTC (rev 
65825)
@@ -22,6 +22,11 @@
                        app.Backend.CreateProjectWidgetPlug (frontend, 
socketId);
                }
                
+               protected override void OnDestroyPlug (uint socketId)
+               {
+                       app.Backend.DestroyProjectWidgetPlug ();
+               }
+               
                protected override Gtk.Widget OnCreateWidget ()
                {
                        return app.Backend.GetProjectWidget (frontend);

Modified: trunk/stetic/libsteticui/SignalsEditor.cs
===================================================================
--- trunk/stetic/libsteticui/SignalsEditor.cs   2006-09-22 18:00:01 UTC (rev 
65824)
+++ trunk/stetic/libsteticui/SignalsEditor.cs   2006-09-22 21:51:17 UTC (rev 
65825)
@@ -29,6 +29,11 @@
                        session = app.Backend.CreateSignalsWidgetPlug 
(frontend, socketId);
                }
                
+               protected override void OnDestroyPlug (uint socketId)
+               {
+                       app.Backend.DestroySignalsWidgetPlug ();
+               }
+               
                protected override Gtk.Widget OnCreateWidget ()
                {
                        session = app.Backend.GetSignalsWidget (frontend);

Modified: trunk/stetic/libsteticui/WidgetDesigner.cs
===================================================================
--- trunk/stetic/libsteticui/WidgetDesigner.cs  2006-09-22 18:00:01 UTC (rev 
65824)
+++ trunk/stetic/libsteticui/WidgetDesigner.cs  2006-09-22 21:51:17 UTC (rev 
65825)
@@ -10,7 +10,6 @@
                Component selection;
                Component rootWidget;
                
-               string sessionData;
                Project project;
                Project editedProject;
                int reloadCount;
@@ -21,6 +20,7 @@
                public event EventHandler BindField;
                public event EventHandler ModifiedChanged;
                public event EventHandler SelectionChanged;
+               public event EventHandler RootComponentChanged;
                public event ComponentSignalEventHandler SignalAdded;
                public event ComponentSignalEventHandler SignalRemoved;
                public event ComponentSignalEventHandler SignalChanged;
@@ -99,6 +99,11 @@
                        session.CreateWrapperWidgetPlug (socketId);
                }
                
+               protected override void OnDestroyPlug (uint socketId)
+               {
+                       session.DestroyWrapperWidgetPlug ();
+               }
+               
                protected override Gtk.Widget OnCreateWidget ()
                {
                        return session.WrapperWidget;
@@ -146,10 +151,11 @@
                        if (!autoCommitChanges)
                                editedProject.Dispose ();
 
-                       System.Runtime.Remoting.RemotingServices.Disconnect 
(frontend);
                        if (session != null)
                                session.Dispose ();
                        base.Dispose ();
+
+                       System.Runtime.Remoting.RemotingServices.Disconnect 
(frontend);
                }
                
                public void Save ()
@@ -168,32 +174,46 @@
                {
                        rootWidget = app.GetComponent (session.RootWidget, 
null, null);
                        UpdateWidget ();
+                       if (RootComponentChanged != null)
+                               RootComponentChanged (this, EventArgs.Empty);
                }
                
-               protected override void OnBackendChanging ()
+               internal override void OnBackendChanging ()
                {
                        reloadCount = 0;
-                       if (!autoCommitChanges)
-                               sessionData = session.SaveState ();
-                       if (session != null)
-                               session.Dispose ();
-                       session = null;
                        base.OnBackendChanging ();
                }
                
-               protected override void OnBackendChanged ()
+               internal override void OnBackendChanged (ApplicationBackend 
oldBackend)
                {
                        // Can't do anything until the projects are reloaded
                        // This is checked in OnProjectBackendChanged.
                }
                
-               void OnProjectBackendChanged (object s, EventArgs a)
+               void OnProjectBackendChanged (ApplicationBackend oldBackend)
                {
                        if (++reloadCount == 2) {
+                               object sessionData = null;
+                               
+                               if (oldBackend != null && !autoCommitChanges) {
+                                       sessionData = session.SaveState ();
+                                       session.DestroyWrapperWidgetPlug ();
+                               }
+
+                               // Don't dispose the session here, since it 
will dispose
+                               // the underlying project, and we can't do it 
because
+                               // it may need to process the OnBackendChanging 
event
+                               // as well.
+                       
                                CreateSession ();
+                               
                                if (sessionData != null && session != null)
                                        session.RestoreState (sessionData);
-                               base.OnBackendChanged ();
+
+                               base.OnBackendChanged (oldBackend);
+                               
+                               if (RootComponentChanged != null)
+                                       RootComponentChanged (this, 
EventArgs.Empty);
                        }
                }
                

Modified: trunk/stetic/libsteticui/WidgetDesignerBackend.cs
===================================================================
--- trunk/stetic/libsteticui/WidgetDesignerBackend.cs   2006-09-22 18:00:01 UTC 
(rev 65824)
+++ trunk/stetic/libsteticui/WidgetDesignerBackend.cs   2006-09-22 21:51:17 UTC 
(rev 65825)
@@ -134,6 +134,8 @@
                
                public override void Dispose ()
                {
+                       if (preview == null)
+                               return;
                        if (wrapper != null)
                                wrapper.DetachDesigner (resizableFixed);
                        preview.SizeAllocated -= new Gtk.SizeAllocatedHandler 
(OnResized);

Modified: trunk/stetic/libsteticui/WidgetEditSession.cs
===================================================================
--- trunk/stetic/libsteticui/WidgetEditSession.cs       2006-09-22 18:00:01 UTC 
(rev 65824)
+++ trunk/stetic/libsteticui/WidgetEditSession.cs       2006-09-22 21:51:17 UTC 
(rev 65825)
@@ -144,6 +144,15 @@
                        Gdk.Threads.Leave ();
                }
                
+               public void DestroyWrapperWidgetPlug ()
+               {
+                       if (designer != null) {
+                               Gtk.Plug plug = (Gtk.Plug) WrapperWidget.Parent;
+                               plug.Remove (WrapperWidget);
+                               plug.Destroy ();
+                       }
+               }
+               
                public void Save ()
                {
                        if (!autoCommitChanges) {
@@ -170,6 +179,7 @@
                        if (toolbar != null)
                                toolbar.Destroy ();
                        
+                       gproject.ProjectReloaded -= new EventHandler 
(OnProjectReloaded);
 //                     gproject.WidgetMemberNameChanged -= new 
Stetic.Wrapper.WidgetNameChangedHandler (OnWidgetNameChanged);
                        
                        if (!autoCommitChanges) {
@@ -188,6 +198,7 @@
                                plug.Destroy ();
                        gproject = null;
                        rootWidget = null;
+                       frontend = null;
                        System.Runtime.Remoting.RemotingServices.Disconnect 
(this);
                }
 
@@ -208,7 +219,8 @@
                
                void OnModifiedChanged (object s, EventArgs a)
                {
-                       frontend.NotifyModifiedChanged ();
+                       if (frontend != null)
+                               frontend.NotifyModifiedChanged ();
                }
                
                void OnProjectReloaded (object s, EventArgs a)
@@ -260,12 +272,12 @@
                                frontend.NotifySelectionChanged 
(Component.GetSafeReference (ObjectWrapper.Lookup (widget.Selection)));
                }
                
-               public string SaveState ()
+               public object SaveState ()
                {
                        return null;
                }
                
-               public void RestoreState (string stateData)
+               public void RestoreState (object sessionData)
                {
                }
        }

Modified: trunk/stetic/libsteticui/WidgetPropertyTree.cs
===================================================================
--- trunk/stetic/libsteticui/WidgetPropertyTree.cs      2006-09-22 18:00:01 UTC 
(rev 65824)
+++ trunk/stetic/libsteticui/WidgetPropertyTree.cs      2006-09-22 21:51:17 UTC 
(rev 65825)
@@ -15,6 +15,11 @@
                        app.Backend.CreatePropertiesWidgetPlug (socketId);
                }
                
+               protected override void OnDestroyPlug (uint socketId)
+               {
+                       app.Backend.DestroyPropertiesWidgetPlug ();
+               }
+               
                protected override Gtk.Widget OnCreateWidget ()
                {
                        return app.Backend.GetPropertiesWidget ();

Modified: trunk/stetic/stetic/DesignerView.cs
===================================================================
--- trunk/stetic/stetic/DesignerView.cs 2006-09-22 18:00:01 UTC (rev 65824)
+++ trunk/stetic/stetic/DesignerView.cs 2006-09-22 21:51:17 UTC (rev 65825)
@@ -9,9 +9,12 @@
        {
                Gtk.Widget design;
                Gtk.Widget actionbox;
+               Component widget;
                
                public DesignerView (Stetic.Project project, Component widget)
                {
+                       this.widget = widget;
+
                        // Widget design tab
                        
                        design = project.CreateWidgetDesigner (widget, true);
@@ -27,6 +30,10 @@
                        TabPos = Gtk.PositionType.Bottom;
                }
                
+               public Component Component {
+                       get { return widget; }
+               }
+               
                public override void Dispose ()
                {
                        base.Dispose ();

Modified: trunk/stetic/stetic/Stetic.cs
===================================================================
--- trunk/stetic/stetic/Stetic.cs       2006-09-22 18:00:01 UTC (rev 65824)
+++ trunk/stetic/stetic/Stetic.cs       2006-09-22 21:51:17 UTC (rev 65825)
@@ -35,7 +35,7 @@
                public static int Main (string[] args)
                {
                        int n = 0;
-                       IsolationMode mode = IsolationMode.None; // 
IsolationMode.ProcessUnix;
+                       IsolationMode mode = IsolationMode.ProcessUnix;
                        
                        while (n < args.Length) {
                                string arg = args[n];
@@ -111,6 +111,7 @@
                        Project.ComponentRemoved += OnWidgetRemoved;
                        Project.SelectionChanged += OnSelectionChanged;
                        Project.ModifiedChanged += OnProjectModified;
+                       Project.ProjectReloaded += OnProjectReloaded;
 
                        Palette = SteticApp.PaletteWidget;
                        ProjectView = SteticApp.ProjectWidget;
@@ -225,6 +226,31 @@
                        MainWindow.Title = title;
                }
                
+               static void OnProjectReloaded (object sender, EventArgs a)
+               {
+                       if (WidgetNotebook.Page == -1)
+                               return;
+                       
+                       // Get the opened components
+                       
+                       int active = WidgetNotebook.Page;
+                       ArrayList pages = new ArrayList ();
+                       while (WidgetNotebook.NPages > 0) {
+                               DesignerView view = (DesignerView) 
WidgetNotebook.GetNthPage (0);
+                               pages.Add (view.Component.Name);
+                               WidgetNotebook.Remove (view);
+                       }
+                       openWindows.Clear ();
+                       
+                       // Reopen the components
+                       foreach (string s in pages) {
+                               Component w = Project.GetComponent (s);
+                               if (w != null)
+                                       OpenWindow (w);
+                       }
+                       WidgetNotebook.Page = active;
+               }
+               
                static bool IsWindowOpen (Component component)
                {
                        Gtk.Widget w = openWindows [component] as Gtk.Widget;

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

Reply via email to