Removed invisible place holder menu item in recent files menu.

Create separate sub menu for the recent files menu in the toolbar to prevent GTK warnings when using GTK >= 2.10.


git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@1041 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
Enrico Tröger 2006-12-01 18:44:35 +00:00
parent ac3c7c54ad
commit ab258acf33
6 changed files with 87 additions and 53 deletions

View File

@ -1,3 +1,12 @@
2006-12-01 Enrico Tröger <enrico.troeger@uvena.de>
* geany.glade, src/interface.c, src/geany.h, src/main.c,
src/ui_utils.c:
Removed invisible place holder menu item in recent files menu.
Create separate sub menu for the recent files menu in the toolbar to
prevent GTK warnings when using GTK >= 2.10.
2006-12-01 Nick Treleaven <nick.treleaven@btinternet.com>
* src/vte.c:

View File

@ -18,6 +18,7 @@
<property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
<property name="focus_on_map">True</property>
<property name="urgency_hint">False</property>
<accessibility>
<atkproperty name="AtkObject::accessible_name" translatable="yes">Geany</atkproperty>
</accessibility>
@ -31,6 +32,8 @@
<child>
<widget class="GtkMenuBar" id="menubar1">
<property name="visible">True</property>
<property name="pack_direction">GTK_PACK_DIRECTION_LTR</property>
<property name="child_pack_direction">GTK_PACK_DIRECTION_LTR</property>
<child>
<widget class="GtkMenuItem" id="menuitem1">
@ -105,13 +108,6 @@
<child>
<widget class="GtkMenu" id="recent_files1_menu">
<child>
<widget class="GtkMenuItem" id="invisible5">
<property name="label" translatable="yes">invisible</property>
<property name="use_underline">True</property>
</widget>
</child>
</widget>
</child>
</widget>
@ -2658,6 +2654,7 @@
<property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
<property name="focus_on_map">True</property>
<property name="urgency_hint">False</property>
<property name="has_separator">True</property>
<child internal-child="vbox">

View File

@ -160,6 +160,8 @@ typedef struct MyApp
GtkWidget *popup_menu;
GtkWidget *toolbar_menu;
GtkWidget *new_file_menu;
GtkWidget *recent_files_menubar;
GtkWidget *recent_files_toolbar;
GtkWidget *menu_insert_include_item[2];
GtkWidget *popup_goto_items[3];
GtkWidget *popup_items[5];

View File

@ -44,7 +44,6 @@ create_window1 (void)
GtkWidget *menu_open1;
GtkWidget *recent_files1;
GtkWidget *recent_files1_menu;
GtkWidget *invisible5;
GtkWidget *separator13;
GtkWidget *menu_save1;
GtkWidget *menu_save_as1;
@ -293,9 +292,6 @@ create_window1 (void)
recent_files1_menu = gtk_menu_new ();
gtk_menu_item_set_submenu (GTK_MENU_ITEM (recent_files1), recent_files1_menu);
invisible5 = gtk_menu_item_new_with_mnemonic (_("invisible"));
gtk_container_add (GTK_CONTAINER (recent_files1_menu), invisible5);
separator13 = gtk_separator_menu_item_new ();
gtk_widget_show (separator13);
gtk_container_add (GTK_CONTAINER (menuitem1_menu), separator13);
@ -1408,7 +1404,6 @@ create_window1 (void)
GLADE_HOOKUP_OBJECT (window1, menu_open1, "menu_open1");
GLADE_HOOKUP_OBJECT (window1, recent_files1, "recent_files1");
GLADE_HOOKUP_OBJECT (window1, recent_files1_menu, "recent_files1_menu");
GLADE_HOOKUP_OBJECT (window1, invisible5, "invisible5");
GLADE_HOOKUP_OBJECT (window1, separator13, "separator13");
GLADE_HOOKUP_OBJECT (window1, menu_save1, "menu_save1");
GLADE_HOOKUP_OBJECT (window1, menu_save_as1, "menu_save_as1");

View File

