コード例 #1
0
        private void SearchForSubtask()
        {
            int  i     = 0;
            bool found = false;

            foreach (char c in Editor_TextBox.Text)
            {
                if (c == ':')
                {
                    string subtaskNum = JSON_Reader.GetSubtaskNum(i, Editor_TextBox.Text);
                    if (subtaskNum.Replace(" ", "").Replace(",", "") == Find_TextBox.Text.Replace(" ", "").Replace(",", ""))
                    {
                        found = true;

                        int startHighlighht = Editor_TextBox.Text.LastIndexOf("\"", i - 2);
                        Editor_TextBox.SelectionStart = i;
                        Editor_TextBox.Select(i, -(i - startHighlighht));
                        Editor_TextBox.ScrollToCaret();
                        HideFindButton();
                        searchSubtask = false;
                        break;
                    }
                }
                i++;
            }
            if (!found)
            {
                ConsoleHandler.append_Force_CanRepeat("That subtask was not found");
            }
        }
コード例 #2
0
 private void Replace_Button_Click(object sender, EventArgs e)
 {
     if (Find_TB.Text.Length <= 0)
     {
         MessageBox.Show("You didn't enter anything to search for. Please Try Again");
     }
     if (Replace_TB.Text.Length <= 0)
     {
         MessageBox.Show("You didn't enter anything to replace with. Please Try Again");
     }
     if (Option1_CB.Checked)
     {
         Editor_TextBox.Text = Editor_TextBox.Text.Replace(Find_TB.Text, Replace_TB.Text);
     }
     else
     {
         if (!searchPhrase_selected)
         {
             MessageBox.Show("You need to find something before you can try replacing it...");
         }
         else
         {
             Editor_TextBox.Focus();
             ReplaceText();
         }
     }
 }
コード例 #3
0
        private void LintPanel_MouseClick(object sender, MouseEventArgs e)
        {
            if (jsonError)
            {
                try
                {
                    string error = JSON_Reader.GetJSON_Error(Editor_TextBox.Text);
                    ConsoleHandler.force_append_Notice(error);
                    //Line number
                    string[] split      = error.Split(',');
                    string[] line       = split[split.Length - 2].Split(' ');
                    int      lineNumber = Int32.Parse(line[line.Length - 1].Replace(".", "").Replace(",", ""));

                    //Position in line
                    string[] pos     = split[split.Length - 1].Split(' ');
                    int      linePos = Int32.Parse(pos[pos.Length - 1].Replace(".", "").Replace(",", ""));

                    //Scroll to the line above error
                    int index = Editor_TextBox.GetFirstCharIndexFromLine(lineNumber - 3) + linePos;
                    Editor_TextBox.Select(index, 1);
                    Editor_TextBox.ScrollToCaret();

                    int numChars = (Editor_TextBox.GetFirstCharIndexFromLine(lineNumber - 1)) - (Editor_TextBox.GetFirstCharIndexFromLine(lineNumber - 2));

                    //highlight line with error
                    index = Editor_TextBox.GetFirstCharIndexFromLine(lineNumber - 2) + linePos;
                    Editor_TextBox.Focus();
                    Editor_TextBox.Select(index, numChars - 2);
                }
                catch
                {
                    ConsoleHandler.append_CanRepeat("Something went wrong... Unable to find the bad json");
                }
            }
        }
コード例 #4
0
        private void Editor_TextBox_SelectionChanged(object sender, EventArgs e)
        {
            Point pt = Editor_TextBox.GetPositionFromCharIndex(Editor_TextBox.SelectionStart);

            if (pt.X == 1)
            {
                AddLineNumbers();
            }
        }
コード例 #5
0
        private void JsonEditor_UserControl_Resize(object sender, EventArgs e)
        {
            Editor_TextBox.Size = new Size(this.Width - 43, this.Height - 38);
            tB_line.Size        = new Size(tB_line.Width, this.Height - 38);

            Point pt = Editor_TextBox.GetPositionFromCharIndex(Editor_TextBox.SelectionStart);

            if (pt.X == 1)
            {
                AddLineNumbers();
            }
        }
