Patch from Aidan Delaney to tidy tabpopup.c by factoring out

2006-06-10  Elijah Newren  <newren gmail com>

	Patch from Aidan Delaney to tidy tabpopup.c by factoring out
	tab_entry_new().  #166890.

	* src/tabpopup.c (tab_entry_new): new function,
	(meta_ui_tab_popup_new): use tab_entry_new() to remove a big chunk
	of code, plus a few other small cleanups.
This commit is contained in:
Elijah Newren 2006-06-11 02:44:55 +00:00 committed by Elijah Newren
parent 5eaf79f6fa
commit bcbdfbe177
2 changed files with 107 additions and 91 deletions

View File

@ -1,3 +1,12 @@
2006-06-10 Elijah Newren <newren gmail com>
Patch from Aidan Delaney to tidy tabpopup.c by factoring out
tab_entry_new(). #166890.
* src/tabpopup.c (tab_entry_new): new function,
(meta_ui_tab_popup_new): use tab_entry_new() to remove a big chunk
of code, plus a few other small cleanups.
Tue Jun 6 12:46:42 2006 Søren Sandmann <sandmann@redhat.com> Tue Jun 6 12:46:42 2006 Søren Sandmann <sandmann@redhat.com>
* configure.in (GETTEXT_PACKAGE): Bunp intltool requirement to * configure.in (GETTEXT_PACKAGE): Bunp intltool requirement to

View File

