[Monodevelop-patches-list] r1191 - in trunk/MonoDevelop: . src/Main/Base/Commands src/Main/Base/Gui src/Main/Base/Gui/Workbench src/Main/Base/Gui/Workbench/Layouts

commit-watcher at mono-cvs.ximian.com commit-watcher at mono-cvs.ximian.com
Thu Mar 18 20:49:56 EST 2004


Author: ggiraldez
Date: 2004-03-18 20:49:56 -0500 (Thu, 18 Mar 2004)
New Revision: 1191

Modified:
   trunk/MonoDevelop/ChangeLog
   trunk/MonoDevelop/src/Main/Base/Commands/MenuItemBuilders.cs
   trunk/MonoDevelop/src/Main/Base/Gui/IWorkbench.cs
   trunk/MonoDevelop/src/Main/Base/Gui/IWorkbenchLayout.cs
   trunk/MonoDevelop/src/Main/Base/Gui/Workbench/DefaultWorkbench.cs
   trunk/MonoDevelop/src/Main/Base/Gui/Workbench/Layouts/SdiWorkspaceLayout.cs
Log:
2004-03-18  Gustavo Gir?\195?\161ldez  <gustavo.giraldez at gmx.net>

	* src/Main/Base/Gui/IWorkbench.cs: Added WorkbenchContext enum,
	Context property and ContextChanged event.

	* src/Main/Base/Gui/IWorkbenchLayout.cs: Added CurrentLayout
	and PadContentCollection properties.

	* src/Main/Base/Gui/Workbench/DefaultWorkbench.cs: Connect to the
	debugging service's StartedEvent, and switch workbench context
	whenever debugging is started or stopped.

	* src/Main/Base/Gui/Workbench/Layouts/SdiWorkspaceLayout.cs: Added
	layout switching functionality.  Connect to the IWorkbench's new
	ContextChanged event and switch layouts when starting/stopping
	debug.  Provide a collection of valid content pads for the current
	workbench context.

	* src/Main/Base/Commands/MenuItemBuilders.cs: Take the collection
	of content pads from the layout.



Modified: trunk/MonoDevelop/ChangeLog
===================================================================
--- trunk/MonoDevelop/ChangeLog	2004-03-18 23:26:45 UTC (rev 1190)
+++ trunk/MonoDevelop/ChangeLog	2004-03-19 01:49:56 UTC (rev 1191)
@@ -1,3 +1,24 @@
+2004-03-18  Gustavo Giráldez  <gustavo.giraldez at gmx.net>
+
+	* src/Main/Base/Gui/IWorkbench.cs: Added WorkbenchContext enum,
+	Context property and ContextChanged event.
+
+	* src/Main/Base/Gui/IWorkbenchLayout.cs: Added CurrentLayout
+	and PadContentCollection properties.
+
+	* src/Main/Base/Gui/Workbench/DefaultWorkbench.cs: Connect to the
+	debugging service's StartedEvent, and switch workbench context
+	whenever debugging is started or stopped.
+
+	* src/Main/Base/Gui/Workbench/Layouts/SdiWorkspaceLayout.cs: Added
+	layout switching functionality.  Connect to the IWorkbench's new
+	ContextChanged event and switch layouts when starting/stopping
+	debug.  Provide a collection of valid content pads for the current
+	workbench context.
+
+	* src/Main/Base/Commands/MenuItemBuilders.cs: Take the collection
+	of content pads from the layout.
+
 2004-03-17	John BouAntoun  <jba-mono at optusnet.com.au>
 	
 	* src/Main/Base/Commands/MenuItemBuilders.cs:

