private void UpdateState(string name) { if (name == "FilePath") { if (!string.IsNullOrEmpty(filePath) && File.Exists(FilePath)) { // Set current definition var fileInfo = new FileInfo(FilePath); var definition = ThemedHighlightingManager.Instance.GetDefinitionByExtension(fileInfo.Extension); if (definition != null) { CurrentSyntax = definition.Name; } else { CurrentSyntax = "None"; } // Do not preview files over 4MB or binary IsLargeOrBinary = fileInfo.Length > 4096000 || Utils.IsBinary(FilePath); // Disable highlighting for large number of matches HighlightDisabled = GrepResult?.Matches?.Count > 5000; // Tell View to show window ShowPreview?.Invoke(this, new ShowEventArgs { ClearContent = true }); } else { // Tell View to show window and clear content ShowPreview?.Invoke(this, new ShowEventArgs { ClearContent = true }); } } if (name == "LineNumber") { // Tell View to show window but not clear content ShowPreview?.Invoke(this, new ShowEventArgs { ClearContent = false }); } if (name == "CurrentSyntax") { // Tell View to show window and clear content ShowPreview?.Invoke(this, new ShowEventArgs { ClearContent = true }); } }
private void UpdateState(string name) { if (name == nameof(GrepResult)) { MarkerLineNumbers = GrepResult.SearchResults.Where(sr => !sr.IsContext) .Select(sr => sr.LineNumber).Distinct().ToList(); } if (name == nameof(FilePath)) { ClearPositionMarkers(); if (!string.IsNullOrEmpty(filePath) && File.Exists(FilePath)) { // Set current definition var fileInfo = new FileInfo(FilePath); var definition = ThemedHighlightingManager.Instance.GetDefinitionByExtension(fileInfo.Extension); CurrentSyntax = definition != null ? definition.Name : Resources.Preview_SyntaxNone; try { // Do not preview files over 4MB or binary IsPdf = Utils.IsPdfFile(FilePath); IsLargeOrBinary = fileInfo.Length > 4096000 || Utils.IsBinary(FilePath) || IsPdf; } catch (System.IO.IOException ex) { // Is the file locked and cannot be read by IsBinary? // message is shown in the preview window logger.Error(ex, "Failure in check for large or binary"); } // Disable highlighting for large number of matches HighlightDisabled = GrepResult?.Matches?.Count > 5000; // Tell View to show window ShowPreview?.Invoke(this, EventArgs.Empty); } else { // Tell View to show window and clear content ShowPreview?.Invoke(this, EventArgs.Empty); } } }
private void UpdateState(string name) { if (name == nameof(FilePath)) { if (!string.IsNullOrEmpty(filePath) && File.Exists(FilePath)) { // Set current definition var fileInfo = new FileInfo(FilePath); var definition = ThemedHighlightingManager.Instance.GetDefinitionByExtension(fileInfo.Extension); if (definition != null) { CurrentSyntax = definition.Name; } else { CurrentSyntax = "None"; } try { // Do not preview files over 4MB or binary IsLargeOrBinary = fileInfo.Length > 4096000 || Utils.IsBinary(FilePath); } catch (System.IO.IOException ex) { // Is the file locked and cannot be read by IsBinary? // message is shown in the preview window logger.Error(ex, "Failure in check for large or binary"); } // Disable highlighting for large number of matches HighlightDisabled = GrepResult?.Matches?.Count > 5000; // Tell View to show window ShowPreview?.Invoke(this, new ShowEventArgs { ClearContent = true }); } else { // Tell View to show window and clear content ShowPreview?.Invoke(this, new ShowEventArgs { ClearContent = true }); } } if (name == nameof(LineNumber)) { // Tell View to show window but not clear content ShowPreview?.Invoke(this, new ShowEventArgs { ClearContent = false }); } if (name == nameof(CurrentSyntax)) { // Tell View to show window and clear content ShowPreview?.Invoke(this, new ShowEventArgs { ClearContent = true }); } }