Index: src/DeltaShell/DeltaShell.Plugins.CommonTools.Gui/Forms/TextDocumentView.cs =================================================================== diff -u -r7bc7719bed5c5cd676302ba3da2d4d8409968a1a -r5fc71a385897af92ccb092f2f969b5709afab85a --- src/DeltaShell/DeltaShell.Plugins.CommonTools.Gui/Forms/TextDocumentView.cs (.../TextDocumentView.cs) (revision 7bc7719bed5c5cd676302ba3da2d4d8409968a1a) +++ src/DeltaShell/DeltaShell.Plugins.CommonTools.Gui/Forms/TextDocumentView.cs (.../TextDocumentView.cs) (revision 5fc71a385897af92ccb092f2f969b5709afab85a) @@ -7,15 +7,20 @@ using DelftTools.Controls; using DelftTools.Utils; using DelftTools.Utils.Aop; -using DelftTools.Utils.Editing; using DeltaShell.Plugins.CommonTools.Gui.Properties; namespace DeltaShell.Plugins.CommonTools.Gui.Forms { public partial class TextDocumentView : UserControl, ISearchableView { + private static readonly Bitmap TextDocumentImage = Resources.TextDocument; private TextDocumentBase textDocument; + private bool textModified; + + private string characters = ""; + private bool settingContent = false; + public TextDocumentView() { InitializeComponent(); @@ -24,23 +29,26 @@ findAndReplaceControl1.GetCurrentPosition = () => textBox.SelectionStart; findAndReplaceControl1.SelectText = (start, length) => textBox.Select(start, length); findAndReplaceControl1.ScrollToPosition = i => + { + if (textBox.SelectionStart != i) { - if (textBox.SelectionStart != i) - { - textBox.Select(i, 0); - } - textBox.ScrollToCaret(); - }; + textBox.Select(i, 0); + } + textBox.ScrollToCaret(); + }; } public object Data { - get { return textDocument; } + get + { + return textDocument; + } set { if (textDocument != null) { - ((INotifyPropertyChange)textDocument).PropertyChanged -= TextDocumentView_PropertyChanged; + ((INotifyPropertyChange) textDocument).PropertyChanged -= TextDocumentView_PropertyChanged; } textDocument = value as TextDocumentBase; @@ -49,7 +57,7 @@ { textBox.Text = textDocument.Content; textBox.ReadOnly = textDocument.ReadOnly; - ((INotifyPropertyChange)textDocument).PropertyChanged += TextDocumentView_PropertyChanged; + ((INotifyPropertyChange) textDocument).PropertyChanged += TextDocumentView_PropertyChanged; } /*if (textDocument == null) @@ -73,6 +81,41 @@ } } + public Image Image + { + get + { + return TextDocumentImage; + } + set {} + } + + public ViewInfo ViewInfo { get; set; } + + public void EnsureVisible(object item) + { + var text = item as string; + if (text == null) + { + return; + } + + textBox.SelectionStart = textBox.Text.IndexOf(text, 0, StringComparison.InvariantCulture); + textBox.ScrollToCaret(); + textBox.SelectionLength = text.Length; + } + + public IEnumerable> SearchItemsByText(string text, bool caseSensitive, Func isSearchCancelled, Action setProgressPercentage) + { + var lines = textDocument.Content.Split(new[] + { + "\r", + "\n", + "\n\r" + }, StringSplitOptions.RemoveEmptyEntries); + return lines.Where(l => caseSensitive ? l.Contains(text) : l.ToLower().Contains(text.ToLower())).Select(l => new System.Tuple(l, l)); + } + protected override void OnVisibleChanged(EventArgs e) { base.OnVisibleChanged(e); @@ -89,8 +132,8 @@ textModified = false; } } - - void TextDocumentView_PropertyChanged(object sender, PropertyChangedEventArgs e) + + private void TextDocumentView_PropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == "Content" && !settingContent && !IsDisposed) { @@ -106,46 +149,19 @@ settingContent = false; } - public Image Image - { - get { return TextDocumentImage; } - set { } - } - - public void EnsureVisible(object item) - { - var text = item as string; - if (text == null) return; - - textBox.SelectionStart = textBox.Text.IndexOf(text, 0, StringComparison.InvariantCulture); - textBox.ScrollToCaret(); - textBox.SelectionLength = text.Length; - } - - public ViewInfo ViewInfo { get; set; } - - public IEnumerable> SearchItemsByText(string text, bool caseSensitive, Func isSearchCancelled, Action setProgressPercentage) - { - var lines = textDocument.Content.Split(new[] { "\r","\n","\n\r" }, StringSplitOptions.RemoveEmptyEntries); - return lines.Where(l => caseSensitive ? l.Contains(text) : l.ToLower().Contains(text.ToLower())).Select(l => new System.Tuple(l,l)); - } - - private bool textModified; - private void TextBoxTextChanged(object sender, EventArgs e) { - if (settingContent || IsDisposed) return; + if (settingContent || IsDisposed) + { + return; + } textModified = true; timer.Stop(); timer.Start(); } - private string characters = ""; - private bool settingContent = false; - private static readonly Bitmap TextDocumentImage = Properties.Resources.TextDocument; - private void TimerTick(object sender, EventArgs e) { settingContent = true; @@ -163,40 +179,40 @@ { if (ModifierKeys != Keys.Control) { - if(e.KeyChar == (char)Keys.Return) + if (e.KeyChar == (char) Keys.Return) { characters += ""; } - else if(e.KeyChar == '\b' || e.KeyChar == (char)Keys.Delete) + else if (e.KeyChar == '\b' || e.KeyChar == (char) Keys.Delete) { characters += ""; } else { characters += e.KeyChar; - } + } } - base.OnKeyPress(e); + OnKeyPress(e); } private void TextBoxKeyUp(object sender, KeyEventArgs e) { if (ModifierKeys == Keys.Control) { - if(e.KeyCode == Keys.V) + if (e.KeyCode == Keys.V) { characters += ""; } - if(e.KeyCode == Keys.X) + if (e.KeyCode == Keys.X) { characters += ""; } } - else if(e.KeyCode == Keys.Delete) + else if (e.KeyCode == Keys.Delete) { characters += ""; } - base.OnKeyUp(e); + OnKeyUp(e); } private void textBox_KeyDown(object sender, KeyEventArgs e) @@ -206,12 +222,12 @@ findAndReplaceControl1.Visible = true; findAndReplaceControl1.Focus(); e.Handled = true; - } + } } private void TextDocumentView_Load(object sender, EventArgs e) { textBox.SelectionStart = 0; } } -} +} \ No newline at end of file