Skip to content

Commit

Permalink
persistent window locked/unlocked & salvaged old favorites/ignored bl…
Browse files Browse the repository at this point in the history
…ueprint that were lost in previous udpate
  • Loading branch information
msarilar committed Nov 11, 2016
1 parent 0d83f33 commit 548a3dc
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 20 deletions.
3 changes: 3 additions & 0 deletions EDEngineer/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
<setting name="ResetUI" serializeAs="String">
<value>False</value>
</setting>
<setting name="WindowUnlocked" serializeAs="String">
<value>False</value>
</setting>
</EDEngineer.Properties.Settings>
</userSettings>
</configuration>
11 changes: 7 additions & 4 deletions EDEngineer/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@ public App()
{
AppDomain.CurrentDomain.UnhandledException += (o, e) =>
{
Current.MainWindow.Visibility = Visibility.Hidden;
if (Current.MainWindow != null)
{
Current.MainWindow.Visibility = Visibility.Hidden;
}

new ErrorWindow((Exception)e.ExceptionObject).ShowDialog();
Current.MainWindow.Close();
Current.MainWindow?.Close();
};

Current.DispatcherUnhandledException += (o, e) =>
{
Current.MainWindow.Visibility = Visibility.Hidden;
new ErrorWindow(e.Exception).ShowDialog();
Current.MainWindow.Close();
Current.MainWindow?.Close();
};
}
}
Expand Down
29 changes: 28 additions & 1 deletion EDEngineer/CommanderViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,40 @@ private void LoadBlueprints()
{
blueprint.Favorite = true;
favoritedBlueprints.Add(blueprint);

if (Settings.Default.Favorites.Contains($"{blueprint}"))
{
Settings.Default.Favorites.Remove($"{blueprint}");
Settings.Default.Save();
}
}
else if (Settings.Default.Favorites.Contains($"{blueprint}"))
{
blueprint.Favorite = true;
favoritedBlueprints.Add(blueprint);
Settings.Default.Favorites.Remove($"{blueprint}");
Settings.Default.Favorites.Add($"{CommanderName}:{blueprint}");
Settings.Default.Save();
}

if (Settings.Default.Ignored.Contains($"{CommanderName}:{blueprint}"))
{
blueprint.Ignored = true;
}

if (Settings.Default.Ignored.Contains($"{blueprint}"))
{
Settings.Default.Ignored.Remove($"{blueprint}");
Settings.Default.Save();
}
}
else if (Settings.Default.Ignored.Contains($"{blueprint}"))
{
blueprint.Ignored = true;
Settings.Default.Ignored.Remove($"{blueprint}");
Settings.Default.Ignored.Add($"{CommanderName}:{blueprint}");
Settings.Default.Save();
}

blueprint.PropertyChanged += (o, e) =>
{
if (e.PropertyName == "Favorite")
Expand Down
41 changes: 31 additions & 10 deletions EDEngineer/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,22 @@ public MainWindow()
}

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();
DataContext = viewModel;

Expand Down Expand Up @@ -100,7 +116,10 @@ private void MainWindowLoaded(object sender, RoutedEventArgs args)
ResetWindowPositionButton.Visibility = Visibility.Visible;
}

icon = TrayIconManager.Init((o, e) => ShowWindow(), (o, e) => Close(), ConfigureShortcut, (o, e) => ToggleEditModeChecked(o, null));
icon = TrayIconManager.Init((o, e) => ShowWindow(),
(o, e) => Close(), ConfigureShortcut,
(o, e) => ToggleEditModeChecked(o, null),
(o, e) => ResetWindowPositionButtonClicked(o, null));

var shortcut = SettingsManager.Shortcut;

Expand Down Expand Up @@ -304,7 +323,7 @@ protected override void OnClosed(EventArgs e)
icon.Dispose();
}

viewModel.LogWatcher?.Dispose();
viewModel?.LogWatcher?.Dispose();
}

private void WindowActivatedCompleted(object sender, EventArgs e)
Expand All @@ -320,14 +339,10 @@ private void WindowDeactivatedCompleted(object sender, EventArgs e)