@ -137,6 +137,75 @@ dimm_icon (GdkPixbuf *pixbuf)
return dimmed_pixbuf; return dimmed_pixbuf;
} }
static TabEntry*
tab_entry_new (const MetaTabEntry *entry,
gint screen_width,
gboolean outline)
{
TabEntry *te;
/* FIXME: make max title size some random relationship to the
* screen, avg char width of our font would be a better number.
*/
int max_chars_per_title = screen_width / 15;
te = g_new (TabEntry, 1);
te->key = entry->key;
te->title = NULL;
if (entry->title)
{
gchar *tmp;
if (entry->hidden)
{
tmp = g_markup_printf_escaped ("[%s]", entry->title);
}
else
{
tmp = g_markup_printf_escaped ("%s", entry->title);
}
if (entry->demands_attention)
{
/* Escape the whole line of text then markup the text and
* copy it back into the original buffer.
*/
gchar *markup, *escaped;
escaped = g_markup_escape_text (tmp, -1);
markup = g_strdup_printf ("<b>%s</b>", escaped);
g_free (escaped);
g_free (tmp);
tmp = markup;
}
te->title = meta_g_utf8_strndup (tmp, max_chars_per_title);
g_free (tmp);
}
te->widget = NULL;
te->icon = entry->icon;
te->blank = entry->blank;
te->dimmed_icon = NULL;
if (te->icon)
{
g_object_ref (G_OBJECT (te->icon));
if (entry->hidden)
te->dimmed_icon = dimm_icon (entry->icon);
}
if (outline)
{
te->rect.x = entry->rect.x;
te->rect.y = entry->rect.y;
te->rect.width = entry->rect.width;
te->rect.height = entry->rect.height;
te->inner_rect.x = entry->inner_rect.x;
te->inner_rect.y = entry->inner_rect.y;
te->inner_rect.width = entry->inner_rect.width;
te->inner_rect.height = entry->inner_rect.height;
}
return te;
}
MetaTabPopup* MetaTabPopup*
meta_ui_tab_popup_new (const MetaTabEntry *entries, meta_ui_tab_popup_new (const MetaTabEntry *entries,
int screen_number, int screen_number,
@ -146,7 +215,6 @@ meta_ui_tab_popup_new (const MetaTabEntry *entries,
{ {
MetaTabPopup *popup; MetaTabPopup *popup;
int i, left, right, top, bottom; int i, left, right, top, bottom;
GList *tab_entries;
int height; int height;
GtkWidget *table; GtkWidget *table;
GtkWidget *vbox; GtkWidget *vbox;
@ -154,16 +222,16 @@ meta_ui_tab_popup_new (const MetaTabEntry *entries,
GList *tmp; GList *tmp;
GtkWidget *frame; GtkWidget *frame;
int max_label_width; /* the actual max width of the labels we create */ int max_label_width; /* the actual max width of the labels we create */
int max_chars_per_title; /* max chars we allow in a label */
GdkScreen *screen; GdkScreen *screen;
popup = g_new (MetaTabPopup, 1); popup = g_new (MetaTabPopup, 1);
popup->outline_window = gtk_window_new (GTK_WINDOW_POPUP); popup->outline_window = gtk_window_new (GTK_WINDOW_POPUP);
screen = gdk_display_get_screen (gdk_display_get_default (),
screen_number);
gtk_window_set_screen (GTK_WINDOW (popup->outline_window), gtk_window_set_screen (GTK_WINDOW (popup->outline_window),
gdk_display_get_screen (gdk_display_get_default (), screen);
screen_number));
gtk_widget_set_app_paintable (popup->outline_window, TRUE); gtk_widget_set_app_paintable (popup->outline_window, TRUE);
gtk_widget_realize (popup->outline_window); gtk_widget_realize (popup->outline_window);
@ -173,9 +241,6 @@ meta_ui_tab_popup_new (const MetaTabEntry *entries,
popup->window = gtk_window_new (GTK_WINDOW_POPUP); popup->window = gtk_window_new (GTK_WINDOW_POPUP);
screen = gdk_display_get_screen (gdk_display_get_default (),
screen_number);
gtk_window_set_screen (GTK_WINDOW (popup->window), gtk_window_set_screen (GTK_WINDOW (popup->window),
screen); screen);
@ -189,72 +254,14 @@ meta_ui_tab_popup_new (const MetaTabEntry *entries,
popup->current_selected_entry = NULL; popup->current_selected_entry = NULL;
popup->outline = outline; popup->outline = outline;
/* make max title size some random relationship to the screen, int screen_width = gdk_screen_get_width (screen);
* avg char width of our font would be a better number.
*/
max_chars_per_title = gdk_screen_get_width (screen) / 15;
tab_entries = NULL;
for (i = 0; i < entry_count; ++i) for (i = 0; i < entry_count; ++i)
{ {
TabEntry *te; TabEntry* new_entry = tab_entry_new (&entries[i], screen_width, outline);
popup->entries = g_list_prepend (popup->entries, new_entry);
te = g_new (TabEntry, 1);
te->key = entries[i].key;
te->title = NULL;
if (entries[i].title)
{
gchar *temp;
if (entries[i].hidden)
{
temp = g_markup_printf_escaped ("[%s]", entries[i].title);
}
else
{
temp = g_markup_printf_escaped ("%s", entries[i].title);
} }
if (entries[i].demands_attention) popup->entries = g_list_reverse (popup->entries);
{
gchar *escaped, *markup;
escaped = g_markup_escape_text (temp, -1);
markup = g_strdup_printf ("<b>%s</b>", escaped);
g_free (escaped);
g_free (temp);
temp = markup;
}
te->title = meta_g_utf8_strndup (temp, max_chars_per_title);
g_free (temp);
}
te->widget = NULL;
te->icon = entries[i].icon;
te->blank = entries[i].blank;
te->dimmed_icon = NULL;
if (te->icon)
{
g_object_ref (G_OBJECT (te->icon));
if (entries[i].hidden)
te->dimmed_icon = dimm_icon (entries[i].icon);
}
if (outline)
{
te->rect.x = entries[i].rect.x;
te->rect.y = entries[i].rect.y;
te->rect.width = entries[i].rect.width;
te->rect.height = entries[i].rect.height;
te->inner_rect.x = entries[i].inner_rect.x;
te->inner_rect.y = entries[i].inner_rect.y;
te->inner_rect.width = entries[i].inner_rect.width;
te->inner_rect.height = entries[i].inner_rect.height;
}
tab_entries = g_list_prepend (tab_entries, te);
}
popup->entries = g_list_reverse (tab_entries);
g_assert (width > 0); g_assert (width > 0);
height = i / width; height = i / width;
@ -366,7 +373,7 @@ meta_ui_tab_popup_new (const MetaTabEntry *entries,
} }
static void static void
free_entry (gpointer data, gpointer user_data) free_tab_entry (gpointer data, gpointer user_data)
{ {
TabEntry *te; TabEntry *te;
@ -389,7 +396,7 @@ meta_ui_tab_popup_free (MetaTabPopup *popup)
gtk_widget_destroy (popup->outline_window); gtk_widget_destroy (popup->outline_window);
gtk_widget_destroy (popup->window); gtk_widget_destroy (popup->window);
g_list_foreach (popup->entries, free_entry, NULL); g_list_foreach (popup->entries, free_tab_entry, NULL);
g_list_free (popup->entries); g_list_free (popup->entries);