private void ReloadLinkMenu(ToolStripMenuItem menu, Link link) { menu.Image = Recursos.GetImage(link.Icon); menu.Text = link.Name; menu.Tag = link; foreach (var l in link.SubLinks) { if (l.IsSeparator) { menu.DropDownItems.Add(new ToolStripSeparator()); } else { var m = new ToolStripMenuItem(); ReloadLinkMenu(m, l); menu.DropDownItems.Add(m); } } if (link.IsFolder) { if (!link.ShowFolderContent) { menu.Click += (sender, e) => Utils.Action.DoLink(sender.GetTag <Link>()); return; } menu.DropDownOpening += (sender, e) => { Utils.Menu.CreateSubFoldersMenu((ToolStripMenuItem)sender, sender.GetTag <Link>(), new System.IO.DirectoryInfo(sender.GetTag <Link>().Path)); }; } else { menu.Click += (sender, e) => Utils.Action.DoLink(sender.GetTag <Link>()); } }
private void AgregateFilesMenu(ToolStripMenuItem mainmenu, string pattern, System.IO.DirectoryInfo dir) { var files = dir.GetFiles(pattern, System.IO.SearchOption.TopDirectoryOnly); foreach (var file in files.OrderBy(p => p.FullName)) { var menu = new ToolStripMenuItem(file.Name, Recursos.GetImage(file.FullName), (sender, e) => { Utils.Action.DoOpenFile(sender.GetTag <string>()); }); menu.Tag = file.FullName; mainmenu.DropDownItems.Add(menu); } }
public void CreateSubFoldersMenu(ToolStripMenuItem mainmenu, Link link, System.IO.DirectoryInfo dir) { if (!dir.Exists) { return; } var subdirs = new System.IO.DirectoryInfo[0]; if (link.ShowSubFolders) { subdirs = dir.GetDirectories("*", System.IO.SearchOption.TopDirectoryOnly); } mainmenu.DropDownItems.Clear(); if (link.ShowOpenFolder) { mainmenu.DropDownItems.Add(new ToolStripMenuItem("Abrir Carpeta", Resources.Open_Folder_yellow.ToBitmap(), (sender, e) => { Utils.Action.DoOpenFile(sender.GetTag <string>()); }).Do((m) => { m.Tag = dir.FullName; })); mainmenu.DropDownItems.Add(new ToolStripSeparator()); } foreach (var subdir in subdirs.OrderBy(p => p.FullName)) { var mSubdir = new ToolStripMenuItem(); mSubdir.Text = subdir.Name; mSubdir.Image = Recursos.GetImage(link.Icon); mSubdir.Tag = link; mSubdir.DropDownOpening += (sender, e) => { CreateSubFoldersMenu((ToolStripMenuItem)sender, sender.GetTag <Link>(), subdir); }; mainmenu.DropDownItems.Add(mSubdir); } AgregateFilesMenu(mainmenu, link.FolderFileFilter, dir); }