Fix plugin toolbar icon placement. Now they are always inserted before the Quit button if it is the last toolbar element or at the end otherwise.

git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@3361 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
Enrico Tröger 2008-12-11 16:51:46 +00:00
parent f40aedeffd
commit 5d97590d21
3 changed files with 31 additions and 7 deletions

View File

@ -1,3 +1,11 @@
2008-12-11 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
* src/plugins.c, src/toolbar.c:
Fix plugin toolbar icon placement. Now they are always inserted
before the Quit button if it is the last toolbar element or at
the end otherwise.
2008-12-11 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
* src/utils.h, src/prefs.c, src/stash.c, src/stash.h, src/keyfile.c,

View File

@ -1255,13 +1255,12 @@ void plugin_add_toolbar_item(GeanyPlugin *plugin, GtkToolItem *item)
GtkToolItem *sep;
pos = toolbar_get_insert_position();
/* pos should be valid even if the quit btn is hidden */
g_return_if_fail(pos >= 0);
gtk_toolbar_insert(toolbar, item, pos);
sep = gtk_separator_tool_item_new();
gtk_toolbar_insert(toolbar, sep, pos + 1);
gtk_toolbar_insert(toolbar, sep, pos);
autosep->widget = GTK_WIDGET(sep);
gtk_toolbar_insert(toolbar, item, pos + 1);
}
else
{

View File

@ -247,14 +247,31 @@ GtkWidget *toolbar_init(void)
/* Returns the position for adding new toolbar items. The returned position can be used
* to add new toolbar items with @c gtk_toolbar_insert(). The toolbar object can be accessed
* with @a geany->main_widgets->toolbar.
* The position is always the last one before the Quit button (if it is shown).
* The position is always the last one before the Quit button or the very last position if the
* Quit button is not the last toolbar item.
*
* @return The position for new toolbar items or @c -1 if an error occurred.
* @return The position for new toolbar items.
*/
gint toolbar_get_insert_position(void)
{
GtkWidget *quit = toolbar_get_widget_by_name("Quit");
gint pos = gtk_toolbar_get_item_index(GTK_TOOLBAR(main_widgets.toolbar), GTK_TOOL_ITEM(quit));
gint quit_pos = -1, pos;
if (quit != NULL)
quit_pos = gtk_toolbar_get_item_index(GTK_TOOLBAR(main_widgets.toolbar), GTK_TOOL_ITEM(quit));
pos = gtk_toolbar_get_n_items(GTK_TOOLBAR(main_widgets.toolbar));
if (quit_pos == (pos - 1))
{
/* if the toolbar item before the quit button is a separator, insert new items before */
if (GTK_IS_SEPARATOR_TOOL_ITEM(gtk_toolbar_get_nth_item(
GTK_TOOLBAR(main_widgets.toolbar), quit_pos - 1)))
{
return quit_pos - 1;
}
/* else return the position of the quit button to insert new items before */
return quit_pos;
}
return pos;
}