Commit 02d51b8c authored by Paolo Bacchilega's avatar Paolo Bacchilega
Browse files

added the bookmarks to the headerbar

parent 3729585c
......@@ -5,6 +5,7 @@ context = actions
iconsdir = $(themedir)/$(size)/$(context)
icons_DATA = \
bookmarks-symbolic.svg \
browser-mode.svg \
file-catalog.svg \
file-library.svg \
......
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="16"
height="16"
id="svg2"
version="1.1"
inkscape:version="0.48.4 r9939"
sodipodi:docname="bookmarks-symbolic.svg">
<defs
id="defs4" />
<sodipodi:namedview
id="base"
pagecolor="#555753"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="1"
inkscape:pageshadow="2"
inkscape:zoom="32"
inkscape:cx="4.1967014"
inkscape:cy="10.284634"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="true"
inkscape:snap-grids="false"
inkscape:window-width="1483"
inkscape:window-height="933"
inkscape:window-x="390"
inkscape:window-y="156"
inkscape:window-maximized="0"
showborder="true"
fit-margin-top="0"
fit-margin-right="0"
fit-margin-left="0"
fit-margin-bottom="0"
showguides="true">
<inkscape:grid
type="xygrid"
id="grid7044"
empspacing="8"
visible="true"
enabled="true"
snapvisiblegridlinesonly="true"
originx="-31.97559px"
originy="-816.00002px" />
</sodipodi:namedview>
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title />
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Livello 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(-31.97559,-220.36218)">
<path
style="fill:#bebebe;fill-opacity:1;stroke:none"
d="m 4.02441,0.96879 0.00684,13.96871 4.0625,-3.96875 3.9375,4.0625 0.03125,-14.03123 z"
id="path2996"
inkscape:connector-curvature="0"
transform="translate(31.97559,220.36218)"
sodipodi:nodetypes="cccccc" />
</g>
</svg>
......@@ -10,8 +10,16 @@ libbookmarks_la_SOURCES = \
callbacks.h \
dlg-bookmarks.c \
dlg-bookmarks.h \
resources.c \
resources.h \
main.c
RESOURCES_DEP = $(shell $(GLIB_COMPILE_RESOURCES) --generate-dependencies --sourcedir=$(srcdir) $(srcdir)/gresource.xml)
resources.c: gresource.xml $(RESOURCES_DEP)
$(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate --c-name gth $(srcdir)/gresource.xml
resources.h: gresource.xml $(RESOURCES_DEP)
$(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate --c-name gth $(srcdir)/gresource.xml
libbookmarks_la_CFLAGS = $(GTHUMB_CFLAGS) -I$(top_srcdir) -I$(top_builddir)/gthumb
libbookmarks_la_LDFLAGS = $(EXTENSION_LIBTOOL_FLAGS)
libbookmarks_la_LIBADD = $(GTHUMB_LIBS)
......@@ -24,7 +32,9 @@ extensionini_DATA = $(extensionini_in_files:.extension.in.in=.extension)
@GTHUMB_EXTENSION_IN_RULE@
@GTHUMB_EXTENSION_RULE@
EXTRA_DIST = $(extensionini_in_files)
EXTRA_DIST = \
$(extensionini_in_files) \
gresource.xml
DISTCLEANFILES = $(extensionini_DATA)
......
......@@ -52,3 +52,35 @@ gth_browser_activate_action_bookmarks_edit (GtkAction *action,
{
dlg_bookmarks (browser);
}
void
gth_browser_activate_bookmarks_add (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
GthBrowser *browser = GTH_BROWSER (user_data);
GBookmarkFile *bookmarks;
GFile *location;
char *uri;
location = gth_browser_get_location (browser);
if (location == NULL)
return;
bookmarks = gth_main_get_default_bookmarks ();
uri = g_file_get_uri (location);
_g_bookmark_file_add_uri (bookmarks, uri);
gth_main_bookmarks_changed ();
g_free (uri);
}
void
gth_browser_activate_bookmarks_edit (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
dlg_bookmarks (GTH_BROWSER (user_data));
}
......@@ -29,4 +29,7 @@
DEFINE_ACTION(gth_browser_activate_action_bookmarks_add)
DEFINE_ACTION(gth_browser_activate_action_bookmarks_edit)
DEF_ACTION_CALLBACK (gth_browser_activate_bookmarks_add)
DEF_ACTION_CALLBACK (gth_browser_activate_bookmarks_edit)
#endif /* ACTIONS_H */
......@@ -30,48 +30,19 @@
#define BROWSER_DATA_KEY "bookmarks-browser-data"
static const char *fixed_ui_info =
"<ui>"
" <menubar name='MenuBar'>"
" <placeholder name='OtherMenus'>"
" <menu name='Bookmarks' action='BookmarksMenu'>"
" <menuitem action='Bookmarks_Add'/>"
" <menuitem action='Bookmarks_Edit'/>"
" <separator/>"
" <menu name='SystemBookmarks' action='SystemBookmarksMenu'>"
" </menu>"
" <separator name='EntryPointListSeparator'/>"
" <placeholder name='EntryPointList'/>"
" <separator name='BookmarkListSeparator'/>"
" <placeholder name='BookmarkList'/>"
" </menu>"
" </placeholder>"
" </menubar>"
"</ui>";
static GtkActionEntry bookmarks_action_entries[] = {
{ "BookmarksMenu", NULL, N_("_Bookmarks") },
{ "SystemBookmarksMenu", NULL, N_("_System Bookmarks") },
{ "Bookmarks_Add", GTK_STOCK_ADD,
N_("_Add Bookmark"), "<control>D",
N_("Add current location to bookmarks"),
G_CALLBACK (gth_browser_activate_action_bookmarks_add) },
{ "Bookmarks_Edit", NULL,
N_("_Edit Bookmarks..."), "<control>B",
N_("Edit bookmarks"),
G_CALLBACK (gth_browser_activate_action_bookmarks_edit) },
static const GActionEntry actions[] = {
{ "bookmarks-add", gth_browser_activate_bookmarks_add },
{ "bookmarks-edit", gth_browser_activate_bookmarks_edit }
};
static guint bookmarks_action_entries_size = G_N_ELEMENTS (bookmarks_action_entries);
typedef struct {
GthBrowser *browser;
GtkActionGroup *actions;
guint bookmarks_changed_id;
guint entry_points_changed_id;
GthBrowser *browser;
guint bookmarks_changed_id;
guint entry_points_changed_id;
GMenu *system_bookmarks_menu;
GMenu *entry_points_menu;
GMenu *bookmarks_menu;
} BrowserData;
......@@ -88,6 +59,9 @@ browser_data_free (BrowserData *data)
data->entry_points_changed_id);
data->entry_points_changed_id = 0;
}
_g_object_unref (data->system_bookmarks_menu);
_g_object_unref (data->entry_points_menu);
_g_object_unref (data->bookmarks_menu);
g_free (data);
}
......@@ -118,23 +92,20 @@ static void
update_system_bookmark_list_from_content (GthBrowser *browser,
const char *content)
{
GtkWidget *bookmark_list;
GtkWidget *menu;
char **lines;
int i;
BrowserData *data;
char **lines;
int i;
bookmark_list = gtk_ui_manager_get_widget (gth_browser_get_ui_manager (browser), "/MenuBar/OtherMenus/Bookmarks/SystemBookmarks");
menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (bookmark_list));
_gtk_container_remove_children (GTK_CONTAINER (menu), NULL, NULL);
data = g_object_get_data (G_OBJECT (browser), BROWSER_DATA_KEY);
g_return_if_fail (data != NULL);
lines = g_strsplit (content, "\n", -1);
for (i = 0; lines[i] != NULL; i++) {
char **line;
char *uri;
GFile *file;
GIcon *icon;
char *name;
char **line;
char *uri;
GFile *file;
char *name;
GMenuItem *item;
line = g_strsplit (lines[i], " ", 2);
uri = line[0];
......@@ -144,31 +115,21 @@ update_system_bookmark_list_from_content (GthBrowser *browser,
}
file = g_file_new_for_uri (uri);
icon = _g_file_get_icon (file);
name = g_strdup (strchr (lines[i], ' '));
if (name == NULL)
name = _g_file_get_display_name (file);
if (name == NULL)
name = g_file_get_parse_name (file);
_gth_browser_add_file_menu_item_full (browser,
menu,
file,
icon,
name,
GTH_ACTION_GO_TO,
i,
-1);
item = _g_menu_item_new_for_file (file, name);
g_menu_item_set_action_and_target (item, "win.go-to-location", "s", uri);
g_menu_append_item (data->system_bookmarks_menu, item);
g_free (name);
_g_object_unref (icon);
g_object_unref (file);
g_strfreev (line);
}
g_strfreev (lines);
if (i > 0)
gtk_widget_show (bookmark_list);
g_strfreev (lines);
}
......@@ -208,12 +169,19 @@ update_system_bookmark_list_ready (GObject *source_object,
static void
_gth_browser_update_system_bookmark_list (GthBrowser *browser)
{
BrowserData *browser_data;
GFile *bookmark_file;
GFileInputStream *input_stream;
UpdateBookmarksData *data;
browser_data = g_object_get_data (G_OBJECT (browser), BROWSER_DATA_KEY);
g_return_if_fail (browser_data != NULL);
g_menu_remove_all (browser_data->system_bookmarks_menu);
/* give priority to XDG_CONFIG_HOME/gtk-3.0/bookmarks if not found
* try the old ~/.gtk-bookmarks */
bookmark_file = gth_user_dir_get_file_for_read (GTH_DIR_CONFIG, "gtk-3.0", "bookmarks", NULL);
if (! g_file_query_exists (bookmark_file, NULL)) {
char *path;
......@@ -249,41 +217,31 @@ _gth_browser_update_system_bookmark_list (GthBrowser *browser)
static void
_gth_browser_update_bookmark_list (GthBrowser *browser)
{
GtkWidget *menu;
GtkWidget *bookmark_list;
GtkWidget *bookmark_list_separator;
BrowserData *data;
GBookmarkFile *bookmarks;
char **uris;
gsize length;
int i;
bookmark_list = gtk_ui_manager_get_widget (gth_browser_get_ui_manager (browser), "/MenuBar/OtherMenus/Bookmarks/BookmarkList");
menu = gtk_widget_get_parent (bookmark_list);
data = g_object_get_data (G_OBJECT (browser), BROWSER_DATA_KEY);
g_return_if_fail (data != NULL);
_gtk_container_remove_children (GTK_CONTAINER (menu), bookmark_list, NULL);
g_menu_remove_all (data->bookmarks_menu);
bookmarks = gth_main_get_default_bookmarks ();
uris = g_bookmark_file_get_uris (bookmarks, &length);
bookmark_list_separator = gtk_ui_manager_get_widget (gth_browser_get_ui_manager (browser), "/MenuBar/OtherMenus/Bookmarks/BookmarkListSeparator");
if (length > 0)
gtk_widget_show (bookmark_list_separator);
else
gtk_widget_hide (bookmark_list_separator);
uris = g_bookmark_file_get_uris (bookmarks, NULL);
for (i = 0; uris[i] != NULL; i++) {
GFile *file;
char *name;
GFile *file;
char *name;
GMenuItem *item;
file = g_file_new_for_uri (uris[i]);
name = g_bookmark_file_get_title (bookmarks, uris[i], NULL);
_gth_browser_add_file_menu_item (browser,
menu,
file,
name,
GTH_ACTION_GO_TO,
i);
item = _g_menu_item_new_for_file (file, name);
g_menu_item_set_action_and_target (item, "win.go-to-location", "s", uris[i]);
g_menu_append_item (data->bookmarks_menu, item);
_g_object_unref (item);
g_free (name);
g_object_unref (file);
}
......@@ -306,33 +264,28 @@ bookmarks_changed_cb (GthMonitor *monitor,
static void
_gth_browser_update_entry_point_list (GthBrowser *browser)
{
GtkUIManager *ui;
GtkWidget *separator1;
GtkWidget *separator2;
GtkWidget *menu;
BrowserData *data;
GList *entry_points;
GList *scan;
int position;
ui = gth_browser_get_ui_manager (browser);
separator1 = gtk_ui_manager_get_widget (ui, "/MenuBar/OtherMenus/Bookmarks/EntryPointListSeparator");
separator2 = gtk_ui_manager_get_widget (ui, "/MenuBar/OtherMenus/Bookmarks/BookmarkListSeparator");
menu = gtk_widget_get_parent (separator1);
_gtk_container_remove_children (GTK_CONTAINER (menu), separator1, separator2);
data = g_object_get_data (G_OBJECT (browser), BROWSER_DATA_KEY);
g_return_if_fail (data != NULL);
g_menu_remove_all (data->entry_points_menu);
position = 6;
entry_points = gth_main_get_all_entry_points ();
for (scan = entry_points; scan; scan = scan->next) {
GthFileData *file_data = scan->data;
GMenuItem *item;
char *uri;
_gth_browser_add_file_menu_item_full (browser,
menu,
file_data->file,
g_file_info_get_icon (file_data->info),
g_file_info_get_display_name (file_data->info),
GTH_ACTION_GO_TO,
0,
position++);
item = _g_menu_item_new_for_file (file_data->file, NULL);
uri = g_file_get_uri (file_data->file);
g_menu_item_set_action_and_target (item, "win.go-to-location", "s", uri);
g_menu_append_item (data->entry_points_menu, item);
g_free (uri);
g_object_unref (item);
}
_g_object_list_unref (entry_points);
......@@ -352,28 +305,39 @@ void
bookmarks__gth_browser_construct_cb (GthBrowser *browser)
{
BrowserData *data;
GError *error = NULL;
g_return_if_fail (GTH_IS_BROWSER (browser));
data = g_new0 (BrowserData, 1);
g_object_set_data_full (G_OBJECT (browser), BROWSER_DATA_KEY, data, (GDestroyNotify) browser_data_free);
data->browser = browser;
g_action_map_add_action_entries (G_ACTION_MAP (browser),
actions,
G_N_ELEMENTS (actions),
browser);
{
GtkWidget *button;
GtkBuilder *builder;
button = _gtk_menu_button_new_for_header_bar ();
gtk_widget_set_tooltip_text (button, _("Bookmarks"));
gtk_container_add (GTK_CONTAINER (button), gtk_image_new_from_icon_name ("bookmarks-symbolic", GTK_ICON_SIZE_MENU));
data->actions = gtk_action_group_new ("Bookmarks Actions");
gtk_action_group_set_translation_domain (data->actions, NULL);
gtk_action_group_add_actions (data->actions,
bookmarks_action_entries,
bookmarks_action_entries_size,
browser);
gtk_ui_manager_insert_action_group (gth_browser_get_ui_manager (browser), data->actions, 0);
if (! gtk_ui_manager_add_ui_from_string (gth_browser_get_ui_manager (browser), fixed_ui_info, -1, &error)) {
g_message ("building menus failed: %s", error->message);
g_error_free (error);
builder = gtk_builder_new_from_resource ("/org/gnome/gThumb/bookmarks/data/ui/bookmarks-menu.ui");
data->system_bookmarks_menu = G_MENU (gtk_builder_get_object (builder, "system-bookmarks"));
data->entry_points_menu = G_MENU (gtk_builder_get_object (builder, "entry-points"));
data->bookmarks_menu = G_MENU (gtk_builder_get_object (builder, "bookmarks"));
gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (button), G_MENU_MODEL (gtk_builder_get_object (builder, "bookmarks-menu")));
gtk_widget_show_all (button);
gtk_box_pack_start (GTK_BOX (gth_browser_get_headerbar_section (browser, GTH_BROWSER_HEADER_SECTION_BROWSER_COMMANDS)), button, FALSE, FALSE, 0);
g_object_unref (builder);
}
data->browser = browser;
data->bookmarks_changed_id = g_signal_connect (gth_main_get_default_monitor (),
"bookmarks-changed",
G_CALLBACK (bookmarks_changed_cb),
......
uidir = $(pkgdatadir)/ui
ui_DATA = bookmarks.ui
EXTRA_DIST = $(ui_DATA)
EXTRA_DIST = \
bookmarks.ui \
bookmarks-menu.ui
-include $(top_srcdir)/git.mk
<?xml version="1.0"?>
<interface>
<!-- interface-requires gtk+ 3.0 -->
<menu id="bookmarks-menu">
<section>
<item>
<attribute name="label" translatable="yes">_Add Bookmark</attribute>
<attribute name="action">win.bookmarks-add</attribute>
<attribute name="accel"><![CDATA[<Ctrl>D]]></attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Edit Bookmarks…</attribute>
<attribute name="action">win.bookmarks-edit</attribute>
<attribute name="accel"><![CDATA[<Ctrl>B]]></attribute>
</item>
</section>
<submenu id="system-bookmarks">
<attribute name="label" translatable="yes">_System Bookmarks</attribute>
</submenu>
<section id="entry-points">
</section>
<section id="bookmarks">
</section>
</menu>
</interface>
<?xml version="1.0"?>
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.16.0 on Sat Oct 19 11:45:32 2013 -->
<interface>
<requires lib="gtk+" version="2.16"/>
<!-- interface-naming-policy project-wide -->
<!-- interface-requires gtk+ 3.10 -->
<object class="GtkDialog" id="bookmarks_dialog">
<property name="height_request">300</property>
<property name="height_request">400</property>
<property name="can_focus">False</property>
<property name="border_width">5</property>
<property name="title" translatable="yes">Bookmarks</property>
<property name="type_hint">dialog</property>
<child internal-child="vbox">
<object class="GtkVBox" id="dialog-vbox7">
<object class="GtkBox" id="dialog-vbox7">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child internal-child="action_area">
<object class="GtkButtonBox" id="dialog-action_area7">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="bm_close_button">
<property name="label">gtk-close</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkHBox" id="hbox57">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="border_width">6</property>
<property name="spacing">24</property>
<child>
<object class="GtkVBox" id="vbox47">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<property name="can_focus">False</property>
<property name="spacing">6</property>
<child>
<object class="GtkLabel" id="bm_bookmarks_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">_Bookmarks:</property>
<property name="use_underline">True</property>
......@@ -35,48 +66,99 @@
</packing>
</child>
<child>
<object class="GtkHBox" id="hbox90">
<object class="GtkBox" id="box1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkScrolledWindow" id="bm_list_container">
<property name="width_request">250</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">automatic</property>
<property name="vscrollbar_policy">automatic</property>
<property name="window_placement">bottom-right</property>
<property name="vexpand">True</property>
<property name="window_placement">bottom-left</property>
<property name="shadow_type">etched-in</property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>