Пример #1
0
        private void buttonReplaceAll_Click(object sender, RoutedEventArgs e)
        {
            if (!lastFind.Contains(textBoxFind.Text))
            {
                lastFind.Insert(0, textBoxFind.Text);
            }
            if (!comboBoxFind.Items.Contains(textBoxFind.Text))
            {
                comboBoxFind.Items.Insert(0, textBoxFind.Text);
            }
            comboBoxFind.SelectedItem = textBoxFind.Text;
            if (!lastReplace.Contains(textBoxReplace.Text))
            {
                lastReplace.Insert(0, textBoxReplace.Text);
            }
            if (!comboBoxReplace.Items.Contains(textBoxReplace.Text))
            {
                comboBoxReplace.Items.Insert(0, textBoxReplace.Text);
            }
            comboBoxReplace.SelectedItem = textBoxReplace.Text;

            SBDocument sbDocument = mainWindow.GetActiveDocument();

            if (sbDocument.TextArea.SelectedText.ToUpperInvariant() != textBoxFind.Text.ToUpperInvariant())
            {
                sbDocument.searchManager.Find(true, textBoxFind.Text);
            }
            if (sbDocument.TextArea.SelectedText.ToUpperInvariant() != textBoxFind.Text.ToUpperInvariant())
            {
                return;
            }

            List <int> markStart = new List <int>();

            while (sbDocument.TextArea.SelectedText.ToUpperInvariant() == textBoxFind.Text.ToUpperInvariant())
            {
                if (markStart.Contains(sbDocument.TextArea.SelectionStart))
                {
                    break;
                }
                markStart.Add(sbDocument.TextArea.SelectionStart);
                sbDocument.searchManager.Find(true, textBoxFind.Text);
            }

            int iLen = sbDocument.TextArea.SelectedText.Length;

            markStart.Sort();
            markStart.Reverse();
            foreach (int iStart in markStart)
            {
                sbDocument.TextArea.SetTargetRange(iStart, iStart + iLen);
                sbDocument.TextArea.ReplaceTarget(textBoxReplace.Text);
            }
        }
Пример #2
0
        private void buttonFindNext_Click(object sender, RoutedEventArgs e)
        {
            if (!lastFind.Contains(textBoxFind.Text))
            {
                lastFind.Insert(0, textBoxFind.Text);
            }
            if (!comboBoxFind.Items.Contains(textBoxFind.Text))
            {
                comboBoxFind.Items.Insert(0, textBoxFind.Text);
            }
            comboBoxFind.SelectedItem = textBoxFind.Text;

            SBDocument sbDocument = mainWindow.GetActiveDocument();

            sbDocument.searchManager.Find(true, textBoxFind.Text);
        }
Пример #3
0
        private void buttonReplace_Click(object sender, RoutedEventArgs e)
        {
            if (!lastFind.Contains(textBoxFind.Text))
            {
                lastFind.Insert(0, textBoxFind.Text);
            }
            if (!comboBoxFind.Items.Contains(textBoxFind.Text))
            {
                comboBoxFind.Items.Insert(0, textBoxFind.Text);
            }
            comboBoxFind.SelectedItem = textBoxFind.Text;
            if (!lastReplace.Contains(textBoxReplace.Text))
            {
                lastReplace.Insert(0, textBoxReplace.Text);
            }
            if (!comboBoxReplace.Items.Contains(textBoxReplace.Text))
            {
                comboBoxReplace.Items.Insert(0, textBoxReplace.Text);
            }
            comboBoxReplace.SelectedItem = textBoxReplace.Text;

            SBDocument sbDocument = mainWindow.GetActiveDocument();

            if (sbDocument.TextArea.SelectedText.ToUpperInvariant() != textBoxFind.Text.ToUpperInvariant())
            {
                sbDocument.searchManager.Find(true, textBoxFind.Text);
            }
            if (sbDocument.TextArea.SelectedText.ToUpperInvariant() != textBoxFind.Text.ToUpperInvariant())
            {
                return;
            }

            int iStart = sbDocument.TextArea.SelectionStart;
            int iLen   = sbDocument.TextArea.SelectedText.Length;

            sbDocument.TextArea.SetTargetRange(iStart, iStart + iLen);
            sbDocument.TextArea.ReplaceTarget(textBoxReplace.Text);
            sbDocument.TextArea.CurrentPosition = sbDocument.TextArea.SelectionStart + textBoxReplace.Text.Length;

            sbDocument.searchManager.Find(true, textBoxFind.Text);
        }
