Пример #1
0
        private void LoadIcon(MirandaPlugin owner, MenuItemDeclarationAttribute attrib)
        {
            try
            {
                if (!attrib.HasIcon)
                    return;

                if (attrib.UseEmbeddedIcon)
                {
                    using (Stream stream = owner.GetType().Assembly.GetManifestResourceStream(attrib.IconID))
                    {
                        if (stream != null)
                            Icon = IconImageCache.Singleton.GetStreamedIcon(stream).Handle;
                        else
                            Debug.Fail("Embedded icon not found.");
                    }
                }
                else
                    Icon = Skin.LoadIcon(int.Parse(attrib.IconID));
            }
            catch
            {
                this.Icon = IntPtr.Zero;
            }
        }
        public void FindTest()
        {
            string tag = "tag";

            MenuItemDeclarationCollection list = new MenuItemDeclarationCollection();
            MenuItemDeclarationAttribute attrib = new MenuItemDeclarationAttribute("a", "b");
            attrib.Tag = tag;
            list.Add(attrib);

            MenuItemDeclarationReadOnlyCollection target = new MenuItemDeclarationReadOnlyCollection(list);

            MenuItemDeclarationAttribute expected = attrib;
            MenuItemDeclarationAttribute actual = target.Find(tag);

            Assert.AreEqual(expected, actual, "FindByTag did not return the expected value.");
            Assert.AreEqual(null, target.Find("foo"), "FindByTag return wrong result.");
        }
Пример #3
0
        public CLISTMENUITEM(MirandaPlugin owner, MenuItemDeclarationAttribute attrib)
        {
            if (owner == null)
                throw new ArgumentNullException("owner");

            if (attrib == null)
                throw new ArgumentNullException("attrib");

            this.Text = attrib.Text;
            this.Service = attrib.Service;
            this.ContactOwner = attrib.OwningModule;
            this.Flags = (uint)attrib.Flags;
            this.PopUpMenu = attrib.PopUpMenu;
            this.PopUpPosition = attrib.PopUpPosition;
            this.Position = attrib.Position;
            this.HotKey = (uint)attrib.HotKey;
            this.Icon = IntPtr.Zero;
            this.Size = Marshal.SizeOf(typeof(CLISTMENUITEM));

            LoadIcon(owner, attrib);
        }
Пример #4
0
        /// <summary>
        /// Initializes the managed menu for managed plugins. This menu, unlike Miranda's, supports item removal.
        /// </summary>
        private void InitializeManagedMenu()
        {
            ManagedMainMenu = new ManagedMainMenu();

            MenuItemDeclarationAttribute item = new MenuItemDeclarationAttribute(TextResources.UI_Text_ShowManagedMainMenu, ShowManagedMenuServiceName);
            item.IsContactMenuItem = false;
            item.HasIcon = true;
            item.UseEmbeddedIcon = true;
            item.IconID = "Virtuoso.Miranda.Plugins.Resources.ShowManagedMenuItems.ico";

            // Add a proxy item for the managed menu into M's menu (on behalf of a dummy plugin)
            MirandaContext.Current.ContactList.AddMenuItem(MirandaPlugin.Hyphen.Singleton, item);
        }
Пример #5
0
        /// <summary>
        /// Populates Miranda's menu with Hyphen's items and initializes managed menu for plugins.
        /// </summary>
        private void InitializeMenu()
        {
            PluginDescriptor descriptor = MirandaPlugin.Hyphen.Singleton.Descriptor;
            ContactList clist = MirandaContext.Current.ContactList;

            // Create services for the items
            HookManager.CreateHook(HookDescriptor.SetUpAndStore(InternalHooks, LoadUnloadPluginsServiceName, descriptor, LoadUnloadPluginsService, HookType.ServiceFunction));
            HookManager.CreateHook(HookDescriptor.SetUpAndStore(InternalHooks, ConfigureModulesServiceName, descriptor, ConfigureModulesService, HookType.ServiceFunction));
            HookManager.CreateHook(HookDescriptor.SetUpAndStore(InternalHooks, ShowManagedMenuServiceName, descriptor, ShowManagedMenuService, HookType.ServiceFunction));
            HookManager.CreateHook(HookDescriptor.SetUpAndStore(InternalHooks, ManagePluginsServiceName, descriptor, ManagePluginsService, HookType.ServiceFunction));

            InitializeManagedMenu();

            MenuItemDeclarationAttribute item = new MenuItemDeclarationAttribute(TextResources.UI_Text_LoadUnloadPlugins, TextResources.UI_Text_Hyphen, LoadUnloadPluginsServiceName);
            item.IsContactMenuItem = false;
            item.HasIcon = true;
            item.UseEmbeddedIcon = true;
            item.IconID = "Virtuoso.Miranda.Plugins.Resources.LoadUnloadPlugins.ico";
            clist.AddMenuItem(MirandaPlugin.Hyphen.Singleton, item);

            item = PluginTasksItem = new MenuItemDeclarationAttribute(TextResources.UI_Text_ManagePlugins, TextResources.UI_Text_Hyphen, ManagePluginsServiceName);
            item.IsContactMenuItem = false;
            item.HasIcon = true;
            item.UseEmbeddedIcon = true;
            item.IconID = "Virtuoso.Miranda.Plugins.Resources.Configure.ico";
            clist.AddMenuItem(MirandaPlugin.Hyphen.Singleton, item);

            item = new MenuItemDeclarationAttribute(TextResources.UI_Text_ConfigureStandaloneModules, TextResources.UI_Text_Hyphen, ConfigureModulesServiceName);
            item.IsContactMenuItem = false;
            item.HasIcon = true;
            item.UseEmbeddedIcon = true;
            item.IconID = "Virtuoso.Miranda.Plugins.Resources.Configure.ico";
            clist.AddMenuItem(MirandaPlugin.Hyphen.Singleton, item);
        }
