[tasque/viewmodel: 32/78] Implemented Show and Hide commands on TaskWindow
- From: Antonius Riha <antoniusri src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tasque/viewmodel: 32/78] Implemented Show and Hide commands on TaskWindow
- Date: Wed, 29 Aug 2012 18:37:21 +0000 (UTC)
commit 7dcf80a3aef28bfd47277b6d80b4edc612577592
Author: Antonius Riha <antoniusriha gmail com>
Date: Mon Jul 30 00:56:10 2012 +0200
Implemented Show and Hide commands on TaskWindow
src/Tasque.Gtk/TaskWindow.cs | 75 +++++++++++++++++++++++++++++
src/libtasqueui/Legacy/MainWindowModel.cs | 9 ++++
src/libtasqueui/Point.cs | 43 ++++++++++++++++
src/libtasqueui/UICommand.cs | 43 ++++++++++++++++-
src/libtasqueui/libtasqueui.csproj | 1 +
5 files changed, 169 insertions(+), 2 deletions(-)
---
diff --git a/src/Tasque.Gtk/TaskWindow.cs b/src/Tasque.Gtk/TaskWindow.cs
index 80a2484..35b006b 100644
--- a/src/Tasque.Gtk/TaskWindow.cs
+++ b/src/Tasque.Gtk/TaskWindow.cs
@@ -37,6 +37,7 @@ using Mono.Unix;
using Tasque;
using CollectionTransforms;
using System.Collections;
+using Tasque.UIModel.Legacy;
namespace Tasque
{
@@ -1283,5 +1284,79 @@ namespace Tasque
fake_menu.Append (foo);
}
+
+ ////////////// ------- New implementation starts below ------- //////////////
+
+ void Ctor (MainWindowModel mainWindowModel)
+ {
+ if (mainWindowModel == null)
+ throw new ArgumentNullException ("mainWindowModel");
+ vm = mainWindowModel;
+ mainWindowModel.Show.SetExecuteAction (ShowWindow, true);
+ mainWindowModel.Hide.SetExecuteAction (HideWindow, true);
+ }
+
+ void ShowWindow ()
+ {
+ if (!Visible) {
+ var position = vm.Position;
+ if (!position.IsEmpty)
+ Move (position.X, position.Y);
+ }
+ Present ();
+ vm.Hide.CanExecute = true;
+ }
+
+ void HideWindow ()
+ {
+ int x, y;
+ GetPosition (out x, out y);
+ vm.Position = new Point (x, y);
+ Hide ();
+ vm.Hide.CanExecute = false;
+ }
+
+// private static void ShowWindow(bool supportToggle)
+// {
+// if(taskWindow != null) {
+// if(taskWindow.IsActive && supportToggle) {
+// int x;
+// int y;
+//
+// taskWindow.GetPosition(out x, out y);
+//
+// lastXPos = x;
+// lastYPos = y;
+//
+// taskWindow.Hide();
+// } else {
+// if(!taskWindow.Visible) {
+// int x = lastXPos;
+// int y = lastYPos;
+//
+// if (x >= 0 && y >= 0)
+// taskWindow.Move(x, y);
+// }
+// taskWindow.Present();
+// }
+// } else if (Application.Backend != null) {
+// TaskWindow.taskWindow = new TaskWindow(Application.Backend);
+// if(lastXPos == 0 || lastYPos == 0)
+// {
+// lastXPos = Application.Preferences.GetInt("MainWindowLastXPos");
+// lastYPos = Application.Preferences.GetInt("MainWindowLastYPos");
+// }
+//
+// int x = lastXPos;
+// int y = lastYPos;
+//
+// if (x >= 0 && y >= 0)
+// taskWindow.Move(x, y);
+//
+// taskWindow.ShowAll();
+// }
+// }
+
+ MainWindowModel vm;
}
}
diff --git a/src/libtasqueui/Legacy/MainWindowModel.cs b/src/libtasqueui/Legacy/MainWindowModel.cs
index 280e5af..14e3303 100644
--- a/src/libtasqueui/Legacy/MainWindowModel.cs
+++ b/src/libtasqueui/Legacy/MainWindowModel.cs
@@ -81,6 +81,12 @@ namespace Tasque.UIModel.Legacy
}
}
+ public UICommand Hide { get { return hide ?? (hide = new UICommand ()); } }
+
+ public UICommand Show { get { return show ?? (show = new UICommand ()); } }
+
+ public Point Position { get; set; }
+
public ICommand ShowContextMenu { get { throw new NotImplementedException (); } }
public void OnDayChanged ()
@@ -147,5 +153,8 @@ namespace Tasque.UIModel.Legacy
MainWindowContextMenuModel contextMenu;
Task selectedTask;
+
+ UICommand hide;
+ UICommand show;
}
}
diff --git a/src/libtasqueui/Point.cs b/src/libtasqueui/Point.cs
new file mode 100644
index 0000000..8057296
--- /dev/null
+++ b/src/libtasqueui/Point.cs
@@ -0,0 +1,43 @@
+//
+// Point.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.
+
+namespace Tasque.UIModel
+{
+ public struct Point
+ {
+ public Point (int x, int y)
+ {
+ X = x;
+ Y = y;
+ }
+
+ public bool IsEmpty { get { return X == 0 && Y == 0; } }
+
+ public int X { get; set; }
+
+ public int Y { get; set; }
+ }
+}
diff --git a/src/libtasqueui/UICommand.cs b/src/libtasqueui/UICommand.cs
index 222609f..cb7eaa1 100644
--- a/src/libtasqueui/UICommand.cs
+++ b/src/libtasqueui/UICommand.cs
@@ -23,13 +23,52 @@
// 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.Diagnostics;
namespace Tasque.UIModel
{
- public abstract class UICommand : CommandBase
+ //DOCS: sealed so that protected SetCanExecute and UnsetCanExecute
+ // can't be invoked directly
+ public sealed class UICommand : CommandBase
{
- public UICommand ()
+ new public bool CanExecute {
+ get { return base.CanExecute; }
+ set {
+ if (value && ExecuteAction == null)
+ throw new InvalidOperationException ("Can't set CanExecute to true " +
+ "when ExecuteAction is null.");
+
+ if (!value)
+ UnsetCanExecute (string.Empty);
+ else
+ SetCanExecute ();
+ }
+ }
+
+ public Action ExecuteAction { get { return executeAction; } }
+
+ public override void Execute ()
+ {
+ if (CanExecute)
+ ExecuteAction ();
+ else
+ Debug.WriteLine ("Cannot execute: " + (string.IsNullOrWhiteSpace(ErrorMessage)
+ ? "(none given)" : ErrorMessage));
+ }
+
+ //DOCS: sets canexecute to true
+ public void SetExecuteAction (Action executeAction)
+ {
+ this.executeAction = executeAction;
+ }
+
+ public void SetExecuteAction (Action executeAction, bool canExecute)
{
+ SetExecuteAction (executeAction);
+ CanExecute = canExecute;
}
+
+ Action executeAction;
}
}
diff --git a/src/libtasqueui/libtasqueui.csproj b/src/libtasqueui/libtasqueui.csproj
index d7316a4..f453061 100644
--- a/src/libtasqueui/libtasqueui.csproj
+++ b/src/libtasqueui/libtasqueui.csproj
@@ -111,6 +111,7 @@
<Compile Include="TaskGroupModel.cs" />
<Compile Include="TaskGroupModelFactory.cs" />
<Compile Include="CompletedTaskGroupModel.cs" />
+ <Compile Include="Point.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]