Ejemplo n.º 1
0
        //! Function to add TaggedItems to tag from different data structures

        /*!
         * \param item a TaggedItem object
         */
        public void AddToTag(TaggedItem item)
        {
            if (!ItemList.Contains(item))
            {
                ItemList.Add(item);
            }
        }
Ejemplo n.º 2
0
        //! Method to populate a Tag with a given tagName with information from Directory Info

        /*!
         * \param dirInfo a Directory Info instance to innumerate through directories
         * \param tagName a string name of a Tag object to populate
         */
        void PopulateTag(DirectoryInfo dirInfo, string tagName)
        {
            foreach (var file in dirInfo.GetFiles())
            {
                var fileItem = new TaggedItem(file.Name, file.Extension, file.CreationTime.ToString("g"),
                                              file.LastAccessTime.ToString("g"), file.FullName);
                if (!_session.Tags.Find(x => x.TagName.Equals(tagName)).ItemList.Contains(fileItem))
                {
                    _session.Tags.Find(x => x.TagName.Equals(tagName)).
                    AddToTag(fileItem);
                }
            }
        }
Ejemplo n.º 3
0
        //! A context menu for right clicking on tags

        /*!
         * \param listBox a listBox Windows Forms object
         * \param locationPoint a Point struct of x/y integer coordinates
         * \param selectedTag a Tag object on which the context menu was invoked
         * \param openedTag a Tag object currently opened in ListView
         * \param session a Session object
         * \param listViewItems a list of selected ListViewItems
         */
        public static bool ShowContextMenu(ListBox listBox, Point locationPoint, Tag selectedTag, Tag openedTag,
                                           CurrentSession session, List <ListViewItem> listViewItems)
        {
            var toolStripMenuItem1 = new ToolStripMenuItem {
                Text = @"Add to tag"
            };

            toolStripMenuItem1.Click += ToolStripMenuItem1Click;
            var toolStripMenuItem2 = new ToolStripMenuItem {
                Text = @"Remove from tag"
            };

            toolStripMenuItem2.Click += ToolStripMenuItem2Click;
            var toolStripMenuItem3 = new ToolStripMenuItem {
                Text = @"Delete tag"
            };

            toolStripMenuItem3.Click += ToolStripMenuItem3Click;
            var contextMenuStrip = new ContextMenuStrip();

            contextMenuStrip.Items.AddRange(new ToolStripItem[]
                                            { toolStripMenuItem1, toolStripMenuItem2, toolStripMenuItem3 });

            //! First Item: Adding to tag

            /*!
             *  Event Handler of a first element of context menu.
             *  transfers information of selected ListViewItems from openedTag to selectedTag
             */
            void ToolStripMenuItem1Click(object sender, EventArgs e)
            {
                //! Assigning lengthy data to easy to understand variables
                var donorTag    = openedTag;
                var receiverTag = selectedTag;

                //! Preventing Duplication of taggedItems
                if (donorTag != receiverTag)
                {
                    foreach (var item in listViewItems)
                    {
                        TaggedItem passedItem = donorTag.ItemList.Find(x => x.ItemName == item.Text);
                        //! Adding selected item
                        if (!receiverTag.ItemList.Contains(passedItem))
                        {
                            receiverTag.AddToTag(passedItem);
                        }
                    }
                    selectedTag.ItemList = receiverTag.ItemList;
                }
            }

            //! Second Item: Removing from tag

            /*!
             *  Event Handler of a second element of context menu.
             *  Removes information of selected ListViewItems from selectedTag
             */
            void ToolStripMenuItem2Click(object sender, EventArgs e)
            {
                foreach (var item in listViewItems)
                {
                    TaggedItem removedItem = selectedTag.ItemList.FirstOrDefault(x => x.ItemName == item.Text);
                    if (removedItem != null)
                    {
                        selectedTag.RemoveFromTag(removedItem);
                    }
                }
            }

            //Third Item: Removing tag

            /*!
             *  Event Handler of a second element of context menu.
             *  Removes selectedTag
             */
            void ToolStripMenuItem3Click(object sender, EventArgs e)
            {
                session.RemoveTag(selectedTag);
                listBox.Items.Remove(selectedTag.TagName);
            }

            contextMenuStrip.Show(listBox, locationPoint, ToolStripDropDownDirection.Default);

            return(true);
        }
Ejemplo n.º 4
0
        //! Overloaded function to remove TaggedItems from tag using different data structures

        /*!
         * \param item a TaggedItem object
         */
        public void RemoveFromTag(TaggedItem item)
        {
            ItemList.Remove(item);
        }