コード例 #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
ファイル: PreviewControl.xaml.cs プロジェクト: rudzen/dnGrep
        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
ファイル: PreviewView.xaml.cs プロジェクト: esiwgnahz/dnGrep
        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
ファイル: PreviewView.xaml.cs プロジェクト: shu2333/dnGrep
        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;
                }
            }
        }