Browse Source

try List<ItemWithCommand> for filtering nodes

pull/21/merge
PeterForstmeier 14 years ago
parent
commit
b964a68112
  1. 1
      src/AddIns/Analysis/CodeQuality/CodeQualityAnalysis.csproj
  2. 14
      src/AddIns/Analysis/CodeQuality/Src/MainWindow.xaml
  3. 127
      src/AddIns/Analysis/CodeQuality/Src/MainWindowModel.cs
  4. 38
      src/AddIns/Analysis/CodeQuality/Src/Utility/testclass.cs

1
src/AddIns/Analysis/CodeQuality/CodeQualityAnalysis.csproj

@ -151,6 +151,7 @@
<Compile Include="Src\Utility\Localizeable\EnumToFriendlyNameConverter.cs" /> <Compile Include="Src\Utility\Localizeable\EnumToFriendlyNameConverter.cs" />
<Compile Include="Src\Utility\Localizeable\LocalizableDescriptionAttribute.cs" /> <Compile Include="Src\Utility\Localizeable\LocalizableDescriptionAttribute.cs" />
<Compile Include="Src\Utility\Matrix.cs" /> <Compile Include="Src\Utility\Matrix.cs" />
<Compile Include="Src\Utility\testclass.cs" />
<Compile Include="Src\Utility\VisibleMatrix.cs" /> <Compile Include="Src\Utility\VisibleMatrix.cs" />
<Page Include="Resources\GridSplitterTemplate.xaml" /> <Page Include="Resources\GridSplitterTemplate.xaml" />
<Page Include="Resources\GraphTemplate.xaml"> <Page Include="Resources\GraphTemplate.xaml">

14
src/AddIns/Analysis/CodeQuality/Src/MainWindow.xaml

@ -307,7 +307,7 @@
</util:ComboBoxWithCommand> </util:ComboBoxWithCommand>
<TextBlock Margin="4,0,0,0" Text="Metric: " /> <TextBlock Margin="4,0,0,0" Text="Metric: " />
<!--
<util:ComboBoxWithCommand Width="200" Margin="4,0,0,0" <util:ComboBoxWithCommand Width="200" Margin="4,0,0,0"
ItemsSource="{Binding Source={StaticResource Metrics}}" ItemsSource="{Binding Source={StaticResource Metrics}}"
SelectedItem="{Binding SelectedMetrics}" SelectedItem="{Binding SelectedMetrics}"
@ -325,7 +325,17 @@
</DataTemplate> </DataTemplate>
</util:ComboBoxWithCommand.ItemTemplate> </util:ComboBoxWithCommand.ItemTemplate>
</util:ComboBoxWithCommand> </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> </ToolBar>
</ToolBarTray> </ToolBarTray>

127
src/AddIns/Analysis/CodeQuality/Src/MainWindowModel.cs

@ -16,6 +16,7 @@ using System.Windows.Controls;
using System.Windows.Input; using System.Windows.Input;
using ICSharpCode.CodeQualityAnalysis.Utility.Localizeable; using ICSharpCode.CodeQualityAnalysis.Utility.Localizeable;
using ICSharpCode.CodeQualityAnalysis.Utility;
using ICSharpCode.SharpDevelop.Widgets; using ICSharpCode.SharpDevelop.Widgets;
namespace ICSharpCode.CodeQualityAnalysis namespace ICSharpCode.CodeQualityAnalysis
@ -64,6 +65,8 @@ namespace ICSharpCode.CodeQualityAnalysis
ActivateMetrics = new RelayCommand(ActivateMetricsExecute); ActivateMetrics = new RelayCommand(ActivateMetricsExecute);
ShowTreeMap = new RelayCommand(ShowTreemapExecute,CanActivateTreemap); ShowTreeMap = new RelayCommand(ShowTreemapExecute,CanActivateTreemap);
ExecuteSelectedItemWithCommand = new RelayCommand (ExecuteSelectedItem);
} }
@ -193,7 +196,13 @@ namespace ICSharpCode.CodeQualityAnalysis
private ObservableCollection<INode> nodes; private ObservableCollection<INode> nodes;
public ObservableCollection<INode> Nodes { public ObservableCollection<INode> Nodes {
get { return nodes; } get {
if (nodes == null)
{
nodes = new ObservableCollection<INode>();
}
return nodes;
}
set { nodes = value; set { nodes = value;
base.RaisePropertyChanged(() =>this.Nodes);} base.RaisePropertyChanged(() =>this.Nodes);}
} }
@ -219,7 +228,6 @@ namespace ICSharpCode.CodeQualityAnalysis
public MetricsLevel SelectedMetricsLevel { public MetricsLevel SelectedMetricsLevel {
get { return selectedMetricsLevel; } get { return selectedMetricsLevel; }
set { selectedMetricsLevel = value; set { selectedMetricsLevel = value;
SelectedMetricsIndex = 0;
base.RaisePropertyChanged(() =>this.SelectedMetricsLevel); base.RaisePropertyChanged(() =>this.SelectedMetricsLevel);
ResetTreeMap(); ResetTreeMap();
} }
@ -243,6 +251,7 @@ namespace ICSharpCode.CodeQualityAnalysis
} }
} }
/*
int selectedMetricsIndex; int selectedMetricsIndex;
public int SelectedMetricsIndex { public int SelectedMetricsIndex {
@ -251,6 +260,7 @@ namespace ICSharpCode.CodeQualityAnalysis
selectedMetricsIndex = value; selectedMetricsIndex = value;
base.RaisePropertyChanged(() =>this.SelectedMetricsIndex);} base.RaisePropertyChanged(() =>this.SelectedMetricsIndex);}
} }
*/
#endregion #endregion
@ -259,7 +269,7 @@ namespace ICSharpCode.CodeQualityAnalysis
public ICommand ActivateMetrics {get;private set;} public ICommand ActivateMetrics {get;private set;}
bool metricsIsActive; bool metricsIsActive;
/*
void ActivateMetricsExecute () void ActivateMetricsExecute ()
{ {
@ -280,18 +290,117 @@ namespace ICSharpCode.CodeQualityAnalysis
throw new Exception("Invalid value for MetricsLevel"); throw new Exception("Invalid value for MetricsLevel");
} }
} }
*/
#endregion #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 #region ShowTreeMap Treemap
void ResetTreeMap() void ResetTreeMap()
{ {
if (Nodes != null) {
Nodes.Clear(); Nodes.Clear();
} ItemsWithCommand.Clear();
base.RaisePropertyChanged(() => Nodes);
base.RaisePropertyChanged(() => ItemsWithCommand);
metricsIsActive = false; metricsIsActive = false;
} }
@ -379,8 +488,16 @@ namespace ICSharpCode.CodeQualityAnalysis
} }
#endregion #endregion
}
public class ItemWithCommand
{
public ItemWithCommand()
{
}
public string Description {get; set;}
public ICommand Command {get; set;}
} }
} }

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);
}
}
}
Loading…
Cancel
Save