Ejemplo n.º 1
0
        private static Image GetAssociatedImage(MRUItem item)
        {
            string executable  = FindExecutable(item.FilePath);
            Icon   iconForFile = Icon.ExtractAssociatedIcon(executable);

            return(iconForFile.ToBitmap());
        }
Ejemplo n.º 2
0
        private MRUItem MakeItem(string text, int counter = -1)
        {
            counter = GetCounter(counter);
            var item = new MRUItem(counter, text);

            return(item);
        }
Ejemplo n.º 3
0
        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");
        }
Ejemplo n.º 4
0
        /// <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);
        }
Ejemplo n.º 5
0
        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;
        }
Ejemplo n.º 6
0
 /// <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);
        }
Ejemplo n.º 8
0
        /// <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();
            }
        }
Ejemplo n.º 9
0
        /// <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();
            }
        }
Ejemplo n.º 10
0
        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");
        }
Ejemplo n.º 11
0
        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);
        }
Ejemplo n.º 12
0
        private static Image GetImageFromFile(MRUItem item)
        {
            Image image;

            try
            {
                Icon iconForFile = Icon.ExtractAssociatedIcon(item.FilePath);
                image = iconForFile.ToBitmap();
            }
            catch (Exception)
            {
                image = null;
            }
            return(image);
        }
Ejemplo n.º 13
0
        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);
            }
        }
Ejemplo n.º 14
0
        /// <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);
            }
        }
Ejemplo n.º 15
0
        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);
        }
Ejemplo n.º 16
0
        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);
        }
Ejemplo n.º 17
0
        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);
        }
Ejemplo n.º 18
0
 public void AddItem(string fileName, string pathName, int page, System.Windows.Media.Imaging.BitmapImage image)
 {
     this.list.AddMRUItem(MRUItem.Create(fileName, pathName, page, image));
 }
Ejemplo n.º 19
0
 public void Initialize(MRUItem item, MRUGuiItemLocalization localization, string itemImagePath)
 {
     this.item = item;
 }
Ejemplo n.º 20
0
 public void Initialize(MRUItem item, MRUGuiItemLocalization localization)
 {
     Initialize(item, localization, null);
 }
Ejemplo n.º 21
0
        /// <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);
        }
Ejemplo n.º 22
0
 private void StoreItem(MRUItem item)
 {
     Storage[item.Text] = item;
 }
Ejemplo n.º 23
0
 /// <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, "");
 }