本文整理汇总了C#中VSADDRESULT类的典型用法代码示例。如果您正苦于以下问题:C# VSADDRESULT类的具体用法?C# VSADDRESULT怎么用?C# VSADDRESULT使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
VSADDRESULT类属于命名空间,在下文中一共展示了VSADDRESULT类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddFromTemplate
/// <summary>
/// Creates a new project item from an existing item template file and adds it to the project.
/// </summary>
/// <param name="fileName">The full path and file name of the template project file.</param>
/// <param name="name">The file name to use for the new project item.</param>
/// <returns>A ProjectItem object. </returns>
public override EnvDTE.ProjectItem AddFromTemplate(string fileName, string name)
{
if (this.Project == null || this.Project.Project == null || this.Project.Project.Site == null || this.Project.Project.IsClosed)
{
throw new InvalidOperationException();
}
ProjectNode proj = this.Project.Project;
IVsExtensibility3 extensibility = this.Project.Project.Site.GetService(typeof(IVsExtensibility)) as IVsExtensibility3;
if (extensibility == null)
{
throw new InvalidOperationException();
}
EnvDTE.ProjectItem itemAdded = null;
extensibility.EnterAutomationFunction();
try
{
// Determine the operation based on the extension of the filename.
// We should run the wizard only if the extension is vstemplate
// otherwise it's a clone operation
VSADDITEMOPERATION op;
if (Utilities.IsTemplateFile(fileName))
{
op = VSADDITEMOPERATION.VSADDITEMOP_RUNWIZARD;
}
else
{
op = VSADDITEMOPERATION.VSADDITEMOP_CLONEFILE;
}
VSADDRESULT[] result = new VSADDRESULT[1];
// It is not a very good idea to throw since the AddItem might return Cancel or Abort.
// The problem is that up in the call stack the wizard code does not check whether it has received a ProjectItem or not and will crash.
// The other problem is that we cannot get add wizard dialog back if a cancel or abort was returned because we throw and that code will never be executed. Typical catch 22.
ErrorHandler.ThrowOnFailure(proj.AddItem(this.NodeWithItems.ID, op, name, 0, new string[1] { fileName }, IntPtr.Zero, result));
string fileDirectory = proj.GetBaseDirectoryForAddingFiles(this.NodeWithItems);
string templateFilePath = System.IO.Path.Combine(fileDirectory, name);
itemAdded = this.EvaluateAddResult(result[0], templateFilePath);
}
finally
{
extensibility.ExitAutomationFunction();
}
return itemAdded;
}
示例2: AddItem
public int AddItem(uint itemidLoc, VSADDITEMOPERATION dwAddItemOperation, string pszItemName, uint cFilesToOpen, string[] rgpszFilesToOpen, IntPtr hwndDlgOwner, VSADDRESULT[] pResult)
{
AddItemCalled = true;
AddItemArgumentItemidLoc = itemidLoc;
AddItemArgumentAddItemOperation = dwAddItemOperation;
AddItemArgumentItemName = pszItemName;
AddItemArgumentFilesToOpen = cFilesToOpen;
AddItemArgumentArrayFilesToOpen = rgpszFilesToOpen;
return VSConstants.S_OK;
}
示例3: CreateNewFile
private static void CreateNewFile(NodejsProjectNode projectNode, uint containerId, string fileType) {
using (var dialog = new NewFileNameForm(GetInitialName(fileType))) {
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
string itemName = dialog.TextBox.Text;
VSADDRESULT[] pResult = new VSADDRESULT[1];
projectNode.AddItem(
containerId, // Identifier of the container folder.
VSADDITEMOPERATION.VSADDITEMOP_CLONEFILE, // Indicate that we want to create this new file by cloning a template file.
itemName,
1, // Number of templates in the next parameter. Must be 1 if using VSADDITEMOP_CLONEFILE.
new string[] { GetTemplateFile(fileType) }, // Array contains the template file path.
IntPtr.Zero, // Handle to the Add Item dialog box. Must be Zero if using VSADDITEMOP_CLONEFILE.
pResult
);
// TODO: Do we need to check if result[0] = VSADDRESULT.ADDRESULT_Success here?
}
}
}
示例4: AddNodeIfTargetExistInStorage
/// <summary>
/// Add an existing item (file/folder) to the project if it already exist in our storage.
/// </summary>
/// <param name="parentNode">Node to that this item to</param>
/// <param name="name">Name of the item being added</param>
/// <param name="targetPath">Path of the item being added</param>
/// <returns>Node that was added</returns>
/*protected, but public for FSharp.Project.dll*/
public virtual HierarchyNode AddNodeIfTargetExistInStorage(HierarchyNode parentNode, string name, string targetPath)
{
HierarchyNode newNode = parentNode;
// If the file/directory exist, add a node for it
if (FSSafe.File.SafeExists(targetPath))
{
VSADDRESULT[] result = new VSADDRESULT[1];
ErrorHandler.ThrowOnFailure(this.AddItem(parentNode.ID, VSADDITEMOPERATION.VSADDITEMOP_OPENFILE, name, 1, new string[] { targetPath }, IntPtr.Zero, result));
if (result[0] != VSADDRESULT.ADDRESULT_Success)
throw new ApplicationException();
newNode = this.FindChild(targetPath);
if (newNode == null)
throw new ApplicationException();
}
else if (Directory.Exists(targetPath))
{
newNode = this.CreateFolderNodes(targetPath);
}
return newNode;
}
示例5: CreateNewFile
internal static void CreateNewFile(NodejsProjectNode projectNode, uint containerId) {
using (var dialog = new NewFileNameForm("")) {
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
string itemName = dialog.TextBox.Text;
if (string.IsNullOrWhiteSpace(itemName)) {
return;
}
itemName = itemName.Trim();
VSADDRESULT[] pResult = new VSADDRESULT[1];
projectNode.AddItem(
containerId, // Identifier of the container folder.
VSADDITEMOPERATION.VSADDITEMOP_CLONEFILE, // Indicate that we want to create this new file by cloning a template file.
itemName,
1, // Number of templates in the next parameter. Must be 1 if using VSADDITEMOP_CLONEFILE.
new string[] { Path.GetTempFileName() }, // Array contains the template file path.
IntPtr.Zero, // Handle to the Add Item dialog box. Must be Zero if using VSADDITEMOP_CLONEFILE.
pResult);
}
}
}
示例6:
int IVsProject.AddItem(uint itemidLoc, VSADDITEMOPERATION dwAddItemOperation, string pszItemName, uint cFilesToOpen, string[] rgpszFilesToOpen, IntPtr hwndDlgOwner, VSADDRESULT[] pResult) {
return _innerProject.AddItem(itemidLoc, dwAddItemOperation, pszItemName, cFilesToOpen, rgpszFilesToOpen, hwndDlgOwner, pResult);
}
示例7: AddItem
// (after dialog) Add existing item -> AdItemWithSpecific
public override int AddItem(uint itemIdLoc, VSADDITEMOPERATION op, string itemName, uint filesToOpen, string[] files, IntPtr dlgOwner, VSADDRESULT[] result)
{
// Special MSBuild case: we invoked it directly instead of using the "add item" dialog.
if (itemName != null && itemName.Equals("SimResult"))
{
SimResultsNode resultsNode = null;
if (this.IsSimResultFilePresent())
resultsNode = this.FindChild("Results.sim") as SimResultsNode;
if (resultsNode == null)
{
resultsNode = CreateAndAddSimResultsFile(); //TODO: what about save on project unload/exit?
}
var simulationTimestamp = DateTime.Now;
bool filePresent = false;
bool renameOutput = true;
Boolean.TryParse(GetProjectProperty("RenameOutput"), out renameOutput);
string baseOutputName = GetProjectProperty("BaseOutputName");
if (String.IsNullOrEmpty(baseOutputName))
{
var msBuildProject = BlenXProjectPackage.MSBuildProjectFromIVsProject(this);
foreach (Microsoft.Build.BuildEngine.BuildItem item in msBuildProject.EvaluatedItems)
{
if (item.Name.Equals(SimFiles.Prog.ToString()))
{
baseOutputName = item.Include;
break;
}
}
if (String.IsNullOrEmpty(baseOutputName))
baseOutputName = Path.GetFileNameWithoutExtension(this.ProjectFile) + ".prog";
}
string newOutputName;
if (renameOutput)
{
newOutputName = baseOutputName + simulationTimestamp.ToString("yyyy'-'MM'-'dd'-'HH'-'mm'-'ss");
// TODO: try to move!
filePresent = TryCopy(baseOutputName, newOutputName, "spec");
TryCopy(baseOutputName, newOutputName, "E.out");
TryCopy(baseOutputName, newOutputName, "C.out");
TryCopy(baseOutputName, newOutputName, "V.out");
}
else
{
newOutputName = baseOutputName;
filePresent = File.Exists(this.ProjectFolder + Path.DirectorySeparatorChar + baseOutputName + ".spec");
}
if (filePresent)
{
resultsNode.AddEntry(newOutputName, this.ProjectFolder, simulationTimestamp);
}
return VSConstants.S_OK;
}
// Add existing item: itemIdLoc = 4294967294, VSADDITEMOP_OPENFILE, itemName = null, files (filename), null, VSADDRESULT 1 (init with ADDRESULT_Failure)
return base.AddItem(itemIdLoc, op, itemName, filesToOpen, files, dlgOwner, result);
}
示例8: EvaluateAddResult
/// <summary>
/// Evaluates the result of an add operation.
/// </summary>
/// <param name="result">The <paramref name="VSADDRESULT"/> returned by the Add methods</param>
/// <param name="path">The full path of the item added.</param>
/// <returns>A ProjectItem object.</returns>
private EnvDTE.ProjectItem EvaluateAddResult(VSADDRESULT result, string path) {
return Project.ProjectNode.Site.GetUIThread().Invoke<EnvDTE.ProjectItem>(() => {
if (result != VSADDRESULT.ADDRESULT_Failure) {
if (Directory.Exists(path)) {
path = CommonUtils.EnsureEndSeparator(path);
}
HierarchyNode nodeAdded = this.NodeWithItems.ProjectMgr.FindNodeByFullPath(path);
Debug.Assert(nodeAdded != null, "We should have been able to find the new element in the hierarchy");
if (nodeAdded != null) {
EnvDTE.ProjectItem item = null;
var fileNode = nodeAdded as FileNode;
if (fileNode != null) {
item = new OAFileItem(this.Project, fileNode);
} else {
item = new OAProjectItem(this.Project, nodeAdded);
}
return item;
}
}
return null;
});
}
示例9: AddFromTemplate
/// <summary>
/// Creates a new project item from an existing item template file and adds it to the project.
/// </summary>
/// <param name="fileName">The full path and file name of the template project file.</param>
/// <param name="name">The file name to use for the new project item.</param>
/// <returns>A ProjectItem object. </returns>
public override EnvDTE.ProjectItem AddFromTemplate(string fileName, string name) {
CheckProjectIsValid();
ProjectNode proj = this.Project.ProjectNode;
EnvDTE.ProjectItem itemAdded = null;
using (AutomationScope scope = new AutomationScope(this.Project.ProjectNode.Site)) {
// Determine the operation based on the extension of the filename.
// We should run the wizard only if the extension is vstemplate
// otherwise it's a clone operation
VSADDITEMOPERATION op;
Project.ProjectNode.Site.GetUIThread().Invoke(() => {
if (Utilities.IsTemplateFile(fileName)) {
op = VSADDITEMOPERATION.VSADDITEMOP_RUNWIZARD;
} else {
op = VSADDITEMOPERATION.VSADDITEMOP_CLONEFILE;
}
VSADDRESULT[] result = new VSADDRESULT[1];
// It is not a very good idea to throw since the AddItem might return Cancel or Abort.
// The problem is that up in the call stack the wizard code does not check whether it has received a ProjectItem or not and will crash.
// The other problem is that we cannot get add wizard dialog back if a cancel or abort was returned because we throw and that code will never be executed. Typical catch 22.
ErrorHandler.ThrowOnFailure(proj.AddItem(this.NodeWithItems.ID, op, name, 0, new string[1] { fileName }, IntPtr.Zero, result));
string fileDirectory = proj.GetBaseDirectoryForAddingFiles(this.NodeWithItems);
string templateFilePath = System.IO.Path.Combine(fileDirectory, name);
itemAdded = this.EvaluateAddResult(result[0], templateFilePath);
});
}
return itemAdded;
}
示例10: EvaluateAddResult
protected virtual EnvDTE.ProjectItem EvaluateAddResult(VSADDRESULT result, string path)
{
return UIThread.DoOnUIThread(delegate()
{
if (result == VSADDRESULT.ADDRESULT_Success)
{
HierarchyNode nodeAdded = this.NodeWithItems.FindChild(path);
Debug.Assert(nodeAdded != null, "We should have been able to find the new element in the hierarchy");
if (nodeAdded != null)
{
EnvDTE.ProjectItem item = null;
if (nodeAdded is FileNode)
{
item = new OAFileItem(this.Project, nodeAdded as FileNode);
}
else if (nodeAdded is NestedProjectNode)
{
item = new OANestedProjectItem(this.Project, nodeAdded as NestedProjectNode);
}
else
{
item = new OAProjectItem<HierarchyNode>(this.Project, nodeAdded);
}
this.Items.Add(item);
return item;
}
}
return null;
});
}
示例11: AddProject
int IVsProject.AddItem(uint itemidLoc, VSADDITEMOPERATION dwAddItemOperation, string pszItemName, uint cFilesToOpen, string[] rgpszFilesToOpen, IntPtr hwndDlgOwner, VSADDRESULT[] pResult)
{
if (Directory.Exists(rgpszFilesToOpen[0]))
{
AddProject(new MockVSHierarchy(rgpszFilesToOpen[0], this));
}
else
{
children.Add(rgpszFilesToOpen[0]);
if (project != null)
{
FileInfo itemFileInfo = new FileInfo(rgpszFilesToOpen[0]);
project.Save(fileName);
FileInfo projectFileInfo = new FileInfo(project.FullFileName);
string itemName = itemFileInfo.FullName.Substring(projectFileInfo.Directory.FullName.Length + 1);
project.AddNewItem("Compile", itemName);
project.Save(fileName);
}
}
return VSConstants.S_OK;
}
示例12: AddFileToNodeFromProjectReference
/// <summary>
/// Adds an item from a project refererence to target node.
/// </summary>
/// <param name="projectRef"></param>
/// <param name="targetNode"></param>
private bool AddFileToNodeFromProjectReference(string projectRef, HierarchyNode targetNode)
{
if (String.IsNullOrEmpty(projectRef))
{
throw new ArgumentException(SR.GetString(SR.ParameterCannotBeNullOrEmpty, CultureInfo.CurrentUICulture), "projectRef");
}
if (targetNode == null)
{
throw new ArgumentNullException("targetNode");
}
IVsSolution solution = this.GetService(typeof(IVsSolution)) as IVsSolution;
if (solution == null)
{
throw new InvalidOperationException();
}
uint itemidLoc;
IVsHierarchy hierarchy;
string str;
VSUPDATEPROJREFREASON[] reason = new VSUPDATEPROJREFREASON[1];
ErrorHandler.ThrowOnFailure(solution.GetItemOfProjref(projectRef, out hierarchy, out itemidLoc, out str, reason));
if (hierarchy == null)
{
throw new InvalidOperationException();
}
// This will throw invalid cast exception if the hierrachy is not a project.
IVsProject project = (IVsProject)hierarchy;
string moniker;
ErrorHandler.ThrowOnFailure(project.GetMkDocument(itemidLoc, out moniker));
string[] files = new String[1] { moniker };
VSADDRESULT[] vsaddresult = new VSADDRESULT[1];
vsaddresult[0] = VSADDRESULT.ADDRESULT_Failure;
int addResult = targetNode.ProjectMgr.DoAddItem(targetNode.ID, VSADDITEMOPERATION.VSADDITEMOP_OPENFILE, null, 0, files, IntPtr.Zero, vsaddresult, AddItemContext.Paste);
if (addResult != VSConstants.S_OK && addResult != VSConstants.S_FALSE && addResult != (int)OleConstants.OLECMDERR_E_CANCELED)
{
ErrorHandler.ThrowOnFailure(addResult);
return false;
}
return (vsaddresult[0] == VSADDRESULT.ADDRESULT_Success);
}
示例13: AddNodeIfTargetExistInStorage
/// <summary>
/// Add an existing item (file/folder) to the project if it already exist in our storage.
/// </summary>
/// <param name="parentNode">Node to that this item to</param>
/// <param name="name">Name of the item being added</param>
/// <param name="targetPath">Path of the item being added</param>
/// <returns>Node that was added</returns>
protected virtual HierarchyNode AddNodeIfTargetExistInStorage(HierarchyNode parentNode, string name,
string targetPath)
{
if (parentNode == null)
{
return null;
}
var newNode = parentNode;
// If the file/directory exist, add a node for it
if (File.Exists(targetPath))
{
var result = new VSADDRESULT[1];
ErrorHandler.ThrowOnFailure(AddItem(parentNode.ID, VSADDITEMOPERATION.VSADDITEMOP_OPENFILE, name, 1,
new[] {targetPath}, IntPtr.Zero, result));
if (result[0] != VSADDRESULT.ADDRESULT_Success)
throw new Exception();
newNode = FindChild(targetPath);
if (newNode == null)
throw new Exception();
}
else if (Directory.Exists(targetPath))
{
newNode = CreateFolderNodes(targetPath);
}
return newNode;
}
示例14: AddFiles
// This is for moving files from one part of our project to another.
/// <include file='doc\Hierarchy.uex' path='docs/doc[@for="HierarchyNode.AddFiles"]/*' />
public void AddFiles(string[] rgSrcFiles){
if (rgSrcFiles == null || rgSrcFiles.Length == 0)
return;
IVsSolution srpIVsSolution = this.GetService(typeof(IVsSolution)) as IVsSolution;
if (srpIVsSolution == null)
return;
IVsProject ourProj = (IVsProject)this.projectMgr;
foreach (string file in rgSrcFiles){
uint itemidLoc;
IVsHierarchy srpIVsHierarchy;
string str;
VSUPDATEPROJREFREASON[] reason = new VSUPDATEPROJREFREASON[1];
srpIVsSolution.GetItemOfProjref(file, out srpIVsHierarchy, out itemidLoc, out str, reason);
if (srpIVsHierarchy == null){
throw new InvalidOperationException();//E_UNEXPECTED;
}
IVsProject srpIVsProject = (IVsProject)srpIVsHierarchy;
if (srpIVsProject == null){
continue;
}
string cbstrMoniker;
srpIVsProject.GetMkDocument(itemidLoc, out cbstrMoniker);
if (File.Exists(cbstrMoniker)){
string[] files = new String[1]{ cbstrMoniker };
VSADDRESULT[] vsaddresult = new VSADDRESULT[1];
vsaddresult[0] = VSADDRESULT.ADDRESULT_Failure;
// bugbug: support dropping into subfolder.
ourProj.AddItem(this.projectMgr.hierarchyId, VSADDITEMOPERATION.VSADDITEMOP_OPENFILE, null, 1, files, IntPtr.Zero, vsaddresult);
if (vsaddresult[0] == VSADDRESULT.ADDRESULT_Cancel){
break;
}
}
}
}
示例15: AddItem
public virtual int AddItem(uint itemIdLoc, VSADDITEMOPERATION op, string itemName, uint filesToOpen, string[] files, IntPtr dlgOwner, VSADDRESULT[] result)
{
Guid empty = Guid.Empty;
return AddItemWithSpecific(itemIdLoc, op, itemName, filesToOpen, files, dlgOwner, 0, ref empty, null, ref empty, result);
}