More general help on creating editor windows

Discussions related to SoftPro Select user interface development.

Moderator: Phil Barton

Post Reply
czentman
Posts: 157
Joined: Tue Dec 02, 2008 12:02 pm

More general help on creating editor windows

Post by czentman »

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);

}
}


}
czentman
Posts: 157
Joined: Tue Dec 02, 2008 12:02 pm

Re: More general help on creating editor windows

Post by czentman »

I got it working but I have the editorControl declared to be set as object. What's the real thing to set it to? But it all looks like it runs so far so that's good.
Hadi Chemaly

Re: More general help on creating editor windows

Post by Hadi Chemaly »

As the comment in method OnCreateControl() states, editorControl is simply a private member (of the MyEditorPane class) of type System.Windows.Forms.Control or whatever type derived from Control that you want to create. I'm not sure I understand your issue about "myEditorPane" nor do I see this variable declared anywhere in your code; I'm guessing you figured it out, otherwise let me know and I will gladly help further.

As far as GUIDs are concerned, it doesn't really matter whether you define them in the ctd file or not, it's a matter of preference. Depending on the complexity of your packages, if you need to use those same GUIDs in different places, it would make sense to define them once in the ctd and then reference them using the designer generated GuidString.

The ctd is the command table definition file for your package. It is where you describe the UI elements of your package (ribbon tabs and button, quick access toolbar, application menu, context menus, toolbars etc.) as well as associated and independent commands (e.g. ribbon button A opens the MyEditorPane window, shortcut Ctrl+I+E launches internet explorer, etc.).
Post Reply