Modified: trunk/MonoDevelop/src/Main/Base/Commands/MenuItemBuilders.cs
===================================================================
--- trunk/MonoDevelop/src/Main/Base/Commands/MenuItemBuilders.cs	2004-03-18 23:26:45 UTC (rev 1190)
+++ trunk/MonoDevelop/src/Main/Base/Commands/MenuItemBuilders.cs	2004-03-19 01:49:56 UTC (rev 1191)
@@ -347,9 +347,15 @@
 		public Gtk.MenuItem[] BuildSubmenu(ConditionCollection conditionCollection, object owner)
 		{
 			ArrayList items = new ArrayList();
-			foreach (IPadContent padContent in WorkbenchSingleton.Workbench.PadContentCollection) {
-				items.Add(new MyMenuItem(padContent));
+			IWorkbench wb = WorkbenchSingleton.Workbench;
+			if (wb.WorkbenchLayout != null)
+			{
+				PadContentCollection pads = wb.WorkbenchLayout.PadContentCollection;
+				foreach (IPadContent padContent in pads) {
+					items.Add(new MyMenuItem(padContent));
+				}
 			}
+			
 			return (Gtk.MenuItem[])items.ToArray(typeof(Gtk.MenuItem));
 		}
 	}

Modified: trunk/MonoDevelop/src/Main/Base/Gui/IWorkbench.cs
===================================================================
--- trunk/MonoDevelop/src/Main/Base/Gui/IWorkbench.cs	2004-03-18 23:26:45 UTC (rev 1190)
+++ trunk/MonoDevelop/src/Main/Base/Gui/IWorkbench.cs	2004-03-19 01:49:56 UTC (rev 1191)
@@ -10,6 +10,12 @@
 
 namespace MonoDevelop.Gui
 {
+	public enum WorkbenchContext
+	{
+		Edit,
+		Debug
+	}
+	
 	/// <summary>
 	/// This is the basic interface to the workspace.
 	/// </summary>
@@ -89,5 +95,17 @@
 		/// the foreground (e.g. editable) changed to a new one.
 		/// </summary>
 		event EventHandler ActiveWorkbenchWindowChanged;
+
+		/// <summary>
+		/// The context the workbench is currently in
+		/// </summary>
+		WorkbenchContext Context {
+			get;
+		}
+		
+		/// <summary>
+		/// Called when the Context property changes
+		/// </summary>
+		event EventHandler ContextChanged;
 	}
 }

Modified: trunk/MonoDevelop/src/Main/Base/Gui/IWorkbenchLayout.cs
===================================================================
--- trunk/MonoDevelop/src/Main/Base/Gui/IWorkbenchLayout.cs	2004-03-18 23:26:45 UTC (rev 1190)
+++ trunk/MonoDevelop/src/Main/Base/Gui/IWorkbenchLayout.cs	2004-03-19 01:49:56 UTC (rev 1191)
@@ -30,6 +30,11 @@
 		IWorkbenchWindow ActiveWorkbenchwindow {
 			get;
 		}
+
+		string CurrentLayout {
+			get;
+			set;
+		}
 		
 		/// <summary>
 		/// Attaches this layout manager to a workbench object.
@@ -79,5 +84,12 @@
 		/// the foreground (e.g. editable) changed to a new one.
 		/// </summary>
 		event EventHandler ActiveWorkbenchWindowChanged;
+
+		/// <summary>
+		/// A collection of all valid pads in the layout for the workbench context.
+		/// </summary>
+		PadContentCollection PadContentCollection {
+			get;
+		}
 	}
 }