@ -207,12 +207,8 @@ static void apply_settings(void)
// connect the toolbar dropdown menus
gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(
lookup_widget(app->window, "menutoolbutton1")), app->new_file_menu);
#if 0
// gtk2.10 doesn't like doubly attached menus
gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(
lookup_widget(app->window, "toolbutton9")),
lookup_widget(app->window, "recent_files1_menu"));
#endif
lookup_widget(app->window, "toolbutton9")), app->recent_files_toolbar);
// set the tab placements of the notebooks
gtk_notebook_set_tab_pos(GTK_NOTEBOOK(app->notebook), app->tab_pos_editor);
@ -247,6 +243,7 @@ static void main_init(void)
app->window = create_window1();
app->new_file_menu = gtk_menu_new();
app->recent_files_toolbar = gtk_menu_new();
// store important pointers in the MyApp structure
app->toolbar = lookup_widget(app->window, "toolbar1");
@ -258,6 +255,7 @@ static void main_init(void)
app->toolbar_menu = create_toolbar_popup_menu1();
app->compile_button = lookup_widget(app->window, "toolbutton13");
app->run_button = lookup_widget(app->window, "toolbutton26");
app->recent_files_menubar = lookup_widget(app->window, "recent_files1_menu");
app->popup_goto_items[0] = lookup_widget(app->popup_menu, "goto_tag_definition1");
app->popup_goto_items[1] = lookup_widget(app->popup_menu, "goto_tag_declaration1");
app->popup_goto_items[2] = lookup_widget(app->popup_menu, "find_usage1");

View File

