File size: 7,983 Bytes
8c763fb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | // Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System;
using System.Windows;
using System.Windows.Input;
using Microsoft.Management.UI.Internal;
using Microsoft.Management.UI.Internal.ShowCommand;
namespace Microsoft.PowerShell.Commands.ShowCommandInternal
{
/// <summary>
/// Interaction logic for CmdletGUI.xaml.
/// </summary>
public partial class ShowAllModulesWindow : Window
{
/// <summary>
/// private constants for ZoomLevel.
/// </summary>
private double zoomLevel = 1.0;
/// <summary>
/// Zoom Increments.
/// </summary>
private const double ZOOM_INCREMENT = 0.2;
/// <summary>
/// Max ZoomLevel.
/// </summary>
private const double ZOOM_MAX = 3.0;
/// <summary>
/// Min ZoomLevel.
/// </summary>
private const double ZOOM_MIN = 0.5;
#region Construction and Destructor
/// <summary>
/// Initializes a new instance of the ShowAllModulesWindow class.
/// </summary>
public ShowAllModulesWindow()
{
this.InitializeComponent();
if (this.AllModulesControl != null && this.AllModulesControl.ShowModuleControl != null)
{
this.AllModulesControl.ShowModuleControl.Owner = this;
}
this.SizeChanged += this.ShowAllModulesWindow_SizeChanged;
this.LocationChanged += this.ShowAllModulesWindow_LocationChanged;
this.StateChanged += this.ShowAllModulesWindow_StateChanged;
this.Loaded += this.ShowAllModulesWindow_Loaded;
RoutedCommand plusSettings = new RoutedCommand();
KeyGestureConverter keyGestureConverter = new KeyGestureConverter();
try
{
plusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString(UICultureResources.ZoomIn1Shortcut));
plusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString(UICultureResources.ZoomIn2Shortcut));
plusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString(UICultureResources.ZoomIn3Shortcut));
plusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString(UICultureResources.ZoomIn4Shortcut));
CommandBindings.Add(new CommandBinding(plusSettings, ZoomEventHandlerPlus));
}
catch (NotSupportedException)
{
// localized has a problematic string - going to default
plusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString("Ctrl+Add"));
plusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString("Ctrl+Plus"));
CommandBindings.Add(new CommandBinding(plusSettings, ZoomEventHandlerPlus));
}
RoutedCommand minusSettings = new RoutedCommand();
try
{
minusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString(UICultureResources.ZoomOut1Shortcut));
minusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString(UICultureResources.ZoomOut2Shortcut));
minusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString(UICultureResources.ZoomOut3Shortcut));
minusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString(UICultureResources.ZoomOut4Shortcut));
CommandBindings.Add(new CommandBinding(minusSettings, ZoomEventHandlerMinus));
}
catch (NotSupportedException)
{
// localized has a problematic string - going to default
minusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString("Ctrl+Subtract"));
minusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString("Ctrl+Minus"));
CommandBindings.Add(new CommandBinding(minusSettings, ZoomEventHandlerMinus));
}
}
/// <summary>
/// Saves the user settings.
/// </summary>
/// <param name="e">Event arguments.</param>
protected override void OnClosed(System.EventArgs e)
{
ShowCommandSettings.Default.Save();
base.OnClosed(e);
}
/// <summary>
/// Sets the focus on the CommandName control.
/// </summary>
/// <param name="sender">Event sender.</param>
/// <param name="e">Event arguments.</param>
private void ShowAllModulesWindow_Loaded(object sender, RoutedEventArgs e)
{
this.AllModulesControl.CommandName.Focus();
}
/// <summary>
/// Saves size changes in user settings.
/// </summary>
/// <param name="sender">Event sender.</param>
/// <param name="e">Event arguments.</param>
private void ShowAllModulesWindow_SizeChanged(object sender, SizeChangedEventArgs e)
{
ShowCommandSettings.Default.ShowCommandsWidth = this.Width;
ShowCommandSettings.Default.ShowCommandsHeight = this.Height;
}
/// <summary>
/// Saves position changes in user settings.
/// </summary>
/// <param name="sender">Event sender.</param>
/// <param name="e">Event arguments.</param>
private void ShowAllModulesWindow_LocationChanged(object sender, System.EventArgs e)
{
ShowCommandSettings.Default.ShowCommandsTop = this.Top;
ShowCommandSettings.Default.ShowCommandsLeft = this.Left;
}
/// <summary>
/// Updates the user setting with window state.
/// </summary>
/// <param name="sender">Event sender.</param>
/// <param name="e">Event arguments.</param>
private void ShowAllModulesWindow_StateChanged(object sender, System.EventArgs e)
{
ShowCommandSettings.Default.ShowCommandsWindowMaximized = this.WindowState == WindowState.Maximized;
}
/// <summary>
/// Implements ZoomIn.
/// </summary>
/// <param name="sender">.</param>
/// <param name="e">.</param>
private void ZoomEventHandlerPlus(object sender, ExecutedRoutedEventArgs e)
{
AllModulesViewModel viewModel = this.DataContext as AllModulesViewModel;
if (viewModel == null)
{
return;
}
if (this.zoomLevel == 0)
{
this.zoomLevel = 1;
}
if (this.zoomLevel < ZOOM_MAX)
{
// ViewModel applies ZoomLevel after dividing it by 100, So multiply it by 100 and then later reset to normal by dividing for next zoom
this.zoomLevel = (this.zoomLevel + ZOOM_INCREMENT) * 100;
viewModel.ZoomLevel = this.zoomLevel;
this.zoomLevel /= 100;
}
}
/// <summary>
/// Implements ZoomOut.
/// </summary>
/// <param name="sender">.</param>
/// <param name="e">.</param>
private void ZoomEventHandlerMinus(object sender, ExecutedRoutedEventArgs e)
{
AllModulesViewModel viewModel = this.DataContext as AllModulesViewModel;
if (viewModel == null)
{
return;
}
if (this.zoomLevel >= ZOOM_MIN)
{
// ViewModel applies ZoomLevel after dividing it by 100, So multiply it by 100 and then later reset to normal by dividing it for next zoom
this.zoomLevel = (this.zoomLevel - ZOOM_INCREMENT) * 100;
viewModel.ZoomLevel = this.zoomLevel;
this.zoomLevel /= 100;
}
}
#endregion
}
}
|