Modified: trunk/MonoDevelop/src/Main/Base/Gui/Workbench/DefaultWorkbench.cs
===================================================================
--- trunk/MonoDevelop/src/Main/Base/Gui/Workbench/DefaultWorkbench.cs	2004-03-18 23:26:45 UTC (rev 1190)
+++ trunk/MonoDevelop/src/Main/Base/Gui/Workbench/DefaultWorkbench.cs	2004-03-19 01:49:56 UTC (rev 1191)
@@ -85,10 +85,10 @@
 		public IWorkbenchLayout WorkbenchLayout {
 			get {
 				//FIXME: i added this, we need to fix this shit
-				if (layout == null) {
-					layout = new SdiWorkbenchLayout ();
-					layout.Attach(this);
-				}
+				//				if (layout == null) {
+				//	layout = new SdiWorkbenchLayout ();
+				//	layout.Attach(this);
+				//}
 				return layout;
 			}
 			set {
@@ -142,11 +142,18 @@
 			this.WindowPosition = Gtk.WindowPosition.None;
 
 			DebuggingService dbgr = (DebuggingService)ServiceManager.Services.GetService (typeof (DebuggingService));
+			dbgr.StartedEvent += new EventHandler (onDebuggerStarted);
 			dbgr.PausedEvent += new EventHandler (onDebuggerPaused);
 			dbgr.ResumedEvent += new EventHandler (onDebuggerResumed);		
 			dbgr.StoppedEvent += new EventHandler (onDebuggerStopped);		
 		}
 
+		void onDebuggerStarted (object o, EventArgs e)
+		{
+			context = WorkbenchContext.Debug;
+			ContextChanged (this, new EventArgs());
+		}
+		
 		void onDebuggerPaused (object o, EventArgs e)
 		{
 			DebuggingService dbgr = (DebuggingService)ServiceManager.Services.GetService (typeof (DebuggingService));
@@ -176,7 +183,9 @@
 					((IDebuggableEditor)content).ClearExecutingAt (cur_dbgLineNumber);
 					break;
 				}
-			}	
+			}
+			context = WorkbenchContext.Edit;
+			ContextChanged (this, new EventArgs());
 		}
 		
 		public void InitializeWorkspace()
@@ -690,6 +699,17 @@
 #endif
 		
 		public event EventHandler ActiveWorkbenchWindowChanged;
+
+		/// Context switching specific parts
+		WorkbenchContext context = WorkbenchContext.Edit;
+		
+		public WorkbenchContext Context {
+			get {
+				return context;
+			}
+		}
+
+		public event EventHandler ContextChanged;
 	}
 }
 

