Ejemplo n.º 1
0
        public override DockablePanel OpenView(Model Model)
        {
            var r = new TextDocumentEditor(
                this,
                OpenEditors.Count != 0 ? (OpenEditors[0] as TextDocumentEditor).GetScintillaDocument() : (ScintillaNET.Document?)null,
                Model.SpellChecker, Model.Thesaurus);

            r.CustomizeContextMenu = (menu) =>
            {
                var item = menu.MenuItems.Add("Cut to new document");
                item.Click += (sender, args) =>
                {
                    var createCommand = new Commands.CreateNewDocument(System.IO.Path.GetDirectoryName(Path), "txt");
                    r.InvokeCommand(createCommand);
                    if (!createCommand.Succeeded)
                    {
                        System.Windows.Forms.MessageBox.Show("Failed to create new file.");
                        return;
                    }

                    var prose = r.textEditor.SelectedText;
                    System.IO.File.WriteAllText(createCommand.FullPath, prose);
                    r.textEditor.ReplaceSelection("");

                    MadeChanges();
                };
            };
            OpenEditors.Add(r);
            return(r);
        }
Ejemplo n.º 2
0
        private void NewFileMenuItemHandler(object sender, EventArgs e)
        {
            Commands.CreateNewDocument createCommand = null;
            TreeNode newNode = null;

            if (ContextNode != null)
            {
                var tag     = ContextNode.Tag as NodeTag;
                var dirPath = tag.Path;
                if (tag.NodeType == NodeTag.Type.File)
                {
                    dirPath = System.IO.Path.GetDirectoryName(dirPath);
                }
                createCommand = new Commands.CreateNewDocument(dirPath, "txt");
                InvokeCommand(createCommand);
                UpdateNode(ContextNode);
                foreach (TreeNode node in ContextNode.Nodes)
                {
                    if ((node.Tag as NodeTag).Path == dirPath + "\\" + createCommand.NewFileName)
                    {
                        newNode = node;
                    }
                }
            }
            else
            {
                createCommand = new Commands.CreateNewDocument(Project.Path, "txt");
                InvokeCommand(createCommand);
                UpdateNode(null);
                foreach (TreeNode node in treeView.Nodes)
                {
                    if ((node.Tag as NodeTag).Path == Project.Path + "\\" + createCommand.NewFileName)
                    {
                        newNode = node;
                    }
                }
            }

            newNode.EnsureVisible();
            treeView.SelectedNode = newNode;
            newNode.BeginEdit();
        }
Ejemplo n.º 3
0
        private void newFileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Commands.CreateNewDocument createCommand = null;
            TreeNode newNode = null;

            if (ContextNode != null)
            {
                var tag = ContextNode.Tag as NodeTag;
                createCommand = new Commands.CreateNewDocument(tag.Path);
                ControllerCommand(createCommand);
                UpdateNode(ContextNode);
                foreach (TreeNode node in ContextNode.Nodes)
                {
                    if ((node.Tag as NodeTag).Path == tag.Path + "\\" + createCommand.NewFileName)
                    {
                        newNode = node;
                    }
                }
            }
            else
            {
                createCommand = new Commands.CreateNewDocument(System.IO.Path.GetDirectoryName(Project.Path));
                ControllerCommand(createCommand);
                UpdateNode(null);
                foreach (TreeNode node in treeView.Nodes)
                {
                    if ((node.Tag as NodeTag).Path == System.IO.Path.GetDirectoryName(Project.Path) + "\\" + createCommand.NewFileName)
                    {
                        newNode = node;
                    }
                }
            }

            newNode.EnsureVisible();
            treeView.SelectedNode = newNode;
            newNode.BeginEdit();
        }