Create extension/plugin using html javascript, vbscript, IronPython, Vb.net and C#
Html Extension need to be in folder:
C:\Users\[username]\Documents\Cato Saelid\Simple Html to Nws\HtmlExt
Best practice will be to create a folder for your extension in "HtmlExt" folder
You use window.external to connect to the object that Simple Html to Nws Plus expose for scripting
/* get referece to editor */
var d=window.external
/*
var t=d.selectstart; // Where Selection starts
var e=d.selectlength; // Selection length
// Select all text in editor
// d.selectall();
// Replace selectd text in editor
d.selectedtext=""Hi from javascript!""
// Get all text
// var t= d.text
// Display Color Dialog with a Color
// return selected color
var c=d.colordialog("#cc3333");
// Display Browse for File Dialog
var f=d.filedialog();
// read a document into doc
var doc=d.readfile(f);
// Show Display Filter Dialog with a filter
// Return filter selected
var ft=d.filterdialog("progid:DXImageTransform.Microsoft.Barn(Duration = 5, Motion = out, Orientation = vertical)");
*/
<?xml version="1.0" encoding="utf-8" ?>
<settings>
<name value="Name for your Extension" />
<icon value="Iconusedbythemenu.ico" />
<document value="Pagename.html" />
<tips value="A tip that are displayed in Menu" />
<selection value="false" />
<height value="780" />
<width value="1080" />
</settings>
IronPython Extension need to be in folder:
C:\Users\[username]\Documents\Cato Saelid\Simple Html to Nws\PythonExt
Best practice will be to create a folder for your extension in "PythonExt" folder
Add Reference To File SHNC.dll and import SHNC
Simple Html to Nws Plus will look for a class with name TextPlugin
Create class TextPlugin(SHNC.ITextPlugin):
import clr
clr.AddReference("System")
clr.AddReference("System.IO")
clr.AddReference("System.ComponentModel")
clr.AddReference("System.Drawing")
clr.AddReference("System.Windows.Forms")
clr.AddReferenceToFile("SHNC.dll")
from System.IO import *
from System.ComponentModel import *
from System.Drawing import *
from System.Windows.Forms import *
import SHNC
class Form1(Form):
def __init__(self):
self.InitializeComponent()
def InitializeComponent(self):
self.components = Container()
#
# Form1
#
self.Name="Form1"
self.Location=Point(15,15)
self.Text='''Simple Text Editor'''
self.Visible=True
self.editor=SHNC.ITextHost
#
# contextMenuStrip1
#
.....................................
............................
class TextPlugin(SHNC.ITextPlugin):
def __init__(self):
self.Menu=ToolStripMenuItem()
self.Menu.Name="MyTexteditor"
self.Menu.Text="My Text editor"
self.Menu.Image=base64toimage(Texteditor1image)
self.Menu.Click += self.Texteditor1menuPressed
self.Name="Texteditor1"
self.UseHaveSelection=False
self.txt=SHNC.ITextHost
def Initialize(self,Host):
self.editor=Host
def Texteditor1menuPressed(self, sender,args):
frmForm1 =Form1()
frmForm1.editor=self.txt
frmForm1.Show()
def base64toimage(str64):
return Bitmap(MemoryStream(Convert.FromBase64String(str64)))
def base64toicon(str64):
return Icon(MemoryStream(Convert.FromBase64String(str64)))
<?xml version="1.0" encoding="utf-8" ?>
<PythonItem ScriptFile="extensionName.py" />
Use Form Designer plugin to create and design the outline for your IronPython extension for Simple Html to Nws Plus
I had never looked at any Python language before I tried to write this plugin for Simple Html to Nws Plus.
The goal was only to have a simple tool to let me design the outline and create the python script for a extension that Simple Html to Nws Plus can load.
That are basicly what this plugin does, not all properties in the property editor are implemented.
VB.net plugin dll need to be in where progam .exe folder\Plugins
Best practice will be to create a folder for your extension in "Plugins" folder
Add Reference To File SHNC.dll and import SHNC
Imports SHNC
Imports System.Windows.Forms
Imports System.ComponentModel.Composition
<Export(GetType(ITextPlugin))>
Public Class SimplePlugin
Implements SHNC.ITextPlugin
Private WithEvents txt As SHNC.ITextHost
Private WithEvents mnu As New ToolStripMenuItem
Private myname As String = "Simple Plugin"
Public Sub Initialize(Host As SHNC.ITextHost) Implements SHNC.ITextPlugin.Initialize
txt = Host
End Sub
Public ReadOnly Property Menu As System.Windows.Forms.ToolStripMenuItem Implements SHNC.ITextPlugin.Menu
Get
Return mnu
End Get
End Property
Public ReadOnly Property Name As String Implements SHNC.ITextPlugin.Name
Get
Return myname
End Get
End Property
Public Sub New()
mnu.Text = myname
mnu.Image = My.Resources.paper_icon
mnu.ToolTipText = "My test plugin"
End Sub
Private Sub mnu_Click(sender As Object, e As System.EventArgs) Handles mnu.Click
' Your code goes here
End Sub
Public ReadOnly Property UseHaveSelection As Boolean Implements SHNC.ITextPlugin.UseHaveSelection
Get
' Return True if menu only should be enabled if we have a selection otherwise set this to false
Return True
End Get
End Property
End Class
C# plugin dll need to be in where progam .exe folder\Plugins
Best practice will be to create a folder for your extension in "Plugins" folder
Add Reference To File SHNC.dll and import SHNC
VB.net to C# coverter Output
using SHNC;
using System.Windows.Forms;
using System.ComponentModel.Composition;
namespace TestCplugin
{
[Export(typeof(ITextPlugin))]
public class SimplePlugin : SHNC.ITextPlugin
{
private SHNC.ITextHost txt;
private ToolStripMenuItem mnu = new ToolStripMenuItem();
private string myname = "Simple Plugin";
public void Initialize(SHNC.ITextHost Host)
{
txt = Host;
}
public System.Windows.Forms.ToolStripMenuItem Menu
{
get
{
return mnu;
}
}
public string Name
{
get
{
return myname;
}
}
public SimplePlugin()
{
mnu.Text = myname;
mnu.Image = global::TestCplugin.Properties.Resource.paper_icon;
mnu.ToolTipText = "My test plugin";
mnu.Click += mnu_Click;
}
private void mnu_Click(object sender, System.EventArgs e)
{
MessageBox.Show(txt.SelectedText);
}
public bool UseHaveSelection
{
get
{
// Return True if menu only should be enabled if we have a selection otherwise set this to false
return true;
}
}
}
}