/// <summary> /// Displays the picker. /// </summary> public bool ShowDialog() { if (this.RootItem == null) { throw new InvalidOperationException(Resources.SolutionPicker_ErrorNoRootItem); } // Initialize the view var picker = new SolutionPickerView(); picker.Owner = this.Owner; if (!string.IsNullOrEmpty(this.Title)) { picker.Title = this.Title; } // Initialize the model var root = new FilteredItemContainer(this.RootItem, this.Filter); var model = new SolutionPickerViewModel(root, this.Filter); model.EmptyItemsMessage = this.EmptyItemsMessage; model.SetSelectedItem(this.SelectedItem); //Bind the model and view picker.DataContext = model; var result = false; tracer.ShieldUI(() => { // Display the view result = picker.ShowDialog().GetValueOrDefault(); if (result) { if (model.GetSelectedItem() == null) { result = false; } else { this.SelectedItem = model.GetSelectedItem().Item; } } }, Resources.SolutionPicker_ErrorFailedDialog); return(result); }
/// <summary> /// This function is the callback used to execute the command when the menu item is clicked. /// See the constructor to see how the menu item is associated with this function using /// OleMenuCommandService service and MenuCommand class. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event args.</param> private void MenuItemCallback(object sender, EventArgs e) { IVsSolution solution = _package.GetService <IVsSolution, SVsSolution>(); // As the "Edit Links" command is added on the Project menu even when no solution is opened, it must // be validated that a solution exists (in case it doesn't, GetSolutionInfo() returns 3 nulled strings). ErrorHandler.ThrowOnFailure(solution.GetSolutionInfo(out string s1, out string s2, out string s3)); if (s1 != null && s2 != null && s3 != null) { IVsUIShell uiShell = _package.GetService <IVsUIShell, SVsUIShell>(); ErrorHandler.ThrowOnFailure(uiShell.GetDialogOwnerHwnd(out IntPtr parentHwnd)); HierarchyNodeFactory hierarchyNodeFactory = new HierarchyNodeFactory(ServiceProvider); IHierarchyNode targetProject = hierarchyNodeFactory.GetSelectedProject(); SolutionPickerView solutionPicker = new SolutionPickerView(ServiceProvider, targetProject); DialogResult result = solutionPicker.ShowDialog(new WindowHandleAdapter(parentHwnd)); if (result == DialogResult.OK) { try { IHierarchyNode sourceProject = solutionPicker.SelectedNode; IProjectLinkTracker linker = _package.GetService <IProjectLinkTracker, ISProjectLinkTracker>(); // todo linker.AddProjectLink(sourceProject.ProjectGuid, targetProject.ProjectGuid); if (solutionPicker.CopyProjectItemsByDefault) { linker.LinkAllProjectItems(sourceProject.ProjectGuid, targetProject.ProjectGuid); } _package.ShowInformationalMessageBox( Resources.ProjectLinkerCaption, Resources.ProjectsSuccessfullyLinked, false); } catch (ProjectLinkerException ex) { _package.ShowInformationalMessageBox(Resources.ProjectLinkerCaption, ex.Message, true); } } } }