Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

try List<ItemWithCommand> for filtering nodes

  • Loading branch information...
commit b964a68112843cc19751c9e6e23121d4da35a124 1 parent dd45b72
@PeterForstmeier PeterForstmeier authored
View
1  src/AddIns/Analysis/CodeQuality/CodeQualityAnalysis.csproj
@@ -151,6 +151,7 @@
<Compile Include="Src\Utility\Localizeable\EnumToFriendlyNameConverter.cs" />
<Compile Include="Src\Utility\Localizeable\LocalizableDescriptionAttribute.cs" />
<Compile Include="Src\Utility\Matrix.cs" />
+ <Compile Include="Src\Utility\testclass.cs" />
<Compile Include="Src\Utility\VisibleMatrix.cs" />
<Page Include="Resources\GridSplitterTemplate.xaml" />
<Page Include="Resources\GraphTemplate.xaml">
View
14 src/AddIns/Analysis/CodeQuality/Src/MainWindow.xaml
@@ -307,7 +307,7 @@
</util:ComboBoxWithCommand>
<TextBlock Margin="4,0,0,0" Text="Metric: " />
-
+ <!--
<util:ComboBoxWithCommand Width="200" Margin="4,0,0,0"
ItemsSource="{Binding Source={StaticResource Metrics}}"
SelectedItem="{Binding SelectedMetrics}"
@@ -325,7 +325,17 @@
</DataTemplate>
</util:ComboBoxWithCommand.ItemTemplate>
</util:ComboBoxWithCommand>
-
+ -->
+ <util:ComboBoxWithCommand Width="200" Margin="4,0,0,0"
+ ItemsSource="{Binding ItemsWithCommand}"
+ SelectedItem="{Binding SelectedItemWithCommand}"
+ Command="{Binding ExecuteSelectedItemWithCommand}">
+ <util:ComboBoxWithCommand.ItemTemplate>
+ <DataTemplate>
+ <Label Content="{Binding Description}"></Label>
+ </DataTemplate>
+ </util:ComboBoxWithCommand.ItemTemplate>
+ </util:ComboBoxWithCommand>
</ToolBar>
</ToolBarTray>
View
135 src/AddIns/Analysis/CodeQuality/Src/MainWindowModel.cs
@@ -16,6 +16,7 @@
using System.Windows.Input;
using ICSharpCode.CodeQualityAnalysis.Utility.Localizeable;
+using ICSharpCode.CodeQualityAnalysis.Utility;
using ICSharpCode.SharpDevelop.Widgets;
namespace ICSharpCode.CodeQualityAnalysis
@@ -64,6 +65,8 @@ public MainWindowViewModel():base()
ActivateMetrics = new RelayCommand(ActivateMetricsExecute);
ShowTreeMap = new RelayCommand(ShowTreemapExecute,CanActivateTreemap);
+
+ ExecuteSelectedItemWithCommand = new RelayCommand (ExecuteSelectedItem);
}
@@ -193,7 +196,13 @@ string UpdateToolStrip()
private ObservableCollection<INode> nodes;
public ObservableCollection<INode> Nodes {
- get { return nodes; }
+ get {
+ if (nodes == null)
+ {
+ nodes = new ObservableCollection<INode>();
+ }
+ return nodes;
+ }
set { nodes = value;
base.RaisePropertyChanged(() =>this.Nodes);}
}
@@ -219,7 +228,6 @@ string UpdateToolStrip()
public MetricsLevel SelectedMetricsLevel {
get { return selectedMetricsLevel; }
set { selectedMetricsLevel = value;
- SelectedMetricsIndex = 0;
base.RaisePropertyChanged(() =>this.SelectedMetricsLevel);
ResetTreeMap();
}
@@ -227,7 +235,7 @@ string UpdateToolStrip()
#endregion
- #region Metrics Combo > Right Combobox
+ #region Metrics Combo > Right Combobox
public Metrics Metrics
{
@@ -243,6 +251,7 @@ public Metrics Metrics
}
}
+ /*
int selectedMetricsIndex;
public int SelectedMetricsIndex {
@@ -251,6 +260,7 @@ public Metrics Metrics
selectedMetricsIndex = value;
base.RaisePropertyChanged(() =>this.SelectedMetricsIndex);}
}
+ */
#endregion
@@ -259,7 +269,7 @@ public Metrics Metrics
public ICommand ActivateMetrics {get;private set;}
bool metricsIsActive;
-
+ /*
void ActivateMetricsExecute ()
{
@@ -280,18 +290,117 @@ void ActivateMetricsExecute ()
throw new Exception("Invalid value for MetricsLevel");
}
}
+ */
#endregion
+ #region testregion
+
+ List<ItemWithCommand> itemsWithCommand;
+
+ public List<ItemWithCommand> ItemsWithCommand {
+ get {
+ if (itemsWithCommand == null) {
+ itemsWithCommand = new List<ItemWithCommand>();
+ }
+ return itemsWithCommand;
+ }
+ set { itemsWithCommand = value;
+ base.RaisePropertyChanged(() => ItemsWithCommand);}
+ }
+
+ void ActivateMetricsExecute ()
+ {
+ itemsWithCommand.Clear();
+ switch (SelectedMetricsLevel) {
+ case MetricsLevel.Assembly:
+
+ break;
+ case MetricsLevel.Namespace:
+
+ break;
+ case MetricsLevel.Type:
+
+ break;
+ case MetricsLevel.Method:
+ ItemsWithCommand.Add(new ItemWithCommand()
+ {
+ Description = "IL Instructions",
+ Command = new RelayCommand (ExecuteMerhodIlInstructions)
+ });
+ ItemsWithCommand.Add(new ItemWithCommand()
+ {
+ Description = "Cyclomatic Complexity",
+ Command = new RelayCommand (ExecuteMethodComplexity)
+ });
+ ItemsWithCommand.Add(new ItemWithCommand()
+ {
+ Description = "Variables",
+ Command = new RelayCommand (ExecuteMethodVariables)
+ });
+
+ break;
+ default:
+ throw new Exception("Invalid value for MetricsLevel");
+ }
+ }
+
+ ItemWithCommand selectedItemWithCommand;
+
+ public ItemWithCommand SelectedItemWithCommand {
+ get { return selectedItemWithCommand; }
+ set { selectedItemWithCommand = value;
+ base.RaisePropertyChanged(() => SelectedItemWithCommand);}
+ }
+
+ private void ExecuteMerhodIlInstructions()
+ {
+ var t = new testclass(MainModule);
+ TreeValueProperty = "Instructions.Count";
+ Nodes = t.QueryMethod();
+ }
+
+ private void ExecuteMethodComplexity ()
+ {
+ var t = new testclass(MainModule);
+ TreeValueProperty = Metrics.CyclomaticComplexity.ToString();
+ var tt = t.QueryMethod();
+ foreach (var element in tt) {
+ var m = element as Method;
+ Console.WriteLine("{0} - {1}",m.Name,m.CyclomaticComplexity);
+ }
+ Nodes = t.QueryMethod();
+ }
+
+
+ private void ExecuteMethodVariables ()
+ {
+ var t = new testclass(MainModule);
+ TreeValueProperty = Metrics.Variables.ToString();
+ Nodes = t.QueryMethod();
+ }
+
+ public ICommand ExecuteSelectedItemWithCommand {get; private set;}
+
+ void ExecuteSelectedItem()
+ {
+ SelectedItemWithCommand.Command.Execute(null);
+ }
+
+
+ #endregion
#region ShowTreeMap Treemap
void ResetTreeMap()
{
- if (Nodes != null) {
- Nodes.Clear();
- }
+
+ Nodes.Clear();
+ ItemsWithCommand.Clear();
+
+ base.RaisePropertyChanged(() => Nodes);
+ base.RaisePropertyChanged(() => ItemsWithCommand);
metricsIsActive = false;
}
@@ -379,8 +488,16 @@ ObservableCollection<INode> PrepareNodes()
}
#endregion
+ }
+
+
+ public class ItemWithCommand
+ {
+ public ItemWithCommand()
+ {
+ }
-
-
+ public string Description {get; set;}
+ public ICommand Command {get; set;}
}
}
View
38 src/AddIns/Analysis/CodeQuality/Src/Utility/testclass.cs
@@ -0,0 +1,38 @@
+/*
+ * Created by SharpDevelop.
+ * User: Peter Forstmeier
+ * Date: 25.12.2011
+ * Time: 19:07
+ *
+ * To change this template use Tools | Options | Coding | Edit Standard Headers.
+ */
+using System;
+using System.Linq;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+
+namespace ICSharpCode.CodeQualityAnalysis.Utility
+{
+ /// <summary>
+ /// Description of testclass.
+ /// </summary>
+ public class testclass
+ {
+ public testclass(Module mainModule)
+ {
+ MainModule = mainModule;
+ }
+
+ public Module MainModule {get; private set;}
+
+ public ObservableCollection <INode> QueryMethod()
+ {
+ IEnumerable<INode> list = new List<INode>();
+ list = from ns in MainModule.Namespaces
+ from type in ns.Types
+ from method in type.Methods
+ select method;
+ return new ObservableCollection <INode>(list);
+ }
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.