public void ViewPatch(string text) { ResetForDiff(); _internalFileViewer.SetText(text, isDiff: true); TextLoaded?.Invoke(this, null); RestoreCurrentScrollPos(); }
public void ViewText(string fileName, string text) { ResetForText(fileName); // Check for binary file. if (FileHelper.IsBinaryFileAccordingToContent(text)) { _internalFileViewer.SetText("Binary file: " + fileName + " (Detected)"); TextLoaded?.Invoke(this, null); return; } _internalFileViewer.SetText(text); TextLoaded?.Invoke(this, null); RestoreCurrentScrollPos(); }
public FileViewer() { TreatAllFilesAsText = false; ShowEntireFile = false; NumberOfContextLines = AppSettings.NumberOfContextLines; InitializeComponent(); InitializeComplete(); UICommandsSourceSet += OnUICommandsSourceSet; internalFileViewer.MouseEnter += (_, e) => OnMouseEnter(e); internalFileViewer.MouseLeave += (_, e) => OnMouseLeave(e); internalFileViewer.MouseMove += (_, e) => OnMouseMove(e); internalFileViewer.KeyUp += (_, e) => OnKeyUp(e); _async = new AsyncLoader(); _async.LoadingError += (_, e) => { if (!IsDisposed) { ResetForText(null); internalFileViewer.SetText("Unsupported file: \n\n" + e.Exception.ToString(), openWithDifftool: null /* not applicable */); TextLoaded?.Invoke(this, null); } }; IgnoreWhitespaceChanges = AppSettings.IgnoreWhitespaceChanges; ignoreWhiteSpaces.Checked = IgnoreWhitespaceChanges; ignoreWhiteSpaces.Image = Images.WhitespaceIgnore; ignoreWhitespaceChangesToolStripMenuItem.Checked = IgnoreWhitespaceChanges; ignoreWhitespaceChangesToolStripMenuItem.Image = ignoreWhiteSpaces.Image; ignoreAllWhitespaces.Checked = AppSettings.IgnoreAllWhitespaceChanges; ignoreAllWhitespaces.Image = Images.WhitespaceIgnoreAll; ignoreAllWhitespaceChangesToolStripMenuItem.Checked = ignoreAllWhitespaces.Checked; ignoreAllWhitespaceChangesToolStripMenuItem.Image = ignoreAllWhitespaces.Image; ShowEntireFile = AppSettings.ShowEntireFile; showEntireFileButton.Checked = ShowEntireFile; showEntireFileToolStripMenuItem.Checked = ShowEntireFile; SetStateOfContextLinesButtons(); showNonPrintChars.Checked = AppSettings.ShowNonPrintingChars; showNonprintableCharactersToolStripMenuItem.Checked = AppSettings.ShowNonPrintingChars; ToggleNonPrintingChars(AppSettings.ShowNonPrintingChars); IsReadOnly = true; internalFileViewer.MouseMove += (_, e) => { if (_currentViewIsPatch && !fileviewerToolbar.Visible) { fileviewerToolbar.Visible = true; fileviewerToolbar.Location = new Point(Width - fileviewerToolbar.Width - 40, 0); fileviewerToolbar.BringToFront(); } }; internalFileViewer.MouseLeave += (_, e) => { if (GetChildAtPoint(PointToClient(MousePosition)) != fileviewerToolbar && fileviewerToolbar != null) { fileviewerToolbar.Visible = false; } }; internalFileViewer.TextChanged += (sender, e) => { if (_patchHighlighting) { internalFileViewer.AddPatchHighlighting(); } TextChanged?.Invoke(sender, e); }; internalFileViewer.ScrollPosChanged += (sender, e) => ScrollPosChanged?.Invoke(sender, e); internalFileViewer.SelectedLineChanged += (sender, e) => SelectedLineChanged?.Invoke(sender, e); internalFileViewer.DoubleClick += (_, args) => RequestDiffView?.Invoke(this, EventArgs.Empty); HotkeysEnabled = true; if (!IsDesignModeActive && ContextMenuStrip == null) { ContextMenuStrip = contextMenu; } contextMenu.Opening += (sender, e) => { copyToolStripMenuItem.Enabled = internalFileViewer.GetSelectionLength() > 0; ContextMenuOpening?.Invoke(sender, e); }; _fullPathResolver = new FullPathResolver(() => Module.WorkingDir); }
public FileViewer() { TreatAllFilesAsText = false; ShowEntireFile = false; NumberOfVisibleLines = AppSettings.NumberOfContextLines; InitializeComponent(); Translate(); GitUICommandsSourceSet += FileViewer_GitUICommandsSourceSet; _internalFileViewer = new FileViewerInternal(() => Module); _internalFileViewer.MouseEnter += _internalFileViewer_MouseEnter; _internalFileViewer.MouseLeave += _internalFileViewer_MouseLeave; _internalFileViewer.MouseMove += _internalFileViewer_MouseMove; _internalFileViewer.KeyUp += _internalFileViewer_KeyUp; var internalFileViewerControl = (Control)_internalFileViewer; internalFileViewerControl.Dock = DockStyle.Fill; Controls.Add(internalFileViewerControl); _async = new AsyncLoader(); _async.LoadingError += (sender, args) => { if (!IsDisposed) { ResetForText(null); _internalFileViewer.SetText("Unsupported file: \n\n" + args.Exception.ToString(), openWithDifftool: null /* not applicable */); TextLoaded?.Invoke(this, null); } }; IgnoreWhitespaceChanges = AppSettings.IgnoreWhitespaceChanges; ignoreWhiteSpaces.Checked = IgnoreWhitespaceChanges; ignoreWhiteSpaces.Image = Properties.Resources.ignore_whitespaces; ignoreWhitespaceChangesToolStripMenuItem.Checked = IgnoreWhitespaceChanges; ignoreWhitespaceChangesToolStripMenuItem.Image = ignoreWhiteSpaces.Image; ignoreAllWhitespaces.Checked = AppSettings.IgnoreAllWhitespaceChanges; ignoreAllWhitespaces.Image = Properties.Resources.ignore_all_whitespaces; ignoreAllWhitespaceChangesToolStripMenuItem.Checked = ignoreAllWhitespaces.Checked; ignoreAllWhitespaceChangesToolStripMenuItem.Image = ignoreAllWhitespaces.Image; ShowEntireFile = AppSettings.ShowEntireFile; showEntireFileButton.Checked = ShowEntireFile; showEntireFileToolStripMenuItem.Checked = ShowEntireFile; showNonPrintChars.Checked = AppSettings.ShowNonPrintingChars; showNonprintableCharactersToolStripMenuItem.Checked = AppSettings.ShowNonPrintingChars; ToggleNonPrintingChars(AppSettings.ShowNonPrintingChars); IsReadOnly = true; var encodingList = AppSettings.AvailableEncodings.Values.Select(e => e.EncodingName).ToList(); var defaultEncodingName = Encoding.Default.EncodingName; for (int i = 0; i < encodingList.Count; i++) { if (string.Compare(encodingList[i], defaultEncodingName, true) == 0) { encodingList[i] = "Default (" + Encoding.Default.HeaderName + ")"; break; } } encodingToolStripComboBox.Items.AddRange(encodingList.ToArray()); _internalFileViewer.MouseMove += TextAreaMouseMove; _internalFileViewer.MouseLeave += TextAreaMouseLeave; _internalFileViewer.TextChanged += TextEditor_TextChanged; _internalFileViewer.ScrollPosChanged += _internalFileViewer_ScrollPosChanged; _internalFileViewer.SelectedLineChanged += _internalFileViewer_SelectedLineChanged; _internalFileViewer.DoubleClick += (sender, args) => OnRequestDiffView(EventArgs.Empty); HotkeysEnabled = true; if (RunTime() && ContextMenuStrip == null) { ContextMenuStrip = contextMenu; } contextMenu.Opening += ContextMenu_Opening; _fullPathResolver = new FullPathResolver(() => Module.WorkingDir); }
public FileViewer() { TreatAllFilesAsText = false; ShowEntireFile = false; NumberOfContextLines = AppSettings.NumberOfContextLines; InitializeComponent(); InitializeComplete(); UICommandsSourceSet += OnUICommandsSourceSet; _internalFileViewer = new FileViewerInternal(() => Module); _internalFileViewer.MouseEnter += (_, e) => OnMouseEnter(e); _internalFileViewer.MouseLeave += (_, e) => OnMouseLeave(e); _internalFileViewer.MouseMove += (_, e) => OnMouseMove(e); _internalFileViewer.KeyUp += (_, e) => OnKeyUp(e); var internalFileViewerControl = (Control)_internalFileViewer; internalFileViewerControl.Dock = DockStyle.Fill; Controls.Add(internalFileViewerControl); _async = new AsyncLoader(); _async.LoadingError += (_, e) => { if (!IsDisposed) { ResetForText(null); _internalFileViewer.SetText("Unsupported file: \n\n" + e.Exception.ToString(), openWithDifftool: null /* not applicable */); TextLoaded?.Invoke(this, null); } }; IgnoreWhitespaceChanges = AppSettings.IgnoreWhitespaceChanges; ignoreWhiteSpaces.Checked = IgnoreWhitespaceChanges; ignoreWhiteSpaces.Image = Images.WhitespaceIgnore; ignoreWhitespaceChangesToolStripMenuItem.Checked = IgnoreWhitespaceChanges; ignoreWhitespaceChangesToolStripMenuItem.Image = ignoreWhiteSpaces.Image; ignoreAllWhitespaces.Checked = AppSettings.IgnoreAllWhitespaceChanges; ignoreAllWhitespaces.Image = Images.WhitespaceIgnoreAll; ignoreAllWhitespaceChangesToolStripMenuItem.Checked = ignoreAllWhitespaces.Checked; ignoreAllWhitespaceChangesToolStripMenuItem.Image = ignoreAllWhitespaces.Image; ShowEntireFile = AppSettings.ShowEntireFile; showEntireFileButton.Checked = ShowEntireFile; showEntireFileToolStripMenuItem.Checked = ShowEntireFile; SetStateOfContextLinesButtons(); showNonPrintChars.Checked = AppSettings.ShowNonPrintingChars; showNonprintableCharactersToolStripMenuItem.Checked = AppSettings.ShowNonPrintingChars; ToggleNonPrintingChars(AppSettings.ShowNonPrintingChars); IsReadOnly = true; var encodingList = AppSettings.AvailableEncodings.Values.Select(e => e.EncodingName).ToList(); var defaultEncodingName = Encoding.Default.EncodingName; for (int i = 0; i < encodingList.Count; i++) { if (string.Equals(encodingList[i], defaultEncodingName, StringComparison.OrdinalIgnoreCase)) { encodingList[i] = "Default (" + Encoding.Default.HeaderName + ")"; break; } } encodingToolStripComboBox.Items.AddRange(encodingList.ToArray <object>()); _internalFileViewer.MouseMove += (_, e) => { if (_currentViewIsPatch && !fileviewerToolbar.Visible) { fileviewerToolbar.Visible = true; fileviewerToolbar.Location = new Point(Width - fileviewerToolbar.Width - 40, 0); fileviewerToolbar.BringToFront(); } }; _internalFileViewer.MouseLeave += (_, e) => { if (GetChildAtPoint(PointToClient(MousePosition)) != fileviewerToolbar && fileviewerToolbar != null) { fileviewerToolbar.Visible = false; } }; _internalFileViewer.TextChanged += (sender, e) => { if (_patchHighlighting) { _internalFileViewer.AddPatchHighlighting(); } TextChanged?.Invoke(sender, e); }; _internalFileViewer.ScrollPosChanged += (sender, e) => ScrollPosChanged?.Invoke(sender, e); _internalFileViewer.SelectedLineChanged += (sender, e) => SelectedLineChanged?.Invoke(sender, e); _internalFileViewer.DoubleClick += (_, args) => RequestDiffView?.Invoke(this, EventArgs.Empty); HotkeysEnabled = true; if (!IsDesignModeActive && ContextMenuStrip == null) { ContextMenuStrip = contextMenu; } contextMenu.Opening += (sender, e) => { copyToolStripMenuItem.Enabled = _internalFileViewer.GetSelectionLength() > 0; ContextMenuOpening?.Invoke(sender, e); }; _fullPathResolver = new FullPathResolver(() => Module.WorkingDir); }
protected virtual void OnTextLoaded(TextLoadedEventArgs e) { TextLoaded?.Invoke(this, e); }