Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add IssueOptions panel.

  • Loading branch information...
commit 5e1642ebd222ba53d5f7bfe2f2b24b3600ce093d 1 parent bd32925
@dgrunwald dgrunwald authored
Showing with 362 additions and 98 deletions.
  1. +4 −1 src/AddIns/BackendBindings/CSharpBinding/Project/CSharpBinding.addin
  2. +18 −0 src/AddIns/BackendBindings/CSharpBinding/Project/CSharpBinding.csproj
  3. +1 −2  src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/CSharpCodeActionProviderDoozer.cs
  4. +98 −6 src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/IssueManager.cs
  5. +42 −0 src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/IssueOptions.xaml
  6. +64 −0 src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/IssueOptions.xaml.cs
  7. +47 −0 src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/IssueOptionsViewModel.cs
  8. +12 −2 src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ContextActions/ContextActionOptions.xaml
  9. +5 −1 src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ContextActions/ContextActionOptions.xaml.cs
  10. +10 −9 src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/AddServiceReferenceViewModel.cs
  11. +9 −9 src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/AdvancedServiceViewModel.cs
  12. +1 −3 src/Main/Base/Project/Src/Gui/Dialogs/TabbedOptions.cs
  13. +3 −7 src/Main/Base/Project/Src/Gui/Dialogs/TreeViewOptionsDialog.xaml.cs
  14. +2 −1  src/Main/Base/Project/Src/Internal/Doozers/DefaultOptionPanelDescriptor.cs
  15. +2 −4 src/Main/Core/Project/Src/Services/PropertyService/Properties.cs
  16. +33 −4 src/Main/ICSharpCode.Core.Presentation/RestrictDesiredSize.cs
  17. +11 −49 src/Main/ICSharpCode.SharpDevelop.Widgets/Project/ViewModelBase.cs
