Skip to content
This repository has been archived by the owner on Oct 16, 2020. It is now read-only.

Commit

Permalink
try List<ItemWithCommand> for filtering nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterForstmeier committed Dec 27, 2011
1 parent dd45b72 commit b964a68
Show file tree
Hide file tree
Showing 4 changed files with 177 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/AddIns/Analysis/CodeQuality/CodeQualityAnalysis.csproj
Expand Up @@ -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">
Expand Down
14 changes: 12 additions & 2 deletions src/AddIns/Analysis/CodeQuality/Src/MainWindow.xaml
Expand Up @@ -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}"
Expand All @@ -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>

Expand Down
135 changes: 126 additions & 9 deletions src/AddIns/Analysis/CodeQuality/Src/MainWindowModel.cs
Expand Up @@ -16,6 +16,7 @@
using System.Windows.Input;

using ICSharpCode.CodeQualityAnalysis.Utility.Localizeable;
using ICSharpCode.CodeQualityAnalysis.Utility;
using ICSharpCode.SharpDevelop.Widgets;

namespace ICSharpCode.CodeQualityAnalysis
Expand Down Expand Up @@ -64,6 +65,8 @@ public MainWindowViewModel():base()

ActivateMetrics = new RelayCommand(ActivateMetricsExecute);
ShowTreeMap = new RelayCommand(ShowTreemapExecute,CanActivateTreemap);

ExecuteSelectedItemWithCommand = new RelayCommand (ExecuteSelectedItem);
}


Expand Down Expand Up @@ -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);}
}
Expand All @@ -219,15 +228,14 @@ string UpdateToolStrip()
public MetricsLevel SelectedMetricsLevel {
get { return selectedMetricsLevel; }
set { selectedMetricsLevel = value;
SelectedMetricsIndex = 0;
base.RaisePropertyChanged(() =>this.SelectedMetricsLevel);
ResetTreeMap();
}
}

#endregion

#region Metrics Combo > Right Combobox
#region Metrics Combo > Right Combobox

public Metrics Metrics
{
Expand All @@ -243,6 +251,7 @@ public Metrics Metrics
}
}

/*
int selectedMetricsIndex;
public int SelectedMetricsIndex {
Expand All @@ -251,6 +260,7 @@ public Metrics Metrics
selectedMetricsIndex = value;
base.RaisePropertyChanged(() =>this.SelectedMetricsIndex);}
}
*/

#endregion

Expand All @@ -259,7 +269,7 @@ public Metrics Metrics
public ICommand ActivateMetrics {get;private set;}

bool metricsIsActive;

/*
void ActivateMetricsExecute ()
{
Expand All @@ -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;
}

Expand Down Expand Up @@ -379,8 +488,16 @@ ObservableCollection<INode> PrepareNodes()
}

#endregion
}


public class ItemWithCommand
{
public ItemWithCommand()
{
}



public string Description {get; set;}
public ICommand Command {get; set;}
}
}
38 changes: 38 additions & 0 deletions 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);
}
}
}

0 comments on commit b964a68

Please sign in to comment.