Exemple #1
0
        public ReplaceWindow()
        {
            InitializeComponent();

            if (Properties.Settings.Default.ReplaceBounds == Rect.Empty ||
                Properties.Settings.Default.ReplaceBounds == new Rect(0, 0, 0, 0))
            {
                Width  = 800;
                Height = 980;
                WindowStartupLocation = WindowStartupLocation.CenterScreen;
            }
            else
            {
                WindowStartupLocation = WindowStartupLocation.Manual;
                Left   = Properties.Settings.Default.ReplaceBounds.Left;
                Top    = Properties.Settings.Default.ReplaceBounds.Top;
                Width  = Properties.Settings.Default.ReplaceBounds.Width;
                Height = Properties.Settings.Default.ReplaceBounds.Height;
            }

            Loaded += (s, e) =>
            {
                if (!this.IsOnScreen())
                {
                    this.CenterWindow();
                }

                this.ConstrainToScreen();
            };

            cbWrapText.IsChecked = GrepSettings.Instance.Get <bool?>(GrepSettings.Key.ReplaceWindowWrap);
            zoomSlider.Value     = GrepSettings.Instance.Get <int>(GrepSettings.Key.ReplaceWindowFontSize);

            textEditor.ShowLineNumbers = false; // using custom line numbers

            lineNumberMargin = new ReplaceViewLineNumberMargin();
            Line line = (Line)DottedLineMargin.Create();

            textEditor.TextArea.LeftMargins.Insert(0, lineNumberMargin);
            textEditor.TextArea.LeftMargins.Insert(1, line);
            var lineNumbersForeground = new Binding("LineNumbersForeground")
            {
                Source = textEditor
            };

            line.SetBinding(Line.StrokeProperty, lineNumbersForeground);
            lineNumberMargin.SetBinding(Control.ForegroundProperty, lineNumbersForeground);

            DataContext = ViewModel;

            ViewModel.LoadFile        += (s, e) => LoadFile();
            ViewModel.ReplaceMatch    += (s, e) => textEditor.TextArea.TextView.Redraw();
            ViewModel.PropertyChanged += ViewModel_PropertyChanged;
            ViewModel.CloseTrue       += ViewModel_CloseTrue;

            textEditor.Loaded += (s, e) =>
            {
                // once loaded, move to the first file
                ViewModel.SelectNextFile();
            };

            Closing += (s, e) => SaveSettings();

            textEditor.TextArea.Caret.PositionChanged += Caret_PositionChanged;
        }
Exemple #2
0
        public ReplaceWindow()
        {
            InitializeComponent();

            if (LayoutProperties.ReplaceBounds == Rect.Empty ||
                LayoutProperties.ReplaceBounds == new Rect(0, 0, 0, 0) ||
                !ViewModel.IsFullDialog)
            {
                Width  = ViewModel.DialogSize.Width;
                Height = ViewModel.DialogSize.Height;
                WindowStartupLocation = WindowStartupLocation.CenterScreen;
            }
            else
            {
                WindowStartupLocation = WindowStartupLocation.Manual;
                Left   = LayoutProperties.ReplaceBounds.Left;
                Top    = LayoutProperties.ReplaceBounds.Top;
                Width  = LayoutProperties.ReplaceBounds.Width;
                Height = LayoutProperties.ReplaceBounds.Height;
            }

            Loaded += (s, e) =>
            {
                if (!this.IsOnScreen())
                {
                    this.CenterWindow();
                }

                this.ConstrainToScreen();
            };

            if (ViewModel.IsFullDialog)
            {
                cbWrapText.IsChecked = GrepSettings.Instance.Get <bool?>(GrepSettings.Key.ReplaceWindowWrap);
                zoomSlider.Value     = GrepSettings.Instance.Get <int>(GrepSettings.Key.ReplaceWindowFontSize);

                textEditor.ShowLineNumbers = false; // using custom line numbers

                lineNumberMargin = new ReplaceViewLineNumberMargin();
                Line line = (Line)DottedLineMargin.Create();
                textEditor.TextArea.LeftMargins.Insert(0, lineNumberMargin);
                textEditor.TextArea.LeftMargins.Insert(1, line);
                var lineNumbersForeground = new Binding("LineNumbersForeground")
                {
                    Source = textEditor
                };
                line.SetBinding(Line.StrokeProperty, lineNumbersForeground);
                lineNumberMargin.SetBinding(Control.ForegroundProperty, lineNumbersForeground);

                searchPanel             = SearchPanel.Install(textEditor);
                searchPanel.MarkerBrush = Application.Current.Resources["Match.Highlight.Background"] as Brush;

                ViewModel.LoadFile        += (s, e) => LoadFile();
                ViewModel.ReplaceMatch    += (s, e) => textEditor.TextArea.TextView.Redraw();
                ViewModel.PropertyChanged += ViewModel_PropertyChanged;

                textEditor.Loaded += (s, e) =>
                {
                    // once loaded, move to the first file
                    ViewModel.SelectNextFile();
                };

                textEditor.TextArea.Caret.PositionChanged += Caret_PositionChanged;
            }
            else
            {
                Loaded += (s, e) =>
                {
                    // once loaded, move to the first file
                    ViewModel.SelectNextFile();
                };
            }

            ViewModel.CloseTrue += ViewModel_CloseTrue;

            DataContext = ViewModel;

            Closing += (s, e) => SaveSettings();
        }