/// <summary>Returns the details window if it exists, otherwise null.</summary> /// <param name="Artifact">The TreeViewArtifact to get it's detailswindow.</param> /// <returns>A toolSpiraExplorerDetails if found, null otherwise.</returns> public toolSpiraExplorerDetails FindExistingToolWindow(TreeViewArtifact Artifact, bool create = false) { toolSpiraExplorerDetails retWindow = null; try { if (SpiraExplorerPackage._windowDetails == null) { SpiraExplorerPackage._windowDetails = new Dictionary <TreeViewArtifact, int>(); } //Get the window ID if it already exists. int NextId = -1; if (SpiraExplorerPackage._windowDetails.ContainsKey(Artifact)) //Get the ID if it exists. { NextId = SpiraExplorerPackage._windowDetails[Artifact]; } else //Figure out the next ID. { SpiraExplorerPackage._numWindowIds++; NextId = SpiraExplorerPackage._numWindowIds; SpiraExplorerPackage._windowDetails.Add(Artifact, SpiraExplorerPackage._numWindowIds); } //Now try to grab the window.. retWindow = this.FindToolWindow(typeof(toolSpiraExplorerDetails), NextId, false) as toolSpiraExplorerDetails; if (retWindow == null && create) { retWindow = this.FindToolWindow(typeof(toolSpiraExplorerDetails), NextId, true) as toolSpiraExplorerDetails; } } catch (Exception ex) { Logger.LogMessage(ex, "Error creating window."); retWindow = null; } return(retWindow); }
public void OpenDetailsToolWindow(TreeViewArtifact Artifact) { string METHOD = CLASS + "OpenDetailsToolWindow"; try { //Find the existing window.. toolSpiraExplorerDetails window = this.FindExistingToolWindow(Artifact, true); if (window != null) { //If the window is hidden and is not in an unsaved state, reload window contents. // If window is not hidden, simply bring it to foreground. // If window is not created, load window contents. // If window is hidden and in an unsaved state, simply bring it to foreground. //See if we need to reset the content. if (!window.IsContentSet || (window.IsHidden && !window.IsChanged)) { //Generate the details screen. object detailContent = null; switch (Artifact.ArtifactType) { case TreeViewArtifact.ArtifactTypeEnum.Incident: frmDetailsIncident detIncident = new frmDetailsIncident(Artifact, window); detailContent = detIncident; break; case TreeViewArtifact.ArtifactTypeEnum.Requirement: frmDetailsRequirement detRequirement = new frmDetailsRequirement(Artifact, window); detailContent = detRequirement; break; case TreeViewArtifact.ArtifactTypeEnum.Task: frmDetailsTask detTask = new frmDetailsTask(Artifact, window); detailContent = detTask; break; } //Set toolwindow's content. if (detailContent != null) { ((cntrlDetailsForm)window.FormControl).Content = detailContent; } } //Get the frame. IVsWindowFrame windowFrame = (IVsWindowFrame)window.Frame; windowFrame.SetProperty((int)__VSFPROPID.VSFPROPID_FrameMode, VSFRAMEMODE.VSFM_MdiChild); Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(windowFrame.Show()); ((dynamic)((cntrlDetailsForm)window.FormControl).Content).IsHidden = false; } else { //Log an error. Logger.LogMessage(METHOD, "Could not create window.", EventLogEntryType.Error); MessageBox.Show(StaticFuncs.getCultureResource.GetString("app_General_WindowOpenErrorMessage"), StaticFuncs.getCultureResource.GetString("app_General_WindowOpenError"), MessageBoxButton.OK, MessageBoxImage.Error); } } catch (Exception ex) { Logger.LogMessage(ex, "OpenDetailsToolWindow()"); MessageBox.Show(StaticFuncs.getCultureResource.GetString("app_General_UnexpectedError"), StaticFuncs.getCultureResource.GetString("app_General_ApplicationShortName"), MessageBoxButton.OK, MessageBoxImage.Error); } }