Merge branch 'SP-174'
This commit is contained in:
commit
81e8acb459
4 files changed
+167
-101
No files matched your search
@@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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"
|
||||
>
|
||||
<Window.Resources>
|
||||
<ResourceDictionary>
|
||||
<Style x:Key="CommonList" TargetType="{x:Type ItemsControl}">
|
||||
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
|
||||
<Setter Property="Background" Value="Transparent" />
|
||||
<Setter Property="BorderThickness" Value="0" />
|
||||
</Style>
|
||||
</ResourceDictionary>
|
||||
</Window.Resources>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Window.Resources>
|
||||
<ResourceDictionary>
|
||||
<Style x:Key="CommonList" TargetType="{x:Type ItemsControl}">
|
||||
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
|
||||
<Setter Property="Background" Value="Transparent" />
|
||||
<Setter Property="BorderThickness" Value="0" />
|
||||
</Style>
|
||||
</ResourceDictionary>
|
||||
</Window.Resources>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<StackPanel Grid.Row="1" Margin="5">
|
||||
<GroupBox Header="Existing Workspaces">
|
||||
<StackPanel>
|
||||
<ComboBox x:Name="workspaces_cb" Margin="4" Grid.IsSharedSizeScope="True" ItemsSource="{DynamicResource header_and_data}" SelectedValue="{Binding selected_workspace, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
|
||||
<!-- Inspiration for the table like appearance with headers taken from
|
||||
https://stackoverflow.com/questions/5807899/multiple-item-combo-box-with-headers
|
||||
-->
|
||||
<ComboBox.Resources>
|
||||
<CompositeCollection x:Key="header_and_data">
|
||||
<ComboBoxItem IsEnabled="False">
|
||||
<Grid TextElement.FontWeight="Bold">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" SharedSizeGroup="NameGroup"/>
|
||||
<ColumnDefinition Width="5"/>
|
||||
<ColumnDefinition Width="Auto" SharedSizeGroup="LastSaveTime_DateGroup" />
|
||||
<ColumnDefinition Width="5"/>
|
||||
<ColumnDefinition Width="Auto" SharedSizeGroup="LastSaveTime_TimeGroup" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Grid.Column="0" Text="Name"/>
|
||||
<TextBlock Grid.Column="2" Grid.ColumnSpan="3" Text="Last Save Time"/>
|
||||
</Grid>
|
||||
</ComboBoxItem>
|
||||
<Separator/>
|
||||
<CollectionContainer Collection="{Binding Source={x:Reference workspaces_cb}, Path=DataContext.Workspaces}"/>
|
||||
</CompositeCollection>
|
||||
<DataTemplate DataType="{x:Type local:WorkspaceViewModel}">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Border BorderThickness="0,0,0,0" BorderBrush="{ui:BTSColor UI.Button.normal_border}">
|
||||
<Grid Margin="5 7 5 7">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock>Save Current Workspace As:</TextBlock>
|
||||
<Grid Grid.Row="1">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBox Margin="4" Text="{Binding SaveName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Stretch" />
|
||||
<Button Grid.Column="1" HorizontalAlignment="Right" Margin="4" Command="{Binding SaveWorkspace}" IsDefault="True" MinWidth="60">Save</Button>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Border>
|
||||
<ScrollViewer Grid.Row="1" Grid.ColumnSpan="2" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Auto">
|
||||
<ItemsControl ItemsSource="{Binding Workspaces}" Style="{StaticResource CommonList}">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<controls:WorkspaceItemControl />
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</ScrollViewer>
|
||||
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" SharedSizeGroup="NameGroup"/>
|
||||
<ColumnDefinition Width="5"/>
|
||||
<ColumnDefinition Width="Auto" SharedSizeGroup="LastSaveTime_DateGroup" />
|
||||
<ColumnDefinition Width="5"/>
|
||||
<ColumnDefinition Width="Auto" SharedSizeGroup="LastSaveTime_TimeGroup" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Grid.Column="0" Text="{Binding Name}"/>
|
||||
<TextBlock Grid.Column="2" HorizontalAlignment="Right">
|
||||
<TextBlock.Style>
|
||||
<Style TargetType="TextBlock">
|
||||
<Setter Property="Text" Value="{Binding LastSaveTime, StringFormat=d}" />
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding LastSaveTime}" Value="{x:Static sys:DateTime.MinValue}">
|
||||
<Setter Property="Text" Value="" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</TextBlock.Style>
|
||||
</TextBlock>
|
||||
<TextBlock Grid.Column="4" HorizontalAlignment="Right">
|
||||
<TextBlock.Style>
|
||||
<Style TargetType="TextBlock">
|
||||
<Setter Property="Text" Value="{Binding LastSaveTime, StringFormat=T}" />
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding LastSaveTime}" Value="{x:Static sys:DateTime.MinValue}">
|
||||
<Setter Property="Text" Value="" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</TextBlock.Style>
|
||||
</TextBlock>
|
||||
</Grid>
|
||||
<!--controls:DialogSkirtOKCancel Grid.Row="1" Grid.ColumnSpan="2"/-->
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ComboBox.Resources>
|
||||
</ComboBox>
|
||||
<UniformGrid Rows="1" Margin="4" >
|
||||
<Button Grid.Column="1" MinWidth="60" Command="{Binding LoadCommand}">Load</Button>
|
||||
<Button Grid.Column="2" MinWidth="60" Command="{Binding SaveCommand}">Save</Button>
|
||||
<Button Grid.Column="3" MinWidth="60" Command="{Binding DeleteCommand}">Delete</Button>
|
||||
</UniformGrid>
|
||||
</StackPanel>
|
||||
</GroupBox>
|
||||
<Border BorderThickness="0,0,0,0" BorderBrush="{ui:BTSColor UI.Button.normal_border}">
|
||||
<Grid Margin="5 7 5 7">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid Grid.Row="1">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBox Margin="4" Text="{Binding SaveName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Stretch" />
|
||||
<Button Grid.Column="2" MinWidth="60" Command="{Binding SaveNewWorkspace}">Create New</Button>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -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");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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; }
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user