forked from killswitch1111/powerguivsx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPSCommandExplorerWindow.cs
More file actions
137 lines (123 loc) · 5.01 KB
/
Copy pathPSCommandExplorerWindow.cs
File metadata and controls
137 lines (123 loc) · 5.01 KB
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
using System;
using System.ComponentModel.Design;
using System.Runtime.InteropServices;
using System.Windows.Controls;
using EnvDTE;
using EnvDTE80;
using Microsoft.Internal.VisualStudio.PlatformUI;
using Microsoft.VisualStudio.PlatformUI;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using PowerShellTools.Common;
using PowerShellTools.Explorer.Search;
namespace PowerShellTools.Explorer
{
/// <summary>
/// This class implements the tool window exposed by this package and hosts a user control.
///
/// In Visual Studio tool windows are composed of a frame (implemented by the shell) and a pane,
/// usually implemented by the package implementer.
///
/// This class derives from the ToolWindowPane class provided from the MPF in order to use its
/// implementation of the IVsUIElementPane interface.
/// </summary>
[Guid("dd9b7693-1385-46a9-a054-06566904f861")]
public class PSCommandExplorerWindow : ToolWindowPane, IHostWindow
{
private readonly IDataProvider _dataProvider;
private readonly PSCommandExplorer _commandExplorer;
/// <summary>
/// Standard constructor for the tool window.
/// </summary>
public PSCommandExplorerWindow() :
base(null)
{
_dataProvider = new DataProvider();
_commandExplorer = new PSCommandExplorer(this, _dataProvider);
// Set the window title reading it from the resources.
this.Caption = Resources.ToolWindowTitle;
// Set the image that will appear on the tab of the window frame
// when docked with an other window
// The resource ID correspond to the one defined in the resx file
// while the Index is the offset in the bitmap strip. Each image in
// the strip being 16x16.
this.BitmapResourceID = 301;
this.BitmapIndex = 1;
// This is the user control hosted by the tool window; Note that, even if this class implements IDisposable,
// we are not calling Dispose on this object. This is because ToolWindowPane calls Dispose on
// the object returned by the Content property.
base.Content = new HostControl();
ShowCommandExplorer();
}
public HostControl ContentHost
{
get
{
return (HostControl)base.Content;
}
set
{
((HostControl)base.Content).Content = value;
}
}
public void ShowCommandExplorer()
{
SetCaption(string.Empty);
ContentHost.Content = _commandExplorer;
}
public void ShowParameterEditor(IPowerShellCommand command)
{
var view = new PSParameterEditor(this, _dataProvider);
ContentHost.Content = view;
((PSParameterEditorViewModel)view.DataContext).LoadCommand(command);
}
public void SetCaption(string caption)
{
if (string.IsNullOrWhiteSpace(caption))
{
Caption = Resources.ToolWindowTitle;
}
else
{
Caption = string.Format("{0} - {1}", Resources.ToolWindowTitle, caption);
}
}
public override bool SearchEnabled
{
get
{
return ContentHost.IsHostingSearchTarget;
}
}
public override IVsSearchTask CreateSearch(uint dwCookie, IVsSearchQuery pSearchQuery, IVsSearchCallback pSearchCallback)
{
ShowCommandExplorer();
ISearchTaskTarget searchTarget = ((UserControl)ContentHost.Content).DataContext as ISearchTaskTarget;
if (searchTarget == null || pSearchQuery == null || pSearchCallback == null)
{
return null;
}
return new SearchTask(dwCookie, pSearchQuery, pSearchCallback, searchTarget);
}
public override void ClearSearch()
{
ISearchTaskTarget searchTarget = ((UserControl)ContentHost.Content).DataContext as ISearchTaskTarget;
if (searchTarget != null)
{
searchTarget.ClearSearch();
}
}
public override void ProvideSearchSettings(IVsUIDataSource pSearchSettings)
{
Utilities.SetValue(pSearchSettings,
SearchSettingsDataSource.SearchStartTypeProperty.Name,
(uint)VSSEARCHSTARTTYPE.SST_DELAYED);
Utilities.SetValue(pSearchSettings,
SearchSettingsDataSource.SearchProgressTypeProperty.Name,
(uint)VSSEARCHPROGRESSTYPE.SPT_DETERMINATE);
Utilities.SetValue(pSearchSettings,
SearchSettingsDataSource.SearchWatermarkProperty.Name,
"Search PowerShell commands");
}
}
}