Esempio n. 1
0
 private void SetCursorToFirstLineOfNextPacket_IfItIsTheLastPacket()
 {
     REPLData.Packet lastPacket = null;
     for (int i = LineToUserPacket.Count - 1; i >= 0; i--)
     {
         if (LineToUserPacket[i] != null)
         {
             lastPacket = LineToUserPacket[i];
             break;
         }
     }
     REPLData.Packet thisPacket = LineToUserPacket[CursorLine];
     for (int i = CursorLine + 1; i < LineToUserPacket.Count; i++)
     {
         if (LineToUserPacket[i] != null && LineToUserPacket[i] != thisPacket && LineKinds[i] == REPLData.Kind.User)
         {
             if (LineToUserPacket[i] == lastPacket)
             {
                 CursorLine = i;
                 CursorX    = 2;
             }
             break;
         }
     }
 }
Esempio n. 2
0
 private void DeleteSelection()
 {
     REPLData.Packet packet = LineToUserPacket[CursorLine];
     if (packet != null)
     {
         int startLine  = LineToPacketLine[SelectionStartLine];
         int finishLine = LineToPacketLine[SelectionFinishLine];
         packet.User.DeleteRange(startLine, SelectionStartX, finishLine, SelectionFinishX);
         CursorLine = SelectionStartLine;
         CursorX    = SelectionStartX + 2;
         SetUpLines();
         SelectionActive = false;
         SendScrolleeInfo();
         InvalidateVisual();
     }
 }
Esempio n. 3
0
 private void SetCursorToFirstLineOfLastPacket()
 {
     REPLData.Packet lastPacket = null;
     for (int i = LineToUserPacket.Count - 1; i >= 0; i--)
     {
         if (LineToUserPacket[i] != null)
         {
             lastPacket = LineToUserPacket[i];
             int j = i;
             while (j > 0 && LineToUserPacket[j - 1] == lastPacket)
             {
                 j--;
             }
             CursorLine = j;
             CursorX    = 2;
             break;
         }
     }
 }
Esempio n. 4
0
        private void InputChar(char ch)
        {
            if (SelectionActive && (SelectionStartLine != SelectionFinishLine || SelectionStartX != SelectionFinishX))
            {
                DeleteSelection();
                if (ch == '\b' || ch == '\x7f')
                {
                    return;
                }
            }
            SelectionActive = false;

            REPLData.Packet packet     = LineToPacket[CursorLine];
            int             packetLine = LineToPacketLine[CursorLine];

            if (packetLine < 0)
            {
                packetLine = 1;
            }

            bool isShift = (Keyboard.Modifiers & ModifierKeys.Shift) != 0;

            if (ch == '\n' && isShift && !DoingInsert)
            {
                //if (packetLine +1 == packet.User.Count ) {
                string output = Command(packet.User.AsReadOnly());
                if (output != "")
                {
                    char first = output[0];
                    output           = output.Substring(1);
                    packet.Reply     = output.SplitIntoLines();
                    packet.ReplyKind = (first == '+') ? REPLData.Kind.Reply : REPLData.Kind.Error;
                    MakeSureEmptyPacketExists();
                    SetUpLines();
                    if (first == '+')
                    {
                        SetCursorToFirstLineOfNextPacket_IfItIsTheLastPacket();
                    }
                    SendScrolleeInfo();
                    InvalidateVisual();
                    return;
                }
                //}
            }

            if (LineKinds[CursorLine] == REPLData.Kind.User)
            {
                switch (ch)
                {
                case '\n':
                    string line1, line2;
                    Lines[CursorLine].SplitIntoTwo(CursorX - 2, out line1, out line2);
                    packet.User[packetLine] = line1;
                    packet.User.Insert(packetLine + 1, line2);
                    CursorLine++;
                    CursorX = 2;
                    SetUpLines();
                    break;

                case '\b':
                    if (CursorX == 2)
                    {
                        // Join line to previous, if there is a previous
                        if (packetLine == 0 || CursorLine == 0)
                        {
                            return;                           // There is no previous line.
                        }
                        CursorX = Lines[CursorLine - 1].Length + 2;
                        CursorLine--;
                        packet.User[packetLine - 1] += packet.User[packetLine];
                        packet.User.RemoveAt(packetLine);
                        SetUpLines();
                    }
                    else
                    {
                        // Just delete one character.
                        CursorX--;
                        packet.User[packetLine] = Lines[CursorLine] = Lines[CursorLine].RemoveCharAt(CursorX - 2);
                    }
                    break;

                case '\x7f':
                    if (CursorX - 2 >= Lines[CursorLine].Length)
                    {
                        // At end of the line, so merge in the following line (if there is one).
                        if (CursorLine + 1 < LineKinds.Count && LineKinds[CursorLine + 1] == REPLData.Kind.User)
                        {
                            packet.User[packetLine] = Lines[CursorLine] = Lines[CursorLine].PadRight(CursorX - 2) + Lines[CursorLine + 1];
                            packet.User.RemoveAt(packetLine + 1);
                            SetUpLines();
                        }
                    }
                    else
                    {
                        packet.User[packetLine] = Lines[CursorLine] = Lines[CursorLine].RemoveCharAt(CursorX - 2);
                    }
                    break;

                default:
                    packet.User[packetLine] = Lines[CursorLine] = Lines[CursorLine].InsertChar(CursorX - 2, ch);
                    CursorX++;
                    break;
                }
                SendScrolleeInfo();
                InvalidateVisual();
            }
        }
