コード例 #1
0
        public void ReloadTagsData()
        {
            List <ColorTagState> backupTags = null;

            if (TagsList == null)
            {
                TagsList = new List <ColorTagState> ();
            }
            else
            {
                backupTags = new List <ColorTagState> ();
                backupTags.AddRange(TagsList);
                TagsList.Clear();
            }

            if (AnnCategoryTagUtil.Instance == null)
            {
                return;
            }

            var tagList     = AnnCategoryTagUtil.Instance.GetTags();
            var tempTagList = new List <AnnotationTag> ();

            tempTagList.AddRange(tagList);

            if (tagList != null)
            {
                foreach (var tag in tempTagList)
                {
                    var colorTag = new ColorTagState();
                    colorTag.CheckState = NSCellStateValue.Off;
                    if (backupTags != null)
                    {
                        for (int i = 0; i < backupTags.Count; i++)
                        {
                            if (tag.TagId == backupTags [i].Tag.TagId)
                            {
                                colorTag.CheckState = backupTags [i].CheckState;
                                break;
                            }
                        }
                    }

                    colorTag.Tag = tag;
                    TagsList.Add(colorTag);
                }
            }

            if (backupTags != null)
            {
                backupTags.Clear();
                backupTags = null;
            }

            if (TagsTableView != null)
            {
                TagsTableView.ReloadData();
            }
        }
コード例 #2
0
        public override void ViewDidLoad()
        {
            if (TagsList == null)
            {
                TagsList = new List <AnnotationTag> (0);
            }
            else
            {
                TagsList.Clear();
            }

            var tagList = AnnCategoryTagUtil.Instance.GetTags();

            if (tagList != null)
            {
                TagsList.AddRange(tagList);
            }

            TagTableView.UsesAlternatingRowBackgroundColors               = false;
            TagTableView.EnclosingScrollView.ScrollerKnobStyle            = NSScrollerKnobStyle.Default;
            TagTableView.EnclosingScrollView.VerticalScroller.ControlSize = NSControlSize.Small;
            TagTableView.SelectionHighlightStyle             = NSTableViewSelectionHighlightStyle.Regular;
            TagTableView.EnclosingScrollView.BackgroundColor = NSColor.White;
            TagTableView.EnclosingScrollView.BorderType      = NSBorderType.BezelBorder;
            TagTableView.GridStyleMask = NSTableViewGridStyle.None;

            TagTableView.DataSource = new EditTagTableDataSource(TagsList, this);
            TagTableView.Delegate   = new EditTagTableDelegate(TagsList, this);
            TagTableView.ReloadData();

            var attributedTitle = Utility.AttributeTitle("Done", NSColor.Red, 13);

            DoneButton.AttributedTitle = attributedTitle;
            var alterTitle = Utility.AttributeTitle("Done", NSColor.Red, 13);

            DoneButton.AttributedAlternateTitle = alterTitle;

            string[] typeArray = { "NSStringPboardType" };
            TagTableView.RegisterForDraggedTypes(typeArray);

            this.CurrentTagIndex = -1;
        }
コード例 #3
0
        public void ReloadAnnotationData()
        {
            if (AnnCategoryTagUtil.Instance == null)
            {
                return;
            }
            if (TagsList == null)
            {
                TagsList = new List <AnnotationTag> ();
            }
            else
            {
                TagsList.Clear();
            }

            var tag = new AnnotationTag();

            tag.Color = string.Empty;
            tag.Title = "All Tags";
            tag.TagId = Guid.Empty;
            TagsList.Add(tag);

            var noTag = new AnnotationTag();

            noTag.Color = string.Empty;
            noTag.Title = "No tag";
            noTag.TagId = Guid.Empty;
            TagsList.Add(noTag);

            var tags = AnnCategoryTagUtil.Instance.GetTags();

            TagsList.AddRange(tags);

            if (TagsTableView != null)
            {
                TagsTableView.ReloadData();
            }
        }
コード例 #4
0
        public void UpdateTags()
        {
            TagsClean = "";
            if (tags == null)             // TODO: v0.7.7 returns null tags when there are no plugins enabled.
            {
                tags = "";                // Use empty string as fallback instead
            }
            var separatedTags = tags.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var s in separatedTags)
            {
                TagsClean += s.Substring(Math.Max(s.IndexOf(':') + 1, 0)).Trim() + ", ";
            }
            TagsClean = TagsClean.Trim().TrimEnd(',');
            TagsList.Clear();
            foreach (var s in separatedTags)
            {
                TagsList.Add(s.Trim());
            }

            // TODO: Apparently we can crash here with a COMException
            try
            {
                TagsGroups.Clear();
            }
            catch (Exception e)
            {
                // Drop original collection, can cause more COMExceptions
                TagsGroups = new ObservableCollection <ArchiveTagsGroup>();
#if WINDOWS_UWP
                Crashes.TrackError(e);
#endif
            }
            var tmp = new List <ArchiveTagsGroup>();
            foreach (var s in separatedTags)
            {
                var parts      = s.Trim().Split(new char[] { ':' }, 2);
                var @namespace = parts.Length == 2 ? parts[0] : "other";
                var group      = tmp.FirstOrDefault(tg => tg.Namespace.Equals(@namespace));
                if (group == null)
                {
                    group = AddTagsGroup(tmp, @namespace);
                }
                var tag = parts[parts.Length - 1];
                if (parts[0].Equals("date_added"))
                {
                    if (long.TryParse(tag, out long unixTime))
                    {
                        tag = Util.UnixTimeToDateTime(unixTime).ToString();
                    }
                }
                group.Tags.Add(new ArchiveTagsGroupTag {
                    FullTag = s.Trim(), Tag = tag, Namespace = @namespace
                });
            }
            tmp.Sort((a, b) => string.Compare(a.Namespace, b.Namespace));
            var c = tmp.Find(g => g.Namespace.Equals("other"));
            if (c != null)
            {
                tmp.Remove(c);
                tmp.Add(c);
            }
            try
            {
                tmp.ForEach(g =>
                {
                    g.Namespace = g.Namespace.UpperFirstLetter().Replace('_', ' ');
                    TagsGroups.Add(g);
                });
            }
            catch (Exception e)
            {
                // Handle damaged collection just in case
#if WINDOWS_UWP
                Crashes.TrackError(e);
#endif
            }
        }