Пример #4
0
        private void DisplayFile(SearchFile searchFile)
        {
            WindowsFormsHost host = new WindowsFormsHost();
            SBDocument       doc  = new SBDocument();

            host.Child        = doc.TextArea;
            doc.TextArea.Text = File.ReadAllText(searchFile.FilePath);
            gridSearcherPreview.Children.Add(host);
            doc.WrapMode          = MainWindow.wrap ? WrapMode.Whitespace : WrapMode.None;
            doc.IndentationGuides = MainWindow.indent ? IndentView.LookBoth : IndentView.None;
            doc.ViewWhitespace    = MainWindow.whitespace ? WhitespaceMode.VisibleAlways : WhitespaceMode.Invisible;
            doc.TextArea.Zoom     = MainWindow.zoom;
            doc.Theme             = MainWindow.theme;

            doc.TextArea.ReadOnly                = true;
            doc.TextArea.SearchFlags             = SearchFlags.None;
            doc.TextArea.Indicators[0].ForeColor = SBDocument.IntToColor(MainWindow.FIND_HIGHLIGHT_COLOR);
            doc.TextArea.Indicators[0].Style     = IndicatorStyle.RoundBox;
            if (textBoxSearcherText.Text != "")
            {
                doc.TextArea.TargetStart = 0;
                doc.TextArea.TargetEnd   = doc.TextArea.TextLength;

                string          keyword       = textBoxSearcherText.Text;
                RegexOptions    caseSensitive = (bool)checkBoxSearcherCase.IsChecked ? RegexOptions.None : RegexOptions.IgnoreCase;
                string          wholeWord     = (bool)checkBoxSearcherWord.IsChecked ? "\\b" + keyword + "\\b" : keyword;
                MatchCollection matches       = Regex.Matches(doc.TextArea.Text, wholeWord, caseSensitive);
                foreach (Match match in matches)
                {
                    doc.TextArea.IndicatorFillRange(match.Index, match.Length);
                }
                textBoxMatches.Text = matches.Count + " matches found";
            }
            else
            {
                textBoxMatches.Text = "";
            }
            doc.TextArea.CurrentPosition = 0;
            doc.TextArea.ScrollCaret();
        }
Пример #5
0
        internal FindAndReplace(MainWindow mainWindow)
        {
            this.mainWindow = mainWindow;
            InitializeComponent();

            FontSize = 12 + MainWindow.zoom;

            Topmost = true;

            SBDocument sbDocument = mainWindow.GetActiveDocument();

            foreach (string item in mainWindow.cbFindText.Items)
            {
                if (!lastFind.Contains(item))
                {
                    lastFind.Add(item);
                }
            }
            if (sbDocument.TextArea.SelectedText != "" && !lastFind.Contains(sbDocument.TextArea.SelectedText))
            {
                lastFind.Insert(0, sbDocument.TextArea.SelectedText);
            }

            foreach (string item in lastFind)
            {
                comboBoxFind.Items.Add(item);
            }
            foreach (string item in lastReplace)
            {
                comboBoxReplace.Items.Add(item);
            }

            textBoxFind.Text             = lastFind.Count > 0 ? lastFind[0] : "";
            textBoxReplace.Text          = lastReplace.Count > 0 ? lastReplace[0] : "";
            comboBoxFind.SelectedItem    = textBoxFind.Text;
            comboBoxReplace.SelectedItem = textBoxReplace.Text;

            Left = SystemParameters.PrimaryScreenWidth - Width - 20;
            Top  = (SystemParameters.PrimaryScreenHeight - Height) / 2;
        }
