private UndoRedoSetup() { UtilTrace.Ini(); UndoEnable = new UndoEnableEnt(); //UndoEnable.redoRect = new System.Drawing.Rectangle(912, 95, 16, 18); //UndoEnable.undoRect = new System.Drawing.Rectangle(884, 95, 16, 18); //this.tabControl1.OnDrawControl += new PaintEventHandler(UndoEnable.ShowIcons); RegEnt = new RegUndoEnt(); RegEnt.funHandler += delegate() { //BindToControl(); }; RegEnt.enable = UndoEnable; //newUtilTrace.UtilTrace.ViewModel = this; //UtilTrace.tbMain = tabControl1; //regEnt.vm = this; //regEnt.tb = tabControl1; //UtilTrace.SaveHistoryTraces(); //UtilTrace.SaveHistoryTraces("tab", this.tabControl1.SelectedTab, null); UtilTrace.RegUndo(RegEnt); UtilTrace.ChkMainUndo += delegate() { //BindToControl(); RegEnt.ChkUndoEnable(); //this.Invalidate(); }; IsInitialized = false; }
/// <summary> /// 保存历史痕迹 /// </summary> /// <param name="type">类型</param> /// <param name="data">数据</param> /// <param name="ent">注册实体</param> public static void SaveHistoryTraces(string type, object data, RegUndoEnt ent) { var index = 0; for (var i = 0; i < _PrjList.Count; i++) { if (_PrjList[i].id == _currentHistoryId) { index = i; break; } } index = index + 1; if (index < _PrjList.Count) { _PrjList.RemoveRange(index, _PrjList.Count - index); } var _his_data = new TraceEnt(); _his_data.id = Guid.NewGuid().ToString(); if (!string.IsNullOrEmpty(type) && data != null) { _his_data.type = type; _his_data.data = data; if (type == "tab") { //定义实现选项卡切换撤销方法 _his_data.eventHandler += delegate() { isTabSwitching = true; //tbMain.SelectedTab = (TabPage)_his_data.data; isTabSwitching = false; }; } } else { _his_data.type = "prj"; //ViewModel.DoSavePipingStructure(); _his_data.data = Project.GetProjectInstance.DeepClone(); } _PrjList.Add(_his_data); _currentHistoryId = _his_data.id; if (ChkMainUndo != null) { ChkMainUndo(); } if (ent != null) { ent.ChkUndoEnable(); } EnableUndo?.Invoke(); EnableRedo?.Invoke(); }
/// <summary> /// 注册撤销实体方法 /// </summary> /// <param name="regEnt"></param> public static void RegUndo(RegUndoEnt regEnt) { regEnt.lockkey = Guid.NewGuid().ToString(); regEnt.enable.revoke = true; regEnt.enable.back = true; //注册当前锁定标识位 LockHistoryTrace(regEnt.lockkey); //实现检查撤销状态委托对象方法 regEnt.ChkUndoEnableHandler += delegate() { var ret = ChkUndoEnable(regEnt.lockkey); regEnt.enable.revoke = ret.revoke; regEnt.enable.back = ret.back; if (regEnt.tb != null) { regEnt.tb.Invalidate(); } }; //实现向前撤销委托对象方法 regEnt.undoHandler += delegate() { System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor; var ret = RevokeTrace(regEnt.lockkey); regEnt.fun(); regEnt.enable.revoke = ret.revoke; regEnt.enable.back = ret.back; ChkMainUndo(); ReLoadMain(); EnableRedo?.Invoke(); System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default; }; //实现向后撤销委托对象方法 regEnt.redoHandler += delegate() { System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor; var ret = BackTrace(); regEnt.fun(); regEnt.enable.revoke = ret.revoke; regEnt.enable.back = ret.back; ChkMainUndo(); ReLoadMain(); EnableUndo?.Invoke(); System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default; }; }