Merged in SPARK-1144 (pull request #22)

SPARK-144 Remove Docking Facility from Launcher

Approved-by: Michael Harding <michael.harding@bluetradesys.com>
This commit is contained in:
Eric Harding committed 2018-05-21 14:57:49 +00:00
commit 80fde10cd5
4 files changed
+6 -190

No files matched your search

@@ -37,8 +37,7 @@ namespace mbts.ui.shell {
public bool show_text = true;
[ProtoMember(102)]
public bool always_on_top = false;
[ProtoMember(103)]
public DockState dock = DockState.FLOATING;
//[ProtoMember(103)] //used
}
[ProtoContract]
+3 -11
View File
@@ -138,10 +138,10 @@
</ItemsControl>
</StackPanel>
<TextBlock Text="{Binding Title}" Grid.Row="0" Margin="2" MouseDown="TextBlock_MouseDown" Height="16" Visibility="{Binding IsDocked, Converter={StaticResource BoolToVisibility},ConverterParameter=true}" />
<TextBlock Text="{Binding Title}" Grid.Row="0" Margin="2" MouseDown="TextBlock_MouseDown" Height="16" Visibility="Visible" />
<!-- Window close button -->
<StackPanel Orientation="Horizontal" Grid.Row="0" HorizontalAlignment="Right" VerticalAlignment="Center" Visibility="{Binding IsDocked, Converter={StaticResource BoolToVisibility},ConverterParameter=true}">
<StackPanel Orientation="Horizontal" Grid.Row="0" HorizontalAlignment="Right" VerticalAlignment="Center" Visibility="Visible">
<Button Command="{Binding MinimizeCommand}" Style="{StaticResource RoundMinimizeButton}" />
<Button Command="{Binding CloseCommand}" Style="{StaticResource RoundCloseButton}" />
</StackPanel>
@@ -151,17 +151,9 @@
</Border>
<Window.ContextMenu>
<ContextMenu Background="{StaticResource CommonBackground}">
<MenuItem Header="Layout">
<MenuItem Header="Vertical Layout" IsCheckable="True" IsChecked="{Binding IsVertical, Mode=TwoWay}" Visibility="{Binding IsDocked, Converter={StaticResource BoolToVisibility},ConverterParameter=true}" />
<Separator Visibility="{Binding IsDocked, Converter={StaticResource BoolToVisibility},ConverterParameter=true}" />
<MenuItem Header="Dock Top" IsCheckable="True" IsChecked="{Binding IsDockedTop, Mode=TwoWay}" />
<MenuItem Header="Dock Right" IsCheckable="True" IsChecked="{Binding IsDockedRight, Mode=TwoWay}" />
<MenuItem Header="Dock Bottom" IsCheckable="True" IsChecked="{Binding IsDockedBottom, Mode=TwoWay}" />
<MenuItem Header="Dock Left" IsCheckable="True" IsChecked="{Binding IsDockedLeft, Mode=TwoWay}" />
</MenuItem>
<MenuItem Header="Vertical Layout" IsCheckable="True" IsChecked="{Binding IsVertical, Mode=TwoWay}" />
<MenuItem Header="Show Text" IsCheckable="True" IsChecked="{Binding ShowText, Mode=TwoWay}" />
<MenuItem Header="Always Visible" IsCheckable="True" IsChecked="{Binding Topmost, Mode=TwoWay}" />
<MenuItem Header="Support" Command="{Binding SupportCommand}" />
<MenuItem Header="About Spark" Command="{Binding AboutCommand}" />
<MenuItem Header="Exit" Command="{Binding CloseCommand}" />
</ContextMenu>
@@ -150,8 +150,6 @@ namespace mbts.ui.shell
public bool ShowText { get { return true; } }
public double ItemWidth { get { return 85.0; } }
public bool IsDocked { get { return false; } }
public IEnumerable<object> Modules {
get {
return new object[] {
@@ -39,10 +39,6 @@ namespace mbts.ui.shell
_browser = browser;
_error_service = errors;
_bus = bus;
// It's very important that we make every effort to restore the work area
// If we fail the customer will have to log out and log back in.
AppDomain.CurrentDomain.UnhandledException += (o, e) => restore_work_area();
}
ObservableAutoWrapper<ShellModuleVM, IShellModule> _modules;
@@ -73,41 +69,6 @@ namespace mbts.ui.shell
set { Orientation = value ? Orientation.Vertical : Orientation.Horizontal; }
}
private DockState _dock = DockState.FLOATING;
public DockState DockState
{
get { return _dock; }
set {
var old = _dock;
_dock = value;
RaisePropertyChanged("DockState");
RaisePropertyChanged("IsDocked");
RaisePropertyChanged("IsDockedLeft");
RaisePropertyChanged("IsDockedTop");
RaisePropertyChanged("IsDockedRight");
RaisePropertyChanged("IsDockedBottom");
update_docking(old, value);
}
}
public bool IsDockedLeft {
get { return DockState == DockState.LEFT; }
set { DockState = value ? DockState.LEFT : DockState.FLOATING; }
}
public bool IsDockedTop {
get { return DockState == DockState.TOP; }
set { DockState = value ? DockState.TOP : DockState.FLOATING; }
}
public bool IsDockedRight {
get { return DockState == DockState.RIGHT; }
set { DockState = value ? DockState.RIGHT : DockState.FLOATING; }
}
public bool IsDockedBottom {
get { return DockState == DockState.BOTTOM; }
set { DockState = value ? DockState.BOTTOM : DockState.FLOATING; }
}
public bool IsDocked { get { return DockState != shell.DockState.FLOATING; } }
private bool _topmost = false;
public bool Topmost {
get { return _topmost; }
@@ -121,7 +82,6 @@ namespace mbts.ui.shell
_show_text = value;
RaisePropertyChanged("ShowText");
RaisePropertyChanged("ItemWidth");
update_docking(_dock, _dock);
}
}
@@ -132,146 +92,22 @@ namespace mbts.ui.shell
}
}
void _window_LocationChanged(object sender, EventArgs e) {
if (IsDocked) {
// It would be "better" to hook the window proc and prevent movement in the first place
// but this is easier to doo from the viewmodel
update_docked_location(_dock);
}
}
// Used to restore the work area if a crash occurs
private void restore_work_area() {
if (IsDocked) {
NativeMethods.SetWorkArea(_default_work_area);
}
}
public ICommand CloseCommand { get { return new DelegateCommand(_ => _window.Close()); } }
public ICommand MinimizeCommand { get { return new DelegateCommand(_ => _window.WindowState = System.Windows.WindowState.Minimized); } }
public ICommand SupportCommand => new DelegateCommand(_ => _error_service.show_support_window("", "Contact Support"));
public ICommand AboutCommand { get { return new DelegateCommand(_ => SparkCommands.ShowAboutSpark.execute(_bus)); } }
#region Docking
private Rect _default_work_area;
private Point _undocked_loc;
private Orientation _undocked_orientation;
private async void update_docking(DockState ostate, DockState nstate) {
// If wer'e called too early we can't get the monitor properties. We should get called again later
if (_window == null) return;
Rect current_workarea;
Rect new_workarea;
if (ostate == DockState.FLOATING) {
// If we're moving *from* FLOATING we need to save the current work area for this monitor
_default_work_area = current_workarea = NativeMethods.GetWorkArea(_window.hwnd());
_undocked_loc = new Point(_window.Left, _window.Top);
_undocked_orientation = Orientation;
}
else {
// If we're moving from one docked state to another we need to start from the original work area
current_workarea = _default_work_area;
}
// Update current_workarea
switch (nstate) {
case DockState.FLOATING:
NativeMethods.SetWorkArea(_default_work_area);
_window.SizeToContent = SizeToContent.WidthAndHeight;
_window.Left = _undocked_loc.X;
_window.Top = _undocked_loc.Y;
Orientation = _undocked_orientation;
break;
case DockState.LEFT:
Orientation = System.Windows.Controls.Orientation.Vertical;
_window.SizeToContent = SizeToContent.Width;
_window.Height = current_workarea.Height;
await _window.FromEvent<object, EventArgs>("LayoutUpdated");
new_workarea = new Rect(
current_workarea.Left + _window.ActualWidth,
current_workarea.Top,
current_workarea.Width - _window.ActualWidth,
current_workarea.Height);
NativeMethods.SetWorkArea(new_workarea);
break;
case DockState.RIGHT:
Orientation = System.Windows.Controls.Orientation.Vertical;
_window.SizeToContent = SizeToContent.Width;
_window.Height = current_workarea.Height;
await _window.FromEvent<object, EventArgs>("LayoutUpdated");
new_workarea = new Rect(
current_workarea.Left,
current_workarea.Top,
current_workarea.Width - _window.ActualWidth,
current_workarea.Height);
NativeMethods.SetWorkArea(new_workarea);
break;
case DockState.TOP:
Orientation = System.Windows.Controls.Orientation.Horizontal;
_window.SizeToContent = SizeToContent.Height;
_window.Width = current_workarea.Width;
await _window.FromEvent<object, EventArgs>("LayoutUpdated");
new_workarea = new Rect(
current_workarea.Left,
current_workarea.Top + _window.ActualHeight,
current_workarea.Width,
current_workarea.Height - _window.ActualHeight);
NativeMethods.SetWorkArea(new_workarea);
break;
case DockState.BOTTOM:
Orientation = System.Windows.Controls.Orientation.Horizontal;
_window.SizeToContent = SizeToContent.Height;
_window.Width = current_workarea.Width;
await _window.FromEvent<object, EventArgs>("LayoutUpdated");
new_workarea = new Rect(
current_workarea.Left,
current_workarea.Top,
current_workarea.Width,
current_workarea.Height - _window.ActualHeight);
NativeMethods.SetWorkArea(new_workarea);
break;
}
update_docked_location(nstate);
}
private void update_docked_location(DockState state) {
switch (state) {
case DockState.FLOATING: break;
case DockState.TOP:
case shell.DockState.LEFT:
_window.Top = _default_work_area.Top;
_window.Left = _default_work_area.Left;
break;
case DockState.RIGHT:
_window.Top = _default_work_area.Top;
_window.Left = _default_work_area.Right - _window.ActualWidth;
break;
case DockState.BOTTOM:
_window.Top = _default_work_area.Bottom - _window.ActualHeight;
_window.Left = _default_work_area.Left;
break;
}
}
#endregion
#region ILauncher
public WindowPosition get_position() {
var pos = _window.get_position();
pos.horizontal = this.Orientation == System.Windows.Controls.Orientation.Horizontal;
pos.horizontal = this.Orientation == Orientation.Horizontal;
pos.always_on_top = _topmost;
pos.dock = DockState;
pos.show_text = ShowText;
return pos;
}
public async void set_position(WindowPosition pos) {
public void set_position(WindowPosition pos) {
Logger.assert(_window == null);
_window = new Launcher(this);
@@ -285,21 +121,12 @@ namespace mbts.ui.shell
_window.Closing += (s, e) => {
NativeMethods.PostMessage(NativeMethods.HWND_BROADCAST, NativeMethods.WM_SHELL_TERMINATE, IntPtr.Zero, IntPtr.Zero);
restore_work_area();
closing?.Invoke(e);
};
if (_shown) {
show();
}
// Wait for the window to be created before we dock it
if (pos != null) {
if (!_window.IsInitialized) {
await _window.FromEvent<object, EventArgs>("SourceInitialized");
}
DockState = pos.dock;
}
}
public void show() {