pascalabcnet/VisualPascalABCNET/DS/PluginsController/PluginsController.cs
AlexanderZemlyak 342375501b
New languages engine (#3120)
* Implement first version of languages interfaces and classes

ParsersController заменен на LanguageProvider.

* Update ParserTools.csproj

* Update RemoteCompiler.cs

* Update TestRunner

* Rename LanguageIntegrator project to Languages

* Update TestRunner

* Rename Parsers folder

* Rename PascalABCParser.dll to PascalABCLanguage.dll

* Reorganise LanguageIntegrator and rename DocTagsParser

* Update Release Generators

* Update language loading messages

* Update linux version

* Move BaseParser fields to ILanguage interface

* Revert "Update Release Generators"

This reverts commit 26a991c71b81e643d9fbd9a815ddca222768dda9.

* Revert "Rename PascalABCParser.dll to PascalABCLanguage.dll"

* Clean the mess in parser folders

* Organize namespaces properly

* Revert "Rename LanguageIntegrator project to Languages"

* Add new enclosing folders for standard languages

* Organize namespaces of LanguageIntegrator properly

* Rename StandardLanguages to Languages

* Comment the rest of Visual basic source code

* Update OutputPath in pascal parser project

* Move BaseParser methods to IParser

* Restore Pascal parser project initial structure

* Add PascalLanguage project

* Move SyntaxTreeConverters project to Languages\Pascal folder

* Rename SemanticRules in parser project

* Rename Errors1 to Errors in parser project

* Delete LambdaConverter dll from installer

* Update language integrator to load *Language.dll files

* Move lambda converter project to pascal lanuage dir

* Revert "Delete LambdaConverter dll from installer"

This reverts commit dd56f559ebe4f8c4c5c33752d44e6953001b96a5.

* Switch off VBNETParser building

* Delete syntax tree converters controller

* Delete lambda converter dll from repository

* Reorganize syntax tree to semantic tree conversion stage

* Add BaseLanguage class to make language initialization more neat

* Delete syntax tree post processors entity from ILanguage and refactor ABCStatistics calls

* Add new IDocParser interface for documentation comments parser

* Clean up folders

* Add helper data structures to reduce parameters amount in CompileInterface and CompileImplementation

* Add documentation to language classes

* Move Union struct in global namespace and project (ParserTools)

* Add more comments and a safe select language method

* Rename SemanticRules class

* Fix directives format null bug

* Add System.Linq ref to LanguageIntegrator

* Delete SyntaxToSemanticTreeConverter interface

* Add BaseSyntaxTreeConverter

* Call safe select language method in intellisence

* Delete source files providers from parsers

* Rename GetSyntaxTree method

* Change Prebuild tree to be virtual - not abstract

* Refresh documentation a bit

* Add temporary language check for ABCHealth button

* Add parser reference to parser tools

* Move current compilation unit assigning higher to avoid bug with unit check

* Delete null DirectiveInfo's and refactor directives' code

* Add a few more comments
2024-05-25 12:26:32 +03:00

205 lines
9.1 KiB
C#

// Copyright (c) Ivan Bondarev, Stanislav Mikhalkovich (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace VisualPascalABCPlugins
{
public class PluginLoadingError : Exception
{
public Exception Error;
public string FileName;
public PluginLoadingError(string FileName, Exception e)
:base(FileName)
{
Error = e;
this.FileName = FileName;
}
public override string ToString()
{
return string.Format(PascalABCCompiler.StringResources.Get("VPPC_PLUGIN_{0}_LOADING_ERROR_{1}"), Path.GetFileName(FileName),Error);
}
}
public class PluginsController
{
private IWorkbench workbench;
private List<IVisualPascalABCPlugin> plugins = new List<IVisualPascalABCPlugin>();
public List<IVisualPascalABCPlugin> Plugins
{
get { return plugins; }
}
private List<PluginLoadingError> errorList = new List<PluginLoadingError>();
public List<PluginLoadingError> ErrorList
{
get { return errorList; }
}
public System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem = null;
public System.Windows.Forms.ToolStrip ToolStrip = null;
public IVisualEnvironmentCompiler VisualEnvironmentCompiler = null;
public PluginsController(IVisualEnvironmentCompiler VisualEnvironmentCompiler)
{
this.VisualEnvironmentCompiler = VisualEnvironmentCompiler;
}
public PluginsController(IVisualEnvironmentCompiler VisualEnvironmentCompiler,System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem, System.Windows.Forms.ToolStrip ToolStrip, IWorkbench workbench)
{
this.ToolStripMenuItem = ToolStripMenuItem;
this.ToolStrip = ToolStrip;
this.VisualEnvironmentCompiler = VisualEnvironmentCompiler;
this.workbench = workbench;
}
bool AddMenuSeparator = false;
bool AddToolBarSeparator = false;
delegate void AddInGuiDelegate(IVisualPascalABCPlugin Plugin);
private void AddInGUI(IVisualPascalABCPlugin Plugin)
{
if (ToolStripMenuItem == null) return;
List<IPluginGUIItem> MenuItems=new List<IPluginGUIItem>(),ToolBarItems=new List<IPluginGUIItem>();
Plugin.GetGUI(MenuItems, ToolBarItems);
if (MenuItems.Count > 1 && (ToolStripMenuItem.DropDownItems.Count > 0 && (ToolStripMenuItem.DropDownItems[ToolStripMenuItem.DropDownItems.Count - 1].Tag is IPluginGUIItem)))
{
ToolStripMenuItem.DropDownItems.Add(new System.Windows.Forms.ToolStripSeparator());
AddMenuSeparator = false;
}
if (MenuItems.Count > 0)
{
if (AddMenuSeparator)
{
AddMenuSeparator = false;
ToolStripMenuItem.DropDownItems.Add(new System.Windows.Forms.ToolStripSeparator());
}
foreach (IPluginGUIItem Item in MenuItems)
{
System.Windows.Forms.ToolStripMenuItem menuItem = new System.Windows.Forms.ToolStripMenuItem();
menuItem.Image = Item.Image;
menuItem.ImageTransparentColor = Item.ImageTransparentColor;
menuItem.Text = Item.Text;
//menuItem.ToolTipText = Item.Hint;
menuItem.Tag = Item;
Item.menuItem = menuItem;
menuItem.ShortcutKeys = Item.ShortcutKeys;
if (Item.ShortcutKeyDisplayString != null)
menuItem.ShortcutKeyDisplayString = Item.ShortcutKeyDisplayString;
menuItem.Click += new EventHandler(item_Click);
ToolStripMenuItem.DropDownItems.Add(menuItem);
PascalABCCompiler.StringResources.SetTextForObject(menuItem, "");
}
}
if (MenuItems.Count > 1)
AddMenuSeparator = true;
if (ToolStrip.Items.Count > 0 && !(ToolStrip.Items[ToolStrip.Items.Count - 1] is System.Windows.Forms.ToolStripSeparator) && ToolBarItems.Count > 1 && ((ToolStrip.Items[ToolStrip.Items.Count - 1].Tag is IPluginGUIItem)))
{
ToolStrip.Items.Add(new System.Windows.Forms.ToolStripSeparator());
AddToolBarSeparator = false;
}
if (ToolBarItems.Count > 0)
{
if (AddToolBarSeparator)
{
AddToolBarSeparator = false;
ToolStrip.Items.Add(new System.Windows.Forms.ToolStripSeparator());
}
foreach (IPluginGUIItem Item in ToolBarItems)
{
System.Windows.Forms.ToolStripButton button = null;
button = new System.Windows.Forms.ToolStripButton();
button.Image = Item.Image;
button.ImageTransparentColor = Item.ImageTransparentColor;
//button.Text = Item.Text;
button.ToolTipText = Item.Hint;
button.Click += new EventHandler(button_Click);
button.Tag = Item;
Item.toolStripButton = button;
ToolStrip.Items.Add(button);
PascalABCCompiler.StringResources.SetTextForObject(button, "");
}
}
if (ToolBarItems.Count > 1)
AddToolBarSeparator = true;
//ToolStrip.Refresh();
if (ToolStripMenuItem.Visible == false)
ToolStripMenuItem.Visible = true;
if (Plugin is IExtendedVisualPascalABCPlugin iex)
iex.AfterAddInGUI();
}
void button_Click(object sender, EventArgs e)
{
((IPluginGUIItem)((System.Windows.Forms.ToolStripButton)sender).Tag).Execute();
}
void item_Click(object sender, EventArgs e)
{
((IPluginGUIItem)((System.Windows.Forms.ToolStripItem)sender).Tag).Execute();
}
public void AddPlugins()
{
AddPlugins(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName));
}
public void AddPlugins(string DirectoryName)
{
DirectoryInfo di = new DirectoryInfo(DirectoryName);
FileInfo[] dllfiles = di.GetFiles("*.dll");
System.Reflection.Assembly assembly = null;
VisualPascalABCPlugins.IVisualPascalABCPlugin Plugin;
foreach (FileInfo fi in dllfiles)
{
switch (fi.Name.ToLower())
{
case "avalondock.dll":
case "codecompletion.dll":
case "compiler.dll":
case "compilertools.dll":
case "debuggercore.dll":
case "netgenerator.dll":
case "treeconverter.dll":
case "pascalabcparser.dll":
case "syntaxtree.dll":
case "semantictree.dll":
case "weifenluo.winformsui.docking.dll":
case "pluginssupport.dll":
case "localization.dll":
case "pascallanguage.dll":
continue;
}
if (fi.Name.StartsWith("NETXP.", StringComparison.InvariantCultureIgnoreCase) || fi.Name.StartsWith("Mono.", StringComparison.InvariantCultureIgnoreCase) || fi.Name.StartsWith("ICSharpCode.", StringComparison.InvariantCultureIgnoreCase))
continue;
try
{
assembly = System.Reflection.Assembly.LoadFile(fi.FullName);
try
{
Type[] types = assembly.GetTypes();
foreach (Type type in types)
{
if (type.Name.IndexOf("VisualPascalABCPlugin") >= 0 && type.IsClass)
{
Object obj = Activator.CreateInstance(type, workbench);
if (obj is VisualPascalABCPlugins.IVisualPascalABCPlugin)
{
Plugin = obj as VisualPascalABCPlugins.IVisualPascalABCPlugin;
Plugins.Add(Plugin);
VisualEnvironmentCompiler.BeginInvoke(new AddInGuiDelegate(AddInGUI), Plugin);
}
}
}
}
catch (Exception e)
{
ErrorList.Add(new PluginLoadingError(fi.FullName, e));
}
}
catch (Exception e)
{
//если dll не нетовская
}
}
}
}
}