[Monodevelop-patches-list] r648 - in trunk/MonoDevelop: data/resources/glade src/AddIns/DisplayBindings/TextEditor src/AddIns/DisplayBindings/TextEditor/Gui/Dialogs src/AddIns/DisplayBindings/TextEditor/Gui/OptionPanels src/Main/Base/Gui/Dialogs/OptionPanels

commit-watcher at mono-cvs.ximian.com commit-watcher at mono-cvs.ximian.com
Sun Jan 25 07:36:15 EST 2004


Author: jba
Date: 2004-01-25 07:36:14 -0500 (Sun, 25 Jan 2004)
New Revision: 648

Added:
   trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Gui/Dialogs/EditTemplateGroupDialog.cs
Modified:
   trunk/MonoDevelop/data/resources/glade/texteditoraddin.glade
   trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Gui/OptionPanels/CodeTemplatePanel.cs
   trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Makefile
   trunk/MonoDevelop/src/Main/Base/Gui/Dialogs/OptionPanels/EditTemplateDialog.cs
Log:
finished the code templates dialog finally. need to make the accept buttons defaults on the dialogs though

Modified: trunk/MonoDevelop/data/resources/glade/texteditoraddin.glade
===================================================================
--- trunk/MonoDevelop/data/resources/glade/texteditoraddin.glade	2004-01-25 08:16:43 UTC (rev 647)
+++ trunk/MonoDevelop/data/resources/glade/texteditoraddin.glade	2004-01-25 12:36:14 UTC (rev 648)
@@ -2,7 +2,6 @@
 <!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">
 
 <glade-interface>
-<requires lib="gnome"/>
 
 <widget class="GtkDialog" id="GotoLineDialog">
   <property name="visible">True</property>
@@ -172,4 +171,275 @@
   </child>
 </widget>
 
