1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-09-28 03:06:20 -04:00

Transfer changes for ascii link labeling

This commit is contained in:
Martin Miller 2016-01-31 10:23:08 +01:00 committed by Witold Filipczyk
parent aec900f2ae
commit 28b7bd1ec2
8 changed files with 84 additions and 1 deletions

View File

@ -40,6 +40,7 @@ ACTION_(MAIN, "history-move-forward", HISTORY_MOVE_FORWARD, N__("Go forward in h
ACTION_(MAIN, "jump-to-link", JUMP_TO_LINK, N__("Jump to link"), ACTION_REQUIRE_VIEW_STATE | ACTION_JUMP_TO_LINK),
ACTION_(MAIN, "keybinding-manager", KEYBINDING_MANAGER, N__("Open keybinding manager"), ACTION_RESTRICT_ANONYMOUS),
ACTION_(MAIN, "kill-backgrounded-connections", KILL_BACKGROUNDED_CONNECTIONS, N__("Kill all backgrounded connections"), 0),
ACTION_(MAIN, "link-dialog", LINK_DIALOG, N__("Open link selection dialog"), 0),
ACTION_(MAIN, "link-download", LINK_DOWNLOAD, N__("Download the current link"), ACTION_RESTRICT_ANONYMOUS | ACTION_REQUIRE_VIEW_STATE | ACTION_REQUIRE_LOCATION | ACTION_JUMP_TO_LINK | ACTION_REQUIRE_LINK),
ACTION_(MAIN, "link-download-image", LINK_DOWNLOAD_IMAGE, N__("Download the current image"), ACTION_RESTRICT_ANONYMOUS | ACTION_REQUIRE_VIEW_STATE | ACTION_REQUIRE_LOCATION | ACTION_JUMP_TO_LINK | ACTION_REQUIRE_LINK),
ACTION_(MAIN, "link-download-resume", LINK_DOWNLOAD_RESUME, N__("Attempt to resume download of the current link"), ACTION_RESTRICT_ANONYMOUS | ACTION_REQUIRE_VIEW_STATE | ACTION_REQUIRE_LOCATION | ACTION_JUMP_TO_LINK | ACTION_REQUIRE_LINK),

View File

@ -344,6 +344,12 @@ static union option_info config_options_info[] = {
"the order in which links should receive focus when using the "
"keyboard to navigate the document.")),
INIT_OPT_STRING("document.browse.links", N_("Specify link label key"),
"label_key", 0, "0123456789",
N_("Default is 0123456789, which is standard numeric labeling."
"Ascii based strings like gfdsahjkl;trewqyuiopvcxznm can also"
"be used.")),
INIT_OPT_BOOL("document.browse.links", N_("Missing fragment reporting"),
"missing_fragment", 0, 1,
N_("Open a message box when document has no tag with given "

View File

@ -1500,9 +1500,50 @@ put_chars_conv(struct html_context *html_context,
NULL, (void (*)(void *, unsigned char *, int)) put_chars, html_context);
}
/*
* Converts a number in base 10 to a string in another base whose symbols are
* represented by key. I the trivial case, key="0123456789". A more homerow
* friendly key="gfdsahjkl;trewqyuiopvcxznm". Returns the length of link_sym.
*/
static int
dec2qwerty(int num, char *link_sym, const char *key)
{
int base = strlen(key);
int newlen = 1;
while (pow(base, newlen) < num) ++newlen;
link_sym[newlen] = '\0';
for (int i=1; i<=newlen; ++i) {
int key_index = num % base;
link_sym[newlen-i] = key[key_index];
num /= base;
}
return newlen;
}
/*
* Returns the value of link_sym in decimal according to key.
*/
int
qwerty2dec(const char *link_sym, const char *key)
{
int z = 0;
int base = strlen(key);
int symlen = strlen(link_sym);
for (int i=0; i<symlen; ++i) {
int j=0;
while (key[j] != link_sym[symlen-1-i]) ++j;
z += j*pow(base,i);
}
return z;
}
static inline void
put_link_number(struct html_context *html_context)
{
char *symkey = get_opt_str("document.browse.links.label_key", NULL);
struct part *part = html_context->part;
unsigned char s[64];
unsigned char *fl = format.link;
@ -1515,7 +1556,7 @@ put_link_number(struct html_context *html_context)
format.form = NULL;
s[slen++] = '[';
ulongcat(s, &slen, part->link_num, sizeof(s) - 3, 0);
slen += dec2qwerty(part->link_num, s+1, symkey);
s[slen++] = ']';
s[slen] = '\0';

View File

@ -68,4 +68,5 @@ void free_table_cache(void);
struct part *format_html_part(struct html_context *html_context, unsigned char *, unsigned char *, int, int, int, struct document *, int, int, unsigned char *, int);
int qwerty2dec(const char *link_sym, const char *key);
#endif

View File

@ -44,6 +44,11 @@
#include "viewer/text/search.h"
#include "viewer/text/view.h"
static void
link_dialog_action(struct session *ses)
{
open_link_dialog(ses);
}
static void
goto_url_action(struct session *ses,
@ -277,6 +282,10 @@ do_action(struct session *ses, enum main_action action_id, int verbose)
abort_background_connections();
break;
case ACT_MAIN_LINK_DIALOG:
link_dialog_action(ses);
break;
case ACT_MAIN_LINK_DOWNLOAD:
case ACT_MAIN_LINK_DOWNLOAD_IMAGE:
case ACT_MAIN_LINK_DOWNLOAD_RESUME:

View File

@ -1216,6 +1216,21 @@ goto_link_number(struct session *ses, unsigned char *num)
goto_link_number_do(ses, doc_view, atoi(num) - 1);
}
void
goto_link_symbol(struct session *ses, unsigned char *sym)
{
char *symkey = get_opt_str("document_browse.links.label_key", ses);
struct document_view *doc_view;
assert(ses && sym);
if_assert_failed return;
doc_view = current_frame(ses);
assert(doc_view);
if_assert_failed return;
int num = qwerty2dec(sym, symkey);
goto_link_number_do(ses, doc_view, num - 1);
}
/** See if this document is interested in the key user pressed. */
enum frame_event_status
try_document_key(struct session *ses, struct document_view *doc_view,

View File

@ -49,6 +49,7 @@ void jump_to_link_number(struct session *ses, struct document_view *doc_view, in
struct link *goto_current_link(struct session *ses, struct document_view *, int);
struct link *goto_link(struct session *ses, struct document_view *, struct link *, int);
void goto_link_number(struct session *ses, unsigned char *num);
void goto_link_symbol(struct session *ses, unsigned char *sym);
void get_link_x_bounds(struct link *link, int y, int *min_x, int *max_x);

View File

@ -1025,6 +1025,15 @@ try_mark_key(struct session *ses, struct document_view *doc_view,
}
#endif
void
open_link_dialog(struct session *ses)
{
input_dialog(ses->tab->term, NULL,
N_("Go to link"), N_("Enter link number"),
ses, NULL, MAX_STR_LEN, "", 0, 0, NULL,
(void (*)(void *, unsigned char *)) goto_link_symbol, NULL);
}
static enum frame_event_status
try_prefix_key(struct session *ses, struct document_view *doc_view,
struct term_event *ev)