//editor void EditorDeclarationSelectionChanged(IStructDeclarer declarer, Declaration declaration) { if (declarer.Declaration == null || declarer.Declaration.Name != declaration.Name) { declarer.Declaration = declaration; (declarer.IOManager as IOManager).UpdateFromDeclaration(declaration); SetDescriptiveName(declarer, declaration.Name); } }
void SetDescriptiveName(IStructDeclarer declarer, string text) { FDescriptiveUpdates[declarer] = () => { var nodeHost = (declarer as IStructDeclareEmit).IOFactory.PluginHost; var label = nodeHost.GetPin("Descriptive Name")?.GetSpread(); //on create pins are null if (label != text) { var id = nodeHost.GetID(); var msg = $"<PATCH><NODE id=\"{id}\"><PIN pinname=\"Descriptive Name\" slicecount=\"1\" values=\"{text}\"></PIN></NODE></PATCH>"; FHDEHost.SendXMLSnippet(nodeHost.ParentNode.GetNodeInfo().Filename, msg, false); //nodeHost.GetPin("Descriptive Name")?.SetSpread(text); //gui doesn't save it this way } }; }
//load from config pin void LoadDeclaration(IPluginHost2 nodeHost, IStructDeclarer declarer, string text) { if (declarer.Declaration == null || declarer.Declaration.ToString() != text) //we are only interested in cache on startup { var d = FDeclarationFactory["Template"]; if (!string.IsNullOrWhiteSpace(text)) { d = FDeclarationFactory.Create(text); var existing = FDeclarationFactory.Get(d.Name); if (existing == null) //is new { FDeclarationFactory.Add(d, false); } else if (d.Equals(existing)) //equals existing, don't worry { d = existing; } else { var solution = FConflictMgr.Solve(nodeHost, d, FDeclarationFactory.FDeclarations); switch (solution.SolutionKind) { case ConflictManager.ConflictSolutionKind.Ignore: d = existing; break; case ConflictManager.ConflictSolutionKind.Split: d = FDeclarationFactory.Get(solution.DeclarationName); if (d == null) { d = FDeclarationFactory.Create(solution.DeclarationName, solution.DeclarationBody); FDeclarationFactory.Add(d, false); } break; case ConflictManager.ConflictSolutionKind.Overwrite: d = FDeclarationFactory.Create(solution.DeclarationName, solution.DeclarationBody); FDeclarationFactory.Update(existing.Name, d); break; } } } declarer.Declaration = d; (declarer.IOManager as IOManager).UpdateFromDeclaration(d); SetDescriptiveName(declarer, d.Name); } }
void EditorUpdateDeclaration(DeclarationUI ui, IStructDeclarer declarer, string newName, string newFields) { var oldDecl = declarer.Declaration; if (oldDecl.Name != newName && FDeclarationFactory.Get(newName) != null) { ui.AppendError($"Declaration named '{newName}' already exists"); return; } else if (!FDeclarationFactory.WellformedDeclarationName(newName)) { ui.AppendError($"Declaration name malformed"); return; } var d = FDeclarationFactory.Create(newName, newFields); if (!d.Equals(oldDecl)) { FDeclarationFactory.Update(oldDecl.Name, d); SetDescriptiveName(declarer, d.Name); } }
void EditorCreateDeclaration(DeclarationUI ui, IStructDeclarer declarer, string newName, string newFields) { if (!FDeclarationFactory.WellformedDeclarationName(newName)) { ui.AppendError($"Declaration name malformed"); return; } Declaration d = FDeclarationFactory.Get(newName); if (d == null) { d = FDeclarationFactory.Create(newName, newFields); FDeclarationFactory.Add(d); declarer.Declaration = d; (declarer.IOManager as IOManager).UpdateFromDeclaration(d); SetDescriptiveName(declarer, d.Name); } else { ui.AppendError($"Declaration named '{newName}' already exists"); } }