+<widget class="GtkWindow" id="CodeTemplatePane">
+  <property name="visible">True</property>
+  <property name="title" translatable="yes">CodeTemplatePane</property>
+  <property name="type">GTK_WINDOW_TOPLEVEL</property>
+  <property name="window_position">GTK_WIN_POS_NONE</property>
+  <property name="modal">False</property>
+  <property name="resizable">True</property>
+  <property name="destroy_with_parent">False</property>
+
+  <child>
+    <widget class="GtkVBox" id="vbox13">
+      <property name="border_width">12</property>
+      <property name="visible">True</property>
+      <property name="homogeneous">False</property>
+      <property name="spacing">6</property>
+
+      <child>
+	<widget class="GtkTable" id="table2">
+	  <property name="visible">True</property>
+	  <property name="n_rows">2</property>
+	  <property name="n_columns">2</property>
+	  <property name="homogeneous">False</property>
+	  <property name="row_spacing">6</property>
+	  <property name="column_spacing">6</property>
+
+	  <child>
+	    <widget class="GtkLabel" id="extensionLabel">
+	      <property name="visible">True</property>
+	      <property name="label" translatable="yes">extensionLabel</property>
+	      <property name="use_underline">True</property>
+	      <property name="use_markup">False</property>
+	      <property name="justify">GTK_JUSTIFY_LEFT</property>
+	      <property name="wrap">False</property>
+	      <property name="selectable">False</property>
+	      <property name="xalign">0</property>
+	      <property name="yalign">0.5</property>
+	      <property name="xpad">0</property>
+	      <property name="ypad">0</property>
+	      <property name="mnemonic_widget">groupOptionMenu</property>
+	    </widget>
+	    <packing>
+	      <property name="left_attach">0</property>
+	      <property name="right_attach">1</property>
+	      <property name="top_attach">0</property>
+	      <property name="bottom_attach">1</property>
+	      <property name="x_options">fill</property>
+	      <property name="y_options"></property>
+	    </packing>
+	  </child>
+
+	  <child>
+	    <widget class="GtkHBox" id="hbox8">
+	      <property name="visible">True</property>
+	      <property name="homogeneous">False</property>
+	      <property name="spacing">6</property>
+
+	      <child>
+		<widget class="GtkButton" id="addGroupButton">
+		  <property name="visible">True</property>
+		  <property name="can_focus">True</property>
+		  <property name="label" translatable="yes">button6</property>
+		  <property name="use_underline">True</property>
+		  <property name="relief">GTK_RELIEF_NORMAL</property>
+		</widget>
+		<packing>
+		  <property name="padding">0</property>
+		  <property name="expand">False</property>
+		  <property name="fill">False</property>
+		</packing>
+	      </child>
+
+	      <child>
+		<widget class="GtkButton" id="editGroupButton">
+		  <property name="visible">True</property>
+		  <property name="can_focus">True</property>
+		  <property name="label" translatable="yes">button1</property>
+		  <property name="use_underline">True</property>
+		  <property name="relief">GTK_RELIEF_NORMAL</property>
+		</widget>
+		<packing>
+		  <property name="padding">0</property>
+		  <property name="expand">False</property>
+		  <property name="fill">False</property>
+		</packing>
+	      </child>
+
+	      <child>
+		<widget class="GtkButton" id="removeGroupButton">
+		  <property name="visible">True</property>
+		  <property name="can_focus">True</property>
+		  <property name="label" translatable="yes">button2</property>
+		  <property name="use_underline">True</property>
+		  <property name="relief">GTK_RELIEF_NORMAL</property>
+		</widget>
+		<packing>
+		  <property name="padding">0</property>
+		  <property name="expand">False</property>
+		  <property name="fill">False</property>
+		</packing>
+	      </child>
+	    </widget>
+	    <packing>
+	      <property name="left_attach">1</property>
+	      <property name="right_attach">2</property>
+	      <property name="top_attach">1</property>
+	      <property name="bottom_attach">2</property>
+	      <property name="x_options">fill</property>
+	    </packing>
+	  </child>
+
+	  <child>
+	    <widget class="GtkOptionMenu" id="groupOptionMenu">
+	      <property name="visible">True</property>
+	      <property name="can_focus">True</property>
+	      <property name="history">-1</property>
+	    </widget>
+	    <packing>
+	      <property name="left_attach">1</property>
+	      <property name="right_attach">2</property>
+	      <property name="top_attach">0</property>
+	      <property name="bottom_attach">1</property>
+	      <property name="x_options">fill</property>
+	      <property name="y_options"></property>
+	    </packing>
+	  </child>
+	</widget>
+	<packing>
+	  <property name="padding">0</property>
+	  <property name="expand">False</property>
+	  <property name="fill">True</property>
+	</packing>
+      </child>
+
+      <child>
+	<widget class="GtkHBox" id="hbox9">
+	  <property name="visible">True</property>
+	  <property name="homogeneous">False</property>
+	  <property name="spacing">6</property>
+
+	  <child>
+	    <widget class="GtkScrolledWindow" id="scrolledwindow3">
+	      <property name="visible">True</property>
+	      <property name="can_focus">True</property>
+	      <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+	      <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+	      <property name="shadow_type">GTK_SHADOW_NONE</property>
+	      <property name="window_placement">GTK_CORNER_TOP_LEFT</property>
+
+	      <child>
+		<widget class="GtkTreeView" id="templateListView">
+		  <property name="visible">True</property>
+		  <property name="can_focus">True</property>
+		  <property name="headers_visible">True</property>
+		  <property name="rules_hint">False</property>
+		  <property name="reorderable">False</property>
+		  <property name="enable_search">True</property>
+		</widget>
+	      </child>
+	    </widget>
+	    <packing>
+	      <property name="padding">0</property>
+	      <property name="expand">True</property>
+	      <property name="fill">True</property>
+	    </packing>
+	  </child>
+
+	  <child>
+	    <widget class="GtkVBox" id="vbox14">
+	      <property name="visible">True</property>
+	      <property name="homogeneous">False</property>
+	      <property name="spacing">6</property>
+
+	      <child>
+		<widget class="GtkButton" id="removeButton">
+		  <property name="visible">True</property>
+		  <property name="can_focus">True</property>
+		  <property name="label" translatable="yes">button3</property>
+		  <property name="use_underline">True</property>
+		  <property name="relief">GTK_RELIEF_NORMAL</property>
+		</widget>
+		<packing>
+		  <property name="padding">0</property>
+		  <property name="expand">False</property>
+		  <property name="fill">False</property>
+		  <property name="pack_type">GTK_PACK_END</property>
+		</packing>
+	      </child>
+
+	      <child>
+		<widget class="GtkButton" id="editButton">
+		  <property name="visible">True</property>
+		  <property name="can_focus">True</property>
+		  <property name="label" translatable="yes">button4</property>
+		  <property name="use_underline">True</property>
+		  <property name="relief">GTK_RELIEF_NORMAL</property>
+		</widget>
+		<packing>
+		  <property name="padding">0</property>
+		  <property name="expand">False</property>
+		  <property name="fill">False</property>
+		  <property name="pack_type">GTK_PACK_END</property>
+		</packing>
+	      </child>
+
+	      <child>
+		<widget class="GtkButton" id="addButton">
+		  <property name="visible">True</property>
+		  <property name="can_focus">True</property>
+		  <property name="label" translatable="yes">button5</property>
+		  <property name="use_underline">True</property>
+		  <property name="relief">GTK_RELIEF_NORMAL</property>
+		</widget>
+		<packing>
+		  <property name="padding">0</property>
+		  <property name="expand">False</property>
+		  <property name="fill">False</property>
+		  <property name="pack_type">GTK_PACK_END</property>
+		</packing>
+	      </child>
+	    </widget>
+	    <packing>
+	      <property name="padding">0</property>
+	      <property name="expand">False</property>
+	      <property name="fill">True</property>
+	    </packing>
+	  </child>
+	</widget>
+	<packing>
+	  <property name="padding">0</property>
+	  <property name="expand">True</property>
+	  <property name="fill">True</property>
+	</packing>
+      </child>
+
+      <child>
+	<widget class="GtkScrolledWindow" id="scrolledwindow4">
+	  <property name="visible">True</property>
+	  <property name="can_focus">True</property>
+	  <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+	  <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+	  <property name="shadow_type">GTK_SHADOW_NONE</property>
+	  <property name="window_placement">GTK_CORNER_TOP_LEFT</property>
+
+	  <child>
+	    <widget class="GtkTextView" id="templateTextView">
+	      <property name="visible">True</property>
+	      <property name="can_focus">True</property>
+	      <property name="editable">True</property>
+	      <property name="justification">GTK_JUSTIFY_LEFT</property>
+	      <property name="wrap_mode">GTK_WRAP_NONE</property>
+	      <property name="cursor_visible">True</property>
+	      <property name="pixels_above_lines">0</property>
+	      <property name="pixels_below_lines">0</property>
+	      <property name="pixels_inside_wrap">0</property>
+	      <property name="left_margin">0</property>
+	      <property name="right_margin">0</property>
+	      <property name="indent">0</property>
+	      <property name="text" translatable="yes"></property>
+	    </widget>
+	  </child>
+	</widget>
+	<packing>
+	  <property name="padding">0</property>
+	  <property name="expand">True</property>
+	  <property name="fill">True</property>
+	</packing>
+      </child>
+    </widget>
+  </child>
+</widget>
+
 </glade-interface>

