File size: 3,349 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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Windows;
using System.Windows.Controls;

namespace Microsoft.PowerShell.Commands.ShowCommandInternal
{
    /// <summary>
    /// Interaction logic for CmdletControl.xaml.
    /// </summary>
    public partial class CmdletControl : UserControl
    {
        /// <summary>
        /// Field used for the CurrentCommandViewModel parameter.
        /// </summary>
        private CommandViewModel currentCommandViewModel;

        #region Construction and Destructor
        /// <summary>
        /// Initializes a new instance of the CmdletControl class.
        /// </summary>
        public CmdletControl()
        {
            InitializeComponent();
            this.NotImportedControl.ImportModuleButton.Click += ImportModuleButton_Click;
            this.ParameterSetTabControl.DataContextChanged += new DependencyPropertyChangedEventHandler(this.ParameterSetTabControl_DataContextChanged);
            this.KeyDown += this.CmdletControl_KeyDown;
            this.helpButton.innerButton.Click += this.HelpButton_Click;
        }
        #endregion

        #region Properties
        /// <summary>
        /// Gets the owner of the ViewModel.
        /// </summary>
        private CommandViewModel CurrentCommandViewModel
        {
            get { return this.currentCommandViewModel; }
        }
        #endregion

        #region Private Events

        /// <summary>
        /// DataContextChanged event.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void ParameterSetTabControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (this.DataContext == null)
            {
                return;
            }

            CommandViewModel viewModel = (CommandViewModel)this.DataContext;
            this.currentCommandViewModel = viewModel;

            if (viewModel.ParameterSets.Count == 0)
            {
                return;
            }

            this.ParameterSetTabControl.SelectedItem = viewModel.ParameterSets[0];
        }

        /// <summary>
        /// Key down event for user press F1 button.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void CmdletControl_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if (e.Key == System.Windows.Input.Key.F1)
            {
                this.CurrentCommandViewModel.OpenHelpWindow();
            }
        }

        /// <summary>
        /// Help button event.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void HelpButton_Click(object sender, RoutedEventArgs e)
        {
            this.CurrentCommandViewModel.OpenHelpWindow();
        }

        /// <summary>
        /// Import Module Button event.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void ImportModuleButton_Click(object sender, RoutedEventArgs e)
        {
            this.CurrentCommandViewModel.OnImportModule();
        }
        #endregion
    }
}