public void loadFile() { if (File.Exists(patch)) { textBox.LoadFile(patch); } }
public bool LoadContent(object content, TextEditorControl textEditor) { string itemName = String.Empty; if (content != null) { itemName = content as string; } if (textEditor == null) { throw new NullParameterException("TextEditor parameter is null!"); } string tmp = itemName; if (String.IsNullOrEmpty(itemName)) { _openDialog.FileName = String.Empty; if (_openDialog.ShowDialog() != DialogResult.OK) { return(false); } tmp = _openDialog.FileName; } _fileName = tmp; textEditor.LoadFile(_fileName, false, true); FileInfo fi = new FileInfo(_fileName); _hint = fi.Name; return(true); }
void miOpen_Click(object sender, EventArgs e) { TextEditorControl editor = ActiveEditor; if (editor != null) { using (OpenFileDialog dialog = new OpenFileDialog()) { //dialog.Filter = SharpPadFileFilter; dialog.FilterIndex = 0; if (DialogResult.OK == dialog.ShowDialog()) { editor.LoadFile(dialog.FileName); //CheckCurrentViewMode(editor.Document.HighlightingStrategy.Name); //if (Path.GetExtension(dialog.FileName).ToLower() == ".xml") //{ // if (!(ActiveEditor.Document.FoldingManager.FoldingStrategy is XmlFoldingStrategy)) // { // ActiveEditor.Document.FoldingManager.FoldingStrategy = new XmlFoldingStrategy(); // } //} UpdateFolding(); } } } }
/// <summary> /// Called when new file was created and added to project. /// </summary> /// <param name="file">File descriptor.</param> /// <param name="exists">True if file already exists in file system (just adding, without creating).</param> /// <returns>Form control as IDE document content.</returns> public Control onNewFile(IdeProject.File file, bool exists) { // create text editor control that will be able to edit our scripts. TextEditorControl editor = new TextEditorControl(); editor.Dock = DockStyle.Fill; editor.IsReadOnly = false; // here we can inject syntax highlighting for Tiny BASIC language. try { editor.SetHighlighting("TinyBASIC"); } catch (Exception exc) { while (exc.InnerException != null) { exc = exc.InnerException; } MessageBox.Show(@"Error occurred during Syntax Highlight binding to code editor:" + Environment.NewLine + exc.Message, Constants.NAME + @" Plugin Exception"); } editor.Encoding = Encoding.ASCII; // make sure that we wants to use ASCII encoding. if (!exists) { // setup editor content and save it to file if file does not exists. editor.Text = Constants.FILE_TEMPLATE; editor.SaveFile(mBridge.GetProjectPath() + @"\" + file.relativePath); } else { // or load file to editor otherwise. editor.LoadFile(mBridge.GetProjectPath() + @"\" + file.relativePath); } editor.Encoding = Encoding.ASCII; return(editor); }
public bool LoadFile(string filename) { TextEditorControl editor = ActiveEditor; if (editor != null) { try { editor.LoadFile(filename); CheckCurrentViewMode(editor.Document.HighlightingStrategy.Name); if (Path.GetExtension(filename).ToLower() == ".xml") { if (!(ActiveEditor.Document.FoldingManager.FoldingStrategy is XmlFoldingStrategy)) { ActiveEditor.Document.FoldingManager.FoldingStrategy = new XmlFoldingStrategy(); } UpdateFolding(); } } catch (Exception) { MessageBox.Show("打开文件失败!", "提示"); return(false); } return(true); } else { return(false); } }
public DocumentPanel(string fileName) { InitializeComponent(); _fileName = fileName; TabText = _fileName; if (PlatformSupport.Platform == PlatformType.Windows) { Icon = Properties.Resources.document_properties; // SharpDevelop text editor is Windows only. var txtDocument = new TextEditorControl { Dock = DockStyle.Fill, IsReadOnly = true, Name = "txtDocument" }; Controls.Add(txtDocument); txtDocument.SetHighlighting("SMI"); // Activate the highlighting, use the name from the SyntaxDefinition node. txtDocument.LoadFile(_fileName); } else { var txtDocument = new RichTextBox { Dock = DockStyle.Fill, Name = "txtDocument", ReadOnly = true }; Controls.Add(txtDocument); txtDocument.LoadFile(_fileName, RichTextBoxStreamType.PlainText); } }
/// <summary> /// Loads the file from the corresponding text editor window if it is /// open otherwise the file is loaded from the file system. /// </summary> void LoadFile(string fileName) { // Get currently open text editor that matches the filename. TextEditorControl openTextEditor = null; IWorkbenchWindow window = FileService.GetOpenFile(fileName); if (window != null) { ITextEditorControlProvider provider = window.ActiveViewContent as ITextEditorControlProvider; if (provider != null) { openTextEditor = provider.TextEditorControl; } } // Load the text into the definition view's text editor. if (openTextEditor != null) { ctl.Document.HighlightingStrategy = HighlightingStrategyFactory.CreateHighlightingStrategyForFile(fileName); ctl.Text = openTextEditor.Text; ctl.FileName = fileName; } else { ctl.LoadFile(fileName, true, true); // TODO: get AutoDetectEncoding from settings } }
public void OpenFile(string fileName) { //先查看要打开的文件是否已经打开 foreach (TabPage page1 in this.fileTabControl.TabPages) { string file = page1.Tag.ToString().EndsWith("*") ? page1.Tag.ToString().Substring(0, page1.Tag.ToString().Length - 1) : page1.Tag.ToString(); if (file == fileName) { MessageBox.Show("该文件已经打开!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } } TabPage page = new TabPage(Path.GetFileName(fileName)); page.Tag = fileName; page.ToolTipText = fileName; TextEditorControl textEditor = new TextEditorControl(); textEditor.LoadFile(fileName, true); textEditor.Dock = DockStyle.Fill; textEditor.ActiveTextAreaControl.TextArea.MouseUp += new MouseEventHandler(ShowContextMenu); textEditor.Document.DocumentChanged += new DocumentEventHandler(this.UpdateCurrentFileTitle); page.Controls.Add(textEditor); this.fileTabControl.TabPages.Add(page); this.fileTabControl.SelectedIndex = this.fileTabControl.TabPages.Count - 1; }
public override void LoadFile(string fileName) { textEditorControl.IsReadOnly = (File.GetAttributes(fileName) & FileAttributes.ReadOnly) == FileAttributes.ReadOnly; textEditorControl.LoadFile(fileName); ContentName = fileName; IsDirty = false; SetWatcher(); }
public void LoadFile(string path) { textEditorControl.TextChanged -= new EventHandler(Handle_EditorTextChanged); textEditorControl.LoadFile(path, true, true); textEditorControl.TextChanged += new EventHandler(Handle_EditorTextChanged); this.Text = Path.GetFileName(path); this.ToolTipText = path; }
public virtual bool LoadContent(object content, TextEditorControl textEditor) { string itemName = String.Empty; if (content != null) { itemName = content as string; } if (textEditor == null) { throw new NullParameterException("TextEditor parameter is null!"); } string tmp = itemName; if (String.IsNullOrEmpty(itemName)) { _openDialog.FileName = String.Empty; if (_openDialog.ShowDialog() != DialogResult.OK) { return(false); } tmp = _openDialog.FileName; Program.MainForm.AddFileToMru(tmp); } _filePath = tmp; FileInfo fi = new FileInfo(_filePath); _hint = fi.Name; if (fi.Extension.ToLowerInvariant() == ".sql" || fi.Extension.ToLowerInvariant() == ".qry") { textEditor.LoadFile(_filePath, true, true); } else { textEditor.LoadFile(_filePath, true, true); } return(true); }
void OpenFile(string fileName, int line, int column) { if (fileName != textEditorControl.FileName) { textEditorControl.LoadFile(fileName, true, true); } textEditorControl.ActiveTextAreaControl.ScrollTo(int.MaxValue); textEditorControl.ActiveTextAreaControl.Caret.Line = line - 1; textEditorControl.ActiveTextAreaControl.ScrollToCaret(); CodeCoverageService.ShowCodeCoverage(textEditorControl, fileName); }
public void LoadFile(string file) { if (File.Exists(file)) { openFile = file; this.Text = Path.GetFileName(file); textEditorControl.LoadFile(file); ILanguageStrategy lang = LanguageManager.GetLanguageStrategyForFile(file); if (lang != null) { textEditorControl.Document.FoldingManager.FoldingStrategy = lang.FoldingStrategy; textEditorControl.Document.HighlightingStrategy = lang.HighlightingStrategy; completionKeyHandler.CompletionDataProvider = lang.CompletionData; } saved = true; this.Text = this.Text.Replace("*", ""); } }
public frmAbout(PBObjLib.Application app) { m_App = app; InitializeComponent(); string tmp = Path.GetTempPath() + @"\mPBScript.cs"; if (!File.Exists(tmp)) { File.Create(tmp).Close(); } editor.LoadFile(tmp); editor.Dock = DockStyle.Fill; // this.groupBox2.Controls.Add(editor); }
public void OpenScriptFromFile() { openFileDialog1.FileName = String.Empty; if (openFileDialog1.ShowDialog() != DialogResult.OK) { return; } _textEditor.LoadFile(openFileDialog1.FileName, false, true); _fileName = openFileDialog1.FileName; statLblFileName.Text = openFileDialog1.FileName; FileInfo fi = new FileInfo(_fileName); this.TabText = fi.Name; this.Text = this.TabText; }
public static TextEditorControl open(this TextEditorControl textEditorControl, string sourceCodeFile) { return((TextEditorControl)textEditorControl.invokeOnThread( () => { if (sourceCodeFile.fileExists()) { textEditorControl.LoadFile(sourceCodeFile); } else { textEditorControl.SetHighlighting("C#"); textEditorControl.Document.TextContent = sourceCodeFile; } return textEditorControl; })); }
/// <summary> /// Called when project file is loaded into IDE as document. /// </summary> /// <param name="file">File descriptor.</param> /// <returns>Form control as IDE document content.</returns> public Control onLoadFile(IdeProject.File file) { TextEditorControl editor = new TextEditorControl(); editor.Dock = DockStyle.Fill; editor.IsReadOnly = false; try { editor.SetHighlighting("TinyBASIC"); } catch (Exception exc) { while (exc.InnerException != null) { exc = exc.InnerException; } MessageBox.Show(@"Error occurred during Syntax Highlight binding to code editor:" + Environment.NewLine + exc.Message, Constants.NAME + @" Plugin Exception"); } editor.Encoding = Encoding.ASCII; editor.LoadFile(mBridge.GetProjectPath() + @"\" + file.relativePath); editor.Encoding = Encoding.ASCII; return(editor); }
public bool LoadFromFile(string fileName) { _textEditor.LoadFile(fileName, true, true); return(true); }
private void miFile_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e) { #region 快捷菜单-文件 try { switch (e.ClickedItem.Name) { case "miOpenFile": //打开 { TextEditorControl editor = textEditorContent; if (editor != null) { using (OpenFileDialog dialog = new OpenFileDialog()) { dialog.Filter = SharpPadFileFilter; dialog.FilterIndex = 0; if (DialogResult.OK == dialog.ShowDialog()) { editor.LoadFile(dialog.FileName); CheckCurrentViewMode(editor.Document.HighlightingStrategy.Name); if (System.IO.Path.GetExtension(dialog.FileName).ToLower() == ".xml") { if (!(textEditorContent.Document.FoldingManager.FoldingStrategy is XmlFoldingStrategy)) { textEditorContent.Document.FoldingManager.FoldingStrategy = new XmlFoldingStrategy(); } UpdateFolding(); } } } } } break; case "miSave": //保存 { TextEditorControl editor = textEditorContent; if (editor != null) { SaveAs(); } } break; case "miSaveAs": //另存为 SaveAs(); break; } } catch (System.AccessViolationException accEx) { LogHelper.WriteException(accEx); } catch (System.StackOverflowException flowEx) { LogHelper.WriteException(flowEx); } catch (Exception ex) { LogHelper.WriteException(ex); } #endregion }
private void FrmLegend_Load(object sender, EventArgs e) { txtEditControl.LoadFile(ConfigurationManager.AppSettings["Legend"].ToString()); txtEditControl.Enabled = false; }
private void FrmTemplate_Load(object sender, EventArgs e) { txtEditControl.LoadFile(ConfigurationManager.AppSettings["TempCS"].ToString()); LoadCmbTipo(); }
//添加选项卡 private void AddTabItem(string filePath, string name) { if (!File.Exists(filePath)) { return; } foreach (TabItem item in tabControl1.Tabs) { if (item.Text != name) { continue; } TextEditorControl textEditor = item.AttachedControl.Controls[0] as TextEditorControl; if (textEditor == null) { continue; } if (textEditor.FileName == filePath) { tabControl1.SelectedTab = item; return; } } DevComponents.DotNetBar.TabControlPanel tabControlPanel = new TabControlPanel(); DevComponents.DotNetBar.TabItem tabItem = new TabItem(); ICSharpCode.TextEditor.TextEditorControl textEditorControl = new TextEditorControl(); // tabControl1 tabControl1.CanReorderTabs = true; tabControl1.Controls.Add(tabControlPanel); tabControl1.Dock = System.Windows.Forms.DockStyle.Fill; tabControl1.Location = new System.Drawing.Point(0, 0); tabControl1.Name = "tabControl" + name; tabControl1.SelectedTabFont = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold); tabControl1.SelectedTabIndex = 0; tabControl1.Size = new System.Drawing.Size(805, 438); tabControl1.TabIndex = 0; tabControl1.TabLayoutType = DevComponents.DotNetBar.eTabLayoutType.FixedWithNavigationBox; tabControl1.Tabs.Add(tabItem); tabControl1.SelectedTab = tabItem; // tabItem1 tabItem.AttachedControl = tabControlPanel; tabItem.Name = "tabItem" + tabControl1.Tabs.Count + 1; tabItem.Text = name; tabItem.MouseDown += new MouseEventHandler(tabItem_MouseDown); // tabControlPanel1 tabControlPanel.Controls.Add(textEditorControl); tabControlPanel.Dock = System.Windows.Forms.DockStyle.Fill; tabControlPanel.Location = new System.Drawing.Point(0, 26); tabControlPanel.Name = "tabControlPanel" + tabControl1.Tabs.Count + 1; tabControlPanel.Padding = new System.Windows.Forms.Padding(1); tabControlPanel.Size = new System.Drawing.Size(805, 412); tabControlPanel.Style.BackColor1.Color = System.Drawing.Color.FromArgb(((int)(((byte)(142)))), ((int)(((byte)(179)))), ((int)(((byte)(231))))); tabControlPanel.Style.BackColor2.Color = System.Drawing.Color.FromArgb(((int)(((byte)(223)))), ((int)(((byte)(237)))), ((int)(((byte)(254))))); tabControlPanel.Style.Border = DevComponents.DotNetBar.eBorderType.SingleLine; tabControlPanel.Style.BorderColor.Color = System.Drawing.Color.FromArgb(((int)(((byte)(59)))), ((int)(((byte)(97)))), ((int)(((byte)(156))))); tabControlPanel.Style.BorderSide = ((DevComponents.DotNetBar.eBorderSide)(((DevComponents.DotNetBar.eBorderSide.Left | DevComponents.DotNetBar.eBorderSide.Right) | DevComponents.DotNetBar.eBorderSide.Bottom))); tabControlPanel.Style.GradientAngle = 90; tabControlPanel.TabItem = tabItem; // textEditorControl1 textEditorControl.Dock = System.Windows.Forms.DockStyle.Fill; textEditorControl.IsReadOnly = false; textEditorControl.Location = new System.Drawing.Point(1, 1); textEditorControl.Name = "textEditorControl" + tabControl1.Tabs.Count + 1; textEditorControl.Size = new System.Drawing.Size(803, 410); textEditorControl.LoadFile(filePath); //contextMenuBar1.SetContextMenuEx(textEditorControl, textEditorControlMenu); }
private void tvDirectory_DoubleClick(object sender, EventArgs e) { TreeNode selectNode = tvDirectory.SelectedNode; if (selectNode != null && selectNode.Tag != null) { if (selectNode.ImageKey != folderKeyOfImageList) { #region 打开文件 string dsoFramerExtensionString = ".doc,.docx,.rtf,.ppt,.odt,.docm,.dotx,.dotm,.dot,.xls,"; string generalExtensionString = ".txt,.cs,.vb,.java,.cpp,.il,.xml,.config,"; string webBrowerExtensionString = ".htm,.html,.mht,.pdf,"; string[] generalExtensions = generalExtensionString.Split(','); string[] dsoFramerExtensions = dsoFramerExtensionString.Split(','); string[] webBrowerExtensions = webBrowerExtensionString.Split(','); string[] extensions = (dsoFramerExtensionString + generalExtensionString + webBrowerExtensionString).TrimEnd(',').Split(','); string path = selectNode.Tag.ToString(); try { if (extensions.Contains(Path.GetExtension(path))) { if (dsoFramerExtensions.Contains(Path.GetExtension(path))) { this.editorContainer.Controls.Clear(); //dsoFramer必须先把控件Add上,再打开文件 this.editorContainer.Controls.Add(this.axFramerControl1); this.axFramerControl1.Open(path); //this.axFramerControl1.Focus(); } else if (webBrowerExtensions.Contains(Path.GetExtension(path))) { this.editorContainer.Controls.Clear(); this.webBrower.Navigate(path); this.editorContainer.Controls.Add(this.webBrower); this.webBrower.Focus(); } else { string content = File.ReadAllText(path); this.editorContainer.Controls.Clear(); txtCode.LoadFile(path); this.editorContainer.Controls.Add(this.txtCode); txtCode.Focus(); } txtFileName.Text = path.ToString(); } else { OpenFileBySystem(path); } } catch (Exception ex) { this.ShowMessage(ex); OpenFileBySystem(path); } #endregion } } }
public DocumentForm(string path) : this() { textEditorControl.LoadFile(path, true, true); Title = FileName; Modified = false; }