This repository was archived by the owner on Apr 29, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
FileHandlers and MenuExtensions
exelix edited this page Aug 24, 2018
·
3 revisions
File handlers, once registered are used to try opening files unknown to the GameExtension.
You can ask the editor to try opening a file with the loaded handlers using:
OpenFileHandler.OpenFile(fileName,fileStream);
Implementing the IFileHander interface is pretty simple:
class MyFileHandler : IFileHander
{
public string HandlerName => "MyFileHandler";
public bool IsFormatSupported(string filename, Stream file)
{
//Check if this class can handle the file, if so return true
//stream position is always 0
}
public void OpenFile(string filename, Stream file)
{
//Open a form or converter for the file, this should be non-blocking
}
}
When your class is completed you just need to add it to the manifest:
public IFileHander[] Handlers => new IFileHander[] { new MyFileHandler() };
The IMenuExtension interface is used to add items to the menus of the editor, these menus are always shown no matter the current GameModule, if you want to show a custom menu ONLY for your GameModule (eg. settings) this is not the way to implement it.
To implement a MenuExtension you must provide 3 ToolStripMenuItem arrays, each will be added to the relative ToolStrip in the main window.
class MenuExt : IMenuExtension
{
public ToolStripMenuItem[] FileMenuExtensions { get; internal set; }
public ToolStripMenuItem[] ToolsMenuExtensions { get; internal set; }
public ToolStripMenuItem[] TitleBarExtensions { get; internal set; }
public MenuExt()
{
ToolsMenuExtensions = new ToolStripMenuItem[]
{
new ToolStripMenuItem(){ Text = "A button"},
};
ToolsMenuExtensions[0].Click += TheClickHandler;
}
}
the unused arrays can be set to null