Example #1
0
        public static List<TagItem> GetTagsList(TagFilesDatabase currentDb, TagsCombinaton tagsCombination, string searchText)
        {
            if (currentDb == null) return null;

            List<TagItem> ret = new List<TagItem>();
            // Add each tag from the database
            for (int i = 0; i < currentDb.Tags.Count; i++)
            {
                // Extract the tag
                FileTag tag = currentDb.Tags[i];

                // Show the tag only if it's not in the history of tags being selected - 
                // (You should not show tag 'X' after selecting tag 'X')                                    
                if (!tagsCombination.ContainsByValue(tag, false) && tag.Value.ToLower().Contains(searchText.ToLower()))
                {
                    TagItem item = new TagItem();
                    // Set the tag item (including text of the tag with the tag's file-count                    
                    item.Text = (tag.Value == "" ? No_Tags_String : tag.ToString()) +
                        "\n  [" + currentDb.CountFilesByTag(tag).ToString() + "]";
                    item.RawFileTag = tag;

                    // Map the tag to it's group
                    int groupKeyIndex = currentDb.tagGroupMapping[i];
                    item.GroupName = currentDb.groupsNames[groupKeyIndex];
                    item.GroupKey = currentDb.groupsKeys[groupKeyIndex];

                    ret.Add(item);
                }
            }
            return ret;
        }
Example #2
0
        public BrowseTagsForm()
        {
            InitializeComponent();
            

            // Initialize all the members of the form
            this.fullDatabase = new TagFilesDatabase();
            this.currentDatabase = new TagFilesDatabase();
            this.tagsCombination = new TagsCombinaton();
            this.iconExtractor = new IconExtractor(this.imageListSmallIcons,
                this.imageListLargeIcons, 2);            

            // Subscribe to the FileSystemWatcher events
            this.fileSystemWatcherAllFiles.Renamed += new System.IO.RenamedEventHandler(fileSystemWatcher1_Renamed);
            this.fileSystemWatcherAllFiles.Deleted += new System.IO.FileSystemEventHandler(fileSystemWatcher1_Deleted);
            this.fileSystemWatcherAllFiles.Created += new System.IO.FileSystemEventHandler(fileSystemWatcher1_Created);                        

            // Subscribe to the TagsCombiationViewer events
            this.tagsCombinationViewer.RemoveRequested += new TagsCombinationViewer.RemoveHandler(tagsCombinationViewer1_RemoveRequested);
            this.tagsCombinationViewer.InverseRequested += new TagsCombinationViewer.InverseHandler(tagsCombinationViewer1_InverseRequested);

                        
            InitializeVirtualObjectListView();
            InitializeTagsListView();
            SetWindowTheme(this.listViewTags.Handle, "explorer", null);
            SetWindowTheme(this.virtualListViewFiles.Handle, "explorer", null);
        }
Example #3
0
        public void UpdateItems(TagFilesDatabase currentDb, TagsCombinaton tagsCombination, string searchText)
        {
            var tagItems = TagsListWraper.GetTagsList(currentDb, tagsCombination, searchText);            
            Dictionary<string, string> groups = new Dictionary<string,string>();
            if (tagItems != null)
            for (int i = 0; i < tagItems.Count; i++)
                groups[tagItems[i].GroupKey] = tagItems[i].GroupName;

            // Create the groups list. (Skip the default group - index 0)
            this.Groups.Clear();
            foreach (var kvp in groups)
                this.Groups.Add(kvp.Key, kvp.Value);            
            
            // Create item for the listView:
            List<ListViewItem> tagsList = new List<ListViewItem>();
            ListViewItem tagItem;
            // Add each tag from the database
            int j = 0;
            foreach (var t in tagItems)
            {
                // Show the tag only if it's not in the history of tags being selected - 
                // (You should not show tag 'X' after selecting tag 'X')
                if (!tagsCombination.ContainsByValue(t.RawFileTag, false) && 
                    t.Value.ToLower().Contains(searchText.ToLower()))
                {
                    // Set the tag item (including text of the tag with the tag's file-count
                    tagItem = new ListViewItem();
                    //tagItem.Text = j++.ToString().PadLeft(9, 'a') + "\n [10]";
                    tagItem.Text = t.Text;
                    tagItem.Tag = t.RawFileTag;

                    // Set image of the tag: special image if the tag's file-count is equals the
                    // database file-count. a regular folder image if not.
                    if (currentDb.Files.Count == currentDb.CountFilesByTag(t.RawFileTag))
                        tagItem.ImageIndex = 1;
                    else
                        tagItem.ImageIndex = 0;

                    // Map the tag to it's group
                    tagItem.Group = this.Groups[t.GroupKey];
                    tagsList.Add(tagItem);
                    //this.Items.Add(tagItem);
                }
            }

            // ** Sort the tags by groups, and inside of each group
            //ListViewItem tmp = new ListViewItem();
            //for (int i = 0; i < tagsList.Count; i++)
            //{
            //    for (int j = i + 1; j < tagsList.Count; j++)
            //    {
            //        int comperator = tagsList[i].Group.Name.CompareTo(tagsList[j].Group.Name);
            //        if (comperator == 1) // item[i].Group > item[j].Group
            //        { // Swap items
            //            tmp = (ListViewItem)tagsList[i].Clone();
            //            tagsList[i] = (ListViewItem)tagsList[j].Clone();
            //            tagsList[j] = tmp;
            //        }
            //        else if (comperator == 0) // Equal groups
            //        { // Sort internally

            //            comperator = ((FileTag)tagsList[i].Tag).ToString().CompareTo(
            //                ((FileTag)tagsList[j].Tag).ToString());

            //            if (comperator == 1)
            //            {
            //                tmp = (ListViewItem)tagsList[i].Clone();
            //                tagsList[i] = (ListViewItem)tagsList[j].Clone();
            //                tagsList[j] = tmp;
            //            }
            //        }
            //    }
            //}


            // ** Add to list view
            this.BeginUpdate();
            this.Clear();
            foreach (ListViewItem item in tagsList)
               this.Items.Add(item);
            
            this.EndUpdate();        
        }
