/// <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); }
/// <summary> /// Called when project file is saved. /// </summary> /// <param name="file">File descriptor.</param> /// <param name="control">IDE document content control.</param> /// <returns>Form control as IDE document content.</returns> public bool onSaveFile(IdeProject.File file, Control control) { if (!(control is TextEditorControl)) { return(false); } TextEditorControl editor = control as TextEditorControl; editor.Encoding = Encoding.ASCII; editor.SaveFile(mBridge.GetProjectPath() + @"\" + file.relativePath); editor.Encoding = Encoding.ASCII; return(true); }
/// <summary> /// Called after project creation. /// Here you should initialize your project content. /// </summary> /// <param name="project">Project descriptor.</param> /// <returns>True if successful.</returns> public bool onProjectCreated(IdeProject project) { // create main project file. IdeProject.File f = new IdeProject.File(); // file uppercased extension as file type. It can be anything, but that way it's simple to manage. f.type = "BAS"; // file path relative to project directory. f.relativePath = "main.bas"; // add created file to project files list. project.files.Add(f); // then notify IDE (using bridge) to update views with new project content. mBridge.onProjectChanged(project); return(true); }
/// <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); }