Click here to Skip to main content
12,068,108 members (65,020 online)
Click here to Skip to main content

Stats

41.4K views
1.3K downloads
106 bookmarked
Posted

Plug-in Framework

, 14 Sep 2010 CPOL
Basic framework for building desktop plug-in applications.
PluginFramework.zip
PluginFramework
Demo
bin
Debug
Plugins
Release
Plugins
Forms
Properties
Settings.settings
DemoFormPlugin
Properties
Settings.settings
DemoUserControlPlugin
Properties
Settings.settings
MBG.Extensions
Collections
Controls
Core
Data
Math
Properties
Xml
MBG.IO
Properties
PluginFramework.Attributes
Properties
PluginFramework.Controls
Properties
Resources
Icons
SettingsIcon.ico
TreeIcon.ico
Images
SettingsImage.png
TreeImage.png
PluginFramework.Interface
Properties
PluginFramework.Utilities
Properties
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PluginFramework.Interface;
using PluginFramework.Utilities;

namespace PluginFramework.Controls
{
    public partial class SettingsForm : Form
    {
        private IDictionary<string, PluginInfo> plugins = null;
        private Dictionary<string, ISettingsPlugin> settingsPlugins = new Dictionary<string, ISettingsPlugin>();
        private ImageList imageList = new ImageList();

        public SettingsForm(IDictionary<string, PluginInfo> plugins)
        {
            InitializeComponent();

            this.plugins = plugins;
            LoadSettings();

            if (settingsPlugins.Count == 0)
            {
                MessageBox.Show(
                    "None of the plugins have any settings to configure",
                    "No Settings",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Exclamation);
                this.Dispose();
            }
        }

        private void LoadSettings()
        {
            foreach (KeyValuePair<string, PluginInfo> kv in plugins)
            {
                ISettingsPlugin settingsPlugin = PluginHelper.GetSettingsPlugin(kv.Value.AssemblyPath);
                if (settingsPlugin != null)
                {
                    settingsPlugins.Add(kv.Key, settingsPlugin);
                }
            }

            foreach (KeyValuePair<string, ISettingsPlugin> kv in settingsPlugins)
            {
                pluginTreeView.AddSettingsPlugin(plugins[kv.Key], kv.Value);
            }
        }

        private void pluginTreeView_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (e.Node.Tag == null)
            { return; }

            ISettingsPlugin settingsPlugin = e.Node.Tag as ISettingsPlugin;

            UserControl control = settingsPlugin.Content;
            contentPanel.Controls.Clear();
            contentPanel.Controls.Add(control);
            control.Dock = DockStyle.Fill;
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

vnmatt
Software Developer (Senior) Freelancer
Vietnam Vietnam
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.160208.1 | Last Updated 14 Sep 2010
Article Copyright 2010 by vnmatt
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid