Skip to content

Commit

Permalink
Lieferung 3 feature-a: porting to mvvm pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
kaiarn committed Feb 9, 2018
2 parents f67116c + f77e36a commit ec0b289
Show file tree
Hide file tree
Showing 17 changed files with 459 additions and 792 deletions.
3 changes: 2 additions & 1 deletion LegendGenerator.App/Data/FormData.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@
<AttributeQuery />
<ChkFarbwerte>false</ChkFarbwerte>
<ChkAllowNullLegendNumber>false</ChkAllowNullLegendNumber>
<ChkGifExport>false</ChkGifExport>
<ChkGraphicExport>false</ChkGraphicExport>
<GraphicExportDirectory></GraphicExportDirectory>
<XOffset>10</XOffset>
<YOffset>3</YOffset>
<Vertikalabstand>0,3</Vertikalabstand>
Expand Down
358 changes: 11 additions & 347 deletions LegendGenerator.App/LayoutCreator.cs

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion LegendGenerator.App/LegendGenerator.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,16 @@
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
</Compile>
<Compile Include="Model\DesignDataservice.cs" />
<Compile Include="Utils\AdornerBehavior.cs" />
<Compile Include="Utils\CustomStringToColorConverter.cs" />
<Compile Include="Utils\Converter.cs" />
<Compile Include="Utils\Events.cs" />
<Compile Include="Utils\NotifyBase.cs" />
<Compile Include="Utils\ValidationAttribute.cs" />
<Compile Include="ViewModel\Help\XpsHelpEnViewModel.cs" />
<Compile Include="ViewModel\Help\XpsHelpViewModel.cs" />
<Compile Include="ViewModel\Help\HelpViewModel.cs" />
<Compile Include="ViewModel\LocalizableViewModel.cs" />
<Compile Include="ViewModel\MainViewModel.cs" />
<Compile Include="ViewModel\Help\CopyrightViewModel.cs" />
<Compile Include="ViewModel\Help\OverviewViewModel.cs" />
Expand Down
183 changes: 91 additions & 92 deletions LegendGenerator.App/MainWindow.xaml

Large diffs are not rendered by default.

281 changes: 9 additions & 272 deletions LegendGenerator.App/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
using System;
using System.Resources;
using System.Collections;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Microsoft.Win32;
using ESRI.ArcGIS.Framework;
using ESRI.ArcGIS.ArcMapUI;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Display;
using System.IO;
using LegendGenerator.App.Resources;
using LegendGenerator.App.View.Help;
using LegendGenerator.App.Model;
using LegendGenerator.App.Utils;
using System.Windows.Threading;
using LegendGenerator.App.View;
using LegendGenerator.App.ViewModel;
using System.Linq;

namespace LegendGenerator.App
{
Expand All @@ -29,13 +23,8 @@ public partial class MainWindow : Window
private IApplication m_application;//um auf die Map zuzugreifen, wird vom Command via Konstruktor initialisiert
private IMxDocument pMxDoc;
private IActiveView pActiveView;
private IMap pMap;

private string language;
private string pfadKonfigurationsdatei = String.Empty;//XML-Projektfile;

private string pfadSymbolDirectory;
private bool checkedGifExport;
private IMap pMap;

//Objekt zur Klasse mit den GIS-Funktionalitäten!!!
LayoutCreator layoutCreator;
protected AboutDialog aboutWindow;
Expand All @@ -51,31 +40,7 @@ public partial class MainWindow : Window
#endregion

#region properties:

public string PfadSymbolDirectory
{
get
{
return this.pfadSymbolDirectory;
}
set
{
this.pfadSymbolDirectory = value;
}
}

public bool CheckedGifExport
{
get
{
return this.checkedGifExport;
}
set
{
this.checkedGifExport = value;
}
}


/// <summary>
/// Returns the formdata model.
/// If this returns null, the user cancelled the input.
Expand All @@ -96,8 +61,7 @@ public FormularData FormData

public MainWindow()
{
InitializeComponent();
//this.DataContext = (App.Current.Resources["Locator"] as ViewModelLocator).Main;
InitializeComponent();
var mainViewModel = (this.Resources["Locator"] as ViewModelLocator).Main;
this.DataContext = mainViewModel;
mainViewModel.RequestClose += this.OnViewModelRequestClose;
Expand All @@ -108,29 +72,15 @@ public MainWindow(IApplication application)
if (null == application)
{
throw new Exception("Hook helper is not initialized");
}

}
InitializeComponent();
var mainViewModel = (this.Resources["Locator"] as ViewModelLocator).Main;
mainViewModel.Application = application;
this.DataContext = mainViewModel;
mainViewModel.RequestClose += this.OnViewModelRequestClose;

m_application = application;//?? throw new Exception("Hook helper is not initialized");//for the communication with the ArcGIS-Application!
layoutCreator = new LayoutCreator(this, m_application);//um auf die GIS-Methoden zugreifen zu können

//language settings: detect the windows language settings and load the correct language:
language = System.Globalization.CultureInfo.CurrentCulture.Name;
if (language.Contains("de") == true)
{
language = "de";
this.chkSpracheDeutsch.IsChecked = true;
}
else
{
language = "en";
this.chkSpracheEnglisch.IsChecked = true;
}
Resource.Culture = new System.Globalization.CultureInfo(language);
}

