| | | 1 | | using GMap.NET.WindowsPresentation; |
| | | 2 | | using MahApps.Metro.Controls; |
| | | 3 | | using OffRouteMap.Properties; |
| | | 4 | | using System.Windows.Input; |
| | | 5 | | |
| | | 6 | | namespace OffRouteMap |
| | | 7 | | { |
| | | 8 | | |
| | | 9 | | public partial class MainWindow : MetroWindow |
| | | 10 | | { |
| | | 11 | | private readonly ThemeService _themeService; |
| | | 12 | | private readonly MainViewModel _viewModel; |
| | | 13 | | |
| | 0 | 14 | | public MainWindow () |
| | | 15 | | { |
| | 0 | 16 | | InitializeComponent(); |
| | | 17 | | |
| | | 18 | | // A primitve way for localisations. |
| | 0 | 19 | | btnCacheRoot.ToolTip = Strings.FolderDialog_Title; |
| | 0 | 20 | | btnDelete.ToolTip = Strings.DelCommand_Hint; |
| | 0 | 21 | | btnLoad.ToolTip = Strings.LoadDialog_Title; |
| | 0 | 22 | | btnSave.ToolTip = Strings.SaveDialog_Title; |
| | | 23 | | |
| | | 24 | | // set the UI theme |
| | 0 | 25 | | _themeService = new ThemeService(140, 220, 178); |
| | 0 | 26 | | _themeService.ApplyTheme(this, Settings.Default.isDark); |
| | | 27 | | |
| | 0 | 28 | | gmapControl.MouseMove += GMapControl_MouseMove; |
| | 0 | 29 | | gmapControl.MouseDoubleClick += GMapControl_MouseDoubleClick; |
| | 0 | 30 | | gmapControl.MouseRightButtonDown += GMapControl_MouseRightButtonDown; |
| | | 31 | | |
| | 0 | 32 | | var gmapWrapper = new GMapControlWrapper(gmapControl); |
| | 0 | 33 | | _viewModel = new MainViewModel(gmapWrapper); |
| | 0 | 34 | | DataContext = _viewModel; |
| | 0 | 35 | | } |
| | | 36 | | |
| | | 37 | | private void Window_Closing (object sender, System.ComponentModel.CancelEventArgs e) |
| | | 38 | | { |
| | 0 | 39 | | var viewModel = (MainViewModel)this.DataContext; |
| | | 40 | | |
| | 0 | 41 | | if (viewModel.BeforeClosingCommand.CanExecute(null)) |
| | | 42 | | { |
| | 0 | 43 | | viewModel.BeforeClosingCommand.Execute(null); |
| | | 44 | | } |
| | | 45 | | |
| | | 46 | | // @todo some newbie trail and error here :-S |
| | 0 | 47 | | e.Cancel = false; |
| | | 48 | | //Application.Current.Shutdown(); |
| | 0 | 49 | | Environment.Exit(0); |
| | | 50 | | //this.Close(); |
| | 0 | 51 | | } |
| | | 52 | | |
| | | 53 | | /// <summary> |
| | | 54 | | /// The event of mouse movement on the map forward to the DataModel. |
| | | 55 | | /// </summary> |
| | | 56 | | /// <param name="sender">sending ui element</param> |
| | | 57 | | /// <param name="e">mouse event. we need its position here</param> |
| | | 58 | | private void GMapControl_MouseMove (object sender, MouseEventArgs e) |
| | | 59 | | { |
| | 0 | 60 | | var point = e.GetPosition(gmapControl); |
| | 0 | 61 | | _viewModel.UpdateMousePositionFrom(point); |
| | 0 | 62 | | } |
| | | 63 | | |
| | | 64 | | /// <summary> |
| | | 65 | | /// The event of mouse double click on the map forward to the DataModel. |
| | | 66 | | /// </summary> |
| | | 67 | | /// <param name="sender">sending ui element</param> |
| | | 68 | | /// <param name="e">mouse event. we need its position here</param> |
| | | 69 | | private void GMapControl_MouseDoubleClick (object sender, MouseButtonEventArgs e) |
| | | 70 | | { |
| | 0 | 71 | | var point = e.GetPosition(gmapControl); |
| | 0 | 72 | | _viewModel.UpdateMousePositionFrom(point); |
| | 0 | 73 | | _viewModel.AddRoutePoint(); |
| | 0 | 74 | | } |
| | | 75 | | |
| | | 76 | | /// <summary> |
| | | 77 | | /// The event of mouse click on the map forward to the DataModel. |
| | | 78 | | /// </summary> |
| | | 79 | | /// <param name="sender">sending ui element</param> |
| | | 80 | | /// <param name="e">mouse event. we need its position here</param> |
| | | 81 | | private void GMapControl_MouseRightButtonDown (object sender, MouseButtonEventArgs e) |
| | | 82 | | { |
| | 0 | 83 | | var point = e.GetPosition(gmapControl); |
| | 0 | 84 | | _viewModel.UpdateMousePositionFrom(point); |
| | 0 | 85 | | _viewModel.RemoveLastRoutePoint(); |
| | 0 | 86 | | } |
| | | 87 | | } |
| | | 88 | | } |