2020-08-17 10:00:56 -07:00
|
|
|
// Copyright (c) Microsoft Corporation
|
|
|
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
|
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
|
|
|
|
|
|
using System;
|
2021-01-27 21:33:52 +03:00
|
|
|
using System.Collections.Generic;
|
2021-10-11 17:39:01 +02:00
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.IO;
|
2020-08-17 10:00:56 -07:00
|
|
|
using System.Windows;
|
2021-08-10 14:40:08 +03:00
|
|
|
using System.Windows.Automation;
|
|
|
|
|
using System.Windows.Automation.Peers;
|
2020-08-17 10:00:56 -07:00
|
|
|
using System.Windows.Controls;
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
using FancyZonesEditor.Models;
|
2021-01-27 21:33:52 +03:00
|
|
|
using FancyZonesEditor.Utils;
|
|
|
|
|
using ModernWpf.Controls;
|
2020-08-17 10:00:56 -07:00
|
|
|
|
|
|
|
|
namespace FancyZonesEditor
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Interaction logic for MainWindow.xaml
|
|
|
|
|
/// </summary>
|
2021-01-27 21:33:52 +03:00
|
|
|
public partial class MainWindow : Window
|
2020-08-17 10:00:56 -07:00
|
|
|
{
|
2021-01-27 21:33:52 +03:00
|
|
|
private const int DefaultWrapPanelItemSize = 164;
|
|
|
|
|
private const int SmallWrapPanelItemSize = 164;
|
2020-11-17 11:38:19 +03:00
|
|
|
private const int MinimalForDefaultWrapPanelsHeight = 900;
|
|
|
|
|
|
|
|
|
|
private readonly MainWindowSettingsModel _settings = ((App)Application.Current).MainWindowSettings;
|
2021-05-14 09:54:34 -07:00
|
|
|
private LayoutModel _backup;
|
2020-08-17 10:00:56 -07:00
|
|
|
|
2021-05-14 09:54:34 -07:00
|
|
|
private ContentDialog _openedDialog;
|
2021-08-10 14:40:08 +03:00
|
|
|
private TextBlock _createLayoutAnnounce;
|
2020-08-17 10:00:56 -07:00
|
|
|
|
2020-11-17 11:38:19 +03:00
|
|
|
public int WrapPanelItemSize { get; set; } = DefaultWrapPanelItemSize;
|
2020-08-17 10:00:56 -07:00
|
|
|
|
2020-11-17 11:38:19 +03:00
|
|
|
public MainWindow(bool spanZonesAcrossMonitors, Rect workArea)
|
2020-08-17 10:00:56 -07:00
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2021-08-10 14:40:08 +03:00
|
|
|
_createLayoutAnnounce = (TextBlock)FindName("LayoutCreationAnnounce");
|
2020-08-17 10:00:56 -07:00
|
|
|
DataContext = _settings;
|
|
|
|
|
|
|
|
|
|
KeyUp += MainWindow_KeyUp;
|
|
|
|
|
|
2021-08-23 14:29:00 +03:00
|
|
|
// Prevent closing the dialog with enter
|
|
|
|
|
PreviewKeyDown += (object sender, KeyEventArgs e) =>
|
|
|
|
|
{
|
|
|
|
|
if (e.Key == Key.Enter && _openedDialog != null && _openedDialog.IsVisible)
|
|
|
|
|
{
|
|
|
|
|
var source = e.OriginalSource as RadioButton;
|
|
|
|
|
if (source != null && source.IsChecked != true)
|
|
|
|
|
{
|
|
|
|
|
source.IsChecked = true;
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-11-17 11:38:19 +03:00
|
|
|
if (spanZonesAcrossMonitors)
|
|
|
|
|
{
|
|
|
|
|
WindowStartupLocation = WindowStartupLocation.CenterScreen;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (workArea.Height < MinimalForDefaultWrapPanelsHeight || App.Overlay.MultiMonitorMode)
|
2020-08-17 10:00:56 -07:00
|
|
|
{
|
2020-11-17 11:38:19 +03:00
|
|
|
WrapPanelItemSize = SmallWrapPanelItemSize;
|
2020-08-17 10:00:56 -07:00
|
|
|
}
|
2021-01-27 21:33:52 +03:00
|
|
|
|
2021-02-02 11:16:03 +03:00
|
|
|
MaxWidth = workArea.Width;
|
|
|
|
|
MaxHeight = workArea.Height;
|
2021-01-27 21:33:52 +03:00
|
|
|
SizeToContent = SizeToContent.WidthAndHeight;
|
2020-08-17 10:00:56 -07:00
|
|
|
}
|
|
|
|
|
|
2020-11-17 11:38:19 +03:00
|
|
|
public void Update()
|
|
|
|
|
{
|
|
|
|
|
DataContext = _settings;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-17 10:00:56 -07:00
|
|
|
private void MainWindow_KeyUp(object sender, KeyEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.Key == Key.Escape)
|
|
|
|
|
{
|
2021-05-04 16:18:06 +02:00
|
|
|
CloseDialog(sender);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LayoutItem_MouseDoubleClick(object sender, MouseButtonEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
CloseDialog(sender);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CloseDialog(object sender)
|
|
|
|
|
{
|
|
|
|
|
if (_openedDialog != null)
|
|
|
|
|
{
|
|
|
|
|
_openedDialog.Hide();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
OnClosing(sender, null);
|
2020-08-17 10:00:56 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DecrementZones_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
2021-01-27 21:33:52 +03:00
|
|
|
var mainEditor = App.Overlay;
|
|
|
|
|
if (!(mainEditor.CurrentDataContext is LayoutModel model))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (model.TemplateZoneCount > 1)
|
2020-08-17 10:00:56 -07:00
|
|
|
{
|
2021-01-27 21:33:52 +03:00
|
|
|
model.TemplateZoneCount--;
|
2020-08-17 10:00:56 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void IncrementZones_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
2021-01-27 21:33:52 +03:00
|
|
|
var mainEditor = App.Overlay;
|
|
|
|
|
if (!(mainEditor.CurrentDataContext is LayoutModel model))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-29 15:10:37 +03:00
|
|
|
if (model.IsZoneAddingAllowed)
|
2020-08-17 10:00:56 -07:00
|
|
|
{
|
2021-01-27 21:33:52 +03:00
|
|
|
model.TemplateZoneCount++;
|
2020-08-17 10:00:56 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-27 21:33:52 +03:00
|
|
|
private void LayoutItem_MouseEnter(object sender, MouseEventArgs e)
|
2020-08-17 10:00:56 -07:00
|
|
|
{
|
2021-01-27 21:33:52 +03:00
|
|
|
// Select(((Grid)sender).DataContext as LayoutModel);
|
2020-08-17 10:00:56 -07:00
|
|
|
}
|
|
|
|
|
|
2020-11-10 16:24:20 +01:00
|
|
|
private void LayoutItem_Focused(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
2021-01-27 21:33:52 +03:00
|
|
|
// Ignore focus on Edit button click
|
|
|
|
|
if (e.Source is Button)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-10 16:24:20 +01:00
|
|
|
Select(((Border)sender).DataContext as LayoutModel);
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-27 21:33:52 +03:00
|
|
|
private void LayoutItem_KeyDown(object sender, KeyEventArgs e)
|
2020-11-10 16:24:20 +01:00
|
|
|
{
|
|
|
|
|
if (e.Key == Key.Return || e.Key == Key.Space)
|
|
|
|
|
{
|
|
|
|
|
// When certain layout item (template or custom) is focused through keyboard and user
|
|
|
|
|
// presses Enter or Space key, layout will be applied.
|
|
|
|
|
Apply();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-17 10:00:56 -07:00
|
|
|
private void Select(LayoutModel newSelection)
|
|
|
|
|
{
|
2021-01-27 21:33:52 +03:00
|
|
|
_settings.SetSelectedModel(newSelection);
|
|
|
|
|
App.Overlay.CurrentDataContext = newSelection;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async void NewLayoutButton_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
2021-10-05 12:55:23 +03:00
|
|
|
if (_openedDialog != null)
|
|
|
|
|
{
|
|
|
|
|
// another dialog already opened
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-27 21:33:52 +03:00
|
|
|
string defaultNamePrefix = FancyZonesEditor.Properties.Resources.Default_Custom_Layout_Name;
|
|
|
|
|
int maxCustomIndex = 0;
|
|
|
|
|
foreach (LayoutModel customModel in MainWindowSettingsModel.CustomModels)
|
2020-08-17 10:00:56 -07:00
|
|
|
{
|
2021-01-27 21:33:52 +03:00
|
|
|
string name = customModel.Name;
|
|
|
|
|
if (name.StartsWith(defaultNamePrefix))
|
|
|
|
|
{
|
|
|
|
|
if (int.TryParse(name.Substring(defaultNamePrefix.Length), out int i))
|
|
|
|
|
{
|
|
|
|
|
if (maxCustomIndex < i)
|
|
|
|
|
{
|
|
|
|
|
maxCustomIndex = i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-17 10:00:56 -07:00
|
|
|
}
|
|
|
|
|
|
2021-01-27 21:33:52 +03:00
|
|
|
LayoutNameText.Text = defaultNamePrefix + " " + (++maxCustomIndex);
|
|
|
|
|
GridLayoutRadioButton.IsChecked = true;
|
|
|
|
|
GridLayoutRadioButton.Focus();
|
|
|
|
|
await NewLayoutDialog.ShowAsync();
|
2020-08-17 10:00:56 -07:00
|
|
|
}
|
|
|
|
|
|
2021-01-27 21:33:52 +03:00
|
|
|
private void DuplicateLayout_Click(object sender, RoutedEventArgs e)
|
2020-08-17 10:00:56 -07:00
|
|
|
{
|
2021-01-27 21:33:52 +03:00
|
|
|
EditLayoutDialog.Hide();
|
|
|
|
|
|
2020-11-17 11:38:19 +03:00
|
|
|
var mainEditor = App.Overlay;
|
|
|
|
|
if (!(mainEditor.CurrentDataContext is LayoutModel model))
|
2020-08-17 10:00:56 -07:00
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
model.IsSelected = false;
|
|
|
|
|
|
2021-01-27 21:33:52 +03:00
|
|
|
// make a copy
|
|
|
|
|
model = model.Clone();
|
|
|
|
|
mainEditor.CurrentDataContext = model;
|
2020-08-17 10:00:56 -07:00
|
|
|
|
2021-01-27 21:33:52 +03:00
|
|
|
string name = model.Name;
|
|
|
|
|
var index = name.LastIndexOf('(');
|
|
|
|
|
if (index != -1)
|
2020-08-17 10:00:56 -07:00
|
|
|
{
|
2021-01-27 21:33:52 +03:00
|
|
|
name = name.Remove(index);
|
|
|
|
|
name = name.TrimEnd();
|
|
|
|
|
}
|
2020-08-17 10:00:56 -07:00
|
|
|
|
2021-08-10 14:40:08 +03:00
|
|
|
AnnounceSuccessfulLayoutCreation(name);
|
2021-01-27 21:33:52 +03:00
|
|
|
int maxCustomIndex = 0;
|
|
|
|
|
foreach (LayoutModel customModel in MainWindowSettingsModel.CustomModels)
|
|
|
|
|
{
|
|
|
|
|
string customModelName = customModel.Name;
|
|
|
|
|
if (customModelName.StartsWith(name))
|
2020-08-17 10:00:56 -07:00
|
|
|
{
|
2021-01-27 21:33:52 +03:00
|
|
|
int openBraceIndex = customModelName.LastIndexOf('(');
|
|
|
|
|
int closeBraceIndex = customModelName.LastIndexOf(')');
|
|
|
|
|
if (openBraceIndex != -1 && closeBraceIndex != -1)
|
2020-08-17 10:00:56 -07:00
|
|
|
{
|
2021-01-27 21:33:52 +03:00
|
|
|
string indexSubstring = customModelName.Substring(openBraceIndex + 1, closeBraceIndex - openBraceIndex - 1);
|
|
|
|
|
|
|
|
|
|
if (int.TryParse(indexSubstring, out int i))
|
2020-08-17 10:00:56 -07:00
|
|
|
{
|
|
|
|
|
if (maxCustomIndex < i)
|
|
|
|
|
{
|
|
|
|
|
maxCustomIndex = i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-27 21:33:52 +03:00
|
|
|
model.Name = name + " (" + (++maxCustomIndex) + ')';
|
2020-08-17 10:00:56 -07:00
|
|
|
|
2021-01-27 21:33:52 +03:00
|
|
|
model.Persist();
|
|
|
|
|
|
|
|
|
|
App.Overlay.SetLayoutSettings(App.Overlay.Monitors[App.Overlay.CurrentDesktop], model);
|
|
|
|
|
App.FancyZonesEditorIO.SerializeZoneSettings();
|
2020-11-10 16:24:20 +01:00
|
|
|
}
|
|
|
|
|
|
2021-08-10 14:40:08 +03:00
|
|
|
private void AnnounceSuccessfulLayoutCreation(string name)
|
|
|
|
|
{
|
|
|
|
|
if (AutomationPeer.ListenerExists(AutomationEvents.MenuOpened))
|
|
|
|
|
{
|
|
|
|
|
var peer = UIElementAutomationPeer.FromElement(_createLayoutAnnounce);
|
|
|
|
|
AutomationProperties.SetName(_createLayoutAnnounce, name + " " + FancyZonesEditor.Properties.Resources.Layout_Creation_Announce);
|
|
|
|
|
peer?.RaiseAutomationEvent(AutomationEvents.MenuOpened);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-10 16:24:20 +01:00
|
|
|
private void Apply()
|
2020-08-17 10:00:56 -07:00
|
|
|
{
|
2020-11-17 11:38:19 +03:00
|
|
|
var mainEditor = App.Overlay;
|
|
|
|
|
if (mainEditor.CurrentDataContext is LayoutModel model)
|
2020-08-17 10:00:56 -07:00
|
|
|
{
|
2021-01-27 21:33:52 +03:00
|
|
|
_settings.SetAppliedModel(model);
|
|
|
|
|
App.Overlay.SetLayoutSettings(App.Overlay.Monitors[App.Overlay.CurrentDesktop], model);
|
|
|
|
|
App.FancyZonesEditorIO.SerializeZoneSettings();
|
2020-08-17 10:00:56 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnClosing(object sender, EventArgs e)
|
|
|
|
|
{
|
2021-08-05 19:29:54 +03:00
|
|
|
CancelLayoutChanges();
|
|
|
|
|
|
2021-01-27 21:33:52 +03:00
|
|
|
App.FancyZonesEditorIO.SerializeZoneSettings();
|
2020-11-17 11:38:19 +03:00
|
|
|
App.Overlay.CloseLayoutWindow();
|
2020-11-19 10:03:22 +03:00
|
|
|
App.Current.Shutdown();
|
2020-08-17 10:00:56 -07:00
|
|
|
}
|
|
|
|
|
|
2021-01-27 21:33:52 +03:00
|
|
|
private void DeleteLayout_Click(object sender, RoutedEventArgs e)
|
2020-08-17 10:00:56 -07:00
|
|
|
{
|
2021-01-27 21:33:52 +03:00
|
|
|
EditLayoutDialog.Hide();
|
|
|
|
|
DeleteLayout((FrameworkElement)sender);
|
2020-08-17 10:00:56 -07:00
|
|
|
}
|
|
|
|
|
|
2021-01-27 21:33:52 +03:00
|
|
|
private async void EditLayout_Click(object sender, RoutedEventArgs e)
|
2020-08-17 10:00:56 -07:00
|
|
|
{
|
2021-08-04 15:23:28 +01:00
|
|
|
// Avoid trying to open the same dialog twice.
|
2021-08-23 18:20:04 +03:00
|
|
|
if (_openedDialog != null)
|
2021-01-27 21:33:52 +03:00
|
|
|
{
|
2021-08-23 18:20:04 +03:00
|
|
|
return;
|
|
|
|
|
}
|
2021-08-04 15:23:28 +01:00
|
|
|
|
2021-08-23 18:20:04 +03:00
|
|
|
var dataContext = ((FrameworkElement)sender).DataContext;
|
|
|
|
|
Select((LayoutModel)dataContext);
|
2021-01-27 21:33:52 +03:00
|
|
|
|
2021-08-23 18:20:04 +03:00
|
|
|
if (_settings.SelectedModel is GridLayoutModel grid)
|
|
|
|
|
{
|
2021-08-25 14:26:55 +03:00
|
|
|
_backup = new GridLayoutModel(grid);
|
2021-08-23 18:20:04 +03:00
|
|
|
}
|
|
|
|
|
else if (_settings.SelectedModel is CanvasLayoutModel canvas)
|
|
|
|
|
{
|
2021-08-25 14:26:55 +03:00
|
|
|
_backup = new CanvasLayoutModel(canvas);
|
2021-08-04 15:23:28 +01:00
|
|
|
}
|
2021-08-23 18:20:04 +03:00
|
|
|
|
|
|
|
|
await EditLayoutDialog.ShowAsync();
|
2020-08-17 10:00:56 -07:00
|
|
|
}
|
|
|
|
|
|
2021-01-27 21:33:52 +03:00
|
|
|
private void EditZones_Click(object sender, RoutedEventArgs e)
|
2020-08-17 10:00:56 -07:00
|
|
|
{
|
2021-05-04 13:49:38 +02:00
|
|
|
var dataContext = ((FrameworkElement)sender).DataContext;
|
|
|
|
|
Select((LayoutModel)dataContext);
|
2021-01-27 21:33:52 +03:00
|
|
|
EditLayoutDialog.Hide();
|
|
|
|
|
var mainEditor = App.Overlay;
|
|
|
|
|
if (!(mainEditor.CurrentDataContext is LayoutModel model))
|
2020-08-17 10:00:56 -07:00
|
|
|
{
|
2021-01-27 21:33:52 +03:00
|
|
|
return;
|
2020-08-17 10:00:56 -07:00
|
|
|
}
|
|
|
|
|
|
2021-01-27 21:33:52 +03:00
|
|
|
_settings.SetSelectedModel(model);
|
|
|
|
|
|
|
|
|
|
Hide();
|
|
|
|
|
mainEditor.OpenEditor(model);
|
2020-08-17 10:00:56 -07:00
|
|
|
}
|
2020-11-17 11:38:19 +03:00
|
|
|
|
|
|
|
|
private void ScrollViewer_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
ScrollViewer scrollviewer = sender as ScrollViewer;
|
|
|
|
|
if (e.Delta > 0)
|
|
|
|
|
{
|
|
|
|
|
scrollviewer.LineLeft();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
scrollviewer.LineRight();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-27 21:33:52 +03:00
|
|
|
private void NewLayoutDialog_PrimaryButtonClick(ModernWpf.Controls.ContentDialog sender, ModernWpf.Controls.ContentDialogButtonClickEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
LayoutModel selectedLayoutModel;
|
|
|
|
|
|
|
|
|
|
if (GridLayoutRadioButton.IsChecked == true)
|
|
|
|
|
{
|
|
|
|
|
GridLayoutModel gridModel = new GridLayoutModel(LayoutNameText.Text, LayoutType.Custom)
|
|
|
|
|
{
|
|
|
|
|
Rows = 1,
|
|
|
|
|
RowPercents = new List<int>(1) { GridLayoutModel.GridMultiplier },
|
|
|
|
|
};
|
|
|
|
|
selectedLayoutModel = gridModel;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-03-11 10:50:53 +01:00
|
|
|
var area = App.Overlay.WorkArea;
|
|
|
|
|
CanvasLayoutModel canvasModel = new CanvasLayoutModel(LayoutNameText.Text, LayoutType.Custom, (int)area.Width, (int)area.Height);
|
2021-02-03 15:56:08 +03:00
|
|
|
canvasModel.AddZone();
|
|
|
|
|
selectedLayoutModel = canvasModel;
|
2021-01-27 21:33:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
selectedLayoutModel.InitTemplateZones();
|
|
|
|
|
|
2021-02-01 20:54:29 +01:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Hide();
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// See https://github.com/microsoft/PowerToys/issues/9396
|
|
|
|
|
Hide();
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-27 21:33:52 +03:00
|
|
|
App.Overlay.CurrentDataContext = selectedLayoutModel;
|
2021-02-01 20:54:29 +01:00
|
|
|
App.Overlay.OpenEditor(selectedLayoutModel);
|
2021-01-27 21:33:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This is required to fix a WPF rendering bug when using custom chrome
|
|
|
|
|
private void OnContentRendered(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
InvalidateVisual();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// EditLayout: Cancel changes
|
|
|
|
|
private void EditLayoutDialog_SecondaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
|
2020-11-19 10:03:22 +03:00
|
|
|
{
|
2021-08-05 19:29:54 +03:00
|
|
|
CancelLayoutChanges();
|
2021-01-27 21:33:52 +03:00
|
|
|
Select(_settings.AppliedModel);
|
|
|
|
|
}
|
2020-11-19 10:03:22 +03:00
|
|
|
|
2021-01-27 21:33:52 +03:00
|
|
|
// EditLayout: Save changes
|
|
|
|
|
private void EditLayoutDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
var mainEditor = App.Overlay;
|
|
|
|
|
if (!(mainEditor.CurrentDataContext is LayoutModel model))
|
2020-11-19 10:03:22 +03:00
|
|
|
{
|
2021-01-27 21:33:52 +03:00
|
|
|
return;
|
2020-11-19 10:03:22 +03:00
|
|
|
}
|
|
|
|
|
|
2021-01-27 21:33:52 +03:00
|
|
|
_backup = null;
|
2020-11-19 10:03:22 +03:00
|
|
|
|
2021-01-27 21:33:52 +03:00
|
|
|
// update current settings
|
|
|
|
|
if (model == _settings.AppliedModel)
|
|
|
|
|
{
|
|
|
|
|
App.Overlay.SetLayoutSettings(App.Overlay.Monitors[App.Overlay.CurrentDesktop], model);
|
|
|
|
|
}
|
2020-11-19 10:03:22 +03:00
|
|
|
|
2021-01-27 21:33:52 +03:00
|
|
|
App.FancyZonesEditorIO.SerializeZoneSettings();
|
|
|
|
|
|
|
|
|
|
// reset selected model
|
|
|
|
|
Select(_settings.AppliedModel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async void DeleteLayout(FrameworkElement element)
|
|
|
|
|
{
|
2021-05-04 13:49:38 +02:00
|
|
|
var dialog = new ContentDialog()
|
2021-01-27 21:33:52 +03:00
|
|
|
{
|
2021-05-04 13:49:38 +02:00
|
|
|
Title = Properties.Resources.Are_You_Sure,
|
|
|
|
|
Content = Properties.Resources.Are_You_Sure_Description,
|
|
|
|
|
PrimaryButtonText = Properties.Resources.Delete,
|
|
|
|
|
SecondaryButtonText = Properties.Resources.Cancel,
|
2021-01-27 21:33:52 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var result = await dialog.ShowAsync();
|
|
|
|
|
if (result == ContentDialogResult.Primary)
|
2020-11-19 10:03:22 +03:00
|
|
|
{
|
2021-01-27 21:33:52 +03:00
|
|
|
LayoutModel model = element.DataContext as LayoutModel;
|
|
|
|
|
|
2021-09-27 17:35:33 +03:00
|
|
|
if (_backup != null && model.Guid == _backup.Guid)
|
2021-09-23 18:24:24 +03:00
|
|
|
{
|
|
|
|
|
_backup = null;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-27 21:33:52 +03:00
|
|
|
if (model == _settings.AppliedModel)
|
|
|
|
|
{
|
|
|
|
|
_settings.SetAppliedModel(_settings.BlankModel);
|
|
|
|
|
Select(_settings.BlankModel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var monitor in App.Overlay.Monitors)
|
|
|
|
|
{
|
|
|
|
|
if (monitor.Settings.ZonesetUuid == model.Uuid)
|
|
|
|
|
{
|
|
|
|
|
App.Overlay.SetLayoutSettings(monitor, _settings.BlankModel);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
App.FancyZonesEditorIO.SerializeZoneSettings();
|
|
|
|
|
model.Delete();
|
2020-11-19 10:03:22 +03:00
|
|
|
}
|
|
|
|
|
}
|
2021-01-27 21:33:52 +03:00
|
|
|
|
|
|
|
|
private void Dialog_Opened(ContentDialog sender, ContentDialogOpenedEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
_openedDialog = sender;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Dialog_Closed(ContentDialog sender, ContentDialogClosedEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
_openedDialog = null;
|
|
|
|
|
}
|
2021-04-20 14:56:18 +02:00
|
|
|
|
|
|
|
|
private void EditDialogNumberBox_KeyDown(object sender, KeyEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// Making sure that pressing Enter when changing values in a NumberBox will not close the edit dialog.
|
|
|
|
|
if (e.Key == Key.Enter)
|
|
|
|
|
{
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-05-04 13:49:38 +02:00
|
|
|
|
|
|
|
|
private void Layout_ItemClick(object sender, ItemClickEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Select(e.ClickedItem as LayoutModel);
|
|
|
|
|
Apply();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Monitor_ItemClick(object sender, ItemClickEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
monitorViewModel.SelectCommand.Execute(e.ClickedItem as MonitorInfoModel);
|
|
|
|
|
}
|
2021-05-04 15:36:03 +02:00
|
|
|
|
|
|
|
|
private void ComboBox_KeyDown(object sender, KeyEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.Key == Key.Enter || e.Key == Key.Space)
|
|
|
|
|
{
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
ComboBox selectedComboBox = sender as ComboBox;
|
|
|
|
|
if (!selectedComboBox.IsDropDownOpen)
|
|
|
|
|
{
|
|
|
|
|
selectedComboBox.IsDropDownOpen = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-08-04 14:50:32 +02:00
|
|
|
|
|
|
|
|
private void TextBox_GotKeyboardFocus(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
TextBox tb = sender as TextBox;
|
|
|
|
|
tb.SelectionStart = tb.Text.Length;
|
|
|
|
|
}
|
2021-08-05 19:29:54 +03:00
|
|
|
|
|
|
|
|
private void CancelLayoutChanges()
|
|
|
|
|
{
|
|
|
|
|
if (_backup != null)
|
|
|
|
|
{
|
|
|
|
|
_settings.RestoreSelectedModel(_backup);
|
|
|
|
|
_backup = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-08-12 14:17:44 +01:00
|
|
|
|
|
|
|
|
private void NumberBox_Loaded(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// The TextBox inside a NumberBox doesn't inherit the Automation Properties name, so we have to set it.
|
|
|
|
|
var numberBox = sender as NumberBox;
|
|
|
|
|
const string numberBoxTextBoxName = "InputBox"; // Text box template part name given by ModernWPF.
|
|
|
|
|
numberBox.ApplyTemplate(); // Apply template to be able to change child's property.
|
|
|
|
|
var numberBoxTextBox = numberBox.Template.FindName(numberBoxTextBoxName, numberBox) as TextBox;
|
|
|
|
|
numberBoxTextBox.SetValue(AutomationProperties.NameProperty, numberBox.GetValue(AutomationProperties.NameProperty));
|
|
|
|
|
}
|
2021-10-11 17:39:01 +02:00
|
|
|
|
|
|
|
|
private void SettingsBtn_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var assemblyPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
|
|
|
|
|
var fullPath = Directory.GetParent(assemblyPath).FullName;
|
|
|
|
|
Process.Start(new ProcessStartInfo(fullPath + "\\..\\PowerToys.exe") { Arguments = "--open-settings=FancyZones" });
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-17 10:00:56 -07:00
|
|
|
}
|
|
|
|
|
}
|