Example #1
0
        public Plugin(ITrayKitPlugin trayKitPlugin)
        {
            if (trayKitPlugin == null)
            {
                throw new ArgumentNullException(nameof(trayKitPlugin));
            }
            TrayKitPlugin = trayKitPlugin;
            TrayKitPlugin.Commands.CollectionChanged += OnCommandCollectionChanged;

            Enabled = true;
        }
Example #2
0
        private static object GetSettingsContainer(ITrayKitPlugin plugin)
        {
            var pluginType = plugin.GetType();
            var settingsContainerProperty = pluginType.GetProperties().Where(x => Attribute.IsDefined(x, typeof(Base.Settings.TrayKitPluginSettingsContainerAttribute))).FirstOrDefault();

            if (settingsContainerProperty == null)
            {
                return(null);
            }

            var settingsContainerType     = settingsContainerProperty.PropertyType;
            var settingsContainerInstance = pluginType.GetProperty(settingsContainerProperty.Name).GetValue(plugin);

            return(settingsContainerInstance);
        }
        // TODO: Refactor this. Maybe create a ContextMenuItemCreator-Class which creates the items when given a plugin.
        /// <summary>
        /// Creates menu-items for a plugin.
        /// </summary>
        /// <param name="plugin">The plugin which the menu-items should be created for.</param>
        public void ImportPlugin(ITrayKitPlugin plugin)
        {
            if (plugin == null)
            {
                throw new ArgumentNullException(nameof(plugin));
            }

            var isFirstPlugin = !(from ToolStripMenuItem q in Items
                                  where q.Tag.ToString() != BASE_ITEM_TAG
                                  select q).Any();

            var newItemIndex = pluginStartingIndex;

            if (!isFirstPlugin)
            {
                newItemIndex = (from ToolStripMenuItem q in Items
                                where q.Tag.ToString() != BASE_ITEM_TAG
                                select Items.IndexOf(q)).Max() + 1; // + 1 because the new item has to be placed behind the last plugin-item already in the list.
            }

            if (!plugin.Commands.Any())
            {
                AddItem(plugin.Name, plugin.Name, plugin.Name, plugin.Image, true, newItemIndex);
            }
            else if (plugin.Commands.Count == 1)
            {
                var command = plugin.Commands[0];
                AddItem(command.Name, command.Name, command.GetFullCommandKey(), command.Image, true, newItemIndex);
            }
            else
            {
                var pluginItem = AddItem(plugin.Name, plugin.Name, plugin.Name, plugin.Image, false, newItemIndex);
                foreach (var command in (from q in plugin.Commands
                                         orderby q.SortPosition ascending
                                         select q))
                {
                    var commandItem = new ToolStripMenuItem()
                    {
                        Name  = command.Name,
                        Text  = command.Name,
                        Tag   = command.GetFullCommandKey(),
                        Image = command.Image
                    };
                    commandItem.Click += Item_Click;
                    pluginItem.DropDownItems.Add(commandItem);
                }
            }
        }
Example #4
0
        public static PluginSettingList FindPluginSettings(ITrayKitPlugin plugin)
        {
            if (plugin == null)
            {
                throw new ArgumentNullException(nameof(plugin));
            }

            PluginSettingList result     = null;
            var settingContainerInstance = GetSettingsContainer(plugin);

            if (settingContainerInstance != null)
            {
                result = new PluginSettingList();
                var settings = GetSettingsFromSettingsContainer(settingContainerInstance);

                foreach (var setting in settings)
                {
                    result.Add(CreatePluginSetting(setting, settingContainerInstance, plugin));
                }
            }

            return(result);
        }
        public void RemovePlugin(ITrayKitPlugin plugin)
        {
            ToolStripMenuItem menuItem = null;

            if (plugin.Commands.Count == 1)
            {
                var command = plugin.Commands[0];
                menuItem = (from ToolStripMenuItem q in Items
                            where q.Tag.ToString() == command.GetFullCommandKey()
                            select q).FirstOrDefault();
            }
            else
            {
                menuItem = (from ToolStripMenuItem q in Items
                            where q.Tag.ToString() == plugin.Name
                            select q).FirstOrDefault();
            }

            if (menuItem != null)
            {
                Items.Remove(menuItem);
            }
        }
Example #6
0
        public static PluginSettingList FindPluginSettings(ITrayKitPlugin plugin)
        {
            var settings = Utilities.PluginSettingsFinder.FindPluginSettings(plugin);

            return(settings ?? new PluginSettingList());
        }
 public HelloWorldCommand(ITrayKitPlugin plugin)
 {
     Plugin = plugin;
     Image  = SystemIcons.Shield.ToBitmap();
 }
Example #8
0
 private static void SetInstancePropertyValues(object instance, Attribute attribute, ITrayKitPlugin plugin,
                                               object propertyValue, PropertyInfo sourceProperty, object settingsContainer)
 {
     instance.GetType().GetProperty(nameof(IPluginSetting.SettingAttribute)).SetValue(instance, attribute);
     instance.GetType().GetProperty(nameof(IPluginSetting.PluginAssembly)).SetValue(instance, plugin.GetPluginAssemblyName());
     instance.GetType().GetProperty(nameof(PluginSetting <Object> .Value)).SetValue(instance, propertyValue);
     instance.GetType().GetProperty(nameof(IPluginSetting.PropertyName)).SetValue(instance, sourceProperty.Name);
     instance.GetType().GetProperty(nameof(IPluginSetting.PluginSettingsContainer)).SetValue(instance, settingsContainer);
     instance.GetType().GetProperty(nameof(IPluginSetting.SourceSettingProperty)).SetValue(instance, sourceProperty);
 }
Example #9
0
        private static IPluginSetting CreatePluginSetting(PropertyInfo property, object settingsContainer, ITrayKitPlugin plugin)
        {
            var propertyValue = GetSettingPropertyValue(property, settingsContainer);
            var instance      = GetGenericPluginSettingInstance(property);
            var attribute     = property.GetCustomAttribute(typeof(Base.Settings.TrayKitPluginSettingAttribute));

            SetInstancePropertyValues(instance, attribute, plugin, propertyValue, property, settingsContainer);

            return((IPluginSetting)instance);
        }
Example #10
0
 public TwoPlusTwoCommand(ITrayKitPlugin plugin)
 {
     Plugin = plugin;
     Image  = SystemIcons.Question.ToBitmap();
 }
 public static string GetPluginAssemblyName(this ITrayKitPlugin plugin)
 {
     return(plugin?.GetType().Assembly.GetName().Name);
 }
 public static Assembly GetPluginAssembly(this ITrayKitPlugin plugin)
 {
     return(plugin?.GetType().Assembly);
 }
Example #13
0
 public AddNewCommand(ITrayKitPlugin plugin)
 {
     Plugin = plugin;
 }
Example #14
0
 public TrayKitCommand(ITrayKitPlugin plugin)
 {
     Plugin = plugin;
 }