示例#1
0
        /// <summary>
        /// Add a List of recently Opened Files to the Menu
        /// </summary>
        /// <param name="menu"></param>
        public void UpdateRecentFileMenu(System.Windows.Forms.ToolStripMenuItem menu)
        {
            menu.DropDownItems.Clear();

            string[] files = Helper.WindowsRegistry.GetRecentFiles();
            foreach (string file in files)
            {
                if (System.IO.File.Exists(file))
                {
                    string sname = file;
                    if (sname.Length > MAX_FILENAME_LENGTH)
                    {
                        sname = "..." + sname.Substring(file.Length - MAX_FILENAME_LENGTH, MAX_FILENAME_LENGTH);
                    }

                    System.Windows.Forms.ToolStripMenuItem mbi = new System.Windows.Forms.ToolStripMenuItem(sname);
                    mbi.Tag    = file;
                    mbi.Click += new EventHandler(OpenRecent);
                    System.Windows.Forms.KeysConverter kc = new KeysConverter();

                    LoadFileWrappersExt.SetShurtcutKey(mbi, GetShortCut(menu.DropDownItems.Count + 1));

                    menu.DropDownItems.Add(mbi);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Add one Dock to the List
        /// </summary>
        /// <param name="c"></param>
        /// <param name="first"></param>
        void AddDockItem(Ambertation.Windows.Forms.DockPanel c, bool first)
        {
            ToolStripMenuItem mi = new ToolStripMenuItem(c.Text);

            if (first)
            {
                miWindow.DropDownItems.Add("-");
            }
            mi.Image = c.TabImage;

            mi.Click  += new EventHandler(Activate_miWindowDocks);
            mi.Tag     = c;
            mi.Checked = c.IsOpen;

            if (c.Tag != null)
            {
                if (c.Tag is System.Windows.Forms.Shortcut)
                {
                    LoadFileWrappersExt.SetShurtcutKey(mi, (System.Windows.Forms.Shortcut)c.Tag);
                }
            }

            /*c.VisibleChanged += new EventHandler(CloseDockControl);
             * c.Closed += new EventHandler(CloseDockControl);*/
            c.OpenedStateChanged += new EventHandler(CloseDockControl);
            c.Tag = mi;

            miWindow.DropDownItems.Add(mi);
        }
示例#3
0
        /// <summary>
        /// Tries to load the IWrapperFactory from the passed File
        /// </summary>
        /// <param name="file">The File where to look in</param>
        /// <returns>null or a Wrapper Factory</returns>
        public static void LoadToolFactory(string file, LoadFileWrappersExt lfw)
        {
            object o = LoadPlugin(file, typeof(IToolFactory), lfw);

            if (o != null)
            {
                lfw.treg.Register((IToolFactory)o);
            }
        }
示例#4
0
        internal PluginManager(
            ToolStripMenuItem toolmenu,
            ToolStrip tootoolbar,
            TD.SandDock.TabControl dc,
            LoadedPackage lp,
            SteepValley.Windows.Forms.ThemedControls.XPTaskBox defaultactiontaskbox,
            ContextMenuStrip defaultactionmenu,
            SteepValley.Windows.Forms.ThemedControls.XPTaskBox toolactiontaskbox,
            SteepValley.Windows.Forms.ThemedControls.XPTaskBox extactiontaskbox,
            ToolStrip actiontoolbar,
            Ambertation.Windows.Forms.DockContainer docktooldc,
            ToolStripMenuItem helpmenu,
            SimPe.Windows.Forms.ResourceListViewExt lv
            ) : base(true)
        {
            Splash.Screen.SetMessage("Loading Type Registry");
            SimPe.PackedFiles.TypeRegistry tr = new SimPe.PackedFiles.TypeRegistry();

            FileTable.ProviderRegistry    = tr;
            FileTable.ToolRegistry        = tr;
            FileTable.WrapperRegistry     = tr;
            FileTable.CommandLineRegistry = tr;
            FileTable.HelpTopicRegistry   = tr;
            FileTable.SettingsRegistry    = tr;

            wloader = new LoadFileWrappersExt();

            this.LoadDynamicWrappers();
            this.LoadStaticWrappers();
            this.LoadMenuItems(toolmenu, tootoolbar);

            Splash.Screen.SetMessage("Loading Listeners");
            wloader.AddListeners(ref ChangedGuiResourceEvent);
            //dc.ActiveDocumentChanged += new TD.SandDock.ActiveDocumentEventHandler(wloader.ActiveDocumentChanged);
            //lp.AfterFileLoad += new SimPe.Events.PackageFileLoadedEvent(wloader.ChangedPackage);


            Splash.Screen.SetMessage("Loading Default Actions");
            LoadActionTools(defaultactiontaskbox, actiontoolbar, defaultactionmenu, GetDefaultActions(lv));
            Splash.Screen.SetMessage("Loading External Tools");
            LoadActionTools(toolactiontaskbox, actiontoolbar, defaultactionmenu, LoadExternalTools());
            Splash.Screen.SetMessage("Loading Default Tools");
            LoadActionTools(extactiontaskbox, actiontoolbar, null, null);

            Splash.Screen.SetMessage("Loading Docks");
            LoadDocks(docktooldc, lp);
            Splash.Screen.SetMessage("Loading Help Topics");
            lht = new LoadHelpTopics(helpmenu);

            Splash.Screen.SetMessage("Loaded Help Topics");
        }
示例#5
0
        /// <summary>
        /// Loads the First Class form a File implementing the passed Interface
        /// </summary>
        /// <param name="file">The File the Class is stored in</param>
        /// <param name="interfaceType">The Type of the FIle</param>
        /// <returns>The Class Implementing the given type or null if none was found</returns>
        public static object LoadPlugin(string file, Type interfaceType, LoadFileWrappersExt lfw)
        {
            if (lfw.ignore.Contains(System.IO.Path.GetFileName(file).Trim().ToLower()))
            {
                return(null);
            }
            if (!File.Exists(file))
            {
                return(null);
            }
            if (!Helper.CanLoadPlugin(file))
            {
                return(null);
            }

            AssemblyName myAssemblyName;

            try
            {
                myAssemblyName = AssemblyName.GetAssemblyName(file);
            }
            catch
            {
                return(null);
            }

            Assembly a = System.Reflection.Assembly.LoadFrom(file);

            try
            {
                Type[] mytypes = a.GetTypes();

                foreach (Type t in mytypes)
                {
                    Type mit = t.GetInterface(interfaceType.FullName);
                    if (mit != null)

                    {
                        object obj = Activator.CreateInstance(t);
                        return(obj);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            return(null);
        }
示例#6
0
        /// <summary>
        /// Add one single MenuItem (and all needed Parents)
        /// </summary>
        /// <param name="item"></param>
        /// <param name="parts"></param>
        public static void AddMenuItem(ref SimPe.Events.ChangedResourceEvent ev, ToolStripItemCollection parent, ToolMenuItemExt item, string[] parts)
        {
            System.Reflection.Assembly a = typeof(LoadFileWrappersExt).Assembly;

            for (int i = 0; i < parts.Length - 1; i++)
            {
                string            name = SimPe.Localization.GetString(parts[i]);
                ToolStripMenuItem mi   = null;
                //find an existing Menu Item
                if (parent != null)
                {
                    foreach (ToolStripMenuItem oi in parent)
                    {
                        if (oi.Text.ToLower().Trim() == name.ToLower().Trim())
                        {
                            mi = oi;
                            break;
                        }
                    }
                }
                if (mi == null)
                {
                    mi = new ToolStripMenuItem(name);

                    if (parent != null)
                    {
                        System.IO.Stream imgstr = a.GetManifestResourceStream("SimPe." + parts[i] + ".png");
                        if (imgstr != null)
                        {
                            mi.Image = System.Drawing.Image.FromStream(imgstr);
                        }
                        parent.Insert(0, mi);
                    }
                }

                parent = mi.DropDownItems;
            }

            if (item.ToolExt != null)
            {
                LoadFileWrappersExt.SetShurtcutKey(item, item.ToolExt.Shortcut);
                item.Image = item.ToolExt.Icon;
                //item.ToolTipText = item.ToolExt.ToString();
            }

            parent.Add(item);
            ev += new SimPe.Events.ChangedResourceEvent(item.ChangeEnabledStateEventHandler);
            item.ChangeEnabledStateEventHandler(item, new SimPe.Events.ResourceEventArgs(null));
        }
示例#7
0
        /// <summary>
        /// Load all Wrappers found in the Plugins Folder
        /// </summary>
        void LoadDynamicWrappers()
        {
            Splash.Screen.SetMessage("Loading Dynamic Wrappers");
            string folder = Helper.SimPePluginPath;

            if (!System.IO.Directory.Exists(folder))
            {
                return;
            }

            string[] files = System.IO.Directory.GetFiles(folder, "*.plugin.dll");

            foreach (string file in files)
            {
                Splash.Screen.SetMessage("Loading " + System.IO.Path.GetFileName(file).Replace(".dll", "").Replace(".", " "));
#if !DEBUG
                try
#endif
                {
                    LoadFileWrappersExt.LoadWrapperFactory(file, wloader);
                }
#if !DEBUG
                catch (Exception ex)
                {
                    Exception e = new Exception("Unable to load WrapperFactory", new Exception("Invalid Interface in " + file, ex));
                    LoadFileWrappersExt.LoadErrorWrapper(new SimPe.PackedFiles.Wrapper.ErrorWrapper(file, ex), wloader);
                    Helper.ExceptionMessage(ex);
                }
#endif

#if !DEBUG
                try
#endif
                {
                    LoadFileWrappersExt.LoadToolFactory(file, wloader);
                }
#if !DEBUG
                catch (Exception ex)
                {
                    Exception e = new Exception("Unable to load ToolFactory", new Exception("Invalid Interface in " + file, ex));
                    Helper.ExceptionMessage(e);
                }
#endif
            }
            //wloader.AddMenuItems(this.miPlugins, new EventHandler(ToolChangePacakge));
            Splash.Screen.SetMessage("Loaded Dynamic Wrappers");
        }
示例#8
0
        /// <summary>
        /// Create a new Instance
        /// </summary>
        /// <param name="tool"></param>
        public ActionToolDescriptor(SimPe.Interfaces.IToolAction tool)
        {
            //this.lp = lp;
            this.tool = tool;

            ll      = new SteepValley.Windows.Forms.XPLinkedLabelIcon();
            ll.Name = tool.ToString();
            if (tool.Icon != null)
            {
                if (tool.Icon is System.Drawing.Bitmap)
                {
                    ll.Icon = System.Drawing.Icon.FromHandle(((System.Drawing.Bitmap)tool.Icon).GetHicon());
                }
            }
            ll.Text     = SimPe.Localization.GetString(tool.ToString());
            ll.LinkArea = new System.Windows.Forms.LinkArea(0, ll.Text.Length);
            ll.Font     = new System.Drawing.Font("Verdana", ll.Font.Size, System.Drawing.FontStyle.Bold);
            ll.Height   = 16;
            ll.AutoSize = true;

            ll.LinkClicked += new EventHandler(LinkClicked);

            mi        = new System.Windows.Forms.ToolStripMenuItem(ll.Text);
            mi.Click += new EventHandler(LinkClicked);
            mi.Image  = tool.Icon;
            LoadFileWrappersExt.SetShurtcutKey(mi, tool.Shortcut);
            mi.EnabledChanged += new EventHandler(mi_EnabledChanged);
            mi.CheckedChanged += new EventHandler(mi_CheckedChanged);

            if (tool.Icon != null)
            {
                bi             = new MyButtonItem("action." + tool.GetType().Namespace + "." + tool.GetType().Name);
                bi.Text        = "";
                bi.ToolTipText = ll.Text;
                bi.Image       = tool.Icon;
                //bi.BuddyMenu = mi;

                bi.Checked = mi.Checked;
                bi.Enabled = mi.Enabled;
                bi.Click  += new EventHandler(LinkClicked);
            }

            //Make Sure the Action is disabled on StartUp
            ChangeEnabledStateEventHandler(null, new SimPe.Events.ResourceEventArgs(lp));
        }
示例#9
0
        void LoadMenuItems(ToolStripMenuItem toolmenu, ToolStrip tootoolbar)
        {
            ToolMenuItemExt.ExternalToolNotify chghandler = new ToolMenuItemExt.ExternalToolNotify(ClosedToolPluginHandler);
            IToolExt[] toolsp = (IToolExt[])FileTable.ToolRegistry.ToolsPlus;
            foreach (IToolExt tool in toolsp)
            {
                string   name  = tool.ToString();
                string[] parts = name.Split("\\".ToCharArray());
                name = Localization.GetString(parts[parts.Length - 1]);
                Splash.Screen.SetMessage("Loading " + name);
                ToolMenuItemExt item = new ToolMenuItemExt(name, tool, chghandler);

                LoadFileWrappersExt.AddMenuItem(ref ChangedGuiResourceEvent, toolmenu.DropDownItems, item, parts);
            }

            ITool[] tools = FileTable.ToolRegistry.Tools;
            foreach (ITool tool in tools)
            {
                string name = tool.ToString().Trim();
                if (name == "")
                {
                    continue;
                }

                string[] parts = name.Split("\\".ToCharArray());
                name = Localization.GetString(parts[parts.Length - 1]);
                Splash.Screen.SetMessage("Loading " + name);
                ToolMenuItemExt item = new ToolMenuItemExt(name, tool, chghandler);

                LoadFileWrappersExt.AddMenuItem(ref ChangedGuiResourceEvent, toolmenu.DropDownItems, item, parts);
            }

            Splash.Screen.SetMessage("Creating Toolbar");
            LoadFileWrappersExt.BuildToolBar(tootoolbar, toolmenu.DropDownItems);
            //EnableMenuItems(null);
            Splash.Screen.SetMessage("Loaded Menu Items");
        }
示例#10
0
 public static void LoadErrorWrapper(SimPe.PackedFiles.Wrapper.ErrorWrapper w, LoadFileWrappersExt lfw)
 {
     lfw.reg.Register(w);
 }