private void createFile(string fullPath) { var sr = File.CreateText(fullPath); sr.Close(); CodeEditorWrapper.NewDocument(fullPath); }
private void _AfterSelect(object sender, TreeViewEventArgs e) { if (CodeEditorWrapper == null) { return; } if (CodeEditorWrapper.ContainsDocument(SelectedNode.FullPath)) { if (CodeEditorWrapper.CurrentFileName != SelectedNode.FullPath) { CodeEditorWrapper.SwitchTab(SelectedNode.FullPath); //CodeEditorWrapper.CurrentFileName = this.SelectedNode.FullPath; //CodeEditorWrapper.SwitchDocument(this.SelectedNode.FullPath); } } else if (File.Exists(SelectedNode.FullPath)) { CodeEditorWrapper.NewDocument(SelectedNode.FullPath); } }
public DirectoryTree() { InitializeComponent(); AfterSelect += _AfterSelect; ContextMenu = new ContextMenu(new[] { new MenuItem(Strings.DirectoryTree_DirectoryTree_New_file, (o, e) => { var attr = File.GetAttributes(ctxNode.FullPath); var newNode = attr.HasFlag(FileAttributes.Directory) ? ctxNode.Nodes.Add(Strings.DirectoryTree_DirectoryTree_New_file + " " + id) : ctxNode.Parent.Nodes.Add(Strings.DirectoryTree_DirectoryTree_New_file + " " + id); id++; LabelEdit = true; if (!newNode.IsEditing) { newNode.BeginEdit(); } //CodeEditorWrapper?.NewDocument(); //RefreshDisplay(); //_buttonClicked = ButtonClick.New; }), new MenuItem(Strings.DirectoryTree_DirectoryTree_Rename_file, (o, e) => { //oldPath = ctxNode.FullPath; if (ctxNode == TopNode) { return; } LabelEdit = true; if (!ctxNode.IsEditing) { ctxNode.BeginEdit(); //ctxNode.EndEdit(true); /* if (oldPath != ctxNode.FullPath) * { * System.IO.File.Move(oldPath, ctxNode.FullPath); * CodeEditorWrapper?.RenameDocument(oldPath, ctxNode.FullPath); * }*/ //RefreshDisplay(); //_buttonClicked = ButtonClick.Rename; } }), new MenuItem(Strings.DirectoryTree_DirectoryTree_Delete_file, (o, e) => { if (ctxNode == TopNode) { return; } CodeEditorWrapper?.RemoveTab(ctxNode.FullPath); File.Delete(ctxNode.FullPath); Nodes.Remove(ctxNode); SelectedNode = TopNode; //RefreshDisplay(); //_buttonClicked = ButtonClick.Delete; }) }); NodeMouseClick += DirectoryTree_NodeMouseDoubleClick; //NodeMouseDoubleClick += DirectoryTree_NodeMouseDoubleClick; AfterLabelEdit += treeView1_AfterLabelEdit; }
private void treeView1_AfterLabelEdit(object sender, NodeLabelEditEventArgs e) { if (CodeEditorWrapper == null) { return; } //MessageBox.Show(e.Label); //MessageBox.Show(e.Node.Text); if (e.Label == null && !File.Exists(e.Node.FullPath)) // there was no change in default name and file does not yet exists - we need to create a new one { createFile(e.Node.FullPath); e.Node.EndEdit(false); return; } if (e.Label == null) //no changes to already existing file's name - do nothing { return; } if (e.Label.Length > 0) { if (e.Label.IndexOfAny(new[] { '/', '\\', ':', '*', '<', '>', '|', '?', '"' }) == -1) { // Stop editing without canceling the label change. if (e.Node.Text != e.Label) { var oldPath = e.Node.FullPath; e.Node.Text = e.Label; if (oldPath != e.Node.FullPath || !File.Exists(oldPath)) { File.Delete(e.Node.FullPath); //if(File.Exists(oldPath)) var containsDocument = CodeEditorWrapper.ContainsDocument(oldPath); if (containsDocument) { File.Move(oldPath, e.Node.FullPath); CodeEditorWrapper?.RenameDocument(oldPath, e.Node.FullPath); } else { createFile(e.Node.FullPath); } } } e.Node.EndEdit(false); } else { // Cancel the label edit action, inform the user, and // place the node in edit mode again. e.CancelEdit = true; MessageBox.Show(Strings.DirectoryTree_treeView1_AfterLabelEdit_ + Strings.DirectoryTree_treeView1_AfterLabelEdit_The_invalid_characters, Strings.DirectoryTree_treeView1_AfterLabelEdit_Node_Label_Edit); e.Node.BeginEdit(); } } else { /* Cancel the label edit action, inform the user, and * place the node in edit mode again. */ e.CancelEdit = true; MessageBox.Show( Strings.DirectoryTree_treeView1_AfterLabelEdit_ + Strings.DirectoryTree_treeView1_AfterLabelEdit_The_label_cannot_be_blank , Strings.DirectoryTree_treeView1_AfterLabelEdit_Node_Label_Edit); e.Node.BeginEdit(); } }