Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit 5da7b92

Browse files
committed
Added editing of solution-wide formatting options (accessible through property pad).
1 parent 144fde6 commit 5da7b92

5 files changed

Lines changed: 82 additions & 10 deletions

File tree

src/AddIns/BackendBindings/CSharpBinding/Project/CSharpBinding.addin

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,12 @@
158158
</OptionPanel>
159159
</Path>
160160

161+
<Path path = "/SharpDevelop/Dialogs/SolutionFormattingOptionsDialog">
162+
<OptionPanel id="C#Formatting"
163+
label="C#"
164+
class="CSharpBinding.OptionPanels.CSharpSolutionFormattingOptionPanel"/>
165+
</Path>
166+
161167
<Path path = "/SharpDevelop/Workbench/MainMenu/Search">
162168
<MenuItem id = "SearchForIssues"
163169
label="Search For Issues..."

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ public void CloneFrom(CSharpFormattingOptionsContainer options)
9999
activeOptions.Clear();
100100
foreach (var activeOption in options.activeOptions)
101101
activeOptions.Add(activeOption);
102-
Reset(options.cachedOptions.Clone());
102+
cachedOptions = options.cachedOptions.Clone();
103+
OnPropertyChanged(null);
103104
}
104105

105106
#region INotifyPropertyChanged implementation

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

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ internal class FormattingGroupContainer : DependencyObject, IFormattingItemConta
4747

4848
public static readonly DependencyProperty TextProperty =
4949
DependencyProperty.Register("Text", typeof(string), typeof(FormattingGroupContainer),
50-
new FrameworkPropertyMetadata());
50+
new FrameworkPropertyMetadata());
5151

5252
public string Text {
5353
get { return (string) GetValue(TextProperty); }
@@ -85,7 +85,7 @@ internal class FormattingOption : DependencyObject
8585
{
8686
public static readonly DependencyProperty TextProperty =
8787
DependencyProperty.Register("Text", typeof(string), typeof(FormattingOption),
88-
new FrameworkPropertyMetadata());
88+
new FrameworkPropertyMetadata());
8989
public string Text {
9090
get { return (string) GetValue(TextProperty); }
9191
set { SetValue(TextProperty, value); }
@@ -113,13 +113,11 @@ public CSharpFormattingEditor()
113113

114114
InitializeComponent();
115115
this.DataContext = this;
116-
117-
FillPresetList();
118116
}
119117

120118
public static readonly DependencyProperty OptionsContainerProperty =
121119
DependencyProperty.Register("OptionsContainer", typeof(CSharpFormattingOptionsContainer), typeof(CSharpFormattingEditor),
122-
new FrameworkPropertyMetadata());
120+
new FrameworkPropertyMetadata(OnOptionsContainerPropertyChanged));
123121

124122
public CSharpFormattingOptionsContainer OptionsContainer {
125123
get { return (CSharpFormattingOptionsContainer)GetValue(OptionsContainerProperty); }
@@ -128,15 +126,27 @@ public CSharpFormattingOptionsContainer OptionsContainer {
128126

129127
public static readonly DependencyProperty AllowPresetsProperty =
130128
DependencyProperty.Register("AllowPresets", typeof(bool), typeof(CSharpFormattingEditor),
131-
new FrameworkPropertyMetadata());
129+
new FrameworkPropertyMetadata());
132130

133131
public bool AllowPresets {
134132
get { return (bool)GetValue(AllowPresetsProperty); }
135133
set { SetValue(AllowPresetsProperty, value); }
136134
}
137135

138-
private void FillPresetList()
136+
static void OnOptionsContainerPropertyChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
139137
{
138+
var editor = o as CSharpFormattingEditor;
139+
if (editor != null) {
140+
var container = e.NewValue as CSharpFormattingOptionsContainer;
141+
if (container != null) {
142+
editor.FillPresetList(container);
143+
}
144+
}
145+
}
146+
147+
private void FillPresetList(CSharpFormattingOptionsContainer container)
148+
{
149+
presets["Default"] = () => null;
140150
presets["Empty"] = FormattingOptionsFactory.CreateEmpty;
141151
presets["SharpDevelop"] = FormattingOptionsFactory.CreateSharpDevelop;
142152
presets["Mono"] = FormattingOptionsFactory.CreateMono;
@@ -145,7 +155,11 @@ private void FillPresetList()
145155
presets["Whitesmiths"] = FormattingOptionsFactory.CreateWhitesmiths;
146156
presets["GNU"] = FormattingOptionsFactory.CreateGNU;
147157

148-
// TODO Localize "(no preset)"!
158+
// TODO Localize!
159+
if (container.Parent != null) {
160+
// Add a "default" preset
161+
presetItems.Add(new ComboBoxItem { Content = "Default", Tag = "Default" });
162+
}
149163
presetItems.Add(new ComboBoxItem { Content = "Empty", Tag = "Empty" });
150164
presetItems.Add(new ComboBoxItem { Content = "SharpDevelop", Tag = "SharpDevelop" });
151165
presetItems.Add(new ComboBoxItem { Content = "Mono", Tag = "Mono" });

src/AddIns/BackendBindings/CSharpBinding/Project/Src/OptionPanels/CSharpFormattingOptionPanel.xaml.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,17 @@ public CSharpGlobalFormattingOptionPanel()
4545
}
4646
}
4747

