Exemplo n.º 1
0
        private ExplorerNode CreateNewFolder()
        {
            if (SelectedNode == null)
            {
                return(null);
            }

            ExplorerNode node = SelectedNode;

            if (node != null && node.ExplorerType != ExplorerType.Folder)
            {
                node = node.Parent;
            }

            // return to default
            if (node == null)
            {
                node = this;
            }

            if (node.Children.Count == 1 && node.Children[0].ExplorerType == ExplorerType.Dummy)
            {
                node.Expand();
            }

            //Debug.WriteLine(Path);

            string s = node.Path;
            int    i = 1;

            do
            {
                s = node.Path + "\\" + Properties.Resources.memo_foldername_prefix
                    + i.ToString();
                if (!Directory.Exists(s))
                {
                    break;
                }
                i++;
            } while (true);

            Directory.CreateDirectory(s);

            ExplorerNode childnode = new ExplorerNode
            {
                Name         = s.Substring(s.LastIndexOf("\\") + 1),
                Path         = s,
                ExplorerType = ExplorerType.Folder,
                Children     = new ObservableCollection <ExplorerNode> {
                    dummyExplorerNode
                },
                Parent = node,
            };

            node.Children.Add(childnode);

            Messenger.Default.Send(new CustomMessage(
                                       CustomMessage.MessageType.CREATED_NEW_FOLDER, childnode.Name, childnode.Path, childnode));

            // Selecting
            node.IsExpanded      = true;
            childnode.IsSelected = true;

            return(childnode);
        }
Exemplo n.º 2
0
        private ExplorerNode CreateNew(string filename = null)
        {
            Debug.WriteLine("CreateNew");

            if (SelectedNode == null)
            {
                return(null);
            }

            ExplorerNode node = SelectedNode;

            if (node != null && node.ExplorerType != ExplorerType.Folder)
            {
                node = node.Parent;
            }

            // return to default
            if (node == null)
            {
                node = this;
            }

            if (node.Children.Count == 1 && node.Children[0].ExplorerType == ExplorerType.Dummy)
            {
                node.Expand();
            }

            string s = node.Path;

            if (filename != null)
            {
                s = node.Path + "\\" + filename;
            }
            else
            {
                int i = 1;
                do
                {
                    s = node.Path + "\\" + Properties.Resources.memo_filename_prefix + i.ToString() + "." + FILE_EXTENSION1;
                    if (!File.Exists(s))
                    {
                        break;
                    }
                    i++;
                } while (true);
            }

            System.IO.File.WriteAllText(s, "");

            string descfile = Properties.Resources.str_folder_desc + "." + ExplorerNode.FILE_EXTENSION1;

            if (descfile != filename)
            {
                ExplorerNode childnode = new ExplorerNode
                {
                    Name         = s.Substring(s.LastIndexOf("\\") + 1),
                    Path         = s,
                    ExplorerType = ExplorerType.File,
                    Parent       = node,
                };

                node.Children.Add(childnode);

                Messenger.Default.Send(new CustomMessage(
                                           CustomMessage.MessageType.CREATED_NEW, childnode.Name, childnode.Path, childnode));

                childnode.IsSelected = true;

                // Selecting node
                node.IsExpanded = true;

                return(childnode);
            }
            else
            {
                // Selecting node
                node.IsExpanded = true;

                return(null);
            }
        }