Added: trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Gui/Dialogs/EditTemplateGroupDialog.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Gui/Dialogs/EditTemplateGroupDialog.cs	2004-01-25 08:16:43 UTC (rev 647)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Gui/Dialogs/EditTemplateGroupDialog.cs	2004-01-25 12:36:14 UTC (rev 648)
@@ -0,0 +1,87 @@
+// <file>
+//     <copyright see="prj:///doc/copyright.txt"/>
+//     <license see="prj:///doc/license.txt"/>
+//     <owner name="Mike Krüger" email="mike at icsharpcode.net"/>
+//     <version value="$version"/>
+// </file>
+
+using System;
+using System.IO;
+
+using ICSharpCode.SharpDevelop.Internal.Templates;
+using ICSharpCode.Core.Services;
+
+namespace ICSharpCode.SharpDevelop.Gui.Dialogs
+{
+	public class EditTemplateGroupDialog : Gtk.Dialog 
+	{
+		CodeTemplateGroup codeTemplateGroup;
+		string titlePrefix = string.Empty;
+		
+		// Gtk members
+		Gtk.Entry templateExtensionsTextBox;		
+		
+		// Services
+		StringParserService StringParserService = (StringParserService)ServiceManager.Services.GetService (typeof (StringParserService));
+		
+		public CodeTemplateGroup CodeTemplateGroup {
+			get {
+				return codeTemplateGroup;
+			}
+		}
+		
+		public EditTemplateGroupDialog(CodeTemplateGroup codeTemplateGroup, string titlePrefix)
+		{
+			this.codeTemplateGroup = codeTemplateGroup;
+			this.titlePrefix = titlePrefix;
+			InitializeComponents();
+			this.ShowAll();
+		}
+		
+		void AcceptEvent(object sender, EventArgs e)
+		{
+			codeTemplateGroup.ExtensionStrings = templateExtensionsTextBox.Text.Split(';');
+			
+			// close the window
+			CancelEvent(sender, EventArgs.Empty);
+		}
+		
+		void CancelEvent(object sender, EventArgs e)
+		{
+			this.Destroy();
+		}
+		
+		void InitializeComponents()
+		{
+			// set up this actual dialog
+			this.Modal = true;
+			// FIXME: make this a resource in the resource file
+			this.Title = titlePrefix + "Code Group";
+			
+			// set up the dialog fields and add them
+			templateExtensionsTextBox = new Gtk.Entry();
+			templateExtensionsTextBox.ActivatesDefault = true;
+			// FIXME: make this a resource in the resource file
+			Gtk.Label label1 = new Gtk.Label("Extensions (; seperated)");
+			
+			label1.Xalign = 0;			
+			templateExtensionsTextBox.Text    = string.Join(";", codeTemplateGroup.ExtensionStrings);
+			
+			// FIXME: make the labels both part of the same sizing group so they have the same left and right rows.
+			Gtk.HBox hBox1 = new Gtk.HBox(false, 6);
+			hBox1.PackStart(label1, false, false, 6);
+			hBox1.PackStart(templateExtensionsTextBox, false, false, 6);
+			
+			this.VBox.PackStart(hBox1, false, false, 6);
+			
+			// set up the buttons and add them
+			this.DefaultResponse = (int) Gtk.ResponseType.Ok;
+			Gtk.Button cancelButton = new Gtk.Button(Gtk.Stock.Cancel);
+			Gtk.Button okButton = new Gtk.Button(Gtk.Stock.Ok);
+			okButton.Clicked += new EventHandler(AcceptEvent);
+			cancelButton.Clicked += new EventHandler(CancelEvent);
+			this.AddActionWidget (cancelButton, Gtk.ResponseType.Cancel);
+			this.AddActionWidget (okButton, (int) Gtk.ResponseType.Ok);
+		}
+	}
+}

Modified: trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Gui/OptionPanels/CodeTemplatePanel.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Gui/OptionPanels/CodeTemplatePanel.cs	2004-01-25 08:16:43 UTC (rev 647)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Gui/OptionPanels/CodeTemplatePanel.cs	2004-01-25 12:36:14 UTC (rev 648)
@@ -18,239 +18,396 @@
 
 using ICSharpCode.TextEditor;
 using ICSharpCode.TextEditor.Document;
+using ICSharpCode.SharpDevelop.Gui.Dialogs;
 
