예제 #1
0
 void SetImg(Border border, AppLink link)
 {
     border.ToolTip = link.Name + "\r\n" + link.FileName;
     border.Tag = link;
     var label = border.Child as Label;
     label.ToolTip = border.ToolTip;
     label.Tag = link;
     var image = label.Content as Image;
     image.ToolTip = border.ToolTip;
     if (link.IsRelative)
     {
         image.Source = Helper.Global.GetIcon(Helper.Global.AppPath + link.FileName);
     }
     else
     {
         image.Source = Helper.Global.GetIcon(link.FileName);
     }
     image.Tag = link;
 }
예제 #2
0
        /// <summary>
        /// 添加快捷方式,操作
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_AddFileLink_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(txt_LinkName.Text)) { txt_LinkName.Focus(); return; }
                if (string.IsNullOrWhiteSpace(txt_LinkFileName.Text)) { txt_LinkFileName.Focus(); return; }
                var only = Helper.Global.AppLinks.FirstOrDefault(m => m.Name.ToUpper() == txt_LinkName.Text.ToUpper());
                if (only != null)
                {
                    txt_LinkName.Text = "";
                    TextBoxHelper.SetWatermark(txt_LinkName, "名称已存在!");
                    return;
                }
                var isrel = false;
                var filename = System.IO.Path.GetFullPath(txt_LinkFileName.Text);
                if (filename.StartsWith(AppDomain.CurrentDomain.BaseDirectory))
                {
                    isrel = true;
                    filename = filename.Replace(AppDomain.CurrentDomain.BaseDirectory, "");
                }

                var subc = btn_AddFileLink.Tag as RootCategory;
                var link = new AppLink() { ID = Guid.NewGuid(), Name = txt_LinkName.Text, FileName = txt_LinkFileName.Text, Args = txt_Args.Text, IsRelative = isrel, Tags = txt_Tags.Text, SortNum = (int)nud_Sort.Value, PID = subc.ID, Extension = System.IO.Path.GetExtension(txt_LinkFileName.Text) };

                Helper.Global.AppLinks.Add(link);
                Helper.Global.SaveAppLinks();

                var wrapPanel = this.tabMain.FindChild<Expander>(Helper.Global.EncodeCtrlName(subc.ID.ToString())).Content as ListBox;

                wrapPanel.Items.Clear();
                foreach (var l in Helper.Global.AppLinks.FindAll(m => m.PID == link.PID).OrderBy(m => m.SortNum))
                {
                    wrapPanel.Items.Add(GetImg(l));
                }

                Flyout_AddFileLink.IsOpen = false;
                txt_LinkName.Text = "";
                txt_LinkFileName.Text = "";
                btn_AddFileLink.Tag = null;
                txt_Args.Text = "";
                chb_IsRelative.IsChecked = true;
                txt_Tags.Text = "";
                nud_Sort.Value = 1;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message+"\r\n"+ex.StackTrace);
            }
        }
