Browse Source

Set Icons in AnalysisProjectOptionsPanelXaml.xaml

pull/30/head
PeterForstmeier 14 years ago
parent
commit
0ed2a4815b
  1. 27
      src/AddIns/Analysis/CodeAnalysis/Src/AnalysisProjectOptionsPanelXaml.xaml
  2. 85
      src/AddIns/Analysis/CodeAnalysis/Src/AnalysisProjectOptionsPanelXaml.xaml.cs

27
src/AddIns/Analysis/CodeAnalysis/Src/AnalysisProjectOptionsPanelXaml.xaml

@ -6,7 +6,11 @@ @@ -6,7 +6,11 @@
xmlns:project="clr-namespace:ICSharpCode.SharpDevelop.Project;assembly=ICSharpCode.SharpDevelop"
xmlns:widgets="http://icsharpcode.net/sharpdevelop/widgets"
xmlns:tv="http://icsharpcode.net/sharpdevelop/treeview"
xmlns:local="clr-namespace:ICSharpCode.CodeAnalysis"
xmlns:core="http://icsharpcode.net/sharpdevelop/core">
<optionpanels:ProjectOptionPanel.Resources>
<local:ImageConverter x:Key="imageConverter"></local:ImageConverter>
</optionpanels:ProjectOptionPanel.Resources>
<ScrollViewer VerticalScrollBarVisibility="Auto">
<Grid >
<Grid.RowDefinitions>
@ -31,8 +35,9 @@ @@ -31,8 +35,9 @@
Style="{x:Static core:GlobalStyles.ButtonStyle}"
Content="{core:Localize ICSharpCode.CodeAnalysis.ProjectOptions.AddRemoveRuleAssembly}"></Button>
<tv:SharpTreeView x:Name="ruleTreeView" ShowRoot="False" ShowLines="False"
Grid.Row="2" Grid.ColumnSpan="3" >
<tv:SharpTreeView x:Name="ruleTreeView" ShowRoot="False" ShowLines="False" IsSynchronizedWithCurrentItem="True"
Grid.Row="2" Grid.ColumnSpan="3" SelectedItem="{Binding SelectedNode}">
<ListView.View>
<tv:SharpGridView >
<tv:SharpGridView.Columns>
@ -43,16 +48,28 @@ @@ -43,16 +48,28 @@
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Width="25">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Image Source="{Binding Path=RuleIcon, Converter={StaticResource imageConverter}}"></Image>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Action" Width="100">
<GridViewColumn.CellTemplate>
<DataTemplate>
<ComboBox Width="70" Background="Transparent"
ItemsSource="{Binding Path=BLA}"
DisplayMemberPath="DisplayValue"
></ComboBox>
ItemsSource="{Binding Path=RuleState}"
SelectedIndex="{Binding Index}"
DisplayMemberPath="DisplayValue">
</ComboBox>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</tv:SharpGridView.Columns>
</tv:SharpGridView>
</ListView.View>

85
src/AddIns/Analysis/CodeAnalysis/Src/AnalysisProjectOptionsPanelXaml.xaml.cs

@ -8,6 +8,10 @@ @@ -8,6 +8,10 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Drawing;
using System.Drawing.Imaging;
using System.Globalization;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows;
@ -16,6 +20,7 @@ using System.Windows.Data; @@ -16,6 +20,7 @@ using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using Gui.Dialogs.OptionPanels.ProjectOptions;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop;
@ -31,17 +36,21 @@ namespace ICSharpCode.CodeAnalysis @@ -31,17 +36,21 @@ namespace ICSharpCode.CodeAnalysis
/// <summary>
/// Interaction logic for AnalysisProjectOptionsPanelXaml.xaml
/// </summary>
public partial class AnalysisProjectOptionsPanelXaml : ProjectOptionPanel
{
private bool initSuccess;
private bool userCheck;
private Dictionary<string, RuleTreeNode> rules = new Dictionary<string, RuleTreeNode>();
private List<KeyItemPair> bla = new List<KeyItemPair>();
public AnalysisProjectOptionsPanelXaml()
{
InitializeComponent();
DataContext = this;
bla.Add(new KeyItemPair("Warning","Warning"));
bla.Add(new KeyItemPair("Error","Error"));
bla.Add(new KeyItemPair("None","None"));
@ -185,7 +194,6 @@ namespace ICSharpCode.CodeAnalysis @@ -185,7 +194,6 @@ namespace ICSharpCode.CodeAnalysis
#endregion
#region RuleList
void ReloadRuleList()
@ -245,16 +253,51 @@ namespace ICSharpCode.CodeAnalysis @@ -245,16 +253,51 @@ namespace ICSharpCode.CodeAnalysis
#endregion
#region TreeView
#region TreeNodes
class BaseTree:SharpTreeNode
{
public BaseTree(IEnumerable<KeyItemPair> bla)
private Icon ruleIcon;
private int index;
public BaseTree(IEnumerable<KeyItemPair> ruleState)
{
this.BLA = bla;
this.RuleState = ruleState;
RuleIcon = SystemIcons.Warning;
}
public IEnumerable<KeyItemPair> BLA {get;set;}
public IEnumerable<KeyItemPair> RuleState {get;set;}
public Icon RuleIcon {
get { return ruleIcon; }
set { ruleIcon = value;
base.RaisePropertyChanged("RuleIcon");
}
}
public int Index {
get { return index; }
set { index = value;
switch (index) {
case 0:
RuleIcon = SystemIcons.Warning;
break;
case 1:
RuleIcon = SystemIcons.Error;
break;
case 2:
RuleIcon = null;
break;
default:
break;
}
base.RaisePropertyChanged("Index");
}
}
}
@ -268,6 +311,7 @@ namespace ICSharpCode.CodeAnalysis @@ -268,6 +311,7 @@ namespace ICSharpCode.CodeAnalysis
foreach (FxCopRule rule in category.Rules) {
this.Children.Add(new RuleTreeNode(rule,bla));
}
}
@ -306,7 +350,7 @@ namespace ICSharpCode.CodeAnalysis @@ -306,7 +350,7 @@ namespace ICSharpCode.CodeAnalysis
internal FxCopRule rule;
internal bool isError;
public RuleTreeNode(FxCopRule rule,IEnumerable<KeyItemPair> bla):base(bla)
public RuleTreeNode(FxCopRule rule,IEnumerable<KeyItemPair> ruleState):base(ruleState)
{
this.rule = rule;
}
@ -341,4 +385,33 @@ namespace ICSharpCode.CodeAnalysis @@ -341,4 +385,33 @@ namespace ICSharpCode.CodeAnalysis
}
#endregion
}
[ValueConversion(typeof(System.Drawing.Icon), typeof(System.Windows.Media.ImageSource))]
public class ImageConverter : IValueConverter
{
public object Convert(object value, Type targetType,
object parameter, CultureInfo culture)
{
// empty images are empty...
if (value == null) { return null; }
var image = (System.Drawing.Icon)value;
// Winforms Image we want to get the WPF Image from...
var bitmap = new System.Windows.Media.Imaging.BitmapImage();
bitmap.BeginInit();
MemoryStream memoryStream = new MemoryStream();
// Save to a memory stream...
image.Save(memoryStream);
// Rewind the stream...
memoryStream.Seek(0, System.IO.SeekOrigin.Begin);
bitmap.StreamSource = memoryStream;
bitmap.EndInit();
return bitmap;
}
public object ConvertBack(object value, Type targetType,
object parameter, CultureInfo culture)
{
return null;
}
}
}
Loading…
Cancel
Save