コード例 #6
0
        private void ReplaceButton_Click(object sender, EventArgs e)
        {
            if (Find_TextBox.Text.Length <= 0)
            {
                MessageBox.Show("You didn't enter anything to search for. Please Try Again");
            }
            if (Replace_TextBox.Text.Length <= 0)
            {
                MessageBox.Show("You didn't enter anything to replace with. Please Try Again");
            }
            if (findNextPhrase)
            {
                MessageBox.Show("You need to find something before you can try replacing it...");
            }
            else if (findNextPhrase == false)
            {
                Editor_TextBox.Text = Editor_TextBox.Text.Remove(startPosition - endPosition, Find_TextBox.Text.Length);
                Editor_TextBox.Text = Editor_TextBox.Text.Insert(startPosition - endPosition, Replace_TextBox.Text);
                endPosition         = this.Replace_TextBox.Text.Length;
                startPosition       = startPosition + endPosition;

                endEditor = Editor_TextBox.Text.Length;

                startPosition = Editor_TextBox.SelectionStart + 1;

                if (previousSearchPhrase != Find_TextBox.Text)
                {
                    endPosition    = 0;
                    numPhraseFound = 0;
                }

                for (int i = 0; i < endEditor; i = startPosition)
                {
                    previousSearchPhrase = this.Find_TextBox.Text;
                    isCurrentlySearching = true;
                    if (i == -1)
                    {
                        isCurrentlySearching = false;
                        break;
                    }
                    startPosition = Editor_TextBox.Find(Find_TextBox.Text, startPosition, endEditor, RichTextBoxFinds.None);
                    if (startPosition >= 0)
                    {
                        numPhraseFound++;
                        //Editor_TextBox.SelectionColor = Color.Blue;       //saving this value for later use
                        endPosition   = this.Find_TextBox.Text.Length;
                        startPosition = startPosition + endPosition;
                        break;
                    }
                }
            }
        }
コード例 #7
0
        private void EditorLoading(object sender, EventArgs e)
        {
            tB_line.Font = Editor_TextBox.Font;
            Editor_TextBox.Select();
            AddLineNumbers();

            bool close = false;

            if (close)
            {
                this.Close();
            }
        }
コード例 #8
0
        private void FindText()
        {
            if (Find_TextBox.Text.Length <= 0)
            {
                MessageBox.Show("You didn't enter anything to search for. Please Try Again");
            }
            else
            {
                findNextPhrase = true;
                endEditor      = Editor_TextBox.Text.Length;

                startPosition = Editor_TextBox.SelectionStart + 1;

                if (previousSearchPhrase != Find_TextBox.Text)
                {
                    endPosition    = 0;
                    numPhraseFound = 0;
                }
                for (int i = 0; i < endEditor; i = startPosition)
                {
                    previousSearchPhrase = this.Find_TextBox.Text;
                    isCurrentlySearching = true;
                    if (i == -1)
                    {
                        isCurrentlySearching = false;
                        break;
                    }
                    if (startPosition >= endEditor)
                    {
                        MessageBox.Show("Reached the end of the file");
                        break;
                    }
                    startPosition = Editor_TextBox.Find(Find_TextBox.Text, startPosition, endEditor, RichTextBoxFinds.None);
                    if (startPosition >= 0)
                    {
                        findNextPhrase = false;
                        numPhraseFound++;
                        //Editor_TextBox.SelectionColor = Color.Blue;       //saving this value for later use
                        endPosition   = this.Find_TextBox.Text.Length;
                        startPosition = startPosition + endPosition;
                        break;
                    }

                    if (numPhraseFound == 0)
                    {
                        MessageBox.Show("No Match Found!!!");
                    }
                }
            }
        }
コード例 #9
0
        public JsonEditor_Instance()
        {
            InitializeComponent();
            SetHideEvents();
            Editor_TextBox.Select();
            AddLineNumbers();

            Find_Button.KeyDown                += Find_TB_KeyDown;
            Replace_TB.KeyDown                 += Find_TB_KeyDown;
            SearchOptions_Panel.KeyDown        += Find_TB_KeyDown;
            SearchOptions_Button.KeyDown       += Find_TB_KeyDown;
            Editor_TextBox.MouseUp             += Editor_TextBox_RightClicked;
            Weapons_Button.DropDownItemClicked += Weapons_Button_Click;
            //path and filename have NOT been set yet. Use FinishedLoading()
        }
