Permalink
Browse files

Add IssueOptions panel.

  • Loading branch information...
1 parent bd32925 commit 5e1642ebd222ba53d5f7bfe2f2b24b3600ce093d @dgrunwald dgrunwald committed Mar 23, 2012
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 ...ain/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
@@ -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>
@@ -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>
@@ -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 {
@@ -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,21 +109,23 @@ 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;
this.InspectedVersion = inspectedVersion;
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]));
}
}
@@ -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>
@@ -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();
+ }
+ }
+}
@@ -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); }
+ }
+ }
+}
Oops, something went wrong.

0 comments on commit 5e1642e

Please sign in to comment.