#endregion
Expand Down Expand Up @@ -176,18 +126,6 @@ private void BtnCreateLegend_Click(object sender, RoutedEventArgs e)
}
}

private void MnuStyleDump_Click(object sender, RoutedEventArgs e)
{
try
{
layoutCreator.StyleDump();
}
catch
{
MessageBox.Show("A general error during the stryle dumping process is occured!", "Style Dump Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}

#endregion

#region windows wpf-window methods
Expand Down Expand Up @@ -280,182 +218,7 @@ void OnOpenDocument()
}

#endregion

private void ChkSpracheDeutsch_Checked(object sender, RoutedEventArgs e)
{
this.chkSpracheEnglisch.IsChecked = false;
this.language = "de";

System.Globalization.CultureInfo test = new System.Globalization.CultureInfo(language);
Resource.Culture = new System.Globalization.CultureInfo(language);

Window window = this;
List<string> ControlNames = new List<string>();

ResourceSet resourceSet = Resource.ResourceManager.GetResourceSet(test, true, true);
foreach (DictionaryEntry entry in resourceSet)
{
string resourceKey = entry.Key.ToString();//Schlüssel = Name des Controls
object resource = entry.Value;//=Content der labels
ControlNames.Add(resourceKey.ToString());
}

foreach (Label lbl in TreeHelper.FindChildren<Label>(window))
{
if (ControlNames.Contains(lbl.Name))
{
// do something with lbl here
string content = lbl.Name;
lbl.Content = Resource.ResourceManager.GetString(content, Resource.Culture);
}

}

foreach (System.Windows.Controls.Button btn in TreeHelper.FindChildren<System.Windows.Controls.Button>(window))
{
if (ControlNames.Contains(btn.Name))
{
// do something with btn here
string content = btn.Name;
btn.Content = Resource.ResourceManager.GetString(content, Resource.Culture);
}
}

foreach (CheckBox chk in TreeHelper.FindChildren<CheckBox>(window))
{
if (ControlNames.Contains(chk.Name))
{
// do something with chk here
string content = chk.Name;
chk.Content = Resource.ResourceManager.GetString(content, Resource.Culture);
}
}

foreach (GroupBox grp in TreeHelper.FindChildren<GroupBox>(window))
{
if (ControlNames.Contains(grp.Name))
{
// do something with grp here
string header = grp.Name;
grp.Header = Resource.ResourceManager.GetString(header, Resource.Culture);
}
}

foreach (TabItem tabi in TreeHelper.FindChildren<TabItem>(window))
{
if (ControlNames.Contains(tabi.Name))
{
// do something with mni here
string header = tabi.Name;
tabi.Header = Resource.ResourceManager.GetString(header, Resource.Culture);
}
}

foreach (MenuItem mni in TreeHelper.FindChildren<MenuItem>(window))
{
if (ControlNames.Contains(mni.Name))
{
// do something with mni here
string header = mni.Name;
mni.Header = Resource.ResourceManager.GetString(header, Resource.Culture);
}
}
}

private void ChkSpracheDeutsch_Unchecked(object sender, RoutedEventArgs e)
{
this.chkSpracheEnglisch.IsChecked = true;
}

private void ChkSpracheEnglisch_Checked(object sender, RoutedEventArgs e)
{

this.chkSpracheDeutsch.IsChecked = false;
this.language = "en";
System.Globalization.CultureInfo test = new System.Globalization.CultureInfo(language);
Resource.Culture = new System.Globalization.CultureInfo(language);

Window window = this;

List<string> ControlNames = new List<string>();

ResourceSet resourceSet = Resource.ResourceManager.GetResourceSet(test, true, true);
foreach (DictionaryEntry entry in resourceSet)
{
string resourceKey = entry.Key.ToString();//Schlüssel = Name des Controls
object resource = entry.Value;//=Content der labels
ControlNames.Add(resourceKey.ToString());


}

foreach (Label lbl in TreeHelper.FindChildren<Label>(window))
{
if (ControlNames.Contains(lbl.Name))
{
// do something with lbl here
string content = lbl.Name;
lbl.Content = Resource.ResourceManager.GetString(content, Resource.Culture);
}

}

foreach (System.Windows.Controls.Button btn in TreeHelper.FindChildren<System.Windows.Controls.Button>(window))
{
if (ControlNames.Contains(btn.Name))
{
// do something with btn here
string content = btn.Name;
btn.Content = Resource.ResourceManager.GetString(content, Resource.Culture);
}
}

foreach (CheckBox chk in TreeHelper.FindChildren<CheckBox>(window))
{
if (ControlNames.Contains(chk.Name))
{
// do something with chk here
string content = chk.Name;
chk.Content = Resource.ResourceManager.GetString(content, Resource.Culture);
}
}

foreach (GroupBox grp in TreeHelper.FindChildren<GroupBox>(window))
{
if (ControlNames.Contains(grp.Name))
{
// do something with grp here
string header = grp.Name;
grp.Header = Resource.ResourceManager.GetString(header, Resource.Culture);
}
}

foreach (TabItem tabi in TreeHelper.FindChildren<TabItem>(window))
{
if (ControlNames.Contains(tabi.Name))
{
// do something with mni here
string header = tabi.Name;
tabi.Header = Resource.ResourceManager.GetString(header, Resource.Culture);
}
}

foreach (MenuItem mni in TreeHelper.FindChildren<MenuItem>(window))
{
if (ControlNames.Contains(mni.Name))
{
// do something with mni here
string header = mni.Name;
mni.Header = Resource.ResourceManager.GetString(header, Resource.Culture);
}
}
}

private void ChkSpracheEnglisch_Unchecked(object sender, RoutedEventArgs e)
{
this.chkSpracheDeutsch.IsChecked = true;
}


private void MnuAppHelp_Click(object sender, RoutedEventArgs e)
{
HelpWindow lgh = null;
Expand Down Expand Up @@ -560,27 +323,7 @@ private void MnuFortlaufendeNummer_Click(object sender, RoutedEventArgs e)
fnd.Close();
}
}

private void MnuGraphicExport_Click(object sender, RoutedEventArgs e)
{
SymbolDialog sd = null;
try
{
sd = new SymbolDialog(this);
//ab.ShowDialog();
sd.ShowDialog();//modal
if (sd.BtnClicked == true)
{
MessageBox.Show("The images will be exported during the legend-creating process in the defined folder!", "Info", MessageBoxButton.OK, MessageBoxImage.Information);
}
}
catch
{
MessageBox.Show("Please restart the about window!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
sd.Close();
}
}


private void BtnFortlaufendeNummer_Click(object sender, RoutedEventArgs e)
{
//Öffnen eines File Dialogs zur Auswahl der Konfigurationsdatei:
Expand Down Expand Up @@ -657,13 +400,7 @@ private void OnViewModelRequestClose(object sender, FeedbackEventArgs e)
base.Close();
}
}

private string CreateFileDoesNotExistMsg()
{
return "The example XML file '" + pfadKonfigurationsdatei + "' does not exist." + "\n\n" +
"To create the example XML file, enter formular data details, then click the 'Save' button.";
}


private void UpdateCboStyleFile()
{
cboStyleFile.Items.Clear();
Expand Down
Loading

0 comments on commit ec0b289

Please sign in to comment.