//======================================================================== // Constructors //======================================================================== //Common Constructor Helper private void _initPre(string name, ProjectFile.FileType type) { InitializeComponent(); icsEditor = new TextEditorControl(); icsEditor.Dock = DockStyle.Fill; icsEditor.Document.DocumentChanged += icsEditor_DocumentChanged; icsEditor.ActiveTextAreaControl.TextArea.MouseDown += new MouseEventHandler(icsEditor_MouseDown); icsEditor.VRulerRow = 132; icsEditor.IndentStyle = IndentStyle.Smart; if (type == ProjectFile.FileType.REPGEN) { icsEditor.SetHighlighting("RepGen"); completer = new RepGenComplete(); folder = new RepGenFold(); icsEditor.Document.FoldingManager.FoldingStrategy = folder; } Controls.Add(icsEditor); DockAreas = DockAreas.Document; Text = fileName = name; Icon = IconFromType(type); fileType = type; }
public static TextEditorControl Build(string highlighting, IFoldingStrategy foldingStrategy, AbstractInsightDataProvider insight) { var ret = new TextEditorControl(); /*_completionProvider = completionProvider; _insight = insight; ret.Document.FormattingStrategy = new CSharpFormattingStrategy(); ret.Document.FoldingManager.FoldingStrategy = foldingStrategy; ret.CompletionRequest += new EventHandler<CompletionEventArgs>(CompletionRequest); ret.InsightRequest += new EventHandler<InsightEventArgs>(InsightRequest); ret.ToolTipRequest += new EventHandler<ToolTipRequestEventArgs>(ToolTipRequest); */ ret.Dock = DockStyle.Fill; Font consolasFont = new Font("Consolas", 9.75f); ret.Font = consolasFont; var timer = new Timer(); timer.Enabled = true; timer.Interval = 2000; timer.Tick += new EventHandler(UpdateFoldings); timer.Tag = ret; ret.Document.HighlightingStrategy = HighlightingManager.Manager.FindHighlighterForFile(highlighting); return ret; }
public static TextEditorControl Build(string highlighting, IFoldingStrategy foldingStrategy, AbstractInsightDataProvider insight) { var ret = new TextEditorControl(); /*_completionProvider = completionProvider; * _insight = insight; * * ret.Document.FormattingStrategy = new CSharpFormattingStrategy(); * ret.Document.FoldingManager.FoldingStrategy = foldingStrategy; * * ret.CompletionRequest += new EventHandler<CompletionEventArgs>(CompletionRequest); * ret.InsightRequest += new EventHandler<InsightEventArgs>(InsightRequest); * ret.ToolTipRequest += new EventHandler<ToolTipRequestEventArgs>(ToolTipRequest); */ ret.Dock = DockStyle.Fill; Font consolasFont = new Font("Consolas", 9.75f); ret.Font = consolasFont; var timer = new Timer(); timer.Enabled = true; timer.Interval = 2000; timer.Tick += new EventHandler(UpdateFoldings); timer.Tag = ret; ret.Document.HighlightingStrategy = HighlightingManager.Manager.FindHighlighterForFile(highlighting); return(ret); }
public PHPLanguageBinding(EditorControl edit) { editor = edit; editor.ActiveTextAreaControl.TextArea.KeyDown += new System.Windows.Forms.KeyEventHandler(TextArea_KeyDown); phpFolding = new PHPFoldingStrategy(); phpFormatting = new PHPFormattingStrategy(); }
/// <summary> /// Initializes a new code editor. /// </summary> public CodeEditorViewModel(IFoldingStrategy foldingStrategy, IHighlightingDefinition highlightingDefinition, IEnumerable <MenuViewModel> snippets, IClipboard clipboard) : this() { _clipboard = clipboard; FoldingStrategy = foldingStrategy; HighlightingDefinition = highlightingDefinition; Snippets = snippets; }
public void SetFoldingStrategy(string typename) { if (typename == "C#") { this.foldingStrategy = new CSharpFoldingStrategy(); } else if (typename == "TSql") { this.foldingStrategy = new TSqlFoldingStrategy(); } }
/// <summary> /// Add two estimators. /// </summary> /// <param name="estimator">The estimator to add to.</param> /// <param name="otherEstimator">The other estimator to add.</param> /// <param name="foldingStrategy">THe folding strategy to use</param> /// <param name="inPlace">When <c>true</c> the data is added to the given <paramref name="estimator"/>, otherwise a new estimator is created.</param> /// <returns></returns> internal static IBitMinwiseHashEstimatorFullData Add( this IBitMinwiseHashEstimatorFullData estimator, IBitMinwiseHashEstimatorFullData otherEstimator, IFoldingStrategy foldingStrategy, bool inPlace = false) { if (estimator == null || otherEstimator == null) { return(null); } var foldingFactors = foldingStrategy?.GetFoldFactors(estimator.Capacity, otherEstimator.Capacity); if ((estimator.Capacity != otherEstimator.Capacity && (foldingFactors?.Item1 ?? 0L) <= 1 && (foldingFactors?.Item2 ?? 0L) <= 1) || estimator.HashCount != otherEstimator.HashCount) { throw new ArgumentException("Minwise estimators with different capacity or hash count cannot be added."); } var res = inPlace && ((foldingFactors?.Item1 ?? 1L) == 1L) && ((foldingFactors?.Item2 ?? 1L) == 1L) ? estimator : new BitMinwiseHashEstimatorFullData { Capacity = estimator.Capacity / (foldingFactors?.Item1 ?? 1L), HashCount = estimator.HashCount, BitSize = estimator.BitSize, ItemCount = estimator.ItemCount, }; if (estimator.Values != null && otherEstimator.Values != null) { res.SetValues(false); } if (res.Values == null) { return(res); } Parallel.ForEach( Partitioner.Create(0L, res.Values.LongLength), (range, state) => { for (var i = range.Item1; i < range.Item2; i++) { res.Values[i] = Math.Min( GetFolded(estimator.Values, i, foldingFactors?.Item1, Math.Min, int.MaxValue), GetFolded(otherEstimator.Values, i, foldingFactors?.Item2, Math.Min, int.MaxValue)); } }); res.ItemCount += otherEstimator.ItemCount; return(res); }
public void Dispose() { _helper = null; _foldingManager = null; _foldingStrategy = null; if (_foldingUpdateTimer != null) { _foldingUpdateTimer.Stop(); } _foldingUpdateTimer = null; }
//------------------------------------------------------------------------ private void SaveAsSymitar() { frmFileOpen saveAs = new frmFileOpen(fileName); DialogResult result = saveAs.ShowDialog(Util.MainForm); if (result == DialogResult.Cancel) { saveAs.Dispose(); return; } if (result == DialogResult.No) { saveAs.Dispose(); SaveAsLocal(); return; } if (saveAs.saveAsIsLocal) //not a Local Filesystem file, but a LOCAL mounted Filesystem file { fileLocal = saveAs.saveAsLocal.Path + '\\' + saveAs.saveAsName; if (SaveLocal()) { fileOrigin = Origin.LOCAL; fileType = FileTypeFromExtension(fileLocal); Icon = IconFromType(fileType); } } else { SymInst inst = saveAs.saveAsInst; fileSym = new SymFile(inst.Parent.IP, inst.SymDir, saveAs.saveAsName, DateTime.Now, icsEditor.Text.Length, saveAs.saveAsType); fileName = saveAs.saveAsName; if (SaveSymitar()) { fileOrigin = Origin.SYM; fileType = FileTypeFromSymFile(fileSym); Icon = IconFromType(fileType); if (fileType == ProjectFile.FileType.REPGEN) { icsEditor.SetHighlighting("RepGen"); completer = new RepGenComplete(); folder = new RepGenFold(); icsEditor.Document.FoldingManager.FoldingStrategy = folder; } else if (fileType == ProjectFile.FileType.LETTER) { icsEditor.SetHighlighting("Default"); icsEditor.Document.FoldingManager.FoldingStrategy = new ICSharpCode.TextEditor.Document.IndentFoldingStrategy(); } SetModified(false, true); } } }
public void SetDocumentEditor(TextEditorBase TE) { mTextEditor = TE; IHighlightingDefinition HD = TE.HighlightingDefinition; if (HD != null) { textEditor.SyntaxHighlighting = HD; } else { // try to use Avalon highlighting built in to find the correct highlight by file extension string ext = Path.GetExtension(FileName).ToLower(); textEditor.SyntaxHighlighting = ICSharpCode.AvalonEdit.Highlighting.HighlightingManager.Instance.GetDefinitionByExtension(ext); } IFoldingStrategy FG = TE.FoldingStrategy; if (FG != null) { try { mFoldingManager = FoldingManager.Install(textEditor.TextArea); } catch { } mFoldingStrategy = FG; InitFoldings(); } textEditor.TextArea.Caret.PositionChanged += Caret_PositionChanged; //TODO: set indentation manager // Add tools in toolbar if (TE.Tools != null) { foreach (ITextEditorToolBarItem t in TE.Tools) { if (t is TextEditorToolBarItem) { TextEditorToolBarItem textEditorToolBarItem = (TextEditorToolBarItem)t; AddToolbarTool(textEditorToolBarItem.Image, textEditorToolBarItem.clickHandler, textEditorToolBarItem.toolTip, textEditorToolBarItem.toolVisibility); } else { // Plugin text editor AddPluginToolbarTool(t); } } } }
public JTranEditor() { InitializeComponent(); _foldingStrategy = new JsonFoldingStrategies(winEditBox, null); _codeCompletion = new JTranCodeCompletion(this); winEditBox.TextArea.TextEntering += winEditBox_TextArea_TextEntering; winEditBox.TextArea.TextEntered += winEditBox_TextArea_TextEntered; winEditBox.TextArea.SelectionCornerRadius = 0; winEditBox.TextArea.SelectionForeground = new SolidColorBrush(System.Windows.Media.Color.FromRgb(0, 0, 0)); winEditBox.TextArea.SelectionBrush = new SolidColorBrush(System.Windows.Media.Color.FromRgb(153, 201, 239)); winEditBox.TextArea.SelectionBorder = new System.Windows.Media.Pen(winEditBox.TextArea.SelectionBrush, 0); }
//------------------------------------------------------------------------ private void SaveAsLocal() { SaveFileDialog sfd = new SaveFileDialog(); sfd.DefaultExt = ExtensionFromType(fileType); sfd.Filter = "All Files (*.*)|*.*"; sfd.FileName = fileName; sfd.Title = "Save As"; if (fileLocal != null) { sfd.InitialDirectory = Util.FileDirectoryPathLocal(fileLocal); } if (sfd.ShowDialog() == DialogResult.OK) { try { Util.FileWriteLocal(sfd.FileName, icsEditor.Text); fileLocal = sfd.FileName; fileName = Util.FileBaseNameLocal(fileLocal); fileOrigin = Origin.LOCAL; fileType = FileTypeFromExtension(fileLocal); Icon = IconFromType(fileType); if (fileType == ProjectFile.FileType.REPGEN) { icsEditor.SetHighlighting("RepGen"); completer = new RepGenComplete(); folder = new RepGenFold(); icsEditor.Document.FoldingManager.FoldingStrategy = folder; } else if (fileType == ProjectFile.FileType.LETTER) { icsEditor.SetHighlighting("Default"); icsEditor.Document.FoldingManager.FoldingStrategy = new ICSharpCode.TextEditor.Document.IndentFoldingStrategy(); } SetModified(false, true); } catch (Exception ex) { MessageBox.Show("Error Saving File\n" + ex.Message, "PwrIDE", MessageBoxButtons.OK, MessageBoxIcon.Error); } } sfd.Dispose(); }
public void Dispose() { cssFolding = null; cssFormatting = null; }
public void Dispose() { _helper = null; _foldingManager = null; _foldingStrategy = null; if (_foldingUpdateTimer != null) _foldingUpdateTimer.Stop(); _foldingUpdateTimer = null; }
public void Dispose() { jsFolding = null; jsFormatting = null; }
public JSLanguageBinding(EditorControl edit) { editor = edit; jsFolding = new PHPFoldingStrategy(); }
/// <summary> /// Intersect two estimators /// </summary> /// <param name="estimator"></param> /// <param name="otherEstimator"></param> /// <param name="foldingStrategy"></param> /// <param name="inPlace"></param> /// <returns></returns> /// <remarks>Logically possible, but the item count is pretty much useless after this operation.</remarks> internal static BitMinwiseHashEstimatorFullData Intersect( this IBitMinwiseHashEstimatorFullData estimator, IBitMinwiseHashEstimatorFullData otherEstimator, IFoldingStrategy foldingStrategy) { if (estimator == null && otherEstimator == null) { return(null); } var foldingFactors = estimator == null || otherEstimator == null? null : foldingStrategy?.GetFoldFactors(estimator.Capacity, otherEstimator.Capacity); if (estimator == null) { return(new BitMinwiseHashEstimatorFullData { BitSize = otherEstimator.BitSize, Capacity = otherEstimator.Capacity, HashCount = otherEstimator.HashCount, ItemCount = 0 }); } if (otherEstimator != null && ((estimator.Capacity != otherEstimator.Capacity && (foldingFactors?.Item1 ?? 0L) <= 1 && (foldingFactors?.Item2 ?? 0L) <= 1) || estimator.HashCount != otherEstimator.HashCount)) { throw new ArgumentException("Minwise estimators with different capacity or hash count cannot be intersected."); } var res = new BitMinwiseHashEstimatorFullData { Capacity = estimator.Capacity / (foldingFactors?.Item1 ?? 1L), HashCount = estimator.HashCount, BitSize = estimator.BitSize, ItemCount = otherEstimator == null ? 0 : estimator.ItemCount }; if (estimator.Values != null && otherEstimator?.Values != null) { res.SetValues(false); } if (res.Values == null) { return(res); } var dropped = 0; Parallel.ForEach( Partitioner.Create(0L, res.Values.LongLength), (range, state) => { for (var i = range.Item1; i < range.Item2; i++) { var estimatorValue = GetFolded( estimator.Values, i, foldingFactors?.Item1, Math.Min, int.MaxValue); var otherEstimatorValue = GetFolded( otherEstimator.Values, i, foldingFactors?.Item2, Math.Min, int.MaxValue); if (estimatorValue == int.MaxValue || otherEstimatorValue == int.MaxValue || otherEstimatorValue != estimatorValue) { Interlocked.Increment(ref dropped); } res.Values[i] = Math.Max(estimatorValue, otherEstimatorValue); } }); //wildly wrong, but about as good as it gets. res.ItemCount = Math.Max( 0, Math.Min( estimator.ItemCount, otherEstimator.ItemCount) - (long)Math.Ceiling(dropped / (0.5D * res.HashCount))); return(res); }
public void Dispose() { htmlFolding = null; htmlFormatting = null; }
/// <summary> /// Creates new foldings and updates a <see cref="FoldingManager"/> with them. /// </summary> public static IEnumerable <NewFolding> GenerateFoldings(this FoldingManager manager, TextDocument document, IFoldingStrategy strategy) { int firstErrorOffset; var newFoldings = strategy.CreateNewFoldings(document, out firstErrorOffset).ToList(); manager.UpdateFoldings(newFoldings); return(newFoldings); }
public JsonEditViewModel(TextEditor winEditor, ICodeCompletion codeCompletion, Preferences preferences) { _foldingStrategy = new JsonFoldingStrategies(winEditor, preferences); _codeCompletion = codeCompletion; }
/// <remarks> /// Loads a file from the specified stream. /// </remarks> /// <param name="fileName">The name of the file to open. Used to find the correct highlighting strategy /// if autoLoadHighlighting is active, and sets the filename property to this value.</param> /// <param name="stream">The stream to actually load the file content from.</param> /// <param name="autoLoadHighlighting">Automatically load the highlighting for the file</param> /// <param name="autodetectEncoding">Automatically detect file encoding and set Encoding property to the detected encoding.</param> public void LoadFile(string fileName, Stream stream, bool autoLoadHighlighting, bool autodetectEncoding) { BeginUpdate(); _document.TextContent = string.Empty; _document.UndoStack.ClearAll(); _document.BookmarkManager.Clear(); if (autoLoadHighlighting) { try { _document.HighlightingStrategy = HighlightingManager.Instance.FindHighlighterForFile(fileName); // TODOsyntax this doesn't belong here. I did it because it needed a file/home. IFoldingStrategy fs = null; if (_document.HighlightingStrategy != null) { switch (_document.HighlightingStrategy.Folding) { case "Code": fs = new CodeFoldingStrategy(); break; case "CSharp": fs = new CSharpFoldingStrategy(); break; case "Markdown": fs = new MarkdownFoldingStrategy(); break; case "Xml": fs = new XmlFoldingStrategy(); break; } } _document.FoldingManager.FoldingStrategy = fs; } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } if (autodetectEncoding) { Encoding encoding = Encoding; Document.TextContent = Util.FileReader.ReadFileContent(stream, encoding); Encoding = encoding; } else { using (StreamReader reader = new StreamReader(fileName, Encoding)) { string s = reader.ReadToEnd(); Document.TextContent = s; // TODO2*** 50Mb takes 6 seconds... } } FileName = fileName; Document.UpdateQueue.Clear(); EndUpdate(); OptionsChanged(); Refresh(); }
public static void AddStrategy(string[] extensions, IFoldingStrategy strategy) { foldingStrategies.Add(extensions, strategy); }
public HTMLLanguageBinding(EditorControl edit) { editor = edit; htmlFolding = new PHPFoldingStrategy(); htmlFormatting = new HTMLFormattingStrategy(); }
public CSSLanguageBinding(EditorControl edit) { editor = edit; cssFolding = new PHPFoldingStrategy(); cssFormatting = new DefaultFormattingStrategy(); }