예제 #1
0
        /**
         * When the user hits the new doc button, it asks for the name and then
         * saves it to the storage.
         */
        private void createDocumentButton_Click(object sender, EventArgs e)
        {
            try
            {
                // Make sure a destination is selected
                if (treeView.SelectedNode == null)
                {
                    MessageBox.Show("Please select destination of new document");
                }
                else
                {
                    InputDialog inputDialog = new InputDialog("Input name of new Document");
                    inputDialog.ShowDialog();

                    if (!inputDialog.Canceled)
                    {
                        string   title  = inputDialog.Input;
                        Document newDoc = new Document("", title, activeUser);

                        // Create a path for the document
                        string path = treeView.SelectedNode.FullPath;
                        if (selectedFolder.FileType == DocType.Project)
                        {
                            path = "";
                        }
                        else if (isDocument)
                        {
                            path = path.Substring(
                                selectedProject.ToString().Count() + 1,
                                path.Count() - selectedDocument.Title.Count() - selectedProject.ToString().Count() - 2);
                        }
                        else
                        {
                            path = path.Substring(selectedProject.ToString().Count() + 1);
                        }



                        path = Regex.Replace(path, @"\\", "/");

                        Controller.CreateDocument(activeUser, path, selectedProject, title);

                        RefreshTreeView();
                    }
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Sorry, something went wrong trying to contact the server.");
            }
        }
예제 #2
0
        private void createFolderButton_Click(object sender, EventArgs e)
        {
            // Make sure a destination is selected
            if (treeView.SelectedNode == null)
            {
                MessageBox.Show("Please select destination of new folder");
            }
            else
            {
                InputDialog inputDialog = new InputDialog("What should your new folder be called?", "name");
                inputDialog.ShowDialog();
                if (!inputDialog.Canceled)
                {
                    if (!CheckName(inputDialog.Input))
                    {
                        return;
                    }

                    string path;
                    // If the project root itself is selected, just discard the whole path
                    if (selectedFolder.FileType == DocType.Project)
                    {
                        path = inputDialog.Input;
                    }
                    else
                    {
                        path = treeView.SelectedNode.FullPath;
                        path = path.Substring(selectedProject.ToString().Count() + 1);

                        if (isDocument)
                        {
                            path = path.Substring(0, path.Count() - selectedDocument.Title.Count() - 1);
                        }

                        path = Regex.Replace(path, @"\\", "/");

                        path += "/" + inputDialog.Input;
                    }

                    Controller.CreateDocument(activeUser, path, selectedProject, "Welcome to your new folder!");
                }
                RefreshTreeView();
            }
        }