+using Gtk;
+using MonoDevelop.Gui;
+
 namespace ICSharpCode.SharpDevelop.Gui.Dialogs.OptionPanels 
 {
 	public class CodeTemplatePane : AbstractOptionPanel
-	{/*
-		ArrayList templateGroups;
-		int       currentSelectedGroup = -1;
-		
-		public CodeTemplateGroup CurrentTemplateGroup {
-			get {
-				if (currentSelectedGroup < 0 || currentSelectedGroup >= templateGroups.Count) {
-					return null;
+	{
+		class CodeTemplatePanelWidget : GladeWidgetExtract {
+			// members
+			ArrayList templateGroups;
+			int       currentSelectedGroup = -1;
+			
+			// Services
+			StringParserService StringParserService = (StringParserService)ServiceManager.Services.GetService (typeof (StringParserService));
+			PropertyService PropertyService = (PropertyService)ServiceManager.Services.GetService(typeof(PropertyService));
+			MessageService MessageService = (MessageService)ServiceManager.Services.GetService(typeof(MessageService));					
+			
+			// Gtk widgets
+			[Glade.Widget] Label extensionLabel;
+			[Glade.Widget] Gtk.TreeView templateListView;
+			ListStore templateListViewStore = new ListStore(typeof(CodeTemplate));
+			[Glade.Widget] Button removeButton;
+			[Glade.Widget] Button addButton;
+			[Glade.Widget] Button editButton;
+			[Glade.Widget] Button addGroupButton;
+			[Glade.Widget] Button editGroupButton;
+			[Glade.Widget] Button removeGroupButton;
+			TextBuffer templateTextBuffer = new TextBuffer(null);
+			[Glade.Widget] Gtk.TextView templateTextView;
+			[Glade.Widget] OptionMenu groupOptionMenu;
+			Menu groupMenu;
+			
+			public CodeTemplateGroup CurrentTemplateGroup {
+				get {
+					if (currentSelectedGroup < 0 || currentSelectedGroup >= templateGroups.Count) {
+						return null;
+					}
+					return (CodeTemplateGroup)templateGroups[currentSelectedGroup];
 				}
-				return (CodeTemplateGroup)templateGroups[currentSelectedGroup];
 			}
-		}
-		
-		public override void LoadPanelContents()
-		{
-			templateGroups = CodeTemplateLoader.TemplateGroups;
 			
-			SetupFromXml(Path.Combine(PropertyService.DataDirectory,
-			                          @"resources\panels\CodeTemplatePanel.xfrm"));
+			public ArrayList TemplateGroups {
+				get {
+					return this.templateGroups;
+				}
+			}
 			
-			ControlDictionary["removeButton"].Click += new System.EventHandler(RemoveEvent);
-			ControlDictionary["addButton"].Click    += new System.EventHandler(AddEvent);
-			ControlDictionary["editButton"].Click   += new System.EventHandler(EditEvent);
+			public CodeTemplatePanelWidget (ArrayList templateGroups) : base ("texteditoraddin.glade", "CodeTemplatePane")
+			{
+				this.templateGroups = templateGroups;
+				
+				SetLabels();
+				
+				// set up the treeview
+				templateListView.Reorderable = false;
+				templateListView.HeadersVisible = true;
+				templateListView.Selection.Mode = SelectionMode.Multiple;
+				templateListView.Model = templateListViewStore;
+				
+				// set up the text view
+				templateTextView.Buffer = templateTextBuffer;
+				//templateTextView.Font = new System.Drawing.Font("Courier New", 10f);
+				
+				// wire in the events
+				removeButton.Clicked += new System.EventHandler(RemoveEvent);
+				addButton.Clicked    += new System.EventHandler(AddEvent);
+				editButton.Clicked   += new System.EventHandler(EditEvent);
+				
+				addGroupButton.Clicked    += new System.EventHandler(AddGroupEvent);
+				editGroupButton.Clicked += new System.EventHandler(EditGroupEvent);
+				removeGroupButton.Clicked += new System.EventHandler(RemoveGroupEvent);
+				templateListView.RowActivated		+= new GtkSharp.RowActivatedHandler(RowActivatedEvent);
+				templateListView.Selection.Changed 	+= new EventHandler(IndexChange);
+				templateTextBuffer.Changed += new EventHandler(TextChange);
+				
+				if (templateGroups.Count > 0) {
+					currentSelectedGroup = 0;
+				}
+				
+				FillGroupOptionMenu();
+				BuildListView();
+				IndexChange(null, null);
+				SetEnabledStatus();
+			}
 			
-			ControlDictionary["addGroupButton"].Click    += new System.EventHandler(AddGroupEvent);
-			ControlDictionary["removeGroupButton"].Click += new System.EventHandler(RemoveGroupEvent);
+			void SetLabels()
+			{
+				extensionLabel.TextWithMnemonic = StringParserService.Parse("${res:Dialog.Options.CodeTemplate.ExtensionsLabel}");
+				removeButton.Label = StringParserService.Parse("${res:Global.RemoveButtonText}");
+				addButton.Label = StringParserService.Parse("${res:Global.AddButtonText}");
+				editButton.Label = StringParserService.Parse("${res:Global.EditButtonText}");
+				addGroupButton.Label = StringParserService.Parse("${res:Dialog.Options.CodeTemplate.AddGroupLabel}");
+				// FIXME: make this use the resource file for the label
+				editGroupButton.Label = "Ed_it Group";
+				removeGroupButton.Label = StringParserService.Parse("${res:Dialog.Options.CodeTemplate.RemoveGroupLabel}");
+				
+				CellRendererText textRenderer = new CellRendererText ();
+				
+				// and listview columns 
+				templateListView.AppendColumn (
+					StringParserService.Parse("${res:Dialog.Options.CodeTemplate.Template}"), 
+					textRenderer,  
+					new TreeCellDataFunc(TemplateListViewCellDataFunc));
+				templateListView.AppendColumn (
+					StringParserService.Parse("${res:Dialog.Options.CodeTemplate.Description}"), 
+					textRenderer, 
+					new TreeCellDataFunc(TemplateListViewCellDataFunc));
+			}
 			
+			// function to render the cell
+			void TemplateListViewCellDataFunc(TreeViewColumn column, CellRenderer renderer, TreeModel model, TreeIter iter)
+			{
+				string toWrite = string.Empty;
+				
+				CodeTemplate codeTemplate = ((ListStore)model).GetValue(iter, 0) as CodeTemplate;
+				
+				if(column.Title == StringParserService.Parse("${res:Dialog.Options.CodeTemplate.Template}"))
+				{
+					// first column
+					((CellRendererText)renderer).Text = codeTemplate.Shortcut;
+				}
+				else
+				{
+					// second column
+					((CellRendererText)renderer).Text = codeTemplate.Description;
+				}
+			}
 			
-			((RichTextBox)ControlDictionary["templateRichTextBox"]).Font = new System.Drawing.Font("Courier New", 10f);
-			((RichTextBox)ControlDictionary["templateRichTextBox"]).TextChanged += new EventHandler(TextChange);
+			void SetEnabledStatus()
+			{
+				bool groupSelected = CurrentTemplateGroup != null;
+				bool groupsEmpty   = templateGroups.Count != 0;
+				
+				SetEnabledStatus(groupSelected, addButton, editButton, removeButton, templateListView, templateTextView);
+				SetEnabledStatus(groupsEmpty, groupOptionMenu, extensionLabel);
+				if (groupSelected) {
+					bool oneItemSelected = templateListView.Selection.CountSelectedRows() == 1;
+					bool isItemSelected  = templateListView.Selection.CountSelectedRows() > 0;
+					SetEnabledStatus(oneItemSelected, editButton, templateTextView);
+					SetEnabledStatus(isItemSelected, removeButton);
+				}
+			}
 			
-			((ListView)ControlDictionary["templateListView"]).Activation = ItemActivation.Standard;
-			((ListView)ControlDictionary["templateListView"]).ItemActivate         += new System.EventHandler(EditEvent);
-			((ListView)ControlDictionary["templateListView"]).SelectedIndexChanged += new System.EventHandler(IndexChange);
+			// disables or enables (sets sensitivty) a specified array of widgets
+			public void SetEnabledStatus(bool enabled, params Widget[] controls)
+			{
+				foreach (Widget control in controls) {				
+					if (control == null) {
+						MessageService.ShowError("Control not found!");
+					} else {
+						control.Sensitive = enabled;
+					}
+				}
+			}
 			
-			((ComboBox)ControlDictionary["groupComboBox"]).DropDown += new EventHandler(FillGroupBoxEvent);
+	#region GroupComboBox event handler
+			void SetGroupSelection(object sender, EventArgs e)
+			{
+				currentSelectedGroup = groupOptionMenu.History;
+				BuildListView();
+			}		
 			
-			if (templateGroups.Count > 0) {
-				currentSelectedGroup = 0;
+	#endregion
+			
+	#region Group Button events
+			void AddGroupEvent(object sender, EventArgs e)
+			{
+				CodeTemplateGroup templateGroup = new CodeTemplateGroup(".???");
+				if(ShowEditTemplateGroupDialog(ref templateGroup, "New ")) {
+					templateGroups.Add(templateGroup);
+					FillGroupOptionMenu();
+					groupOptionMenu.SetHistory((uint) templateGroups.Count - 1);
+					SetEnabledStatus();
+				}
 			}
 			
-			FillGroupComboBox();
-			BuildListView();
-			IndexChange(null, null);
-			SetEnabledStatus();
-		}
-		
-		public override bool StorePanelContents()
-		{
-			CodeTemplateLoader.TemplateGroups = templateGroups;
-			CodeTemplateLoader.SaveTemplates();
-			return true;
-		}
-		
-		void FillGroupBoxEvent(object sender, EventArgs e)
-		{
-			FillGroupComboBox();
-		}
-		
-		void SetEnabledStatus()
-		{
-			bool groupSelected = CurrentTemplateGroup != null;
-			bool groupsEmpty   = templateGroups.Count != 0;
+			void EditGroupEvent(object sender, EventArgs e)
+			{
+				
+				int index = groupOptionMenu.History;
+				CodeTemplateGroup templateGroup = (CodeTemplateGroup) templateGroups[index];
+				if(ShowEditTemplateGroupDialog(ref templateGroup, "Edit ")) {
+					templateGroups[index] = templateGroup;
+					FillGroupOptionMenu();
+					groupOptionMenu.SetHistory((uint)index);
+					SetEnabledStatus();
+				}
+			}
 			
-			SetEnabledStatus(groupSelected, "addButton", "editButton", "removeButton", "templateListView", "templateRichTextBox");
-			SetEnabledStatus(groupsEmpty, "groupComboBox", "extensionLabel");
-			if (groupSelected) {
-				bool oneItemSelected = ((ListView)ControlDictionary["templateListView"]).SelectedItems.Count == 1;
-				bool isItemSelected  = ((ListView)ControlDictionary["templateListView"]).SelectedItems.Count > 0;
-				SetEnabledStatus(oneItemSelected, "editButton", "templateRichTextBox");
-				SetEnabledStatus(isItemSelected, "removeButton");
+			void RemoveGroupEvent(object sender, EventArgs e)
+			{
+				if (CurrentTemplateGroup != null) {
+					templateGroups.RemoveAt(currentSelectedGroup);
+					if (templateGroups.Count == 0) {
+						currentSelectedGroup = -1;
+					} else {
+						groupOptionMenu.SetHistory((uint) Math.Min(currentSelectedGroup, templateGroups.Count - 1));
+					}
+					FillGroupOptionMenu();
+					BuildListView();
+					SetEnabledStatus();
+				}
 			}
-		}
-		
-#region GroupComboBox event handler
-		void SetGroupSelection(object sender, EventArgs e)
-		{
-			currentSelectedGroup = ((ComboBox)ControlDictionary["groupComboBox"]).SelectedIndex;
-			BuildListView();
-		}
-		
-		void GroupComboBoxTextChanged(object sender, EventArgs e)
-		{
-			if (((ComboBox)ControlDictionary["groupComboBox"]).SelectedIndex >= 0) {
-				currentSelectedGroup = ((ComboBox)ControlDictionary["groupComboBox"]).SelectedIndex;
+			
+			bool ShowEditTemplateGroupDialog(ref CodeTemplateGroup templateGroup, string title)
+			{
+				using (EditTemplateGroupDialog etgd = new EditTemplateGroupDialog(templateGroup, title)) {
+					return (etgd.Run() == (int) Gtk.ResponseType.Ok);
+				}
 			}
-			if (CurrentTemplateGroup != null) {
-				CurrentTemplateGroup.ExtensionStrings = ((ComboBox)ControlDictionary["groupComboBox"]).Text.Split(';');
+	#endregion
+			
+	#region Template Button events
+			void RemoveEvent(object sender, System.EventArgs e)
+			{
+				// first copy the selected item paths into a temp array
+				int maxIndex = -1;				
+				int selectedItemCount = templateListView.Selection.CountSelectedRows();
+				TreeIter[] selectedIters = new TreeIter[selectedItemCount];
+				TreeModel lv;
+				GLib.List pathList = templateListView.Selection.GetSelectedRows(out lv);								
+				for(int i = 0; i < selectedItemCount; i++) {
+					TreePath path = (TreePath) pathList[i];
+					((ListStore)lv).GetIter(out selectedIters[i], path);
+					maxIndex = path.Indices[0];
+				}
+				
+				// now delete each item in that list
+				foreach(TreeIter toDelete in selectedIters) {
+					TreeIter itr = toDelete;					
+					((ListStore)lv).Remove(out itr);
+				}
+				
+				StoreTemplateGroup();
+				
+				// try and select the next item after the one removed
+				if(maxIndex > -1) {
+					templateListView.Selection.UnselectAll();
+					TreeIter nextIter;
+					maxIndex += 1- selectedItemCount;
+					if(templateListViewStore.GetIterFromString(out nextIter, maxIndex.ToString())) {				
+						// select the next one
+						templateListView.Selection.SelectIter(nextIter);
+					} else {
+						// select the very last one
+						maxIndex = templateListViewStore.IterNChildren() - 1;
+						if(templateListViewStore.GetIterFromString(out nextIter, (maxIndex).ToString())) {
+							templateListView.Selection.SelectIter(nextIter);
+						}
+					}
+				}
 			}
-		}
-#endregion
-		
-#region Group Button events
-		void AddGroupEvent(object sender, EventArgs e)
-		{
-			templateGroups.Add(new CodeTemplateGroup(".???"));
-			FillGroupComboBox();
-			((ComboBox)ControlDictionary["groupComboBox"]).SelectedIndex = templateGroups.Count - 1;
-			SetEnabledStatus();
-		}
-		
-		void RemoveGroupEvent(object sender, EventArgs e)
-		{
-			if (CurrentTemplateGroup != null) {
-				templateGroups.RemoveAt(currentSelectedGroup);
-				if (templateGroups.Count == 0) {
-					currentSelectedGroup = -1;
-				} else {
-					((ComboBox)ControlDictionary["groupComboBox"]).SelectedIndex = Math.Min(currentSelectedGroup, templateGroups.Count - 1);
+			
+			void AddEvent(object sender, System.EventArgs e)
+			{
+				CodeTemplate newTemplate = new CodeTemplate();
+				using (EditTemplateDialog etd = new EditTemplateDialog(newTemplate)) {
+					if (etd.Run() == (int) Gtk.ResponseType.Ok) {
+						CurrentTemplateGroup.Templates.Add(newTemplate);						
+						templateListView.Selection.UnselectAll();
+						BuildListView();
+						
+						// select the newly added last one
+						TreeIter nextIter;
+						int maxIndex = templateListViewStore.IterNChildren() - 1;
+						if(templateListViewStore.GetIterFromString(out nextIter, (maxIndex).ToString())) {
+							templateListView.Selection.SelectIter(nextIter);
+						}
+					}
 				}
-				FillGroupComboBox();
-				BuildListView();
-				SetEnabledStatus();
 			}
-		}
-#endregion
-		
-#region Template Button events
-		void RemoveEvent(object sender, System.EventArgs e)
-		{
-			object[] selectedItems = new object[((ListView)ControlDictionary["templateListView"]).SelectedItems.Count];
-			((ListView)ControlDictionary["templateListView"]).SelectedItems.CopyTo(selectedItems, 0);
 			
-			foreach (ListViewItem item in selectedItems) {
-				((ListView)ControlDictionary["templateListView"]).Items.Remove(item);
+			void EditEvent(object sender, System.EventArgs e)
+			{
+				TreeIter selectedIter;
+				TreeModel ls;				
+				if(((ListStore)templateListView.Model).GetIter(out selectedIter, (TreePath) templateListView.Selection.GetSelectedRows(out ls)[0])) {
+					CodeTemplate template = ls.GetValue(selectedIter, 0) as CodeTemplate;
+					
+					using (EditTemplateDialog etd = new EditTemplateDialog(template)) {
+						if (etd.Run() == (int) Gtk.ResponseType.Ok) {
+							ls.SetValue(selectedIter, 0, template);
+							StoreTemplateGroup();
+						}
+					}					
+					
+					// select the newly edited item
+					templateListView.Selection.SelectIter(selectedIter);
+				}				
 			}
-			StoreTemplateGroup();
-		}
-		
-		void AddEvent(object sender, System.EventArgs e)
-		{
-			CodeTemplate newTemplate = new CodeTemplate();
-			using (EditTemplateDialog etd = new EditTemplateDialog(newTemplate)) {
-				if (etd.ShowDialog() == DialogResult.OK) {
-					CurrentTemplateGroup.Templates.Add(newTemplate);
-					((ListView)ControlDictionary["templateListView"]).SelectedItems.Clear();
-					BuildListView();
-					((ListView)ControlDictionary["templateListView"]).Select();
-				}
+			
+			// raised when a treeview row is double clicked on
+			void RowActivatedEvent(object sender, GtkSharp.RowActivatedArgs ra)
+			{
+				EditEvent(sender, System.EventArgs.Empty);
 			}
-		}
-		
-		void EditEvent(object sender, System.EventArgs e)
-		{
-			int i = GetCurrentIndex();
-			if (i != -1) {
-				ListViewItem item = ((ListView)ControlDictionary["templateListView"]).SelectedItems[0];
-				CodeTemplate template = (CodeTemplate)item.Tag;
-				template = new CodeTemplate(template.Shortcut, template.Description, template.Text);
+	#endregion
+			
+			void FillGroupOptionMenu()
+			{
+				groupOptionMenu.Changed -= new EventHandler(SetGroupSelection);
 				
-				using (EditTemplateDialog etd = new EditTemplateDialog(template)) {
-					if (etd.ShowDialog() == DialogResult.OK) {
-						item.Tag = template;
-						StoreTemplateGroup();
-					}
+				// remove the menu items
+				groupOptionMenu.RemoveMenu();
+				groupMenu = new Menu();
+				
+				
+				foreach (CodeTemplateGroup templateGroup in templateGroups) {					
+					groupMenu.Append(Gtk.MenuItem.NewWithLabel(String.Join(";", templateGroup.ExtensionStrings)));					
 				}
 				
-				BuildListView();
+				groupMenu.ShowAll();
+				groupOptionMenu.Menu = groupMenu;
+				if (currentSelectedGroup >= 0) {
+					groupOptionMenu.SetHistory((uint)currentSelectedGroup);
+				}
+				
+				groupOptionMenu.Changed += new EventHandler(SetGroupSelection);
 			}
-		}
-#endregion
-		
-		void FillGroupComboBox()
-		{
-			((ComboBox)ControlDictionary["groupComboBox"]).TextChanged          -= new EventHandler(GroupComboBoxTextChanged);
-			((ComboBox)ControlDictionary["groupComboBox"]).SelectedIndexChanged -= new EventHandler(SetGroupSelection);
 			
-			((ComboBox)ControlDictionary["groupComboBox"]).Items.Clear();
-			foreach (CodeTemplateGroup templateGroup in templateGroups) {
-				((ComboBox)ControlDictionary["groupComboBox"]).Items.Add(String.Join(";", templateGroup.ExtensionStrings));
+			void IndexChange(object sender, System.EventArgs e)
+			{
+				if(templateListView.Selection.CountSelectedRows() == 1) {
+					TreeIter selectedIter;
+					TreeModel listStore;				
+					((ListStore)templateListView.Model).GetIter(out selectedIter, (TreePath) templateListView.Selection.GetSelectedRows(out listStore)[0]);
+					templateTextBuffer.Text    = ((CodeTemplate)listStore.GetValue(selectedIter, 0)).Text;
+				} else {
+					templateTextBuffer.Text    = String.Empty;
+				}
+				SetEnabledStatus();
 			}
-			((ComboBox)ControlDictionary["groupComboBox"]).Text = CurrentTemplateGroup != null ? ((ComboBox)ControlDictionary["groupComboBox"]).Items[currentSelectedGroup].ToString() : String.Empty;
-			if (currentSelectedGroup >= 0) {
-				((ComboBox)ControlDictionary["groupComboBox"]).SelectedIndex = currentSelectedGroup;
+			
+			void TextChange(object sender, EventArgs e)
+			{
+				if(templateListView.Selection.CountSelectedRows() == 1) {
+					TreeIter selectedIter;
+					TreeModel listStore;				
+					((ListStore)templateListView.Model).GetIter(out selectedIter, (TreePath) templateListView.Selection.GetSelectedRows(out listStore)[0]);
+					((CodeTemplate)listStore.GetValue(selectedIter, 0)).Text = templateTextBuffer.Text;
+				}
 			}
 			
-			((ComboBox)ControlDictionary["groupComboBox"]).SelectedIndexChanged += new EventHandler(SetGroupSelection);
-			((ComboBox)ControlDictionary["groupComboBox"]).TextChanged          += new EventHandler(GroupComboBoxTextChanged);
-		}
-		
-		int GetCurrentIndex()
-		{
-			if (((ListView)ControlDictionary["templateListView"]).SelectedItems.Count == 1) {
-				return ((ListView)ControlDictionary["templateListView"]).SelectedItems[0].Index;
+			void StoreTemplateGroup()
+			{
+				if (CurrentTemplateGroup != null) {
+					CurrentTemplateGroup.Templates.Clear();
+						
+					TreeIter first;			
+					if(templateListView.Model.GetIterFirst(out first)) {
+						TreeIter current = first;
+						
+						// loop through items in the tree, adding each item to the template group
+						do {
+							CurrentTemplateGroup.Templates.Add(templateListView.Model.GetValue(current, 0)); 
+						} while(templateListView.Model.IterNext(out current));
+					}
+				}
 			}
-			return -1;
-		}
-		
-		void IndexChange(object sender, System.EventArgs e)
-		{
-			int i = GetCurrentIndex();
 			
-			if (i != -1) {
-				ControlDictionary["templateRichTextBox"].Text    = ((CodeTemplate)((ListView)ControlDictionary["templateListView"]).SelectedItems[0].Tag).Text;
-			} else {
-				ControlDictionary["templateRichTextBox"].Text    = String.Empty;
+			void BuildListView()
+			{
+				ListStore listStore = templateListView.Model as ListStore;
+				listStore.Clear();
+				if (CurrentTemplateGroup != null) {
+					foreach (CodeTemplate template in CurrentTemplateGroup.Templates) {
+						listStore.AppendValues(template);					
+					}
+				}
+				IndexChange(this, EventArgs.Empty);
 			}
-			SetEnabledStatus();
 		}
 		
-		void TextChange(object sender, EventArgs e)
-		{
-			int i = GetCurrentIndex();
-			if (i != -1) {
-				((CodeTemplate)((ListView)ControlDictionary["templateListView"]).SelectedItems[0].Tag).Text = ControlDictionary["templateRichTextBox"].Text;
-			}
-		}
+		CodeTemplatePanelWidget widget;
 		
-		void StoreTemplateGroup()
+		public override void LoadPanelContents()
 		{
-			if (CurrentTemplateGroup != null) {
-				CurrentTemplateGroup.Templates.Clear();
-				foreach (ListViewItem item in ((ListView)ControlDictionary["templateListView"]).Items) {
-					CurrentTemplateGroup.Templates.Add(item.Tag);
-				}
-			}
+			// create a new CodeTemplatePanelWidget using glade files and add it
+			// pass in the template groups that it needs
+			this.Add (widget = new CodeTemplatePanelWidget (CodeTemplateLoader.TemplateGroups));
 		}
-		
-		void BuildListView()
+			
+		public override bool StorePanelContents()
 		{
-			((ListView)ControlDictionary["templateListView"]).Items.Clear();
-			if (CurrentTemplateGroup != null) {
-				foreach (CodeTemplate template in CurrentTemplateGroup.Templates) {
-					ListViewItem newItem = new ListViewItem(new string[] { template.Shortcut, template.Description });
-					newItem.Tag = template;
-					((ListView)ControlDictionary["templateListView"]).Items.Add(newItem);
-				}
-			}
-			IndexChange(this, EventArgs.Empty);
-		}*/
+			// get template groups from widhet and save them
+			CodeTemplateLoader.TemplateGroups = widget.TemplateGroups;
+			CodeTemplateLoader.SaveTemplates();
+			return true;
+		}		
 	}
 }