private void ToggleEditModeChecked(object sender, RoutedEventArgs e)
{
var w = new MainWindow()
{
AllowsTransparency = !AllowsTransparency,
WindowStyle = WindowStyle == WindowStyle.SingleBorderWindow ? WindowStyle.None : WindowStyle.SingleBorderWindow,
Topmost = !Topmost,
ShowInTaskbar = !ShowInTaskbar
};
Properties.Settings.Default.WindowUnlocked = !Properties.Settings.Default.WindowUnlocked;
Properties.Settings.Default.Save();

var w = new MainWindow();
Close();
w.Show();
}
Expand Down Expand Up @@ -357,7 +372,13 @@ private void ResetWindowPositionButtonClicked(object sender, RoutedEventArgs e)
{
SettingsManager.Dimensions.Reset();
bypassPositionSave = true;
ToggleEditModeChecked(null, null);

Properties.Settings.Default.WindowUnlocked = false;
Properties.Settings.Default.Save();

var w = new MainWindow();
Close();
w.Show();
}
}
}
12 changes: 12 additions & 0 deletions EDEngineer/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions EDEngineer/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,8 @@
<Setting Name="ResetUI" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="WindowUnlocked" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
</Settings>
</SettingsFile>
2 changes: 1 addition & 1 deletion EDEngineer/Resources/Data/releaseNotes.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[
{
"Version": "1.0.0.31",
"Content": ""
"Content": "* Persistent window state (locked / unlocked) between restarts\r\n* Salvaged your old favorites/ignored blueprints that were lost in the previous update!\r\n Added a new Reset command in the tasktray icon in case your screen goes black. Checkout the Help command too!"
},
{
"Version": "1.0.0.30",
Expand Down
16 changes: 12 additions & 4 deletions EDEngineer/Utils/UI/TrayIconManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ public static class TrayIconManager
public static IDisposable Init(EventHandler showHandler,
EventHandler quitHandler,
EventHandler configureShortcutHandler,
EventHandler unlockWindowHandler)
EventHandler unlockWindowHandler,
EventHandler resetWindowHandler)
{
var menu = BuildContextMenu(showHandler, quitHandler, configureShortcutHandler, unlockWindowHandler);
var menu = BuildContextMenu(showHandler, quitHandler, configureShortcutHandler, unlockWindowHandler, resetWindowHandler);

var icon = new NotifyIcon
{
Expand All @@ -30,7 +31,7 @@ public static IDisposable Init(EventHandler showHandler,
});
}

private static ContextMenu BuildContextMenu(EventHandler showHandler, EventHandler quitHandler, EventHandler configureShortcutHandler, EventHandler unlockWindowHandler)
private static ContextMenu BuildContextMenu(EventHandler showHandler, EventHandler quitHandler, EventHandler configureShortcutHandler, EventHandler unlockWindowHandler, EventHandler resetWindowHandler)
{
var showItem = new MenuItem()
{
Expand All @@ -40,10 +41,16 @@ private static ContextMenu BuildContextMenu(EventHandler showHandler, EventHandl

var unlockItem = new MenuItem()
{
Text = "Toggle Window Mode (Lock/Unlocked)"
Text = "Toggle Window Mode (Locked/Unlocked)"
};
unlockItem.Click += unlockWindowHandler;

var resetItem = new MenuItem()
{
Text = "Reset Window Position"
};
resetItem.Click += resetWindowHandler;

var setShortCutItem = new MenuItem()
{
Text = "Set Shortcut"
Expand All @@ -65,6 +72,7 @@ private static ContextMenu BuildContextMenu(EventHandler showHandler, EventHandl
var menu = new ContextMenu();
menu.MenuItems.Add(showItem);
menu.MenuItems.Add(unlockItem);
menu.MenuItems.Add(resetItem);
menu.MenuItems.Add(setShortCutItem);
menu.MenuItems.Add("-");
menu.MenuItems.Add(helpItem);
Expand Down

0 comments on commit 548a3dc

Please sign in to comment.