From 482a76ae3a4e60aaff7187afb0c25967f6506dd2 Mon Sep 17 00:00:00 2001 From: Michael Harding Date: Fri, 2 Feb 2018 16:52:05 -0500 Subject: [PATCH] Add Workspaces dialog to the Settings menu --- .../Modules/Settings/SettingsShellModule.cs | 26 ++++++- src/client/spark/Spark.csproj | 8 ++ .../view/Controls/DialogButtonSkirt.xaml | 19 +++-- .../view/Controls/DialogButtonSkirt.xaml.cs | 15 +++- src/client/spark/view/Resources/Buttons.xaml | 30 ++++++++ .../Workspaces/WorkspacesDialogView.xaml | 77 +++++++++++++++++++ .../Workspaces/WorkspacesDialogView.xaml.cs | 30 ++++++++ .../Workspaces/WorkspacesDialogViewModel.cs | 55 +++++++++++++ 8 files changed, 251 insertions(+), 9 deletions(-) create mode 100644 src/client/spark/view/Shell/Workspaces/WorkspacesDialogView.xaml create mode 100644 src/client/spark/view/Shell/Workspaces/WorkspacesDialogView.xaml.cs create mode 100644 src/client/spark/view/Shell/Workspaces/WorkspacesDialogViewModel.cs diff --git a/src/client/spark/Modules/Settings/SettingsShellModule.cs b/src/client/spark/Modules/Settings/SettingsShellModule.cs index 1e5d6fcda..a20b0e834 100644 --- a/src/client/spark/Modules/Settings/SettingsShellModule.cs +++ b/src/client/spark/Modules/Settings/SettingsShellModule.cs @@ -1,4 +1,7 @@ -using mbts.ui; +using mbts; +using mbts.ui; +using mbts.ui.shell; +using mbts.spark; using System; using System.Collections.Generic; using System.Threading.Tasks; @@ -7,17 +10,24 @@ using System.IO; using System.Windows.Media; using bts.api; using System.ComponentModel.Composition; -using mbts.ui.shell; + namespace bts.ui { [Export(typeof(IShellModule))] class SettingsShellModule : IShellModule { readonly IBus _bus; + IDisposable _dispose; + + WorkspacesModel ws_model; [ImportingConstructor] public SettingsShellModule(IBus bus, WorkspacesModel ws) { // todo: Create workspaces dialog // todo: settings dialog + ws_model = ws; + _dispose = bus.subscribe(SparkTags.ShowWorkspaces).Subscribe(_ => show_workspaces_dialog()); + + _bus = bus; } public ImageSource icon => Icons.Admin; @@ -35,6 +45,16 @@ namespace bts.ui { throw new NotImplementedException(); } - public void Dispose() { } + public void show_workspaces_dialog() + { + WorkspacesDialogView ws_dialog = new WorkspacesDialogView(ws_model); + ws_dialog.Show(); + } + + + + public void Dispose() { + Disposable.dispose(ref _dispose); + } } } diff --git a/src/client/spark/Spark.csproj b/src/client/spark/Spark.csproj index 7276d9151..6019d857a 100644 --- a/src/client/spark/Spark.csproj +++ b/src/client/spark/Spark.csproj @@ -49,6 +49,9 @@ + + + @@ -59,6 +62,11 @@ + + + Code + + diff --git a/src/client/spark/view/Controls/DialogButtonSkirt.xaml b/src/client/spark/view/Controls/DialogButtonSkirt.xaml index ab4ebd7a3..f764a1bcd 100644 --- a/src/client/spark/view/Controls/DialogButtonSkirt.xaml +++ b/src/client/spark/view/Controls/DialogButtonSkirt.xaml @@ -10,12 +10,21 @@ mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Save Current Workspace As: + + + + + + + + + + + Shared + + + + + + + + + diff --git a/src/client/spark/view/Shell/Workspaces/WorkspacesDialogView.xaml.cs b/src/client/spark/view/Shell/Workspaces/WorkspacesDialogView.xaml.cs new file mode 100644 index 000000000..ca317443a --- /dev/null +++ b/src/client/spark/view/Shell/Workspaces/WorkspacesDialogView.xaml.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace mbts.ui.shell +{ + /// + /// Interaction logic for WorkspacesDialogView.xaml + /// + public partial class WorkspacesDialogView : Window + { + public WorkspacesDialogView(WorkspacesModel wm) + { + InitializeComponent(); + + this.DataContext = new WorkspacesDialogViewModel(wm); + } + } +} diff --git a/src/client/spark/view/Shell/Workspaces/WorkspacesDialogViewModel.cs b/src/client/spark/view/Shell/Workspaces/WorkspacesDialogViewModel.cs new file mode 100644 index 000000000..d91e9fd8f --- /dev/null +++ b/src/client/spark/view/Shell/Workspaces/WorkspacesDialogViewModel.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Windows.Input; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using mbts; +using mbts.ui; +using mbts.ui.shell; + +namespace mbts.ui.shell +{ + public class WorkspacesDialogViewModel : ViewModelBaseWithValidation + { + private WorkspacesModel _work_model; + + public WorkspacesDialogViewModel(WorkspacesModel wm) + { + _work_model = wm; + } + + public ObservableCollection Workspaces { get { return _work_model.Workspaces; } } + public string SaveName { get; set; } + public bool IsPublicWorkspace { get; set; } + public bool ShowWorkspaces { get; set; } + + public ICommand SaveWorkspace + { + get + { + return new DelegateCommand(arg => { + // Check for errors in the input + if (string.IsNullOrEmpty(SaveName)) + { + set_error("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)); + return; + } + else + { + clear_error("SaveName"); + } + // Save + _work_model.save_workspace(SaveName, ispublic: IsPublicWorkspace); + }); + } + } + + } +}