2 Main dialog (file panels) of the Midnight Commander
4 Copyright (C) 1994-2018
5 Free Software Foundation, Inc.
8 Miguel de Icaza, 1994, 1995, 1996, 1997
9 Janne Kukonlehto, 1994, 1995
11 Andrew Borodin <aborodin@vmail.ru>, 2009, 2010, 2012, 2013
12 Slava Zanko <slavazanko@gmail.com>, 2013
14 This file is part of the Midnight Commander.
16 The Midnight Commander is free software: you can redistribute it
17 and/or modify it under the terms of the GNU General Public License as
18 published by the Free Software Foundation, either version 3 of the License,
19 or (at your option) any later version.
21 The Midnight Commander is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program. If not, see <http://www.gnu.org/licenses/>.
31 * \brief Source: main dialog (file panels) of the Midnight Commander
42 #include <sys/types.h>
45 #include <pwd.h> /* for username in xterm title */
47 #include "lib/global.h"
48 #include "lib/fileloc.h" /* MC_HINT */
50 #include "lib/tty/tty.h"
51 #include "lib/tty/key.h" /* KEY_M_* masks */
55 #include "lib/vfs/vfs.h"
58 #ifdef ENABLE_SUBSHELL
59 #include "src/subshell/subshell.h"
61 #include "src/setup.h" /* variables */
62 #include "src/learn.h" /* learn_keys() */
63 #include "src/keybind-defaults.h"
64 #include "lib/keybind.h"
65 #include "lib/event.h"
68 #include "boxes.h" /* sort_box(), tree_box() */
70 #include "cmd.h" /* commands */
73 #include "command.h" /* cmdline */
74 #include "dir.h" /* dir_list_clean() */
80 #ifdef USE_INTERNAL_EDIT
81 #include "src/editor/edit.h"
85 #include "src/diffviewer/ydiff.h"
88 #include "src/consaver/cons.saver.h" /* show_console_contents */
92 /*** global variables ****************************************************************************/
94 /* When the modes are active, left_panel, right_panel and tree_panel */
95 /* point to a proper data structure. You should check with the functions */
96 /* get_current_type and get_other_type the types of the panels before using */
97 /* this pointer variables */
99 /* The structures for the panels */
100 WPanel
*left_panel
= NULL
;
101 WPanel
*right_panel
= NULL
;
102 /* Pointer to the selected and unselected panel */
103 WPanel
*current_panel
= NULL
;
106 WMenuBar
*the_menubar
= NULL
;
107 /* The widget where we draw the prompt */
115 const char *mc_prompt
= NULL
;
117 /*** file scope macro definitions ****************************************************************/
121 * Don't restrict the output on the screen manager level,
122 * the translation tables take care of it.
124 #endif /* !HAVE_CHARSET */
126 /*** file scope type declarations ****************************************************************/
128 /*** file scope variables ************************************************************************/
130 static menu_t
*left_menu
, *right_menu
;
132 static gboolean ctl_x_map_enabled
= FALSE
;
134 /*** file scope functions ************************************************************************/
136 /** Stop MC main dialog and the current dialog if it exists.
137 * Needed to provide fast exit from MC viewer or editor on shell exit */
141 dlg_stop (midnight_dlg
);
143 if ((top_dlg
!= NULL
) && (top_dlg
->data
!= NULL
))
144 dlg_stop (DIALOG (top_dlg
->data
));
147 /* --------------------------------------------------------------------------------------------- */
154 sel_dir
= tree_box (selection (current_panel
)->fname
);
157 vfs_path_t
*sel_vdir
;
159 sel_vdir
= vfs_path_from_str (sel_dir
);
160 do_cd (sel_vdir
, cd_exact
);
161 vfs_path_free (sel_vdir
);
166 /* --------------------------------------------------------------------------------------------- */
168 #ifdef LISTMODE_EDITOR
174 if (get_current_type () != view_listing
)
177 newmode
= listmode_edit (current_panel
->user_format
);
181 g_free (current_panel
->user_format
);
182 current_panel
->list_format
= list_user
;
183 current_panel
->user_format
= newmode
;
184 set_panel_formats (current_panel
);
188 #endif /* LISTMODE_EDITOR */
190 /* --------------------------------------------------------------------------------------------- */
193 create_panel_menu (void)
195 GList
*entries
= NULL
;
197 entries
= g_list_prepend (entries
, menu_entry_create (_("File listin&g"), CK_PanelListing
));
198 entries
= g_list_prepend (entries
, menu_entry_create (_("&Quick view"), CK_PanelQuickView
));
199 entries
= g_list_prepend (entries
, menu_entry_create (_("&Info"), CK_PanelInfo
));
200 entries
= g_list_prepend (entries
, menu_entry_create (_("&Tree"), CK_PanelTree
));
201 entries
= g_list_prepend (entries
, menu_separator_create ());
203 g_list_prepend (entries
,
204 menu_entry_create (_("&Listing format..."), CK_SetupListingFormat
));
205 entries
= g_list_prepend (entries
, menu_entry_create (_("&Sort order..."), CK_Sort
));
206 entries
= g_list_prepend (entries
, menu_entry_create (_("&Filter..."), CK_Filter
));
208 entries
= g_list_prepend (entries
, menu_entry_create (_("&Encoding..."), CK_SelectCodepage
));
210 entries
= g_list_prepend (entries
, menu_separator_create ());
211 #ifdef ENABLE_VFS_FTP
212 entries
= g_list_prepend (entries
, menu_entry_create (_("FT&P link..."), CK_ConnectFtp
));
214 #ifdef ENABLE_VFS_FISH
215 entries
= g_list_prepend (entries
, menu_entry_create (_("S&hell link..."), CK_ConnectFish
));
217 #ifdef ENABLE_VFS_SFTP
218 entries
= g_list_prepend (entries
, menu_entry_create (_("S&FTP link..."), CK_ConnectSftp
));
220 #ifdef ENABLE_VFS_SMB
221 entries
= g_list_prepend (entries
, menu_entry_create (_("SM&B link..."), CK_ConnectSmb
));
223 entries
= g_list_prepend (entries
, menu_entry_create (_("Paneli&ze"), CK_Panelize
));
224 entries
= g_list_prepend (entries
, menu_separator_create ());
225 entries
= g_list_prepend (entries
, menu_entry_create (_("&Rescan"), CK_Reread
));
227 return g_list_reverse (entries
);
230 /* --------------------------------------------------------------------------------------------- */
233 create_file_menu (void)
235 GList
*entries
= NULL
;
237 entries
= g_list_prepend (entries
, menu_entry_create (_("&View"), CK_View
));
238 entries
= g_list_prepend (entries
, menu_entry_create (_("Vie&w file..."), CK_ViewFile
));
239 entries
= g_list_prepend (entries
, menu_entry_create (_("&Filtered view"), CK_ViewFiltered
));
240 entries
= g_list_prepend (entries
, menu_entry_create (_("&Edit"), CK_Edit
));
241 entries
= g_list_prepend (entries
, menu_entry_create (_("&Copy"), CK_Copy
));
242 entries
= g_list_prepend (entries
, menu_entry_create (_("C&hmod"), CK_ChangeMode
));
243 entries
= g_list_prepend (entries
, menu_entry_create (_("&Link"), CK_Link
));
244 entries
= g_list_prepend (entries
, menu_entry_create (_("&Symlink"), CK_LinkSymbolic
));
246 g_list_prepend (entries
,
247 menu_entry_create (_("Relative symlin&k"), CK_LinkSymbolicRelative
));
248 entries
= g_list_prepend (entries
, menu_entry_create (_("Edit s&ymlink"), CK_LinkSymbolicEdit
));
249 entries
= g_list_prepend (entries
, menu_entry_create (_("Ch&own"), CK_ChangeOwn
));
251 g_list_prepend (entries
, menu_entry_create (_("&Advanced chown"), CK_ChangeOwnAdvanced
));
252 entries
= g_list_prepend (entries
, menu_entry_create (_("&Rename/Move"), CK_Move
));
253 entries
= g_list_prepend (entries
, menu_entry_create (_("&Mkdir"), CK_MakeDir
));
254 entries
= g_list_prepend (entries
, menu_entry_create (_("&Delete"), CK_Delete
));
255 entries
= g_list_prepend (entries
, menu_entry_create (_("&Quick cd"), CK_CdQuick
));
256 entries
= g_list_prepend (entries
, menu_separator_create ());
257 entries
= g_list_prepend (entries
, menu_entry_create (_("Select &group"), CK_Select
));
258 entries
= g_list_prepend (entries
, menu_entry_create (_("U&nselect group"), CK_Unselect
));
259 entries
= g_list_prepend (entries
, menu_entry_create (_("&Invert selection"), CK_SelectInvert
));
260 entries
= g_list_prepend (entries
, menu_separator_create ());
261 entries
= g_list_prepend (entries
, menu_entry_create (_("E&xit"), CK_Quit
));
263 return g_list_reverse (entries
);
266 /* --------------------------------------------------------------------------------------------- */
269 create_command_menu (void)
271 /* I know, I'm lazy, but the tree widget when it's not running
272 * as a panel still has some problems, I have not yet finished
273 * the WTree widget port, sorry.
275 GList
*entries
= NULL
;
277 entries
= g_list_prepend (entries
, menu_entry_create (_("&User menu"), CK_UserMenu
));
278 entries
= g_list_prepend (entries
, menu_entry_create (_("&Directory tree"), CK_Tree
));
279 entries
= g_list_prepend (entries
, menu_entry_create (_("&Find file"), CK_Find
));
280 entries
= g_list_prepend (entries
, menu_entry_create (_("S&wap panels"), CK_Swap
));
281 entries
= g_list_prepend (entries
, menu_entry_create (_("Switch &panels on/off"), CK_Shell
));
283 g_list_prepend (entries
, menu_entry_create (_("&Compare directories"), CK_CompareDirs
));
285 entries
= g_list_prepend (entries
, menu_entry_create (_("C&ompare files"), CK_CompareFiles
));
288 g_list_prepend (entries
, menu_entry_create (_("E&xternal panelize"), CK_ExternalPanelize
));
289 entries
= g_list_prepend (entries
, menu_entry_create (_("Show directory s&izes"), CK_DirSize
));
290 entries
= g_list_prepend (entries
, menu_separator_create ());
291 entries
= g_list_prepend (entries
, menu_entry_create (_("Command &history"), CK_History
));
292 entries
= g_list_prepend (entries
, menu_entry_create (_("Di&rectory hotlist"), CK_HotList
));
294 entries
= g_list_prepend (entries
, menu_entry_create (_("&Active VFS list"), CK_VfsList
));
296 #ifdef ENABLE_BACKGROUND
297 entries
= g_list_prepend (entries
, menu_entry_create (_("&Background jobs"), CK_Jobs
));
299 entries
= g_list_prepend (entries
, menu_entry_create (_("Screen lis&t"), CK_ScreenList
));
300 entries
= g_list_prepend (entries
, menu_separator_create ());
301 #ifdef ENABLE_VFS_UNDELFS
303 g_list_prepend (entries
,
304 menu_entry_create (_("&Undelete files (ext2fs only)"), CK_Undelete
));
306 #ifdef LISTMODE_EDITOR
307 entries
= g_list_prepend (entries
, menu_entry_create (_("&Listing format edit"), CK_ListMode
));
309 #if defined (ENABLE_VFS_UNDELFS) || defined (LISTMODE_EDITOR)
310 entries
= g_list_prepend (entries
, menu_separator_create ());
313 g_list_prepend (entries
,
314 menu_entry_create (_("Edit &extension file"), CK_EditExtensionsFile
));
315 entries
= g_list_prepend (entries
, menu_entry_create (_("Edit &menu file"), CK_EditUserMenu
));
317 g_list_prepend (entries
,
318 menu_entry_create (_("Edit hi&ghlighting group file"),
319 CK_EditFileHighlightFile
));
321 return g_list_reverse (entries
);
324 /* --------------------------------------------------------------------------------------------- */
327 create_options_menu (void)
329 GList
*entries
= NULL
;
331 entries
= g_list_prepend (entries
, menu_entry_create (_("&Configuration..."), CK_Options
));
332 entries
= g_list_prepend (entries
, menu_entry_create (_("&Layout..."), CK_OptionsLayout
));
333 entries
= g_list_prepend (entries
, menu_entry_create (_("&Panel options..."), CK_OptionsPanel
));
335 g_list_prepend (entries
, menu_entry_create (_("C&onfirmation..."), CK_OptionsConfirm
));
337 g_list_prepend (entries
, menu_entry_create (_("&Appearance..."), CK_OptionsAppearance
));
339 g_list_prepend (entries
, menu_entry_create (_("&Display bits..."), CK_OptionsDisplayBits
));
340 entries
= g_list_prepend (entries
, menu_entry_create (_("Learn &keys..."), CK_LearnKeys
));
342 entries
= g_list_prepend (entries
, menu_entry_create (_("&Virtual FS..."), CK_OptionsVfs
));
344 entries
= g_list_prepend (entries
, menu_separator_create ());
345 entries
= g_list_prepend (entries
, menu_entry_create (_("&Save setup"), CK_SaveSetup
));
347 return g_list_reverse (entries
);
350 /* --------------------------------------------------------------------------------------------- */
355 left_menu
= create_menu ("", create_panel_menu (), "[Left and Right Menus]");
356 menubar_add_menu (the_menubar
, left_menu
);
357 menubar_add_menu (the_menubar
, create_menu (_("&File"), create_file_menu (), "[File Menu]"));
358 menubar_add_menu (the_menubar
,
359 create_menu (_("&Command"), create_command_menu (), "[Command Menu]"));
360 menubar_add_menu (the_menubar
,
361 create_menu (_("&Options"), create_options_menu (), "[Options Menu]"));
362 right_menu
= create_menu ("", create_panel_menu (), "[Left and Right Menus]");
363 menubar_add_menu (the_menubar
, right_menu
);
367 /* --------------------------------------------------------------------------------------------- */
370 menu_last_selected_cmd (void)
372 menubar_activate (the_menubar
, drop_menus
, -1);
375 /* --------------------------------------------------------------------------------------------- */
382 if ((get_current_index () == 0) == (current_panel
->active
!= 0))
385 selected
= g_list_length (the_menubar
->menu
) - 1;
387 menubar_activate (the_menubar
, drop_menus
, selected
);
390 /* --------------------------------------------------------------------------------------------- */
396 const panel_field_t
*sort_order
;
398 if (!SELECTED_IS_PANEL
)
402 sort_order
= sort_box (&p
->sort_info
, p
->sort_field
);
403 panel_set_sort_order (p
, sort_order
);
406 /* --------------------------------------------------------------------------------------------- */
409 midnight_get_shortcut (long command
)
412 const char *shortcut
= NULL
;
414 shortcut
= keybind_lookup_keymap_shortcut (main_map
, command
);
415 if (shortcut
!= NULL
)
416 return g_strdup (shortcut
);
418 shortcut
= keybind_lookup_keymap_shortcut (panel_map
, command
);
419 if (shortcut
!= NULL
)
420 return g_strdup (shortcut
);
422 ext_map
= keybind_lookup_keymap_shortcut (main_map
, CK_ExtendedKeyMap
);
424 shortcut
= keybind_lookup_keymap_shortcut (main_x_map
, command
);
425 if (shortcut
!= NULL
)
426 return g_strdup_printf ("%s %s", ext_map
, shortcut
);
431 /* --------------------------------------------------------------------------------------------- */
434 midnight_get_title (const WDialog
* h
, size_t len
)
442 title_path_prepare (&path
, &login
);
444 p
= g_strdup_printf ("%s [%s]:%s", _("Panels:"), login
, path
);
447 path
= g_strdup (str_trunc (p
, len
- 4));
453 /* --------------------------------------------------------------------------------------------- */
456 toggle_panels_split (void)
458 panels_layout
.horizontal_split
= !panels_layout
.horizontal_split
;
463 /* --------------------------------------------------------------------------------------------- */
468 check_panel_timestamp (const WPanel
* panel
, panel_view_mode_t mode
, struct vfs_class
*vclass
,
471 if (mode
== view_listing
)
473 const vfs_path_element_t
*path_element
;
475 path_element
= vfs_path_get_by_index (panel
->cwd_vpath
, -1);
477 if (path_element
->class != vclass
)
480 if (vfs_getid (panel
->cwd_vpath
) != id
)
486 /* --------------------------------------------------------------------------------------------- */
490 check_current_panel_timestamp (const gchar
* event_group_name
, const gchar
* event_name
,
491 gpointer init_data
, gpointer data
)
493 ev_vfs_stamp_create_t
*event_data
= (ev_vfs_stamp_create_t
*) data
;
495 (void) event_group_name
;
500 check_panel_timestamp (current_panel
, get_current_type (), event_data
->vclass
,
502 return !event_data
->ret
;
505 /* --------------------------------------------------------------------------------------------- */
509 check_other_panel_timestamp (const gchar
* event_group_name
, const gchar
* event_name
,
510 gpointer init_data
, gpointer data
)
512 ev_vfs_stamp_create_t
*event_data
= (ev_vfs_stamp_create_t
*) data
;
514 (void) event_group_name
;
519 check_panel_timestamp (other_panel
, get_other_type (), event_data
->vclass
, event_data
->id
);
520 return !event_data
->ret
;
522 #endif /* ENABLE_VFS */
524 /* --------------------------------------------------------------------------------------------- */
528 print_vfs_message (const gchar
* event_group_name
, const gchar
* event_name
,
529 gpointer init_data
, gpointer data
)
531 ev_vfs_print_message_t
*event_data
= (ev_vfs_print_message_t
*) data
;
533 (void) event_group_name
;
537 if (mc_global
.midnight_shutdown
)
540 if (!mc_global
.message_visible
|| the_hint
== NULL
|| WIDGET (the_hint
)->owner
== NULL
)
544 if (!nice_rotating_dash
|| (ok_to_refresh
<= 0))
547 /* Preserve current cursor position */
548 tty_getyx (&row
, &col
);
551 tty_setcolor (NORMAL_COLOR
);
552 tty_print_string (str_fit_to_term (event_data
->msg
, COLS
- 1, J_LEFT
));
554 /* Restore cursor position */
555 tty_gotoyx (row
, col
);
560 if (mc_global
.message_visible
)
561 set_hintbar (event_data
->msg
);
564 MC_PTR_FREE (event_data
->msg
);
568 /* --------------------------------------------------------------------------------------------- */
573 int current_index
, other_index
;
574 panel_view_mode_t current_mode
, other_mode
;
575 char *current_dir
, *other_dir
;
576 vfs_path_t
*original_dir
;
579 * Following cases from command line are possible:
580 * 'mc' (no arguments): mc_run_param0 == NULL, mc_run_param1 == NULL
581 * active panel uses current directory
582 * passive panel uses "other_dir" from panels.ini
584 * 'mc dir1 dir2' (two arguments): mc_run_param0 != NULL, mc_run_param1 != NULL
585 * active panel uses mc_run_param0
586 * passive panel uses mc_run_param1
588 * 'mc dir1' (single argument): mc_run_param0 != NULL, mc_run_param1 == NULL
589 * active panel uses mc_run_param0
590 * passive panel uses "other_dir" from panels.ini
593 /* Set up panel directories */
594 if (boot_current_is_left
)
596 /* left panel is active */
599 current_mode
= startup_left_mode
;
600 other_mode
= startup_right_mode
;
602 if (mc_run_param0
== NULL
&& mc_run_param1
== NULL
)
605 current_dir
= NULL
; /* assume current dir */
606 other_dir
= saved_other_dir
; /* from ini */
608 else if (mc_run_param0
!= NULL
&& mc_run_param1
!= NULL
)
611 current_dir
= (char *) mc_run_param0
;
612 other_dir
= mc_run_param1
;
614 else /* mc_run_param0 != NULL && mc_run_param1 == NULL */
617 current_dir
= (char *) mc_run_param0
;
618 other_dir
= saved_other_dir
; /* from ini */
623 /* right panel is active */
626 current_mode
= startup_right_mode
;
627 other_mode
= startup_left_mode
;
629 if (mc_run_param0
== NULL
&& mc_run_param1
== NULL
)
632 current_dir
= NULL
; /* assume current dir */
633 other_dir
= saved_other_dir
; /* from ini */
635 else if (mc_run_param0
!= NULL
&& mc_run_param1
!= NULL
)
638 current_dir
= (char *) mc_run_param0
;
639 other_dir
= mc_run_param1
;
641 else /* mc_run_param0 != NULL && mc_run_param1 == NULL */
644 current_dir
= (char *) mc_run_param0
;
645 other_dir
= saved_other_dir
; /* from ini */
649 /* 1. Get current dir */
650 original_dir
= vfs_path_clone (vfs_get_raw_current_dir ());
652 /* 2. Create passive panel */
653 if (other_dir
!= NULL
)
657 if (g_path_is_absolute (other_dir
))
658 vpath
= vfs_path_from_str (other_dir
);
660 vpath
= vfs_path_append_new (original_dir
, other_dir
, (char *) NULL
);
662 vfs_path_free (vpath
);
664 set_display_type (other_index
, other_mode
);
666 /* 3. Create active panel */
667 if (current_dir
== NULL
)
668 mc_chdir (original_dir
);
673 if (g_path_is_absolute (current_dir
))
674 vpath
= vfs_path_from_str (current_dir
);
676 vpath
= vfs_path_append_new (original_dir
, current_dir
, (char *) NULL
);
678 vfs_path_free (vpath
);
680 set_display_type (current_index
, current_mode
);
682 if (startup_left_mode
== view_listing
)
683 current_panel
= left_panel
;
684 else if (right_panel
!= NULL
)
685 current_panel
= right_panel
;
687 current_panel
= left_panel
;
689 vfs_path_free (original_dir
);
692 mc_event_add (MCEVENT_GROUP_CORE
, "vfs_timestamp", check_other_panel_timestamp
, NULL
, NULL
);
693 mc_event_add (MCEVENT_GROUP_CORE
, "vfs_timestamp", check_current_panel_timestamp
, NULL
, NULL
);
694 #endif /* ENABLE_VFS */
696 mc_event_add (MCEVENT_GROUP_CORE
, "vfs_print_message", print_vfs_message
, NULL
, NULL
);
699 /* --------------------------------------------------------------------------------------------- */
702 midnight_put_panel_path (WPanel
* panel
)
704 vfs_path_t
*cwd_vpath
;
705 const char *cwd_vpath_str
;
711 cwd_vpath
= remove_encoding_from_path (panel
->cwd_vpath
);
713 cwd_vpath
= vfs_path_clone (panel
->cwd_vpath
);
716 cwd_vpath_str
= vfs_path_as_str (cwd_vpath
);
718 command_insert (cmdline
, cwd_vpath_str
, FALSE
);
720 if (!IS_PATH_SEP (cwd_vpath_str
[strlen (cwd_vpath_str
) - 1]))
721 command_insert (cmdline
, PATH_SEP_STR
, FALSE
);
723 vfs_path_free (cwd_vpath
);
726 /* --------------------------------------------------------------------------------------------- */
729 put_link (WPanel
* panel
)
733 if (S_ISLNK (selection (panel
)->st
.st_mode
))
735 char buffer
[MC_MAXPATHLEN
];
739 vpath
= vfs_path_append_new (panel
->cwd_vpath
, selection (panel
)->fname
, (char *) NULL
);
740 i
= mc_readlink (vpath
, buffer
, sizeof (buffer
) - 1);
741 vfs_path_free (vpath
);
746 command_insert (cmdline
, buffer
, TRUE
);
751 /* --------------------------------------------------------------------------------------------- */
754 put_current_link (void)
756 put_link (current_panel
);
759 /* --------------------------------------------------------------------------------------------- */
762 put_other_link (void)
764 if (get_other_type () == view_listing
)
765 put_link (other_panel
);
768 /* --------------------------------------------------------------------------------------------- */
770 /** Insert the selected file name into the input line */
772 put_current_selected (void)
779 if (get_current_type () == view_tree
)
782 const vfs_path_t
*selected_name
;
784 tree
= (WTree
*) get_panel_widget (get_current_index ());
785 selected_name
= tree_selected_name (tree
);
786 tmp
= vfs_path_as_str (selected_name
);
789 tmp
= selection (current_panel
)->fname
;
791 command_insert (cmdline
, tmp
, TRUE
);
794 /* --------------------------------------------------------------------------------------------- */
797 put_tagged (WPanel
* panel
)
801 input_disable_update (cmdline
);
806 for (i
= 0; i
< panel
->dir
.len
; i
++)
808 if (panel
->dir
.list
[i
].f
.marked
)
809 command_insert (cmdline
, panel
->dir
.list
[i
].fname
, TRUE
);
814 command_insert (cmdline
, panel
->dir
.list
[panel
->selected
].fname
, TRUE
);
816 input_enable_update (cmdline
);
819 /* --------------------------------------------------------------------------------------------- */
822 put_current_tagged (void)
824 put_tagged (current_panel
);
827 /* --------------------------------------------------------------------------------------------- */
830 put_other_tagged (void)
832 if (get_other_type () == view_listing
)
833 put_tagged (other_panel
);
836 /* --------------------------------------------------------------------------------------------- */
841 ctl_x_map_enabled
= TRUE
;
844 /* --------------------------------------------------------------------------------------------- */
851 tty_display_8bit (TRUE
);
853 tty_display_8bit (mc_global
.full_eight_bits
);
854 #endif /* HAVE_CHARSET */
856 #else /* HAVE_SLANG */
859 tty_display_8bit (TRUE
);
861 tty_display_8bit (mc_global
.eight_bit_clean
);
862 #endif /* HAVE_CHARSET */
863 #endif /* HAVE_SLANG */
865 #ifdef ENABLE_SUBSHELL
866 if (mc_global
.tty
.use_subshell
)
867 add_select_channel (mc_global
.tty
.subshell_pty
, load_prompt
, 0);
868 #endif /* !ENABLE_SUBSHELL */
870 if ((tty_baudrate () < 9600) || mc_global
.tty
.slow_terminal
)
874 /* --------------------------------------------------------------------------------------------- */
877 setup_dummy_mc (void)
885 vpath
= vfs_path_from_str (d
);
886 ret
= mc_chdir (vpath
);
888 vfs_path_free (vpath
);
892 /* --------------------------------------------------------------------------------------------- */
899 * We sync the profiles since the hotlist may have changed, while
900 * we only change the setup data if we have the auto save feature set
903 save_setup (auto_save_setup
, panels_options
.auto_save_setup
);
905 vfs_stamp_path (vfs_get_raw_current_dir ());
907 if ((current_panel
!= NULL
) && (get_current_type () == view_listing
))
908 vfs_stamp_path (current_panel
->cwd_vpath
);
910 if ((other_panel
!= NULL
) && (get_other_type () == view_listing
))
911 vfs_stamp_path (other_panel
->cwd_vpath
);
914 /* --------------------------------------------------------------------------------------------- */
917 create_file_manager (void)
919 midnight_dlg
->get_shortcut
= midnight_get_shortcut
;
920 midnight_dlg
->get_title
= midnight_get_title
;
921 /* allow rebind tab */
922 widget_want_tab (WIDGET (midnight_dlg
), TRUE
);
924 the_menubar
= menubar_new (0, 0, COLS
, NULL
, menubar_visible
);
925 add_widget (midnight_dlg
, the_menubar
);
929 add_widget (midnight_dlg
, get_panel_widget (0));
930 add_widget (midnight_dlg
, get_panel_widget (1));
932 the_hint
= label_new (0, 0, 0);
933 the_hint
->transparent
= 1;
934 the_hint
->auto_adjust_cols
= 0;
935 WIDGET (the_hint
)->cols
= COLS
;
936 add_widget (midnight_dlg
, the_hint
);
938 cmdline
= command_new (0, 0, 0);
939 add_widget (midnight_dlg
, cmdline
);
941 the_prompt
= label_new (0, 0, mc_prompt
);
942 the_prompt
->transparent
= TRUE
;
943 add_widget (midnight_dlg
, the_prompt
);
945 the_bar
= buttonbar_new (mc_global
.keybar_visible
);
946 add_widget (midnight_dlg
, the_bar
);
947 midnight_set_buttonbar (the_bar
);
950 /* --------------------------------------------------------------------------------------------- */
952 /** result must be free'd (I think this should go in util.c) */
954 prepend_cwd_on_local (const char *filename
)
958 vpath
= vfs_path_from_str (filename
);
959 if (!vfs_file_is_local (vpath
) || g_path_is_absolute (filename
))
962 vfs_path_free (vpath
);
964 return vfs_path_append_new (vfs_get_raw_current_dir (), filename
, (char *) NULL
);
967 /* --------------------------------------------------------------------------------------------- */
969 /** Invoke the internal view/edit routine with:
970 * the default processing and forcing the internal viewer/editor
973 mc_maybe_editor_or_viewer (void)
977 switch (mc_global
.mc_run_mode
)
979 #ifdef USE_INTERNAL_EDIT
981 ret
= edit_files ((GList
*) mc_run_param0
);
983 #endif /* USE_INTERNAL_EDIT */
986 vfs_path_t
*vpath
= NULL
;
988 if (mc_run_param0
!= NULL
&& *(char *) mc_run_param0
!= '\0')
989 vpath
= prepend_cwd_on_local ((char *) mc_run_param0
);
991 ret
= view_file (vpath
, FALSE
, TRUE
);
992 vfs_path_free (vpath
);
996 case MC_RUN_DIFFVIEWER
:
997 ret
= dview_diff_cmd (mc_run_param0
, mc_run_param1
);
999 #endif /* USE_DIFF_VIEW */
1007 /* --------------------------------------------------------------------------------------------- */
1010 quit_cmd_internal (int quiet
)
1015 n
= dialog_switch_num () - 1;
1018 char msg
[BUF_MEDIUM
];
1020 g_snprintf (msg
, sizeof (msg
),
1021 ngettext ("You have %zu opened screen. Quit anyway?",
1022 "You have %zu opened screens. Quit anyway?", n
), n
);
1024 if (query_dialog (_("The Midnight Commander"), msg
, D_NORMAL
, 2, _("&Yes"), _("&No")) != 0)
1028 else if (quiet
|| !confirm_exit
)
1030 else if (query_dialog (_("The Midnight Commander"),
1031 _("Do you really want to quit the Midnight Commander?"),
1032 D_NORMAL
, 2, _("&Yes"), _("&No")) == 0)
1037 #ifdef ENABLE_SUBSHELL
1038 if (!mc_global
.tty
.use_subshell
)
1040 else if ((q
= exit_subshell ()? 1 : 0) != 0)
1050 /* --------------------------------------------------------------------------------------------- */
1055 return quit_cmd_internal (0);
1058 /* --------------------------------------------------------------------------------------------- */
1061 * Repaint the contents of the panels without frames. To schedule panel
1062 * for repainting, set panel->dirty to 1. There are many reasons why
1063 * the panels need to be repainted, and this is a costly operation, so
1064 * it's done once per event.
1068 update_dirty_panels (void)
1070 if (get_current_type () == view_listing
&& current_panel
->dirty
)
1071 widget_redraw (WIDGET (current_panel
));
1073 if (get_other_type () == view_listing
&& other_panel
->dirty
)
1074 widget_redraw (WIDGET (other_panel
));
1077 /* --------------------------------------------------------------------------------------------- */
1080 toggle_show_hidden (void)
1082 panels_options
.show_dot_files
= !panels_options
.show_dot_files
;
1083 update_panels (UP_RELOAD
, UP_KEEPSEL
);
1084 /* redraw panels forced */
1085 update_dirty_panels ();
1088 /* --------------------------------------------------------------------------------------------- */
1091 midnight_execute_cmd (Widget
* sender
, long command
)
1093 cb_ret_t res
= MSG_HANDLED
;
1097 /* stop quick search before executing any command */
1098 send_message (current_panel
, NULL
, MSG_ACTION
, CK_SearchStop
, NULL
);
1102 case CK_ChangePanel
:
1108 case CK_SetupListingFormat
:
1109 setup_listing_format_cmd ();
1117 case CK_ChangeOwnAdvanced
:
1118 advanced_chown_cmd ();
1120 case CK_CompareDirs
:
1121 compare_dirs_cmd ();
1131 case CK_OptionsConfirm
:
1137 case CK_PutCurrentPath
:
1138 midnight_put_panel_path (current_panel
);
1140 case CK_PutCurrentSelected
:
1141 put_current_selected ();
1143 case CK_PutCurrentFullSelected
:
1144 midnight_put_panel_path (current_panel
);
1145 put_current_selected ();
1147 case CK_PutCurrentLink
:
1148 put_current_link ();
1150 case CK_PutCurrentTagged
:
1151 put_current_tagged ();
1153 case CK_PutOtherPath
:
1154 if (get_other_type () == view_listing
)
1155 midnight_put_panel_path (other_panel
);
1157 case CK_PutOtherLink
:
1160 case CK_PutOtherTagged
:
1161 put_other_tagged ();
1167 dialog_switch_list ();
1169 #ifdef USE_DIFF_VIEW
1170 case CK_CompareFiles
:
1174 case CK_OptionsDisplayBits
:
1175 display_bits_box ();
1180 #ifdef USE_INTERNAL_EDIT
1181 case CK_EditForceInternal
:
1182 edit_cmd_force_internal ();
1185 case CK_EditExtensionsFile
:
1188 case CK_EditFileHighlightFile
:
1191 case CK_EditUserMenu
:
1192 edit_mc_menu_cmd ();
1194 case CK_LinkSymbolicEdit
:
1195 edit_symlink_cmd ();
1197 case CK_ExternalPanelize
:
1198 external_panelize ();
1203 case CK_ViewFiltered
:
1204 view_filtered_cmd ();
1209 #ifdef ENABLE_VFS_FISH
1210 case CK_ConnectFish
:
1214 #ifdef ENABLE_VFS_FTP
1219 #ifdef ENABLE_VFS_SFTP
1220 case CK_ConnectSftp
:
1224 #ifdef ENABLE_VFS_SMB
1228 #endif /* ENABLE_VFS_SMB */
1236 /* show the history of command line widget */
1237 send_message (cmdline
, NULL
, MSG_ACTION
, CK_History
, NULL
);
1240 if (sender
== WIDGET (the_menubar
))
1241 info_cmd (); /* menu */
1243 info_cmd_no_menu (); /* shortcut or buttonbar */
1245 #ifdef ENABLE_BACKGROUND
1250 case CK_OptionsLayout
:
1253 case CK_OptionsAppearance
:
1260 link_cmd (LINK_HARDLINK
);
1262 case CK_PanelListing
:
1265 #ifdef LISTMODE_EDITOR
1273 case CK_MenuLastSelected
:
1274 menu_last_selected_cmd ();
1279 case CK_OptionsPanel
:
1280 panel_options_box ();
1283 case CK_SelectCodepage
:
1293 case CK_PanelQuickView
:
1294 if (sender
== WIDGET (the_menubar
))
1295 quick_view_cmd (); /* menu */
1297 quick_cmd_no_menu (); /* shortcut or buttonabr */
1305 case CK_LinkSymbolicRelative
:
1306 link_cmd (LINK_SYMLINK_RELATIVE
);
1324 case CK_SelectInvert
:
1325 res
= send_message (current_panel
, midnight_dlg
, MSG_ACTION
, command
, NULL
);
1331 smart_dirsize_cmd ();
1336 case CK_ExtendedKeyMap
:
1340 mc_event_raise (MCEVENT_GROUP_CORE
, "suspend", NULL
);
1345 case CK_LinkSymbolic
:
1346 link_cmd (LINK_SYMLINK_ABSOLUTE
);
1349 toggle_show_hidden ();
1351 case CK_SplitVertHoriz
:
1352 toggle_panels_split ();
1355 panels_split_equal ();
1358 panels_split_more ();
1361 panels_split_less ();
1369 #ifdef ENABLE_VFS_UNDELFS
1375 user_file_menu_cmd ();
1384 /* don't close panels due to SIGINT */
1387 res
= MSG_NOT_HANDLED
;
1393 /* --------------------------------------------------------------------------------------------- */
1396 * Whether the command-line should not respond to key events.
1398 * This is TRUE if a QuickView or TreeView have the focus, as they're going
1399 * to consume some keys and there's no sense in passing to the command-line
1400 * just the leftovers.
1403 is_cmdline_mute (void)
1405 /* When one of panels is other than view_listing,
1406 current_panel points to view_listing panel all time independently of
1407 it's activity. Thus, we can't use get_current_type() here.
1408 current_panel should point to actualy current active panel
1409 independently of it's type. */
1410 return (current_panel
->active
== 0
1411 && (get_other_type () == view_quick
|| get_other_type () == view_tree
));
1414 /* --------------------------------------------------------------------------------------------- */
1417 * Handles the Enter key on the command-line.
1419 * Returns TRUE if non-whitespace was indeed processed.
1422 handle_cmdline_enter (void)
1426 for (i
= 0; cmdline
->buffer
[i
] != '\0' && whitespace (cmdline
->buffer
[i
]); i
++)
1429 if (cmdline
->buffer
[i
] != '\0')
1431 send_message (cmdline
, NULL
, MSG_KEY
, '\n', NULL
);
1435 input_insert (cmdline
, "", FALSE
);
1441 /* --------------------------------------------------------------------------------------------- */
1444 midnight_callback (Widget
* w
, Widget
* sender
, widget_msg_t msg
, int parm
, void *data
)
1457 /* We handle the special case of the output lines */
1458 if (mc_global
.tty
.console_flag
!= '\0' && output_lines
)
1459 show_console_contents (output_start_y
,
1460 LINES
- output_lines
- mc_global
.keybar_visible
-
1461 1, LINES
- mc_global
.keybar_visible
- 1);
1465 /* dlg_set_size() is surplus for this case */
1469 menubar_arrange (the_menubar
);
1473 /* We only need the first idle event to show user menu after start */
1474 widget_idle (w
, FALSE
);
1476 if (boot_current_is_left
)
1477 widget_select (get_panel_widget (0));
1479 widget_select (get_panel_widget (1));
1482 midnight_execute_cmd (NULL
, CK_UserMenu
);
1486 if (ctl_x_map_enabled
)
1488 ctl_x_map_enabled
= FALSE
;
1489 command
= keybind_lookup_keymap_command (main_x_map
, parm
);
1490 if (command
!= CK_IgnoreKey
)
1491 return midnight_execute_cmd (NULL
, command
);
1494 /* FIXME: should handle all menu shortcuts before this point */
1495 if (widget_get_state (WIDGET (the_menubar
), WST_FOCUSED
))
1496 return MSG_NOT_HANDLED
;
1498 if (parm
== '\n' && !is_cmdline_mute ())
1500 if (handle_cmdline_enter ())
1502 /* Else: the panel will handle it. */
1505 if ((!mc_global
.tty
.alternate_plus_minus
1506 || !(mc_global
.tty
.console_flag
!= '\0' || mc_global
.tty
.xterm_flag
)) && !quote
1507 && !current_panel
->searching
)
1509 if (!only_leading_plus_minus
)
1511 /* Special treatement, since the input line will eat them */
1513 return send_message (current_panel
, midnight_dlg
, MSG_ACTION
, CK_Select
, NULL
);
1515 if (parm
== '\\' || parm
== '-')
1516 return send_message (current_panel
, midnight_dlg
, MSG_ACTION
, CK_Unselect
,
1520 return send_message (current_panel
, midnight_dlg
, MSG_ACTION
, CK_SelectInvert
,
1523 else if (!command_prompt
|| cmdline
->buffer
[0] == '\0')
1525 /* Special treatement '+', '-', '\', '*' only when this is
1526 * first char on input line
1529 return send_message (current_panel
, midnight_dlg
, MSG_ACTION
, CK_Select
, NULL
);
1531 if (parm
== '\\' || parm
== '-')
1532 return send_message (current_panel
, midnight_dlg
, MSG_ACTION
, CK_Unselect
,
1536 return send_message (current_panel
, midnight_dlg
, MSG_ACTION
, CK_SelectInvert
,
1540 return MSG_NOT_HANDLED
;
1542 case MSG_HOTKEY_HANDLED
:
1543 if ((get_current_type () == view_listing
) && current_panel
->searching
)
1545 current_panel
->dirty
= 1; /* FIXME: unneeded? */
1546 send_message (current_panel
, NULL
, MSG_ACTION
, CK_SearchStop
, NULL
);
1550 case MSG_UNHANDLED_KEY
:
1552 cb_ret_t v
= MSG_NOT_HANDLED
;
1554 if (ctl_x_map_enabled
)
1556 ctl_x_map_enabled
= FALSE
;
1557 command
= keybind_lookup_keymap_command (main_x_map
, parm
);
1560 command
= keybind_lookup_keymap_command (main_map
, parm
);
1562 if (command
!= CK_IgnoreKey
)
1563 v
= midnight_execute_cmd (NULL
, command
);
1565 if (v
== MSG_NOT_HANDLED
&& command_prompt
&& !is_cmdline_mute ())
1566 v
= send_message (cmdline
, NULL
, MSG_KEY
, parm
, NULL
);
1572 if (!widget_get_state (WIDGET (the_menubar
), WST_FOCUSED
))
1573 update_dirty_panels ();
1577 /* Handle shortcuts, menu, and buttonbar. */
1578 return midnight_execute_cmd (sender
, parm
);
1585 return dlg_default_callback (w
, sender
, msg
, parm
, data
);
1589 /* --------------------------------------------------------------------------------------------- */
1590 /*** public functions ****************************************************************************/
1591 /* --------------------------------------------------------------------------------------------- */
1596 menu_set_name (left_menu
, panels_layout
.horizontal_split
? _("&Above") : _("&Left"));
1597 menu_set_name (right_menu
, panels_layout
.horizontal_split
? _("&Below") : _("&Right"));
1598 menubar_arrange (the_menubar
);
1599 menubar_set_visible (the_menubar
, menubar_visible
);
1602 /* --------------------------------------------------------------------------------------------- */
1605 midnight_set_buttonbar (WButtonBar
* b
)
1607 buttonbar_set_label (b
, 1, Q_ ("ButtonBar|Help"), main_map
, NULL
);
1608 buttonbar_set_label (b
, 2, Q_ ("ButtonBar|Menu"), main_map
, NULL
);
1609 buttonbar_set_label (b
, 3, Q_ ("ButtonBar|View"), main_map
, NULL
);
1610 buttonbar_set_label (b
, 4, Q_ ("ButtonBar|Edit"), main_map
, NULL
);
1611 buttonbar_set_label (b
, 5, Q_ ("ButtonBar|Copy"), main_map
, NULL
);
1612 buttonbar_set_label (b
, 6, Q_ ("ButtonBar|RenMov"), main_map
, NULL
);
1613 buttonbar_set_label (b
, 7, Q_ ("ButtonBar|Mkdir"), main_map
, NULL
);
1614 buttonbar_set_label (b
, 8, Q_ ("ButtonBar|Delete"), main_map
, NULL
);
1615 buttonbar_set_label (b
, 9, Q_ ("ButtonBar|PullDn"), main_map
, NULL
);
1616 buttonbar_set_label (b
, 10, Q_ ("ButtonBar|Quit"), main_map
, NULL
);
1619 /* --------------------------------------------------------------------------------------------- */
1621 * Return a random hint. If force is TRUE, ignore the timeout.
1625 get_random_hint (gboolean force
)
1627 static const guint64 update_period
= 60 * G_USEC_PER_SEC
;
1628 static guint64 tv
= 0;
1630 char *data
, *result
= NULL
, *eop
;
1634 /* Do not change hints more often than one minute */
1635 if (!force
&& !mc_time_elapsed (&tv
, update_period
))
1636 return g_strdup ("");
1638 data
= load_mc_home_file (mc_global
.share_data_dir
, MC_HINT
, NULL
, &len
);
1642 /* get a random entry */
1643 srand ((unsigned int) (tv
/ G_USEC_PER_SEC
));
1644 start
= ((size_t) rand ()) % (len
- 1);
1646 /* Search the start of paragraph */
1647 for (; start
!= 0; start
--)
1648 if (data
[start
] == '\n' && data
[start
+ 1] == '\n')
1654 /* Search the end of paragraph */
1655 for (eop
= data
+ start
; *eop
!= '\0'; eop
++)
1657 if (*eop
== '\n' && *(eop
+ 1) == '\n')
1666 /* hint files are stored in utf-8 */
1667 /* try convert hint file from utf-8 to terminal encoding */
1668 conv
= str_crt_conv_from ("UTF-8");
1669 if (conv
!= INVALID_CONV
)
1673 buffer
= g_string_sized_new (len
- start
);
1674 if (str_convert (conv
, &data
[start
], buffer
) != ESTR_FAILURE
)
1675 result
= g_string_free (buffer
, FALSE
);
1677 g_string_free (buffer
, TRUE
);
1678 str_close_conv (conv
);
1681 result
= g_strndup (data
+ start
, len
- start
);
1688 /* --------------------------------------------------------------------------------------------- */
1690 * Load new hint and display it.
1691 * IF force is not 0, ignore the timeout.
1695 load_hint (gboolean force
)
1699 if (WIDGET (the_hint
)->owner
== NULL
)
1702 if (!mc_global
.message_visible
)
1704 label_set_text (the_hint
, NULL
);
1708 hint
= get_random_hint (force
);
1718 char text
[BUF_SMALL
];
1720 g_snprintf (text
, sizeof (text
), _("GNU Midnight Commander %s\n"), VERSION
);
1725 /* --------------------------------------------------------------------------------------------- */
1730 input_free_completions (cmdline
);
1731 dlg_select_next_widget (midnight_dlg
);
1734 /* --------------------------------------------------------------------------------------------- */
1736 /** Save current stat of directories to avoid reloading the panels
1737 * when no modifications have taken place
1740 save_cwds_stat (void)
1742 if (panels_options
.fast_reload
)
1744 mc_stat (current_panel
->cwd_vpath
, &(current_panel
->dir_stat
));
1745 if (get_other_type () == view_listing
)
1746 mc_stat (other_panel
->cwd_vpath
, &(other_panel
->dir_stat
));
1750 /* --------------------------------------------------------------------------------------------- */
1753 quiet_quit_cmd (void)
1755 print_last_revert
= TRUE
;
1756 return quit_cmd_internal (1);
1759 /* --------------------------------------------------------------------------------------------- */
1761 /** Run the main dialog that occupies the whole screen */
1767 #ifdef USE_INTERNAL_EDIT
1771 midnight_dlg
= dlg_create (FALSE
, 0, 0, 1, 1, WPOS_FULLSCREEN
, FALSE
, dialog_colors
,
1772 midnight_callback
, NULL
, "[main]", NULL
);
1774 /* Check if we were invoked as an editor or file viewer */
1775 if (mc_global
.mc_run_mode
!= MC_RUN_FULL
)
1778 ret
= mc_maybe_editor_or_viewer ();
1782 /* We only need the first idle event to show user menu after start */
1783 widget_idle (WIDGET (midnight_dlg
), TRUE
);
1786 mc_filehighlight
= mc_fhl_new (TRUE
);
1788 create_file_manager ();
1789 (void) dlg_run (midnight_dlg
);
1791 mc_fhl_free (&mc_filehighlight
);
1795 /* dlg_destroy destroys even current_panel->cwd_vpath, so we have to save a copy :) */
1796 if (mc_args__last_wd_file
!= NULL
&& vfs_current_is_local ())
1797 last_wd_string
= g_strdup (vfs_path_as_str (current_panel
->cwd_vpath
));
1799 /* don't handle VFS timestamps for dirs opened in panels */
1800 mc_event_destroy (MCEVENT_GROUP_CORE
, "vfs_timestamp");
1802 dir_list_free_list (&panelized_panel
.list
);
1806 mc_global
.midnight_shutdown
= TRUE
;
1807 dialog_switch_shutdown ();
1809 dlg_destroy (midnight_dlg
);
1810 current_panel
= NULL
;
1812 #ifdef USE_INTERNAL_EDIT
1816 if ((quit
& SUBSHELL_EXIT
) == 0)
1822 /* --------------------------------------------------------------------------------------------- */