/// <summary> /// 初始化每个面板的快捷方式信息 /// </summary> private List <ItemInfo> ReadData() { try { List <ItemInfo> allItem = new List <ItemInfo>(); for (int i = 1; i <= PageCount; i++) { List <ItemInfo> itemList = i.GetData(); allItem.AddRange(itemList); foreach (var info in itemList) { var ic = new ItemControl(info.ItemPath, info.ItemName, i, info.ItemIndex); ((PanelControl)this.maingrid.Children[i - 1]).wrapPanel1.Children.Insert(ic.OverallIndex, ic); ic.del += new DelItem(DelItem); ic.movePage += new MoveItemPage(MoveItemOnPage); } } return(allItem); } catch (Exception ee) { MyWork.NoteLog(ee); return(null); } }
///// <summary> ///// 前后移动项目 ///// </summary> ///// <param name="page">所在页面</param> ///// <param name="index">索引</param> ///// <param name="direction">移动方向,true为向前,false为向后</param> //private void MoveItemOnIndex(int page, int index, bool direction) //{ // if (direction && index != 0) // { // ItemControl temp = ((maingrid.Children[page - 1] as PanelControl).wrapPanel1.Children[index - 1]) as ItemControl; // (maingrid.Children[page - 1] as PanelControl).wrapPanel1.Children.RemoveAt(index - 1); // (maingrid.Children[page - 1] as PanelControl).wrapPanel1.Children.Insert(index, temp); // temp.OverallIndex += 1; // (((maingrid.Children[page - 1] as PanelControl).wrapPanel1.Children[index - 1]) as ItemControl).OverallIndex -= 1; // Dal.ChangeIndex((((maingrid.Children[page - 1] as PanelControl).wrapPanel1.Children[index - 1]) as ItemControl).ItemPath, index - 1); // Dal.ChangeIndex((((maingrid.Children[page - 1] as PanelControl).wrapPanel1.Children[index]) as ItemControl).ItemPath, index); // } // if (!direction && index != (maingrid.Children[page - 1] as PanelControl).wrapPanel1.Children.Count - 1) // { // ItemControl temp = ((maingrid.Children[page - 1] as PanelControl).wrapPanel1.Children[index]) as ItemControl; // (maingrid.Children[page - 1] as PanelControl).wrapPanel1.Children.RemoveAt(index); // (maingrid.Children[page - 1] as PanelControl).wrapPanel1.Children.Insert(index + 1, temp); // temp.OverallIndex += 1; // (((maingrid.Children[page - 1] as PanelControl).wrapPanel1.Children[index]) as ItemControl).OverallIndex = index; // Dal.ChangeIndex((((maingrid.Children[page - 1] as PanelControl).wrapPanel1.Children[index + 1]) as ItemControl).ItemPath, index + 1); // Dal.ChangeIndex((((maingrid.Children[page - 1] as PanelControl).wrapPanel1.Children[index]) as ItemControl).ItemPath, index); // } //} #endregion /// <summary> /// 移动项目到前(后)页 /// </summary> /// <param name="page">所在页面</param> /// <param name="index">索引</param> /// <param name="direction">移动方向,true为向前,false为向后</param> private void MoveItemOnPage(int page, int index, bool direction) { /////是否为此页最后一个 bool flag = (maingrid.Children[page - 1] as PanelControl).wrapPanel1.Children.Count - 1 == index ? true : false; if (!direction) { #region if (page == maingrid.Children.Count) { this.maingrid.Children.Add(new PanelControl((PageCount - CurrentPage + 1) * this.Width)); this.pagingGrid.Children.Add(new PageControl(false)); PageCount += 1; UpdatePageControl(PageCount); MoveItemOnPage(page, index, direction); } else { ItemControl temp = (maingrid.Children[page - 1] as PanelControl).wrapPanel1.Children[index] as ItemControl; (maingrid.Children[page - 1] as PanelControl).wrapPanel1.Children.RemoveAt(index); if ((maingrid.Children[page] as PanelControl).wrapPanel1.Children.Count == 20) { MoveItemOnPage(page + 1, 19, false);/////后一页的最后一个 } (maingrid.Children[page] as PanelControl).wrapPanel1.Children.Add(temp); temp.OverallIndex = (maingrid.Children[page] as PanelControl).wrapPanel1.Children.Count - 1; temp.PageIndex = page + 1; temp.Path.ChangeIndex(temp.PageIndex, temp.OverallIndex); } #endregion } else if (CurrentPage != 1) { #region ItemControl temp = (maingrid.Children[page - 1] as PanelControl).wrapPanel1.Children[index] as ItemControl; (maingrid.Children[page - 1] as PanelControl).wrapPanel1.Children.RemoveAt(index); if ((maingrid.Children[page - 2] as PanelControl).wrapPanel1.Children.Count == 20) { MoveItemOnPage(page - 1, 19, false);/////前一页的最后一个 } (maingrid.Children[page - 2] as PanelControl).wrapPanel1.Children.Add(temp); temp.OverallIndex = (maingrid.Children[page - 2] as PanelControl).wrapPanel1.Children.Count - 1; temp.PageIndex = page - 1; temp.Path.ChangeIndex(temp.PageIndex, temp.OverallIndex); #endregion } if (!flag) { for (int i = index; i < (maingrid.Children[page - 1] as PanelControl).wrapPanel1.Children.Count; i++) { ((maingrid.Children[page - 1] as PanelControl).wrapPanel1.Children[i] as ItemControl).OverallIndex -= 1; } page.UpdateIndex(index); } }
private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) /////准备拖动项目或结束编辑 { if (editItem) /////处于编辑状态 { var panel = maingrid.Children[CurrentPage - 1] as PanelControl; var ing = panel.InputHitTest(e.GetPosition(panel)) as FrameworkElement; var ing2 = topGrid.InputHitTest(e.GetPosition(topGrid)) as FrameworkElement; //if(ing2!=null) if (ing == null)////不是在maingrid点击 { if (ing2 == null || ing2.GetType().Equals(typeof(System.Windows.Controls.TextBlock))) { ChangeEdit(); } } else if (ing.Height > 20)////点击的不是移除按钮 { var border = ing.Parent as FrameworkElement; var grid = border.Parent as FrameworkElement; item = grid.Parent as ItemControl; tempIndex = item.OverallIndex; tempItem = new ItemControl(item.Path, item.DisplayName, item.PageIndex, item.OverallIndex); tempItem.image_del.Visibility = Visibility.Visible; tempItem.HorizontalAlignment = HorizontalAlignment.Left; tempItem.VerticalAlignment = VerticalAlignment.Top; item.image1.Source = null; item.textBox1.Text = ""; item.image_del.Visibility = Visibility.Hidden; int left, top; if ((item.OverallIndex + 1) % 5 == 0) { left = 4 * 120; top = (item.OverallIndex + 1) / 5 * 90 - 90; } else { left = ((item.OverallIndex + 1) % 5 - 1) * 120; top = (item.OverallIndex + 1) / 5 * 90; } tempItem.Margin = new Thickness(left, top, 0, 0); maingrid.Children.Add(tempItem); dragItem = true; mouseLocationBeforeDrag = e.GetPosition(this); ItemoldMargin = new Point(tempItem.Margin.Left, tempItem.Margin.Top); } } }
/// <summary> /// 初始化每个面板的快捷方式信息 /// </summary> private List<ItemInfo> ReadData() { try { List<ItemInfo> allItem = new List<ItemInfo>(); for (int i = 1; i <= PageCount; i++) { List<ItemInfo> itemList = i.GetData(); allItem.AddRange(itemList); foreach (var info in itemList) { var ic = new ItemControl(info.ItemPath, info.ItemName, i, info.ItemIndex); ((PanelControl)this.maingrid.Children[i - 1]).wrapPanel1.Children.Insert(ic.OverallIndex, ic); ic.del += new DelItem(DelItem); ic.movePage += new MoveItemPage(MoveItemOnPage); } } return allItem; } catch (Exception ee) { MyWork.NoteLog(ee); return null; } }
/////准备拖动项目或结束编辑 private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (editItem)/////处于编辑状态 { var panel = maingrid.Children[CurrentPage - 1] as PanelControl; var ing = panel.InputHitTest(e.GetPosition(panel)) as FrameworkElement; var ing2 = topGrid.InputHitTest(e.GetPosition(topGrid)) as FrameworkElement; //if(ing2!=null) if (ing == null)////不是在maingrid点击 { if (ing2 == null || ing2.GetType().Equals(typeof(System.Windows.Controls.TextBlock))) ChangeEdit(); } else if (ing.Height > 20)////点击的不是移除按钮 { var border = ing.Parent as FrameworkElement; var grid = border.Parent as FrameworkElement; item = grid.Parent as ItemControl; tempIndex = item.OverallIndex; tempItem = new ItemControl(item.Path, item.DisplayName, item.PageIndex, item.OverallIndex); tempItem.image_del.Visibility = Visibility.Visible; tempItem.HorizontalAlignment = HorizontalAlignment.Left; tempItem.VerticalAlignment = VerticalAlignment.Top; item.image1.Source = null; item.textBox1.Text = ""; item.image_del.Visibility = Visibility.Hidden; int left, top; if ((item.OverallIndex + 1) % 5 == 0) { left = 4 * 120; top = (item.OverallIndex + 1) / 5 * 90 - 90; } else { left = ((item.OverallIndex + 1) % 5 - 1) * 120; top = (item.OverallIndex + 1) / 5 * 90; } tempItem.Margin = new Thickness(left, top, 0, 0); maingrid.Children.Add(tempItem); dragItem = true; mouseLocationBeforeDrag = e.GetPosition(this); ItemoldMargin = new Point(tempItem.Margin.Left, tempItem.Margin.Top); } } }
/// <summary> /// 添加新快捷方式 /// </summary> /// <param name="path">执行路径</param> /// <param name="page">添加到的面板</param> private void AddItem(string path, int page, params string[] args) { if (path.JudgeFileType() != FileType.None) { if (path.Substring(path.LastIndexOf('.') + 1, 3).ToLower() == "lnk") { #region 若文件(夹)存在,使用真实路径递归 string truePath = path.getPathByLnk(); if (!File.Exists(truePath) && !Directory.Exists(truePath)) { #region this.Deactivated -= new EventHandler(Window_Deactivated); MessageBox.Show("文件(夹)不存在或快捷方式信息错误", "提示", MessageBoxButton.OK, MessageBoxImage.Information); this.Deactivated += new EventHandler(Window_Deactivated); #endregion } else////文件(夹)存在,递归 { string name = path.GetNameByPath(); //try //{ // File.Delete(path); //} //catch (Exception eee){ throw eee; } AddItem(truePath, page, name); } #endregion } else ////不是lnk文件 { if (!path.CheckExists()) { int thiscount = ((PanelControl)this.maingrid.Children[page - 1]).wrapPanel1.Children.Count; if (thiscount == 20) { #region 若此页已满,递归向下一页添加 page += 1; if (this.maingrid.Children.Count < page) { this.maingrid.Children.Add(new PanelControl((PageCount - CurrentPage + 1) * this.Width)); this.pagingGrid.Children.Add(new PageControl(false)); PageCount += 1; UpdatePageControl(PageCount); } if (args.Length == 0) { AddItem(path, page); } else { AddItem(path, page, args[0]); } #endregion } else////此页未满 { ItemControl ic = args.Length == 0 ? new ItemControl(path, page, thiscount) : new ItemControl(path, args[0], page, thiscount); ic.del += new DelItem(DelItem); ic.movePage += new MoveItemPage(MoveItemOnPage); (this.maingrid.Children[page - 1] as PanelControl).wrapPanel1.Children.Add(ic); Dal.Add(path, ic.DisplayName, ic.PageIndex, ic.OverallIndex, ic.ItemType); } } } } }