-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from ewrogers/fix-autosave
Fix autosave
- Loading branch information
Showing
37 changed files
with
694 additions
and
925 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using System; | ||
|
||
namespace SleepHunter.Common | ||
{ | ||
public abstract class UpdatableObject : ObservableObject, IDisposable | ||
{ | ||
protected bool isDisposed; | ||
|
||
public event EventHandler Updated; | ||
|
||
public void Update() | ||
{ | ||
CheckIfDisposed(); | ||
|
||
OnUpdate(); | ||
RaiseUpdated(); | ||
} | ||
|
||
public bool TryUpdate() | ||
{ | ||
CheckIfDisposed(); | ||
|
||
try | ||
{ | ||
Update(); | ||
return true; | ||
} | ||
catch | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
|
||
~UpdatableObject() => Dispose(false); | ||
|
||
public void RaiseUpdated() | ||
{ | ||
CheckIfDisposed(); | ||
Updated?.Invoke(this, EventArgs.Empty); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
Dispose(true); | ||
GC.SuppressFinalize(this); | ||
} | ||
|
||
protected virtual void Dispose(bool isDisposing) | ||
{ | ||
if (isDisposed) | ||
return; | ||
|
||
if (isDisposing) | ||
{ | ||
|
||
} | ||
|
||
isDisposed = true; | ||
} | ||
|
||
protected abstract void OnUpdate(); | ||
|
||
protected void CheckIfDisposed() | ||
{ | ||
if (isDisposed) | ||
throw new ObjectDisposedException(GetType().Name); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
SleepHunter/Extensions/CharacterExtender.cs → ...pHunter/Extensions/CharacterExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System.Windows.Threading; | ||
using SleepHunter.Threading; | ||
|
||
namespace SleepHunter.Extensions | ||
{ | ||
public static class DispatcherExtensions | ||
{ | ||
public static UIThreadAwaitable SwitchToUIThread(this Dispatcher dispatcher) | ||
{ | ||
return new UIThreadAwaitable(dispatcher); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System; | ||
using SleepHunter.Views; | ||
using System.Windows; | ||
|
||
namespace SleepHunter.Extensions | ||
{ | ||
public static class WindowExtensions | ||
{ | ||
public static bool? ShowMessageBox(this Window owner, string windowTitle, string messageText, string subText = null, MessageBoxButton buttons = MessageBoxButton.OK, int width = 420, int height = 280) | ||
{ | ||
if (owner == null) | ||
throw new ArgumentNullException(nameof(owner)); | ||
|
||
var messageBox = new MessageBoxWindow | ||
{ | ||
Title = windowTitle ?? string.Empty, | ||
Width = width, | ||
Height = height, | ||
MessageText = messageText ?? string.Empty, | ||
SubText = subText ?? string.Empty | ||
}; | ||
|
||
if (buttons == MessageBoxButton.OK) | ||
{ | ||
messageBox.CancelButtonColumnWidth = new GridLength(1, GridUnitType.Auto); | ||
messageBox.CancelButtonVisibility = Visibility.Collapsed; | ||
} | ||
|
||
if (buttons.HasFlag(MessageBoxButton.YesNo)) | ||
{ | ||
messageBox.OkButtonText = "_Yes"; | ||
messageBox.CancelButtonText = "_No"; | ||
} | ||
|
||
if (!owner.IsLoaded) | ||
owner.Show(); | ||
|
||
messageBox.Owner = owner; | ||
|
||
return messageBox.ShowDialog(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.