Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        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();
            }
        }