예제 #3
0
        private void btn_Import_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var p_cate = btn_Import.Tag as RootCategory;
                var dir = new System.IO.DirectoryInfo(System.IO.Path.Combine(Helper.Global.AppBagName, txt_Import.Text));
                if (dir.Exists)
                {
                    var wrapPanel = this.tabMain.FindChild<Expander>(Helper.Global.EncodeCtrlName(p_cate.ID.ToString())).Content as ListBox;
                    var filters = txt_Filter.Text.Split(new string[] { "|",";",","},  StringSplitOptions.RemoveEmptyEntries);

                    List<System.IO.FileInfo> filelist = new List<System.IO.FileInfo>();
                    foreach (var flt in filters)
                    {
                        filelist.AddRange(dir.GetFiles(flt, System.IO.SearchOption.AllDirectories));
                    }
                    if (filelist.Count == 0) { filelist.AddRange(dir.GetFiles("*.exe", System.IO.SearchOption.AllDirectories)); }
                    foreach (var file in filelist)
                    {
                        var isrel = false;
                        var filename = file.FullName;
                        if (filename.StartsWith(AppDomain.CurrentDomain.BaseDirectory))
                        {
                            isrel = true;
                            filename = filename.Replace(AppDomain.CurrentDomain.BaseDirectory, "");
                        }

                        var link = new AppLink() { ID = Guid.NewGuid(), IsRelative = isrel, SortNum = 99, Name = System.IO.Path.GetFileNameWithoutExtension(file.FullName), Tags = System.IO.Path.GetFileName(file.FullName), FileName = filename, PID = p_cate.ID, Extension = file.Extension };
                        var only = Helper.Global.AppLinks.FirstOrDefault(m => m.Name.ToUpper() == link.Name.ToUpper());
                        if (only == null)
                        {
                            Helper.Global.AppLinks.Add(link);
                            wrapPanel.Items.Add(GetImg(link));
                        }
                    }
                    Helper.Global.SaveAppLinks();
                    Flyout_Import.IsOpen = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message+"\r\n"+ex.StackTrace);
            }
        }
예제 #4
0
        /// <summary>
        /// 生成打包好的图片对象
        /// </summary>
        /// <param name="link"></param>
        /// <returns></returns>
        Border GetImg(AppLink link)
        {
            try
            {
                var border = new Border() { Name = Helper.Global.EncodeCtrlName(link.ID.ToString()), ToolTip = link.Name + "\r\n" + link.FileName, Tag = link, ContextMenu = SubCMenu_App };
                border.Style = (link.IsRelative) ? (Style)this.FindResource("LinkBorder") : (Style)this.FindResource("LinkBorder2");
                var label = new Label() { Width = 64, Height = 64, Style = (Style)this.FindResource("LinkLabel"), HorizontalContentAlignment = System.Windows.HorizontalAlignment.Center, VerticalContentAlignment = System.Windows.VerticalAlignment.Center, ToolTip = border.ToolTip, Tag = link };

                var image = new Image()
                {
                    ToolTip = border.ToolTip,
                    Width = 32,
                    Height = 32,
                };
                image.Effect = new System.Windows.Media.Effects.DropShadowEffect() { ShadowDepth=2, BlurRadius=2, Opacity=0.8 };

                if (link.IsRelative)
                {
                    var path = Helper.Global.AppPath + link.FileName;
                    if (System.IO.File.Exists(path))
                    {
                        image.Source = Helper.Global.GetIcon(path);
                    }
                    else if (System.IO.Directory.Exists(path))
                    {
                        image.Source = new BitmapImage(new Uri("Res/folder.png", UriKind.Relative));
                    }

                }
                else
                {
                    var path = link.FileName;
                    if (System.IO.File.Exists(path))
                    {
                        image.Source = Helper.Global.GetIcon(path);
                    }
                    else if (System.IO.Directory.Exists(path))
                    {
                        image.Source = new BitmapImage(new Uri("Res/folder.png", UriKind.Relative));
                    }
                }
                image.Tag = link;
                //image.MouseLeftButtonUp += image_MouseLeftButtonDown;
                label.MouseLeftButtonUp += image_MouseLeftButtonDown;
                label.Content = image;
                border.Child = label;
                return border;
            }
            catch (Exception ex)
            {
                return new Border();
            }
        }