48+
/// <summary>
49+
/// Option panel for solution-wide formatting settings.
50+
/// </summary>
51+
internal class CSharpSolutionFormattingOptionPanel : CSharpFormattingOptionPanel
52+
{
53+
public CSharpSolutionFormattingOptionPanel()
54+
: base(CSharpFormattingOptionsPersistence.SolutionOptions, true)
55+
{
56+
}
57+
}
58+
4859
/// <summary>
4960
/// Interaction logic for CSharpFormattingOptionPanel.xaml
5061
/// </summary>

src/Main/SharpDevelop/Project/Solution.cs

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@
1818

1919
using System;
2020
using System.Collections.Generic;
21+
using System.ComponentModel;
22+
using System.Drawing.Design;
2123
using System.IO;
2224
using System.Linq;
2325
using System.Windows.Threading;
2426
using System.Xml;
2527
using ICSharpCode.Core;
2628
using ICSharpCode.NRefactory;
2729
using ICSharpCode.SharpDevelop.Dom;
30+
using ICSharpCode.SharpDevelop.Gui;
2831
using ICSharpCode.SharpDevelop.Workbench;
2932

3033
namespace ICSharpCode.SharpDevelop.Project
@@ -337,7 +340,7 @@ public void Save()
337340
else
338341
{
339342
MessageService.ShowErrorFormatted
340-
("${res:SharpDevelop.Solution.CannotSave.UnauthorizedAccessException}", fileName, ex.Message);
343+
("${res:SharpDevelop.Solution.CannotSave.UnauthorizedAccessException}", fileName, ex.Message);
341344
}
342345
}
343346
}
@@ -502,6 +505,42 @@ public bool IsDirty {
502505
}
503506
#endregion
504507

508+
[EditorAttribute(typeof(FormatterSettingsEditor), typeof(UITypeEditor))]
509+
public object FormatterSettings
510+
{
511+
get {
512+
// We don't need any return value etc.
513+
return null;
514+
}
515+
}
516+
517+
/// <summary>
518+
/// Pseudo-editor showing a "..." for FormattingSettings option and opening the formatting editor for solution
519+
/// </summary>
520+
class FormatterSettingsEditor : UITypeEditor
521+
{
522+
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
523+
{
524+
return UITypeEditorEditStyle.Modal;
525+
}
526+
527+
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
528+
{
529+
var treeNode = AddInTree.GetTreeNode("/SharpDevelop/Dialogs/SolutionFormattingOptionsDialog", false);
530+
bool? result = ICSharpCode.SharpDevelop.Commands.OptionsCommand.ShowTreeOptions(
531+
"Solution Formatting Options",
532+
treeNode);
533+
if ((bool) result) {
534+
// Formatting options have been changed, make solution dirty
535+
var solution = context.Instance as Solution;
536+
if (solution != null) {
537+
solution.IsDirty = true;
538+
}
539+
}
540+
return null;
541+
}
542+
}
543+
505544
public override string ToString()
506545
{
507546
return "[Solution " + fileName + " with " + projects.Count + " projects]";
@@ -516,3 +555,4 @@ public Version MinVSVersion {
516555
}
517556
}
518557
}
558+

0 commit comments

Comments
 (0)