mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-22 12:32:40 +03:00
Code indentation in src directory
Signed-off-by: Slava Zanko <slavazanko@gmail.com>
This commit is contained in:
parent
14e958a0a4
commit
1ff8b77f92
@ -18,4 +18,4 @@
|
||||
void chown_advanced_cmd (void);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif
|
||||
#endif /* MC__ACHOWN_H */
|
||||
|
@ -52,4 +52,4 @@ void unregister_task_with_pid (pid_t pid);
|
||||
|
||||
#endif /* !WITH_BACKGROUND */
|
||||
|
||||
#endif /* MC_BACKGROUND_H */
|
||||
#endif /* MC__BACKGROUND_H */
|
||||
|
@ -30,4 +30,4 @@ void symlink_dialog (const char *existing, const char *new, char **ret_existing,
|
||||
char *tree_box (const char *current_dir);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif
|
||||
#endif /* MC__BOXES_H */
|
||||
|
@ -106,4 +106,4 @@ convert_from_input_c (int c)
|
||||
|
||||
#endif /* HAVE_CHARSET */
|
||||
|
||||
#endif /* MC_CHARSETS_H */
|
||||
#endif /* MC__CHARSETS_H */
|
||||
|
@ -18,4 +18,4 @@
|
||||
void chmod_cmd (void);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif
|
||||
#endif /* MC__CHMOD_H */
|
||||
|
@ -18,4 +18,4 @@
|
||||
void chown_cmd (void);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif
|
||||
#endif /* MC__CHOWN_H */
|
||||
|
@ -19,4 +19,4 @@ gboolean copy_file_to_ext_clip (void);
|
||||
gboolean paste_to_file_from_ext_clip (void);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif
|
||||
#endif /* MC__CLIPBOARD_H */
|
||||
|
@ -101,4 +101,4 @@ void toggle_listing_cmd (void);
|
||||
void encoding_cmd (void);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif
|
||||
#endif /* MC__CMD_H */
|
||||
|
@ -524,4 +524,4 @@
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC_CMD_DEF_H */
|
||||
#endif /* MC__CMD_DEF_H */
|
||||
|
@ -24,4 +24,4 @@ void do_cd_command (char *cmd);
|
||||
void command_insert (WInput * in, const char *text, int insert_extra_space);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif
|
||||
#endif /* MC__COMMAND_H */
|
||||
|
@ -37,13 +37,15 @@
|
||||
#include "wtools.h" /* Listbox */
|
||||
#include "dialog-switch.h"
|
||||
|
||||
/*** global variables **************************************************/
|
||||
|
||||
/*** file scope macro definitions **************************************/
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
/*** file scope type declarations **************************************/
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
/*** file scope variables **********************************************/
|
||||
|
||||
/* List of dialogs: filemanagers, editors, viewers */
|
||||
static GList *mc_dialogs = NULL;
|
||||
@ -52,7 +54,8 @@ static GList *mc_current = NULL;
|
||||
/* Is there any dialogs that we have to run after returning to the manager from another dialog */
|
||||
static gboolean dialog_switch_pending = FALSE;
|
||||
|
||||
/*** file scope functions **********************************************/
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static unsigned char
|
||||
get_hotkey (int n)
|
||||
@ -60,8 +63,10 @@ get_hotkey (int n)
|
||||
return (n <= 9) ? '0' + n : 'a' + n - 10;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
dialog_switch_goto (GList *dlg)
|
||||
dialog_switch_goto (GList * dlg)
|
||||
{
|
||||
if (mc_current != dlg)
|
||||
{
|
||||
@ -91,10 +96,12 @@ dialog_switch_goto (GList *dlg)
|
||||
}
|
||||
}
|
||||
|
||||
/*** public functions **************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
dialog_switch_add (Dlg_head *h)
|
||||
dialog_switch_add (Dlg_head * h)
|
||||
{
|
||||
GList *dlg;
|
||||
|
||||
@ -109,8 +116,10 @@ dialog_switch_add (Dlg_head *h)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
dialog_switch_remove (Dlg_head *h)
|
||||
dialog_switch_remove (Dlg_head * h)
|
||||
{
|
||||
GList *this;
|
||||
|
||||
@ -128,12 +137,16 @@ dialog_switch_remove (Dlg_head *h)
|
||||
mc_current = mc_dialogs;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
size_t
|
||||
dialog_switch_num (void)
|
||||
{
|
||||
return g_list_length (mc_dialogs);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
dialog_switch_next (void)
|
||||
{
|
||||
@ -149,6 +162,8 @@ dialog_switch_next (void)
|
||||
dialog_switch_goto (next);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
dialog_switch_prev (void)
|
||||
{
|
||||
@ -164,6 +179,8 @@ dialog_switch_prev (void)
|
||||
dialog_switch_goto (prev);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
dialog_switch_list (void)
|
||||
{
|
||||
@ -177,8 +194,8 @@ dialog_switch_list (void)
|
||||
if (midnight_shutdown || mc_current == NULL)
|
||||
return;
|
||||
|
||||
lines = min ((size_t) (LINES * 2/3), dlg_num);
|
||||
cols = COLS * 2/3;
|
||||
lines = min ((size_t) (LINES * 2 / 3), dlg_num);
|
||||
cols = COLS * 2 / 3;
|
||||
|
||||
listbox = create_listbox_window (lines, cols, _("Screens"), "[Screen selector]");
|
||||
|
||||
@ -190,7 +207,7 @@ dialog_switch_list (void)
|
||||
dlg = (Dlg_head *) h->data;
|
||||
|
||||
if ((dlg != NULL) && (dlg->get_title != NULL))
|
||||
title = dlg->get_title (dlg, listbox->list->widget.cols - 2); /* FIXME! */
|
||||
title = dlg->get_title (dlg, listbox->list->widget.cols - 2); /* FIXME! */
|
||||
else
|
||||
title = g_strdup ("");
|
||||
|
||||
@ -209,6 +226,8 @@ dialog_switch_list (void)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
dialog_switch_process_pending (void)
|
||||
{
|
||||
@ -238,6 +257,8 @@ dialog_switch_process_pending (void)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
dialog_switch_got_winch (void)
|
||||
{
|
||||
@ -248,6 +269,8 @@ dialog_switch_got_winch (void)
|
||||
((Dlg_head *) dlg->data)->winch_pending = TRUE;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
dialog_switch_shutdown (void)
|
||||
{
|
||||
@ -259,3 +282,5 @@ dialog_switch_shutdown (void)
|
||||
destroy_dlg (dlg);
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -1,11 +1,22 @@
|
||||
|
||||
#ifndef MC_DIALOG_SWITCH_H
|
||||
#define MC_DIALOG_SWITCH_H
|
||||
#ifndef MC__DIALOG_SWITCH_H
|
||||
#define MC__DIALOG_SWITCH_H
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
struct Dlg_head;
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
void dialog_switch_add (struct Dlg_head *h);
|
||||
void dialog_switch_remove (struct Dlg_head *h);
|
||||
size_t dialog_switch_num (void);
|
||||
@ -18,4 +29,5 @@ int dialog_switch_process_pending (void);
|
||||
void dialog_switch_got_winch (void);
|
||||
void dialog_switch_shutdown (void);
|
||||
|
||||
#endif /* MC_DIALOG_SWITCH_H */
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__DIALOG_SWITCH_H */
|
||||
|
1009
src/dialog.c
1009
src/dialog.c
File diff suppressed because it is too large
Load Diff
192
src/dialog.h
192
src/dialog.h
@ -3,7 +3,7 @@
|
||||
2005, 2007, 2009, 2010 Free Software Foundation
|
||||
|
||||
Authors: 1994, 1995 Radek Doulik, Miguel de Icaza
|
||||
2009, 2010 Andrew Borodin
|
||||
2009, 2010 Andrew Borodin
|
||||
|
||||
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
|
||||
@ -24,8 +24,8 @@
|
||||
* \brief Header: dialog box features module
|
||||
*/
|
||||
|
||||
#ifndef MC_DIALOG_H
|
||||
#define MC_DIALOG_H
|
||||
#ifndef MC__DIALOG_H
|
||||
#define MC__DIALOG_H
|
||||
|
||||
#include <sys/types.h> /* size_t */
|
||||
|
||||
@ -33,6 +33,8 @@
|
||||
#include "lib/tty/mouse.h"
|
||||
#include "lib/hook.h" /* hook_t */
|
||||
|
||||
/*** defined constants ***************************************************************************/
|
||||
|
||||
/* Common return values */
|
||||
#define B_EXIT 0
|
||||
#define B_CANCEL 1
|
||||
@ -40,7 +42,19 @@
|
||||
#define B_HELP 3
|
||||
#define B_USER 100
|
||||
|
||||
typedef struct Widget Widget;
|
||||
#define widget_move(w, _y, _x) tty_gotoyx (((Widget *)(w))->y + _y, ((Widget *)(w))->x + _x)
|
||||
#define dlg_move(h, _y, _x) tty_gotoyx (((Dlg_head *)(h))->y + _y, ((Dlg_head *)(h))->x + _x)
|
||||
|
||||
/* Sets/clear the specified flag in the options field */
|
||||
#define widget_option(w,f,i) \
|
||||
w.options = ((i) ? ((w).options | (f)) : ((w).options & (~(f))))
|
||||
|
||||
#define widget_want_cursor(w,i) widget_option((w), W_WANT_CURSOR, (i))
|
||||
#define widget_want_hotkey(w,i) widget_option((w), W_WANT_HOTKEY, (i))
|
||||
#define widget_disable(w,i) widget_option((w), W_DISABLED, (i))
|
||||
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/* Widget messages */
|
||||
typedef enum
|
||||
@ -111,23 +125,9 @@ typedef enum
|
||||
DLG_CLOSED = 2 /* Dialog is closed */
|
||||
} dlg_state_t;
|
||||
|
||||
/* Dialog callback */
|
||||
typedef struct Dlg_head Dlg_head;
|
||||
typedef cb_ret_t (*dlg_cb_fn) (Dlg_head * h, Widget * sender,
|
||||
dlg_msg_t msg, int parm, void *data);
|
||||
|
||||
/* menu command execution */
|
||||
typedef cb_ret_t (*menu_exec_fn) (int command);
|
||||
|
||||
/* get string representation of shortcut assigned with command */
|
||||
/* as menu is a widget of dialog, ask dialog about shortcut string */
|
||||
typedef char *(*dlg_shortcut_str) (unsigned long command);
|
||||
|
||||
/* get dialog name to show in dialog list */
|
||||
typedef char *(*dlg_title_str) (const Dlg_head * h, size_t len);
|
||||
|
||||
/* Dialog color constants */
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
DLG_COLOR_NORMAL,
|
||||
DLG_COLOR_FOCUS,
|
||||
DLG_COLOR_HOT_NORMAL,
|
||||
@ -136,15 +136,61 @@ typedef enum {
|
||||
DLG_COLOR_COUNT
|
||||
} dlg_colors_enum_t;
|
||||
|
||||
/* widget options */
|
||||
typedef enum
|
||||
{
|
||||
W_WANT_HOTKEY = (1 << 1),
|
||||
W_WANT_CURSOR = (1 << 2),
|
||||
W_WANT_IDLE = (1 << 3),
|
||||
W_IS_INPUT = (1 << 4),
|
||||
W_DISABLED = (1 << 5) /* Widget cannot be selected */
|
||||
} widget_options_t;
|
||||
|
||||
/* Flags for widget repositioning on dialog resize */
|
||||
typedef enum
|
||||
{
|
||||
WPOS_KEEP_LEFT = (1 << 0), /* keep widget distance to left border of dialog */
|
||||
WPOS_KEEP_RIGHT = (1 << 1), /* keep widget distance to right border of dialog */
|
||||
WPOS_KEEP_TOP = (1 << 2), /* keep widget distance to top border of dialog */
|
||||
WPOS_KEEP_BOTTOM = (1 << 3), /* keep widget distance to bottom border of dialog */
|
||||
WPOS_KEEP_HORZ = WPOS_KEEP_LEFT | WPOS_KEEP_RIGHT,
|
||||
WPOS_KEEP_VERT = WPOS_KEEP_TOP | WPOS_KEEP_BOTTOM,
|
||||
WPOS_KEEP_ALL = WPOS_KEEP_HORZ | WPOS_KEEP_VERT
|
||||
} widget_pos_flags_t;
|
||||
|
||||
/*** typedefs(not structures) ********************************************************************/
|
||||
|
||||
typedef struct Widget Widget;
|
||||
|
||||
/* Dialog callback */
|
||||
typedef struct Dlg_head Dlg_head;
|
||||
|
||||
/* get string representation of shortcut assigned with command */
|
||||
/* as menu is a widget of dialog, ask dialog about shortcut string */
|
||||
typedef char *(*dlg_shortcut_str) (unsigned long command);
|
||||
|
||||
/* get dialog name to show in dialog list */
|
||||
typedef char *(*dlg_title_str) (const Dlg_head * h, size_t len);
|
||||
|
||||
typedef int dlg_colors_t[DLG_COLOR_COUNT];
|
||||
|
||||
/* Widget callback */
|
||||
typedef cb_ret_t (*callback_fn) (Widget * widget, widget_msg_t msg, int parm);
|
||||
|
||||
typedef cb_ret_t (*dlg_cb_fn) (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data);
|
||||
|
||||
/* menu command execution */
|
||||
typedef cb_ret_t (*menu_exec_fn) (int command);
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
struct Dlg_head
|
||||
{
|
||||
/* Set by the user */
|
||||
gboolean modal; /* type of dialog: modal or not */
|
||||
dlg_flags_t flags; /* User flags */
|
||||
const char *help_ctx; /* Name of the help entry */
|
||||
dlg_colors_t color; /* Color set. Unused in viewer and editor */
|
||||
dlg_colors_t color; /* Color set. Unused in viewer and editor */
|
||||
char *title; /* Title of the dialog */
|
||||
|
||||
/* Set and received by the user */
|
||||
@ -172,35 +218,6 @@ struct Dlg_head
|
||||
struct Dlg_head *parent; /* Parent dialog */
|
||||
};
|
||||
|
||||
/* Color styles for normal and error dialogs */
|
||||
extern dlg_colors_t dialog_colors;
|
||||
extern dlg_colors_t alarm_colors;
|
||||
|
||||
/* Widget callback */
|
||||
typedef cb_ret_t (*callback_fn) (Widget * widget, widget_msg_t msg, int parm);
|
||||
|
||||
/* widget options */
|
||||
typedef enum
|
||||
{
|
||||
W_WANT_HOTKEY = (1 << 1),
|
||||
W_WANT_CURSOR = (1 << 2),
|
||||
W_WANT_IDLE = (1 << 3),
|
||||
W_IS_INPUT = (1 << 4),
|
||||
W_DISABLED = (1 << 5) /* Widget cannot be selected */
|
||||
} widget_options_t;
|
||||
|
||||
/* Flags for widget repositioning on dialog resize */
|
||||
typedef enum
|
||||
{
|
||||
WPOS_KEEP_LEFT = (1 << 0), /* keep widget distance to left border of dialog */
|
||||
WPOS_KEEP_RIGHT = (1 << 1), /* keep widget distance to right border of dialog */
|
||||
WPOS_KEEP_TOP = (1 << 2), /* keep widget distance to top border of dialog */
|
||||
WPOS_KEEP_BOTTOM = (1 << 3), /* keep widget distance to bottom border of dialog */
|
||||
WPOS_KEEP_HORZ = WPOS_KEEP_LEFT | WPOS_KEEP_RIGHT,
|
||||
WPOS_KEEP_VERT = WPOS_KEEP_TOP | WPOS_KEEP_BOTTOM,
|
||||
WPOS_KEEP_ALL = WPOS_KEEP_HORZ | WPOS_KEEP_VERT
|
||||
} widget_pos_flags_t;
|
||||
|
||||
/* Every Widget must have this as its first element */
|
||||
struct Widget
|
||||
{
|
||||
@ -208,12 +225,25 @@ struct Widget
|
||||
int cols, lines;
|
||||
widget_options_t options;
|
||||
widget_pos_flags_t pos_flags; /* repositioning flags */
|
||||
unsigned int id; /* Number of the widget, starting with 0 */
|
||||
unsigned int id; /* Number of the widget, starting with 0 */
|
||||
callback_fn callback;
|
||||
mouse_h mouse;
|
||||
struct Dlg_head *owner;
|
||||
};
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/* Color styles for normal and error dialogs */
|
||||
extern dlg_colors_t dialog_colors;
|
||||
extern dlg_colors_t alarm_colors;
|
||||
|
||||
extern GList *top_dlg;
|
||||
|
||||
/* A hook list for idle events */
|
||||
extern hook_t *idle_hook;
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
/* draw box in window */
|
||||
void draw_box (Dlg_head * h, int y, int x, int ys, int xs, gboolean single);
|
||||
|
||||
@ -240,7 +270,7 @@ void destroy_dlg (Dlg_head * h);
|
||||
void dlg_run_done (Dlg_head * h);
|
||||
void dlg_process_event (Dlg_head * h, int key, Gpm_Event * event);
|
||||
|
||||
char *dlg_get_title (const Dlg_head *h, size_t len);
|
||||
char *dlg_get_title (const Dlg_head * h, size_t len);
|
||||
|
||||
/* To activate/deactivate the idle message generation */
|
||||
void set_idle_proc (Dlg_head * d, int enable);
|
||||
@ -258,15 +288,30 @@ void init_widget (Widget * w, int y, int x, int lines, int cols,
|
||||
cb_ret_t default_dlg_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data);
|
||||
|
||||
/* Default paint routine for dialogs */
|
||||
void common_dialog_repaint (Dlg_head *h);
|
||||
void common_dialog_repaint (Dlg_head * h);
|
||||
|
||||
#define widget_move(w, _y, _x) tty_gotoyx (((Widget *)(w))->y + _y, ((Widget *)(w))->x + _x)
|
||||
#define dlg_move(h, _y, _x) tty_gotoyx (((Dlg_head *)(h))->y + _y, ((Dlg_head *)(h))->x + _x)
|
||||
void dlg_replace_widget (Widget * old, Widget * new);
|
||||
int dlg_overlap (Widget * a, Widget * b);
|
||||
void widget_erase (Widget *);
|
||||
void dlg_erase (Dlg_head * h);
|
||||
void dlg_stop (Dlg_head * h);
|
||||
|
||||
extern GList *top_dlg;
|
||||
/* Widget selection */
|
||||
void dlg_select_widget (void *widget);
|
||||
void dlg_one_up (Dlg_head * h);
|
||||
void dlg_one_down (Dlg_head * h);
|
||||
int dlg_focus (Dlg_head * h);
|
||||
Widget *find_widget_type (const Dlg_head * h, callback_fn callback);
|
||||
Widget *dlg_find_by_id (const Dlg_head * h, unsigned int id);
|
||||
void dlg_select_by_id (const Dlg_head * h, unsigned int id);
|
||||
|
||||
/* A hook list for idle events */
|
||||
extern hook_t *idle_hook;
|
||||
/* Redraw all dialogs */
|
||||
void do_refresh (void);
|
||||
|
||||
/* Used in load_prompt() */
|
||||
void update_cursor (Dlg_head * h);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
|
||||
static inline cb_ret_t
|
||||
send_message (Widget * w, widget_msg_t msg, int parm)
|
||||
@ -288,33 +333,4 @@ dlg_get_current_widget_id (const Dlg_head * h)
|
||||
return ((Widget *) h->current->data)->id;
|
||||
}
|
||||
|
||||
void dlg_replace_widget (Widget * old, Widget * new);
|
||||
int dlg_overlap (Widget * a, Widget * b);
|
||||
void widget_erase (Widget *);
|
||||
void dlg_erase (Dlg_head * h);
|
||||
void dlg_stop (Dlg_head * h);
|
||||
|
||||
/* Widget selection */
|
||||
void dlg_select_widget (void *widget);
|
||||
void dlg_one_up (Dlg_head * h);
|
||||
void dlg_one_down (Dlg_head * h);
|
||||
int dlg_focus (Dlg_head * h);
|
||||
Widget *find_widget_type (const Dlg_head * h, callback_fn callback);
|
||||
Widget *dlg_find_by_id (const Dlg_head * h, unsigned int id);
|
||||
void dlg_select_by_id (const Dlg_head * h, unsigned int id);
|
||||
|
||||
/* Redraw all dialogs */
|
||||
void do_refresh (void);
|
||||
|
||||
/* Sets/clear the specified flag in the options field */
|
||||
#define widget_option(w,f,i) \
|
||||
w.options = ((i) ? ((w).options | (f)) : ((w).options & (~(f))))
|
||||
|
||||
#define widget_want_cursor(w,i) widget_option((w), W_WANT_CURSOR, (i))
|
||||
#define widget_want_hotkey(w,i) widget_option((w), W_WANT_HOTKEY, (i))
|
||||
#define widget_disable(w,i) widget_option((w), W_DISABLED, (i))
|
||||
|
||||
/* Used in load_prompt() */
|
||||
void update_cursor (Dlg_head * h);
|
||||
|
||||
#endif /* MC_DIALOG_H */
|
||||
#endif /* MC__DIALOG_H */
|
||||
|
72
src/dir.h
72
src/dir.h
@ -1,20 +1,28 @@
|
||||
|
||||
/** \file dir.h
|
||||
* \brief Header: directory routines
|
||||
*/
|
||||
|
||||
#ifndef MC_DIR_H
|
||||
#define MC_DIR_H
|
||||
#ifndef MC__DIR_H
|
||||
#define MC__DIR_H
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "lib/global.h"
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
#define MIN_FILES 128
|
||||
#define RESIZE_STEPS 128
|
||||
|
||||
typedef int sortfn (const void *, const void *);
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
/* keys are set only during sorting */
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
/* File attributes */
|
||||
size_t fnamelen;
|
||||
char *fname;
|
||||
@ -25,45 +33,49 @@ typedef struct {
|
||||
char *second_sort_key;
|
||||
|
||||
/* Flags */
|
||||
struct {
|
||||
unsigned int marked:1; /* File marked in pane window */
|
||||
unsigned int link_to_dir:1; /* If this is a link, does it point to directory? */
|
||||
unsigned int stale_link:1; /* If this is a symlink and points to Charon's land */
|
||||
unsigned int dir_size_computed:1; /* Size of directory was computed with dirsizes_cmd */
|
||||
struct
|
||||
{
|
||||
unsigned int marked:1; /* File marked in pane window */
|
||||
unsigned int link_to_dir:1; /* If this is a link, does it point to directory? */
|
||||
unsigned int stale_link:1; /* If this is a symlink and points to Charon's land */
|
||||
unsigned int dir_size_computed:1; /* Size of directory was computed with dirsizes_cmd */
|
||||
} f;
|
||||
} file_entry;
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
file_entry *list;
|
||||
int size;
|
||||
int size;
|
||||
} dir_list;
|
||||
|
||||
typedef int sortfn (const void *, const void *);
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
int do_load_dir (const char *path, dir_list * list, sortfn * sort, int reverse,
|
||||
int case_sensitive, int exec_ff, const char *fltr);
|
||||
int case_sensitive, int exec_ff, const char *fltr);
|
||||
void do_sort (dir_list * list, sortfn * sort, int top, int reverse,
|
||||
int case_sensitive, int exec_ff);
|
||||
int case_sensitive, int exec_ff);
|
||||
int do_reload_dir (const char *path, dir_list * list, sortfn * sort, int count,
|
||||
int reverse, int case_sensitive, int exec_ff, const char *fltr);
|
||||
int reverse, int case_sensitive, int exec_ff, const char *fltr);
|
||||
void clean_dir (dir_list * list, int count);
|
||||
gboolean set_zero_dir (dir_list *list);
|
||||
int handle_path (dir_list *list, const char *path, struct stat *buf1,
|
||||
int next_free, int *link_to_dir, int *stale_link);
|
||||
gboolean set_zero_dir (dir_list * list);
|
||||
int handle_path (dir_list * list, const char *path, struct stat *buf1,
|
||||
int next_free, int *link_to_dir, int *stale_link);
|
||||
|
||||
/* Sorting functions */
|
||||
int unsorted (file_entry *a, file_entry *b);
|
||||
int sort_name (file_entry *a, file_entry *b);
|
||||
int sort_vers (file_entry *a, file_entry *b);
|
||||
int sort_ext (file_entry *a, file_entry *b);
|
||||
int sort_time (file_entry *a, file_entry *b);
|
||||
int sort_atime (file_entry *a, file_entry *b);
|
||||
int sort_ctime (file_entry *a, file_entry *b);
|
||||
int sort_size (file_entry *a, file_entry *b);
|
||||
int sort_inode (file_entry *a, file_entry *b);
|
||||
|
||||
int unsorted (file_entry * a, file_entry * b);
|
||||
int sort_name (file_entry * a, file_entry * b);
|
||||
int sort_vers (file_entry * a, file_entry * b);
|
||||
int sort_ext (file_entry * a, file_entry * b);
|
||||
int sort_time (file_entry * a, file_entry * b);
|
||||
int sort_atime (file_entry * a, file_entry * b);
|
||||
int sort_ctime (file_entry * a, file_entry * b);
|
||||
int sort_size (file_entry * a, file_entry * b);
|
||||
int sort_inode (file_entry * a, file_entry * b);
|
||||
|
||||
int link_isdir (const file_entry *);
|
||||
int if_link_is_exe (const char *full_name, const file_entry *file);
|
||||
int if_link_is_exe (const char *full_name, const file_entry * file);
|
||||
|
||||
#endif /* MC_DIR_H */
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__DIR_H */
|
||||
|
127
src/execute.c
127
src/execute.c
@ -41,6 +41,16 @@
|
||||
#include "execute.h"
|
||||
#include "lib/vfs/mc-vfs/vfs.h"
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
edition_post_exec (void)
|
||||
@ -59,6 +69,7 @@ edition_post_exec (void)
|
||||
application_keypad_mode ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
edition_pre_exec (void)
|
||||
@ -89,23 +100,7 @@ edition_pre_exec (void)
|
||||
do_exit_ca_mode ();
|
||||
}
|
||||
|
||||
|
||||
/* Set up the terminal before executing a program */
|
||||
void
|
||||
pre_exec (void)
|
||||
{
|
||||
use_dash (FALSE);
|
||||
edition_pre_exec ();
|
||||
}
|
||||
|
||||
/* Hide the terminal after executing a program */
|
||||
void
|
||||
post_exec (void)
|
||||
{
|
||||
edition_post_exec ();
|
||||
use_dash (TRUE);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
#ifdef HAVE_SUBSHELL_SUPPORT
|
||||
static void
|
||||
@ -120,6 +115,8 @@ do_possible_cd (const char *new_dir)
|
||||
}
|
||||
#endif /* HAVE_SUBSHELL_SUPPORT */
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
do_execute (const char *lc_shell, const char *command, int flags)
|
||||
{
|
||||
@ -208,8 +205,63 @@ do_execute (const char *lc_shell, const char *command, int flags)
|
||||
use_dash (TRUE);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
do_suspend_cmd (void)
|
||||
{
|
||||
pre_exec ();
|
||||
|
||||
if (console_flag && !use_subshell)
|
||||
handle_console (CONSOLE_RESTORE);
|
||||
|
||||
#ifdef SIGTSTP
|
||||
{
|
||||
struct sigaction sigtstp_action;
|
||||
|
||||
/* Make sure that the SIGTSTP below will suspend us directly,
|
||||
without calling ncurses' SIGTSTP handler; we *don't* want
|
||||
ncurses to redraw the screen immediately after the SIGCONT */
|
||||
sigaction (SIGTSTP, &startup_handler, &sigtstp_action);
|
||||
|
||||
kill (getpid (), SIGTSTP);
|
||||
|
||||
/* Restore previous SIGTSTP action */
|
||||
sigaction (SIGTSTP, &sigtstp_action, NULL);
|
||||
}
|
||||
#endif /* SIGTSTP */
|
||||
|
||||
if (console_flag && !use_subshell)
|
||||
handle_console (CONSOLE_SAVE);
|
||||
|
||||
edition_post_exec ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/** Set up the terminal before executing a program */
|
||||
|
||||
void
|
||||
pre_exec (void)
|
||||
{
|
||||
use_dash (FALSE);
|
||||
edition_pre_exec ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Hide the terminal after executing a program */
|
||||
void
|
||||
post_exec (void)
|
||||
{
|
||||
edition_post_exec ();
|
||||
use_dash (TRUE);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/* Executes a command */
|
||||
|
||||
void
|
||||
shell_execute (const char *command, int flags)
|
||||
{
|
||||
@ -234,6 +286,7 @@ shell_execute (const char *command, int flags)
|
||||
g_free (cmd);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
exec_shell (void)
|
||||
@ -241,6 +294,7 @@ exec_shell (void)
|
||||
do_execute (shell, 0, 0);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
toggle_panels (void)
|
||||
@ -340,37 +394,7 @@ toggle_panels (void)
|
||||
repaint_screen ();
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
do_suspend_cmd (void)
|
||||
{
|
||||
pre_exec ();
|
||||
|
||||
if (console_flag && !use_subshell)
|
||||
handle_console (CONSOLE_RESTORE);
|
||||
|
||||
#ifdef SIGTSTP
|
||||
{
|
||||
struct sigaction sigtstp_action;
|
||||
|
||||
/* Make sure that the SIGTSTP below will suspend us directly,
|
||||
without calling ncurses' SIGTSTP handler; we *don't* want
|
||||
ncurses to redraw the screen immediately after the SIGCONT */
|
||||
sigaction (SIGTSTP, &startup_handler, &sigtstp_action);
|
||||
|
||||
kill (getpid (), SIGTSTP);
|
||||
|
||||
/* Restore previous SIGTSTP action */
|
||||
sigaction (SIGTSTP, &sigtstp_action, NULL);
|
||||
}
|
||||
#endif /* SIGTSTP */
|
||||
|
||||
if (console_flag && !use_subshell)
|
||||
handle_console (CONSOLE_SAVE);
|
||||
|
||||
edition_post_exec ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
suspend_cmd (void)
|
||||
@ -383,11 +407,12 @@ suspend_cmd (void)
|
||||
do_refresh ();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Execute command on a filename that can be on VFS.
|
||||
* Errors are reported to the user.
|
||||
*/
|
||||
|
||||
void
|
||||
execute_with_vfs_arg (const char *command, const char *filename)
|
||||
{
|
||||
@ -430,3 +455,5 @@ execute_with_vfs_arg (const char *command, const char *filename)
|
||||
g_free (localcopy);
|
||||
g_free (fn);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -1,16 +1,25 @@
|
||||
|
||||
/** \file execute.h
|
||||
* \brief Header: execution routines
|
||||
*/
|
||||
|
||||
#ifndef MC_EXECUTE_H
|
||||
#define MC_EXECUTE_H
|
||||
#ifndef MC__EXECUTE_H
|
||||
#define MC__EXECUTE_H
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/* flags for shell_execute */
|
||||
#define EXECUTE_INTERNAL (1 << 0)
|
||||
#define EXECUTE_AS_SHELL (1 << 2)
|
||||
#define EXECUTE_HIDE (1 << 3)
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
/* Execute functions that use the shell to execute */
|
||||
void shell_execute (const char *command, int flags);
|
||||
|
||||
@ -29,4 +38,5 @@ void execute_with_vfs_arg (const char *command, const char *filename);
|
||||
void post_exec (void);
|
||||
void pre_exec (void);
|
||||
|
||||
#endif /* MC_EXECUTE_H */
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__EXECUTE_H */
|
||||
|
74
src/ext.c
74
src/ext.c
@ -55,23 +55,33 @@
|
||||
#include "dialog-switch.h"
|
||||
#include "ext.h"
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
/* If set, we execute the file command to check the file type */
|
||||
int use_file_to_check_type = 1;
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
#ifdef FILE_L
|
||||
#define FILE_CMD "file -L "
|
||||
#else
|
||||
#define FILE_CMD "file "
|
||||
#endif
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
typedef char *(*quote_func_t) (const char *name, int quote_percent);
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
/* This variable points to a copy of the mc.ext file in memory
|
||||
* With this we avoid loading/parsing the file each time we
|
||||
* need it
|
||||
*/
|
||||
static char *data = NULL;
|
||||
|
||||
void
|
||||
flush_extension_file (void)
|
||||
{
|
||||
g_free (data);
|
||||
data = NULL;
|
||||
}
|
||||
|
||||
typedef char *(*quote_func_t) (const char *name, int quote_percent);
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
exec_extension (const char *filename, const char *lc_data, int *move_dir, int start_line)
|
||||
@ -134,8 +144,7 @@ exec_extension (const char *filename, const char *lc_data, int *move_dir, int st
|
||||
char *parameter;
|
||||
|
||||
parameter_found = 0;
|
||||
parameter =
|
||||
input_dialog (_("Parameter"), lc_prompt, MC_HISTORY_EXT_PARAMETER, "");
|
||||
parameter = input_dialog (_("Parameter"), lc_prompt, MC_HISTORY_EXT_PARAMETER, "");
|
||||
if (parameter == NULL)
|
||||
{
|
||||
/* User canceled */
|
||||
@ -364,19 +373,15 @@ exec_extension (const char *filename, const char *lc_data, int *move_dir, int st
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef FILE_L
|
||||
# define FILE_CMD "file -L "
|
||||
#else
|
||||
# define FILE_CMD "file "
|
||||
#endif
|
||||
|
||||
/*
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Run cmd_file with args, put result into buf.
|
||||
* If error, put '\0' into buf[0]
|
||||
* Return 1 if the data is valid, 0 otherwise, -1 for fatal errors.
|
||||
*
|
||||
* NOTES: buf is null-terminated string.
|
||||
*/
|
||||
|
||||
static int
|
||||
get_popen_information (const char *cmd_file, const char *args, char *buf, int buflen)
|
||||
{
|
||||
@ -413,10 +418,12 @@ get_popen_information (const char *cmd_file, const char *args, char *buf, int bu
|
||||
return read_bytes ? 1 : 0;
|
||||
}
|
||||
|
||||
/*
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Run the "file" command on the local file.
|
||||
* Return 1 if the data is valid, 0 otherwise, -1 for fatal errors.
|
||||
*/
|
||||
|
||||
static int
|
||||
get_file_type_local (const char *filename, char *buf, int buflen)
|
||||
{
|
||||
@ -430,11 +437,13 @@ get_file_type_local (const char *filename, char *buf, int buflen)
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef HAVE_CHARSET
|
||||
/*
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Run the "enca" command on the local file.
|
||||
* Return 1 if the data is valid, 0 otherwise, -1 for fatal errors.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CHARSET
|
||||
static int
|
||||
get_file_encoding_local (const char *filename, char *buf, int buflen)
|
||||
{
|
||||
@ -455,12 +464,14 @@ get_file_encoding_local (const char *filename, char *buf, int buflen)
|
||||
}
|
||||
#endif /* HAVE_CHARSET */
|
||||
|
||||
/*
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Invoke the "file" command on the file and match its output against PTR.
|
||||
* have_type is a flag that is set if we already have tried to determine
|
||||
* the type of that file.
|
||||
* Return 1 for match, 0 for no match, -1 errors.
|
||||
*/
|
||||
|
||||
static int
|
||||
regex_check_type (const char *filename, const char *ptr, int *have_type)
|
||||
{
|
||||
@ -563,8 +574,20 @@ regex_check_type (const char *filename, const char *ptr, int *have_type)
|
||||
return found;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/* The second argument is action, i.e. Open, View or Edit
|
||||
void
|
||||
flush_extension_file (void)
|
||||
{
|
||||
g_free (data);
|
||||
data = NULL;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* The second argument is action, i.e. Open, View or Edit
|
||||
*
|
||||
* This function returns:
|
||||
*
|
||||
@ -575,6 +598,7 @@ regex_check_type (const char *filename, const char *ptr, int *have_type)
|
||||
* If action == "View" then a parameter is checked in the form of "View:%d",
|
||||
* if the value for %d exists, then the viewer is started up at that line number.
|
||||
*/
|
||||
|
||||
int
|
||||
regex_command (const char *filename, const char *action, int *move_dir)
|
||||
{
|
||||
@ -651,9 +675,8 @@ regex_command (const char *filename, const char *action, int *move_dir)
|
||||
}
|
||||
if (home_error)
|
||||
{
|
||||
char *title =
|
||||
g_strdup_printf (_("~/%s file error"),
|
||||
MC_USERCONF_DIR PATH_SEP_STR MC_FILEBIND_FILE);
|
||||
char *title = g_strdup_printf (_("~/%s file error"),
|
||||
MC_USERCONF_DIR PATH_SEP_STR MC_FILEBIND_FILE);
|
||||
message (D_ERROR, title,
|
||||
_("The format of the ~/%s file has "
|
||||
"changed with version 3.0. You may either want to copy "
|
||||
@ -812,3 +835,4 @@ regex_command (const char *filename, const char *action, int *move_dir)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
17
src/ext.h
17
src/ext.h
@ -1,10 +1,18 @@
|
||||
|
||||
/** \file ext.h
|
||||
* \brief Header: extension dependent execution
|
||||
*/
|
||||
|
||||
#ifndef MC_EXT_H
|
||||
#define MC_EXT_H
|
||||
#ifndef MC__EXT_H
|
||||
#define MC__EXT_H
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
int regex_command (const char *filename, const char *action, int *move_dir);
|
||||
|
||||
@ -13,4 +21,5 @@ int regex_command (const char *filename, const char *action, int *move_dir);
|
||||
*/
|
||||
void flush_extension_file (void);
|
||||
|
||||
#endif
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__EXT_H */
|
||||
|
1552
src/file.c
1552
src/file.c
File diff suppressed because it is too large
Load Diff
43
src/file.h
43
src/file.h
@ -1,10 +1,9 @@
|
||||
|
||||
/** \file file.h
|
||||
* \brief Header: File and directory operation routines
|
||||
*/
|
||||
|
||||
#ifndef MC_FILE_H
|
||||
#define MC_FILE_H
|
||||
#ifndef MC__FILE_H
|
||||
#define MC__FILE_H
|
||||
|
||||
#include <sys/types.h> /* off_t */
|
||||
#include <sys/time.h>
|
||||
@ -14,8 +13,31 @@
|
||||
#include "widget.h" /* WLabel */
|
||||
#include "fileopctx.h"
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/* Compute directory size */
|
||||
/* callback to update status dialog */
|
||||
typedef FileProgressStatus (*compute_dir_size_callback) (const void *ui, const char *dirname);
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
struct link;
|
||||
|
||||
/* status dialog of directory size computing */
|
||||
typedef struct
|
||||
{
|
||||
Dlg_head *dlg;
|
||||
WLabel *dirname;
|
||||
} ComputeDirSizeUI;
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
extern int file_op_compute_totals;
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
FileProgressStatus copy_file_file (FileOpTotalContext * tctx, FileOpContext * ctx,
|
||||
const char *src_path, const char *dst_path);
|
||||
FileProgressStatus move_dir_dir (FileOpTotalContext * tctx, FileOpContext * ctx,
|
||||
@ -28,32 +50,21 @@ FileProgressStatus erase_dir (FileOpTotalContext * tctx, FileOpContext * ctx, co
|
||||
|
||||
gboolean panel_operate (void *source_panel, FileOperation op, gboolean force_single);
|
||||
|
||||
extern int file_op_compute_totals;
|
||||
|
||||
/* Error reporting routines */
|
||||
|
||||
/* Report error with one file */
|
||||
FileProgressStatus file_error (const char *format, const char *file);
|
||||
|
||||
/* Compute directory size */
|
||||
/* callback to update status dialog */
|
||||
typedef FileProgressStatus (*compute_dir_size_callback) (const void *ui, const char *dirname);
|
||||
|
||||
/* return value is FILE_CONT or FILE_ABORT */
|
||||
FileProgressStatus compute_dir_size (const char *dirname, const void *ui,
|
||||
compute_dir_size_callback cback,
|
||||
off_t * ret_marked, double *ret_total,
|
||||
gboolean compute_symlinks);
|
||||
|
||||
/* status dialog of directory size computing */
|
||||
typedef struct
|
||||
{
|
||||
Dlg_head *dlg;
|
||||
WLabel *dirname;
|
||||
} ComputeDirSizeUI;
|
||||
|
||||
ComputeDirSizeUI *compute_dir_size_create_ui (void);
|
||||
void compute_dir_size_destroy_ui (ComputeDirSizeUI * ui);
|
||||
FileProgressStatus compute_dir_size_update_ui (const void *ui, const char *dirname);
|
||||
|
||||
#endif /* MC_FILE_H */
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__FILE_H */
|
||||
|
871
src/filegui.c
871
src/filegui.c
@ -58,20 +58,20 @@
|
||||
#if defined(STAT_STATVFS) \
|
||||
&& (defined(HAVE_STRUCT_STATVFS_F_BASETYPE) \
|
||||
|| defined(HAVE_STRUCT_STATVFS_F_FSTYPENAME))
|
||||
# include <sys/statvfs.h>
|
||||
# define STRUCT_STATFS struct statvfs
|
||||
# define STATFS statvfs
|
||||
#include <sys/statvfs.h>
|
||||
#define STRUCT_STATFS struct statvfs
|
||||
#define STATFS statvfs
|
||||
#elif defined(HAVE_STATFS) && !defined(STAT_STATFS4)
|
||||
# ifdef HAVE_SYS_VFS_H
|
||||
# include <sys/vfs.h>
|
||||
# elif defined(HAVE_SYS_MOUNT_H) && defined(HAVE_SYS_PARAM_H)
|
||||
# include <sys/param.h>
|
||||
# include <sys/mount.h>
|
||||
# elif defined(HAVE_SYS_STATFS_H)
|
||||
# include <sys/statfs.h>
|
||||
# endif
|
||||
# define STRUCT_STATFS struct statfs
|
||||
# define STATFS statfs
|
||||
#ifdef HAVE_SYS_VFS_H
|
||||
#include <sys/vfs.h>
|
||||
#elif defined(HAVE_SYS_MOUNT_H) && defined(HAVE_SYS_PARAM_H)
|
||||
#include <sys/param.h>
|
||||
#include <sys/mount.h>
|
||||
#elif defined(HAVE_SYS_STATFS_H)
|
||||
#include <sys/statfs.h>
|
||||
#endif
|
||||
#define STRUCT_STATFS struct statfs
|
||||
#define STATFS statfs
|
||||
#endif
|
||||
|
||||
#include <unistd.h>
|
||||
@ -97,6 +97,26 @@
|
||||
#include "filegui.h"
|
||||
|
||||
/* }}} */
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
int classic_progressbar = 1;
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
/* Hack: the vfs code should not rely on this */
|
||||
#define WITH_FULL_PATHS 1
|
||||
|
||||
/* File operate window sizes */
|
||||
#define WX 58
|
||||
#define WY 11
|
||||
#define FCOPY_LABEL_X 3
|
||||
|
||||
#define truncFileString(ui, s) str_trunc (s, 52)
|
||||
#define truncFileStringSecure(ui, s) path_trunc (s, 52)
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
typedef enum {
|
||||
MSDOS_SUPER_MAGIC = 0x4d44,
|
||||
@ -109,9 +129,6 @@ typedef enum {
|
||||
} filegui_nonattrs_fs_t;
|
||||
/* *INDENT-ON* */
|
||||
|
||||
/* Hack: the vfs code should not rely on this */
|
||||
#define WITH_FULL_PATHS 1
|
||||
|
||||
/* Used for button result values */
|
||||
typedef enum
|
||||
{
|
||||
@ -156,15 +173,13 @@ typedef struct
|
||||
struct stat *s_stat, *d_stat;
|
||||
} FileOpContextUI;
|
||||
|
||||
int classic_progressbar = 1;
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
/* Used to save the hint line */
|
||||
static int last_hint_line;
|
||||
|
||||
/* File operate window sizes */
|
||||
#define WX 58
|
||||
#define WY 11
|
||||
#define FCOPY_LABEL_X 3
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static gboolean
|
||||
filegui__check_attrs_on_fs (const char *fs_path)
|
||||
@ -178,7 +193,7 @@ filegui__check_attrs_on_fs (const char *fs_path)
|
||||
if (STATFS (fs_path, &stfs) != 0)
|
||||
return TRUE;
|
||||
|
||||
# ifdef __linux__
|
||||
#ifdef __linux__
|
||||
switch ((filegui_nonattrs_fs_t) stfs.f_type)
|
||||
{
|
||||
case MSDOS_SUPER_MAGIC:
|
||||
@ -190,7 +205,7 @@ filegui__check_attrs_on_fs (const char *fs_path)
|
||||
case USBDEVICE_SUPER_MAGIC:
|
||||
return FALSE;
|
||||
}
|
||||
# elif defined(HAVE_STRUCT_STATFS_F_FSTYPENAME) \
|
||||
#elif defined(HAVE_STRUCT_STATFS_F_FSTYPENAME) \
|
||||
|| defined(HAVE_STRUCT_STATVFS_F_FSTYPENAME)
|
||||
if (!strcmp (stfs.f_fstypename, "msdos")
|
||||
|| !strcmp (stfs.f_fstypename, "msdosfs")
|
||||
@ -198,194 +213,19 @@ filegui__check_attrs_on_fs (const char *fs_path)
|
||||
|| !strcmp (stfs.f_fstypename, "procfs")
|
||||
|| !strcmp (stfs.f_fstypename, "smbfs") || strstr (stfs.f_fstypename, "fusefs"))
|
||||
return FALSE;
|
||||
# elif defined(HAVE_STRUCT_STATVFS_F_BASETYPE)
|
||||
#elif defined(HAVE_STRUCT_STATVFS_F_BASETYPE)
|
||||
if (!strcmp (stfs.f_basetype, "pcfs")
|
||||
|| !strcmp (stfs.f_basetype, "ntfs")
|
||||
|| !strcmp (stfs.f_basetype, "proc")
|
||||
|| !strcmp (stfs.f_basetype, "smbfs") || !strcmp (stfs.f_basetype, "fuse"))
|
||||
return FALSE;
|
||||
# endif
|
||||
#endif
|
||||
#endif /* STATFS */
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
FileProgressStatus
|
||||
check_progress_buttons (FileOpContext * ctx)
|
||||
{
|
||||
int c;
|
||||
Gpm_Event event;
|
||||
FileOpContextUI *ui;
|
||||
|
||||
if (ctx->ui == NULL)
|
||||
return FILE_CONT;
|
||||
|
||||
ui = ctx->ui;
|
||||
|
||||
event.x = -1; /* Don't show the GPM cursor */
|
||||
c = tty_get_event (&event, FALSE, FALSE);
|
||||
if (c == EV_NONE)
|
||||
return FILE_CONT;
|
||||
|
||||
/* Reinitialize to avoid old values after events other than
|
||||
selecting a button */
|
||||
ui->op_dlg->ret_value = FILE_CONT;
|
||||
|
||||
dlg_process_event (ui->op_dlg, c, &event);
|
||||
switch (ui->op_dlg->ret_value)
|
||||
{
|
||||
case FILE_SKIP:
|
||||
return FILE_SKIP;
|
||||
case B_CANCEL:
|
||||
case FILE_ABORT:
|
||||
return FILE_ABORT;
|
||||
default:
|
||||
return FILE_CONT;
|
||||
}
|
||||
}
|
||||
|
||||
/* {{{ File progress display routines */
|
||||
|
||||
void
|
||||
file_op_context_create_ui_without_init (FileOpContext * ctx, gboolean with_eta,
|
||||
filegui_dialog_type_t dialog_type)
|
||||
{
|
||||
FileOpContextUI *ui;
|
||||
int minus = 0, total_reserve = 0;
|
||||
const char *abort_button_label = N_("&Abort");
|
||||
const char *skip_button_label = N_("&Skip");
|
||||
int abort_button_width, skip_button_width, buttons_width;
|
||||
int dlg_width;
|
||||
|
||||
g_return_if_fail (ctx != NULL);
|
||||
g_return_if_fail (ctx->ui == NULL);
|
||||
|
||||
#ifdef ENABLE_NLS
|
||||
abort_button_label = _(abort_button_label);
|
||||
skip_button_label = _(skip_button_label);
|
||||
#endif
|
||||
|
||||
abort_button_width = str_term_width1 (abort_button_label) + 3;
|
||||
skip_button_width = str_term_width1 (skip_button_label) + 3;
|
||||
buttons_width = abort_button_width + skip_button_width + 2;
|
||||
|
||||
dlg_width = max (WX, buttons_width + 6);
|
||||
|
||||
ui = g_new0 (FileOpContextUI, 1);
|
||||
ctx->ui = ui;
|
||||
|
||||
ctx->dialog_type = dialog_type;
|
||||
|
||||
switch (dialog_type)
|
||||
{
|
||||
case FILEGUI_DIALOG_ONE_ITEM:
|
||||
total_reserve = 0;
|
||||
minus = verbose ? 0 : 2;
|
||||
break;
|
||||
case FILEGUI_DIALOG_MULTI_ITEM:
|
||||
total_reserve = 5;
|
||||
minus = verbose ? 0 : 7;
|
||||
break;
|
||||
case FILEGUI_DIALOG_DELETE_ITEM:
|
||||
total_reserve = -5;
|
||||
minus = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
ctx->recursive_result = RECURSIVE_YES;
|
||||
|
||||
ui->replace_result = REPLACE_YES;
|
||||
ui->showing_eta = with_eta;
|
||||
ui->showing_bps = with_eta;
|
||||
|
||||
ui->op_dlg =
|
||||
create_dlg (TRUE, 0, 0, WY - minus + 1 + total_reserve, dlg_width,
|
||||
dialog_colors, NULL, NULL, op_names[ctx->operation], DLG_CENTER | DLG_REVERSE);
|
||||
|
||||
last_hint_line = the_hint->widget.y;
|
||||
if ((ui->op_dlg->y + ui->op_dlg->lines) > last_hint_line)
|
||||
the_hint->widget.y = ui->op_dlg->y + ui->op_dlg->lines + 1;
|
||||
|
||||
add_widget (ui->op_dlg,
|
||||
button_new (WY - minus - 2 + total_reserve,
|
||||
dlg_width / 2 + 1, FILE_ABORT,
|
||||
NORMAL_BUTTON, abort_button_label, NULL));
|
||||
add_widget (ui->op_dlg,
|
||||
button_new (WY - minus - 2 + total_reserve,
|
||||
dlg_width / 2 - 1 - skip_button_width, FILE_SKIP,
|
||||
NORMAL_BUTTON, skip_button_label, NULL));
|
||||
|
||||
|
||||
if (verbose && dialog_type == FILEGUI_DIALOG_MULTI_ITEM)
|
||||
{
|
||||
add_widget (ui->op_dlg, hline_new (8, 1, dlg_width - 2));
|
||||
|
||||
add_widget (ui->op_dlg, ui->total_bytes_label = label_new (8, FCOPY_LABEL_X + 15, ""));
|
||||
|
||||
add_widget (ui->op_dlg, ui->progress_total_gauge =
|
||||
gauge_new (9, FCOPY_LABEL_X + 3, 0, 100, 0));
|
||||
|
||||
add_widget (ui->op_dlg, ui->total_files_processed_label =
|
||||
label_new (11, FCOPY_LABEL_X, ""));
|
||||
|
||||
add_widget (ui->op_dlg, ui->time_label = label_new (12, FCOPY_LABEL_X, ""));
|
||||
}
|
||||
|
||||
add_widget (ui->op_dlg, ui->progress_file_label = label_new (7, FCOPY_LABEL_X, ""));
|
||||
|
||||
add_widget (ui->op_dlg, ui->progress_file_gauge = gauge_new (6, FCOPY_LABEL_X + 3, 0, 100, 0));
|
||||
|
||||
add_widget (ui->op_dlg, ui->file_string[1] = label_new (5, FCOPY_LABEL_X, ""));
|
||||
|
||||
add_widget (ui->op_dlg, ui->file_label[1] = label_new (4, FCOPY_LABEL_X, ""));
|
||||
add_widget (ui->op_dlg, ui->file_string[0] = label_new (3, FCOPY_LABEL_X, ""));
|
||||
add_widget (ui->op_dlg, ui->file_label[0] = label_new (2, FCOPY_LABEL_X, ""));
|
||||
|
||||
if ((right_panel == current_panel) && !classic_progressbar)
|
||||
{
|
||||
ui->progress_file_gauge->from_left_to_right = FALSE;
|
||||
if (dialog_type == FILEGUI_DIALOG_MULTI_ITEM)
|
||||
ui->progress_total_gauge->from_left_to_right = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
file_op_context_create_ui (FileOpContext * ctx, gboolean with_eta,
|
||||
filegui_dialog_type_t dialog_type)
|
||||
{
|
||||
FileOpContextUI *ui;
|
||||
|
||||
g_return_if_fail (ctx != NULL);
|
||||
g_return_if_fail (ctx->ui == NULL);
|
||||
|
||||
file_op_context_create_ui_without_init (ctx, with_eta, dialog_type);
|
||||
ui = ctx->ui;
|
||||
|
||||
/* We will manage the dialog without any help, that's why
|
||||
we have to call init_dlg */
|
||||
init_dlg (ui->op_dlg);
|
||||
}
|
||||
|
||||
void
|
||||
file_op_context_destroy_ui (FileOpContext * ctx)
|
||||
{
|
||||
FileOpContextUI *ui;
|
||||
|
||||
g_return_if_fail (ctx != NULL);
|
||||
|
||||
if (ctx->ui)
|
||||
{
|
||||
ui = ctx->ui;
|
||||
|
||||
dlg_run_done (ui->op_dlg);
|
||||
destroy_dlg (ui->op_dlg);
|
||||
g_free (ui);
|
||||
}
|
||||
|
||||
the_hint->widget.y = last_hint_line;
|
||||
|
||||
ctx->ui = NULL;
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
file_frmt_time (char *buffer, double eta_secs)
|
||||
@ -397,6 +237,8 @@ file_frmt_time (char *buffer, double eta_secs)
|
||||
g_snprintf (buffer, BUF_TINY, _("%d:%02d.%02d"), eta_hours, eta_mins, eta_s);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
file_eta_prepare_for_show (char *buffer, double eta_secs, gboolean always_show)
|
||||
{
|
||||
@ -412,6 +254,8 @@ file_eta_prepare_for_show (char *buffer, double eta_secs, gboolean always_show)
|
||||
g_snprintf (buffer, BUF_TINY, _("ETA %s"), _fmt_buff);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
file_bps_prepare_for_show (char *buffer, long bps)
|
||||
{
|
||||
@ -431,204 +275,7 @@ file_bps_prepare_for_show (char *buffer, long bps)
|
||||
*buffer = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
show progressbar for file
|
||||
*/
|
||||
void
|
||||
file_progress_show (FileOpContext * ctx, off_t done, off_t total,
|
||||
const char *stalled_msg, gboolean force_update)
|
||||
{
|
||||
FileOpContextUI *ui;
|
||||
char buffer[BUF_TINY];
|
||||
char buffer2[BUF_TINY];
|
||||
char buffer3[BUF_TINY];
|
||||
|
||||
g_return_if_fail (ctx != NULL);
|
||||
|
||||
if (ctx->ui == NULL)
|
||||
return;
|
||||
|
||||
ui = ctx->ui;
|
||||
|
||||
if (!verbose)
|
||||
return;
|
||||
|
||||
if (total == 0)
|
||||
{
|
||||
gauge_show (ui->progress_file_gauge, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
gauge_set_value (ui->progress_file_gauge, 1024, (int) (1024 * done / total));
|
||||
gauge_show (ui->progress_file_gauge, 1);
|
||||
|
||||
if (!force_update)
|
||||
return;
|
||||
|
||||
if (ui->showing_eta && ctx->eta_secs > 0.5)
|
||||
{
|
||||
file_eta_prepare_for_show (buffer2, ctx->eta_secs, FALSE);
|
||||
file_bps_prepare_for_show (buffer3, ctx->bps);
|
||||
g_snprintf (buffer, BUF_TINY, "%s (%s) %s", buffer2, buffer3, stalled_msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_snprintf (buffer, BUF_TINY, "%s", stalled_msg);
|
||||
}
|
||||
|
||||
label_set_text (ui->progress_file_label, buffer);
|
||||
}
|
||||
|
||||
void
|
||||
file_progress_show_count (FileOpContext * ctx, off_t done, off_t total)
|
||||
{
|
||||
char buffer[BUF_TINY];
|
||||
FileOpContextUI *ui;
|
||||
|
||||
g_return_if_fail (ctx != NULL);
|
||||
|
||||
if (ctx->dialog_type != FILEGUI_DIALOG_MULTI_ITEM || ctx->ui == NULL)
|
||||
return;
|
||||
|
||||
ui = ctx->ui;
|
||||
|
||||
if (!verbose)
|
||||
return;
|
||||
|
||||
g_snprintf (buffer, BUF_TINY, _("Files processed: %llu of %llu"),
|
||||
(unsigned long long) done, (unsigned long long) total);
|
||||
|
||||
label_set_text (ui->total_files_processed_label, buffer);
|
||||
}
|
||||
|
||||
void
|
||||
file_progress_show_total (FileOpTotalContext * tctx, FileOpContext * ctx, double copyed_bytes,
|
||||
gboolean need_show_total_summary)
|
||||
{
|
||||
char buffer[BUF_TINY];
|
||||
char buffer2[BUF_TINY];
|
||||
char buffer3[BUF_TINY];
|
||||
char buffer4[BUF_TINY];
|
||||
struct timeval tv_current;
|
||||
FileOpContextUI *ui;
|
||||
|
||||
if (!verbose)
|
||||
return;
|
||||
|
||||
if (ctx->dialog_type != FILEGUI_DIALOG_MULTI_ITEM || ctx->ui == NULL)
|
||||
return;
|
||||
|
||||
ui = ctx->ui;
|
||||
|
||||
if (ctx->progress_bytes > 0)
|
||||
{
|
||||
gauge_set_value (ui->progress_total_gauge, 1024,
|
||||
(int) (1024 * copyed_bytes / ctx->progress_bytes));
|
||||
gauge_show (ui->progress_total_gauge, 1);
|
||||
}
|
||||
else
|
||||
gauge_show (ui->progress_total_gauge, 0);
|
||||
|
||||
|
||||
if (!need_show_total_summary && tctx->bps == 0)
|
||||
return;
|
||||
|
||||
gettimeofday (&tv_current, NULL);
|
||||
file_frmt_time (buffer2, tv_current.tv_sec - tctx->transfer_start.tv_sec);
|
||||
file_eta_prepare_for_show (buffer3, tctx->eta_secs, TRUE);
|
||||
file_bps_prepare_for_show (buffer4, (long) tctx->bps);
|
||||
|
||||
g_snprintf (buffer, BUF_TINY, _("Time: %s %s (%s)"), buffer2, buffer3, buffer4);
|
||||
label_set_text (ui->time_label, buffer);
|
||||
|
||||
size_trunc_len (buffer2, 5, tctx->copyed_bytes, 0, panels_options.kilobyte_si);
|
||||
size_trunc_len (buffer3, 5, ctx->progress_bytes, 0, panels_options.kilobyte_si);
|
||||
|
||||
g_snprintf (buffer, BUF_TINY, _("Total: %s of %s"), buffer2, buffer3);
|
||||
|
||||
label_set_text (ui->total_bytes_label, buffer);
|
||||
|
||||
}
|
||||
|
||||
/* }}} */
|
||||
|
||||
#define truncFileString(ui, s) str_trunc (s, 52)
|
||||
#define truncFileStringSecure(ui, s) path_trunc (s, 52)
|
||||
|
||||
void
|
||||
file_progress_show_source (FileOpContext * ctx, const char *s)
|
||||
{
|
||||
FileOpContextUI *ui;
|
||||
|
||||
g_return_if_fail (ctx != NULL);
|
||||
|
||||
if (ctx->ui == NULL)
|
||||
return;
|
||||
|
||||
ui = ctx->ui;
|
||||
|
||||
if (s != NULL)
|
||||
{
|
||||
#ifdef WITH_FULL_PATHS
|
||||
int i = strlen (current_panel->cwd);
|
||||
|
||||
/* We remove the full path we have added before */
|
||||
if (!strncmp (s, current_panel->cwd, i))
|
||||
{
|
||||
if (s[i] == PATH_SEP)
|
||||
s += i + 1;
|
||||
}
|
||||
#endif /* WITH_FULL_PATHS */
|
||||
|
||||
label_set_text (ui->file_label[0], _("Source"));
|
||||
label_set_text (ui->file_string[0], truncFileString (ui, s));
|
||||
}
|
||||
else
|
||||
{
|
||||
label_set_text (ui->file_label[0], "");
|
||||
label_set_text (ui->file_string[0], "");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
file_progress_show_target (FileOpContext * ctx, const char *s)
|
||||
{
|
||||
FileOpContextUI *ui;
|
||||
|
||||
g_return_if_fail (ctx != NULL);
|
||||
|
||||
if (ctx->ui == NULL)
|
||||
return;
|
||||
|
||||
ui = ctx->ui;
|
||||
|
||||
if (s != NULL)
|
||||
{
|
||||
label_set_text (ui->file_label[1], _("Target"));
|
||||
label_set_text (ui->file_string[1], truncFileStringSecure (ui, s));
|
||||
}
|
||||
else
|
||||
{
|
||||
label_set_text (ui->file_label[1], "");
|
||||
label_set_text (ui->file_string[1], "");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
file_progress_show_deleting (FileOpContext * ctx, const char *s)
|
||||
{
|
||||
FileOpContextUI *ui;
|
||||
|
||||
g_return_if_fail (ctx != NULL);
|
||||
|
||||
if (ctx->ui == NULL)
|
||||
return;
|
||||
|
||||
ui = ctx->ui;
|
||||
label_set_text (ui->file_label[0], _("Deleting"));
|
||||
label_set_text (ui->file_label[0], truncFileStringSecure (ui, s));
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*
|
||||
* FIXME: probably it is better to replace this with quick dialog machinery,
|
||||
* but actually I'm not familiar with it and have not much time :(
|
||||
@ -825,6 +472,417 @@ overwrite_query_dialog (FileOpContext * ctx, enum OperationMode mode)
|
||||
#undef ADD_RD_BUTTON
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static gboolean
|
||||
is_wildcarded (char *p)
|
||||
{
|
||||
for (; *p; p++)
|
||||
{
|
||||
if (*p == '*')
|
||||
return TRUE;
|
||||
if (*p == '\\' && p[1] >= '1' && p[1] <= '9')
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
FileProgressStatus
|
||||
check_progress_buttons (FileOpContext * ctx)
|
||||
{
|
||||
int c;
|
||||
Gpm_Event event;
|
||||
FileOpContextUI *ui;
|
||||
|
||||
if (ctx->ui == NULL)
|
||||
return FILE_CONT;
|
||||
|
||||
ui = ctx->ui;
|
||||
|
||||
event.x = -1; /* Don't show the GPM cursor */
|
||||
c = tty_get_event (&event, FALSE, FALSE);
|
||||
if (c == EV_NONE)
|
||||
return FILE_CONT;
|
||||
|
||||
/* Reinitialize to avoid old values after events other than
|
||||
selecting a button */
|
||||
ui->op_dlg->ret_value = FILE_CONT;
|
||||
|
||||
dlg_process_event (ui->op_dlg, c, &event);
|
||||
switch (ui->op_dlg->ret_value)
|
||||
{
|
||||
case FILE_SKIP:
|
||||
return FILE_SKIP;
|
||||
case B_CANCEL:
|
||||
case FILE_ABORT:
|
||||
return FILE_ABORT;
|
||||
default:
|
||||
return FILE_CONT;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/* {{{ File progress display routines */
|
||||
|
||||
void
|
||||
file_op_context_create_ui_without_init (FileOpContext * ctx, gboolean with_eta,
|
||||
filegui_dialog_type_t dialog_type)
|
||||
{
|
||||
FileOpContextUI *ui;
|
||||
int minus = 0, total_reserve = 0;
|
||||
const char *abort_button_label = N_("&Abort");
|
||||
const char *skip_button_label = N_("&Skip");
|
||||
int abort_button_width, skip_button_width, buttons_width;
|
||||
int dlg_width;
|
||||
|
||||
g_return_if_fail (ctx != NULL);
|
||||
g_return_if_fail (ctx->ui == NULL);
|
||||
|
||||
#ifdef ENABLE_NLS
|
||||
abort_button_label = _(abort_button_label);
|
||||
skip_button_label = _(skip_button_label);
|
||||
#endif
|
||||
|
||||
abort_button_width = str_term_width1 (abort_button_label) + 3;
|
||||
skip_button_width = str_term_width1 (skip_button_label) + 3;
|
||||
buttons_width = abort_button_width + skip_button_width + 2;
|
||||
|
||||
dlg_width = max (WX, buttons_width + 6);
|
||||
|
||||
ui = g_new0 (FileOpContextUI, 1);
|
||||
ctx->ui = ui;
|
||||
|
||||
ctx->dialog_type = dialog_type;
|
||||
|
||||
switch (dialog_type)
|
||||
{
|
||||
case FILEGUI_DIALOG_ONE_ITEM:
|
||||
total_reserve = 0;
|
||||
minus = verbose ? 0 : 2;
|
||||
break;
|
||||
case FILEGUI_DIALOG_MULTI_ITEM:
|
||||
total_reserve = 5;
|
||||
minus = verbose ? 0 : 7;
|
||||
break;
|
||||
case FILEGUI_DIALOG_DELETE_ITEM:
|
||||
total_reserve = -5;
|
||||
minus = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
ctx->recursive_result = RECURSIVE_YES;
|
||||
|
||||
ui->replace_result = REPLACE_YES;
|
||||
ui->showing_eta = with_eta;
|
||||
ui->showing_bps = with_eta;
|
||||
|
||||
ui->op_dlg =
|
||||
create_dlg (TRUE, 0, 0, WY - minus + 1 + total_reserve, dlg_width,
|
||||
dialog_colors, NULL, NULL, op_names[ctx->operation], DLG_CENTER | DLG_REVERSE);
|
||||
|
||||
last_hint_line = the_hint->widget.y;
|
||||
if ((ui->op_dlg->y + ui->op_dlg->lines) > last_hint_line)
|
||||
the_hint->widget.y = ui->op_dlg->y + ui->op_dlg->lines + 1;
|
||||
|
||||
add_widget (ui->op_dlg,
|
||||
button_new (WY - minus - 2 + total_reserve,
|
||||
dlg_width / 2 + 1, FILE_ABORT,
|
||||
NORMAL_BUTTON, abort_button_label, NULL));
|
||||
add_widget (ui->op_dlg,
|
||||
button_new (WY - minus - 2 + total_reserve,
|
||||
dlg_width / 2 - 1 - skip_button_width, FILE_SKIP,
|
||||
NORMAL_BUTTON, skip_button_label, NULL));
|
||||
|
||||
|
||||
if (verbose && dialog_type == FILEGUI_DIALOG_MULTI_ITEM)
|
||||
{
|
||||
add_widget (ui->op_dlg, hline_new (8, 1, dlg_width - 2));
|
||||
|
||||
add_widget (ui->op_dlg, ui->total_bytes_label = label_new (8, FCOPY_LABEL_X + 15, ""));
|
||||
|
||||
add_widget (ui->op_dlg, ui->progress_total_gauge =
|
||||
gauge_new (9, FCOPY_LABEL_X + 3, 0, 100, 0));
|
||||
|
||||
add_widget (ui->op_dlg, ui->total_files_processed_label =
|
||||
label_new (11, FCOPY_LABEL_X, ""));
|
||||
|
||||
add_widget (ui->op_dlg, ui->time_label = label_new (12, FCOPY_LABEL_X, ""));
|
||||
}
|
||||
|
||||
add_widget (ui->op_dlg, ui->progress_file_label = label_new (7, FCOPY_LABEL_X, ""));
|
||||
|
||||
add_widget (ui->op_dlg, ui->progress_file_gauge = gauge_new (6, FCOPY_LABEL_X + 3, 0, 100, 0));
|
||||
|
||||
add_widget (ui->op_dlg, ui->file_string[1] = label_new (5, FCOPY_LABEL_X, ""));
|
||||
|
||||
add_widget (ui->op_dlg, ui->file_label[1] = label_new (4, FCOPY_LABEL_X, ""));
|
||||
add_widget (ui->op_dlg, ui->file_string[0] = label_new (3, FCOPY_LABEL_X, ""));
|
||||
add_widget (ui->op_dlg, ui->file_label[0] = label_new (2, FCOPY_LABEL_X, ""));
|
||||
|
||||
if ((right_panel == current_panel) && !classic_progressbar)
|
||||
{
|
||||
ui->progress_file_gauge->from_left_to_right = FALSE;
|
||||
if (dialog_type == FILEGUI_DIALOG_MULTI_ITEM)
|
||||
ui->progress_total_gauge->from_left_to_right = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
file_op_context_create_ui (FileOpContext * ctx, gboolean with_eta,
|
||||
filegui_dialog_type_t dialog_type)
|
||||
{
|
||||
FileOpContextUI *ui;
|
||||
|
||||
g_return_if_fail (ctx != NULL);
|
||||
g_return_if_fail (ctx->ui == NULL);
|
||||
|
||||
file_op_context_create_ui_without_init (ctx, with_eta, dialog_type);
|
||||
ui = ctx->ui;
|
||||
|
||||
/* We will manage the dialog without any help, that's why
|
||||
we have to call init_dlg */
|
||||
init_dlg (ui->op_dlg);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
file_op_context_destroy_ui (FileOpContext * ctx)
|
||||
{
|
||||
FileOpContextUI *ui;
|
||||
|
||||
g_return_if_fail (ctx != NULL);
|
||||
|
||||
if (ctx->ui)
|
||||
{
|
||||
ui = ctx->ui;
|
||||
|
||||
dlg_run_done (ui->op_dlg);
|
||||
destroy_dlg (ui->op_dlg);
|
||||
g_free (ui);
|
||||
}
|
||||
|
||||
the_hint->widget.y = last_hint_line;
|
||||
|
||||
ctx->ui = NULL;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
show progressbar for file
|
||||
*/
|
||||
|
||||
void
|
||||
file_progress_show (FileOpContext * ctx, off_t done, off_t total,
|
||||
const char *stalled_msg, gboolean force_update)
|
||||
{
|
||||
FileOpContextUI *ui;
|
||||
char buffer[BUF_TINY];
|
||||
char buffer2[BUF_TINY];
|
||||
char buffer3[BUF_TINY];
|
||||
|
||||
g_return_if_fail (ctx != NULL);
|
||||
|
||||
if (ctx->ui == NULL)
|
||||
return;
|
||||
|
||||
ui = ctx->ui;
|
||||
|
||||
if (!verbose)
|
||||
return;
|
||||
|
||||
if (total == 0)
|
||||
{
|
||||
gauge_show (ui->progress_file_gauge, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
gauge_set_value (ui->progress_file_gauge, 1024, (int) (1024 * done / total));
|
||||
gauge_show (ui->progress_file_gauge, 1);
|
||||
|
||||
if (!force_update)
|
||||
return;
|
||||
|
||||
if (ui->showing_eta && ctx->eta_secs > 0.5)
|
||||
{
|
||||
file_eta_prepare_for_show (buffer2, ctx->eta_secs, FALSE);
|
||||
file_bps_prepare_for_show (buffer3, ctx->bps);
|
||||
g_snprintf (buffer, BUF_TINY, "%s (%s) %s", buffer2, buffer3, stalled_msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_snprintf (buffer, BUF_TINY, "%s", stalled_msg);
|
||||
}
|
||||
|
||||
label_set_text (ui->progress_file_label, buffer);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
file_progress_show_count (FileOpContext * ctx, off_t done, off_t total)
|
||||
{
|
||||
char buffer[BUF_TINY];
|
||||
FileOpContextUI *ui;
|
||||
|
||||
g_return_if_fail (ctx != NULL);
|
||||
|
||||
if (ctx->dialog_type != FILEGUI_DIALOG_MULTI_ITEM || ctx->ui == NULL)
|
||||
return;
|
||||
|
||||
ui = ctx->ui;
|
||||
|
||||
if (!verbose)
|
||||
return;
|
||||
|
||||
g_snprintf (buffer, BUF_TINY, _("Files processed: %llu of %llu"),
|
||||
(unsigned long long) done, (unsigned long long) total);
|
||||
|
||||
label_set_text (ui->total_files_processed_label, buffer);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
file_progress_show_total (FileOpTotalContext * tctx, FileOpContext * ctx, double copyed_bytes,
|
||||
gboolean need_show_total_summary)
|
||||
{
|
||||
char buffer[BUF_TINY];
|
||||
char buffer2[BUF_TINY];
|
||||
char buffer3[BUF_TINY];
|
||||
char buffer4[BUF_TINY];
|
||||
struct timeval tv_current;
|
||||
FileOpContextUI *ui;
|
||||
|
||||
if (!verbose)
|
||||
return;
|
||||
|
||||
if (ctx->dialog_type != FILEGUI_DIALOG_MULTI_ITEM || ctx->ui == NULL)
|
||||
return;
|
||||
|
||||
ui = ctx->ui;
|
||||
|
||||
if (ctx->progress_bytes > 0)
|
||||
{
|
||||
gauge_set_value (ui->progress_total_gauge, 1024,
|
||||
(int) (1024 * copyed_bytes / ctx->progress_bytes));
|
||||
gauge_show (ui->progress_total_gauge, 1);
|
||||
}
|
||||
else
|
||||
gauge_show (ui->progress_total_gauge, 0);
|
||||
|
||||
|
||||
if (!need_show_total_summary && tctx->bps == 0)
|
||||
return;
|
||||
|
||||
gettimeofday (&tv_current, NULL);
|
||||
file_frmt_time (buffer2, tv_current.tv_sec - tctx->transfer_start.tv_sec);
|
||||
file_eta_prepare_for_show (buffer3, tctx->eta_secs, TRUE);
|
||||
file_bps_prepare_for_show (buffer4, (long) tctx->bps);
|
||||
|
||||
g_snprintf (buffer, BUF_TINY, _("Time: %s %s (%s)"), buffer2, buffer3, buffer4);
|
||||
label_set_text (ui->time_label, buffer);
|
||||
|
||||
size_trunc_len (buffer2, 5, tctx->copyed_bytes, 0, panels_options.kilobyte_si);
|
||||
size_trunc_len (buffer3, 5, ctx->progress_bytes, 0, panels_options.kilobyte_si);
|
||||
|
||||
g_snprintf (buffer, BUF_TINY, _("Total: %s of %s"), buffer2, buffer3);
|
||||
|
||||
label_set_text (ui->total_bytes_label, buffer);
|
||||
|
||||
}
|
||||
|
||||
/* }}} */
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
file_progress_show_source (FileOpContext * ctx, const char *s)
|
||||
{
|
||||
FileOpContextUI *ui;
|
||||
|
||||
g_return_if_fail (ctx != NULL);
|
||||
|
||||
if (ctx->ui == NULL)
|
||||
return;
|
||||
|
||||
ui = ctx->ui;
|
||||
|
||||
if (s != NULL)
|
||||
{
|
||||
#ifdef WITH_FULL_PATHS
|
||||
int i = strlen (current_panel->cwd);
|
||||
|
||||
/* We remove the full path we have added before */
|
||||
if (!strncmp (s, current_panel->cwd, i))
|
||||
{
|
||||
if (s[i] == PATH_SEP)
|
||||
s += i + 1;
|
||||
}
|
||||
#endif /* WITH_FULL_PATHS */
|
||||
|
||||
label_set_text (ui->file_label[0], _("Source"));
|
||||
label_set_text (ui->file_string[0], truncFileString (ui, s));
|
||||
}
|
||||
else
|
||||
{
|
||||
label_set_text (ui->file_label[0], "");
|
||||
label_set_text (ui->file_string[0], "");
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
file_progress_show_target (FileOpContext * ctx, const char *s)
|
||||
{
|
||||
FileOpContextUI *ui;
|
||||
|
||||
g_return_if_fail (ctx != NULL);
|
||||
|
||||
if (ctx->ui == NULL)
|
||||
return;
|
||||
|
||||
ui = ctx->ui;
|
||||
|
||||
if (s != NULL)
|
||||
{
|
||||
label_set_text (ui->file_label[1], _("Target"));
|
||||
label_set_text (ui->file_string[1], truncFileStringSecure (ui, s));
|
||||
}
|
||||
else
|
||||
{
|
||||
label_set_text (ui->file_label[1], "");
|
||||
label_set_text (ui->file_string[1], "");
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
file_progress_show_deleting (FileOpContext * ctx, const char *s)
|
||||
{
|
||||
FileOpContextUI *ui;
|
||||
|
||||
g_return_if_fail (ctx != NULL);
|
||||
|
||||
if (ctx->ui == NULL)
|
||||
return;
|
||||
|
||||
ui = ctx->ui;
|
||||
label_set_text (ui->file_label[0], _("Deleting"));
|
||||
label_set_text (ui->file_label[0], truncFileStringSecure (ui, s));
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
FileProgressStatus
|
||||
file_progress_real_query_replace (FileOpContext * ctx,
|
||||
enum OperationMode mode, const char *destname,
|
||||
@ -882,18 +940,7 @@ file_progress_real_query_replace (FileOpContext * ctx,
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
is_wildcarded (char *p)
|
||||
{
|
||||
for (; *p; p++)
|
||||
{
|
||||
if (*p == '*')
|
||||
return TRUE;
|
||||
if (*p == '\\' && p[1] >= '1' && p[1] <= '9')
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
char *
|
||||
file_mask_dialog (FileOpContext * ctx, FileOperation operation,
|
||||
@ -1135,3 +1182,5 @@ file_mask_dialog (FileOpContext * ctx, FileOperation operation,
|
||||
|
||||
return dest_dir;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -1,39 +1,52 @@
|
||||
|
||||
/** \file filegui.h
|
||||
* \brief Header: file management GUI for the text mode edition
|
||||
*/
|
||||
|
||||
#ifndef MC_FILEGUI_H
|
||||
#define MC_FILEGUI_H
|
||||
#ifndef MC__FILEGUI_H
|
||||
#define MC__FILEGUI_H
|
||||
|
||||
#include "lib/global.h"
|
||||
#include "fileopctx.h"
|
||||
|
||||
typedef enum {
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
typedef enum
|
||||
{
|
||||
FILEGUI_DIALOG_ONE_ITEM,
|
||||
FILEGUI_DIALOG_MULTI_ITEM,
|
||||
FILEGUI_DIALOG_DELETE_ITEM
|
||||
} filegui_dialog_type_t;
|
||||
|
||||
void file_op_context_create_ui (FileOpContext *ctx, gboolean with_eta, filegui_dialog_type_t dialog_type);
|
||||
void file_op_context_create_ui_without_init (FileOpContext *ctx, gboolean with_eta, filegui_dialog_type_t dialog_type);
|
||||
void file_op_context_destroy_ui (FileOpContext *ctx);
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
void file_op_context_create_ui (FileOpContext * ctx, gboolean with_eta,
|
||||
filegui_dialog_type_t dialog_type);
|
||||
void file_op_context_create_ui_without_init (FileOpContext * ctx, gboolean with_eta,
|
||||
filegui_dialog_type_t dialog_type);
|
||||
void file_op_context_destroy_ui (FileOpContext * ctx);
|
||||
|
||||
|
||||
char *file_mask_dialog (FileOpContext *ctx, FileOperation operation,
|
||||
gboolean only_one,
|
||||
const char *format, const void *text,
|
||||
const char *def_text, gboolean *do_background);
|
||||
char *file_mask_dialog (FileOpContext * ctx, FileOperation operation,
|
||||
gboolean only_one,
|
||||
const char *format, const void *text,
|
||||
const char *def_text, gboolean * do_background);
|
||||
|
||||
FileProgressStatus check_progress_buttons (FileOpContext *ctx);
|
||||
FileProgressStatus check_progress_buttons (FileOpContext * ctx);
|
||||
|
||||
void file_progress_show (FileOpContext *ctx, off_t done, off_t total,
|
||||
const char *stalled_msg, gboolean force_update);
|
||||
void file_progress_show_count (FileOpContext *ctx, off_t done, off_t total);
|
||||
void file_progress_show_total (FileOpTotalContext *tctx, FileOpContext *ctx,
|
||||
double copyed_bytes, gboolean need_show_total_summary);
|
||||
void file_progress_show_source (FileOpContext *ctx, const char *path);
|
||||
void file_progress_show_target (FileOpContext *ctx, const char *path);
|
||||
void file_progress_show_deleting (FileOpContext *ctx, const char *path);
|
||||
void file_progress_show (FileOpContext * ctx, off_t done, off_t total,
|
||||
const char *stalled_msg, gboolean force_update);
|
||||
void file_progress_show_count (FileOpContext * ctx, off_t done, off_t total);
|
||||
void file_progress_show_total (FileOpTotalContext * tctx, FileOpContext * ctx,
|
||||
double copyed_bytes, gboolean need_show_total_summary);
|
||||
void file_progress_show_source (FileOpContext * ctx, const char *path);
|
||||
void file_progress_show_target (FileOpContext * ctx, const char *path);
|
||||
void file_progress_show_deleting (FileOpContext * ctx, const char *path);
|
||||
|
||||
#endif /* MC_FILEGUI_H */
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__FILEGUI_H */
|
||||
|
@ -4,8 +4,8 @@
|
||||
structure.
|
||||
|
||||
Author:
|
||||
Janne Kukonlehto
|
||||
Miguel de Icaza
|
||||
Janne Kukonlehto
|
||||
Miguel de Icaza
|
||||
|
||||
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
|
||||
@ -39,7 +39,16 @@
|
||||
|
||||
#include "lib/vfs/mc-vfs/vfs.h"
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static char *
|
||||
get_absolute_name (const char *file)
|
||||
@ -47,11 +56,13 @@ get_absolute_name (const char *file)
|
||||
char dir[MC_MAXPATHLEN];
|
||||
|
||||
if (file[0] == PATH_SEP)
|
||||
return g_strdup (file);
|
||||
return g_strdup (file);
|
||||
mc_get_current_wd (dir, MC_MAXPATHLEN);
|
||||
return concat_dir_and_file (dir, file);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
my_mkdir_rec (char *s, mode_t mode)
|
||||
{
|
||||
@ -59,17 +70,18 @@ my_mkdir_rec (char *s, mode_t mode)
|
||||
int result;
|
||||
|
||||
if (!mc_mkdir (s, mode))
|
||||
return 0;
|
||||
return 0;
|
||||
else if (errno != ENOENT)
|
||||
return -1;
|
||||
return -1;
|
||||
|
||||
/* FIXME: should check instead if s is at the root of that filesystem */
|
||||
if (!vfs_file_is_local (s))
|
||||
return -1;
|
||||
return -1;
|
||||
|
||||
if (!strcmp (s, PATH_SEP_STR)) {
|
||||
errno = ENOTDIR;
|
||||
return -1;
|
||||
if (!strcmp (s, PATH_SEP_STR))
|
||||
{
|
||||
errno = ENOTDIR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
p = concat_dir_and_file (s, "..");
|
||||
@ -78,12 +90,16 @@ my_mkdir_rec (char *s, mode_t mode)
|
||||
|
||||
result = my_mkdir_rec (q, mode);
|
||||
if (result == 0)
|
||||
result = mc_mkdir (s, mode);
|
||||
result = mc_mkdir (s, mode);
|
||||
|
||||
g_free (q);
|
||||
return result;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
my_mkdir (const char *s, mode_t mode)
|
||||
{
|
||||
@ -91,24 +107,28 @@ my_mkdir (const char *s, mode_t mode)
|
||||
char *my_s;
|
||||
|
||||
result = mc_mkdir (s, mode);
|
||||
if (result) {
|
||||
char *p = vfs_canon (s);
|
||||
if (result)
|
||||
{
|
||||
char *p = vfs_canon (s);
|
||||
|
||||
result = my_mkdir_rec (p, mode);
|
||||
g_free (p);
|
||||
result = my_mkdir_rec (p, mode);
|
||||
g_free (p);
|
||||
}
|
||||
if (result == 0) {
|
||||
my_s = get_absolute_name (s);
|
||||
if (result == 0)
|
||||
{
|
||||
my_s = get_absolute_name (s);
|
||||
|
||||
#ifdef FIXME
|
||||
tree_add_entry (tree, my_s);
|
||||
tree_add_entry (tree, my_s);
|
||||
#endif
|
||||
|
||||
g_free (my_s);
|
||||
g_free (my_s);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
my_rmdir (const char *s)
|
||||
{
|
||||
@ -120,14 +140,17 @@ my_rmdir (const char *s)
|
||||
|
||||
/* FIXME: Should receive a Wtree! */
|
||||
result = mc_rmdir (s);
|
||||
if (result == 0) {
|
||||
my_s = get_absolute_name (s);
|
||||
if (result == 0)
|
||||
{
|
||||
my_s = get_absolute_name (s);
|
||||
|
||||
#ifdef FIXME
|
||||
tree_remove_entry (tree, my_s);
|
||||
tree_remove_entry (tree, my_s);
|
||||
#endif
|
||||
|
||||
g_free (my_s);
|
||||
g_free (my_s);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -38,6 +38,21 @@
|
||||
#include "lib/search.h"
|
||||
#include "lib/vfs/mc-vfs/vfs.h"
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* \fn FileOpContext * file_op_context_new (FileOperation op)
|
||||
* \param op file operation struct
|
||||
@ -46,6 +61,7 @@
|
||||
* Creates a new file operation context with the default values. If you later want
|
||||
* to have a user interface for this, call file_op_context_create_ui().
|
||||
*/
|
||||
|
||||
FileOpContext *
|
||||
file_op_context_new (FileOperation op)
|
||||
{
|
||||
@ -66,7 +82,7 @@ file_op_context_new (FileOperation op)
|
||||
return ctx;
|
||||
}
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* \fn void file_op_context_destroy (FileOpContext *ctx)
|
||||
* \param ctx The file operation context to destroy.
|
||||
@ -74,6 +90,7 @@ file_op_context_new (FileOperation op)
|
||||
* Destroys the specified file operation context and its associated UI data, if
|
||||
* it exists.
|
||||
*/
|
||||
|
||||
void
|
||||
file_op_context_destroy (FileOpContext * ctx)
|
||||
{
|
||||
@ -89,6 +106,8 @@ file_op_context_destroy (FileOpContext * ctx)
|
||||
g_free (ctx);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
FileOpTotalContext *
|
||||
file_op_total_context_new (void)
|
||||
{
|
||||
@ -99,9 +118,13 @@ file_op_total_context_new (void)
|
||||
return tctx;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
file_op_total_context_destroy (FileOpTotalContext * tctx)
|
||||
{
|
||||
g_return_if_fail (tctx != NULL);
|
||||
g_free (tctx);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
294
src/fileopctx.h
294
src/fileopctx.h
@ -1,4 +1,3 @@
|
||||
|
||||
/** \file fileopctx.h
|
||||
* \brief Header: file operation contexts
|
||||
* \date 1998
|
||||
@ -12,8 +11,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef FILEOPCTX_H
|
||||
#define FILEOPCTX_H
|
||||
#ifndef MC__FILEOPCTX_H
|
||||
#define MC__FILEOPCTX_H
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
@ -21,156 +20,169 @@
|
||||
|
||||
#include "lib/global.h"
|
||||
|
||||
struct mc_search_struct;
|
||||
|
||||
typedef enum {
|
||||
OP_COPY = 0,
|
||||
OP_MOVE = 1,
|
||||
OP_DELETE = 2
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
typedef int (*mc_stat_fn) (const char *filename, struct stat * buf);
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
typedef enum
|
||||
{
|
||||
OP_COPY = 0,
|
||||
OP_MOVE = 1,
|
||||
OP_DELETE = 2
|
||||
} FileOperation;
|
||||
|
||||
typedef enum {
|
||||
RECURSIVE_YES = 0,
|
||||
RECURSIVE_NO = 1,
|
||||
typedef enum
|
||||
{
|
||||
RECURSIVE_YES = 0,
|
||||
RECURSIVE_NO = 1,
|
||||
RECURSIVE_ALWAYS = 2,
|
||||
RECURSIVE_NEVER = 3,
|
||||
RECURSIVE_ABORT = 4
|
||||
RECURSIVE_NEVER = 3,
|
||||
RECURSIVE_ABORT = 4
|
||||
} FileCopyMode;
|
||||
|
||||
typedef int (*mc_stat_fn) (const char *filename, struct stat *buf);
|
||||
|
||||
/* This structure describes a context for file operations. It is used to update
|
||||
* the progress windows and pass around options.
|
||||
*/
|
||||
typedef struct FileOpContext {
|
||||
/* Operation type (copy, move, delete) */
|
||||
FileOperation operation;
|
||||
|
||||
/* The estimated time of arrival in seconds */
|
||||
double eta_secs;
|
||||
|
||||
/* Transferred bytes per second */
|
||||
long bps;
|
||||
|
||||
/* Transferred seconds */
|
||||
long bps_time;
|
||||
|
||||
/* Whether the panel total has been computed */
|
||||
gboolean progress_totals_computed;
|
||||
int dialog_type;
|
||||
|
||||
/* Counters for progress indicators */
|
||||
off_t progress_count;
|
||||
double progress_bytes;
|
||||
|
||||
/* The value of the "preserve Attributes" checkbox in the copy file dialog.
|
||||
* We can't use the value of "ctx->preserve" because it can change in order
|
||||
* to preserve file attributs when moving files across filesystem boundaries
|
||||
* (we want to keep the value of the checkbox between copy operations).
|
||||
*/
|
||||
gboolean op_preserve;
|
||||
|
||||
/* Result from the recursive query */
|
||||
FileCopyMode recursive_result;
|
||||
|
||||
/* Whether to do a reget */
|
||||
off_t do_reget;
|
||||
|
||||
/* Controls appending to files */
|
||||
gboolean do_append;
|
||||
|
||||
/* Whether to stat or lstat */
|
||||
gboolean follow_links;
|
||||
|
||||
/* Pointer to the stat function we will use */
|
||||
mc_stat_fn stat_func;
|
||||
|
||||
/* Whether to recompute symlinks */
|
||||
gboolean stable_symlinks;
|
||||
|
||||
/* Preserve the original files' owner, group, permissions, and
|
||||
* timestamps (owner, group only as root).
|
||||
*/
|
||||
int preserve;
|
||||
|
||||
/* If running as root, preserve the original uid/gid (we don't want to
|
||||
* try chown for non root) preserve_uidgid = preserve && uid == 0
|
||||
*/
|
||||
gboolean preserve_uidgid;
|
||||
|
||||
/* The bits to preserve in created files' modes on file copy */
|
||||
int umask_kill;
|
||||
|
||||
/* The mask of files to actually operate on */
|
||||
char *dest_mask;
|
||||
|
||||
/* search handler */
|
||||
struct mc_search_struct *search_handle;
|
||||
|
||||
/* Whether to dive into subdirectories for recursive operations */
|
||||
int dive_into_subdirs;
|
||||
|
||||
/* When moving directories cross filesystem boundaries delete the
|
||||
* successfully copied files when all files below the directory and its
|
||||
* subdirectories were processed.
|
||||
*
|
||||
* If erase_at_end is FALSE files will be deleted immediately after their
|
||||
* successful copy (Note: this behavior is not tested and at the moment
|
||||
* it can't be changed at runtime).
|
||||
*/
|
||||
gboolean erase_at_end;
|
||||
|
||||
/* PID of the child for background operations */
|
||||
pid_t pid;
|
||||
|
||||
/* User interface data goes here */
|
||||
void *ui;
|
||||
} FileOpContext;
|
||||
|
||||
typedef struct {
|
||||
off_t progress_count;
|
||||
double progress_bytes;
|
||||
double copyed_bytes;
|
||||
size_t bps;
|
||||
size_t bps_count;
|
||||
struct timeval transfer_start;
|
||||
double eta_secs;
|
||||
|
||||
gboolean ask_overwrite;
|
||||
gboolean is_toplevel_file;
|
||||
|
||||
} FileOpTotalContext;
|
||||
|
||||
|
||||
FileOpContext *file_op_context_new (FileOperation op);
|
||||
void file_op_context_destroy (FileOpContext *ctx);
|
||||
|
||||
FileOpTotalContext *file_op_total_context_new (void);
|
||||
void file_op_total_context_destroy (FileOpTotalContext *tctx);
|
||||
|
||||
|
||||
extern const char *op_names [3];
|
||||
|
||||
typedef enum {
|
||||
FILE_CONT = 0,
|
||||
FILE_RETRY = 1,
|
||||
FILE_SKIP = 2,
|
||||
FILE_ABORT = 3
|
||||
typedef enum
|
||||
{
|
||||
FILE_CONT = 0,
|
||||
FILE_RETRY = 1,
|
||||
FILE_SKIP = 2,
|
||||
FILE_ABORT = 3
|
||||
} FileProgressStatus;
|
||||
|
||||
/* First argument passed to real functions */
|
||||
enum OperationMode {
|
||||
enum OperationMode
|
||||
{
|
||||
Foreground,
|
||||
Background
|
||||
};
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
struct mc_search_struct;
|
||||
|
||||
/* This structure describes a context for file operations. It is used to update
|
||||
* the progress windows and pass around options.
|
||||
*/
|
||||
typedef struct FileOpContext
|
||||
{
|
||||
/* Operation type (copy, move, delete) */
|
||||
FileOperation operation;
|
||||
|
||||
/* The estimated time of arrival in seconds */
|
||||
double eta_secs;
|
||||
|
||||
/* Transferred bytes per second */
|
||||
long bps;
|
||||
|
||||
/* Transferred seconds */
|
||||
long bps_time;
|
||||
|
||||
/* Whether the panel total has been computed */
|
||||
gboolean progress_totals_computed;
|
||||
int dialog_type;
|
||||
|
||||
/* Counters for progress indicators */
|
||||
off_t progress_count;
|
||||
double progress_bytes;
|
||||
|
||||
/* The value of the "preserve Attributes" checkbox in the copy file dialog.
|
||||
* We can't use the value of "ctx->preserve" because it can change in order
|
||||
* to preserve file attributs when moving files across filesystem boundaries
|
||||
* (we want to keep the value of the checkbox between copy operations).
|
||||
*/
|
||||
gboolean op_preserve;
|
||||
|
||||
/* Result from the recursive query */
|
||||
FileCopyMode recursive_result;
|
||||
|
||||
/* Whether to do a reget */
|
||||
off_t do_reget;
|
||||
|
||||
/* Controls appending to files */
|
||||
gboolean do_append;
|
||||
|
||||
/* Whether to stat or lstat */
|
||||
gboolean follow_links;
|
||||
|
||||
/* Pointer to the stat function we will use */
|
||||
mc_stat_fn stat_func;
|
||||
|
||||
/* Whether to recompute symlinks */
|
||||
gboolean stable_symlinks;
|
||||
|
||||
/* Preserve the original files' owner, group, permissions, and
|
||||
* timestamps (owner, group only as root).
|
||||
*/
|
||||
int preserve;
|
||||
|
||||
/* If running as root, preserve the original uid/gid (we don't want to
|
||||
* try chown for non root) preserve_uidgid = preserve && uid == 0
|
||||
*/
|
||||
gboolean preserve_uidgid;
|
||||
|
||||
/* The bits to preserve in created files' modes on file copy */
|
||||
int umask_kill;
|
||||
|
||||
/* The mask of files to actually operate on */
|
||||
char *dest_mask;
|
||||
|
||||
/* search handler */
|
||||
struct mc_search_struct *search_handle;
|
||||
|
||||
/* Whether to dive into subdirectories for recursive operations */
|
||||
int dive_into_subdirs;
|
||||
|
||||
/* When moving directories cross filesystem boundaries delete the
|
||||
* successfully copied files when all files below the directory and its
|
||||
* subdirectories were processed.
|
||||
*
|
||||
* If erase_at_end is FALSE files will be deleted immediately after their
|
||||
* successful copy (Note: this behavior is not tested and at the moment
|
||||
* it can't be changed at runtime).
|
||||
*/
|
||||
gboolean erase_at_end;
|
||||
|
||||
/* PID of the child for background operations */
|
||||
pid_t pid;
|
||||
|
||||
/* User interface data goes here */
|
||||
void *ui;
|
||||
} FileOpContext;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
off_t progress_count;
|
||||
double progress_bytes;
|
||||
double copyed_bytes;
|
||||
size_t bps;
|
||||
size_t bps_count;
|
||||
struct timeval transfer_start;
|
||||
double eta_secs;
|
||||
|
||||
gboolean ask_overwrite;
|
||||
gboolean is_toplevel_file;
|
||||
|
||||
} FileOpTotalContext;
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
extern const char *op_names[3];
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
FileOpContext *file_op_context_new (FileOperation op);
|
||||
void file_op_context_destroy (FileOpContext * ctx);
|
||||
|
||||
FileOpTotalContext *file_op_total_context_new (void);
|
||||
void file_op_total_context_destroy (FileOpTotalContext * tctx);
|
||||
|
||||
/* The following functions are implemented separately by each port */
|
||||
FileProgressStatus file_progress_real_query_replace (FileOpContext * ctx,
|
||||
enum OperationMode mode,
|
||||
const char *destname,
|
||||
struct stat *_s_stat, struct stat *_d_stat);
|
||||
|
||||
FileProgressStatus file_progress_real_query_replace (FileOpContext *ctx,
|
||||
enum OperationMode mode,
|
||||
const char *destname,
|
||||
struct stat *_s_stat,
|
||||
struct stat *_d_stat);
|
||||
|
||||
|
||||
#endif
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__FILEOPCTX_H */
|
||||
|
170
src/find.c
170
src/find.c
@ -57,20 +57,20 @@
|
||||
|
||||
#include "find.h"
|
||||
|
||||
/* Size of the find parameters window */
|
||||
#if HAVE_CHARSET
|
||||
static int FIND_Y = 17;
|
||||
#else
|
||||
static int FIND_Y = 16;
|
||||
#endif
|
||||
static int FIND_X = 68;
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
/* List of directories to be ignored, separated by ':' */
|
||||
char **find_ignore_dirs = NULL;
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
/* Size of the find window */
|
||||
#define FIND2_Y (LINES - 4)
|
||||
|
||||
static int FIND2_X = 64;
|
||||
#define FIND2_X_USE (FIND2_X - 20)
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
/* A couple of extra messages we need */
|
||||
enum
|
||||
{
|
||||
@ -88,8 +88,36 @@ typedef enum
|
||||
FIND_ABORT
|
||||
} FindProgressStatus;
|
||||
|
||||
/* List of directories to be ignored, separated by ':' */
|
||||
char **find_ignore_dirs = NULL;
|
||||
/* find file options */
|
||||
typedef struct
|
||||
{
|
||||
/* file name options */
|
||||
gboolean file_case_sens;
|
||||
gboolean file_pattern;
|
||||
gboolean find_recurs;
|
||||
gboolean skip_hidden;
|
||||
gboolean file_all_charsets;
|
||||
|
||||
/* file content options */
|
||||
gboolean content_use;
|
||||
gboolean content_case_sens;
|
||||
gboolean content_regexp;
|
||||
gboolean content_first_hit;
|
||||
gboolean content_whole_words;
|
||||
gboolean content_all_charsets;
|
||||
} find_file_options_t;
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
/* Size of the find parameters window */
|
||||
#if HAVE_CHARSET
|
||||
static int FIND_Y = 17;
|
||||
#else
|
||||
static int FIND_Y = 16;
|
||||
#endif
|
||||
static int FIND_X = 68;
|
||||
|
||||
static int FIND2_X = 64;
|
||||
|
||||
/* static variables to remember find parameters */
|
||||
static WInput *in_start; /* Start path */
|
||||
@ -162,25 +190,6 @@ static struct
|
||||
};
|
||||
/* *INDENT-ON* */
|
||||
|
||||
/* find file options */
|
||||
typedef struct
|
||||
{
|
||||
/* file name options */
|
||||
gboolean file_case_sens;
|
||||
gboolean file_pattern;
|
||||
gboolean find_recurs;
|
||||
gboolean skip_hidden;
|
||||
gboolean file_all_charsets;
|
||||
|
||||
/* file content options */
|
||||
gboolean content_use;
|
||||
gboolean content_case_sens;
|
||||
gboolean content_regexp;
|
||||
gboolean content_first_hit;
|
||||
gboolean content_whole_words;
|
||||
gboolean content_all_charsets;
|
||||
} find_file_options_t;
|
||||
|
||||
static find_file_options_t options = {
|
||||
TRUE, TRUE, TRUE, FALSE, FALSE,
|
||||
FALSE, TRUE, FALSE, FALSE, FALSE, FALSE
|
||||
@ -191,12 +200,16 @@ static char *in_start_dir = INPUT_LAST_TEXT;
|
||||
static mc_search_t *search_file_handle = NULL;
|
||||
static mc_search_t *search_content_handle = NULL;
|
||||
|
||||
/*** file scope functions ************************************************************************/
|
||||
|
||||
static int
|
||||
find_ignore_dirs_cmp (const void *d1, const void *d2)
|
||||
{
|
||||
return strcmp (*(const char **) d1, *(const char **) d2);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
find_load_options (void)
|
||||
{
|
||||
@ -287,6 +300,8 @@ find_load_options (void)
|
||||
mc_config_get_bool (mc_main_config, "FindFile", "content_all_charsets", FALSE);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
find_save_options (void)
|
||||
{
|
||||
@ -305,24 +320,32 @@ find_save_options (void)
|
||||
options.content_all_charsets);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static inline char *
|
||||
add_to_list (const char *text, void *data)
|
||||
{
|
||||
return listbox_add_item (find_list, LISTBOX_APPEND_AT_END, 0, text, data);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static inline void
|
||||
stop_idle (void *data)
|
||||
{
|
||||
set_idle_proc (data, 0);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static inline void
|
||||
status_update (const char *text)
|
||||
{
|
||||
label_set_text (status_label, text);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
found_num_update (void)
|
||||
{
|
||||
@ -331,13 +354,17 @@ found_num_update (void)
|
||||
label_set_text (found_num_label, buffer);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
get_list_info (char **file, char **dir)
|
||||
{
|
||||
listbox_get_current (find_list, file, (void **) dir);
|
||||
}
|
||||
|
||||
/* check regular expression */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** check regular expression */
|
||||
|
||||
static gboolean
|
||||
find_check_regexp (const char *r)
|
||||
{
|
||||
@ -356,10 +383,12 @@ find_check_regexp (const char *r)
|
||||
return regexp_ok;
|
||||
}
|
||||
|
||||
/*
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Callback for the parameter dialog.
|
||||
* Validate regex, prevent closing the dialog if it's invalid.
|
||||
*/
|
||||
|
||||
static cb_ret_t
|
||||
find_parm_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
|
||||
{
|
||||
@ -424,7 +453,8 @@ find_parm_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* find_parameters: gets information from the user
|
||||
*
|
||||
* If the return value is TRUE, then the following holds:
|
||||
@ -437,6 +467,7 @@ find_parm_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void
|
||||
* behavior for the other two parameters.
|
||||
*
|
||||
*/
|
||||
|
||||
static gboolean
|
||||
find_parameters (char **start_dir, char **pattern, char **content)
|
||||
{
|
||||
@ -659,21 +690,26 @@ find_parameters (char **start_dir, char **pattern, char **content)
|
||||
return return_value;
|
||||
}
|
||||
|
||||
#if GLIB_CHECK_VERSION (2, 14, 0)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
#if GLIB_CHECK_VERSION (2, 14, 0)
|
||||
static inline void
|
||||
push_directory (const char *dir)
|
||||
{
|
||||
g_queue_push_head (&dir_queue, (void *) dir);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static inline char *
|
||||
pop_directory (void)
|
||||
{
|
||||
return (char *) g_queue_pop_tail (&dir_queue);
|
||||
}
|
||||
|
||||
/* Remove all the items from the stack */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Remove all the items from the stack */
|
||||
|
||||
static void
|
||||
clear_stack (void)
|
||||
{
|
||||
@ -681,8 +717,9 @@ clear_stack (void)
|
||||
g_queue_clear (&dir_queue);
|
||||
}
|
||||
|
||||
#else /* GLIB_CHECK_VERSION */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
#else /* GLIB_CHECK_VERSION */
|
||||
static void
|
||||
push_directory (const char *dir)
|
||||
{
|
||||
@ -694,6 +731,8 @@ push_directory (const char *dir)
|
||||
dir_stack_base = new;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static char *
|
||||
pop_directory (void)
|
||||
{
|
||||
@ -711,7 +750,9 @@ pop_directory (void)
|
||||
return name;
|
||||
}
|
||||
|
||||
/* Remove all the items from the stack */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Remove all the items from the stack */
|
||||
|
||||
static void
|
||||
clear_stack (void)
|
||||
{
|
||||
@ -719,9 +760,10 @@ clear_stack (void)
|
||||
while ((dir = pop_directory ()) != NULL)
|
||||
g_free (dir);
|
||||
}
|
||||
|
||||
#endif /* GLIB_CHECK_VERSION */
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
insert_file (const char *dir, const char *file)
|
||||
{
|
||||
@ -751,6 +793,8 @@ insert_file (const char *dir, const char *file)
|
||||
g_free (tmp_name);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
find_add_match (const char *dir, const char *file)
|
||||
{
|
||||
@ -765,7 +809,8 @@ find_add_match (const char *dir, const char *file)
|
||||
found_num_update ();
|
||||
}
|
||||
|
||||
/*
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* get_line_at:
|
||||
*
|
||||
* Returns malloced null-terminated line from file file_fd.
|
||||
@ -774,6 +819,7 @@ find_add_match (const char *dir, const char *file)
|
||||
* n_read - number of read chars.
|
||||
* has_newline - is there newline ?
|
||||
*/
|
||||
|
||||
static char *
|
||||
get_line_at (int file_fd, char *buf, int buf_size, int *pos, int *n_read, gboolean * has_newline)
|
||||
{
|
||||
@ -819,6 +865,8 @@ get_line_at (int file_fd, char *buf, int buf_size, int *pos, int *n_read, gboole
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static FindProgressStatus
|
||||
check_find_events (Dlg_head * h)
|
||||
{
|
||||
@ -846,7 +894,8 @@ check_find_events (Dlg_head * h)
|
||||
return FIND_CONT;
|
||||
}
|
||||
|
||||
/*
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* search_content:
|
||||
*
|
||||
* Search the content_pattern string in the DIRECTORY/FILE.
|
||||
@ -855,6 +904,7 @@ check_find_events (Dlg_head * h)
|
||||
* returns FALSE if do_search should look for another file
|
||||
* TRUE if do_search should exit and proceed to the event handler
|
||||
*/
|
||||
|
||||
static gboolean
|
||||
search_content (Dlg_head * h, const char *directory, const char *filename)
|
||||
{
|
||||
@ -953,6 +1003,8 @@ search_content (Dlg_head * h, const char *directory, const char *filename)
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static inline gboolean
|
||||
find_ignore_dir_search (const char *dir)
|
||||
{
|
||||
@ -981,6 +1033,8 @@ find_ignore_dir_search (const char *dir)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
find_rotate_dash (const Dlg_head *h, gboolean finish)
|
||||
{
|
||||
@ -997,6 +1051,8 @@ find_rotate_dash (const Dlg_head *h, gboolean finish)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
do_search (Dlg_head *h)
|
||||
{
|
||||
@ -1129,6 +1185,8 @@ do_search (Dlg_head *h)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
init_find_vars (void)
|
||||
{
|
||||
@ -1140,6 +1198,8 @@ init_find_vars (void)
|
||||
clear_stack ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static char *
|
||||
make_fullname (const char *dirname, const char *filename)
|
||||
{
|
||||
@ -1151,6 +1211,8 @@ make_fullname (const char *dirname, const char *filename)
|
||||
return concat_dir_and_file (dirname, filename);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
find_do_view_edit (int unparsed_view, int edit, char *dir, char *file)
|
||||
{
|
||||
@ -1177,6 +1239,8 @@ find_do_view_edit (int unparsed_view, int edit, char *dir, char *file)
|
||||
g_free (fullname);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static cb_ret_t
|
||||
view_edit_currently_selected_file (int unparsed_view, int edit)
|
||||
{
|
||||
@ -1192,6 +1256,8 @@ view_edit_currently_selected_file (int unparsed_view, int edit)
|
||||
return MSG_HANDLED;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static cb_ret_t
|
||||
find_callback (Dlg_head *h, Widget * sender, dlg_msg_t msg, int parm, void *data)
|
||||
{
|
||||
@ -1218,7 +1284,9 @@ find_callback (Dlg_head *h, Widget * sender, dlg_msg_t msg, int parm, void *data
|
||||
}
|
||||
}
|
||||
|
||||
/* Handles the Stop/Start button in the find window */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Handles the Stop/Start button in the find window */
|
||||
|
||||
static int
|
||||
start_stop (WButton * button, int action)
|
||||
{
|
||||
@ -1235,7 +1303,9 @@ start_stop (WButton * button, int action)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Handle view command, when invoked as a button */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Handle view command, when invoked as a button */
|
||||
|
||||
static int
|
||||
find_do_view_file (WButton * button, int action)
|
||||
{
|
||||
@ -1246,7 +1316,9 @@ find_do_view_file (WButton * button, int action)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Handle edit command, when invoked as a button */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Handle edit command, when invoked as a button */
|
||||
|
||||
static int
|
||||
find_do_edit_file (WButton * button, int action)
|
||||
{
|
||||
@ -1257,6 +1329,8 @@ find_do_edit_file (WButton * button, int action)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
setup_gui (void)
|
||||
{
|
||||
@ -1340,6 +1414,8 @@ setup_gui (void)
|
||||
add_widget (find_dlg, find_list);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
run_process (void)
|
||||
{
|
||||
@ -1372,6 +1448,8 @@ run_process (void)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
kill_gui (void)
|
||||
{
|
||||
@ -1379,6 +1457,8 @@ kill_gui (void)
|
||||
destroy_dlg (find_dlg);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
find_file (const char *start_dir, const char *pattern, const char *content,
|
||||
char **dirname, char **filename)
|
||||
@ -1493,6 +1573,10 @@ find_file (const char *start_dir, const char *pattern, const char *content,
|
||||
return return_value;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
do_find (void)
|
||||
{
|
||||
@ -1549,3 +1633,5 @@ do_find (void)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
18
src/find.h
18
src/find.h
@ -1,11 +1,21 @@
|
||||
|
||||
/** \file find.h
|
||||
* \brief Header: Find file command
|
||||
*/
|
||||
|
||||
#ifndef MC_FIND_H
|
||||
#define MC_FIND_H
|
||||
#ifndef MC__FIND_H
|
||||
#define MC__FIND_H
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
void do_find (void);
|
||||
|
||||
#endif
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__FIND_H */
|
||||
|
116
src/help.c
116
src/help.c
@ -67,6 +67,10 @@
|
||||
#include "help.h"
|
||||
#include "main.h"
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
#define MAXLINKNAME 80
|
||||
#define HISTORY_SIZE 20
|
||||
#define HELP_WINDOW_WIDTH min(80, COLS - 16)
|
||||
@ -76,6 +80,16 @@
|
||||
#define STRING_LINK_END "\03"
|
||||
#define STRING_NODE_END "\04"
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
/* Link areas for the mouse */
|
||||
typedef struct Link_Area
|
||||
{
|
||||
int x1, y1, x2, y2;
|
||||
const char *link_name;
|
||||
} Link_Area;
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
static char *fdata = NULL; /* Pointer to the loaded data file */
|
||||
static int help_lines; /* Lines in help viewer */
|
||||
@ -95,20 +109,17 @@ static struct
|
||||
const char *link; /* Pointer to the selected link */
|
||||
} history[HISTORY_SIZE];
|
||||
|
||||
/* Link areas for the mouse */
|
||||
typedef struct Link_Area
|
||||
{
|
||||
int x1, y1, x2, y2;
|
||||
const char *link_name;
|
||||
} Link_Area;
|
||||
|
||||
static GSList *link_area = NULL;
|
||||
static gboolean inside_link_area = FALSE;
|
||||
|
||||
static cb_ret_t help_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data);
|
||||
|
||||
/* returns the position where text was found in the start buffer */
|
||||
/* or 0 if not found */
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/** returns the position where text was found in the start buffer
|
||||
* or 0 if not found
|
||||
*/
|
||||
static const char *
|
||||
search_string (const char *start, const char *text)
|
||||
{
|
||||
@ -144,8 +155,12 @@ search_string (const char *start, const char *text)
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Searches text in the buffer pointed by start. Search ends */
|
||||
/* if the CHAR_NODE_END is found in the text. Returns 0 on failure */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Searches text in the buffer pointed by start. Search ends
|
||||
* if the CHAR_NODE_END is found in the text.
|
||||
* @returns 0 on failure
|
||||
*/
|
||||
|
||||
static const char *
|
||||
search_string_node (const char *start, const char *text)
|
||||
{
|
||||
@ -166,8 +181,11 @@ search_string_node (const char *start, const char *text)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Searches the_char in the buffer pointer by start and searches */
|
||||
/* it can search forward (direction = 1) or backward (direction = -1) */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Searches the_char in the buffer pointer by start and searches
|
||||
* it can search forward (direction = 1) or backward (direction = -1)
|
||||
*/
|
||||
|
||||
static const char *
|
||||
search_char_node (const char *start, char the_char, int direction)
|
||||
{
|
||||
@ -180,7 +198,9 @@ search_char_node (const char *start, char the_char, int direction)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Returns the new current pointer when moved lines lines */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Returns the new current pointer when moved lines lines */
|
||||
|
||||
static const char *
|
||||
move_forward2 (const char *c, int lines)
|
||||
{
|
||||
@ -199,6 +219,8 @@ move_forward2 (const char *c, int lines)
|
||||
return currentpoint = c;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static const char *
|
||||
move_backward2 (const char *c, int lines)
|
||||
{
|
||||
@ -225,6 +247,8 @@ move_backward2 (const char *c, int lines)
|
||||
return currentpoint = c;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
move_forward (int i)
|
||||
{
|
||||
@ -232,12 +256,16 @@ move_forward (int i)
|
||||
currentpoint = move_forward2 (currentpoint, i);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
move_backward (int i)
|
||||
{
|
||||
currentpoint = move_backward2 (currentpoint, ++i);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
move_to_top (void)
|
||||
{
|
||||
@ -250,6 +278,8 @@ move_to_top (void)
|
||||
selected_item = NULL;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
move_to_bottom (void)
|
||||
{
|
||||
@ -259,6 +289,8 @@ move_to_bottom (void)
|
||||
move_backward (1);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static const char *
|
||||
help_follow_link (const char *start, const char *lc_selected_item)
|
||||
{
|
||||
@ -290,6 +322,8 @@ help_follow_link (const char *start, const char *lc_selected_item)
|
||||
return _("Help file format error\n");
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static const char *
|
||||
select_next_link (const char *current_link)
|
||||
{
|
||||
@ -307,12 +341,16 @@ select_next_link (const char *current_link)
|
||||
return p - 1;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static const char *
|
||||
select_prev_link (const char *current_link)
|
||||
{
|
||||
return current_link == NULL ? NULL : search_char_node (current_link - 1, CHAR_LINK_START, -1);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
start_link_area (int x, int y, const char *link_name)
|
||||
{
|
||||
@ -333,6 +371,8 @@ start_link_area (int x, int y, const char *link_name)
|
||||
inside_link_area = TRUE;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
end_link_area (int x, int y)
|
||||
{
|
||||
@ -346,6 +386,8 @@ end_link_area (int x, int y)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
clear_link_areas (void)
|
||||
{
|
||||
@ -355,6 +397,8 @@ clear_link_areas (void)
|
||||
inside_link_area = FALSE;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
help_print_word (Dlg_head * h, GString * word, int *col, int *line, gboolean add_space)
|
||||
{
|
||||
@ -397,6 +441,8 @@ help_print_word (Dlg_head * h, GString * word, int *col, int *line, gboolean add
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
help_show (Dlg_head * h, const char *paint_start)
|
||||
{
|
||||
@ -549,6 +595,8 @@ help_show (Dlg_head * h, const char *paint_start)
|
||||
dlg_move (h, active_line, active_col);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
help_event (Gpm_Event * event, void *vp)
|
||||
{
|
||||
@ -621,7 +669,9 @@ help_event (Gpm_Event * event, void *vp)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* show help */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** show help */
|
||||
|
||||
static void
|
||||
help_help (Dlg_head * h)
|
||||
{
|
||||
@ -640,6 +690,8 @@ help_help (Dlg_head * h)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
help_index (Dlg_head * h)
|
||||
{
|
||||
@ -661,6 +713,8 @@ help_index (Dlg_head * h)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
help_back (Dlg_head * h)
|
||||
{
|
||||
@ -673,6 +727,8 @@ help_back (Dlg_head * h)
|
||||
help_callback (h, NULL, DLG_DRAW, 0, NULL); /* FIXME: unneeded? */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
help_next_link (gboolean move_down)
|
||||
{
|
||||
@ -696,6 +752,8 @@ help_next_link (gboolean move_down)
|
||||
selected_item = NULL;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
help_prev_link (gboolean move_up)
|
||||
{
|
||||
@ -714,6 +772,8 @@ help_prev_link (gboolean move_up)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
help_next_node (void)
|
||||
{
|
||||
@ -733,6 +793,8 @@ help_next_node (void)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
help_prev_node (void)
|
||||
{
|
||||
@ -750,6 +812,8 @@ help_prev_node (void)
|
||||
selected_item = NULL;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
help_select_link (void)
|
||||
{
|
||||
@ -781,6 +845,8 @@ help_select_link (void)
|
||||
selected_item = NULL;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static cb_ret_t
|
||||
help_execute_cmd (unsigned long command)
|
||||
{
|
||||
@ -846,6 +912,8 @@ help_execute_cmd (unsigned long command)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static cb_ret_t
|
||||
help_handle_key (Dlg_head * h, int c)
|
||||
{
|
||||
@ -859,6 +927,8 @@ help_handle_key (Dlg_head * h, int c)
|
||||
return MSG_HANDLED;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static cb_ret_t
|
||||
help_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
|
||||
{
|
||||
@ -890,13 +960,17 @@ help_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *dat
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
interactive_display_finish (void)
|
||||
{
|
||||
clear_link_areas ();
|
||||
}
|
||||
|
||||
/* translate help file into terminal encoding */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** translate help file into terminal encoding */
|
||||
|
||||
static void
|
||||
translate_file (char *filedata)
|
||||
{
|
||||
@ -925,6 +999,8 @@ translate_file (char *filedata)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static cb_ret_t
|
||||
md_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
{
|
||||
@ -939,6 +1015,8 @@ md_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static Widget *
|
||||
mousedispatch_new (int y, int x, int yl, int xl)
|
||||
{
|
||||
@ -947,6 +1025,10 @@ mousedispatch_new (int y, int x, int yl, int xl)
|
||||
return w;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
interactive_display (const char *filename, const char *node)
|
||||
{
|
||||
@ -1043,3 +1125,5 @@ interactive_display (const char *filename, const char *node)
|
||||
interactive_display_finish ();
|
||||
destroy_dlg (whelp);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
18
src/help.h
18
src/help.h
@ -1,4 +1,3 @@
|
||||
|
||||
/** \file help.h
|
||||
* \brief Header: hypertext file browser
|
||||
*
|
||||
@ -26,8 +25,10 @@
|
||||
* This file is included by help.c and man2hlp.c
|
||||
*/
|
||||
|
||||
#ifndef MC_HELP_H
|
||||
#define MC_HELP_H
|
||||
#ifndef MC__HELP_H
|
||||
#define MC__HELP_H
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/* Markers used in the help files */
|
||||
#define CHAR_LINK_START '\01' /* Ctrl-A */
|
||||
@ -41,6 +42,15 @@
|
||||
#define CHAR_FONT_NORMAL '\013' /* Ctrl-K */
|
||||
#define CHAR_FONT_ITALIC '\024' /* Ctrl-T */
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
void interactive_display (const char *filename, const char *node);
|
||||
|
||||
#endif /* MC_HELP_H */
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__HELP_H */
|
||||
|
@ -1,10 +1,11 @@
|
||||
|
||||
/** \file history.h
|
||||
* \brief Header: defines history section names
|
||||
*/
|
||||
|
||||
#ifndef MC_HISTORY_H
|
||||
#define MC_HISTORY_H
|
||||
#ifndef MC__HISTORY_H
|
||||
#define MC__HISTORY_H
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/* history section names */
|
||||
|
||||
@ -45,4 +46,14 @@
|
||||
|
||||
#define MC_HISTORY_YDIFF_GOTO_LINE "mc.ydiff.goto-line"
|
||||
|
||||
#endif /* MC_HISTORY_H */
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
|
||||
#endif /* MC__HISTORY_H */
|
||||
|
367
src/hotlist.c
367
src/hotlist.c
@ -61,6 +61,12 @@
|
||||
#include "command.h" /* cmdline */
|
||||
#include "history.h"
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
int hotlist_has_dot_dot = 1;
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
#define UX 5
|
||||
#define UY 2
|
||||
|
||||
@ -83,15 +89,49 @@
|
||||
#define B_REFRESH_VFS (B_USER + 9)
|
||||
#endif
|
||||
|
||||
int hotlist_has_dot_dot = 1;
|
||||
#define new_hotlist() g_new0(struct hotlist, 1)
|
||||
|
||||
static WListbox *l_hotlist;
|
||||
static WListbox *l_movelist;
|
||||
#define CHECK_BUFFER \
|
||||
do \
|
||||
{ \
|
||||
size_t i; \
|
||||
i = strlen (current->label); \
|
||||
if (i + 3 > buflen) { \
|
||||
g_free (buf); \
|
||||
buflen = 1024 * (i/1024 + 1); \
|
||||
buf = g_malloc (buflen); \
|
||||
} \
|
||||
buf[0] = '\0'; \
|
||||
} while (0)
|
||||
|
||||
static Dlg_head *hotlist_dlg;
|
||||
static Dlg_head *movelist_dlg;
|
||||
#define TKN_GROUP 0
|
||||
#define TKN_ENTRY 1
|
||||
#define TKN_STRING 2
|
||||
#define TKN_URL 3
|
||||
#define TKN_ENDGROUP 4
|
||||
#define TKN_COMMENT 5
|
||||
#define TKN_EOL 125
|
||||
#define TKN_EOF 126
|
||||
#define TKN_UNKNOWN 127
|
||||
|
||||
static WLabel *pname, *pname_group, *movelist_group;
|
||||
#define SKIP_TO_EOL \
|
||||
{ \
|
||||
int _tkn; \
|
||||
while ((_tkn = hot_next_token ()) != TKN_EOF && _tkn != TKN_EOL) ; \
|
||||
}
|
||||
|
||||
#define CHECK_TOKEN(_TKN_) \
|
||||
tkn = hot_next_token (); \
|
||||
if (tkn != _TKN_) \
|
||||
{ \
|
||||
hotlist_state.readonly = 1; \
|
||||
hotlist_state.file_error = 1; \
|
||||
while (tkn != TKN_EOL && tkn != TKN_EOF) \
|
||||
tkn = hot_next_token (); \
|
||||
break; \
|
||||
}
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
enum HotListType
|
||||
{
|
||||
@ -122,6 +162,27 @@ static struct
|
||||
int type; /* LIST_HOTLIST || LIST_VFSLIST */
|
||||
} hotlist_state;
|
||||
|
||||
/* Directory hotlist */
|
||||
struct hotlist
|
||||
{
|
||||
enum HotListType type;
|
||||
char *directory;
|
||||
char *label;
|
||||
struct hotlist *head;
|
||||
struct hotlist *up;
|
||||
struct hotlist *next;
|
||||
};
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
static WListbox *l_hotlist;
|
||||
static WListbox *l_movelist;
|
||||
|
||||
static Dlg_head *hotlist_dlg;
|
||||
static Dlg_head *movelist_dlg;
|
||||
|
||||
static WLabel *pname, *pname_group, *movelist_group;
|
||||
|
||||
static struct _hotlist_but
|
||||
{
|
||||
int ret_cmd, flags, y, x;
|
||||
@ -159,19 +220,21 @@ static struct _hotlist_but
|
||||
/* *INDENT-ON* */
|
||||
};
|
||||
|
||||
/* Directory hotlist */
|
||||
static struct hotlist
|
||||
{
|
||||
enum HotListType type;
|
||||
char *directory;
|
||||
char *label;
|
||||
struct hotlist *head;
|
||||
struct hotlist *up;
|
||||
struct hotlist *next;
|
||||
} *hotlist = NULL;
|
||||
static struct hotlist *hotlist = NULL;
|
||||
|
||||
static struct hotlist *current_group;
|
||||
|
||||
static GString *tkn_buf = NULL;
|
||||
|
||||
static char *hotlist_file_name;
|
||||
static FILE *hotlist_file;
|
||||
static time_t hotlist_file_mtime;
|
||||
|
||||
static int list_level = 0;
|
||||
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void init_movelist (int, struct hotlist *);
|
||||
static void add_new_group_cmd (void);
|
||||
static void add_new_entry_cmd (void);
|
||||
@ -179,7 +242,7 @@ static void remove_from_hotlist (struct hotlist *entry);
|
||||
static void load_hotlist (void);
|
||||
static void add_dotdot_to_list (void);
|
||||
|
||||
#define new_hotlist() g_new0(struct hotlist, 1)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
hotlist_refresh (Dlg_head * dlg)
|
||||
@ -192,7 +255,9 @@ hotlist_refresh (Dlg_head * dlg)
|
||||
draw_box (dlg, dlg->lines - 8, 5, 3, dlg->cols - (UX * 2), TRUE);
|
||||
}
|
||||
|
||||
/* If current->data is 0, then we are dealing with a VFS pathname */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** If current->data is 0, then we are dealing with a VFS pathname */
|
||||
|
||||
static void
|
||||
update_path_name (void)
|
||||
{
|
||||
@ -232,18 +297,7 @@ update_path_name (void)
|
||||
dlg_redraw (dlg);
|
||||
}
|
||||
|
||||
#define CHECK_BUFFER \
|
||||
do \
|
||||
{ \
|
||||
size_t i; \
|
||||
i = strlen (current->label); \
|
||||
if (i + 3 > buflen) { \
|
||||
g_free (buf); \
|
||||
buflen = 1024 * (i/1024 + 1); \
|
||||
buf = g_malloc (buflen); \
|
||||
} \
|
||||
buf[0] = '\0'; \
|
||||
} while (0)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
fill_listbox (void)
|
||||
@ -282,6 +336,8 @@ fill_listbox (void)
|
||||
g_string_free (buff, TRUE);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
unlink_entry (struct hotlist *entry)
|
||||
{
|
||||
@ -299,6 +355,8 @@ unlink_entry (struct hotlist *entry)
|
||||
entry->next = entry->up = 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
#ifdef ENABLE_VFS
|
||||
static void
|
||||
add_name_to_list (const char *path)
|
||||
@ -307,8 +365,10 @@ add_name_to_list (const char *path)
|
||||
}
|
||||
#endif /* !ENABLE_VFS */
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
hotlist_button_callback (WButton *button, int action)
|
||||
hotlist_button_callback (WButton * button, int action)
|
||||
{
|
||||
(void) button;
|
||||
|
||||
@ -456,6 +516,8 @@ hotlist_button_callback (WButton *button, int action)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static inline cb_ret_t
|
||||
hotlist_handle_key (Dlg_head * h, int key)
|
||||
{
|
||||
@ -521,6 +583,8 @@ hotlist_handle_key (Dlg_head * h, int key)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static cb_ret_t
|
||||
hotlist_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
|
||||
{
|
||||
@ -556,6 +620,8 @@ hotlist_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
l_call (WListbox * list)
|
||||
{
|
||||
@ -596,7 +662,8 @@ l_call (WListbox * list)
|
||||
return LISTBOX_CONT;
|
||||
}
|
||||
|
||||
/*
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Expands all button names (once) and recalculates button positions.
|
||||
* returns number of columns in the dialog box, which is 10 chars longer
|
||||
* then buttonbar.
|
||||
@ -604,6 +671,7 @@ l_call (WListbox * list)
|
||||
* If common width of the window (i.e. in xterm) is less than returned
|
||||
* width - sorry :) (anyway this did not handled in previous version too)
|
||||
*/
|
||||
|
||||
static int
|
||||
init_i18n_stuff (int list_type, int cols)
|
||||
{
|
||||
@ -677,6 +745,8 @@ init_i18n_stuff (int list_type, int cols)
|
||||
return cols;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
init_hotlist (int list_type)
|
||||
{
|
||||
@ -755,6 +825,8 @@ init_hotlist (int list_type)
|
||||
/* add listbox to the dialogs */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
init_movelist (int list_type, struct hotlist *item)
|
||||
{
|
||||
@ -796,10 +868,12 @@ init_movelist (int list_type, struct hotlist *item)
|
||||
/* add listbox to the dialogs */
|
||||
}
|
||||
|
||||
/*
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Destroy the list dialog.
|
||||
* Don't confuse with done_hotlist() for the list in memory.
|
||||
*/
|
||||
|
||||
static void
|
||||
hotlist_done (void)
|
||||
{
|
||||
@ -810,12 +884,16 @@ hotlist_done (void)
|
||||
repaint_screen ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static inline char *
|
||||
find_group_section (struct hotlist *grp)
|
||||
{
|
||||
return g_strconcat (grp->directory, ".Group", (char *) NULL);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static struct hotlist *
|
||||
add2hotlist (char *label, char *directory, enum HotListType type, listbox_append_t pos)
|
||||
{
|
||||
@ -902,8 +980,8 @@ add2hotlist (char *label, char *directory, enum HotListType type, listbox_append
|
||||
|
||||
}
|
||||
|
||||
#ifdef ENABLE_NLS
|
||||
/*
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Support routine for add_new_entry_input()/add_new_group_input()
|
||||
* Change positions of buttons (first three widgets).
|
||||
*
|
||||
@ -911,6 +989,8 @@ add2hotlist (char *label, char *directory, enum HotListType type, listbox_append
|
||||
* internationalized label lengths and total buttonbar length...assume
|
||||
* 64 is longer anyway.
|
||||
*/
|
||||
|
||||
#ifdef ENABLE_NLS
|
||||
static void
|
||||
add_widgets_i18n (QuickWidget * qw, int len)
|
||||
{
|
||||
@ -931,6 +1011,8 @@ add_widgets_i18n (QuickWidget * qw, int len)
|
||||
}
|
||||
#endif /* ENABLE_NLS */
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
add_new_entry_input (const char *header, const char *text1, const char *text2,
|
||||
const char *help, char **r1, char **r2)
|
||||
@ -997,6 +1079,8 @@ add_new_entry_input (const char *header, const char *text1, const char *text2,
|
||||
#undef RELATIVE_Y_INPUT_PTH
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
add_new_entry_cmd (void)
|
||||
{
|
||||
@ -1027,6 +1111,8 @@ add_new_entry_cmd (void)
|
||||
hotlist_state.modified = 1;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
add_new_group_input (const char *header, const char *label, char **result)
|
||||
{
|
||||
@ -1080,6 +1166,8 @@ add_new_group_input (const char *header, const char *label, char **result)
|
||||
return (ret != B_CANCEL) ? ret : 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
add_new_group_cmd (void)
|
||||
{
|
||||
@ -1098,29 +1186,7 @@ add_new_group_cmd (void)
|
||||
hotlist_state.modified = 1;
|
||||
}
|
||||
|
||||
void
|
||||
add2hotlist_cmd (void)
|
||||
{
|
||||
char *lc_prompt, *label;
|
||||
const char *cp = _("Label for \"%s\":");
|
||||
int l = str_term_width1 (cp);
|
||||
char *label_string = g_strdup (current_panel->cwd);
|
||||
|
||||
strip_password (label_string, 1);
|
||||
|
||||
lc_prompt = g_strdup_printf (cp, path_trunc (current_panel->cwd, COLS - 2 * UX - (l + 8)));
|
||||
label = input_dialog (_("Add to hotlist"), lc_prompt, MC_HISTORY_HOTLIST_ADD, label_string);
|
||||
g_free (lc_prompt);
|
||||
|
||||
if (!label || !*label)
|
||||
{
|
||||
g_free (label_string);
|
||||
g_free (label);
|
||||
return;
|
||||
}
|
||||
add2hotlist (label, label_string, HL_TYPE_ENTRY, LISTBOX_APPEND_AT_END);
|
||||
hotlist_state.modified = 1;
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
remove_group (struct hotlist *grp)
|
||||
@ -1143,6 +1209,8 @@ remove_group (struct hotlist *grp)
|
||||
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
remove_from_hotlist (struct hotlist *entry)
|
||||
{
|
||||
@ -1200,44 +1268,7 @@ remove_from_hotlist (struct hotlist *entry)
|
||||
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 */
|
||||
tty_setcolor (SELECTED_COLOR);
|
||||
|
||||
hotlist_state.running = 1;
|
||||
run_dlg (hotlist_dlg);
|
||||
hotlist_state.running = 0;
|
||||
save_hotlist ();
|
||||
|
||||
switch (hotlist_dlg->ret_value)
|
||||
{
|
||||
default:
|
||||
case B_CANCEL:
|
||||
break;
|
||||
|
||||
case B_ENTER:
|
||||
{
|
||||
char *text = NULL;
|
||||
struct hotlist *hlp = NULL;
|
||||
|
||||
listbox_get_current (l_hotlist, &text, (void **) &hlp);
|
||||
target = g_strdup (hlp != NULL ? hlp->directory : text);
|
||||
break;
|
||||
}
|
||||
} /* switch */
|
||||
|
||||
hotlist_done ();
|
||||
return target;
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
load_group (struct hotlist *grp)
|
||||
@ -1276,21 +1307,7 @@ load_group (struct hotlist *grp)
|
||||
load_group (current);
|
||||
}
|
||||
|
||||
#define TKN_GROUP 0
|
||||
#define TKN_ENTRY 1
|
||||
#define TKN_STRING 2
|
||||
#define TKN_URL 3
|
||||
#define TKN_ENDGROUP 4
|
||||
#define TKN_COMMENT 5
|
||||
#define TKN_EOL 125
|
||||
#define TKN_EOF 126
|
||||
#define TKN_UNKNOWN 127
|
||||
|
||||
static GString *tkn_buf = NULL;
|
||||
|
||||
static char *hotlist_file_name;
|
||||
static FILE *hotlist_file;
|
||||
static time_t hotlist_file_mtime;
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
hot_skip_blanks (void)
|
||||
@ -1303,6 +1320,8 @@ hot_skip_blanks (void)
|
||||
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
hot_next_token (void)
|
||||
{
|
||||
@ -1386,22 +1405,7 @@ hot_next_token (void)
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define SKIP_TO_EOL \
|
||||
{ \
|
||||
int _tkn; \
|
||||
while ((_tkn = hot_next_token ()) != TKN_EOF && _tkn != TKN_EOL) ; \
|
||||
}
|
||||
|
||||
#define CHECK_TOKEN(_TKN_) \
|
||||
tkn = hot_next_token (); \
|
||||
if (tkn != _TKN_) \
|
||||
{ \
|
||||
hotlist_state.readonly = 1; \
|
||||
hotlist_state.file_error = 1; \
|
||||
while (tkn != TKN_EOL && tkn != TKN_EOF) \
|
||||
tkn = hot_next_token (); \
|
||||
break; \
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
hot_load_group (struct hotlist *grp)
|
||||
@ -1453,6 +1457,8 @@ hot_load_group (struct hotlist *grp)
|
||||
SKIP_TO_EOL;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
hot_load_file (struct hotlist *grp)
|
||||
{
|
||||
@ -1497,6 +1503,8 @@ hot_load_file (struct hotlist *grp)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
clean_up_hotlist_groups (const char *section)
|
||||
{
|
||||
@ -1523,7 +1531,7 @@ clean_up_hotlist_groups (const char *section)
|
||||
g_free (grp_section);
|
||||
}
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
load_hotlist (void)
|
||||
@ -1569,7 +1577,8 @@ load_hotlist (void)
|
||||
remove_old_list = 1;
|
||||
else
|
||||
message (D_ERROR, _("Hotlist Load"),
|
||||
_("MC was unable to write ~/%s file,\nyour old hotlist entries were not deleted"),
|
||||
_
|
||||
("MC was unable to write ~/%s file,\nyour old hotlist entries were not deleted"),
|
||||
MC_USERCONF_DIR PATH_SEP_STR MC_HOTLIST_FILE);
|
||||
}
|
||||
else
|
||||
@ -1592,8 +1601,7 @@ load_hotlist (void)
|
||||
current_group = hotlist;
|
||||
}
|
||||
|
||||
|
||||
static int list_level = 0;
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
hot_save_group (struct hotlist *grp)
|
||||
@ -1654,6 +1662,89 @@ do { \
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
add_dotdot_to_list (void)
|
||||
{
|
||||
if (current_group != hotlist)
|
||||
{
|
||||
if (hotlist_has_dot_dot != 0)
|
||||
add2hotlist (g_strdup (".."), g_strdup (".."), HL_TYPE_DOTDOT, LISTBOX_APPEND_AT_END);
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
add2hotlist_cmd (void)
|
||||
{
|
||||
char *lc_prompt, *label;
|
||||
const char *cp = _("Label for \"%s\":");
|
||||
int l = str_term_width1 (cp);
|
||||
char *label_string = g_strdup (current_panel->cwd);
|
||||
|
||||
strip_password (label_string, 1);
|
||||
|
||||
lc_prompt = g_strdup_printf (cp, path_trunc (current_panel->cwd, COLS - 2 * UX - (l + 8)));
|
||||
label = input_dialog (_("Add to hotlist"), lc_prompt, MC_HISTORY_HOTLIST_ADD, label_string);
|
||||
g_free (lc_prompt);
|
||||
|
||||
if (!label || !*label)
|
||||
{
|
||||
g_free (label_string);
|
||||
g_free (label);
|
||||
return;
|
||||
}
|
||||
add2hotlist (label, label_string, HL_TYPE_ENTRY, LISTBOX_APPEND_AT_END);
|
||||
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 */
|
||||
tty_setcolor (SELECTED_COLOR);
|
||||
|
||||
hotlist_state.running = 1;
|
||||
run_dlg (hotlist_dlg);
|
||||
hotlist_state.running = 0;
|
||||
save_hotlist ();
|
||||
|
||||
switch (hotlist_dlg->ret_value)
|
||||
{
|
||||
default:
|
||||
case B_CANCEL:
|
||||
break;
|
||||
|
||||
case B_ENTER:
|
||||
{
|
||||
char *text = NULL;
|
||||
struct hotlist *hlp = NULL;
|
||||
|
||||
listbox_get_current (l_hotlist, &text, (void **) &hlp);
|
||||
target = g_strdup (hlp != NULL ? hlp->directory : text);
|
||||
break;
|
||||
}
|
||||
} /* switch */
|
||||
|
||||
hotlist_done ();
|
||||
return target;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
save_hotlist (void)
|
||||
{
|
||||
@ -1681,10 +1772,12 @@ save_hotlist (void)
|
||||
return saved;
|
||||
}
|
||||
|
||||
/*
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Unload list from memory.
|
||||
* Don't confuse with hotlist_done() for GUI.
|
||||
*/
|
||||
|
||||
void
|
||||
done_hotlist (void)
|
||||
{
|
||||
@ -1711,12 +1804,4 @@ done_hotlist (void)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
add_dotdot_to_list (void)
|
||||
{
|
||||
if (current_group != hotlist)
|
||||
{
|
||||
if (hotlist_has_dot_dot != 0)
|
||||
add2hotlist (g_strdup (".."), g_strdup (".."), HL_TYPE_DOTDOT, LISTBOX_APPEND_AT_END);
|
||||
}
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -1,18 +1,28 @@
|
||||
|
||||
/** \file hotlist.h
|
||||
* \brief Header: directory hotlist
|
||||
*/
|
||||
|
||||
#ifndef MC_HOTLIST_H
|
||||
#define MC_HOTLIST_H
|
||||
#ifndef MC__HOTLIST_H
|
||||
#define MC__HOTLIST_H
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
#define LIST_VFSLIST 0x01
|
||||
#define LIST_HOTLIST 0x02
|
||||
#define LIST_MOVELIST 0x04
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
void add2hotlist_cmd (void);
|
||||
char *hotlist_cmd (int list_vfs);
|
||||
int save_hotlist (void);
|
||||
int save_hotlist (void);
|
||||
void done_hotlist (void);
|
||||
|
||||
#endif
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__HOTLIST_H */
|
||||
|
29
src/info.c
29
src/info.c
@ -44,18 +44,29 @@
|
||||
#include "setup.h" /* panels_options */
|
||||
#include "info.h"
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
#ifndef VERSION
|
||||
# define VERSION "undefined"
|
||||
#define VERSION "undefined"
|
||||
#endif
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
struct WInfo
|
||||
{
|
||||
Widget widget;
|
||||
int ready;
|
||||
};
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
static struct my_statfs myfs_stats;
|
||||
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
info_box (struct WInfo *info)
|
||||
{
|
||||
@ -68,7 +79,7 @@ info_box (struct WInfo *info)
|
||||
draw_box (info->widget.owner, info->widget.y, info->widget.x,
|
||||
info->widget.lines, info->widget.cols, FALSE);
|
||||
|
||||
widget_move (&info->widget, 0, (info->widget.cols - len - 2)/2);
|
||||
widget_move (&info->widget, 0, (info->widget.cols - len - 2) / 2);
|
||||
tty_printf (" %s ", title);
|
||||
|
||||
widget_move (&info->widget, 2, 0);
|
||||
@ -78,6 +89,8 @@ info_box (struct WInfo *info)
|
||||
tty_draw_hline (info->widget.y + 2, info->widget.x + 1, ACS_HLINE, info->widget.cols - 2);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
info_show_info (struct WInfo *info)
|
||||
{
|
||||
@ -238,6 +251,8 @@ info_show_info (struct WInfo *info)
|
||||
g_string_free (buff, TRUE);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
info_hook (void *data)
|
||||
{
|
||||
@ -254,6 +269,8 @@ info_hook (void *data)
|
||||
info_show_info (info);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static cb_ret_t
|
||||
info_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
{
|
||||
@ -285,6 +302,8 @@ info_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
info_event (Gpm_Event * event, void *data)
|
||||
{
|
||||
@ -300,6 +319,10 @@ info_event (Gpm_Event * event, void *data)
|
||||
return MOU_NORMAL;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
WInfo *
|
||||
info_new (int y, int x, int lines, int cols)
|
||||
{
|
||||
@ -312,3 +335,5 @@ info_new (int y, int x, int lines, int cols)
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
18
src/info.h
18
src/info.h
@ -1,14 +1,24 @@
|
||||
|
||||
/** \file info.h
|
||||
* \brief Header: panel managing
|
||||
*/
|
||||
|
||||
#ifndef MC_INFO_H
|
||||
#define MC_INFO_H
|
||||
#ifndef MC__INFO_H
|
||||
#define MC__INFO_H
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
struct WInfo;
|
||||
typedef struct WInfo WInfo;
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
WInfo *info_new (int y, int x, int lines, int cols);
|
||||
|
||||
#endif /* MC_INFO_H */
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__INFO_H */
|
||||
|
2092
src/keybind.c
2092
src/keybind.c
File diff suppressed because it is too large
Load Diff
@ -1,33 +1,39 @@
|
||||
|
||||
#ifndef MC_KEYBIND_H
|
||||
#define MC_KEYBIND_H
|
||||
#ifndef MC__KEYBIND_H
|
||||
#define MC__KEYBIND_H
|
||||
|
||||
#include "lib/global.h"
|
||||
|
||||
typedef struct name_keymap_t {
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
#define KEYMAP_SHORTCUT_LENGTH 32 /* FIXME: is 32 bytes enough for shortcut? */
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
typedef struct name_keymap_t
|
||||
{
|
||||
const char *name;
|
||||
unsigned long val;
|
||||
} name_keymap_t;
|
||||
|
||||
typedef struct key_config_t {
|
||||
time_t mtime; /* mtime at the moment we read config file */
|
||||
typedef struct key_config_t
|
||||
{
|
||||
time_t mtime; /* mtime at the moment we read config file */
|
||||
GArray *keymap;
|
||||
GArray *ext_keymap;
|
||||
gchar *labels[10];
|
||||
} key_config_t;
|
||||
|
||||
/* The global keymaps are of this type */
|
||||
#define KEYMAP_SHORTCUT_LENGTH 32 /* FIXME: is 32 bytes enough for shortcut? */
|
||||
typedef struct global_keymap_t {
|
||||
typedef struct global_keymap_t
|
||||
{
|
||||
long key;
|
||||
unsigned long command;
|
||||
char caption[KEYMAP_SHORTCUT_LENGTH];
|
||||
} global_keymap_t;
|
||||
|
||||
void keybind_cmd_bind (GArray *keymap, const char *keybind, unsigned long action);
|
||||
unsigned long lookup_action (const char *name);
|
||||
const char *lookup_keymap_shortcut (const global_keymap_t *keymap, unsigned long action);
|
||||
unsigned long lookup_keymap_command (const global_keymap_t *keymap, long key);
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
#ifdef USE_INTERNAL_EDIT
|
||||
extern GArray *editor_keymap;
|
||||
@ -98,4 +104,12 @@ extern const global_keymap_t default_dialog_keymap[];
|
||||
extern const global_keymap_t default_diff_keymap[];
|
||||
#endif
|
||||
|
||||
#endif /* MC_KEYBIND_H */
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
void keybind_cmd_bind (GArray * keymap, const char *keybind, unsigned long action);
|
||||
unsigned long lookup_action (const char *name);
|
||||
const char *lookup_keymap_shortcut (const global_keymap_t * keymap, unsigned long action);
|
||||
unsigned long lookup_keymap_command (const global_keymap_t * keymap, long key);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__KEYBIND_H */
|
||||
|
269
src/layout.c
269
src/layout.c
@ -39,7 +39,7 @@
|
||||
* resizing code depends on it...
|
||||
*/
|
||||
#ifdef HAVE_SYS_IOCTL_H
|
||||
# include <sys/ioctl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#endif
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
@ -74,6 +74,8 @@
|
||||
|
||||
#include "setup.h" /* For save_setup() */
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
/* Controls the display of the rotating dash on the verbose mode */
|
||||
int nice_rotating_dash = 1;
|
||||
|
||||
@ -110,11 +112,30 @@ int free_space = 1;
|
||||
/* The starting line for the output of the subprogram */
|
||||
int output_start_y = 0;
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
/* The maximum number of views managed by the set_display_type routine */
|
||||
/* Must be at least two (for current and other). Please note that until */
|
||||
/* Janne gets around this, we will only manage two of them :-) */
|
||||
#define MAX_VIEWS 2
|
||||
|
||||
/* Width 12 for a wee Quick (Hex) View */
|
||||
#define MINWIDTH 12
|
||||
#define MINHEIGHT 5
|
||||
|
||||
#define B_2LEFT B_USER
|
||||
#define B_2RIGHT (B_USER + 1)
|
||||
#define B_PLUS (B_USER + 2)
|
||||
#define B_MINUS (B_USER + 3)
|
||||
|
||||
|
||||
#define LAYOUT_OPTIONS_COUNT (sizeof (check_options) / sizeof (check_options[0]))
|
||||
#define OTHER_OPTIONS_COUNT (LAYOUT_OPTIONS_COUNT - 1)
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
static struct
|
||||
{
|
||||
panel_view_mode_t type;
|
||||
@ -149,15 +170,6 @@ static int _free_space;
|
||||
|
||||
static int height;
|
||||
|
||||
/* Width 12 for a wee Quick (Hex) View */
|
||||
#define MINWIDTH 12
|
||||
#define MINHEIGHT 5
|
||||
|
||||
#define B_2LEFT B_USER
|
||||
#define B_2RIGHT (B_USER + 1)
|
||||
#define B_PLUS (B_USER + 2)
|
||||
#define B_MINUS (B_USER + 3)
|
||||
|
||||
static const char *s_split_direction[2] = {
|
||||
N_("&Vertical"),
|
||||
N_("&Horizontal")
|
||||
@ -184,15 +196,17 @@ static struct
|
||||
/* *INDENT-ON* */
|
||||
};
|
||||
|
||||
#define LAYOUT_OPTIONS_COUNT (sizeof (check_options) / sizeof (check_options[0]))
|
||||
#define OTHER_OPTIONS_COUNT (LAYOUT_OPTIONS_COUNT - 1)
|
||||
|
||||
static gsize first_width;
|
||||
static const char *output_lines_label = NULL;
|
||||
static int output_lines_label_len;
|
||||
|
||||
static WButton *bleft_widget, *bright_widget;
|
||||
|
||||
static int ok_to_refresh = 1;
|
||||
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static inline void
|
||||
_check_split (void)
|
||||
{
|
||||
@ -219,8 +233,10 @@ _check_split (void)
|
||||
old_horizontal_split = _horizontal_split;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
update_split (const Dlg_head *h)
|
||||
update_split (const Dlg_head * h)
|
||||
{
|
||||
/* Check split has to be done before testing if it changed, since
|
||||
it can change due to calling _check_split() as well */
|
||||
@ -241,8 +257,10 @@ update_split (const Dlg_head *h)
|
||||
tty_print_char ('=');
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
b_left_right_cback (WButton *button, int action)
|
||||
b_left_right_cback (WButton * button, int action)
|
||||
{
|
||||
(void) action;
|
||||
|
||||
@ -255,8 +273,10 @@ b_left_right_cback (WButton *button, int action)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
bplus_cback (WButton *button, int action)
|
||||
bplus_cback (WButton * button, int action)
|
||||
{
|
||||
(void) button;
|
||||
(void) action;
|
||||
@ -266,8 +286,10 @@ bplus_cback (WButton *button, int action)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
bminus_cback (WButton *button, int action)
|
||||
bminus_cback (WButton * button, int action)
|
||||
{
|
||||
(void) button;
|
||||
(void) action;
|
||||
@ -277,6 +299,8 @@ bminus_cback (WButton *button, int action)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static cb_ret_t
|
||||
layout_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
|
||||
{
|
||||
@ -380,6 +404,8 @@ layout_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *d
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static Dlg_head *
|
||||
init_layout (void)
|
||||
{
|
||||
@ -525,6 +551,86 @@ init_layout (void)
|
||||
return layout_dlg;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
check_split (void)
|
||||
{
|
||||
if (horizontal_split)
|
||||
{
|
||||
if (equal_split)
|
||||
first_panel_size = height / 2;
|
||||
else if (first_panel_size < MINHEIGHT)
|
||||
first_panel_size = MINHEIGHT;
|
||||
else if (first_panel_size > height - MINHEIGHT)
|
||||
first_panel_size = height - MINHEIGHT;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (equal_split)
|
||||
first_panel_size = COLS / 2;
|
||||
else if (first_panel_size < MINWIDTH)
|
||||
first_panel_size = MINWIDTH;
|
||||
else if (first_panel_size > COLS - MINWIDTH)
|
||||
first_panel_size = COLS - MINWIDTH;
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
panel_do_cols (int idx)
|
||||
{
|
||||
if (get_display_type (idx) == view_listing)
|
||||
set_panel_formats ((WPanel *) panels[idx].widget);
|
||||
else
|
||||
panel_update_cols (panels[idx].widget, frame_half);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static inline void
|
||||
low_level_change_screen_size (void)
|
||||
{
|
||||
#if defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4
|
||||
#if defined TIOCGWINSZ
|
||||
struct winsize winsz;
|
||||
|
||||
winsz.ws_col = winsz.ws_row = 0;
|
||||
/* Ioctl on the STDIN_FILENO */
|
||||
ioctl (0, TIOCGWINSZ, &winsz);
|
||||
if (winsz.ws_col && winsz.ws_row)
|
||||
{
|
||||
#if defined(NCURSES_VERSION) && defined(HAVE_RESIZETERM)
|
||||
resizeterm (winsz.ws_row, winsz.ws_col);
|
||||
clearok (stdscr, TRUE); /* sigwinch's should use a semaphore! */
|
||||
#else
|
||||
COLS = winsz.ws_col;
|
||||
LINES = winsz.ws_row;
|
||||
#endif
|
||||
#ifdef HAVE_SUBSHELL_SUPPORT
|
||||
resize_subshell ();
|
||||
#endif
|
||||
}
|
||||
#endif /* TIOCGWINSZ */
|
||||
#endif /* defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4 */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
dlg_resize_cb (void *data, void *user_data)
|
||||
{
|
||||
Dlg_head *d = data;
|
||||
|
||||
(void) user_data;
|
||||
d->callback (d, NULL, DLG_RESIZE, 0, NULL);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
layout_change (void)
|
||||
{
|
||||
@ -537,6 +643,8 @@ layout_change (void)
|
||||
load_hint (1);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
layout_box (void)
|
||||
{
|
||||
@ -569,28 +677,7 @@ layout_box (void)
|
||||
layout_change ();
|
||||
}
|
||||
|
||||
static void
|
||||
check_split (void)
|
||||
{
|
||||
if (horizontal_split)
|
||||
{
|
||||
if (equal_split)
|
||||
first_panel_size = height / 2;
|
||||
else if (first_panel_size < MINHEIGHT)
|
||||
first_panel_size = MINHEIGHT;
|
||||
else if (first_panel_size > height - MINHEIGHT)
|
||||
first_panel_size = height - MINHEIGHT;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (equal_split)
|
||||
first_panel_size = COLS / 2;
|
||||
else if (first_panel_size < MINWIDTH)
|
||||
first_panel_size = MINWIDTH;
|
||||
else if (first_panel_size > COLS - MINWIDTH)
|
||||
first_panel_size = COLS - MINWIDTH;
|
||||
}
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
clr_scr (void)
|
||||
@ -600,6 +687,8 @@ clr_scr (void)
|
||||
tty_refresh ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
repaint_screen (void)
|
||||
{
|
||||
@ -607,6 +696,8 @@ repaint_screen (void)
|
||||
tty_refresh ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
mc_refresh (void)
|
||||
{
|
||||
@ -624,14 +715,7 @@ mc_refresh (void)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
panel_do_cols (int idx)
|
||||
{
|
||||
if (get_display_type (idx) == view_listing)
|
||||
set_panel_formats ((WPanel *) panels[idx].widget);
|
||||
else
|
||||
panel_update_cols (panels[idx].widget, frame_half);
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
setup_panels (void)
|
||||
@ -717,41 +801,7 @@ setup_panels (void)
|
||||
update_xterm_title_path ();
|
||||
}
|
||||
|
||||
static inline void
|
||||
low_level_change_screen_size (void)
|
||||
{
|
||||
#if defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4
|
||||
#if defined TIOCGWINSZ
|
||||
struct winsize winsz;
|
||||
|
||||
winsz.ws_col = winsz.ws_row = 0;
|
||||
/* Ioctl on the STDIN_FILENO */
|
||||
ioctl (0, TIOCGWINSZ, &winsz);
|
||||
if (winsz.ws_col && winsz.ws_row)
|
||||
{
|
||||
#if defined(NCURSES_VERSION) && defined(HAVE_RESIZETERM)
|
||||
resizeterm (winsz.ws_row, winsz.ws_col);
|
||||
clearok (stdscr, TRUE); /* sigwinch's should use a semaphore! */
|
||||
#else
|
||||
COLS = winsz.ws_col;
|
||||
LINES = winsz.ws_row;
|
||||
#endif
|
||||
#ifdef HAVE_SUBSHELL_SUPPORT
|
||||
resize_subshell ();
|
||||
#endif
|
||||
}
|
||||
#endif /* TIOCGWINSZ */
|
||||
#endif /* defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4 */
|
||||
}
|
||||
|
||||
static void
|
||||
dlg_resize_cb (void *data, void *user_data)
|
||||
{
|
||||
Dlg_head *d = data;
|
||||
|
||||
(void) user_data;
|
||||
d->callback (d, NULL, DLG_RESIZE, 0, NULL);
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
sigwinch_handler (int dummy)
|
||||
@ -763,6 +813,8 @@ sigwinch_handler (int dummy)
|
||||
winch_flag = 1;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
change_screen_size (void)
|
||||
{
|
||||
@ -799,7 +851,8 @@ change_screen_size (void)
|
||||
#endif /* defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4 */
|
||||
}
|
||||
|
||||
static int ok_to_refresh = 1;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
use_dash (gboolean flag)
|
||||
@ -810,6 +863,8 @@ use_dash (gboolean flag)
|
||||
ok_to_refresh--;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
set_hintbar (const char *str)
|
||||
{
|
||||
@ -818,6 +873,8 @@ set_hintbar (const char *str)
|
||||
mc_refresh ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
print_vfs_message (const char *msg, ...)
|
||||
{
|
||||
@ -855,6 +912,8 @@ print_vfs_message (const char *msg, ...)
|
||||
set_hintbar (str);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
rotate_dash (void)
|
||||
{
|
||||
@ -873,6 +932,8 @@ rotate_dash (void)
|
||||
pos++;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
const char *
|
||||
get_nth_panel_name (int num)
|
||||
{
|
||||
@ -889,6 +950,7 @@ get_nth_panel_name (int num)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/* I wonder if I should start to use the folding mode than Dugan uses */
|
||||
/* */
|
||||
/* This is the centralized managing of the panel display types */
|
||||
@ -900,6 +962,7 @@ get_nth_panel_name (int num)
|
||||
/* Set the num-th panel to the view type: type */
|
||||
/* This routine also keeps at least one WPanel object in the screen */
|
||||
/* since a lot of routines depend on the current_panel variable */
|
||||
|
||||
void
|
||||
set_display_type (int num, panel_view_mode_t type)
|
||||
{
|
||||
@ -965,7 +1028,7 @@ set_display_type (int num, panel_view_mode_t type)
|
||||
|
||||
case view_info:
|
||||
new_widget = (Widget *) info_new (y, x, lines, cols);
|
||||
break;
|
||||
break;
|
||||
|
||||
case view_tree:
|
||||
new_widget = (Widget *) tree_new (y, x, lines, cols, TRUE);
|
||||
@ -973,7 +1036,7 @@ set_display_type (int num, panel_view_mode_t type)
|
||||
|
||||
case view_quick:
|
||||
new_widget = (Widget *) mcview_new (y, x, lines, cols, TRUE);
|
||||
the_other_panel = (WPanel *) panels [the_other].widget;
|
||||
the_other_panel = (WPanel *) panels[the_other].widget;
|
||||
if (the_other_panel != NULL)
|
||||
file_name = the_other_panel->dir.list[the_other_panel->selected].fname;
|
||||
else
|
||||
@ -1022,9 +1085,11 @@ set_display_type (int num, panel_view_mode_t type)
|
||||
g_free (old_widget);
|
||||
}
|
||||
|
||||
/* This routine is deeply sticked to the two panels idea.
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** This routine is deeply sticked to the two panels idea.
|
||||
What should it do in more panels. ANSWER - don't use it
|
||||
in any multiple panels environment. */
|
||||
|
||||
void
|
||||
swap_panels (void)
|
||||
{
|
||||
@ -1118,18 +1183,24 @@ swap_panels (void)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
panel_view_mode_t
|
||||
get_display_type (int idx)
|
||||
{
|
||||
return panels[idx].type;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
struct Widget *
|
||||
get_panel_widget (int idx)
|
||||
{
|
||||
return panels[idx].widget;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
get_current_index (void)
|
||||
{
|
||||
@ -1139,19 +1210,25 @@ get_current_index (void)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
get_other_index (void)
|
||||
{
|
||||
return !get_current_index ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
struct WPanel *
|
||||
get_other_panel (void)
|
||||
{
|
||||
return (struct WPanel *) get_panel_widget (get_other_index ());
|
||||
}
|
||||
|
||||
/* Returns the view type for the current panel/view */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Returns the view type for the current panel/view */
|
||||
|
||||
panel_view_mode_t
|
||||
get_current_type (void)
|
||||
{
|
||||
@ -1161,7 +1238,9 @@ get_current_type (void)
|
||||
return panels[1].type;
|
||||
}
|
||||
|
||||
/* Returns the view type of the unselected panel */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Returns the view type of the unselected panel */
|
||||
|
||||
panel_view_mode_t
|
||||
get_other_type (void)
|
||||
{
|
||||
@ -1171,7 +1250,9 @@ get_other_type (void)
|
||||
return panels[0].type;
|
||||
}
|
||||
|
||||
/* Save current list_view widget directory into panel */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Save current list_view widget directory into panel */
|
||||
|
||||
void
|
||||
save_panel_dir (int idx)
|
||||
{
|
||||
@ -1189,7 +1270,9 @@ save_panel_dir (int idx)
|
||||
}
|
||||
}
|
||||
|
||||
/* Save current list_view widget directory into panel */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Save current list_view widget directory into panel */
|
||||
|
||||
Widget *
|
||||
restore_into_right_dir_panel (int idx, Widget * from_widget)
|
||||
{
|
||||
@ -1206,8 +1289,10 @@ restore_into_right_dir_panel (int idx, Widget * from_widget)
|
||||
return new_widget;
|
||||
}
|
||||
|
||||
/* Return working dir, if it's view_listing - cwd,
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Return working dir, if it's view_listing - cwd,
|
||||
but for other types - last_saved_dir */
|
||||
|
||||
const char *
|
||||
get_panel_dir_for (const WPanel * widget)
|
||||
{
|
||||
@ -1225,3 +1310,5 @@ get_panel_dir_for (const WPanel * widget)
|
||||
|
||||
return panels[i].last_saved_dir;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
50
src/layout.h
50
src/layout.h
@ -1,15 +1,38 @@
|
||||
|
||||
/** \file layout.h
|
||||
* \brief Header: panel layout module
|
||||
*/
|
||||
|
||||
#ifndef MC_LAYOUT_H
|
||||
#define MC_LAYOUT_H
|
||||
#ifndef MC__LAYOUT_H
|
||||
#define MC__LAYOUT_H
|
||||
|
||||
#include "lib/global.h"
|
||||
#include "panel.h"
|
||||
#include "widget.h"
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
extern int winch_flag;
|
||||
extern int equal_split;
|
||||
extern int first_panel_size;
|
||||
extern int output_lines;
|
||||
extern int command_prompt;
|
||||
extern int keybar_visible;
|
||||
extern int output_start_y;
|
||||
extern int message_visible;
|
||||
extern int xterm_title;
|
||||
extern int free_space;
|
||||
|
||||
extern int horizontal_split;
|
||||
extern int nice_rotating_dash;
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
void layout_change (void);
|
||||
void layout_box (void);
|
||||
void setup_panels (void);
|
||||
@ -30,8 +53,8 @@ struct Widget *get_panel_widget (int idx);
|
||||
struct WPanel *get_other_panel (void);
|
||||
|
||||
void save_panel_dir (int idx);
|
||||
Widget *restore_into_right_dir_panel (int idx, Widget *from_widget);
|
||||
const char *get_panel_dir_for (const WPanel *widget);
|
||||
Widget *restore_into_right_dir_panel (int idx, Widget * from_widget);
|
||||
const char *get_panel_dir_for (const WPanel * widget);
|
||||
|
||||
void set_hintbar (const char *str);
|
||||
|
||||
@ -44,18 +67,5 @@ void clr_scr (void);
|
||||
void repaint_screen (void);
|
||||
void mc_refresh (void);
|
||||
|
||||
extern int winch_flag;
|
||||
extern int equal_split;
|
||||
extern int first_panel_size;
|
||||
extern int output_lines;
|
||||
extern int command_prompt;
|
||||
extern int keybar_visible;
|
||||
extern int output_start_y;
|
||||
extern int message_visible;
|
||||
extern int xterm_title;
|
||||
extern int free_space;
|
||||
|
||||
extern int horizontal_split;
|
||||
extern int nice_rotating_dash;
|
||||
|
||||
#endif
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__LAYOUT_H */
|
||||
|
354
src/learn.c
354
src/learn.c
@ -1,7 +1,7 @@
|
||||
/* Learn keys
|
||||
Copyright (C) 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
|
||||
2007, 2009 Free Software Foundation, Inc.
|
||||
|
||||
|
||||
Written by: 1995 Jakub Jelinek
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
@ -38,17 +38,21 @@
|
||||
|
||||
#include "lib/tty/tty.h"
|
||||
#include "lib/tty/key.h"
|
||||
#include "lib/mcconfig.h" /* Save profile */
|
||||
#include "lib/mcconfig.h" /* Save profile */
|
||||
#include "lib/strescape.h"
|
||||
#include "lib/strutil.h"
|
||||
|
||||
#include "dialog.h"
|
||||
#include "widget.h"
|
||||
#include "setup.h"
|
||||
#include "layout.h" /* repaint_screen() */
|
||||
#include "layout.h" /* repaint_screen() */
|
||||
#include "learn.h"
|
||||
#include "wtools.h"
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
#define UX 4
|
||||
#define UY 3
|
||||
|
||||
@ -59,31 +63,45 @@
|
||||
|
||||
#define BUTTONS 2
|
||||
|
||||
static struct {
|
||||
int ret_cmd, flags, y, x;
|
||||
const char *text;
|
||||
} learn_but[BUTTONS] = {
|
||||
/* *INDENT-OFF */
|
||||
{ B_CANCEL, NORMAL_BUTTON, 0, 39, N_("&Cancel") },
|
||||
{ B_ENTER, DEFPUSH_BUTTON, 0, 25, N_("&Save") }
|
||||
/* *INDENT-ON */
|
||||
};
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
static Dlg_head *learn_dlg;
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
Widget *button;
|
||||
Widget *label;
|
||||
int ok;
|
||||
char *sequence;
|
||||
} learnkey;
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
static struct
|
||||
{
|
||||
int ret_cmd, flags, y, x;
|
||||
const char *text;
|
||||
} learn_but[BUTTONS] =
|
||||
{
|
||||
/* *INDENT-OFF */
|
||||
{
|
||||
B_CANCEL, NORMAL_BUTTON, 0, 39, N_("&Cancel")},
|
||||
{
|
||||
B_ENTER, DEFPUSH_BUTTON, 0, 25, N_("&Save")}
|
||||
/* *INDENT-ON */
|
||||
};
|
||||
|
||||
static Dlg_head *learn_dlg;
|
||||
|
||||
static learnkey *learnkeys = NULL;
|
||||
static int learn_total;
|
||||
static int learnok;
|
||||
static int learnchanged;
|
||||
static const char* learn_title = N_("Learn keys");
|
||||
static const char *learn_title = N_("Learn keys");
|
||||
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int learn_button (WButton *button, int action)
|
||||
static int
|
||||
learn_button (WButton * button, int action)
|
||||
{
|
||||
Dlg_head *d;
|
||||
char *seq;
|
||||
@ -91,63 +109,69 @@ static int learn_button (WButton *button, int action)
|
||||
(void) button;
|
||||
|
||||
d = create_message (D_ERROR, _("Teach me a key"),
|
||||
_("Please press the %s\n"
|
||||
"and then wait until this message disappears.\n\n"
|
||||
"Then, press it again to see if OK appears\n"
|
||||
"next to its button.\n\n"
|
||||
"If you want to escape, press a single Escape key\n"
|
||||
"and wait as well."),
|
||||
_(key_name_conv_tab [action - B_USER].longname));
|
||||
_("Please press the %s\n"
|
||||
"and then wait until this message disappears.\n\n"
|
||||
"Then, press it again to see if OK appears\n"
|
||||
"next to its button.\n\n"
|
||||
"If you want to escape, press a single Escape key\n"
|
||||
"and wait as well."), _(key_name_conv_tab[action - B_USER].longname));
|
||||
mc_refresh ();
|
||||
if (learnkeys [action - B_USER].sequence != NULL) {
|
||||
g_free (learnkeys [action - B_USER].sequence);
|
||||
learnkeys [action - B_USER].sequence = NULL;
|
||||
if (learnkeys[action - B_USER].sequence != NULL)
|
||||
{
|
||||
g_free (learnkeys[action - B_USER].sequence);
|
||||
learnkeys[action - B_USER].sequence = NULL;
|
||||
}
|
||||
seq = learn_key ();
|
||||
|
||||
if (seq){
|
||||
/* Esc hides the dialog and do not allow definitions of
|
||||
* regular characters
|
||||
*/
|
||||
gboolean seq_ok = FALSE;
|
||||
if (seq)
|
||||
{
|
||||
/* Esc hides the dialog and do not allow definitions of
|
||||
* regular characters
|
||||
*/
|
||||
gboolean seq_ok = FALSE;
|
||||
|
||||
if (*seq && strcmp (seq, "\\e") && strcmp (seq, "\\e\\e")
|
||||
&& strcmp (seq, "^m" ) && strcmp (seq, "^i" )
|
||||
&& (seq [1] || (*seq < ' ' || *seq > '~'))){
|
||||
if (*seq && strcmp (seq, "\\e") && strcmp (seq, "\\e\\e")
|
||||
&& strcmp (seq, "^m") && strcmp (seq, "^i") && (seq[1] || (*seq < ' ' || *seq > '~')))
|
||||
{
|
||||
|
||||
learnchanged = 1;
|
||||
learnkeys [action - B_USER].sequence = seq;
|
||||
seq = convert_controls (seq);
|
||||
seq_ok = define_sequence (key_name_conv_tab [action - B_USER].code,
|
||||
seq, MCKEY_NOACTION);
|
||||
}
|
||||
learnchanged = 1;
|
||||
learnkeys[action - B_USER].sequence = seq;
|
||||
seq = convert_controls (seq);
|
||||
seq_ok = define_sequence (key_name_conv_tab[action - B_USER].code, seq, MCKEY_NOACTION);
|
||||
}
|
||||
|
||||
if (!seq_ok)
|
||||
message (D_NORMAL, _("Cannot accept this key"),
|
||||
_("You have entered \"%s\""), seq);
|
||||
if (!seq_ok)
|
||||
message (D_NORMAL, _("Cannot accept this key"), _("You have entered \"%s\""), seq);
|
||||
|
||||
g_free (seq);
|
||||
g_free (seq);
|
||||
}
|
||||
|
||||
dlg_run_done (d);
|
||||
destroy_dlg (d);
|
||||
dlg_select_widget (learnkeys [action - B_USER].button);
|
||||
return 0; /* Do not kill learn_dlg */
|
||||
dlg_select_widget (learnkeys[action - B_USER].button);
|
||||
return 0; /* Do not kill learn_dlg */
|
||||
}
|
||||
|
||||
static int learn_move (int right)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
learn_move (int right)
|
||||
{
|
||||
int i, totalcols;
|
||||
|
||||
|
||||
totalcols = (learn_total - 1) / ROWS + 1;
|
||||
for (i = 0; i < learn_total; i++)
|
||||
if (learnkeys [i].button == (Widget *) learn_dlg->current->data) {
|
||||
if (right) {
|
||||
if (learnkeys[i].button == (Widget *) learn_dlg->current->data)
|
||||
{
|
||||
if (right)
|
||||
{
|
||||
if (i < learn_total - ROWS)
|
||||
i += ROWS;
|
||||
else
|
||||
else
|
||||
i %= ROWS;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
if (i / ROWS)
|
||||
i -= ROWS;
|
||||
else if (i + (totalcols - 1) * ROWS >= learn_total)
|
||||
@ -155,85 +179,97 @@ static int learn_move (int right)
|
||||
else
|
||||
i += (totalcols - 1) * ROWS;
|
||||
}
|
||||
dlg_select_widget (learnkeys [i].button);
|
||||
dlg_select_widget (learnkeys[i].button);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
learn_check_key (int c)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < learn_total; i++) {
|
||||
if (key_name_conv_tab[i].code != c || learnkeys[i].ok)
|
||||
continue;
|
||||
for (i = 0; i < learn_total; i++)
|
||||
{
|
||||
if (key_name_conv_tab[i].code != c || learnkeys[i].ok)
|
||||
continue;
|
||||
|
||||
dlg_select_widget (learnkeys[i].button);
|
||||
/* TRANSLATORS: This label appears near learned keys. Keep it short. */
|
||||
label_set_text ((WLabel *) learnkeys[i].label, _("OK"));
|
||||
learnkeys[i].ok = 1;
|
||||
learnok++;
|
||||
if (learnok >= learn_total) {
|
||||
learn_dlg->ret_value = B_CANCEL;
|
||||
if (learnchanged) {
|
||||
if (query_dialog (learn_title,
|
||||
_
|
||||
("It seems that all your keys already\n"
|
||||
"work fine. That's great."), D_ERROR, 2,
|
||||
_("&Save"), _("&Discard")) == 0)
|
||||
learn_dlg->ret_value = B_ENTER;
|
||||
} else {
|
||||
message (D_ERROR, learn_title,
|
||||
_
|
||||
("Great! You have a complete terminal database!\n"
|
||||
"All your keys work well."));
|
||||
}
|
||||
dlg_stop (learn_dlg);
|
||||
}
|
||||
return 1;
|
||||
dlg_select_widget (learnkeys[i].button);
|
||||
/* TRANSLATORS: This label appears near learned keys. Keep it short. */
|
||||
label_set_text ((WLabel *) learnkeys[i].label, _("OK"));
|
||||
learnkeys[i].ok = 1;
|
||||
learnok++;
|
||||
if (learnok >= learn_total)
|
||||
{
|
||||
learn_dlg->ret_value = B_CANCEL;
|
||||
if (learnchanged)
|
||||
{
|
||||
if (query_dialog (learn_title,
|
||||
_
|
||||
("It seems that all your keys already\n"
|
||||
"work fine. That's great."), D_ERROR, 2,
|
||||
_("&Save"), _("&Discard")) == 0)
|
||||
learn_dlg->ret_value = B_ENTER;
|
||||
}
|
||||
else
|
||||
{
|
||||
message (D_ERROR, learn_title,
|
||||
_
|
||||
("Great! You have a complete terminal database!\n"
|
||||
"All your keys work well."));
|
||||
}
|
||||
dlg_stop (learn_dlg);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
switch (c) {
|
||||
switch (c)
|
||||
{
|
||||
case KEY_LEFT:
|
||||
case 'h':
|
||||
return learn_move (0);
|
||||
return learn_move (0);
|
||||
case KEY_RIGHT:
|
||||
case 'l':
|
||||
return learn_move (1);
|
||||
return learn_move (1);
|
||||
case 'j':
|
||||
dlg_one_down (learn_dlg);
|
||||
return 1;
|
||||
dlg_one_down (learn_dlg);
|
||||
return 1;
|
||||
case 'k':
|
||||
dlg_one_up (learn_dlg);
|
||||
return 1;
|
||||
dlg_one_up (learn_dlg);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Prevent from disappearing if a non-defined sequence is pressed
|
||||
and contains a button hotkey. Only recognize hotkeys with ALT. */
|
||||
if (c < 255 && g_ascii_isalnum (c))
|
||||
return 1;
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static cb_ret_t
|
||||
learn_callback (Dlg_head *h, Widget *sender,
|
||||
dlg_msg_t msg, int parm, void *data)
|
||||
learn_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
|
||||
{
|
||||
switch (msg) {
|
||||
switch (msg)
|
||||
{
|
||||
case DLG_DRAW:
|
||||
common_dialog_repaint (h);
|
||||
return MSG_HANDLED;
|
||||
common_dialog_repaint (h);
|
||||
return MSG_HANDLED;
|
||||
|
||||
case DLG_KEY:
|
||||
return learn_check_key (parm);
|
||||
return learn_check_key (parm);
|
||||
|
||||
default:
|
||||
return default_dlg_callback (h, sender, msg, parm, data);
|
||||
return default_dlg_callback (h, sender, msg, parm, data);
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
init_learn (void)
|
||||
{
|
||||
@ -243,78 +279,79 @@ init_learn (void)
|
||||
|
||||
#ifdef ENABLE_NLS
|
||||
static int i18n_flag = 0;
|
||||
if (!i18n_flag) {
|
||||
learn_but[0].text = _(learn_but[0].text);
|
||||
learn_but[0].x = 78 / 2 + 4;
|
||||
if (!i18n_flag)
|
||||
{
|
||||
learn_but[0].text = _(learn_but[0].text);
|
||||
learn_but[0].x = 78 / 2 + 4;
|
||||
|
||||
learn_but[1].text = _(learn_but[1].text);
|
||||
learn_but[1].x = 78 / 2 - (str_term_width1 (learn_but[1].text) + 9);
|
||||
learn_but[1].text = _(learn_but[1].text);
|
||||
learn_but[1].x = 78 / 2 - (str_term_width1 (learn_but[1].text) + 9);
|
||||
|
||||
learn_title = _(learn_title);
|
||||
i18n_flag = 1;
|
||||
learn_title = _(learn_title);
|
||||
i18n_flag = 1;
|
||||
}
|
||||
#endif /* ENABLE_NLS */
|
||||
#endif /* ENABLE_NLS */
|
||||
|
||||
do_refresh ();
|
||||
|
||||
learn_dlg =
|
||||
create_dlg (TRUE, 0, 0, 23, 78, dialog_colors, learn_callback,
|
||||
"[Learn keys]", learn_title, DLG_CENTER | DLG_REVERSE);
|
||||
create_dlg (TRUE, 0, 0, 23, 78, dialog_colors, learn_callback,
|
||||
"[Learn keys]", learn_title, DLG_CENTER | DLG_REVERSE);
|
||||
|
||||
for (i = 0; i < BUTTONS; i++)
|
||||
add_widget (learn_dlg,
|
||||
button_new (BY + learn_but[i].y, learn_but[i].x,
|
||||
learn_but[i].ret_cmd, learn_but[i].flags,
|
||||
_(learn_but[i].text), 0));
|
||||
add_widget (learn_dlg,
|
||||
button_new (BY + learn_but[i].y, learn_but[i].x,
|
||||
learn_but[i].ret_cmd, learn_but[i].flags, _(learn_but[i].text), 0));
|
||||
|
||||
x = UX;
|
||||
y = UY;
|
||||
for (key = key_name_conv_tab, j = 0;
|
||||
key->name != NULL && strcmp (key->name, "kpleft");
|
||||
key++, j++)
|
||||
;
|
||||
key->name != NULL && strcmp (key->name, "kpleft"); key++, j++)
|
||||
;
|
||||
learnkeys = g_new (learnkey, j);
|
||||
x += ((j - 1) / ROWS) * COLSHIFT;
|
||||
y += (j - 1) % ROWS;
|
||||
learn_total = j;
|
||||
learnok = 0;
|
||||
learnchanged = 0;
|
||||
for (i = j - 1, key = key_name_conv_tab + j - 1; i >= 0; i--, key--) {
|
||||
learnkeys[i].ok = 0;
|
||||
learnkeys[i].sequence = NULL;
|
||||
g_snprintf (buffer, sizeof (buffer), "%-16s", _(key->longname));
|
||||
add_widget (learn_dlg, learnkeys[i].button = (Widget *)
|
||||
button_new (y, x, B_USER + i, NARROW_BUTTON, buffer,
|
||||
learn_button));
|
||||
add_widget (learn_dlg, learnkeys[i].label = (Widget *)
|
||||
label_new (y, x + 19, ""));
|
||||
if (i % 13)
|
||||
y--;
|
||||
else {
|
||||
x -= COLSHIFT;
|
||||
y = UY + ROWS - 1;
|
||||
}
|
||||
for (i = j - 1, key = key_name_conv_tab + j - 1; i >= 0; i--, key--)
|
||||
{
|
||||
learnkeys[i].ok = 0;
|
||||
learnkeys[i].sequence = NULL;
|
||||
g_snprintf (buffer, sizeof (buffer), "%-16s", _(key->longname));
|
||||
add_widget (learn_dlg, learnkeys[i].button = (Widget *)
|
||||
button_new (y, x, B_USER + i, NARROW_BUTTON, buffer, learn_button));
|
||||
add_widget (learn_dlg, learnkeys[i].label = (Widget *) label_new (y, x + 19, ""));
|
||||
if (i % 13)
|
||||
y--;
|
||||
else
|
||||
{
|
||||
x -= COLSHIFT;
|
||||
y = UY + ROWS - 1;
|
||||
}
|
||||
}
|
||||
add_widget (learn_dlg,
|
||||
label_new (UY + 14, 5,
|
||||
_
|
||||
("Press all the keys mentioned here. After you have done it, check")));
|
||||
label_new (UY + 14, 5,
|
||||
_("Press all the keys mentioned here. After you have done it, check")));
|
||||
add_widget (learn_dlg,
|
||||
label_new (UY + 15, 5,
|
||||
_
|
||||
("which keys are not marked with OK. Press space on the missing")));
|
||||
label_new (UY + 15, 5,
|
||||
_("which keys are not marked with OK. Press space on the missing")));
|
||||
add_widget (learn_dlg,
|
||||
label_new (UY + 16, 5,
|
||||
_
|
||||
("key, or click with the mouse to define it. Move around with Tab.")));
|
||||
label_new (UY + 16, 5,
|
||||
_("key, or click with the mouse to define it. Move around with Tab.")));
|
||||
}
|
||||
|
||||
static void learn_done (void)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
learn_done (void)
|
||||
{
|
||||
destroy_dlg (learn_dlg);
|
||||
repaint_screen ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
learn_save (void)
|
||||
{
|
||||
@ -323,17 +360,19 @@ learn_save (void)
|
||||
char *section = g_strconcat ("terminal:", getenv ("TERM"), (char *) NULL);
|
||||
char *esc_str;
|
||||
|
||||
for (i = 0; i < learn_total; i++) {
|
||||
if (learnkeys [i].sequence != NULL) {
|
||||
profile_changed = 1;
|
||||
for (i = 0; i < learn_total; i++)
|
||||
{
|
||||
if (learnkeys[i].sequence != NULL)
|
||||
{
|
||||
profile_changed = 1;
|
||||
|
||||
esc_str = strutils_escape (learnkeys [i].sequence, -1, ";\\", TRUE);
|
||||
esc_str = strutils_escape (learnkeys[i].sequence, -1, ";\\", TRUE);
|
||||
|
||||
mc_config_direct_set_string(mc_main_config, section,
|
||||
key_name_conv_tab [i].name, esc_str);
|
||||
mc_config_direct_set_string (mc_main_config, section,
|
||||
key_name_conv_tab[i].name, esc_str);
|
||||
|
||||
g_free(esc_str);
|
||||
}
|
||||
g_free (esc_str);
|
||||
}
|
||||
}
|
||||
|
||||
/* On the one hand no good idea to save the complete setup but
|
||||
@ -343,32 +382,38 @@ learn_save (void)
|
||||
* disk is much worse.
|
||||
*/
|
||||
if (profile_changed)
|
||||
mc_config_save_file (mc_main_config, NULL);
|
||||
mc_config_save_file (mc_main_config, NULL);
|
||||
|
||||
g_free (section);
|
||||
}
|
||||
|
||||
void learn_keys (void)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
learn_keys (void)
|
||||
{
|
||||
int save_old_esc_mode = old_esc_mode;
|
||||
int save_alternate_plus_minus = alternate_plus_minus;
|
||||
|
||||
old_esc_mode = 0; /* old_esc_mode cannot work in learn keys dialog */
|
||||
alternate_plus_minus = 1; /* don't translate KP_ADD, KP_SUBTRACT and
|
||||
KP_MULTIPLY to '+', '-' and '*' in
|
||||
correct_key_code */
|
||||
|
||||
old_esc_mode = 0; /* old_esc_mode cannot work in learn keys dialog */
|
||||
alternate_plus_minus = 1; /* don't translate KP_ADD, KP_SUBTRACT and
|
||||
KP_MULTIPLY to '+', '-' and '*' in
|
||||
correct_key_code */
|
||||
application_keypad_mode ();
|
||||
init_learn ();
|
||||
|
||||
run_dlg (learn_dlg);
|
||||
|
||||
|
||||
old_esc_mode = save_old_esc_mode;
|
||||
alternate_plus_minus = save_alternate_plus_minus;
|
||||
|
||||
if (!alternate_plus_minus)
|
||||
numeric_keypad_mode ();
|
||||
|
||||
switch (learn_dlg->ret_value) {
|
||||
|
||||
switch (learn_dlg->ret_value)
|
||||
{
|
||||
case B_ENTER:
|
||||
learn_save ();
|
||||
break;
|
||||
@ -377,3 +422,4 @@ void learn_keys (void)
|
||||
learn_done ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
18
src/learn.h
18
src/learn.h
@ -1,11 +1,21 @@
|
||||
|
||||
/** \file learn.h
|
||||
* \brief Header: learn keys module
|
||||
*/
|
||||
|
||||
#ifndef MC_LEARN_H
|
||||
#define MC_LEARN_H
|
||||
#ifndef MC__LEARN_H
|
||||
#define MC__LEARN_H
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
void learn_keys (void);
|
||||
|
||||
#endif
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__LEARN_H */
|
||||
|
214
src/listmode.c
214
src/listmode.c
@ -3,7 +3,7 @@
|
||||
2006, 2007 Free Software Foundation, Inc.
|
||||
|
||||
Written by: 1994 Radek Doulik
|
||||
1995 Janne Kukonlehto
|
||||
1995 Janne Kukonlehto
|
||||
|
||||
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
|
||||
@ -45,12 +45,16 @@
|
||||
|
||||
/* Needed for the extern declarations of integer parameters */
|
||||
#include "dir.h"
|
||||
#include "panel.h" /* Needed for the externs */
|
||||
#include "panel.h" /* Needed for the externs */
|
||||
#include "file.h"
|
||||
#include "layout.h" /* repaint_screen() */
|
||||
#include "layout.h" /* repaint_screen() */
|
||||
#include "main.h"
|
||||
#include "listmode.h"
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
#define UX 5
|
||||
#define UY 2
|
||||
|
||||
@ -60,6 +64,26 @@
|
||||
#define B_ADD B_USER
|
||||
#define B_REMOVE (B_USER + 1)
|
||||
|
||||
#define B_PLUS B_USER
|
||||
#define B_MINUS (B_USER+1)
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
struct listmode_button
|
||||
{
|
||||
int ret_cmd, flags, y, x;
|
||||
char *text;
|
||||
bcback callback;
|
||||
};
|
||||
|
||||
struct listmode_label
|
||||
{
|
||||
int y, x;
|
||||
char *text;
|
||||
};
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
static WListbox *l_listmode;
|
||||
|
||||
static WLabel *pname;
|
||||
@ -67,29 +91,20 @@ static WLabel *pname;
|
||||
static char *listmode_section = "[Listing format edit]";
|
||||
|
||||
static char *s_genwidth[2] = { "Half width", "Full width" };
|
||||
|
||||
static WRadio *radio_genwidth;
|
||||
static char *s_columns[2] = { "One column", "Two columns" };
|
||||
|
||||
static WRadio *radio_columns;
|
||||
static char *s_justify[3] =
|
||||
{ "Left justified", "Default justification", "Right justified" };
|
||||
static char *s_justify[3] = { "Left justified", "Default justification", "Right justified" };
|
||||
|
||||
static WRadio *radio_justify;
|
||||
static char *s_itemwidth[3] =
|
||||
{ "Free width", "Fixed width", "Growable width" };
|
||||
static char *s_itemwidth[3] = { "Free width", "Fixed width", "Growable width" };
|
||||
|
||||
static WRadio *radio_itemwidth;
|
||||
|
||||
struct listmode_button {
|
||||
int ret_cmd, flags, y, x;
|
||||
char *text;
|
||||
bcback callback;
|
||||
};
|
||||
|
||||
#define B_PLUS B_USER
|
||||
#define B_MINUS (B_USER+1)
|
||||
|
||||
struct listmode_label {
|
||||
int y, x;
|
||||
char *text;
|
||||
};
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static char *
|
||||
select_new_item (void)
|
||||
@ -99,46 +114,54 @@ select_new_item (void)
|
||||
int i;
|
||||
Listbox *mylistbox;
|
||||
|
||||
possible_items = panel_get_user_possible_fields(NULL);
|
||||
possible_items = panel_get_user_possible_fields (NULL);
|
||||
|
||||
mylistbox =
|
||||
create_listbox_window (20, 12, "Add listing format item",
|
||||
listmode_section);
|
||||
for (i = 0; possible_items[i]; i++) {
|
||||
listbox_add_item (mylistbox->list, LISTBOX_APPEND_AT_END, 0, possible_items[i], NULL);
|
||||
mylistbox = create_listbox_window (20, 12, "Add listing format item", listmode_section);
|
||||
for (i = 0; possible_items[i]; i++)
|
||||
{
|
||||
listbox_add_item (mylistbox->list, LISTBOX_APPEND_AT_END, 0, possible_items[i], NULL);
|
||||
}
|
||||
|
||||
i = run_listbox (mylistbox);
|
||||
if (i >= 0)
|
||||
ret = g_strdup(possible_items[i]);
|
||||
ret = g_strdup (possible_items[i]);
|
||||
|
||||
g_strfreev (possible_items);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
bplus_cback (int action)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
bminus_cback (int action)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
badd_cback (int action)
|
||||
{
|
||||
char *s = select_new_item ();
|
||||
if (s) {
|
||||
listbox_add_item (l_listmode, LISTBOX_APPEND_AT_END, 0, s, NULL);
|
||||
g_free(s);
|
||||
if (s)
|
||||
{
|
||||
listbox_add_item (l_listmode, LISTBOX_APPEND_AT_END, 0, s, NULL);
|
||||
g_free (s);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
bremove_cback (int action)
|
||||
{
|
||||
@ -146,6 +169,8 @@ bremove_cback (int action)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static Dlg_head *
|
||||
init_listmode (char *oldlistformat)
|
||||
{
|
||||
@ -156,47 +181,40 @@ init_listmode (char *oldlistformat)
|
||||
Dlg_head *listmode_dlg;
|
||||
|
||||
static struct listmode_label listmode_labels[] = {
|
||||
{UY + 13, UX + 22, "Item width:"}
|
||||
{UY + 13, UX + 22, "Item width:"}
|
||||
};
|
||||
|
||||
static struct listmode_button listmode_but[] = {
|
||||
{B_CANCEL, NORMAL_BUTTON, BY, BX + 53, "&Cancel", NULL},
|
||||
{B_ADD, NORMAL_BUTTON, BY, BX + 22, "&Add item", badd_cback},
|
||||
{B_REMOVE, NORMAL_BUTTON, BY, BX + 10, "&Remove", bremove_cback},
|
||||
{B_ENTER, DEFPUSH_BUTTON, BY, BX, "&OK", NULL},
|
||||
{B_PLUS, NARROW_BUTTON, UY + 13, UX + 37, "&+", bplus_cback},
|
||||
{B_MINUS, NARROW_BUTTON, UY + 13, UX + 34, "&-", bminus_cback},
|
||||
{B_CANCEL, NORMAL_BUTTON, BY, BX + 53, "&Cancel", NULL},
|
||||
{B_ADD, NORMAL_BUTTON, BY, BX + 22, "&Add item", badd_cback},
|
||||
{B_REMOVE, NORMAL_BUTTON, BY, BX + 10, "&Remove", bremove_cback},
|
||||
{B_ENTER, DEFPUSH_BUTTON, BY, BX, "&OK", NULL},
|
||||
{B_PLUS, NARROW_BUTTON, UY + 13, UX + 37, "&+", bplus_cback},
|
||||
{B_MINUS, NARROW_BUTTON, UY + 13, UX + 34, "&-", bminus_cback},
|
||||
};
|
||||
|
||||
do_refresh ();
|
||||
|
||||
listmode_dlg =
|
||||
create_dlg (TRUE, 0, 0, 22, 74, dialog_colors, NULL, listmode_section,
|
||||
"Listing format edit", DLG_CENTER | DLG_REVERSE);
|
||||
create_dlg (TRUE, 0, 0, 22, 74, dialog_colors, NULL, listmode_section,
|
||||
"Listing format edit", DLG_CENTER | DLG_REVERSE);
|
||||
|
||||
add_widget (listmode_dlg,
|
||||
groupbox_new (UY, UX, 4, 63, "General options"));
|
||||
add_widget (listmode_dlg, groupbox_new (UY, UX, 4, 63, "General options"));
|
||||
add_widget (listmode_dlg, groupbox_new (UY + 4, UX, 11, 18, "Items"));
|
||||
add_widget (listmode_dlg,
|
||||
groupbox_new (UY + 4, UX + 20, 11, 43, "Item options"));
|
||||
add_widget (listmode_dlg, groupbox_new (UY + 4, UX + 20, 11, 43, "Item options"));
|
||||
|
||||
for (i = 0;
|
||||
i < sizeof (listmode_but) / sizeof (struct listmode_button); i++)
|
||||
add_widget (listmode_dlg,
|
||||
button_new (listmode_but[i].y, listmode_but[i].x,
|
||||
listmode_but[i].ret_cmd,
|
||||
listmode_but[i].flags,
|
||||
listmode_but[i].text,
|
||||
listmode_but[i].callback));
|
||||
for (i = 0; i < sizeof (listmode_but) / sizeof (struct listmode_button); i++)
|
||||
add_widget (listmode_dlg,
|
||||
button_new (listmode_but[i].y, listmode_but[i].x,
|
||||
listmode_but[i].ret_cmd,
|
||||
listmode_but[i].flags,
|
||||
listmode_but[i].text, listmode_but[i].callback));
|
||||
|
||||
/* We add the labels. */
|
||||
for (i = 0;
|
||||
i < sizeof (listmode_labels) / sizeof (struct listmode_label);
|
||||
i++) {
|
||||
pname =
|
||||
label_new (listmode_labels[i].y, listmode_labels[i].x,
|
||||
listmode_labels[i].text);
|
||||
add_widget (listmode_dlg, pname);
|
||||
for (i = 0; i < sizeof (listmode_labels) / sizeof (struct listmode_label); i++)
|
||||
{
|
||||
pname = label_new (listmode_labels[i].y, listmode_labels[i].x, listmode_labels[i].text);
|
||||
add_widget (listmode_dlg, pname);
|
||||
}
|
||||
|
||||
radio_itemwidth = radio_new (UY + 9, UX + 22, 3, s_itemwidth);
|
||||
@ -209,25 +227,30 @@ init_listmode (char *oldlistformat)
|
||||
/* get new listbox */
|
||||
l_listmode = listbox_new (UY + 5, UX + 1, 9, 16, FALSE, NULL);
|
||||
|
||||
if (strncmp (oldlistformat, "full ", 5) == 0) {
|
||||
format_width = 1;
|
||||
oldlistformat += 5;
|
||||
if (strncmp (oldlistformat, "full ", 5) == 0)
|
||||
{
|
||||
format_width = 1;
|
||||
oldlistformat += 5;
|
||||
}
|
||||
if (strncmp (oldlistformat, "half ", 5) == 0) {
|
||||
oldlistformat += 5;
|
||||
if (strncmp (oldlistformat, "half ", 5) == 0)
|
||||
{
|
||||
oldlistformat += 5;
|
||||
}
|
||||
if (strncmp (oldlistformat, "2 ", 2) == 0) {
|
||||
format_columns = 1;
|
||||
oldlistformat += 2;
|
||||
if (strncmp (oldlistformat, "2 ", 2) == 0)
|
||||
{
|
||||
format_columns = 1;
|
||||
oldlistformat += 2;
|
||||
}
|
||||
if (strncmp (oldlistformat, "1 ", 2) == 0) {
|
||||
oldlistformat += 2;
|
||||
if (strncmp (oldlistformat, "1 ", 2) == 0)
|
||||
{
|
||||
oldlistformat += 2;
|
||||
}
|
||||
s = strtok (oldlistformat, ",");
|
||||
|
||||
while (s) {
|
||||
listbox_add_item (l_listmode, LISTBOX_APPEND_AT_END, 0, s, NULL);
|
||||
s = strtok (NULL, ",");
|
||||
while (s)
|
||||
{
|
||||
listbox_add_item (l_listmode, LISTBOX_APPEND_AT_END, 0, s, NULL);
|
||||
s = strtok (NULL, ",");
|
||||
}
|
||||
|
||||
/* add listbox to the dialogs */
|
||||
@ -243,15 +266,19 @@ init_listmode (char *oldlistformat)
|
||||
return listmode_dlg;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
listmode_done (Dlg_head *h)
|
||||
listmode_done (Dlg_head * h)
|
||||
{
|
||||
destroy_dlg (h);
|
||||
if (0)
|
||||
update_panels (UP_OPTIMIZE, UP_KEEPSEL);
|
||||
update_panels (UP_OPTIMIZE, UP_KEEPSEL);
|
||||
repaint_screen ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static char *
|
||||
collect_new_format (void)
|
||||
{
|
||||
@ -262,26 +289,31 @@ collect_new_format (void)
|
||||
|
||||
newformat = g_malloc (1024);
|
||||
if (radio_genwidth->sel)
|
||||
strcpy (newformat, "full ");
|
||||
strcpy (newformat, "full ");
|
||||
else
|
||||
strcpy (newformat, "half ");
|
||||
strcpy (newformat, "half ");
|
||||
if (radio_columns->sel)
|
||||
strcat (newformat, "2 ");
|
||||
strcat (newformat, "2 ");
|
||||
last = NULL;
|
||||
for (i = 0;; i++) {
|
||||
listbox_select_entry (l_listmode, i);
|
||||
listbox_get_current (l_listmode, &text, &extra);
|
||||
if (text == last)
|
||||
break;
|
||||
if (last != NULL)
|
||||
strcat (newformat, ",");
|
||||
strcat (newformat, text);
|
||||
last = text;
|
||||
for (i = 0;; i++)
|
||||
{
|
||||
listbox_select_entry (l_listmode, i);
|
||||
listbox_get_current (l_listmode, &text, &extra);
|
||||
if (text == last)
|
||||
break;
|
||||
if (last != NULL)
|
||||
strcat (newformat, ",");
|
||||
strcat (newformat, text);
|
||||
last = text;
|
||||
}
|
||||
return newformat;
|
||||
}
|
||||
|
||||
/* Return new format or NULL if the user cancelled the dialog */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/** Return new format or NULL if the user cancelled the dialog */
|
||||
char *
|
||||
listmode_edit (char *oldlistformat)
|
||||
{
|
||||
@ -293,11 +325,15 @@ listmode_edit (char *oldlistformat)
|
||||
listmode_dlg = init_listmode (s);
|
||||
g_free (s);
|
||||
|
||||
if (run_dlg (listmode_dlg) == B_ENTER) {
|
||||
newformat = collect_new_format ();
|
||||
if (run_dlg (listmode_dlg) == B_ENTER)
|
||||
{
|
||||
newformat = collect_new_format ();
|
||||
}
|
||||
|
||||
listmode_done (listmode_dlg);
|
||||
return newformat;
|
||||
}
|
||||
#endif /* LISTMODE_EDITOR */
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
#endif /* LISTMODE_EDITOR */
|
||||
|
@ -1,13 +1,22 @@
|
||||
|
||||
/** \file listmode.h
|
||||
* \brief Header: directory panel listing format editor
|
||||
*/
|
||||
|
||||
#ifndef MC_LISTMODE_H
|
||||
#define MC_LISTMODE_H
|
||||
#ifndef MC__LISTMODE_H
|
||||
#define MC__LISTMODE_H
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
#ifdef LISTMODE_EDITOR
|
||||
char *listmode_edit (char*);
|
||||
char *listmode_edit (char *);
|
||||
#endif /* LISTMODE_EDITOR */
|
||||
|
||||
#endif
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__LISTMODE_H */
|
||||
|
@ -1,19 +1,29 @@
|
||||
|
||||
/** \file main-widgets.h
|
||||
* \brief Header: provides definitions for some widgets
|
||||
*/
|
||||
|
||||
#ifndef MC_MAIN_WIDGETS_H
|
||||
#define MC_MAIN_WIDGETS_H
|
||||
#ifndef MC__MAIN_WIDGETS_H
|
||||
#define MC__MAIN_WIDGETS_H
|
||||
|
||||
#include "widget.h"
|
||||
#include "dialog.h"
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
extern WButtonBar *the_bar;
|
||||
extern WLabel *the_prompt;
|
||||
extern WLabel *the_hint;
|
||||
extern Dlg_head *midnight_dlg;
|
||||
extern WLabel *the_prompt;
|
||||
extern WLabel *the_hint;
|
||||
extern Dlg_head *midnight_dlg;
|
||||
|
||||
extern struct WMenuBar *the_menubar;
|
||||
|
||||
#endif
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__MAIN_WIDGETS_H */
|
||||
|
735
src/main.c
735
src/main.c
File diff suppressed because it is too large
Load Diff
78
src/main.h
78
src/main.h
@ -1,14 +1,21 @@
|
||||
|
||||
/** \file main.h
|
||||
* \brief Header: this is a main module header
|
||||
*/
|
||||
|
||||
#ifndef MC_MAIN_H
|
||||
#define MC_MAIN_H
|
||||
#ifndef MC__MAIN_H
|
||||
#define MC__MAIN_H
|
||||
|
||||
#include "lib/global.h"
|
||||
#include "keybind.h"
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
#define MENU_PANEL (is_right ? right_panel : left_panel)
|
||||
#define MENU_PANEL_IDX (is_right ? 1 : 0)
|
||||
#define SELECTED_IS_PANEL (get_display_type (is_right ? 1 : 0) == view_listing)
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/* run mode and params */
|
||||
typedef enum
|
||||
{
|
||||
@ -18,6 +25,25 @@ typedef enum
|
||||
MC_RUN_DIFFVIEWER
|
||||
} mc_run_mode_t;
|
||||
|
||||
/* If true, after executing a command, wait for a keystroke */
|
||||
enum
|
||||
{ pause_never, pause_on_dumb_terminals, pause_always };
|
||||
|
||||
enum cd_enum
|
||||
{
|
||||
cd_parse_command,
|
||||
cd_exact
|
||||
};
|
||||
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
struct WButtonBar;
|
||||
|
||||
struct mc_fhl_struct;
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
extern mc_run_mode_t mc_run_mode;
|
||||
/*
|
||||
* MC_RUN_FULL: dir for left panel
|
||||
@ -34,20 +60,9 @@ extern char *mc_run_param0;
|
||||
*/
|
||||
extern char *mc_run_param1;
|
||||
|
||||
void toggle_show_hidden (void);
|
||||
|
||||
extern int quote;
|
||||
extern volatile int quit;
|
||||
|
||||
/* If true, after executing a command, wait for a keystroke */
|
||||
enum { pause_never, pause_on_dumb_terminals, pause_always };
|
||||
|
||||
void subshell_chdir (const char *command);
|
||||
|
||||
struct WButtonBar;
|
||||
|
||||
void midnight_set_buttonbar (struct WButtonBar *b);
|
||||
|
||||
/* See main.c for details on these variables */
|
||||
extern int auto_menu;
|
||||
extern int pause_after_run;
|
||||
@ -95,26 +110,31 @@ extern char *shell;
|
||||
extern int auto_fill_mkdir_name;
|
||||
/* Ugly hack in order to distinguish between left and right panel in menubar */
|
||||
extern int is_right; /* If the selected menu was the right */
|
||||
#define MENU_PANEL (is_right ? right_panel : left_panel)
|
||||
#define MENU_PANEL_IDX (is_right ? 1 : 0)
|
||||
#define SELECTED_IS_PANEL (get_display_type (is_right ? 1 : 0) == view_listing)
|
||||
|
||||
extern const char *mc_prompt;
|
||||
extern char *mc_home;
|
||||
extern char *mc_home_alt;
|
||||
|
||||
extern struct mc_fhl_struct *mc_filehighlight;
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
void toggle_show_hidden (void);
|
||||
|
||||
void subshell_chdir (const char *command);
|
||||
|
||||
void midnight_set_buttonbar (struct WButtonBar *b);
|
||||
|
||||
#ifdef HAVE_SUBSHELL_SUPPORT
|
||||
void do_update_prompt (void);
|
||||
int load_prompt (int fd, void *unused);
|
||||
#endif
|
||||
|
||||
enum cd_enum
|
||||
{
|
||||
cd_parse_command,
|
||||
cd_exact
|
||||
};
|
||||
|
||||
int do_cd (const char *new_dir, enum cd_enum cd_type);
|
||||
void sort_cmd (void);
|
||||
void change_panel (void);
|
||||
void save_cwds_stat (void);
|
||||
gboolean quiet_quit_cmd (void); /* For cmd.c and command.c */
|
||||
gboolean quiet_quit_cmd (void); /* For cmd.c and command.c */
|
||||
|
||||
void touch_bar (void);
|
||||
void update_xterm_title_path (void);
|
||||
@ -122,13 +142,6 @@ void load_hint (int force);
|
||||
|
||||
void print_vfs_message (const char *msg, ...) __attribute__ ((format (__printf__, 1, 2)));
|
||||
|
||||
extern const char *mc_prompt;
|
||||
extern char *mc_home;
|
||||
extern char *mc_home_alt;
|
||||
|
||||
struct mc_fhl_struct;
|
||||
extern struct mc_fhl_struct *mc_filehighlight;
|
||||
|
||||
char *get_mc_lib_dir (void);
|
||||
|
||||
void done_menu (void);
|
||||
@ -136,4 +149,5 @@ void init_menu (void);
|
||||
|
||||
char *remove_encoding_from_path (const char *);
|
||||
|
||||
#endif /* MC_MAIN_H */
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__MAIN_H */
|
||||
|
171
src/menu.c
171
src/menu.c
@ -41,34 +41,20 @@
|
||||
#include "main.h" /* is_right */
|
||||
#include "menu.h"
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
int menubar_visible = 1; /* This is the new default */
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
static cb_ret_t menubar_callback (Widget * w, widget_msg_t msg, int parm);
|
||||
|
||||
menu_entry_t *
|
||||
menu_entry_create (const char *name, unsigned long command)
|
||||
{
|
||||
menu_entry_t *entry;
|
||||
|
||||
entry = g_new (menu_entry_t, 1);
|
||||
entry->first_letter = ' ';
|
||||
entry->text = parse_hotkey (name);
|
||||
entry->command = command;
|
||||
entry->shortcut = NULL;
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
void
|
||||
menu_entry_free (menu_entry_t * entry)
|
||||
{
|
||||
if (entry != NULL)
|
||||
{
|
||||
release_hotkey (entry->text);
|
||||
g_free (entry->shortcut);
|
||||
g_free (entry);
|
||||
}
|
||||
}
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
menu_arrange (Menu * menu, dlg_shortcut_str get_shortcut)
|
||||
@ -107,32 +93,7 @@ menu_arrange (Menu * menu, dlg_shortcut_str get_shortcut)
|
||||
}
|
||||
}
|
||||
|
||||
Menu *
|
||||
create_menu (const char *name, GList * entries, const char *help_node)
|
||||
{
|
||||
Menu *menu;
|
||||
|
||||
menu = g_new (Menu, 1);
|
||||
menu->start_x = 0;
|
||||
menu->text = parse_hotkey (name);
|
||||
menu->entries = entries;
|
||||
menu->max_entry_len = 1;
|
||||
menu->max_hotkey_len = 0;
|
||||
menu->selected = 0;
|
||||
menu->help_node = g_strdup (help_node);
|
||||
|
||||
return menu;
|
||||
}
|
||||
|
||||
void
|
||||
destroy_menu (Menu * menu)
|
||||
{
|
||||
release_hotkey (menu->text);
|
||||
g_list_foreach (menu->entries, (GFunc) menu_entry_free, NULL);
|
||||
g_list_free (menu->entries);
|
||||
g_free (menu->help_node);
|
||||
g_free (menu);
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
menubar_paint_idx (WMenuBar * menubar, unsigned int idx, int color)
|
||||
@ -189,6 +150,8 @@ menubar_paint_idx (WMenuBar * menubar, unsigned int idx, int color)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
menubar_draw_drop (WMenuBar * menubar)
|
||||
{
|
||||
@ -210,6 +173,8 @@ menubar_draw_drop (WMenuBar * menubar)
|
||||
i == menu->selected ? MENU_SELECTED_COLOR : MENU_ENTRY_COLOR);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
menubar_set_color (WMenuBar * menubar, gboolean current, gboolean hotkey)
|
||||
{
|
||||
@ -221,6 +186,8 @@ menubar_set_color (WMenuBar * menubar, gboolean current, gboolean hotkey)
|
||||
tty_setcolor (hotkey ? MENU_HOT_COLOR : MENU_ENTRY_COLOR);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
menubar_draw (WMenuBar * menubar)
|
||||
{
|
||||
@ -262,6 +229,8 @@ menubar_draw (WMenuBar * menubar)
|
||||
((Menu *) g_list_nth_data (menubar->menu, menubar->selected))->start_x);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
menubar_remove (WMenuBar * menubar)
|
||||
{
|
||||
@ -273,6 +242,8 @@ menubar_remove (WMenuBar * menubar)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
menubar_left (WMenuBar * menubar)
|
||||
{
|
||||
@ -284,6 +255,8 @@ menubar_left (WMenuBar * menubar)
|
||||
menubar_draw (menubar);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
menubar_right (WMenuBar * menubar)
|
||||
{
|
||||
@ -292,6 +265,8 @@ menubar_right (WMenuBar * menubar)
|
||||
menubar_draw (menubar);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
menubar_finish (WMenuBar * menubar)
|
||||
{
|
||||
@ -304,6 +279,8 @@ menubar_finish (WMenuBar * menubar)
|
||||
do_refresh ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
menubar_drop (WMenuBar * menubar, unsigned int selected)
|
||||
{
|
||||
@ -312,6 +289,8 @@ menubar_drop (WMenuBar * menubar, unsigned int selected)
|
||||
menubar_draw (menubar);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
menubar_execute (WMenuBar * menubar)
|
||||
{
|
||||
@ -328,6 +307,8 @@ menubar_execute (WMenuBar * menubar)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
menubar_down (WMenuBar * menubar)
|
||||
{
|
||||
@ -347,6 +328,8 @@ menubar_down (WMenuBar * menubar)
|
||||
menubar_paint_idx (menubar, menu->selected, MENU_SELECTED_COLOR);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
menubar_up (WMenuBar * menubar)
|
||||
{
|
||||
@ -369,6 +352,8 @@ menubar_up (WMenuBar * menubar)
|
||||
menubar_paint_idx (menubar, menu->selected, MENU_SELECTED_COLOR);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
menubar_first (WMenuBar * menubar)
|
||||
{
|
||||
@ -395,6 +380,8 @@ menubar_first (WMenuBar * menubar)
|
||||
menubar_paint_idx (menubar, menu->selected, MENU_SELECTED_COLOR);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
menubar_last (WMenuBar * menubar)
|
||||
{
|
||||
@ -419,6 +406,8 @@ menubar_last (WMenuBar * menubar)
|
||||
menubar_paint_idx (menubar, menu->selected, MENU_SELECTED_COLOR);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
menubar_handle_key (WMenuBar * menubar, int key)
|
||||
{
|
||||
@ -530,6 +519,8 @@ menubar_handle_key (WMenuBar * menubar, int key)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static cb_ret_t
|
||||
menubar_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
{
|
||||
@ -590,6 +581,8 @@ menubar_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
menubar_event (Gpm_Event * event, void *data)
|
||||
{
|
||||
@ -714,6 +707,70 @@ menubar_event (Gpm_Event * event, void *data)
|
||||
return MOU_NORMAL;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
menu_entry_t *
|
||||
menu_entry_create (const char *name, unsigned long command)
|
||||
{
|
||||
menu_entry_t *entry;
|
||||
|
||||
entry = g_new (menu_entry_t, 1);
|
||||
entry->first_letter = ' ';
|
||||
entry->text = parse_hotkey (name);
|
||||
entry->command = command;
|
||||
entry->shortcut = NULL;
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
menu_entry_free (menu_entry_t * entry)
|
||||
{
|
||||
if (entry != NULL)
|
||||
{
|
||||
release_hotkey (entry->text);
|
||||
g_free (entry->shortcut);
|
||||
g_free (entry);
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
Menu *
|
||||
create_menu (const char *name, GList * entries, const char *help_node)
|
||||
{
|
||||
Menu *menu;
|
||||
|
||||
menu = g_new (Menu, 1);
|
||||
menu->start_x = 0;
|
||||
menu->text = parse_hotkey (name);
|
||||
menu->entries = entries;
|
||||
menu->max_entry_len = 1;
|
||||
menu->max_hotkey_len = 0;
|
||||
menu->selected = 0;
|
||||
menu->help_node = g_strdup (help_node);
|
||||
|
||||
return menu;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
destroy_menu (Menu * menu)
|
||||
{
|
||||
release_hotkey (menu->text);
|
||||
g_list_foreach (menu->entries, (GFunc) menu_entry_free, NULL);
|
||||
g_list_free (menu->entries);
|
||||
g_free (menu->help_node);
|
||||
g_free (menu);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
WMenuBar *
|
||||
menubar_new (int y, int x, int cols, GList * menu)
|
||||
{
|
||||
@ -725,6 +782,8 @@ menubar_new (int y, int x, int cols, GList * menu)
|
||||
return menubar;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
menubar_set_menu (WMenuBar * menubar, GList * menu)
|
||||
{
|
||||
@ -742,6 +801,8 @@ menubar_set_menu (WMenuBar * menubar, GList * menu)
|
||||
menubar_arrange (menubar);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
menubar_add_menu (WMenuBar * menubar, Menu * menu)
|
||||
{
|
||||
@ -754,10 +815,12 @@ menubar_add_menu (WMenuBar * menubar, Menu * menu)
|
||||
menubar_arrange (menubar);
|
||||
}
|
||||
|
||||
/*
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Properly space menubar items. Should be called when menubar is created
|
||||
* and also when widget width is changed (i.e. upon xterm resize).
|
||||
*/
|
||||
|
||||
void
|
||||
menubar_arrange (WMenuBar * menubar)
|
||||
{
|
||||
@ -811,9 +874,13 @@ menubar_arrange (WMenuBar * menubar)
|
||||
#endif /* RESIZABLE_MENUBAR */
|
||||
}
|
||||
|
||||
/* Find MenuBar widget in the dialog */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Find MenuBar widget in the dialog */
|
||||
|
||||
WMenuBar *
|
||||
find_menubar (const Dlg_head * h)
|
||||
{
|
||||
return (WMenuBar *) find_widget_type (h, menubar_callback);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
75
src/menu.h
75
src/menu.h
@ -1,4 +1,3 @@
|
||||
|
||||
/* Header file for pulldown menu engine for Midnignt Commander
|
||||
Copyright (C) 1994, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
|
||||
2007, 2009 Free Software Foundation, Inc.
|
||||
@ -21,56 +20,70 @@
|
||||
* \brief Header: pulldown menu code
|
||||
*/
|
||||
|
||||
#ifndef MC_MENU_H
|
||||
#define MC_MENU_H
|
||||
#ifndef MC__MENU_H
|
||||
#define MC__MENU_H
|
||||
|
||||
#include "lib/global.h"
|
||||
#include "widget.h"
|
||||
|
||||
extern int menubar_visible;
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
typedef struct menu_entry_t {
|
||||
#define menu_separator_create() NULL
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
typedef struct menu_entry_t
|
||||
{
|
||||
unsigned char first_letter;
|
||||
struct hotkey_t text;
|
||||
unsigned long command;
|
||||
char *shortcut;
|
||||
} menu_entry_t;
|
||||
|
||||
menu_entry_t *menu_entry_create (const char *name, unsigned long command);
|
||||
void menu_entry_free (menu_entry_t *me);
|
||||
#define menu_separator_create() NULL
|
||||
|
||||
typedef struct Menu {
|
||||
int start_x; /* position relative to menubar start */
|
||||
typedef struct Menu
|
||||
{
|
||||
int start_x; /* position relative to menubar start */
|
||||
struct hotkey_t text;
|
||||
GList *entries;
|
||||
size_t max_entry_len; /* cached max length of entry texts (text + shortcut) */
|
||||
size_t max_hotkey_len; /* cached max length of shortcuts */
|
||||
unsigned int selected; /* pointer to current menu entry */
|
||||
size_t max_entry_len; /* cached max length of entry texts (text + shortcut) */
|
||||
size_t max_hotkey_len; /* cached max length of shortcuts */
|
||||
unsigned int selected; /* pointer to current menu entry */
|
||||
char *help_node;
|
||||
} Menu;
|
||||
|
||||
Menu *create_menu (const char *name, GList *entries,
|
||||
const char *help_node);
|
||||
|
||||
void destroy_menu (Menu *menu);
|
||||
|
||||
/* The button bar menu */
|
||||
typedef struct WMenuBar {
|
||||
typedef struct WMenuBar
|
||||
{
|
||||
Widget widget;
|
||||
|
||||
gboolean is_active; /* If the menubar is in use */
|
||||
gboolean is_dropped; /* If the menubar has dropped */
|
||||
GList *menu; /* The actual menus */
|
||||
size_t selected; /* Selected menu on the top bar */
|
||||
int previous_widget; /* Selected widget ID before activating menu */
|
||||
gboolean is_active; /* If the menubar is in use */
|
||||
gboolean is_dropped; /* If the menubar has dropped */
|
||||
GList *menu; /* The actual menus */
|
||||
size_t selected; /* Selected menu on the top bar */
|
||||
int previous_widget; /* Selected widget ID before activating menu */
|
||||
} WMenuBar;
|
||||
|
||||
WMenuBar *menubar_new (int y, int x, int cols, GList *menu);
|
||||
void menubar_set_menu (WMenuBar *menubar, GList *menu);
|
||||
void menubar_add_menu (WMenuBar *menubar, Menu *menu);
|
||||
void menubar_arrange (WMenuBar *menubar);
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
WMenuBar *find_menubar (const Dlg_head *h);
|
||||
extern int menubar_visible;
|
||||
|
||||
#endif /* MC_MENU_H */
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
menu_entry_t *menu_entry_create (const char *name, unsigned long command);
|
||||
void menu_entry_free (menu_entry_t * me);
|
||||
|
||||
Menu *create_menu (const char *name, GList * entries, const char *help_node);
|
||||
|
||||
void destroy_menu (Menu * menu);
|
||||
|
||||
WMenuBar *menubar_new (int y, int x, int cols, GList * menu);
|
||||
void menubar_set_menu (WMenuBar * menubar, GList * menu);
|
||||
void menubar_add_menu (WMenuBar * menubar, Menu * menu);
|
||||
void menubar_arrange (WMenuBar * menubar);
|
||||
|
||||
WMenuBar *find_menubar (const Dlg_head * h);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__MENU_H */
|
||||
|
199
src/mfmt.c
199
src/mfmt.c
@ -22,7 +22,14 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
enum states {
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
enum states
|
||||
{
|
||||
header,
|
||||
definition,
|
||||
plain,
|
||||
@ -34,104 +41,130 @@ enum states {
|
||||
seen_m
|
||||
};
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
int c;
|
||||
int state = newline;
|
||||
int space_seen = 0;
|
||||
|
||||
while ((c = getchar ()) != EOF){
|
||||
switch (state){
|
||||
case plain:
|
||||
if (c == '\n')
|
||||
state = newline;
|
||||
putchar (c);
|
||||
break;
|
||||
|
||||
case newline:
|
||||
if (c == 'F')
|
||||
state = seen_f;
|
||||
|
||||
while ((c = getchar ()) != EOF)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case plain:
|
||||
if (c == '\n')
|
||||
state = newline;
|
||||
putchar (c);
|
||||
break;
|
||||
|
||||
case newline:
|
||||
if (c == 'F')
|
||||
state = seen_f;
|
||||
else if (c == '\n')
|
||||
putchar ('\n');
|
||||
else {
|
||||
state = plain;
|
||||
putchar (c);
|
||||
}
|
||||
break;
|
||||
|
||||
case seen_f:
|
||||
if (c == 'r')
|
||||
state = seen_r;
|
||||
else {
|
||||
printf ("F%c", c);
|
||||
state = plain;
|
||||
}
|
||||
break;
|
||||
else
|
||||
{
|
||||
state = plain;
|
||||
putchar (c);
|
||||
}
|
||||
break;
|
||||
|
||||
case seen_r:
|
||||
if (c == 'o')
|
||||
state = seen_o;
|
||||
else {
|
||||
state = plain;
|
||||
printf ("Fr%c", c);
|
||||
}
|
||||
break;
|
||||
case seen_f:
|
||||
if (c == 'r')
|
||||
state = seen_r;
|
||||
else
|
||||
{
|
||||
printf ("F%c", c);
|
||||
state = plain;
|
||||
}
|
||||
break;
|
||||
|
||||
case seen_o:
|
||||
if (c == 'm'){
|
||||
state = seen_m;
|
||||
} else {
|
||||
state = plain;
|
||||
printf ("Fro%c", c);
|
||||
}
|
||||
break;
|
||||
case seen_r:
|
||||
if (c == 'o')
|
||||
state = seen_o;
|
||||
else
|
||||
{
|
||||
state = plain;
|
||||
printf ("Fr%c", c);
|
||||
}
|
||||
break;
|
||||
|
||||
case seen_m:
|
||||
if (c == ' '){
|
||||
state = definition;
|
||||
printf ("_\bF_\br_\bo_\bm ");
|
||||
} else {
|
||||
state = plain;
|
||||
printf ("From%c", c);
|
||||
}
|
||||
break;
|
||||
|
||||
case header_new:
|
||||
space_seen = 0;
|
||||
if (c == ' ' || c == '\t') {
|
||||
case seen_o:
|
||||
if (c == 'm')
|
||||
{
|
||||
state = seen_m;
|
||||
}
|
||||
else
|
||||
{
|
||||
state = plain;
|
||||
printf ("Fro%c", c);
|
||||
}
|
||||
break;
|
||||
|
||||
case seen_m:
|
||||
if (c == ' ')
|
||||
{
|
||||
state = definition;
|
||||
printf ("_\bF_\br_\bo_\bm ");
|
||||
}
|
||||
else
|
||||
{
|
||||
state = plain;
|
||||
printf ("From%c", c);
|
||||
}
|
||||
break;
|
||||
|
||||
case header_new:
|
||||
space_seen = 0;
|
||||
if (c == ' ' || c == '\t')
|
||||
{
|
||||
state = definition;
|
||||
putchar (c);
|
||||
break;
|
||||
}
|
||||
if (c == '\n'){
|
||||
state = plain;
|
||||
putchar (c);
|
||||
break;
|
||||
}
|
||||
|
||||
case header:
|
||||
if (c == '\n'){
|
||||
putchar (c);
|
||||
state = header_new;
|
||||
break;
|
||||
}
|
||||
printf ("_\b%c", c);
|
||||
if (c == ' ')
|
||||
space_seen = 1;
|
||||
if (c == ':' && !space_seen)
|
||||
state = definition;
|
||||
break;
|
||||
if (c == '\n')
|
||||
{
|
||||
state = plain;
|
||||
putchar (c);
|
||||
break;
|
||||
}
|
||||
|
||||
case definition:
|
||||
if (c == '\n'){
|
||||
putchar (c);
|
||||
state = header_new;
|
||||
break;
|
||||
}
|
||||
printf ("%c\b%c", c, c);
|
||||
break;
|
||||
}
|
||||
case header:
|
||||
if (c == '\n')
|
||||
{
|
||||
putchar (c);
|
||||
state = header_new;
|
||||
break;
|
||||
}
|
||||
printf ("_\b%c", c);
|
||||
if (c == ' ')
|
||||
space_seen = 1;
|
||||
if (c == ':' && !space_seen)
|
||||
state = definition;
|
||||
break;
|
||||
|
||||
case definition:
|
||||
if (c == '\n')
|
||||
{
|
||||
putchar (c);
|
||||
state = header_new;
|
||||
break;
|
||||
}
|
||||
printf ("%c\b%c", c, c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
245
src/mountlist.c
245
src/mountlist.c
@ -113,6 +113,10 @@
|
||||
#include "lib/global.h"
|
||||
#include "mountlist.h"
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
#ifdef DOLPHIN
|
||||
/* So special that it's not worth putting this in autoconf. */
|
||||
#undef MOUNTED_FREAD_FSTYP
|
||||
@ -120,13 +124,15 @@
|
||||
#endif
|
||||
|
||||
#if defined (__QNX__) && !defined(__QNXNTO__) && !defined (HAVE_INFOMOUNT_LIST)
|
||||
# define HAVE_INFOMOUNT_QNX
|
||||
#define HAVE_INFOMOUNT_QNX
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_INFOMOUNT_LIST) || defined(HAVE_INFOMOUNT_QNX)
|
||||
# define HAVE_INFOMOUNT
|
||||
#define HAVE_INFOMOUNT
|
||||
#endif
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
/* A mount table entry. */
|
||||
struct mount_entry
|
||||
{
|
||||
@ -146,12 +152,18 @@ struct fs_usage
|
||||
fsfilcnt_t fsu_ffree; /* Free file nodes. */
|
||||
};
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
static int get_fs_usage (char *path, struct fs_usage *fsp);
|
||||
|
||||
#ifdef HAVE_INFOMOUNT_LIST
|
||||
|
||||
static struct mount_entry *mount_list = NULL;
|
||||
#endif /* HAVE_INFOMOUNT_LIST */
|
||||
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
#ifdef HAVE_INFOMOUNT_LIST
|
||||
static void
|
||||
free_mount_entry (struct mount_entry *me)
|
||||
{
|
||||
@ -167,6 +179,8 @@ free_mount_entry (struct mount_entry *me)
|
||||
}
|
||||
|
||||
#ifdef MOUNTED_GETMNTENT1 /* 4.3BSD, SunOS, HP-UX, Dynix, Irix. */
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/* Return the value of the hexadecimal number represented by CP.
|
||||
No prefix (like '0x') or suffix (like 'h') is expected to be
|
||||
part of CP. */
|
||||
@ -195,6 +209,8 @@ xatoi (const char *cp)
|
||||
|
||||
#ifdef MOUNTED_GETMNTINFO
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
#ifndef HAVE_STRUCT_STATFS_F_FSTYPENAME
|
||||
static char *
|
||||
fstype_to_string (short t)
|
||||
@ -293,6 +309,8 @@ fstype_to_string (short t)
|
||||
|
||||
#endif /* MOUNTED_GETMNTINFO */
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
#ifdef MOUNTED_VMOUNT /* AIX. */
|
||||
static char *
|
||||
fstype_to_string (int t)
|
||||
@ -307,7 +325,8 @@ fstype_to_string (int t)
|
||||
}
|
||||
#endif /* MOUNTED_VMOUNT */
|
||||
|
||||
/* Return a list of the currently mounted filesystems, or NULL on error.
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Return a list of the currently mounted filesystems, or NULL on error.
|
||||
Add each entry to the tail of the list so that they stay in order.
|
||||
If NEED_FS_TYPE is nonzero, ensure that the filesystem type fields in
|
||||
the returned list are valid. Otherwise, they might not be.
|
||||
@ -612,8 +631,10 @@ read_filesystem_list (int need_fs_type, int all_fs)
|
||||
}
|
||||
#endif /* HAVE_INFOMOUNT_LIST */
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
#ifdef HAVE_INFOMOUNT_QNX
|
||||
/*
|
||||
/**
|
||||
** QNX has no [gs]etmnt*(), [gs]etfs*(), or /etc/mnttab, but can do
|
||||
** this via the following code.
|
||||
** Note that, as this is based on CWD, it only fills one mount_entry
|
||||
@ -707,109 +728,8 @@ read_filesystem_list (int need_fs_type, int all_fs)
|
||||
}
|
||||
#endif /* HAVE_INFOMOUNT_QNX */
|
||||
|
||||
void
|
||||
free_my_statfs (void)
|
||||
{
|
||||
#ifdef HAVE_INFOMOUNT_LIST
|
||||
while (mount_list)
|
||||
{
|
||||
struct mount_entry *next = mount_list->me_next;
|
||||
free_mount_entry (mount_list);
|
||||
mount_list = next;
|
||||
}
|
||||
mount_list = NULL;
|
||||
#endif /* HAVE_INFOMOUNT_LIST */
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
init_my_statfs (void)
|
||||
{
|
||||
#ifdef HAVE_INFOMOUNT_LIST
|
||||
free_my_statfs ();
|
||||
mount_list = read_filesystem_list (1, 1);
|
||||
#endif /* HAVE_INFOMOUNT_LIST */
|
||||
}
|
||||
|
||||
void
|
||||
my_statfs (struct my_statfs *myfs_stats, const char *path)
|
||||
{
|
||||
#ifdef HAVE_INFOMOUNT_LIST
|
||||
size_t i, len = 0;
|
||||
struct mount_entry *entry = NULL;
|
||||
struct mount_entry *temp = mount_list;
|
||||
struct fs_usage fs_use;
|
||||
|
||||
while (temp)
|
||||
{
|
||||
i = strlen (temp->me_mountdir);
|
||||
if (i > len && (strncmp (path, temp->me_mountdir, i) == 0))
|
||||
if (!entry || (path[i] == PATH_SEP || path[i] == '\0'))
|
||||
{
|
||||
len = i;
|
||||
entry = temp;
|
||||
}
|
||||
temp = temp->me_next;
|
||||
}
|
||||
|
||||
if (entry)
|
||||
{
|
||||
memset (&fs_use, 0, sizeof (struct fs_usage));
|
||||
get_fs_usage (entry->me_mountdir, &fs_use);
|
||||
|
||||
myfs_stats->type = entry->me_dev;
|
||||
myfs_stats->typename = entry->me_type;
|
||||
myfs_stats->mpoint = entry->me_mountdir;
|
||||
myfs_stats->device = entry->me_devname;
|
||||
myfs_stats->avail = getuid ()? fs_use.fsu_bavail / 2 : fs_use.fsu_bfree / 2;
|
||||
myfs_stats->total = fs_use.fsu_blocks / 2;
|
||||
myfs_stats->nfree = fs_use.fsu_ffree;
|
||||
myfs_stats->nodes = fs_use.fsu_files;
|
||||
}
|
||||
else
|
||||
#endif /* HAVE_INFOMOUNT_LIST */
|
||||
|
||||
#ifdef HAVE_INFOMOUNT_QNX
|
||||
/*
|
||||
** This is the "other side" of the hack to read_filesystem_list() in
|
||||
** mountlist.c.
|
||||
** It's not the most efficient approach, but consumes less memory. It
|
||||
** also accomodates QNX's ability to mount filesystems on the fly.
|
||||
*/
|
||||
struct mount_entry *entry;
|
||||
struct fs_usage fs_use;
|
||||
|
||||
entry = read_filesystem_list (0, 0);
|
||||
if (entry != NULL)
|
||||
{
|
||||
get_fs_usage (entry->me_mountdir, &fs_use);
|
||||
|
||||
myfs_stats->type = entry->me_dev;
|
||||
myfs_stats->typename = entry->me_type;
|
||||
myfs_stats->mpoint = entry->me_mountdir;
|
||||
myfs_stats->device = entry->me_devname;
|
||||
|
||||
myfs_stats->avail = fs_use.fsu_bfree / 2;
|
||||
myfs_stats->total = fs_use.fsu_blocks / 2;
|
||||
myfs_stats->nfree = fs_use.fsu_ffree;
|
||||
myfs_stats->nodes = fs_use.fsu_files;
|
||||
}
|
||||
else
|
||||
#endif /* HAVE_INFOMOUNT_QNX */
|
||||
{
|
||||
myfs_stats->type = 0;
|
||||
myfs_stats->mpoint = "unknown";
|
||||
myfs_stats->device = "unknown";
|
||||
myfs_stats->avail = 0;
|
||||
myfs_stats->total = 0;
|
||||
myfs_stats->nfree = 0;
|
||||
myfs_stats->nodes = 0;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_INFOMOUNT
|
||||
|
||||
/* Return the number of TOSIZE-byte blocks used by
|
||||
/** Return the number of TOSIZE-byte blocks used by
|
||||
BLOCKS FROMSIZE-byte blocks, rounding away from zero.
|
||||
TOSIZE must be positive. Return -1 if FROMSIZE is not positive. */
|
||||
|
||||
@ -829,6 +749,7 @@ fs_adjust_blocks (fsblkcnt_t blocks, int fromsize, int tosize)
|
||||
return blocks / (tosize / fromsize);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
#if defined(_AIX) && defined(_I386)
|
||||
/* AIX PS/2 does not supply statfs. */
|
||||
static int
|
||||
@ -860,6 +781,7 @@ aix_statfs (char *path, struct statfs *fsb)
|
||||
the filesystem on which PATH resides.
|
||||
Return 0 if successful, -1 if not. */
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
static int
|
||||
get_fs_usage (char *path, struct fs_usage *fsp)
|
||||
{
|
||||
@ -942,3 +864,112 @@ get_fs_usage (char *path, struct fs_usage *fsp)
|
||||
}
|
||||
|
||||
#endif /* HAVE_INFOMOUNT */
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
free_my_statfs (void)
|
||||
{
|
||||
#ifdef HAVE_INFOMOUNT_LIST
|
||||
while (mount_list)
|
||||
{
|
||||
struct mount_entry *next = mount_list->me_next;
|
||||
free_mount_entry (mount_list);
|
||||
mount_list = next;
|
||||
}
|
||||
mount_list = NULL;
|
||||
#endif /* HAVE_INFOMOUNT_LIST */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
init_my_statfs (void)
|
||||
{
|
||||
#ifdef HAVE_INFOMOUNT_LIST
|
||||
free_my_statfs ();
|
||||
mount_list = read_filesystem_list (1, 1);
|
||||
#endif /* HAVE_INFOMOUNT_LIST */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
my_statfs (struct my_statfs *myfs_stats, const char *path)
|
||||
{
|
||||
#ifdef HAVE_INFOMOUNT_LIST
|
||||
size_t i, len = 0;
|
||||
struct mount_entry *entry = NULL;
|
||||
struct mount_entry *temp = mount_list;
|
||||
struct fs_usage fs_use;
|
||||
|
||||
while (temp)
|
||||
{
|
||||
i = strlen (temp->me_mountdir);
|
||||
if (i > len && (strncmp (path, temp->me_mountdir, i) == 0))
|
||||
if (!entry || (path[i] == PATH_SEP || path[i] == '\0'))
|
||||
{
|
||||
len = i;
|
||||
entry = temp;
|
||||
}
|
||||
temp = temp->me_next;
|
||||
}
|
||||
|
||||
if (entry)
|
||||
{
|
||||
memset (&fs_use, 0, sizeof (struct fs_usage));
|
||||
get_fs_usage (entry->me_mountdir, &fs_use);
|
||||
|
||||
myfs_stats->type = entry->me_dev;
|
||||
myfs_stats->typename = entry->me_type;
|
||||
myfs_stats->mpoint = entry->me_mountdir;
|
||||
myfs_stats->device = entry->me_devname;
|
||||
myfs_stats->avail = getuid ()? fs_use.fsu_bavail / 2 : fs_use.fsu_bfree / 2;
|
||||
myfs_stats->total = fs_use.fsu_blocks / 2;
|
||||
myfs_stats->nfree = fs_use.fsu_ffree;
|
||||
myfs_stats->nodes = fs_use.fsu_files;
|
||||
}
|
||||
else
|
||||
#endif /* HAVE_INFOMOUNT_LIST */
|
||||
|
||||
#ifdef HAVE_INFOMOUNT_QNX
|
||||
/*
|
||||
** This is the "other side" of the hack to read_filesystem_list() in
|
||||
** mountlist.c.
|
||||
** It's not the most efficient approach, but consumes less memory. It
|
||||
** also accomodates QNX's ability to mount filesystems on the fly.
|
||||
*/
|
||||
struct mount_entry *entry;
|
||||
struct fs_usage fs_use;
|
||||
|
||||
entry = read_filesystem_list (0, 0);
|
||||
if (entry != NULL)
|
||||
{
|
||||
get_fs_usage (entry->me_mountdir, &fs_use);
|
||||
|
||||
myfs_stats->type = entry->me_dev;
|
||||
myfs_stats->typename = entry->me_type;
|
||||
myfs_stats->mpoint = entry->me_mountdir;
|
||||
myfs_stats->device = entry->me_devname;
|
||||
|
||||
myfs_stats->avail = fs_use.fsu_bfree / 2;
|
||||
myfs_stats->total = fs_use.fsu_blocks / 2;
|
||||
myfs_stats->nfree = fs_use.fsu_ffree;
|
||||
myfs_stats->nodes = fs_use.fsu_files;
|
||||
}
|
||||
else
|
||||
#endif /* HAVE_INFOMOUNT_QNX */
|
||||
{
|
||||
myfs_stats->type = 0;
|
||||
myfs_stats->mpoint = "unknown";
|
||||
myfs_stats->device = "unknown";
|
||||
myfs_stats->avail = 0;
|
||||
myfs_stats->total = 0;
|
||||
myfs_stats->nfree = 0;
|
||||
myfs_stats->nodes = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -19,8 +19,14 @@
|
||||
* \brief Header: list of mounted filesystems
|
||||
*/
|
||||
|
||||
#ifndef MC_MOUNTLIST_H
|
||||
#define MC_MOUNTLIST_H
|
||||
#ifndef MC__MOUNTLIST_H
|
||||
#define MC__MOUNTLIST_H
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
/* Filesystem status */
|
||||
struct my_statfs
|
||||
@ -35,8 +41,14 @@ struct my_statfs
|
||||
int nodes;
|
||||
};
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
|
||||
void init_my_statfs (void);
|
||||
void my_statfs (struct my_statfs *myfs_stats, const char *path);
|
||||
void free_my_statfs (void);
|
||||
|
||||
#endif
|
||||
#endif /* MC__MOUNTLIST_H */
|
||||
|
78
src/option.c
78
src/option.c
@ -47,36 +47,51 @@
|
||||
|
||||
#include "option.h"
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static cb_ret_t
|
||||
configure_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
|
||||
{
|
||||
switch (msg)
|
||||
{
|
||||
case DLG_ACTION:
|
||||
if (sender->id == 18)
|
||||
{
|
||||
/* message from "Single press" checkbutton */
|
||||
const gboolean not_single = !(((WCheck *) sender)->state & C_BOOL);
|
||||
Widget *w;
|
||||
case DLG_ACTION:
|
||||
if (sender->id == 18)
|
||||
{
|
||||
/* message from "Single press" checkbutton */
|
||||
const gboolean not_single = !(((WCheck *) sender)->state & C_BOOL);
|
||||
Widget *w;
|
||||
|
||||
/* label */
|
||||
w = dlg_find_by_id (h, sender->id - 1);
|
||||
widget_disable (*w, not_single);
|
||||
send_message (w, WIDGET_DRAW, 0);
|
||||
/* input */
|
||||
w = dlg_find_by_id (h, sender->id - 2);
|
||||
widget_disable (*w, not_single);
|
||||
send_message (w, WIDGET_DRAW, 0);
|
||||
/* label */
|
||||
w = dlg_find_by_id (h, sender->id - 1);
|
||||
widget_disable (*w, not_single);
|
||||
send_message (w, WIDGET_DRAW, 0);
|
||||
/* input */
|
||||
w = dlg_find_by_id (h, sender->id - 2);
|
||||
widget_disable (*w, not_single);
|
||||
send_message (w, WIDGET_DRAW, 0);
|
||||
|
||||
return MSG_HANDLED;
|
||||
}
|
||||
return MSG_NOT_HANDLED;
|
||||
return MSG_HANDLED;
|
||||
}
|
||||
return MSG_NOT_HANDLED;
|
||||
|
||||
default:
|
||||
return default_dlg_callback (h, sender, msg, parm, data);
|
||||
default:
|
||||
return default_dlg_callback (h, sender, msg, parm, data);
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
configure_box (void)
|
||||
{
|
||||
@ -128,14 +143,15 @@ configure_box (void)
|
||||
|
||||
/* Esc key mode */
|
||||
QUICK_INPUT (10, dlg_width, 10, dlg_height, (const char *) time_out, 8, 0,
|
||||
MC_HISTORY_ESC_TIMEOUT, &time_out_new),
|
||||
MC_HISTORY_ESC_TIMEOUT, &time_out_new),
|
||||
QUICK_LABEL (5, dlg_width, 10, dlg_height, N_("Timeout:")),
|
||||
QUICK_CHECKBOX (5, dlg_width, 9, dlg_height, N_("S&ingle press"), &old_esc_mode),
|
||||
QUICK_GROUPBOX (3, dlg_width, 8, dlg_height, dlg_width / 2 - 4, 4, N_("Esc key mode")),
|
||||
|
||||
/* file operation options */
|
||||
QUICK_CHECKBOX (5, dlg_width, 6, dlg_height, N_("Mkdi&r autoname"), &auto_fill_mkdir_name),
|
||||
QUICK_CHECKBOX (5, dlg_width, 5, dlg_height, N_("Classic pro&gressbar"), &classic_progressbar),
|
||||
QUICK_CHECKBOX (5, dlg_width, 5, dlg_height, N_("Classic pro&gressbar"),
|
||||
&classic_progressbar),
|
||||
QUICK_CHECKBOX (5, dlg_width, 4, dlg_height, N_("Compute tota&ls"),
|
||||
&file_op_compute_totals),
|
||||
QUICK_CHECKBOX (5, dlg_width, 3, dlg_height, N_("&Verbose operation"), &verbose),
|
||||
@ -260,6 +276,8 @@ configure_box (void)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
panel_options_box (void)
|
||||
{
|
||||
@ -280,7 +298,8 @@ panel_options_box (void)
|
||||
/* quick search */
|
||||
QUICK_RADIO (dlg_width / 2 + 2, dlg_width, 12, dlg_height, QSEARCH_NUM, qsearch_options,
|
||||
(int *) &panels_options.qsearch_mode),
|
||||
QUICK_GROUPBOX (dlg_width / 2, dlg_width, 11, dlg_height, dlg_width / 2 - 4, QSEARCH_NUM + 2,
|
||||
QUICK_GROUPBOX (dlg_width / 2, dlg_width, 11, dlg_height, dlg_width / 2 - 4,
|
||||
QSEARCH_NUM + 2,
|
||||
N_("Quick search")),
|
||||
/* file highlighting */
|
||||
QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 9, dlg_height, N_("&Permissions"),
|
||||
@ -315,7 +334,8 @@ panel_options_box (void)
|
||||
&panels_options.mix_all_files),
|
||||
QUICK_CHECKBOX (5, dlg_width, 3, dlg_height, N_("Use SI si&ze units"),
|
||||
&panels_options.kilobyte_si),
|
||||
QUICK_GROUPBOX (3, dlg_width, 2, dlg_height, dlg_width / 2 - 4, 14, N_("Main panel options")),
|
||||
QUICK_GROUPBOX (3, dlg_width, 2, dlg_height, dlg_width / 2 - 4, 14,
|
||||
N_("Main panel options")),
|
||||
QUICK_END
|
||||
};
|
||||
|
||||
@ -377,7 +397,7 @@ panel_options_box (void)
|
||||
c_len = max (c_len, str_term_width1 (qsearch_options[i]) + 3);
|
||||
/* groupboxes */
|
||||
g_len = max (c_len + 2, str_term_width1 (quick_widgets[4].u.groupbox.title) + 4);
|
||||
g_len = max (g_len, str_term_width1 (quick_widgets[ 7].u.groupbox.title) + 4);
|
||||
g_len = max (g_len, str_term_width1 (quick_widgets[7].u.groupbox.title) + 4);
|
||||
g_len = max (g_len, str_term_width1 (quick_widgets[11].u.groupbox.title) + 4);
|
||||
g_len = max (g_len, str_term_width1 (quick_widgets[20].u.groupbox.title) + 4);
|
||||
/* dialog width */
|
||||
@ -392,14 +412,13 @@ panel_options_box (void)
|
||||
|
||||
/* groupboxes */
|
||||
quick_widgets[4].u.groupbox.width =
|
||||
quick_widgets[ 7].u.groupbox.width =
|
||||
quick_widgets[7].u.groupbox.width =
|
||||
quick_widgets[11].u.groupbox.width = Quick_input.xlen / 2 - 3;
|
||||
quick_widgets[20].u.groupbox.width = Quick_input.xlen / 2 - 4;
|
||||
|
||||
/* right column */
|
||||
quick_widgets[4].relative_x =
|
||||
quick_widgets[ 7].relative_x =
|
||||
quick_widgets[11].relative_x = Quick_input.xlen / 2;
|
||||
quick_widgets[7].relative_x = quick_widgets[11].relative_x = Quick_input.xlen / 2;
|
||||
for (i = 3; i < 11; i++)
|
||||
if ((i != 4) && (i != 7))
|
||||
quick_widgets[i].relative_x = quick_widgets[4].relative_x + 2;
|
||||
@ -418,8 +437,7 @@ panel_options_box (void)
|
||||
message (D_NORMAL, _("Information"),
|
||||
_("Using the fast reload option may not reflect the exact\n"
|
||||
"directory contents. In this case you'll need to do a\n"
|
||||
"manual reload of the directory. See the man page for\n"
|
||||
"the details."));
|
||||
"manual reload of the directory. See the man page for\n" "the details."));
|
||||
panels_options.fast_reload_msg_shown = TRUE;
|
||||
}
|
||||
update_panels (UP_RELOAD, UP_KEEPSEL);
|
||||
@ -432,3 +450,5 @@ panel_options_box (void)
|
||||
mc_config_save_file (mc_main_config, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
18
src/option.h
18
src/option.h
@ -1,12 +1,22 @@
|
||||
|
||||
/** \file option.h
|
||||
* \brief Header: configure box module
|
||||
*/
|
||||
|
||||
#ifndef MC_OPTION_H
|
||||
#define MC_OPTION_H
|
||||
#ifndef MC__OPTION_H
|
||||
#define MC__OPTION_H
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
void configure_box (void);
|
||||
void panel_options_box (void);
|
||||
|
||||
#endif
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__OPTION_H */
|
||||
|
271
src/panel.h
271
src/panel.h
@ -1,162 +1,177 @@
|
||||
|
||||
/** \file panel.h
|
||||
* \brief Header: defines WPanel structure
|
||||
*/
|
||||
|
||||
#ifndef MC_PANEL_H
|
||||
#define MC_PANEL_H
|
||||
#ifndef MC__PANEL_H
|
||||
#define MC__PANEL_H
|
||||
|
||||
#include "lib/global.h" /* gboolean */
|
||||
#include "lib/fs.h" /* MC_MAXPATHLEN */
|
||||
#include "lib/global.h" /* gboolean */
|
||||
#include "lib/fs.h" /* MC_MAXPATHLEN */
|
||||
#include "lib/strutil.h"
|
||||
|
||||
#include "dir.h" /* dir_list */
|
||||
#include "dialog.h" /* Widget */
|
||||
#include "main.h" /* cd_enum */
|
||||
#include "dir.h" /* dir_list */
|
||||
#include "dialog.h" /* Widget */
|
||||
#include "main.h" /* cd_enum */
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
#define selection(p) (&(p->dir.list[p->selected]))
|
||||
#define DEFAULT_USER_FORMAT "half type name | size | perm"
|
||||
|
||||
#define LIST_TYPES 4
|
||||
|
||||
enum list_types {
|
||||
list_full, /* Name, size, perm/date */
|
||||
list_brief, /* Name */
|
||||
list_long, /* Like ls -l */
|
||||
list_user /* User defined */
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
view_listing = 0, /* Directory listing */
|
||||
view_info = 1, /* Information panel */
|
||||
view_tree = 2, /* Tree view */
|
||||
view_quick = 3, /* Quick view */
|
||||
view_nothing = 4, /* Undefined */
|
||||
} panel_view_mode_t;
|
||||
|
||||
enum panel_display_enum {
|
||||
frame_full, /* full screen frame */
|
||||
frame_half /* half screen frame */
|
||||
};
|
||||
|
||||
struct format_e;
|
||||
|
||||
typedef struct panel_format_struct {
|
||||
const char *id;
|
||||
int min_size;
|
||||
int expands;
|
||||
align_crt_t default_just;
|
||||
const char *hotkey;
|
||||
const char *title_hotkey;
|
||||
gboolean is_user_choice;
|
||||
gboolean use_in_user_format;
|
||||
const char *(*string_fn)(file_entry *, int);
|
||||
sortfn *sort_routine; /* used by mouse_sort_col() */
|
||||
} panel_field_t;
|
||||
|
||||
extern panel_field_t panel_fields [];
|
||||
|
||||
typedef struct WPanel {
|
||||
Widget widget;
|
||||
dir_list dir; /* Directory contents */
|
||||
|
||||
int list_type; /* listing type (was view_type) */
|
||||
int active; /* If panel is currently selected */
|
||||
char cwd [MC_MAXPATHLEN];/* Current Working Directory */
|
||||
char lwd [MC_MAXPATHLEN];/* Last Working Directory */
|
||||
GList *dir_history; /* directory history */
|
||||
char *hist_name; /* directory history name for history file */
|
||||
int count; /* Number of files in dir structure */
|
||||
int marked; /* Count of marked files */
|
||||
int dirs_marked; /* Count of marked directories */
|
||||
double total; /* Bytes in marked files */
|
||||
int top_file; /* The file showed on the top of the panel */
|
||||
int selected; /* Index to the selected file */
|
||||
int reverse; /* Show listing in reverse? */
|
||||
int case_sensitive; /* Listing is case sensitive? */
|
||||
int exec_first; /* Show executable top in list? */
|
||||
int split; /* Split panel to allow two columns */
|
||||
int is_panelized; /* Flag: special filelisting, can't reload */
|
||||
int frame_size; /* half or full frame */
|
||||
const panel_field_t *current_sort_field;
|
||||
char *filter; /* File name filter */
|
||||
|
||||
int dirty; /* Should we redisplay the panel? */
|
||||
|
||||
int user_mini_status; /* Is user_status_format used */
|
||||
char *user_format; /* User format */
|
||||
char *user_status_format[LIST_TYPES];/* User format for status line */
|
||||
|
||||
struct format_e *format; /* Display format */
|
||||
struct format_e *status_format; /* Mini status format */
|
||||
|
||||
int format_modified; /* If the format was changed this is set */
|
||||
|
||||
char *panel_name; /* The panel name */
|
||||
struct stat dir_stat; /* Stat of current dir: used by execute () */
|
||||
|
||||
int codepage; /* panel codepage */
|
||||
|
||||
gboolean searching;
|
||||
char search_buffer [MC_MAXFILENAMELEN];
|
||||
char prev_search_buffer [MC_MAXFILENAMELEN];
|
||||
char search_char [MB_LEN_MAX]; /*buffer for multibytes characters*/
|
||||
int search_chpoint; /*point after last characters in search_char*/
|
||||
} WPanel;
|
||||
|
||||
WPanel *panel_new (const char *panel_name);
|
||||
WPanel *panel_new_with_dir (const char *panel_name, const char *dr);
|
||||
void panel_clean_dir (WPanel *panel);
|
||||
|
||||
extern int torben_fj_mode;
|
||||
extern int show_mini_info;
|
||||
|
||||
void panel_reload (WPanel *panel);
|
||||
void panel_set_sort_order (WPanel *panel, const panel_field_t *sort_order);
|
||||
void panel_re_sort (WPanel *panel);
|
||||
void panel_change_encoding (WPanel * panel);
|
||||
|
||||
#define UP_OPTIMIZE 0
|
||||
#define UP_RELOAD 1
|
||||
#define UP_ONLY_CURRENT 2
|
||||
|
||||
#define UP_KEEPSEL ((char *) -1)
|
||||
|
||||
void update_dirty_panels (void);
|
||||
void update_panels (int force_update, const char *current_file);
|
||||
void panel_update_cols (Widget *widget, int frame_size);
|
||||
int set_panel_formats (WPanel *p);
|
||||
|
||||
#define other_panel get_other_panel()
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
enum list_types
|
||||
{
|
||||
list_full, /* Name, size, perm/date */
|
||||
list_brief, /* Name */
|
||||
list_long, /* Like ls -l */
|
||||
list_user /* User defined */
|
||||
};
|
||||
|
||||
typedef enum
|
||||
{
|
||||
view_listing = 0, /* Directory listing */
|
||||
view_info = 1, /* Information panel */
|
||||
view_tree = 2, /* Tree view */
|
||||
view_quick = 3, /* Quick view */
|
||||
view_nothing = 4, /* Undefined */
|
||||
} panel_view_mode_t;
|
||||
|
||||
enum panel_display_enum
|
||||
{
|
||||
frame_full, /* full screen frame */
|
||||
frame_half /* half screen frame */
|
||||
};
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
struct format_e;
|
||||
|
||||
typedef struct panel_format_struct
|
||||
{
|
||||
const char *id;
|
||||
int min_size;
|
||||
int expands;
|
||||
align_crt_t default_just;
|
||||
const char *hotkey;
|
||||
const char *title_hotkey;
|
||||
gboolean is_user_choice;
|
||||
gboolean use_in_user_format;
|
||||
const char *(*string_fn) (file_entry *, int);
|
||||
sortfn *sort_routine; /* used by mouse_sort_col() */
|
||||
} panel_field_t;
|
||||
|
||||
typedef struct WPanel
|
||||
{
|
||||
Widget widget;
|
||||
dir_list dir; /* Directory contents */
|
||||
|
||||
int list_type; /* listing type (was view_type) */
|
||||
int active; /* If panel is currently selected */
|
||||
char cwd[MC_MAXPATHLEN]; /* Current Working Directory */
|
||||
char lwd[MC_MAXPATHLEN]; /* Last Working Directory */
|
||||
GList *dir_history; /* directory history */
|
||||
char *hist_name; /* directory history name for history file */
|
||||
int count; /* Number of files in dir structure */
|
||||
int marked; /* Count of marked files */
|
||||
int dirs_marked; /* Count of marked directories */
|
||||
double total; /* Bytes in marked files */
|
||||
int top_file; /* The file showed on the top of the panel */
|
||||
int selected; /* Index to the selected file */
|
||||
int reverse; /* Show listing in reverse? */
|
||||
int case_sensitive; /* Listing is case sensitive? */
|
||||
int exec_first; /* Show executable top in list? */
|
||||
int split; /* Split panel to allow two columns */
|
||||
int is_panelized; /* Flag: special filelisting, can't reload */
|
||||
int frame_size; /* half or full frame */
|
||||
const panel_field_t *current_sort_field;
|
||||
char *filter; /* File name filter */
|
||||
|
||||
int dirty; /* Should we redisplay the panel? */
|
||||
|
||||
int user_mini_status; /* Is user_status_format used */
|
||||
char *user_format; /* User format */
|
||||
char *user_status_format[LIST_TYPES]; /* User format for status line */
|
||||
|
||||
struct format_e *format; /* Display format */
|
||||
struct format_e *status_format; /* Mini status format */
|
||||
|
||||
int format_modified; /* If the format was changed this is set */
|
||||
|
||||
char *panel_name; /* The panel name */
|
||||
struct stat dir_stat; /* Stat of current dir: used by execute () */
|
||||
|
||||
int codepage; /* panel codepage */
|
||||
|
||||
gboolean searching;
|
||||
char search_buffer[MC_MAXFILENAMELEN];
|
||||
char prev_search_buffer[MC_MAXFILENAMELEN];
|
||||
char search_char[MB_LEN_MAX]; /*buffer for multibytes characters */
|
||||
int search_chpoint; /*point after last characters in search_char */
|
||||
} WPanel;
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
extern panel_field_t panel_fields[];
|
||||
|
||||
extern int torben_fj_mode;
|
||||
extern int show_mini_info;
|
||||
|
||||
extern WPanel *left_panel;
|
||||
extern WPanel *right_panel;
|
||||
extern WPanel *current_panel;
|
||||
|
||||
void try_to_select (WPanel *panel, const char *name);
|
||||
|
||||
void unmark_files (WPanel *panel);
|
||||
void select_item (WPanel *panel);
|
||||
|
||||
extern hook_t *select_file_hook;
|
||||
|
||||
void recalculate_panel_summary (WPanel *panel);
|
||||
void file_mark (WPanel *panel, int idx, int val);
|
||||
void do_file_mark (WPanel *panel, int idx, int val);
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
WPanel *panel_new (const char *panel_name);
|
||||
WPanel *panel_new_with_dir (const char *panel_name, const char *dr);
|
||||
void panel_clean_dir (WPanel * panel);
|
||||
|
||||
void panel_reload (WPanel * panel);
|
||||
void panel_set_sort_order (WPanel * panel, const panel_field_t * sort_order);
|
||||
void panel_re_sort (WPanel * panel);
|
||||
void panel_change_encoding (WPanel * panel);
|
||||
|
||||
void update_dirty_panels (void);
|
||||
void update_panels (int force_update, const char *current_file);
|
||||
void panel_update_cols (Widget * widget, int frame_size);
|
||||
int set_panel_formats (WPanel * p);
|
||||
|
||||
void try_to_select (WPanel * panel, const char *name);
|
||||
|
||||
void unmark_files (WPanel * panel);
|
||||
void select_item (WPanel * panel);
|
||||
|
||||
void recalculate_panel_summary (WPanel * panel);
|
||||
void file_mark (WPanel * panel, int idx, int val);
|
||||
void do_file_mark (WPanel * panel, int idx, int val);
|
||||
|
||||
gboolean do_panel_cd (struct WPanel *panel, const char *new_dir, enum cd_enum cd_type);
|
||||
|
||||
void directory_history_add (struct WPanel *panel, const char *dir);
|
||||
|
||||
gsize panel_get_num_of_sortable_fields(void);
|
||||
const char **panel_get_sortable_fields(gsize *);
|
||||
const panel_field_t *panel_get_field_by_id(const char *);
|
||||
const panel_field_t *panel_get_field_by_title(const char *);
|
||||
const panel_field_t *panel_get_field_by_title_hotkey(const char *);
|
||||
gsize panel_get_num_of_user_possible_fields(void);
|
||||
const char **panel_get_user_possible_fields(gsize *);
|
||||
gsize panel_get_num_of_sortable_fields (void);
|
||||
const char **panel_get_sortable_fields (gsize *);
|
||||
const panel_field_t *panel_get_field_by_id (const char *);
|
||||
const panel_field_t *panel_get_field_by_title (const char *);
|
||||
const panel_field_t *panel_get_field_by_title_hotkey (const char *);
|
||||
gsize panel_get_num_of_user_possible_fields (void);
|
||||
const char **panel_get_user_possible_fields (gsize *);
|
||||
|
||||
void panel_init(void);
|
||||
void panel_deinit(void);
|
||||
void panel_init (void);
|
||||
void panel_deinit (void);
|
||||
|
||||
#endif /* MC_PANEL_H */
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__PANEL_H */
|
||||
|
310
src/panelize.c
310
src/panelize.c
@ -51,6 +51,10 @@
|
||||
#include "panelize.h"
|
||||
#include "history.h"
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
#define UX 5
|
||||
#define UY 2
|
||||
|
||||
@ -62,6 +66,10 @@
|
||||
#define B_ADD B_USER
|
||||
#define B_REMOVE (B_USER + 1)
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
static WListbox *l_panelize;
|
||||
static Dlg_head *panelize_dlg;
|
||||
static int last_listitem;
|
||||
@ -82,7 +90,6 @@ static struct
|
||||
};
|
||||
|
||||
static const char *panelize_section = "Panelize";
|
||||
static void do_external_panelize (char *command);
|
||||
|
||||
/* Directory panelize */
|
||||
static struct panelize
|
||||
@ -92,6 +99,13 @@ static struct panelize
|
||||
struct panelize *next;
|
||||
} *panelize = NULL;
|
||||
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void do_external_panelize (char *command);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
update_command (void)
|
||||
{
|
||||
@ -107,6 +121,8 @@ update_command (void)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static cb_ret_t
|
||||
panelize_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
|
||||
{
|
||||
@ -129,6 +145,8 @@ panelize_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
init_panelize (void)
|
||||
{
|
||||
@ -176,7 +194,7 @@ init_panelize (void)
|
||||
panelize_but[i].flags, panelize_but[i].text, 0));
|
||||
|
||||
pname =
|
||||
input_new (UY + 14, UX, input_get_default_colors(),
|
||||
input_new (UY + 14, UX, input_get_default_colors (),
|
||||
panelize_dlg->cols - 10, "", "in", INPUT_COMPLETE_DEFAULT);
|
||||
add_widget (panelize_dlg, pname);
|
||||
|
||||
@ -197,6 +215,8 @@ init_panelize (void)
|
||||
listbox_select_entry (l_panelize, listbox_search_text (l_panelize, _("Other command")));
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
panelize_done (void)
|
||||
{
|
||||
@ -204,6 +224,8 @@ panelize_done (void)
|
||||
repaint_screen ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
add2panelize (char *label, char *command)
|
||||
{
|
||||
@ -235,6 +257,8 @@ add2panelize (char *label, char *command)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
add2panelize_cmd (void)
|
||||
{
|
||||
@ -256,6 +280,8 @@ add2panelize_cmd (void)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
remove_from_panelize (struct panelize *entry)
|
||||
{
|
||||
@ -282,139 +308,7 @@ remove_from_panelize (struct panelize *entry)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
external_panelize (void)
|
||||
{
|
||||
char *target = NULL;
|
||||
|
||||
if (!vfs_current_is_local ())
|
||||
{
|
||||
message (D_ERROR, MSG_ERROR, _("Cannot run external panelize in a non-local directory"));
|
||||
return;
|
||||
}
|
||||
|
||||
init_panelize ();
|
||||
|
||||
/* display file info */
|
||||
tty_setcolor (SELECTED_COLOR);
|
||||
|
||||
run_dlg (panelize_dlg);
|
||||
|
||||
switch (panelize_dlg->ret_value)
|
||||
{
|
||||
case B_CANCEL:
|
||||
break;
|
||||
|
||||
case B_ADD:
|
||||
add2panelize_cmd ();
|
||||
break;
|
||||
|
||||
case B_REMOVE:
|
||||
{
|
||||
struct panelize *entry;
|
||||
|
||||
listbox_get_current (l_panelize, NULL, (void **) &entry);
|
||||
remove_from_panelize (entry);
|
||||
break;
|
||||
}
|
||||
|
||||
case B_ENTER:
|
||||
target = pname->buffer;
|
||||
if (target != NULL && *target)
|
||||
{
|
||||
char *cmd = g_strdup (target);
|
||||
destroy_dlg (panelize_dlg);
|
||||
do_external_panelize (cmd);
|
||||
g_free (cmd);
|
||||
repaint_screen ();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
panelize_done ();
|
||||
}
|
||||
|
||||
void
|
||||
load_panelize (void)
|
||||
{
|
||||
gchar **profile_keys, **keys;
|
||||
gsize len;
|
||||
GIConv conv;
|
||||
GString *buffer;
|
||||
|
||||
conv = str_crt_conv_from ("UTF-8");
|
||||
|
||||
profile_keys = keys = mc_config_get_keys (mc_main_config, panelize_section, &len);
|
||||
|
||||
add2panelize (g_strdup (_("Other command")), g_strdup (""));
|
||||
|
||||
if (!profile_keys || *profile_keys == NULL)
|
||||
{
|
||||
add2panelize (g_strdup (_("Find rejects after patching")),
|
||||
g_strdup ("find . -name \\*.rej -print"));
|
||||
add2panelize (g_strdup (_("Find *.orig after patching")),
|
||||
g_strdup ("find . -name \\*.orig -print"));
|
||||
add2panelize (g_strdup (_("Find SUID and SGID programs")),
|
||||
g_strdup
|
||||
("find . \\( \\( -perm -04000 -a -perm +011 \\) -o \\( -perm -02000 -a -perm +01 \\) \\) -print"));
|
||||
return;
|
||||
}
|
||||
|
||||
while (*profile_keys)
|
||||
{
|
||||
|
||||
if (utf8_display || conv == INVALID_CONV)
|
||||
{
|
||||
buffer = g_string_new (*profile_keys);
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer = g_string_new ("");
|
||||
if (str_convert (conv, *profile_keys, buffer) == ESTR_FAILURE)
|
||||
{
|
||||
g_string_free (buffer, TRUE);
|
||||
buffer = g_string_new (*profile_keys);
|
||||
}
|
||||
}
|
||||
|
||||
add2panelize (g_string_free (buffer, FALSE),
|
||||
mc_config_get_string (mc_main_config, panelize_section, *profile_keys, ""));
|
||||
profile_keys++;
|
||||
}
|
||||
g_strfreev (keys);
|
||||
str_close_conv (conv);
|
||||
}
|
||||
|
||||
void
|
||||
save_panelize (void)
|
||||
{
|
||||
struct panelize *current = panelize;
|
||||
|
||||
mc_config_del_group (mc_main_config, panelize_section);
|
||||
for (; current; current = current->next)
|
||||
{
|
||||
if (strcmp (current->label, _("Other command")))
|
||||
mc_config_set_string (mc_main_config,
|
||||
panelize_section, current->label, current->command);
|
||||
}
|
||||
mc_config_save_file (mc_main_config, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
done_panelize (void)
|
||||
{
|
||||
struct panelize *current = panelize;
|
||||
struct panelize *next;
|
||||
|
||||
for (; current; current = next)
|
||||
{
|
||||
next = current->next;
|
||||
g_free (current->label);
|
||||
g_free (current->command);
|
||||
g_free (current);
|
||||
}
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
do_external_panelize (char *command)
|
||||
@ -495,3 +389,149 @@ do_external_panelize (char *command)
|
||||
try_to_select (current_panel, NULL);
|
||||
panel_re_sort (current_panel);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
external_panelize (void)
|
||||
{
|
||||
char *target = NULL;
|
||||
|
||||
if (!vfs_current_is_local ())
|
||||
{
|
||||
message (D_ERROR, MSG_ERROR, _("Cannot run external panelize in a non-local directory"));
|
||||
return;
|
||||
}
|
||||
|
||||
init_panelize ();
|
||||
|
||||
/* display file info */
|
||||
tty_setcolor (SELECTED_COLOR);
|
||||
|
||||
run_dlg (panelize_dlg);
|
||||
|
||||
switch (panelize_dlg->ret_value)
|
||||
{
|
||||
case B_CANCEL:
|
||||
break;
|
||||
|
||||
case B_ADD:
|
||||
add2panelize_cmd ();
|
||||
break;
|
||||
|
||||
case B_REMOVE:
|
||||
{
|
||||
struct panelize *entry;
|
||||
|
||||
listbox_get_current (l_panelize, NULL, (void **) &entry);
|
||||
remove_from_panelize (entry);
|
||||
break;
|
||||
}
|
||||
|
||||
case B_ENTER:
|
||||
target = pname->buffer;
|
||||
if (target != NULL && *target)
|
||||
{
|
||||
char *cmd = g_strdup (target);
|
||||
destroy_dlg (panelize_dlg);
|
||||
do_external_panelize (cmd);
|
||||
g_free (cmd);
|
||||
repaint_screen ();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
panelize_done ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
load_panelize (void)
|
||||
{
|
||||
gchar **profile_keys, **keys;
|
||||
gsize len;
|
||||
GIConv conv;
|
||||
GString *buffer;
|
||||
|
||||
conv = str_crt_conv_from ("UTF-8");
|
||||
|
||||
profile_keys = keys = mc_config_get_keys (mc_main_config, panelize_section, &len);
|
||||
|
||||
add2panelize (g_strdup (_("Other command")), g_strdup (""));
|
||||
|
||||
if (!profile_keys || *profile_keys == NULL)
|
||||
{
|
||||
add2panelize (g_strdup (_("Find rejects after patching")),
|
||||
g_strdup ("find . -name \\*.rej -print"));
|
||||
add2panelize (g_strdup (_("Find *.orig after patching")),
|
||||
g_strdup ("find . -name \\*.orig -print"));
|
||||
add2panelize (g_strdup (_("Find SUID and SGID programs")),
|
||||
g_strdup
|
||||
("find . \\( \\( -perm -04000 -a -perm +011 \\) -o \\( -perm -02000 -a -perm +01 \\) \\) -print"));
|
||||
return;
|
||||
}
|
||||
|
||||
while (*profile_keys)
|
||||
{
|
||||
|
||||
if (utf8_display || conv == INVALID_CONV)
|
||||
{
|
||||
buffer = g_string_new (*profile_keys);
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer = g_string_new ("");
|
||||
if (str_convert (conv, *profile_keys, buffer) == ESTR_FAILURE)
|
||||
{
|
||||
g_string_free (buffer, TRUE);
|
||||
buffer = g_string_new (*profile_keys);
|
||||
}
|
||||
}
|
||||
|
||||
add2panelize (g_string_free (buffer, FALSE),
|
||||
mc_config_get_string (mc_main_config, panelize_section, *profile_keys, ""));
|
||||
profile_keys++;
|
||||
}
|
||||
g_strfreev (keys);
|
||||
str_close_conv (conv);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
save_panelize (void)
|
||||
{
|
||||
struct panelize *current = panelize;
|
||||
|
||||
mc_config_del_group (mc_main_config, panelize_section);
|
||||
for (; current; current = current->next)
|
||||
{
|
||||
if (strcmp (current->label, _("Other command")))
|
||||
mc_config_set_string (mc_main_config,
|
||||
panelize_section, current->label, current->command);
|
||||
}
|
||||
mc_config_save_file (mc_main_config, NULL);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
done_panelize (void)
|
||||
{
|
||||
struct panelize *current = panelize;
|
||||
struct panelize *next;
|
||||
|
||||
for (; current; current = next)
|
||||
{
|
||||
next = current->next;
|
||||
g_free (current->label);
|
||||
g_free (current->command);
|
||||
g_free (current);
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -1,14 +1,24 @@
|
||||
|
||||
/** \file panelize.h
|
||||
* \brief Header: External panelization module
|
||||
*/
|
||||
|
||||
#ifndef MC_PANELIZE_H
|
||||
#define MC_PANELIZE_H
|
||||
#ifndef MC__PANELIZE_H
|
||||
#define MC__PANELIZE_H
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
void external_panelize (void);
|
||||
void load_panelize (void);
|
||||
void save_panelize (void);
|
||||
void done_panelize (void);
|
||||
|
||||
#endif
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__PANELIZE_H */
|
||||
|
2284
src/screen.c
2284
src/screen.c
File diff suppressed because it is too large
Load Diff
@ -36,21 +36,37 @@
|
||||
#include "selcodepage.h"
|
||||
#include "main.h"
|
||||
|
||||
#define ENTRY_LEN 30
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
/* Numbers of (file I/O) and (input/display) codepages. -1 if not selected */
|
||||
int source_codepage = -1;
|
||||
int default_source_codepage = -1;
|
||||
int display_codepage = -1;
|
||||
char* autodetect_codeset = NULL;
|
||||
char *autodetect_codeset = NULL;
|
||||
gboolean is_autodetect_codeset_enabled = FALSE;
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
#define ENTRY_LEN 30
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
static unsigned char
|
||||
get_hotkey (int n)
|
||||
{
|
||||
return (n <= 9) ? '0' + n : 'a' + n - 10;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/* Return value:
|
||||
* -2 (SELECT_CHARSET_CANCEL) : Cancel
|
||||
* -1 (SELECT_CHARSET_OTHER_8BIT) : "Other 8 bit" if seldisplay == TRUE
|
||||
@ -66,54 +82,61 @@ select_charset (int center_y, int center_x, int current_charset, gboolean seldis
|
||||
|
||||
/* Create listbox */
|
||||
Listbox *listbox = create_listbox_window_centered (center_y, center_x,
|
||||
codepages->len + 1, ENTRY_LEN + 2,
|
||||
_("Choose codepage"),
|
||||
"[Codepages Translation]");
|
||||
codepages->len + 1, ENTRY_LEN + 2,
|
||||
_("Choose codepage"),
|
||||
"[Codepages Translation]");
|
||||
|
||||
if (!seldisplay)
|
||||
LISTBOX_APPEND_TEXT (listbox, '-', _("- < No translation >"),
|
||||
NULL);
|
||||
LISTBOX_APPEND_TEXT (listbox, '-', _("- < No translation >"), NULL);
|
||||
|
||||
/* insert all the items found */
|
||||
for (i = 0; i < codepages->len; i++) {
|
||||
const char *name = ((codepage_desc *) g_ptr_array_index (codepages, i))->name;
|
||||
g_snprintf (buffer, sizeof (buffer), "%c %s", get_hotkey (i),
|
||||
name);
|
||||
LISTBOX_APPEND_TEXT (listbox, get_hotkey (i), buffer, NULL);
|
||||
for (i = 0; i < codepages->len; i++)
|
||||
{
|
||||
const char *name = ((codepage_desc *) g_ptr_array_index (codepages, i))->name;
|
||||
g_snprintf (buffer, sizeof (buffer), "%c %s", get_hotkey (i), name);
|
||||
LISTBOX_APPEND_TEXT (listbox, get_hotkey (i), buffer, NULL);
|
||||
}
|
||||
if (seldisplay) {
|
||||
if (seldisplay)
|
||||
{
|
||||
unsigned char hotkey = get_hotkey (codepages->len);
|
||||
g_snprintf (buffer, sizeof (buffer), "%c %s", hotkey, _("Other 8 bit"));
|
||||
LISTBOX_APPEND_TEXT (listbox, hotkey, buffer, NULL);
|
||||
g_snprintf (buffer, sizeof (buffer), "%c %s", hotkey, _("Other 8 bit"));
|
||||
LISTBOX_APPEND_TEXT (listbox, hotkey, buffer, NULL);
|
||||
}
|
||||
|
||||
/* Select the default entry */
|
||||
i = (seldisplay)
|
||||
? ((current_charset < 0) ? codepages->len : (size_t) current_charset)
|
||||
: ((size_t)current_charset + 1);
|
||||
? ((current_charset < 0) ? codepages->len : (size_t) current_charset)
|
||||
: ((size_t) current_charset + 1);
|
||||
|
||||
listbox_select_entry (listbox->list, i);
|
||||
|
||||
listbox_result = run_listbox (listbox);
|
||||
|
||||
if (listbox_result < 0) {
|
||||
/* Cancel dialog */
|
||||
return SELECT_CHARSET_CANCEL;
|
||||
} else {
|
||||
/* some charset has been selected */
|
||||
if (seldisplay) {
|
||||
/* charset list is finished with "Other 8 bit" item */
|
||||
return (listbox_result >= (int) codepages->len)
|
||||
? SELECT_CHARSET_OTHER_8BIT
|
||||
: listbox_result;
|
||||
} else {
|
||||
/* charset list is began with "- < No translation >" item */
|
||||
return (listbox_result - 1);
|
||||
}
|
||||
if (listbox_result < 0)
|
||||
{
|
||||
/* Cancel dialog */
|
||||
return SELECT_CHARSET_CANCEL;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* some charset has been selected */
|
||||
if (seldisplay)
|
||||
{
|
||||
/* charset list is finished with "Other 8 bit" item */
|
||||
return (listbox_result >= (int) codepages->len)
|
||||
? SELECT_CHARSET_OTHER_8BIT : listbox_result;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* charset list is began with "- < No translation >" item */
|
||||
return (listbox_result - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Set codepage */
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Set codepage */
|
||||
gboolean
|
||||
do_set_codepage (int codepage)
|
||||
{
|
||||
@ -122,19 +145,20 @@ do_set_codepage (int codepage)
|
||||
|
||||
source_codepage = codepage;
|
||||
errmsg = init_translation_table (codepage == SELECT_CHARSET_NO_TRANSLATE ?
|
||||
display_codepage : source_codepage,
|
||||
display_codepage);
|
||||
display_codepage : source_codepage, display_codepage);
|
||||
ret = errmsg == NULL;
|
||||
|
||||
if (!ret) {
|
||||
message (D_ERROR, MSG_ERROR, "%s", errmsg);
|
||||
g_free (errmsg);
|
||||
if (!ret)
|
||||
{
|
||||
message (D_ERROR, MSG_ERROR, "%s", errmsg);
|
||||
g_free (errmsg);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Show menu selecting codepage */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Show menu selecting codepage */
|
||||
|
||||
gboolean
|
||||
do_select_codepage (void)
|
||||
@ -143,10 +167,12 @@ do_select_codepage (void)
|
||||
|
||||
r = select_charset (-1, -1, default_source_codepage, FALSE);
|
||||
if (r == SELECT_CHARSET_CANCEL)
|
||||
return FALSE;
|
||||
return FALSE;
|
||||
|
||||
default_source_codepage = r;
|
||||
return do_set_codepage (default_source_codepage);
|
||||
}
|
||||
|
||||
#endif /* HAVE_CHARSET */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
#endif /* HAVE_CHARSET */
|
||||
|
@ -3,14 +3,12 @@
|
||||
* \brief Header: user %interface for charset %selection
|
||||
*/
|
||||
|
||||
#ifndef MC_SELCODEPAGE_H
|
||||
#define MC_SELCODEPAGE_H
|
||||
#ifndef MC__SELCODEPAGE_H
|
||||
#define MC__SELCODEPAGE_H
|
||||
|
||||
#include "lib/global.h"
|
||||
|
||||
int select_charset (int center_y, int center_x, int current_charset, gboolean seldisplay);
|
||||
gboolean do_set_codepage (int);
|
||||
gboolean do_select_codepage (void);
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/* some results of select_charset() */
|
||||
#define SELECT_CHARSET_CANCEL -2
|
||||
@ -24,4 +22,18 @@ gboolean do_select_codepage (void);
|
||||
/* In other cases select_charset() returns non-negative value
|
||||
* which is number of codepage in codepage list */
|
||||
|
||||
#endif /* MC_SELCODEPAGE_H */
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
|
||||
int select_charset (int center_y, int center_x, int current_charset, gboolean seldisplay);
|
||||
gboolean do_set_codepage (int);
|
||||
gboolean do_select_codepage (void);
|
||||
|
||||
#endif /* MC__SELCODEPAGE_H */
|
||||
|
76
src/setup.c
76
src/setup.c
@ -71,8 +71,7 @@
|
||||
|
||||
#include "setup.h"
|
||||
|
||||
/*** global variables **************************************************/
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
char *profile_name; /* .mc/ini */
|
||||
char *global_profile_name; /* mc.lib */
|
||||
|
||||
@ -112,15 +111,15 @@ panels_options_t panels_options = {
|
||||
|
||||
int easy_patterns = 1;
|
||||
|
||||
/*** file scope macro definitions **************************************/
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
/* In order to use everywhere the same setup for the locale we use defines */
|
||||
#define FMTYEAR _("%b %e %Y")
|
||||
#define FMTTIME _("%b %e %H:%M")
|
||||
|
||||
/*** file scope type declarations **************************************/
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
/*** file scope variables **********************************************/
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
static char *panels_profile_name = NULL; /* .mc/panels.ini */
|
||||
|
||||
@ -301,7 +300,9 @@ static const struct
|
||||
|
||||
static const char *panels_section = "Panels";
|
||||
|
||||
/*** file scope functions **********************************************/
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
/**
|
||||
Get name of config file.
|
||||
@ -377,6 +378,8 @@ load_setup_get_full_config_name (const char *subdir, const char *config_file_nam
|
||||
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static const char *
|
||||
setup__is_cfg_group_must_panel_config (const char *grp)
|
||||
{
|
||||
@ -387,6 +390,8 @@ setup__is_cfg_group_must_panel_config (const char *grp)
|
||||
? grp : NULL;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
setup__move_panels_config_into_separate_file (const char *profile)
|
||||
{
|
||||
@ -442,11 +447,13 @@ setup__move_panels_config_into_separate_file (const char *profile)
|
||||
mc_config_deinit (tmp_cfg);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
Create new mc_config object from specified ini-file or
|
||||
append data to existing mc_config object from ini-file
|
||||
|
||||
*/
|
||||
|
||||
static void
|
||||
load_setup_init_config_from_file (mc_config_t ** config, const char *fname)
|
||||
{
|
||||
@ -462,6 +469,8 @@ load_setup_init_config_from_file (mc_config_t ** config, const char *fname)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
load_layout (void)
|
||||
{
|
||||
@ -472,6 +481,8 @@ load_layout (void)
|
||||
layout[i].opt_name, *layout[i].opt_addr);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
load_keys_from_section (const char *terminal, mc_config_t * cfg)
|
||||
{
|
||||
@ -536,6 +547,8 @@ load_keys_from_section (const char *terminal, mc_config_t * cfg)
|
||||
g_free (section_name);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
load_keymap_from_section (const char *section_name, GArray * keymap, mc_config_t * cfg)
|
||||
{
|
||||
@ -587,6 +600,8 @@ load_keymap_from_section (const char *section_name, GArray * keymap, mc_config_t
|
||||
g_strfreev (keys);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static mc_config_t *
|
||||
load_setup_get_keymap_profile_config (void)
|
||||
{
|
||||
@ -642,6 +657,8 @@ load_setup_get_keymap_profile_config (void)
|
||||
return keymap_config;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static panel_view_mode_t
|
||||
setup__load_panel_state (const char *section)
|
||||
{
|
||||
@ -664,6 +681,8 @@ setup__load_panel_state (const char *section)
|
||||
return mode;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
panel_save_type (const char *section, panel_view_mode_t type)
|
||||
{
|
||||
@ -677,7 +696,9 @@ panel_save_type (const char *section, panel_view_mode_t type)
|
||||
}
|
||||
}
|
||||
|
||||
/*** public functions **************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
char *
|
||||
setup_init (void)
|
||||
@ -716,6 +737,8 @@ setup_init (void)
|
||||
return profile;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
load_setup (void)
|
||||
{
|
||||
@ -850,6 +873,8 @@ load_setup (void)
|
||||
clipboard_paste_path = mc_config_get_string (mc_main_config, "Misc", "clipboard_paste", "");
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
gboolean
|
||||
save_setup (void)
|
||||
{
|
||||
@ -890,6 +915,8 @@ save_setup (void)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
done_setup (void)
|
||||
{
|
||||
@ -915,6 +942,8 @@ done_setup (void)
|
||||
/* directory_history_free (); */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
save_config (void)
|
||||
{
|
||||
@ -940,6 +969,8 @@ save_config (void)
|
||||
g_free (profile);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
setup_save_config_show_error (const char *filename, GError ** error)
|
||||
{
|
||||
@ -951,6 +982,8 @@ setup_save_config_show_error (const char *filename, GError ** error)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
save_layout (void)
|
||||
{
|
||||
@ -965,6 +998,8 @@ save_layout (void)
|
||||
g_free (profile);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
load_key_defs (void)
|
||||
{
|
||||
@ -986,6 +1021,8 @@ load_key_defs (void)
|
||||
load_keys_from_section (getenv ("TERM"), mc_main_config);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
#ifdef ENABLE_VFS_FTP
|
||||
char *
|
||||
load_anon_passwd (void)
|
||||
@ -1002,6 +1039,8 @@ load_anon_passwd (void)
|
||||
}
|
||||
#endif /* ENABLE_VFS_FTP */
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
load_keymap_defs (void)
|
||||
{
|
||||
@ -1097,6 +1136,8 @@ load_keymap_defs (void)
|
||||
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
free_keymap_defs (void)
|
||||
{
|
||||
@ -1132,6 +1173,8 @@ free_keymap_defs (void)
|
||||
#endif
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
panel_load_setup (WPanel * panel, const char *section)
|
||||
{
|
||||
@ -1179,6 +1222,8 @@ panel_load_setup (WPanel * panel, const char *section)
|
||||
panel->user_mini_status = mc_config_get_int (mc_panels_config, section, "user_mini_status", 0);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
panel_save_setup (struct WPanel *panel, const char *section)
|
||||
{
|
||||
@ -1209,6 +1254,8 @@ panel_save_setup (struct WPanel *panel, const char *section)
|
||||
mc_config_set_int (mc_panels_config, section, "user_mini_status", panel->user_mini_status);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
save_panel_types (void)
|
||||
{
|
||||
@ -1244,6 +1291,8 @@ save_panel_types (void)
|
||||
mc_config_save_file (mc_panels_config, NULL);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
Load panels options from [Panels] section.
|
||||
*/
|
||||
@ -1258,11 +1307,12 @@ panels_load_options (void)
|
||||
*panels_ini_options[i].opt_addr =
|
||||
mc_config_get_int (mc_main_config, CONFIG_APP_SECTION,
|
||||
panels_ini_options[i].opt_old_name != NULL
|
||||
? panels_ini_options[i].opt_old_name : panels_ini_options[i].opt_name,
|
||||
? panels_ini_options[i].
|
||||
opt_old_name : panels_ini_options[i].opt_name,
|
||||
*panels_ini_options[i].opt_addr);
|
||||
|
||||
qmode = mc_config_get_int (mc_main_config, CONFIG_APP_SECTION,
|
||||
"quick_search_case_sensitive", (int) panels_options.qsearch_mode);
|
||||
"quick_search_case_sensitive", (int) panels_options.qsearch_mode);
|
||||
if (qmode < 0)
|
||||
panels_options.qsearch_mode = QSEARCH_CASE_INSENSITIVE;
|
||||
else if (qmode >= QSEARCH_NUM)
|
||||
@ -1280,7 +1330,7 @@ panels_load_options (void)
|
||||
*panels_ini_options[i].opt_addr);
|
||||
|
||||
qmode = mc_config_get_int (mc_main_config, panels_section,
|
||||
"quick_search_mode", (int) panels_options.qsearch_mode);
|
||||
"quick_search_mode", (int) panels_options.qsearch_mode);
|
||||
if (qmode < 0)
|
||||
panels_options.qsearch_mode = QSEARCH_CASE_INSENSITIVE;
|
||||
else if (qmode >= QSEARCH_NUM)
|
||||
@ -1290,6 +1340,8 @@ panels_load_options (void)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
Save panels options in [Panels] section.
|
||||
*/
|
||||
@ -1303,5 +1355,7 @@ panels_save_options (void)
|
||||
panels_ini_options[i].opt_name, *panels_ini_options[i].opt_addr);
|
||||
|
||||
mc_config_set_int (mc_main_config, panels_section,
|
||||
"quick_search_mode", (int) panels_options.qsearch_mode);
|
||||
"quick_search_mode", (int) panels_options.qsearch_mode);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
98
src/setup.h
98
src/setup.h
@ -1,17 +1,57 @@
|
||||
|
||||
/** \file setup.h
|
||||
* \brief Header: setup loading/saving
|
||||
*/
|
||||
|
||||
#ifndef MC_SETUP_H
|
||||
#define MC_SETUP_H
|
||||
#ifndef MC__SETUP_H
|
||||
#define MC__SETUP_H
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "lib/global.h" /* GError */
|
||||
|
||||
#include "panel.h" /* WPanel, panel_view_mode_t */
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/* TAB length for editor and viewer */
|
||||
#define DEFAULT_TAB_SPACING 8
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
typedef enum
|
||||
{
|
||||
QSEARCH_CASE_INSENSITIVE = 0, /* quick search in case insensitive mode */
|
||||
QSEARCH_CASE_SENSITIVE = 1, /* quick search in case sensitive mode */
|
||||
QSEARCH_PANEL_CASE = 2, /* quick search get value from panel case_sensitive */
|
||||
QSEARCH_NUM
|
||||
} qsearch_mode_t;
|
||||
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
/* panels ini options; [Panels] section */
|
||||
typedef struct
|
||||
{
|
||||
gboolean kilobyte_si; /* If TRUE, SI units (1000 based) will be used for larger units
|
||||
* (kilobyte, megabyte, ...). If FALSE, binary units (1024 based) will be used */
|
||||
gboolean mix_all_files; /* If FALSE then directories are shown separately from files */
|
||||
gboolean show_backups; /* If TRUE, show files ending in ~ */
|
||||
gboolean show_dot_files; /* If TRUE, show files starting with a dot */
|
||||
gboolean fast_reload; /* If TRUE then use stat() on the cwd to determine directory changes */
|
||||
gboolean fast_reload_msg_shown; /* Have we shown the fast-reload warning in the past? */
|
||||
gboolean mark_moves_down; /* If TRUE, marking a files moves the cursor down */
|
||||
gboolean reverse_files_only; /* If TRUE, only selection of files is inverted */
|
||||
gboolean auto_save_setup;
|
||||
gboolean navigate_with_arrows; /* If TRUE: l&r arrows are used to chdir if the input line is empty */
|
||||
gboolean scroll_pages; /* If TRUE, panel is scrolled by half the display when the cursor reaches
|
||||
the end or the beginning of the panel */
|
||||
gboolean mouse_move_pages; /* Scroll page/item using mouse wheel */
|
||||
gboolean filetype_mode; /* If TRUE then add per file type hilighting */
|
||||
gboolean permission_mode; /* If TRUE, we use permission hilighting */
|
||||
qsearch_mode_t qsearch_mode; /* Quick search mode */
|
||||
} panels_options_t;
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/* global paremeters */
|
||||
extern char *profile_name;
|
||||
extern char *global_profile_name;
|
||||
@ -25,17 +65,21 @@ extern int setup_copymove_persistent_attr;
|
||||
extern int num_history_items_recorded;
|
||||
extern int classic_progressbar;
|
||||
extern int easy_patterns;
|
||||
|
||||
/* TAB length for editor and viewer */
|
||||
#define DEFAULT_TAB_SPACING 8
|
||||
extern int option_tab_spacing;
|
||||
|
||||
extern panels_options_t panels_options;
|
||||
|
||||
extern panel_view_mode_t startup_left_mode;
|
||||
extern panel_view_mode_t startup_right_mode;
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
char *setup_init (void);
|
||||
void load_setup (void);
|
||||
gboolean save_setup (void);
|
||||
void done_setup (void);
|
||||
void save_config (void);
|
||||
void setup_save_config_show_error (const char *filename, GError **error);
|
||||
void setup_save_config_show_error (const char *filename, GError ** error);
|
||||
|
||||
void save_layout (void);
|
||||
|
||||
@ -47,41 +91,6 @@ char *load_anon_passwd (void);
|
||||
void load_keymap_defs (void);
|
||||
void free_keymap_defs (void);
|
||||
|
||||
typedef enum
|
||||
{
|
||||
QSEARCH_CASE_INSENSITIVE = 0, /* quick search in case insensitive mode */
|
||||
QSEARCH_CASE_SENSITIVE = 1, /* quick search in case sensitive mode */
|
||||
QSEARCH_PANEL_CASE = 2, /* quick search get value from panel case_sensitive */
|
||||
QSEARCH_NUM
|
||||
} qsearch_mode_t;
|
||||
|
||||
/* panels ini options; [Panels] section */
|
||||
typedef struct
|
||||
{
|
||||
gboolean kilobyte_si; /* If TRUE, SI units (1000 based) will be used for larger units
|
||||
* (kilobyte, megabyte, ...). If FALSE, binary units (1024 based) will be used */
|
||||
gboolean mix_all_files; /* If FALSE then directories are shown separately from files */
|
||||
gboolean show_backups; /* If TRUE, show files ending in ~ */
|
||||
gboolean show_dot_files; /* If TRUE, show files starting with a dot */
|
||||
gboolean fast_reload; /* If TRUE then use stat() on the cwd to determine directory changes */
|
||||
gboolean fast_reload_msg_shown; /* Have we shown the fast-reload warning in the past? */
|
||||
gboolean mark_moves_down; /* If TRUE, marking a files moves the cursor down */
|
||||
gboolean reverse_files_only; /* If TRUE, only selection of files is inverted */
|
||||
gboolean auto_save_setup;
|
||||
gboolean navigate_with_arrows; /* If TRUE: l&r arrows are used to chdir if the input line is empty */
|
||||
gboolean scroll_pages; /* If TRUE, panel is scrolled by half the display when the cursor reaches
|
||||
the end or the beginning of the panel */
|
||||
gboolean mouse_move_pages; /* Scroll page/item using mouse wheel */
|
||||
gboolean filetype_mode; /* If TRUE then add per file type hilighting */
|
||||
gboolean permission_mode; /* If TRUE, we use permission hilighting */
|
||||
qsearch_mode_t qsearch_mode; /* Quick search mode */
|
||||
} panels_options_t;
|
||||
|
||||
extern panels_options_t panels_options;
|
||||
|
||||
extern panel_view_mode_t startup_left_mode;
|
||||
extern panel_view_mode_t startup_right_mode;
|
||||
|
||||
void panel_load_setup (struct WPanel *panel, const char *section);
|
||||
void panel_save_setup (struct WPanel *panel, const char *section);
|
||||
void save_panel_types (void);
|
||||
@ -89,4 +98,5 @@ void save_panel_types (void);
|
||||
void panels_load_options (void);
|
||||
void panels_save_options (void);
|
||||
|
||||
#endif /* MC_SETUP_H */
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__SETUP_H */
|
||||
|
833
src/subshell.c
833
src/subshell.c
@ -25,7 +25,7 @@
|
||||
#ifdef HAVE_SUBSHELL_SUPPORT
|
||||
|
||||
#ifndef _GNU_SOURCE
|
||||
# define _GNU_SOURCE 1
|
||||
#define _GNU_SOURCE 1
|
||||
#endif
|
||||
|
||||
#include <ctype.h>
|
||||
@ -38,13 +38,13 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#ifdef HAVE_SYS_IOCTL_H
|
||||
# include <sys/ioctl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#endif
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifdef HAVE_STROPTS_H
|
||||
# include <stropts.h> /* For I_PUSH */
|
||||
#include <stropts.h> /* For I_PUSH */
|
||||
#endif /* HAVE_STROPTS_H */
|
||||
|
||||
#include "lib/global.h"
|
||||
@ -60,36 +60,7 @@
|
||||
#include "consaver/cons.saver.h" /* handle_console() */
|
||||
#include "subshell.h"
|
||||
|
||||
#ifndef WEXITSTATUS
|
||||
# define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
|
||||
#endif
|
||||
|
||||
#ifndef WIFEXITED
|
||||
# define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
|
||||
#endif
|
||||
|
||||
/* tcsh closes all non-standard file descriptors, so we have to use a pipe */
|
||||
static char tcsh_fifo[128];
|
||||
|
||||
/* Local functions */
|
||||
static void init_raw_mode (void);
|
||||
static gboolean feed_subshell (int how, int fail_on_error);
|
||||
static void synchronize (void);
|
||||
static int pty_open_master (char *pty_name);
|
||||
static int pty_open_slave (const char *pty_name);
|
||||
static int resize_tty (int fd);
|
||||
|
||||
#ifndef STDIN_FILENO
|
||||
# define STDIN_FILENO 0
|
||||
#endif
|
||||
|
||||
#ifndef STDOUT_FILENO
|
||||
# define STDOUT_FILENO 1
|
||||
#endif
|
||||
|
||||
#ifndef STDERR_FILENO
|
||||
# define STDERR_FILENO 2
|
||||
#endif
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
/* If using a subshell for evaluating commands this is true */
|
||||
int use_subshell =
|
||||
@ -101,10 +72,6 @@ int use_subshell =
|
||||
|
||||
/* File descriptors of the pseudoterminal used by the subshell */
|
||||
int subshell_pty = 0;
|
||||
static int subshell_pty_slave = -1;
|
||||
|
||||
/* The key for switching back to MC from the subshell */
|
||||
static const char subshell_switch_key = XCTRL ('o') & 255;
|
||||
|
||||
/* State of the subshell:
|
||||
* INACTIVE: the default state; awaiting a command
|
||||
@ -115,6 +82,28 @@ enum subshell_state_enum subshell_state;
|
||||
/* Holds the latest prompt captured from the subshell */
|
||||
char *subshell_prompt = NULL;
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
#ifndef WEXITSTATUS
|
||||
#define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
|
||||
#endif
|
||||
|
||||
#ifndef WIFEXITED
|
||||
#define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
|
||||
#endif
|
||||
|
||||
#ifndef STDIN_FILENO
|
||||
#define STDIN_FILENO 0
|
||||
#endif
|
||||
|
||||
#ifndef STDOUT_FILENO
|
||||
#define STDOUT_FILENO 1
|
||||
#endif
|
||||
|
||||
#ifndef STDERR_FILENO
|
||||
#define STDERR_FILENO 2
|
||||
#endif
|
||||
|
||||
/* Initial length of the buffer for the subshell's prompt */
|
||||
#define INITIAL_PROMPT_SIZE 10
|
||||
|
||||
@ -124,6 +113,8 @@ char *subshell_prompt = NULL;
|
||||
/* Length of the buffer for all I/O with the subshell */
|
||||
#define PTY_BUFFER_SIZE BUF_SMALL /* Arbitrary; but keep it >= 80 */
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
/* For pipes */
|
||||
enum
|
||||
{
|
||||
@ -131,11 +122,6 @@ enum
|
||||
WRITE = 1
|
||||
};
|
||||
|
||||
static char pty_buffer[PTY_BUFFER_SIZE] = "\0"; /* For reading/writing on the subshell's pty */
|
||||
static int subshell_pipe[2]; /* To pass CWD info from the subshell to MC */
|
||||
static pid_t subshell_pid = 1; /* The subshell's process ID */
|
||||
static char subshell_cwd[MC_MAXPATHLEN + 1]; /* One extra char for final '\n' */
|
||||
|
||||
/* Subshell type (gleaned from the SHELL environment variable, if available) */
|
||||
static enum
|
||||
{
|
||||
@ -145,6 +131,30 @@ static enum
|
||||
FISH
|
||||
} subshell_type;
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
/* tcsh closes all non-standard file descriptors, so we have to use a pipe */
|
||||
static char tcsh_fifo[128];
|
||||
|
||||
static int subshell_pty_slave = -1;
|
||||
|
||||
/* The key for switching back to MC from the subshell */
|
||||
/* *INDENT-OFF* */
|
||||
static const char subshell_switch_key = XCTRL ('o') & 255;
|
||||
/* *INDENT-ON* */
|
||||
|
||||
/* For reading/writing on the subshell's pty */
|
||||
static char pty_buffer[PTY_BUFFER_SIZE] = "\0";
|
||||
|
||||
/* To pass CWD info from the subshell to MC */
|
||||
static int subshell_pipe[2];
|
||||
|
||||
/* The subshell's process ID */
|
||||
static pid_t subshell_pid = 1;
|
||||
|
||||
/* One extra char for final '\n' */
|
||||
static char subshell_cwd[MC_MAXPATHLEN + 1];
|
||||
|
||||
/* Flag to indicate whether the subshell is ready for next command */
|
||||
static int subshell_ready;
|
||||
|
||||
@ -167,9 +177,21 @@ static struct termios raw_mode;
|
||||
static int prompt_pos;
|
||||
|
||||
|
||||
/*
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void init_raw_mode (void);
|
||||
static gboolean feed_subshell (int how, int fail_on_error);
|
||||
static void synchronize (void);
|
||||
static int pty_open_master (char *pty_name);
|
||||
static int pty_open_slave (const char *pty_name);
|
||||
static int resize_tty (int fd);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Write all data, even if the write() call is interrupted.
|
||||
*/
|
||||
|
||||
static ssize_t
|
||||
write_all (int fd, const void *buf, size_t count)
|
||||
{
|
||||
@ -195,7 +217,8 @@ write_all (int fd, const void *buf, size_t count)
|
||||
return written;
|
||||
}
|
||||
|
||||
/*
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Prepare child process to running the shell and run it.
|
||||
*
|
||||
* Modifies the global variables (in the child process only):
|
||||
@ -203,6 +226,7 @@ write_all (int fd, const void *buf, size_t count)
|
||||
*
|
||||
* Returns: never.
|
||||
*/
|
||||
|
||||
static void
|
||||
init_subshell_child (const char *pty_name)
|
||||
{
|
||||
@ -326,13 +350,15 @@ init_subshell_child (const char *pty_name)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Check MC_SID to prevent running one mc from another.
|
||||
* Return:
|
||||
* 0 if no parent mc in our session was found,
|
||||
* 1 if parent mc was found and the user wants to continue,
|
||||
* 2 if parent mc was found and the user wants to quit mc.
|
||||
*/
|
||||
|
||||
static int
|
||||
check_sid (void)
|
||||
{
|
||||
@ -368,8 +394,358 @@ check_sid (void)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/*
|
||||
static void
|
||||
init_raw_mode ()
|
||||
{
|
||||
static int initialized = 0;
|
||||
|
||||
/* MC calls tty_reset_shell_mode() in pre_exec() to set the real tty to its */
|
||||
/* original settings. However, here we need to make this tty very raw, */
|
||||
/* so that all keyboard signals, XON/XOFF, etc. will get through to the */
|
||||
/* pty. So, instead of changing the code for execute(), pre_exec(), */
|
||||
/* etc, we just set up the modes we need here, before each command. */
|
||||
|
||||
if (initialized == 0) /* First time: initialise `raw_mode' */
|
||||
{
|
||||
tcgetattr (STDOUT_FILENO, &raw_mode);
|
||||
raw_mode.c_lflag &= ~ICANON; /* Disable line-editing chars, etc. */
|
||||
raw_mode.c_lflag &= ~ISIG; /* Disable intr, quit & suspend chars */
|
||||
raw_mode.c_lflag &= ~ECHO; /* Disable input echoing */
|
||||
raw_mode.c_iflag &= ~IXON; /* Pass ^S/^Q to subshell undisturbed */
|
||||
raw_mode.c_iflag &= ~ICRNL; /* Don't translate CRs into LFs */
|
||||
raw_mode.c_oflag &= ~OPOST; /* Don't postprocess output */
|
||||
raw_mode.c_cc[VTIME] = 0; /* IE: wait forever, and return as */
|
||||
raw_mode.c_cc[VMIN] = 1; /* soon as a character is available */
|
||||
initialized = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Feed the subshell our keyboard input until it says it's finished */
|
||||
|
||||
static gboolean
|
||||
feed_subshell (int how, int fail_on_error)
|
||||
{
|
||||
fd_set read_set; /* For `select' */
|
||||
int maxfdp;
|
||||
int bytes; /* For the return value from `read' */
|
||||
int i; /* Loop counter */
|
||||
|
||||
struct timeval wtime; /* Maximum time we wait for the subshell */
|
||||
struct timeval *wptr;
|
||||
|
||||
/* we wait up to 10 seconds if fail_on_error, forever otherwise */
|
||||
wtime.tv_sec = 10;
|
||||
wtime.tv_usec = 0;
|
||||
wptr = fail_on_error ? &wtime : NULL;
|
||||
|
||||
while (TRUE)
|
||||
{
|
||||
if (!subshell_alive)
|
||||
return FALSE;
|
||||
|
||||
/* Prepare the file-descriptor set and call `select' */
|
||||
|
||||
FD_ZERO (&read_set);
|
||||
FD_SET (subshell_pty, &read_set);
|
||||
FD_SET (subshell_pipe[READ], &read_set);
|
||||
maxfdp = max (subshell_pty, subshell_pipe[READ]);
|
||||
if (how == VISIBLY)
|
||||
{
|
||||
FD_SET (STDIN_FILENO, &read_set);
|
||||
maxfdp = max (maxfdp, STDIN_FILENO);
|
||||
}
|
||||
|
||||
if (select (maxfdp + 1, &read_set, NULL, NULL, wptr) == -1)
|
||||
{
|
||||
|
||||
/* Despite using SA_RESTART, we still have to check for this */
|
||||
if (errno == EINTR)
|
||||
continue; /* try all over again */
|
||||
tcsetattr (STDOUT_FILENO, TCSANOW, &shell_mode);
|
||||
fprintf (stderr, "select (FD_SETSIZE, &read_set...): %s\r\n",
|
||||
unix_error_string (errno));
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (FD_ISSET (subshell_pty, &read_set))
|
||||
/* Read from the subshell, write to stdout */
|
||||
|
||||
/* This loop improves performance by reducing context switches
|
||||
by a factor of 20 or so... unfortunately, it also hangs MC
|
||||
randomly, because of an apparent Linux bug. Investigate. */
|
||||
/* for (i=0; i<5; ++i) * FIXME -- experimental */
|
||||
{
|
||||
bytes = read (subshell_pty, pty_buffer, sizeof (pty_buffer));
|
||||
|
||||
/* The subshell has died */
|
||||
if (bytes == -1 && errno == EIO && !subshell_alive)
|
||||
return FALSE;
|
||||
|
||||
if (bytes <= 0)
|
||||
{
|
||||
tcsetattr (STDOUT_FILENO, TCSANOW, &shell_mode);
|
||||
fprintf (stderr, "read (subshell_pty...): %s\r\n", unix_error_string (errno));
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (how == VISIBLY)
|
||||
write_all (STDOUT_FILENO, pty_buffer, bytes);
|
||||
}
|
||||
|
||||
else if (FD_ISSET (subshell_pipe[READ], &read_set))
|
||||
/* Read the subshell's CWD and capture its prompt */
|
||||
{
|
||||
bytes = read (subshell_pipe[READ], subshell_cwd, MC_MAXPATHLEN + 1);
|
||||
if (bytes <= 0)
|
||||
{
|
||||
tcsetattr (STDOUT_FILENO, TCSANOW, &shell_mode);
|
||||
fprintf (stderr, "read (subshell_pipe[READ]...): %s\r\n",
|
||||
unix_error_string (errno));
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
subshell_cwd[bytes - 1] = 0; /* Squash the final '\n' */
|
||||
|
||||
synchronize ();
|
||||
|
||||
subshell_ready = TRUE;
|
||||
if (subshell_state == RUNNING_COMMAND)
|
||||
{
|
||||
subshell_state = INACTIVE;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
else if (FD_ISSET (STDIN_FILENO, &read_set))
|
||||
/* Read from stdin, write to the subshell */
|
||||
{
|
||||
bytes = read (STDIN_FILENO, pty_buffer, sizeof (pty_buffer));
|
||||
if (bytes <= 0)
|
||||
{
|
||||
tcsetattr (STDOUT_FILENO, TCSANOW, &shell_mode);
|
||||
fprintf (stderr,
|
||||
"read (STDIN_FILENO, pty_buffer...): %s\r\n", unix_error_string (errno));
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
for (i = 0; i < bytes; ++i)
|
||||
if (pty_buffer[i] == subshell_switch_key)
|
||||
{
|
||||
write_all (subshell_pty, pty_buffer, i);
|
||||
if (subshell_ready)
|
||||
subshell_state = INACTIVE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
write_all (subshell_pty, pty_buffer, bytes);
|
||||
|
||||
if (pty_buffer[bytes - 1] == '\n' || pty_buffer[bytes - 1] == '\r')
|
||||
subshell_ready = FALSE;
|
||||
}
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Wait until the subshell dies or stops. If it stops, make it resume.
|
||||
* Possibly modifies the globals `subshell_alive' and `subshell_stopped'
|
||||
*/
|
||||
|
||||
static void
|
||||
synchronize (void)
|
||||
{
|
||||
sigset_t sigchld_mask, old_mask;
|
||||
|
||||
sigemptyset (&sigchld_mask);
|
||||
sigaddset (&sigchld_mask, SIGCHLD);
|
||||
sigprocmask (SIG_BLOCK, &sigchld_mask, &old_mask);
|
||||
|
||||
/*
|
||||
* SIGCHLD should not be blocked, but we unblock it just in case.
|
||||
* This is known to be useful for cygwin 1.3.12 and older.
|
||||
*/
|
||||
sigdelset (&old_mask, SIGCHLD);
|
||||
|
||||
/* Wait until the subshell has stopped */
|
||||
while (subshell_alive && !subshell_stopped)
|
||||
sigsuspend (&old_mask);
|
||||
|
||||
if (subshell_state != ACTIVE)
|
||||
{
|
||||
/* Discard all remaining data from stdin to the subshell */
|
||||
tcflush (subshell_pty_slave, TCIFLUSH);
|
||||
}
|
||||
|
||||
subshell_stopped = FALSE;
|
||||
kill (subshell_pid, SIGCONT);
|
||||
|
||||
sigprocmask (SIG_SETMASK, &old_mask, NULL);
|
||||
/* We can't do any better without modifying the shell(s) */
|
||||
}
|
||||
|
||||
/* pty opening functions */
|
||||
|
||||
#ifdef HAVE_GRANTPT
|
||||
|
||||
/* System V version of pty_open_master */
|
||||
|
||||
static int
|
||||
pty_open_master (char *pty_name)
|
||||
{
|
||||
char *slave_name;
|
||||
int pty_master;
|
||||
|
||||
#ifdef HAVE_POSIX_OPENPT
|
||||
pty_master = posix_openpt (O_RDWR);
|
||||
#elif HAVE_GETPT
|
||||
/* getpt () is a GNU extension (glibc 2.1.x) */
|
||||
pty_master = getpt ();
|
||||
#elif IS_AIX
|
||||
strcpy (pty_name, "/dev/ptc");
|
||||
pty_master = open (pty_name, O_RDWR);
|
||||
#else
|
||||
strcpy (pty_name, "/dev/ptmx");
|
||||
pty_master = open (pty_name, O_RDWR);
|
||||
#endif
|
||||
|
||||
if (pty_master == -1)
|
||||
return -1;
|
||||
|
||||
if (grantpt (pty_master) == -1 /* Grant access to slave */
|
||||
|| unlockpt (pty_master) == -1 /* Clear slave's lock flag */
|
||||
|| !(slave_name = ptsname (pty_master))) /* Get slave's name */
|
||||
{
|
||||
close (pty_master);
|
||||
return -1;
|
||||
}
|
||||
strcpy (pty_name, slave_name);
|
||||
return pty_master;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** System V version of pty_open_slave */
|
||||
|
||||
static int
|
||||
pty_open_slave (const char *pty_name)
|
||||
{
|
||||
int pty_slave = open (pty_name, O_RDWR);
|
||||
|
||||
if (pty_slave == -1)
|
||||
{
|
||||
fprintf (stderr, "open (%s, O_RDWR): %s\r\n", pty_name, unix_error_string (errno));
|
||||
return -1;
|
||||
}
|
||||
#if !defined(__osf__) && !defined(__linux__)
|
||||
#if defined (I_FIND) && defined (I_PUSH)
|
||||
if (!ioctl (pty_slave, I_FIND, "ptem"))
|
||||
if (ioctl (pty_slave, I_PUSH, "ptem") == -1)
|
||||
{
|
||||
fprintf (stderr, "ioctl (%d, I_PUSH, \"ptem\") failed: %s\r\n",
|
||||
pty_slave, unix_error_string (errno));
|
||||
close (pty_slave);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!ioctl (pty_slave, I_FIND, "ldterm"))
|
||||
if (ioctl (pty_slave, I_PUSH, "ldterm") == -1)
|
||||
{
|
||||
fprintf (stderr,
|
||||
"ioctl (%d, I_PUSH, \"ldterm\") failed: %s\r\n",
|
||||
pty_slave, unix_error_string (errno));
|
||||
close (pty_slave);
|
||||
return -1;
|
||||
}
|
||||
#if !defined(sgi) && !defined(__sgi)
|
||||
if (!ioctl (pty_slave, I_FIND, "ttcompat"))
|
||||
if (ioctl (pty_slave, I_PUSH, "ttcompat") == -1)
|
||||
{
|
||||
fprintf (stderr,
|
||||
"ioctl (%d, I_PUSH, \"ttcompat\") failed: %s\r\n",
|
||||
pty_slave, unix_error_string (errno));
|
||||
close (pty_slave);
|
||||
return -1;
|
||||
}
|
||||
#endif /* sgi || __sgi */
|
||||
#endif /* I_FIND && I_PUSH */
|
||||
#endif /* __osf__ || __linux__ */
|
||||
|
||||
fcntl (pty_slave, F_SETFD, FD_CLOEXEC);
|
||||
return pty_slave;
|
||||
}
|
||||
|
||||
#else /* !HAVE_GRANTPT */
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** BSD version of pty_open_master */
|
||||
static int
|
||||
pty_open_master (char *pty_name)
|
||||
{
|
||||
int pty_master;
|
||||
const char *ptr1, *ptr2;
|
||||
|
||||
strcpy (pty_name, "/dev/ptyXX");
|
||||
for (ptr1 = "pqrstuvwxyzPQRST"; *ptr1; ++ptr1)
|
||||
{
|
||||
pty_name[8] = *ptr1;
|
||||
for (ptr2 = "0123456789abcdef"; *ptr2 != '\0'; ++ptr2)
|
||||
{
|
||||
pty_name[9] = *ptr2;
|
||||
|
||||
/* Try to open master */
|
||||
pty_master = open (pty_name, O_RDWR);
|
||||
if (pty_master == -1)
|
||||
{
|
||||
if (errno == ENOENT) /* Different from EIO */
|
||||
return -1; /* Out of pty devices */
|
||||
continue; /* Try next pty device */
|
||||
}
|
||||
pty_name[5] = 't'; /* Change "pty" to "tty" */
|
||||
if (access (pty_name, 6) != 0)
|
||||
{
|
||||
close (pty_master);
|
||||
pty_name[5] = 'p';
|
||||
continue;
|
||||
}
|
||||
return pty_master;
|
||||
}
|
||||
}
|
||||
return -1; /* Ran out of pty devices */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** BSD version of pty_open_slave */
|
||||
|
||||
static int
|
||||
pty_open_slave (const char *pty_name)
|
||||
{
|
||||
int pty_slave;
|
||||
struct group *group_info = getgrnam ("tty");
|
||||
|
||||
if (group_info != NULL)
|
||||
{
|
||||
/* The following two calls will only succeed if we are root */
|
||||
/* [Commented out while permissions problem is investigated] */
|
||||
/* chown (pty_name, getuid (), group_info->gr_gid); FIXME */
|
||||
/* chmod (pty_name, S_IRUSR | S_IWUSR | S_IWGRP); FIXME */
|
||||
}
|
||||
pty_slave = open (pty_name, O_RDWR);
|
||||
if (pty_slave == -1)
|
||||
fprintf (stderr, "open (pty_name, O_RDWR): %s\r\n", pty_name);
|
||||
fcntl (pty_slave, F_SETFD, FD_CLOEXEC);
|
||||
return pty_slave;
|
||||
}
|
||||
#endif /* !HAVE_GRANTPT */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Fork the subshell, and set up many, many things.
|
||||
*
|
||||
* Possibly modifies the global variables:
|
||||
@ -533,33 +909,7 @@ init_subshell (void)
|
||||
use_subshell = FALSE; /* Subshell died instantly, so don't use it */
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
init_raw_mode ()
|
||||
{
|
||||
static int initialized = 0;
|
||||
|
||||
/* MC calls tty_reset_shell_mode() in pre_exec() to set the real tty to its */
|
||||
/* original settings. However, here we need to make this tty very raw, */
|
||||
/* so that all keyboard signals, XON/XOFF, etc. will get through to the */
|
||||
/* pty. So, instead of changing the code for execute(), pre_exec(), */
|
||||
/* etc, we just set up the modes we need here, before each command. */
|
||||
|
||||
if (initialized == 0) /* First time: initialise `raw_mode' */
|
||||
{
|
||||
tcgetattr (STDOUT_FILENO, &raw_mode);
|
||||
raw_mode.c_lflag &= ~ICANON; /* Disable line-editing chars, etc. */
|
||||
raw_mode.c_lflag &= ~ISIG; /* Disable intr, quit & suspend chars */
|
||||
raw_mode.c_lflag &= ~ECHO; /* Disable input echoing */
|
||||
raw_mode.c_iflag &= ~IXON; /* Pass ^S/^Q to subshell undisturbed */
|
||||
raw_mode.c_iflag &= ~ICRNL; /* Don't translate CRs into LFs */
|
||||
raw_mode.c_oflag &= ~OPOST; /* Don't postprocess output */
|
||||
raw_mode.c_cc[VTIME] = 0; /* IE: wait forever, and return as */
|
||||
raw_mode.c_cc[VMIN] = 1; /* soon as a character is available */
|
||||
initialized = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
invoke_subshell (const char *command, int how, char **new_dir)
|
||||
@ -612,6 +962,8 @@ invoke_subshell (const char *command, int how, char **new_dir)
|
||||
}
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
read_subshell_prompt (void)
|
||||
{
|
||||
@ -670,7 +1022,9 @@ read_subshell_prompt (void)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* Resize given terminal using TIOCSWINSZ, return ioctl() result */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Resize given terminal using TIOCSWINSZ, return ioctl() result */
|
||||
|
||||
static int
|
||||
resize_tty (int fd)
|
||||
{
|
||||
@ -687,7 +1041,9 @@ resize_tty (int fd)
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Resize subshell_pty */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Resize subshell_pty */
|
||||
|
||||
void
|
||||
resize_subshell (void)
|
||||
{
|
||||
@ -697,6 +1053,8 @@ resize_subshell (void)
|
||||
resize_tty (subshell_pty);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
exit_subshell (void)
|
||||
{
|
||||
@ -726,7 +1084,8 @@ exit_subshell (void)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Carefully quote directory name to allow entering any directory safely,
|
||||
* no matter what weird characters it may contain in its name.
|
||||
* NOTE: Treat directory name an untrusted data, don't allow it to cause
|
||||
@ -742,6 +1101,7 @@ exit_subshell (void)
|
||||
* cd "`printf "%b" 'ABC\0nnnDEF\0nnnXYZ'`"
|
||||
*
|
||||
*/
|
||||
|
||||
static char *
|
||||
subshell_name_quote (const char *s)
|
||||
{
|
||||
@ -809,7 +1169,9 @@ subshell_name_quote (const char *s)
|
||||
}
|
||||
|
||||
|
||||
/* If it actually changed the directory it returns true */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** If it actually changed the directory it returns true */
|
||||
|
||||
void
|
||||
do_subshell_chdir (const char *directory, int do_update, int reset_prompt)
|
||||
{
|
||||
@ -903,6 +1265,7 @@ do_subshell_chdir (const char *directory, int do_update, int reset_prompt)
|
||||
/* like /usr////lib/../bin, or the strcmp() above will fail */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
subshell_get_console_attributes (void)
|
||||
@ -917,9 +1280,11 @@ subshell_get_console_attributes (void)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Figure out whether the subshell has stopped, exited or been killed
|
||||
* Possibly modifies: `subshell_alive', `subshell_stopped' and `quit' */
|
||||
|
||||
/* Figure out whether the subshell has stopped, exited or been killed */
|
||||
/* Possibly modifies: `subshell_alive', `subshell_stopped' and `quit' */
|
||||
void
|
||||
sigchld_handler (int sig)
|
||||
{
|
||||
@ -978,314 +1343,6 @@ sigchld_handler (int sig)
|
||||
/* If we got here, some other child exited; ignore it */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/* Feed the subshell our keyboard input until it says it's finished */
|
||||
static gboolean
|
||||
feed_subshell (int how, int fail_on_error)
|
||||
{
|
||||
fd_set read_set; /* For `select' */
|
||||
int maxfdp;
|
||||
int bytes; /* For the return value from `read' */
|
||||
int i; /* Loop counter */
|
||||
|
||||
struct timeval wtime; /* Maximum time we wait for the subshell */
|
||||
struct timeval *wptr;
|
||||
|
||||
/* we wait up to 10 seconds if fail_on_error, forever otherwise */
|
||||
wtime.tv_sec = 10;
|
||||
wtime.tv_usec = 0;
|
||||
wptr = fail_on_error ? &wtime : NULL;
|
||||
|
||||
while (TRUE)
|
||||
{
|
||||
if (!subshell_alive)
|
||||
return FALSE;
|
||||
|
||||
/* Prepare the file-descriptor set and call `select' */
|
||||
|
||||
FD_ZERO (&read_set);
|
||||
FD_SET (subshell_pty, &read_set);
|
||||
FD_SET (subshell_pipe[READ], &read_set);
|
||||
maxfdp = max (subshell_pty, subshell_pipe[READ]);
|
||||
if (how == VISIBLY)
|
||||
{
|
||||
FD_SET (STDIN_FILENO, &read_set);
|
||||
maxfdp = max (maxfdp, STDIN_FILENO);
|
||||
}
|
||||
|
||||
if (select (maxfdp + 1, &read_set, NULL, NULL, wptr) == -1)
|
||||
{
|
||||
|
||||
/* Despite using SA_RESTART, we still have to check for this */
|
||||
if (errno == EINTR)
|
||||
continue; /* try all over again */
|
||||
tcsetattr (STDOUT_FILENO, TCSANOW, &shell_mode);
|
||||
fprintf (stderr, "select (FD_SETSIZE, &read_set...): %s\r\n",
|
||||
unix_error_string (errno));
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (FD_ISSET (subshell_pty, &read_set))
|
||||
/* Read from the subshell, write to stdout */
|
||||
|
||||
/* This loop improves performance by reducing context switches
|
||||
by a factor of 20 or so... unfortunately, it also hangs MC
|
||||
randomly, because of an apparent Linux bug. Investigate. */
|
||||
/* for (i=0; i<5; ++i) * FIXME -- experimental */
|
||||
{
|
||||
bytes = read (subshell_pty, pty_buffer, sizeof (pty_buffer));
|
||||
|
||||
/* The subshell has died */
|
||||
if (bytes == -1 && errno == EIO && !subshell_alive)
|
||||
return FALSE;
|
||||
|
||||
if (bytes <= 0)
|
||||
{
|
||||
tcsetattr (STDOUT_FILENO, TCSANOW, &shell_mode);
|
||||
fprintf (stderr, "read (subshell_pty...): %s\r\n", unix_error_string (errno));
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (how == VISIBLY)
|
||||
write_all (STDOUT_FILENO, pty_buffer, bytes);
|
||||
}
|
||||
|
||||
else if (FD_ISSET (subshell_pipe[READ], &read_set))
|
||||
/* Read the subshell's CWD and capture its prompt */
|
||||
{
|
||||
bytes = read (subshell_pipe[READ], subshell_cwd, MC_MAXPATHLEN + 1);
|
||||
if (bytes <= 0)
|
||||
{
|
||||
tcsetattr (STDOUT_FILENO, TCSANOW, &shell_mode);
|
||||
fprintf (stderr, "read (subshell_pipe[READ]...): %s\r\n",
|
||||
unix_error_string (errno));
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
subshell_cwd[bytes - 1] = 0; /* Squash the final '\n' */
|
||||
|
||||
synchronize ();
|
||||
|
||||
subshell_ready = TRUE;
|
||||
if (subshell_state == RUNNING_COMMAND)
|
||||
{
|
||||
subshell_state = INACTIVE;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
else if (FD_ISSET (STDIN_FILENO, &read_set))
|
||||
/* Read from stdin, write to the subshell */
|
||||
{
|
||||
bytes = read (STDIN_FILENO, pty_buffer, sizeof (pty_buffer));
|
||||
if (bytes <= 0)
|
||||
{
|
||||
tcsetattr (STDOUT_FILENO, TCSANOW, &shell_mode);
|
||||
fprintf (stderr,
|
||||
"read (STDIN_FILENO, pty_buffer...): %s\r\n", unix_error_string (errno));
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
for (i = 0; i < bytes; ++i)
|
||||
if (pty_buffer[i] == subshell_switch_key)
|
||||
{
|
||||
write_all (subshell_pty, pty_buffer, i);
|
||||
if (subshell_ready)
|
||||
subshell_state = INACTIVE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
write_all (subshell_pty, pty_buffer, bytes);
|
||||
|
||||
if (pty_buffer[bytes - 1] == '\n' || pty_buffer[bytes - 1] == '\r')
|
||||
subshell_ready = FALSE;
|
||||
}
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Wait until the subshell dies or stops. If it stops, make it resume. */
|
||||
/* Possibly modifies the globals `subshell_alive' and `subshell_stopped' */
|
||||
static void
|
||||
synchronize (void)
|
||||
{
|
||||
sigset_t sigchld_mask, old_mask;
|
||||
|
||||
sigemptyset (&sigchld_mask);
|
||||
sigaddset (&sigchld_mask, SIGCHLD);
|
||||
sigprocmask (SIG_BLOCK, &sigchld_mask, &old_mask);
|
||||
|
||||
/*
|
||||
* SIGCHLD should not be blocked, but we unblock it just in case.
|
||||
* This is known to be useful for cygwin 1.3.12 and older.
|
||||
*/
|
||||
sigdelset (&old_mask, SIGCHLD);
|
||||
|
||||
/* Wait until the subshell has stopped */
|
||||
while (subshell_alive && !subshell_stopped)
|
||||
sigsuspend (&old_mask);
|
||||
|
||||
if (subshell_state != ACTIVE)
|
||||
{
|
||||
/* Discard all remaining data from stdin to the subshell */
|
||||
tcflush (subshell_pty_slave, TCIFLUSH);
|
||||
}
|
||||
|
||||
subshell_stopped = FALSE;
|
||||
kill (subshell_pid, SIGCONT);
|
||||
|
||||
sigprocmask (SIG_SETMASK, &old_mask, NULL);
|
||||
/* We can't do any better without modifying the shell(s) */
|
||||
}
|
||||
|
||||
/* pty opening functions */
|
||||
|
||||
#ifdef HAVE_GRANTPT
|
||||
|
||||
/* System V version of pty_open_master */
|
||||
|
||||
static int
|
||||
pty_open_master (char *pty_name)
|
||||
{
|
||||
char *slave_name;
|
||||
int pty_master;
|
||||
|
||||
#ifdef HAVE_POSIX_OPENPT
|
||||
pty_master = posix_openpt (O_RDWR);
|
||||
#elif HAVE_GETPT
|
||||
/* getpt () is a GNU extension (glibc 2.1.x) */
|
||||
pty_master = getpt ();
|
||||
#elif IS_AIX
|
||||
strcpy (pty_name, "/dev/ptc");
|
||||
pty_master = open (pty_name, O_RDWR);
|
||||
#else
|
||||
strcpy (pty_name, "/dev/ptmx");
|
||||
pty_master = open (pty_name, O_RDWR);
|
||||
#endif
|
||||
|
||||
if (pty_master == -1)
|
||||
return -1;
|
||||
|
||||
if (grantpt (pty_master) == -1 /* Grant access to slave */
|
||||
|| unlockpt (pty_master) == -1 /* Clear slave's lock flag */
|
||||
|| !(slave_name = ptsname (pty_master))) /* Get slave's name */
|
||||
{
|
||||
close (pty_master);
|
||||
return -1;
|
||||
}
|
||||
strcpy (pty_name, slave_name);
|
||||
return pty_master;
|
||||
}
|
||||
|
||||
/* System V version of pty_open_slave */
|
||||
static int
|
||||
pty_open_slave (const char *pty_name)
|
||||
{
|
||||
int pty_slave = open (pty_name, O_RDWR);
|
||||
|
||||
if (pty_slave == -1)
|
||||
{
|
||||
fprintf (stderr, "open (%s, O_RDWR): %s\r\n", pty_name, unix_error_string (errno));
|
||||
return -1;
|
||||
}
|
||||
#if !defined(__osf__) && !defined(__linux__)
|
||||
#if defined (I_FIND) && defined (I_PUSH)
|
||||
if (!ioctl (pty_slave, I_FIND, "ptem"))
|
||||
if (ioctl (pty_slave, I_PUSH, "ptem") == -1)
|
||||
{
|
||||
fprintf (stderr, "ioctl (%d, I_PUSH, \"ptem\") failed: %s\r\n",
|
||||
pty_slave, unix_error_string (errno));
|
||||
close (pty_slave);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!ioctl (pty_slave, I_FIND, "ldterm"))
|
||||
if (ioctl (pty_slave, I_PUSH, "ldterm") == -1)
|
||||
{
|
||||
fprintf (stderr,
|
||||
"ioctl (%d, I_PUSH, \"ldterm\") failed: %s\r\n",
|
||||
pty_slave, unix_error_string (errno));
|
||||
close (pty_slave);
|
||||
return -1;
|
||||
}
|
||||
#if !defined(sgi) && !defined(__sgi)
|
||||
if (!ioctl (pty_slave, I_FIND, "ttcompat"))
|
||||
if (ioctl (pty_slave, I_PUSH, "ttcompat") == -1)
|
||||
{
|
||||
fprintf (stderr,
|
||||
"ioctl (%d, I_PUSH, \"ttcompat\") failed: %s\r\n",
|
||||
pty_slave, unix_error_string (errno));
|
||||
close (pty_slave);
|
||||
return -1;
|
||||
}
|
||||
#endif /* sgi || __sgi */
|
||||
#endif /* I_FIND && I_PUSH */
|
||||
#endif /* __osf__ || __linux__ */
|
||||
|
||||
fcntl (pty_slave, F_SETFD, FD_CLOEXEC);
|
||||
return pty_slave;
|
||||
}
|
||||
|
||||
#else /* !HAVE_GRANTPT */
|
||||
|
||||
/* BSD version of pty_open_master */
|
||||
static int
|
||||
pty_open_master (char *pty_name)
|
||||
{
|
||||
int pty_master;
|
||||
const char *ptr1, *ptr2;
|
||||
|
||||
strcpy (pty_name, "/dev/ptyXX");
|
||||
for (ptr1 = "pqrstuvwxyzPQRST"; *ptr1; ++ptr1)
|
||||
{
|
||||
pty_name[8] = *ptr1;
|
||||
for (ptr2 = "0123456789abcdef"; *ptr2 != '\0'; ++ptr2)
|
||||
{
|
||||
pty_name[9] = *ptr2;
|
||||
|
||||
/* Try to open master */
|
||||
pty_master = open (pty_name, O_RDWR);
|
||||
if (pty_master == -1)
|
||||
{
|
||||
if (errno == ENOENT) /* Different from EIO */
|
||||
return -1; /* Out of pty devices */
|
||||
continue; /* Try next pty device */
|
||||
}
|
||||
pty_name[5] = 't'; /* Change "pty" to "tty" */
|
||||
if (access (pty_name, 6) != 0)
|
||||
{
|
||||
close (pty_master);
|
||||
pty_name[5] = 'p';
|
||||
continue;
|
||||
}
|
||||
return pty_master;
|
||||
}
|
||||
}
|
||||
return -1; /* Ran out of pty devices */
|
||||
}
|
||||
|
||||
/* BSD version of pty_open_slave */
|
||||
static int
|
||||
pty_open_slave (const char *pty_name)
|
||||
{
|
||||
int pty_slave;
|
||||
struct group *group_info = getgrnam ("tty");
|
||||
|
||||
if (group_info != NULL)
|
||||
{
|
||||
/* The following two calls will only succeed if we are root */
|
||||
/* [Commented out while permissions problem is investigated] */
|
||||
/* chown (pty_name, getuid (), group_info->gr_gid); FIXME */
|
||||
/* chmod (pty_name, S_IRUSR | S_IWUSR | S_IWGRP); FIXME */
|
||||
}
|
||||
pty_slave = open (pty_name, O_RDWR);
|
||||
if (pty_slave == -1)
|
||||
fprintf (stderr, "open (pty_name, O_RDWR): %s\r\n", pty_name);
|
||||
fcntl (pty_slave, F_SETFD, FD_CLOEXEC);
|
||||
return pty_slave;
|
||||
}
|
||||
|
||||
#endif /* !HAVE_GRANTPT */
|
||||
#endif /* HAVE_SUBSHELL_SUPPORT */
|
||||
|
@ -1,10 +1,11 @@
|
||||
|
||||
/** \file subshell.h
|
||||
* \brief Header: concurrent shell support
|
||||
*/
|
||||
|
||||
#ifndef MC_SUBSHELL_H
|
||||
#define MC_SUBSHELL_H
|
||||
#ifndef MC__SUBSHELL_H
|
||||
#define MC__SUBSHELL_H
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/* Used to distinguish between a normal MC termination and */
|
||||
/* one caused by typing `exit' or `logout' in the subshell */
|
||||
@ -12,23 +13,34 @@
|
||||
|
||||
#ifdef HAVE_SUBSHELL_SUPPORT
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/* State of the subshell; see subshell.c for an explanation */
|
||||
|
||||
enum subshell_state_enum
|
||||
{ INACTIVE, ACTIVE, RUNNING_COMMAND };
|
||||
|
||||
/* For the `how' argument to various functions */
|
||||
enum
|
||||
{ QUIETLY, VISIBLY };
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/* If using a subshell for evaluating commands this is true */
|
||||
extern int use_subshell;
|
||||
|
||||
/* File descriptor of the pseudoterminal used by the subshell */
|
||||
extern int subshell_pty;
|
||||
|
||||
/* State of the subshell; see subshell.c for an explanation */
|
||||
enum subshell_state_enum {INACTIVE, ACTIVE, RUNNING_COMMAND};
|
||||
extern enum subshell_state_enum subshell_state;
|
||||
|
||||
/* Holds the latest prompt captured from the subshell */
|
||||
extern char *subshell_prompt;
|
||||
|
||||
/* For the `how' argument to various functions */
|
||||
enum {QUIETLY, VISIBLY};
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
/* Exported functions */
|
||||
void init_subshell (void);
|
||||
int invoke_subshell (const char *command, int how, char **new_dir);
|
||||
int read_subshell_prompt (void);
|
||||
@ -38,8 +50,9 @@ void do_subshell_chdir (const char *directory, int update_prompt, int reset_prom
|
||||
void subshell_get_console_attributes (void);
|
||||
void sigchld_handler (int sig);
|
||||
|
||||
#else
|
||||
#else /* not HAVE_SUBSHELL_SUPPORT */
|
||||
#define use_subshell 0
|
||||
#endif /* not HAVE_SUBSHELL_SUPPORT */
|
||||
|
||||
#endif
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__SUBSHELL_H */
|
||||
|
@ -31,6 +31,14 @@
|
||||
#include "lib/global.h"
|
||||
#include "src/textconf.h"
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
#ifdef ENABLE_VFS
|
||||
static const char *const vfs_supported[] = {
|
||||
#ifdef ENABLE_VFS_CPIO
|
||||
@ -59,8 +67,7 @@ static const char *const vfs_supported[] = {
|
||||
#endif /* ENABLE_VFS_SMB */
|
||||
NULL
|
||||
};
|
||||
#endif /* ENABLE_VFS */
|
||||
|
||||
#endif /* ENABLE_VFS */
|
||||
|
||||
static const char *const features[] = {
|
||||
#ifdef USE_INTERNAL_EDIT
|
||||
@ -81,18 +88,18 @@ static const char *const features[] = {
|
||||
N_("Using the ncursesw library"),
|
||||
#else
|
||||
#error "Cannot compile mc without S-Lang or ncurses"
|
||||
#endif /* !HAVE_SLANG && !USE_NCURSES */
|
||||
#endif /* !HAVE_SLANG && !USE_NCURSES */
|
||||
|
||||
"\n",
|
||||
|
||||
#ifdef HAVE_SUBSHELL_SUPPORT
|
||||
# ifdef SUBSHELL_OPTIONAL
|
||||
#ifdef SUBSHELL_OPTIONAL
|
||||
N_("With optional subshell support"),
|
||||
# else
|
||||
#else
|
||||
N_("With subshell support as default"),
|
||||
# endif
|
||||
#endif
|
||||
"\n",
|
||||
#endif /* !HAVE_SUBSHELL_SUPPORT */
|
||||
#endif /* !HAVE_SUBSHELL_SUPPORT */
|
||||
|
||||
#ifdef WITH_BACKGROUND
|
||||
N_("With support for background operations\n"),
|
||||
@ -119,6 +126,13 @@ static const char *const features[] = {
|
||||
NULL
|
||||
};
|
||||
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
show_version (void)
|
||||
{
|
||||
@ -129,23 +143,25 @@ show_version (void)
|
||||
#ifdef ENABLE_VFS
|
||||
printf (_("Virtual File Systems:"));
|
||||
for (i = 0; vfs_supported[i] != NULL; i++)
|
||||
printf ("%s %s", i == 0 ? "" : ",", _(vfs_supported[i]));
|
||||
printf ("%s %s", i == 0 ? "" : ",", _(vfs_supported[i]));
|
||||
|
||||
printf ("\n");
|
||||
#endif /* ENABLE_VFS */
|
||||
#endif /* ENABLE_VFS */
|
||||
|
||||
for (i = 0; features[i] != NULL; i++)
|
||||
printf ("%s", _(features[i]));
|
||||
printf ("%s", _(features[i]));
|
||||
|
||||
(void)printf(_("Data types:"));
|
||||
(void) printf (_("Data types:"));
|
||||
#define TYPE_INFO(T) \
|
||||
(void)printf(" %s: %d;", #T, (int) (CHAR_BIT * sizeof(T)))
|
||||
TYPE_INFO(char);
|
||||
TYPE_INFO(int);
|
||||
TYPE_INFO(long);
|
||||
TYPE_INFO(void *);
|
||||
TYPE_INFO(size_t);
|
||||
TYPE_INFO(off_t);
|
||||
TYPE_INFO (char);
|
||||
TYPE_INFO (int);
|
||||
TYPE_INFO (long);
|
||||
TYPE_INFO (void *);
|
||||
TYPE_INFO (size_t);
|
||||
TYPE_INFO (off_t);
|
||||
#undef TYPE_INFO
|
||||
(void)printf("\n");
|
||||
(void) printf ("\n");
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -1,11 +1,21 @@
|
||||
|
||||
/** \file textconf.h
|
||||
* \brief Header: prints features specific for this build
|
||||
*/
|
||||
|
||||
#ifndef MC_TEXTCONF_H
|
||||
#define MC_TEXTCONF_H
|
||||
#ifndef MC__TEXTCONF_H
|
||||
#define MC__TEXTCONF_H
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
extern void show_version (void);
|
||||
|
||||
#endif
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__TEXTCONF_H */
|
||||
|
148
src/tree.c
148
src/tree.c
@ -68,21 +68,24 @@
|
||||
#include "tree.h"
|
||||
#include "filegui.h"
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
#define tlines(t) (t->is_panel ? t->widget.lines - 2 - (show_mini_info ? 2 : 0) : t->widget.lines)
|
||||
|
||||
/* Use the color of the parent widget for the unselected entries */
|
||||
#define TREE_NORMALC(h) (h->color[DLG_COLOR_NORMAL])
|
||||
#define TREE_CURRENTC(h) (h->color[DLG_COLOR_FOCUS])
|
||||
|
||||
/* Specifies the display mode: 1d or 2d */
|
||||
static gboolean tree_navigation_flag = FALSE;
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
struct WTree
|
||||
{
|
||||
Widget widget;
|
||||
struct TreeStore *store;
|
||||
tree_entry *selected_ptr; /* The selected directory */
|
||||
char search_buffer[MC_MAXFILENAMELEN]; /* Current search string */
|
||||
char search_buffer[MC_MAXFILENAMELEN]; /* Current search string */
|
||||
tree_entry **tree_shown; /* Entries currently on screen */
|
||||
int is_panel; /* panel or plain widget flag */
|
||||
int active; /* if it's currently selected */
|
||||
@ -91,9 +94,18 @@ struct WTree
|
||||
shown and the selected */
|
||||
};
|
||||
|
||||
/* Forwards */
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
/* Specifies the display mode: 1d or 2d */
|
||||
static gboolean tree_navigation_flag = FALSE;
|
||||
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void tree_rescan (void *data);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static tree_entry *
|
||||
back_ptr (tree_entry * ptr, int *count)
|
||||
{
|
||||
@ -108,6 +120,8 @@ back_ptr (tree_entry * ptr, int *count)
|
||||
return ptr;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static tree_entry *
|
||||
forw_ptr (tree_entry * ptr, int *count)
|
||||
{
|
||||
@ -122,6 +136,8 @@ forw_ptr (tree_entry * ptr, int *count)
|
||||
return ptr;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
remove_callback (tree_entry * entry, void *data)
|
||||
{
|
||||
@ -136,7 +152,9 @@ remove_callback (tree_entry * entry, void *data)
|
||||
}
|
||||
}
|
||||
|
||||
/* Save the ~/.mc/Tree file */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Save the ~/.mc/Tree file */
|
||||
|
||||
static void
|
||||
save_tree (WTree * tree)
|
||||
{
|
||||
@ -156,6 +174,8 @@ save_tree (WTree * tree)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
tree_remove_entry (WTree * tree, char *name)
|
||||
{
|
||||
@ -163,6 +183,8 @@ tree_remove_entry (WTree * tree, char *name)
|
||||
tree_store_remove_entry (name);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
tree_destroy (WTree * tree)
|
||||
{
|
||||
@ -174,7 +196,9 @@ tree_destroy (WTree * tree)
|
||||
tree->selected_ptr = NULL;
|
||||
}
|
||||
|
||||
/* Loads the .mc.tree file */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Loads the .mc.tree file */
|
||||
|
||||
static void
|
||||
load_tree (WTree * tree)
|
||||
{
|
||||
@ -184,6 +208,8 @@ load_tree (WTree * tree)
|
||||
tree_chdir (tree, home_dir);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
tree_show_mini_info (WTree * tree, int tree_lines, int tree_cols)
|
||||
{
|
||||
@ -220,6 +246,8 @@ tree_show_mini_info (WTree * tree, int tree_lines, int tree_cols)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
show_tree (WTree * tree)
|
||||
{
|
||||
@ -298,7 +326,7 @@ show_tree (WTree * tree)
|
||||
|
||||
if (tree->is_panel)
|
||||
tty_setcolor (tree->active && current == tree->selected_ptr
|
||||
? SELECTED_COLOR : NORMAL_COLOR);
|
||||
? SELECTED_COLOR : NORMAL_COLOR);
|
||||
else
|
||||
tty_setcolor (current == tree->selected_ptr ? TREE_CURRENTC (h) : TREE_NORMALC (h));
|
||||
|
||||
@ -306,7 +334,8 @@ show_tree (WTree * tree)
|
||||
if (current->sublevel == topsublevel)
|
||||
{
|
||||
/* Show full name */
|
||||
tty_print_string (str_fit_to_term (current->name, tree_cols + (tree->is_panel ? 0 : 1), J_LEFT_FIT));
|
||||
tty_print_string (str_fit_to_term
|
||||
(current->name, tree_cols + (tree->is_panel ? 0 : 1), J_LEFT_FIT));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -336,7 +365,8 @@ show_tree (WTree * tree)
|
||||
|
||||
/* Show sub-name */
|
||||
tty_print_char (' ');
|
||||
tty_print_string (str_fit_to_term (current->subname, tree_cols - x - 3 * j, J_LEFT_FIT));
|
||||
tty_print_string (str_fit_to_term
|
||||
(current->subname, tree_cols - x - 3 * j, J_LEFT_FIT));
|
||||
}
|
||||
|
||||
/* Calculate the next value for current */
|
||||
@ -373,6 +403,8 @@ show_tree (WTree * tree)
|
||||
tree_show_mini_info (tree, tree_lines, tree_cols);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
tree_check_focus (WTree * tree)
|
||||
{
|
||||
@ -382,6 +414,8 @@ tree_check_focus (WTree * tree)
|
||||
tree->topdiff = tlines (tree) - 3 - 1;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
tree_move_backward (WTree * tree, int i)
|
||||
{
|
||||
@ -409,6 +443,8 @@ tree_move_backward (WTree * tree, int i)
|
||||
tree_check_focus (tree);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
tree_move_forward (WTree * tree, int i)
|
||||
{
|
||||
@ -436,6 +472,8 @@ tree_move_forward (WTree * tree, int i)
|
||||
tree_check_focus (tree);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
tree_move_to_child (WTree * tree)
|
||||
{
|
||||
@ -468,6 +506,8 @@ tree_move_to_child (WTree * tree)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static gboolean
|
||||
tree_move_to_parent (WTree * tree)
|
||||
{
|
||||
@ -491,6 +531,8 @@ tree_move_to_parent (WTree * tree)
|
||||
return tree->selected_ptr != old;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
tree_move_to_top (WTree * tree)
|
||||
{
|
||||
@ -498,6 +540,8 @@ tree_move_to_top (WTree * tree)
|
||||
tree->topdiff = 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
tree_move_to_bottom (WTree * tree)
|
||||
{
|
||||
@ -505,7 +549,9 @@ tree_move_to_bottom (WTree * tree)
|
||||
tree->topdiff = tlines (tree) - 3 - 1;
|
||||
}
|
||||
|
||||
/* Handle mouse click */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Handle mouse click */
|
||||
|
||||
static void
|
||||
tree_event (WTree * tree, int y)
|
||||
{
|
||||
@ -517,6 +563,8 @@ tree_event (WTree * tree, int y)
|
||||
show_tree (tree);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
tree_chdir_sel (WTree * tree)
|
||||
{
|
||||
@ -535,6 +583,8 @@ tree_chdir_sel (WTree * tree)
|
||||
show_tree (tree);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
maybe_chdir (WTree * tree)
|
||||
{
|
||||
@ -542,7 +592,9 @@ maybe_chdir (WTree * tree)
|
||||
tree_chdir_sel (tree);
|
||||
}
|
||||
|
||||
/* Mouse callback */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Mouse callback */
|
||||
|
||||
static int
|
||||
event_callback (Gpm_Event * event, void *data)
|
||||
{
|
||||
@ -587,7 +639,9 @@ event_callback (Gpm_Event * event, void *data)
|
||||
return MOU_NORMAL;
|
||||
}
|
||||
|
||||
/* Search tree for text */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Search tree for text */
|
||||
|
||||
static int
|
||||
search_tree (WTree * tree, char *text)
|
||||
{
|
||||
@ -619,6 +673,8 @@ search_tree (WTree * tree, char *text)
|
||||
return found;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
tree_do_search (WTree * tree, int key)
|
||||
{
|
||||
@ -640,6 +696,8 @@ tree_do_search (WTree * tree, int key)
|
||||
maybe_chdir (tree);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
tree_rescan (void *data)
|
||||
{
|
||||
@ -655,6 +713,8 @@ tree_rescan (void *data)
|
||||
ret = mc_chdir (old_dir);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
tree_forget (void *data)
|
||||
{
|
||||
@ -663,6 +723,8 @@ tree_forget (void *data)
|
||||
tree_remove_entry (tree, tree->selected_ptr->name);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
tree_copy (WTree * tree, const char *default_dest)
|
||||
{
|
||||
@ -695,6 +757,8 @@ tree_copy (WTree * tree, const char *default_dest)
|
||||
g_free (dest);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
tree_move (WTree * tree, const char *default_dest)
|
||||
{
|
||||
@ -743,6 +807,8 @@ tree_move (WTree * tree, const char *default_dest)
|
||||
g_free (dest);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
#if 0
|
||||
static void
|
||||
tree_mkdir (WTree * tree)
|
||||
@ -763,6 +829,8 @@ tree_mkdir (WTree * tree)
|
||||
}
|
||||
#endif
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
tree_rmdir (void *data)
|
||||
{
|
||||
@ -795,6 +863,8 @@ tree_rmdir (void *data)
|
||||
file_op_context_destroy (ctx);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static inline void
|
||||
tree_move_up (WTree * tree)
|
||||
{
|
||||
@ -803,6 +873,8 @@ tree_move_up (WTree * tree)
|
||||
maybe_chdir (tree);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static inline void
|
||||
tree_move_down (WTree * tree)
|
||||
{
|
||||
@ -811,6 +883,8 @@ tree_move_down (WTree * tree)
|
||||
maybe_chdir (tree);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static inline void
|
||||
tree_move_home (WTree * tree)
|
||||
{
|
||||
@ -819,6 +893,8 @@ tree_move_home (WTree * tree)
|
||||
maybe_chdir (tree);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static inline void
|
||||
tree_move_end (WTree * tree)
|
||||
{
|
||||
@ -827,6 +903,8 @@ tree_move_end (WTree * tree)
|
||||
maybe_chdir (tree);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
tree_move_pgup (WTree * tree)
|
||||
{
|
||||
@ -835,6 +913,8 @@ tree_move_pgup (WTree * tree)
|
||||
maybe_chdir (tree);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
tree_move_pgdn (WTree * tree)
|
||||
{
|
||||
@ -843,6 +923,8 @@ tree_move_pgdn (WTree * tree)
|
||||
maybe_chdir (tree);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static gboolean
|
||||
tree_move_left (WTree * tree)
|
||||
{
|
||||
@ -858,6 +940,8 @@ tree_move_left (WTree * tree)
|
||||
return v;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static gboolean
|
||||
tree_move_right (WTree * tree)
|
||||
{
|
||||
@ -874,6 +958,8 @@ tree_move_right (WTree * tree)
|
||||
return v;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
tree_start_search (WTree * tree)
|
||||
{
|
||||
@ -904,6 +990,8 @@ tree_start_search (WTree * tree)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
tree_toggle_navig (WTree * tree)
|
||||
{
|
||||
@ -913,6 +1001,8 @@ tree_toggle_navig (WTree * tree)
|
||||
: Q_ ("ButtonBar|Dynamc"), tree_map, (Widget *) tree);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static cb_ret_t
|
||||
tree_execute_cmd (WTree * tree, unsigned long command)
|
||||
{
|
||||
@ -977,6 +1067,8 @@ tree_execute_cmd (WTree * tree, unsigned long command)
|
||||
return res;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static cb_ret_t
|
||||
tree_key (WTree * tree, int key)
|
||||
{
|
||||
@ -1030,6 +1122,8 @@ tree_key (WTree * tree, int key)
|
||||
return MSG_NOT_HANDLED;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
tree_frame (Dlg_head * h, WTree * tree)
|
||||
{
|
||||
@ -1042,19 +1136,21 @@ tree_frame (Dlg_head * h, WTree * tree)
|
||||
|
||||
draw_box (h, tree->widget.y, tree->widget.x, tree->widget.lines, tree->widget.cols, FALSE);
|
||||
|
||||
widget_move (&tree->widget, 0, (tree->widget.cols - len - 2)/2);
|
||||
widget_move (&tree->widget, 0, (tree->widget.cols - len - 2) / 2);
|
||||
tty_printf (" %s ", title);
|
||||
|
||||
if (show_mini_info)
|
||||
widget_move (&tree->widget, tlines (tree) + 1, 0);
|
||||
tty_print_alt_char (ACS_LTEE, FALSE);
|
||||
widget_move (&tree->widget, tlines (tree) + 1, tree->widget.cols - 1);
|
||||
tty_print_alt_char (ACS_RTEE, FALSE);
|
||||
tty_draw_hline (tree->widget.y + tlines (tree) + 1,
|
||||
tree->widget.x + 1, ACS_HLINE, tree->widget.cols - 2);
|
||||
tty_print_alt_char (ACS_LTEE, FALSE);
|
||||
widget_move (&tree->widget, tlines (tree) + 1, tree->widget.cols - 1);
|
||||
tty_print_alt_char (ACS_RTEE, FALSE);
|
||||
tty_draw_hline (tree->widget.y + tlines (tree) + 1,
|
||||
tree->widget.x + 1, ACS_HLINE, tree->widget.cols - 2);
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static cb_ret_t
|
||||
tree_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
{
|
||||
@ -1117,6 +1213,10 @@ tree_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
WTree *
|
||||
tree_new (int y, int x, int lines, int cols, gboolean is_panel)
|
||||
{
|
||||
@ -1140,6 +1240,8 @@ tree_new (int y, int x, int lines, int cols, gboolean is_panel)
|
||||
return tree;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tree_chdir (WTree * tree, const char *dir)
|
||||
{
|
||||
@ -1154,21 +1256,29 @@ tree_chdir (WTree * tree, const char *dir)
|
||||
}
|
||||
}
|
||||
|
||||
/* Return name of the currently selected entry */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Return name of the currently selected entry */
|
||||
|
||||
char *
|
||||
tree_selected_name (const WTree * tree)
|
||||
{
|
||||
return tree->selected_ptr->name;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
sync_tree (const char *path)
|
||||
{
|
||||
tree_chdir (the_tree, path);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
WTree *
|
||||
find_tree (struct Dlg_head *h)
|
||||
{
|
||||
return (WTree *) find_widget_type (h, tree_callback);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
26
src/tree.h
26
src/tree.h
@ -1,27 +1,37 @@
|
||||
|
||||
/** \file tree.h
|
||||
* \brief Header: directory tree browser
|
||||
*/
|
||||
|
||||
#ifndef MC_TREE_H
|
||||
#define MC_TREE_H
|
||||
#ifndef MC__TREE_H
|
||||
#define MC__TREE_H
|
||||
|
||||
#include "lib/global.h"
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
typedef struct WTree WTree;
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
extern WTree *the_tree;
|
||||
extern int xtree_mode;
|
||||
|
||||
struct Dlg_head;
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
WTree *tree_new (int y, int x, int lines, int cols, gboolean is_panel);
|
||||
|
||||
void tree_chdir (WTree *tree, const char *dir);
|
||||
char *tree_selected_name (const WTree *tree);
|
||||
void tree_chdir (WTree * tree, const char *dir);
|
||||
char *tree_selected_name (const WTree * tree);
|
||||
|
||||
void sync_tree (const char *pathname);
|
||||
|
||||
struct Dlg_head;
|
||||
|
||||
WTree *find_tree (struct Dlg_head *h);
|
||||
|
||||
#endif /* MC_TREE_H */
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__TREE_H */
|
||||
|
318
src/treestore.c
318
src/treestore.c
@ -56,13 +56,26 @@
|
||||
#include "treestore.h"
|
||||
#include "setup.h"
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
#define TREE_SIGNATURE "Midnight Commander TreeStore v 2.0"
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
static struct TreeStore ts;
|
||||
|
||||
static hook_t *remove_entry_hooks;
|
||||
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static tree_entry *tree_store_add_entry (const char *name);
|
||||
|
||||
static hook_t *remove_entry_hooks;
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
tree_store_dirty (int state)
|
||||
@ -70,7 +83,9 @@ tree_store_dirty (int state)
|
||||
ts.dirty = state;
|
||||
}
|
||||
|
||||
/* Returns the number of common bytes in the strings. */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Returns the number of common bytes in the strings. */
|
||||
|
||||
static size_t
|
||||
str_common (const char *s1, const char *s2)
|
||||
{
|
||||
@ -81,6 +96,7 @@ str_common (const char *s1, const char *s2)
|
||||
return result;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/* The directory names are arranged in a single linked list in the same
|
||||
order as they are displayed. When the tree is displayed the expected
|
||||
order is like this:
|
||||
@ -102,6 +118,7 @@ str_common (const char *s1, const char *s2)
|
||||
greater than zero if p1 is found to be less than, to match, or be greater
|
||||
than p2.
|
||||
*/
|
||||
|
||||
static int
|
||||
pathcmp (const char *p1, const char *p2)
|
||||
{
|
||||
@ -120,27 +137,7 @@ pathcmp (const char *p1, const char *p2)
|
||||
return (*p1 - *p2);
|
||||
}
|
||||
|
||||
/* Searches for specified directory */
|
||||
tree_entry *
|
||||
tree_store_whereis (const char *name)
|
||||
{
|
||||
tree_entry *current = ts.tree_first;
|
||||
int flag = -1;
|
||||
|
||||
while (current && (flag = pathcmp (current->name, name)) < 0)
|
||||
current = current->next;
|
||||
|
||||
if (flag == 0)
|
||||
return current;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct TreeStore *
|
||||
tree_store_get (void)
|
||||
{
|
||||
return &ts;
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static char *
|
||||
decode (char *buffer)
|
||||
@ -179,7 +176,9 @@ decode (char *buffer)
|
||||
return res;
|
||||
}
|
||||
|
||||
/* Loads the tree store from the specified filename */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Loads the tree store from the specified filename */
|
||||
|
||||
static int
|
||||
tree_store_load_from (char *name)
|
||||
{
|
||||
@ -283,23 +282,7 @@ tree_store_load_from (char *name)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* \fn int tree_store_load(void)
|
||||
* \brief Loads the tree from the default location
|
||||
* \return 1 if success (true), 0 otherwise (false)
|
||||
*/
|
||||
int
|
||||
tree_store_load (void)
|
||||
{
|
||||
char *name;
|
||||
int retval;
|
||||
|
||||
name = g_build_filename (home_dir, MC_USERCONF_DIR, MC_TREESTORE_FILE, NULL);
|
||||
retval = tree_store_load_from (name);
|
||||
g_free (name);
|
||||
|
||||
return retval;
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static char *
|
||||
encode (const char *string)
|
||||
@ -341,7 +324,9 @@ encode (const char *string)
|
||||
return res;
|
||||
}
|
||||
|
||||
/* Saves the tree to the specified filename */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Saves the tree to the specified filename */
|
||||
|
||||
static int
|
||||
tree_store_save_to (char *name)
|
||||
{
|
||||
@ -392,32 +377,7 @@ tree_store_save_to (char *name)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* \fn int tree_store_save(void)
|
||||
* \brief Saves the tree to the default file in an atomic fashion
|
||||
* \return 0 if success, errno on error
|
||||
*/
|
||||
int
|
||||
tree_store_save (void)
|
||||
{
|
||||
char *name;
|
||||
int retval;
|
||||
|
||||
name = g_build_filename (home_dir, MC_USERCONF_DIR, MC_TREESTORE_FILE, NULL);
|
||||
mc_util_make_backup_if_possible (name, ".tmp");
|
||||
|
||||
retval = tree_store_save_to (name);
|
||||
if (retval != 0)
|
||||
{
|
||||
mc_util_restore_from_backup_if_possible (name, ".tmp");
|
||||
g_free (name);
|
||||
return retval;
|
||||
}
|
||||
|
||||
mc_util_unlink_backup_if_possible (name, ".tmp");
|
||||
g_free (name);
|
||||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static tree_entry *
|
||||
tree_store_add_entry (const char *name)
|
||||
@ -530,17 +490,7 @@ tree_store_add_entry (const char *name)
|
||||
return new;
|
||||
}
|
||||
|
||||
void
|
||||
tree_store_add_entry_remove_hook (tree_store_remove_fn callback, void *data)
|
||||
{
|
||||
add_hook (&remove_entry_hooks, (void (*)(void *)) callback, data);
|
||||
}
|
||||
|
||||
void
|
||||
tree_store_remove_entry_remove_hook (tree_store_remove_fn callback)
|
||||
{
|
||||
delete_hook (&remove_entry_hooks, (void (*)(void *)) callback);
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
tree_store_notify_remove (tree_entry * entry)
|
||||
@ -556,6 +506,8 @@ tree_store_notify_remove (tree_entry * entry)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static tree_entry *
|
||||
remove_entry (tree_entry * entry)
|
||||
{
|
||||
@ -594,6 +546,153 @@ remove_entry (tree_entry * entry)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
process_special_dirs (GList ** special_dirs, char *file)
|
||||
{
|
||||
gchar **buffers, **start_buff;
|
||||
mc_config_t *cfg;
|
||||
gsize buffers_len;
|
||||
|
||||
cfg = mc_config_init (file);
|
||||
if (cfg == NULL)
|
||||
return;
|
||||
|
||||
start_buff = buffers = mc_config_get_string_list (cfg, "Special dirs", "list", &buffers_len);
|
||||
if (buffers != NULL)
|
||||
{
|
||||
while (*buffers != NULL)
|
||||
{
|
||||
*special_dirs = g_list_prepend (*special_dirs, *buffers);
|
||||
*buffers = NULL;
|
||||
buffers++;
|
||||
}
|
||||
g_strfreev (start_buff);
|
||||
}
|
||||
mc_config_deinit (cfg);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static gboolean
|
||||
should_skip_directory (const char *dir)
|
||||
{
|
||||
static GList *special_dirs = NULL;
|
||||
GList *l;
|
||||
static gboolean loaded = FALSE;
|
||||
|
||||
if (!loaded)
|
||||
{
|
||||
loaded = TRUE;
|
||||
setup_init ();
|
||||
process_special_dirs (&special_dirs, profile_name);
|
||||
process_special_dirs (&special_dirs, global_profile_name);
|
||||
}
|
||||
|
||||
for (l = special_dirs; l != NULL; l = g_list_next (l))
|
||||
if (strncmp (dir, l->data, strlen (l->data)) == 0)
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/* Searches for specified directory */
|
||||
tree_entry *
|
||||
tree_store_whereis (const char *name)
|
||||
{
|
||||
tree_entry *current = ts.tree_first;
|
||||
int flag = -1;
|
||||
|
||||
while (current && (flag = pathcmp (current->name, name)) < 0)
|
||||
current = current->next;
|
||||
|
||||
if (flag == 0)
|
||||
return current;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
struct TreeStore *
|
||||
tree_store_get (void)
|
||||
{
|
||||
return &ts;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* \fn int tree_store_load(void)
|
||||
* \brief Loads the tree from the default location
|
||||
* \return 1 if success (true), 0 otherwise (false)
|
||||
*/
|
||||
|
||||
int
|
||||
tree_store_load (void)
|
||||
{
|
||||
char *name;
|
||||
int retval;
|
||||
|
||||
name = g_build_filename (home_dir, MC_USERCONF_DIR, MC_TREESTORE_FILE, NULL);
|
||||
retval = tree_store_load_from (name);
|
||||
g_free (name);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* \fn int tree_store_save(void)
|
||||
* \brief Saves the tree to the default file in an atomic fashion
|
||||
* \return 0 if success, errno on error
|
||||
*/
|
||||
|
||||
int
|
||||
tree_store_save (void)
|
||||
{
|
||||
char *name;
|
||||
int retval;
|
||||
|
||||
name = g_build_filename (home_dir, MC_USERCONF_DIR, MC_TREESTORE_FILE, NULL);
|
||||
mc_util_make_backup_if_possible (name, ".tmp");
|
||||
|
||||
retval = tree_store_save_to (name);
|
||||
if (retval != 0)
|
||||
{
|
||||
mc_util_restore_from_backup_if_possible (name, ".tmp");
|
||||
g_free (name);
|
||||
return retval;
|
||||
}
|
||||
|
||||
mc_util_unlink_backup_if_possible (name, ".tmp");
|
||||
g_free (name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tree_store_add_entry_remove_hook (tree_store_remove_fn callback, void *data)
|
||||
{
|
||||
add_hook (&remove_entry_hooks, (void (*)(void *)) callback, data);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tree_store_remove_entry_remove_hook (tree_store_remove_fn callback)
|
||||
{
|
||||
delete_hook (&remove_entry_hooks, (void (*)(void *)) callback);
|
||||
}
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tree_store_remove_entry (const char *name)
|
||||
{
|
||||
@ -627,7 +726,9 @@ tree_store_remove_entry (const char *name)
|
||||
return;
|
||||
}
|
||||
|
||||
/* This subdirectory exists -> clear deletion mark */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** This subdirectory exists -> clear deletion mark */
|
||||
|
||||
void
|
||||
tree_store_mark_checked (const char *subname)
|
||||
{
|
||||
@ -678,7 +779,9 @@ tree_store_mark_checked (const char *subname)
|
||||
}
|
||||
}
|
||||
|
||||
/* Mark the subdirectories of the current directory for delete */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Mark the subdirectories of the current directory for delete */
|
||||
|
||||
tree_entry *
|
||||
tree_store_start_check (const char *path)
|
||||
{
|
||||
@ -729,7 +832,9 @@ tree_store_start_check (const char *path)
|
||||
return retval;
|
||||
}
|
||||
|
||||
/* Delete subdirectories which still have the deletion mark */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Delete subdirectories which still have the deletion mark */
|
||||
|
||||
void
|
||||
tree_store_end_check (void)
|
||||
{
|
||||
@ -767,52 +872,7 @@ tree_store_end_check (void)
|
||||
g_list_free (the_queue);
|
||||
}
|
||||
|
||||
static void
|
||||
process_special_dirs (GList ** special_dirs, char *file)
|
||||
{
|
||||
gchar **buffers, **start_buff;
|
||||
mc_config_t *cfg;
|
||||
gsize buffers_len;
|
||||
|
||||
cfg = mc_config_init (file);
|
||||
if (cfg == NULL)
|
||||
return;
|
||||
|
||||
start_buff = buffers = mc_config_get_string_list (cfg, "Special dirs", "list", &buffers_len);
|
||||
if (buffers != NULL)
|
||||
{
|
||||
while (*buffers != NULL)
|
||||
{
|
||||
*special_dirs = g_list_prepend (*special_dirs, *buffers);
|
||||
*buffers = NULL;
|
||||
buffers++;
|
||||
}
|
||||
g_strfreev (start_buff);
|
||||
}
|
||||
mc_config_deinit (cfg);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
should_skip_directory (const char *dir)
|
||||
{
|
||||
static GList *special_dirs = NULL;
|
||||
GList *l;
|
||||
static gboolean loaded = FALSE;
|
||||
|
||||
if (!loaded)
|
||||
{
|
||||
loaded = TRUE;
|
||||
setup_init ();
|
||||
process_special_dirs (&special_dirs, profile_name);
|
||||
process_special_dirs (&special_dirs, global_profile_name);
|
||||
}
|
||||
|
||||
for (l = special_dirs; l != NULL; l = g_list_next (l))
|
||||
if (strncmp (dir, l->data, strlen (l->data)) == 0)
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
tree_entry *
|
||||
tree_store_rescan (const char *dir)
|
||||
@ -863,3 +923,5 @@ tree_store_rescan (const char *dir)
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -1,34 +1,51 @@
|
||||
|
||||
/** \file treestore.h
|
||||
* \brief Header: tree store
|
||||
*
|
||||
* Contains a storage of the file system tree representation.
|
||||
*/
|
||||
|
||||
#ifndef MC_TREE_STORE_H
|
||||
#define MC_TREE_STORE_H
|
||||
#ifndef MC__TREE_STORE_H
|
||||
#define MC__TREE_STORE_H
|
||||
|
||||
typedef struct tree_entry {
|
||||
char *name; /* The full path of directory */
|
||||
int sublevel; /* Number of parent directories (slashes) */
|
||||
long submask; /* Bitmask of existing sublevels after this entry */
|
||||
const char *subname; /* The last part of name (the actual name) */
|
||||
unsigned int mark:1; /* Flag: Is this entry marked (e. g. for delete)? */
|
||||
unsigned int scanned:1; /* Flag: childs scanned or not */
|
||||
struct tree_entry *next; /* Next item in the list */
|
||||
struct tree_entry *prev; /* Previous item in the list */
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/*
|
||||
* Register/unregister notification functions for "entry_remove"
|
||||
*/
|
||||
struct tree_entry;
|
||||
typedef void (*tree_store_remove_fn) (struct tree_entry * tree, void *data);
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
typedef struct tree_entry
|
||||
{
|
||||
char *name; /* The full path of directory */
|
||||
int sublevel; /* Number of parent directories (slashes) */
|
||||
long submask; /* Bitmask of existing sublevels after this entry */
|
||||
const char *subname; /* The last part of name (the actual name) */
|
||||
unsigned int mark:1; /* Flag: Is this entry marked (e. g. for delete)? */
|
||||
unsigned int scanned:1; /* Flag: childs scanned or not */
|
||||
struct tree_entry *next; /* Next item in the list */
|
||||
struct tree_entry *prev; /* Previous item in the list */
|
||||
} tree_entry;
|
||||
|
||||
struct TreeStore {
|
||||
tree_entry *tree_first; /* First entry in the list */
|
||||
tree_entry *tree_last; /* Last entry in the list */
|
||||
tree_entry *check_start; /* Start of checked subdirectories */
|
||||
struct TreeStore
|
||||
{
|
||||
tree_entry *tree_first; /* First entry in the list */
|
||||
tree_entry *tree_last; /* Last entry in the list */
|
||||
tree_entry *check_start; /* Start of checked subdirectories */
|
||||
char *check_name;
|
||||
GList *add_queue; /* List of strings of added directories */
|
||||
GList *add_queue; /* List of strings of added directories */
|
||||
unsigned int loaded:1;
|
||||
unsigned int dirty:1;
|
||||
};
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
struct TreeStore *tree_store_get (void);
|
||||
int tree_store_load (void);
|
||||
int tree_store_save (void);
|
||||
@ -39,12 +56,8 @@ void tree_store_end_check (void);
|
||||
tree_entry *tree_store_whereis (const char *name);
|
||||
tree_entry *tree_store_rescan (const char *dir);
|
||||
|
||||
/*
|
||||
* Register/unregister notification functions for "entry_remove"
|
||||
*/
|
||||
typedef void (*tree_store_remove_fn) (tree_entry *tree, void *data);
|
||||
void tree_store_add_entry_remove_hook (tree_store_remove_fn callback,
|
||||
void *data);
|
||||
void tree_store_add_entry_remove_hook (tree_store_remove_fn callback, void *data);
|
||||
void tree_store_remove_entry_remove_hook (tree_store_remove_fn callback);
|
||||
|
||||
#endif
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__TREE_STORE_H */
|
||||
|
1025
src/user.c
1025
src/user.c
File diff suppressed because it is too large
Load Diff
18
src/user.h
18
src/user.h
@ -1,19 +1,29 @@
|
||||
|
||||
/** \file user.h
|
||||
* \brief Header: user menu implementation
|
||||
*/
|
||||
|
||||
#ifndef MC_USER_H
|
||||
#define MC_USER_H
|
||||
#ifndef MC__USER_H
|
||||
#define MC__USER_H
|
||||
|
||||
#include "lib/global.h"
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
struct WEdit;
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
void user_menu_cmd (struct WEdit *edit_widget);
|
||||
char *expand_format (struct WEdit *edit_widget, char c, gboolean do_quote);
|
||||
int check_format_view (const char *);
|
||||
int check_format_var (const char *, char **);
|
||||
int check_format_cd (const char *);
|
||||
|
||||
#endif /* MC_USER_H */
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__USER_H */
|
||||
|
849
src/wtools.c
849
src/wtools.c
@ -44,92 +44,23 @@
|
||||
#include "wtools.h"
|
||||
#include "background.h" /* parent_call */
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
Listbox *
|
||||
create_listbox_window_centered (int center_y, int center_x, int lines, int cols,
|
||||
const char *title, const char *help)
|
||||
{
|
||||
const dlg_colors_t listbox_colors = {
|
||||
MENU_ENTRY_COLOR,
|
||||
MENU_SELECTED_COLOR,
|
||||
MENU_HOT_COLOR,
|
||||
MENU_HOTSEL_COLOR,
|
||||
COLOR_TITLE
|
||||
};
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
const int space = 4;
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
int xpos, ypos, len;
|
||||
Listbox *listbox;
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
/* Adjust sizes */
|
||||
lines = min (lines, LINES - 6);
|
||||
static Dlg_head *last_query_dlg;
|
||||
|
||||
if (title != NULL)
|
||||
{
|
||||
len = str_term_width1 (title) + 4;
|
||||
cols = max (cols, len);
|
||||
}
|
||||
static int sel_pos = 0;
|
||||
|
||||
cols = min (cols, COLS - 6);
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/* adjust position */
|
||||
if ((center_y < 0) || (center_x < 0))
|
||||
{
|
||||
ypos = LINES / 2;
|
||||
xpos = COLS / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
ypos = center_y;
|
||||
xpos = center_x;
|
||||
}
|
||||
/** default query callback, used to reposition query */
|
||||
|
||||
ypos -= lines / 2;
|
||||
xpos -= cols / 2;
|
||||
|
||||
if (ypos + lines >= LINES)
|
||||
ypos = LINES - lines - space;
|
||||
if (ypos < 0)
|
||||
ypos = 0;
|
||||
|
||||
if (xpos + cols >= COLS)
|
||||
xpos = COLS - cols - space;
|
||||
if (xpos < 0)
|
||||
xpos = 0;
|
||||
|
||||
listbox = g_new (Listbox, 1);
|
||||
|
||||
listbox->dlg =
|
||||
create_dlg (TRUE, ypos, xpos, lines + space, cols + space,
|
||||
listbox_colors, NULL, help, title, DLG_REVERSE | DLG_TRYUP);
|
||||
|
||||
listbox->list = listbox_new (2, 2, lines, cols, FALSE, NULL);
|
||||
add_widget (listbox->dlg, listbox->list);
|
||||
|
||||
return listbox;
|
||||
}
|
||||
|
||||
Listbox *
|
||||
create_listbox_window (int lines, int cols, const char *title, const char *help)
|
||||
{
|
||||
return create_listbox_window_centered (-1, -1, lines, cols, title, help);
|
||||
}
|
||||
|
||||
/* Returns the number of the item selected */
|
||||
int
|
||||
run_listbox (Listbox * l)
|
||||
{
|
||||
int val = -1;
|
||||
|
||||
if (run_dlg (l->dlg) != B_CANCEL)
|
||||
val = l->list->pos;
|
||||
destroy_dlg (l->dlg);
|
||||
g_free (l);
|
||||
return val;
|
||||
}
|
||||
|
||||
/* default query callback, used to reposition query */
|
||||
static cb_ret_t
|
||||
default_query_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
|
||||
{
|
||||
@ -150,110 +81,9 @@ default_query_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm,
|
||||
}
|
||||
}
|
||||
|
||||
static Dlg_head *last_query_dlg;
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Create message dialog */
|
||||
|
||||
static int sel_pos = 0;
|
||||
|
||||
/* Used to ask questions to the user */
|
||||
int
|
||||
query_dialog (const char *header, const char *text, int flags, int count, ...)
|
||||
{
|
||||
va_list ap;
|
||||
Dlg_head *query_dlg;
|
||||
WButton *button;
|
||||
WButton *defbutton = NULL;
|
||||
int win_len = 0;
|
||||
int i;
|
||||
int result = -1;
|
||||
int cols, lines;
|
||||
char *cur_name;
|
||||
const int *query_colors = (flags & D_ERROR) ? alarm_colors : dialog_colors;
|
||||
|
||||
if (header == MSG_ERROR)
|
||||
header = _("Error");
|
||||
|
||||
if (count > 0)
|
||||
{
|
||||
va_start (ap, count);
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
char *cp = va_arg (ap, char *);
|
||||
win_len += str_term_width1 (cp) + 6;
|
||||
if (strchr (cp, '&') != NULL)
|
||||
win_len--;
|
||||
}
|
||||
va_end (ap);
|
||||
}
|
||||
|
||||
/* count coordinates */
|
||||
str_msg_term_size (text, &lines, &cols);
|
||||
cols = 6 + max (win_len, max (str_term_width1 (header), cols));
|
||||
lines += 4 + (count > 0 ? 2 : 0);
|
||||
|
||||
/* prepare dialog */
|
||||
query_dlg =
|
||||
create_dlg (TRUE, 0, 0, lines, cols, query_colors, default_query_callback,
|
||||
"[QueryBox]", header, DLG_NONE);
|
||||
|
||||
if (count > 0)
|
||||
{
|
||||
cols = (cols - win_len - 2) / 2 + 2;
|
||||
va_start (ap, count);
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
int xpos;
|
||||
|
||||
cur_name = va_arg (ap, char *);
|
||||
xpos = str_term_width1 (cur_name) + 6;
|
||||
if (strchr (cur_name, '&') != NULL)
|
||||
xpos--;
|
||||
|
||||
button = button_new (lines - 3, cols, B_USER + i, NORMAL_BUTTON, cur_name, 0);
|
||||
add_widget (query_dlg, button);
|
||||
cols += xpos;
|
||||
if (i == sel_pos)
|
||||
defbutton = button;
|
||||
}
|
||||
va_end (ap);
|
||||
|
||||
add_widget (query_dlg, label_new (2, 3, text));
|
||||
|
||||
/* do resize before running and selecting any widget */
|
||||
default_query_callback (query_dlg, NULL, DLG_RESIZE, 0, NULL);
|
||||
|
||||
if (defbutton)
|
||||
dlg_select_widget (defbutton);
|
||||
|
||||
/* run dialog and make result */
|
||||
switch (run_dlg (query_dlg))
|
||||
{
|
||||
case B_CANCEL:
|
||||
break;
|
||||
default:
|
||||
result = query_dlg->ret_value - B_USER;
|
||||
}
|
||||
|
||||
/* free used memory */
|
||||
destroy_dlg (query_dlg);
|
||||
}
|
||||
else
|
||||
{
|
||||
add_widget (query_dlg, label_new (2, 3, text));
|
||||
add_widget (query_dlg, button_new (0, 0, 0, HIDDEN_BUTTON, "-", 0));
|
||||
last_query_dlg = query_dlg;
|
||||
}
|
||||
sel_pos = 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
query_set_sel (int new_sel)
|
||||
{
|
||||
sel_pos = new_sel;
|
||||
}
|
||||
|
||||
|
||||
/* Create message dialog */
|
||||
static struct Dlg_head *
|
||||
do_create_message (int flags, const char *title, const char *text)
|
||||
{
|
||||
@ -274,33 +104,12 @@ do_create_message (int flags, const char *title, const char *text)
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Create message dialog. The caller must call dlg_run_done() and
|
||||
* destroy_dlg() to dismiss it. Not safe to call from background.
|
||||
*/
|
||||
struct Dlg_head *
|
||||
create_message (int flags, const char *title, const char *text, ...)
|
||||
{
|
||||
va_list args;
|
||||
Dlg_head *d;
|
||||
char *p;
|
||||
|
||||
va_start (args, text);
|
||||
p = g_strdup_vprintf (text, args);
|
||||
va_end (args);
|
||||
|
||||
d = do_create_message (flags, title, p);
|
||||
g_free (p);
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Show message dialog. Dismiss it when any key is pressed.
|
||||
* Not safe to call from background.
|
||||
*/
|
||||
|
||||
static void
|
||||
fg_message (int flags, const char *title, const char *text)
|
||||
{
|
||||
@ -313,7 +122,9 @@ fg_message (int flags, const char *title, const char *text)
|
||||
}
|
||||
|
||||
|
||||
/* Show message box from background */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Show message box from background */
|
||||
|
||||
#ifdef WITH_BACKGROUND
|
||||
static void
|
||||
bg_message (int dummy, int *flags, char *title, const char *text)
|
||||
@ -325,201 +136,11 @@ bg_message (int dummy, int *flags, char *title, const char *text)
|
||||
}
|
||||
#endif /* WITH_BACKGROUND */
|
||||
|
||||
|
||||
/* Show message box, background safe */
|
||||
void
|
||||
message (int flags, const char *title, const char *text, ...)
|
||||
{
|
||||
char *p;
|
||||
va_list ap;
|
||||
union
|
||||
{
|
||||
void *p;
|
||||
void (*f) (int, int *, char *, const char *);
|
||||
} func;
|
||||
|
||||
va_start (ap, text);
|
||||
p = g_strdup_vprintf (text, ap);
|
||||
va_end (ap);
|
||||
|
||||
if (title == MSG_ERROR)
|
||||
title = _("Error");
|
||||
|
||||
#ifdef WITH_BACKGROUND
|
||||
if (we_are_background)
|
||||
{
|
||||
func.f = bg_message;
|
||||
parent_call (func.p, NULL, 3, sizeof (flags), &flags, strlen (title), title, strlen (p), p);
|
||||
}
|
||||
else
|
||||
#endif /* WITH_BACKGROUND */
|
||||
fg_message (flags, title, p);
|
||||
|
||||
g_free (p);
|
||||
}
|
||||
|
||||
|
||||
/* {{{ Quick dialog routines */
|
||||
|
||||
|
||||
int
|
||||
quick_dialog_skip (QuickDialog * qd, int nskip)
|
||||
{
|
||||
#ifdef ENABLE_NLS
|
||||
#define I18N(x) (x = !qd->i18n && x && *x ? _(x): x)
|
||||
#else
|
||||
#define I18N(x) (x = x)
|
||||
#endif
|
||||
Dlg_head *dd;
|
||||
QuickWidget *qw;
|
||||
WInput *in;
|
||||
WRadio *r;
|
||||
int return_val;
|
||||
|
||||
I18N (qd->title);
|
||||
|
||||
if ((qd->xpos == -1) || (qd->ypos == -1))
|
||||
dd = create_dlg (TRUE, 0, 0, qd->ylen, qd->xlen,
|
||||
dialog_colors, qd->callback, qd->help, qd->title,
|
||||
DLG_CENTER | DLG_TRYUP | DLG_REVERSE);
|
||||
else
|
||||
dd = create_dlg (TRUE, qd->ypos, qd->xpos, qd->ylen, qd->xlen,
|
||||
dialog_colors, qd->callback, qd->help, qd->title, DLG_REVERSE);
|
||||
|
||||
for (qw = qd->widgets; qw->widget_type != quick_end; qw++)
|
||||
{
|
||||
int xpos;
|
||||
int ypos;
|
||||
|
||||
xpos = (qd->xlen * qw->relative_x) / qw->x_divisions;
|
||||
ypos = (qd->ylen * qw->relative_y) / qw->y_divisions;
|
||||
|
||||
switch (qw->widget_type)
|
||||
{
|
||||
case quick_checkbox:
|
||||
qw->widget =
|
||||
(Widget *) check_new (ypos, xpos, *qw->u.checkbox.state,
|
||||
I18N (qw->u.checkbox.text));
|
||||
break;
|
||||
|
||||
case quick_button:
|
||||
qw->widget = (Widget *) button_new (ypos, xpos, qw->u.button.action,
|
||||
(qw->u.button.action ==
|
||||
B_ENTER) ? DEFPUSH_BUTTON : NORMAL_BUTTON,
|
||||
I18N (qw->u.button.text), qw->u.button.callback);
|
||||
break;
|
||||
|
||||
case quick_input:
|
||||
in = input_new (ypos, xpos, input_get_default_colors(),
|
||||
qw->u.input.len, qw->u.input.text, qw->u.input.histname,
|
||||
INPUT_COMPLETE_DEFAULT);
|
||||
in->is_password = (qw->u.input.flags == 1);
|
||||
if ((qw->u.input.flags & 2) != 0)
|
||||
in->completion_flags |= INPUT_COMPLETE_CD;
|
||||
qw->widget = (Widget *) in;
|
||||
*qw->u.input.result = NULL;
|
||||
break;
|
||||
|
||||
case quick_label:
|
||||
qw->widget = (Widget *) label_new (ypos, xpos, I18N (qw->u.label.text));
|
||||
break;
|
||||
|
||||
case quick_groupbox:
|
||||
qw->widget = (Widget *) groupbox_new (ypos, xpos,
|
||||
qw->u.groupbox.height,
|
||||
qw->u.groupbox.width,
|
||||
I18N (qw->u.groupbox.title));
|
||||
break;
|
||||
|
||||
case quick_radio:
|
||||
{
|
||||
int i;
|
||||
char **items = NULL;
|
||||
|
||||
/* create the copy of radio_items to avoid mwmory leak */
|
||||
items = g_new0 (char *, qw->u.radio.count + 1);
|
||||
|
||||
if (!qd->i18n)
|
||||
for (i = 0; i < qw->u.radio.count; i++)
|
||||
items[i] = g_strdup (_(qw->u.radio.items[i]));
|
||||
else
|
||||
for (i = 0; i < qw->u.radio.count; i++)
|
||||
items[i] = g_strdup (qw->u.radio.items[i]);
|
||||
|
||||
r = radio_new (ypos, xpos, qw->u.radio.count, (const char **) items);
|
||||
r->pos = r->sel = *qw->u.radio.value;
|
||||
qw->widget = (Widget *) r;
|
||||
g_strfreev (items);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
qw->widget = NULL;
|
||||
fprintf (stderr, "QuickWidget: unknown widget type\n");
|
||||
break;
|
||||
}
|
||||
|
||||
if (qw->widget != NULL)
|
||||
{
|
||||
qw->widget->options |= qw->options; /* FIXME: cannot reset flags, setup only */
|
||||
add_widget (dd, qw->widget);
|
||||
}
|
||||
}
|
||||
|
||||
while (nskip-- != 0)
|
||||
{
|
||||
dd->current = g_list_next (dd->current);
|
||||
if (dd->current == NULL)
|
||||
dd->current = dd->widgets;
|
||||
}
|
||||
|
||||
return_val = run_dlg (dd);
|
||||
|
||||
/* Get the data if we found something interesting */
|
||||
if (return_val != B_CANCEL)
|
||||
{
|
||||
for (qw = qd->widgets; qw->widget_type != quick_end; qw++)
|
||||
{
|
||||
switch (qw->widget_type)
|
||||
{
|
||||
case quick_checkbox:
|
||||
*qw->u.checkbox.state = ((WCheck *) qw->widget)->state & C_BOOL;
|
||||
break;
|
||||
|
||||
case quick_input:
|
||||
if ((qw->u.input.flags & 2) != 0)
|
||||
*qw->u.input.result = tilde_expand (((WInput *) qw->widget)->buffer);
|
||||
else
|
||||
*qw->u.input.result = g_strdup (((WInput *) qw->widget)->buffer);
|
||||
break;
|
||||
|
||||
case quick_radio:
|
||||
*qw->u.radio.value = ((WRadio *) qw->widget)->sel;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
destroy_dlg (dd);
|
||||
|
||||
return return_val;
|
||||
#undef I18N
|
||||
}
|
||||
|
||||
int
|
||||
quick_dialog (QuickDialog * qd)
|
||||
{
|
||||
return quick_dialog_skip (qd, 0);
|
||||
}
|
||||
|
||||
/* }}} */
|
||||
|
||||
/* {{{ Input routines */
|
||||
|
||||
/*
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Show dialog, not background safe.
|
||||
*
|
||||
* If the arguments "header" and "text" should be translated,
|
||||
@ -618,12 +239,432 @@ fg_input_dialog_help (const char *header, const char *text, const char *help,
|
||||
return (ret != B_CANCEL) ? my_str : NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
/* }}} */
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
Listbox *
|
||||
create_listbox_window_centered (int center_y, int center_x, int lines, int cols,
|
||||
const char *title, const char *help)
|
||||
{
|
||||
const dlg_colors_t listbox_colors = {
|
||||
MENU_ENTRY_COLOR,
|
||||
MENU_SELECTED_COLOR,
|
||||
MENU_HOT_COLOR,
|
||||
MENU_HOTSEL_COLOR,
|
||||
COLOR_TITLE
|
||||
};
|
||||
|
||||
const int space = 4;
|
||||
|
||||
int xpos, ypos, len;
|
||||
Listbox *listbox;
|
||||
|
||||
/* Adjust sizes */
|
||||
lines = min (lines, LINES - 6);
|
||||
|
||||
if (title != NULL)
|
||||
{
|
||||
len = str_term_width1 (title) + 4;
|
||||
cols = max (cols, len);
|
||||
}
|
||||
|
||||
cols = min (cols, COLS - 6);
|
||||
|
||||
/* adjust position */
|
||||
if ((center_y < 0) || (center_x < 0))
|
||||
{
|
||||
ypos = LINES / 2;
|
||||
xpos = COLS / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
ypos = center_y;
|
||||
xpos = center_x;
|
||||
}
|
||||
|
||||
ypos -= lines / 2;
|
||||
xpos -= cols / 2;
|
||||
|
||||
if (ypos + lines >= LINES)
|
||||
ypos = LINES - lines - space;
|
||||
if (ypos < 0)
|
||||
ypos = 0;
|
||||
|
||||
if (xpos + cols >= COLS)
|
||||
xpos = COLS - cols - space;
|
||||
if (xpos < 0)
|
||||
xpos = 0;
|
||||
|
||||
listbox = g_new (Listbox, 1);
|
||||
|
||||
listbox->dlg =
|
||||
create_dlg (TRUE, ypos, xpos, lines + space, cols + space,
|
||||
listbox_colors, NULL, help, title, DLG_REVERSE | DLG_TRYUP);
|
||||
|
||||
listbox->list = listbox_new (2, 2, lines, cols, FALSE, NULL);
|
||||
add_widget (listbox->dlg, listbox->list);
|
||||
|
||||
return listbox;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
Listbox *
|
||||
create_listbox_window (int lines, int cols, const char *title, const char *help)
|
||||
{
|
||||
return create_listbox_window_centered (-1, -1, lines, cols, title, help);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Returns the number of the item selected */
|
||||
|
||||
int
|
||||
run_listbox (Listbox * l)
|
||||
{
|
||||
int val = -1;
|
||||
|
||||
if (run_dlg (l->dlg) != B_CANCEL)
|
||||
val = l->list->pos;
|
||||
destroy_dlg (l->dlg);
|
||||
g_free (l);
|
||||
return val;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Used to ask questions to the user */
|
||||
|
||||
int
|
||||
query_dialog (const char *header, const char *text, int flags, int count, ...)
|
||||
{
|
||||
va_list ap;
|
||||
Dlg_head *query_dlg;
|
||||
WButton *button;
|
||||
WButton *defbutton = NULL;
|
||||
int win_len = 0;
|
||||
int i;
|
||||
int result = -1;
|
||||
int cols, lines;
|
||||
char *cur_name;
|
||||
const int *query_colors = (flags & D_ERROR) ? alarm_colors : dialog_colors;
|
||||
|
||||
if (header == MSG_ERROR)
|
||||
header = _("Error");
|
||||
|
||||
if (count > 0)
|
||||
{
|
||||
va_start (ap, count);
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
char *cp = va_arg (ap, char *);
|
||||
win_len += str_term_width1 (cp) + 6;
|
||||
if (strchr (cp, '&') != NULL)
|
||||
win_len--;
|
||||
}
|
||||
va_end (ap);
|
||||
}
|
||||
|
||||
/* count coordinates */
|
||||
str_msg_term_size (text, &lines, &cols);
|
||||
cols = 6 + max (win_len, max (str_term_width1 (header), cols));
|
||||
lines += 4 + (count > 0 ? 2 : 0);
|
||||
|
||||
/* prepare dialog */
|
||||
query_dlg =
|
||||
create_dlg (TRUE, 0, 0, lines, cols, query_colors, default_query_callback,
|
||||
"[QueryBox]", header, DLG_NONE);
|
||||
|
||||
if (count > 0)
|
||||
{
|
||||
cols = (cols - win_len - 2) / 2 + 2;
|
||||
va_start (ap, count);
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
int xpos;
|
||||
|
||||
cur_name = va_arg (ap, char *);
|
||||
xpos = str_term_width1 (cur_name) + 6;
|
||||
if (strchr (cur_name, '&') != NULL)
|
||||
xpos--;
|
||||
|
||||
button = button_new (lines - 3, cols, B_USER + i, NORMAL_BUTTON, cur_name, 0);
|
||||
add_widget (query_dlg, button);
|
||||
cols += xpos;
|
||||
if (i == sel_pos)
|
||||
defbutton = button;
|
||||
}
|
||||
va_end (ap);
|
||||
|
||||
add_widget (query_dlg, label_new (2, 3, text));
|
||||
|
||||
/* do resize before running and selecting any widget */
|
||||
default_query_callback (query_dlg, NULL, DLG_RESIZE, 0, NULL);
|
||||
|
||||
if (defbutton)
|
||||
dlg_select_widget (defbutton);
|
||||
|
||||
/* run dialog and make result */
|
||||
switch (run_dlg (query_dlg))
|
||||
{
|
||||
case B_CANCEL:
|
||||
break;
|
||||
default:
|
||||
result = query_dlg->ret_value - B_USER;
|
||||
}
|
||||
|
||||
/* free used memory */
|
||||
destroy_dlg (query_dlg);
|
||||
}
|
||||
else
|
||||
{
|
||||
add_widget (query_dlg, label_new (2, 3, text));
|
||||
add_widget (query_dlg, button_new (0, 0, 0, HIDDEN_BUTTON, "-", 0));
|
||||
last_query_dlg = query_dlg;
|
||||
}
|
||||
sel_pos = 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
query_set_sel (int new_sel)
|
||||
{
|
||||
sel_pos = new_sel;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Create message dialog. The caller must call dlg_run_done() and
|
||||
* destroy_dlg() to dismiss it. Not safe to call from background.
|
||||
*/
|
||||
|
||||
struct Dlg_head *
|
||||
create_message (int flags, const char *title, const char *text, ...)
|
||||
{
|
||||
va_list args;
|
||||
Dlg_head *d;
|
||||
char *p;
|
||||
|
||||
va_start (args, text);
|
||||
p = g_strdup_vprintf (text, args);
|
||||
va_end (args);
|
||||
|
||||
d = do_create_message (flags, title, p);
|
||||
g_free (p);
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Show message box, background safe */
|
||||
|
||||
void
|
||||
message (int flags, const char *title, const char *text, ...)
|
||||
{
|
||||
char *p;
|
||||
va_list ap;
|
||||
union
|
||||
{
|
||||
void *p;
|
||||
void (*f) (int, int *, char *, const char *);
|
||||
} func;
|
||||
|
||||
va_start (ap, text);
|
||||
p = g_strdup_vprintf (text, ap);
|
||||
va_end (ap);
|
||||
|
||||
if (title == MSG_ERROR)
|
||||
title = _("Error");
|
||||
|
||||
#ifdef WITH_BACKGROUND
|
||||
if (we_are_background)
|
||||
{
|
||||
func.f = bg_message;
|
||||
parent_call (func.p, NULL, 3, sizeof (flags), &flags, strlen (title), title, strlen (p), p);
|
||||
}
|
||||
else
|
||||
#endif /* WITH_BACKGROUND */
|
||||
fg_message (flags, title, p);
|
||||
|
||||
g_free (p);
|
||||
}
|
||||
|
||||
|
||||
/* {{{ Quick dialog routines */
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
quick_dialog_skip (QuickDialog * qd, int nskip)
|
||||
{
|
||||
#ifdef ENABLE_NLS
|
||||
#define I18N(x) (x = !qd->i18n && x && *x ? _(x): x)
|
||||
#else
|
||||
#define I18N(x) (x = x)
|
||||
#endif
|
||||
Dlg_head *dd;
|
||||
QuickWidget *qw;
|
||||
WInput *in;
|
||||
WRadio *r;
|
||||
int return_val;
|
||||
|
||||
I18N (qd->title);
|
||||
|
||||
if ((qd->xpos == -1) || (qd->ypos == -1))
|
||||
dd = create_dlg (TRUE, 0, 0, qd->ylen, qd->xlen,
|
||||
dialog_colors, qd->callback, qd->help, qd->title,
|
||||
DLG_CENTER | DLG_TRYUP | DLG_REVERSE);
|
||||
else
|
||||
dd = create_dlg (TRUE, qd->ypos, qd->xpos, qd->ylen, qd->xlen,
|
||||
dialog_colors, qd->callback, qd->help, qd->title, DLG_REVERSE);
|
||||
|
||||
for (qw = qd->widgets; qw->widget_type != quick_end; qw++)
|
||||
{
|
||||
int xpos;
|
||||
int ypos;
|
||||
|
||||
xpos = (qd->xlen * qw->relative_x) / qw->x_divisions;
|
||||
ypos = (qd->ylen * qw->relative_y) / qw->y_divisions;
|
||||
|
||||
switch (qw->widget_type)
|
||||
{
|
||||
case quick_checkbox:
|
||||
qw->widget =
|
||||
(Widget *) check_new (ypos, xpos, *qw->u.checkbox.state,
|
||||
I18N (qw->u.checkbox.text));
|
||||
break;
|
||||
|
||||
case quick_button:
|
||||
qw->widget = (Widget *) button_new (ypos, xpos, qw->u.button.action,
|
||||
(qw->u.button.action ==
|
||||
B_ENTER) ? DEFPUSH_BUTTON : NORMAL_BUTTON,
|
||||
I18N (qw->u.button.text), qw->u.button.callback);
|
||||
break;
|
||||
|
||||
case quick_input:
|
||||
in = input_new (ypos, xpos, input_get_default_colors (),
|
||||
qw->u.input.len, qw->u.input.text, qw->u.input.histname,
|
||||
INPUT_COMPLETE_DEFAULT);
|
||||
in->is_password = (qw->u.input.flags == 1);
|
||||
if ((qw->u.input.flags & 2) != 0)
|
||||
in->completion_flags |= INPUT_COMPLETE_CD;
|
||||
qw->widget = (Widget *) in;
|
||||
*qw->u.input.result = NULL;
|
||||
break;
|
||||
|
||||
case quick_label:
|
||||
qw->widget = (Widget *) label_new (ypos, xpos, I18N (qw->u.label.text));
|
||||
break;
|
||||
|
||||
case quick_groupbox:
|
||||
qw->widget = (Widget *) groupbox_new (ypos, xpos,
|
||||
qw->u.groupbox.height,
|
||||
qw->u.groupbox.width,
|
||||
I18N (qw->u.groupbox.title));
|
||||
break;
|
||||
|
||||
case quick_radio:
|
||||
{
|
||||
int i;
|
||||
char **items = NULL;
|
||||
|
||||
/* create the copy of radio_items to avoid mwmory leak */
|
||||
items = g_new0 (char *, qw->u.radio.count + 1);
|
||||
|
||||
if (!qd->i18n)
|
||||
for (i = 0; i < qw->u.radio.count; i++)
|
||||
items[i] = g_strdup (_(qw->u.radio.items[i]));
|
||||
else
|
||||
for (i = 0; i < qw->u.radio.count; i++)
|
||||
items[i] = g_strdup (qw->u.radio.items[i]);
|
||||
|
||||
r = radio_new (ypos, xpos, qw->u.radio.count, (const char **) items);
|
||||
r->pos = r->sel = *qw->u.radio.value;
|
||||
qw->widget = (Widget *) r;
|
||||
g_strfreev (items);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
qw->widget = NULL;
|
||||
fprintf (stderr, "QuickWidget: unknown widget type\n");
|
||||
break;
|
||||
}
|
||||
|
||||
if (qw->widget != NULL)
|
||||
{
|
||||
qw->widget->options |= qw->options; /* FIXME: cannot reset flags, setup only */
|
||||
add_widget (dd, qw->widget);
|
||||
}
|
||||
}
|
||||
|
||||
while (nskip-- != 0)
|
||||
{
|
||||
dd->current = g_list_next (dd->current);
|
||||
if (dd->current == NULL)
|
||||
dd->current = dd->widgets;
|
||||
}
|
||||
|
||||
return_val = run_dlg (dd);
|
||||
|
||||
/* Get the data if we found something interesting */
|
||||
if (return_val != B_CANCEL)
|
||||
{
|
||||
for (qw = qd->widgets; qw->widget_type != quick_end; qw++)
|
||||
{
|
||||
switch (qw->widget_type)
|
||||
{
|
||||
case quick_checkbox:
|
||||
*qw->u.checkbox.state = ((WCheck *) qw->widget)->state & C_BOOL;
|
||||
break;
|
||||
|
||||
case quick_input:
|
||||
if ((qw->u.input.flags & 2) != 0)
|
||||
*qw->u.input.result = tilde_expand (((WInput *) qw->widget)->buffer);
|
||||
else
|
||||
*qw->u.input.result = g_strdup (((WInput *) qw->widget)->buffer);
|
||||
break;
|
||||
|
||||
case quick_radio:
|
||||
*qw->u.radio.value = ((WRadio *) qw->widget)->sel;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
destroy_dlg (dd);
|
||||
|
||||
return return_val;
|
||||
#undef I18N
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
quick_dialog (QuickDialog * qd)
|
||||
{
|
||||
return quick_dialog_skip (qd, 0);
|
||||
}
|
||||
|
||||
/* }}} */
|
||||
|
||||
/* {{{ Input routines */
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Show input dialog, background safe.
|
||||
*
|
||||
* If the arguments "header" and "text" should be translated,
|
||||
* that MUST be done by the caller of these wrappers.
|
||||
*/
|
||||
|
||||
char *
|
||||
input_dialog_help (const char *header, const char *text, const char *help,
|
||||
const char *history_name, const char *def_text)
|
||||
@ -648,13 +689,17 @@ input_dialog_help (const char *header, const char *text, const char *help,
|
||||
return fg_input_dialog_help (header, text, help, history_name, def_text);
|
||||
}
|
||||
|
||||
/* Show input dialog with default help, background safe */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Show input dialog with default help, background safe */
|
||||
|
||||
char *
|
||||
input_dialog (const char *header, const char *text, const char *history_name, const char *def_text)
|
||||
{
|
||||
return input_dialog_help (header, text, "[Input Line Keys]", history_name, def_text);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
char *
|
||||
input_expand_dialog (const char *header, const char *text,
|
||||
const char *history_name, const char *def_text)
|
||||
@ -672,6 +717,8 @@ input_expand_dialog (const char *header, const char *text,
|
||||
return result;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/* }}} */
|
||||
|
||||
/* }}} */
|
||||
|
210
src/wtools.h
210
src/wtools.h
@ -1,101 +1,19 @@
|
||||
|
||||
/** \file wtools.h
|
||||
* \brief Header: widget based utility functions
|
||||
*/
|
||||
|
||||
#ifndef MC_WTOOLS_H
|
||||
#define MC_WTOOLS_H
|
||||
#ifndef MC__WTOOLS_H
|
||||
#define MC__WTOOLS_H
|
||||
|
||||
#include "lib/global.h"
|
||||
#include "dialog.h"
|
||||
#include "widget.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
struct Dlg_head *dlg;
|
||||
struct WListbox *list;
|
||||
} Listbox;
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/* Listbox utility functions */
|
||||
Listbox *create_listbox_window_centered (int center_y, int center_x, int lines, int cols,
|
||||
const char *title, const char *help);
|
||||
Listbox *create_listbox_window (int lines, int cols, const char *title, const char *help);
|
||||
#define LISTBOX_APPEND_TEXT(l,h,t,d) \
|
||||
listbox_add_item (l->list, LISTBOX_APPEND_AT_END, h, t, d)
|
||||
|
||||
int run_listbox (Listbox * l);
|
||||
|
||||
/* Quick Widgets */
|
||||
typedef enum
|
||||
{
|
||||
quick_end = 0,
|
||||
quick_checkbox = 1,
|
||||
quick_button = 2,
|
||||
quick_input = 3,
|
||||
quick_label = 4,
|
||||
quick_radio = 5,
|
||||
quick_groupbox = 6
|
||||
} quick_t;
|
||||
|
||||
/* The widget is placed on relative_?/divisions_? of the parent widget */
|
||||
typedef struct
|
||||
{
|
||||
quick_t widget_type;
|
||||
|
||||
int relative_x;
|
||||
int x_divisions;
|
||||
int relative_y;
|
||||
int y_divisions;
|
||||
|
||||
Widget *widget;
|
||||
widget_options_t options;
|
||||
|
||||
/* widget parameters */
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
const char *text;
|
||||
int *state; /* in/out */
|
||||
} checkbox;
|
||||
|
||||
struct
|
||||
{
|
||||
const char *text;
|
||||
int action;
|
||||
bcback callback;
|
||||
} button;
|
||||
|
||||
struct
|
||||
{
|
||||
const char *text;
|
||||
int len;
|
||||
int flags; /* 1 -- is_password, 2 -- INPUT_COMPLETE_CD */
|
||||
const char *histname;
|
||||
char **result;
|
||||
} input;
|
||||
|
||||
struct
|
||||
{
|
||||
const char *text;
|
||||
} label;
|
||||
|
||||
struct
|
||||
{
|
||||
int count;
|
||||
const char **items;
|
||||
int *value; /* in/out */
|
||||
} radio;
|
||||
|
||||
struct
|
||||
{
|
||||
int width;
|
||||
int height;
|
||||
const char *title;
|
||||
} groupbox;
|
||||
} u;
|
||||
} QuickWidget;
|
||||
|
||||
#define QUICK_CHECKBOX(x, xdiv, y, ydiv, txt, st) \
|
||||
{ \
|
||||
.widget_type = quick_checkbox, \
|
||||
@ -223,6 +141,100 @@ typedef struct
|
||||
} \
|
||||
}
|
||||
|
||||
/* Pass this as def_text to request a password */
|
||||
#define INPUT_PASSWORD ((char *) -1)
|
||||
|
||||
/* Use this as header for message() - it expands to "Error" */
|
||||
#define MSG_ERROR ((char *) -1)
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/* Quick Widgets */
|
||||
typedef enum
|
||||
{
|
||||
quick_end = 0,
|
||||
quick_checkbox = 1,
|
||||
quick_button = 2,
|
||||
quick_input = 3,
|
||||
quick_label = 4,
|
||||
quick_radio = 5,
|
||||
quick_groupbox = 6
|
||||
} quick_t;
|
||||
|
||||
/* flags for message() and query_dialog() */
|
||||
enum
|
||||
{
|
||||
D_NORMAL = 0,
|
||||
D_ERROR = 1
|
||||
} /* dialog options */ ;
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
struct Dlg_head *dlg;
|
||||
struct WListbox *list;
|
||||
} Listbox;
|
||||
|
||||
/* The widget is placed on relative_?/divisions_? of the parent widget */
|
||||
typedef struct
|
||||
{
|
||||
quick_t widget_type;
|
||||
|
||||
int relative_x;
|
||||
int x_divisions;
|
||||
int relative_y;
|
||||
int y_divisions;
|
||||
|
||||
Widget *widget;
|
||||
widget_options_t options;
|
||||
|
||||
/* widget parameters */
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
const char *text;
|
||||
int *state; /* in/out */
|
||||
} checkbox;
|
||||
|
||||
struct
|
||||
{
|
||||
const char *text;
|
||||
int action;
|
||||
bcback callback;
|
||||
} button;
|
||||
|
||||
struct
|
||||
{
|
||||
const char *text;
|
||||
int len;
|
||||
int flags; /* 1 -- is_password, 2 -- INPUT_COMPLETE_CD */
|
||||
const char *histname;
|
||||
char **result;
|
||||
} input;
|
||||
|
||||
struct
|
||||
{
|
||||
const char *text;
|
||||
} label;
|
||||
|
||||
struct
|
||||
{
|
||||
int count;
|
||||
const char **items;
|
||||
int *value; /* in/out */
|
||||
} radio;
|
||||
|
||||
struct
|
||||
{
|
||||
int width;
|
||||
int height;
|
||||
const char *title;
|
||||
} groupbox;
|
||||
} u;
|
||||
} QuickWidget;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int xlen, ylen;
|
||||
@ -234,14 +246,22 @@ typedef struct
|
||||
gboolean i18n; /* If true, internationalization has happened */
|
||||
} QuickDialog;
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
/* Listbox utility functions */
|
||||
Listbox *create_listbox_window_centered (int center_y, int center_x, int lines, int cols,
|
||||
const char *title, const char *help);
|
||||
Listbox *create_listbox_window (int lines, int cols, const char *title, const char *help);
|
||||
|
||||
int run_listbox (Listbox * l);
|
||||
|
||||
int quick_dialog (QuickDialog * qd);
|
||||
int quick_dialog_skip (QuickDialog * qd, int nskip);
|
||||
|
||||
/* The input dialogs */
|
||||
|
||||
/* Pass this as def_text to request a password */
|
||||
#define INPUT_PASSWORD ((char *) -1)
|
||||
|
||||
char *input_dialog (const char *header, const char *text,
|
||||
const char *history_name, const char *def_text);
|
||||
char *input_dialog_help (const char *header, const char *text, const char *help,
|
||||
@ -259,17 +279,7 @@ struct Dlg_head *create_message (int flags, const char *title,
|
||||
void message (int flags, const char *title, const char *text, ...)
|
||||
__attribute__ ((format (__printf__, 3, 4)));
|
||||
|
||||
|
||||
/* Use this as header for message() - it expands to "Error" */
|
||||
#define MSG_ERROR ((char *) -1)
|
||||
|
||||
int query_dialog (const char *header, const char *text, int flags, int count, ...);
|
||||
|
||||
/* flags for message() and query_dialog() */
|
||||
enum
|
||||
{
|
||||
D_NORMAL = 0,
|
||||
D_ERROR = 1
|
||||
} /* dialog options */ ;
|
||||
|
||||
#endif
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__WTOOLS_H */
|
||||
|
Loading…
Reference in New Issue
Block a user