📄 hotlist.c
字号:
if (!hotlist_i18n_flag)
{
i = sizeof (hotlist_but) / sizeof (hotlist_but [0]);
while (i--)
hotlist_but [i].text = _(hotlist_but [i].text);
cancel_but = _(cancel_but);
hotlist_i18n_flag = 1;
}
#endif /* ENABLE_NLS */
/* Dynamic resizing of buttonbars */
{
int len[2], count[2]; /* at most two lines of buttons */
int cur_x[2], row;
i = sizeof (hotlist_but) / sizeof (hotlist_but [0]);
len[0] = len[1] = count[0] = count[1] = 0;
/* Count len of buttonbars, assuming 2 extra space between buttons */
while (i--)
{
if (! (hotlist_but[i].type & list_type))
continue;
row = hotlist_but [i].y;
++count [row];
len [row] += strlen (hotlist_but [i].text) + 5;
if (hotlist_but [i].flags == DEFPUSH_BUTTON)
len [row] += 2;
}
len[0] -= 2;
len[1] -= 2;
cols = max(cols, max(len[0], len[1]));
/* arrange buttons */
cur_x[0] = cur_x[1] = 0;
i = sizeof (hotlist_but) / sizeof (hotlist_but [0]);
while (i--)
{
if (! (hotlist_but[i].type & list_type))
continue;
row = hotlist_but [i].y;
if (hotlist_but [i].x != 0)
{
/* not first int the row */
if (!strcmp (hotlist_but [i].text, cancel_but))
hotlist_but [i].x =
cols - strlen (hotlist_but [i].text) - 13;
else
hotlist_but [i].x = cur_x [row];
}
cur_x [row] += strlen (hotlist_but [i].text) + 2
+ (hotlist_but [i].flags == DEFPUSH_BUTTON ? 5 : 3);
}
}
return cols;
}
static void init_hotlist (int list_type)
{
int i;
int hotlist_cols = init_i18n_stuff (list_type, COLS - 6);
do_refresh ();
hotlist_state.expanded = GetPrivateProfileInt ("HotlistConfig",
"expanded_view_of_groups", 0, profile_name);
hotlist_dlg = create_dlg (0, 0, LINES-2, hotlist_cols, dialog_colors,
hotlist_callback,
list_type == LIST_VFSLIST ? "[vfshot]" : "[Hotlist]",
list_type == LIST_VFSLIST ? "vfshot" : "hotlist",
DLG_CENTER|DLG_GRID);
x_set_dialog_title (hotlist_dlg,
list_type == LIST_VFSLIST ? _("Active VFS directories") : _("Directory hotlist"));
#define XTRACT(i) BY+hotlist_but[i].y, BX+hotlist_but[i].x, hotlist_but[i].ret_cmd, hotlist_but[i].flags, hotlist_but[i].text, hotlist_button_callback, 0, hotlist_but[i].tkname
for (i = 0; i < BUTTONS; i++){
if (hotlist_but[i].type & list_type)
add_widgetl (hotlist_dlg, button_new (XTRACT (i)), (i == BUTTONS - 1) ?
XV_WLAY_CENTERROW : XV_WLAY_RIGHTOF);
}
#undef XTRACT
/* We add the labels.
* pname will hold entry's pathname;
* pname_group will hold name of current group
*/
pname = label_new (UY-11+LINES, UX+2, "", "the-lab");
add_widget (hotlist_dlg, pname);
#ifndef HAVE_X
if (!hotlist_state.moving) {
add_widget (hotlist_dlg, label_new (UY-12+LINES, UX+1, _(" Directory path "), NULL));
/* This one holds the displayed pathname */
pname_group = label_new (UY, UX+1, _(" Directory label "), NULL);
add_widget (hotlist_dlg, pname_group);
}
#endif
/* get new listbox */
l_hotlist = listbox_new (UY + 1, UX + 1, COLS-2*UX-8, LINES-14, listbox_cback, l_call, "listbox");
/* Fill the hotlist with the active VFS or the hotlist */
if (list_type == LIST_VFSLIST){
listbox_add_item (l_hotlist, 0, 0, home_dir, 0);
vfs_fill_names (add_name_to_list);
} else
fill_listbox ();
add_widgetl (hotlist_dlg, l_hotlist, XV_WLAY_EXTENDWIDTH);
/* add listbox to the dialogs */
}
static void init_movelist (int list_type, struct hotlist *item)
{
int i;
char *hdr = copy_strings (_("Moving "), item->label, 0);
int movelist_cols = init_i18n_stuff (list_type, COLS - 6);
do_refresh ();
movelist_dlg = create_dlg (0, 0, LINES-6, movelist_cols, dialog_colors,
hotlist_callback, "[Hotlist]",
"movelist",
DLG_CENTER|DLG_GRID);
x_set_dialog_title (movelist_dlg, hdr);
free (hdr);
#define XTRACT(i) BY-4+hotlist_but[i].y, BX+hotlist_but[i].x, hotlist_but[i].ret_cmd, hotlist_but[i].flags, hotlist_but[i].text, hotlist_button_callback, 0, hotlist_but[i].tkname
for (i = 0; i < BUTTONS; i++){
if (hotlist_but[i].type & list_type)
add_widgetl (movelist_dlg, button_new (XTRACT (i)), (i == BUTTONS - 1) ?
XV_WLAY_CENTERROW : XV_WLAY_RIGHTOF);
}
#undef XTRACT
/* We add the labels. We are interested in the last one,
* that one will hold the path name label
*/
#ifndef HAVE_X
movelist_group = label_new (UY, UX+1, _(" Directory label "), NULL);
add_widget (movelist_dlg, movelist_group);
#endif
/* get new listbox */
l_movelist = listbox_new (UY + 1, UX + 1,
movelist_dlg->cols - 2*UX - 2, movelist_dlg->lines - 8,
listbox_cback, l_call, "listbox");
fill_listbox ();
add_widgetl (movelist_dlg, l_movelist, XV_WLAY_EXTENDWIDTH);
/* add listbox to the dialogs */
}
static void hotlist_done (void)
{
destroy_dlg (hotlist_dlg);
if (0)
update_panels (UP_OPTIMIZE, UP_KEEPSEL);
repaint_screen ();
}
static char *
find_group_section (struct hotlist *grp)
{
return copy_strings (grp->directory, ".Group", (char *)0);
}
/* 1.11.96 bor: added pos parameter to control placement of new item.
see widget.c, listbox_add_item()
now hotlist is in unsorted mode
*/
static struct hotlist *
add2hotlist (char *label, char *directory, enum HotListType type, int pos)
{
struct hotlist *current;
struct hotlist *new;
if (l_hotlist && l_hotlist->current)
current = l_hotlist->current->data;
new = new_hotlist ();
new->type = type;
new->label = label;
new->directory = directory;
new->up = current_group;
if (!current_group->head) { /* first element in group */
current_group->head = new;
} else if (pos == 2) { /* should be appended after current*/
new->next = current->next;
current->next = new;
} else if (pos == 1 &&
current == current_group->head) {
/* should be inserted before first item */
new->next = current;
current_group->head = new;
} else if (pos == 1) { /* befor current */
struct hotlist *p = current_group->head;
while (p->next != current)
p = p->next;
new->next = current;
p->next = new;
} else { /* append at the end */
struct hotlist *p = current_group->head;
while (p->next)
p = p->next;
p->next = new;
}
if (hotlist_state.running && type != HL_TYPE_COMMENT) {
if (type == HL_TYPE_GROUP) {
char *lbl = copy_strings ("->", new->label, (char *)0);
listbox_add_item (l_hotlist, pos, 0, lbl, new);
free (lbl);
} else
listbox_add_item (l_hotlist, pos, 0, new->label, new);
listbox_select_entry (l_hotlist, l_hotlist->current);
}
return new;
}
/*
* Support routine for add_new_entry_input()/add_new_group_input()
* Change positions of buttons (first three widgets).
*
* This is just a quick hack. Accurate procedure must take care of
* internationalized label lengths and total buttonbar length...assume
* 64 is longer anyway.
*/
static void add_widgets_i18n(QuickWidget* qw, int len)
{
int i, l[3], space, cur_x;
for (i = 0; i < 3; i++)
{
qw [i].text = _(qw [i].text);
l[i] = strlen (qw [i].text) + 3;
}
space = (len - 4 - l[0] - l[1] - l[2]) / 4;
for (cur_x = 2 + space, i = 3; i--; cur_x += l[i] + space)
{
qw [i].relative_x = cur_x;
qw [i].x_divisions = len;
}
}
static int add_new_entry_input (char *header, char *text1, char *text2, char *help, char **r1, char **r2)
{
QuickDialog Quick_input;
QuickWidget quick_widgets [] = {
{ quick_button, 55, 80, 4, 0, N_("&Cancel"), 0, B_CANCEL, 0, 0,
XV_WLAY_DONTCARE, "button-cancel" },
{ quick_button, 30, 80, 4, 0, N_("&Insert"), 0, B_INSERT, 0, 0,
XV_WLAY_DONTCARE, "button-insert" },
{ quick_button, 10, 80, 4, 0, N_("&Append"), 0, B_APPEND, 0, 0,
XV_WLAY_DONTCARE, "button-append" },
{ quick_input, 4, 80, 4, 0, "",58, 0, 0, 0, XV_WLAY_BELOWCLOSE, "input-pth" },
{ quick_label, 3, 80, 3, 0, 0, 0, 0, 0, 0, XV_WLAY_DONTCARE, "label-pth" },
{ quick_input, 4, 80, 3, 0, "", 58, 0, 0, 0, XV_WLAY_BELOWCLOSE, "input-lbl" },
{ quick_label, 3, 80, 2, 0, 0, 0, 0, 0, 0, XV_WLAY_DONTCARE, "label-lbl" },
{ 0 } };
int len;
int i;
int lines1, lines2;
char *my_str1, *my_str2;
#ifdef ENABLE_NLS
static int i18n_flag = 0;
#endif /* ENABLE_NLS */
len = max (strlen (header), msglen (text1, &lines1));
len = max (len, msglen (text2, &lines2)) + 4;
len = max (len, 64);
#ifdef ENABLE_NLS
if (!i18n_flag)
{
add_widgets_i18n(quick_widgets, len);
i18n_flag = 1;
}
#endif /* ENABLE_NLS */
Quick_input.xlen = len;
Quick_input.xpos = -1;
Quick_input.title = header;
Quick_input.help = help;
Quick_input.class = "hotlist_new_entry";
Quick_input.i18n = 0;
quick_widgets [6].text = text1;
quick_widgets [4].text = text2;
quick_widgets [5].text = *r1;
quick_widgets [3].text = *r2;
for (i = 0; i < 7; i++)
quick_widgets [i].y_divisions = lines1+lines2+7;
Quick_input.ylen = lines1 + lines2 + 7;
quick_widgets [0].relative_y += (lines1 + lines2);
quick_widgets [1].relative_y += (lines1 + lines2);
quick_widgets [2].relative_y += (lines1 + lines2);
quick_widgets [3].relative_y += (lines1);
quick_widgets [4].relative_y += (lines1);
quick_widgets [5].str_result = &my_str1;
quick_widgets [3].str_result = &my_str2;
Quick_input.widgets = quick_widgets;
if ((i = quick_dialog (&Quick_input)) != B_CANCEL){
*r1 = *(quick_widgets [5].str_result);
*r2 = *(quick_widgets [3].str_result);
return i;
} else
return 0;
}
static void add_new_entry_cmd (void)
{
char *title = 0, *url = 0;
int ret;
/* Take current directory as default value for input fields */
title = url = cpanel->cwd;
ret = add_new_entry_input (_("New hotlist entry"), _("Directory label"), _("Directory path"),
"[Hotlist]", &title, &url);
if (!ret || !title || !*title || !url || !*url)
return;
if (ret == B_ENTER || ret == B_APPEND)
add2hotlist (strdup (title), strdup (url), HL_TYPE_ENTRY, 2);
else
add2hotlist (strdup (title), strdup (url), HL_TYPE_ENTRY, 1);
hotlist_state.modified = 1;
}
static int add_new_group_input (char *header, char *label, char **result)
{
int ret;
QuickDialog Quick_input;
QuickWidget quick_widgets [] = {
{ quick_button, 55, 80, 1, 0, N_("&Cancel"), 0, B_CANCEL, 0, 0,
XV_WLAY_DONTCARE, "button-cancel" },
{ quick_button, 30, 80, 1, 0, N_("&Insert"), 0, B_INSERT, 0, 0,
XV_WLAY_DONTCARE, "button-insert" },
{ quick_button, 10, 80, 1, 0, N_("&Append"), 0, B_APPEND, 0, 0,
XV_WLAY_DONTCARE, "button-append" },
{ quick_input, 4, 80, 0, 0, "", 58, 0, 0, 0, XV_WLAY_BELOWCLOSE, "input" },
{ quick_label, 3, 80, 2, 0, 0, 0, 0, 0, 0, XV_WLAY_DONTCARE, "label" },
{ 0 } };
int len;
int i;
int lines;
char *my_str;
#ifdef ENABLE_NLS
static int i18n_flag = 0;
#endif /* ENABLE_NLS */
len = max (strlen (header), msglen (label, &lines)) + 4;
len = max (len, 64);
#ifdef ENABLE_NLS
if (!i18n_flag)
{
add_widgets_i18n(quick_widgets, len);
i18n_flag = 1;
}
#endif /* ENABLE_NLS */
Quick_input.xlen = len;
Quick_input.xpos = -1;
Quick_input.title = header;
Quick_input.help = "[Hotlist]";
Quick_input.class = "hotlist_new_group";
Quick_input.i18n = 0;
quick_widgets [4].text = label;
for (i = 0; i < 5; i++)
quick_widgets [i].y_divisions = lines+6;
Quick_input.ylen = lines + 6;
for (i = 0; i < 4; i++)
quick_widgets [i].relative_y += 2 + lines;
quick_widgets [3].str_result = &my_str;
quick_widgets [3].text = "";
Quick_input.widgets = quick_widgets;
if ((ret = quick_dialog (&Quick_input)) != B_CANCEL){
*result = *(quick_widgets [3].str_result);
return ret;
} else
return 0;
}
void add_new_group_cmd (void)
{
char *label;
int ret;
ret = add_new_group_input (_(" New hotlist group "), _("Name of new group"), &label);
if (!ret || !label || !*label)
return;
if (ret == B_ENTER || ret == B_APPEND)
add2hotlist (label, 0, HL_TYPE_GROUP, 2);
else
add2hotlist (label, 0, HL_TYPE_GROUP, 1);
hotlist_state.modified = 1;
}
void add2hotlist_cmd (void)
{
char *prompt, *label;
char* cp = _("Label for \"%s\":");
int l = strlen(cp);
prompt = xmalloc (strlen (cpanel->cwd) + l, "add2hotlist_cmd");
sprintf (prompt, cp, name_trunc (cpanel->cwd, COLS-2*UX-(l+8)));
label = input_dialog (_(" Add to hotlist "), prompt, cpanel->cwd);
free (prompt);
if (!label || !*label)
return;
add2hotlist (label, strdup (cpanel->cwd), HL_TYPE_ENTRY, 0);
hotlist_state.modified = 1;
}
static void remove_group (struct hotlist *grp)
{
struct hotlist *current = grp->head;
while (current) {
struct hotlist *next = current->next;
if (current->type == HL_TYPE_GROUP)
remove_group (current);
if (current->label)
free (current->label);
if (current->directory)
free (current->directory);
free (current);
current = next;
}
}
static void remove_from_hotlist (struct hotlist *entry)
{
if (entry->type == HL_TYPE_GROUP) {
if (entry->head) {
char *header;
int result;
header = copy_strings (_(" Remove: "),
name_trunc (entry->label, 30),
" ",
0);
result = query_dialog (header, _("\n Group not empty.\n Remove it?"),
D_ERROR, 2,
_("&No"), _("&Yes"));
free (header);
if (!result)
return;
}
remove_group (entry);
}
unlink_entry (entry);
if (entry->label)
free (entry->label);
if (entry->directory)
free (entry->directory);
free (entry);
/* now remove list entry from screen */
listbox_remove_current (l_hotlist, 1);
hotlist_state.modified = 1;
}
char *hotlist_cmd (int vfs_or_hotlist)
{
char *target = NULL;
hotlist_state.type = vfs_or_hotlist;
load_hotlist ();
init_hotlist (vfs_or_hotlist);
/* display file info */
attrset (SELECTED_COLOR);
hotlist_state.running = 1;
run_dlg (hotlist_dlg);
hotlist_state.running = 0;
save_hotlist ();
switch (hotlist_dlg->ret_value) {
case B_CANCEL:
break;
case B_ENTER:
if (l_hotlist->current->data) {
struct hotlist *hlp = (struct hotlist*) l_hotlist->current->data;
target = strdup (hlp->directory);
} else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -