Ejemplo n.º 1
0
        public static string GetDescFileName(ExplorerNode node)
        {
            string filename = null;

            if (node != null)
            {
                if (node.ExplorerType == ExplorerType.Folder)
                {
                    string dirname = node.Path + "\\";
                    string file1   = Properties.Resources.str_folder_desc + "." + ExplorerNode.FILE_EXTENSION1;
                    string file2   = Properties.Resources.str_folder_desc + "." + ExplorerNode.FILE_EXTENSION2;

                    if (System.IO.File.Exists(dirname + file1))
                    {
                        filename = file1;
                    }
                    else if (System.IO.File.Exists(dirname + file2))
                    {
                        filename = file2;
                    }
                }
            }

            return(filename);
        }
Ejemplo n.º 2
0
        private void DeleteFileOrFolder()
        {
            if (SelectedNode == null)
            {
                return;
            }

            var node = SelectedNode;

            if (node != null)
            {
                try
                {
                    if (node.ExplorerType == ExplorerType.Folder)
                    {
                        // delete desc file
                        string descfilepath       = node.Path + "\\" + GetDescFileName(node);
                        Collection <string> files = new Collection <string>();
                        foreach (string s in Directory.GetFiles(node.Path))
                        {
                            files.Add(s);
                        }
                        if (files.Count == 1 && files[0] == descfilepath)
                        {
                            try
                            {
                                File.Delete(descfilepath);
                            }
                            catch (IOException e) {
                                MainViewModel.MessageBoxShow(e.Message);
                            }
                        }

                        // delete folder
                        Directory.Delete(node.Path);
                    }
                    else if (node.ExplorerType == ExplorerType.File)
                    {
                        File.Delete(node.Path);
                    }
                }
                catch (IOException e) {
                    MainViewModel.MessageBoxShow(e.Message);
                    return;
                }

                if (node.Parent != null)
                {
                    ExplorerNode parent = node.Parent;
                    parent.Children.Remove(node);
                    parent.IsSelected = true;
                }

                node = null;
            }
        }
Ejemplo n.º 3
0
        private void _folderChange(string path)
        {
            Debug.WriteLine("_folderChange:" + path);

            if (System.IO.Directory.Exists(path))
            {
                if (FirstGeneration != null)
                {
                    FirstGeneration.Clear();
                }

                Messenger.Default.Send(new CustomMessage(
                                           CustomMessage.MessageType.TREEVIEW_DESTROYED));

                // FirstGeneration
                var firsts = new ObservableCollection <ExplorerNode>();
                var node   = new ExplorerNode(path);
                firsts.Add(node);
                FirstGeneration = firsts;
                node.IsExpanded = true;
                node.IsSelected = true;

                Messenger.Default.Send(new CustomMessage(
                                           CustomMessage.MessageType.FOLDER_CHANGED, path, null, null));

                // Save in Setting
                if (_userPrefs != null)
                {
                    _userPrefs.WorkingFolder = path;
                }
            }
            else
            {
                MessageBoxShow(Properties.Resources.msg_no_folder_exsits);
                return;
            }
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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);
            }
        }
