Example #1
0
        public static void PrompToCreateFile()
        {
            Console.Write("Enter File Name:");
            string FileName = Console.ReadLine();

            HtmlFilehandler.CreateFile(FileName);
        }
Example #2
0
        public static void PromptToLoadFile()
        {
            Console.Write("Enter File To Load:");
            string FileName = Console.ReadLine() + ".txt";

            if (File.Exists(Path.Combine(HtmlFilehandler.FilePath, FileName)) && HtmlFilehandler.FileHtmlName != FileName)
            {
                HtmlFilehandler.SetEditorLines(Path.Combine(HtmlFilehandler.FilePath, HtmlFilehandler.SerealizedEditorPrefix + FileName));
                HtmlFilehandler.SetFileName(FileName.Remove(FileName.Length - 4, 4));
            }
            else
            {
                Console.WriteLine("FileNotFound");
            }
        }
Example #3
0
        public static void CommandPrompt(ConsoleKeyInfo UserInput, Characters[][] List)
        {
            if (TagsListActive == false)
            {
                if (UserInput.Modifiers == ConsoleModifiers.Control)
                {
                    switch (UserInput.Key)
                    {
                    case ConsoleKey.R:
                        HtmlFilehandler.LoadHtml();
                        break;

                    case ConsoleKey.W:
                        HtmlFilehandler.SaveHtml();
                        break;

                    case ConsoleKey.O:
                        HtmlFilehandler.OpenHtmlFile();
                        break;

                    case ConsoleKey.N:
                        if (HtmlFilehandler.FileName == "")
                        {
                            UserInterFace.PrompToCreateFile();
                            Console.Clear();
                            Console.SetCursorPosition(left, top);
                        }
                        else
                        {
                            Console.Clear();
                            left = 0; top = 0;
                            Console.SetCursorPosition(left, top);
                            UserInterFace.PrompToCreateFile();
                            ClearWrite(false, false, true);

                            Console.SetCursorPosition(left, top);
                        }

                        break;
                    }
                }
                else if (UserInput.Modifiers == ConsoleModifiers.Alt)
                {
                    switch (UserInput.Key)
                    {
                    case ConsoleKey.R:
                        Console.Clear();
                        left = 0; top = 0;
                        Console.SetCursorPosition(left, top);
                        UserInterFace.PromptToLoadFile();
                        ClearWrite(false, false, true);

                        Console.SetCursorPosition(left, top);
                        break;

                    case ConsoleKey.T:
                        TagsListActive = true;
                        ClearWrite(true, false, false);
                        UserInterFace.PromptToSelectTags();
                        leftTags = Console.CursorLeft;
                        topTags  = Console.CursorTop;
                        break;
                    }
                }
                else
                {
                    switch (UserInput.Key)
                    {
                    case ConsoleKey.Delete:
                        TextEditor.DeleteChar(left, top);
                        Console.SetCursorPosition(left, top);

                        break;

                    case ConsoleKey.Enter:
                        EnterPressed = true;
                        TextEditor.TruncateAndInsert(List, top);
                        TextEditor.InsertLines(List, left, top);
                        TextEditor.LinesWithText();
                        EnterPressed = false;
                        break;

                    case ConsoleKey.Backspace:
                        DeletePressed = true;
                        if (left != 0)
                        {
                            TextEditor.BackSpace(left, top);
                            TextEditor.WriteRange(left - 1, top, List, TextEditor.NonEmptyCharCounter(top, List) + 1);
                            left--;
                            Console.SetCursorPosition(left, top);
                        }

                        break;

                    case ConsoleKey.RightArrow:
                        if (MoveNext(left, top, UserInput)[0] == false && TextEditor.NonEmptyCharCounter(top, List) == left)
                        {
                            Console.SetCursorPosition(left, top);
                            NavigateEditorLines(left, top, List);
                        }
                        else if (MoveNext(left, top, UserInput)[0] == false && TextEditor.DefaultLineLength == left + 1)
                        {
                            Console.SetCursorPosition(left, top);
                            NavigateEditorLines(left, top, List);
                        }
                        else
                        {
                            left++;
                            Console.SetCursorPosition(left, top);
                            NavigateEditorLines(left, top, List);
                        }

                        break;

                    case ConsoleKey.LeftArrow:
                        if (left != 0)
                        {
                            left--;
                        }
                        Console.SetCursorPosition(left, top);
                        NavigateEditorLines(left, top, List);
                        break;

                    case ConsoleKey.UpArrow:
                        if (MoveNext(left, top, UserInput)[1] == true && top != 0 && List[top - 1][left].Character == '\0')
                        {
                            if (TextEditor.NonEmptyCharCounter(top - 1, List) == TextEditor.DefaultLineLength)
                            {
                                left = TextEditor.NonEmptyCharCounter(top - 1, List) - 1;
                            }

                            else
                            {
                                left = TextEditor.NonEmptyCharCounter(top - 1, List);
                            }

                            top--;
                            Console.SetCursorPosition(left, top);
                            NavigateEditorLines(left, top, List);
                        }
                        else if (MoveNext(left, top, UserInput)[1] == true && top != 0 && List[top - 1][left].Character != '\0')
                        {
                            top--;
                            Console.SetCursorPosition(left, top);
                            NavigateEditorLines(left, top, List);
                        }
                        else
                        {
                            if (top != 0)
                            {
                                top--;
                                Console.SetCursorPosition(left, top);
                                NavigateEditorLines(left, top, List);
                            }

                            else
                            {
                                Console.SetCursorPosition(left, top);
                                NavigateEditorLines(left, top, List);
                            }
                        }


                        break;

                    case ConsoleKey.DownArrow:
                        if (top == List.Length - 1)
                        {
                            Console.SetCursorPosition(left, top);
                            NavigateEditorLines(left, top, List);
                        }
                        else
                        {
                            if (MoveNext(left, top, UserInput)[2] == false)
                            {
                                top++;
                                left = 0;
                                Console.SetCursorPosition(left, top);
                                NavigateEditorLines(left, top, List);
                            }
                            else if (MoveNext(left, top, UserInput)[2] == true && List[top + 1][left].Character != '\0')
                            {
                                top++;
                                Console.SetCursorPosition(left, top);
                                NavigateEditorLines(left, top, List);
                            }
                            else if (MoveNext(left, top, UserInput)[2] == true && List[top + 1][left].Character == '\0')
                            {
                                left = TextEditor.NonEmptyCharCounter(top + 1, List);
                                top++;
                                Console.SetCursorPosition(left, top);
                                NavigateEditorLines(left, top, List);
                            }
                        }

                        break;

                    default:
                        if (TextEditor.WithinText(left, top) == true)
                        {
                            Console.Write(UserInput.KeyChar);
                            TextEditor.InsertCharWithinText(UserInput.KeyChar, left, top);
                            TextEditor.WriteRange(left + 1, top, List, TextEditor.NonEmptyCharCounter(top, List));
                            DeletePressed = false;
                            NavigateEditorLines(left, top, List);
                            left++;
                            Console.SetCursorPosition(left, top);
                            if (CurrentChar == '>')
                            {
                                HtmlFilehandler.SaveHtml();
                            }
                        }
                        else
                        {
                            TextEditor.WriteToEditorLinesAtEnd(UserInput.KeyChar, left, top);
                            NavigateEditorLines(left, top, List);
                            left++;
                            Console.SetCursorPosition(left, top);
                            if (CurrentChar == '>')
                            {
                                HtmlFilehandler.SaveHtml();
                            }
                            DeletePressed = false;
                        }

                        break;
                    }
                }
            }
            else
            {
                if (UserInput.Modifiers == ConsoleModifiers.Control)
                {
                    switch (UserInput.Key)
                    {
                    case ConsoleKey.E:
                        ClearWrite(false, false, true);
                        TagsListActive = false;
                        break;
                    }
                }
                else
                {
                    char         OutOfRange = '\0';
                    Characters[] ToInsert   = HtmlTagsLibrary.GetTagToInsert(left, top, topTags);
                    switch (UserInput.Key)
                    {
                    case ConsoleKey.Tab:
                        string Tags       = new string((from v in ToInsert select v.Character).ToArray());
                        string openingTag = Tags.Split('>')[0] + '>';
                        string ClosingTag = Tags.Split('>')[1] + '>';
                        for (int i = 0; i < openingTag.Length; i++)
                        {
                            TextEditor.InsertCharWithinText(openingTag[i], left + i, top);
                        }
                        ClearWrite(false, false, true);
                        Console.SetCursorPosition(left, top);
                        loopMoveRight = true;
                        while (loopMoveRight == true)
                        {
                            ConsoleKeyInfo CKI = Console.ReadKey(true);
                            MoveRight(CKI, ClosingTag, left);
                            Console.SetCursorPosition(left, top);
                        }
                        TagsListActive = false;
                        break;

                    case ConsoleKey.Enter:

                        for (int i = 0; i < ToInsert.Length; i++)
                        {
                            TextEditor.InsertCharWithinText(ToInsert[i].Character, left + i, top);
                        }
                        ClearWrite(false, false, true);
                        Console.SetCursorPosition(left, top);
                        TagsListActive = false;
                        break;

                    case ConsoleKey.RightArrow:
                        leftTags++;
                        Console.SetCursorPosition(leftTags, topTags);
                        NavigateEditorLines(leftTags, topTags, HtmlTagsLibrary.LibraryEditorLines);
                        break;

                    case ConsoleKey.UpArrow:
                        topTags--;
                        Console.SetCursorPosition(leftTags, topTags);
                        NavigateEditorLines(leftTags, topTags, HtmlTagsLibrary.LibraryEditorLines);
                        break;

                    case ConsoleKey.LeftArrow:
                        if (leftTags != 0)
                        {
                            leftTags--;
                            Console.SetCursorPosition(leftTags, topTags);
                            NavigateEditorLines(leftTags, topTags, HtmlTagsLibrary.LibraryEditorLines);
                        }

                        break;

                    case ConsoleKey.DownArrow:
                        topTags++;
                        Console.SetCursorPosition(leftTags, topTags);
                        NavigateEditorLines(leftTags, topTags, HtmlTagsLibrary.LibraryEditorLines);
                        break;
                    }
                }
            }
        }