#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
midori_browser_edit_bookmark_dialog_new (MidoriBrowser* browser,
KatzeItem* bookmark,
int type = 0;
gchar* parent;
- if (katze_item_get_uri (item))
+ if (ITEM_IS_BOOKMARK (item))
type = 1;
if (folder)
gchar* sqlcmd;
char* errmsg = NULL;
- if (katze_item_get_uri (item))
+ if (ITEM_IS_BOOKMARK (item))
sqlcmd = sqlite3_mprintf (
"DELETE FROM bookmarks WHERE uri = '%q'",
katze_item_get_uri (item));
&model, &iter))
{
KatzeItem* item;
- gboolean is_separator;
+ MidoriBrowser* browser;
gtk_tree_model_get (model, &iter, 0, &item, -1);
- is_separator = item && !katze_item_get_uri (item);
- if (!is_separator)
- {
- MidoriBrowser* browser = midori_browser_get_for_widget (toolitem);
- midori_browser_edit_bookmark_dialog_new (browser, item, FALSE, FALSE);
- }
+ g_assert (!ITEM_IS_SEPARATOR (item));
+
+ browser = midori_browser_get_for_widget (toolitem);
+ midori_browser_edit_bookmark_dialog_new (browser, item, FALSE, FALSE);
+
g_object_unref (item);
}
}
if (katze_tree_view_get_selected_iter (treeview, &model, &iter))
{
- gboolean is_separator;
-
gtk_tree_model_get (model, &iter, 0, &item, -1);
- if (!item)
- return;
- is_separator = !katze_item_get_uri (item);
- gtk_widget_set_sensitive (bookmarks->edit, !is_separator);
+
+ gtk_widget_set_sensitive (bookmarks->edit, !ITEM_IS_SEPARATOR (item));
gtk_widget_set_sensitive (bookmarks->delete, TRUE);
- g_object_unref (item);
+ if (item != NULL)
+ g_object_unref (item);
}
else
{
/* TODO: Would it be better to not do this on every redraw? */
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,
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);
g_object_set (renderer, "pixbuf", pixbuf, NULL);
const gchar* uri;
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);
if (label)
GTK_BIN (menuitem))), label);
if (!strcmp (stock_id, GTK_STOCK_EDIT))
gtk_widget_set_sensitive (menuitem,
- KATZE_IS_ARRAY (item) || uri != NULL);
- else if (!KATZE_IS_ARRAY (item) && strcmp (stock_id, GTK_STOCK_DELETE))
+ !ITEM_IS_SEPARATOR (item));
+ else if (!ITEM_IS_FOLDER (item) && strcmp (stock_id, GTK_STOCK_DELETE))
gtk_widget_set_sensitive (menuitem, uri != NULL);
g_object_set_data (G_OBJECT (menuitem), "KatzeItem", item);
g_signal_connect (menuitem, "activate", G_CALLBACK (callback), bookmarks);
const gchar* uri;
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));
midori_browser_set_current_uri (browser, uri);
guint n;
item = (KatzeItem*)g_object_get_data (G_OBJECT (menuitem), "KatzeItem");
- if (KATZE_IS_ARRAY (item))
+ if (ITEM_IS_FOLDER (item))
{
KatzeItem* child;
guint i = 0;
+ g_return_if_fail (KATZE_IS_ARRAY (item));
while ((child = katze_array_get_nth_item (KATZE_ARRAY (item), i)))
{
if ((uri = katze_item_get_uri (child)) && *uri)
MidoriBookmarks* bookmarks)
{
KatzeItem* item;
- gboolean is_separator;
+ MidoriBrowser* browser;
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)
- {
- MidoriBrowser* browser = midori_browser_get_for_widget (GTK_WIDGET (bookmarks));
- midori_browser_edit_bookmark_dialog_new (browser, item, FALSE, FALSE);
- }
+ browser = midori_browser_get_for_widget (GTK_WIDGET (bookmarks));
+ midori_browser_edit_bookmark_dialog_new (browser, item, FALSE, FALSE);
}
static void
GtkWidget* menuitem;
menu = gtk_menu_new ();
- if (KATZE_IS_ARRAY (item))
+ if (ITEM_IS_FOLDER (item))
midori_bookmarks_popup_item (menu,
STOCK_TAB_NEW, _("Open all in _Tabs"),
item, midori_bookmarks_open_in_tab_activate_cb, bookmarks);
if (event->button == 2)
{
- const gchar* uri = katze_item_get_uri (item);
-
- if (uri && *uri)
+ const gchar* uri;
+ if (ITEM_IS_BOOKMARK (item) && (uri = katze_item_get_uri (item)) && *uri)
{
MidoriBrowser* browser;
gint n;
else
midori_bookmarks_popup (widget, event, item, bookmarks);
- g_object_unref (item);
+ if (item != NULL)
+ g_object_unref (item);
return TRUE;
}
return FALSE;