* all plugins commands are bindable

support detachable menus in submenus of plugins menus
user_shortcuts_init() and user_shortcuts_save() are moved to not the most convenient spot, as init has to happen after plugins init and before menus creation
This commit is contained in:
Garux
2019-03-13 19:45:51 +03:00
parent 51ee1dcccb
commit 502c0f8bc1
5 changed files with 121 additions and 122 deletions

View File

@@ -33,61 +33,45 @@
#include "mainframe.h"
#include "preferences.h"
int m_nNextPlugInID = 0;
void plugin_activated( GtkWidget* widget, gpointer data ){
const char* str = (const char*)g_object_get_data( G_OBJECT( widget ),"command" );
GetPlugInMgr().Dispatch( gpointer_to_int( data ), str );
}
#include "gtkmisc.h"
#include <stack>
typedef std::stack<GtkWidget*> WidgetStack;
typedef std::stack<GtkMenu*> MenuStack;
void PlugInMenu_Add( GtkMenu* plugin_menu, IPlugIn* pPlugIn ){
GtkWidget *menu, *item, *parent, *subMenu;
const char *menuText, *menuCommand;
WidgetStack menuStack;
GtkMenu *menu;
const char *menuText;
MenuStack menuStack;
parent = gtk_menu_item_new_with_label( pPlugIn->getMenuName() );
gtk_widget_show( parent );
gtk_container_add( GTK_CONTAINER( plugin_menu ), parent );
menu = create_sub_menu_with_mnemonic( plugin_menu, pPlugIn->getMenuName() );
if ( g_Layout_enableDetachableMenus.m_value ) {
menu_tearoff( menu );
}
std::size_t nCount = pPlugIn->getCommandCount();
if ( nCount > 0 ) {
menu = gtk_menu_new();
if ( g_Layout_enableDetachableMenus.m_value ) {
menu_tearoff( GTK_MENU( menu ) );
}
{
while ( nCount > 0 )
{
menuText = pPlugIn->getCommandTitle( --nCount );
menuCommand = pPlugIn->getCommand( nCount );
if ( menuText != 0 && strlen( menuText ) > 0 ) {
if ( !strcmp( menuText, "-" ) ) {
item = gtk_menu_item_new();
gtk_widget_set_sensitive( item, FALSE );
if ( plugin_menu_separator( menuText ) ) {
menu_separator( menu );
}
else if ( !strcmp( menuText, ">" ) ) {
else if ( plugin_submenu_in( menuText ) ) {
menuText = pPlugIn->getCommandTitle( --nCount );
menuCommand = pPlugIn->getCommand( nCount );
if ( !strcmp( menuText, "-" ) || !strcmp( menuText, ">" ) || !strcmp( menuText, "<" ) ) {
if ( plugin_menu_special( menuText ) ) {
globalErrorStream() << pPlugIn->getMenuName() << " Invalid title (" << menuText << ") for submenu.\n";
continue;
}
item = gtk_menu_item_new_with_label( menuText );
gtk_widget_show( item );
gtk_container_add( GTK_CONTAINER( menu ), item );
subMenu = gtk_menu_new();
gtk_menu_item_set_submenu( GTK_MENU_ITEM( item ), subMenu );
menuStack.push( menu );
menu = subMenu;
menu = create_sub_menu_with_mnemonic( menu, menuText );
if ( g_Layout_enableDetachableMenus.m_value ) {
menu_tearoff( menu );
}
continue;
}
else if ( !strcmp( menuText, "<" ) ) {
else if ( plugin_submenu_out( menuText ) ) {
if ( !menuStack.empty() ) {
menu = menuStack.top();
menuStack.pop();
@@ -100,28 +84,13 @@ void PlugInMenu_Add( GtkMenu* plugin_menu, IPlugIn* pPlugIn ){
}
else
{
item = gtk_menu_item_new_with_label( menuText );
g_object_set_data( G_OBJECT( item ),"command", const_cast<gpointer>( static_cast<const void*>( menuCommand ) ) );
g_signal_connect( G_OBJECT( item ), "activate", G_CALLBACK( plugin_activated ), gint_to_pointer( m_nNextPlugInID ) );
create_menu_item_with_mnemonic( menu, menuText, pPlugIn->getGlobalCommand( nCount ) );
}
gtk_widget_show( item );
gtk_container_add( GTK_CONTAINER( menu ), item );
pPlugIn->addMenuID( m_nNextPlugInID++ );
}
}
if ( !menuStack.empty() ) {
std::size_t size = menuStack.size();
if ( size != 0 ) {
globalErrorStream() << pPlugIn->getMenuName() << " mismatched > <. " << Unsigned( size ) << " submenu(s) not closed.\n";
}
for ( std::size_t i = 0; i < ( size - 1 ); i++ )
{
menuStack.pop();
}
menu = menuStack.top();
menuStack.pop();
globalErrorStream() << pPlugIn->getMenuName() << " mismatched > <. " << Unsigned( menuStack.size() ) << " submenu(s) not closed.\n";
}
gtk_menu_item_set_submenu( GTK_MENU_ITEM( parent ), menu );
}
}
@@ -145,8 +114,6 @@ public:
}
void PluginsMenu_clear(){
m_nNextPlugInID = 0;
GList* lst = g_list_find( gtk_container_children( GTK_CONTAINER( g_plugins_menu ) ), GTK_WIDGET( g_plugins_menu_separator ) );
while ( lst->next )
{