From 8926af5118568fb55e99d6175ec6cd8f13ff8821 Mon Sep 17 00:00:00 2001 From: PeterForstmeier Date: Sun, 4 Sep 2011 16:02:28 +0200 Subject: [PATCH] ViewModel - MainWindow.xaml --- .../Analysis/CodeQuality/Src/MainWindow.xaml | 14 +- .../CodeQuality/Src/MainWindow.xaml.cs | 26 ++-- .../Src/MainWindowTranslationModel.cs | 131 ++++++++++++------ 3 files changed, 112 insertions(+), 59 deletions(-) diff --git a/src/AddIns/Analysis/CodeQuality/Src/MainWindow.xaml b/src/AddIns/Analysis/CodeQuality/Src/MainWindow.xaml index ae112c0b37..9940fa460b 100644 --- a/src/AddIns/Analysis/CodeQuality/Src/MainWindow.xaml +++ b/src/AddIns/Analysis/CodeQuality/Src/MainWindow.xaml @@ -46,7 +46,7 @@ DataContext="{Binding RelativeSource={RelativeSource Self}}" - + @@ -93,16 +93,16 @@ DataContext="{Binding RelativeSource={RelativeSource Self}}" HighlightAlgorithmType="Simple" VertexClick="graphLayout_VertexClick" /> + + Style="{DynamicResource GridSplitterStyle1}"> @@ -154,15 +154,15 @@ DataContext="{Binding RelativeSource={RelativeSource Self}}" - + - + - + diff --git a/src/AddIns/Analysis/CodeQuality/Src/MainWindow.xaml.cs b/src/AddIns/Analysis/CodeQuality/Src/MainWindow.xaml.cs index 4f3ef2a03d..01b830d2b6 100644 --- a/src/AddIns/Analysis/CodeQuality/Src/MainWindow.xaml.cs +++ b/src/AddIns/Analysis/CodeQuality/Src/MainWindow.xaml.cs @@ -26,8 +26,8 @@ namespace ICSharpCode.CodeQualityAnalysis public partial class MainWindow : Window, INotifyPropertyChanged { private MetricsReader metricsReader; - public event PropertyChangedEventHandler PropertyChanged; + public event PropertyChangedEventHandler PropertyChanged; public MetricsReader MetricsReader { @@ -43,13 +43,12 @@ namespace ICSharpCode.CodeQualityAnalysis } } - - public MainWindow() { InitializeComponent(); } + private void NotifyPropertyChanged(string propertyName) { if (PropertyChanged != null) @@ -58,6 +57,9 @@ namespace ICSharpCode.CodeQualityAnalysis private void btnOpenAssembly_Click(object sender, RoutedEventArgs e) { + + var dc = this.DataContext as MainWindowTranslationViewModel; + var fileDialog = new OpenFileDialog { Filter = "Component Files (*.dll, *.exe)|*.dll;*.exe" @@ -68,16 +70,18 @@ namespace ICSharpCode.CodeQualityAnalysis if (String.IsNullOrEmpty(fileDialog.FileName)) return; - progressBar.Visibility = Visibility.Visible; - assemblyStats.Visibility = Visibility.Hidden; - fileAssemblyLoading.Text = System.IO.Path.GetFileName(fileDialog.FileName); + dc.ProgressbarVisible = Visibility.Visible; + dc.AssemblyStatsVisible = Visibility.Hidden; + dc.FileName = 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; + + dc.ProgressbarVisible = Visibility.Hidden; + dc.AssemblyStatsVisible = Visibility.Visible; + dc.MainTabEnable = true; + Helper.FillTree(definitionTree, metricsReader.MainModule); FillMatrix(); }; @@ -134,7 +138,8 @@ namespace ICSharpCode.CodeQualityAnalysis var vertex = vertexControl.Vertex as DependencyVertex; if (vertex != null) { - txbTypeInfo.Text = vertex.Node.GetInfo(); + var d = this.DataContext as MainWindowTranslationViewModel; + d.TypeInfo = vertex.Node.GetInfo(); } } } @@ -146,6 +151,7 @@ namespace ICSharpCode.CodeQualityAnalysis private void btnSaveImageGraph_Click(object sender, RoutedEventArgs e) { + var fileDialog = new SaveFileDialog() { Filter = "PNG (*.png)|*.png|JPEG (*.jpg)|*.jpg|GIF (*.gif)|*.gif|BMP (*.bmp)|*.bmp|TIFF (.tiff)|*.tiff" diff --git a/src/AddIns/Analysis/CodeQuality/Src/MainWindowTranslationModel.cs b/src/AddIns/Analysis/CodeQuality/Src/MainWindowTranslationModel.cs index 5f30832a1a..4b148a066f 100644 --- a/src/AddIns/Analysis/CodeQuality/Src/MainWindowTranslationModel.cs +++ b/src/AddIns/Analysis/CodeQuality/Src/MainWindowTranslationModel.cs @@ -9,7 +9,9 @@ using System; using System.ComponentModel; using System.Linq; +using System.Windows; using System.Windows.Input; +using System.Windows.Media.Imaging; using ICSharpCode.CodeQualityAnalysis.Controls; using ICSharpCode.CodeQualityAnalysis.Utility; @@ -22,6 +24,9 @@ namespace ICSharpCode.CodeQualityAnalysis /// public class MainWindowTranslationViewModel :ViewModelBase { + string typeInfo; + + public MainWindowTranslationViewModel():base() { @@ -37,71 +42,113 @@ namespace ICSharpCode.CodeQualityAnalysis public string DependencyGraph {get; private set;} + private string fileName; + public string FileName { + get { return fileName; } + set { fileName = value; + base.RaisePropertyChanged(() =>FileName);} + } + + private Visibility progressbarVisibly ; + + public Visibility ProgressbarVisible { + get { return progressbarVisibly; } + set { progressbarVisibly = value; + base.RaisePropertyChanged(() =>ProgressbarVisible); + } + } + + private Visibility assemblyStatsVisible; + + public Visibility AssemblyStatsVisible { + get { return assemblyStatsVisible; } + set { assemblyStatsVisible = value; + base.RaisePropertyChanged(() => AssemblyStatsVisible); + } + } + + bool mainTabEnable; + + public bool MainTabEnable { + get { return mainTabEnable; } + set { mainTabEnable = value; + base.RaisePropertyChanged(() => MainTabEnable); + } + } + + public string TypeInfo { + get { return typeInfo; } + set { typeInfo = value; + base.RaisePropertyChanged(() =>this.TypeInfo); + } + } - #region OpenAssembly /* + #region OpenAssembly + public ICommand OpenAssemblyCommand { - get { return new RelayCommand(OpenAssemblyExecute, CanOpenAssemblyExecute); } + get { return new RelayCommand(SaveAssemblyExecute, CanSaveAssemblyExecute); } } - Boolean CanOpenAssemblyExecute() + Boolean CanSaveAssemblyExecute() { return true; } - void OpenAssemblyExecute() + void SaveAssemblyExecute() { - var fileDialog = new OpenFileDialog + var fileDialog = new SaveFileDialog() { - Filter = "Component Files (*.dll, *.exe)|*.dll;*.exe" + Filter = "PNG (*.png)|*.png|JPEG (*.jpg)|*.jpg|GIF (*.gif)|*.gif|BMP (*.bmp)|*.bmp|TIFF (.tiff)|*.tiff" }; 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(ns)); - foreach (var type in ns.Types) { - matrix.HeaderRows.Add(new Cell(type)); - } - matrix.HeaderColumns.Add(new Cell(ns)); - foreach (var type in ns.Types) { - matrix.HeaderColumns.Add(new Cell(type)); + // render it + var renderBitmap = new RenderTargetBitmap((int)graphLayout.ActualWidth, + (int)graphLayout.ActualHeight, + 96d, + 96d, + PixelFormats.Default); + renderBitmap.Render(graphLayout); + + using (var outStream = new FileStream(fileDialog.FileName, FileMode.Create)) + { + BitmapEncoder encoder; + + switch (fileDialog.FilterIndex) + { + case 1: + encoder = new PngBitmapEncoder(); + break; + case 2: + encoder = new JpegBitmapEncoder(); + break; + case 3: + encoder = new GifBitmapEncoder(); + break; + case 4: + encoder = new BmpBitmapEncoder(); + break; + case 5: + encoder = new TiffBitmapEncoder(); + break; + default: + encoder = new PngBitmapEncoder(); + break; } + + encoder.Frames.Add(BitmapFrame.Create(renderBitmap)); + encoder.Save(outStream); } - - //matrixControl.Matrix = matrix; - //matrixControl.DrawTree(metricsReader.MainModule); - } - */ + } #endregion + */ } }