Example #4
0
        /// <summary>
        /// 
        /// </summary>
        private void updateTagsListView(ListView tagsListView, TagFilesDatabase database, TagsCombinaton tagsCombination, string searchTagText)
        {
            //for (int i = 0; i < 5; i++)
            //{
            //    tagsListView1.Groups.Add("key_"+i.ToString(), "name_" + i.ToString());
            //}
            //tagsListView.BeginUpdate();
            //tagsListView.Clear();
            //for (int i = 0; i < 100; i++)
            //{
            //    ListViewItem item = new ListViewItem();
            //    item.Text = "T".PadLeft(12, 'a');
            //    item.ImageIndex = i % 2;
            //    item.Group = tagsListView1.Groups[i % 5];
            //    item.Tag = new object();
            //    this.tagsListView1.Items.Add(item);
            //}
            //tagsListView.EndUpdate();
            //return;

            this.setTagsListViewObject();

            this.tagsListView1.UpdateItems(database, tagsCombination, searchTagText);

            // Create the groups list. (Skip the default group - index 0)
            tagsListView.Groups.Clear();
            for (int i = 1; i < database.groupsNames.Count; i++)
            {
                string groupName = database.groupsNames[i];
                string groupKey = database.groupsKeys[i];
                tagsListView.Groups.Add(groupKey, groupName);
            }
            // Add the default group (with index 0) as the last group
            tagsListView.Groups.Add(database.groupsKeys[0], database.groupsNames[0]);

            // Create item for the listView:
            List<ListViewItem> tagsList = new List<ListViewItem>();
            ListViewItem tagItem;
            // Add each tag from the database
            for (int i = 0; i < database.Tags.Count; i++)
            {
                // Extract the tag
                FileTag tag = database.Tags[i];

                // Show the tag only if it's not in the history of tags being selected - 
                // (You should not show tag 'X' after selecting tag 'X')
                bool showTagCondition;
                showTagCondition =                   
                    !tagsCombination.ContainsByValue(tag, false) && 
                    tag.Value.ToLower().Contains(searchTagText.ToLower());
                if (showTagCondition)
                {
                    // Set the tag item (including text of the tag with the tag's file-count
                    tagItem = new ListViewItem();
                    tagItem.Text = (tag.Value == "" ? noTagsString : tag.ToString()) +
                        "\n  [" + database.CountFilesByTag(tag).ToString() + "]";
                    tagItem.Tag = tag;

                    // Set image of the tag: special image if the tag's file-count is equals the
                    // database file-count. a regular folder image if not.
                    if (database.Files.Count == database.CountFilesByTag(tag))
                        tagItem.ImageIndex = 1;
                    else
                        tagItem.ImageIndex = 0;

                    // Map the tag to it's group
                    int groupKeyIndex = database.tagGroupMapping[i];
                    string groupKey = database.groupsKeys[groupKeyIndex];
                    tagItem.Group = tagsListView.Groups[groupKey];
                    tagsList.Add(tagItem);
                }
            }

            // ** Sort the tags by groups, and inside of each group
            ListViewItem tmp = new ListViewItem();
            for (int i = 0; i < tagsList.Count; i++)
            {
                for (int j = i + 1; j < tagsList.Count; j++)
                {
                    int comperator = tagsList[i].Group.Name.CompareTo(tagsList[j].Group.Name);
                    if (comperator == 1) // item[i].Group > item[j].Group
                    { // Swap items
                        tmp = (ListViewItem)tagsList[i].Clone();
                        tagsList[i] = (ListViewItem)tagsList[j].Clone();
                        tagsList[j] = tmp;
                    }
                    else if (comperator == 0) // Equal groups
                    { // Sort internally

                        comperator = ((FileTag)tagsList[i].Tag).ToString().CompareTo(
                            ((FileTag)tagsList[j].Tag).ToString());

                        if (comperator == 1)
                        {
                            tmp = (ListViewItem)tagsList[i].Clone();
                            tagsList[i] = (ListViewItem)tagsList[j].Clone();
                            tagsList[j] = tmp;
                        }
                    }
                }
            }


            // ** Add to list view
            tagsListView.BeginUpdate();
            tagsListView.Clear();
            foreach (ListViewItem item in tagsList)
                tagsListView.Items.Add(item);
            
            tagsListView.EndUpdate();
        }
Example #5
0
        /// <summary>
        /// This method is in charge of updating the tags listView and the files listView in accordence
        /// with the data stored in the object 'database' and in 'tagsCombination'.
        /// </summary>
        /// <param name="database"></param>
        /// <param name="tagsCombination"></param>
        private void updateView(TagFilesDatabase database, TagsCombinaton tagsCombination)
        {
            // Update tags listview
            this.updateTagsListView(this.listViewTags, database, tagsCombination, this.txtSearchTag.Text);

            // Update files listview
            this.updateFilesListView(this.listViewFiles);            

            // Update the TagsCombinationViewer control
            this.tagsCombinationViewer.Update(tagsCombination);
        }
        public TagFilesDatabase GetPartialDatabase(TagsCombinaton tagsCombination)
        {
            TagFilesDatabase ret = this;

            for (int i = 0; i < tagsCombination.Count; i++)
            {
                // Set partial database
                ret = ret.GetPartialDatabase(tagsCombination[i]);
            }

            return ret;
        }
        public void Update(TagsCombinaton newTagsCombination)
        {            
            int leftLocation = 0;
            int correction = 0;
            string OrString = "|";
            string AndString = "&&";

            Button btn;
            Label lbl;

            // First, clear old controls
            for (int c = this.Controls.Count - 1; c >= 0; c--)
            {
                if (this.Controls[c] is Button || this.Controls[c] is Label)
                    this.Controls.RemoveAt(c);
            }
            

            // Now, paint each control according with the new tags combination
            for (int i = 0; i < newTagsCombination.Count; i++)
            {
                // Paint '('
                if (newTagsCombination[i].Count > 1)
                {                    
                    lbl = this.CreateLabel("(", 16, 0);
                    lbl.Left = leftLocation;
                    this.Controls.Add(lbl);                    
                    leftLocation = lbl.Right - correction;
                }
            
                for (int j = 0; j < newTagsCombination[i].Count; j++)
                {
                    // Paint the button for the tag
                    btn = new Button();
                    btn.Click += new EventHandler(this.btn_Click);
                    btn.MouseUp += new MouseEventHandler(this.btn_MouseUp);
                    btn.Tag = new TagsCombinationViewerEventArgs(i, j);
                    btn.Left = leftLocation;
                    btn.Top = 3;
                    btn.AutoSizeMode = AutoSizeMode.GrowAndShrink;
                    btn.AutoSize = true;
                    btn.Text = newTagsCombination[i][j].Inverse? "Not " + newTagsCombination[i][j].Value: newTagsCombination[i][j].Value;
                    this.Controls.Add(btn);
                    btn.BringToFront();
                    leftLocation = btn.Right;

                    // Paint OR char: '|'
                    if (j < newTagsCombination[i].Count - 1)
                    {
                        lbl = this.CreateLabel(OrString, 8, 7);
                        lbl.Left = leftLocation;
                        this.Controls.Add(lbl);                        
                        leftLocation = lbl.Right;
                    }                    
                }

                // Paint ')'
                bool closeBracesExists = false;
                if (newTagsCombination[i].Count > 1)
                {
                    lbl = this.CreateLabel(")", 16, 0);
                    lbl.Left = leftLocation - correction;
                    this.Controls.Add(lbl);                    
                    leftLocation = lbl.Right - correction;
                    closeBracesExists = true;
                }

                // Paint AND char: '&'
                if (i < newTagsCombination.Count - 1)
                {
                    lbl = this.CreateLabel(AndString, 16, 0);
                    if (closeBracesExists)
                        lbl.Left = leftLocation;
                    else
                        lbl.Left = leftLocation - correction;
                                        
                    this.Controls.Add(lbl);                    
                    leftLocation = lbl.Right - correction;
                }
            }
        }