private static Image GetAssociatedImage(MRUItem item) { string executable = FindExecutable(item.FilePath); Icon iconForFile = Icon.ExtractAssociatedIcon(executable); return(iconForFile.ToBitmap()); }
private MRUItem MakeItem(string text, int counter = -1) { counter = GetCounter(counter); var item = new MRUItem(counter, text); return(item); }
public void ShouldWorkWithNewMRUItemThatAddedWithManager() { Initialize(); viewMock.IsActionAllowedResponse = true; // add new item manager.AddFile("path3"); Assert.IsTrue(viewMock.ShowedContainers.Count == 2, "Wrong containers count on adding"); Assert.IsTrue(viewMock.ItemViews.Count == 3, "Wrong items count on adding"); // pin it MRUItemViewMock itemView = GetMockItemViewForPath("path3"); itemView.InvokePinItemRequested(); // container with pinned items always goes first Assert.IsTrue(viewMock.ShowedContainers[0].Items.Count() == 2, "Wrong items count in pinned group"); Assert.IsTrue(viewMock.ItemViews.Count == 3, "Wrong items count on pin"); // select it itemView.InvokeItemSelected(); MRUItem mruItem = manager.MRUItems.FirstOrDefault(m => m.FilePath == "path3"); Assert.IsTrue(mruItem.SelectedCount == 2, "Wrong 'selected count' attribute"); // delete it itemView.InvokeDeleteItemRequested(); Assert.IsTrue(viewMock.ShowedContainers.Count == 2, "Wrong containers count on deletion"); Assert.IsTrue(viewMock.ItemViews.Count == 2, "Wrong items count on deletion"); }
/// <summary> /// Returns image for given MRU item /// </summary> /// <param name="item">MRU item</param> /// <param name="imagePath">path to image for to use with given MRU item</param> /// <returns>If path to image specified, than image from this path will be returned, otherwise method will try to get image from file itself. /// If all above fail - than image from resource file will be used</returns> public static Image GetImageForItem(MRUItem item, string imagePath) { Image itemImage; try { if (!string.IsNullOrEmpty(imagePath) && File.Exists(imagePath)) { itemImage = Image.FromFile(imagePath); } else { itemImage = GetImageFromFile(item); if (itemImage == null) { itemImage = GetAssociatedImage(item); } } } catch (Exception) { itemImage = Properties.Resources.icons8_file_64; } return(itemImage); }
private void Initialize(MRUItem item, MRUGuiItemLocalization localization, Image itemImage) { this.item = item; pictureBoxFileIco.Image = itemImage; FileInfo fileInfo = new FileInfo(item.FilePath); labelFileName.Text = fileInfo.Name; labelPath.Text = fileInfo.DirectoryName; labelDate.Text = item.LastAccessedDate.ToString("dd/MM/yyyy"); ToolTip tt = new ToolTip(); tt.SetToolTip(this.pictureBoxRemove, localization.DeleteItemLabel); if (item.Pinned) { tt.SetToolTip(this.pictureBoxPin, localization.UnpinItemLabel); } else { tt.SetToolTip(this.pictureBoxPin, localization.PinItemLabel); } if (this.Parent != null) { normalColor = this.Parent.BackColor; } BackColor = normalColor; }
/// <summary> /// Init control with given MRU item /// </summary> /// <param name="item">MRU item to show on control</param> /// <param name="localization">localization instance</param> /// <param name="imagePathForItem">image for menu item (currently not supported)</param> public void Initialize(MRUItem item, MRUGuiItemLocalization localization, string imagePathForItem) { this.item = item; UpdateAppearance(); this.Image = ImageResolver.GetImageForItem(item, imagePathForItem); // subscribe to events this.Click += MRUItemMenu_Click; }
private List <MRUItem> CreateAllRangeItems(DateTime today) { List <MRUItem> items = new List <MRUItem>(); // pinned item MRUItem item1 = new MRUItem { FilePath = "C:/path1/a1", Pinned = true, SelectedCount = 1, LastAccessedDate = today }; // today's not pinned item MRUItem item2 = new MRUItem { FilePath = "C:/path2/A2", Pinned = false, SelectedCount = 3, LastAccessedDate = today }; // yesterday's not pinned item MRUItem item3 = new MRUItem { FilePath = "C:/path3/b2", Pinned = false, SelectedCount = 3, LastAccessedDate = today.AddDays(-1) }; // this week not pinned item MRUItem item4 = new MRUItem { FilePath = "C:/path4/C2", Pinned = false, SelectedCount = 4, LastAccessedDate = today.AddDays(-2) }; // this month not pinned item MRUItem item5 = new MRUItem { FilePath = "C:/b2/x1", Pinned = false, SelectedCount = 5, LastAccessedDate = today.AddDays(-8) }; items.Add(item1); items.Add(item2); items.Add(item3); items.Add(item4); items.Add(item5); return(items); }
/// <summary> /// Change state of pinned property for given file /// </summary> /// <param name="path">File full path</param> public void ChangePinStateForFile(string path) { MRUItem existedItem = MRUItems.FirstOrDefault(item => item.FilePath == path); if (existedItem != null) { existedItem.Pinned = !existedItem.Pinned; UpdateMRUItems(); } }
/// <summary> /// Remove given file from MRU items /// </summary> /// <param name="path">File full path</param> public void RemoveFile(string path) { MRUItem existedItem = MRUItems.FirstOrDefault(item => item.FilePath == path); if (existedItem != null) { MRUItems = MRUItems.Where(item => item.FilePath != path).ToList(); UpdateMRUItems(); } }
public void ShouldUpdateMRUItemSelectedCountOnItemSelected() { Initialize(); MRUItemViewMock itemView = GetMockItemViewForPath("path1"); itemView.InvokeItemSelected(); MRUItem item = manager.MRUItems.FirstOrDefault(m => m.FilePath == "path1"); Assert.IsTrue(item.SelectedCount == 2, "Wrong 'selected count' attribute"); }
private bool PerformSelectItem(string path) { bool response = false; MRUItem existedItem = MRUItems.FirstOrDefault(item => item.FilePath == path); if (existedItem != null) { existedItem.SelectedCount++; existedItem.LastAccessedDate = DateTime.Now; UpdateMRUItems(); response = true; } return(response); }
private static Image GetImageFromFile(MRUItem item) { Image image; try { Icon iconForFile = Icon.ExtractAssociatedIcon(item.FilePath); image = iconForFile.ToBitmap(); } catch (Exception) { image = null; } return(image); }
public int GetPageNumberForPath(string path) { int i = this.list.IndexOf(path); MRUItem item = null; //if ((i >= 0) && (i < Math.Min(this.list.ShowMaxEntries, this.list.MaxEntries))) if ((i >= 0) && (i < this.list.ShowMaxEntries)) { item = this.list[i]; } if (item != null) { return(item.PageNumber); } else { return(1); } }
/// <summary> /// Add file to tracking as MRU item /// </summary> /// <param name="path">File full path</param> public void AddFile(string path) { MRUItem existedItem = MRUItems.FirstOrDefault(item => item.FilePath == path); if (existedItem == null) { MRUItem item = new MRUItem() { FilePath = path, LastAccessedDate = DateTime.Now, Pinned = false, SelectedCount = 1 }; MRUItems.Add(item); UpdateMRUItems(); } else { PerformSelectItem(path); } }
private List <MRUItem> CreateItems() { List <MRUItem> items = new List <MRUItem>(); MRUItem item1 = new MRUItem { FilePath = "path1", Pinned = true, SelectedCount = 1, LastAccessedDate = new DateTime(2019, 4, 27) }; MRUItem item2 = new MRUItem { FilePath = "path2", Pinned = false, SelectedCount = 3, LastAccessedDate = new System.DateTime(2019, 4, 26) }; MRUItem item3 = new MRUItem { FilePath = "path3", Pinned = false, SelectedCount = 3, LastAccessedDate = new System.DateTime(2019, 4, 25) }; MRUItem item4 = new MRUItem { FilePath = "path4", Pinned = false, SelectedCount = 3, LastAccessedDate = new System.DateTime(2019, 4, 24) }; items.Add(item1); items.Add(item4); items.Add(item3); items.Add(item2); return(items); }
private List <MRUItem> CreateItems() { List <MRUItem> items = new List <MRUItem>(); MRUItem item1 = new MRUItem { FilePath = "path1", Pinned = true, SelectedCount = 1 }; MRUItem item2 = new MRUItem { FilePath = "path2", Pinned = false, SelectedCount = 3 }; items.Add(item1); items.Add(item2); return(items); }
private List <MRUItem> CreateItems(DateTime today) { List <MRUItem> items = new List <MRUItem>(); MRUItem item1 = new MRUItem { FilePath = "path1", Pinned = true, SelectedCount = 1, LastAccessedDate = today }; MRUItem item2 = new MRUItem { FilePath = "path2", Pinned = false, SelectedCount = 3, LastAccessedDate = today }; items.Add(item1); items.Add(item2); return(items); }
public void AddItem(string fileName, string pathName, int page, System.Windows.Media.Imaging.BitmapImage image) { this.list.AddMRUItem(MRUItem.Create(fileName, pathName, page, image)); }
public void Initialize(MRUItem item, MRUGuiItemLocalization localization, string itemImagePath) { this.item = item; }
public void Initialize(MRUItem item, MRUGuiItemLocalization localization) { Initialize(item, localization, null); }
/// <summary> /// Init control with given MRU item /// </summary> /// <param name="item">MRU item to show on control</param> /// <param name="localization">localization instance</param> /// <param name="imagePath">image for menu item (currently not supported)</param> public void Initialize(MRUItem item, MRUGuiItemLocalization localization, string imagePath) { Image itemImage = ImageResolver.GetImageForItem(item, imagePath); this.Initialize(item, localization, itemImage); }
private void StoreItem(MRUItem item) { Storage[item.Text] = item; }
/// <summary> /// Init control with given MRU item /// </summary> /// <param name="item">MRU item to show on control</param> /// <param name="localization">localization instance</param> public void Initialize(MRUItem item, MRUGuiItemLocalization localization) { this.Initialize(item, localization, ""); }