1 /* Routines invoked by a function key
2 They normally operate on the current panel.
4 Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
5 2005, 2006, 2007, 2009 Free Software Foundation, Inc.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
22 * \brief Source: routines invoked by a function key
24 * They normally operate on the current panel.
33 #include <sys/types.h>
36 # include <sys/mman.h>
50 #include "../src/tty/tty.h" /* LINES */
51 #include "../src/tty/key.h" /* ALT() macro */
52 #include "../src/tty/win.h" /* do_enter_ca_mode() */
54 #include "../src/search/search.h"
56 #include "../src/mcconfig/mcconfig.h"
58 #include "cmd.h" /* Our definitions */
59 #include "fileopctx.h"
60 #include "file.h" /* file operation routines */
61 #include "find.h" /* do_find() */
62 #include "hotlist.h" /* hotlist_cmd() */
63 #include "tree.h" /* tree_chdir() */
64 #include "subshell.h" /* use_subshell */
65 #include "cons.saver.h" /* console_flag */
66 #include "dialog.h" /* Widget */
67 #include "wtools.h" /* message() */
68 #include "widget.h" /* push_history() */
69 #include "main.h" /* change_panel() */
70 #include "panel.h" /* current_panel */
71 #include "help.h" /* interactive_display() */
72 #include "user.h" /* MC_GLOBAL_MENU */
73 #include "command.h" /* cmdline */
74 #include "layout.h" /* get_current_type() */
75 #include "ext.h" /* regex_command() */
76 #include "boxes.h" /* cd_dialog() */
78 #include "execute.h" /* toggle_panels() */
82 #include "../src/viewer/mcviewer.h"
88 #ifdef USE_INTERNAL_EDIT
89 # include "../edit/edit.h"
92 /* If set and you don't have subshell support,then C-o will give you a shell */
93 int output_starts_shell
= 0;
95 /* If set, use the builtin editor */
96 int use_internal_edit
= 1;
98 /* Automatically fills name with current selected item name on mkdir */
99 int auto_fill_mkdir_name
= 1;
101 /* if set, only selection of files is inverted */
102 int reverse_files_only
= 1;
104 /* selection flags */
106 SELECT_FILES_ONLY
= 1 << 0,
107 SELECT_MATCH_CASE
= 1 << 1,
108 SELECT_SHELL_PATTERNS
= 1 << 2
111 static select_flags_t select_flags
= SELECT_MATCH_CASE
| SELECT_SHELL_PATTERNS
;
114 view_file_at_line (const char *filename
, int plain_view
, int internal
,
117 static const char *viewer
= NULL
;
122 int changed_hex_mode
= 0;
123 int changed_nroff_flag
= 0;
124 int changed_magic_flag
= 0;
126 mcview_altered_hex_mode
= 0;
127 mcview_altered_nroff_flag
= 0;
128 mcview_altered_magic_flag
= 0;
129 if (mcview_default_hex_mode
)
130 changed_hex_mode
= 1;
131 if (mcview_default_nroff_flag
)
132 changed_nroff_flag
= 1;
133 if (mcview_default_magic_flag
)
134 changed_magic_flag
= 1;
135 mcview_default_hex_mode
= 0;
136 mcview_default_nroff_flag
= 0;
137 mcview_default_magic_flag
= 0;
138 mcview_viewer (NULL
, filename
, &move_dir
, start_line
);
139 if (changed_hex_mode
&& !mcview_altered_hex_mode
)
140 mcview_default_hex_mode
= 1;
141 if (changed_nroff_flag
&& !mcview_altered_nroff_flag
)
142 mcview_default_nroff_flag
= 1;
143 if (changed_magic_flag
&& !mcview_altered_magic_flag
)
144 mcview_default_magic_flag
= 1;
149 char view_entry
[BUF_TINY
];
152 g_snprintf (view_entry
, sizeof (view_entry
), "View:%d",
155 strcpy (view_entry
, "View");
157 if (regex_command (filename
, view_entry
, &move_dir
) == 0) {
158 mcview_viewer (NULL
, filename
, &move_dir
, start_line
);
163 viewer
= getenv ("VIEWER");
165 viewer
= getenv ("PAGER");
169 execute_with_vfs_arg (viewer
, filename
);
174 /* view_file (filename, plain_view, internal)
177 * filename: The file name to view
178 * plain_view: If set does not do any fancy pre-processing (no filtering) and
179 * always invokes the internal viewer.
180 * internal: If set uses the internal viewer, otherwise an external viewer.
183 view_file (const char *filename
, int plain_view
, int internal
)
185 return view_file_at_line (filename
, plain_view
, internal
, 0);
188 /* scan_for_file (panel, idx, direction)
191 * panel: pointer to the panel on which we operate
192 * idx: starting file.
193 * direction: 1, or -1
195 static int scan_for_file (WPanel
*panel
, int idx
, int direction
)
197 int i
= idx
+ direction
;
201 i
= panel
->count
- 1;
202 if (i
== panel
->count
)
204 if (!S_ISDIR (panel
->dir
.list
[i
].st
.st_mode
))
212 * Run viewer (internal or external) on the currently selected file.
213 * If normal is 1, force internal viewer and raw mode (used for F13).
216 do_view_cmd (int normal
)
218 /* Directories are viewed by changing to them */
219 if (S_ISDIR (selection (current_panel
)->st
.st_mode
)
220 || link_isdir (selection (current_panel
))) {
221 if (confirm_view_dir
&& (current_panel
->marked
|| current_panel
->dirs_marked
)) {
223 (_(" Confirmation "), _("Files tagged, want to cd?"), D_NORMAL
, 2,
224 _("&Yes"), _("&No")) != 0) {
228 if (!do_cd (selection (current_panel
)->fname
, cd_exact
))
229 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
234 file_idx
= current_panel
->selected
;
236 filename
= current_panel
->dir
.list
[file_idx
].fname
;
238 dir
= view_file (filename
, normal
, use_internal_view
);
241 file_idx
= scan_for_file (current_panel
, file_idx
, dir
);
248 /* Run user's preferred viewer on the currently selected file */
255 /* Ask for file and run user's preferred viewer on it */
262 input_expand_dialog (_(" View file "), _(" Filename:"),
263 MC_HISTORY_FM_VIEW_FILE
, selection (current_panel
)->fname
);
267 view_file (filename
, 0, use_internal_view
);
271 /* Run plain internal viewer on the currently selected file */
273 view_simple_cmd (void)
279 filtered_view_cmd (void)
284 input_dialog (_(" Filtered view "),
285 _(" Filter command and arguments:"),
286 MC_HISTORY_FM_FILTERED_VIEW
,
287 selection (current_panel
)->fname
);
291 mcview_viewer (command
, "", NULL
, 0);
297 do_edit_at_line (const char *what
, int start_line
)
299 static const char *editor
= NULL
;
301 #ifdef USE_INTERNAL_EDIT
302 if (use_internal_edit
)
303 edit_file (what
, start_line
);
305 #endif /* USE_INTERNAL_EDIT */
307 if (editor
== NULL
) {
308 editor
= getenv ("EDITOR");
310 editor
= get_default_editor ();
312 execute_with_vfs_arg (editor
, what
);
314 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
319 do_edit (const char *what
)
321 do_edit_at_line (what
, 0);
327 if (regex_command (selection (current_panel
)->fname
, "Edit", 0) == 0)
328 do_edit (selection (current_panel
)->fname
);
337 /* Invoked by F5. Copy, default to the other panel. */
342 if (panel_operate (current_panel
, OP_COPY
, 0)) {
343 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
348 /* Invoked by F6. Move/rename, default to the other panel, ignore marks. */
352 if (panel_operate (current_panel
, OP_MOVE
, 0)){
353 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
358 /* Invoked by F15. Copy, default to the same panel, ignore marks. */
359 void copy_cmd_local (void)
362 if (panel_operate (current_panel
, OP_COPY
, 1)){
363 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
368 /* Invoked by F16. Move/rename, default to the same panel. */
369 void ren_cmd_local (void)
372 if (panel_operate (current_panel
, OP_MOVE
, 1)){
373 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
382 const char *name
= "";
384 /* If 'on' then automatically fills name with current selected item name */
385 if (auto_fill_mkdir_name
)
386 name
= selection (current_panel
)->fname
;
389 input_expand_dialog (_("Create a new Directory"),
390 _(" Enter directory name:"),
397 if (dir
[0] == '/' || dir
[0] == '~')
398 absdir
= g_strdup (dir
);
400 absdir
= concat_dir_and_file (current_panel
->cwd
, dir
);
403 if (my_mkdir (absdir
, 0777) == 0) {
404 update_panels (UP_OPTIMIZE
, dir
);
406 select_item (current_panel
);
408 message (D_ERROR
, MSG_ERROR
, " %s ", unix_error_string (errno
));
415 void delete_cmd (void)
419 if (panel_operate (current_panel
, OP_DELETE
, 0)){
420 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
425 /* Invoked by F18. Remove selected file, regardless of marked files. */
426 void delete_cmd_local (void)
430 if (panel_operate (current_panel
, OP_DELETE
, 1)){
431 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
442 set_panel_filter_to (WPanel
*p
, char *allocated_filter_string
)
447 if (!(allocated_filter_string
[0] == '*' && allocated_filter_string
[1] == 0))
448 p
->filter
= allocated_filter_string
;
450 g_free (allocated_filter_string
);
454 /* Set a given panel filter expression */
456 set_panel_filter (WPanel
*p
)
461 x
= p
->filter
? p
->filter
: easy_patterns
? "*" : ".";
463 reg_exp
= input_dialog_help (_(" Filter "),
464 _(" Set expression for filtering filenames"),
465 "[Filter...]", MC_HISTORY_FM_PANEL_FILTER
, x
);
468 set_panel_filter_to (p
, reg_exp
);
471 /* Invoked from the left/right menus */
472 void filter_cmd (void)
476 if (!SELECTED_IS_PANEL
)
480 set_panel_filter (p
);
483 void reread_cmd (void)
487 if (get_current_type () == view_listing
&&
488 get_other_type () == view_listing
)
489 flag
= strcmp (current_panel
->cwd
, other_panel
->cwd
) ? UP_ONLY_CURRENT
: 0;
491 flag
= UP_ONLY_CURRENT
;
493 update_panels (UP_RELOAD
|flag
, UP_KEEPSEL
);
498 reverse_selection_cmd (void)
503 for (i
= 0; i
< current_panel
->count
; i
++) {
504 file
= ¤t_panel
->dir
.list
[i
];
505 if ((reverse_files_only
== 0) || !S_ISDIR (file
->st
.st_mode
))
506 do_file_mark (current_panel
, i
, !file
->f
.marked
);
511 select_unselect_cmd (const char *title
, const char *history_name
, gboolean do_select
)
517 int files_only
= (select_flags
& SELECT_FILES_ONLY
) != 0;
518 int case_sens
= (select_flags
& SELECT_MATCH_CASE
) != 0;
519 int shell_patterns
= (select_flags
& SELECT_SHELL_PATTERNS
) != 0;
525 QuickWidget quick_widgets
[] = {
526 { quick_checkbox
, 3, DX
, DY
- 3, DY
, N_("&Using shell patterns"), 0, 0, &shell_patterns
, NULL
, NULL
},
527 { quick_checkbox
, DX
/2 + 1, DX
, DY
- 4, DY
, N_("&Case sensitive"), 0, 0, &case_sens
, NULL
, NULL
},
528 { quick_checkbox
, 3, DX
, DY
- 4, DY
, N_("&Files only"), 0, 0, &files_only
, NULL
, NULL
},
529 { quick_input
, 3, DX
, DY
- 5, DY
, INPUT_LAST_TEXT
, DX
- 6, 0, NULL
, ®_exp
, history_name
},
533 QuickDialog quick_dlg
= {
534 DX
, DY
, -1, -1, title
, "[Select/Unselect Files]", quick_widgets
, 0
537 if (quick_dialog (&quick_dlg
) == B_CANCEL
)
546 search
= mc_search_new (reg_exp
, -1);
547 search
->search_type
= (shell_patterns
!= 0) ? MC_SEARCH_T_GLOB
: MC_SEARCH_T_REGEX
;
548 search
->is_entire_line
= TRUE
;
549 search
->is_case_sentitive
= case_sens
!= 0;
551 for (i
= 0; i
< current_panel
->count
; i
++) {
552 if (strcmp (current_panel
->dir
.list
[i
].fname
, "..") == 0)
554 if (S_ISDIR (current_panel
->dir
.list
[i
].st
.st_mode
) && files_only
!= 0)
557 if (mc_search_run (search
, current_panel
->dir
.list
[i
].fname
,
558 0, current_panel
->dir
.list
[i
].fnamelen
, NULL
))
559 do_file_mark (current_panel
, i
, do_select
);
562 mc_search_free (search
);
568 select_flags
|= SELECT_MATCH_CASE
;
570 select_flags
|= SELECT_FILES_ONLY
;
571 if (shell_patterns
!= 0)
572 select_flags
|= SELECT_SHELL_PATTERNS
;
575 void select_cmd (void)
577 select_unselect_cmd (_(" Select "), ":select_cmd: Select ", TRUE
);
580 void unselect_cmd (void)
582 select_unselect_cmd (_(" Unselect "), ":unselect_cmd: Unselect ", FALSE
);
592 if (geteuid () == 0){
593 dir
= query_dialog (_("Extension file edit"),
594 _(" Which extension file you want to edit? "), D_NORMAL
, 2,
595 _("&User"), _("&System Wide"));
597 extdir
= concat_dir_and_file (mc_home
, MC_LIB_EXT
);
600 buffer
= concat_dir_and_file (home_dir
, MC_USER_EXT
);
601 check_for_default (extdir
, buffer
);
604 } else if (dir
== 1) {
605 if (!exist_file(extdir
)) {
607 extdir
= concat_dir_and_file (mc_home_alt
, MC_LIB_EXT
);
612 flush_extension_file ();
615 /* edit file menu for mc */
617 edit_mc_menu_cmd (void)
625 _(" Which menu file do you want to edit? "),
626 D_NORMAL
, geteuid() ? 2 : 3,
627 _("&Local"), _("&User"), _("&System Wide")
630 menufile
= concat_dir_and_file (mc_home
, MC_GLOBAL_MENU
);
632 if (!exist_file(menufile
)) {
634 menufile
= concat_dir_and_file (mc_home_alt
, MC_GLOBAL_MENU
);
639 buffer
= g_strdup (MC_LOCAL_MENU
);
640 check_for_default (menufile
, buffer
);
641 chmod (buffer
, 0600);
645 buffer
= concat_dir_and_file (home_dir
, MC_HOME_MENU
);
646 check_for_default (menufile
, buffer
);
650 buffer
= concat_dir_and_file (mc_home
, MC_GLOBAL_MENU
);
651 if (!exist_file(buffer
)) {
653 buffer
= concat_dir_and_file (mc_home_alt
, MC_GLOBAL_MENU
);
668 void quick_chdir_cmd (void)
672 target
= hotlist_cmd (LIST_HOTLIST
);
676 if (get_current_type () == view_tree
)
677 tree_chdir (the_tree
, target
);
679 if (!do_cd (target
, cd_exact
))
680 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory") );
685 void reselect_vfs (void)
689 target
= hotlist_cmd (LIST_VFSLIST
);
693 if (!do_cd (target
, cd_exact
))
694 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory") );
699 static int compare_files (char *name1
, char *name2
, off_t size
)
702 int result
= -1; /* Different by default */
707 file1
= open (name1
, O_RDONLY
);
709 file2
= open (name2
, O_RDONLY
);
714 data1
= mmap (0, size
, PROT_READ
, MAP_FILE
| MAP_PRIVATE
, file1
, 0);
715 if (data1
!= (char*) -1){
716 data2
= mmap (0, size
, PROT_READ
, MAP_FILE
| MAP_PRIVATE
, file2
, 0);
717 if (data2
!= (char*) -1){
719 result
= memcmp (data1
, data2
, size
);
720 munmap (data2
, size
);
722 munmap (data1
, size
);
725 /* Don't have mmap() :( Even more ugly :) */
726 char buf1
[BUFSIZ
], buf2
[BUFSIZ
];
731 while((n1
= read(file1
,buf1
,BUFSIZ
)) == -1 && errno
== EINTR
);
732 while((n2
= read(file2
,buf2
,BUFSIZ
)) == -1 && errno
== EINTR
);
733 } while (n1
== n2
&& n1
== BUFSIZ
&& !memcmp(buf1
,buf2
,BUFSIZ
));
734 result
= (n1
!= n2
) || memcmp(buf1
,buf2
,n1
);
735 #endif /* !HAVE_MMAP */
744 compare_quick
, compare_size_only
, compare_thourough
748 compare_dir (WPanel
*panel
, WPanel
*other
, enum CompareMode mode
)
751 char *src_name
, *dst_name
;
753 /* No marks by default */
756 panel
->dirs_marked
= 0;
758 /* Handle all files in the panel */
759 for (i
= 0; i
< panel
->count
; i
++){
760 file_entry
*source
= &panel
->dir
.list
[i
];
762 /* Default: unmarked */
763 file_mark (panel
, i
, 0);
765 /* Skip directories */
766 if (S_ISDIR (source
->st
.st_mode
))
769 /* Search the corresponding entry from the other panel */
770 for (j
= 0; j
< other
->count
; j
++){
771 if (strcmp (source
->fname
,
772 other
->dir
.list
[j
].fname
) == 0)
775 if (j
>= other
->count
)
776 /* Not found -> mark */
777 do_file_mark (panel
, i
, 1);
780 file_entry
*target
= &other
->dir
.list
[j
];
782 if (mode
!= compare_size_only
){
783 /* Older version is not marked */
784 if (source
->st
.st_mtime
< target
->st
.st_mtime
)
788 /* Newer version with different size is marked */
789 if (source
->st
.st_size
!= target
->st
.st_size
){
790 do_file_mark (panel
, i
, 1);
794 if (mode
== compare_size_only
)
797 if (mode
== compare_quick
){
798 /* Thorough compare off, compare only time stamps */
799 /* Mark newer version, don't mark version with the same date */
800 if (source
->st
.st_mtime
> target
->st
.st_mtime
){
801 do_file_mark (panel
, i
, 1);
806 /* Thorough compare on, do byte-by-byte comparison */
807 src_name
= concat_dir_and_file (panel
->cwd
, source
->fname
);
808 dst_name
= concat_dir_and_file (other
->cwd
, target
->fname
);
809 if (compare_files (src_name
, dst_name
, source
->st
.st_size
))
810 do_file_mark (panel
, i
, 1);
818 compare_dirs_cmd (void)
821 enum CompareMode thorough_flag
;
824 query_dialog (_(" Compare directories "),
825 _(" Select compare method: "), D_NORMAL
, 4,
826 _("&Quick"), _("&Size only"), _("&Thorough"), _("&Cancel"));
828 if (choice
< 0 || choice
> 2)
831 thorough_flag
= choice
;
833 if (get_current_type () == view_listing
834 && get_other_type () == view_listing
) {
835 compare_dir (current_panel
, other_panel
, thorough_flag
);
836 compare_dir (other_panel
, current_panel
, thorough_flag
);
838 message (D_ERROR
, MSG_ERROR
,
839 _(" Both panels should be in the "
840 "listing mode to use this command "));
847 /* show the history of command line widget */
848 send_message (&cmdline
->widget
, WIDGET_KEY
, ALT ('h'));
858 view_other_cmd (void)
860 static int message_flag
= TRUE
;
862 if (!xterm_flag
&& !console_flag
&& !use_subshell
&& !output_starts_shell
) {
864 message (D_ERROR
, MSG_ERROR
,
865 _(" Not an xterm or Linux console; \n"
866 " the panels cannot be toggled. "));
867 message_flag
= FALSE
;
874 do_link (int symbolic_link
, const char *fname
)
876 char *dest
= NULL
, *src
= NULL
;
878 if (!symbolic_link
) {
879 src
= g_strdup_printf (_("Link %s to:"), str_trunc (fname
, 46));
880 dest
= input_expand_dialog (_(" Link "), src
, MC_HISTORY_FM_LINK
, "");
884 if (-1 == mc_link (fname
, dest
))
885 message (D_ERROR
, MSG_ERROR
, _(" link: %s "),
886 unix_error_string (errno
));
891 /* suggest the full path for symlink */
892 s
= concat_dir_and_file (current_panel
->cwd
, fname
);
894 if (get_other_type () == view_listing
) {
895 d
= concat_dir_and_file (other_panel
->cwd
, fname
);
897 d
= g_strdup (fname
);
900 symlink_dialog (s
, d
, &dest
, &src
);
904 if (!dest
|| !*dest
|| !src
|| !*src
)
907 if (-1 == mc_symlink (dest
, src
))
908 message (D_ERROR
, MSG_ERROR
, _(" symlink: %s "),
909 unix_error_string (errno
));
911 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
921 do_link (0, selection (current_panel
)->fname
);
924 void symlink_cmd (void)
926 char *filename
= NULL
;
927 filename
= selection (current_panel
)->fname
;
930 do_link (1, filename
);
934 void edit_symlink_cmd (void)
936 if (S_ISLNK (selection (current_panel
)->st
.st_mode
)) {
937 char buffer
[MC_MAXPATHLEN
];
942 p
= selection (current_panel
)->fname
;
944 q
= g_strdup_printf (_(" Symlink `%s\' points to: "), str_trunc (p
, 32));
946 i
= readlink (p
, buffer
, MC_MAXPATHLEN
- 1);
949 dest
= input_expand_dialog (_(" Edit symlink "), q
, MC_HISTORY_FM_EDIT_LINK
, buffer
);
951 if (*dest
&& strcmp (buffer
, dest
)) {
953 if (-1 == mc_unlink (p
)){
954 message (D_ERROR
, MSG_ERROR
, _(" edit symlink, unable to remove %s: %s "),
955 p
, unix_error_string (errno
));
957 if (-1 == mc_symlink (dest
, p
))
958 message (D_ERROR
, MSG_ERROR
, _(" edit symlink: %s "),
959 unix_error_string (errno
));
961 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
969 message (D_ERROR
, MSG_ERROR
, _("`%s' is not a symbolic link"),
970 selection (current_panel
)->fname
);
976 interactive_display (NULL
, "[main]");
980 user_file_menu_cmd (void)
982 user_menu_cmd (NULL
);
985 /* partly taken from dcigettext.c, returns "" for default locale */
986 /* value should be freed by calling function g_free() */
987 char *guess_message_value (void)
989 static const char * const var
[] = {
990 /* The highest priority value is the `LANGUAGE' environment
991 variable. This is a GNU extension. */
993 /* Setting of LC_ALL overwrites all other. */
995 /* Next comes the name of the desired category. */
997 /* Last possibility is the LANG environment variable. */
999 /* NULL exit loops */
1004 const char *locale
= NULL
;
1006 while (var
[i
] != NULL
) {
1007 locale
= getenv (var
[i
]);
1008 if (locale
!= NULL
&& locale
[0] != '\0')
1016 return g_strdup (locale
);
1020 * Return a random hint. If force is not 0, ignore the timeout.
1023 get_random_hint (int force
)
1025 char *data
, *result
= NULL
, *eol
;
1028 static int last_sec
;
1029 static struct timeval tv
;
1033 /* Do not change hints more often than one minute */
1034 gettimeofday (&tv
, NULL
);
1035 if (!force
&& !(tv
.tv_sec
> last_sec
+ 60))
1036 return g_strdup ("");
1037 last_sec
= tv
.tv_sec
;
1039 data
= load_mc_home_file (MC_HINT
, NULL
);
1043 /* get a random entry */
1045 len
= strlen (data
);
1046 start
= rand () % len
;
1048 for (; start
; start
--) {
1049 if (data
[start
] == '\n') {
1054 eol
= strchr (&data
[start
], '\n');
1058 /* hint files are stored in utf-8 */
1059 /* try convert hint file from utf-8 to terminal encoding */
1060 conv
= str_crt_conv_from ("UTF-8");
1061 if (conv
!= INVALID_CONV
) {
1062 buffer
= g_string_new ("");
1063 if (str_convert (conv
, &data
[start
], buffer
) != ESTR_FAILURE
) {
1064 result
= g_strdup (buffer
->str
);
1066 g_string_free (buffer
, TRUE
);
1067 str_close_conv (conv
);
1074 #if defined(USE_NETCODE) || defined(USE_EXT2FSLIB)
1076 nice_cd (const char *text
, const char *xtext
, const char *help
,
1077 const char *history_name
, const char *prefix
, int to_home
)
1082 if (!SELECTED_IS_PANEL
)
1085 machine
= input_dialog_help (text
, xtext
, help
, history_name
, "");
1089 to_home
= 0; /* FIXME: how to solve going to home nicely? /~/ is
1090 ugly as hell and leads to problems in vfs layer */
1092 if (strncmp (prefix
, machine
, strlen (prefix
)) == 0)
1093 cd_path
= g_strconcat (machine
, to_home
? "/~/" : (char *) NULL
, (char *) NULL
);
1095 cd_path
= g_strconcat (prefix
, machine
, to_home
? "/~/" : (char *) NULL
, (char *) NULL
);
1097 if (do_panel_cd (MENU_PANEL
, cd_path
, 0))
1098 directory_history_add (MENU_PANEL
, (MENU_PANEL
)->cwd
);
1100 message (D_ERROR
, MSG_ERROR
, _(" Cannot chdir to %s "), cd_path
);
1104 #endif /* USE_NETCODE || USE_EXT2FSLIB */
1109 static const char *machine_str
= N_(" Enter machine name (F1 for details): ");
1111 #ifdef ENABLE_VFS_MCFS
1112 void netlink_cmd (void)
1114 nice_cd (_(" Link to a remote machine "), _(machine_str
),
1115 "[Network File System]", ":netlink_cmd: Link to a remote ",
1118 #endif /* ENABLE_VFS_MCFS */
1120 void ftplink_cmd (void)
1122 nice_cd (_(" FTP to machine "), _(machine_str
),
1123 "[FTP File System]", ":ftplink_cmd: FTP to machine ", "/#ftp:", 1);
1126 void fishlink_cmd (void)
1128 nice_cd (_(" Shell link to machine "), _(machine_str
),
1129 "[FIle transfer over SHell filesystem]", ":fishlink_cmd: Shell link to machine ",
1134 void smblink_cmd (void)
1136 nice_cd (_(" SMB link to machine "), _(machine_str
),
1137 "[SMB File System]", ":smblink_cmd: SMB link to machine ",
1140 #endif /* WITH_SMBFS */
1141 #endif /* USE_NETCODE */
1143 #ifdef USE_EXT2FSLIB
1144 void undelete_cmd (void)
1146 nice_cd (_(" Undelete files on an ext2 file system "),
1147 _(" Enter device (without /dev/) to undelete\n "
1148 " files on: (F1 for details)"),
1149 "[Undelete File System]", ":undelete_cmd: Undel on ext2 fs ",
1152 #endif /* USE_EXT2FSLIB */
1154 void quick_cd_cmd (void)
1156 char *p
= cd_dialog ();
1159 char *q
= g_strconcat ("cd ", p
, (char *) NULL
);
1169 \brief calculate dirs sizes
1171 calculate dirs sizes and resort panel:
1172 dirs_selected = show size for selected dirs,
1173 otherwise = show size for dir under cursor:
1174 dir under cursor ".." = show size for all dirs,
1175 otherwise = show size for dir under cursor
1178 smart_dirsize_cmd (void)
1180 WPanel
*panel
= current_panel
;
1183 entry
= &(panel
->dir
.list
[panel
->selected
]);
1184 if ( ( S_ISDIR (entry
->st
.st_mode
) && ( strcmp(entry
->fname
, "..") == 0 ) )
1185 || panel
->dirs_marked
)
1188 single_dirsize_cmd ();
1192 single_dirsize_cmd (void)
1194 WPanel
*panel
= current_panel
;
1198 ComputeDirSizeUI
*ui
;
1200 entry
= &(panel
->dir
.list
[panel
->selected
]);
1201 if (S_ISDIR (entry
->st
.st_mode
) && strcmp(entry
->fname
, "..") != 0) {
1202 ui
= compute_dir_size_create_ui ();
1206 if (compute_dir_size (entry
->fname
, ui
, compute_dir_size_update_ui
,
1207 &marked
, &total
) == FILE_CONT
) {
1208 entry
->st
.st_size
= (off_t
) total
;
1209 entry
->f
.dir_size_computed
= 1;
1212 compute_dir_size_destroy_ui (ui
);
1215 if (mark_moves_down
)
1216 send_message (&(panel
->widget
), WIDGET_KEY
, KEY_DOWN
);
1218 recalculate_panel_summary (panel
);
1220 if ( current_panel
->sort_type
== (sortfn
*) sort_size
)
1221 panel_re_sort (panel
);
1229 WPanel
*panel
= current_panel
;
1233 ComputeDirSizeUI
*ui
;
1235 ui
= compute_dir_size_create_ui ();
1237 for (i
= 0; i
< panel
->count
; i
++)
1238 if (S_ISDIR (panel
->dir
.list
[i
].st
.st_mode
)
1239 && ((panel
->dirs_marked
&& panel
->dir
.list
[i
].f
.marked
)
1240 || !panel
->dirs_marked
)
1241 && strcmp (panel
->dir
.list
[i
].fname
, "..") != 0) {
1244 if (compute_dir_size (panel
->dir
.list
[i
].fname
,
1245 ui
, compute_dir_size_update_ui
,
1246 &marked
, &total
) != FILE_CONT
)
1249 panel
->dir
.list
[i
].st
.st_size
= (off_t
) total
;
1250 panel
->dir
.list
[i
].f
.dir_size_computed
= 1;
1253 compute_dir_size_destroy_ui (ui
);
1255 recalculate_panel_summary (panel
);
1257 if ( current_panel
->sort_type
== (sortfn
*) sort_size
)
1258 panel_re_sort (panel
);
1264 save_setup_cmd (void)
1267 message (D_NORMAL
, _(" Setup "), _(" Setup saved to ~/%s"), PROFILE_NAME
);
1271 configure_panel_listing (WPanel
*p
, int view_type
, int use_msformat
, char *user
, char *status
)
1273 p
->user_mini_status
= use_msformat
;
1274 p
->list_type
= view_type
;
1276 if (view_type
== list_user
|| use_msformat
){
1277 g_free (p
->user_format
);
1278 p
->user_format
= user
;
1280 g_free (p
->user_status_format
[view_type
]);
1281 p
->user_status_format
[view_type
] = status
;
1283 set_panel_formats (p
);
1290 set_panel_formats (p
);
1295 info_cmd_no_menu (void)
1297 if (get_display_type (0) == view_info
)
1298 set_display_type (0, view_listing
);
1299 else if (get_display_type (1) == view_info
)
1300 set_display_type (1, view_listing
);
1302 set_display_type (current_panel
== left_panel
? 1 : 0, view_info
);
1306 quick_cmd_no_menu (void)
1308 if (get_display_type (0) == view_quick
)
1309 set_display_type (0, view_listing
);
1310 else if (get_display_type (1) == view_quick
)
1311 set_display_type (1, view_listing
);
1313 set_display_type (current_panel
== left_panel
? 1 : 0, view_quick
);
1317 switch_to_listing (int panel_index
)
1319 if (get_display_type (panel_index
) != view_listing
)
1320 set_display_type (panel_index
, view_listing
);
1326 int view_type
, use_msformat
;
1327 char *user
, *status
;
1331 display_type
= get_display_type (MENU_PANEL_IDX
);
1332 if (display_type
== view_listing
)
1333 p
= MENU_PANEL_IDX
== 0 ? left_panel
: right_panel
;
1337 view_type
= display_box (p
, &user
, &status
, &use_msformat
, MENU_PANEL_IDX
);
1339 if (view_type
== -1)
1342 switch_to_listing (MENU_PANEL_IDX
);
1344 p
= MENU_PANEL_IDX
== 0 ? left_panel
: right_panel
;
1346 configure_panel_listing (p
, view_type
, use_msformat
, user
, status
);
1352 set_display_type (MENU_PANEL_IDX
, view_tree
);
1358 set_display_type (MENU_PANEL_IDX
, view_info
);
1362 quick_view_cmd (void)
1364 if ((WPanel
*) get_panel_widget (MENU_PANEL_IDX
) == current_panel
)
1366 set_display_type (MENU_PANEL_IDX
, view_quick
);
1369 /* Handle the tree internal listing modes switching */
1371 set_basic_panel_listing_to (int panel_index
, int listing_mode
)
1373 WPanel
*p
= (WPanel
*) get_panel_widget (panel_index
);
1375 switch_to_listing (panel_index
);
1376 p
->list_type
= listing_mode
;
1377 if (set_panel_formats (p
))
1385 toggle_listing_cmd (void)
1387 int current
= get_current_index ();
1388 WPanel
*p
= (WPanel
*) get_panel_widget (current
);
1390 set_basic_panel_listing_to (current
, (p
->list_type
+ 1) % LIST_TYPES
);
1398 if (!SELECTED_IS_PANEL
)
1402 set_panel_encoding (panel
);