/// <summary> /// Updates the file source (ie. write the file) /// </summary> public void SetSource(string file, string src) { switch (type) { case OperationType.FindInSource: this.source = src; break; default: EncodingFileInfo info = FileHelper.GetEncodingFileInfo(file); if (this.updateSourceFile || !this.IsDocumentCached(file)) { FileHelper.WriteFile(file, src, Encoding.GetEncoding(info.CodePage), info.ContainsBOM); } else { // make this method thread safe if ((PluginBase.MainForm as Form).InvokeRequired) { (PluginBase.MainForm as Form).BeginInvoke((MethodInvoker) delegate { openDocuments[file].SciControl.Text = src; }); } else { openDocuments[file].SciControl.Text = src; } } break; } }
public static String GetSnippet(String word, String syntax, Encoding current) { string surroundFolder = "surround"; String globalDir = Path.Combine(PathHelper.SnippetDir, surroundFolder); String global = Path.Combine(globalDir, word + ".fds"); String specificDir = Path.Combine(PathHelper.SnippetDir, syntax); specificDir = Path.Combine(specificDir, surroundFolder); String specific = Path.Combine(specificDir, word + ".fds"); if (File.Exists(specific)) { EncodingFileInfo info = FileHelper.GetEncodingFileInfo(specific); return(DataConverter.ChangeEncoding(info.Contents, info.CodePage, current.CodePage)); } else if (File.Exists(global)) { EncodingFileInfo info = FileHelper.GetEncodingFileInfo(global); return(DataConverter.ChangeEncoding(info.Contents, info.CodePage, current.CodePage)); } else { return(null); } }
/// <summary> /// Reloads an editable document /// </summary> public void Reload(Boolean showQuestion) { if (!this.IsEditable) { return; } if (showQuestion) { String dlgTitle = TextHelper.GetString("Title.ConfirmDialog"); String message = TextHelper.GetString("Info.AreYouSureToReload"); if (MessageBox.Show(Globals.MainForm, message, " " + dlgTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } } Globals.MainForm.ReloadingDocument = true; Int32 position = this.SciControl.CurrentPos; TextEvent te = new TextEvent(EventType.FileReload, this.FileName); EventManager.DispatchEvent(Globals.MainForm, te); if (!te.Handled) { EncodingFileInfo info = FileHelper.GetEncodingFileInfo(this.FileName); if (info.CodePage == -1) { Globals.MainForm.ReloadingDocument = false; return; // If the files is locked, stop. } Encoding encoding = Encoding.GetEncoding(info.CodePage); this.SciControl.IsReadOnly = false; this.SciControl.Encoding = encoding; this.SciControl.Text = info.Contents; this.SciControl.IsReadOnly = FileHelper.FileIsReadOnly(this.FileName); this.SciControl.SetSel(position, position); this.SciControl.EmptyUndoBuffer(); int lineCount = SciControl.LineCount; foreach (var lineNum in this.bookmarks) { if (lineNum < 0) { continue; } if (lineNum >= lineCount) { if (!MarkerManager.HasMarker(SciControl, 0, lineCount - 1)) { MarkerManager.ToggleMarker(SciControl, 0, lineCount - 1); } } else { MarkerManager.ToggleMarker(SciControl, 0, lineNum); } } this.InitBookmarks(); this.fileInfo = new FileInfo(this.FileName); } Globals.MainForm.OnDocumentReload(this); }
/// <summary> /// Gets the active encoding name from the current codepage /// </summary> public static String GetActiveEncodingName() { ITabbedDocument document = Globals.CurrentDocument; if (document != null && document.IsEditable) { Int32 codepage = document.SciControl.Encoding.CodePage; EncodingFileInfo info = FileHelper.GetEncodingFileInfo(document.FileName); if (codepage == info.CodePage) { if (ScintillaManager.IsUnicode(info.CodePage)) { String name = "Unicode (" + info.Charset + ")"; return(info.ContainsBOM ? name + " (BOM)" : name); } else { String name = TextHelper.GetStringWithoutMnemonics("Label.8Bits"); return(name + " (" + info.Charset + ")"); } } else // Opened in different encoding... { Boolean hasBOM = document.SciControl.SaveBOM; if (codepage == Encoding.UTF8.CodePage) { return(GetLabelAsPlainText("Label.UTF8", true, hasBOM)); } else if (codepage == Encoding.UTF7.CodePage) { return(GetLabelAsPlainText("Label.UTF7", true, hasBOM)); } else if (codepage == Encoding.BigEndianUnicode.CodePage) { return(GetLabelAsPlainText("Label.BigEndian", true, hasBOM)); } else if (codepage == Encoding.Unicode.CodePage) { return(GetLabelAsPlainText("Label.LittleEndian", true, hasBOM)); } else { return(GetLabelAsPlainText("Label.8Bits", false, false)); } } } else { return(TextHelper.GetString("Info.Unknown")); } }
/// <summary> /// Updates the file source (ie. write the file) /// </summary> public void SetSource(string file, string src) { switch (type) { case OperationType.FindInSource: this.source = src; break; default: EncodingFileInfo info = FileHelper.GetEncodingFileInfo(file); FileHelper.WriteFile(file, src, Encoding.GetEncoding(info.CodePage), info.ContainsBOM); break; } }
/// <summary> /// Parse a file adding all the found Matches into the listView /// </summary> private void ParseFile(String path) { if (!File.Exists(path)) { return; } Hashtable itemTag; ListViewItem item; EncodingFileInfo info = FileHelper.GetEncodingFileInfo(path); if (info.CodePage == -1) { return; // If the file is locked, stop. } MatchCollection matches = this.todoParser.Matches(info.Contents); this.RemoveItemsByPath(path); if (matches.Count > 0) { foreach (Match match in matches) { itemTag = new Hashtable(); itemTag["FullPath"] = path; itemTag["LastWriteTime"] = new FileInfo(path).LastWriteTime; itemTag["Position"] = match.Groups[2].Index; item = new ListViewItem(new String[] { "", match.Groups[2].Index.ToString(), match.Groups[2].Value, CleanMatch(match.Groups[3].Value), Path.GetFileName(path), Path.GetDirectoryName(path) }, FindImageIndex(match.Groups[2].Value)); item.Tag = itemTag; item.Name = path; item.ToolTipText = match.Groups[2].Value; this.listView.Items.Add(item); this.AddToGroup(item, path); } this.columnPath.Width = -2; // Extend last column } }
/// <summary> /// Reloads an editable document /// </summary> public void Reload(Boolean showQuestion) { if (!this.IsEditable) { return; } if (showQuestion) { String dlgTitle = TextHelper.GetString("Title.ConfirmDialog"); String message = TextHelper.GetString("Info.AreYouSureToReload"); if (MessageBox.Show(Globals.MainForm, message, " " + dlgTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } } Globals.MainForm.ReloadingDocument = true; Int32 position = this.SciControl.CurrentPos; TextEvent te = new TextEvent(EventType.FileReload, this.FileName); EventManager.DispatchEvent(Globals.MainForm, te); if (!te.Handled) { EncodingFileInfo info = FileHelper.GetEncodingFileInfo(this.FileName); if (info.CodePage == -1) { Globals.MainForm.ReloadingDocument = false; return; // If the files is locked, stop. } Encoding encoding = Encoding.GetEncoding(info.CodePage); this.SciControl.IsReadOnly = false; this.SciControl.Encoding = encoding; this.SciControl.CodePage = ScintillaManager.SelectCodePage(info.CodePage); this.SciControl.Text = info.Contents; this.SciControl.IsReadOnly = FileHelper.FileIsReadOnly(this.FileName); this.SciControl.SetSel(position, position); this.SciControl.EmptyUndoBuffer(); this.SciControl.Focus(); } Globals.MainForm.OnDocumentReload(this); }