2005-09-15 09:58:31 -04:00
|
|
|
/* Global history dialogs */
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "elinks.h"
|
|
|
|
|
|
|
|
#include "bfu/dialog.h"
|
|
|
|
#include "bookmarks/dialogs.h"
|
|
|
|
#include "dialogs/edit.h"
|
|
|
|
#include "globhist/dialogs.h"
|
|
|
|
#include "globhist/globhist.h"
|
|
|
|
#include "intl/gettext/libintl.h"
|
|
|
|
#include "main/object.h"
|
|
|
|
#include "protocol/uri.h"
|
|
|
|
#include "terminal/terminal.h"
|
|
|
|
#include "util/memory.h"
|
|
|
|
#include "util/string.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* Implementation of the listbox operations */
|
|
|
|
|
2008-07-08 03:06:31 -04:00
|
|
|
static void
|
|
|
|
lock_globhist_item(struct listbox_item *item)
|
2005-09-15 09:58:31 -04:00
|
|
|
{
|
|
|
|
object_lock((struct global_history_item *) item->udata);
|
|
|
|
}
|
|
|
|
|
2008-07-08 03:06:31 -04:00
|
|
|
static void
|
|
|
|
unlock_globhist_item(struct listbox_item *item)
|
2005-09-15 09:58:31 -04:00
|
|
|
{
|
2008-07-11 07:12:37 -04:00
|
|
|
object_unlock((struct global_history_item *) item->udata);
|
2005-09-15 09:58:31 -04:00
|
|
|
}
|
|
|
|
|
2008-07-08 03:06:31 -04:00
|
|
|
static int
|
|
|
|
is_globhist_item_used(struct listbox_item *item)
|
2005-09-15 09:58:31 -04:00
|
|
|
{
|
|
|
|
return is_object_used((struct global_history_item *) item->udata);
|
|
|
|
}
|
|
|
|
|
2021-01-02 10:20:27 -05:00
|
|
|
static char *
|
2005-09-15 09:58:31 -04:00
|
|
|
get_globhist_item_text(struct listbox_item *box_item, struct terminal *term)
|
|
|
|
{
|
|
|
|
struct global_history_item *item = box_item->udata;
|
2019-04-21 06:27:40 -04:00
|
|
|
struct string info;
|
2005-09-15 09:58:31 -04:00
|
|
|
|
2007-08-28 12:41:18 -04:00
|
|
|
if (get_opt_int("document.history.global.display_type", NULL)
|
2005-09-15 09:58:31 -04:00
|
|
|
&& *item->title)
|
|
|
|
return stracpy(item->title);
|
|
|
|
|
|
|
|
if (!init_string(&info)) return NULL;
|
|
|
|
add_string_uri_to_string(&info, item->url, URI_PUBLIC);
|
|
|
|
return info.source;
|
|
|
|
}
|
|
|
|
|
2021-01-02 10:20:27 -05:00
|
|
|
static char *
|
2005-09-15 09:58:31 -04:00
|
|
|
get_globhist_item_info(struct listbox_item *box_item, struct terminal *term)
|
|
|
|
{
|
|
|
|
struct global_history_item *item = box_item->udata;
|
2019-04-21 06:27:40 -04:00
|
|
|
struct string info;
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
if (box_item->type == BI_FOLDER) return NULL;
|
|
|
|
if (!init_string(&info)) return NULL;
|
|
|
|
|
|
|
|
add_format_to_string(&info, "%s: %s", _("Title", term), item->title);
|
|
|
|
add_format_to_string(&info, "\n%s: %s", _("URL", term), item->url);
|
|
|
|
add_format_to_string(&info, "\n%s: %s", _("Last visit time", term),
|
|
|
|
ctime(&item->last_visit));
|
|
|
|
|
|
|
|
return info.source;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct listbox_item *
|
|
|
|
get_globhist_item_root(struct listbox_item *box_item)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct uri *
|
|
|
|
get_globhist_item_uri(struct listbox_item *item)
|
|
|
|
{
|
|
|
|
struct global_history_item *historyitem = item->udata;
|
|
|
|
|
|
|
|
return get_uri(historyitem->url, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
can_delete_globhist_item(struct listbox_item *item)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
delete_globhist_item(struct listbox_item *item, int last)
|
|
|
|
{
|
|
|
|
struct global_history_item *historyitem = item->udata;
|
|
|
|
|
|
|
|
assert(!is_object_used(historyitem));
|
|
|
|
|
|
|
|
delete_global_history_item(historyitem);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct listbox_ops_messages globhist_messages = {
|
|
|
|
/* cant_delete_item */
|
|
|
|
N_("Sorry, but history entry \"%s\" cannot be deleted."),
|
|
|
|
/* cant_delete_used_item */
|
|
|
|
N_("Sorry, but history entry \"%s\" is being used by something else."),
|
|
|
|
/* cant_delete_folder */
|
|
|
|
NULL,
|
|
|
|
/* cant_delete_used_folder */
|
|
|
|
NULL,
|
|
|
|
/* delete_marked_items_title */
|
|
|
|
N_("Delete marked history entries"),
|
|
|
|
/* delete_marked_items */
|
|
|
|
N_("Delete marked history entries?"),
|
|
|
|
/* delete_folder_title */
|
|
|
|
NULL,
|
|
|
|
/* delete_folder */
|
|
|
|
NULL,
|
|
|
|
/* delete_item_title */
|
|
|
|
N_("Delete history entry"),
|
2006-05-27 01:51:24 -04:00
|
|
|
/* delete_item; xgettext:c-format */
|
2005-09-15 09:58:31 -04:00
|
|
|
N_("Delete this history entry?"),
|
|
|
|
/* clear_all_items_title */
|
|
|
|
N_("Clear all history entries"),
|
|
|
|
/* clear_all_items_title */
|
|
|
|
N_("Do you really want to remove all history entries?"),
|
|
|
|
};
|
|
|
|
|
2007-02-04 08:17:49 -05:00
|
|
|
static const struct listbox_ops gh_listbox_ops = {
|
2005-09-15 09:58:31 -04:00
|
|
|
lock_globhist_item,
|
|
|
|
unlock_globhist_item,
|
|
|
|
is_globhist_item_used,
|
|
|
|
get_globhist_item_text,
|
|
|
|
get_globhist_item_info,
|
|
|
|
get_globhist_item_uri,
|
|
|
|
get_globhist_item_root,
|
|
|
|
NULL,
|
|
|
|
can_delete_globhist_item,
|
|
|
|
delete_globhist_item,
|
|
|
|
NULL,
|
|
|
|
&globhist_messages,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Searching: */
|
|
|
|
|
|
|
|
static void
|
|
|
|
history_search_do(void *data)
|
|
|
|
{
|
|
|
|
struct dialog *dlg = data;
|
|
|
|
struct listbox_item *item = globhist_browser.root.child.next;
|
|
|
|
struct listbox_data *box;
|
|
|
|
|
|
|
|
if (!globhist_simple_search(dlg->widgets[1].data, dlg->widgets[0].data)) return;
|
|
|
|
if (list_empty(globhist_browser.root.child)) return;
|
|
|
|
|
|
|
|
/* Shouldn't we rather do this only for the specific listbox_data box
|
|
|
|
* in dlg->widget->data so only the current dialog is updated? --jonas */
|
|
|
|
foreach (box, globhist_browser.boxes) {
|
|
|
|
box->top = item;
|
|
|
|
box->sel = box->top;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
launch_search_dialog(struct terminal *term, struct dialog_data *parent,
|
|
|
|
struct session *ses)
|
|
|
|
{
|
|
|
|
do_edit_dialog(term, 1, N_("Search history"), gh_last_searched_title,
|
|
|
|
gh_last_searched_url, ses, parent, history_search_do,
|
|
|
|
NULL, NULL, EDIT_DLG_SEARCH);
|
|
|
|
}
|
|
|
|
|
|
|
|
static widget_handler_status_T
|
|
|
|
push_search_button(struct dialog_data *dlg_data, struct widget_data *widget_data)
|
|
|
|
{
|
|
|
|
launch_search_dialog(dlg_data->win->term, dlg_data,
|
|
|
|
(struct session *) dlg_data->dlg->udata);
|
|
|
|
return EVENT_PROCESSED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Toggling: */
|
|
|
|
|
|
|
|
static widget_handler_status_T
|
|
|
|
push_toggle_display_button(struct dialog_data *dlg_data, struct widget_data *widget_data)
|
|
|
|
{
|
|
|
|
int *display_type;
|
|
|
|
|
2007-08-28 12:41:18 -04:00
|
|
|
display_type = &get_opt_int("document.history.global.display_type",
|
|
|
|
NULL);
|
2005-09-15 09:58:31 -04:00
|
|
|
*display_type = !*display_type;
|
|
|
|
|
|
|
|
update_hierbox_browser(&globhist_browser);
|
|
|
|
|
|
|
|
return EVENT_PROCESSED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Bookmarking: */
|
|
|
|
|
|
|
|
#ifdef CONFIG_BOOKMARKS
|
|
|
|
static widget_handler_status_T
|
|
|
|
push_bookmark_button(struct dialog_data *dlg_data,
|
|
|
|
struct widget_data *some_useless_info_button)
|
|
|
|
{
|
|
|
|
struct listbox_data *box = get_dlg_listbox_data(dlg_data);
|
|
|
|
struct terminal *term = dlg_data->win->term;
|
|
|
|
struct global_history_item *historyitem;
|
|
|
|
|
|
|
|
if (!box->sel) return EVENT_PROCESSED;
|
|
|
|
|
|
|
|
historyitem = box->sel->udata;
|
|
|
|
if (!historyitem) return EVENT_PROCESSED;
|
|
|
|
|
|
|
|
launch_bm_add_dialog(term, NULL, NULL,
|
|
|
|
historyitem->title, historyitem->url);
|
|
|
|
|
|
|
|
return EVENT_PROCESSED;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* The global history manager: */
|
|
|
|
|
2007-02-04 06:54:07 -05:00
|
|
|
static const struct hierbox_browser_button globhist_buttons[] = {
|
Here is a framework that detects cases where a PO file assigns
the same accelerator key to multiple buttons in a dialog box or
to multiple items in a menu. ELinks already has some support for
this but it requires the translator to run ELinks and manually
scan through all menus and dialogs. The attached changes make it
possible to quickly detect and list any conflicts, including ones
that can only occur on operating systems or configurations that
the translator is not currently using.
The changes have no immediate effect on the elinks executable or
the MO files. PO files become larger, however.
The scheme works like this:
- Like before, accelerator keys in translatable strings are
tagged with the tilde (~) character.
- Whenever a C source file defines an accelerator key, it must
assign one or more named "contexts" to it. The translations in
the PO files inherit these contexts. If multiple strings use
the same accelerator (case insensitive) in the same context,
that's a conflict and can be detected automatically.
- The contexts are defined with "gettext_accelerator_context"
comments in source files. These comments delimit regions where
all translatable strings containing tildes are given the same
contexts. There must be one special comment at the top of the
region; it lists the contexts assigned to that region. The
region automatically ends at the end of the function (found
with regexp /^\}/), but it can also be closed explicitly with
another special comment. The comments are formatted like this:
/* [gettext_accelerator_context(foo, bar, baz)]
begins a region that uses the contexts "foo", "bar", and "baz".
The comma is the delimiter; whitespace is optional.
[gettext_accelerator_context()]
ends the region. */
The scripts don't currently check whether this syntax occurs
inside or outside comments.
- The names of contexts consist of C identifiers delimited with
periods. I typically used the name of a function that sets
up a dialog, or the name of an array where the items of a
menu are listed. There is a special feature for static
functions: if the name begins with a period, then the period
will be replaced with the name of the source file and a colon.
- If a menu is programmatically generated from multiple parts,
of which some are never used together, so that it is safe to
use the same accelerators in them, then it is necessary to
define multiple contexts for the same menu. link_menu() in
src/viewer/text/link.c is the most complex example of this.
- During make update-po:
- A Perl script (po/gather-accelerator-contexts.pl) reads
po/elinks.pot, scans the source files listed in it for
"gettext_accelerator_context" comments, and rewrites
po/elinks.pot with "accelerator_context" comments that
indicate the contexts of each msgid: the union of all
contexts of all of its uses in the source files. It also
removes any "gettext_accelerator_context" comments that
xgettext --add-comments has copied to elinks.pot.
- If po/gather-accelerator-contexts.pl does not find any
contexts for some use of an msgid that seems to contain an
accelerator (because it contains a tilde), it warns. If the
tilde refers to e.g. "~/.elinks" and does not actually mark
an accelerator, the warning can be silenced by specifying the
special context "IGNORE", which the script otherwise ignores.
- msgmerge copies the "accelerator_context" comments from
po/elinks.pot to po/*.po. Translators do not edit those
comments.
- During make check-po:
- Another Perl script (po/check-accelerator-contexts.pl) reads
po/*.po and keeps track of which accelerators have been bound
in each context. It warns about any conflicts it finds.
This script does not access the C source files; thus it does
not matter if the line numbers in "#:" lines are out of date.
This implementation is not perfect and I am not proposing to
add it to the main source tree at this time. Specifically:
- It introduces compile-time dependencies on Perl and Locale::PO.
There should be a configure-time or compile-time check so that
the new features are skipped if the prerequisites are missing.
- When the scripts include msgstr strings in warnings, they
should transcode them from the charset of the PO file to the
one specified by the user's locale.
- It is not adequately documented (well, except perhaps here).
- po/check-accelerator-contexts.pl reports the same conflict
multiple times if it occurs in multiple contexts.
- The warning messages should include line numbers, so that users
of Emacs could conveniently edit the conflicting part of the PO
file. This is not feasible with the current version of
Locale::PO.
- Locale::PO does not understand #~ lines and spews warnings
about them. There is an ugly hack to hide these warnings.
- Jonas Fonseca suggested the script could propose accelerators
that are still available. This has not been implemented.
There are three files attached:
- po/gather-accelerator-contexts.pl: Augments elinks.pot with
context information.
- po/check-accelerator-contexts.pl: Checks conflicts.
- accelerator-contexts.diff: Makes po/Makefile run the scripts,
and adds special comments to source files.
2005-12-04 18:38:29 -05:00
|
|
|
/* [gettext_accelerator_context(.globhist_buttons)] */
|
2005-09-15 09:58:31 -04:00
|
|
|
{ N_("~Goto"), push_hierbox_goto_button, 1 },
|
|
|
|
{ N_("~Info"), push_hierbox_info_button, 1 },
|
|
|
|
#ifdef CONFIG_BOOKMARKS
|
|
|
|
{ N_("~Bookmark"), push_bookmark_button, 0 },
|
|
|
|
#endif
|
|
|
|
{ N_("~Delete"), push_hierbox_delete_button, 0 },
|
|
|
|
{ N_("~Search"), push_search_button, 1 },
|
|
|
|
{ N_("~Toggle display"), push_toggle_display_button, 1 },
|
|
|
|
{ N_("C~lear"), push_hierbox_clear_button, 0 },
|
|
|
|
#if 0
|
|
|
|
/* TODO: Would this be useful? --jonas */
|
2007-02-04 06:54:07 -05:00
|
|
|
{ N_("Save"), push_save_button, 0 },
|
2005-09-15 09:58:31 -04:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
struct_hierbox_browser(
|
|
|
|
globhist_browser,
|
|
|
|
N_("Global history manager"),
|
|
|
|
globhist_buttons,
|
|
|
|
&gh_listbox_ops
|
|
|
|
);
|
|
|
|
|
|
|
|
void
|
|
|
|
history_manager(struct session *ses)
|
|
|
|
{
|
|
|
|
mem_free_set(&gh_last_searched_title, NULL);
|
|
|
|
mem_free_set(&gh_last_searched_url, NULL);
|
|
|
|
hierbox_browser(&globhist_browser, ses);
|
|
|
|
}
|