本文整理汇总了C#中VSITEMSELECTION类的典型用法代码示例。如果您正苦于以下问题:C# VSITEMSELECTION类的具体用法?C# VSITEMSELECTION怎么用?C# VSITEMSELECTION使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
VSITEMSELECTION类属于命名空间,在下文中一共展示了VSITEMSELECTION类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetProjectsOfCurrentSelections
static public IList<IVsProject> GetProjectsOfCurrentSelections()
{
List<IVsProject> results = new List<IVsProject>();
int hr = VSConstants.S_OK;
var selectionMonitor = _serviceProvider.GetService(typeof(SVsShellMonitorSelection)) as IVsMonitorSelection;
if (selectionMonitor == null)
{
Debug.Fail("Failed to get SVsShellMonitorSelection service.");
return results;
}
IntPtr hierarchyPtr = IntPtr.Zero;
uint itemID = 0;
IVsMultiItemSelect multiSelect = null;
IntPtr containerPtr = IntPtr.Zero;
hr = selectionMonitor.GetCurrentSelection(out hierarchyPtr, out itemID, out multiSelect, out containerPtr);
if (IntPtr.Zero != containerPtr)
{
Marshal.Release(containerPtr);
containerPtr = IntPtr.Zero;
}
Debug.Assert(hr == VSConstants.S_OK, "GetCurrentSelection failed.");
if (itemID == (uint)VSConstants.VSITEMID.Selection)
{
uint itemCount = 0;
int fSingleHierarchy = 0;
hr = multiSelect.GetSelectionInfo(out itemCount, out fSingleHierarchy);
Debug.Assert(hr == VSConstants.S_OK, "GetSelectionInfo failed.");
VSITEMSELECTION[] items = new VSITEMSELECTION[itemCount];
hr = multiSelect.GetSelectedItems(0, itemCount, items);
Debug.Assert(hr == VSConstants.S_OK, "GetSelectedItems failed.");
foreach (VSITEMSELECTION item in items)
{
IVsProject project = GetProjectOfItem(item.pHier, item.itemid);
if (!results.Contains(project))
{
results.Add(project);
}
}
}
else
{
// case where no visible project is open (single file)
if (hierarchyPtr != IntPtr.Zero)
{
IVsHierarchy hierarchy = (IVsHierarchy)Marshal.GetUniqueObjectForIUnknown(hierarchyPtr);
results.Add(GetProjectOfItem(hierarchy, itemID));
}
}
return results;
}
示例2: SourceImage
public SourceImage(VSITEMSELECTION item)
{
this.item = item;
this.features = new ObservableCollection<OutputFeature>();
InitSourcePathAndScale();
InitSourceImage();
OutputHelpers.PopulateFeatures(this);
this.PostInitialize();
}
示例3: GetSelectedProjects
public Project[] GetSelectedProjects()
{
IntPtr hierarchyPointer, selectionContainerPointer;
IVsMultiItemSelect multiItemSelect;
uint projectItemId;
MonitorSelectionService.GetCurrentSelection(out hierarchyPointer, out projectItemId, out multiItemSelect, out selectionContainerPointer);
if (projectItemId == (uint)VSConstants.VSITEMID.Selection)
{
// Multiple projects are selected
uint numberOfSelectedItems;
int isSingleHieracrchy;
multiItemSelect.GetSelectionInfo(out numberOfSelectedItems, out isSingleHieracrchy);
var selectedItems = new VSITEMSELECTION[numberOfSelectedItems];
multiItemSelect.GetSelectedItems(0, numberOfSelectedItems, selectedItems);
var result = new Project[numberOfSelectedItems];
for (int i = 0; i < numberOfSelectedItems; i++)
{
object selectedObject = null;
ErrorHandler.ThrowOnFailure(selectedItems[i].pHier.GetProperty(selectedItems[i].itemid, (int)__VSHPROPID.VSHPROPID_ExtObject, out selectedObject));
result[i] = selectedObject as Project;
}
return result;
}
else
{
// Only one project is selected
object selectedObject = null;
IVsHierarchy selectedHierarchy = null;
try
{
selectedHierarchy = Marshal.GetTypedObjectForIUnknown(hierarchyPointer, typeof(IVsHierarchy)) as IVsHierarchy;
}
catch (Exception)
{
return null;
}
if (selectedHierarchy != null)
{
ErrorHandler.ThrowOnFailure(selectedHierarchy.GetProperty(projectItemId, (int)__VSHPROPID.VSHPROPID_ExtObject, out selectedObject));
}
Project selectedProject = selectedObject as Project;
return new Project[] { selectedProject };
}
}
示例4: GetSelection
public IEnumerable<IVsHierarchyItem> GetSelection ()
{
return asyncManager.Run (async () => {
await asyncManager.SwitchToMainThread ();
var selHier = IntPtr.Zero;
uint selId;
IVsMultiItemSelect selMulti;
try {
ErrorHandler.ThrowOnFailure (hierarchyWindow.GetCurrentSelection (out selHier, out selId, out selMulti));
// There may be no selection at all.
if (selMulti == null && selHier == IntPtr.Zero)
return Enumerable.Empty<IVsHierarchyItem> ();
// This is a single item selection.
if (selMulti == null) {
return new[] { hierarchyManager.GetHierarchyItem (
(IVsHierarchy)Marshal.GetTypedObjectForIUnknown (selHier, typeof (IVsHierarchy)), selId) };
}
// This is a multiple item selection.
uint selCount;
int singleHier;
ErrorHandler.ThrowOnFailure (selMulti.GetSelectionInfo (out selCount, out singleHier));
var selection = new VSITEMSELECTION[selCount];
ErrorHandler.ThrowOnFailure (selMulti.GetSelectedItems (0, selCount, selection));
return selection.Where (sel => sel.pHier != null)
.Select (sel => hierarchyManager.GetHierarchyItem (sel.pHier, sel.itemid))
.ToArray ();
} finally {
if (selHier != IntPtr.Zero)
Marshal.Release (selHier);
}
});
}
示例5: PackageSelectionDataObject
DataObject PackageSelectionDataObject(bool cutHighlightItems){
CleanupSelectionDataObject(false, false, false);
IVsUIHierarchyWindow w = this.projectMgr.GetIVsUIHierarchyWindow(VsConstants.Guid_SolutionExplorer);
IVsSolution solution = this.GetService(typeof(IVsSolution)) as IVsSolution;
IVsMonitorSelection ms = this.GetService(typeof(IVsMonitorSelection)) as IVsMonitorSelection;
IntPtr psel;
IVsMultiItemSelect itemSelect;
IntPtr psc;
uint vsitemid;
StringBuilder sb = new StringBuilder();
ms.GetCurrentSelection(out psel, out vsitemid, out itemSelect, out psc);
IVsHierarchy sel = (IVsHierarchy)Marshal.GetTypedObjectForIUnknown(psel, typeof(IVsHierarchy));
ISelectionContainer sc = (ISelectionContainer)Marshal.GetTypedObjectForIUnknown(psc, typeof(ISelectionContainer));
const uint GSI_fOmitHierPtrs = 0x00000001;
if ((sel != (IVsHierarchy)this) || (vsitemid == VsConstants.VSITEMID_ROOT) || (vsitemid == VsConstants.VSITEMID_NIL))
throw new InvalidOperationException();
if ((vsitemid == VsConstants.VSITEMID_SELECTION) && (itemSelect != null)){
int singleHierarchy;
uint pcItems;
itemSelect.GetSelectionInfo(out pcItems, out singleHierarchy);
if (singleHierarchy != 0) // "!BOOL" == "!= 0" ?
throw new InvalidOperationException();
this.itemsDragged = new ArrayList();
VSITEMSELECTION[] items = new VSITEMSELECTION[pcItems];
itemSelect.GetSelectedItems(GSI_fOmitHierPtrs, pcItems, items);
for (uint i = 0; i < pcItems; i++){
if (items[i].itemid == VsConstants.VSITEMID_ROOT){
this.itemsDragged.Clear();// abort
break;
}
this.itemsDragged.Add(items[i].pHier);
string projref;
solution.GetProjrefOfItem((IVsHierarchy)this, items[i].itemid, out projref);
if ((projref == null) || (projref.Length == 0)){
this.itemsDragged.Clear(); // abort
break;
}
sb.Append(projref);
sb.Append('\0'); // separated by nulls.
}
} else if (vsitemid != VsConstants.VSITEMID_ROOT){
this.itemsDragged = new ArrayList();
this.itemsDragged.Add(this.projectMgr.NodeFromItemId(vsitemid));
string projref;
solution.GetProjrefOfItem((IVsHierarchy)this, vsitemid, out projref);
sb.Append(projref);
}
if (sb.ToString() == "" || this.itemsDragged.Count == 0)
return null;
sb.Append('\0'); // double null at end.
_DROPFILES df = new _DROPFILES();
int dwSize = Marshal.SizeOf(df);
Int16 wideChar = 0;
int dwChar = Marshal.SizeOf(wideChar);
IntPtr ptr = Marshal.AllocHGlobal(dwSize + ((sb.Length + 1) * dwChar));
df.pFiles = dwSize;
df.fWide = 1;
IntPtr data = DataObject.GlobalLock(ptr);
Marshal.StructureToPtr(df, data, false);
IntPtr strData = new IntPtr((long)data + dwSize);
DataObject.CopyStringToHGlobal(sb.ToString(), strData);
DataObject.GlobalUnLock(data);
DataObject dobj = new DataObject();
FORMATETC fmt = DragDropHelper.CreateFormatEtc();
dobj.SetData(fmt, ptr);
if (cutHighlightItems){
bool first = true;
foreach (HierarchyNode node in this.itemsDragged){
w.ExpandItem((IVsUIHierarchy)this.projectMgr, node.hierarchyId, first ? EXPANDFLAGS.EXPF_CutHighlightItem : EXPANDFLAGS.EXPF_AddCutHighlightItem);
first = false;
}
}
return dobj;
}
示例6: GetSelectedItems
/// <summary>
/// Gets all of the currently selected items.
/// </summary>
/// <returns></returns>
private IEnumerable<VSITEMSELECTION> GetSelectedItems() {
IVsMonitorSelection monitorSelection = _package.GetService(typeof(IVsMonitorSelection)) as IVsMonitorSelection;
IntPtr hierarchyPtr = IntPtr.Zero;
IntPtr selectionContainer = IntPtr.Zero;
try {
uint selectionItemId;
IVsMultiItemSelect multiItemSelect = null;
ErrorHandler.ThrowOnFailure(monitorSelection.GetCurrentSelection(out hierarchyPtr, out selectionItemId, out multiItemSelect, out selectionContainer));
if (selectionItemId != VSConstants.VSITEMID_NIL && hierarchyPtr != IntPtr.Zero) {
IVsHierarchy hierarchy = Marshal.GetObjectForIUnknown(hierarchyPtr) as IVsHierarchy;
if (selectionItemId != VSConstants.VSITEMID_SELECTION) {
// This is a single selection. Compare hirarchy with our hierarchy and get node from itemid
if (Utilities.IsSameComObject(this, hierarchy)) {
yield return new VSITEMSELECTION() { itemid = selectionItemId, pHier = hierarchy };
}
} else if (multiItemSelect != null) {
// This is a multiple item selection.
// Get number of items selected and also determine if the items are located in more than one hierarchy
uint numberOfSelectedItems;
int isSingleHierarchyInt;
ErrorHandler.ThrowOnFailure(multiItemSelect.GetSelectionInfo(out numberOfSelectedItems, out isSingleHierarchyInt));
bool isSingleHierarchy = (isSingleHierarchyInt != 0);
// Now loop all selected items and add to the list only those that are selected within this hierarchy
if (!isSingleHierarchy || (isSingleHierarchy && Utilities.IsSameComObject(this, hierarchy))) {
Debug.Assert(numberOfSelectedItems > 0, "Bad number of selected itemd");
VSITEMSELECTION[] vsItemSelections = new VSITEMSELECTION[numberOfSelectedItems];
uint flags = (isSingleHierarchy) ? (uint)__VSGSIFLAGS.GSI_fOmitHierPtrs : 0;
ErrorHandler.ThrowOnFailure(multiItemSelect.GetSelectedItems(flags, numberOfSelectedItems, vsItemSelections));
foreach (VSITEMSELECTION vsItemSelection in vsItemSelections) {
yield return new VSITEMSELECTION() { itemid = vsItemSelection.itemid, pHier = hierarchy };
}
}
}
}
} finally {
if (hierarchyPtr != IntPtr.Zero) {
Marshal.Release(hierarchyPtr);
}
if (selectionContainer != IntPtr.Zero) {
Marshal.Release(selectionContainer);
}
}
}
示例7: GetItemType
internal static Guid GetItemType(VSITEMSELECTION vsItemSelection) {
Guid typeGuid;
try {
ErrorHandler.ThrowOnFailure(
vsItemSelection.pHier.GetGuidProperty(
vsItemSelection.itemid,
(int)__VSHPROPID.VSHPROPID_TypeGuid,
out typeGuid
)
);
} catch (System.Runtime.InteropServices.COMException) {
return Guid.Empty;
}
return typeGuid;
}
示例8: TestSccMenuCommands
public void TestSccMenuCommands()
{
int result = 0;
Guid badGuid = new Guid();
Guid guidCmdGroup = GuidList.guidSccProviderCmdSet;
OLECMD[] cmdAddToScc = new OLECMD[1];
cmdAddToScc[0].cmdID = CommandId.icmdAddToSourceControl;
OLECMD[] cmdCheckin = new OLECMD[1];
cmdCheckin[0].cmdID = CommandId.icmdCheckin;
OLECMD[] cmdCheckout = new OLECMD[1];
cmdCheckout[0].cmdID = CommandId.icmdCheckout;
OLECMD[] cmdUseSccOffline = new OLECMD[1];
cmdUseSccOffline[0].cmdID = CommandId.icmdUseSccOffline;
OLECMD[] cmdViewToolWindow = new OLECMD[1];
cmdViewToolWindow[0].cmdID = CommandId.icmdViewToolWindow;
OLECMD[] cmdToolWindowToolbarCommand = new OLECMD[1];
cmdToolWindowToolbarCommand[0].cmdID = CommandId.icmdToolWindowToolbarCommand;
OLECMD[] cmdUnsupported = new OLECMD[1];
cmdUnsupported[0].cmdID = 0;
// Initialize the provider, etc
SccProviderService target = GetSccProviderServiceInstance;
// Mock a service implementing IVsMonitorSelection
BaseMock monitorSelection = MockIVsMonitorSelectionFactory.GetMonSel();
serviceProvider.AddService(typeof(IVsMonitorSelection), monitorSelection, true);
// Commands that don't belong to our package should not be supported
result = _sccProvider.QueryStatus(ref badGuid, 1, cmdAddToScc, IntPtr.Zero);
Assert.AreEqual((int)Microsoft.VisualStudio.OLE.Interop.Constants.OLECMDERR_E_NOTSUPPORTED, result);
// The command should be invisible when there is no solution
VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_INVISIBLE, cmdAddToScc);
// Activate the provider and test the result
target.SetActive();
Assert.AreEqual(true, target.Active, "Microsoft.Samples.VisualStudio.SourceControlIntegration.SccProvider.SccProviderService.Active was not reported correctly.");
// The commands should be invisible when there is no solution
VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_INVISIBLE, cmdAddToScc);
VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_INVISIBLE, cmdCheckin);
VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_INVISIBLE, cmdCheckout);
VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_INVISIBLE, cmdUseSccOffline);
// Commands that don't belong to our package should not be supported
result = _sccProvider.QueryStatus(ref guidCmdGroup, 1, cmdUnsupported, IntPtr.Zero);
Assert.AreEqual((int)Microsoft.VisualStudio.OLE.Interop.Constants.OLECMDERR_E_NOTSUPPORTED, result);
// Deactivate the provider and test the result
target.SetInactive();
Assert.AreEqual(false, target.Active, "Microsoft.Samples.VisualStudio.SourceControlIntegration.SccProvider.SccProviderService.Active was not reported correctly.");
// Create a solution
solution.SolutionFile = Path.GetTempFileName();
MockIVsProject project = new MockIVsProject(Path.GetTempFileName());
project.AddItem(Path.GetTempFileName());
solution.AddProject(project);
// The commands should be invisible when the provider is not active
VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_INVISIBLE, cmdAddToScc);
VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_INVISIBLE, cmdCheckin);
VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_INVISIBLE, cmdCheckout);
VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_INVISIBLE, cmdUseSccOffline);
VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_INVISIBLE, cmdViewToolWindow);
VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_INVISIBLE, cmdToolWindowToolbarCommand);
// Activate the provider and test the result
target.SetActive();
Assert.AreEqual(true, target.Active, "Microsoft.Samples.VisualStudio.SourceControlIntegration.SccProvider.SccProviderService.Active was not reported correctly.");
// The command should be visible but disabled now, except the toolwindow ones
VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdAddToScc);
VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdCheckin);
VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdCheckout);
VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdUseSccOffline);
VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED, cmdViewToolWindow);
VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED, cmdToolWindowToolbarCommand);
// Set selection to solution node
VSITEMSELECTION selSolutionRoot;
selSolutionRoot.pHier = _solution as IVsHierarchy;
selSolutionRoot.itemid = VSConstants.VSITEMID_ROOT;
monitorSelection["Selection"] = new VSITEMSELECTION[] { selSolutionRoot };
// The add command should be available, rest should be disabled
VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED, cmdAddToScc);
VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdCheckin);
VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdCheckout);
VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdUseSccOffline);
// Still solution hierarchy, but other way
selSolutionRoot.pHier = null;
selSolutionRoot.itemid = VSConstants.VSITEMID_ROOT;
monitorSelection["Selection"] = new VSITEMSELECTION[] { selSolutionRoot };
// The add command should be available, rest should be disabled
VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED, cmdAddToScc);
VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdCheckin);
VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdCheckout);
//.........这里部分代码省略.........
示例9: Name
internal static string Name(VSITEMSELECTION item) {
return GetItemName(item.pHier, item.itemid);
}
示例10: GetSelectedNodes
/// <summary>
/// Gets the list of directly selected VSITEMSELECTION objects
/// </summary>
/// <returns>A list of VSITEMSELECTION objects</returns>
private IList<VSITEMSELECTION> GetSelectedNodes()
{
// Retrieve shell interface in order to get current selection
IVsMonitorSelection monitorSelection = _sccProvider.GetService(typeof(IVsMonitorSelection)) as IVsMonitorSelection;
Debug.Assert(monitorSelection != null, "Could not get the IVsMonitorSelection object from the services exposed by this project");
if (monitorSelection == null)
{
throw new InvalidOperationException();
}
List<VSITEMSELECTION> selectedNodes = new List<VSITEMSELECTION>();
IntPtr hierarchyPtr = IntPtr.Zero;
IntPtr selectionContainer = IntPtr.Zero;
try
{
// Get the current project hierarchy, project item, and selection container for the current selection
// If the selection spans multiple hierachies, hierarchyPtr is Zero
uint itemid;
IVsMultiItemSelect multiItemSelect = null;
ErrorHandler.ThrowOnFailure(monitorSelection.GetCurrentSelection(out hierarchyPtr, out itemid, out multiItemSelect, out selectionContainer));
if (itemid != VSConstants.VSITEMID_SELECTION)
{
// We only care if there are nodes selected in the tree
if (itemid != VSConstants.VSITEMID_NIL)
{
if (hierarchyPtr == IntPtr.Zero)
{
// Solution is selected
VSITEMSELECTION vsItemSelection;
vsItemSelection.pHier = null;
vsItemSelection.itemid = itemid;
selectedNodes.Add(vsItemSelection);
}
else
{
IVsHierarchy hierarchy = (IVsHierarchy)Marshal.GetObjectForIUnknown(hierarchyPtr);
// Single item selection
VSITEMSELECTION vsItemSelection;
vsItemSelection.pHier = hierarchy;
vsItemSelection.itemid = itemid;
selectedNodes.Add(vsItemSelection);
}
}
}
else
{
if (multiItemSelect != null)
{
// This is a multiple item selection.
//Get number of items selected and also determine if the items are located in more than one hierarchy
uint numberOfSelectedItems;
int isSingleHierarchyInt;
ErrorHandler.ThrowOnFailure(multiItemSelect.GetSelectionInfo(out numberOfSelectedItems, out isSingleHierarchyInt));
bool isSingleHierarchy = (isSingleHierarchyInt != 0);
// Now loop all selected items and add them to the list
Debug.Assert(numberOfSelectedItems > 0, "Bad number of selected itemd");
if (numberOfSelectedItems > 0)
{
VSITEMSELECTION[] vsItemSelections = new VSITEMSELECTION[numberOfSelectedItems];
ErrorHandler.ThrowOnFailure(multiItemSelect.GetSelectedItems(0, numberOfSelectedItems, vsItemSelections));
foreach (VSITEMSELECTION vsItemSelection in vsItemSelections)
{
selectedNodes.Add(vsItemSelection);
}
}
}
}
}
finally
{
if (hierarchyPtr != IntPtr.Zero)
{
Marshal.Release(hierarchyPtr);
}
if (selectionContainer != IntPtr.Zero)
{
Marshal.Release(selectionContainer);
}
}
return selectedNodes;
}
示例11: GetSelectedSourceImage
public static VSITEMSELECTION GetSelectedSourceImage(this IVsMonitorSelection monitorSelection)
{
VSITEMSELECTION sel = new VSITEMSELECTION();
if (monitorSelection != null)
{
IntPtr hierarchyPtr = IntPtr.Zero;
IntPtr selectionContainerPtr = IntPtr.Zero;
try
{
IVsMultiItemSelect multiSelect;
if (monitorSelection.GetCurrentSelection(out hierarchyPtr, out sel.itemid, out multiSelect, out selectionContainerPtr) >= 0)
{
sel.pHier = Marshal.GetObjectForIUnknown(hierarchyPtr) as IVsHierarchy;
if (sel.pHier != null && multiSelect != null)
{
uint items;
int singleHierarchy;
if (multiSelect.GetSelectionInfo(out items, out singleHierarchy) >= 0 && items != 1)
{
// Must have only one item selected
sel.pHier = null;
}
}
}
}
finally
{
if (hierarchyPtr != IntPtr.Zero)
{
Marshal.Release(hierarchyPtr);
hierarchyPtr = IntPtr.Zero;
}
if (selectionContainerPtr != IntPtr.Zero)
{
Marshal.Release(selectionContainerPtr);
selectionContainerPtr = IntPtr.Zero;
}
}
}
bool isImage = false;
if (sel.pHier != null)
{
object nameObj;
if (sel.pHier.GetProperty(sel.itemid, (int)__VSHPROPID.VSHPROPID_Name, out nameObj) >= 0)
{
isImage = ImageHelpers.IsSourceImageFile(nameObj as string);
}
}
if (!isImage)
{
sel = new VSITEMSELECTION();
}
return sel;
}
示例12: GetExtensionObject
internal static EnvDTE.ProjectItem GetExtensionObject(VSITEMSELECTION selection) {
object project;
ErrorHandler.ThrowOnFailure(
selection.pHier.GetProperty(
selection.itemid,
(int)__VSHPROPID.VSHPROPID_ExtObject,
out project
)
);
return (project as EnvDTE.ProjectItem);
}
示例13: RefreshSourceControlGlyphs
private void RefreshSourceControlGlyphs(VSITEMSELECTION node)
{
var project = node.pHier as IVsSccProject2;
if (project != null)
{
// Refresh all the glyphs in the project; the project will call back GetSccGlyphs()
// with the files for each node that will need new glyph
project.SccGlyphChanged(0, null, null, null);
}
else if (node.itemid == VSConstants.VSITEMID_ROOT)
{
// Note: The solution's hierarchy does not implement IVsSccProject2, IVsSccProject interfaces
// It may be a pain to treat the solution as special case everywhere; a possible workaround is
// to implement a solution-wrapper class, that will implement IVsSccProject2, IVsSccProject and
// IVsHierarhcy interfaces, and that could be used in provider's code wherever a solution is needed.
// This approach could unify the treatment of solution and projects in the provider's code.
// Until then, solution is treated as special case
var sccService = _serviceProvider.GetService<SourceControlProvider>();
string directory, fileName, userFile;
ErrorHandler.ThrowOnFailure(_vsSolution.GetSolutionInfo(out directory, out fileName, out userFile));
var rgpszFullPaths = new[] {fileName};
var rgsiGlyphs = new VsStateIcon[1];
sccService.GetSccGlyph(1, rgpszFullPaths, rgsiGlyphs, new uint[1]);
// Set the solution's glyph directly in the hierarchy
((IVsHierarchy)_vsSolution).SetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_StateIconIndex, rgsiGlyphs[0]);
}
}
示例14: AddToNewFile
private static void AddToNewFile(VSITEMSELECTION item, AddAzureServiceDialog dlg) {
var code = dlg.GenerateServiceCode();
var tempFile = Path.GetTempFileName();
File.WriteAllText(tempFile, code);
var projectItem = GetProjectItems(item).AddFromTemplate(
tempFile,
dlg.ServiceName.Text + ".py"
);
var window = projectItem.Open();
window.Activate();
}
示例15: GetProjectItems
internal static EnvDTE.ProjectItems GetProjectItems(VSITEMSELECTION selection) {
object project;
ErrorHandler.ThrowOnFailure(
selection.pHier.GetProperty(
selection.itemid,
(int)__VSHPROPID.VSHPROPID_ExtObject,
out project
)
);
if (project is EnvDTE.ProjectItem) {
return ((EnvDTE.ProjectItem)project).ProjectItems;
}
return ((EnvDTE.Project)project).ProjectItems;
}