コード例 #10
0
 private void NoItem_CM_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
 {
     if (e.ClickedItem.Text == "Paste")
     {
         Editor_TextBox.SelectionStart = CharIndex_UnderMouse;
         Editor_TextBox.Paste();
     }
     if (e.ClickedItem.Text == "Find Subtask")
     {
         FindSubtask_Button_Event();
     }
     if (e.ClickedItem.Text == "Get this subtask number")
     {
         GetSubtaskNum();
     }
 }
コード例 #11
0
        private void RemoveEmptySpaces()
        {
            int numSpaces    = IndentNewLines();
            int startIndex   = Editor_TextBox.GetFirstCharIndexOfCurrentLine();
            int currentIndex = Editor_TextBox.SelectionStart;

            //if(currentIndex <= (startIndex + numSpaces))
            if (currentIndex <= (startIndex + numSpaces))
            {
                if (numSpaces > 5)
                {
                    Editor_TextBox.SelectionLength = 5;
                    Editor_TextBox.SelectionStart  = currentIndex - 5;
                    Editor_TextBox.SelectedText    = "";
                }
            }
        }
コード例 #12
0
 private void jsonContextClicked(object sender, ToolStripItemClickedEventArgs e)
 {
     if (e.ClickedItem.Text == "Paste")
     {
         try
         {
             Editor_TextBox.SelectionStart = CharIndex_UnderMouse;
             Editor_TextBox.Paste();
         }
         catch (Exception)
         {
         }
     }
     if (e.ClickedItem.Text == "Find subtask")
     {
         try
         {
             ConsoleHandler.force_append_Notice("Please enter the subtask numbers you are looking for in the \"Find\" text box above.\n>> Example:    0,0,1");
             searchSubtask = true;
             ShowFindMenu();
         }
         catch (Exception)
         {
         }
     }
     if (e.ClickedItem.Text == "Get current subtask number")
     {
         if (jsonError == false)
         {
             try
             {
                 //func here
                 GetSubtaskNum();
             }
             catch (Exception)
             {
             }
         }
         else
         {
             ConsoleHandler.append_Force("JSON error detected... You need to fix the JSON error before you can get the subtask");
         }
     }
 }
コード例 #13
0
 private void Find_Button_Click(object sender, EventArgs e)
 {
     if (Find_TB.Text.Length > 0)
     {
         Editor_TextBox.Focus();
         if (Option1_CB.Checked)
         {
             SearchForSubtask();
         }
         else
         {
             FindText();
         }
     }
     else
     {
         ConsoleHandler.append("You didn't enter anything to search");
     }
 }
コード例 #14
0
        private void ItemHighlighted_CM_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            if (e.ClickedItem.Text == "Copy")
            {
                if (Editor_TextBox.SelectedText.Length > 0)
                {
                    Clipboard.SetText(Editor_TextBox.SelectedText);
                }
            }
            if (e.ClickedItem.Text == "Paste")
            {
                Editor_TextBox.Paste();
            }
            if (e.ClickedItem.Text == "Find")
            {
                Find_TB.Text = Editor_TextBox.SelectedText;
                if (!Find_Panel.Visible)
                {
                    ShowSearchMenu("find");
                }

                Option1_CB.Checked = false;
            }
            if (e.ClickedItem.Text == "Replace")
            {
                ShowSearchMenu("replace");
                if (!Replace_TB.Visible)
                {
                    ShowSearchMenu("replace");
                }

                Find_TB.Text       = Editor_TextBox.SelectedText;
                Option1_CB.Checked = false;
            }
            if (e.ClickedItem.Text == "Find subtask")
            {
                FindSubtask_Button_Event();
            }
            if (e.ClickedItem.Text == "Get current subtask number")
            {
                GetSubtaskNum();
            }
        }