Esempio n. 5
0
        public string RestoreImage(string filename)
        {
            LexListBuilder allMethodsAndFields = new LexListBuilder();

            allMethodsAndFields.Add("partial class `Type {", "Type", typeof(REPL));
            if (filename == "")
            {
                foreach (var s in Directory.GetFiles(Path.GetDirectoryName(Persist.FileName), "*.cs"))
                {
                    Line(Path.GetFileNameWithoutExtension(s));
                }
                return("");
            }
            else
            {
                SaveImage("LastDeleted");
                Maker.Clear();
                Fields = new List <object>();

                List <REPLData.Packet> list = new List <REPLData.Packet>();
                try {
                    using (StreamReader sr = new StreamReader(CodeTextFileName(filename))) {
                        while (true)
                        {
                            if (sr.EndOfStream)
                            {
                                break;
                            }
                            List <string> user = ReadBlockOfLines(sr);
                            if (sr.EndOfStream)
                            {
                                break;
                            }
                            string        id   = sr.ReadLine();
                            REPLData.Kind kind = REPLData.Kind.Error;
                            switch (id)
                            {
                            case "Reply": kind = REPLData.Kind.Reply; break;

                            case "User": kind = REPLData.Kind.User; break;
                            }
                            if (sr.EndOfStream)
                            {
                                break;
                            }
                            List <string>   reply  = ReadBlockOfLines(sr);
                            REPLData.Packet packet = new REPLData.Packet()
                            {
                                Reply = reply, User = user, ReplyKind = kind
                            };
                            try {
                                switch (ExamineUserInput(user.AsReadOnly()))
                                {
                                case PacketAction.Method:
                                case PacketAction.Field:
                                    foreach (var s in user)
                                    {
                                        allMethodsAndFields.Add(s);
                                    }
                                    break;
                                }
                            } catch (Exception ex) {
                                packet.Reply = new List <string>()
                                {
                                    ex.Message
                                };
                            }
                            list.Add(packet);
                        }
                    }
                } catch (Exception ex) {
                    return("Failed: " + ex.Message);
                }
                ReplPanel.ChangeData(list);
                allMethodsAndFields.Add("}");
                Maker.AddMethodsAndFields(allMethodsAndFields.ToLexList(), true);

                MessageBox.Show(
                    "The image from '" + filename + "' has been restored.\n\n" +
                    "Please remember that only the methods and fields have been restored,\n" +
                    "the contents of the fields have not.\n" +
                    "So all fields are null or 0.", "NOTE!");
                return("");
            }
        }