diff --git a/src/client/spark/view/Shell/Workspaces/WorkspaceViewModel.cs b/src/client/spark/view/Shell/Workspaces/WorkspaceViewModel.cs
index 49bb41138..0ce33b9eb 100644
--- a/src/client/spark/view/Shell/Workspaces/WorkspaceViewModel.cs
+++ b/src/client/spark/view/Shell/Workspaces/WorkspaceViewModel.cs
@@ -1,4 +1,5 @@
-using System;
+using mbts.utils;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -9,8 +10,6 @@ namespace mbts.ui.shell
{
public class WorkspaceViewModel : ViewModelBase
{
- private const string INITIAL_VISUAL_STATE = "Normal";
-
WorkspacesModel _parent;
public WorkspaceViewModel(WorkspacesModel parent, string name, WorkspaceDefinition definition) {
_parent = parent;
@@ -19,45 +18,12 @@ namespace mbts.ui.shell
}
public string Name { get; private set; }
+ public DateTime LastSaveTime => Definition.last_save_lldatetime.lldatetime().ToLocalTime();
public bool IsShared { get { return Definition.is_shared; } }
public object Icon {
get { return Icons.Window; }
}
- private string _vstate = INITIAL_VISUAL_STATE;
- public string VisualState {
- get {
- // this unconventional getter acts as a reset after the VisualStateManager has played
- // i.e. if we overwrite a workspace then save, then close the window, when we open the
- // window back up, we'll see item animate b/c it has never been reset from the animate
- // state. This is necessary b/c the lifetime of Workspaces is not tied to the lifetime
- // of the View, rather it lives in the Model and is only instantiated on startup via MEF
- var return_val = _vstate;
- _vstate = INITIAL_VISUAL_STATE;
- return return_val;
- }
- set {
- _vstate = value;
- RaisePropertyChanged("VisualState");
- }
- }
-
internal WorkspaceDefinition Definition { get; private set; }
-
- public ICommand ActivateCommand {
- get {
- return new DelegateCommand(param => {
- var unused = _parent.load_workspace(Definition, Name);
- });
- }
- }
-
- public ICommand DeleteCommand {
- get {
- return new DelegateCommand(param => {
- _parent.delete_workspace(Name, Definition);
- });
- }
- }
}
}
diff --git a/src/client/spark/view/Shell/Workspaces/WorkspacesDialogView.xaml b/src/client/spark/view/Shell/Workspaces/WorkspacesDialogView.xaml
index 38f388d91..19ecd7978 100644
--- a/src/client/spark/view/Shell/Workspaces/WorkspacesDialogView.xaml
+++ b/src/client/spark/view/Shell/Workspaces/WorkspacesDialogView.xaml
@@ -6,6 +6,7 @@
xmlns:local="clr-namespace:mbts.ui.shell"
mc:Ignorable="d"
xmlns:controls="clr-namespace:mbts.ui.controls"
+ xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:ui="clr-namespace:mbts.ui"
Width="250"
MaxHeight="700"
@@ -13,54 +14,108 @@
ui:WindowStyle.ShowMinimizeButton="False"
Style="{StaticResource BTSDialog}"
Title="Workspaces"
+ Topmost="True"
>
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
- Save Current Workspace As:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/client/spark/view/Shell/Workspaces/WorkspacesDialogViewModel.cs b/src/client/spark/view/Shell/Workspaces/WorkspacesDialogViewModel.cs
index 80282e25e..72c80dc7d 100644
--- a/src/client/spark/view/Shell/Workspaces/WorkspacesDialogViewModel.cs
+++ b/src/client/spark/view/Shell/Workspaces/WorkspacesDialogViewModel.cs
@@ -8,12 +8,15 @@ using System.Threading.Tasks;
using mbts;
using mbts.ui;
using mbts.ui.shell;
+using bts.spark;
+using System.Windows;
namespace mbts.ui.shell
{
public class WorkspacesDialogViewModel : ViewModelBaseWithValidation
{
private WorkspacesModel _work_model;
+ IRaiseCanExecuteChangedCommand _load_command, _delete_command, _save_command;
public WorkspacesDialogViewModel(WorkspacesModel wm)
{
@@ -25,36 +28,74 @@ namespace mbts.ui.shell
public bool IsPublicWorkspace { get; set; }
public bool ShowWorkspaces { get; set; }
- public ICommand SaveWorkspace
+ WorkspaceViewModel _selected_workspace;
+ public WorkspaceViewModel selected_workspace {
+ get => _selected_workspace;
+ set {
+ if (Set(ref _selected_workspace, value)) {
+ LoadCommand.TryRaiseCanExecuteChanged();
+ DeleteCommand.TryRaiseCanExecuteChanged();
+ SaveCommand.TryRaiseCanExecuteChanged();
+ }
+ }
+ }
+
+ private bool _command_can_execute() => selected_workspace != null;
+ private void _clear_error_state() => clear_error(nameof(SaveName));
+
+ public ICommand LoadCommand => _load_command ??
+ (_load_command = new DelegateCommand(
+ () => {
+ _work_model.load_workspace(selected_workspace.Definition, selected_workspace.Name).ignore();
+ _clear_error_state();
+ }, _command_can_execute));
+ public ICommand DeleteCommand => _delete_command ??
+ (_delete_command = new DelegateCommand(
+ () => {
+ if (BTSMessageBox.Show(
+ $"Delete the \"{selected_workspace.Name}\" workspace?",
+ "Delete Existing Workspace Confirmation",
+ BTSMessageBoxButtons.Yes | BTSMessageBoxButtons.No,
+ MessageBoxImage.Question) == BTSMessageBoxButtons.Yes) {
+ _work_model.delete_workspace(selected_workspace.Name, selected_workspace.Definition).ignore();
+ _clear_error_state();
+ }
+ }, _command_can_execute));
+ public ICommand SaveCommand => _save_command ??
+ (_save_command = new DelegateCommand(
+ () => {
+ if (BTSMessageBox.Show(
+ $"Overwrite \"{selected_workspace.Name}\" with current layout?",
+ "Save Existing Workspace Confirmation",
+ BTSMessageBoxButtons.Yes | BTSMessageBoxButtons.No,
+ MessageBoxImage.Question) == BTSMessageBoxButtons.Yes) {
+ _work_model.save_workspace(selected_workspace.Name, ispublic:selected_workspace.Definition.is_shared);
+ _clear_error_state();
+ }
+ }, _command_can_execute));
+
+ public ICommand SaveNewWorkspace
{
get
{
return new DelegateCommand(arg => {
+ _clear_error_state();
// Check for errors in the input
- if (string.IsNullOrEmpty(SaveName))
- {
- set_error("SaveName", "Workspace must be named");
+ if (string.IsNullOrEmpty(SaveName)) {
+ set_error(nameof(SaveName), "Workspace must be named");
return;
}
- if (SaveName.Contains(WorkspacesModel.ACTIVE_WORKSPACE_PREFIX))
- {
- set_error("SaveName", "Workspace name cannot contains '{0}'".fmt(WorkspacesModel.ACTIVE_WORKSPACE_PREFIX));
+ if (SaveName.Contains(WorkspacesModel.ACTIVE_WORKSPACE_PREFIX)) {
+ set_error(nameof(SaveName), "Workspace name cannot contains '{0}'".fmt(WorkspacesModel.ACTIVE_WORKSPACE_PREFIX));
return;
}
- else
- {
- clear_error("SaveName");
+ if (Workspaces.Any(x => x.Name.Replace(WorkspacesModel.SHARED_MONIKER, string.Empty) == SaveName && x.IsShared == IsPublicWorkspace)) {
+ set_error(nameof(SaveName), $"Workspace already exists '{SaveName}'");
+ return;
}
- var save_candidate_already_exists = Workspaces.Any(x => x.Name.Replace(WorkspacesModel.SHARED_MONIKER, string.Empty) == SaveName && x.IsShared == IsPublicWorkspace);
- // Save
_work_model.save_workspace(SaveName, ispublic: IsPublicWorkspace);
-
- // if we just overwrote something, have the vm reflect it
- if (save_candidate_already_exists)
- Workspaces.Where(x => x.Name.Replace(WorkspacesModel.SHARED_MONIKER, string.Empty) == SaveName && x.IsShared == IsPublicWorkspace).ForEach(x => x.VisualState = "Overridden");
});
}
}
-
}
}
diff --git a/src/client/spark/view/Shell/Workspaces/WorkspacesModel.cs b/src/client/spark/view/Shell/Workspaces/WorkspacesModel.cs
index 867c34b18..7f55387d7 100644
--- a/src/client/spark/view/Shell/Workspaces/WorkspacesModel.cs
+++ b/src/client/spark/view/Shell/Workspaces/WorkspacesModel.cs
@@ -179,6 +179,7 @@ namespace mbts.ui.shell
public void save_workspace(string name, bool persist=true, bool ispublic=false) {
WorkspaceDefinition workspace = get_workspace();
workspace.is_shared = ispublic;
+ workspace.last_save_lldatetime = LLDateTime.now().value;
if (ispublic) { name += SHARED_MONIKER; }
// Remove the old one if a workspace by this name exists already
@@ -282,5 +283,8 @@ namespace mbts.ui.shell
[ProtoMember(10, IsRequired = false)]
public bool is_shared { get; set; }
+ [ProtoMember(11, IsRequired = false)]
+ public ulong last_save_lldatetime { get; set; }
+
}
}