Browse Source

Add TranslationViewModel to MainView

pull/19/head
PeterForstmeier 15 years ago
parent
commit
b461484356
  1. 3
      src/AddIns/Analysis/CodeQuality/CodeQualityAnalysis.csproj
  2. 3
      src/AddIns/Analysis/CodeQuality/Src/Helper.cs
  3. 27
      src/AddIns/Analysis/CodeQuality/Src/MainWindow.xaml
  4. 5
      src/AddIns/Analysis/CodeQuality/Src/MainWindow.xaml.cs
  5. 102
      src/AddIns/Analysis/CodeQuality/Src/MainWindowTranslationModel.cs
  6. 155
      src/AddIns/Analysis/CodeQuality/Src/Utility/RelayCommand.cs
  7. 80
      src/AddIns/Analysis/CodeQuality/Src/Utility/ViewModelBase.cs

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

@ -133,6 +133,7 @@
<Compile Include="Src\INode.cs" /> <Compile Include="Src\INode.cs" />
<Compile Include="Src\Instruction.cs" /> <Compile Include="Src\Instruction.cs" />
<Compile Include="Src\IValue.cs" /> <Compile Include="Src\IValue.cs" />
<Compile Include="Src\MainWindowTranslationModel.cs" />
<Compile Include="Src\NodeIconService.cs" /> <Compile Include="Src\NodeIconService.cs" />
<Compile Include="Src\IDependency.cs" /> <Compile Include="Src\IDependency.cs" />
<Compile Include="Src\MetricsReader.cs" /> <Compile Include="Src\MetricsReader.cs" />
@ -143,6 +144,8 @@
<Compile Include="Src\Type.cs" /> <Compile Include="Src\Type.cs" />
<Compile Include="Src\Utility\DoubleKeyDictionary.cs" /> <Compile Include="Src\Utility\DoubleKeyDictionary.cs" />
<Compile Include="Src\Utility\Matrix.cs" /> <Compile Include="Src\Utility\Matrix.cs" />
<Compile Include="Src\Utility\RelayCommand.cs" />
<Compile Include="Src\Utility\ViewModelBase.cs" />
<Page Include="Resources\GraphTemplate.xaml"> <Page Include="Resources\GraphTemplate.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>

3
src/AddIns/Analysis/CodeQuality/Src/Helper.cs

