2 * Copyright © 2005 Peter Harvey
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2, or (at your option)
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * $Id: ephy-bookmark-action-group.c 6952 2007-03-11 19:42:02Z chpe $
23 #include "ephy-shell.h"
24 #include "ephy-bookmark-action-group.h"
25 #include "ephy-bookmark-action.h"
26 #include "ephy-bookmarks.h"
27 #include "ephy-bookmarks-ui.h"
28 #include "ephy-link.h"
29 #include "ephy-node.h"
30 #include "ephy-node-common.h"
31 #include "ephy-debug.h"
33 #include <gtk/gtkaction.h>
34 #include <gtk/gtkactiongroup.h>
38 smart_added_cb (EphyNode
*parent
,
40 GtkActionGroup
*action_group
)
43 char name
[EPHY_BOOKMARK_ACTION_NAME_BUFFER_SIZE
];
45 EPHY_BOOKMARK_ACTION_NAME_PRINTF (name
, child
);
47 action
= gtk_action_group_get_action (action_group
, name
);
51 ephy_bookmark_action_updated ((EphyBookmarkAction
*) action
);
56 smart_removed_cb (EphyNode
*parent
,
59 GtkActionGroup
*action_group
)
62 char name
[EPHY_BOOKMARK_ACTION_NAME_BUFFER_SIZE
];
64 EPHY_BOOKMARK_ACTION_NAME_PRINTF (name
, child
);
66 action
= gtk_action_group_get_action (action_group
, name
);
70 ephy_bookmark_action_updated ((EphyBookmarkAction
*) action
);
75 node_changed_cb (EphyNode
*parent
,
78 GtkActionGroup
*action_group
)
81 char name
[EPHY_BOOKMARK_ACTION_NAME_BUFFER_SIZE
];
83 EPHY_BOOKMARK_ACTION_NAME_PRINTF (name
, child
);
85 action
= gtk_action_group_get_action (action_group
, name
);
89 ephy_bookmark_action_updated ((EphyBookmarkAction
*) action
);
94 node_added_cb (EphyNode
*parent
,
96 GtkActionGroup
*action_group
)
99 char name
[EPHY_BOOKMARK_ACTION_NAME_BUFFER_SIZE
];
102 EPHY_BOOKMARK_ACTION_NAME_PRINTF (name
, child
);
104 action
= ephy_bookmark_action_new (child
, name
);
106 g_snprintf (accel
, sizeof (accel
), "<Actions>/%s/%s",
107 gtk_action_group_get_name (action_group
),
109 gtk_action_set_accel_path (action
, accel
);
110 gtk_action_group_add_action (action_group
, action
);
111 g_object_unref (action
);
113 ephy_bookmark_action_updated ((EphyBookmarkAction
*) action
);
115 g_signal_connect_swapped (action
, "open-link",
116 G_CALLBACK (ephy_link_open
), action_group
);
120 node_removed_cb (EphyNode
*parent
,
123 GtkActionGroup
*action_group
)
126 char name
[EPHY_BOOKMARK_ACTION_NAME_BUFFER_SIZE
];
128 EPHY_BOOKMARK_ACTION_NAME_PRINTF (name
, child
);
130 action
= gtk_action_group_get_action (action_group
, name
);
134 gtk_action_group_remove_action (action_group
, action
);
139 ephy_bookmark_group_new (EphyNode
*node
)
141 EphyBookmarks
*bookmarks
;
144 GtkActionGroup
*action_group
;
147 bookmarks
= ephy_shell_get_bookmarks (ephy_shell
);
148 smart
= ephy_bookmarks_get_smart_bookmarks (bookmarks
);
150 action_group
= (GtkActionGroup
*) ephy_link_action_group_new ("BA");
152 children
= ephy_node_get_children (node
);
153 for (i
= 0; i
< children
->len
; i
++)
155 node_added_cb (node
, g_ptr_array_index (children
, i
),
159 ephy_node_signal_connect_object (node
, EPHY_NODE_CHILD_ADDED
,
160 (EphyNodeCallback
) node_added_cb
,
161 (GObject
*) action_group
);
162 ephy_node_signal_connect_object (node
, EPHY_NODE_CHILD_REMOVED
,
163 (EphyNodeCallback
) node_removed_cb
,
164 (GObject
*) action_group
);
165 ephy_node_signal_connect_object (node
, EPHY_NODE_CHILD_CHANGED
,
166 (EphyNodeCallback
) node_changed_cb
,
167 (GObject
*) action_group
);
169 ephy_node_signal_connect_object (smart
, EPHY_NODE_CHILD_ADDED
,
170 (EphyNodeCallback
) smart_added_cb
,
171 (GObject
*) action_group
);
172 ephy_node_signal_connect_object (smart
, EPHY_NODE_CHILD_REMOVED
,
173 (EphyNodeCallback
) smart_removed_cb
,
174 (GObject
*) action_group
);