[FZ Editor] Switch between zone and dialog with Ctrl + Tab (#11435)

* focus zone by ctrl + tab
* focus back
This commit is contained in:
Seraphima Zykova 2021-05-25 07:59:34 +03:00 committed by GitHub
parent b79ab9cd5d
commit 6821c50ffe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 62 additions and 12 deletions

View File

@ -4,6 +4,7 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using FancyZonesEditor.Models;
using FancyZonesEditor.Utils;
@ -23,6 +24,25 @@ namespace FancyZonesEditor
{
InitializeComponent();
Loaded += OnLoaded;
KeyDown += CanvasEditor_KeyDown;
}
private void CanvasEditor_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
{
if (e.Key == Key.Tab && (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)))
{
e.Handled = true;
App.Overlay.FocusEditorWindow();
}
}
public void FocusZone()
{
if (Preview.Children.Count > 0)
{
var canvas = Preview.Children[0] as CanvasZone;
canvas.FocusZone();
}
}
private void OnLoaded(object sender, RoutedEventArgs e)

View File

@ -18,6 +18,7 @@ namespace FancyZonesEditor
InitializeComponent();
KeyUp += CanvasEditorWindow_KeyUp;
KeyDown += CanvasEditorWindow_KeyDown;
_model = App.Overlay.CurrentDataContext as CanvasLayoutModel;
_stashedModel = (CanvasLayoutModel)_model.Clone();
@ -49,5 +50,14 @@ namespace FancyZonesEditor
OnCancel(sender, null);
}
}
private void CanvasEditorWindow_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Tab && (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)))
{
e.Handled = true;
App.Overlay.FocusEditor();
}
}
}
}

View File

@ -341,6 +341,11 @@ namespace FancyZonesEditor
public int ZoneIndex { get => zoneIndex; set => zoneIndex = value; }
public void FocusZone()
{
Keyboard.Focus(RootBorder);
}
private void NWResize_DragStarted(object sender, System.Windows.Controls.Primitives.DragStartedEventArgs e)
{
snappyX = NewMagneticSnapper(true, ResizeMode.BottomEdge);

View File

@ -14,7 +14,8 @@ namespace FancyZonesEditor
{
private MainWindow _mainWindow;
private LayoutPreview _layoutPreview;
private UserControl _editor;
private UserControl _editorLayout;
private EditorWindow _editorWindow;
public List<Monitor> Monitors { get; private set; }
@ -228,34 +229,32 @@ namespace FancyZonesEditor
_layoutPreview = null;
if (CurrentDataContext is GridLayoutModel)
{
_editor = new GridEditor();
_editorLayout = new GridEditor();
}
else if (CurrentDataContext is CanvasLayoutModel)
{
_editor = new CanvasEditor();
_editorLayout = new CanvasEditor();
}
CurrentLayoutWindow.Content = _editor;
EditorWindow window;
CurrentLayoutWindow.Content = _editorLayout;
if (model is GridLayoutModel)
{
window = new GridEditorWindow();
_editorWindow = new GridEditorWindow();
}
else
{
window = new CanvasEditorWindow();
_editorWindow = new CanvasEditorWindow();
}
window.Owner = Monitors[App.Overlay.CurrentDesktop].Window;
window.DataContext = model;
window.Show();
_editorWindow.Owner = Monitors[App.Overlay.CurrentDesktop].Window;
_editorWindow.DataContext = model;
_editorWindow.Show();
}
public void CloseEditor()
{
_editor = null;
_editorLayout = null;
_layoutPreview = new LayoutPreview
{
IsActualSize = true,
@ -267,6 +266,22 @@ namespace FancyZonesEditor
OpenMainWindow();
}
public void FocusEditor()
{
if (_editorLayout != null && _editorLayout is CanvasEditor canvasEditor)
{
canvasEditor.FocusZone();
}
}
public void FocusEditorWindow()
{
if (_editorWindow != null)
{
_editorWindow.Focus();
}
}
public void CloseLayoutWindow()
{
for (int i = 0; i < DesktopsCount; i++)