Modified: trunk/MonoDevelop/src/Main/Base/Gui/Workbench/Layouts/SdiWorkspaceLayout.cs
===================================================================
--- trunk/MonoDevelop/src/Main/Base/Gui/Workbench/Layouts/SdiWorkspaceLayout.cs	2004-03-18 23:26:45 UTC (rev 1190)
+++ trunk/MonoDevelop/src/Main/Base/Gui/Workbench/Layouts/SdiWorkspaceLayout.cs	2004-03-19 01:49:56 UTC (rev 1191)
@@ -29,6 +29,7 @@
 	{
 		static PropertyService propertyService = (PropertyService)ServiceManager.Services.GetService(typeof(PropertyService));
 		static string configFile = propertyService.ConfigDirectory + "DefaultEditingLayout.xml";
+		private string currentLayout = "";
 
 		private IWorkbench workbench;
 		Window wbWindow;
@@ -37,9 +38,14 @@
 		Dock dock;
 		DockLayout dockLayout;
 		Notebook tabControl;
+		EventHandler contextChangedHandler;
 
 		ArrayList _windows = new ArrayList ();
 
+		public SdiWorkbenchLayout () {
+			contextChangedHandler = new EventHandler (onContextChanged);
+		}
+		
 		public IWorkbenchWindow ActiveWorkbenchwindow {
 			get {
 				if (tabControl == null || tabControl.CurrentPage < 0 || tabControl.CurrentPage >= tabControl.NPages)  {
@@ -95,88 +101,171 @@
 			
 			foreach (IViewContent content in workbench.ViewContentCollection)
 				ShowView (content);
-			
+
+			// create DockItems for all the pads
 			foreach (IPadContent content in workbench.PadContentCollection)
-				ShowPad (content);
+			{
+				item = new DockItem (content.ToString (),
+				                     content.Title,
+				                     content.Icon,
+				                     DockItemBehavior.Normal);
+				item.Add (content.Control);
+				item.ShowAll ();
+				dock.AddItem (item, DockPlacement.Left);
+			}
+			// by default, the active pad collection is the full set
+			activePadCollection = workbench.PadContentCollection;
 
 			// FIXME: GTKize
 			//tabControl.SwitchPage += new EventHandler(ActiveMdiChanged);
 			//tabControl.SelectionChanged += new EventHandler(ActiveMdiChanged);
 			
 			CreateDefaultLayout();
-			RedrawAllComponents();
+			//RedrawAllComponents();
 			wbWindow.ShowAll ();
+
+			workbench.ContextChanged += contextChangedHandler;
 		}
 
+		void onContextChanged (object o, EventArgs e)
+		{
+			WorkbenchContext ctxt = workbench.Context;
+			Console.WriteLine ("Workbench changed context to " + ctxt);
+			SwitchContext (ctxt);
+		}
+
+		void SwitchContext (WorkbenchContext ctxt)
+		{
+			PadContentCollection old = activePadCollection;
+			
+			// switch pad collections
+			if (padCollections [ctxt] != null)
+				activePadCollection = (PadContentCollection) padCollections [ctxt];
+			else
+				// this is so, for unkwown contexts, we get the full set of pads
+				activePadCollection = workbench.PadContentCollection;
+
+			switch (ctxt)
+			{
+			case WorkbenchContext.Debug:
+				CurrentLayout = "Debug";
+				break;
+
+			default:
+			case WorkbenchContext.Edit:
+				CurrentLayout = "Default";
+				break;
+
+			}
+			
+			// make sure invalid pads for the new context are not visible
+			foreach (IPadContent content in old)
+			{
+				if (!activePadCollection.Contains (content))
+				{
+					DockItem item = dock.GetItemByName (content.ToString ());
+					if (item != null)
+						item.HideItem ();
+				}
+			}
+		}
+		
 		public Gtk.Widget LayoutWidget {
 			get { return rootWidget; }
 		}
 		
-		Content GetContent(string padTypeName)
+		public string CurrentLayout {
+			get
+			{
+				return currentLayout;
+			}
+			set
+			{
+				if (currentLayout != "")
+					dockLayout.SaveLayout (currentLayout);
+				
+				currentLayout = value;
+
+				if (!dockLayout.LoadLayout (value))
+					// if the "Default" layout doesn't exists, load the real default
+					// so old layout xml files work smoothly
+					dockLayout.LoadLayout (null);
+			}
+		}
+
+		// pad collection for the current workbench context
+		PadContentCollection activePadCollection;
+
+		// set of PadContentCollection objects for the different workbench contexts
+		Hashtable padCollections = new Hashtable ();
+
+		public PadContentCollection PadContentCollection {
+			get {
+				return activePadCollection;
+			}
+		}
+		
+		DockItem GetDockItem (IPadContent content)
 		{
-			IPadContent pad = ((IWorkbench)wbWindow).PadContentCollection[padTypeName];
-			if (pad != null) {
-				return (Content)contentHash[pad];
+			if (activePadCollection.Contains (content))
+			{
+				DockItem item = dock.GetItemByName (content.ToString ());
+				return item;
 			}
 			return null;
 		}
 		
 		void CreateDefaultLayout()
 		{
-			//Console.WriteLine("Creating Default Layout...");
-			WindowContent leftContent   = null;
-			WindowContent rightContent  = null;
-			WindowContent bottomContent = null;
-			
-			string[] leftContents = new string[] {
-				"MonoDevelop.Gui.Pads.HelpTree",
+			string[] commonPads = new string[] {
 				"MonoDevelop.Gui.Pads.ProjectBrowser.ProjectBrowserView",
 				"MonoDevelop.Gui.Pads.ClassScout",
 				"MonoDevelop.Gui.Pads.FileScout",
-				"MonoDevelop.Gui.Pads.SideBarView"
-			};
-			string[] rightContents = new string[] {
+				"MonoDevelop.Gui.Pads.SideBarView",
 				"MonoDevelop.Gui.Pads.PropertyPad",
+				"MonoDevelop.Gui.Pads.OpenTaskView",
+				"MonoDevelop.Gui.Pads.HelpTree",
+				"MonoDevelop.EditorBindings.Gui.Pads.CompilerMessageView",
 				"MonoDevelop.Gui.Pads.HelpBrowser"
 			};
-			string[] bottomContents = new string[] {
-				"MonoDevelop.Gui.Pads.OpenTaskView",
-				"MonoDevelop.EditorBindings.Gui.Pads.CompilerMessageView",
+
+			string[] debugPads = new string[] {
 				"MonoDevelop.SourceEditor.Gui.DebuggerLocalsPad"
 			};
+
+			string[] editPads = new string[] {
+			};
+
+			PadContentCollection collection;
 			
-			foreach (string typeName in leftContents) {
-				Content c = GetContent (typeName);
-				if (c != null) {
-					DockItem item = new DockItem (typeName, c.Title, c.Image,
-								      DockItemBehavior.Normal);
-					item.Add (c.Widget);
-					item.ShowAll ();
-					dock.AddItem (item, DockPlacement.Left);
+			foreach (WorkbenchContext ctxt in Enum.GetValues (typeof (WorkbenchContext)))
+			{
+				collection = new PadContentCollection ();
+				padCollections [ctxt] = collection;
+				foreach (string padTypeName in commonPads)
+				{
+					IPadContent pad = workbench.PadContentCollection [padTypeName];
+					if (pad != null)
+						collection.Add (pad);
 				}
 			}
 			
-			foreach (string typeName in bottomContents) {
-				Content c = GetContent (typeName);
-				if (c != null) {
-					DockItem item = new DockItem (typeName, c.Title, c.Image,
-								      DockItemBehavior.Normal);
-					item.Add (c.Widget);
-					item.ShowAll ();
-					dock.AddItem (item, DockPlacement.Bottom);
-				}
+			collection = (PadContentCollection) padCollections [WorkbenchContext.Edit];
+			foreach (string padTypeName in editPads)
+			{
+				IPadContent pad = workbench.PadContentCollection [padTypeName];
+				if (pad != null)
+					collection.Add (pad);
 			}
-			
-			foreach (string typeName in rightContents) {
-				Content c = GetContent (typeName);
-				if (c != null) {
-					DockItem item = new DockItem (typeName, c.Title, c.Image,
-								      DockItemBehavior.Normal);
-					item.Add (c.Widget);
-					item.ShowAll ();
-					dock.AddItem (item, DockPlacement.Right);
-				}
+				
+			collection = (PadContentCollection) padCollections [WorkbenchContext.Debug];
+			foreach (string padTypeName in debugPads)
+			{
+				IPadContent pad = workbench.PadContentCollection [padTypeName];
+				if (pad != null)
+					collection.Add (pad);
 			}
+				
 			//Console.WriteLine(" Default Layout created.");
 			dockLayout = new DockLayout (dock);
 			if (File.Exists (configFile)) {
@@ -184,12 +273,16 @@
 			} else {
 				dockLayout.LoadFromFile ("../data/options/DefaultEditingLayout.xml");
 			}
-			dockLayout.LoadLayout ("__default__");
-		}		
+			
+			SwitchContext (workbench.Context);
+		}
 
 		public void Detach()
 		{
+			workbench.ContextChanged -= contextChangedHandler;
+
 			//Console.WriteLine("Call to SdiWorkSpaceLayout.Detach");
+			dockLayout.SaveLayout (currentLayout);
 			dockLayout.SaveToFile (configFile);
 			rootWidget.Remove(((DefaultWorkbench)workbench).TopMenu);
 			foreach (Gtk.Widget w in toolbarContainer.Children) {
@@ -197,98 +290,44 @@
 			}
 			rootWidget.Remove(toolbarContainer);
 			wbWindow.Remove(rootWidget);
+			activePadCollection = null;
 		}
 
-		Hashtable contentHash = new Hashtable();
-		
-	
 		public void ShowPad (IPadContent content)
 		{
-			if (contentHash[content] == null) {
-				/*DockItem item = new DockItem (content.Title,
-							      content.Title,
-							      DockItemBehavior.Normal);
-				item.Add (content.Control);
-				item.ShowAll ();
-				dock.AddItem (item, DockPlacement.Top);*/
-			
-				/*IProperties properties = (IProperties)propertyService.GetProperty("Workspace.ViewMementos", new DefaultProperties());
-				//content.Control.Dock = DockStyle.None;
-				Content newContent;
-				if (content.Icon != null) {
-					//ImageList imgList = new ImageList();
-					//imgList.ColorDepth = ColorDepth.Depth32Bit;
-					//IconService iconService = (IconService)ServiceManager.Services.GetService(typeof(IconService));
-					//imgList.Images.Add(iconService.GetBitmap(content.Icon));
-					//newContent = dockManager.Contents.Add(content.Control, content.Title, imgList, 0);
-					//newContent = dockManager.Contents.Add(content.Control, content.Title, iconService.GetBitmap(content.Icon));
-				} else {
-					//newContent = dockManager.Contents.Add(content.Control, content.Title);
-				}*/
-				contentHash[content] = new Content (content.Control, content.Title, content.Icon);
-			} else {
-				Content c = (Content)contentHash[content];
-				if (c != null) {
-					DockItem item = dock.GetItemByName (content.ToString ());
-					item.ShowItem ();
-				}
-			}
+			DockItem item = GetDockItem (content);
+			if (item != null)
+				item.ShowItem();
 		}
 		
-		public bool IsVisible(IPadContent padContent)
+		public bool IsVisible (IPadContent padContent)
 		{
-			if (padContent != null) {
-				Content content = (Content)contentHash[padContent];
-				if (content != null) {
-					DockItem item = dock.GetItemByName (padContent.ToString ());
-					if (item != null) {
-						return item.IsAttached;
-					}
-				}
-			}
-
+			DockItem item = GetDockItem (padContent);
+			if (item != null)
+				return item.IsAttached;
 			return false;
 		}
 		
-		public void HidePad(IPadContent padContent)
+		public void HidePad (IPadContent padContent)
 		{
-			// FIXME: GTKize
-
-			if (padContent != null) {
-				Content content = (Content)contentHash[padContent];
-				if (content != null) {
-					DockItem item = dock.GetItemByName (padContent.ToString ());
-					item.HideItem ();
-				}
-			}
-
+			DockItem item = GetDockItem (padContent);
+			if (item != null)
+				item.HideItem();
 		}
 		
-		public void ActivatePad(IPadContent padContent)
+		public void ActivatePad (IPadContent padContent)
 		{
-			// FIXME: GTKize
-
-			if (padContent != null) {
-				Content content = (Content)contentHash[padContent];
-				if (content != null) {
-					content.BringToFront();
-				}
-			}
+			DockItem item = GetDockItem (padContent);
+			if (item != null)
+				item.Present (null);
 		}
 		
 		public void RedrawAllComponents()
 		{
-			// FIXME: GTKize
-
-			//tabControl.Style = (Crownwood.Magic.Common.VisualStyle)propertyService.GetProperty("MonoDevelop.Gui.TabVisualStyle", Crownwood.Magic.Common.VisualStyle.IDE);
-
-			// redraw correct pad content names (language changed).
-			//foreach (IPadContent content in ((IWorkbench)wbForm).PadContentCollection) {
 			foreach (IPadContent content in ((IWorkbench)workbench).PadContentCollection) {
-				Content c = (Content)contentHash[content];
-				if (c != null) {
-					c.Title = c.FullTitle = content.Title;
-				}
+				DockItem item = dock.GetItemByName (content.ToString ());
+				if (item != null)
+					item.LongName = content.Title;
 			}
 		}
 		




More information about the Monodevelop-patches-list mailing list