public CodeTab(OpenedFile file) { InitializeComponent(); switch (GetFileType(file.Name)) { case "txt": CodeEditorSyntaxLoader.SetSyntax(Editor, SyntaxLanguage.Text); break; default: CodeEditorSyntaxLoader.SetSyntax(Editor, SyntaxLanguage.Lua); break; } Editor.Open(file.FullName); Tag = file; }
/// <summary> /// Adds a previously created project file to the project /// </summary> /// <param name="file">The file to add</param> public void AddProjectFile(OpenedFile file) { if (file.Folder == null) { // Add to Project Project.Files.Add(file); var tn = new TreeNode { Text = file.Name, ImageKey = "code", ContextMenuStrip = CodeStrip, SelectedImageKey = "code", Tag = file }; file.Node = tn; TreeView.Nodes[0].Nodes.Add(tn); TreeView.ExpandAll(); } else { // Add to the folder file.Folder.Files.Add(file); var tn = new TreeNode { Text = file.Name, ImageKey = "code", ContextMenuStrip = CodeStrip, SelectedImageKey = "code", Tag = file }; file.Node = tn; file.Folder.Node.Nodes.Add(tn); TreeView.ExpandAll(); } }
/// <summary> /// Shows the add new item dialog and adds a new item /// </summary> public void AddNewItem() { if (!IsProjectOpen()) return; var nfd = new NewFileDialog(); if (nfd.ShowDialog() != DialogResult.OK) return; var pf = new OpenedFile(); string filePath; if (_explorer.tvFiles.SelectedNode == null) // Just do the normal adding to project... { filePath = Project.Path; pf.Folder = null; } else switch (_explorer.tvFiles.SelectedNode.Tag.GetType().Name) { case "Project": filePath = Project.Path; pf.Folder = null; break; case "Folder": filePath = ((Folder) _explorer.tvFiles.SelectedNode.Tag).FullName(); pf.Folder = ((Folder) _explorer.tvFiles.SelectedNode.Tag); break; case "OpenedFile": if (((OpenedFile) _explorer.tvFiles.SelectedNode.Tag).Folder == null) // Project File { filePath = Project.Path; pf.Folder = null; } else // File in Folder, so folders parent is cool :D { filePath = ((OpenedFile) _explorer.tvFiles.SelectedNode.Tag).Folder.FullName(); pf.Folder = ((OpenedFile) _explorer.tvFiles.SelectedNode.Tag).Folder; } break; default: filePath = Project.Path; pf.Folder = null; break; } if (File.Exists(filePath + @"\" + nfd.FileName)) { Util.ShowError(StringTable.FileAlreadyExists); AddNewItem(); return; } File.Create(filePath + @"\" + nfd.FileName).Close(); File.WriteAllText(filePath + @"\" + nfd.FileName, PreprocessCode(nfd.SelectedTemplate.Code)); pf.Name = nfd.FileName; pf.Saved = false; pf.FullName = filePath + @"\" + pf.Name; Project.Saved = false; AddProjectFile(pf); SaveProject(); OpenFile(filePath + @"\" + nfd.FileName); }
/// <summary> /// Creates a tab and shows a project file, if the tab is already created it is made active /// </summary> /// <param name="file">The file to show</param> public void ShowProjectFile(OpenedFile file) { if (IsProjectFileShown(file)) { MakeProjectFileActive(file); return; } if (File.Exists(file.FullName)) { file.Valid = true; file.Node.ImageKey = "code"; file.Node.SelectedImageKey = "code"; } else { Util.ShowError(StringTable.ProjectFileLost.Replace("%FILE%", file.Name)); return; } if (_fileLoading) return; _fileLoading = true; var ct = new CodeTab(file) {TabText = file.Name}; ct.Show(Manager); file.Editor = ct.Editor; _fileLoading = false; }
/// <summary> /// Creates and shows a tab for an opened file which is sperate from the project /// </summary> /// <param name="file">The file to open</param> public void ShowOpenedFile(OpenedFile file) { _fileLoading = true; var ct = new CodeTab(file) {TabText = file.Name}; ct.Show(Manager); if (file.Editor == null) file.Editor = ct.Editor; _fileLoading = false; }
/// <summary> /// Saves a project file /// </summary> /// <param name="file">The project file to save</param> public void SaveProjectFile(OpenedFile file) { file.Save(); }
/// <summary> /// Displays a dialog and renames a project file /// </summary> /// <param name="file">The file to rename</param> public void RenameProjectFile(OpenedFile file) { if (IsProjectOpen()) { // HACK!!! FIX!!! //RenameResult rr = RenameDialog.ShowDialog(file.Name); //foreach (char chr in rr.RenameRes.ToCharArray()) //{ // foreach (char invalidChar in Path.GetInvalidFileNameChars()) // { // if (chr == invalidChar) // { // // invalid character, call RenameProjectFile() again // Util.ShowError(StringTable.InvalidFileName); // RenameProjectFile(file); // return; // } // } //} //switch (rr.DialogRes) //{ // case DialogResult.OK: // if (file.Name == rr.RenameRes) // return; // File.Copy(file.FullName, file.FullName.Replace(file.Name, rr.RenameRes)); // File.Delete(file.FullName); // RenameNode(file, rr.RenameRes); // RenameCodeTab(file, rr.RenameRes); // file.FullName = file.FullName.Replace(file.Name, rr.RenameRes); // file.Name = rr.RenameRes; // file.Saved = false; // project.Saved = false; // break; // case DialogResult.Cancel: // return; //} } }
/// <summary> /// Checks if a specific project file is shown in the interface /// </summary> /// <param name="file">The project file to check</param> /// <returns>True if the file is open, otherwise false</returns> public bool IsProjectFileShown(OpenedFile file) { foreach (DockableWindow tp in Manager.Documents) { if (IsSpecialTab(tp)) continue; if (tp.Tag == file) return true; } return false; }
/// <summary> /// Renames a a code tab of a project file /// </summary> /// <param name="file">The project file to rename</param> /// <param name="newName">The new name to give the code tab</param> public void RenameCodeTab(OpenedFile file, string newName) { foreach (DockableWindow td in Manager.Documents) { if (IsSpecialTab(td)) continue; if (td.Tag == file) td.Text = newName; } }
/// <summary> /// Removes a previously created project file from the project /// </summary> /// <param name="file">The file to remove</param> public void RemoveProjectFile(OpenedFile file) { if (IsProjectOpen()) { // HACK!!! FIX!!! //DialogResult res = FileRemoveDialog.ShowDialog(file.Name); //switch (res) //{ // case DialogResult.Yes: // File.Delete(file.FullName); // CloseCodeTab(file); // RemoveNode(file); // project.Files.Remove(file); // project.Saved = false; // break; // case DialogResult.No: // CloseCodeTab(file); // RemoveNode(file); // project.Files.Remove(file); // project.Saved = false; // break; // case DialogResult.Cancel: // return; //} } }
/// <summary> /// Removes a specific project file node /// </summary> /// <param name="file">The project file to remove</param> public void RemoveNode(OpenedFile file) { if (!IsProjectOpen()) return; foreach (TreeNode tn in TreeView.Nodes[0].Nodes) { if (!(tn.Tag is OpenedFile)) continue; if (tn.Tag == file) tn.Remove(); } }
/// <summary> /// Opens a file directly from a filename /// </summary> /// <param name="fname">The filename to open</param> public void OpenFile(string fname) { var of = new OpenedFile {FullName = fname}; var fi = new FileInfo(fname); of.Name = fi.Name; of.Saved = true; ShowOpenedFile(of); }
/// <summary> /// Shows a dialog and opens a file which will not be part of the project /// </summary> public void OpenFile() { var ofd = new OpenFileDialog { Title = "Open file...", CheckFileExists = true, CheckPathExists = true, DereferenceLinks = true, Filter = "Lua Files (*.lua)|*.lua|All Files (*.*)|*.*", Multiselect = true }; if (ofd.ShowDialog() != DialogResult.OK) return; foreach (string file in ofd.FileNames) { var of = new OpenedFile(); of.FullName = file; var fi = new FileInfo(file); of.Name = fi.Name; of.Saved = true; ShowOpenedFile(of); } }
/// <summary> /// Shows the open file dialog and adds an existing item /// </summary> public void AddExistingItem() { if (!IsProjectOpen()) return; var ofd = new OpenFileDialog { Filter = "Lua Files (*.lua)|*.lua", Multiselect = true, Title = "Add Existing Item..." }; if (ofd.ShowDialog() != DialogResult.OK) return; foreach (string name in ofd.FileNames) { var fi = new FileInfo(name); // Were we clicked on a node in the treeview? If so, was it a folder or a file in a // Folder? If so, add it to that folder, otherwise just add it to the project. object selNode = _explorer.tvFiles.SelectedNode.Tag; OpenedFile selFile; Folder selFolder; OpenedFile pf; switch (selNode.GetType().Name) { case "OpenedFile": selFile = ((OpenedFile) selNode); if (selFile.Folder == null) { // Add to Project pf = new OpenedFile {Name = fi.Name, Saved = true}; pf.FullName = Project.Path + @"\" + pf.Name; } else { // Add to the selected files containing folder pf = new OpenedFile { Name = fi.Name, Saved = true, Folder = selFile.Folder, FullName = selFile.Folder.FullName() + @"\" + fi.Name }; } break; case "Folder": selFolder = ((Folder) selNode); pf = new OpenedFile { Name = fi.Name, Saved = true, Folder = selFolder, FullName = selFolder.FullName() + @"\" + fi.Name }; break; default: pf = new OpenedFile {Name = fi.Name, Saved = true}; pf.FullName = Project.Path + @"\" + pf.Name; break; } if (DoesProjectFileExist(pf.FullName)) { Util.ShowError(StringTable.FileAlreadyAdded); continue; } AddProjectFile(pf); } Project.Saved = false; SaveProject(); }
/// <summary> /// Makes a previously opened project file active /// </summary> /// <param name="file">The file to activate</param> public void MakeProjectFileActive(OpenedFile file) { // HACK: FIX! //foreach ( TabbedDocument tp in manager.Documents ) //{ // if ( !IsSpecialTab( tp ) ) // { // if ( tp.Tag == file ) // manager.ActiveDocument = tp; // } //} }
/// <summary> /// Closes a code tab without saving /// </summary> /// <param name="file"></param> public void CloseCodeTab(OpenedFile file) { foreach (DockableWindow td in Manager.Documents) { if (IsSpecialTab(td)) continue; if (td.Tag == file) td.Close(); } }
public void DeleteFile(OpenedFile file) { DialogResult msgRes = Util.ShowQuestion( "Do you want to remove the physical File from the hard drive?\nYes: Remove both Project Reference and Physical File\nNo: Remove Project Reference and leave Physical File\nCancel: Cancel File Operation"); if (msgRes == DialogResult.Yes) { // Remove the TreeNode file.Node.Remove(); if (file.FullName != null) // Remove physical file File.Delete(file.FullName); // Remove the project reference if (file.Folder == null) // Remove from Project Project.Files.Remove(file); else // Remove from the parent folder file.Folder.Files.Remove(file); } else if (msgRes == DialogResult.No) { file.Node.Remove(); // Remove the project reference if (file.Folder == null) // Remove from Project Project.Files.Remove(file); else // Remove from the parent folder file.Folder.Files.Remove(file); } }
/// <summary> /// Renames an existing project file node to something else /// </summary> /// <param name="file">The file to rename</param> /// <param name="newName">The new name to give the file</param> public void RenameNode(OpenedFile file, string newName) { if (!IsProjectOpen()) return; foreach (TreeNode tn in TreeView.Nodes[0].Nodes) { if (!(tn.Tag is OpenedFile)) continue; if (tn.Tag == file) tn.Text = newName; } }