public TEditor GetEditor <TEditor>(IUniqueData data) where TEditor : DataEditorForm { DataEditorForm foundForm = editorList.Find( f => f.GetEditorData <IUniqueData>().Equals(data)); if (foundForm != null) { foundForm.Focus(); return((TEditor)foundForm); } else { //ConstructorInfo ctor = typeof(TEditor).GetConstructor(new Type[0]); //if (ctor == null) //{ // throw new Exception( // "Could not create new data editor of type '" // + typeof(TEditor).Name + // "' because no empty constructor exists."); //} //TEditor editor = (TEditor)ctor.Invoke(new object[0]); TEditor editor = Activator.CreateInstance <TEditor>(); editorList.Add(editor); return(editor); } }
private ProtectedBinary OpenBinaryDataLegacy(string name, ProtectedBinary binary) { ProtectedBinary modifiedData = null; var data = binary.ReadData(); var dataClass = BinaryDataClassifier.Classify(name, data); if (DataEditorForm.SupportsDataType(dataClass)) { var editor = new DataEditorForm(); editor.InitEx(name, data); editor.ShowDialog(); if (editor.EditedBinaryData != null) { modifiedData = new ProtectedBinary(binary.IsProtected, editor.EditedBinaryData); } UIUtil.DestroyForm(editor); } else { var viewer = new DataViewerForm(); viewer.InitEx(name, data); UIUtil.ShowDialogAndDestroy(viewer); } return(modifiedData); }
internal static void BuildOpenWithMenu(DynamicMenu dm, string strItem, ProtectedBinary pb, bool bReadOnly) { if (dm == null) { Debug.Assert(false); return; } dm.Clear(); if (string.IsNullOrEmpty(strItem)) { Debug.Assert(false); return; } if (pb == null) { Debug.Assert(false); return; } byte[] pbData = pb.ReadData(); if (pbData == null) { Debug.Assert(false); return; } BinaryDataClass bdc = BinaryDataClassifier.Classify(strItem, pbData); BinaryDataOpenOptions oo = new BinaryDataOpenOptions(); oo.Handler = BinaryDataHandler.InternalViewer; dm.AddItem(KPRes.InternalViewer, Properties.Resources.B16x16_View_Detailed, oo); oo = new BinaryDataOpenOptions(); oo.Handler = BinaryDataHandler.InternalEditor; ToolStripMenuItem tsmiIntEditor = dm.AddItem(KPRes.InternalEditor, Properties.Resources.B16x16_View_Detailed, oo); oo = new BinaryDataOpenOptions(); oo.Handler = BinaryDataHandler.ExternalApp; ToolStripMenuItem tsmiExt = dm.AddItem(KPRes.ExternalApp, Properties.Resources.B16x16_Make_KDevelop, oo); if (!DataEditorForm.SupportsDataType(bdc) || bReadOnly) { tsmiIntEditor.Enabled = false; } if (bReadOnly) { tsmiExt.Enabled = false; } }
public void ShowEditorAsync(DataEditorForm dataEditor) { dataEditor.FormClosed += new FormClosedEventHandler(dataEditor_FormClosed); dataEditor.AfterLoadAsync += new DataActionAfterEventHandler(dataEditor_AfterLoadAsync); dataEditor.AfterCreateAsync += new DataActionAfterEventHandler(dataEditor_AfterCreateAsync); dataEditor.AfterUpdateAsync += new DataActionAfterEventHandler(dataEditor_AfterUpdateAsync); // Ensure that status is not changed when form not created. dataEditor.AutoChangeStatus = false; Guid statusGuid = AsyncStatusChange("Loading editor..."); dataEditor.RunLoadAsync(new LoadEditorArgs(statusGuid, true)); }
private static BinaryDataHandler ChooseHandler(string strName, byte[] pbData, BinaryDataOpenOptions opt) { BinaryDataClass bdc = BinaryDataClassifier.Classify(strName, pbData); if (DataEditorForm.SupportsDataType(bdc) && !opt.ReadOnly) { return(BinaryDataHandler.InternalEditor); } if (DataViewerForm.SupportsDataType(bdc)) { return(BinaryDataHandler.InternalViewer); } return(BinaryDataHandler.ExternalApp); }
void dataEditor_AfterLoadAsync(object sender, DataActionAfterEventArgs e) { if (e.CheckType <LoadEditorArgs>()) { LoadEditorArgs args = e.GetData <LoadEditorArgs>(); DataEditorForm dataEditor = (DataEditorForm)sender; if (args.ShowAfterLoad) { dataEditor.Show(); } AsyncStatusRevert(args.StatusGuid); // Ensure that status auto changes again (assumes it was enabled before). dataEditor.AutoChangeStatus = true; } }
public static ProtectedBinary Open(string strName, ProtectedBinary pb, BinaryDataOpenOptions opt) { if (string.IsNullOrEmpty(strName)) { Debug.Assert(false); return(null); } if (pb == null) { Debug.Assert(false); return(null); } if (opt == null) { opt = new BinaryDataOpenOptions(); } byte[] pbData = pb.ReadData(); if (pbData == null) { Debug.Assert(false); return(null); } BinaryDataHandler h = opt.Handler; if (h == BinaryDataHandler.Default) { h = ChooseHandler(strName, pbData, opt); } byte[] pbModData = null; if (h == BinaryDataHandler.InternalViewer) { DataViewerForm dvf = new DataViewerForm(); dvf.InitEx(strName, pbData); UIUtil.ShowDialogAndDestroy(dvf); } else if (h == BinaryDataHandler.InternalEditor) { DataEditorForm def = new DataEditorForm(); def.InitEx(strName, pbData); def.ShowDialog(); if (def.EditedBinaryData != null) { pbModData = def.EditedBinaryData; } UIUtil.DestroyForm(def); } else if (h == BinaryDataHandler.ExternalApp) { pbModData = OpenExternal(strName, pbData, opt); } else { Debug.Assert(false); } if ((pbModData != null) && !MemUtil.ArraysEqual(pbData, pbModData) && !opt.ReadOnly) { return(new ProtectedBinary(pb.IsProtected, pbModData)); } return(null); }
public static ProtectedBinary Open(string strName, ProtectedBinary pb, BinaryDataOpenOptions opt) { if (string.IsNullOrEmpty(strName)) { Debug.Assert(false); return(null); } if (pb == null) { Debug.Assert(false); return(null); } if (opt == null) { opt = new BinaryDataOpenOptions(); } byte[] pbData = pb.ReadData(); if (pbData == null) { Debug.Assert(false); return(null); } BinaryDataHandler h = opt.Handler; if (h == BinaryDataHandler.Default) { h = ChooseHandler(strName, pbData, opt); } byte[] pbModData = null; if (h == BinaryDataHandler.InternalViewer) { DataViewerForm dvf = new DataViewerForm(); dvf.InitEx(strName, pbData); UIUtil.ShowDialogAndDestroy(dvf); } else if (h == BinaryDataHandler.InternalEditor) { DataEditorForm def = new DataEditorForm(); def.InitEx(strName, pbData); def.ShowDialog(); if (def.EditedBinaryData != null) { pbModData = def.EditedBinaryData; } UIUtil.DestroyForm(def); } else if (h == BinaryDataHandler.ExternalApp) { pbModData = OpenExternal(strName, pbData, opt); } else { Debug.Assert(false); } ProtectedBinary r = null; if ((pbModData != null) && !MemUtil.ArraysEqual(pbData, pbModData) && !opt.ReadOnly) { if (FileDialogsEx.CheckAttachmentSize(pbModData.LongLength, KPRes.AttachFailed + MessageService.NewParagraph + strName)) { r = new ProtectedBinary(pb.IsProtected, pbModData); } } if (pb.IsProtected) { MemUtil.ZeroByteArray(pbData); } return(r); }