Skip to content

Commit

Permalink
Merge branch 'dev' into feature-286-thresholddate
Browse files Browse the repository at this point in the history
  • Loading branch information
benrhughes authored Nov 19, 2018
2 parents 1e4a907 + 144cbb8 commit d30d16f
Show file tree
Hide file tree
Showing 15 changed files with 180 additions and 66 deletions.
70 changes: 59 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,28 +1,17 @@
# ReSharper meta directory
_ReSharper*

# Build Folders (you can keep bin if you'd like, to store dlls and pdbs)
bin
obj

*.pdb
*.exe
*.dll

# user settings
*.user
*.suo

# if you have pictures, windows will likely create those annoying index files
Thumbs.db

# mstest test results
TestResults

# generated installer packages
*.msi
*.exe

# finalbuilder log/tmp files
*.fbl7
*.fb7lck
Expand All @@ -36,6 +25,65 @@ testtasks.txt

# ignore installer output
Installer/Output
Installer/ProgramFiles

# NuGet Packages Directory
packages/

# ides
.idea
*.iml
.vs
_ReSharper*
*.sln.Dotsettings

# linux
*~
.directory # KDE directory preferences
.Trash-* # Linux trash folder which might appear on any partition or disk

# macos
.DS_Store
.AppleDouble
.LSOverride
Icon # Icon must end with two \r
._* # Thumbnails
.DocumentRevisions-V100 # Files that might appear in the root of a volume
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.AppleDB # Directories potentially created on remote AFP share
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

# windows
Thumbs.db
ehthumbs.db
Desktop.ini
$RECYCLE.BIN/
*.cab # Windows Installer files
*.msi
*.msm
*.msp
*.lnk # Windows shortcuts

# idea
.idea
*.iml
out
gen

# visual studio
.vs

# sqlite
*.db
*.sqlite3

# ctag generated file
tags
.tags
21 changes: 19 additions & 2 deletions Client/Controls/IntellisenseTextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
Expand All @@ -22,6 +23,9 @@ public class IntellisenseTextBox : TextBox
private ListBox IntellisenseList { get; set; }
private int IntelliPos { get; set; } // used to position the Intellisense popup

private readonly Regex StartDateWithPriorityRegex = new Regex(@"[0-9]{4}\-[0-9]{2}\-[0-9]{2}\s\(");
private readonly List<string> Priorities = Enumerable.Range('A', 26).Select(i => $"({Convert.ToChar(i)})").ToList();

public TaskList TaskList
{
get
Expand Down Expand Up @@ -249,7 +253,7 @@ private string FindIntelliWord()
}

/// <summary>
/// Triggers the Intellisense popup to appear when "+" or "@" is pressed in the text box.
/// Triggers the Intellisense popup to appear when "+", "@" or "(" is pressed in the text box.
/// </summary>
/// <param name="sender">Not used</param>
/// <param name="e">Event arguments</param>
Expand All @@ -259,12 +263,17 @@ private void IntellisenseTextBox_TextChanged(object sender, TextChangedEventArgs
{
return;
}

if (this.TaskList == null)
{
return;
}

CheckKeyAndShowPopup();
}

public void CheckKeyAndShowPopup()
{
var lastAddedCharacter = this.Text.Substring(this.CaretIndex - 1, 1);
switch (lastAddedCharacter)
{
Expand All @@ -277,6 +286,14 @@ private void IntellisenseTextBox_TextChanged(object sender, TextChangedEventArgs
this.IntelliPos = this.CaretIndex - 1;
ShowIntellisensePopup(this.TaskList.Contexts, this.GetRectFromCharacterIndex(this.IntelliPos));
break;
case "(":
if (this.CaretIndex == 1 ||
(this.CaretIndex == 12 && StartDateWithPriorityRegex.IsMatch(this.Text.Substring(0, 12))))
{
this.IntelliPos = this.CaretIndex - 1;
ShowIntellisensePopup(Priorities, this.GetRectFromCharacterIndex(this.IntelliPos));
}
break;
}
}

Expand Down
4 changes: 4 additions & 0 deletions Client/Controls/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
xmlns:local="clr-namespace:Client"
xmlns:convertors="clr-namespace:Client.Converters"
Loaded="Window_Loaded"
Closing="Window_Closing"
Title="todotxt.net"
mc:Ignorable="d"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
Expand All @@ -31,6 +32,7 @@
<RoutedUICommand x:Key="EmulateDownArrow" Text="Down" />
<!-- Task menu commands -->
<RoutedUICommand x:Key="NewTask" Text="New Task" />
<RoutedUICommand x:Key="NewTaskWithPriority" Text="New Task with Priority" />
<RoutedUICommand x:Key="UpdateTask" Text="Update Task" />
<RoutedUICommand x:Key="DeleteTask" Text="Delete Task" />
<RoutedUICommand x:Key="AppendText" Text="Append Text" />
Expand Down Expand Up @@ -125,6 +127,7 @@
<CommandBinding Command="{StaticResource CopySelectedTaskToNewTask}" CanExecute="WhenSingleTaskSelectedCanExecute" Executed="CopySelectedTaskToNewTaskExecuted"/>
<!-- Task menu commands -->
<CommandBinding Command="{StaticResource NewTask}" CanExecute="AlwaysCanExecute" Executed="NewTaskExecuted"/>
<CommandBinding Command="{StaticResource NewTaskWithPriority}" CanExecute="AlwaysCanExecute" Executed="NewTaskWithPriorityExecuted"/>
<CommandBinding Command="{StaticResource UpdateTask}" CanExecute="WhenSingleTaskSelectedCanExecute" Executed="UpdateTaskExecuted"/>
<CommandBinding Command="{StaticResource AppendText}" CanExecute="WhenTasksSelectedCanExecute" Executed="AppendTextExecuted"/>
<CommandBinding Command="{StaticResource DeleteTask}" CanExecute="WhenTasksSelectedCanExecute" Executed="DeleteTaskExecuted"/>
Expand Down Expand Up @@ -321,6 +324,7 @@
<KeyBinding Command="{StaticResource EmulateDownArrow}" Key="J" />
<!-- Task menu commands -->
<KeyBinding Command="{StaticResource NewTask}" Key="N" />
<KeyBinding Command="{StaticResource NewTaskWithPriority}" Key="D9" Modifiers="Shift" />
<KeyBinding Command="{StaticResource PrintFile}" Key="P" />
<KeyBinding Command="{StaticResource UpdateTask}" Key="U" />
<KeyBinding Command="{StaticResource UpdateTask}" Key="F2" />
Expand Down
21 changes: 21 additions & 0 deletions Client/Controls/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Reflection;
using System.Windows;
Expand Down Expand Up @@ -135,6 +137,20 @@ private void Window_Loaded(object sender, RoutedEventArgs e)
DataContext = ViewModel;
}