Modified: trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Makefile
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Makefile	2004-01-25 08:16:43 UTC (rev 647)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Makefile	2004-01-25 12:36:14 UTC (rev 648)
@@ -17,6 +17,7 @@
 ./Gui/OptionPanels/CodeTemplatePanel.cs \
 ./Gui/OptionPanels/BehaviorTextEditorPanel.cs \
 ./Gui/OptionPanels/MarkersTextEditorPanel.cs \
+./Gui/Dialogs/EditTemplateGroupDialog.cs \
 ./Gui/Dialogs/ExportProjectToHtmlDialog.cs \
 ./Gui/Dialogs/SortOptionsDialog.cs \
 ./Gui/Dialogs/ReplaceInFilesDialog.cs \
@@ -71,6 +72,7 @@
 		/r:../../../../build/bin/ICSharpCode.TextEditor.dll \
 		/r:../../../../build/bin/SharpDevelop.Base.dll \
 		/r:System.DirectoryServices.dll /r:pango-sharp.dll /r:glade-sharp.dll \
+		/r:MonoDevelop.Gui /r:glib-sharp.dll \
 		/resource:../../../../data/resources/glade/texteditoraddin.glade,texteditoraddin.glade \
 		/define:GTK /r:gtk-sharp.dll /r:gdk-sharp.dll \
 		$(SOURCES)

