More general help on creating editor windows
Posted: Tue Jan 13, 2009 11:55 am
I went through the SDK documentation and the other topic on this but I still feel pretty in the dark and playing a guessing game of what I'm doing right and/or wrong. I'm getting an error on compilation becuase "editorControl" in my OnCreateControl function is not declared. I can't find the right way to declare it, besides that you wrote to him the function without it being declared. Also the myEditorPane was also not declared but I manually created a userControl and called it MyEditorPane so that doesn't give me an error anymore. I'm pretty lost. I also am not sure where or if I'm supposed to put an editor GUID in the ctd file. Neither the documentation nor your thread about this said anything about modifying the ctd at all so I didn't. Please help!
This is my code so far.
using System.Runtime.InteropServices;
using SoftPro.Select.Shell;
using SoftPro.Select.Shell.Registration;
using SoftPro;
/// <summary>
/// Summary description for MyPackage.
/// </summary>
/// <remarks></remarks>
namespace ShellPackage1
{
[Guid("B151A458-CE14-4913-A327-033726FD5DE9")]
class MyEditorPane : EditorPane
{
public MyEditorPane()
{
this.Title = "My Title";
}
protected override System.Windows.Forms.Control OnCreateControl()
{
// editorControl is a private member of type Control.
if (editorControl == null) {
editorControl = new MyEditorControl();
}
// More initialization code here.
return editorControl;
}
}
[Guid("CAE5A32B-08F1-4770-829D-8CD65BA1D40D")]
class MyEditorFactory : EditorFactory
{
public MyEditorFactory(IServiceProvider sp) : base(sp)
{
}
protected override IWindowPane OnCreateEditor(ref Uri moniker, ref string name, string view, object existingData, EditorCreateFlags flags, ref object data, ref Guid commandUI, ref bool mru)
{
data = null;
//the MyEditor GUID
commandUI = new Guid("B151A458-CE14-4913-A327-033726FD5DE9");
IWindowPane pane = null;
//TODO: parse the moniker to extract fragments if necessary
//pass in moniker data if needed
pane = new MyEditorPane();
name = pane.Title;
data = pane;
return pane;
}
}
/// <summary>
/// Summary description for MyPackage.
/// </summary>
[RegisterPackage("My Company", "My Product", "1.0.0.0", "")]
[RegisterProduct("My Company", "My Product", "1.0", "This is my package.", "")]
[ProvideCommandTable("ClientPhonebook.MyPackage.cto")]
[ProvideEditorFactory(typeof(MyEditorFactory), "My Editor Factory")]
[ProvideEditorExtension(typeof(MyEditorFactory), "sp-select", "mypackage/record", 10)]
[Guid(ClientPhonebook.MyPackage.PackageGuidString)]
partial class MyPackage : Package
{
protected override void OnInitialize()
{
//TODO: Provide package initialization logic here.
this.RegisterHandler(ClientPhonebook.MyPackage.RibbonButton1, this.RibbonButton1_Invoked);
base.RegisterEditorFactory(new MyEditorFactory(this));
// Register more factories here.
//MyBase.RegisterHandler(Package.MyButton, Me.MyButton_Invoked)
// Register more handlers here.
}
private void RibbonButton1_Invoked(object sender, EventArgs e)
{
//Dim shell As IShell = Me.GetService(Of IShell)()
//Shell.OpenToolWindow(GetType(MyToolWindow))
Uri moniker = new Uri("sp-select:///mypackage/record");
IShell shell = GetService<IShell>();
shell.OpenStandardEditor(moniker);
}
}
}
This is my code so far.
using System.Runtime.InteropServices;
using SoftPro.Select.Shell;
using SoftPro.Select.Shell.Registration;
using SoftPro;
/// <summary>
/// Summary description for MyPackage.
/// </summary>
/// <remarks></remarks>
namespace ShellPackage1
{
[Guid("B151A458-CE14-4913-A327-033726FD5DE9")]
class MyEditorPane : EditorPane
{
public MyEditorPane()
{
this.Title = "My Title";
}
protected override System.Windows.Forms.Control OnCreateControl()
{
// editorControl is a private member of type Control.
if (editorControl == null) {
editorControl = new MyEditorControl();
}
// More initialization code here.
return editorControl;
}
}
[Guid("CAE5A32B-08F1-4770-829D-8CD65BA1D40D")]
class MyEditorFactory : EditorFactory
{
public MyEditorFactory(IServiceProvider sp) : base(sp)
{
}
protected override IWindowPane OnCreateEditor(ref Uri moniker, ref string name, string view, object existingData, EditorCreateFlags flags, ref object data, ref Guid commandUI, ref bool mru)
{
data = null;
//the MyEditor GUID
commandUI = new Guid("B151A458-CE14-4913-A327-033726FD5DE9");
IWindowPane pane = null;
//TODO: parse the moniker to extract fragments if necessary
//pass in moniker data if needed
pane = new MyEditorPane();
name = pane.Title;
data = pane;
return pane;
}
}
/// <summary>
/// Summary description for MyPackage.
/// </summary>
[RegisterPackage("My Company", "My Product", "1.0.0.0", "")]
[RegisterProduct("My Company", "My Product", "1.0", "This is my package.", "")]
[ProvideCommandTable("ClientPhonebook.MyPackage.cto")]
[ProvideEditorFactory(typeof(MyEditorFactory), "My Editor Factory")]
[ProvideEditorExtension(typeof(MyEditorFactory), "sp-select", "mypackage/record", 10)]
[Guid(ClientPhonebook.MyPackage.PackageGuidString)]
partial class MyPackage : Package
{
protected override void OnInitialize()
{
//TODO: Provide package initialization logic here.
this.RegisterHandler(ClientPhonebook.MyPackage.RibbonButton1, this.RibbonButton1_Invoked);
base.RegisterEditorFactory(new MyEditorFactory(this));
// Register more factories here.
//MyBase.RegisterHandler(Package.MyButton, Me.MyButton_Invoked)
// Register more handlers here.
}
private void RibbonButton1_Invoked(object sender, EventArgs e)
{
//Dim shell As IShell = Me.GetService(Of IShell)()
//Shell.OpenToolWindow(GetType(MyToolWindow))
Uri moniker = new Uri("sp-select:///mypackage/record");
IShell shell = GetService<IShell>();
shell.OpenStandardEditor(moniker);
}
}
}