Exemplo n.º 1
0
        protected void RunTranslate(BaseItem item)
        {
            try
            {
                _activeItem = item;
                _failed = false;
                _viewer.Visible = false;
                _builders.Clear();

                lblCaption.Text = string.Empty;
                btnRefresh.Visible = false;
                if (item == null)
                {
                    lblPleaseWait.Text = string.Empty;
                }
                else
                {
                    lblPleaseWait.Text = "Please wait...";
                }

                if (item != null && !GetHandledTypes().Contains(item.GetType())) return;

                // We're on the main thread. We're using proper threads instead of
                // BackgroundWorkers so we can safely abort them. (The async mode
                // of GViewer does not abort quickly enough)
                if (_thread != null && _thread.ThreadState != ThreadState.Stopped)
                {
                    _timer.Change(Timeout.Infinite, 100);
                    _thread.Abort();
                    _thread = null;
                }

                if (item != null)
                {
                    _thread = new Thread(new ParameterizedThreadStart(thread_doWork));
                    _thread.IsBackground = true;
                    _thread.Priority = ThreadPriority.AboveNormal;

                    _logView.Debug("New thread:" + _thread.ManagedThreadId);

                    _thread.Start(item);
                    _timer.Change(0, 100);
                }
            }
            catch (Exception exc)
            {
                if (_logView.LogCatchAll(exc, "Unexpected plugin error")) throw;
            }
        }
Exemplo n.º 2
0
        internal void BroadcastItemChange(object sender, BaseItem item)
        {
            foreach (KeyValuePair<string, DockContent> pair in _windows)
            {
                if (pair.Value is IActiveItemViewer)
                {
                    if (pair.Value is IWindowPlugin)
                    {
                        List<Type> types = (pair.Value as IWindowPlugin).GetHandledTypes();

                        if (item == null)
                        {
                            CachedSet(pair.Value, item, true);
                        }
                        else if (types != null && types.Contains(item.GetType()))
                        {
                            BaseItem currentItem = (pair.Value as IActiveItemViewer).GetActiveItem();

                            if (item != currentItem)
                            {
                                CachedSet(pair.Value, item, false);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        public void UpdateContextMenu(ContextMenuStrip contextMenu, BaseItem item)
        {
            // The context menu needs to be updated depending on the type of the item.
            if (_contextMenuIndex.ContainsKey(contextMenu))
            {
                // We've been here already, so clear the menu below this point.
                int defaultCount = _contextMenuIndex[contextMenu];
                for (int i = contextMenu.Items.Count - 1; i >= defaultCount; i--)
                {
                    contextMenu.Items.RemoveAt(i);
                }
            }
            else
            {
                _contextMenuIndex.Add(contextMenu, contextMenu.Items.Count);
            }

            if (item == null) return;

            // The rest of the menu is context sensitive on the underlying BaseItem.
            Type type = item.GetType();
            if (_contextOptions.ContainsKey(type))
            {
                List<ToolStripMenuItem> list = _contextOptions[type];
                if (list.Count > 0)
                {
                    if (contextMenu.Items.Count > 0) contextMenu.Items.Add(new ToolStripSeparator());
                    foreach (ToolStripMenuItem mi in list)
                    {
                        contextMenu.Items.Add(mi);

                        // Hang onto the item as well for context clicks.
                        ((MenuInfo)mi.Tag).Item = item;
                    }
                }
            }

            // Add any items that will always be at the end.
            if (contextMenu.Items.Count > 0) contextMenu.Items.Add(new ToolStripSeparator());
            contextMenu.Items.Add(_addToFavouritesMI);

            // Make sure the tags are up to date for any menu function to use.
            (_addToFavouritesMI.Tag as MenuInfo).Item = item;
        }