/* * adds current form to the stack of undo chain items */ private void AddToUndoChain(bool raiseUndoChainIndexChanged) { // we don't add this to the undo stack, unless it is either explicitly asked for, or it is the first // update to the form if (raiseUndoChainIndexChanged || UndoChain.Count == 0) { // removes any undo chains ahead of our curent index, in case user has executed undo, before this action int idxRemove = UndoChain.Count; while (idxRemove > UndoChainIndex) { UndoChain[--idxRemove].UnTie(); } // adding current datasource, and selected control to undo chain list UndoChain.Add(DataSource.Clone()); UndoChain[UndoChain.Count - 1]["_selected"].Value = SelectedControlDna; } if (raiseUndoChainIndexChanged) { UndoChainIndex = UndoChain.Count; RaiseUndoChainIndexChanged(); } }
protected void magix_ide_set_form(object sender, ActiveEventArgs e) { Node ip = Ip(e.Params); if (ShouldInspect(ip)) { AppendInspectFromResource( ip["inspect"], "Magix.ide", "Magix.ide.hyperlisp.inspect.hl", "[magix.ide.set-form-dox].value"); AppendCodeFromResource( ip, "Magix.ide", "Magix.ide.hyperlisp.inspect.hl", "[magix.ide.set-form-sample]"); return; } if (!SurfaceEnabled) { throw new ArgumentException("wysiwyg surface is not enabled"); } Node value = ip["value"]; Dictionary <string, bool> ids = new Dictionary <string, bool>(); bool allUnique = true; foreach (Node idxControl in value) { if (CheckControlIdUnique(idxControl, ids) == false) { allUnique = false; break; } } if (!allUnique) { Node msg = new Node(); msg["message"].Value = "not all controls had unique ids, please fix before surface can be updated"; RaiseActiveEvent( "magix.viewport.show-message", msg); return; } AddToUndoChain(!ip.ContainsValue("skip-undo") || !ip["skip-undo"].Get <bool>()); if (ip.ContainsValue("clear-undo") && ip["clear-undo"].Get <bool>()) { // clearing undo chain UndoChainIndex = 0; UndoChain.Clear(); RaiseUndoChainIndexChanged(); } bool fundamentalChanges = false; Node getControlsNodeBefore = RaiseActiveEvent("magix.ide.list-controls"); DataSource["controls"].Clear(); if (ip.Contains("value")) { DataSource["controls"].AddRange(value.Clone()); } Node getControlsNodeAfter = RaiseActiveEvent("magix.ide.list-controls"); foreach (Node idx in getControlsNodeBefore["controls"]) { if (!getControlsNodeAfter["controls"].Contains(idx.Name)) { fundamentalChanges = true; break; } } if (fundamentalChanges) { SelectedControlDna = null; } else if (ip.ContainsValue("clear-selection") && ip["clear-selection"].Get <bool>()) { SelectedControlDna = null; } foreach (Node idx in getControlsNodeAfter["controls"]) { string id = idx.Get <string>().Split(':')[1]; if (string.IsNullOrEmpty(id)) { // control has no id, creating one now ... Node ctrlNode = DataSource.FindDna(idx.Name); GetNextAvailableControlId(ctrlNode); } } BuildForm(); wrp.ReRender(); if (!ip.ContainsValue("no-update") || !ip["no-update"].Get <bool>()) { RaiseSurfaceAndSelectionChangedChanged(); } }