private void newToolStripMenuItem_Click(object sender, EventArgs e) { UserControl1 us = new UserControl1(); //us.Dock = DockStyle.Right; flowLayoutPanel1.Controls.Add(us); ResizeWindow(); }
internal void load() { var list = XMLSerializer.Deserialize<List<string>>("list", new List<string>() { Path.GetDirectoryName(Application.ExecutablePath) }); foreach (var item in list) { if (Directory.Exists(item)) { var us = createView(item); if (activeUs == null) { activeUs = us; } } } }
//bool mgstart = false; private UserControl1 createView(string path) { UserControl1 us = new UserControl1(); us.listView.BackColor = Color.LightGray; us.Enter += (s, e) => { if (activeUs != null) { activeUs.listView.BackColor = Color.LightGray; if(mg !=null)mg.End(); mglog = string.Empty; //mgstart = false; } activeUs = us; activeUs.listView.BackColor = Color.White; }; //us.listView.DoubleClick += (sender, e) => { // if (us.listView.SelectedIndices.Count == 1) { // var items = us.ItemList; // var index = us.listView.SelectedIndices[0]; // //var fp = System.IO.Path.Combine(us.Path, items[index].Name); // var fp = getFullPath(us.Dir, items[index].Name); // //if (items[index].IsFile) { // if (File.Exists(fp)) { // HistoryListView.Items.Insert(0, fp); // Process.Start(fp); // } // else if(Directory.Exists(fp)){ // us.Dir = fp; // } // } //}; us.listView.DoubleClickEx += (sender, e) => { if (us.listView.SelectedIndices.Count == 1) { var items = us.ItemList; var index = us.listView.SelectedIndices[0]; //var fp = System.IO.Path.Combine(us.Path, items[index].Name); var fp = getFullPath(us.Dir, items[index].Name); //if (items[index].IsFile) { if (File.Exists(fp)) { HistoryListView.Items.Insert(0, fp); Process.Start(fp); } else if (Directory.Exists(fp)) { us.Dir = fp; } } else if (us.listView.SelectedIndices.Count == 0) { us.UpDir(); } }; us.listView.MouseDown += (s, e) => { if (e.Button == MouseButtons.Right) { mglog = string.Empty; //if (mg == null) mg = new MouseGesture(); //mg.Start(us.listView, e.Location); mg.Start(us.listView, us.listView.PointToScreen(new Point(e.X, e.Y))); activeUs.listView.MultiSelect = false; } if (popupForm != null && popupForm.Visible) { popupForm.Visible = false; } }; us.listView.MouseMove += (s, e) => { if (e.Button == MouseButtons.Right) { //Arrow arrow = mg.Test(new Point(e.X, e.Y)); Arrow arrow = mg.Test(us.listView.PointToScreen(new Point(e.X, e.Y))); if (arrow != Arrow.none) { switch (arrow) { case Arrow.up: //label1.Text += "↑"; mglog += "U"; break; case Arrow.right: //label1.Text += "→"; mglog += "R"; break; case Arrow.down: //label1.Text += "↓"; mglog += "D"; break; case Arrow.left: mglog += "L"; //label1.Text += "←"; break; } } } }; us.listView.MouseUpEx += (s, e) => { if (e.Button == MouseButtons.Right) { //Console.WriteLine("mglog=" + mglog); if (MouseGestureMap.ContainsKey(mglog)) { MouseGestureMap[mglog](this); } else if (mglog == string.Empty) { //UserControl1 u = s as UserControl1; var ctm = new ShellContextMenu(); var selfiles = us.SelectedItemList; if (selfiles.Count == 0) { //ctm.CreateFolderMenu(us.listView.PointToScreen(new Point(e.X, e.Y)), us.Dir); DirectoryInfo[] dir = new DirectoryInfo[1]; dir[0] = new DirectoryInfo(us.Dir); ctm.ShowContextMenu(dir, us.listView.PointToScreen(new Point(e.X, e.Y))); } else { List<FileInfo> arrFI = new List<FileInfo>(); selfiles.ForEach(x => { arrFI.Add(new FileInfo(System.IO.Path.Combine(us.Dir, x.Name))); }); ctm.ShowContextMenu(arrFI.ToArray(), us.listView.PointToScreen(new Point(e.X, e.Y))); } } if (mg != null) mg.End(); mglog = string.Empty; activeUs.listView.MultiSelect = true; } }; us.listView.MouseUp += (s, e) => { if (e.Button == MouseButtons.Middle) { if (us.listView.SelectedIndices.Count > 0) { var item = us.ItemList[us.listView.SelectedIndices[0]]; if (!item.IsFile) { var p = Path.Combine(us.Dir, item.Name); createView(p); } } } else if (e.Button == MouseButtons.Right && !activeUs.listView.MultiSelect) { var ctm = new ShellContextMenu(); var selfiles = us.SelectedItemList; //if (selfiles.Count == 0) { // DirectoryInfo[] dir = new DirectoryInfo[1]; // dir[0] = new DirectoryInfo(us.Dir); // ctm.ShowContextMenu(dir, us.listView.PointToScreen(new Point(e.X, e.Y))); //} //else if (selfiles.Count > 0) { List<FileInfo> arrFI = new List<FileInfo>(); selfiles.ForEach(x => { arrFI.Add(new FileInfo(System.IO.Path.Combine(us.Dir, x.Name))); }); ctm.ShowContextMenu(arrFI.ToArray(), us.listView.PointToScreen(new Point(e.X, e.Y))); } activeUs.listView.MultiSelect = true; } }; us.listView.ItemMouseHover += (s, e) => { //e.Item. //var kk=0; }; us.ChangePath += (s, e) => { HistoryListView.Items.Insert(0, e.path); }; flowLayoutPanel1.Controls.Add(us); us.Dir = path; ResizeWindow(); return us; }
//bool mgstart = false; private UserControl1 createView(string path) { UserControl1 us = new UserControl1(); us.listView.BackColor = Color.LightGray; us.Enter += (s, e) => { if (activeUs != null) { activeUs.listView.BackColor = Color.LightGray; if (mg != null) { mg.End(); } mglog = string.Empty; //mgstart = false; } activeUs = us; activeUs.listView.BackColor = Color.White; }; //us.listView.DoubleClick += (sender, e) => { // if (us.listView.SelectedIndices.Count == 1) { // var items = us.ItemList; // var index = us.listView.SelectedIndices[0]; // //var fp = System.IO.Path.Combine(us.Path, items[index].Name); // var fp = getFullPath(us.Dir, items[index].Name); // //if (items[index].IsFile) { // if (File.Exists(fp)) { // HistoryListView.Items.Insert(0, fp); // Process.Start(fp); // } // else if(Directory.Exists(fp)){ // us.Dir = fp; // } // } //}; us.listView.DoubleClickEx += (sender, e) => { if (us.listView.SelectedIndices.Count == 1) { var items = us.ItemList; var index = us.listView.SelectedIndices[0]; //var fp = System.IO.Path.Combine(us.Path, items[index].Name); var fp = getFullPath(us.Dir, items[index].Name); //if (items[index].IsFile) { if (File.Exists(fp)) { HistoryListView.Items.Insert(0, fp); Process.Start(fp); } else if (Directory.Exists(fp)) { us.Dir = fp; } } else if (us.listView.SelectedIndices.Count == 0) { us.UpDir(); } }; us.listView.MouseDown += (s, e) => { if (e.Button == MouseButtons.Right) { mglog = string.Empty; //if (mg == null) mg = new MouseGesture(); //mg.Start(us.listView, e.Location); mg.Start(us.listView, us.listView.PointToScreen(new Point(e.X, e.Y))); activeUs.listView.MultiSelect = false; } if (popupForm != null && popupForm.Visible) { popupForm.Visible = false; } }; us.listView.MouseMove += (s, e) => { if (e.Button == MouseButtons.Right) { //Arrow arrow = mg.Test(new Point(e.X, e.Y)); Arrow arrow = mg.Test(us.listView.PointToScreen(new Point(e.X, e.Y))); if (arrow != Arrow.none) { switch (arrow) { case Arrow.up: //label1.Text += "↑"; mglog += "U"; break; case Arrow.right: //label1.Text += "→"; mglog += "R"; break; case Arrow.down: //label1.Text += "↓"; mglog += "D"; break; case Arrow.left: mglog += "L"; //label1.Text += "←"; break; } } } }; us.listView.MouseUpEx += (s, e) => { if (e.Button == MouseButtons.Right) { //Console.WriteLine("mglog=" + mglog); if (MouseGestureMap.ContainsKey(mglog)) { MouseGestureMap[mglog](this); } else if (mglog == string.Empty) { //UserControl1 u = s as UserControl1; var ctm = new ShellContextMenu(); var selfiles = us.SelectedItemList; if (selfiles.Count == 0) { //ctm.CreateFolderMenu(us.listView.PointToScreen(new Point(e.X, e.Y)), us.Dir); DirectoryInfo[] dir = new DirectoryInfo[1]; dir[0] = new DirectoryInfo(us.Dir); ctm.ShowContextMenu(dir, us.listView.PointToScreen(new Point(e.X, e.Y))); } else { List <FileInfo> arrFI = new List <FileInfo>(); selfiles.ForEach(x => { arrFI.Add(new FileInfo(System.IO.Path.Combine(us.Dir, x.Name))); }); ctm.ShowContextMenu(arrFI.ToArray(), us.listView.PointToScreen(new Point(e.X, e.Y))); } } if (mg != null) { mg.End(); } mglog = string.Empty; activeUs.listView.MultiSelect = true; } }; us.listView.MouseUp += (s, e) => { if (e.Button == MouseButtons.Middle) { if (us.listView.SelectedIndices.Count > 0) { var item = us.ItemList[us.listView.SelectedIndices[0]]; if (!item.IsFile) { var p = Path.Combine(us.Dir, item.Name); createView(p); } } } else if (e.Button == MouseButtons.Right && !activeUs.listView.MultiSelect) { var ctm = new ShellContextMenu(); var selfiles = us.SelectedItemList; //if (selfiles.Count == 0) { // DirectoryInfo[] dir = new DirectoryInfo[1]; // dir[0] = new DirectoryInfo(us.Dir); // ctm.ShowContextMenu(dir, us.listView.PointToScreen(new Point(e.X, e.Y))); //} //else if (selfiles.Count > 0) { List <FileInfo> arrFI = new List <FileInfo>(); selfiles.ForEach(x => { arrFI.Add(new FileInfo(System.IO.Path.Combine(us.Dir, x.Name))); }); ctm.ShowContextMenu(arrFI.ToArray(), us.listView.PointToScreen(new Point(e.X, e.Y))); } activeUs.listView.MultiSelect = true; } }; us.listView.ItemMouseHover += (s, e) => { //e.Item. //var kk=0; }; us.ChangePath += (s, e) => { HistoryListView.Items.Insert(0, e.path); }; flowLayoutPanel1.Controls.Add(us); us.Dir = path; ResizeWindow(); return(us); }