Ejemplo n.º 6
0
        private void Expand()
        {
            string filter1 = "*." + FILE_EXTENSION1;
            string filter2 = "*." + FILE_EXTENSION2;

            if (ExplorerType != ExplorerType.Folder)
            {
                return;
            }

            ExplorerNode dummyExplorerNode = new ExplorerNode {
                ExplorerType = ExplorerType.Dummy
            };

            if (Children.Count == 1 && Children[0].ExplorerType == ExplorerType.Dummy)
            {
                Children.Clear();
                try
                {
                    foreach (string s in Directory.GetDirectories(Path))
                    {
                        string filename = s.Substring(s.LastIndexOf("\\") + 1);
                        string path     = s;

                        Children.Add(new ExplorerNode
                        {
                            Name         = filename,
                            Path         = path,
                            ExplorerType = ExplorerType.Folder,
                            Children     = new ObservableCollection <ExplorerNode> {
                                dummyExplorerNode
                            },
                            Parent = this,
                        });
                    }

                    List <ExplorerNode> _children = new List <ExplorerNode>();

                    foreach (string s in Directory.GetFiles(Path, filter1))
                    {
                        string filename = s.Substring(s.LastIndexOf("\\") + 1);
                        string path     = s;
                        string descfile = Properties.Resources.str_folder_desc + "." + ExplorerNode.FILE_EXTENSION1;

                        if (filename == descfile)
                        {
                            continue;
                        }

                        _children.Add(new ExplorerNode
                        {
                            Name         = filename,
                            Path         = path,
                            ExplorerType = ExplorerType.File,
                            Parent       = this,
                        });
                    }

                    foreach (string s in Directory.GetFiles(Path, filter2))
                    {
                        string filename = s.Substring(s.LastIndexOf("\\") + 1);
                        string path     = s;
                        string descfile = Properties.Resources.str_folder_desc + "." + ExplorerNode.FILE_EXTENSION2;

                        if (filename == descfile)
                        {
                            continue;
                        }

                        _children.Add(new ExplorerNode
                        {
                            Name         = filename,
                            Path         = path,
                            ExplorerType = ExplorerType.File,
                            Parent       = this,
                        });
                    }

                    _children.Sort(delegate(ExplorerNode t1, ExplorerNode t2)
                    {
                        return(t1.Name.CompareTo(t2.Name));
                    });

                    foreach (var item in _children)
                    {
                        Children.Add(item);
                    }
                }
                catch (Exception e) {
                    Debug.Write(e.ToString());
                }
            }
        }
Ejemplo n.º 7
0
        private void Expand()
        {
            string filter1 = "*." + FILE_EXTENSION1;
            string filter2 = "*." + FILE_EXTENSION2;

            if (ExplorerType != ExplorerType.Folder)
                return;

            ExplorerNode dummyExplorerNode = new ExplorerNode { ExplorerType = ExplorerType.Dummy };

            if (Children.Count == 1 && Children[0].ExplorerType == ExplorerType.Dummy)
            {
                Children.Clear();
                try
                {
                    foreach (string s in Directory.GetDirectories(Path))
                    {
                        string filename = s.Substring(s.LastIndexOf("\\") + 1);
                        string path = s;

                        Children.Add(new ExplorerNode
                                        {
                                            Name = filename,
                                            Path = path,
                                            ExplorerType = ExplorerType.Folder,
                                            Children = new ObservableCollection<ExplorerNode> { dummyExplorerNode },
                                            Parent = this,
                                        });
                    }

                    List<ExplorerNode> _children = new List<ExplorerNode>();

                    foreach (string s in Directory.GetFiles(Path, filter1))
                    {
                        string filename = s.Substring(s.LastIndexOf("\\") + 1);
                        string path = s;
                        string descfile = Properties.Resources.str_folder_desc + "." + ExplorerNode.FILE_EXTENSION1;

                        if (filename == descfile)
                            continue;

                        _children.Add(new ExplorerNode
                                        {
                                            Name = filename,
                                            Path = path,
                                            ExplorerType = ExplorerType.File,
                                            Parent = this,
                                        });
                    }

                    foreach (string s in Directory.GetFiles(Path, filter2))
                    {
                        string filename = s.Substring(s.LastIndexOf("\\") + 1);
                        string path = s;
                        string descfile = Properties.Resources.str_folder_desc + "." + ExplorerNode.FILE_EXTENSION2;

                        if (filename == descfile)
                            continue;

                        _children.Add(new ExplorerNode
                        {
                            Name = filename,
                            Path = path,
                            ExplorerType = ExplorerType.File,
                            Parent = this,
                        });
                    }

                    _children.Sort(delegate(ExplorerNode t1, ExplorerNode t2)
                    {
                        return t1.Name.CompareTo(t2.Name);
                    });

                    foreach (var item in _children)
                        Children.Add(item);
                }
                catch (Exception e) {
                    Debug.Write(e.ToString());
                }
            }
        }
