[MonoDevelop] External Tool Option Panel

John BouAntoun secretsquirrel@optusnet.com.au
Sat, 17 Jan 2004 18:12:17 +1100


--=-kdsbY0ln67zt+ipaaaXd
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Guys, here's the diff file for the external tools option panel.

It took me a while to do cause I had to learn Treeview/ListStore.

Two poitns to note:

- Still need to fix popup menus, when MenuService is done
- It doesn't allow multiselect because I keep getting a NullReference
Exception on TreeSelection.GetSelectedRows()[index];

here it is.

jba

--=-kdsbY0ln67zt+ipaaaXd
Content-Disposition: attachment; filename=externaltoolpanel-patch.diff
Content-Type: text/x-patch; name=externaltoolpanel-patch.diff; charset=UTF-8
Content-Transfer-Encoding: 8bit

Index: src/Main/Base/Gui/Dialogs/OptionPanels/ExternalToolPanel.cs
===================================================================
--- src/Main/Base/Gui/Dialogs/OptionPanels/ExternalToolPanel.cs	(revision 511)
+++ src/Main/Base/Gui/Dialogs/OptionPanels/ExternalToolPanel.cs	(working copy)
@@ -1,267 +1,426 @@
-// <file>
-//     <copyright see="prj:///doc/copyright.txt"/>
-//     <license see="prj:///doc/license.txt"/>
-//     <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
-//     <version value="$version"/>
-// </file>
-
-using System;
-using System.IO;
-using System.Collections;
-using System.Windows.Forms;
-
-using ICSharpCode.SharpDevelop.Internal.ExternalTool;
-using ICSharpCode.Core.Properties;
-using ICSharpCode.Core.Services;
-using ICSharpCode.Core.AddIns.Codons;
-
-namespace ICSharpCode.SharpDevelop.Gui.Dialogs.OptionPanels
-{/*
-	public class ExternalToolPane : AbstractOptionPanel
-	{
-		
-		static string[,] argumentQuickInsertMenu = new string[,] {
-			{"${res:Dialog.Options.ExternalTool.QuickInsertMenu.FullItemPath}",      "${ItemPath}"},
-			{"${res:Dialog.Options.ExternalTool.QuickInsertMenu.FullItemDirectory}", "${ItemDir}"},
-			{"${res:Dialog.Options.ExternalTool.QuickInsertMenu.ItemFileName}",      "${ItemFileName}"},
-			{"${res:Dialog.Options.ExternalTool.QuickInsertMenu.ItemExtension}",     "${ItemExt}"},
-			{"-", ""},
-			{"${res:Dialog.Options.ExternalTool.QuickInsertMenu.CurrentLine}",   "${CurLine}"},
-			{"${res:Dialog.Options.ExternalTool.QuickInsertMenu.CurrentColumn}", "${CurCol}"},
-			{"${res:Dialog.Options.ExternalTool.QuickInsertMenu.CurrentText}",   "${CurText}"},
-			{"-", ""},
-			{"${res:Dialog.Options.ExternalTool.QuickInsertMenu.FullTargetPath}",  "${TargetPath}"},
-			{"${res:Dialog.Options.ExternalTool.QuickInsertMenu.TargetDirectory}", "${TargetDir}"},
-			{"${res:Dialog.Options.ExternalTool.QuickInsertMenu.TargetName}",      "${TargetName}"},
-			{"${res:Dialog.Options.ExternalTool.QuickInsertMenu.TargetExtension}", "${TargetExt}"},
-			{"-", ""},
-			{"${res:Dialog.Options.ExternalTool.QuickInsertMenu.ProjectDirectory}", "${ProjectDir}"},
-			{"${res:Dialog.Options.ExternalTool.QuickInsertMenu.ProjectFileName}",  "${ProjectFileName}"},
-			{"-", ""},
-			{"${res:Dialog.Options.ExternalTool.QuickInsertMenu.CombineDirectory}", "${CombineDir}"},
-			{"${res:Dialog.Options.ExternalTool.QuickInsertMenu.CombineFileName}",  "${CombineFileName}"},
-			{"-", ""},
-			{"${res:Dialog.Options.ExternalTool.QuickInsertMenu.SharpDevelopStartupPath}",  "${StartupPath}"},
-		};
-		
-		static string[,] workingDirInsertMenu = new string[,] {
-			{"${res:Dialog.Options.ExternalTool.QuickInsertMenu.FullItemDirectory}", "${ItemDir}"},
-			{"-", ""},
-			{"${res:Dialog.Options.ExternalTool.QuickInsertMenu.TargetDirectory}", "${TargetDir}"},
-			{"${res:Dialog.Options.ExternalTool.QuickInsertMenu.TargetName}",      "${TargetName}"},
-			{"-", ""},
-			{"${res:Dialog.Options.ExternalTool.QuickInsertMenu.ProjectDirectory}", "${ProjectDir}"},
-			{"-", ""},
-			{"${res:Dialog.Options.ExternalTool.QuickInsertMenu.CombineDirectory}", "${CombineDir}"},
-			{"-", ""},
-			{"${res:Dialog.Options.ExternalTool.QuickInsertMenu.SharpDevelopStartupPath}",  "${StartupPath}"},
-		};
-		
-		// these are the control names which are enabled/disabled depending if tool is selected
-		static string[] dependendControlNames = new string[] {
-			"titleTextBox", "commandTextBox", "argumentTextBox", 
-			"workingDirTextBox", "promptArgsCheckBox", "useOutputPadCheckBox", 
-			"titleLabel", "argumentLabel", "commandLabel", 
-			"workingDirLabel", "browseButton", "argumentQuickInsertButton", 
-			"workingDirQuickInsertButton", "moveUpButton", "moveDownButton"
-		};
-		
-		public override void LoadPanelContents()
-		{
-			SetupFromXml(Path.Combine(PropertyService.DataDirectory, 
-			                          @"resources\panels\ExternalToolOptions.xfrm"));
-			
-			((ListBox)ControlDictionary["toolListBox"]).BeginUpdate();
-			try {
-				foreach (object o in ToolLoader.Tool) {
-					((ListBox)ControlDictionary["toolListBox"]).Items.Add(o);
-				}
-			} finally {
-				((ListBox)ControlDictionary["toolListBox"]).EndUpdate();
-			}
-			
-			MenuService.CreateQuickInsertMenu((TextBox)ControlDictionary["argumentTextBox"],
-			                                  ControlDictionary["argumentQuickInsertButton"],
-			                                  argumentQuickInsertMenu);
-			
-			MenuService.CreateQuickInsertMenu((TextBox)ControlDictionary["workingDirTextBox"],
-			                                  ControlDictionary["workingDirQuickInsertButton"],
-			                                  workingDirInsertMenu);
-			
-			((ListBox)ControlDictionary["toolListBox"]).SelectedIndexChanged += new EventHandler(selectEvent);
-			ControlDictionary["removeButton"].Click   += new EventHandler(removeEvent);
-			ControlDictionary["addButton"].Click      += new EventHandler(addEvent);
-			ControlDictionary["moveUpButton"].Click   += new EventHandler(moveUpEvent);
-			ControlDictionary["moveDownButton"].Click += new EventHandler(moveDownEvent);
-			
-			ControlDictionary["browseButton"].Click   += new EventHandler(browseEvent);
-			
-			
-			selectEvent(this, EventArgs.Empty);
-		}
-		
-		void browseEvent(object sender, EventArgs e)
-		{
-			using (OpenFileDialog fdiag  = new OpenFileDialog()) {
-				fdiag.CheckFileExists = true;
-				fdiag.Filter = StringParserService.Parse("${res:SharpDevelop.FileFilter.ExecutableFiles}|*.exe;*.com;*.pif;*.bat;*.cmd|${res:SharpDevelop.FileFilter.AllFiles}|*.*");
-				
-				if (fdiag.ShowDialog() == DialogResult.OK) {
-					ControlDictionary["commandTextBox"].Text = fdiag.FileName;
-				}
-			}
-		}
-		
-		
-		void moveUpEvent(object sender, EventArgs e)
-		{
-			int index = ((ListBox)ControlDictionary["toolListBox"]).SelectedIndex;
-			if (index > 0) {
-				((ListBox)ControlDictionary["toolListBox"]).SelectedIndexChanged -= new EventHandler(selectEvent);
-				try {
-					object tmp = ((ListBox)ControlDictionary["toolListBox"]).Items[index - 1];
-					((ListBox)ControlDictionary["toolListBox"]).Items[index - 1] = ((ListBox)ControlDictionary["toolListBox"]).Items[index];
-					((ListBox)ControlDictionary["toolListBox"]).Items[index] = tmp;
-					((ListBox)ControlDictionary["toolListBox"]).SetSelected(index, false);
-					((ListBox)ControlDictionary["toolListBox"]).SetSelected(index - 1, true);
-				} finally {
-					((ListBox)ControlDictionary["toolListBox"]).SelectedIndexChanged += new EventHandler(selectEvent);
-				}
-			}
-			
-		}
-		void moveDownEvent(object sender, EventArgs e)
-		{
-			int index = ((ListBox)ControlDictionary["toolListBox"]).SelectedIndex;
-			if (index >= 0 && index < ((ListBox)ControlDictionary["toolListBox"]).Items.Count - 1) {
-				((ListBox)ControlDictionary["toolListBox"]).SelectedIndexChanged -= new EventHandler(selectEvent);
-				try {
-					object tmp = ((ListBox)ControlDictionary["toolListBox"]).Items[index + 1];
-					((ListBox)ControlDictionary["toolListBox"]).Items[index + 1] = ((ListBox)ControlDictionary["toolListBox"]).Items[index];
-					((ListBox)ControlDictionary["toolListBox"]).Items[index] = tmp;
-					((ListBox)ControlDictionary["toolListBox"]).SetSelected(index, false);
-					((ListBox)ControlDictionary["toolListBox"]).SetSelected(index + 1, true);
-				} finally {
-					((ListBox)ControlDictionary["toolListBox"]).SelectedIndexChanged += new EventHandler(selectEvent);
-				}
-			}
-		}
-		
-		public override bool StorePanelContents()
-		{
-			ArrayList newlist = new ArrayList();
-			foreach (ExternalTool tool in ((ListBox)ControlDictionary["toolListBox"]).Items) {
-				if (!FileUtilityService.IsValidFileName(tool.Command)) {
-					MessageService.ShowError(String.Format("The command of tool \"{0}\" is invalid.", tool.MenuCommand));
-					return false;
-				}
-				if ((tool.InitialDirectory != "") && (!FileUtilityService.IsValidFileName(tool.InitialDirectory))) {
-					MessageService.ShowError(String.Format("The working directory of tool \"{0}\" is invalid.", tool.MenuCommand));
-					return false;
-				}
-				newlist.Add(tool);
-			}
-			
-			ToolLoader.Tool = newlist;
-			ToolLoader.SaveTools();
-			return true;
-		}
-		
-		void propertyValueChanged(object sender, PropertyValueChangedEventArgs e)
-		{
-			foreach (ListViewItem item in ((ListView)ControlDictionary["toolListView"]).Items) {
-				if (item.Tag != null) {
-					item.Text = item.Tag.ToString();
-				}
-			}
-			
-		}
-		
-		void setToolValues(object sender, EventArgs e)
-		{
-			ExternalTool selectedItem = ((ListBox)ControlDictionary["toolListBox"]).SelectedItem as ExternalTool;
-			
-			selectedItem.MenuCommand        = ControlDictionary["titleTextBox"].Text;
-			selectedItem.Command            = ControlDictionary["commandTextBox"].Text;
-			selectedItem.Arguments          = ControlDictionary["argumentTextBox"].Text;
-			selectedItem.InitialDirectory   = ControlDictionary["workingDirTextBox"].Text;
-			selectedItem.PromptForArguments = ((CheckBox)ControlDictionary["promptArgsCheckBox"]).Checked;
-			selectedItem.UseOutputPad       = ((CheckBox)ControlDictionary["useOutputPadCheckBox"]).Checked;
-		}
-		
-		void selectEvent(object sender, EventArgs e)
-		{
-			SetEnabledStatus(((ListBox)ControlDictionary["toolListBox"]).SelectedItems.Count > 0, "removeButton");
-			
-			ControlDictionary["titleTextBox"].TextChanged      -= new EventHandler(setToolValues);
-			ControlDictionary["commandTextBox"].TextChanged    -= new EventHandler(setToolValues);
-			ControlDictionary["argumentTextBox"].TextChanged   -= new EventHandler(setToolValues);
-			ControlDictionary["workingDirTextBox"].TextChanged   -= new EventHandler(setToolValues);
-			((CheckBox)ControlDictionary["promptArgsCheckBox"]).CheckedChanged   -= new EventHandler(setToolValues);
-			((CheckBox)ControlDictionary["useOutputPadCheckBox"]).CheckedChanged -= new EventHandler(setToolValues);
-			
-			if (((ListBox)ControlDictionary["toolListBox"]).SelectedItems.Count == 1) {
-				ExternalTool selectedItem = ((ListBox)ControlDictionary["toolListBox"]).SelectedItem as ExternalTool;
-				SetEnabledStatus(true, dependendControlNames);
-				ControlDictionary["titleTextBox"].Text      = selectedItem.MenuCommand;
-				ControlDictionary["commandTextBox"].Text    = selectedItem.Command;
-				ControlDictionary["argumentTextBox"].Text   = selectedItem.Arguments;
-				ControlDictionary["workingDirTextBox"].Text = selectedItem.InitialDirectory;
-				((CheckBox)ControlDictionary["promptArgsCheckBox"]).Checked   = selectedItem.PromptForArguments;
-				((CheckBox)ControlDictionary["useOutputPadCheckBox"]).Checked = selectedItem.UseOutputPad;
-			} else {
-				SetEnabledStatus(false, dependendControlNames);
-				
-				ControlDictionary["titleTextBox"].Text      = String.Empty;
-				ControlDictionary["commandTextBox"].Text    = String.Empty;
-				ControlDictionary["argumentTextBox"].Text   = String.Empty;
-				ControlDictionary["workingDirTextBox"].Text = String.Empty;
-				((CheckBox)ControlDictionary["promptArgsCheckBox"]).Checked   = false;
-				((CheckBox)ControlDictionary["useOutputPadCheckBox"]).Checked = false;
-			}
-			
-			ControlDictionary["titleTextBox"].TextChanged      += new EventHandler(setToolValues);
-			ControlDictionary["commandTextBox"].TextChanged    += new EventHandler(setToolValues);
-			ControlDictionary["argumentTextBox"].TextChanged   += new EventHandler(setToolValues);
-			ControlDictionary["workingDirTextBox"].TextChanged += new EventHandler(setToolValues);
-			((CheckBox)ControlDictionary["promptArgsCheckBox"]).CheckedChanged   += new EventHandler(setToolValues);
-			((CheckBox)ControlDictionary["useOutputPadCheckBox"]).CheckedChanged += new EventHandler(setToolValues);
-		}
-		
-		void removeEvent(object sender, EventArgs e)
-		{
-			((ListBox)ControlDictionary["toolListBox"]).BeginUpdate();
-			try {
-				int index = ((ListBox)ControlDictionary["toolListBox"]).SelectedIndex;
-				object[] selectedItems = new object[((ListBox)ControlDictionary["toolListBox"]).SelectedItems.Count];
-				((ListBox)ControlDictionary["toolListBox"]).SelectedItems.CopyTo(selectedItems, 0);
-				((ListBox)ControlDictionary["toolListBox"]).SelectedIndexChanged -= new EventHandler(selectEvent);
-				foreach (object item in selectedItems) {
-					((ListBox)ControlDictionary["toolListBox"]).Items.Remove(item);
-				}
-				((ListBox)ControlDictionary["toolListBox"]).SelectedIndexChanged += new EventHandler(selectEvent);
-				if (((ListBox)ControlDictionary["toolListBox"]).Items.Count == 0) {
-					selectEvent(this, EventArgs.Empty);
-				} else {
-					((ListBox)ControlDictionary["toolListBox"]).SelectedIndex = Math.Min(index,((ListBox)ControlDictionary["toolListBox"]).Items.Count - 1);
-				}
-			} finally {
-				((ListBox)ControlDictionary["toolListBox"]).EndUpdate();
-			}
-		}
-		
-		void addEvent(object sender, EventArgs e)
-		{
-			((ListBox)ControlDictionary["toolListBox"]).BeginUpdate();
-			try {
-				((ListBox)ControlDictionary["toolListBox"]).Items.Add(new ExternalTool());
-				((ListBox)ControlDictionary["toolListBox"]).SelectedIndexChanged -= new EventHandler(selectEvent);
-				((ListBox)ControlDictionary["toolListBox"]).ClearSelected();
-				((ListBox)ControlDictionary["toolListBox"]).SelectedIndexChanged += new EventHandler(selectEvent);
-				((ListBox)ControlDictionary["toolListBox"]).SelectedIndex = ((ListBox)ControlDictionary["toolListBox"]).Items.Count - 1;
-			} finally {
-				((ListBox)ControlDictionary["toolListBox"]).EndUpdate();
-			}
-		}
-	}*/
-}
+// <file>
+//     <copyright see="prj:///doc/copyright.txt"/>
+//     <license see="prj:///doc/license.txt"/>
+//     <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
+//     <version value="$version"/>
+// </file>
+
+using System;
+using System.IO;
+using System.Collections;
+using Gtk;
+
+using ICSharpCode.SharpDevelop.Internal.ExternalTool;
+using ICSharpCode.Core.Properties;
+using ICSharpCode.Core.Services;
+using ICSharpCode.Core.AddIns.Codons;
+
+namespace ICSharpCode.SharpDevelop.Gui.Dialogs.OptionPanels
+{
+	public class ExternalToolPane : AbstractOptionPanel
+	{
+
+		static string[,] argumentQuickInsertMenu = new string[,] {
+			{"${res:Dialog.Options.ExternalTool.QuickInsertMenu.FullItemPath}",      "${ItemPath}"},
+			{"${res:Dialog.Options.ExternalTool.QuickInsertMenu.FullItemDirectory}", "${ItemDir}"},
+			{"${res:Dialog.Options.ExternalTool.QuickInsertMenu.ItemFileName}",      "${ItemFileName}"},
+			{"${res:Dialog.Options.ExternalTool.QuickInsertMenu.ItemExtension}",     "${ItemExt}"},
+			{"-", ""},
+			{"${res:Dialog.Options.ExternalTool.QuickInsertMenu.CurrentLine}",   "${CurLine}"},
+			{"${res:Dialog.Options.ExternalTool.QuickInsertMenu.CurrentColumn}", "${CurCol}"},
+			{"${res:Dialog.Options.ExternalTool.QuickInsertMenu.CurrentText}",   "${CurText}"},
+			{"-", ""},
+			{"${res:Dialog.Options.ExternalTool.QuickInsertMenu.FullTargetPath}",  "${TargetPath}"},
+			{"${res:Dialog.Options.ExternalTool.QuickInsertMenu.TargetDirectory}", "${TargetDir}"},
+			{"${res:Dialog.Options.ExternalTool.QuickInsertMenu.TargetName}",      "${TargetName}"},
+			{"${res:Dialog.Options.ExternalTool.QuickInsertMenu.TargetExtension}", "${TargetExt}"},
+			{"-", ""},
+			{"${res:Dialog.Options.ExternalTool.QuickInsertMenu.ProjectDirectory}", "${ProjectDir}"},
+			{"${res:Dialog.Options.ExternalTool.QuickInsertMenu.ProjectFileName}",  "${ProjectFileName}"},
+			{"-", ""},
+			{"${res:Dialog.Options.ExternalTool.QuickInsertMenu.CombineDirectory}", "${CombineDir}"},
+			{"${res:Dialog.Options.ExternalTool.QuickInsertMenu.CombineFileName}",  "${CombineFileName}"},
+			{"-", ""},
+			{"${res:Dialog.Options.ExternalTool.QuickInsertMenu.SharpDevelopStartupPath}",  "${StartupPath}"},
+		};
+		
+		static string[,] workingDirInsertMenu = new string[,] {
+			{"${res:Dialog.Options.ExternalTool.QuickInsertMenu.FullItemDirectory}", "${ItemDir}"},
+			{"-", ""},
+			{"${res:Dialog.Options.ExternalTool.QuickInsertMenu.TargetDirectory}", "${TargetDir}"},
+			{"${res:Dialog.Options.ExternalTool.QuickInsertMenu.TargetName}",      "${TargetName}"},
+			{"-", ""},
+			{"${res:Dialog.Options.ExternalTool.QuickInsertMenu.ProjectDirectory}", "${ProjectDir}"},
+			{"-", ""},
+			{"${res:Dialog.Options.ExternalTool.QuickInsertMenu.CombineDirectory}", "${CombineDir}"},
+			{"-", ""},
+			{"${res:Dialog.Options.ExternalTool.QuickInsertMenu.SharpDevelopStartupPath}",  "${StartupPath}"},
+		};
+		
+		// gtk controls
+		ListStore toolListBoxStore;
+		TreeView toolListBox;
+		Entry titleTextBox; 
+		Entry commandTextBox; 
+		Entry argumentTextBox; 
+		Entry workingDirTextBox; 
+		CheckButton promptArgsCheckBox; 
+		CheckButton useOutputPadCheckBox; 
+		Label titleLabel; 
+		Label argumentLabel; 
+		Label commandLabel; 
+		Label workingDirLabel; 
+		Button browseButton; 
+		Button argumentQuickInsertButton; 
+		Button workingDirQuickInsertButton; 
+		Button moveUpButton; 
+		Button moveDownButton;
+		Button addButton; 
+		Button removeButton;
+			
+		// these are the control names which are enabled/disabled depending if tool is selected
+		Widget[] dependendControls;
+		
+		// needed for treeview listbox
+		int toolListBoxItemCount = 0;
+		
+		// Services
+		FileUtilityService FileUtilityService = (FileUtilityService)ServiceManager.Services.GetService(typeof(FileUtilityService));
+		StringParserService StringParserService = (StringParserService)ServiceManager.Services.GetService (typeof (StringParserService));
+		PropertyService PropertyService = (PropertyService)ServiceManager.Services.GetService(typeof(PropertyService));
+		MessageService MessageService = (MessageService)ServiceManager.Services.GetService(typeof(MessageService));
+// FIXME: when menu service is created
+//		MenuService MenuService = (MenuService)ServiceManager.Services.GetService(typeof(MenuService));
+		
+		public override void LoadPanelContents()
+		{
+			// set up the form controls instance
+			SetupPanelInstance();
+			
+			// add each tool to the treeStore
+			foreach (object o in ToolLoader.Tool) {
+					toolListBoxStore.AppendValues(((ExternalTool)o).MenuCommand, (ExternalTool) o);
+					toolListBoxItemCount ++;
+			}
+			
+			toolListBox.Reorderable = false;
+			toolListBox.HeadersVisible = true;
+			//toolListBox.Selection.Mode = SelectionMode.Multiple;
+			toolListBox.Model = toolListBoxStore;
+			
+			toolListBox.AppendColumn (
+				StringParserService.Parse("${res:Dialog.Options.ExternalTool.ToolsLabel}"), 
+				new CellRendererText (), 
+				"text", 
+				0);
+			
+			
+// FIXME: when menu service is created
+//			MenuService.CreateQuickInsertMenu(argumentTextBox,
+//			                                  argumentQuickInsertButton,
+//			                                  argumentQuickInsertMenu);
+			
+// FIXME: when menu service is created
+//			MenuService.CreateQuickInsertMenu(workingDirTextBox,
+//			                                  workingDirQuickInsertButton,
+//			                                  workingDirInsertMenu);
+			
+			toolListBox.Selection.Changed += new EventHandler(selectEvent);
+			
+			removeButton.Clicked   += new EventHandler(removeEvent);
+			addButton.Clicked      += new EventHandler(addEvent);
+			moveUpButton.Clicked   += new EventHandler(moveUpEvent);
+			moveDownButton.Clicked += new EventHandler(moveDownEvent);
+			
+			browseButton.Clicked   += new EventHandler(browseEvent);
+			
+			selectEvent(this, EventArgs.Empty);
+		}
+		
+		public override bool StorePanelContents()
+		{
+			ArrayList newlist = new ArrayList();
+			TreeIter first;
+			
+			if(toolListBox.Model.GetIterFirst(out first))
+			{
+				TreeIter current = first;
+				
+				do {
+				// loop through items in the tree
+				
+					ExternalTool tool = toolListBox.Model.GetValue(current, 1) as ExternalTool;
+					if (!FileUtilityService.IsValidFileName(tool.Command)) {
+						MessageService.ShowError(String.Format("The command of tool \"{0}\" is invalid.", tool.MenuCommand));
+						return false;
+					}
+					if ((tool.InitialDirectory != "") && (!FileUtilityService.IsValidFileName(tool.InitialDirectory))) {
+						MessageService.ShowError(String.Format("The working directory of tool \"{0}\" is invalid.", tool.MenuCommand));
+						return false;
+					}
+					newlist.Add(tool);				 
+				} while(toolListBox.Model.IterNext(out current));
+			}
+			ToolLoader.Tool = newlist;
+			ToolLoader.SaveTools();
+			return true;
+		}
+		
+		void SetupPanelInstance()
+		{
+			// instantiate controls			
+			toolListBoxStore = new ListStore(typeof(string), typeof(ExternalTool));
+			toolListBox = new TreeView();
+			toolListBox.SetSizeRequest(200, 150);
+			titleTextBox = new Entry(); 
+			commandTextBox = new Entry(); 
+			argumentTextBox = new Entry(); 
+			workingDirTextBox = new Entry(); 
+			promptArgsCheckBox = CheckButton.NewWithLabel(StringParserService.Parse("${res:Dialog.Options.ExternalTool.PromptForArgsCheckBox}")); 
+			useOutputPadCheckBox = CheckButton.NewWithLabel(StringParserService.Parse("${res:Dialog.Options.ExternalTool.UseOutputWindow}")); 
+			titleLabel = new Label(StringParserService.Parse("${res:Dialog.Options.ExternalTool.TitleLabel}")); 
+			argumentLabel = new Label(StringParserService.Parse("${res:Dialog.Options.ExternalTool.ArgumentLabel}")); 
+			commandLabel = new Label(StringParserService.Parse("${res:Dialog.Options.ExternalTool.CommandLabel}")); 
+			workingDirLabel = new Label(StringParserService.Parse("${res:Dialog.Options.ExternalTool.WorkingDirLabel}"));			
+			browseButton = new Button("..."); 
+			argumentQuickInsertButton = new Button(">"); 
+			workingDirQuickInsertButton = new Button(">"); 
+			moveUpButton = new Button(StringParserService.Parse("${res:Dialog.Options.ExternalTool.MoveUpButton}")); 
+			moveDownButton = new Button(StringParserService.Parse("${res:Dialog.Options.ExternalTool.MoveDownButton}"));
+			removeButton = new Button(StringParserService.Parse("${res:Global.RemoveButtonText}"));
+			addButton = new Button(StringParserService.Parse("${res:Global.AddButtonText}"));
+			
+			dependendControls = new Widget[] {
+				titleTextBox, commandTextBox, argumentTextBox, 
+				workingDirTextBox, promptArgsCheckBox, useOutputPadCheckBox, 
+				titleLabel, argumentLabel, commandLabel, 
+				workingDirLabel, browseButton, argumentQuickInsertButton, 
+				workingDirQuickInsertButton, moveUpButton, moveDownButton
+			};
+			
+			// pack all the controls
+			VBox vBox1 = new VBox(false, 2);
+			vBox1.PackStart(addButton, false, false, 2);
+			vBox1.PackStart(removeButton, false, false, 2);
+			vBox1.PackStart(moveUpButton, false, false, 2);
+			vBox1.PackStart(moveDownButton, false, false, 2);
+			
+			HBox hBox1 = new HBox(false, 2);
+			hBox1.PackStart(toolListBox, false, false, 2);
+			hBox1.PackStart(vBox1, false, false, 2);
+			
+			Table table1 = new Table(4, 3, false);
+			table1.Attach(titleLabel, 0, 1, 0, 1);
+			table1.Attach(titleTextBox, 1, 3, 0, 1);
+			table1.Attach(commandLabel, 0, 1, 1, 2);
+			table1.Attach(commandTextBox, 1, 2, 1, 2);
+			table1.Attach(browseButton, 2, 3, 1, 2);
+			table1.Attach(argumentLabel, 0, 1, 2, 3);
+			table1.Attach(argumentTextBox, 1, 2, 2, 3);
+			table1.Attach(argumentQuickInsertButton, 2, 3, 2, 3);
+			table1.Attach(workingDirLabel, 0, 1, 3, 4);
+			table1.Attach(workingDirTextBox, 1, 2, 3, 4);
+			table1.Attach(workingDirQuickInsertButton, 2, 3, 3, 4);
+			
+			VBox mainBox = new VBox(false, 2);
+			mainBox.PackStart(hBox1, false, false, 2);
+			mainBox.PackStart(table1, false, false, 2);
+			mainBox.PackStart(promptArgsCheckBox, false, false, 2);
+			mainBox.PackStart(useOutputPadCheckBox, false, false, 2);
+			this.Add(mainBox);
+		}
+		
+		void browseEvent(object sender, EventArgs e)
+		{
+			Gtk.FileSelection fs = new Gtk.FileSelection ("File to Open");
+			int response = fs.Run ();
+			string name = fs.Filename;
+			fs.Destroy ();
+			if (response == (int)Gtk.ResponseType.Ok) {
+				commandTextBox.Text = name;
+			}
+		}
+		
+		
+		void moveUpEvent(object sender, EventArgs e)
+		{
+			TreeIter selectedItem;
+			TreeModel ls;
+			// FIXME: change block of code when Selection.GetSelectedRows()[index] issue is fixed
+			// it will need to use the GLib.List of selected items and simply return the first one
+			if(toolListBox.Selection.GetSelected(out ls, out selectedItem))
+			{
+				// we know we have a selected item so get it's index
+				// use that to get the path of the item before it, and swap the two
+				int index = GetSelectedIndex(toolListBox);
+				// only swap if at the top
+				if(index > 0)
+				{
+					TreeIter prev; 
+					if(toolListBox.Model.GetIterFromString(out prev, (index - 1).ToString()))
+					{
+						((ListStore)ls).Swap(selectedItem, prev);
+					}
+				}
+			}
+		}
+		void moveDownEvent(object sender, EventArgs e)
+		{
+			TreeIter selectedItem;
+			TreeModel ls;
+			// FIXME: change block of code when Selection.GetSelectedRows()[index] issue is fixed
+			// it will need to use the GLib.List of selected items and simply return the first one
+			if(toolListBox.Selection.GetSelected(out ls, out selectedItem))
+			{
+				// swap it with the next one
+				TreeIter toSwap = selectedItem;
+				if(ls.IterNext(out toSwap))
+				{
+					((ListStore)ls).Swap(selectedItem, toSwap);
+				}
+			}
+		}
+		
+		void setToolValues(object sender, EventArgs e)
+		{
+			TreeIter selectedIter;
+			TreeModel lv;				
+			ExternalTool selectedItem = null;
+			// FIXME: change block of code when Selection.GetSelectedRows()[index] issue is fixed
+			// it will need to use the GLib.List of selected items and simply return the first one
+			if(toolListBox.Selection.GetSelected(out lv, out selectedIter))
+			{
+				// get the value as an external tool object
+				selectedItem = lv.GetValue(selectedIter, 1) as ExternalTool;
+				
+				
+				lv.SetValue(selectedIter, 0, titleTextBox.Text);
+				selectedItem.MenuCommand        = titleTextBox.Text;
+				selectedItem.Command            = commandTextBox.Text;
+				selectedItem.Arguments          = argumentTextBox.Text;
+				selectedItem.InitialDirectory   = workingDirTextBox.Text;
+				selectedItem.PromptForArguments = promptArgsCheckBox.Active;
+				selectedItem.UseOutputPad       = useOutputPadCheckBox.Active;
+			}
+		}
+		
+		void selectEvent(object sender, EventArgs e)
+		{
+			SetEnabledStatus(toolListBox.Selection.CountSelectedRows() > 0, removeButton);
+			
+			titleTextBox.Changed      -= new EventHandler(setToolValues);
+			commandTextBox.Changed    -= new EventHandler(setToolValues);
+			argumentTextBox.Changed   -= new EventHandler(setToolValues);
+			workingDirTextBox.Changed   -= new EventHandler(setToolValues);
+			promptArgsCheckBox.Toggled   -= new EventHandler(setToolValues);
+			useOutputPadCheckBox.Toggled -= new EventHandler(setToolValues);
+			
+			if (toolListBox.Selection.CountSelectedRows() == 1) {				
+				TreeIter selectedIter;
+				TreeModel ls;
+				// FIXME: use this line of code when Selection.GetSelectedRows()[index] issue is fixed
+				//selectedIter = (TreeIter) (toolListBox.Selection.GetSelectedRows(toolListBoxStore)[0]);				
+				toolListBox.Selection.GetSelected(out ls, out selectedIter);
+				
+				// get the value as an external tool object				
+				ExternalTool selectedItem = (ExternalTool) toolListBox.Model.GetValue(selectedIter, 1);
+				
+				SetEnabledStatus(true, dependendControls);
+				titleTextBox.Text      = selectedItem.MenuCommand;
+				commandTextBox.Text    = selectedItem.Command;
+				argumentTextBox.Text   = selectedItem.Arguments;
+				workingDirTextBox.Text = selectedItem.InitialDirectory;
+				promptArgsCheckBox.Active   = selectedItem.PromptForArguments;
+				useOutputPadCheckBox.Active = selectedItem.UseOutputPad;
+			} else {
+				SetEnabledStatus(false, dependendControls);
+				
+				titleTextBox.Text      = String.Empty;
+				commandTextBox.Text    = String.Empty;
+				argumentTextBox.Text   = String.Empty;
+				workingDirTextBox.Text = String.Empty;
+				promptArgsCheckBox.Active   = false;
+				useOutputPadCheckBox.Active = false;
+			}
+			
+			titleTextBox.Changed      += new EventHandler(setToolValues);
+			commandTextBox.Changed    += new EventHandler(setToolValues);
+			argumentTextBox.Changed   += new EventHandler(setToolValues);
+			workingDirTextBox.Changed += new EventHandler(setToolValues);
+			promptArgsCheckBox.Toggled   += new EventHandler(setToolValues);
+			useOutputPadCheckBox.Toggled += new EventHandler(setToolValues);
+		}
+		
+		void removeEvent(object sender, EventArgs e)
+		{
+	// FIXME: use this block of code when Selection.GetSelectedRows()[index] issue is fixed
+	/*
+			GLib.List selectedItems = (GLib.List) toolListBox.Selection.GetSelectedRows(toolListBoxStore).Clone();
+			int maxIndex = selectedItems.Count - 1;
+			// erase them in reverse order
+			for(int i= maxIndex; i >= 0; i--) {
+				TreeIter removeIter = (TreeIter) selectedItems[i];
+				((ListStore) toolListBox.Model).Remove(out removeIter);
+				toolListBoxItemCount --;
+			}			
+			if (toolListBoxItemCount == 0) {
+				selectEvent(this, EventArgs.Empty);
+			} else {
+				SetSelectedIndex(toolListBox, Math.Min(index,toolListBoxItemCount - 1));
+			}
+	*/
+			TreeModel model;
+			TreeIter iter;
+			if(toolListBox.Selection.GetSelected(out model, out iter)) {
+				((ListStore) model).Remove(out iter);
+			}	
+		}
+		
+		void addEvent(object sender, EventArgs e)
+		{
+			TreeIter itr = toolListBoxStore.AppendValues("New Tool", new ExternalTool());
+			toolListBoxItemCount ++;
+			toolListBox.Selection.UnselectAll();
+			toolListBox.Selection.SelectIter(itr);
+		}
+		
+		// added this event to get the last select row index from gtk TreeView
+		int GetSelectedIndex(TreeView tv)
+		{
+			TreeModel model;
+			TreeIter itr;
+			// FIXME: change block of code when Selection.GetSelectedRows()[index] issue is fixed
+			// it will need to use the GLib.List of selected items and simply return the first one
+			if(tv.Selection.GetSelected(out model, out itr))
+			{
+				// return index of first level node (since only 1 level list model)
+				return model.GetPath(itr).Indices[0];
+			}
+			else
+			{
+				return -1;
+			}
+		}
+		
+		// added this event to set a specific row as selected from index
+		void SetSelectedIndex(TreeView tv, int index)
+		{
+			//convert index to a path
+			TreePath path = new TreePath(index.ToString());
+			tv.Selection.UnselectAll();
+			tv.Selection.SelectPath(path);
+		}
+		
+		// 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;
+				}
+			}
+		}
+	}
+}

--=-kdsbY0ln67zt+ipaaaXd--