Skip to content

Commit

Permalink
[desktop] Topmost if memo is forgotten
Browse files Browse the repository at this point in the history
  • Loading branch information
Banyc committed Dec 7, 2020
1 parent 524107e commit d005870
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/UnforgettableMemo.WinDesktop/MainWindow.xaml.Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ namespace UnforgettableMemo.WinDesktop
{
public partial class MainWindow
{
private readonly MainWindowSettings mainWindowSettings;

public class MainWindowSettings
{
public double? TopLocation { get; set; }
public double? LeftLocation { get; set; }
public bool IsPreemptive { get; set; } = true;
public double RetrievabilityThreshold { get; set; } = 0.9;
}

private MainWindowSettings LoadSettings()
Expand Down
16 changes: 13 additions & 3 deletions src/UnforgettableMemo.WinDesktop/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class MainWindowViewModel
public MainWindow()
{
MainWindowSettings settings = LoadSettings();
this.mainWindowSettings = settings;
if (settings.LeftLocation != null)
{
this.Left = settings.LeftLocation.Value;
Expand Down Expand Up @@ -66,7 +67,7 @@ private void UpdateDisplayingMemo()
this.memoScheduler.GetNewMemo();
}
this.viewModel.DisplayingMemo = this.memoScheduler.Memos[0];
UpdateTxtContent();
UpdateFrontend();

this.memoScheduler.Save();
}
Expand All @@ -78,7 +79,7 @@ private void btnAdd_Click(object sender, RoutedEventArgs e)
return;
}
this.viewModel.DisplayingMemo = this.memoScheduler.GetNewMemo();
UpdateTxtContent();
UpdateFrontend();
this.memoScheduler.Save();
}

Expand Down Expand Up @@ -111,10 +112,19 @@ private void topBar_PreviewMouseLeftButtonDown(object sender, MouseButtonEventAr

private void txtContent_TextChanged(object sender, TextChangedEventArgs e)
{
UpdateTxtContent();
UpdateFrontend();
this.memoScheduler.Save();
}

private void UpdateFrontend()
{
UpdateTxtContent();
if (this.mainWindowSettings.IsPreemptive)
{
this.Topmost = this.viewModel.DisplayingMemo.Retrievability < this.mainWindowSettings.RetrievabilityThreshold;
}
}

private void UpdateTxtContent()
{
BindingExpression binding = this.txtContent.GetBindingExpression(TextBox.TextProperty);
Expand Down

0 comments on commit d005870

Please sign in to comment.