Ejemplo n.º 8
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;
        }
Ejemplo n.º 9
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;
            }
        }
Ejemplo n.º 10
0
        public static string GetDescFileName(ExplorerNode node)
        {
            string filename = null;
            if (node != null)
            {
                if (node.ExplorerType == ExplorerType.Folder)
                {
                    string dirname = node.Path + "\\";
                    string file1 = Properties.Resources.str_folder_desc + "." + ExplorerNode.FILE_EXTENSION1;
                    string file2 = Properties.Resources.str_folder_desc + "." + ExplorerNode.FILE_EXTENSION2;

                    if (System.IO.File.Exists(dirname + file1))
                    {
                        filename = file1;
                    }
                    else if (System.IO.File.Exists(dirname + file2))
                    {
                        filename = file2;
                    }
                }

            }

            return filename;
        }
Ejemplo n.º 11
0
        private void _initializeMessenger()
        {
            Messenger.Default.Register<CustomMessage>(this, (msg) =>
            {
                // Works with the Person object.
                CustomMessage m = (CustomMessage)msg;
                Debug.WriteLine("MainViewModel.CustomMessage: " + m.msgtype);

                switch (m.msgtype)
                {
                    case CustomMessage.MessageType.RENAME_FILE:
                        break;

                    case CustomMessage.MessageType.SELECTED:
                        var node = (ExplorerNode)m.obj;

                        //Debug.WriteLine("EditText: " + EditText);
                        // saving old files
                        OnFileSave();

                        // load files
                        if (node != null)
                        {
                            _currentExplorerNode = node;
                            if (node.ExplorerType == ExplorerType.File)
                            {
                                FileOpen(node.Path);
                            }
                            else if(node.ExplorerType == ExplorerType.Folder)
                            {
                                string file = node.Path + "\\" + Properties.Resources.str_folder_desc + ".";
                                string file1 = file + ExplorerNode.FILE_EXTENSION1;
                                string file2 = file + ExplorerNode.FILE_EXTENSION2;
                                string folder_desc_file = Properties.Resources.str_folder_desc + "." + ExplorerNode.FILE_EXTENSION1;

                                EditTextInit();

                                if (System.IO.File.Exists(file1))
                                {
                                    FileOpen(file1);
                                }
                                else if (System.IO.File.Exists(file2))
                                {
                                    FileOpen(file2);
                                }
                                else
                                {
                                    OnFileNew(folder_desc_file);
                                }

                            }
                            else
                            {
                                EditTextInit();
                            }
                        }
                        else
                        {
                            EditTextInit();
                        }

                        // Title change
                        Title = Version.APP_NAME + " - " + node.Name;
                        break;

                    case CustomMessage.MessageType.CREATED_NEW:
                        break;

                    case CustomMessage.MessageType.CREATED_NEW_FOLDER:
                        break;

                    default:
                        break;
                }
            });
        }
Ejemplo n.º 12
0
        private void _folderChange(string path)
        {
            if (System.IO.Directory.Exists(path))
            {
                if (FirstGeneration != null)
                    FirstGeneration.Clear();

                Messenger.Default.Send(new CustomMessage(
                    CustomMessage.MessageType.TREEVIEW_DESTROYED));

                // FirstGeneration
                var firsts = new ObservableCollection<ExplorerNode>();
                var node = new ExplorerNode(path);
                firsts.Add(node);
                FirstGeneration = firsts;
                node.IsExpanded = true;
                node.IsSelected = true;

                Messenger.Default.Send(new CustomMessage(
                    CustomMessage.MessageType.FOLDER_CHANGED, path, null, null));

                // Save in Setting
                if (_userPrefs != null)
                    _userPrefs.WorkingFolder = path;
            }
            else
            {
                MessageBoxShow(Properties.Resources.msg_no_folder_exsits);
                return;
            }
        }