@ -830,24 +830,30 @@ GtkWidget *ui_new_image_from_inline(gint img, gboolean small_img)
void ui_create_recent_menu()
{
GtkWidget *recent_menu = lookup_widget(app->window, "recent_files1_menu");
GtkWidget *tmp;
guint i;
gchar *filename;
if (g_queue_get_length(app->recent_queue) == 0)
{
gtk_widget_set_sensitive(lookup_widget(app->window, "recent_files1"), FALSE);
gtk_widget_set_sensitive(app->recent_files_menubar, FALSE);
gtk_widget_set_sensitive(app->recent_files_toolbar, FALSE);
return;
}
for (i = 0; i < MIN(app->mru_length, g_queue_get_length(app->recent_queue));
i++)
for (i = 0; i < MIN(app->mru_length, g_queue_get_length(app->recent_queue)); i++)
{
filename = g_queue_peek_nth(app->recent_queue, i);
// create menu item for the recent files menu in the menu bar
tmp = gtk_menu_item_new_with_label(filename);
gtk_widget_show(tmp);
gtk_menu_shell_append(GTK_MENU_SHELL(recent_menu), tmp);
gtk_menu_shell_append(GTK_MENU_SHELL(app->recent_files_menubar), tmp);
g_signal_connect((gpointer) tmp, "activate",
G_CALLBACK(recent_file_activate_cb), NULL);
// create menu item for the recent files menu in the toolbar bar
tmp = gtk_menu_item_new_with_label(filename);
gtk_widget_show(tmp);
gtk_menu_shell_append(GTK_MENU_SHELL(app->recent_files_toolbar), tmp);
g_signal_connect((gpointer) tmp, "activate",
G_CALLBACK(recent_file_activate_cb), NULL);
}
@ -889,11 +895,11 @@ static gchar *menu_item_get_text(GtkMenuItem *menu_item)
{
const gchar *text = NULL;
if (GTK_BIN (menu_item)->child)
if (GTK_BIN(menu_item)->child)
{
GtkWidget *child = GTK_BIN (menu_item)->child;
GtkWidget *child = GTK_BIN(menu_item)->child;
if (GTK_IS_LABEL (child))
if (GTK_IS_LABEL(child))
text = gtk_label_get_text(GTK_LABEL(child));
}
// GTK owns text so it's much safer to return a copy of it in case the memory is reallocated
@ -901,11 +907,26 @@ static gchar *menu_item_get_text(GtkMenuItem *menu_item)
}
static gint find_recent_file_item(gconstpointer list_data, gconstpointer user_data)
{
gchar *menu_text = menu_item_get_text(GTK_MENU_ITEM(list_data));
gint result;
if (g_str_equal(menu_text, user_data))
result = 0;
else
result = 1;
g_free(menu_text);
return result;
}
static void recent_file_loaded(const gchar *utf8_filename)
{
GList *item, *children;
void *data;
GtkWidget *recent_menu, *tmp;
GtkWidget *tmp;
// first reorder the queue
item = g_queue_find_custom(app->recent_queue, utf8_filename, (GCompareFunc) strcmp);
@ -915,31 +936,25 @@ static void recent_file_loaded(const gchar *utf8_filename)
g_queue_remove(app->recent_queue, data);
g_queue_push_head(app->recent_queue, data);
// now reorder the recent files menu
recent_menu = lookup_widget(app->window, "recent_files1_menu");
children = gtk_container_get_children(GTK_CONTAINER(recent_menu));
// remove the old menuitem for the filename
for (item = children; item != NULL; item = g_list_next(item))
{
gchar *menu_text;
children = gtk_container_get_children(GTK_CONTAINER(app->recent_files_menubar));
item = g_list_find_custom(children, utf8_filename, (GCompareFunc) find_recent_file_item);
if (item != NULL) gtk_widget_destroy(GTK_WIDGET(item->data));
data = item->data;
if (! GTK_IS_MENU_ITEM(data)) continue;
menu_text = menu_item_get_text(GTK_MENU_ITEM(data));
children = gtk_container_get_children(GTK_CONTAINER(app->recent_files_toolbar));
item = g_list_find_custom(children, utf8_filename, (GCompareFunc) find_recent_file_item);
if (item != NULL) gtk_widget_destroy(GTK_WIDGET(item->data));
if (g_str_equal(menu_text, utf8_filename))
{
gtk_widget_destroy(GTK_WIDGET(data));
g_free(menu_text);
break;
}
g_free(menu_text);
}
// now prepend a new menuitem for the filename
// now prepend a new menuitem for the filename, first for the recent files menu in the menu bar
tmp = gtk_menu_item_new_with_label(utf8_filename);
gtk_widget_show(tmp);
gtk_menu_shell_prepend(GTK_MENU_SHELL(recent_menu), tmp);
gtk_menu_shell_prepend(GTK_MENU_SHELL(app->recent_files_menubar), tmp);
g_signal_connect((gpointer) tmp, "activate",
G_CALLBACK(recent_file_activate_cb), NULL);
// then for the recent files menu in the tool bar
tmp = gtk_menu_item_new_with_label(utf8_filename);
gtk_widget_show(tmp);
gtk_menu_shell_prepend(GTK_MENU_SHELL(app->recent_files_toolbar), tmp);
g_signal_connect((gpointer) tmp, "activate",
G_CALLBACK(recent_file_activate_cb), NULL);
}
@ -947,11 +962,10 @@ static void recent_file_loaded(const gchar *utf8_filename)
static void update_recent_menu()
{
GtkWidget *recent_menu = lookup_widget(app->window, "recent_files1_menu");
GtkWidget *recent_files_item = lookup_widget(app->window, "recent_files1");
GtkWidget *tmp;
gchar *filename;
GList *children;
GList *children, *item;
if (g_queue_get_length(app->recent_queue) == 0)
{
@ -963,11 +977,23 @@ static void update_recent_menu()
gtk_widget_set_sensitive(recent_files_item, TRUE);
}
// clean the MRU list before adding an item
children = gtk_container_get_children(GTK_CONTAINER(recent_menu));
// clean the MRU list before adding an item (menubar)
children = gtk_container_get_children(GTK_CONTAINER(app->recent_files_menubar));
if (g_list_length(children) > app->mru_length - 1)
{
GList *item = g_list_nth(children, app->mru_length - 1);
item = g_list_nth(children, app->mru_length - 1);
while (item != NULL)
{
if (GTK_IS_MENU_ITEM(item->data)) gtk_widget_destroy(GTK_WIDGET(item->data));
item = g_list_next(item);
}
}
// clean the MRU list before adding an item (toolbar)
children = gtk_container_get_children(GTK_CONTAINER(app->recent_files_toolbar));
if (g_list_length(children) > app->mru_length - 1)
{
item = g_list_nth(children, app->mru_length - 1);
while (item != NULL)
{
if (GTK_IS_MENU_ITEM(item->data)) gtk_widget_destroy(GTK_WIDGET(item->data));
@ -976,9 +1002,16 @@ static void update_recent_menu()
}
filename = g_queue_peek_head(app->recent_queue);
// create item for the menu bar menu
tmp = gtk_menu_item_new_with_label(filename);
gtk_widget_show(tmp);
gtk_menu_shell_prepend(GTK_MENU_SHELL(recent_menu), tmp);
gtk_menu_shell_prepend(GTK_MENU_SHELL(app->recent_files_menubar), tmp);
g_signal_connect((gpointer) tmp, "activate",
G_CALLBACK(recent_file_activate_cb), NULL);
// create item for the tool bar menu
tmp = gtk_menu_item_new_with_label(filename);
gtk_widget_show(tmp);
gtk_menu_shell_prepend(GTK_MENU_SHELL(app->recent_files_toolbar), tmp);
g_signal_connect((gpointer) tmp, "activate",
G_CALLBACK(recent_file_activate_cb), NULL);
}
@ -1117,7 +1150,7 @@ void ui_combo_box_add_to_history(GtkComboBox *combo, const gchar *text)
if (equal) return; // don't prepend duplicate
gtk_combo_box_prepend_text(combo, text);
// limit history
path = gtk_tree_path_new_from_indices(history_len, -1);
if (gtk_tree_model_get_iter(model, &iter, path))