Introduce ITEM_IS_BOOKMARK|FOLDER|SEPARATOR in bookmark panel

The implicit logic for differentiating items is not easy to
read, so we introduce macros for that.
This commit is contained in:
Christian Dywan 2010-07-01 00:13:18 +02:00
parent b0191b69b0
commit 62f5a1c974

View file

@ -24,6 +24,10 @@
#include <gdk/gdkkeysyms.h> #include <gdk/gdkkeysyms.h>
#define ITEM_IS_BOOKMARK(item) (item && katze_item_get_uri (item))
#define ITEM_IS_FOLDER(item) (item && !katze_item_get_uri (item))
#define ITEM_IS_SEPARATOR(item) (item == NULL)
void void
midori_browser_edit_bookmark_dialog_new (MidoriBrowser* browser, midori_browser_edit_bookmark_dialog_new (MidoriBrowser* browser,
KatzeItem* bookmark, KatzeItem* bookmark,
@ -217,7 +221,7 @@ midori_bookmarks_insert_item_db (sqlite3* db,
int type = 0; int type = 0;
gchar* parent; gchar* parent;
if (katze_item_get_uri (item)) if (ITEM_IS_BOOKMARK (item))
type = 1; type = 1;
if (folder) if (folder)
@ -257,7 +261,7 @@ midori_bookmarks_remove_item_from_db (sqlite3* db,
gchar* sqlcmd; gchar* sqlcmd;
char* errmsg = NULL; char* errmsg = NULL;
if (katze_item_get_uri (item)) if (ITEM_IS_BOOKMARK (item))
sqlcmd = sqlite3_mprintf ( sqlcmd = sqlite3_mprintf (
"DELETE FROM bookmarks WHERE uri = '%q'", "DELETE FROM bookmarks WHERE uri = '%q'",
katze_item_get_uri (item)); katze_item_get_uri (item));
@ -326,16 +330,15 @@ midori_bookmarks_edit_clicked_cb (GtkWidget* toolitem,
&model, &iter)) &model, &iter))
{ {
KatzeItem* item; KatzeItem* item;
gboolean is_separator; MidoriBrowser* browser;
gtk_tree_model_get (model, &iter, 0, &item, -1); gtk_tree_model_get (model, &iter, 0, &item, -1);
is_separator = item && !katze_item_get_uri (item); g_assert (!ITEM_IS_SEPARATOR (item));
if (!is_separator)
{ browser = midori_browser_get_for_widget (toolitem);
MidoriBrowser* browser = midori_browser_get_for_widget (toolitem);
midori_browser_edit_bookmark_dialog_new (browser, item, FALSE, FALSE); midori_browser_edit_bookmark_dialog_new (browser, item, FALSE, FALSE);
}
g_object_unref (item); g_object_unref (item);
} }
} }
@ -381,15 +384,12 @@ midori_bookmarks_cursor_or_row_changed_cb (GtkTreeView* treeview,
if (katze_tree_view_get_selected_iter (treeview, &model, &iter)) if (katze_tree_view_get_selected_iter (treeview, &model, &iter))
{ {
gboolean is_separator;
gtk_tree_model_get (model, &iter, 0, &item, -1); gtk_tree_model_get (model, &iter, 0, &item, -1);
if (!item)
return; gtk_widget_set_sensitive (bookmarks->edit, !ITEM_IS_SEPARATOR (item));
is_separator = !katze_item_get_uri (item);
gtk_widget_set_sensitive (bookmarks->edit, !is_separator);
gtk_widget_set_sensitive (bookmarks->delete, TRUE); gtk_widget_set_sensitive (bookmarks->delete, TRUE);
if (item != NULL)
g_object_unref (item); g_object_unref (item);
} }
else else
@ -550,10 +550,10 @@ midori_bookmarks_treeview_render_icon_cb (GtkTreeViewColumn* column,
/* TODO: Would it be better to not do this on every redraw? */ /* TODO: Would it be better to not do this on every redraw? */
pixbuf = NULL; pixbuf = NULL;
if (item && !katze_item_get_uri (item) && katze_item_get_name (item)) if (ITEM_IS_FOLDER (item))
pixbuf = gtk_widget_render_icon (treeview, GTK_STOCK_DIRECTORY, pixbuf = gtk_widget_render_icon (treeview, GTK_STOCK_DIRECTORY,
GTK_ICON_SIZE_MENU, NULL); GTK_ICON_SIZE_MENU, NULL);
else if (item && katze_item_get_uri (item)) else if (ITEM_IS_BOOKMARK (item))
pixbuf = katze_load_cached_icon (katze_item_get_uri (item), treeview); pixbuf = katze_load_cached_icon (katze_item_get_uri (item), treeview);
g_object_set (renderer, "pixbuf", pixbuf, NULL); g_object_set (renderer, "pixbuf", pixbuf, NULL);
@ -621,7 +621,7 @@ midori_bookmarks_popup_item (GtkWidget* menu,
const gchar* uri; const gchar* uri;
GtkWidget* menuitem; GtkWidget* menuitem;
uri = katze_item_get_uri (item); uri = ITEM_IS_BOOKMARK (item) ? katze_item_get_uri (item) : NULL;
menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL); menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
if (label) if (label)
@ -629,8 +629,8 @@ midori_bookmarks_popup_item (GtkWidget* menu,
GTK_BIN (menuitem))), label); GTK_BIN (menuitem))), label);
if (!strcmp (stock_id, GTK_STOCK_EDIT)) if (!strcmp (stock_id, GTK_STOCK_EDIT))
gtk_widget_set_sensitive (menuitem, gtk_widget_set_sensitive (menuitem,
KATZE_IS_ARRAY (item) || uri != NULL); !ITEM_IS_SEPARATOR (item));
else if (!KATZE_IS_ARRAY (item) && strcmp (stock_id, GTK_STOCK_DELETE)) else if (!ITEM_IS_FOLDER (item) && strcmp (stock_id, GTK_STOCK_DELETE))
gtk_widget_set_sensitive (menuitem, uri != NULL); gtk_widget_set_sensitive (menuitem, uri != NULL);
g_object_set_data (G_OBJECT (menuitem), "KatzeItem", item); g_object_set_data (G_OBJECT (menuitem), "KatzeItem", item);
g_signal_connect (menuitem, "activate", G_CALLBACK (callback), bookmarks); g_signal_connect (menuitem, "activate", G_CALLBACK (callback), bookmarks);
@ -646,9 +646,8 @@ midori_bookmarks_open_activate_cb (GtkWidget* menuitem,
const gchar* uri; const gchar* uri;
item = (KatzeItem*)g_object_get_data (G_OBJECT (menuitem), "KatzeItem"); item = (KatzeItem*)g_object_get_data (G_OBJECT (menuitem), "KatzeItem");
uri = katze_item_get_uri (item);
if (uri && *uri) if ((uri = katze_item_get_uri (item)) && *uri)
{ {
MidoriBrowser* browser = midori_browser_get_for_widget (GTK_WIDGET (bookmarks)); MidoriBrowser* browser = midori_browser_get_for_widget (GTK_WIDGET (bookmarks));
midori_browser_set_current_uri (browser, uri); midori_browser_set_current_uri (browser, uri);
@ -664,11 +663,12 @@ midori_bookmarks_open_in_tab_activate_cb (GtkWidget* menuitem,
guint n; guint n;
item = (KatzeItem*)g_object_get_data (G_OBJECT (menuitem), "KatzeItem"); item = (KatzeItem*)g_object_get_data (G_OBJECT (menuitem), "KatzeItem");
if (KATZE_IS_ARRAY (item)) if (ITEM_IS_FOLDER (item))
{ {
KatzeItem* child; KatzeItem* child;
guint i = 0; guint i = 0;
g_return_if_fail (KATZE_IS_ARRAY (item));
while ((child = katze_array_get_nth_item (KATZE_ARRAY (item), i))) while ((child = katze_array_get_nth_item (KATZE_ARRAY (item), i)))
{ {
if ((uri = katze_item_get_uri (child)) && *uri) if ((uri = katze_item_get_uri (child)) && *uri)
@ -727,17 +727,14 @@ midori_bookmarks_edit_activate_cb (GtkWidget* menuitem,
MidoriBookmarks* bookmarks) MidoriBookmarks* bookmarks)
{ {
KatzeItem* item; KatzeItem* item;
gboolean is_separator; MidoriBrowser* browser;
item = (KatzeItem*)g_object_get_data (G_OBJECT (menuitem), "KatzeItem"); item = (KatzeItem*)g_object_get_data (G_OBJECT (menuitem), "KatzeItem");
is_separator = !KATZE_IS_ARRAY (item) && !katze_item_get_uri (item); g_assert (!ITEM_IS_SEPARATOR (item));
if (!is_separator) browser = midori_browser_get_for_widget (GTK_WIDGET (bookmarks));
{
MidoriBrowser* browser = midori_browser_get_for_widget (GTK_WIDGET (bookmarks));
midori_browser_edit_bookmark_dialog_new (browser, item, FALSE, FALSE); midori_browser_edit_bookmark_dialog_new (browser, item, FALSE, FALSE);
} }
}
static void static void
midori_bookmarks_delete_activate_cb (GtkWidget* menuitem, midori_bookmarks_delete_activate_cb (GtkWidget* menuitem,
@ -772,7 +769,7 @@ midori_bookmarks_popup (GtkWidget* widget,
GtkWidget* menuitem; GtkWidget* menuitem;
menu = gtk_menu_new (); menu = gtk_menu_new ();
if (KATZE_IS_ARRAY (item)) if (ITEM_IS_FOLDER (item))
midori_bookmarks_popup_item (menu, midori_bookmarks_popup_item (menu,
STOCK_TAB_NEW, _("Open all in _Tabs"), STOCK_TAB_NEW, _("Open all in _Tabs"),
item, midori_bookmarks_open_in_tab_activate_cb, bookmarks); item, midori_bookmarks_open_in_tab_activate_cb, bookmarks);
@ -815,9 +812,8 @@ midori_bookmarks_button_release_event_cb (GtkWidget* widget,
if (event->button == 2) if (event->button == 2)
{ {
const gchar* uri = katze_item_get_uri (item); const gchar* uri;
if (ITEM_IS_BOOKMARK (item) && (uri = katze_item_get_uri (item)) && *uri)
if (uri && *uri)
{ {
MidoriBrowser* browser; MidoriBrowser* browser;
gint n; gint n;
@ -830,6 +826,7 @@ midori_bookmarks_button_release_event_cb (GtkWidget* widget,
else else
midori_bookmarks_popup (widget, event, item, bookmarks); midori_bookmarks_popup (widget, event, item, bookmarks);
if (item != NULL)
g_object_unref (item); g_object_unref (item);
return TRUE; return TRUE;
} }