Browse Source

Added "Reformat" menu item in Edit and editor context menues. Showing "(solution)" or "(global)" instead of "(default)" on settings referring to parent settings container.

pull/403/head
Andreas Weizel 12 years ago
parent
commit
fa88338bd7
  1. 8
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormattingStrategy/CSharpFormattingOptionsContainer.cs
  2. 15
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormattingStrategy/CSharpFormattingOptionsPersistence.cs
  3. 12
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormattingStrategy/CSharpFormattingStrategy.cs
  4. 5
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormattingStrategy/FormattingOptionBinding.cs
  5. 4
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/OptionPanels/CSharpFormattingEditor.xaml.cs
  6. 5
      src/Main/Base/Project/ICSharpCode.SharpDevelop.addin
  7. 1
      src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj
  8. 41
      src/Main/Base/Project/Src/Editor/Commands/ReformatSelection.cs

8
src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormattingStrategy/CSharpFormattingOptionsContainer.cs

@ -55,6 +55,12 @@ namespace CSharpBinding.FormattingStrategy @@ -55,6 +55,12 @@ namespace CSharpBinding.FormattingStrategy
cachedOptions = CreateCachedOptions();
}
public string DefaultText
{
get;
set;
}
public CSharpFormattingOptionsContainer Parent
{
get {
@ -69,7 +75,7 @@ namespace CSharpBinding.FormattingStrategy @@ -69,7 +75,7 @@ namespace CSharpBinding.FormattingStrategy
public void Reset(CSharpFormattingOptions options = null)
{
activeOptions.Clear();
cachedOptions = options ?? FormattingOptionsFactory.CreateEmpty();
cachedOptions = options ?? CreateCachedOptions();
if ((options != null) || (parent == null)) {
// Activate all options
foreach (var property in typeof(CSharpFormattingOptions).GetProperties()) {

15
src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormattingStrategy/CSharpFormattingOptionsPersistence.cs

@ -47,7 +47,10 @@ namespace CSharpBinding.FormattingStrategy @@ -47,7 +47,10 @@ namespace CSharpBinding.FormattingStrategy
// Load global settings
GlobalOptions = new CSharpFormattingOptionsPersistence(
SD.PropertyService.MainPropertiesContainer, new CSharpFormattingOptionsContainer());
SD.PropertyService.MainPropertiesContainer, new CSharpFormattingOptionsContainer()
{
DefaultText = "(global)" // TODO Localize!
});
GlobalOptions.Load();
// Handlers for solution loading/unloading
@ -76,7 +79,10 @@ namespace CSharpBinding.FormattingStrategy @@ -76,7 +79,10 @@ namespace CSharpBinding.FormattingStrategy
// Lazily create options container for project
projectOptions[key] = new CSharpFormattingOptionsPersistence(
csproject.ExtensionProperties,
new CSharpFormattingOptionsContainer((SolutionOptions ?? GlobalOptions).OptionsContainer));
new CSharpFormattingOptionsContainer((SolutionOptions ?? GlobalOptions).OptionsContainer)
{
DefaultText = "(project)" // TODO Localize!
});
}
return projectOptions[key];
@ -90,7 +96,10 @@ namespace CSharpBinding.FormattingStrategy @@ -90,7 +96,10 @@ namespace CSharpBinding.FormattingStrategy
// Load solution settings
SolutionOptions = new CSharpFormattingOptionsPersistence(
e.Solution.GlobalPreferences,
new CSharpFormattingOptionsContainer(GlobalOptions.OptionsContainer));
new CSharpFormattingOptionsContainer(GlobalOptions.OptionsContainer)
{
DefaultText = "(solution)" // TODO Localize!
});
}
static void SolutionClosed(object sender, SolutionEventArgs e)

12
src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormattingStrategy/CSharpFormattingStrategy.cs

@ -425,6 +425,18 @@ namespace CSharpBinding.FormattingStrategy @@ -425,6 +425,18 @@ namespace CSharpBinding.FormattingStrategy
}
}
return;
case (char) 0:
// In any other case: Simply format selection or whole document
var formattingOptions = CSharpFormattingOptionsPersistence.GetProjectOptions(SD.ProjectService.CurrentProject);
int formattedTextOffset = 0;
int formattedTextLength = textArea.Document.TextLength;
if (textArea.SelectionLength != 0) {
formattedTextOffset = textArea.SelectionStart;
formattedTextLength = textArea.SelectionLength;
}
CSharpFormatterHelper.Format(textArea, formattedTextOffset, formattedTextLength, formattingOptions.OptionsContainer);
break;
}
}

5
src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormattingStrategy/FormattingOptionBinding.cs

