General Help on Creating Editor Windows

Discussions related to SoftPro Select user interface development.

Moderator: Phil Barton

Post Reply
roteague
Posts: 292
Joined: Thu Sep 25, 2008 4:49 pm
Location: Honolulu, Hawaii

General Help on Creating Editor Windows

Post by roteague »

I've created a package, with Ribbons and Buttons. I'm now at the point I want to put up my Editor Window. I've been trying to follow the help system (Add an Editor Window section) as much as I can but I'm at a stopping point. I'm to the point that I want to show my editor window.

In the help file I find:

Code: Select all

    private void MyButton_Invoked(object sender, EventArgs e)
    {
        //Construct your editor uri, or an Order uri for example.
        Uri moniker = ...;

        IShell shell = GetService<IShell>();
        shell.OpenStandardEditor(moniker);
    }
Sorry, but I have no clue what the Uri moniker is supposed to look like, much less how to construct a proper one.

Additionally, the help file doesn't seem to specify it, but I assume I'll need to create a user control to load into this window. Is that correct?

Thanks,
Robert
Hadi Chemaly

Re: General Help on Creating Editor Windows

Post by Hadi Chemaly »

The constructed moniker has to match the editor extension registered with the package. For instance, when you create your package and drop the attribute line:

Code: Select all

[ProvideEditorExtension(typeof(MyEditorFactory), "sp-select", "mypackage/record", 10)]
it means that any moniker built with extension "mypackage/record" will be routed to the factory you have setup to instantiate your package editors (MyEditorFactory in this example).

Then you can construct your moniker as such:

Code: Select all

Uri moniker = "sp-select:///mypackage/record";
If you need multiple instances of the same editor, as with multiple Orders in Select, you will need to expand your moniker to include at least an id fragment, and as many optional fragment pairs as you need; and have your factory, or a "RecordUri" class of your own, handle its parsing. The moniker with ID would look like this:

Code: Select all

"sp-select:///mypackage/record?id=C5672F56-62AA-4EC7-8E6D-92B826EB3607"
and the more complex one with fragments:

Code: Select all

"sp-select:///mypackage/record?id=C5672F56-62AA-4EC7-8E6D-92B826EB3607#arg1=val1&arg2=val2"
You are correct about the need to create a UserControl to be hosted in that editor pane. This control should be instantiated in the OnCreateControl() method that you override in your "MyEditorPane" class:

Code: Select all

/// <summary>
/// Creates the control.
/// </summary>
/// <returns></returns>
protected override Control OnCreateControl()
{
	// editorControl is a private member of type Control.
	if (editorControl == null)
	{
		editorControl = new MyEditorControl();
		// More initialization code here.
	}
	return editorControl;
}
I hope this helps.
roteague
Posts: 292
Joined: Thu Sep 25, 2008 4:49 pm
Location: Honolulu, Hawaii

Re: General Help on Creating Editor Windows

Post by roteague »

Thanks Hadi, that helps tremendously!!
Robert
roteague
Posts: 292
Joined: Thu Sep 25, 2008 4:49 pm
Location: Honolulu, Hawaii

Re: General Help on Creating Editor Windows

Post by roteague »

Well, I'm still not able to get it to work. I'm not sure what I'm missing. My EditorFactory never gets instantiated.

The package is defined as:

Code: Select all

ProvideEditorFactory(GetType(TGAdminEditorFactory), "TG Editor Factory"), _
ProvideEditorExtension(GetType(TGAdminEditorFactory), "sp-select", "TGSoftProPackage/TGAdmin", 10), _
Guid(TGAdminPackage.PackageGuidString)> _
Partial Class TGAdminPackage
    Inherits Package
The factory is defined as:

Code: Select all

<Guid("7C61CDCC-22C5-4eca-B109-BFF47C395219")> _
Public Class TGAdminEditorFactory
    Inherits EditorFactory
And the method to start everything is:

Code: Select all

Private Sub RibbonButton1_Invoked(ByVal sender As Object, ByVal e As EventArgs)

        Dim moniker As New Uri("sp-select:///TGSoftProPackage/TGAdmin")

        Dim shell As IShell = GetService(Of IShell)()
        shell.OpenStandardEditor(moniker)

    End Sub
This method does get called, both shell and moniker are valid (not nothing in other words). However, the factory never gets instantiated (new is not called), nor the OnCreateEditor method gets called.
Robert
Hadi Chemaly

Re: General Help on Creating Editor Windows

Post by Hadi Chemaly »

Can you verify that your package and editor factory were registered correctly in the experimental hive?

You should be able to find the entries in the Registry Editor at My Computer\HKEY_LOCAL_MACHINE\SOFTWARE\SoftPro\Select\2.2Exp\Configuration (or equivalent). Look under Packages and Editors.
roteague
Posts: 292
Joined: Thu Sep 25, 2008 4:49 pm
Location: Honolulu, Hawaii

Re: General Help on Creating Editor Windows

Post by roteague »

Both items are registered. The registry keys match the GUIDs specified for the Editor Factory and Package.

Note: I have both a SnapSection and Package in the same module.
Robert
Hadi Chemaly

Re: General Help on Creating Editor Windows

Post by Hadi Chemaly »

One thing I forgot to mention in my previous post is that you have to re-register your package (using the spregpkg.exe utility) every time you make changes to the package's .ctd file.
Hadi Chemaly

Re: General Help on Creating Editor Windows

Post by Hadi Chemaly »

Never mind, in fact the project is setup to do that for you when you compile and run. I'm investigating your issue further and will let you know of any new findings.
Hadi Chemaly

Re: General Help on Creating Editor Windows

Post by Hadi Chemaly »

Because of our package lazy loading model, you have to register the factories associated with the package when the package gets initialized.

You do that in the package's OnInitialize() method:

Code: Select all

protected override void OnInitialize()
{
	base.RegisterEditorFactory(new MyEditorFactory(this));
	// Register more factories here.

	base.RegisterHandler(Package.MyButton, this.MyButton_Invoked);
	// Register more handlers here.
}
That is where the instance of the factory gets instantiated, passing this (the package instance) to it as the service provider.

Let me know if this works.
roteague
Posts: 292
Joined: Thu Sep 25, 2008 4:49 pm
Location: Honolulu, Hawaii

Re: General Help on Creating Editor Windows

Post by roteague »

Hadi Chemaly wrote:Because of our package lazy loading model, you have to register the factories associated with the package when the package gets initialized.

You do that in the package's OnInitialize() method:

Code: Select all

protected override void OnInitialize()
{
	base.RegisterEditorFactory(new MyEditorFactory(this));
	// Register more factories here.

	base.RegisterHandler(Package.MyButton, this.MyButton_Invoked);
	// Register more handlers here.
}
That is where the instance of the factory gets instantiated, passing this (the package instance) to it as the service provider.

Let me know if this works.

Thanks Hadi!! That worked perfectly!
Robert
Post Reply