@ -17,9 +17,10 @@ namespace ICSharpCode.CodeQualityAnalysis
{ {
public static void FillTree (ICSharpCode.TreeView.SharpTreeView tree,Module module) public static void FillTree (ICSharpCode.TreeView.SharpTreeView tree,Module module)
{ {
tree.ShowRoot = false;
var root = CreateTreeItem(module); var root = CreateTreeItem(module);
tree.Root = root; tree.Root = root;
foreach (var ns in module.Namespaces) foreach (var ns in module.Namespaces)
{ {
var namespaceNode = CreateTreeItem(ns); var namespaceNode = CreateTreeItem(ns);

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

@ -8,16 +8,25 @@
xmlns:debug="clr-namespace:System.Diagnostics;assembly=System" xmlns:debug="clr-namespace:System.Diagnostics;assembly=System"
xmlns:datavis="clr-namespace:System.Windows.Controls.DataVisualization;assembly=System.Windows.Controls.DataVisualization.Toolkit" xmlns:datavis="clr-namespace:System.Windows.Controls.DataVisualization;assembly=System.Windows.Controls.DataVisualization.Toolkit"
xmlns:tree="http://icsharpcode.net/sharpdevelop/treeview" xmlns:tree="http://icsharpcode.net/sharpdevelop/treeview"
xmlns:local="clr-namespace:ICSharpCode.CodeQualityAnalysis"
Title="Code Quality Analysis"
DataContext="{Binding RelativeSource={RelativeSource Self}}" Title="{Binding Title}"
x:Name="root"> x:Name="root">
<!--
Title="Code Quality Analysis"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
-->
<Window.DataContext>
<local:MainWindowTranslationViewModel />
</Window.DataContext>
<Window.Resources> <Window.Resources>
<ResourceDictionary> <ResourceDictionary>
<ResourceDictionary.MergedDictionaries> <ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../Resources/GraphTemplate.xaml" /> <ResourceDictionary Source="../Resources/GraphTemplate.xaml" />
</ResourceDictionary.MergedDictionaries> </ResourceDictionary.MergedDictionaries>
<!--
<DataTemplate x:Key="MemberTemplate"> <DataTemplate x:Key="MemberTemplate">
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<Image Source="{Binding Path=Icon}" Margin="0, 0, 5, 0" /> <Image Source="{Binding Path=Icon}" Margin="0, 0, 5, 0" />
@ -51,6 +60,7 @@
<TextBlock Text="{Binding Path=Name}" /> <TextBlock Text="{Binding Path=Name}" />
</StackPanel> </StackPanel>
</HierarchicalDataTemplate> </HierarchicalDataTemplate>
-->
</ResourceDictionary> </ResourceDictionary>
</Window.Resources> </Window.Resources>
@ -63,7 +73,14 @@
<ToolBarTray Background="White" Grid.Row="0"> <ToolBarTray Background="White" Grid.Row="0">
<ToolBar> <ToolBar>
<Button Name="btnOpenAssembly" Click="btnOpenAssembly_Click" Margin="0 0 5 0">Open Assembly</Button>
<Button Name="btnOpenAssembly"
Content="{Binding OpenAssembly}"
Click="btnOpenAssembly_Click"
Margin="0 0 5 0"></Button>
<!--
<Button Command="{Binding Path=OpenAssemblyCommand}" Margin="0 0 5 0">Open Assembly</Button>
-->
</ToolBar> </ToolBar>
</ToolBarTray> </ToolBarTray>

5
src/AddIns/Analysis/CodeQuality/Src/MainWindow.xaml.cs

@ -22,11 +22,13 @@ namespace ICSharpCode.CodeQualityAnalysis
/// <summary> /// <summary>
/// Interaction logic for MainWindow.xaml /// Interaction logic for MainWindow.xaml
/// </summary> /// </summary>
public partial class MainWindow : Window, INotifyPropertyChanged public partial class MainWindow : Window, INotifyPropertyChanged
{ {
private MetricsReader metricsReader; private MetricsReader metricsReader;
public event PropertyChangedEventHandler PropertyChanged; public event PropertyChangedEventHandler PropertyChanged;
public MetricsReader MetricsReader public MetricsReader MetricsReader
{ {
get get
@ -41,6 +43,8 @@ namespace ICSharpCode.CodeQualityAnalysis
} }
} }
public MainWindow() public MainWindow()
{ {
InitializeComponent(); InitializeComponent();
@ -215,6 +219,7 @@ namespace ICSharpCode.CodeQualityAnalysis
} }
} }
private void Metrics_SelectionChanged(object sender, SelectionChangedEventArgs e) private void Metrics_SelectionChanged(object sender, SelectionChangedEventArgs e)
{ {
var levelItem = cbxMetrixLevel.SelectedItem as ComboBoxItem; var levelItem = cbxMetrixLevel.SelectedItem as ComboBoxItem;

102
src/AddIns/Analysis/CodeQuality/Src/MainWindowTranslationModel.cs

@ -0,0 +1,102 @@
/*
* Created by SharpDevelop.
* User: Peter Forstmeier
* Date: 03.09.2011
* Time: 13:45
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.ComponentModel;
using System.Linq;
using System.Windows.Input;
using ICSharpCode.CodeQualityAnalysis.Controls;
using ICSharpCode.CodeQualityAnalysis.Utility;
using Microsoft.Win32;
namespace ICSharpCode.CodeQualityAnalysis
{
/// <summary>
/// Description of MainWindowViewModel.
/// </summary>
public class MainWindowTranslationViewModel :ViewModelBase
{
public MainWindowTranslationViewModel():base()
{
this.Title = "Code Quality Analysis";
this.OpenAssembly = "OpenAssembly";
}
public string Title {get;private set;}
public string OpenAssembly {get; private set;}
#region OpenAssembly
/*
public ICommand OpenAssemblyCommand
{
get { return new RelayCommand(OpenAssemblyExecute, CanOpenAssemblyExecute); }
}
Boolean CanOpenAssemblyExecute()
{
return true;
}
void OpenAssemblyExecute()
{
var fileDialog = new OpenFileDialog
{
Filter = "Component Files (*.dll, *.exe)|*.dll;*.exe"
};
fileDialog.ShowDialog();
if (String.IsNullOrEmpty(fileDialog.FileName))
return;
progressBar.Visibility = Visibility.Visible;
assemblyStats.Visibility = Visibility.Hidden;
fileAssemblyLoading.Text = System.IO.Path.GetFileName(fileDialog.FileName);
var worker = new BackgroundWorker();
worker.DoWork += (source, args) => MetricsReader = new MetricsReader(fileDialog.FileName);
worker.RunWorkerCompleted += (source, args) => {
progressBar.Visibility = Visibility.Hidden;
assemblyStats.Visibility = Visibility.Visible;
mainTabs.IsEnabled = true;
Helper.FillTree(definitionTree, metricsReader.MainModule);
FillMatrix();
};
worker.RunWorkerAsync();
}
private void FillMatrix()
{
var matrix = new DependencyMatrix();
foreach (var ns in metricsReader.MainModule.Namespaces) {
matrix.HeaderRows.Add(new Cell<INode>(ns));
foreach (var type in ns.Types) {
matrix.HeaderRows.Add(new Cell<INode>(type));
}
matrix.HeaderColumns.Add(new Cell<INode>(ns));
foreach (var type in ns.Types) {
matrix.HeaderColumns.Add(new Cell<INode>(type));
}
}
//matrixControl.Matrix = matrix;
//matrixControl.DrawTree(metricsReader.MainModule);
}
*/
#endregion
}
}

155
src/AddIns/Analysis/CodeQuality/Src/Utility/RelayCommand.cs

@ -0,0 +1,155 @@
/*
* Created by SharpDevelop.
* User: Peter Forstmeier
* Date: 03.09.2011
* Time: 14:25
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Diagnostics;
using System.Windows.Input;
namespace ICSharpCode.CodeQualityAnalysis.Utility
{
public class RelayCommand<T> : ICommand
{
#region Declarations
readonly Predicate<T> _canExecute;
readonly Action<T> _execute;
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="RelayCommand&lt;T&gt;"/> class and the command can always be executed.
/// </summary>
/// <param name="execute">The execution logic.</param>
public RelayCommand(Action<T> execute)
: this(execute, null)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="RelayCommand&lt;T&gt;"/> class.
/// </summary>
/// <param name="execute">The execution logic.</param>
/// <param name="canExecute">The execution status logic.</param>
public RelayCommand(Action<T> execute, Predicate<T> canExecute)
{
if (execute == null)
throw new ArgumentNullException("execute");
_execute = execute;
_canExecute = canExecute;
}
#endregion
#region ICommand Members
public event EventHandler CanExecuteChanged
{
add
{
if (_canExecute != null)
CommandManager.RequerySuggested += value;
}
remove
{
if (_canExecute != null)
CommandManager.RequerySuggested -= value;
}
}
[DebuggerStepThrough]
public Boolean CanExecute(Object parameter)
{
return _canExecute == null ? true : _canExecute((T)parameter);
}
public void Execute(Object parameter)
{
_execute((T)parameter);
}
#endregion
}
/// <summary>
/// A command whose sole purpose is to relay its functionality to other objects by invoking delegates. The default return value for the CanExecute method is 'true'.
/// </summary>
public class RelayCommand : ICommand
{
#region Declarations
readonly Func<Boolean> _canExecute;
readonly Action _execute;
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="RelayCommand&lt;T&gt;"/> class and the command can always be executed.
/// </summary>
/// <param name="execute">The execution logic.</param>
public RelayCommand(Action execute)
: this(execute, null)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="RelayCommand&lt;T&gt;"/> class.
/// </summary>
/// <param name="execute">The execution logic.</param>
/// <param name="canExecute">The execution status logic.</param>
public RelayCommand(Action execute, Func<Boolean> canExecute)
{
if (execute == null)
throw new ArgumentNullException("execute");
_execute = execute;
_canExecute = canExecute;
}
#endregion
#region ICommand Members
public event EventHandler CanExecuteChanged
{
add
{
if (_canExecute != null)
CommandManager.RequerySuggested += value;
}
remove
{
if (_canExecute != null)
CommandManager.RequerySuggested -= value;
}
}
[DebuggerStepThrough]
public Boolean CanExecute(Object parameter)
{
return _canExecute == null ? true : _canExecute();
}
public void Execute(Object parameter)
{
_execute();
}
#endregion
}
}

80
src/AddIns/Analysis/CodeQuality/Src/Utility/ViewModelBase.cs

@ -0,0 +1,80 @@
/*
* Created by SharpDevelop.
* User: Peter Forstmeier
* Date: 03.09.2011
* Time: 13:36
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.ComponentModel;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
namespace ICSharpCode.CodeQualityAnalysis.Utility
{
/// <summary>
/// Description of ViewModelBase.
/// </summary>
public class ViewModelBase:INotifyPropertyChanged
{
public ViewModelBase()
{
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(PropertyChangedEventArgs e)
{
var handler = this.PropertyChanged;
if (handler != null)
{
handler(this, e);
}
}
protected void RaisePropertyChanged<T>(Expression<Func<T>> propertyExpresssion)
{
var propertyName = ExtractPropertyName(propertyExpresssion);
this.RaisePropertyChanged(propertyName);
}
protected void RaisePropertyChanged(String propertyName)
{
OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
}
private static String ExtractPropertyName<T>(Expression<Func<T>> propertyExpresssion)
{
if (propertyExpresssion == null)
{
throw new ArgumentNullException("propertyExpresssion");
}
var memberExpression = propertyExpresssion.Body as MemberExpression;
if (memberExpression == null)
{
throw new ArgumentException("The expression is not a member access expression.", "propertyExpresssion");
}
var property = memberExpression.Member as PropertyInfo;
if (property == null)
{
throw new ArgumentException("The member access expression does not access a property.", "propertyExpresssion");
}
var getMethod = property.GetGetMethod(true);
if (getMethod.IsStatic)
{
throw new ArgumentException("The referenced property is a static property.", "propertyExpresssion");
}
return memberExpression.Member.Name;
}
}
}
Loading…
Cancel
Save