Ejemplo n.º 13
0
        private void OnFileSave()
        {
            Debug.WriteLine("OnFileSave");

            if (_textChanged && _currentExplorerNode != null)
            {
                Debug.WriteLine("File Save..");

                try
                {
                    Messenger.Default.Send(new CustomMessage(
                                               CustomMessage.MessageType.BEFORE_FILE_SAVE));

                    string text = "";
                    if (HtmlMode)
                    {
                        string html_header = "<!DOCTYPE html>\n" +
                                             "<head><meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\" /></head>\n" +
                                             "<body>\n";
                        if (EditHtml != null && EditHtml.IndexOf("<!DOCTYPE html") < 0)
                        {
                            text = html_header + EditHtml;
                        }
                        else
                        {
                            text = EditHtml;
                        }
                    }
                    else
                    {
                        text = EditText;
                    }

                    //Debug.WriteLine("Saving.." + text);

                    string descfile = ExplorerNode.GetDescFileName(_currentExplorerNode);
                    string path;
                    if (descfile != null)
                    {
                        if (_currentExplorerNode.ExplorerType == ExplorerType.Folder)
                        {
                            path = _currentExplorerNode.Path + "\\" + descfile;
                        }
                        else
                        {
                            path = System.IO.Path.GetDirectoryName(_currentExplorerNode.Path) + "\\" + descfile;
                        }
                    }
                    else
                    {
                        path = _currentExplorerNode.Path;
                    }

                    // all text
                    System.IO.File.WriteAllText(path, text);

                    // save last write time
                    _lastWriteTime = File.GetLastWriteTime(path);

                    // save old text
                    _editTextOld = text;

                    Messenger.Default.Send(new CustomMessage(
                                               CustomMessage.MessageType.AFTER_FILE_SAVE));
                }
                catch (System.IO.IOException e)
                {
                    MessageBoxShow(e.Message);
                    return;
                }
            }

            _textChanged = false;
        }
Ejemplo n.º 14
0
        private void _initializeMessenger()
        {
            Messenger.Default.Register <CustomMessage>(this, (msg) =>
            {
                // Works with the Person object.
                CustomMessage m = (CustomMessage)msg;
                Debug.WriteLine("MainViewModel.CustomMessage: " + m.msgtype);

                switch (m.msgtype)
                {
                case CustomMessage.MessageType.RENAME_FILE:
                    break;

                case CustomMessage.MessageType.SELECTED:
                    var node = (ExplorerNode)m.obj;

                    //Debug.WriteLine("EditText: " + EditText);
                    // saving old files
                    OnFileSave();

                    // load files
                    if (node != null)
                    {
                        _currentExplorerNode = node;
                        if (node.ExplorerType == ExplorerType.File)
                        {
                            FileOpen(node.Path);
                        }
                        else if (node.ExplorerType == ExplorerType.Folder)
                        {
                            string file             = node.Path + "\\" + Properties.Resources.str_folder_desc + ".";
                            string file1            = file + ExplorerNode.FILE_EXTENSION1;
                            string file2            = file + ExplorerNode.FILE_EXTENSION2;
                            string folder_desc_file = Properties.Resources.str_folder_desc + "." + ExplorerNode.FILE_EXTENSION1;

                            _editTextInit();

                            if (System.IO.File.Exists(file1))
                            {
                                FileOpen(file1);
                            }
                            else if (System.IO.File.Exists(file2))
                            {
                                FileOpen(file2);
                            }
                            else
                            {
                                OnFileNew(folder_desc_file);
                            }
                        }
                        else
                        {
                            _editTextInit();
                        }
                    }
                    else
                    {
                        _editTextInit();
                    }

                    // Title change
                    Title = Version.APP_NAME + " - " + node.Name;
                    break;

                case CustomMessage.MessageType.CREATED_NEW:
                    break;

                case CustomMessage.MessageType.CREATED_NEW_FOLDER:
                    break;

                default:
                    break;
                }
            });
        }