View
5 src/AddIns/BackendBindings/CSharpBinding/Project/CSharpBinding.addin
@@ -118,10 +118,13 @@
class = "CSharpBinding.CSharpProjectBinding" />
</Path>
- <Path path = "/SharpDevelop/Dialogs/OptionsDialog/TextEditorOptions">
+ <Path path = "/SharpDevelop/Dialogs/OptionsDialog/CodingOptions">
<OptionPanel id = "C#"
insertafter = "Highlighting"
label = "C#">
+ <OptionPanel id="Issues"
+ label="Code inspection"
+ class="CSharpBinding.Refactoring.IssueOptions"/>
<ContextActionOptionPanel id="ContextActions" path="/SharpDevelop/ViewContent/TextEditor/C#/ContextActions"/>
</OptionPanel>
</Path>
View
18 src/AddIns/BackendBindings/CSharpBinding/Project/CSharpBinding.csproj
@@ -66,8 +66,13 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Configuration\AssemblyInfo.cs" />
+ <Compile Include="Src\Refactoring\IssueOptions.xaml.cs">
+ <DependentUpon>IssueOptions.xaml</DependentUpon>
+ <SubType>Code</SubType>
+ </Compile>
<Compile Include="Src\Refactoring\CSharpContextActionWrapper.cs" />
<Compile Include="Src\Refactoring\IssueManager.cs" />
+ <Compile Include="Src\Refactoring\IssueOptionsViewModel.cs" />
<Compile Include="Src\Refactoring\SDScript.cs" />
<EmbeddedResource Include="Resources\BuildOptions.xfrm" />
<EmbeddedResource Include="Resources\MyNamespaceSupportForCSharp.cs" />
@@ -129,15 +134,28 @@
<Name>ICSharpCode.Core</Name>
<Private>False</Private>
</ProjectReference>
+ <ProjectReference Include="..\..\..\..\Main\ICSharpCode.Core.Presentation\ICSharpCode.Core.Presentation.csproj">
+ <Project>{7E4A7172-7FF5-48D0-B719-7CD959DD1AC9}</Project>
+ <Name>ICSharpCode.Core.Presentation</Name>
+ <Private>False</Private>
+ </ProjectReference>
<ProjectReference Include="..\..\..\..\Main\ICSharpCode.Core.WinForms\ICSharpCode.Core.WinForms.csproj">
<Project>{857CA1A3-FC88-4BE0-AB6A-D1EE772AB288}</Project>
<Name>ICSharpCode.Core.WinForms</Name>
<Private>False</Private>
</ProjectReference>
+ <ProjectReference Include="..\..\..\..\Main\ICSharpCode.SharpDevelop.Widgets\Project\ICSharpCode.SharpDevelop.Widgets.csproj">
+ <Project>{8035765F-D51F-4A0C-A746-2FD100E19419}</Project>
+ <Name>ICSharpCode.SharpDevelop.Widgets</Name>
+ <Private>False</Private>
+ </ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="Src\Completion" />
<Folder Include="Src\Refactoring" />
</ItemGroup>
+ <ItemGroup>
+ <Page Include="Src\Refactoring\IssueOptions.xaml" />
+ </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
</Project>
View
3  ...s/BackendBindings/CSharpBinding/Project/Src/Refactoring/CSharpCodeActionProviderDoozer.cs
@@ -76,8 +76,7 @@ bool CreateCodeActionProvider()
}
public string Category {
- get { return string.IsNullOrEmpty(attribute.Category) ? attribute.Title[0].ToString() : attribute.Category; }
- // get { return attribute.Category ?? string.Empty; }
+ get { return attribute.Category ?? string.Empty; }
}
public bool AllowHiding {
View
104 src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/IssueManager.cs
@@ -7,10 +7,12 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
+using System.Windows;
using System.Windows.Media;
using CSharpBinding.Parser;
using ICSharpCode.Core;
using ICSharpCode.NRefactory;
+using ICSharpCode.NRefactory.CSharp;
using ICSharpCode.NRefactory.CSharp.Refactoring;
using ICSharpCode.NRefactory.Editor;
using ICSharpCode.SharpDevelop.Editor;
@@ -25,8 +27,65 @@ namespace CSharpBinding.Refactoring
/// </summary>
public class IssueManager : IDisposable, IContextActionProvider
{
- static readonly Lazy<IList<ICodeIssueProvider>> issueProviders = new Lazy<IList<ICodeIssueProvider>>(
- () => AddInTree.BuildItems<ICodeIssueProvider>("/SharpDevelop/ViewContent/TextEditor/C#/IssueProviders", null, false));
+ static readonly Lazy<IReadOnlyList<IssueProvider>> issueProviders = new Lazy<IReadOnlyList<IssueProvider>>(
+ () => AddInTree.BuildItems<ICodeIssueProvider>("/SharpDevelop/ViewContent/TextEditor/C#/IssueProviders", null, false)
+ .Select(p => new IssueProvider(p)).ToList());
+
+ internal static IReadOnlyList<IssueProvider> IssueProviders {
+ get { return issueProviders.Value; }
+ }
+
+ internal class IssueProvider
+ {
+ readonly ICodeIssueProvider provider;
+ public readonly Type ProviderType;
+ public readonly IssueDescriptionAttribute Attribute;
+
+ public IssueProvider(ICodeIssueProvider provider)
+ {
+ if (provider == null)
+ throw new ArgumentNullException("provider");
+ this.provider = provider;
+ this.ProviderType = provider.GetType();
+ var attributes = ProviderType.GetCustomAttributes(typeof(IssueDescriptionAttribute), true);
+ if (attributes.Length == 1)
+ this.Attribute = (IssueDescriptionAttribute)attributes[0];
+ }
+
+ public Severity DefaultSeverity {
+ get { return Attribute != null ? Attribute.Severity : Severity.Hint; }
+ }
+
+ public IssueMarker DefaultMarker {
+ get { return Attribute != null ? Attribute.IssueMarker : IssueMarker.Underline; }
+ }
+
+ public IEnumerable<CodeIssue> GetIssues(BaseRefactoringContext context)
+ {
+ return provider.GetIssues(context);
+ }
+ }
+
+ public static IReadOnlyDictionary<Type, Severity> GetIssueSeveritySettings()
+ {
+ // TODO: cache the result
+ var dict = new Dictionary<Type, Severity>();
+ var prop = PropertyService.Get("CSharpIssueSeveritySettings", new Properties());
+ foreach (var provider in issueProviders.Value) {
+ dict[provider.ProviderType] = prop.Get(provider.ProviderType.FullName, provider.DefaultSeverity);
+ }
+ return dict;
+ }
+
+ public static void SetIssueSeveritySettings(IReadOnlyDictionary<Type, Severity> dict)
+ {
+ var prop = new Properties();
+ foreach (var pair in dict) {
+ prop.Set(pair.Key.FullName, pair.Value);
+ }
+ PropertyService.Set("CSharpIssueSeveritySettings", prop);
+ }
+
readonly ITextEditor editor;
readonly ITextMarkerService markerService;
@@ -50,14 +109,15 @@ public void Dispose()
sealed class InspectionTag
{
readonly IssueManager manager;
- public readonly ICodeIssueProvider Provider;
+ public readonly IssueProvider Provider;
public readonly ITextSourceVersion InspectedVersion;
public readonly string Description;
public readonly int StartOffset;
public readonly int EndOffset;
public readonly IReadOnlyList<IContextAction> Actions;
+ public readonly Severity Severity;
- public InspectionTag(IssueManager manager, ICodeIssueProvider provider, ITextSourceVersion inspectedVersion, string description, int startOffset, int endOffset, IEnumerable<CodeAction> actions)
+ public InspectionTag(IssueManager manager, IssueProvider provider, ITextSourceVersion inspectedVersion, string description, int startOffset, int endOffset, Severity severity, IEnumerable<CodeAction> actions)
{
this.manager = manager;
this.Provider = provider;
@@ -65,6 +125,7 @@ public InspectionTag(IssueManager manager, ICodeIssueProvider provider, ITextSou
this.Description = description;
this.StartOffset = startOffset;
this.EndOffset = endOffset;
+ this.Severity = severity;
this.Actions = actions.Select(Wrap).ToList();
}
@@ -105,11 +166,34 @@ public void CreateMarker(IDocument document, ITextMarkerService markerService)
return;
marker = markerService.Create(startOffset, endOffset - startOffset);
marker.ToolTip = this.Description;
- marker.MarkerType = TextMarkerType.SquigglyUnderline;
- marker.MarkerColor = Colors.Blue;
+ switch (Provider.DefaultMarker) {
+ case IssueMarker.Underline:
+ Color underlineColor = GetColor(this.Severity);
+ underlineColor.A = 186;
+ marker.MarkerType = TextMarkerType.SquigglyUnderline;
+ marker.MarkerColor = underlineColor;
+ break;
+ case IssueMarker.GrayOut:
+ marker.ForegroundColor = SystemColors.GrayTextColor;
+ break;
+ }
marker.Tag = this;
}
+ static Color GetColor(Severity severity)
+ {
+ switch (severity) {
+ case Severity.Error:
+ return Colors.Red;
+ case Severity.Warning:
+ return Colors.Orange;
+ case Severity.Suggestion:
+ return Colors.Green;
+ default:
+ return Colors.Blue;
+ }
+ }
+
public void RemoveMarker()
{
if (marker != null) {
@@ -163,7 +247,14 @@ void ParserService_ParserUpdateStepFinished(object sender, ParserUpdateStepEvent
var compilation = ParserService.GetCompilationForFile(parseInfo.FileName);
var resolver = parseInfo.GetResolver(compilation);
var context = new SDRefactoringContext(textSource, resolver, new TextLocation(0, 0), 0, 0, cancellationToken);
+ var settings = GetIssueSeveritySettings();
foreach (var issueProvider in issueProviders.Value) {
+ Severity severity;
+ if (!settings.TryGetValue(issueProvider.ProviderType, out severity))
+ severity = Severity.Hint;
+ if (severity == Severity.None)
+ continue;
+
foreach (var issue in issueProvider.GetIssues(context)) {
results.Add(new InspectionTag(
this,
@@ -172,6 +263,7 @@ void ParserService_ParserUpdateStepFinished(object sender, ParserUpdateStepEvent
issue.Desription,
context.GetOffset(issue.Start),
context.GetOffset(issue.End),
+ severity,
issue.Action != null ? new [] { issue.Action } : new CodeAction[0]));
}
}
View
42 src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/IssueOptions.xaml
@@ -0,0 +1,42 @@
+<gui:OptionPanel x:Class="CSharpBinding.Refactoring.IssueOptions"
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:sd="http://icsharpcode.net/sharpdevelop/core"
+ xmlns:nr="clr-namespace:ICSharpCode.NRefactory.CSharp;assembly=ICSharpCode.NRefactory.CSharp"
+ xmlns:gui="clr-namespace:ICSharpCode.SharpDevelop.Gui;assembly=ICSharpCode.SharpDevelop">
+ <DockPanel>
+ <!-- TODO: Translate -->
+ <CheckBox Name="featureEnabledCheckBox" DockPanel.Dock="Top"
+ IsEnabled="False"
+ IsChecked="True" Content="Enable code inspection" />
+ <sd:RestrictDesiredSize Margin="0, 4, 0, 0">
+ <ListBox Name="listBox"
+ HorizontalContentAlignment="Stretch"
+ IsEnabled="{Binding IsChecked, ElementName=featureEnabledCheckBox}">
+ <ListBox.ItemTemplate>
+ <DataTemplate>
+ <DockPanel>
+ <ComboBox DockPanel.Dock="Right"
+ MinWidth="85"
+ VerticalAlignment="Center"
+ gui:EnumBinding.EnumType="{x:Type nr:Severity}"
+ SelectedValue="{Binding Severity}"/>
+ <sd:RestrictDesiredSize RestrictHeight="False" MinWidth="150">
+ <TextBlock Text="{Binding DisplayName}" ToolTip="{Binding ToolTip}" TextWrapping="WrapWithOverflow" />
+ </sd:RestrictDesiredSize>
+ </DockPanel>
+ </DataTemplate>
+ </ListBox.ItemTemplate>
+ <ListBox.GroupStyle>
+ <GroupStyle>
+ <GroupStyle.HeaderTemplate>
+ <DataTemplate DataType="Group">
+ <TextBlock FontWeight="Bold" Text="{Binding Name}" />
+ </DataTemplate>
+ </GroupStyle.HeaderTemplate>
+ </GroupStyle>
+ </ListBox.GroupStyle>
+ </ListBox>
+ </sd:RestrictDesiredSize>
+ </DockPanel>
+</gui:OptionPanel>
View
64 src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/IssueOptions.xaml.cs
@@ -0,0 +1,64 @@
+// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
+// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
+
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using ICSharpCode.NRefactory.CSharp;
+using ICSharpCode.SharpDevelop.Gui;
+using ICSharpCode.SharpDevelop.Refactoring;
+
+namespace CSharpBinding.Refactoring
+{
+ /// <summary>
+ /// Interaction logic for IssueOptions.xaml
+ /// </summary>
+ public partial class IssueOptions : OptionPanel
+ {
+ ObservableCollection<IssueOptionsViewModel> viewModels;
+
+ public IssueOptions()
+ {
+ InitializeComponent();
+ viewModels = new ObservableCollection<IssueOptionsViewModel>(
+ from p in IssueManager.IssueProviders
+ where p.Attribute != null
+ select new IssueOptionsViewModel(p.ProviderType, p.Attribute)
+ );
+ ICollectionView view = CollectionViewSource.GetDefaultView(viewModels);
+ if (viewModels.Any(p => !string.IsNullOrEmpty(p.Category)))
+ view.GroupDescriptions.Add(new PropertyGroupDescription("Category"));
+ listBox.ItemsSource = view;
+ }
+
+ public override void LoadOptions()
+ {
+ base.LoadOptions();
+ var settings = IssueManager.GetIssueSeveritySettings();
+ foreach (var m in viewModels) {
+ Severity severity;
+ if (settings.TryGetValue(m.ProviderType, out severity))
+ m.Severity = severity;
+ }
+ }
+
+ public override bool SaveOptions()
+ {
+ Dictionary<Type, Severity> dict = new Dictionary<Type, Severity>();
+ foreach (var m in viewModels) {
+ dict[m.ProviderType] = m.Severity;
+ }
+ IssueManager.SetIssueSeveritySettings(dict);
+ return base.SaveOptions();
+ }
+ }
+}
View
47 src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/IssueOptionsViewModel.cs
@@ -0,0 +1,47 @@
+// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
+// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
+
+using System;
+using System.ComponentModel;
+using ICSharpCode.NRefactory.CSharp;
+using ICSharpCode.SharpDevelop.Widgets;
+
+namespace CSharpBinding.Refactoring
+{
+ public class IssueOptionsViewModel : ViewModelBase
+ {
+ readonly Type providerType;
+ readonly IssueDescriptionAttribute attribute;
+
+ public IssueOptionsViewModel(Type providerType, IssueDescriptionAttribute attribute)
+ {
+ this.providerType = providerType;
+ this.attribute = attribute;
+ this.Severity = attribute.Severity;
+ }
+
+ public Type ProviderType {
+ get { return providerType; }
+ }
+
+ // TODO: Translate
+ public string DisplayName {
+ get { return attribute.Title; }
+ }
+
+ public string ToolTip {
+ get { return attribute.Description; }
+ }
+
+ public string Category {
+ get { return attribute.Category; }
+ }
+
+ Severity severity;
+
+ public Severity Severity {
+ get { return severity; }
+ set { SetAndNotifyPropertyChanged(ref severity, value); }
+ }
+ }
+}
View
14 src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ContextActions/ContextActionOptions.xaml
@@ -6,18 +6,28 @@
<DockPanel>
<!-- TODO: Translate -->
<CheckBox Name="featureEnabledCheckBox" DockPanel.Dock="Top"
+ IsEnabled="False"
IsChecked="True" Content="Enable context actions" />
<sd:RestrictDesiredSize Margin="0, 4, 0, 0">
- <ListBox x:Name="listBox" SelectionMode="Multiple"
+ <ListBox Name="listBox" SelectionMode="Multiple"
+ IsEnabled="{Binding IsChecked, ElementName=featureEnabledCheckBox}"
ItemContainerStyle="{x:Static sd:GlobalStyles.ListBoxItemFocusHighlightStyle}">
<ListBox.ItemTemplate>
<DataTemplate>
<!-- The checkbox is toggling the actual IsSelected property on the container (ListBoxItem), so it'll update ListBox.SelectedItems -->
<CheckBox Content="{Binding DisplayName}"
- IsEnabled="{Binding IsChecked, ElementName=featureEnabledCheckBox}"
IsChecked="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type ListBoxItem}},Path=IsSelected}" />
</DataTemplate>
</ListBox.ItemTemplate>
+ <ListBox.GroupStyle>
+ <GroupStyle>
+ <GroupStyle.HeaderTemplate>
+ <DataTemplate DataType="Group">
+ <TextBlock FontWeight="Bold" Text="{Binding Name}" />
+ </DataTemplate>
+ </GroupStyle.HeaderTemplate>
+ </GroupStyle>
+ </ListBox.GroupStyle>
</ListBox>
</sd:RestrictDesiredSize>
</DockPanel>
View
6 src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ContextActions/ContextActionOptions.xaml.cs
@@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
+using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows;
@@ -27,7 +28,10 @@ public ContextActionOptions(IEnumerable<IContextActionProvider> providers)
{
InitializeComponent();
this.providers = providers.ToArray();
- listBox.ItemsSource = this.providers;
+ ICollectionView view = CollectionViewSource.GetDefaultView(this.providers);
+ if (this.providers.Any(p => !string.IsNullOrEmpty(p.Category)))
+ view.GroupDescriptions.Add(new PropertyGroupDescription("Category"));
+ listBox.ItemsSource = view;
}
public override void LoadOptions()
View
19 .../Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/AddServiceReferenceViewModel.cs
@@ -256,7 +256,7 @@ public string Title
get { return title; }
set {
title = value;
- base.RaisePropertyChanged(() => Title);
+ OnPropertyChanged();
}
}
@@ -268,7 +268,8 @@ public string Title
get { return discoverButtonContent; }
set {
discoverButtonContent = value;
- base.RaisePropertyChanged(() => DiscoverButtonContent);
+ OnPropertyChanged();
+ OnPropertyChanged();
}
}
@@ -276,7 +277,7 @@ public string Title
get { return mruServices; }
set {
mruServices = value;
- base.RaisePropertyChanged(() => MruServices);
+ OnPropertyChanged();
}
}
@@ -284,7 +285,7 @@ public string Title
get { return selectedService; }
set {
selectedService = value;
- base.RaisePropertyChanged(() => SelectedService);
+ OnPropertyChanged();
}
}
@@ -292,7 +293,7 @@ public string Title
get { return items; }
set {
items = value;
- base.RaisePropertyChanged(() => ServiceItems);
+ OnPropertyChanged();
}
}
@@ -301,7 +302,7 @@ public string Title
set {
myItem = value;
UpdateListView();
- base.RaisePropertyChanged(() => ServiceItem);
+ OnPropertyChanged();
}
}
@@ -309,7 +310,7 @@ public string Title
get { return serviceDescriptionMessage; }
set {
serviceDescriptionMessage = value;
- base.RaisePropertyChanged(() => ServiceDescriptionMessage);
+ OnPropertyChanged();
}
}
@@ -317,7 +318,7 @@ public string Title
get { return defaultNameSpace; }
set {
defaultNameSpace = value;
- base.RaisePropertyChanged(() => DefaultNameSpace);
+ OnPropertyChanged();
}
}
@@ -325,7 +326,7 @@ public string Title
get { return twoValues; }
set {
twoValues = value;
- base.RaisePropertyChanged(() => TwoValues);
+ OnPropertyChanged();
}
}
View
18 ...Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/AdvancedServiceViewModel.cs
@@ -85,7 +85,7 @@ public AdvancedServiceViewModel()
get { return selectedModifier; }
set {
selectedModifier = value;
- base.RaisePropertyChanged(() => SelectedModifier);
+ OnPropertyChanged();
}
}
@@ -95,7 +95,7 @@ public AdvancedServiceViewModel()
get { return generateAsyncOperations; }
set {
generateAsyncOperations = value;
- base.RaisePropertyChanged(() => GenerateAsyncOperations);
+ OnPropertyChanged();
}
}
@@ -105,7 +105,7 @@ public AdvancedServiceViewModel()
get { return generateMessageContract; }
set {
generateMessageContract = value;
- base.RaisePropertyChanged(() => GenerateMessageContract);
+ OnPropertyChanged();
}
}
@@ -115,7 +115,7 @@ public AdvancedServiceViewModel()
get { return collectionType; }
set {
collectionType = value;
- base.RaisePropertyChanged(() => CollectionType);
+ OnPropertyChanged();
}
}
@@ -125,7 +125,7 @@ public AdvancedServiceViewModel()
get { return dictionaryCollectionType; }
set {
dictionaryCollectionType = value;
- base.RaisePropertyChanged(() => DictionaryCollectionType);
+ OnPropertyChanged();
}
}
@@ -136,7 +136,7 @@ public AdvancedServiceViewModel()
set {
useReferencedAssemblies = value;
ReuseTypes = useReferencedAssemblies;
- base.RaisePropertyChanged(() => UseReferencedAssemblies);
+ OnPropertyChanged();
}
}
@@ -146,7 +146,7 @@ public AdvancedServiceViewModel()
get { return reuseTypes; }
set {
reuseTypes = value;
- base.RaisePropertyChanged(() => ReuseTypes);
+ OnPropertyChanged();
}
}
@@ -157,7 +157,7 @@ public AdvancedServiceViewModel()
set {
reuseReferencedTypes = value;
ListViewEnable = value;
- base.RaisePropertyChanged(() => ReuseReferencedTypes);
+ OnPropertyChanged();
}
}
@@ -167,7 +167,7 @@ public AdvancedServiceViewModel()
get { return listViewEnable; }
set {
listViewEnable = value;
- base.RaisePropertyChanged(() => ListViewEnable);
+ OnPropertyChanged();
}
}
View
4 src/Main/Base/Project/Src/Gui/Dialogs/TabbedOptions.cs
@@ -28,9 +28,7 @@ public void AddOptionPanels(IEnumerable<IOptionPanelDescriptor> dialogPanelDescr
if (descriptor.HasOptionPanel) {
this.Items.Add(new OptionTabPage(this, descriptor));
}
- if (descriptor.ChildOptionPanelDescriptors != null) {
- AddOptionPanels(descriptor.ChildOptionPanelDescriptors);
- }
+ AddOptionPanels(descriptor.ChildOptionPanelDescriptors);
}
}
OnIsDirtyChanged(null, null);
View
10 src/Main/Base/Project/Src/Gui/Dialogs/TreeViewOptionsDialog.xaml.cs
@@ -136,7 +136,7 @@ public OptionPanelNode(IOptionPanelDescriptor optionPanel, OptionPanelNode paren
get {
if (IsActive)
return PresentationResourceService.GetBitmapSource("Icons.16x16.SelectionArrow");
- if (OptionPanelDescriptor.ChildOptionPanelDescriptors != null) {
+ if (OptionPanelDescriptor.ChildOptionPanelDescriptors.Any()) {
if (IsExpanded)
return PresentationResourceService.GetBitmapSource("Icons.16x16.OpenFolderBitmap");
else
@@ -152,12 +152,8 @@ public OptionPanelNode(IOptionPanelDescriptor optionPanel, OptionPanelNode paren
public List<OptionPanelNode> Children {
get {
if (children == null) {
- if (OptionPanelDescriptor.ChildOptionPanelDescriptors != null) {
- children = OptionPanelDescriptor.ChildOptionPanelDescriptors
- .Select(op => new OptionPanelNode(op, this)).ToList();
- } else {
- children = new List<OptionPanelNode>();
- }
+ children = OptionPanelDescriptor.ChildOptionPanelDescriptors
+ .Select(op => new OptionPanelNode(op, this)).ToList();
}
return children;
}
View
3  src/Main/Base/Project/Src/Internal/Doozers/DefaultOptionPanelDescriptor.cs
@@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
+using System.Linq;
using ICSharpCode.Core;
namespace ICSharpCode.SharpDevelop
@@ -23,7 +24,7 @@ public class DefaultOptionPanelDescriptor : IOptionPanelDescriptor
public IEnumerable<IOptionPanelDescriptor> ChildOptionPanelDescriptors {
get {
- return optionPanelDescriptors;
+ return optionPanelDescriptors ?? Enumerable.Empty<IOptionPanelDescriptor>();
}
}
View
6 src/Main/Core/Project/Src/Services/PropertyService/Properties.cs
@@ -7,6 +7,7 @@
using System.ComponentModel;
using System.Globalization;
using System.IO;
+using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
@@ -72,10 +73,7 @@ public string[] Elements
{
get {
lock (properties) {
- List<string> ret = new List<string>();
- foreach (KeyValuePair<string, object> property in properties)
- ret.Add(property.Key);
- return ret.ToArray();
+ return properties.Keys.ToArray();
}
}
}
View
37 src/Main/ICSharpCode.Core.Presentation/RestrictDesiredSize.cs
@@ -14,19 +14,48 @@ namespace ICSharpCode.Core.Presentation
/// </summary>
public class RestrictDesiredSize : Decorator
{
- Size lastArrangeSize = new Size(double.NaN, double.NaN);
+ public static readonly DependencyProperty RestrictWidthProperty =
+ DependencyProperty.Register("RestrictWidth", typeof(bool), typeof(RestrictDesiredSize),
+ new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsArrange));
+ public bool RestrictWidth {
+ get { return (bool)GetValue(RestrictWidthProperty); }
+ set { SetValue(RestrictWidthProperty, value); }
+ }
+
+ public static readonly DependencyProperty RestrictHeightProperty =
+ DependencyProperty.Register("RestrictHeight", typeof(bool), typeof(RestrictDesiredSize),
+ new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsArrange));
+
+ public bool RestrictHeight {
+ get { return (bool)GetValue(RestrictHeightProperty); }
+ set { SetValue(RestrictHeightProperty, value); }
+ }
+
+ Size lastArrangeSize = new Size(double.PositiveInfinity, double.PositiveInfinity);
+ Size lastMeasureSize = new Size(double.NaN, double.NaN);
+
protected override Size MeasureOverride(Size constraint)
{
- return new Size(0, 0);
+ if (RestrictWidth && RestrictHeight)
+ return new Size(0, 0);
+
+ if (RestrictWidth && constraint.Width > lastArrangeSize.Width)
+ constraint.Width = lastArrangeSize.Width;
+ if (RestrictHeight && constraint.Height > lastArrangeSize.Height)
+ constraint.Height = lastArrangeSize.Height;
+ lastMeasureSize = constraint;
+ Size baseSize = base.MeasureOverride(constraint);
+ return new Size(RestrictWidth ? 0 : baseSize.Width, RestrictHeight ? 0 : baseSize.Height);
}
protected override Size ArrangeOverride(Size arrangeSize)
{
- if (lastArrangeSize != arrangeSize) {
- lastArrangeSize = arrangeSize;
+ if (lastMeasureSize != arrangeSize) {
+ lastMeasureSize = arrangeSize;
base.MeasureOverride(arrangeSize);
}
+ lastArrangeSize = arrangeSize;
return base.ArrangeOverride(arrangeSize);
}
}
View
60 src/Main/ICSharpCode.SharpDevelop.Widgets/Project/ViewModelBase.cs
@@ -2,73 +2,35 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
+using System.Collections.Generic;
using System.ComponentModel;
using System.Linq.Expressions;
using System.Reflection;
+using System.Runtime.CompilerServices;
namespace ICSharpCode.SharpDevelop.Widgets
{
/// <summary>
- /// Description of ViewModelBase.
+ /// Base class for view models; implements INotifyPropertyChanged.
/// </summary>
- public class ViewModelBase:INotifyPropertyChanged
+ public class ViewModelBase : INotifyPropertyChanged
{
- public ViewModelBase()
- {
- }
-
-
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
- protected virtual void OnPropertyChanged(System.ComponentModel.PropertyChangedEventArgs e)
+ protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
var handler = this.PropertyChanged;
- if (handler != null)
- {
- handler(this, e);
+ if (handler != null) {
+ handler(this, new PropertyChangedEventArgs(propertyName));
}
}
-
- protected void RaisePropertyChanged<T>(Expression<Func<T>> propertyExpresssion)
- {
- var propertyName = ExtractPropertyName(propertyExpresssion);
- this.RaisePropertyChanged(propertyName);
- }
-
-
- protected void RaisePropertyChanged(String propertyName)
- {
- OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
- }
-
-
- private static String ExtractPropertyName<T>(Expression<Func<T>> propertyExpresssion)
+ protected void SetAndNotifyPropertyChanged<T>(ref T field, T newValue, [CallerMemberName] string propertyName = null)
{
- if (propertyExpresssion == null)
- {
- throw new ArgumentNullException("propertyExpresssion");
- }
-
- var memberExpression = propertyExpresssion.Body as MemberExpression;
- if (memberExpression == null)
- {
- throw new ArgumentException("The expression is not a member access expression.", "propertyExpresssion");
+ if (!EqualityComparer<T>.Default.Equals(field, newValue)) {
+ field = newValue;
+ OnPropertyChanged(propertyName);
}
-
- var property = memberExpression.Member as PropertyInfo;
- if (property == null)
- {
- throw new ArgumentException("The member access expression does not access a property.", "propertyExpresssion");
- }
-
- var getMethod = property.GetGetMethod(true);
- if (getMethod.IsStatic)
- {
- throw new ArgumentException("The referenced property is a static property.", "propertyExpresssion");
- }
-
- return memberExpression.Member.Name;
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.