@ -68,7 +68,10 @@ namespace CSharpBinding.FormattingStrategy @@ -68,7 +68,10 @@ namespace CSharpBinding.FormattingStrategy
if (container.Parent != null) {
// Add "default" entry in ComboBox
// TODO Add located resource, maybe context-bound, like "(solution)" or "(global)"!
comboBox.Items.Add(new ComboBoxItem { Content = "(default)", Tag = null });
comboBox.Items.Add(new ComboBoxItem {
Content = (container.Parent ?? container).DefaultText,
Tag = null
});
comboBox.SelectedIndex = 0;
}

4
src/AddIns/BackendBindings/CSharpBinding/Project/Src/OptionPanels/CSharpFormattingEditor.xaml.cs

@ -146,7 +146,7 @@ namespace CSharpBinding.OptionPanels @@ -146,7 +146,7 @@ namespace CSharpBinding.OptionPanels
private void FillPresetList(CSharpFormattingOptionsContainer container)
{
presets["Default"] = () => null;
presets["(default)"] = () => null;
presets["Empty"] = FormattingOptionsFactory.CreateEmpty;
presets["SharpDevelop"] = FormattingOptionsFactory.CreateSharpDevelop;
presets["Mono"] = FormattingOptionsFactory.CreateMono;
@ -158,7 +158,7 @@ namespace CSharpBinding.OptionPanels @@ -158,7 +158,7 @@ namespace CSharpBinding.OptionPanels
// TODO Localize!
if (container.Parent != null) {
// Add a "default" preset
presetItems.Add(new ComboBoxItem { Content = "Default", Tag = "Default" });
presetItems.Add(new ComboBoxItem { Content = (container.Parent ?? container).DefaultText, Tag = "(default)" });
}
presetItems.Add(new ComboBoxItem { Content = "Empty", Tag = "Empty" });
presetItems.Add(new ComboBoxItem { Content = "SharpDevelop", Tag = "SharpDevelop" });

5
src/Main/Base/Project/ICSharpCode.SharpDevelop.addin

@ -2078,6 +2078,10 @@ @@ -2078,6 +2078,10 @@
label = "${res:XML.TextAreaContextMenu.Indent}"
shortcut = "Control|I"
class = "ICSharpCode.SharpDevelop.Editor.Commands.IndentSelection" />
<MenuItem id = "Reformat"
label = "Reformat"
shortcut = "Control|Alt|F"
class = "ICSharpCode.SharpDevelop.Editor.Commands.ReformatSelection" />
</Path>
<Path name = "/SharpDevelop/ViewContent/TextEditor/ToolTips">
@ -2122,6 +2126,7 @@ @@ -2122,6 +2126,7 @@
<MenuItem id = "Separator4" type = "Separator" />
<Include id = "Comment" item = "/SharpDevelop/ViewContent/TextEditor/ContextMenu/Comment" />
<Include id = "Indent" item = "/SharpDevelop/ViewContent/TextEditor/ContextMenu/Indent" />
<Include id = "Reformat" item = "/SharpDevelop/ViewContent/TextEditor/ContextMenu/Reformat" />
</MenuItem>
<MenuItem insertbefore = "SelectAll" id = "Separator3" type = "Separator" />
</Path>

1
src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj

@ -229,6 +229,7 @@ @@ -229,6 +229,7 @@
<Compile Include="Src\Editor\Commands\DeclaringTypeSubMenuBuilder.cs" />
<Compile Include="Src\Editor\Commands\FindReferencesCommand.cs" />
<Compile Include="Src\Editor\Commands\GotoLineNumber.cs" />
<Compile Include="Src\Editor\Commands\ReformatSelection.cs" />
<Compile Include="Src\Editor\Commands\SymbolUnderCaretMenuCommand.cs" />
<Compile Include="Editor\CodeCompletion\CodeCompletionBinding.cs" />
<Compile Include="Editor\CodeCompletion\CodeCompletionDataUsageCache.cs" />

41
src/Main/Base/Project/Src/Editor/Commands/ReformatSelection.cs

@ -0,0 +1,41 @@ @@ -0,0 +1,41 @@
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// 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 ICSharpCode.Core;
namespace ICSharpCode.SharpDevelop.Editor.Commands
{
/// <summary>
/// Menu command to reformat selected code or whole document according to formatter settings.
/// </summary>
public class ReformatSelection : AbstractMenuCommand
{
/// <summary>
/// Starts the command.
/// </summary>
public override void Run()
{
ITextEditor editor = SD.GetActiveViewContentService<ITextEditor>();
if (editor == null)
return;
editor.Language.FormattingStrategy.FormatLine(editor, (char) 0);
}
}
}
Loading…
Cancel
Save