/// <summary> /// Displays the windows form editor - the default fallback, if GUI specific editor is not provided /// </summary> /// <returns><c>true</c>, if windows form editor was displayed, <c>false</c> otherwise.</returns> /// <param name="editor">Editor.</param> /// <param name="windowTitle">Title of the displayed window.</param> public static bool DisplayWindowsFormEditor(IWorkspaceUnitEditor editor, String windowTitle) { System.Windows.Forms.Form winFormWindow = editor as System.Windows.Forms.Form; if (winFormWindow != null) { winFormWindow.Text = windowTitle; if (RuntimeInfo.OperatingSystem == RuntimeInfo.OS.Mac || RuntimeInfo.OperatingSystem == RuntimeInfo.OS.Linux) { //Application.Run begins running a standard application message loop on the current thread, //and makes the specified form visible. //It seems to be taking over the GTK+ message loop, thus the main GTK Window is not responding until //the form is closed. System.Windows.Forms.Application.Run(winFormWindow); //winFormWindow.Close(); //winFormWindow.Dispose(); winFormWindow.Hide(); } else { winFormWindow.Show(); } return(true); } return(false); }
/// <summary> /// Loads the viewer. /// Method searches for assemblies constructed with name of data type assembly + extension. /// For example, if provided extensions are '.UI.WPF.dll' and '.UI.dll' /// and data is of type TLArtifactsCollection from assembly TraceLabSDK.Types.dll, /// method will search for TraceLabSDK.Types.WPF.UI.dll and TraceLabSDK.Types.UI.dll in that order /// for type TLArtifactsCollectionEditor (namespace of both must be the same) /// /// The provided display functions will try to display windows based on their types. /// Typically, one will check for Windows Form and the other for Gui specific editor. /// </summary> /// <param name="data">The data.</param> /// <param name="windowTitle">The window title.</param> /// <param name="assemblyExtensions">The list of assembly extensions to check; </param> /// <param name="displayUnitEditors">The display unit editors.</param> /// <param name="error">The error.</param> /// <returns></returns> public static bool LoadViewer(object data, string windowTitle, string[] assemblyExtensions, DisplayEditor[] displayUnitEditors, out string error) { bool success = false; Type editorType; Type dataType = data.GetType(); error = String.Empty; try { if (GetEditorType(dataType, assemblyExtensions, out editorType)) { ConstructorInfo constructor = editorType.GetConstructor(Type.EmptyTypes); if (constructor != null) { IWorkspaceUnitEditor createdEditor = (IWorkspaceUnitEditor)constructor.Invoke(null); createdEditor.Data = data; //try all display functions foreach (DisplayEditor displayFunc in displayUnitEditors) { success = displayFunc(createdEditor, windowTitle); if (success == true) { break; } } } } else { success = false; error = "Editor has not been found for type: " + dataType.FullName; } } catch (Exception ex) { //format errors if loading was not successful StringBuilder builder = new StringBuilder(); builder.AppendLine("Unable to create editor for type: " + dataType.FullName); builder.AppendLine(ex.Message); error = builder.ToString(); } return(success); }
/// <summary> /// Displays the WPF window. /// </summary> /// <param name="editor">The editor.</param> /// <param name="windowTitle">The window title.</param> /// <returns>if window has been displayed, otherwise false</returns> private bool DisplayWPFWindow(IWorkspaceUnitEditor editor, String windowTitle) { FrameworkElement frameworkElement = editor as FrameworkElement; if (frameworkElement != null) { Window wrapperWindow = new Window { Content = editor, Owner = Application.Current.MainWindow, Title = windowTitle }; wrapperWindow.ShowInTaskbar = false; wrapperWindow.ShowActivated = true; wrapperWindow.WindowStartupLocation = WindowStartupLocation.CenterOwner; wrapperWindow.ShowDialog(); return(true); } return(false); }
/// <summary> /// Displays the WPF window. /// </summary> /// <param name="editor">The editor.</param> /// <param name="windowTitle">The window title.</param> /// <returns>if window has been displayed, otherwise false</returns> private bool DisplayWPFWindow(IWorkspaceUnitEditor editor, String windowTitle) { FrameworkElement frameworkElement = editor as FrameworkElement; if (frameworkElement != null) { Window wrapperWindow = new Window { Content = editor, Owner = Application.Current.MainWindow, Title = windowTitle }; wrapperWindow.ShowInTaskbar = false; wrapperWindow.ShowActivated = true; wrapperWindow.WindowStartupLocation = WindowStartupLocation.CenterOwner; wrapperWindow.ShowDialog(); return true; } return false; }
/// <summary> /// Displays the windows form editor - the default fallback, if GUI specific editor is not provided /// </summary> /// <returns><c>true</c>, if windows form editor was displayed, <c>false</c> otherwise.</returns> /// <param name="editor">Editor.</param> /// <param name="windowTitle">Title of the displayed window.</param> public static bool DisplayWindowsFormEditor(IWorkspaceUnitEditor editor, String windowTitle) { System.Windows.Forms.Form winFormWindow = editor as System.Windows.Forms.Form; if (winFormWindow != null) { winFormWindow.Text = windowTitle; if (RuntimeInfo.OperatingSystem == RuntimeInfo.OS.Mac || RuntimeInfo.OperatingSystem == RuntimeInfo.OS.Linux) { //Application.Run begins running a standard application message loop on the current thread, //and makes the specified form visible. //It seems to be taking over the GTK+ message loop, thus the main GTK Window is not responding until //the form is closed. System.Windows.Forms.Application.Run(winFormWindow); //winFormWindow.Close(); //winFormWindow.Dispose(); winFormWindow.Hide(); } else { winFormWindow.Show(); } return true; } return false; }