2005-09-15 09:58:31 -04:00
|
|
|
/* Menu system */
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "elinks.h"
|
|
|
|
|
|
|
|
#include "bfu/dialog.h"
|
|
|
|
#include "bfu/leds.h"
|
|
|
|
#include "bfu/menu.h"
|
|
|
|
#include "config/options.h"
|
|
|
|
#include "config/urlhist.h"
|
|
|
|
#include "document/document.h"
|
|
|
|
#include "document/view.h"
|
|
|
|
#include "dialogs/exmode.h"
|
|
|
|
#include "dialogs/info.h"
|
|
|
|
#include "dialogs/menu.h"
|
|
|
|
#include "dialogs/options.h"
|
2021-08-08 15:25:08 -04:00
|
|
|
#include "intl/libintl.h"
|
2005-09-15 09:58:31 -04:00
|
|
|
#include "main/event.h"
|
|
|
|
#include "main/main.h"
|
|
|
|
#include "main/select.h"
|
|
|
|
#include "mime/dialogs.h"
|
|
|
|
#include "mime/mime.h"
|
|
|
|
#include "network/connection.h"
|
|
|
|
#include "osdep/osdep.h"
|
|
|
|
#include "osdep/newwin.h"
|
|
|
|
#include "protocol/protocol.h"
|
|
|
|
#include "protocol/uri.h"
|
|
|
|
#include "session/download.h"
|
|
|
|
#include "session/history.h"
|
|
|
|
#include "session/location.h"
|
|
|
|
#include "session/session.h"
|
|
|
|
#include "session/task.h"
|
|
|
|
#include "terminal/tab.h"
|
|
|
|
#include "terminal/terminal.h"
|
|
|
|
#include "util/conv.h"
|
|
|
|
#include "util/file.h"
|
|
|
|
#include "util/memlist.h"
|
|
|
|
#include "util/memory.h"
|
|
|
|
#include "util/string.h"
|
|
|
|
#include "viewer/action.h"
|
|
|
|
#include "viewer/text/link.h"
|
|
|
|
#include "viewer/text/view.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* Helper for url items in help menu. */
|
|
|
|
static void
|
|
|
|
menu_url_shortcut(struct terminal *term, void *url_, void *ses_)
|
|
|
|
{
|
2022-01-25 11:39:39 -05:00
|
|
|
char *url = (char *)url_;
|
|
|
|
struct session *ses = (struct session *)ses_;
|
2022-01-14 14:52:17 -05:00
|
|
|
struct uri *uri = get_uri(url, URI_NONE);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
if (!uri) return;
|
|
|
|
goto_uri(ses, uri);
|
|
|
|
done_uri(uri);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-01-02 10:20:27 -05:00
|
|
|
save_url(struct session *ses, char *url)
|
2005-09-15 09:58:31 -04:00
|
|
|
{
|
|
|
|
struct document_view *doc_view;
|
|
|
|
struct uri *uri;
|
|
|
|
|
|
|
|
assert(ses && ses->tab && ses->tab->term && url);
|
|
|
|
if_assert_failed return;
|
|
|
|
|
|
|
|
if (!*url) return;
|
|
|
|
|
|
|
|
uri = get_translated_uri(url, ses->tab->term->cwd);
|
|
|
|
if (!uri) {
|
2008-08-03 08:24:26 -04:00
|
|
|
print_error_dialog(ses, connection_state(S_BAD_URL),
|
|
|
|
uri, PRI_CANCEL);
|
2005-09-15 09:58:31 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ses->download_uri) done_uri(ses->download_uri);
|
|
|
|
ses->download_uri = uri;
|
|
|
|
|
|
|
|
doc_view = current_frame(ses);
|
|
|
|
assert(doc_view && doc_view->document && doc_view->document->uri);
|
|
|
|
if_assert_failed return;
|
|
|
|
|
|
|
|
set_session_referrer(ses, doc_view->document->uri);
|
|
|
|
query_file(ses, ses->download_uri, ses, start_download, NULL, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
save_url_as(struct session *ses)
|
|
|
|
{
|
|
|
|
input_dialog(ses->tab->term, NULL,
|
|
|
|
N_("Save URL"), N_("Enter URL"),
|
|
|
|
ses, &goto_url_history,
|
|
|
|
MAX_STR_LEN, "", 0, 0, NULL,
|
2021-01-02 10:20:27 -05:00
|
|
|
(void (*)(void *, char *)) save_url,
|
2005-09-15 09:58:31 -04:00
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2007-03-10 16:50:56 -05:00
|
|
|
static void
|
|
|
|
really_exit_prog(void *ses_)
|
2005-09-15 09:58:31 -04:00
|
|
|
{
|
2022-01-25 11:39:39 -05:00
|
|
|
struct session *ses = (struct session *)ses_;
|
2007-03-10 16:50:56 -05:00
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
register_bottom_half(destroy_terminal, ses->tab->term);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2007-03-10 16:50:56 -05:00
|
|
|
dont_exit_prog(void *ses_)
|
2005-09-15 09:58:31 -04:00
|
|
|
{
|
2022-01-25 11:39:39 -05:00
|
|
|
struct session *ses = (struct session *)ses_;
|
2007-03-10 16:50:56 -05:00
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
ses->exit_query = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
query_exit(struct session *ses)
|
|
|
|
{
|
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(query_exit)] */
|
2005-09-15 09:58:31 -04:00
|
|
|
ses->exit_query = 1;
|
|
|
|
msg_box(ses->tab->term, NULL, 0,
|
|
|
|
N_("Exit ELinks"), ALIGN_CENTER,
|
|
|
|
(ses->tab->term->next == ses->tab->term->prev && are_there_downloads())
|
|
|
|
? N_("Do you really want to exit ELinks "
|
|
|
|
"(and terminate all downloads)?")
|
|
|
|
: N_("Do you really want to exit ELinks?"),
|
|
|
|
ses, 2,
|
2007-03-10 16:50:56 -05:00
|
|
|
MSG_BOX_BUTTON(N_("~Yes"), really_exit_prog, B_ENTER),
|
|
|
|
MSG_BOX_BUTTON(N_("~No"), dont_exit_prog, B_ESC));
|
2005-09-15 09:58:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
exit_prog(struct session *ses, int query)
|
|
|
|
{
|
|
|
|
assert(ses);
|
|
|
|
|
|
|
|
/* An exit query is in progress. */
|
|
|
|
if (ses->exit_query)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Force a query if the last terminal is exiting with downloads still in
|
|
|
|
* progress. */
|
|
|
|
if (query || (list_is_singleton(terminals) && are_there_downloads())) {
|
|
|
|
query_exit(ses);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
really_exit_prog(ses);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
go_historywards(struct terminal *term, void *target_, void *ses_)
|
|
|
|
{
|
2022-01-25 11:39:39 -05:00
|
|
|
struct location *target = (struct location *)target_;
|
|
|
|
struct session *ses = (struct session *)ses_;
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
go_history(ses, target);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct menu_item no_hist_menu[] = {
|
|
|
|
INIT_MENU_ITEM(N_("No history"), NULL, ACT_MAIN_NONE, NULL, NULL, NO_SELECT),
|
|
|
|
NULL_MENU_ITEM
|
|
|
|
};
|
|
|
|
|
|
|
|
/* unhist == 0 => history
|
|
|
|
* unhist == 1 => unhistory */
|
|
|
|
static void
|
|
|
|
history_menu_common(struct terminal *term, struct session *ses, int unhist)
|
|
|
|
{
|
|
|
|
struct menu_item *mi = NULL;
|
|
|
|
|
|
|
|
if (have_location(ses)) {
|
|
|
|
struct location *loc;
|
|
|
|
|
|
|
|
for (loc = unhist ? cur_loc(ses)->next : cur_loc(ses)->prev;
|
|
|
|
loc != (struct location *) &ses->history.history;
|
|
|
|
loc = unhist ? loc->next : loc->prev) {
|
2021-01-02 10:20:27 -05:00
|
|
|
char *url;
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
if (!mi) {
|
|
|
|
mi = new_menu(FREE_LIST | FREE_TEXT | NO_INTL);
|
|
|
|
if (!mi) return;
|
|
|
|
}
|
|
|
|
|
|
|
|
url = get_uri_string(loc->vs.uri, URI_PUBLIC);
|
|
|
|
if (url) {
|
|
|
|
add_to_menu(&mi, url, NULL, ACT_MAIN_NONE,
|
|
|
|
go_historywards,
|
|
|
|
(void *) loc, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mi)
|
|
|
|
do_menu(term, no_hist_menu, ses, 0);
|
|
|
|
else
|
|
|
|
do_menu(term, mi, ses, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
history_menu(struct terminal *term, void *xxx, void *ses_)
|
|
|
|
{
|
2022-01-25 11:39:39 -05:00
|
|
|
struct session *ses = (struct session *)ses_;
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
history_menu_common(term, ses, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
unhistory_menu(struct terminal *term, void *xxx, void *ses_)
|
|
|
|
{
|
2022-01-25 11:39:39 -05:00
|
|
|
struct session *ses = (struct session *)ses_;
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
history_menu_common(term, ses, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tab_menu(struct session *ses, int x, int y, int place_above_cursor)
|
|
|
|
{
|
2006-03-11 12:59:40 -05:00
|
|
|
/* [gettext_accelerator_context(tab_menu)] */
|
2005-09-15 09:58:31 -04:00
|
|
|
struct menu_item *menu;
|
2006-09-28 17:50:46 -04:00
|
|
|
int tabs_count;
|
2005-09-15 09:58:31 -04:00
|
|
|
#ifdef CONFIG_BOOKMARKS
|
|
|
|
int anonymous = get_cmd_opt_bool("anonymous");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
assert(ses && ses->tab);
|
|
|
|
if_assert_failed return;
|
|
|
|
|
2006-09-28 17:50:46 -04:00
|
|
|
tabs_count = number_of_tabs(ses->tab->term);
|
2005-09-15 09:58:31 -04:00
|
|
|
menu = new_menu(FREE_LIST);
|
|
|
|
if (!menu) return;
|
|
|
|
|
|
|
|
add_menu_action(&menu, N_("Go ~back"), ACT_MAIN_HISTORY_MOVE_BACK);
|
|
|
|
add_menu_action(&menu, N_("Go for~ward"), ACT_MAIN_HISTORY_MOVE_FORWARD);
|
|
|
|
|
|
|
|
if (have_location(ses)) {
|
|
|
|
add_menu_separator(&menu);
|
|
|
|
|
|
|
|
#ifdef CONFIG_BOOKMARKS
|
|
|
|
if (!anonymous) {
|
|
|
|
add_menu_action(&menu, N_("Bookm~ark document"), ACT_MAIN_ADD_BOOKMARK);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-01-26 23:09:18 -05:00
|
|
|
add_menu_action(&menu, N_("Toggle ~HTML/plain"), ACT_MAIN_TOGGLE_HTML_PLAIN);
|
2005-09-15 09:58:31 -04:00
|
|
|
add_menu_action(&menu, N_("~Reload"), ACT_MAIN_RELOAD);
|
|
|
|
|
|
|
|
if (ses->doc_view && document_has_frames(ses->doc_view->document)) {
|
|
|
|
add_menu_action(&menu, N_("Frame at ~full-screen"), ACT_MAIN_FRAME_MAXIMIZE);
|
2006-03-11 12:59:40 -05:00
|
|
|
add_uri_command_to_menu(&menu, PASS_URI_FRAME,
|
|
|
|
N_("~Pass frame URI to external command"));
|
2005-09-15 09:58:31 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Keep tab related operations below this separator */
|
|
|
|
add_menu_separator(&menu);
|
|
|
|
|
2006-09-28 17:50:46 -04:00
|
|
|
if (tabs_count > 1) {
|
2005-09-15 09:58:31 -04:00
|
|
|
add_menu_action(&menu, N_("Nex~t tab"), ACT_MAIN_TAB_NEXT);
|
|
|
|
add_menu_action(&menu, N_("Pre~v tab"), ACT_MAIN_TAB_PREV);
|
|
|
|
}
|
|
|
|
|
|
|
|
add_menu_action(&menu, N_("~Close tab"), ACT_MAIN_TAB_CLOSE);
|
|
|
|
|
2006-09-28 17:50:46 -04:00
|
|
|
if (tabs_count > 1) {
|
2005-09-15 09:58:31 -04:00
|
|
|
add_menu_action(&menu, N_("C~lose all tabs but the current"),
|
|
|
|
ACT_MAIN_TAB_CLOSE_ALL_BUT_CURRENT);
|
|
|
|
#ifdef CONFIG_BOOKMARKS
|
|
|
|
if (!anonymous) {
|
|
|
|
add_menu_action(&menu, N_("B~ookmark all tabs"),
|
|
|
|
ACT_MAIN_ADD_BOOKMARK_TABS);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2006-03-11 12:59:40 -05:00
|
|
|
if (have_location(ses)) {
|
|
|
|
add_uri_command_to_menu(&menu, PASS_URI_TAB,
|
|
|
|
N_("Pass tab URI to e~xternal command"));
|
|
|
|
}
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
/* Adjust the menu position taking the menu frame into account */
|
|
|
|
if (place_above_cursor) {
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
while (menu[i].text) i++;
|
|
|
|
|
|
|
|
y = int_max(y - i - 1, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
set_window_ptr(ses->tab, x, y);
|
|
|
|
|
|
|
|
do_menu(ses->tab->term, menu, ses, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
do_submenu(struct terminal *term, void *menu_, void *ses_)
|
|
|
|
{
|
2022-01-25 11:39:39 -05:00
|
|
|
struct menu_item *menu = (struct menu_item *)menu_;
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
do_menu(term, menu, ses_, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static struct menu_item file_menu11[] = {
|
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(.file_menu)] */
|
2005-09-15 09:58:31 -04:00
|
|
|
INIT_MENU_ACTION(N_("Open new ~tab"), ACT_MAIN_OPEN_NEW_TAB),
|
|
|
|
INIT_MENU_ACTION(N_("Open new tab in backgroun~d"), ACT_MAIN_OPEN_NEW_TAB_IN_BACKGROUND),
|
|
|
|
INIT_MENU_ACTION(N_("~Go to URL"), ACT_MAIN_GOTO_URL),
|
|
|
|
INIT_MENU_ACTION(N_("Go ~back"), ACT_MAIN_HISTORY_MOVE_BACK),
|
|
|
|
INIT_MENU_ACTION(N_("Go ~forward"), ACT_MAIN_HISTORY_MOVE_FORWARD),
|
|
|
|
INIT_MENU_ITEM(N_("~History"), NULL, ACT_MAIN_NONE, history_menu, NULL, SUBMENU),
|
|
|
|
INIT_MENU_ITEM(N_("~Unhistory"), NULL, ACT_MAIN_NONE, unhistory_menu, NULL, SUBMENU),
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct menu_item file_menu21[] = {
|
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(.file_menu)] */
|
2005-09-15 09:58:31 -04:00
|
|
|
BAR_MENU_ITEM,
|
|
|
|
INIT_MENU_ACTION(N_("~Save as"), ACT_MAIN_SAVE_AS),
|
|
|
|
INIT_MENU_ACTION(N_("Save UR~L as"), ACT_MAIN_SAVE_URL_AS),
|
|
|
|
INIT_MENU_ACTION(N_("Sa~ve formatted document"), ACT_MAIN_SAVE_FORMATTED),
|
|
|
|
#ifdef CONFIG_BOOKMARKS
|
|
|
|
INIT_MENU_ACTION(N_("Bookm~ark document"), ACT_MAIN_ADD_BOOKMARK),
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct menu_item file_menu22[] = {
|
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(.file_menu)] */
|
2005-09-15 09:58:31 -04:00
|
|
|
BAR_MENU_ITEM,
|
|
|
|
INIT_MENU_ACTION(N_("~Kill background connections"), ACT_MAIN_KILL_BACKGROUNDED_CONNECTIONS),
|
|
|
|
INIT_MENU_ACTION(N_("Flush all ~caches"), ACT_MAIN_CACHE_MINIMIZE),
|
|
|
|
INIT_MENU_ACTION(N_("Resource ~info"), ACT_MAIN_RESOURCE_INFO),
|
|
|
|
BAR_MENU_ITEM,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct menu_item file_menu3[] = {
|
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(.file_menu)] */
|
2005-09-15 09:58:31 -04:00
|
|
|
BAR_MENU_ITEM,
|
|
|
|
INIT_MENU_ACTION(N_("E~xit"), ACT_MAIN_QUIT),
|
|
|
|
NULL_MENU_ITEM,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
do_file_menu(struct terminal *term, void *xxx, void *ses_)
|
|
|
|
{
|
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(.file_menu)] */
|
2005-09-15 09:58:31 -04:00
|
|
|
struct menu_item *file_menu, *e, *f;
|
|
|
|
int anonymous = get_cmd_opt_bool("anonymous");
|
|
|
|
int x, o;
|
|
|
|
|
2022-01-16 13:09:27 -05:00
|
|
|
file_menu = (struct menu_item *)mem_alloc(sizeof(file_menu11) + sizeof(file_menu21)
|
2005-09-15 09:58:31 -04:00
|
|
|
+ sizeof(file_menu22) + sizeof(file_menu3)
|
|
|
|
+ 3 * sizeof(struct menu_item));
|
|
|
|
if (!file_menu) return;
|
|
|
|
|
|
|
|
e = file_menu;
|
|
|
|
|
|
|
|
if (!anonymous
|
|
|
|
&& !get_cmd_opt_bool("no-connect")
|
|
|
|
&& !get_cmd_opt_bool("no-home"))
|
|
|
|
o = can_open_in_new(term);
|
|
|
|
else
|
|
|
|
o = 0;
|
|
|
|
|
|
|
|
if (o) {
|
|
|
|
SET_MENU_ITEM(e, N_("Open ~new window"), NULL, ACT_MAIN_OPEN_NEW_WINDOW,
|
|
|
|
open_in_new_window, send_open_new_window,
|
2006-08-12 12:39:45 -04:00
|
|
|
(o - 1) ? SUBMENU : 0, HKS_SHOW, 0);
|
2005-09-15 09:58:31 -04:00
|
|
|
e++;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(e, file_menu11, sizeof(file_menu11));
|
|
|
|
e += sizeof_array(file_menu11);
|
|
|
|
|
|
|
|
if (!anonymous) {
|
|
|
|
memcpy(e, file_menu21, sizeof(file_menu21));
|
|
|
|
e += sizeof_array(file_menu21);
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(e, file_menu22, sizeof(file_menu22));
|
|
|
|
e += sizeof_array(file_menu22);
|
|
|
|
|
|
|
|
x = 1;
|
|
|
|
if (!anonymous && can_open_os_shell(term->environment)) {
|
|
|
|
SET_MENU_ITEM(e, N_("~OS shell"), NULL, ACT_MAIN_OPEN_OS_SHELL,
|
2006-08-12 12:39:45 -04:00
|
|
|
NULL, NULL, 0, HKS_SHOW, 0);
|
2005-09-15 09:58:31 -04:00
|
|
|
e++;
|
|
|
|
x = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (can_resize_window(term->environment)) {
|
|
|
|
SET_MENU_ITEM(e, N_("Resize t~erminal"), NULL, ACT_MAIN_TERMINAL_RESIZE,
|
2006-08-12 12:39:45 -04:00
|
|
|
NULL, NULL, 0, HKS_SHOW, 0);
|
2005-09-15 09:58:31 -04:00
|
|
|
e++;
|
|
|
|
x = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(e, file_menu3 + x, sizeof(file_menu3) - x * sizeof(struct menu_item));
|
|
|
|
e += sizeof_array(file_menu3);
|
|
|
|
|
|
|
|
for (f = file_menu; f < e; f++)
|
|
|
|
f->flags |= FREE_LIST;
|
|
|
|
|
|
|
|
do_menu(term, file_menu, ses_, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct menu_item view_menu[] = {
|
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(.view_menu)] */
|
2005-09-15 09:58:31 -04:00
|
|
|
INIT_MENU_ACTION(N_("~Search"), ACT_MAIN_SEARCH),
|
|
|
|
INIT_MENU_ACTION(N_("Search ~backward"), ACT_MAIN_SEARCH_BACK),
|
|
|
|
INIT_MENU_ACTION(N_("Find ~next"), ACT_MAIN_FIND_NEXT),
|
|
|
|
INIT_MENU_ACTION(N_("Find ~previous"), ACT_MAIN_FIND_NEXT_BACK),
|
|
|
|
INIT_MENU_ACTION(N_("T~ypeahead search"), ACT_MAIN_SEARCH_TYPEAHEAD),
|
|
|
|
BAR_MENU_ITEM,
|
2008-01-26 23:09:18 -05:00
|
|
|
INIT_MENU_ACTION(N_("Toggle ~HTML/plain"), ACT_MAIN_TOGGLE_HTML_PLAIN),
|
2005-09-15 09:58:31 -04:00
|
|
|
INIT_MENU_ACTION(N_("Toggle i~mages"), ACT_MAIN_TOGGLE_DISPLAY_IMAGES),
|
|
|
|
INIT_MENU_ACTION(N_("Toggle ~link numbering"), ACT_MAIN_TOGGLE_NUMBERED_LINKS),
|
|
|
|
INIT_MENU_ACTION(N_("Toggle ~document colors"), ACT_MAIN_TOGGLE_DOCUMENT_COLORS),
|
|
|
|
INIT_MENU_ACTION(N_("~Wrap text on/off"), ACT_MAIN_TOGGLE_WRAP_TEXT),
|
|
|
|
BAR_MENU_ITEM,
|
|
|
|
INIT_MENU_ACTION(N_("Document ~info"), ACT_MAIN_DOCUMENT_INFO),
|
|
|
|
INIT_MENU_ACTION(N_("H~eader info"), ACT_MAIN_HEADER_INFO),
|
|
|
|
INIT_MENU_ACTION(N_("Rel~oad document"), ACT_MAIN_RELOAD),
|
|
|
|
INIT_MENU_ACTION(N_("~Rerender document"), ACT_MAIN_RERENDER),
|
|
|
|
INIT_MENU_ACTION(N_("Frame at ~full-screen"), ACT_MAIN_FRAME_MAXIMIZE),
|
|
|
|
BAR_MENU_ITEM,
|
|
|
|
INIT_MENU_ACTION(N_("Nex~t tab"), ACT_MAIN_TAB_NEXT),
|
|
|
|
INIT_MENU_ACTION(N_("Pre~v tab"), ACT_MAIN_TAB_PREV),
|
|
|
|
INIT_MENU_ACTION(N_("~Close tab"), ACT_MAIN_TAB_CLOSE),
|
|
|
|
NULL_MENU_ITEM
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static struct menu_item help_menu[] = {
|
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(.help_menu)] */
|
2007-10-03 05:23:29 -04:00
|
|
|
INIT_MENU_ITEM(N_("~ELinks homepage"), NULL, ACT_MAIN_NONE, menu_url_shortcut, ELINKS_WEBSITE_URL, 0),
|
2005-09-15 09:58:31 -04:00
|
|
|
INIT_MENU_ITEM(N_("~Documentation"), NULL, ACT_MAIN_NONE, menu_url_shortcut, ELINKS_DOC_URL, 0),
|
|
|
|
INIT_MENU_ITEM(N_("~Keys"), NULL, ACT_MAIN_NONE, menu_keys, NULL, 0),
|
|
|
|
#ifdef CONFIG_LEDS
|
|
|
|
INIT_MENU_ITEM(N_("LED ~indicators"), NULL, ACT_MAIN_NONE, menu_leds_info, NULL, 0),
|
|
|
|
#endif
|
|
|
|
BAR_MENU_ITEM,
|
|
|
|
INIT_MENU_ITEM(N_("~Bugs information"), NULL, ACT_MAIN_NONE, menu_url_shortcut, ELINKS_BUGS_URL, 0),
|
|
|
|
#ifdef CONFIG_DEBUG
|
2005-09-17 06:57:19 -04:00
|
|
|
INIT_MENU_ITEM(N_("ELinks ~GITWeb"), NULL, ACT_MAIN_NONE, menu_url_shortcut, ELINKS_GITWEB_URL, 0),
|
2005-09-15 09:58:31 -04:00
|
|
|
#endif
|
|
|
|
BAR_MENU_ITEM,
|
|
|
|
INIT_MENU_ITEM(N_("~Copying"), NULL, ACT_MAIN_NONE, menu_copying, NULL, 0),
|
2007-10-03 05:16:37 -04:00
|
|
|
INIT_MENU_ITEM(N_("Autho~rs"), NULL, ACT_MAIN_NONE, menu_url_shortcut, ELINKS_AUTHORS_URL, 0),
|
2005-09-15 09:58:31 -04:00
|
|
|
INIT_MENU_ITEM(N_("~About"), NULL, ACT_MAIN_NONE, menu_about, NULL, 0),
|
|
|
|
NULL_MENU_ITEM
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static struct menu_item ext_menu[] = {
|
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(.ext_menu)] */
|
2005-09-15 09:58:31 -04:00
|
|
|
INIT_MENU_ITEM(N_("~Add"), NULL, ACT_MAIN_NONE, menu_add_ext, NULL, 0),
|
|
|
|
INIT_MENU_ITEM(N_("~Modify"), NULL, ACT_MAIN_NONE, menu_list_ext, menu_add_ext, SUBMENU),
|
|
|
|
INIT_MENU_ITEM(N_("~Delete"), NULL, ACT_MAIN_NONE, menu_list_ext, menu_del_ext, SUBMENU),
|
|
|
|
NULL_MENU_ITEM
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct menu_item setup_menu[] = {
|
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(.setup_menu)] */
|
2005-09-15 09:58:31 -04:00
|
|
|
#ifdef CONFIG_NLS
|
|
|
|
INIT_MENU_ITEM(N_("~Language"), NULL, ACT_MAIN_NONE, menu_language_list, NULL, SUBMENU),
|
|
|
|
#endif
|
|
|
|
INIT_MENU_ITEM(N_("C~haracter set"), NULL, ACT_MAIN_NONE, charset_list, NULL, SUBMENU),
|
|
|
|
INIT_MENU_ACTION(N_("~Terminal options"), ACT_MAIN_SHOW_TERM_OPTIONS),
|
|
|
|
INIT_MENU_ITEM(N_("File ~extensions"), NULL, ACT_MAIN_NONE, do_submenu, ext_menu, SUBMENU),
|
|
|
|
BAR_MENU_ITEM,
|
|
|
|
INIT_MENU_ACTION(N_("~Options manager"), ACT_MAIN_OPTIONS_MANAGER),
|
|
|
|
INIT_MENU_ACTION(N_("~Keybinding manager"), ACT_MAIN_KEYBINDING_MANAGER),
|
|
|
|
INIT_MENU_ACTION(N_("~Save options"), ACT_MAIN_SAVE_OPTIONS),
|
|
|
|
NULL_MENU_ITEM
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct menu_item setup_menu_anon[] = {
|
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(.setup_menu)] */
|
2005-09-15 09:58:31 -04:00
|
|
|
INIT_MENU_ITEM(N_("~Language"), NULL, ACT_MAIN_NONE, menu_language_list, NULL, SUBMENU),
|
|
|
|
INIT_MENU_ITEM(N_("C~haracter set"), NULL, ACT_MAIN_NONE, charset_list, NULL, SUBMENU),
|
|
|
|
INIT_MENU_ACTION(N_("~Terminal options"), ACT_MAIN_SHOW_TERM_OPTIONS),
|
|
|
|
NULL_MENU_ITEM
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct menu_item tools_menu[] = {
|
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(.tools_menu)] */
|
2005-09-15 09:58:31 -04:00
|
|
|
#ifdef CONFIG_GLOBHIST
|
|
|
|
INIT_MENU_ACTION(N_("Global ~history"), ACT_MAIN_HISTORY_MANAGER),
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_BOOKMARKS
|
|
|
|
INIT_MENU_ACTION(N_("~Bookmarks"), ACT_MAIN_BOOKMARK_MANAGER),
|
|
|
|
#endif
|
|
|
|
INIT_MENU_ACTION(N_("~Cache"), ACT_MAIN_CACHE_MANAGER),
|
|
|
|
INIT_MENU_ACTION(N_("~Downloads"), ACT_MAIN_DOWNLOAD_MANAGER),
|
|
|
|
#ifdef CONFIG_COOKIES
|
|
|
|
INIT_MENU_ACTION(N_("Coo~kies"), ACT_MAIN_COOKIE_MANAGER),
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_FORMHIST
|
|
|
|
INIT_MENU_ACTION(N_("~Form history"), ACT_MAIN_FORMHIST_MANAGER),
|
|
|
|
#endif
|
|
|
|
INIT_MENU_ACTION(N_("~Authentication"), ACT_MAIN_AUTH_MANAGER),
|
|
|
|
NULL_MENU_ITEM
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
do_setup_menu(struct terminal *term, void *xxx, void *ses_)
|
|
|
|
{
|
2022-01-25 11:39:39 -05:00
|
|
|
struct session *ses = (struct session *)ses_;
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
if (!get_cmd_opt_bool("anonymous"))
|
|
|
|
do_menu(term, setup_menu, ses, 1);
|
|
|
|
else
|
|
|
|
do_menu(term, setup_menu_anon, ses, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct menu_item main_menu[] = {
|
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(.main_menu)] */
|
2005-09-15 09:58:31 -04:00
|
|
|
INIT_MENU_ITEM(N_("~File"), NULL, ACT_MAIN_NONE, do_file_menu, NULL, FREE_LIST | SUBMENU),
|
|
|
|
INIT_MENU_ITEM(N_("~View"), NULL, ACT_MAIN_NONE, do_submenu, view_menu, FREE_LIST | SUBMENU),
|
|
|
|
INIT_MENU_ITEM(N_("~Link"), NULL, ACT_MAIN_NONE, link_menu, NULL, FREE_LIST | SUBMENU),
|
|
|
|
INIT_MENU_ITEM(N_("~Tools"), NULL, ACT_MAIN_NONE, do_submenu, tools_menu, FREE_LIST | SUBMENU),
|
|
|
|
INIT_MENU_ITEM(N_("~Setup"), NULL, ACT_MAIN_NONE, do_setup_menu, NULL, FREE_LIST | SUBMENU),
|
|
|
|
INIT_MENU_ITEM(N_("~Help"), NULL, ACT_MAIN_NONE, do_submenu, help_menu, FREE_LIST | SUBMENU),
|
|
|
|
NULL_MENU_ITEM
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
activate_bfu_technology(struct session *ses, int item)
|
|
|
|
{
|
|
|
|
do_mainmenu(ses->tab->term, main_menu, ses, item);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2021-01-02 10:20:27 -05:00
|
|
|
dialog_goto_url(struct session *ses, char *url)
|
2005-09-15 09:58:31 -04:00
|
|
|
{
|
|
|
|
input_dialog(ses->tab->term, NULL,
|
|
|
|
N_("Go to URL"), N_("Enter URL"),
|
|
|
|
ses, &goto_url_history,
|
|
|
|
MAX_STR_LEN, url, 0, 0, NULL,
|
2021-01-02 10:20:27 -05:00
|
|
|
(void (*)(void *, char *)) goto_url_with_hook,
|
2005-09-15 09:58:31 -04:00
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static INIT_INPUT_HISTORY(file_history);
|
|
|
|
|
|
|
|
void
|
|
|
|
query_file(struct session *ses, struct uri *uri, void *data,
|
2021-01-02 10:20:27 -05:00
|
|
|
void (*std)(void *, char *),
|
2005-09-15 09:58:31 -04:00
|
|
|
void (*cancel)(void *), int interactive)
|
|
|
|
{
|
2019-04-21 06:27:40 -04:00
|
|
|
struct string def;
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
assert(ses && uri);
|
|
|
|
if_assert_failed return;
|
|
|
|
|
|
|
|
/* FIXME: This ``sanity'' checking is mostly for the download code
|
|
|
|
* using this function. They pass ses->download_uri and we have to make
|
|
|
|
* sure that the connection code can download the URI. The reason we do
|
|
|
|
* it before is that then users won't waste time typing a filename and
|
|
|
|
* then discover that the URI can not be downloaded. However it might
|
|
|
|
* be better to introduce a set_session_download_uri() which will do
|
|
|
|
* the checking? --jonas */
|
|
|
|
|
|
|
|
if (uri->protocol == PROTOCOL_UNKNOWN) {
|
2008-08-03 08:24:26 -04:00
|
|
|
print_error_dialog(ses, connection_state(S_UNKNOWN_PROTOCOL),
|
|
|
|
uri, PRI_CANCEL);
|
2005-09-15 09:58:31 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (get_protocol_external_handler(ses->tab->term, uri)) {
|
2008-08-03 08:24:26 -04:00
|
|
|
print_error_dialog(ses, connection_state(S_EXTERNAL_PROTOCOL),
|
|
|
|
uri, PRI_CANCEL);
|
2005-09-15 09:58:31 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!init_string(&def)) return;
|
|
|
|
|
2007-08-28 12:41:18 -04:00
|
|
|
add_to_string(&def, get_opt_str("document.download.directory", NULL));
|
2005-09-15 09:58:31 -04:00
|
|
|
if (def.length && !dir_sep(def.source[def.length - 1]))
|
|
|
|
add_char_to_string(&def, '/');
|
|
|
|
|
|
|
|
add_mime_filename_to_string(&def, uri);
|
|
|
|
|
|
|
|
/* Remove the %-ugliness for display */
|
2006-09-17 09:12:47 -04:00
|
|
|
#ifdef CONFIG_UTF8
|
2007-05-20 08:31:02 -04:00
|
|
|
if (ses->tab->term->utf8_cp)
|
2006-03-12 19:54:34 -05:00
|
|
|
decode_uri_string(&def);
|
|
|
|
else
|
2006-09-17 09:12:47 -04:00
|
|
|
#endif /* CONFIG_UTF8 */
|
2006-03-12 19:54:34 -05:00
|
|
|
decode_uri_string_for_display(&def);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
if (interactive) {
|
|
|
|
input_dialog(ses->tab->term, NULL,
|
|
|
|
N_("Download"), N_("Save to file"),
|
|
|
|
data, &file_history,
|
|
|
|
MAX_STR_LEN, def.source, 0, 0, check_nonempty,
|
2021-01-02 10:20:27 -05:00
|
|
|
(void (*)(void *, char *)) std,
|
2005-09-15 09:58:31 -04:00
|
|
|
(void (*)(void *)) cancel);
|
|
|
|
} else {
|
|
|
|
std(data, def.source);
|
|
|
|
}
|
|
|
|
|
|
|
|
done_string(&def);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
free_history_lists(void)
|
|
|
|
{
|
|
|
|
free_list(file_history.entries);
|
|
|
|
#ifdef CONFIG_SCRIPTING
|
|
|
|
trigger_event_name("free-history");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2022-02-08 12:08:53 -05:00
|
|
|
add_cmdline_bool_option(struct string *string, const char *name)
|
2005-09-15 09:58:31 -04:00
|
|
|
{
|
|
|
|
if (!get_cmd_opt_bool(name)) return;
|
|
|
|
add_to_string(string, " -");
|
|
|
|
add_to_string(string, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
open_uri_in_new_window(struct session *ses, struct uri *uri, struct uri *referrer,
|
2022-01-28 11:37:43 -05:00
|
|
|
term_env_type_T env, cache_mode_T cache_mode,
|
2005-09-15 09:58:31 -04:00
|
|
|
enum task_type task)
|
|
|
|
{
|
|
|
|
int ring = get_cmd_opt_int("session-ring");
|
2019-04-21 06:27:40 -04:00
|
|
|
struct string parameters;
|
2005-09-15 09:58:31 -04:00
|
|
|
int id;
|
|
|
|
|
|
|
|
assert(env && ses);
|
|
|
|
if_assert_failed return;
|
|
|
|
|
|
|
|
id = add_session_info(ses, uri, referrer, cache_mode, task);
|
|
|
|
if (id < 1) return;
|
|
|
|
|
|
|
|
if (!init_string(¶meters)) return;
|
|
|
|
|
|
|
|
add_format_to_string(¶meters, "-base-session %d", id);
|
|
|
|
if (ring) add_format_to_string(¶meters, " -session-ring %d", ring);
|
|
|
|
|
|
|
|
/* No URI means open new (clean) window possibly without connecting to
|
|
|
|
* the current master so add command line options to properly clone the
|
|
|
|
* current master */
|
|
|
|
if (!uri) {
|
|
|
|
/* Adding -touch-files will only lead to problems */
|
|
|
|
add_cmdline_bool_option(¶meters, "localhost");
|
|
|
|
add_cmdline_bool_option(¶meters, "no-home");
|
|
|
|
add_cmdline_bool_option(¶meters, "no-connect");
|
|
|
|
}
|
|
|
|
|
|
|
|
open_new_window(ses->tab->term, program.path, env, parameters.source);
|
|
|
|
done_string(¶meters);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Open a link in a new xterm. */
|
|
|
|
void
|
|
|
|
send_open_in_new_window(struct terminal *term, const struct open_in_new *open,
|
|
|
|
struct session *ses)
|
|
|
|
{
|
|
|
|
struct document_view *doc_view;
|
|
|
|
struct link *link;
|
|
|
|
struct uri *uri;
|
|
|
|
|
|
|
|
assert(term && open && ses);
|
|
|
|
if_assert_failed return;
|
|
|
|
doc_view = current_frame(ses);
|
|
|
|
assert(doc_view && doc_view->vs && doc_view->document);
|
|
|
|
if_assert_failed return;
|
|
|
|
|
|
|
|
link = get_current_link(doc_view);
|
|
|
|
if (!link) return;
|
|
|
|
|
|
|
|
uri = get_link_uri(ses, doc_view, link);
|
|
|
|
if (!uri) return;
|
|
|
|
|
|
|
|
open_uri_in_new_window(ses, uri, NULL, open->env,
|
|
|
|
CACHE_MODE_NORMAL, TASK_NONE);
|
|
|
|
done_uri(uri);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
send_open_new_window(struct terminal *term, const struct open_in_new *open,
|
|
|
|
struct session *ses)
|
|
|
|
{
|
|
|
|
open_uri_in_new_window(ses, NULL, NULL, open->env,
|
|
|
|
CACHE_MODE_NORMAL, TASK_NONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
open_in_new_window(struct terminal *term, void *func_, void *ses_)
|
|
|
|
{
|
2022-01-25 11:39:39 -05:00
|
|
|
menu_func_T func = (menu_func_T)func_;
|
|
|
|
struct session *ses = (struct session *)ses_;
|
2005-09-15 09:58:31 -04:00
|
|
|
struct menu_item *mi;
|
|
|
|
int posibilities;
|
|
|
|
|
|
|
|
assert(term && ses && func);
|
|
|
|
if_assert_failed return;
|
|
|
|
|
|
|
|
switch (can_open_in_new(term)) {
|
|
|
|
case 0:
|
|
|
|
return;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
mi = NULL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
mi = new_menu(FREE_LIST);
|
|
|
|
if (!mi) return;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach_open_in_new (posibilities, term->environment) {
|
|
|
|
const struct open_in_new *oi = &open_in_new[posibilities];
|
|
|
|
|
|
|
|
if (mi == NULL) {
|
|
|
|
func(term, (void *) oi, ses);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
add_to_menu(&mi, oi->text, NULL, ACT_MAIN_NONE, func, (void *) oi, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
do_menu(term, mi, ses, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2021-01-02 10:20:27 -05:00
|
|
|
add_new_win_to_menu(struct menu_item **mi, char *text,
|
2005-09-15 09:58:31 -04:00
|
|
|
struct terminal *term)
|
|
|
|
{
|
|
|
|
int c = can_open_in_new(term);
|
|
|
|
|
|
|
|
if (!c) return;
|
|
|
|
|
|
|
|
/* The URI is saved as session info in the master and not sent to the
|
|
|
|
* instance in the new window so with -no-connect or -no-home enabled
|
|
|
|
* it is not possible to open links URIs. For -anonymous one window
|
|
|
|
* should be enough. */
|
|
|
|
if (get_cmd_opt_bool("no-connect")
|
|
|
|
|| get_cmd_opt_bool("no-home")
|
|
|
|
|| get_cmd_opt_bool("anonymous"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
add_to_menu(mi, text, NULL, ACT_MAIN_OPEN_LINK_IN_NEW_WINDOW,
|
|
|
|
open_in_new_window,
|
2022-02-21 10:13:40 -05:00
|
|
|
(void *)send_open_in_new_window, c - 1 ? SUBMENU : 0);
|
2005-09-15 09:58:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
do_pass_uri_to_command(struct terminal *term, void *command_, void *xxx)
|
|
|
|
{
|
2022-01-25 11:39:39 -05:00
|
|
|
char *command = (char *)command_;
|
2021-03-21 20:00:34 -04:00
|
|
|
int block = command[0] == 'b' ? TERM_EXEC_BG : TERM_EXEC_FG;
|
2005-09-15 09:58:31 -04:00
|
|
|
|
2021-03-21 20:00:34 -04:00
|
|
|
exec_on_terminal(term, command + 1, "", block);
|
2005-09-15 09:58:31 -04:00
|
|
|
mem_free(command);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO:
|
|
|
|
* - Support for passing MIME type
|
|
|
|
* - Merge this function with rewrite_uri(), subst_cmd(), subst_file()
|
|
|
|
* and subst_url(). */
|
2021-01-02 10:20:27 -05:00
|
|
|
static char *
|
|
|
|
format_command(char *format, struct uri *uri)
|
2005-09-15 09:58:31 -04:00
|
|
|
{
|
2019-04-21 06:27:40 -04:00
|
|
|
struct string string;
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
if (!init_string(&string)) return NULL;
|
|
|
|
|
|
|
|
while (*format) {
|
|
|
|
int pos = 0;
|
|
|
|
|
|
|
|
while (format[pos] && format[pos] != '%') pos++;
|
|
|
|
|
|
|
|
add_bytes_to_string(&string, format, pos);
|
|
|
|
format += pos;
|
|
|
|
|
|
|
|
if (*format != '%') continue;
|
|
|
|
|
|
|
|
format++;
|
|
|
|
switch (*format) {
|
|
|
|
case 'c':
|
|
|
|
{
|
2021-01-02 10:20:27 -05:00
|
|
|
char *str = struri(uri);
|
2005-09-15 09:58:31 -04:00
|
|
|
int length = get_real_uri_length(uri);
|
|
|
|
|
|
|
|
add_shell_quoted_to_string(&string,
|
|
|
|
str, length);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case '%':
|
|
|
|
add_char_to_string(&string, '%');
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
add_bytes_to_string(&string, format - 1, 2);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (*format) format++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return string.source;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum frame_event_status
|
|
|
|
pass_uri_to_command(struct session *ses, struct document_view *doc_view,
|
|
|
|
int which_type)
|
|
|
|
{
|
2007-08-28 12:41:18 -04:00
|
|
|
LIST_OF(struct option) *tree = get_opt_tree("document.uri_passing",
|
|
|
|
NULL);
|
2022-01-28 09:20:30 -05:00
|
|
|
pass_uri_type_T type = which_type;
|
2005-09-15 09:58:31 -04:00
|
|
|
struct menu_item *items;
|
2021-03-21 20:00:34 -04:00
|
|
|
struct option *option, *sub;
|
2005-09-15 09:58:31 -04:00
|
|
|
struct uri *uri;
|
|
|
|
int commands = 0;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case PASS_URI_FRAME:
|
2020-10-29 15:40:08 -04:00
|
|
|
uri = get_uri_reference((doc_view->vs && doc_view->vs->uri)
|
|
|
|
? doc_view->vs->uri : doc_view->document->uri);
|
2005-09-15 09:58:31 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PASS_URI_LINK:
|
|
|
|
{
|
|
|
|
struct link *link = get_current_link(doc_view);
|
|
|
|
|
|
|
|
if (!link) return FRAME_EVENT_OK;
|
|
|
|
|
|
|
|
uri = get_link_uri(ses, doc_view, link);
|
|
|
|
if (!uri) return FRAME_EVENT_OK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
case PASS_URI_TAB:
|
2020-10-29 14:21:14 -04:00
|
|
|
uri = have_location(ses) ? cur_loc(ses)->vs.uri : ses->loading_uri;
|
|
|
|
if (!uri) {
|
|
|
|
return FRAME_EVENT_OK;
|
|
|
|
}
|
|
|
|
uri = get_uri_reference(uri);
|
2005-09-15 09:58:31 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
items = new_menu(FREE_LIST | FREE_TEXT | FREE_DATA | NO_INTL);
|
|
|
|
if (!items) {
|
|
|
|
done_uri(uri);
|
|
|
|
return FRAME_EVENT_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (option, *tree) {
|
2021-03-21 20:00:34 -04:00
|
|
|
char *text, *command, *data;
|
|
|
|
int block;
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
if (!strcmp(option->name, "_template_"))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
text = stracpy(option->name);
|
|
|
|
if (!text) continue;
|
|
|
|
|
2021-03-21 20:00:34 -04:00
|
|
|
command = NULL;
|
|
|
|
block = 0;
|
|
|
|
|
|
|
|
foreach (sub, *option->value.tree) {
|
|
|
|
if (!strcmp(sub->name, "command"))
|
|
|
|
command = sub->value.string;
|
|
|
|
if (!strcmp(sub->name, "foreground"))
|
|
|
|
block = sub->value.number;
|
|
|
|
}
|
|
|
|
|
2021-03-22 04:54:41 -04:00
|
|
|
if (!command) {
|
|
|
|
mem_free(text);
|
2021-03-21 20:00:34 -04:00
|
|
|
continue;
|
2021-03-22 04:54:41 -04:00
|
|
|
}
|
2021-03-21 20:00:34 -04:00
|
|
|
|
|
|
|
data = format_command(command, uri);
|
2005-09-15 09:58:31 -04:00
|
|
|
if (!data) {
|
|
|
|
mem_free(text);
|
|
|
|
continue;
|
|
|
|
}
|
2021-03-21 20:00:34 -04:00
|
|
|
insert_in_string(&data, 0, " ", 1);
|
|
|
|
data[0] = block ? 'f' : 'b';
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
add_to_menu(&items, text, NULL, ACT_MAIN_NONE,
|
|
|
|
do_pass_uri_to_command, data, 0);
|
|
|
|
commands++;
|
|
|
|
}
|
|
|
|
|
|
|
|
done_uri(uri);
|
|
|
|
|
|
|
|
if (commands > 1) {
|
|
|
|
do_menu(ses->tab->term, items, ses, 1);
|
|
|
|
} else {
|
|
|
|
if (commands == 1)
|
|
|
|
do_pass_uri_to_command(ses->tab->term, items->data, ses);
|
|
|
|
else
|
|
|
|
mem_free(items->data);
|
|
|
|
mem_free(items->text);
|
|
|
|
mem_free(items);
|
|
|
|
}
|
|
|
|
|
|
|
|
return FRAME_EVENT_OK;
|
|
|
|
}
|
|
|
|
|
2006-03-11 12:59:40 -05:00
|
|
|
/* The caller provides the text of the menu item, so that it can
|
|
|
|
* choose an available accelerator key. */
|
2005-09-15 09:58:31 -04:00
|
|
|
void
|
2022-01-28 09:20:30 -05:00
|
|
|
add_uri_command_to_menu(struct menu_item **mi, pass_uri_type_T type,
|
2021-01-02 10:20:27 -05:00
|
|
|
char *text)
|
2005-09-15 09:58:31 -04:00
|
|
|
{
|
2007-08-28 12:41:18 -04:00
|
|
|
LIST_OF(struct option) *tree = get_opt_tree("document.uri_passing",
|
|
|
|
NULL);
|
2005-09-15 09:58:31 -04:00
|
|
|
struct option *option;
|
|
|
|
int commands = 0;
|
2022-01-28 08:35:18 -05:00
|
|
|
menu_item_flags_T flags = NO_FLAG;
|
2005-09-15 09:58:31 -04:00
|
|
|
action_id_T action_id;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case PASS_URI_FRAME:
|
|
|
|
action_id = ACT_MAIN_FRAME_EXTERNAL_COMMAND;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PASS_URI_LINK:
|
|
|
|
action_id = ACT_MAIN_LINK_EXTERNAL_COMMAND;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
case PASS_URI_TAB:
|
|
|
|
action_id = ACT_MAIN_TAB_EXTERNAL_COMMAND;
|
|
|
|
};
|
|
|
|
|
|
|
|
foreach (option, *tree) {
|
|
|
|
if (!strcmp(option->name, "_template_"))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
commands++;
|
|
|
|
if (commands > 1) {
|
|
|
|
flags = SUBMENU;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (commands == 0) return;
|
|
|
|
|
|
|
|
add_to_menu(mi, text, NULL, action_id, NULL, NULL, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* The file completion menu always has two non selectable menu item at the
|
|
|
|
* start. First is the 'Directory:' or 'Files:' text and then a separator. */
|
|
|
|
#define FILE_COMPLETION_MENU_OFFSET 2
|
|
|
|
|
|
|
|
static struct menu_item empty_directory_menu[] = {
|
|
|
|
INIT_MENU_ITEM(N_("Empty directory"), NULL, ACT_MAIN_NONE, NULL, NULL, NO_SELECT),
|
|
|
|
NULL_MENU_ITEM
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Builds the file completion menu. If there is only one item it is selected
|
|
|
|
* else the menu is launched. */
|
|
|
|
static void
|
|
|
|
complete_file_menu(struct terminal *term, int no_elevator, void *data,
|
|
|
|
menu_func_T file_func, menu_func_T dir_func,
|
2021-01-02 10:20:27 -05:00
|
|
|
char *dirname, char *filename)
|
2005-09-15 09:58:31 -04:00
|
|
|
{
|
|
|
|
struct menu_item *menu = new_menu(FREE_LIST | NO_INTL);
|
|
|
|
struct directory_entry *entries, *entry;
|
|
|
|
int filenamelen = strlen(filename);
|
|
|
|
int direntries = 0, fileentries = 0;
|
|
|
|
|
|
|
|
if (!menu) return;
|
|
|
|
|
|
|
|
entries = get_directory_entries(dirname, 1);
|
|
|
|
if (!entries) {
|
|
|
|
mem_free(menu);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (entry = entries; entry->name; entry++) {
|
2021-01-02 10:20:27 -05:00
|
|
|
char *text;
|
2005-09-15 09:58:31 -04:00
|
|
|
int is_dir = (*entry->attrib == 'd');
|
|
|
|
int is_file = (*entry->attrib == '-');
|
|
|
|
|
|
|
|
mem_free(entry->attrib);
|
|
|
|
if ((!is_dir && !is_file) || !file_can_read(entry->name)) {
|
|
|
|
mem_free(entry->name);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
text = get_filename_position(entry->name);
|
|
|
|
if (strncmp(filename, text, filenamelen)
|
|
|
|
|| (no_elevator && !strcmp("..", text))) {
|
|
|
|
mem_free(entry->name);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_dir) {
|
|
|
|
if (!direntries) {
|
|
|
|
add_to_menu(&menu, _("Directories:", term), NULL,
|
|
|
|
ACT_MAIN_NONE, NULL, NULL, NO_SELECT);
|
|
|
|
add_menu_separator(&menu);
|
|
|
|
}
|
|
|
|
|
|
|
|
add_to_menu(&menu, text, NULL, ACT_MAIN_NONE,
|
|
|
|
dir_func, entry->name, FREE_DATA | SUBMENU);
|
|
|
|
|
|
|
|
direntries++;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if (!fileentries) {
|
|
|
|
if (direntries) add_menu_separator(&menu);
|
|
|
|
add_to_menu(&menu, _("Files:", term), NULL,
|
|
|
|
ACT_MAIN_NONE, NULL, NULL, NO_SELECT);
|
|
|
|
add_menu_separator(&menu);
|
|
|
|
}
|
|
|
|
|
|
|
|
add_to_menu(&menu, text, NULL, ACT_MAIN_NONE,
|
|
|
|
file_func, entry->name, FREE_DATA);
|
|
|
|
|
|
|
|
fileentries++;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mem_free(entries);
|
|
|
|
if (direntries == 0 && fileentries == 0) {
|
|
|
|
mem_free(menu);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Only one entry */
|
|
|
|
if (direntries + fileentries == 1) {
|
2022-01-25 11:39:39 -05:00
|
|
|
char *text = (char *)menu[FILE_COMPLETION_MENU_OFFSET].data;
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
mem_free(menu);
|
|
|
|
|
|
|
|
if (fileentries) {
|
|
|
|
/* Complete what is already there */
|
|
|
|
file_func(term, text, data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* For single directory entries open the lonely subdir if it is
|
|
|
|
* not the parent elevator. */
|
|
|
|
if (strcmp(&text[strlen(dirname)], "..")) {
|
|
|
|
dir_func(term, text, data);
|
|
|
|
} else {
|
|
|
|
do_menu(term, empty_directory_menu, NULL, 0); \
|
|
|
|
}
|
|
|
|
|
|
|
|
mem_free(text);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
/* Start with the first directory or file entry selected */
|
|
|
|
do_menu(term, menu, data, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Prepares the launching of the file completion menu by expanding the @path
|
|
|
|
* and splitting it in directory and file name part. */
|
|
|
|
void
|
2021-01-02 10:20:27 -05:00
|
|
|
auto_complete_file(struct terminal *term, int no_elevator, char *path,
|
2005-09-15 09:58:31 -04:00
|
|
|
menu_func_T file_func, menu_func_T dir_func, void *data)
|
|
|
|
{
|
|
|
|
struct uri *uri;
|
2021-01-02 10:20:27 -05:00
|
|
|
char *dirname;
|
|
|
|
char *filename;
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
assert(term && data && file_func && dir_func && data);
|
|
|
|
|
|
|
|
if (get_cmd_opt_bool("anonymous"))
|
|
|
|
return;
|
|
|
|
|
2022-02-18 08:54:32 -05:00
|
|
|
if (!*path) path = (char *)"./";
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
/* Use the URI translation to handle ./ and ../ and ~/ expansion */
|
|
|
|
uri = get_translated_uri(path, term->cwd);
|
|
|
|
if (!uri) return;
|
|
|
|
|
|
|
|
if (uri->protocol != PROTOCOL_FILE) {
|
|
|
|
path = NULL;
|
|
|
|
} else {
|
|
|
|
path = get_uri_string(uri, URI_PATH);
|
|
|
|
}
|
|
|
|
|
|
|
|
done_uri(uri);
|
|
|
|
if (!path) return;
|
|
|
|
|
|
|
|
filename = get_filename_position(path);
|
|
|
|
|
|
|
|
if (*filename && file_is_dir(path)) {
|
|
|
|
filename = path + strlen(path);
|
|
|
|
|
|
|
|
} else if (*filename && file_exists(path)) {
|
|
|
|
/* Complete any tilde expansion */
|
|
|
|
file_func(term, path, data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Split the path into @dirname and @filename */
|
|
|
|
dirname = path;
|
|
|
|
path = filename;
|
|
|
|
filename = stracpy(path);
|
|
|
|
*path = 0;
|
|
|
|
|
|
|
|
/* Make sure the dirname has an ending slash */
|
|
|
|
if (!dir_sep(path[-1])) {
|
2021-01-02 10:20:27 -05:00
|
|
|
char separator = *dirname;
|
2005-09-15 09:58:31 -04:00
|
|
|
int dirnamelen = path - dirname;
|
|
|
|
|
|
|
|
insert_in_string(&dirname, dirnamelen, &separator, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
complete_file_menu(term, no_elevator, data,
|
|
|
|
file_func, dir_func, dirname, filename);
|
|
|
|
|
|
|
|
mem_free(dirname);
|
|
|
|
mem_free(filename);
|
|
|
|
}
|