Exemplo n.º 1
0
        /// <summary>
        /// add text transformation for the "cut" operation
        /// </summary>
        /// <param name="selectionstart">Selection where the text was cut from</param>
        /// <param name="selectionend">Selection where the cut ended.</param>
        public void CutAdd(int selectionstart, int selectionend)
        {
            TextTransformActor t = new TextTransformActor(selectionstart, selectionend);

            queue.Add(t);
            this.thingy.Enqueue(t);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Call from rtbtext keypress event.
        /// </summary>
        /// <remarks>
        /// Please set the event argument's .handled=true.
        /// </remarks>
        /// <param name="q">the keypress arguments</param>
        /// <param name="selectionindex">index of the cursor</param>
        public void KeyPressadd(System.Windows.Forms.KeyPressEventArgs q, int selectionindex)
        {
            TextTransformActor req;

            req = new TextTransformActor(selectionindex, q.KeyChar);
            queue.Add(req);
            thingy.Enqueue(req);
        }
 public static byte[] GetObjectInBytes(TextTransformActor g)
 {
     System.Runtime.Serialization.Formatters.Binary.BinaryFormatter t = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
     System.IO.Stream y = new System.IO.MemoryStream();
     t.Serialize(y, g);
     byte[] q = new byte[y.Length];
     y.Read(q, 0, (int)y.Length);
     y.Close();
     return(q);
 }
Exemplo n.º 4
0
 private void SendTextTransformation()
 {
     while (true)
     {
         while (thingy.Count > 0)
         {
             server.Send(TextTransformActor.GetObjectInBytes(this.thingy.Dequeue()));
         }
     }
 }
Exemplo n.º 5
0
 private void RecieveandConsolidate()
 {
     byte[] buffery = new byte[1024];
     while (true)
     {
         server.Receive(buffery);
         lock (queue)
             queue.Add(TextTransformActor.GetObjectFromBytes(buffery));
     }
 }
Exemplo n.º 6
0
 public void Add(TextTransformActor ax)
 {
     if (ax.Command == TextTransformType.Initialize)
     {
         //set initial string and discard the actor
         this.initial = ax.Insert;
         ax           = null;
     }
     else
     {
         actions.Add(ax);
     }
 }
Exemplo n.º 7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="a">this is foo</param>
 /// <param name="b">this is bar</param>
 /// <returns>The comparison, context sensitive of course, used to order the list.</returns>
 private static int CompareTextActorTime(TextTransformActor a, TextTransformActor b)
 {
     //If both a and b are append commands, then it should be sorted out based on index. Should not come up on client side.
     if (a.Command == TextTransformType.Append && b.Command == TextTransformType.Append)
     {
         return(a.Index.CompareTo(b.Index));
     }
     //Appends are the most important part, they should be applied first
     if (a.Command == TextTransformType.Append && b.Command != TextTransformType.Append)
     {
         return(-1);
     }
     if (a.Command != TextTransformType.Append && b.Command == TextTransformType.Append)
     {
         return(1);
     }
     return(DateTime.Compare(a.time, b.time));
 }
Exemplo n.º 8
0
        /// <summary>
        /// Add text Transformation for backspace/Delete
        /// Call from rtbtext.previewkeydown(which is important)
        /// </summary>
        /// <param name="key">The keypress event</param>
        /// <param name="SelectionIndex">The index of the cursor</param>
        public void KeyPressDelete(System.Windows.Forms.PreviewKeyDownEventArgs key, int SelectionIndex)
        {
            TextTransformActor req;

            if (key.KeyCode == Keys.Back)
            {//Backspace, delete the character before the cursor.
                req = new TextTransformActor(SelectionIndex - 1, 1);
                req.AlterForClient();
                queue.Add(req);
                thingy.Enqueue(req);
            }
            if (key.KeyCode == Keys.Delete)
            {//Delete key, deletes the character in front of the cursor
                req = new TextTransformActor(SelectionIndex, 1);
                req.AlterForClient();
                queue.Add(req);
                thingy.Enqueue(req);
            }
        }
Exemplo n.º 9
0
        private int CalculateIndexOffset(TextTransformActor d)
        {
            int totaloffset = 0;

            for (int i = 0; actions[i].time < d.time; i++)
            {
                if (actions[i].Index <= d.Index)
                {
                    if (actions[i].Command == TextTransformType.Insert)
                    {
                        totaloffset += actions[i].Length;
                    }
                    else
                    {
                        totaloffset -= actions[i].Length;
                    }
                }
            }
            return(totaloffset);
        }
Exemplo n.º 10
0
        public void PasteAdd(int selectionstart, string insertedtext)
        {
            TextTransformActor r;

            if (insertedtext.Length <= 900)
            {
                r = new TextTransformActor(selectionstart, insertedtext);
                queue.Add(r);
            }
            else
            {
                string[] e = new string[insertedtext.Length / 900];
                for (int i = 0; i * 900 <= insertedtext.Length; i++)
                {
                    e[i] = insertedtext.Substring(0 + i * 900, 899 + i * 900);
                }
                for (int i = 0; i < e.Length; i++)
                {
                    r = new TextTransformActor(selectionstart + i * 900, e[i]);
                    this.queue.Add(r);
                }
            }
        }
Exemplo n.º 11
0
 /// <summary>
 /// Checks Whether a specific transform is inside the pool
 /// </summary>
 /// <param name="t"></param>
 /// <returns></returns>
 public bool ContainsTransform(TextTransformActor t)
 {
     return(this.actions.Contains(t));
 }