コード例 #15
0
        private void FindText()
        {
            endEditor     = Editor_TextBox.Text.Length;
            startPosition = Editor_TextBox.SelectionStart + 1;

            if (previousSearchPhrase != Find_TB.Text)
            {
                startPosition   = 0;
                endPosition     = Find_TB.Text.Length;
                numPhrasesFound = 0;
            }
            for (int i = 0; i < endEditor; i = startPosition)
            {
                searchPhrase_selected = false;
                if (i == -1)
                {
                    MessageBox.Show("Reached the end of the file");
                    break;
                }
                if (startPosition >= endEditor)
                {
                    startPosition = 0;
                    break;
                }
                startPosition = Editor_TextBox.Find(Find_TB.Text, startPosition, endEditor, RichTextBoxFinds.None);
                if (startPosition >= 0)
                {
                    numPhrasesFound++;
                    searchPhrase_selected = true;

                    endPosition          = this.Find_TB.Text.Length;
                    startPosition        = startPosition + endPosition;
                    previousSearchPhrase = this.Find_TB.Text;
                    break;
                }
                if (numPhrasesFound == 0)
                {
                    MessageBox.Show("No Match Found!!!");
                    break;
                }
            }
        }
コード例 #16
0
        private int IndentNewLines()
        {
            int    index = Editor_TextBox.GetFirstCharIndexOfCurrentLine();
            string text  = Editor_TextBox.Text.Remove(0, index);

            int numSpace = 0;

            foreach (char c in text)
            {
                if (c != ' ')
                {
                    break;
                }
                else
                {
                    numSpace++;
                }
            }
            return(numSpace);
        }
コード例 #17
0
        public void AddLineNumbers()
        {
            Point pt          = new Point(0, 0);
            int   First_Index = Editor_TextBox.GetCharIndexFromPosition(pt);
            int   First_Line  = Editor_TextBox.GetLineFromCharIndex(First_Index);

            pt.X = ClientRectangle.Width;
            pt.Y = ClientRectangle.Height;

            int Last_Index = Editor_TextBox.GetCharIndexFromPosition(pt);
            int Last_Line  = Editor_TextBox.GetLineFromCharIndex(Last_Index);

            tB_line.SelectionAlignment = HorizontalAlignment.Center;
            tB_line.Text  = "";
            tB_line.Width = getWidth();
            for (int i = First_Line; i <= Last_Line + 2; i++)
            {
                tB_line.Text += i + 1 + "\n";
            }
        }
コード例 #18
0
        //
        //Find and replace stuff
        //
        #region Find and Replace stuff
        private void ShowSearchMenu(string op)
        {
            Editor_TextBox.Size = new Size(Editor_TextBox.Size.Width, Editor_TextBox.Size.Height - 40);
            tB_line.Size        = new Size(tB_line.Size.Width, tB_line.Size.Height - 40);

            if (op == "find")
            {
                Find_TB.Location              = new Point(Editor_TextBox.Width - 241, 5);
                Find_Button.Location          = new Point(Editor_TextBox.Width - 321, 4);
                SearchOptions_Button.Location = new Point(Editor_TextBox.Width, 4);
                Find_TB.Visible              = !Find_TB.Visible;
                Find_Button.Visible          = !Find_Button.Visible;
                SearchOptions_Button.Visible = !SearchOptions_Button.Visible;

                if (Option1_CB.Text == "Replace all")
                {
                    if (Option1_CB.Checked)
                    {
                        Option1_CB.Checked = false;
                    }
                }
                Option1_CB.Text     = "Subtask";
                Option1_CB.Location = new Point(15, Option1_CB.Location.Y);
                Find_Panel.Visible  = !Find_Panel.Visible;
            }
            if (op == "replace")
            {
                Find_TB.Visible              = !Find_TB.Visible;
                Find_Button.Visible          = !Find_Button.Visible;
                SearchOptions_Button.Visible = !SearchOptions_Button.Visible;
                Replace_TB.Visible           = !Replace_TB.Visible;
                Replace_Button.Visible       = !ShowReplaceMenu_Button.Visible;

                Replace_TB.Location           = new Point(Editor_TextBox.Width - 241, 5);
                Replace_Button.Location       = new Point(Editor_TextBox.Width - 321, 4);
                Find_TB.Location              = new Point(Editor_TextBox.Width - 591, 5);
                Find_Button.Location          = new Point(Editor_TextBox.Width - 671, 4);
                SearchOptions_Button.Location = new Point(Editor_TextBox.Width, 4);

                if (Option1_CB.Text == "Subtask")
                {
                    if (Option1_CB.Checked)
                    {
                        Option1_CB.Checked = false;
                    }
                }
                Option1_CB.Text     = "Replace all";
                Option1_CB.Location = new Point(10, Option1_CB.Location.Y);
                Find_Panel.Visible  = !Find_Panel.Visible;
            }
            if (Find_TB.Visible)
            {
                Find_TB.Focus();
            }
            else
            {
                Editor_TextBox.Focus();
            }

            if (!Find_Panel.Visible)
            {
                Find_TB.Text                = "";
                Replace_TB.Text             = "";
                SearchOptions_Panel.Visible = false;
                Editor_TextBox.Size         = new Size(Editor_TextBox.Size.Width, Editor_TextBox.Size.Height + 80);
                tB_line.Size                = new Size(tB_line.Size.Width, tB_line.Size.Height + 80);
            }
        }
