Exemplo n.º 1
0
        private void menu_open_dir_Click(object sender, RoutedEventArgs e)
        {
            //获取父路径
            string chooes = (lb.SelectedItem as MyListBoxItem).MyMessage;
            string parent;

            if (chooes.Substring(0, 5) == "所在路径:")
            {
                parent = chooes.Substring(5);
            }
            else
            {
                var reg   = new System.Text.RegularExpressions.Regex(@".*(?:\\)");
                var match = reg.Match(chooes, 5);
                parent = match.Value;
            }
            if (parent.Length > 3)
            {
                parent = parent + "\\";
            }

            //刷新关联的三控件
            CurrentPath      = parent;
            address_box.Text = CurrentPath;
            TVChangeByOther  = true;
            MyItemManager.GetTVItemFromPath(tv, parent, true);
            TVChangeByOther = false;
            MyItemManager.FlushLBByCurrentPath(lb, CurrentPath);
            address_box.IsReadOnly = false;//解锁输入框
        }
Exemplo n.º 2
0
        //listbox双击进入或打开事件
        private void lb_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            if (e.OriginalSource.GetType() != typeof(ScrollViewer) && e.RightButton != MouseButtonState.Pressed)
            {
                var    m        = (MyListBoxItem)lb.SelectedItem;
                string filename = m.MyText;

                //处理查找
                if (CurrentPath == "查找")
                {
                    menu_open_Click(sender, e);
                    return;
                }

                //处理当前路径+双击项
                if (CurrentPath == "")  //双击项为盘符
                {
                    CurrentPath = filename.Substring(filename.Length - 3, 2) + "\\";
                }
                else if (CurrentPath.Length < 4)             //当前路径为盘符,不加斜杠
                {
                    if (File.Exists(CurrentPath + filename)) //双击项为文件
                    {
                        System.Diagnostics.Process.Start(CurrentPath + filename);
                    }
                    else
                    {
                        Back_History.AddLast(CurrentPath); //记录进栈
                        CurrentPath += filename;           //双击项为目录
                    }
                }
                else  //当前路径不为盘符加斜杠
                {
                    if (File.Exists(CurrentPath + "\\" + filename))  //双击项为文件
                    {
                        System.Diagnostics.Process.Start(CurrentPath + "\\" + filename);
                        return;
                    }
                    else
                    {
                        Back_History.AddLast(CurrentPath); //记录进栈
                        CurrentPath += "\\" + filename;    //双击项为目录
                    }
                }
                //刷新listbox
                MyItemManager.FlushLBByCurrentPath(lb, CurrentPath);
                //刷新地址栏
                address_box.Text = CurrentPath;
                //使treeview选中项同步变化
                TVChangeByOther = true;
                MyItemManager.GetTVItemFromPath(tv, CurrentPath, true);
                TVChangeByOther = false;

                //清空前进
                if (Ahead_History.Count > 0)
                {
                    Ahead_History.Clear();
                }
            }
        }
Exemplo n.º 3
0
        private void menu_open_Click(object sender, RoutedEventArgs e)
        {
            //获取父路径
            var    lt     = (lb.SelectedItem as MyListBoxItem);
            string chooes = lt.MyMessage;
            string parent = chooes.Substring(5);

            if (chooes.Substring(0, 5) == "所在路径:")
            {
                parent = chooes.Substring(5);
                if (parent.Length > 3)
                {
                    parent = parent + "\\";
                }
                System.Diagnostics.Process.Start(parent + lt.MyText);
            }
            else
            {
                //刷新关联的三控件
                CurrentPath      = parent;
                address_box.Text = CurrentPath;
                TVChangeByOther  = true;
                MyItemManager.GetTVItemFromPath(tv, parent, true);
                TVChangeByOther = false;
                MyItemManager.FlushLBByCurrentPath(lb, CurrentPath);
                address_box.IsReadOnly = false;//解锁输入框
            }
        }
