Skip to content

Commit

Permalink
Fixed a bug where App should exit when last tab was dragged to anothe…
Browse files Browse the repository at this point in the history
…r app instance

Fixed a bug where App should exit when last tab was dragged to another app instance
  • Loading branch information
0x7c13 committed Sep 12, 2019
1 parent 499e7c0 commit cec85f2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/Notepads/Core/INotepadsCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public interface INotepadsCore

event EventHandler<ITextEditor> TextEditorModeChanged;

event EventHandler<ITextEditor> TextEditorMovedToAnotherAppInstance;

event EventHandler<IReadOnlyList<IStorageItem>> StorageItemsDropped;

event KeyEventHandler TextEditorKeyDown;
Expand Down
4 changes: 3 additions & 1 deletion src/Notepads/Core/NotepadsCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public class NotepadsCore : INotepadsCore

public event EventHandler<ITextEditor> TextEditorModeChanged;

public event EventHandler<ITextEditor> TextEditorMovedToAnotherAppInstance;

public event EventHandler<IReadOnlyList<IStorageItem>> StorageItemsDropped;

public event KeyEventHandler TextEditorKeyDown;
Expand Down Expand Up @@ -728,7 +730,7 @@ private void Sets_DragItemsCompleted(ListViewBase sender, DragItemsCompletedEven
{
if (args.Items.FirstOrDefault() is ITextEditor editor)
{
DeleteTextEditor(editor);
TextEditorMovedToAnotherAppInstance?.Invoke(this, editor);
}
}

Expand Down
24 changes: 24 additions & 0 deletions src/Notepads/NotepadsMainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Notepads.Settings;
using Notepads.Utilities;
using Windows.ApplicationModel.Activation;
using Windows.ApplicationModel.Core;
using Windows.ApplicationModel.DataTransfer;
using Windows.ApplicationModel.Resources;
using Windows.Storage;
Expand Down Expand Up @@ -56,6 +57,7 @@ private INotepadsCore NotepadsCore
_notepadsCore.TextEditorUnloaded += OnTextEditorUnloaded;
_notepadsCore.TextEditorKeyDown += OnTextEditor_KeyDown;
_notepadsCore.TextEditorClosing += OnTextEditorClosing;
_notepadsCore.TextEditorMovedToAnotherAppInstance += OnTextEditorMovedToAnotherAppInstance;
_notepadsCore.TextEditorSelectionChanged += (sender, editor) => { if (NotepadsCore.GetSelectedTextEditor() == editor) UpdateLineColumnIndicator(editor); };
_notepadsCore.TextEditorEncodingChanged += (sender, editor) => { if (NotepadsCore.GetSelectedTextEditor() == editor) UpdateEncodingIndicator(editor.GetEncoding()); };
_notepadsCore.TextEditorLineEndingChanged += (sender, editor) => { if (NotepadsCore.GetSelectedTextEditor() == editor) UpdateLineEndingIndicator(editor.GetLineEnding()); };
Expand Down Expand Up @@ -463,6 +465,28 @@ private void OnTextEditorUnloaded(object sender, ITextEditor textEditor)
}
}

private async void OnTextEditorMovedToAnotherAppInstance(object sender, ITextEditor textEditor)
{
// Notepads should exit if last tab was dragged to another app instance
if (NotepadsCore.GetNumberOfOpenedTextEditors() == 1)
{
if (EditorSettingsService.IsSessionSnapshotEnabled)
{
NotepadsCore.DeleteTextEditor(textEditor);
await SessionManager.SaveSessionAsync(() => { SessionManager.IsBackupEnabled = false; });
CoreApplication.Exit();
}
else
{
CoreApplication.Exit();
}
}
else
{
NotepadsCore.DeleteTextEditor(textEditor);
}
}

private async void OnTextEditorClosing(object sender, ITextEditor textEditor)
{
if (NotepadsCore.GetNumberOfOpenedTextEditors() == 1 && textEditor.IsModified == false && textEditor.EditingFile == null)
Expand Down

0 comments on commit cec85f2

Please sign in to comment.