Пример #6
0
        public void Display()
        {
            Cursor cursor = Mouse.OverrideCursor;

            Mouse.OverrideCursor = Cursors.Wait;

            try
            {
                canvas.Children.Clear();
                codeLines.Clear();
                subs.Clear();
                sbDocument = mainWindow.GetActiveDocument();
                //scaleView = 1;
                //scaleTransform.ScaleX = 1.0;
                //scaleTransform.ScaleY = 1.0;
                lastHighlight = null;

                Parse();

                maxrow = 0;
                maxcol = 0;
                foreach (CodeLine codeLine in codeLines)
                {
                    int row = codeLine.row;
                    int col = codeLine.col;

                    if (codeLine.block != eBlock.START && codeLine.block != eBlock.SUB && codeLine.block != eBlock.ELSE && codeLine.block != eBlock.ELSEIF)
                    {
                        ConnectEndIf(row, col, 0, col);
                    }

                    if (codeLine.block == eBlock.ELSE || codeLine.block == eBlock.ELSEIF)
                    {
                        Line connect = new Line()
                        {
                            X1              = borderSpace + (width + widthSpace) * col + 2,
                            X2              = borderSpace + (width + widthSpace) * col - widthSpace - 2,
                            Y1              = borderSpace + heightSpace * row + height / 2,
                            Y2              = borderSpace + heightSpace * row + height / 2,
                            Stroke          = new SolidColorBrush(foreground),
                            StrokeThickness = 2,
                        };
                        canvas.Children.Add(connect);

                        int testCol = col - 1;
                        while (null == HasSymbol(row, testCol) && testCol > 0)
                        {
                            Line connect2 = new Line()
                            {
                                X1              = borderSpace + (width + widthSpace) * (testCol + 1) + 2,
                                X2              = borderSpace + (width + widthSpace) * testCol - widthSpace - 2,
                                Y1              = borderSpace + heightSpace * row + height / 2,
                                Y2              = borderSpace + heightSpace * row + height / 2,
                                Stroke          = new SolidColorBrush(foreground),
                                StrokeThickness = 2,
                            };
                            canvas.Children.Add(connect2);
                            testCol--;
                        }

                        ImageSource arrow = MainWindow.ImageSourceFromBitmap(Properties.Resources.Arrow);
                        Image       img   = new Image()
                        {
                            Width  = 24,
                            Height = 24,
                            Source = arrow,
                        };
                        RotateTransform rotateTransform = new RotateTransform();
                        rotateTransform.CenterX = 12;
                        rotateTransform.CenterY = 12;
                        rotateTransform.Angle   = 180;
                        img.RenderTransform     = new TransformGroup();
                        ((TransformGroup)img.RenderTransform).Children.Add(rotateTransform);
                        canvas.Children.Add(img);
                        Canvas.SetLeft(img, borderSpace + (width + widthSpace) * col - 22);
                        Canvas.SetTop(img, borderSpace + heightSpace * row + height / 2 - 11);
                        Canvas.SetZIndex(img, 1);
                    }

                    if (codeLine.block == eBlock.IF || codeLine.block == eBlock.ELSEIF)
                    {
                        if (TFshape)
                        {
                            Grid imgTrue = CodeShape.GetBlock(Colors.Green, "T", 24, 24, eShape.ELLIPSE);
                            canvas.Children.Add(imgTrue);
                            Canvas.SetLeft(imgTrue, borderSpace + (width + widthSpace) * col + width / 2 - imgTrue.Width / 2);
                            Canvas.SetTop(imgTrue, borderSpace + heightSpace * row + height + 2);
                            Canvas.SetZIndex(imgTrue, 1);

                            Grid imgFalse = CodeShape.GetBlock(Colors.Red, "F", 24, 24, eShape.ELLIPSE);
                            canvas.Children.Add(imgFalse);
                            Canvas.SetLeft(imgFalse, borderSpace + (width + widthSpace) * col + width + 2);
                            Canvas.SetTop(imgFalse, borderSpace + heightSpace * row + height / 2 - imgTrue.Height / 2);
                            Canvas.SetZIndex(imgFalse, 1);
                        }
                        else
                        {
                            TextBlock condition = new TextBlock()
                            {
                                Foreground = new SolidColorBrush(foreground),
                                Text       = "True",
                            };
                            condition.Measure(new Size(double.MaxValue, double.MaxValue));
                            canvas.Children.Add(condition);
                            Canvas.SetLeft(condition, borderSpace + (width + widthSpace) * col + width / 2 + 2);
                            Canvas.SetTop(condition, borderSpace + heightSpace * row + height + 2);

                            condition = new TextBlock()
                            {
                                Foreground = new SolidColorBrush(foreground),
                                Text       = "False",
                            };
                            condition.Measure(new Size(double.MaxValue, double.MaxValue));
                            canvas.Children.Add(condition);
                            Canvas.SetLeft(condition, borderSpace + (width + widthSpace) * col + width + 2);
                            Canvas.SetTop(condition, borderSpace + heightSpace * row + height / 2 - condition.DesiredSize.Height - 2);
                        }
                    }

                    if (codeLine.block == eBlock.ENDIF)
                    {
                        int rowIf = codeLine.rootLine.row;
                        for (int colIf = 0; colIf <= maxcol; colIf++)
                        {
                            CodeLine cl = HasSymbol(rowIf, colIf);
                            if (null != cl && cl.rootLine == codeLine.rootLine)
                            {
                                ConnectEndIf(codeLine.row, codeLine.col, rowIf, colIf);
                            }
                        }
                    }

                    if (codeLine.block == eBlock.ENDFOR || codeLine.block == eBlock.ENDWHILE || codeLine.block == eBlock.GOTO)
                    {
                        ConnectLoop(codeLine.row, codeLine.col, codeLine.rootLine.row, codeLine.rootLine.col);
                    }

                    Color color;
                    switch (codeLine.block)
                    {
                    case eBlock.IF:
                    case eBlock.ELSE:
                    case eBlock.ELSEIF:
                        color = MainWindow.IntToColor(MainWindow.CHART_CONDITION_COLOR);
                        break;

                    case eBlock.START:
                    case eBlock.SUB:
                        color = MainWindow.IntToColor(MainWindow.CHART_START_COLOR);
                        break;

                    case eBlock.GOTO:
                    case eBlock.LABEL:
                    case eBlock.CALL:
                        color = MainWindow.IntToColor(MainWindow.CHART_CALL_COLOR);
                        break;

                    case eBlock.FOR:
                    case eBlock.ENDFOR:
                        color = MainWindow.IntToColor(MainWindow.CHART_FOR_COLOR);
                        break;

                    case eBlock.WHILE:
                    case eBlock.ENDWHILE:
                        color = MainWindow.IntToColor(MainWindow.CHART_WHILE_COLOR);
                        break;

                    default:
                        color = MainWindow.IntToColor(MainWindow.CHART_STATEMENT_COLOR);
                        break;
                    }

                    CodeShape border = new CodeShape(codeLine, width, height, color);
                    codeLine.border        = border;
                    border.grid.MouseDown += new MouseButtonEventHandler(codeClick);

                    canvas.Children.Add(border.grid);
                    Canvas.SetLeft(border.grid, borderSpace + (width + widthSpace) * col);
                    Canvas.SetTop(border.grid, borderSpace + heightSpace * row++);
                    maxcol = Math.Max(maxcol, col);
                    maxrow = Math.Max(maxrow, row);
                }

                canvas.Width  = -widthSpace + 2 * borderSpace + (width + widthSpace) * (maxcol + 1);
                canvas.Height = borderSpace + heightSpace * maxrow;
            }
            catch (Exception ex)
            {
                MainWindow.Errors.Add(new Error("Flow Chart : " + ex.Message));
                OnError();
            }
            Mouse.OverrideCursor = cursor;
        }