Exemplo n.º 4
0
        private void menu_creat_dirs_Click(object sender, RoutedEventArgs e)
        {
            string name = "新建文件夹";
            string parent;

            if (CurrentPath.Length < 4)
            {
                parent = CurrentPath;
            }
            else
            {
                parent = CurrentPath + "\\";
            }
            while (Directory.Exists(parent + name))
            {
                name += " 副本";
            }
            Directory.CreateDirectory(parent + name);
            MyItemManager.FlushLBByCurrentPath(lb, CurrentPath);

            //同步treeview显示
            MyTreeViewItem mytv = new MyTreeViewItem(name, MyIcons.folder);
            var            it   = MyItemManager.GetTVItemFromPath(tv, CurrentPath);

            tv.BeginInit();
            it.Items.Add(mytv);
            tv.EndInit();
        }
Exemplo n.º 5
0
 //后退按钮事件
 private void goback_bt_Click(object sender, RoutedEventArgs e)
 {
     if (Back_History.Count != 0)
     {
         if (address_box.IsReadOnly)
         {
             address_box.IsReadOnly = false;                        //解锁输入框
         }
         //获取历史记录并移出历史记录
         string his = Back_History.Last.Value;
         Back_History.RemoveLast();
         if (CurrentPath != "查找")
         {
             Ahead_History.AddLast(CurrentPath);//当前目录移入前进
         }
         CurrentPath      = his;
         address_box.Text = CurrentPath == "" ? "此电脑" : CurrentPath;
         //刷新tv
         TVChangeByOther = true;
         MyItemManager.GetTVItemFromPath(tv, his, true);
         TVChangeByOther = false;
         //刷新listbox
         MyItemManager.FlushLBByCurrentPath(lb, CurrentPath);
     }
 }
Exemplo n.º 6
0
        private void menu_delete_Click(object sender, RoutedEventArgs e)
        {
            try {
                var    item = lb.SelectedItem as MyListBoxItem;
                string name = item.MyText;
                string _fileinfo;
                if (CurrentPath.Length < 4)
                {
                    _fileinfo = CurrentPath + name;
                }
                else
                {
                    _fileinfo = CurrentPath + "\\" + name;
                }

                var dr = MessageBox.Show("您确认要删除吗?", "删除", MessageBoxButton.YesNo);
                if (dr == MessageBoxResult.No)
                {
                    return;
                }

                if (File.Exists(_fileinfo))
                {
                    File.Delete(_fileinfo);
                    MyItemManager.FlushLBByCurrentPath(lb, CurrentPath);
                }
                else if (Directory.Exists(_fileinfo))
                {
                    //同步treeview显示
                    var it = MyItemManager.GetTVItemFromPath(tv, _fileinfo);
                    tv.BeginInit();
                    (it.Parent as MyTreeViewItem).Items.Remove(it);
                    tv.EndInit();

                    Directory.Delete(_fileinfo, true);
                    MyItemManager.FlushLBByCurrentPath(lb, CurrentPath);
                }
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message, "致命错误");
            }
        }
Exemplo n.º 7
0
 //前进按钮事件
 private void goahead_bt_Click(object sender, RoutedEventArgs e)
 {
     if (Ahead_History.Count != 0)
     {
         if (address_box.IsReadOnly)
         {
             address_box.IsReadOnly = false;                        //解锁输入框
         }
         //当前目录移入历史记录
         Back_History.AddLast(CurrentPath);
         //获取前进并移出
         string go = Ahead_History.Last.Value;
         Ahead_History.RemoveLast();
         //刷新tv
         TVChangeByOther = true;
         MyItemManager.GetTVItemFromPath(tv, go, true);
         TVChangeByOther = false;
         //刷新listbox
         CurrentPath      = go;
         address_box.Text = CurrentPath == "" ? "此电脑" : CurrentPath;
         MyItemManager.FlushLBByCurrentPath(lb, CurrentPath);
     }
 }