コード例 #19
0
        private void SearchForPairs()
        {
            int    duplicate       = -1;
            string searchDirection = "";
            string searchText      = "";

            int index = Editor_TextBox.SelectionStart;

            char[] ch = Editor_TextBox.Text.ToCharArray();
            char   selectedText;
            int    duplicatesFound = 0;

            endEditor     = Editor_TextBox.Text.Length;
            startPosition = Editor_TextBox.SelectionStart;

            if (index - 1 < 0)
            {
                index = 0;
            }
            else if (index - 1 > Editor_TextBox.Text.Length)
            {
                index = Editor_TextBox.Text.Length;
            }
            selectedText = ch[index - 1];

            switch (selectedText)
            {
            case '[':
                searchDirection = "down";
                searchText      = "]";
                break;

            case ']':
                searchDirection = "up";
                searchText      = "[";
                break;

            case '{':
                searchDirection = "down";
                searchText      = "}";
                break;

            case '}':
                searchDirection = "up";
                searchText      = "{";
                break;

            case '(':
                searchDirection = "down";
                searchText      = ")";
                break;

            case ')':
                searchDirection = "up";
                searchText      = "(";
                break;
            }

            for (int i = 0; i < endEditor + 1; i = startPosition)
            {
                duplicate = -1;
                if (startPosition >= endEditor + 1 || i == -1)
                {
                    break;
                }
                else
                {
                    if (searchDirection == "down")
                    {
                        startPosition = Editor_TextBox.Find(searchText, index, endEditor + 1, RichTextBoxFinds.None);
                        if (startPosition >= 0)
                        {
                            //we found the character, lets make sure its the correct match to our pair
                            duplicate = Editor_TextBox.Find(selectedText.ToString(), index, startPosition + 1, RichTextBoxFinds.NoHighlight);
                            if (duplicate != -1)
                            {
                                duplicatesFound++;
                                index = duplicate + 1;
                            }
                            else
                            {
                                if (duplicatesFound != 0)
                                {
                                    index = startPosition + 1;
                                    duplicatesFound--;
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                    else
                    {
                        startPosition = Editor_TextBox.Find(searchText, 0, index, RichTextBoxFinds.Reverse);
                        if (startPosition >= 0)
                        {
                            //we found the character, lets make sure its the match
                            duplicate = Editor_TextBox.Find(selectedText.ToString(), startPosition, index - 1, RichTextBoxFinds.Reverse | RichTextBoxFinds.NoHighlight);
                            if (duplicate != -1)
                            {
                                duplicatesFound++;
                                index = duplicate - 1;
                            }
                            else
                            {
                                if (duplicatesFound != 0)
                                {
                                    index = startPosition - 1;
                                    duplicatesFound--;
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
        }
コード例 #20
0
 private void TB_line_MouseDown(object sender, MouseEventArgs e)
 {
     Editor_TextBox.Select();
     tB_line.DeselectAll();
 }
コード例 #21
0
 private void Editor_TextBox_FontChanged(object sender, EventArgs e)
 {
     tB_line.Font = Editor_TextBox.Font;
     Editor_TextBox.Select();
     AddLineNumbers();
 }