Modified: trunk/MonoDevelop/src/Main/Base/Gui/Dialogs/OptionPanels/EditTemplateDialog.cs
===================================================================
--- trunk/MonoDevelop/src/Main/Base/Gui/Dialogs/OptionPanels/EditTemplateDialog.cs	2004-01-25 08:16:43 UTC (rev 647)
+++ trunk/MonoDevelop/src/Main/Base/Gui/Dialogs/OptionPanels/EditTemplateDialog.cs	2004-01-25 12:36:14 UTC (rev 648)
@@ -9,14 +9,21 @@
 using System.IO;
 
 using ICSharpCode.SharpDevelop.Internal.Templates;
-using ICSharpCode.SharpDevelop.Gui.XmlForms;
+using ICSharpCode.Core.Services;
 
 namespace ICSharpCode.SharpDevelop.Gui.Dialogs
-{/*
-	public class EditTemplateDialog : BaseSharpDevelopForm 
+{
+	public class EditTemplateDialog : Gtk.Dialog 
 	{
 		CodeTemplate codeTemplate;
 		
+		// Gtk members
+		Gtk.Entry templateTextBox;
+		Gtk.Entry descriptionTextBox;
+		
+		// Services
+		StringParserService StringParserService = (StringParserService)ServiceManager.Services.GetService (typeof (StringParserService));
+		
 		public CodeTemplate CodeTemplate {
 			get {
 				return codeTemplate;
@@ -27,25 +34,67 @@
 		{
 			this.codeTemplate = codeTemplate;
 			InitializeComponents();
+			this.ShowAll();
 		}
 		
 		void AcceptEvent(object sender, EventArgs e)
 		{
-			codeTemplate.Shortcut    = ControlDictionary["templateTextBox"].Text;
-			codeTemplate.Description = ControlDictionary["descriptionTextBox"].Text;
+			codeTemplate.Shortcut    = templateTextBox.Text;
+			codeTemplate.Description = descriptionTextBox.Text;
+			
+			// close the window
+			CancelEvent(sender, EventArgs.Empty);
 		}
 		
+		void CancelEvent(object sender, EventArgs e)
+		{
+			this.Destroy();
+		}
+		
 		void InitializeComponents()
 		{
-			base.SetupFromXml(Path.Combine(PropertyService.DataDirectory, @"resources\dialogs\EditTemplateDialog.xfrm"));
+			// set up this actual dialog
+			this.Modal = true;
+			this.Title = StringParserService.Parse("${res:Dialog.Options.CodeTemplate.EditTemplateDialog.DialogName}");
 			
-			ControlDictionary["templateTextBox"].Text    = codeTemplate.Shortcut;
-			ControlDictionary["descriptionTextBox"].Text = codeTemplate.Description;
+			// set up the dialog fields and add them
+			templateTextBox = new Gtk.Entry();
+			descriptionTextBox = new Gtk.Entry();
+			descriptionTextBox.ActivatesDefault = true;
+			Gtk.Label label1 = new Gtk.Label(StringParserService.Parse("${res:Dialog.Options.CodeTemplate.EditTemplateDialog.DescriptionLabel}"));
+			Gtk.Label label2 = new Gtk.Label(StringParserService.Parse("${res:Dialog.Options.CodeTemplate.EditTemplateDialog.TemplateLabel}"));
+			label1.Xalign = 0;
+			label2.Xalign = 0;
+			templateTextBox.Text    = codeTemplate.Shortcut;
+			descriptionTextBox.Text = codeTemplate.Description;			
+			Gtk.SizeGroup sizeGroup1 = new Gtk.SizeGroup(Gtk.SizeGroupMode.Horizontal);
+			Gtk.SizeGroup sizeGroup2 = new Gtk.SizeGroup(Gtk.SizeGroupMode.Horizontal);			
+			sizeGroup1.AddWidget(templateTextBox);
+			sizeGroup1.AddWidget(descriptionTextBox);
+			sizeGroup2.AddWidget(label1);
+			sizeGroup2.AddWidget(label2);
 			
-			ControlDictionary["okButton"].Click += new EventHandler(AcceptEvent);
+			// FIXME: make the labels both part of the same sizing group so they have the same left and right rows.
+			Gtk.HBox hBox1 = new Gtk.HBox(false, 6);
+			hBox1.PackStart(label1, false, false, 6);
+			hBox1.PackStart(descriptionTextBox, false, false, 6);
 			
-			Owner = (Form)WorkbenchSingleton.Workbench;
-			Icon  = null;
+			Gtk.HBox hBox2 = new Gtk.HBox(false, 6);
+			hBox2.PackStart(label2, false, false, 6);
+			hBox2.PackStart(templateTextBox, false, false, 6);
+			
+			this.VBox.PackStart(hBox1, false, false, 6);
+			this.VBox.PackStart(hBox2, false, false, 6);
+			
+			// set up the buttons and add them
+			this.DefaultResponse = (int) Gtk.ResponseType.Ok;
+			Gtk.Button cancelButton = new Gtk.Button(Gtk.Stock.Cancel);
+			Gtk.Button okButton = new Gtk.Button(Gtk.Stock.Ok);
+			okButton.Clicked += new EventHandler(AcceptEvent);
+			cancelButton.Clicked += new EventHandler(CancelEvent);
+			this.AddActionWidget (cancelButton, Gtk.ResponseType.Cancel);
+			this.AddActionWidget (okButton, (int) Gtk.ResponseType.Ok);
+			
 		}
-	}*/
+	}
 }




More information about the Monodevelop-patches-list mailing list