[tasque/viewmodel: 74/78] WiP
- From: Antonius Riha <antoniusri src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tasque/viewmodel: 74/78] WiP
- Date: Wed, 29 Aug 2012 18:40:52 +0000 (UTC)
commit 8cdc4f45bdd12bab0e31338c2a8dccf5a8e5622c
Author: Antonius Riha <antoniusriha gmail com>
Date: Mon Aug 13 12:47:49 2012 +0200
WiP
src/Tasque.Gtk/TaskTreeView.cs | 1 +
src/libtasqueui/Legacy/AboutDialogModel.cs | 2 +-
src/libtasqueui/Legacy/CompletedTaskGroupModel.cs | 4 +-
src/libtasqueui/Legacy/DueDateOptionsModel.cs | 81 +++-------
src/libtasqueui/Legacy/MainWindowModel.cs | 11 +-
src/libtasqueui/Legacy/MainWindowTopPanelModel.cs | 91 ++++++++---
src/libtasqueui/Legacy/NativeApplication.cs | 175 +++++++-------------
src/libtasqueui/Legacy/TaskContextMenuModel.cs | 24 ++--
src/libtasqueui/Legacy/TaskGroupModel.cs | 5 +-
.../{ => Legacy}/TaskGroupModelFactory.cs | 2 +-
src/libtasqueui/Legacy/TaskModel.cs | 31 +++-
src/libtasqueui/Legacy/TrayModel.cs | 10 +-
src/libtasqueui/Legacy/ViewModelRoot.cs | 88 ++++++++++
src/libtasqueui/OptionsModel.cs | 113 +++++++++++++
src/libtasqueui/Point.cs | 10 +-
src/libtasqueui/ViewModel.cs | 2 +-
src/libtasqueui/libtasqueui.csproj | 10 +-
17 files changed, 420 insertions(+), 240 deletions(-)
---
diff --git a/src/Tasque.Gtk/TaskTreeView.cs b/src/Tasque.Gtk/TaskTreeView.cs
index fac72b7..4396b09 100644
--- a/src/Tasque.Gtk/TaskTreeView.cs
+++ b/src/Tasque.Gtk/TaskTreeView.cs
@@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using Gtk;
using Mono.Unix;
+using System.Diagnostics;
namespace Tasque
{
diff --git a/src/libtasqueui/Legacy/AboutDialogModel.cs b/src/libtasqueui/Legacy/AboutDialogModel.cs
index 6b2bfdc..79103cb 100644
--- a/src/libtasqueui/Legacy/AboutDialogModel.cs
+++ b/src/libtasqueui/Legacy/AboutDialogModel.cs
@@ -50,7 +50,7 @@ namespace Tasque.UIModel.Legacy
public string WebsiteUrl { get { return GlobalDefines.Website; } }
- public ReadOnlyCollection<string> Translators {
+ public string Translators {
get {
var translators = Catalog.GetString ("translator-credits");
if (translators == "translator-credits")
diff --git a/src/libtasqueui/Legacy/CompletedTaskGroupModel.cs b/src/libtasqueui/Legacy/CompletedTaskGroupModel.cs
index 88b8cb3..91e1b71 100644
--- a/src/libtasqueui/Legacy/CompletedTaskGroupModel.cs
+++ b/src/libtasqueui/Legacy/CompletedTaskGroupModel.cs
@@ -32,8 +32,8 @@ namespace Tasque.UIModel.Legacy
{
public class CompletedTaskGroupModel : TaskGroupModel, IValueConverter<CompletionDateRange, string>
{
- public CompletedTaskGroupModel (ReadOnlyObservableCollection<Task> tasks,
- Preferences preferences) : base (TaskGroupName.Completed, tasks)
+ public CompletedTaskGroupModel (ReadOnlyObservableCollection<object> tasks,
+ Preferences preferences, ViewModel parent) : base (TaskGroupName.Completed, tasks, parent)
{
if (preferences == null)
throw new ArgumentNullException ("preferences");
diff --git a/src/libtasqueui/Legacy/DueDateOptionsModel.cs b/src/libtasqueui/Legacy/DueDateOptionsModel.cs
index d372f57..45ae7c7 100644
--- a/src/libtasqueui/Legacy/DueDateOptionsModel.cs
+++ b/src/libtasqueui/Legacy/DueDateOptionsModel.cs
@@ -24,20 +24,14 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
-using System.Collections;
-using System.Collections.Generic;
using Mono.Unix;
-using CrossCommand.Generic;
namespace Tasque.UIModel.Legacy
{
- public class DueDateOptionsModel : ViewModel, IEnumerable<string>, ITimeAware
+ public class DueDateOptionsModel : OptionsModel<DateTime>, ITimeAware
{
internal DueDateOptionsModel (ViewModel parent) : base (parent)
{
- options = new Option [10];
- options [8] = new Option (Catalog.GetString ("No Date"), DateTime.MinValue);
- options [9] = new Option (Catalog.GetString ("Choose Date..."), CustomDate);
UpdateDateOptions ();
}
@@ -51,47 +45,17 @@ namespace Tasque.UIModel.Legacy
}
}
- public ICommand<Option> SelectOption {
- get {
- if (selectOption == null) {
- selectOption = new RelayCommand<Option> () {
- CanExecuteAction = (option) => {
- return option != options [9] || customDate != DateTime.MinValue;
- },
- ExecuteAction = (option) => {
- SelectedOption = option;
- if (OptionSelected != null)
- OptionSelected (this, EventArgs.Empty);
- Close.Execute (null);
- }
- };
- }
- return selectOption;
- }
- }
-
- public IEnumerator<string> GetEnumerator ()
+ protected override bool CanExecuteSelectOption (OptionItem parameter)
{
- foreach (var item in options)
- yield return item;
- }
-
- IEnumerator IEnumerable.GetEnumerator ()
- {
- return GetEnumerator ();
+ return parameter != parameter [9] || customDate != DateTime.MinValue;
}
protected override void OnClose ()
{
customDate = DateTime.MinValue;
- SelectedOption = null;
base.OnClose ();
}
- internal Option SelectedOption { get; private set; }
-
- internal event EventHandler OptionSelected;
-
void ITimeAware.OnDayChanged ()
{
UpdateDateOptions ();
@@ -99,39 +63,42 @@ namespace Tasque.UIModel.Legacy
void UpdateDateOptions ()
{
- var today = DateTime.Today;
- options [0] = new Option (today.ToString (Catalog.GetString ("M/d - "))
- + Catalog.GetString ("Today"), today);
+ ProtectedOptions.Clear ();
- var tomorrow = today.AddDays (1);
- options [1] = new Option (tomorrow.ToString (Catalog.GetString ("M/d - "))
- + Catalog.GetString ("Tomorrow"), tomorrow);
+ var today = DateTime.Today;
+ ProtectedOptions.Add (today, new DueDateOption (today.ToString (
+ Catalog.GetString ("M/d - ")) + Catalog.GetString ("Today")));
- var nextWeek = today.AddDays (7);
- options [7] = new Option (nextWeek.ToString (Catalog.GetString ("M/d - "))
- + Catalog.GetString ("In 1 Week"), nextWeek);
+ var tomorrow = today.AddDays (1);
+ ProtectedOptions.Add (tomorrow, new DueDateOption (
+ tomorrow.ToString (Catalog.GetString ("M/d - ")) + Catalog.GetString ("Tomorrow")));
for (int i = 2; i < 7; i++) {
var date = today.AddDays (i);
- options [i] = new Option (date.ToString (Catalog.GetString ("M/d - ddd")), date);
+ ProtectedOptions.Add (date, new DueDateOption (date.ToString (
+ Catalog.GetString ("M/d - ddd"))));
}
+
+ var nextWeek = today.AddDays (7);
+ ProtectedOptions.Add (new DueDateOption (nextWeek, nextWeek.ToString (
+ Catalog.GetString ("M/d - ")) + Catalog.GetString ("In 1 Week")));
+
+ ProtectedOptions.Add (new DueDateOption (DateTime.MinValue, Catalog.GetString ("No Date")));
+ ProtectedOptions.Add (new DueDateOption (customDate, Catalog.GetString ("Choose Date...")));
}
DateTime customDate;
- Option [] options;
- RelayCommand<Option> selectOption;
- public class Option
+ public class DueDateOption : OptionItem
{
- internal Option (string text, DateTime date)
+ internal DueDateOption (DateTime date, string text) : base (date, null)
{
- Text = text;
- Date = date;
+ this.text = text;
}
- internal DateTime Date { get; private set; }
+ public override string Text { get { return text; } }
- public string Text { get; private set; }
+ string text;
}
}
}
diff --git a/src/libtasqueui/Legacy/MainWindowModel.cs b/src/libtasqueui/Legacy/MainWindowModel.cs
index dccc02a..faea302 100644
--- a/src/libtasqueui/Legacy/MainWindowModel.cs
+++ b/src/libtasqueui/Legacy/MainWindowModel.cs
@@ -33,13 +33,16 @@ namespace Tasque.UIModel.Legacy
{
public class MainWindowModel : ViewModel, ITimeAware
{
- internal MainWindowModel (Preferences preferences)
+ internal MainWindowModel (Preferences preferences, ViewModel parent) : base (parent)
{
if (preferences == null)
throw new ArgumentNullException ("preferences");
// register objects in object service
AddObjectToObjectService (new DueDateOptionsModel (this));
+ AddObjectToObjectService (new OptionsModel<TaskPriority> (new TaskPriority [] {
+ TaskPriority.High, TaskPriority.Medium, TaskPriority.Low, TaskPriority.None
+ }, null, this));
UpdateCompletionDateRangeCompareDates ();
@@ -54,7 +57,7 @@ namespace Tasque.UIModel.Legacy
Tasks.CustomSort = new TaskComparer ();
}
- topPanel = new MainWindowTopPanelModel (this);
+ topPanel = new MainWindowTopPanelModel (this, this);
}
public ReadOnlyObservableCollection<TaskGroupModel> Groups {
@@ -174,9 +177,9 @@ namespace Tasque.UIModel.Legacy
TaskGroupModel groupModel;
var groupName = (TaskGroupName)group.Name;
if (groupName == TaskGroupName.Completed)
- groupModel = new CompletedTaskGroupModel (group.Items, Preferences);
+ groupModel = new CompletedTaskGroupModel (group.Items, Preferences, this);
else
- groupModel = new TaskGroupModel (groupName, group.Items);
+ groupModel = new TaskGroupModel (groupName, group.Items, this);
return groupModel;
}
diff --git a/src/libtasqueui/Legacy/MainWindowTopPanelModel.cs b/src/libtasqueui/Legacy/MainWindowTopPanelModel.cs
index 42744d2..77753e1 100644
--- a/src/libtasqueui/Legacy/MainWindowTopPanelModel.cs
+++ b/src/libtasqueui/Legacy/MainWindowTopPanelModel.cs
@@ -25,22 +25,25 @@
// THE SOFTWARE.
using System.Linq;
using CollectionTransforms;
+using CrossCommand;
+using System.Collections.ObjectModel;
+using System;
+using CrossCommand.Generic;
namespace Tasque.UIModel.Legacy
{
public class MainWindowTopPanelModel : ViewModel
{
- internal MainWindowTopPanelModel (MainWindowModel mainWindowModel)
+ internal MainWindowTopPanelModel (MainWindowModel mainWindowModel, ViewModel parent)
+ : base (parent)
{
tasks = mainWindowModel.Tasks;
- Categories = new ReadOnlyObservableSet<Category> (mainWindowModel.Backend.Categories);
+// Categories = new ReadOnlyObservableSet<Category> (mainWindowModel.Backend.Categories);
preferences = mainWindowModel.Preferences;
- selectedCategory = GetSelectedCategory ();
+// selectedCategory = GetSelectedCategory ();
preferences.SettingChanged += HandleSettingChanged;
-
- addTaskCommand = new AddTaskCommand (mainWindowModel.Backend);
}
void HandleSettingChanged (Preferences preferences, string settingKey)
@@ -54,49 +57,87 @@ namespace Tasque.UIModel.Legacy
}
}
- public ReadOnlyObservableSet<Category> Categories { get; private set; }
+ #region Categories
+ public OptionsModel<Category> Categories { get; private set; }
public Category SelectedCategory {
get { return selectedCategory; }
- set {
+ private set {
if (value != selectedCategory)
preferences.Set (Preferences.SelectedCategoryKey, value.Name);
}
}
- public ICommand AddTask { get { return addTaskCommand; } }
+ public ICommand ShowCategories {
+ get {
+ return showCategories ?? (showCategories = new RelayCommand () {
+ ExecuteAction = delegate {
+ var cats = new Category [categories.Count + 1];
+ cats [0] = null; // All category
+ categories.CopyTo (cats, 1); // other categories
+ Categories = new OptionsModel<Category> (cats, null, this);
+ Categories.OptionSelected += delegate {
+ SelectedCategory = Categories.SelectedOption.Value;
+ };
+ }
+ });
+ }
+ }
+ #endregion
- public string NewTaskName {
- get { return addTaskCommand.TaskName; }
- set {
- if (value != addTaskCommand.TaskName) {
- addTaskCommand.TaskName = value;
- OnPropertyChanged ("NewTaskName");
- }
+ #region Add task
+ public ICommand AddTask {
+ get {
+ return addTask ?? (addTask = new RelayCommand () {
+ CanExecuteAction = delegate {
+ return false;
+ }
+ });
}
}
- public Category NewTaskCategory {
- get { return addTaskCommand.Category; }
- set {
- if (value != addTaskCommand.Category) {
- addTaskCommand.Category = value;
- OnPropertyChanged ("NewTaskCategory");
- }
+
+
+ public ICommand<Category> AddTaskToCategory {
+ get {
+ throw new NotImplementedException ();
}
}
- void GetSelectedCategory ()
+// public string NewTaskName {
+// get { return addTaskCommand.TaskName; }
+// set {
+// if (value != addTaskCommand.TaskName) {
+// addTaskCommand.TaskName = value;
+// OnPropertyChanged ("NewTaskName");
+// }
+// }
+// }
+
+// public Category NewTaskCategory {
+// get { return addTaskCommand.Category; }
+// set {
+// if (value != addTaskCommand.Category) {
+// addTaskCommand.Category = value;
+// OnPropertyChanged ("NewTaskCategory");
+// }
+// }
+// }
+ #endregion
+
+ Category GetSelectedCategory ()
{
var selectedCategoryName = preferences.Get (Preferences.SelectedCategoryKey);
- return Categories.SingleOrDefault (c => c.Name == selectedCategoryName);
+ return categories.SingleOrDefault (c => c.Name == selectedCategoryName);
}
Preferences preferences;
ListCollectionView<Task> tasks;
- AddTaskCommand addTaskCommand;
+ RelayCommand addTask;
Category selectedCategory;
+ ReadOnlyObservableCollection<Category> categories;
+ RelayCommand showCategories;
}
}
diff --git a/src/libtasqueui/Legacy/NativeApplication.cs b/src/libtasqueui/Legacy/NativeApplication.cs
index d0da541..3cb6954 100644
--- a/src/libtasqueui/Legacy/NativeApplication.cs
+++ b/src/libtasqueui/Legacy/NativeApplication.cs
@@ -54,62 +54,10 @@ namespace Tasque.UIModel.Legacy
public Backend CurrentBackend { get; private set; }
- public ReadOnlyCollection<Backend> AvailableBackends { get; }
+ public ReadOnlyCollection<Backend> AvailableBackends { get; private set; }
protected string ConfDir { get; private set; }
- public MainWindowModel MainWindowModel {
- get { return mainWindowModel; }
- private set {
- if (value != mainWindowModel) {
- mainWindowModel = value;
- OnPropertyChanged ("MainWindowModel");
- }
- }
- }
- MainWindowModel mainWindowModel;
-
- public RelayCommand ShowMainWindow {
- get { return showMainWindow ?? (showMainWindow = new RelayCommand ()); }
- }
-
- public PreferencesDialogModel PreferencesDialogModel {
- get { return preferencesDialogModel; }
- private set {
- if (value != preferencesDialogModel) {
- preferencesDialogModel = value;
- OnPropertyChanged ("PreferencesDialogModel");
- }
- }
- }
- PreferencesDialogModel preferencesDialogModel;
-
- public RelayCommand ShowPreferencesDialog {
- get { return showPreferencesDialog ?? (showPreferencesDialog = new RelayCommand ()); }
- }
-
- public AboutDialogModel AboutDialogModel { get; private set; }
-
- public ICommand ShowAboutDialog {
- get {
- if (showAboutDialog == null) {
- showAboutDialog = new RelayCommand () {
- ExecuteAction = delegate {
- if (AboutDialogModel == null)
- AboutDialogModel = new AboutDialogModel ("tasque-24", viewModelRoot);
- OnPropertyChanged ("AboutDialogModel");
- }
- };
- }
-
- return showAboutDialog;
- }
- }
-
- RelayCommand showAboutDialog;
-
- RelayCommand showPreferencesDialog;
-
public void Exit (int exitcode)
{
OnExit (exitcode);
@@ -127,10 +75,10 @@ namespace Tasque.UIModel.Legacy
Exit (0);
}
- RemoteInstanceKnocked += delegate {
- if (MainWindowModel != null && MainWindowModel.Show.CanExecute)
- MainWindowModel.Show.Execute ();
- };
+// RemoteInstanceKnocked += delegate {
+// if (MainWindowModel != null && MainWindowModel.Show.CanExecute)
+// MainWindowModel.Show.Execute ();
+// };
preferences = new Preferences (ConfDir);
@@ -160,22 +108,22 @@ namespace Tasque.UIModel.Legacy
CurrentBackend = availableBackends [backendTypeString];
}
- SetupTray (new TrayModel ());
-
- if (CurrentBackend == null) {
- // Pop open the preferences dialog so the user can choose a
- // backend service to use.
- Application.ShowPreferences ();
- } else if (!quietStart) {
- TaskWindow.ShowWindow ();
- }
- if (backend == null || !backend.Configured){
- GLib.Timeout.Add(1000, new GLib.TimeoutHandler(RetryBackend));
- }
-
- nativeApp.InitializeIdle ();
+// SetupTray (new TrayModel ());
+//
+// if (CurrentBackend == null) {
+// // Pop open the preferences dialog so the user can choose a
+// // backend service to use.
+// Application.ShowPreferences ();
+// } else if (!quietStart) {
+// TaskWindow.ShowWindow ();
+// }
+// if (backend == null || !backend.Configured){
+// GLib.Timeout.Add(1000, new GLib.TimeoutHandler(RetryBackend));
+// }
+//
+// nativeApp.InitializeIdle ();
- return false;
+// return false;
}
protected abstract void SetupTray (TrayModel trayModel);
@@ -283,7 +231,7 @@ namespace Tasque.UIModel.Legacy
foreach (var type in types) {
if (!type.IsClass)
continue; // Skip non-class types
- if (type.GetType ("Tasque.Backend") == null)
+ if (Type.GetType ("Tasque.Backend") == null)
continue;
Debug.WriteLine ("Found Available Backend: {0}", type.ToString ());
@@ -305,7 +253,7 @@ namespace Tasque.UIModel.Legacy
void ParseArgs (string[] args)
{
- bool showHelp;
+ bool showHelp = false;
var p = new OptionSet () {
{ "q|quiet", "hide the Tasque window upon start.", v => quietStart = true },
{ "b|backend=", "the name of the {BACKEND} to use.", v => potentialBackendClassName = v },
@@ -334,44 +282,44 @@ namespace Tasque.UIModel.Legacy
void SetBackend (Backend value)
{
bool changingBackend = false;
- if (this.backend != null) {
- UnhookFromTooltipTaskGroupModels ();
- changingBackend = true;
- // Cleanup the old backend
- try {
- Debug.WriteLine ("Cleaning up backend: {0}",
- this.backend.Name);
- this.backend.Cleanup ();
- } catch (Exception e) {
- Trace.TraceWarning ("Exception cleaning up '{0}': {1}",
- this.backend.Name,
- e);
- }
- }
+// if (this.backend != null) {
+// UnhookFromTooltipTaskGroupModels ();
+// changingBackend = true;
+// // Cleanup the old backend
+// try {
+// Debug.WriteLine ("Cleaning up backend: {0}",
+// this.backend.Name);
+// this.backend.Cleanup ();
+// } catch (Exception e) {
+// Trace.TraceWarning ("Exception cleaning up '{0}': {1}",
+// this.backend.Name,
+// e);
+// }
+// }
// Initialize the new backend
- this.backend = value;
- if (this.backend == null) {
- RefreshTrayIconTooltip ();
- return;
- }
-
- Trace.TraceInformation ("Using backend: {0} ({1})",
- this.backend.Name,
- this.backend.GetType ().ToString ());
- this.backend.Initialize();
-
- if (!changingBackend) {
- TaskWindow.Reinitialize (!this.quietStart);
- } else {
- TaskWindow.Reinitialize (true);
- }
-
- RebuildTooltipTaskGroupModels ();
- RefreshTrayIconTooltip ();
-
- Debug.WriteLine("Configuration status: {0}",
- this.backend.Configured.ToString());
+// this.backend = value;
+// if (this.backend == null) {
+// RefreshTrayIconTooltip ();
+// return;
+// }
+//
+// Trace.TraceInformation ("Using backend: {0} ({1})",
+// this.backend.Name,
+// this.backend.GetType ().ToString ());
+// this.backend.Initialize();
+//
+// if (!changingBackend) {
+// TaskWindow.Reinitialize (!this.quietStart);
+// } else {
+// TaskWindow.Reinitialize (true);
+// }
+//
+// RebuildTooltipTaskGroupModels ();
+// RefreshTrayIconTooltip ();
+//
+// Debug.WriteLine("Configuration status: {0}",
+// this.backend.Configured.ToString());
}
void SetCustomBackend ()
@@ -400,13 +348,6 @@ namespace Tasque.UIModel.Legacy
TrayModel tray;
- RelayCommand showMainWindow;
-
ViewModelRoot viewModelRoot;
-
- class ViewModelRoot : ViewModel
- {
- internal ViewModelRoot () : base (null) {}
- }
}
}
diff --git a/src/libtasqueui/Legacy/TaskContextMenuModel.cs b/src/libtasqueui/Legacy/TaskContextMenuModel.cs
index 3ef09a1..dd631c1 100644
--- a/src/libtasqueui/Legacy/TaskContextMenuModel.cs
+++ b/src/libtasqueui/Legacy/TaskContextMenuModel.cs
@@ -29,22 +29,22 @@ namespace Tasque.UIModel.Legacy
{
public class TaskContextMenuModel : ViewModel
{
- public TaskContextMenuModel (MainWindowModel mainWindowModel)
+ public TaskContextMenuModel (MainWindowModel mainWindowModel, ViewModel parent) : base (parent)
{
- removeTaskCommand = new RemoveTaskCommand (Backend);
+// removeTaskCommand = new RemoveTaskCommand (Backend);
}
- public ICommand EditTask { get; private set; }
+// public ICommand EditTask { get; private set; }
+//
+// public ICommand RemoveTask { get { return removeTaskCommand; } }
- public ICommand RemoveTask { get { return removeTaskCommand; } }
+// public void Show (Task selectedTask)
+// {
+// if (selectedTask == null)
+// throw new ArgumentNullException ("selectedTask");
+// removeTaskCommand.Task = selectedTask;
+// }
- public void Show (Task selectedTask)
- {
- if (selectedTask == null)
- throw new ArgumentNullException ("selectedTask");
- removeTaskCommand.Task = selectedTask;
- }
-
- RemoveTaskCommand removeTaskCommand;
+// RemoveTaskCommand removeTaskCommand;
}
}
diff --git a/src/libtasqueui/Legacy/TaskGroupModel.cs b/src/libtasqueui/Legacy/TaskGroupModel.cs
index 3f0a60a..1d7b940 100644
--- a/src/libtasqueui/Legacy/TaskGroupModel.cs
+++ b/src/libtasqueui/Legacy/TaskGroupModel.cs
@@ -30,7 +30,8 @@ namespace Tasque.UIModel.Legacy
{
public class TaskGroupModel : ViewModel
{
- public TaskGroupModel (TaskGroupName groupName, ReadOnlyObservableCollection<Task> tasks)
+ public TaskGroupModel (TaskGroupName groupName, ReadOnlyObservableCollection<object> tasks,
+ ViewModel parent) : base (parent)
{
if (tasks == null)
throw new ArgumentNullException ("tasks");
@@ -40,7 +41,7 @@ namespace Tasque.UIModel.Legacy
Title = taskGroupNameConverter.Convert (groupName, null, null);
}
- public ReadOnlyObservableCollection<Task> Tasks { get; private set; }
+ public ReadOnlyObservableCollection<object> Tasks { get; private set; }
public string Title { get; private set; }
}
diff --git a/src/libtasqueui/TaskGroupModelFactory.cs b/src/libtasqueui/Legacy/TaskGroupModelFactory.cs
similarity index 98%
rename from src/libtasqueui/TaskGroupModelFactory.cs
rename to src/libtasqueui/Legacy/TaskGroupModelFactory.cs
index f99f3ba..9bd328c 100644
--- a/src/libtasqueui/TaskGroupModelFactory.cs
+++ b/src/libtasqueui/Legacy/TaskGroupModelFactory.cs
@@ -26,7 +26,7 @@
using System;
using System.Collections.Generic;
-namespace Tasque
+namespace Tasque.UIModel.Legacy
{
public static class TaskGroupModelFactory
{
diff --git a/src/libtasqueui/Legacy/TaskModel.cs b/src/libtasqueui/Legacy/TaskModel.cs
index b712d41..23b90a5 100644
--- a/src/libtasqueui/Legacy/TaskModel.cs
+++ b/src/libtasqueui/Legacy/TaskModel.cs
@@ -65,7 +65,7 @@ namespace Tasque.UIModel.Legacy
void HandleDueDateOptionSelected (object sender, EventArgs e)
{
DueDateOptions.OptionSelected -= HandleDueDateOptionSelected;
- task.DueDate = DueDateOptions.SelectedOption;
+ task.DueDate = DueDateOptions.SelectedOption.Value;
}
#endregion
@@ -157,7 +157,30 @@ namespace Tasque.UIModel.Legacy
#endregion
#region Priority
- public int Priority { get { return (int)task.Priority; } set { task.Priority = value; } }
+ public OptionsModel<TaskPriority> PriorityOptions { get; private set; }
+
+ public int Priority { get { return (int)task.Priority; } }
+
+ public ICommand ShowPriorityOptions {
+ get {
+ return setPriority ?? (setPriority = new RelayCommand () {
+ CanExecuteAction = delegate { return !task.IsComplete; },
+ ExecuteAction = delegate {
+ var optionsModel = GetObjectFromAncestor (
+ typeof (OptionsModel<TaskPriority>)) as OptionsModel<TaskPriority>;
+ PriorityOptions = optionsModel ?? new OptionsModel<TaskPriority> (this);
+ PriorityOptions.OptionSelected += HandlePriorityOptionSelected;
+ OnPropertyChanged ("PriorityOptions");
+ }
+ });
+ }
+ }
+
+ void HandlePriorityOptionSelected (object sender, EventArgs e)
+ {
+ PriorityOptions.OptionSelected -= HandlePriorityOptionSelected;
+ task.Priority = PriorityOptions.SelectedOption.Value;
+ }
#endregion
void HandleTaskPropertyChanged (object sender, PropertyChangedEventArgs e)
@@ -166,7 +189,9 @@ namespace Tasque.UIModel.Legacy
}
string name;
- RelayCommand toggleIsComplete, saveName, cancelChangeName, showNotesDialog, showDueDateOptions;
+ int priority;
+ RelayCommand toggleIsComplete, saveName, setPriority,
+ cancelChangeName, showNotesDialog, showDueDateOptions;
Task task;
}
}
diff --git a/src/libtasqueui/Legacy/TrayModel.cs b/src/libtasqueui/Legacy/TrayModel.cs
index 3861f74..724ef40 100644
--- a/src/libtasqueui/Legacy/TrayModel.cs
+++ b/src/libtasqueui/Legacy/TrayModel.cs
@@ -30,17 +30,13 @@ namespace Tasque.UIModel.Legacy
{
public class TrayModel : ViewModel
{
- public TrayModel (NativeApplication application)
+ public TrayModel (ViewModel parent) : base (parent)
{
- if (application == null)
- throw new ArgumentNullException ("application");
-
-
}
public string IconName { get { return "tasque"; } }
- public bool IsTaskWindowVisible { get { return application.MainWindowModel.IsVisible; } }
+ public bool IsTaskWindowVisible { get { return false; } }
public ICommand NewTask { get { throw new NotImplementedException (); } }
@@ -53,7 +49,5 @@ namespace Tasque.UIModel.Legacy
public ICommand ShowPreferences { get { throw new NotImplementedException (); } }
public ICommand ToggleTaskWindow { get { throw new NotImplementedException (); } }
-
- NativeApplication application;
}
}
diff --git a/src/libtasqueui/Legacy/ViewModelRoot.cs b/src/libtasqueui/Legacy/ViewModelRoot.cs
new file mode 100644
index 0000000..fe9bdd5
--- /dev/null
+++ b/src/libtasqueui/Legacy/ViewModelRoot.cs
@@ -0,0 +1,88 @@
+//
+// ViewModelRoot.cs
+//
+// Author:
+// Antonius Riha <antoniusriha gmail com>
+//
+// Copyright (c) 2012 Antonius Riha
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+using System;
+using CrossCommand;
+
+namespace Tasque.UIModel.Legacy
+{
+ class ViewModelRoot : ViewModel
+ {
+ internal ViewModelRoot () : base (null)
+ {
+
+ }
+
+
+
+ public MainWindowModel MainWindowModel { get; private set; }
+
+ public RelayCommand ShowMainWindow {
+ get {
+ return showMainWindow ?? (showMainWindow = new RelayCommand () {
+ ExecuteAction = delegate {
+ if (MainWindowModel == null)
+ MainWindowModel = new MainWindowModel (null, this);
+ OnPropertyChanged ("MainWindowModel");
+ }
+ });
+ }
+ }
+
+ public PreferencesDialogModel PreferencesDialogModel { get; private set; }
+
+ public RelayCommand ShowPreferencesDialog {
+ get {
+ return showPreferencesDialog ?? (showPreferencesDialog = new RelayCommand () {
+ ExecuteAction = delegate {
+ if (PreferencesDialogModel == null)
+ PreferencesDialogModel = new PreferencesDialogModel (this);
+ OnPropertyChanged ("PreferencesDialogModel");
+ }
+ });
+ }
+ }
+
+ public AboutDialogModel AboutDialogModel { get; private set; }
+
+ public ICommand ShowAboutDialog {
+ get {
+ return showAboutDialog ?? (showAboutDialog = new RelayCommand () {
+ ExecuteAction = delegate {
+ if (AboutDialogModel == null)
+ AboutDialogModel = new AboutDialogModel ("tasque-24", this);
+ OnPropertyChanged ("AboutDialogModel");
+ }
+ });
+ }
+ }
+
+ internal bool IsMainWindowVisible {
+ get { return MainWindowModel != null || MainWindowModel.IsVisible; }
+ }
+
+ RelayCommand showAboutDialog, showMainWindow, showPreferencesDialog;
+ }
+}
diff --git a/src/libtasqueui/OptionsModel.cs b/src/libtasqueui/OptionsModel.cs
new file mode 100644
index 0000000..d9a3bf8
--- /dev/null
+++ b/src/libtasqueui/OptionsModel.cs
@@ -0,0 +1,113 @@
+//
+// DropDownModel.cs
+//
+// Author:
+// Antonius Riha <antoniusriha gmail com>
+//
+// Copyright (c) 2012 Antonius Riha
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Diagnostics;
+using CrossCommand.Generic;
+
+namespace Tasque.UIModel
+{
+ public class OptionsModel<T> : ViewModel
+ {
+ internal OptionsModel (ViewModel parent) : this (null, parent) {}
+
+ internal OptionsModel (IValueConverter<T, string> converter, ViewModel parent)
+ : this (new OptionItem [] {}, converter, parent) {}
+
+ internal OptionsModel (IEnumerable<T> optionValues, IValueConverter<T, string> converter,
+ ViewModel parent) : base (parent)
+ {
+ Converter = converter;
+
+ ProtectedOptions = new ObservableCollection<OptionItem> ();
+ foreach (var item in optionValues)
+ ProtectedOptions.Add (new OptionItem (item, converter));
+
+ Options = new ReadOnlyObservableCollection<OptionItem> (ProtectedOptions);
+ }
+
+ public IValueConverter<T, string> Converter { get; protected set; }
+
+ public ReadOnlyObservableCollection<OptionItem> Options { get; private set; }
+
+ public OptionItem SelectedOption { get; private set; }
+
+ public ICommand<OptionItem> SelectOption {
+ get {
+ return selectOption ?? (selectOption = new RelayCommand<OptionItem> () {
+ CanExecuteAction = CanExecuteSelectOption,
+ ExecuteAction = ExecuteSelectOption
+ });
+ }
+ }
+
+ public event EventHandler OptionSelected;
+
+ protected ObservableCollection<OptionItem> ProtectedOptions { get; private set; }
+
+ protected virtual bool CanExecuteSelectOption (OptionItem parameter)
+ {
+ return true;
+ }
+
+ protected virtual void ExecuteSelectOption (OptionItem parameter)
+ {
+ SelectedOption = parameter;
+ if (OptionSelected != null)
+ OptionSelected (this, EventArgs.Empty);
+ Close.Execute (null);
+ }
+
+ protected override void OnClose ()
+ {
+ SelectedOption = null;
+ base.OnClose ();
+ }
+
+ RelayCommand<OptionItem> selectOption;
+
+ public class OptionItem
+ {
+ internal OptionItem (T value, IValueConverter<T, string> converter)
+ {
+ if (converter == null)
+ Debug.WriteLine ("DropDownModel: No converter specified. " +
+ "Using ToString() to convert.");
+ Value = value;
+ this.converter = converter;
+ }
+
+ public virtual string Text {
+ get { return converter == null ? Value.ToString () : converter.Convert (Value); }
+ }
+
+ internal T Value { get; private set; }
+
+ IValueConverter<T, string> converter;
+ }
+ }
+}
diff --git a/src/libtasqueui/Point.cs b/src/libtasqueui/Point.cs
index 8057296..50da398 100644
--- a/src/libtasqueui/Point.cs
+++ b/src/libtasqueui/Point.cs
@@ -30,14 +30,16 @@ namespace Tasque.UIModel
{
public Point (int x, int y)
{
- X = x;
- Y = y;
+ this.x = x;
+ this.y = y;
}
public bool IsEmpty { get { return X == 0 && Y == 0; } }
- public int X { get; set; }
+ public int X { get { return x; } }
- public int Y { get; set; }
+ public int Y { get { return y; } }
+
+ int x, y;
}
}
diff --git a/src/libtasqueui/ViewModel.cs b/src/libtasqueui/ViewModel.cs
index 3729379..dff790e 100644
--- a/src/libtasqueui/ViewModel.cs
+++ b/src/libtasqueui/ViewModel.cs
@@ -104,7 +104,7 @@ namespace Tasque.UIModel
protected bool RemoveObjectFromObjectService (object obj)
{
- return obj == null ? false : registeredObjects.Remove (obj);
+ return obj == null ? false : registeredObjects.Remove (obj.GetType ());
}
#endregion
diff --git a/src/libtasqueui/libtasqueui.csproj b/src/libtasqueui/libtasqueui.csproj
index f4f712a..d440d62 100644
--- a/src/libtasqueui/libtasqueui.csproj
+++ b/src/libtasqueui/libtasqueui.csproj
@@ -98,10 +98,7 @@
<Compile Include="Legacy\CompletionDateRange.cs" />
<Compile Include="ITimeAware.cs" />
<Compile Include="Legacy\MainWindowTopPanelModel.cs" />
- <Compile Include="Legacy\Commands\ComponentCommands.cs" />
- <Compile Include="Legacy\Commands\TaskCommands.cs" />
<Compile Include="Legacy\NativeApplication.cs" />
- <Compile Include="TaskGroupModelFactory.cs" />
<Compile Include="Point.cs" />
<Compile Include="Legacy\Preferences.cs" />
<Compile Include="..\Options.cs">
@@ -121,7 +118,10 @@
<Compile Include="ViewModel.cs" />
<Compile Include="Legacy\NotesDialogModel.cs" />
<Compile Include="Legacy\NoteModel.cs" />
+ <Compile Include="Legacy\ViewModelRoot.cs" />
<Compile Include="Legacy\DueDateOptionsModel.cs" />
+ <Compile Include="OptionsModel.cs" />
+ <Compile Include="Legacy\TaskGroupModelFactory.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
@@ -143,4 +143,8 @@
<Name>CrossCommand</Name>
</ProjectReference>
</ItemGroup>
+ <ItemGroup>
+ <None Include="Legacy\Commands\ComponentCommands.cs" />
+ <None Include="Legacy\Commands\TaskCommands.cs" />
+ </ItemGroup>
</Project>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]