diff options
author | Mike Krüger <mkrueger@novell.com> | 2009-06-05 16:34:46 +0400 |
---|---|---|
committer | Mike Krüger <mkrueger@novell.com> | 2009-06-05 16:34:46 +0400 |
commit | 3305e43dfcefbbeba93d5712d1ff7f1aa1581526 (patch) | |
tree | 1a5ab28b18a339b3dce8672d834836280e20fd42 /main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeFormatting | |
parent | fb74188a951069b7ea6011b71783b625fb49f1e9 (diff) | |
parent | e905418656da9e2f9fab93cbd610c17cfa439a3f (diff) |
* Makefile.am:
* gtk-gui/gui.stetic:
* MonoDevelop.Ide.csproj:
* MonoDevelop.Ide.addin.xml:
* MonoDevelop.Ide.CodeFormatting/AddPolicyDialog.cs:
* MonoDevelop.Ide.CodeFormatting/CodeFormattingCommands.cs:
* gtk-gui/MonoDevelop.Ide.CodeFormatting.AddPolicyDialog.cs:
* MonoDevelop.Ide.CodeFormatting/CodeFormattingPolicyPanel.cs:
* gtk-gui/MonoDevelop.Ide.CodeTemplates.EditTemplateDialog.cs:
* MonoDevelop.Ide.CodeFormatting/EditFormattingPolicyDialog.cs:
* MonoDevelop.Ide.CodeFormatting/CodeFormattingPolicyPanelWidget.cs:
* gtk-gui/MonoDevelop.Ide.CodeFormatting.EditFormattingPolicyDialog.cs:
* gtk-gui/MonoDevelop.Ide.CodeFormatting.CodeFormattingPolicyPanelWidget.cs:
Worked on C# formatter it should now fit better in the policy
system.
svn path=/trunk/monodevelop/; revision=135515
Diffstat (limited to 'main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeFormatting')
-rw-r--r-- | main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeFormatting/CodeFormattingCommands.cs (renamed from main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeFormatting/AddPolicyDialog.cs) | 48 | ||||
-rw-r--r-- | main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeFormatting/CodeFormattingPolicyPanel.cs | 183 | ||||
-rw-r--r-- | main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeFormatting/CodeFormattingPolicyPanelWidget.cs (renamed from main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeFormatting/EditFormattingPolicyDialog.cs) | 168 |
3 files changed, 101 insertions, 298 deletions
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeFormatting/AddPolicyDialog.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeFormatting/CodeFormattingCommands.cs index c45b1f3fc4..201fe0585a 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeFormatting/AddPolicyDialog.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeFormatting/CodeFormattingCommands.cs @@ -1,5 +1,5 @@ // -// AddPolicyDialog.cs +// CodeFormattingCommands.cs // // Author: // Mike Krüger <mkrueger@novell.com> @@ -25,41 +25,37 @@ // THE SOFTWARE. using System; -using System.Collections.Generic; +using MonoDevelop.Components.Commands; using MonoDevelop.Projects.Text; -using MonoDevelop.Projects; -using MonoDevelop.Core; +using MonoDevelop.Ide.Gui; + + namespace MonoDevelop.Ide.CodeFormatting { + public enum CodeFormattingCommands { + FormatBuffer + } - - public partial class AddPolicyDialog : Gtk.Dialog + public class FormatBufferHandler : CommandHandler { - public string NewPolicyName { - get { - return entryName.Text; - } - } - public string InitFrom { - get { - return this.comboboxInitFrom.ActiveText; - } + protected override void Update (CommandArrayInfo info) + { + // if (IdeApp.Workspace.Items.Count == 0) + // info.Enabled = false; } - public AddPolicyDialog (List<CodeFormatSettings> settings) + protected override void Run (object tool) { - this.Build(); - this.Title = GettextCatalog.GetString ("New Profile"); - - foreach (var setting in settings) { - this.comboboxInitFrom.AppendText (setting.Name); - } - if (settings.Count == 0) - this.comboboxInitFrom.AppendText ("default"); - - this.comboboxInitFrom.Active = 0; + Document doc = IdeApp.Workbench.ActiveDocument; + if (doc == null) + return; + IPrettyPrinter printer = TextFileService.GetPrettyPrinter (IdeApp.Services.PlatformService.GetMimeTypeForUri (doc.FileName)); + if (printer == null) + return; + doc.TextEditor.Select (0, doc.TextEditor.TextLength); + doc.TextEditor.SelectedText = printer.FormatText (doc.Project, doc.TextEditor.Text); } } } diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeFormatting/CodeFormattingPolicyPanel.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeFormatting/CodeFormattingPolicyPanel.cs deleted file mode 100644 index c507ea2d26..0000000000 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeFormatting/CodeFormattingPolicyPanel.cs +++ /dev/null @@ -1,183 +0,0 @@ -// -// CodeFormattingPolicyPanel.cs -// -// Author: -// Mike Krüger <mkrueger@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 System.Collections.Generic; -using Gtk; -using MonoDevelop.Core; -using MonoDevelop.Core.Serialization; -using MonoDevelop.Projects.Gui.Dialogs; -using MonoDevelop.Projects.Text; - -namespace MonoDevelop.Ide.CodeFormatting -{ - class CodeFormattingPolicyPanel : PolicyOptionsPanel<CodeFormattingPolicy> - { - protected override string PolicyTitleWithMnemonic { - get { return GettextCatalog.GetString ("Code _Format"); } - } - - CodeFormattingPolicyPanelWidget panel; - - public override Widget CreatePanelWidget () - { - panel = new CodeFormattingPolicyPanelWidget (); - panel.ShowAll (); - return panel; - } - - protected override void LoadFrom (CodeFormattingPolicy policy) - { - panel.Policy = policy; - } - - protected override CodeFormattingPolicy GetPolicy () - { - return panel.Policy; - } - } - - [System.ComponentModel.ToolboxItem(true)] - public partial class CodeFormattingPolicyPanelWidget : Gtk.Bin - { - List<string> policies = new List<string> (); - List<CodeFormatSettings> settings; - CodeFormatDescription description; - ListStore formatStore = new ListStore (typeof (string), typeof (CodeFormatSettings)); - - public CodeFormattingPolicy Policy { - get; - set; - } - - public void FillFormattingPolicies () - { - formatStore.Clear (); - foreach (CodeFormatSettings setting in settings) { - formatStore.AppendValues (setting.Name, setting); - } - if (settings.Count == 0) - formatStore.AppendValues ("default", null); - comboboxFormattingPolicies.Active = 0; - } - - public CodeFormattingPolicyPanelWidget() - { - this.Build(); - ListStore store = new ListStore (typeof (string), typeof (string)); - store.AppendValues ("text/x-csharp", "default"); - treeviewUsedProfiles.Model = store; - treeviewUsedProfiles.AppendColumn ("mime type", new CellRendererText (), "text", 0); - treeviewUsedProfiles.AppendColumn ("profile", new CellRendererText (), "text", 1); - description = TextFileService.GetFormatDescription ("text/x-csharp"); - settings = new List<CodeFormatSettings> (TextFileService.GetAvailableSettings (description)); - - - - comboboxFormattingPolicies.Model = formatStore; - /*Gtk.CellRendererText ctx = new Gtk.CellRendererText (); - comboboxFormattingPolicies.PackStart (ctx, true); - comboboxFormattingPolicies.AddAttribute (ctx, "text", 0);*/ - - Mono.TextEditor.TextEditorOptions options = new Mono.TextEditor.TextEditorOptions (); - options.ShowLineNumberMargin = false; - options.ShowFoldMargin = false; - options.ShowIconMargin = false; - options.ShowInvalidLines = false; - options.ShowSpaces = options.ShowTabs = options.ShowEolMarkers = false; - options.ColorScheme = PropertyService.Get ("ColorScheme", "Default"); - texteditor1.Options = options; - texteditor1.Document.ReadOnly = true; - texteditor1.Document.MimeType = description.MimeType; - - buttonAdd.Clicked += ButtonAddClicked; - buttonEdit.Clicked += ButtonEditClicked; - buttonImport.Clicked += ButtonImportClicked; - buttonRemove.Clicked += ButtonRemoveClicked; - FillFormattingPolicies (); - } - - void ButtonRemoveClicked (object sender, EventArgs e) - { - int a = comboboxFormattingPolicies.Active; - if (a >= 0 && a < settings.Count) - settings.RemoveAt (a); - FillFormattingPolicies (); - TextFileService.SetSettings (description, settings); - } - - void ButtonImportClicked (object sender, EventArgs e) - { - Gtk.FileChooserDialog dialog = new Gtk.FileChooserDialog (GettextCatalog.GetString ("Import Profile"), - null, - FileChooserAction.Open, - Gtk.Stock.Cancel, Gtk.ResponseType.Cancel, Gtk.Stock.Open, Gtk.ResponseType.Ok); - FileFilter f1 = new FileFilter(); - f1.Name = "*.xml"; - f1.AddPattern ("*.xml"); - dialog.AddFilter (f1); - FileFilter f2 = new FileFilter(); - f1.Name = "*"; - f2.AddPattern ("*"); - dialog.AddFilter (f2); - if (ResponseType.Ok == (ResponseType)dialog.Run ()) { - settings.Add (description.ImportSettings (dialog.Filename)); - int a = comboboxFormattingPolicies.Active; - FillFormattingPolicies (); - comboboxFormattingPolicies.Active = a; - } - dialog.Destroy (); - } - - void ButtonEditClicked (object sender, EventArgs e) - { - EditFormattingPolicyDialog d = new EditFormattingPolicyDialog (); - CodeFormatSettings setting = new CodeFormatSettings ("New settings"); - int a = comboboxFormattingPolicies.Active; - if (a >= 0 && a < settings.Count) - setting = settings [a]; - d.SetFormat (description, setting); - d.Run (); - d.Destroy (); - FillFormattingPolicies (); - comboboxFormattingPolicies.Active = a; - } - - void ButtonAddClicked (object sender, EventArgs e) - { - AddPolicyDialog addPolicy = new AddPolicyDialog (settings); - ResponseType response = (ResponseType)addPolicy.Run (); - if (response == ResponseType.Ok) { - settings.Add (new CodeFormatSettings (TextFileService.GetSettings (description, addPolicy.InitFrom), addPolicy.NewPolicyName)); - FillFormattingPolicies (); - comboboxFormattingPolicies.Active = settings.Count - 1; - TextFileService.SetSettings (description, settings); - } - addPolicy.Destroy (); - } - } - -} diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeFormatting/EditFormattingPolicyDialog.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeFormatting/CodeFormattingPolicyPanelWidget.cs index 0f2c108e21..763a4e1a42 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeFormatting/EditFormattingPolicyDialog.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeFormatting/CodeFormattingPolicyPanelWidget.cs @@ -1,5 +1,5 @@ // -// EditFormattingPolicyDialog.cs +// CodeFormattingPolicyPanel.cs // // Author: // Mike Krüger <mkrueger@novell.com> @@ -28,84 +28,26 @@ using System; using System.Collections.Generic; using Gtk; using MonoDevelop.Core; +using MonoDevelop.Core.Serialization; +using MonoDevelop.Projects.Gui.Dialogs; using MonoDevelop.Projects.Text; using MonoDevelop.Projects; + namespace MonoDevelop.Ide.CodeFormatting { - public partial class EditFormattingPolicyDialog : Gtk.Dialog + public class TypedCodeFormattingPolicyPanelWidget<T> : CodeFormattingPolicyPanelWidget where T : class, IEquatable<T>, new () { - CodeFormatSettings settings; + T settings; CodeFormatDescription description; - ListStore comboBoxStore; Gtk.TreeStore store; TreeModel model; TreeIter iter; CodeFormatOption option; - public EditFormattingPolicyDialog() + public TypedCodeFormattingPolicyPanelWidget () { - this.Build(); - buttonOk.Clicked += ButtonOkClicked; - - buttonExport.Clicked += ButtonExportClicked; - checkbuttonWhiteSpaces.Toggled += CheckbuttonWhiteSpacesToggled; - comboboxValue.Clear (); - Gtk.CellRendererText ctx = new Gtk.CellRendererText (); - comboboxValue.PackStart (ctx, true); - comboboxValue.AddAttribute (ctx, "text", 1); - - comboBoxStore = new ListStore (typeof (string), typeof (string)); - comboboxValue.Model = comboBoxStore; - - comboboxValue.Changed += HandleChanged; - scrolledwindow2.Child = texteditor1; - scrolledwindow2.ShowAll (); - } - - void ButtonOkClicked (object sender, EventArgs e) - { - if (description == null) - return; - settings.Name = this.entryName.Text; - } - - void ButtonExportClicked (object sender, EventArgs e) - { - Gtk.FileChooserDialog dialog = new Gtk.FileChooserDialog (GettextCatalog.GetString ("Export Profile"), - this, - FileChooserAction.Save, - Gtk.Stock.Cancel, Gtk.ResponseType.Cancel, Gtk.Stock.Save, Gtk.ResponseType.Ok); - dialog.Filter = new FileFilter(); - dialog.Filter.AddPattern ("*.xml"); - if (ResponseType.Ok == (ResponseType)dialog.Run ()) { -// System.Console.WriteLine("fn:" + dialog.Filename); - description.ExportSettings (settings, dialog.Filename); - } - dialog.Destroy (); - } - - void CheckbuttonWhiteSpacesToggled (object sender, EventArgs e) - { - options.ShowSpaces = options.ShowTabs = options.ShowEolMarkers = checkbuttonWhiteSpaces.Active; - this.texteditor1.QueueDraw (); - } - - Mono.TextEditor.TextEditor texteditor1 = new Mono.TextEditor.TextEditor (); - class CustomFormattingPolicy : CodeFormattingPolicy - { - CodeFormatSettings settings; - - public CustomFormattingPolicy (CodeFormatSettings settings) - { - this.settings = settings; - } - - public override CodeFormatSettings GetSettings () - { - return settings; - } } void UpdateExample () @@ -114,28 +56,27 @@ namespace MonoDevelop.Ide.CodeFormatting if (printer == null) return; DotNetProject parent = new DotNetProject (); - parent.Policies.Set <CodeFormattingPolicy> (new CustomFormattingPolicy (settings)); + parent.Policies.Set (settings); texteditor1.Document.Text = printer.FormatText (parent, texteditor1.Document.Text); } - void HandleChanged(object sender, EventArgs e) + protected override void HandleChanged (object sender, EventArgs e) { - CodeFormatType type = description.GetCodeFormatType (option.Type); - int a = comboboxValue.Active; + CodeFormatType type = description.GetCodeFormatType (settings, option); + int a = ComboboxValue.Active; if (type == null || a < 0 || a >= type.Values.Count) return; KeyValuePair<string, string> val = type.Values[a]; - settings.SetValue (option, val.Key); + description.SetValue (settings, option, val.Key); + store.SetValue (iter, valueColumn, val.Key); store.SetValue (iter, valueDisplayTextColumn, GettextCatalog.GetString (val.Value)); UpdateExample (); } - Mono.TextEditor.TextEditorOptions options = new Mono.TextEditor.TextEditorOptions (); - public void SetFormat (CodeFormatDescription description, CodeFormatSettings settings) + + public void SetFormat (CodeFormatDescription description, T settings) { this.description = description; this.settings = settings; - this.entryName.Text = settings.Name; - this.Title = string.Format (GettextCatalog.GetString ("Edit Profile '{0}'"), settings.Name); options.ShowLineNumberMargin = false; options.ShowFoldMargin = false; options.ShowIconMargin = false; @@ -145,26 +86,27 @@ namespace MonoDevelop.Ide.CodeFormatting texteditor1.Options = options; texteditor1.Document.ReadOnly = true; texteditor1.Document.MimeType = description.MimeType; - while (notebookCategories.NPages > 0) { - notebookCategories.RemovePage (0); + while (NotebookCategories.NPages > 0) { + NotebookCategories.RemovePage (0); } if (description != null) { Gtk.Label label = new Gtk.Label (GettextCatalog.GetString ("Text Style")); - notebookCategories.AppendPage (new OverrideTextSettingsPolicyWidget (), label); + NotebookCategories.AppendPage (new OverrideTextSettingsPolicyWidget (), label); foreach (CodeFormatCategory category in description.SubCategories) { AddCategoryPage (category); } } - notebookCategories.ShowAll (); + NotebookCategories.ShowAll (); } + const int keyColumn = 0; const int valueColumn = 1; const int valueDisplayTextColumn = 2; const int objectColumn = 3; - public CodeFormatSettings Settings { + public T Settings { get { return settings; } @@ -173,10 +115,10 @@ namespace MonoDevelop.Ide.CodeFormatting void AppendCategory (Gtk.TreeStore store, TreeIter iter, CodeFormatCategory category) { TreeIter categoryIter = iter.Equals (TreeIter.Zero) - ? store.AppendValues (GettextCatalog.GetString (category.DisplayName), null, category) - : store.AppendValues (iter, GettextCatalog.GetString (category.DisplayName), null, category); + ? store.AppendValues (GettextCatalog.GetString (category.DisplayName), null, null, category) + : store.AppendValues (iter, GettextCatalog.GetString (category.DisplayName), null, null, category); foreach (CodeFormatOption option in category.Options) { - KeyValuePair<string, string> val = settings.GetValue (description, option); + KeyValuePair<string, string> val = description.GetValue (settings, option); store.AppendValues (categoryIter, GettextCatalog.GetString (option.DisplayName), val.Key, @@ -190,7 +132,7 @@ namespace MonoDevelop.Ide.CodeFormatting void AddCategoryPage (CodeFormatCategory category) { Gtk.Label label = new Gtk.Label (GettextCatalog.GetString (category.DisplayName)); - Gtk.TreeStore store = new Gtk.TreeStore (typeof(string), typeof (string), typeof (string), typeof (object)); + Gtk.TreeStore store = new Gtk.TreeStore (typeof (string), typeof (string), typeof (string), typeof (object)); foreach (CodeFormatCategory cat in category.SubCategories) { AppendCategory (store, TreeIter.Zero, cat); } @@ -200,7 +142,7 @@ namespace MonoDevelop.Ide.CodeFormatting tree.Selection.Changed += TreeSelectionChanged; ScrolledWindow sw = new ScrolledWindow (); sw.Child = tree; - notebookCategories.AppendPage (sw, label); + NotebookCategories.AppendPage (sw, label); } void TreeSelectionChanged (object sender, EventArgs e) @@ -214,24 +156,72 @@ namespace MonoDevelop.Ide.CodeFormatting // comboboxentryValue.Sensitive = false; return; } - comboboxValue.Changed -= HandleChanged; + ComboboxValue.Changed -= HandleChanged; // comboboxentryValue.Sensitive = true; - CodeFormatType type = description.GetCodeFormatType (option.Type); + CodeFormatType type = description.GetCodeFormatType (settings, option); texteditor1.Document.Text = option.Example; comboBoxStore.Clear (); int active = 0, i = 0; - KeyValuePair<string, string> curValue = settings.GetValue (description, option); + KeyValuePair<string, string> curValue = description.GetValue (settings, option); foreach (KeyValuePair<string, string> v in type.Values) { if (v.Key == curValue.Key) active = i; comboBoxStore.AppendValues (v.Key, GettextCatalog.GetString (v.Value)); i++; } - comboboxValue.Active = active; - comboboxValue.Changed += HandleChanged; + ComboboxValue.Active = active; + ComboboxValue.Changed += HandleChanged; UpdateExample (); } } } + + [System.ComponentModel.ToolboxItem(true)] + public partial class CodeFormattingPolicyPanelWidget : Gtk.Bin + { + protected ListStore comboBoxStore; + protected Mono.TextEditor.TextEditor texteditor1 = new Mono.TextEditor.TextEditor (); + protected Mono.TextEditor.TextEditorOptions options = new Mono.TextEditor.TextEditorOptions (); + + protected Notebook NotebookCategories { + get { + return notebookCategories; + } + } + protected ComboBox ComboboxValue { + get { + return comboboxValue; + } + } + + public CodeFormattingPolicyPanelWidget () + { + this.Build(); + checkbuttonWhiteSpaces.Toggled += CheckbuttonWhiteSpacesToggled; + comboboxValue.Clear (); + Gtk.CellRendererText ctx = new Gtk.CellRendererText (); + comboboxValue.PackStart (ctx, true); + comboboxValue.AddAttribute (ctx, "text", 1); + + comboBoxStore = new ListStore (typeof (string), typeof (string)); + comboboxValue.Model = comboBoxStore; + + comboboxValue.Changed += HandleChanged; + scrolledwindow2.Child = texteditor1; + ShowAll (); + } + + protected virtual void HandleChanged (object sender, EventArgs e) + { + } + + void CheckbuttonWhiteSpacesToggled (object sender, EventArgs e) + { + options.ShowSpaces = options.ShowTabs = options.ShowEolMarkers = checkbuttonWhiteSpaces.Active; + this.texteditor1.QueueDraw (); + } + + + } } |