Add Workspaces dialog to the Settings menu

This commit is contained in:
Michael Harding committed 2018-02-02 16:52:05 -05:00
1 parent 9fdf52141e
commit 482a76ae3a
8 files changed
+251 -9

No files matched your search

@@ -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);
}
}
}
+8
View File
@@ -49,6 +49,9 @@
<Resource Include="**\*.png" />
<ConfigDefaults Include="../../lib/config/defaults/*.conf" />
</ItemGroup>
<ItemGroup>
<None Remove="view\Shell\Workspaces\WorkspacesView.xaml" />
</ItemGroup>
<ItemGroup>
<Resource Remove="logo.ico" />
</ItemGroup>
@@ -59,6 +62,11 @@
<Folder Include="Controls\SecurityPicker\" />
<Folder Include="view\Extensions\ItemsControl\ObservableItemsSource\" />
</ItemGroup>
<ItemGroup>
<Compile Update="view\Shell\Workspaces\WorkspacesDialogView.xaml.cs">
<SubType>Code</SubType>
</Compile>
</ItemGroup>
<Target Name="diagnostic" AfterTargets="PreBuildEvent">
</Target>
<Target Name="copy_defaults" AfterTargets="PostBuildEvent">
@@ -10,12 +10,21 @@
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<ItemsControl.Resources>
<Style x:Key="Close" TargetType="ctrl:DialogButtonSkirt">
<Setter Property="ItemsSource">
<Setter.Value>
<x:ArrayExtension Type="Button">
<Button Content="Close" Margin="8" ui:Behavior.CloseWindow="True" MinWidth="{Binding Path=ButtonMinWidth, ElementName=me}"/>
</x:ArrayExtension>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="OKCancel" TargetType="ctrl:DialogButtonSkirt">
<Setter Property="ItemsSource">
<Setter.Value>
<x:ArrayExtension Type="Button">
<Button Content="OK" Margin="8,8,0,8" Command="{Binding Apply, RelativeSource={RelativeSource AncestorType=ctrl:DialogButtonSkirt}}" Style="{StaticResource CommonButton}" ui:Behavior.CloseWindow="True" />
<Button Content="Cancel" Margin="8" ui:Behavior.CloseWindow="True" />
<Button Content="OK" Margin="8,8,0,8" Command="{Binding Apply, RelativeSource={RelativeSource AncestorType=ctrl:DialogButtonSkirt}}" Style="{StaticResource CommonButton}" ui:Behavior.CloseWindow="True" MinWidth="{Binding Path=ButtonMinWidth, ElementName=me}"/>
<Button Content="Cancel" Margin="8" ui:Behavior.CloseWindow="True" MinWidth="{Binding Path=ButtonMinWidth, ElementName=me}" />
</x:ArrayExtension>
</Setter.Value>
</Setter>
@@ -24,9 +33,9 @@
<Setter Property="ItemsSource">
<Setter.Value>
<x:ArrayExtension Type="Button">
<Button Content="OK" Margin="8,8,0,8" Command="{Binding Apply, RelativeSource={RelativeSource AncestorType=ctrl:DialogButtonSkirt}}" Style="{StaticResource CommonButton}" ui:Behavior.CloseWindow="True" />
<Button Content="Apply" Margin="8,8,0,8" Command="{Binding Apply, RelativeSource={RelativeSource AncestorType=ctrl:DialogButtonSkirt}}" Style="{StaticResource CommonButton}" />
<Button Content="Cancel" Margin="8" Style="{StaticResource CommonButton}" ui:Behavior.CloseWindow="True" />
<Button Content="OK" Margin="8,8,0,8" Command="{Binding Apply, RelativeSource={RelativeSource AncestorType=ctrl:DialogButtonSkirt}}" Style="{StaticResource CommonButton}" ui:Behavior.CloseWindow="True" MinWidth="{Binding Path=ButtonMinWidth, ElementName=me}"/>
<Button Content="Apply" Margin="8,8,0,8" Command="{Binding Apply, RelativeSource={RelativeSource AncestorType=ctrl:DialogButtonSkirt}}" Style="{StaticResource CommonButton}" MinWidth="{Binding Path=ButtonMinWidth, ElementName=me}"/>
<Button Content="Cancel" Margin="8" Style="{StaticResource CommonButton}" ui:Behavior.CloseWindow="True" MinWidth="{Binding Path=ButtonMinWidth, ElementName=me}"/>
</x:ArrayExtension>
</Setter.Value>
</Setter>
@@ -18,7 +18,20 @@ namespace mbts.ui.controls
set { SetValue(ButtonsAlignmentProperty, value); }
}
public static readonly DependencyProperty ApplyProperty = DependencyProperty.Register("Apply", typeof(ICommand), typeof(DialogButtonSkirt), new FrameworkPropertyMetadata(null));
public double ButtonMinWidth
{
get { return (double)GetValue(ButtonMinWidthProperty); }
set { SetValue(ButtonMinWidthProperty, value); }
}
public static readonly DependencyProperty ButtonMinWidthProperty =
DependencyProperty.Register("ButtonMinWidth", typeof(double), typeof(DialogButtonSkirt), new PropertyMetadata(30.0));
public static readonly DependencyProperty ApplyProperty = DependencyProperty.Register("Apply", typeof(ICommand), typeof(DialogButtonSkirt), new FrameworkPropertyMetadata(null));
public ICommand Apply { get { return GetValue(ApplyProperty) as ICommand; } set { SetValue(ApplyProperty, value); } }
public static readonly DependencyProperty YesProperty = DependencyProperty.Register("Yes", typeof(ICommand), typeof(DialogButtonSkirt), new FrameworkPropertyMetadata(null));
@@ -48,6 +48,36 @@
</Setter>
</Style>
<!-- For dialogs containing a list of items, like the workspaces dialog -->
<Style x:Key="DialogListButton" TargetType="{x:Type Button}">
<Setter Property="Background" Value="Transparent" />
<Setter Property="Foreground" Value="{mbts:BTSColor UI.Button.normal_foreground}" />
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border Name="border"
Background="{TemplateBinding Background}"
BorderThickness="0"
HorizontalAlignment="Stretch"
Padding="5">
<ContentPresenter />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="border" Property="Background" Value="{mbts:BTSColor UI.Button.mouseover_background}" />
<Setter TargetName="border" Property="BorderBrush" Value="{mbts:BTSColor UI.Button.mouseover_border}" />
</Trigger>
<Trigger Property="IsPressed" Value="true">
<Setter TargetName="border" Property="Background" Value="{mbts:BTSColor UI.Button.pressed_background}" />
<Setter TargetName="border" Property="BorderBrush" Value="{mbts:BTSColor UI.Button.pressed_background}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<!-- Spark Menu item used in launcher menus and tool bars-->
<Style x:Key="SparkMenuButton" TargetType="controls:SparkMenuItem">
<Setter Property="SnapsToDevicePixels" Value="true" />
@@ -0,0 +1,77 @@
<Window x:Class="mbts.ui.shell.WorkspacesDialogView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:mbts.ui.shell"
mc:Ignorable="d"
xmlns:controls="clr-namespace:mbts.ui.controls"
xmlns:ui="clr-namespace:mbts.ui"
Width="250"
MinHeight="300"
MaxHeight="700"
ui:WindowStyle.SizeToContent="Height"
ui:WindowStyle.ShowMinimizeButton="False"
Style="{StaticResource BTSDialog}"
>
<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>
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<ScrollViewer HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Auto">
<ItemsControl ItemsSource="{Binding Workspaces}" Style="{StaticResource CommonList}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Command="{Binding ActivateCommand}" Style="{DynamicResource DialogListButton}">
<Grid>
<Image Source="{Binding Icon}" HorizontalAlignment="Left" Height="16" Margin="4" />
<TextBlock Text="{Binding Name}" VerticalAlignment="Center" Margin="28,0,0,0" x:Name="text" />
<Button Style="{StaticResource RoundCloseButton}" HorizontalAlignment="Right" VerticalAlignment="Center" Command="{Binding DeleteCommand}" />
</Grid>
</Button>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
<Border Grid.Row="2" Grid.ColumnSpan="2" BorderThickness="0,1,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>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<TextBox Margin="4" Text="{Binding SaveName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Stretch" />
<CheckBox Margin="4,0,4,0" Grid.Row="1" IsChecked="{Binding IsPublicWorkspace}" HorizontalAlignment="Left">Shared</CheckBox>
<Button Grid.Column="1" HorizontalAlignment="Right" Margin="4" Command="{Binding SaveWorkspace}" IsDefault="True" MinWidth="60">Save</Button>
</Grid>
</Grid>
</Border>
</Grid>
<!--controls:HelpButton ManPage="Workspaces" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,4,8,0" /-->
<controls:DialogButtonSkirt Grid.Row="1" Grid.ColumnSpan="2" Style="{StaticResource Close}" ButtonMinWidth="60" />
</Grid>
</Window>
@@ -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
{
/// <summary>
/// Interaction logic for WorkspacesDialogView.xaml
/// </summary>
public partial class WorkspacesDialogView : Window
{
public WorkspacesDialogView(WorkspacesModel wm)
{
InitializeComponent();
this.DataContext = new WorkspacesDialogViewModel(wm);
}
}
}
@@ -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<WorkspaceViewModel> 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);
});
}
}
}
}