public MainWindow() { var procName = Process.GetCurrentProcess().ProcessName; var processes = Process.GetProcessesByName(procName); if (processes.Length > 1) { System.Windows.Forms.MessageBox.Show($"EDEngineer already running, you can bring it up with your shortcut ({SettingsManager.Shortcut}).", "Oops", MessageBoxButtons.OK, MessageBoxIcon.Warning); Application.Current.Shutdown(); return; } SettingsManager.Init(); try { ReleaseNotesManager.ShowReleaseNotes(); } catch { // silently fail if release notes can't be shown } Languages.InitLanguages(); InitializeComponent(); if (Properties.Settings.Default.WindowUnlocked) { AllowsTransparency = false; WindowStyle = WindowStyle.SingleBorderWindow; Topmost = false; ShowInTaskbar = true; } else { AllowsTransparency = true; WindowStyle = WindowStyle.None; Topmost = true; ShowInTaskbar = false; } viewModel = new MainWindowViewModel(Languages.Instance); DataContext = viewModel; RefreshCargoSources(); viewModel.PropertyChanged += (o, e) => { if (e.PropertyName == "ShowOnlyForFavorites" || e.PropertyName == "ShowZeroes" || e.PropertyName == "CurrentCommander") { RefreshCargoSources(); } }; }
private void PostLoad(WindowDimensions dimensions) { if (dimensions.LeftSideWidth != 1 || dimensions.RightSideWidth != 1) { ContentGrid.ColumnDefinitions[0].Width = new GridLength(dimensions.LeftSideWidth, GridUnitType.Star); ContentGrid.ColumnDefinitions[2].Width = new GridLength(dimensions.RightSideWidth, GridUnitType.Star); } if (AllowsTransparency) { ToggleEditMode.Content = viewModel.Languages.Translate("Unlock Window"); MainSplitter.Visibility = Visibility.Hidden; } else { ToggleEditMode.Content = viewModel.Languages.Translate("Lock Window"); ResetWindowPositionButton.Visibility = Visibility.Visible; } menu = TrayIconManager.BuildContextMenu((o, e) => ShowWindow(), (o, e) => Close(), ConfigureShortcut, (o, e) => ToggleEditModeChecked(o, null), (o, e) => ResetWindowPositionButtonClicked(o, null), (o, e) => Languages.PromptLanguage(viewModel.Languages), () => serverBridge.Toggle(), serverBridge.Running, (o, e) => { ReleaseNotesManager.ShowReleaseNotes(); }, Properties.Settings.Default.CurrentVersion, (o, e) => { new NotificationSettingsWindow(viewModel.Languages).ShowDialog(); }, (o, e) => { new GraphicSettingsWindow(viewModel.GraphicSettings).ShowDialog(); }, (o, e) => { System.Diagnostics.Process.Start($"http://localhost:{SettingsManager.ServerPort}/{viewModel.CurrentCommander.Key}/chart"); }, (o, e) => ClearAggregationAndRestart(o, null), (o, e) => { new SettingsExportWindow(Restart, RefreshShoppingList).ShowDialog(); }); icon = TrayIconManager.Init(menu); try { var shortcut = SettingsManager.Shortcut; var hotKey = (Keys) new KeysConverter().ConvertFromString(shortcut); HotkeyManager.RegisterHotKey(this, hotKey); } catch { SettingsManager.Shortcut = null; ConfigureShortcut(this, EventArgs.Empty); ShowWindow(); } Blueprints.UpdateLayout(); ShoppingList.UpdateLayout(); if (!AllowsTransparency) { saveDimensionScheduler = new PostponeScheduler(SaveDimensions, 500); SizeChanged += (o, e) => saveDimensionScheduler.Schedule(); LocationChanged += (o, e) => saveDimensionScheduler.Schedule(); MainSplitter.DragCompleted += (o, e) => saveDimensionScheduler.Schedule(); } }
private void MainWindowLoaded(object sender, RoutedEventArgs args) { var dimensions = SettingsManager.Dimensions; Width = dimensions.Width; Left = dimensions.Left; Top = dimensions.Top; Height = dimensions.Height; if (dimensions.LeftSideWidth != 1 || dimensions.RightSideWidth != 1) { ContentGrid.ColumnDefinitions[0].Width = new GridLength(dimensions.LeftSideWidth, GridUnitType.Star); ContentGrid.ColumnDefinitions[2].Width = new GridLength(dimensions.RightSideWidth, GridUnitType.Star); } if (AllowsTransparency) { ToggleEditMode.Content = viewModel.Languages.Translate("Unlock Window"); MainSplitter.Visibility = Visibility.Hidden; } else { ToggleEditMode.Content = viewModel.Languages.Translate("Lock Window"); ResetWindowPositionButton.Visibility = Visibility.Visible; } menu = TrayIconManager.BuildContextMenu((o, e) => ShowWindow(), (o, e) => Close(), ConfigureShortcut, (o, e) => ToggleEditModeChecked(o, null), (o, e) => ResetWindowPositionButtonClicked(o, null), (o, e) => Languages.PromptLanguage(viewModel.Languages), () => serverBridge.Toggle(), serverBridge.Running, (o, e) => { ReleaseNotesManager.ShowReleaseNotes(); }, Properties.Settings.Default.CurrentVersion, (o, e) => { ThresholdsManagerWindow.ShowThresholds(viewModel.Languages, viewModel.CurrentCommander.Value.State.Cargo, viewModel.CurrentCommander.Key); }, (o, e) => { new NotificationSettingsWindow(viewModel.Languages).ShowDialog(); }, (o, e) => { new GraphicSettingsWindow(viewModel.GraphicSettings).ShowDialog(); }); icon = TrayIconManager.Init(menu); try { var shortcut = SettingsManager.Shortcut; var hotKey = (Keys) new KeysConverter().ConvertFromString(shortcut); HotkeyManager.RegisterHotKey(this, hotKey); } catch { SettingsManager.Shortcut = null; ConfigureShortcut(this, EventArgs.Empty); ShowWindow(); } Blueprints.UpdateLayout(); ShoppingList.UpdateLayout(); if (!AllowsTransparency) { saveDimensionScheduler = new PostponeScheduler(SaveDimensions, 500); SizeChanged += (o, e) => saveDimensionScheduler.Schedule(); LocationChanged += (o, e) => saveDimensionScheduler.Schedule(); MainSplitter.DragCompleted += (o, e) => saveDimensionScheduler.Schedule(); } }