Ejemplo n.º 1
0
        /**
         * Adds the existing unread states for the specified tab and list of workspaces
         * to the specified array list.
         */

        private void FillStatesForTab(IList states, IResourceList workspaces, string tab)
        {
            if (tab == _tabProvider.GetDefaultTab())
            {
                states.Add(_defaultUnreadState);
            }

            IntHashTable tabHash = (IntHashTable)_unreadStateTabMap [tab];

            if (tabHash != null)
            {
                if (tab != _tabProvider.GetDefaultTab())
                {
                    UnreadState state = (UnreadState)tabHash [0];
                    if (state != null)
                    {
                        states.Add(state);
                    }
                }

                foreach (IResource ws in workspaces)
                {
                    UnreadState state = (UnreadState)tabHash [ws.Id];
                    if (state != null)
                    {
                        states.Add(state);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adjusts the unread count for the specified resource stored in the specified
        /// count map by the specified delta value.
        /// </summary>
        private void AdjustUnreadCount(IResource res, int delta, UnreadState state)
        {
            if (!state.IsPersistent && !state.IsCounterValid(res))
            {
                return;
            }

            int count;

            if (state.IsCounterValid(res) || (state.IsPersistent && !_unreadCountProviders.Contains(res.Type)))
            {
                count = state.GetUnreadCount(res) + delta;
            }
            else
            {
                // this will initiate a new count calculation which will already take into account
                // the new unread state of the resource
                count = state.GetUnreadCount(res);
            }
            if (count >= 0)
            {
                state.UpdateUnreadCounter(res, count);
                if (state.IsPersistent && !_unreadCountProviders.Contains(res.Type))
                {
                    MarkUnreadCounterChanged(res);
                }
            }
        }
Ejemplo n.º 3
0
        private int GetUnreadCountFromLinks(IResource res, UnreadState state)
        {
            int count;
            int persistentCount = GetPersistentUnreadCount(res);

            if (persistentCount == 0)
            {
                count = 0;
            }
            else
            {
                int           unfilteredCount;
                IResourceList links = GetUnreadCountedLinks(res, out unfilteredCount);
                if (links == null)
                {
                    count = 0;
                }
                else
                {
                    links = links.Intersect(_tabProvider.GetTabFilterList(state.Tab), true);
                    count = CountUnreadResources(links);
                    // HACK: Cleanup for out-of-sync UnreadCount values
                    if (links.Count == unfilteredCount && count != persistentCount)
                    {
                        SetPersistentUnreadCount(res, count);
                        MarkUnreadCounterChanged(res);
                    }
                }
            }
            return(count);
        }
Ejemplo n.º 4
0
        /**
         * Switches the state of unread counters to the state associated with the
         * specified key and filter list, and creates a new state if necessary.
         */

        public UnreadState SetUnreadState(string activeTab, IResource activeWorkspace)
        {
            if (activeTab == _tabProvider.GetDefaultTab() && activeWorkspace == null)
            {
                _curUnreadState = _defaultUnreadState;
            }
            else
            {
                IntHashTable tabHash = (IntHashTable)_unreadStateTabMap [activeTab];
                if (tabHash == null)
                {
                    tabHash = new IntHashTable();
                    _unreadStateTabMap [activeTab] = tabHash;
                }

                int         wsId  = (activeWorkspace == null) ? 0 : activeWorkspace.Id;
                UnreadState state = (UnreadState)tabHash [wsId];
                if (state == null)
                {
                    state          = new UnreadState(this, activeTab, activeWorkspace);
                    tabHash [wsId] = state;
                }

                _curUnreadState = state;
            }
            return(_curUnreadState);
        }
Ejemplo n.º 5
0
 private void AdjustCounterInState(IntHashTable tabMap, int workspaceId, IResource resource, int delta)
 {
     if (tabMap != null)
     {
         UnreadState tabState = (UnreadState)tabMap [workspaceId];
         if (tabState != null)
         {
             AdjustUnreadCount(resource, delta, tabState);
         }
     }
 }
Ejemplo n.º 6
0
 public void InvalidateUnreadCounter(IResource res)
 {
     _defaultUnreadState.InvalidateCounter(res);
     foreach (DictionaryEntry de in _unreadStateTabMap)
     {
         IntHashTable ht = (IntHashTable)de.Value;
         foreach (IntHashTable.Entry entry in ht)
         {
             UnreadState state = (UnreadState)entry.Value;
             state.InvalidateCounter(res);
         }
     }
     _curUnreadState.OnUnreadCountChanged(res);
 }
Ejemplo n.º 7
0
        public UnreadManager(WorkspaceManager workspaceManager, IResourceTabProvider tabProvider,
                             ISettingStore settingStore, ICoreProps coreProps)
        {
            _tabProvider        = tabProvider;
            _workspaceManager   = workspaceManager;
            _coreProps          = coreProps;
            _defaultUnreadState = new UnreadState(this, null, null);
            _curUnreadState     = _defaultUnreadState;

            _store               = Core.ResourceStore;
            _propUnreadCount     = _store.PropTypes.Register("UnreadCount", PropDataType.Int, PropTypeFlags.Internal);
            _traceUnreadCounters = settingStore.ReadBool("UnreadCounters", "TraceUnreadCounters", false);

            Core.ResourceAP.JobFinished += environment_ResourceOperationFinished;

            Enabled = true;
        }
Ejemplo n.º 8
0
        /**
         * Returns the count of unread resources returned by the specified provider and
         * filtered by the workspace.
         */

        private int GetProviderUnreadCount(IResource res, UnreadState state, IUnreadCountProvider provider)
        {
            IResourceList unreadList = provider.GetResourcesForView(res);

            if (unreadList == Core.ResourceStore.EmptyResourceList)
            {
                return(0);
            }
            if (state != _defaultUnreadState)
            {
                unreadList = unreadList.Intersect(_tabProvider.GetTabFilterList(state.Tab));
                if (state.Workspace != null)
                {
                    unreadList = unreadList.Intersect(_workspaceManager.GetFilterList(state.Workspace));
                }
            }
            return(unreadList.Count);
        }
Ejemplo n.º 9
0
        /**
         * Refreshes the unread counters on all resources. Assumes to be invoked from the
         * resource thread.
         */

        public void RefreshUnreadCounters()
        {
            IResourceList unreadCountedResources = _store.FindResourcesWithProp(null, _propUnreadCount);

            foreach (IResource unreadCountedRes in unreadCountedResources)
            {
                int           linkCount;
                IResourceList unreadCountedLinks = GetUnreadCountedLinks(unreadCountedRes, out linkCount);
                unreadCountedRes.SetProp(_propUnreadCount, CountUnreadResources(unreadCountedLinks));
            }
            _defaultUnreadState.ResetCounters();
            foreach (DictionaryEntry de in _unreadStateTabMap)
            {
                IntHashTable tabHash = (IntHashTable)de.Value;
                foreach (IntHashTable.Entry ie in tabHash)
                {
                    UnreadState state = (UnreadState)ie.Value;
                    state.ResetCounters();
                }
            }
        }
Ejemplo n.º 10
0
        /**
         * Returns the unread count for the specified state.
         */

        internal int GetCountForState(UnreadState state, IResource res)
        {
            if (state.IsCounterValid(res) || (state != _curUnreadState && !state.IsPersistent))
            {
                return(state.GetCountFromBuffer(res));
            }

            int count;
            IUnreadCountProvider provider = (IUnreadCountProvider)_unreadCountProviders [res.Type];

            if (provider == null)
            {
                count = state.IsPersistent ? res.GetIntProp(_propUnreadCount) :
                        GetUnreadCountFromLinks(res, state);
            }
            else
            {
                count = GetProviderUnreadCount(res, state, provider);
            }
            state.UpdateUnreadCounter(res, count);
            return(count);
        }