2 * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
4 * Copyright (C) 2008, Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include "vikexttools.h"
30 #include <glib/gi18n.h>
32 #define VIK_TOOL_DATA_KEY "vik-tool-data"
34 static GList *ext_tools_list = NULL;
36 void vik_ext_tools_register ( VikExtTool *tool )
38 if ( IS_VIK_EXT_TOOL( tool ) )
39 ext_tools_list = g_list_append ( ext_tools_list, g_object_ref ( tool ) );
42 void vik_ext_tools_unregister_all ()
44 g_list_foreach ( ext_tools_list, (GFunc) g_object_unref, NULL );
47 static void ext_tools_open_cb ( GtkWidget *widget, VikWindow *vwindow )
49 gpointer ptr = g_object_get_data ( G_OBJECT(widget), VIK_TOOL_DATA_KEY );
50 VikExtTool *ext_tool = VIK_EXT_TOOL ( ptr );
51 vik_ext_tool_open ( ext_tool, vwindow );
54 void vik_ext_tools_add_menu_items_to_menu ( VikWindow *vwindow, GtkMenu *menu )
57 for (iter = ext_tools_list; iter; iter = iter->next)
59 VikExtTool *ext_tool = NULL;
61 ext_tool = VIK_EXT_TOOL ( iter->data );
62 label = vik_ext_tool_get_label ( ext_tool );
65 GtkWidget *item = NULL;
66 item = gtk_menu_item_new_with_label ( _(label) );
67 g_free ( label ); label = NULL;
68 // Store tool's ref into the menu entry
69 g_object_set_data ( G_OBJECT(item), VIK_TOOL_DATA_KEY, ext_tool );
70 g_signal_connect ( G_OBJECT(item), "activate", G_CALLBACK(ext_tools_open_cb), vwindow );
71 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
72 gtk_widget_show ( item );
77 void vik_ext_tools_add_menu_items ( VikWindow *vwindow, GtkUIManager *uim )
79 GtkWidget *widget = NULL;
81 widget = gtk_ui_manager_get_widget (uim, "/MainMenu/Tools/Exttools");
82 menu = GTK_MENU ( gtk_menu_item_get_submenu ( GTK_MENU_ITEM ( widget ) ) );
83 vik_ext_tools_add_menu_items_to_menu ( vwindow, menu );
84 gtk_widget_show ( widget );