-
Notifications
You must be signed in to change notification settings - Fork 10
Using menu items
Creating and using menu items in PL/SQL Developer is simple:
- Assign your menu item a unique index and use it in
CreateMenuItem,OnMenuClickand menu related callbacks. - Export
CreateMenuItemfunction to create menu items you'd like. - Export
OnMenuClickto handle clicks on those menu items.
This code sample for menu item creation and handling is intended to quickly demonstrate everything said in this article.
private const int DEMO_OPEN_FILE_MENU_INDEX = 10;
private const int DEMO_SAVE_FILE_MENU_INDEX = 11;
[DllExport("CreateMenuItem", CallingConvention = CallingConvention.Cdecl)]
public static string CreateMenuItem(int index)
{
if (index == DEMO_OPEN_FILE_MENU_INDEX)
{
// This will create Demo open file dialog... menu item
// under Tools menu, when index = 10
return "Tools / Demo open file dialog...";
}
else if (index == DEMO_SAVE_FILE_MENU_INDEX)
{
// This will create Demo save file dialog... menu item
// under Tools menu, when index = 11
return "Tools / Demo save file dialog...";
}
else
{
// For other index values no menu items will be created
return "";
}
}
[DllExport("OnMenuClick", CallingConvention = CallingConvention.Cdecl)]
public static void OnMenuClick(int index)
{
if (index == DEMO_OPEN_FILE_MENU_INDEX)
{
me.ShowOpenFileDialog();
}
else if (index == DEMO_SAVE_FILE_MENU_INDEX)
{
me.ShowSaveFileDialog();
}
}CreateMenuItem creates menu items in PL/SQL Developer menu bar. When PL/SQL Developer calls this function, it passes an index value, which is an integer in range [1; 99]. Thus the first of all you must choose the index value for your menu: any integer in range [1; 99]. If plug-in creates several menu items, choose several distinct values from the range. Use these values to check, whether CreateMenuItem is called with the index value of interest. Also using these values you'll be able to distinguish which menu has been clicked, check the state of the menu etc.
CreateMenuItem is called 99 times for each plug-in this way allowing each plug-in to create up to 99 distinct menu items. First time CreateMenuItem is called with index value 1, second time with value 2 and so on until the last time with value 99. Of course, you don't need 99 duplicated menu items, thus check the index value passed to the function, as demonstrated in the example above.
If CreateMenuItem call must result in menu item creation (index parameter value matches the one you've chosen for your menu item), function must return a string, containing menu item name and its location. Otherwise return an empty string or null. For details on string format refer to "PL/SQL Developer Plug-In interface Documentation" page 2.
When user clicks the menu item created by your plug-in, PL/SQL Developer calls OnMenuClick and passes an index of the menu item clicked. Check whether it matches the value you've assigned, and process accordingly. See the example above.
Introduction
Main concepts
- Anatomy of the plug-in
- Exporting DLL functions
- Using callbacks
Misc
- Using menu items
- Accepting commands in the command window
- Validating DLL exports
- Working with color preferences
- Referencing external C# assemblies