Пример #6
0
 public static void BeginMenuItemUpdate(MenuItemDeclarationAttribute item)
 {
     VerifyNotNull(item);
     Monitor.Enter(item);
 }
Пример #7
0
        public bool ModifyMenuItem(MirandaPlugin owner, MenuItemDeclarationAttribute menuItem, string text, MenuItemProperties flags, Icon icon, HotKeys hotKey, bool updateItemDescriptor)
        {
            if (owner == null)
                throw new ArgumentNullException("owner");

            if (menuItem == null)
                throw new ArgumentNullException("menuItem");

            if (menuItem.MirandaHandle == IntPtr.Zero)
                throw new ArgumentException("Invalid menu item handle.");

            UnmanagedStructHandle<CLISTMENUITEM> nativeHandle = UnmanagedStructHandle<CLISTMENUITEM>.Empty;

            try
            {
                SynchronizationHelper.BeginMenuItemUpdate(menuItem);

                CLISTMENUITEM nativeItem = new CLISTMENUITEM(owner, menuItem);
                MenuItemModifyFlags modifyFlags = MenuItemModifyFlags.None;

                if (text != null)
                {
                    modifyFlags |= MenuItemModifyFlags.CMIM_NAME;
                    nativeItem.Text = text;

                    if (updateItemDescriptor) menuItem.Text = text;
                }
                if (flags != MenuItemProperties.KeepCurrent)
                {
                    modifyFlags |= MenuItemModifyFlags.CMIM_FLAGS;
                    nativeItem.Flags = (uint)flags;

                    if (updateItemDescriptor) menuItem.Flags = flags;
                }
                if (icon != null)
                {
                    modifyFlags |= MenuItemModifyFlags.CMIM_ICON;
                    nativeItem.Icon = icon.Handle;
                }
                if (hotKey != 0)
                {
                    modifyFlags |= MenuItemModifyFlags.CMIM_HOTKEY;
                    nativeItem.HotKey = (uint)hotKey;
                    if (updateItemDescriptor) menuItem.HotKey = hotKey;
                }

                nativeItem.Flags |= (uint)modifyFlags;

                nativeHandle = new UnmanagedStructHandle<CLISTMENUITEM>(ref nativeItem);
                bool result = MirandaContext.Current.CallService(MirandaServices.MS_CLIST_MODIFYMENUITEM, (UIntPtr)(uint)menuItem.MirandaHandle, nativeHandle.IntPtr) == 0
                    ? true : false;

                Debug.Assert(result);
                return result;
            }
            catch (Exception e)
            {
                throw new MirandaException(TextResources.ExceptionMsg_ErrorWhileCallingMirandaService + e.Message, e);
            }
            finally
            {
                nativeHandle.Free();
                SynchronizationHelper.EndUpdate(menuItem);
            }
        }
Пример #8
0
 public bool ModifyMenuItem(MirandaPlugin owner, MenuItemDeclarationAttribute menuItem, string text, MenuItemProperties flags, Icon icon, HotKeys hotKey)
 {
     return ModifyMenuItem(owner, menuItem, text, flags, icon, hotKey, true);
 }
Пример #9
0
 public bool ModifyMenuItem(MirandaPlugin owner, MenuItemDeclarationAttribute menuItem, Icon icon)
 {
     return ModifyMenuItem(owner, menuItem, null, MenuItemProperties.None, icon, 0, true);
 }
Пример #10
0
 public bool ModifyMenuItem(MirandaPlugin owner, MenuItemDeclarationAttribute menuItem, HotKeys hotKey)
 {
     return ModifyMenuItem(owner, menuItem, null, MenuItemProperties.None, null, hotKey, true);
 }
Пример #11
0
 public bool ModifyMenuItem(MirandaPlugin owner, MenuItemDeclarationAttribute menuItem, MenuItemProperties flags)
 {
     return ModifyMenuItem(owner, menuItem, null, flags, null, 0, true);
 }
Пример #12
0
 public bool ModifyMenuItem(MirandaPlugin owner, MenuItemDeclarationAttribute menuItem, string text)
 {
     return ModifyMenuItem(owner, menuItem, text, MenuItemProperties.None, null, 0, true);
 }
Пример #13
0
        public void AddMenuItem(MirandaPlugin owner, MenuItemDeclarationAttribute item)
        {
            if (owner == null)
                throw new ArgumentNullException("owner");

            if (item == null)
                throw new ArgumentNullException("item");

            string serviceName = item.IsContactMenuItem ? MirandaServices.MS_CLIST_ADDCONTACTMENUITEM : MirandaServices.MS_CLIST_ADDMAINMENUITEM;

            UnmanagedStructHandle<CLISTMENUITEM> nativeHandle = UnmanagedStructHandle<CLISTMENUITEM>.Empty;
            CLISTMENUITEM nativeItem = new CLISTMENUITEM(owner, item);

            try
            {
                nativeHandle = new UnmanagedStructHandle<CLISTMENUITEM>(ref nativeItem);

                IntPtr handle = (IntPtr)MirandaContext.Current.CallService(serviceName, UIntPtr.Zero, nativeHandle.IntPtr,
                    (owner is StandalonePlugin && !item.IsAdditional));

                item.MirandaHandle = handle;
                Debug.Assert(handle != IntPtr.Zero);
            }
            finally
            {
                nativeHandle.Free();
            }
        }