private void miSetEvents_Click(object sender, EventArgs e) { MethodDiagramViewer mv = MethodViewer.GetCurrentViewer(); ILimnorDesignerLoader loader = mv.Loader; DlgSelectEvent dlg = new DlgSelectEvent(); dlg.LoadData(_menuData); DialogResult ret = dlg.ShowDialog(this.FindForm()); if (dlg.FrequentlyUsedMethodsChanged) { _menuData.RemoveMenuCollection(); loader.DesignPane.ResetContextMenu(); } if (ret == DialogResult.OK) { IEvent ei = dlg.ReturnEventInfo; if (ei != null) { EventPointer ep = ei as EventPointer; if (ep == null) { EventClass ec = ei as EventClass; if (ec != null) { EventClass ec2 = (EventClass)ec.Clone(); ec2.SetHolder(this.ClassPointer); CustomEventPointer cep = new CustomEventPointer(ec2, this.ClassPointer); ei = cep; } } assignAction(ei); } } }
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { if (context != null && context.Instance != null && provider != null) { IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); if (edSvc != null) { ActionAttachEvent aae = context.Instance as ActionAttachEvent; if (aae != null) { ClassPointer root = aae.Class; if (root != null) { ILimnorDesignerLoader loader = root.GetCurrentLoader(); if (loader != null) { EventHandlerMethod ehm = aae.GetHandlerMethod(); if (ehm != null) { DlgMethod dlg = ehm.GetEditDialog(Rectangle.Empty, loader); dlg.DisableAnimate(); if (edSvc.ShowDialog(dlg) == System.Windows.Forms.DialogResult.OK) { ehm.OnFinishEdit(aae.ActionId, loader); } } } } } } } return(value); }
protected override object OnEditValue(System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, System.Windows.Forms.Design.IWindowsFormsEditorService service, object value) { IWithProject mc = context.Instance as IWithProject; if (mc != null) { if (mc.Project == null) { MathNode.Log(TraceLogClass.GetForm(provider), new DesignerException("Project not set for {0} [{1}]", mc, mc.GetType())); } else { GetterClass val = value as GetterClass; System.Drawing.Point curPoint = System.Windows.Forms.Cursor.Position; rc.X = curPoint.X; rc.Y = curPoint.Y; DlgMethod dlg = val.CreateMethodEditor(rc); try { dlg.SetNameReadOnly(); dlg.LoadMethod(val, EnumParameterEditType.ReadOnly); dlg.Text = val.ToString(); if (service.ShowDialog(dlg) == DialogResult.OK) { value = val; ILimnorDesignerLoader l = LimnorProject.ActiveDesignerLoader as ILimnorDesignerLoader; if (l != null) { //save the property and hence save the getter DesignUtil.SaveCustomProperty(LimnorProject.ActiveDesignerLoader.Node, l.Writer, val.Property); //save actions List <IAction> actions = val.GetActions(); if (actions != null) { foreach (IAction a in actions) { l.GetRootId().SaveAction(a, l.Writer); } } LimnorProject.ActiveDesignerLoader.NotifyChanges(); } } } catch (Exception err) { MathNode.Log(TraceLogClass.GetForm(provider), err); } finally { val.ExitEditor(); } } } return(value); }
protected override void InitializeNewMethod(XmlNode rootNode, ILimnorDesignerLoader loader) { MemberId = (UInt32)Guid.NewGuid().GetHashCode(); if (string.IsNullOrEmpty(Name)) { Name = loader.CreateMethodName("h", null); } else { Name = loader.CreateMethodName(Name, null); } }
public void OnFinishEdit(UInt32 actionBranchId, ILimnorDesignerLoader loader) { try { ILimnorDesignPane dp = loader.DesignPane; if (dp == null) { throw new DesignerException("ILimnorDesignPane not found for class {0}", loader.GetRootId()); } IEvent ep = _event; EventAction ea = null; //event-actions mapping ClassPointer a = loader.GetRootId(); if (a != null) { List <EventAction> lst = a.EventHandlers; if (lst != null) { foreach (EventAction e in lst) { if (e.GetAssignActionId() == actionBranchId && e.Event.IsSameObjectRef(ep)) { ea = e; break; } } } } if (ea == null) { ea = new EventAction(); ea.Event = ep; if (actionBranchId != 0) { ea.SetAssignActionId(actionBranchId); } } _handlerOwner = ea; ea.AddAction(this); a.SaveEventHandler(ea); dp.OnNotifyChanges(); dp.OnAssignAction(ea); } catch (Exception err) { MathNode.Log(TraceLogClass.MainForm, err); } finally { this.ExitEditor(); } }
public override bool Edit(UInt32 actionBranchId, Rectangle rcStart, ILimnorDesignerLoader loader, Form caller) { if (Owner == null) { Owner = loader.GetRootId(); } try { _origiContext = VPLUtil.CurrentRunContext; if (loader.Project.IsWebApplication) { if (this.RunAt == EnumWebRunAt.Client) { VPLUtil.CurrentRunContext = EnumRunContext.Client; } else { VPLUtil.CurrentRunContext = EnumRunContext.Server; } } else { VPLUtil.CurrentRunContext = EnumRunContext.Server; } DlgMethod dlg = this.CreateMethodEditor(rcStart); dlg.LoadMethod(this, EnumParameterEditType.ReadOnly); if (dlg.EditSubAction(caller)) { IsNewMethod = false; loader.GetRootId().SaveAction(this, loader.Writer); loader.NotifyChanges(); return(true); } } catch (Exception err) { MathNode.Log(caller, err); } finally { ExitEditor(); VPLUtil.CurrentRunContext = _origiContext; } return(false); }
public DlgMethod GetEditDialog(Rectangle rcStart, ILimnorDesignerLoader loader) { if (Owner == null) { MathNode.Log(loader.DesignPane.Window as Form, new DesignerException("Calling EventHandlerMethod.Edit with null method owner")); } if (this.Owner == null) { this.Owner = loader.GetRootId(); } DlgMethod dlg = this.CreateMethodEditor(rcStart); if (Parameters != null && Parameters.Count > 0) { if (typeof(object).Equals(Parameters[0].ObjectType) && string.CompareOrdinal(Parameters[0].Name, "sender") == 0) { Parameters[0] = new ParameterClass(this.Event.Owner.ObjectType, "sender", this); Parameters[0].ReadOnly = true; } if (Parameters.Count > 1) { if (typeof(EventArgs).Equals(Parameters[1].ObjectType) && string.CompareOrdinal(Parameters[1].Name, "e") == 0) { ICustomEventMethodDescriptor ce = this.Event.Owner.ObjectInstance as ICustomEventMethodDescriptor; if (ce != null) { Type pType = ce.GetEventArgumentType(this.Event.Name); if (pType != null) { Parameters[1] = new ParameterClass(pType, "e", this); Parameters[1].ReadOnly = true; } } } } } dlg.LoadMethod(this, EnumParameterEditType.ReadOnly); return(dlg); }
private void mi_loadDrawing(object sender, EventArgs e) { MenuItem mi = sender as MenuItem; if (mi != null) { IDrawDesignControl drc = mi.Tag as IDrawDesignControl; if (drc != null && drc.Item != null) { IDesignerHost host = (IDesignerHost)this.GetService(typeof(IDesignerHost)); if (host != null) { HostSurface surface = host.GetService(typeof(DesignSurface)) as HostSurface; if (surface != null) { ClassPointer root = surface.Loader.GetRootId(); if (root != null) { ILimnorDesignerLoader ldp = root.GetDesignerLoader(); if (ldp != null) { IDesignPane idp = ldp.DesignPane as IDesignPane; OpenFileDialog dlg = new OpenFileDialog(); dlg.CheckFileExists = true; dlg.DefaultExt = ".xml"; dlg.Filter = "XML files|*.xml"; dlg.Title = "Select XML file for loading drawing"; if (dlg.ShowDialog(drc.Item.Page) == DialogResult.OK) { drc.Item.LoadDrawingsFromFile(dlg.FileName, idp, drc); } } } } } } } }
public override bool ReloadMethod(ILimnorDesignerLoader loader) { try { XmlNode nodeMethod = loader.Node.SelectSingleNode(string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}/{1}[@{2}='{3}']", XmlTags.XML_CONSTRUCTORS, XmlTags.XML_Item, XmlTags.XMLATT_MethodID, MemberId)); if (nodeMethod != null) { loader.Reader.ReloadObjectFromXmlNode <MethodClass>(nodeMethod, this); return(true); } else { throw new DesignerException("Error calling ReloadMethod. Constructor node not found for id [{0},{1}]", ClassId, MemberId); } } catch (Exception err) { MathNode.Log(TraceLogClass.MainForm, err); } return(false); }
public override bool Edit(UInt32 actionBranchId, Rectangle rcStart, ILimnorDesignerLoader loader, Form caller) { try { _origiContext = VPLUtil.CurrentRunContext; if (loader.Project.IsWebApplication) { if (this.RunAt == EnumWebRunAt.Client) { VPLUtil.CurrentRunContext = EnumRunContext.Client; } else { VPLUtil.CurrentRunContext = EnumRunContext.Server; } } else { VPLUtil.CurrentRunContext = EnumRunContext.Server; } DlgMethod dlg = GetEditDialog(rcStart, loader); if (dlg.ShowDialog(caller) == DialogResult.OK) { OnFinishEdit(actionBranchId, loader); return(true); } } catch (Exception err) { MathNode.Log(caller, err); } finally { VPLUtil.CurrentRunContext = _origiContext; } return(false); }
protected override void OnEditAction() { MethodDiagramViewer mv = this.DiagramViewer; if (mv != null) { ILimnorDesignerLoader loader = mv.DesignerHolder.Designer as ILimnorDesignerLoader; ISingleAction av = this.ActionObject as ISingleAction; string name = av.ActionData.ActionName; FormProgress.HideProgress(); if (av.ActionData.Edit(loader.Writer, mv.Method, this.FindForm(), false)) { if (name != av.ActionData.ActionName) { IMethodDiagram p = this.Parent as IMethodDiagram; if (p != null) { p.OnActionNameChanged(av.ActionData.ActionName, av.ActionId.WholeTaskId); } } mv.Changed = true; } } }
public override void OnNodeSelection(ILimnorDesignerLoader loader) { loader.NotifySelection(this.OwnerIdentity); }
public static IWebHost CreateHtmlHost(ILimnorDesignerLoader loader, Form caller) { IWebHost host = null; Encoding encode = Encoding.Unicode; string docType = null; VirtualWebDir webSite = WebHost.GetWebSite(loader.Project, caller); if (webSite != null) { installHtmlEdiotr(caller); if (!loader.Project.WebFolderGranted) { string err = VPLUtil.GrantFolderFullPermission(webSite.PhysicalDirectory); if (string.IsNullOrEmpty(err)) { loader.Project.SetWebFolderGranted(); } else { MessageBox.Show(caller, string.Format(CultureInfo.InvariantCulture, "Error granting permissions to [{0}]. {1}", webSite.PhysicalDirectory, err), "Web Editor", MessageBoxButtons.OK, MessageBoxIcon.Error); } } WebPage wpage = loader.RootObject as WebPage; bool openWebTab = true; string hf = WebHost.GetHtmlFile(loader.ComponentFilePath); //saved HTML file string editFile = Path.Combine(webSite.PhysicalDirectory, Path.GetFileName(hf)); //in WebFiles //create editFile contents if (File.Exists(hf)) { try { //set editing file to the doc type for editing (IE requirement) //for Chrome, try not to do it string line; StringBuilder sbBeforeHtml = new StringBuilder(); bool gotHtml = false; StreamReader sr = new StreamReader(hf, true); encode = sr.CurrentEncoding; while (!sr.EndOfStream) { line = sr.ReadLine(); if (gotHtml) { } else { if (!string.IsNullOrEmpty(line)) { int pos = line.IndexOf("<html", StringComparison.OrdinalIgnoreCase); if (pos >= 0) { if (pos > 0) { sbBeforeHtml.Append(line.Substring(0, pos)); } docType = sbBeforeHtml.ToString(); gotHtml = true; break; //for Chrome } else { sbBeforeHtml.Append(line); sbBeforeHtml.Append("\r\n"); } } } } sr.Close(); } catch (Exception err) { MessageBox.Show(caller, string.Format(CultureInfo.InvariantCulture, "Error copying [{0}] to [{1}]. {2}", hf, editFile, err.Message), "Load HTML", MessageBoxButtons.OK, MessageBoxIcon.Error); openWebTab = false; } //for Chrome if (openWebTab) { try { File.Copy(hf, editFile, true); } catch (Exception err) { MessageBox.Show(caller, string.Format(CultureInfo.InvariantCulture, "Error copying from [{0}] to [{1}]. {2}.", hf, editFile, err.Message), "Load HTML", MessageBoxButtons.OK, MessageBoxIcon.Error); openWebTab = false; } } if (openWebTab) { int p0 = hf.LastIndexOf('.'); if (p0 > 0) { string css = string.Format(CultureInfo.InvariantCulture, "{0}.css", hf.Substring(0, p0)); if (File.Exists(css)) { string tgt = Path.Combine(webSite.PhysicalDirectory, Path.GetFileName(css)); try { File.Copy(css, tgt, true); } catch (Exception err) { MessageBox.Show(caller, string.Format(CultureInfo.InvariantCulture, "Error copying from [{0}] to [{1}]. {2}.", css, tgt, err.Message), "Load HTML", MessageBoxButtons.OK, MessageBoxIcon.Error); openWebTab = false; } } } } } else { try { StreamWriter sw = new StreamWriter(editFile); sw.Write(Resources.emptyPageEdit); sw.Close(); } catch (Exception err) { MessageBox.Show(caller, string.Format(CultureInfo.InvariantCulture, "Error creating empty html file for editing: [{0}]. {1}", editFile, err.Message), "Load HTML", MessageBoxButtons.OK, MessageBoxIcon.Error); openWebTab = false; } } if (openWebTab) { try { CopyJsLib(webSite.PhysicalDirectory); CopyJsColor(webSite.PhysicalDirectory); } catch (Exception err) { MathNode.Log(err, "Error preparing html file for editing: [{0}]", editFile); openWebTab = false; } bool bErr; string rootPath = IisUtility.FindLocalRootWebPath(caller, out bErr); if (string.IsNullOrEmpty(rootPath)) { MathNode.Log("Cannot get physical path for web root."); } else { string libjs = Path.Combine(rootPath, "libjs"); if (!Directory.Exists(libjs)) { try { Directory.CreateDirectory(libjs); } catch (Exception err2) { MathNode.Log(err2, "Error creating web folder: [{0}]", libjs); } } string jsfile = Path.Combine(libjs, "htmlEditorClient.js"); if (!File.Exists(jsfile)) { try { StreamWriter sw = new StreamWriter(jsfile, false, Encoding.ASCII); sw.Write(Resources.htmleditorClient); sw.Close(); } catch (Exception err3) { MathNode.Log(err3, "Error creating file: [{0}]", jsfile); } } } } if (openWebTab) { #if USECEF if (IntPtr.Size == 4) { WebHostX86 hx86 = new WebHostX86(); host = hx86; hx86.LoadWebHost(loader.Project.ProjectFolder, webSite.PhysicalDirectory, webSite.WebName, editFile, encode, docType, wpage); } else { } //host.SetHtmlFile(editFile, webSite.WebName); #else host = new WebHost(loader.Project.ProjectFolder, webSite.PhysicalDirectory, webSite.WebName, editFile, encode, docType, wpage); host.SetEncode(encode); if (!string.IsNullOrEmpty(docType)) { host.SetDocType(docType); } #endif wpage.RefreshWebDisplay(); } } return(host); }
public TopActionGroupDesignerHolder(ILimnorDesignerLoader designer) : base(designer, 0) { }
public override object OnGetDropDownControl(ITypeDescriptorContext context, IServiceProvider provider, IWindowsFormsEditorService service, object value) { ComponentPointer cp = (ComponentPointer)value; IComponent h = context.Instance as IComponent; if (h == null || h.Site == null) { h = VPL.VPLUtil.GetObject(context.Instance) as IComponent; } if (h == null || h.Site == null) { ClassPointer root = context.Instance as ClassPointer; if (root != null) { h = root.ObjectInstance as IComponent; } } if (h == null || h.Site == null) { IObjectPointer op = context.Instance as IObjectPointer; if (op != null) { ClassPointer root = op.RootPointer; if (root != null) { h = root.ObjectInstance as IComponent; } } } if (h != null && h.Site != null) { ListBox list = new ListBox(); list.Tag = service; list.Click += new EventHandler(list_Click); list.KeyPress += new KeyPressEventHandler(list_KeyPress); foreach (IComponent ic in h.Site.Container.Components) { if (ic is T) { list.Items.Add(new ComponentName(ic)); } else { Type t = VPL.VPLUtil.GetObjectType(ic); if (typeof(T).IsAssignableFrom(t)) { int n = list.Items.Add(new ComponentName(ic)); if (cp != null && list.SelectedIndex < 0 && ic.Site != null) { if (cp.Name == ic.Site.Name) { list.SelectedIndex = n; } } } } } if (list.Items.Count > 0) { service.DropDownControl(list); if (list.SelectedIndex >= 0) { ComponentName c = list.Items[list.SelectedIndex] as ComponentName; if (c != null) { ILimnorDesignerLoader loader = LimnorProject.ActiveDesignerLoader as ILimnorDesignerLoader; UInt32 memberId = loader.ObjectMap.GetObjectID(c.Component); if (memberId != 0) { XmlNode nodeCr = SerializeUtil.GetClassRefNodeByObjectId(loader.Node, memberId); if (nodeCr != null) { loader.Reader.ResetErrors(); ClassInstancePointer cr = loader.Reader.ReadObject <ClassInstancePointer>(nodeCr, loader.GetRootId()); if (loader.Reader.HasErrors) { MathNode.Log(loader.Reader.Errors); } ComponentPointer pt = new ComponentPointer(cr); value = pt; } else { MemberComponentId cid = new MemberComponentId(loader.GetRootId(), c.Component, memberId); ComponentPointer pt = new ComponentPointer(cid); value = pt; } } } } } } return(value); }
public WebClientHandlerDesignerHolder(ILimnorDesignerLoader designer, UInt32 scopeId) : base(designer, scopeId) { }
public override bool Edit(UInt32 actionBranchId, Rectangle rcStart, ILimnorDesignerLoader loader, Form caller) { if (this.Owner == null) { this.Owner = loader.GetRootId(); } DlgMethod dlg = this.CreateMethodEditor(rcStart); try { _origiContext = VPLUtil.CurrentRunContext; if (loader.Project.IsWebApplication) { if (this.RunAt == EnumWebRunAt.Client) { VPLUtil.CurrentRunContext = EnumRunContext.Client; } else { VPLUtil.CurrentRunContext = EnumRunContext.Server; } } else { VPLUtil.CurrentRunContext = EnumRunContext.Server; } dlg.LoadMethod(this, EnumParameterEditType.Edit); if (dlg.ShowDialog(caller) == DialogResult.OK) { _display = null; XmlNode nodeMethodCollection = loader.Node.SelectSingleNode(XmlTags.XML_CONSTRUCTORS); if (nodeMethodCollection == null) { nodeMethodCollection = loader.Node.OwnerDocument.CreateElement(XmlTags.XML_CONSTRUCTORS); loader.Node.AppendChild(nodeMethodCollection); } XmlNode nodeMethod = nodeMethodCollection.SelectSingleNode( string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}[@{1}='{2}']", XmlTags.XML_Item, XmlTags.XMLATT_MethodID, MemberId)); if (nodeMethod == null) { nodeMethod = nodeMethodCollection.OwnerDocument.CreateElement(XmlTags.XML_Item); nodeMethodCollection.AppendChild(nodeMethod); } XmlUtil.SetAttribute(nodeMethod, XmlTags.XMLATT_MethodID, MemberId); XmlUtil.SetAttribute(nodeMethod, XmlTags.XMLATT_NAME, Name); XmlObjectWriter wr = loader.Writer; wr.WriteObjectToNode(nodeMethod, this); if (wr.HasErrors) { MathNode.Log(wr.ErrorCollection); } ILimnorDesignPane pane = loader.Project.GetTypedData <ILimnorDesignPane>(loader.ObjectMap.ClassId); pane.OnNotifyChanges(); return(true); } } catch (Exception err) { MathNode.Log(caller, err); } finally { ExitEditor(); VPLUtil.CurrentRunContext = _origiContext; } return(false); }
protected override void InitializeNewMethod(XmlNode rootNode, ILimnorDesignerLoader loader) { MemberId = (UInt32)(Guid.NewGuid().GetHashCode()); }
public ActionGroupDesignerHolder(ILimnorDesignerLoader designer, UInt32 scopeId) : base(designer, scopeId) { }
public override void OnNodeSelection(ILimnorDesignerLoader loader) { loader.NotifySelection(_connect); }
public override void OnNodeSelection(ILimnorDesignerLoader loader) { loader.NotifySelection(HtmlElement); }