Пример #1
0
        void ViewModel_ShowPreview(object sender, ShowEventArgs e)
        {
            if (!e.ClearContent)
            {
                if (textEditor.IsLoaded)
                {
                    textEditor.ScrollTo(ViewModel.LineNumber, 0);
                }
            }
            else
            {
                textEditor.Clear();
                textEditor.Encoding           = ViewModel.Encoding;
                textEditor.SyntaxHighlighting = ViewModel.HighlightingDefinition;
                textEditor.TextArea.TextView.LinkTextForegroundBrush = Application.Current.Resources["AvalonEdit.Link"] as Brush;
                for (int i = textEditor.TextArea.TextView.LineTransformers.Count - 1; i >= 0; i--)
                {
                    if (textEditor.TextArea.TextView.LineTransformers[i] is PreviewHighlighter)
                    {
                        textEditor.TextArea.TextView.LineTransformers.RemoveAt(i);
                    }
                }

                if (ViewModel.HighlightsOn && !ViewModel.HighlightDisabled && !ViewModel.IsPdf)
                {
                    textEditor.TextArea.TextView.LineTransformers.Add(new PreviewHighlighter(ViewModel.GrepResult));
                }

                try
                {
                    if (!ViewModel.IsLargeOrBinary)
                    {
                        if (!string.IsNullOrWhiteSpace(ViewModel.FilePath))
                        {
                            bool isRTL = Utils.IsRTL(ViewModel.FilePath, ViewModel.Encoding);
                            textEditor.FlowDirection = isRTL ? FlowDirection.RightToLeft : FlowDirection.LeftToRight;

                            using (FileStream stream = File.Open(ViewModel.FilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                            {
                                textEditor.Load(stream);
                            }
                            if (textEditor.IsLoaded)
                            {
                                textEditor.ScrollTo(ViewModel.LineNumber, 0);
                            }
                        }
                        else
                        {
                            //Title = "No files to preview.";
                            textEditor.Text = "";
                        }
                    }
                    //Show();
                }
                catch (Exception ex)
                {
                    textEditor.Text = "Error opening the file: " + ex.Message;
                }
            }
        }
Пример #2
0
        void ViewModel_ShowPreview(object sender, ShowEventArgs e)
        {
            if (!e.ClearContent)
            {
                if (textEditor.IsLoaded)
                {
                    textEditor.ScrollTo(ViewModel.LineNumber, 0);
                }
            }
            else
            {
                textEditor.Clear();
                textEditor.Encoding           = ViewModel.Encoding;
                textEditor.SyntaxHighlighting = ViewModel.HighlightingDefinition;
                for (int i = textEditor.TextArea.TextView.LineTransformers.Count - 1; i >= 0; i--)
                {
                    if (textEditor.TextArea.TextView.LineTransformers[i] is PreviewHighlighter)
                    {
                        textEditor.TextArea.TextView.LineTransformers.RemoveAt(i);
                    }
                }

                if (!ViewModel.HighlightDisabled)
                {
                    textEditor.TextArea.TextView.LineTransformers.Add(new PreviewHighlighter(ViewModel.GrepResult));
                }

                try
                {
                    if (!ViewModel.IsLargeOrBinary)
                    {
                        if (!string.IsNullOrWhiteSpace(ViewModel.FilePath))
                        {
                            //Title = string.Format("Previewing \"{0}\"", ViewModel.DisplayFileName);
                            textEditor.Load(ViewModel.FilePath);
                            if (textEditor.IsLoaded)
                            {
                                textEditor.ScrollTo(ViewModel.LineNumber, 0);
                            }
                        }
                        else
                        {
                            //Title = "No files to preview.";
                            textEditor.Text = "";
                        }
                    }
                    //Show();
                }
                catch (Exception ex)
                {
                    textEditor.Text = "Error opening the file: " + ex.Message;
                }
            }
        }
Пример #3
0
        void inputData_ShowPreview(object sender, ShowEventArgs e)
        {
            if (!e.ClearContent)
            {
                if (textEditor.IsLoaded)
                {
                    textEditor.ScrollTo(inputData.LineNumber, 0);
                }
            }
            else
            {
                textEditor.Clear();
                textEditor.Encoding           = inputData.Encoding;
                textEditor.SyntaxHighlighting = inputData.HighlightingDefinition;
                for (int i = textEditor.TextArea.TextView.LineTransformers.Count - 1; i >= 0; i--)
                {
                    if (textEditor.TextArea.TextView.LineTransformers[i] is PreviewHighlighter)
                    {
                        textEditor.TextArea.TextView.LineTransformers.RemoveAt(i);
                    }
                }
                textEditor.TextArea.TextView.LineTransformers.Add(new PreviewHighlighter(inputData.GrepResult));

                try
                {
                    if (inputData.IsLargeOrBinary != System.Windows.Visibility.Visible)
                    {
                        if (!string.IsNullOrWhiteSpace(inputData.FilePath))
                        {
                            this.Title = string.Format("Previewing \"{0}\"", inputData.FilePath);
                            textEditor.Load(inputData.FilePath);
                            if (textEditor.IsLoaded)
                            {
                                textEditor.ScrollTo(inputData.LineNumber, 0);
                            }
                        }
                        else
                        {
                            this.Title      = "No files to preview.";
                            textEditor.Text = "";
                        }
                    }
                    this.Show();
                }
                catch (Exception ex)
                {
                    textEditor.Text = "Error opening the file: " + ex.Message;
                }
            }
        }
Пример #4
0
        void inputData_ShowPreview(object sender, ShowEventArgs e)
        {
            if (!e.ClearContent)
            {
                if (textEditor.IsLoaded)
                {
                    textEditor.ScrollTo(inputData.LineNumber, 0);
                }

            }
            else
            {
                textEditor.Clear();
                textEditor.SyntaxHighlighting = inputData.HighlightingDefinition;
                for (int i = textEditor.TextArea.TextView.LineTransformers.Count - 1; i >= 0; i--)
                {
                    if (textEditor.TextArea.TextView.LineTransformers[i] is PreviewHighlighter)
                        textEditor.TextArea.TextView.LineTransformers.RemoveAt(i);
                }
                textEditor.TextArea.TextView.LineTransformers.Add(new PreviewHighlighter(inputData.GrepResult));

                try
                {
                    if (inputData.IsLargeOrBinary != System.Windows.Visibility.Visible)
                    {
                        if (!string.IsNullOrWhiteSpace(inputData.FilePath))
                        {
                            this.Title = string.Format("Previewing \"{0}\"", inputData.FilePath);
                            textEditor.Load(inputData.FilePath);
                            if (textEditor.IsLoaded)
                            {
                                textEditor.ScrollTo(inputData.LineNumber, 0);
                            }
                        }
                        else
                        {
                            this.Title = "No files to preview.";
                            textEditor.Text = "";
                        }
                    }
                    this.Show();
                }
                catch (Exception ex)
                {
                    textEditor.Text = "Error opening the file: " + ex.Message;
                }
            }
        }