📄 boxes.c
字号:
/* Some misc dialog boxes for the program.
Copyright (C) 1994, 1995 the Free Software Foundation
Authors: 1994, 1995 Miguel de Icaza
1995 Jakub Jelinek
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include <config.h>
#include "tty.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/param.h>
#include <malloc.h>
#include <signal.h>
#include <ctype.h>
#include "global.h"
#include "mad.h" /* The great mad */
#include "util.h" /* Required by panel.h */
#include "win.h" /* Our window tools */
#include "color.h" /* Color definitions */
#include "dlg.h" /* The nice dialog manager */
#include "widget.h" /* The widgets for the nice dialog manager */
#include "dialog.h" /* For do_refresh() */
#include "wtools.h"
#include "setup.h" /* For profile_name */
#include "profile.h" /* Load/save user formats */
#include "key.h" /* XCTRL and ALT macros */
#include "command.h" /* For cmdline */
#include "dir.h"
#include "panel.h"
#include "boxes.h"
#include "main.h" /* For the confirm_* variables */
#include "tree.h"
#include "layout.h" /* for get_nth_panel_name proto */
#include "background.h" /* for background definitions */
#include "x.h"
static int DISPLAY_X = 45, DISPLAY_Y = 14;
static Dlg_head *dd;
static WRadio *my_radio;
static WInput *user;
static WInput *status;
static WCheck *check_status;
static int current_mode;
extern int ftpfs_always_use_proxy;
static char **displays_status;
static char* display_title = N_(" Listing mode ");
/* Controls whether the array strings have been translated */
static int i18n_displays_flag;
static char *displays [LIST_TYPES] = {
N_("&Full file list"),
N_("&Brief file list"),
N_("&Long file list"),
N_("&User defined:"),
N_("&Icon view"),
};
static int user_hotkey = 'u';
static int display_callback (struct Dlg_head *h, int id, int Msg)
{
#ifndef HAVE_X
char *text;
WInput *input;
switch (Msg){
case DLG_DRAW:
attrset (COLOR_NORMAL);
dlg_erase (h);
draw_box (h, 1, 2, h->lines - 2, h->cols - 4);
attrset (COLOR_HOT_NORMAL);
dlg_move (h, 1, (h->cols - strlen(display_title))/2);
addstr (display_title);
attrset (COLOR_NORMAL);
break;
case DLG_UNFOCUS:
if((WRadio *) h->current->widget == my_radio){
assign_text (status, displays_status [my_radio->sel]);
input_set_point (status, 0);
}
break;
case DLG_KEY:
if (id == '\n'){
if((WRadio *) h->current->widget == my_radio){
assign_text (status, displays_status [my_radio->sel]);
dlg_stop (h);
break;
}
if ((WInput *) h->current->widget == user){
h->ret_value = B_USER + 6;
dlg_stop (h);
break;
}
if ((WInput *) h->current->widget == status){
h->ret_value = B_USER + 7;
dlg_stop (h);
break;
}
}
if (tolower(id) == user_hotkey && h->current->widget != (Widget *) user
&& h->current->widget != (Widget *) status){
my_radio->sel = 3;
dlg_select_widget (h, my_radio); /* force redraw */
dlg_select_widget (h, user);
return MSG_HANDLED;
}
}
#endif
return MSG_NOT_HANDLED;
}
static void display_init (int radio_sel, char *init_text,
int _check_status, char ** _status)
{
char* user_mini_status = _("user &Mini status");
char* ok_button = _("&Ok");
char* cancel_button = _("&Cancel");
static int button_start = 30;
displays_status = _status;
if (!i18n_displays_flag){
int i, l, maxlen = 0;
char* cp;
display_title = _(display_title);
for (i = 0; i < LIST_TYPES; i++)
{
displays [i] = _(displays [i]);
if ((l = strlen(displays [i])) > maxlen)
maxlen = l;
}
i = strlen (ok_button) + 5;
l = strlen (cancel_button) + 3;
l = max(i, l);
i = maxlen + l + 16;
if (i > DISPLAY_X)
DISPLAY_X = i;
i = strlen (user_mini_status) + 13;
if (i > DISPLAY_X)
DISPLAY_X = i;
i = strlen (display_title) + 8;
if (i > DISPLAY_X)
DISPLAY_X = i;
button_start = DISPLAY_X - l - 5;
/* get hotkey of user-defined format string */
cp = strchr(displays[LIST_TYPES-1],'&');
if (cp != NULL && *++cp != '\0')
user_hotkey = tolower(*cp);
i18n_displays_flag = 1;
}
dd = create_dlg (0, 0, DISPLAY_Y, DISPLAY_X, dialog_colors,
display_callback, "[Left and Right Menus]", "display",
DLG_CENTER | DLG_GRID);
x_set_dialog_title (dd, _("Listing mode"));
add_widgetl (dd,
button_new (4, button_start, B_CANCEL,
NORMAL_BUTTON, cancel_button, 0, 0, "cancel-button"),
XV_WLAY_RIGHTOF);
add_widgetl (dd,
button_new (3, button_start, B_ENTER,
DEFPUSH_BUTTON, ok_button, 0, 0, "ok-button"),
XV_WLAY_CENTERROW);
status = input_new (10, 9, INPUT_COLOR, DISPLAY_X-14, _status [radio_sel], "mini-input");
add_widgetl (dd, status, XV_WLAY_RIGHTDOWN);
input_set_point (status, 0);
check_status = check_new (9, 5, _check_status, user_mini_status, "mini-status");
add_widgetl (dd, check_status, XV_WLAY_NEXTROW);
user = input_new (7, 9, INPUT_COLOR, DISPLAY_X-14, init_text, "user-fmt-input");
add_widgetl (dd, user, XV_WLAY_RIGHTDOWN);
input_set_point (user, 0);
#ifdef PORT_HAS_ICON_VIEW
my_radio = radio_new (3, 5, LIST_TYPES, displays, 1, "radio");
#else
my_radio = radio_new (3, 5, LIST_TYPES-1, displays, 1, "radio");
#endif
my_radio->sel = my_radio->pos = current_mode;
add_widgetl (dd, my_radio, XV_WLAY_BELOWCLOSE);
}
int display_box (WPanel *panel, char **userp, char **minip, int *use_msformat,
int num)
{
int result, i;
char *section = NULL;
char *p;
if (!panel) {
p = get_nth_panel_name (num);
panel = (WPanel *) xmalloc (sizeof (WPanel), "temporary panel");
panel->list_type = list_full;
panel->user_format = strdup (DEFAULT_USER_FORMAT);
panel->user_mini_status = 0;
for (i = 0; i < LIST_TYPES; i++)
panel->user_status_format[i] = strdup (DEFAULT_USER_FORMAT);
section = copy_strings ("Temporal:", p, 0);
if (!profile_has_section (section, profile_name)) {
free (section);
section = strdup (p);
}
panel_load_setup (panel, section);
free (section);
}
current_mode = panel->list_type;
display_init (current_mode, panel->user_format,
panel->user_mini_status, panel->user_status_format);
run_dlg (dd);
result = -1;
if (section) {
free (panel->user_format);
for (i = 0; i < LIST_TYPES; i++)
free (panel->user_status_format [i]);
free (panel);
}
if (dd->ret_value != B_CANCEL){
result = my_radio->sel;
*userp = strdup (user->buffer);
*minip = strdup (status->buffer);
*use_msformat = check_status->state & C_BOOL;
}
destroy_dlg (dd);
return result;
}
int SORT_X = 40, SORT_Y = 14;
char *sort_orders_names [SORT_TYPES];
sortfn *sort_box (sortfn *sort_fn, int *reverse, int *case_sensitive)
{
int i, r, l;
sortfn *result;
WCheck *c, *case_sense;
char* ok_button = _("&Ok");
char* cancel_button = _("&Cancel");
char* reverse_label = _("&Reverse");
char* case_label = _("case sensi&tive");
char* sort_title = _("Sort order");
static int i18n_sort_flag = 0, check_pos = 0, button_pos = 0;
if (!i18n_sort_flag)
{
int maxlen = 0;
for (i = SORT_TYPES-1; i >= 0; i--)
{
sort_orders_names [i] = _(sort_orders [i].sort_name);
r = strlen (sort_orders_names [i]);
if (r > maxlen)
maxlen = r;
}
check_pos = maxlen + 9;
r = strlen (reverse_label) + 4;
i = strlen (case_label) + 4;
if (i > r)
r = i;
l = strlen (ok_button) + 6;
i = strlen (cancel_button) + 4;
if (i > l)
l = i;
i = check_pos + max(r,l) + 2;
if (i > SORT_X)
SORT_X = i;
i = strlen (sort_title) + 6;
if (i > SORT_X)
SORT_X = i;
button_pos = SORT_X - l - 2;
i18n_sort_flag = 1;
}
result = 0;
for (i = 0; i < SORT_TYPES; i++)
if ((sortfn *) (sort_orders [i].sort_fn) == sort_fn){
current_mode = i;
break;
}
dd = create_dlg (0, 0, SORT_Y, SORT_X, dialog_colors, common_dialog_callback,
"[Left and Right Menus]", "sort", DLG_CENTER | DLG_GRID);
x_set_dialog_title (dd, sort_title);
add_widgetl (dd,
button_new (10, button_pos, B_CANCEL, NORMAL_BUTTON, cancel_button,
0, 0, "cancel-button"), XV_WLAY_CENTERROW);
add_widgetl (dd,
button_new (9, button_pos, B_ENTER, DEFPUSH_BUTTON, ok_button,
0, 0, "ok-button"), XV_WLAY_RIGHTDOWN);
case_sense = check_new (4, check_pos, *case_sensitive, case_label, "case-check");
add_widgetl (dd, case_sense, XV_WLAY_RIGHTDOWN);
c = check_new (3, check_pos, *reverse, reverse_label, "reverse-check");
add_widgetl (dd, c, XV_WLAY_RIGHTDOWN);
my_radio = radio_new (3, 3, SORT_TYPES, sort_orders_names, 1, "radio-1");
my_radio->sel = my_radio->pos = current_mode;
add_widget (dd, my_radio);
run_dlg (dd);
r = dd->ret_value;
if (r != B_CANCEL){
result = (sortfn *) sort_orders [my_radio->sel].sort_fn;
*reverse = c->state & C_BOOL;
*case_sensitive = case_sense->state & C_BOOL;
} else
result = sort_fn;
destroy_dlg (dd);
return result;
}
#define CONFY 10
#define CONFX 46
static int my_delete;
static int my_overwrite;
static int my_execute;
static int my_exit;
static QuickWidget conf_widgets [] = {
{ quick_button, 4, 6, 4, CONFY, N_("&Cancel"),
0, B_CANCEL, 0, 0, XV_WLAY_RIGHTOF, "c" },
{ quick_button, 4, 6, 3, CONFY, N_("&Ok"),
0, B_ENTER, 0, 0, XV_WLAY_CENTERROW, "o" },
{ quick_checkbox, 1, 13, 6, CONFY, N_(" confirm &Exit "),
9, 0, &my_exit, 0, XV_WLAY_BELOWCLOSE, "e" },
{ quick_checkbox, 1, 13, 5, CONFY, N_(" confirm e&Xecute "),
10, 0, &my_execute, 0, XV_WLAY_BELOWCLOSE, "x" },
{ quick_checkbox, 1, 13, 4, CONFY, N_(" confirm o&Verwrite "),
10, 0, &my_overwrite, 0, XV_WLAY_BELOWCLOSE, "ov" },
{ quick_checkbox, 1, 13, 3, CONFY, N_(" confirm &Delete "),
9, 0, &my_delete, 0, XV_WLAY_BELOWCLOSE, "de" },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, XV_WLAY_DONTCARE }
};
static QuickDialog confirmation =
{ CONFX, CONFY, -1, -1, N_(" Confirmation "), "[Confirmation]", "quick_confirm",
conf_widgets, 0 };
void confirm_box ()
{
#ifdef ENABLE_NLS
static int i18n_flag = 0;
if (!i18n_flag)
{
register int i = sizeof(conf_widgets)/sizeof(QuickWidget) - 1;
int l1, maxlen = 0;
while (i--)
{
conf_widgets [i].text = _(conf_widgets [i].text);
l1 = strlen (conf_widgets [i].text) + 3;
if (l1 > maxlen)
maxlen = l1;
}
/*
* If buttons start on 4/6, checkboxes (with some add'l space)
* must take not more than it.
*/
confirmation.xlen = (maxlen + 5) * 6 / 4;
/*
* And this for the case when buttons with some space to the right
* do not fit within 2/6
*/
l1 = strlen (conf_widgets [0].text) + 3;
i = strlen (conf_widgets [1].text) + 5;
if (i > l1)
l1 = i;
i = (l1 + 3) * 6 / 2;
if (i > confirmation.xlen)
confirmation.xlen = i;
confirmation.title = _(confirmation.title);
i18n_flag = confirmation.i18n = 1;
}
#endif /* ENABLE_NLS */
my_delete = confirm_delete;
my_overwrite = confirm_overwrite;
my_execute = confirm_execute;
my_exit = confirm_exit;
if (quick_dialog (&confirmation) != B_CANCEL){
confirm_delete = my_delete;
confirm_overwrite = my_overwrite;
confirm_execute = my_execute;
confirm_exit = my_exit;
}
}
#define DISPY 11
#define DISPX 46
static int new_mode;
static int new_meta;
char *display_bits_str [] =
{ N_("Full 8 bits output"), N_("ISO 8859-1"), N_("7 bits") };
static QuickWidget display_widgets [] = {
{ quick_button, 4, 6, 4, DISPY, N_("&Cancel"),
0, B_CANCEL, 0, 0, XV_WLAY_CENTERROW, "c" },
{ quick_button, 4, 6, 3, DISPY, N_("&Ok"),
0, B_ENTER, 0, 0, XV_WLAY_CENTERROW, "o" },
{ quick_checkbox, 4, DISPX, 7, DISPY, N_("F&ull 8 bits input"),
0, 0, &new_meta, 0, XV_WLAY_BELOWCLOSE, "u" },
{ quick_radio, 4, DISPX, 3, DISPY, "", 3, 0,
&new_mode, display_bits_str, XV_WLAY_BELOWCLOSE, "r" },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, XV_WLAY_DONTCARE }
};
static QuickDialog display_bits =
{ DISPX, DISPY, -1, -1, N_(" Display bits "), "[Display bits]",
"dbits", display_widgets, 0 };
void display_bits_box ()
{
int current_mode;
#ifdef ENABLE_NLS
static int i18n_flag = 0;
if (!i18n_flag)
{
register int i;
int l1, maxlen = 0;
for (i = 0; i < 3; i++)
{
display_widgets [i].text = _(display_widgets[i].text);
display_bits_str [i] = _(display_bits_str [i]);
l1 = strlen (display_bits_str [i]);
if (l1 > maxlen)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -