The following code help you do open an Dialog where the EA is the parent/owner of the Form. It is designed as method extension to Windows.Forms.Form:
static public DialogResult ShowDialogAtMainWindow(this Form form)
{
IWin32Window win32Window = InternalHelpers.GetMainWindow();
if (win32Window != null) // null means that the main window handle could not be evaluated
return form.ShowDialog(win32Window);
else
return form.ShowDialog(); //fallback: use it without owner
}
Further following code helps you to open standard EA-Property dialogs. Also designed as method extension to the EA.Repository:
public enum EaType
{
Package,
Element,
Attribute,
Operation,
Diagram
}
public static class EaRepositoryExtensions
{
public static void OpenEaPropertyDlg(this EA.Repository rep, int id, EaType type)
{
string dlg;
switch (type)
{
case EaType.Package: dlg = "PKG"; break;
case EaType.Element: dlg = "ELM"; break;
case EaType.Attribute: dlg = "ATT"; break;
case EaType.Operation: dlg = "OP"; break;
case EaType.Diagram: dlg = "DGM"; break;
default: dlg = String.Empty; break;
}
string ret = rep.CustomCommand("CFormCommandHelper", "ProcessCommand", "Dlg=" + dlg + ";id=" + id + ";hwnd=" + InternalHelpers.GetMainWindow().Handle);
}
public static void OpenPackagePropertyDlg(this EA.Repository rep, int packageId)
{
rep.OpenEaPropertyDlg(packageId, EaType.Package);
}
public static void OpenElementPropertyDlg(this EA.Repository rep, int elementId)
{
rep.OpenEaPropertyDlg(elementId, EaType.Element);
}
public static void OpenAttributePropertyDlg(this EA.Repository rep, int attributeId)
{
rep.OpenEaPropertyDlg(attributeId, EaType.Attribute);
}
public static void OpenOperationPropertyDlg(this EA.Repository rep, int opertaionId)
{
rep.OpenEaPropertyDlg(opertaionId, EaType.Operation);
}
public static void OpenDiagramPropertyDlg(this EA.Repository rep, int diagramId)
{
rep.OpenEaPropertyDlg(diagramId, EaType.Diagram);
}
}
Therefore following helpers are required:
public calss InternalHelpers
{
static public IWin32Window GetMainWindow()
{
System.Diagnostics.Process proc = System.Diagnostics.Process.GetCurrentProcess();
if (proc.MainWindowTitle == "") //somtimes a wrong handle is returned, in this case also the title is emty
return null; //return null in this case
else //otherwise return the right handle
return new WindowWrapper(proc.MainWindowHandle);
}
internal class WindowWrapper : System.Windows.Forms.IWin32Window
{
public WindowWrapper(IntPtr handle)
{
_hwnd = handle;
}
public IntPtr Handle
{
get { return _hwnd; }
}
private IntPtr _hwnd;
}
}