예제 #5
0
        void wrapPanel_Drop(object sender, DragEventArgs e)
        {
            //仅支持文件的拖放
            if (!e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                return;
            }

            var listbox = sender as ListBox;

            var exp = listbox.Parent as Expander;
            if (exp == null) { MessageBox.Show("找不到节点"); return; }
            var subc = exp.Tag as RootCategory;
            if (subc == null) { MessageBox.Show("找不到节点信息"); return; }

            //获取拖拽的文件
            string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);

            //这里需要注意,由于程序既支持拖过来也支持拖过去,那么ListBox就也能接收自身拖拽过来的文件
            //为了防止鼠标点击和拖拽的冲突,需要屏蔽从程序自身拖拽过来的文件
            //这里判断文件是否从程序外部拖拽进来,也就是判断图片是否在工作目录下
            //if (files.Length > 0 && !files[0].StartsWith(path) &&
            //    (e.AllowedEffects & DragDropEffects.Copy) == DragDropEffects.Copy)
            //{
            //    e.Effects = DragDropEffects.Copy;
            //}
            //else
            //{
            //    e.Effects = DragDropEffects.None;
            //}

            //List<string> allfile = new List<string>();
            foreach (var file in files)
            {
                if (System.IO.File.Exists(file))
                {
                    // 是文件
                    var file_ext = System.IO.Path.GetExtension(file);
                    //if (file_ext.ToLower() == ".exe")
                    {
                        var isrel = false;
                        var filename = file;
                        if (file.StartsWith(AppDomain.CurrentDomain.BaseDirectory))
                        {
                            isrel = true;
                            filename = file.Replace(AppDomain.CurrentDomain.BaseDirectory, "");
                        }
                        var link = new AppLink() { ID = Guid.NewGuid(), IsRelative = isrel, SortNum = 99, Name = System.IO.Path.GetFileNameWithoutExtension(file), Tags = System.IO.Path.GetFileName(file), FileName = filename, PID = subc.ID, Extension = file_ext };

                        if (Helper.Global.AppLinks.FirstOrDefault(m => m.Name == link.Name) == null)
                        {
                            Helper.Global.AppLinks.Add(link);
                            listbox.Items.Add(GetImg(link));
                        }
                        //allfile.Add(file);
                    }
                }
                else if (System.IO.Directory.Exists(file))
                {
                    // 是文件夹
                    var file_ext = System.IO.Path.GetExtension(file);
                    var isrel = false;
                    var filename = file;
                    if (file.StartsWith(AppDomain.CurrentDomain.BaseDirectory))
                    {
                        isrel = true;
                        filename = file.Replace(AppDomain.CurrentDomain.BaseDirectory, "");
                    }
                    var link = new AppLink() { ID = Guid.NewGuid(), IsRelative = isrel, SortNum = 99, Name = System.IO.Path.GetFileNameWithoutExtension(file), Tags = System.IO.Path.GetFileName(file), FileName = filename, PID = subc.ID, Extension = file_ext };

                    if (Helper.Global.AppLinks.FirstOrDefault(m => m.Name == link.Name) == null)
                    {
                        Helper.Global.AppLinks.Add(link);
                        listbox.Items.Add(GetImg(link));
                    }
                    //var fs = System.IO.Directory.GetFiles(file, "*.exe", System.IO.SearchOption.AllDirectories);
                    //if (fs.Length > 0)
                    //{
                    //    foreach (var f in fs)
                    //    {
                    //        var isrel = false;
                    //        var filename = file;
                    //        if (file.StartsWith(AppDomain.CurrentDomain.BaseDirectory))
                    //        {
                    //            isrel = true;
                    //            filename = file.Replace(AppDomain.CurrentDomain.BaseDirectory, "");
                    //        }
                    //        var link = new AppLink() { ID = Guid.NewGuid(), IsRelative = isrel, SortNum = 99, Name = System.IO.Path.GetFileNameWithoutExtension(file), Tags = System.IO.Path.GetFileName(file), FileName = filename, PID = subc.ID, Extension = ".exe" };

                    //        if (Helper.Global.AppLinks.FirstOrDefault(m => m.Name == link.Name) == null)
                    //        {
                    //            Helper.Global.AppLinks.Add(link);
                    //            listbox.Items.Add(GetImg(link));
                    //        }
                    //    }
                    //    //allfile.AddRange(fs);
                    //}
                }
            }
            Helper.Global.SaveAppLinks();
        }