private void Window_Closing(object sender, CancelEventArgs e)
{
if (Application.Current.ShutdownMode == ShutdownMode.OnExplicitShutdown)
{
return;
}

if (User.Default.MinimiseToSystemTray && User.Default.MinimiseOnClose)
{
e.Cancel = true;
WindowState = WindowState.Minimized;
}
}

#region window location handlers
private void Window_LocationChanged(object sender, EventArgs e)
{
Expand Down Expand Up @@ -290,6 +306,11 @@ private void NewTaskExecuted(object sender, RoutedEventArgs e)
ViewModel.AddNewTask();
}

private void NewTaskWithPriorityExecuted(object sender, RoutedEventArgs e)
{
ViewModel.AddNewTaskWithPriority();
}

private void UpdateTaskExecuted(object sender, RoutedEventArgs e)
{
ViewModel.UpdateTask();
Expand Down
1 change: 1 addition & 0 deletions Client/Controls/Options.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
<CheckBox Content="Filter text is case-sensitive" x:Name="cbCaseSensitiveFilter" />
<CheckBox Content="Intellisense project and context suggestions are case-sensitive" x:Name="cbIntellisenseCaseSensitive" />
<CheckBox Content="Minimise to system tray (requires restart)" x:Name="cbMinToSysTray" />
<CheckBox Content="Minimise to system tray on close" x:Name="cbMinOnClose" IsEnabled="{Binding ElementName=cbMinToSysTray, Path=IsChecked}" />
<CheckBox Content="Enable debug logging" x:Name="cbDebugOn" />
<CheckBox Content="Use Ctrl-Enter to create new task" x:Name="cbRequireCtrlEnter" />
<CheckBox Content="Allow grouping of tasks" x:Name="cbAllowGrouping" />
Expand Down
1 change: 1 addition & 0 deletions Client/Controls/Options.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public Options(FontInfo taskFont)
cbAddCreationDate.IsChecked = User.Default.AddCreationDate;
cbDebugOn.IsChecked = User.Default.DebugLoggingOn;
cbMinToSysTray.IsChecked = User.Default.MinimiseToSystemTray;
cbMinOnClose.IsChecked = User.Default.MinimiseOnClose;
cbRequireCtrlEnter.IsChecked = User.Default.RequireCtrlEnter;
cbAllowGrouping.IsChecked = User.Default.AllowGrouping;
cbMoveFocusToTaskListAfterAddingNewTask.IsChecked = User.Default.MoveFocusToTaskListAfterAddingNewTask;
Expand Down
75 changes: 45 additions & 30 deletions Client/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using System.Text.RegularExpressions;
using System.Globalization;
using Microsoft.Win32;
using System.Windows.Threading;

namespace Client
{
Expand Down Expand Up @@ -594,65 +595,70 @@ public static IEnumerable<Task> FilterList(IEnumerable<Task> tasks)
{
foreach (
var filter in
filters.Split(new string[] {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries))
filters.Split(new string[] {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries))
{
if (filter.Equals("due:today", StringComparison.OrdinalIgnoreCase)
&& task.DueDate == DateTime.Now.ToString("yyyy-MM-dd"))
continue;
else if (filter.Equals("due:future", StringComparison.OrdinalIgnoreCase)
&& task.DueDate.IsDateGreaterThan(DateTime.Now))
if (filter.Equals("due:future", StringComparison.OrdinalIgnoreCase)
&& task.DueDate.IsDateGreaterThan(DateTime.Now))
continue;
else if (filter.Equals("due:past", StringComparison.OrdinalIgnoreCase)
&& task.DueDate.IsDateLessThan(DateTime.Now))
if (filter.Equals("due:past", StringComparison.OrdinalIgnoreCase)
&& task.DueDate.IsDateLessThan(DateTime.Now))
continue;
else if (filter.Equals("due:active", StringComparison.OrdinalIgnoreCase)
&& !task.DueDate.IsNullOrEmpty()
&& !task.DueDate.IsDateGreaterThan(DateTime.Now))
if (filter.Equals("due:active", StringComparison.OrdinalIgnoreCase)
&& !task.DueDate.IsNullOrEmpty()
&& !task.DueDate.IsDateGreaterThan(DateTime.Now))
continue;
else if (filter.Equals("-due:today", StringComparison.OrdinalIgnoreCase)
&& task.DueDate == DateTime.Now.ToString("yyyy-MM-dd"))
if (filter.Equals("-due:today", StringComparison.OrdinalIgnoreCase)
&& task.DueDate == DateTime.Now.ToString("yyyy-MM-dd"))
{
include = false;
continue;
}
else if (filter.Equals("-due:future", StringComparison.OrdinalIgnoreCase)
&& task.DueDate.IsDateGreaterThan(DateTime.Now))
if (filter.Equals("-due:future", StringComparison.OrdinalIgnoreCase)
&& task.DueDate.IsDateGreaterThan(DateTime.Now))
{
include = false;
continue;
}
else if (filter.Equals("-due:past", StringComparison.OrdinalIgnoreCase)
&& task.DueDate.IsDateLessThan(DateTime.Now))
if (filter.Equals("-due:past", StringComparison.OrdinalIgnoreCase)
&& task.DueDate.IsDateLessThan(DateTime.Now))
{
include = false;
continue;
}
else if (filter.Equals("-due:active", StringComparison.OrdinalIgnoreCase)
&& !task.DueDate.IsNullOrEmpty()
&& !task.DueDate.IsDateGreaterThan(DateTime.Now))
if (filter.Equals("-due:active", StringComparison.OrdinalIgnoreCase)
&& !task.DueDate.IsNullOrEmpty()
&& !task.DueDate.IsDateGreaterThan(DateTime.Now))
{
include = false;
continue;
}
else if (filter.Equals("-DONE", StringComparison.Ordinal) && task.Completed)

// "DONE" filter is different from "due" filter in that
// "due" is part of todotxt syntax and would very unlikely occur in task text
// while the word "done" can occur in the text
if (filter.Equals("-DONE", StringComparison.Ordinal))
{
include = false;
continue;
if (task.Completed) include = false;
}
else if (filter.Equals("DONE", StringComparison.Ordinal) && !task.Completed)
else if (filter.Equals("DONE", StringComparison.Ordinal))
{
include = false;
continue;
if (!task.Completed) include = false;
}

if (filter.Substring(0, 1) == "-")
// so if the filter is "DONE" or "-DONE", pass the substring test
else
{
if (task.Raw.Contains(filter.Substring(1), comparer))
if (filter.Substring(0, 1) == "-")
{
if (task.Raw.Contains(filter.Substring(1), comparer))
include = false;
}
else if (!task.Raw.Contains(filter, comparer))
{
include = false;
}
else if (!task.Raw.Contains(filter, comparer))
{
include = false;
}
}
}
}
Expand Down Expand Up @@ -979,6 +985,14 @@ public void AddNewTask()
_window.taskText.Focus();
}

public void AddNewTaskWithPriority()
{
AddNewTask();
_window.taskText.Text = _window.taskText.Text.Length > 0 ? $"( {_window.taskText.Text}" : "(";
_window.taskText.CaretIndex = 1;
Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>_window.taskText.CheckKeyAndShowPopup()));
}

public void UpdateTask()
{
// Abort if no task, or more than one task, is selected.
Expand Down Expand Up @@ -1585,6 +1599,7 @@ public void ShowOptionsDialog()
User.Default.AddCreationDate = o.cbAddCreationDate.IsChecked.Value;
User.Default.DebugLoggingOn = o.cbDebugOn.IsChecked.Value;
User.Default.MinimiseToSystemTray = o.cbMinToSysTray.IsChecked.Value;
User.Default.MinimiseOnClose = o.cbMinOnClose.IsChecked.Value;
User.Default.RequireCtrlEnter = o.cbRequireCtrlEnter.IsChecked.Value;
User.Default.AllowGrouping = o.cbAllowGrouping.IsChecked.Value;
User.Default.PreserveWhiteSpace = o.cbPreserveWhiteSpace.IsChecked.Value;
Expand Down
Loading

0 comments on commit d30d16f

Please sign in to comment.