diff options
author | Lluis Sanchez <lluis@novell.com> | 2010-03-17 15:35:28 +0300 |
---|---|---|
committer | Lluis Sanchez <lluis@novell.com> | 2010-03-17 15:35:28 +0300 |
commit | 8fa37870e9cc22ffccdd494fa951b2c3807d7978 (patch) | |
tree | bda14806802947c51676c183b08f166878964c40 /main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Extensions | |
parent | f1a8582658af8aeb0f6fa459965a2e4d0684c347 (diff) | |
parent | 585086f0ea0a49166046bb8f48d2def87907d0e0 (diff) |
Merged MD.Projects into MD.Core, and MD.Projects.Gui, MD.Core.Gui and MD.Components into MD.Ide.
svn path=/trunk/monodevelop/; revision=153730
Diffstat (limited to 'main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Extensions')
7 files changed, 650 insertions, 0 deletions
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Extensions/ISelectFileDialog.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Extensions/ISelectFileDialog.cs new file mode 100644 index 0000000000..0018fc84c1 --- /dev/null +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Extensions/ISelectFileDialog.cs @@ -0,0 +1,127 @@ +// +// ISelectFileDialog.cs +// +// Author: +// Lluis Sanchez Gual <lluis@novell.com> +// +// Copyright (c) 2010 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +
+using System; +
+namespace MonoDevelop.Components.Extensions
+{ + /// <summary> + /// This interface can be implemented to provide a custom implementation + /// for the SelectFileDialog dialog. + /// </summary>
+ public interface ISelectFileDialogHandler
+ { + bool Run (SelectFileDialogData data);
+ } + + /// <summary> + /// Data for the ISelectFileDialogHandler implementation + /// </summary> + public class SelectFileDialogData: PlatformDialogData + { + public Gtk.FileChooserAction Action { get; set; } + public string CurrentFolder { get; set; } + public bool SelectMultiple { get; set; } + public string[] SelectedFiles { get; set; } + public string InitialFileName { get; set; } + } + + /// <summary> + /// Generic class to be used to implement file selectors. + /// The T type argument is the type of the handler. + /// The U type is the type of the data parameter (must subclass SelectFileDialogData) + /// </summary> + public class SelectFileDialog<T,U>: PlatformDialog<T,U> where U:SelectFileDialogData, new() + { + /// <summary> + /// Action to perform with the file dialog. + /// </summary> + public Gtk.FileChooserAction Action { + get { return data.Action; } + set { data.Action = value; } + } + + /// <summary> + /// Folder to show by default. + /// </summary> + public string CurrentFolder { + get { return data.CurrentFolder; } + set { data.CurrentFolder = value; } + } + + /// <summary> + /// Set to True to allow multiple selection. + /// </summary> + public bool SelectMultiple { + get { return data.SelectMultiple; } + set { data.SelectMultiple = value; } + } + + /// <summary> + /// List of selected files (or folders). + /// </summary> + public string[] SelectedFiles { + get { return data.SelectedFiles; } + } + + /// <summary> + /// Selected file (or folder) when using single selection mode. + /// </summary> + public string SelectedFile { + get { return data.SelectedFiles.Length > 0 ? data.SelectedFiles [0] : null; } + } + + /// <summary> + /// File name to show by default. + /// </summary> + public string InitialFileName { + get { return data.InitialFileName; } + set { data.InitialFileName = value; } + } + + /// <summary> + /// Runs the default implementation of the dialog. + /// </summary> + protected bool RunDefault () + { + FileSelector fdiag = new FileSelector (data.Title, data.Action); + fdiag.SelectMultiple = data.SelectMultiple; + fdiag.TransientFor = data.TransientFor;
+ if (!string.IsNullOrEmpty(data.CurrentFolder))
+ fdiag.SetCurrentFolder(data.CurrentFolder);
+ if (!string.IsNullOrEmpty(data.InitialFileName)) + fdiag.SetFilename (data.InitialFileName); + + try { + int result = fdiag.Run (); + data.SelectedFiles = fdiag.Filenames; + return result == (int) Gtk.ResponseType.Ok; + } finally { + fdiag.Destroy (); + } + } + } +}
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Extensions/MimeTypeNode.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Extensions/MimeTypeNode.cs new file mode 100644 index 0000000000..0bb81a42f0 --- /dev/null +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Extensions/MimeTypeNode.cs @@ -0,0 +1,133 @@ +// MimeTypeNode.cs +// +// Author: +// Lluis Sanchez Gual <lluis@novell.com> +// +// Copyright (c) 2008 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// +// + +using System; +using System.Text; +using System.IO; +using System.Text.RegularExpressions; +using Mono.Addins; +using MonoDevelop.Core; + +namespace MonoDevelop.Ide.Extensions +{ + [ExtensionNodeChild (typeof(MimeTypeFileNode), "File")] + class MimeTypeNode: ExtensionNode + { + [NodeAttribute] + string icon; + + [NodeAttribute ("_description", Localizable=true)] + string description; + + [NodeAttribute (Required=false)] + string baseType; + + [NodeAttribute (Required=false)] + protected bool isText; + + Regex regex; + + public IconId Icon { + get { + return icon; + } + set { + icon = value; + } + } + + public string Description { + get { + return description; + } + set { + description = value; + } + } + + public string BaseType { + get { + if (string.IsNullOrEmpty (baseType)) + return isText ? "text/plain" : null; + else + return baseType; + } + } + + Regex CreateRegex () + { + StringBuilder globalPattern = new StringBuilder (); + + foreach (MimeTypeFileNode file in ChildNodes) { + string pattern = Regex.Escape (file.Pattern); + pattern = pattern.Replace ("\\*",".*"); + pattern = pattern.Replace ("\\?","."); + pattern = pattern.Replace ("\\|","$|^"); + pattern = "^" + pattern + "$"; + if (globalPattern.Length > 0) + globalPattern.Append ('|'); + globalPattern.Append (pattern); + } + return new Regex (globalPattern.ToString ()); + } + + + public bool SupportsFile (string fileName) + { + if (regex == null) + regex = CreateRegex (); + return regex.IsMatch (fileName); + } + + protected override void OnChildNodeAdded (ExtensionNode node) + { + base.OnChildNodeAdded (node); + regex = null; + } + + protected override void OnChildNodeRemoved (ExtensionNode node) + { + base.OnChildNodeRemoved (node); + regex = null; + } + } + + class MimeTypeFileNode: ExtensionNode + { + [NodeAttribute] + string pattern; + + public string Pattern { + get { + return pattern; + } + set { + pattern = value; + } + } + } +} diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Extensions/MimeTypeOptionsPanelNode.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Extensions/MimeTypeOptionsPanelNode.cs new file mode 100644 index 0000000000..25669768dc --- /dev/null +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Extensions/MimeTypeOptionsPanelNode.cs @@ -0,0 +1,48 @@ +// +// MimeTypeOptionsPanelNode.cs +// +// Author: +// Lluis Sanchez Gual <lluis@novell.com> +// +// Copyright (c) 2009 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System; +using Mono.Addins; + +namespace MonoDevelop.Projects.Gui.Extensions +{ + public class MimeTypeOptionsPanelNode: TypeExtensionNode + { + [NodeAttribute] + protected string mimeType; + + [NodeAttribute ("_label")] + protected string label; + + public string MimeType { + get { return mimeType; } + } + + public string Label { + get { return label; } + } + } +} diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Extensions/OptionsDialogSection.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Extensions/OptionsDialogSection.cs new file mode 100644 index 0000000000..c1637c862b --- /dev/null +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Extensions/OptionsDialogSection.cs @@ -0,0 +1,64 @@ +// OptionsDialogSection.cs +// +// Author: +// Lluis Sanchez Gual <lluis@novell.com> +// +// Copyright (c) 2008 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// +// + +using System; +using Mono.Addins; +using MonoDevelop.Core; + +namespace MonoDevelop.Ide.Extensions +{ + [ExtensionNodeChild (typeof(OptionsDialogSection))] + [ExtensionNodeChild (typeof(OptionsPanelNode))] + [ExtensionNode ("Section")] + public class OptionsDialogSection: OptionsPanelNode, ICloneable + { + [NodeAttribute ()] + string icon; + + public OptionsDialogSection () + { + } + + public OptionsDialogSection (Type panelType): base (panelType) + { + } + + public IconId Icon { + get { + return icon; + } + set { + icon = value; + } + } + + public object Clone () + { + return MemberwiseClone (); + } + } +} diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Extensions/OptionsPanelNode.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Extensions/OptionsPanelNode.cs new file mode 100644 index 0000000000..2d8dc1e493 --- /dev/null +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Extensions/OptionsPanelNode.cs @@ -0,0 +1,114 @@ +// OptionsPanelExtensionNode.cs +// +// Author: +// Lluis Sanchez Gual <lluis@novell.com> +// +// Copyright (c) 2008 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// +// + +using System; +using Mono.Addins; +using MonoDevelop.Ide.Gui.Dialogs; + +namespace MonoDevelop.Ide.Extensions +{ + [ExtensionNode ("Panel")] + public class OptionsPanelNode: TypeExtensionNode + { + [NodeAttribute ("class")] + protected string typeName; + + [NodeAttribute ("_label", Localizable=true)] + protected string label; + + [NodeAttribute] + protected PanelGrouping grouping = PanelGrouping.Auto; + + [NodeAttribute] + protected bool fill = false; + + Type panelType; + + public OptionsPanelNode () + { + } + + public OptionsPanelNode (Type panelType) + { + this.panelType = panelType; + } + + public string Label { + get { + return label; + } + set { + label = value; + } + } + + public PanelGrouping Grouping { + get { + return grouping; + } + set { + grouping = value; + } + } + + public bool Fill { + get { + return fill; + } + set { + fill = value; + } + } + + public string TypeName { + get { + return typeName; + } + } + + internal bool CustomNode { + get { return panelType != null; } + } + + public virtual IOptionsPanel CreatePanel () + { + if (panelType != null) + return (IOptionsPanel) Activator.CreateInstance (panelType); + IOptionsPanel p = Addin.CreateInstance (typeName, true) as IOptionsPanel; + if (p == null) + throw new System.InvalidOperationException ("Type '" + typeName + "' does not implement IOptionsPanel"); + return p; + } + } + + public enum PanelGrouping + { + Auto, + Tab, + Box + } +} diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Extensions/PlatformDialog.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Extensions/PlatformDialog.cs new file mode 100644 index 0000000000..f759ec6101 --- /dev/null +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Extensions/PlatformDialog.cs @@ -0,0 +1,87 @@ +// +// PlatformDialog.cs +// +// Author: +// Lluis Sanchez Gual <lluis@novell.com> +// +// Copyright (c) 2010 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +
+using System; +using Mono.Addins;
+
+namespace MonoDevelop.Components.Extensions
+{ + /// <summary> + /// Base class for platform dialog data + /// </summary>
+ public class PlatformDialogData + { + public string Title { get; set; } + public Gtk.Window TransientFor { get; set; } + } + + /// <summary> + /// Base class to be used to implement platform-specific dialogs. + /// T is the handler type. + /// U is the data type where data will be hold. + /// </summary> + public class PlatformDialog<T,U> where U: PlatformDialogData, new() + { + T handler; + bool gotHandler; + + /// <summary> + /// Dialog data + /// </summary> + protected U data = new U (); + + protected T Handler { + get { + if (!gotHandler) { + gotHandler = true; + foreach (object h in AddinManager.GetExtensionObjects ("/MonoDevelop/Components/DialogHandlers", true)) { + if (h is T) { + handler = (T) h; + break; + } + } + } + return handler; + } + } + + /// <summary> + /// Title of the dialog. + /// </summary> + public string Title { + get { return data.Title; } + set { data.Title = value; } + } + + /// <summary> + /// Parent window. + /// </summary> + public Gtk.Window TransientFor { + get { return data.TransientFor; } + set { data.TransientFor = value; } + } + } +}
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Extensions/StockIconCodon.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Extensions/StockIconCodon.cs new file mode 100644 index 0000000000..5b07d1747e --- /dev/null +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Extensions/StockIconCodon.cs @@ -0,0 +1,77 @@ +// +// StockIconAssembly.cs +// +// Author: +// Lluis Sanchez Gual +// + +// +// Copyright (C) 2005 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + + +using System; +using System.Collections; +using System.ComponentModel; +using Mono.Addins; + +namespace MonoDevelop.Ide.Extensions +{ + [ExtensionNode (Description="A stock icon. It is possible to register several icons with the same 'id' and different sizes.")] + internal class StockIconCodon : ExtensionNode + { + [NodeAttribute ("stockid", true, "Id of the stock icon.")] + string stockid; + + [NodeAttribute ("size", "Size of the icon.")] + Gtk.IconSize size = Gtk.IconSize.Invalid; + + [NodeAttribute ("resource", "Name of the resource where the icon is stored.")] + string resource; + + [NodeAttribute ("file", "Name of the file where the icon is stored.")] + string file; + + [NodeAttribute ("icon", "Id of another icon or combination of icons to assign to this stock id.")] + string iconid; + + public string StockId { + get { return stockid; } + } + + public Gtk.IconSize IconSize { + get { return size; } + } + + public string Resource { + get { return resource; } + } + + public string File { + get { return file; } + } + + public string IconId { + get { return iconid; } + } + } +} |