/// <summary> /// 编辑行事件处理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <returns></returns> bool ModifyLineEvent(object sender, ModifyLineEventArgs e) { if (TextDoc.GetLineCounts() > e.TargetLineIndex || e.TargetLineIndex <= 0) { return(false); } else { TextLine targetLine = this.TextDoc.GetTextLineByIndex(e.TargetLineIndex); if (targetLine == null) { return(false); } targetLine.EditContent(e.NewContent); targetLine.Mark = LineMarkType.Changed; MessageQueues.MessagesToSend.Enqueue(MessageWrapper.WriteMsg(this.CallerID, this.Identity, MessageType.UPD, targetLine.ID, e.NewContent)); return(true); } }
/// <summary> /// 处理UPD消息 /// </summary> /// <param name="callerID"></param> /// <param name="lineHash"></param> /// <param name="content"></param> /// <param name="sc"></param> public static void DoUpd(string callerID, int lineHash, string content, SynchronousController sc) { TextLine targetLine = sc.TextDoc.GetLineByHash(lineHash); if (targetLine.Mark == LineMarkType.Changed) { //自己的修改消息会先到达对面,无需发确认消息对面也会知道冲突存在 //TODO:调用消息告知发生冲突的位置和对方文本,由编辑器显示(建议在对应行的下方以另一种颜色显示) return; } if (targetLine.Mark == LineMarkType.Deleted) { //由于删除优先级最高,故对方的该行也将被删除,不必回复确认消息 return; } if (targetLine.Mark == LineMarkType.UnChanged) { targetLine.EditContent(content); int index = sc.TextDoc.GetIndexByHash(lineHash); sc.ToModifyLine(index, content); sc.MessageQueues.MessagesToSend.Enqueue(MessageWrapper.WriteMsg(callerID, sc.Identity, MessageType.VRF, lineHash, "UPD" + content)); return; } }