2 Main dialog (file panels) of the Midnight Commander
4 Copyright (C) 1994-2020
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/execute.h" /* toggle_subshell */
62 #include "src/setup.h" /* variables */
63 #include "src/learn.h" /* learn_keys() */
64 #include "src/keybind-defaults.h"
65 #include "lib/fileloc.h" /* MC_FILEPOS_FILE */
66 #include "lib/keybind.h"
67 #include "lib/event.h"
70 #include "boxes.h" /* sort_box(), tree_box() */
72 #include "cmd.h" /* commands */
75 #include "command.h" /* cmdline */
76 #include "dir.h" /* dir_list_clean() */
82 #ifdef USE_INTERNAL_EDIT
83 #include "src/editor/edit.h"
87 #include "src/diffviewer/ydiff.h"
90 #include "src/consaver/cons.saver.h" /* show_console_contents */
91 #include "src/file_history.h" /* show_file_history() */
95 /*** global variables ****************************************************************************/
97 /* When the modes are active, left_panel, right_panel and tree_panel */
98 /* point to a proper data structure. You should check with the functions */
99 /* get_current_type and get_other_type the types of the panels before using */
100 /* this pointer variables */
102 /* The structures for the panels */
103 WPanel
*left_panel
= NULL
;
104 WPanel
*right_panel
= NULL
;
105 /* Pointer to the selected and unselected panel */
106 WPanel
*current_panel
= NULL
;
109 WMenuBar
*the_menubar
= NULL
;
110 /* The widget where we draw the prompt */
118 const char *mc_prompt
= NULL
;
120 /*** file scope macro definitions ****************************************************************/
124 * Don't restrict the output on the screen manager level,
125 * the translation tables take care of it.
127 #endif /* !HAVE_CHARSET */
129 /*** file scope type declarations ****************************************************************/
131 /*** file scope variables ************************************************************************/
133 static menu_t
*left_menu
, *right_menu
;
135 static gboolean ctl_x_map_enabled
= FALSE
;
137 /*** file scope functions ************************************************************************/
139 /** Stop MC main dialog and the current dialog if it exists.
140 * Needed to provide fast exit from MC viewer or editor on shell exit */
144 dlg_stop (midnight_dlg
);
147 dlg_stop (DIALOG (top_dlg
->data
));
150 /* --------------------------------------------------------------------------------------------- */
157 sel_dir
= tree_box (selection (current_panel
)->fname
);
160 vfs_path_t
*sel_vdir
;
162 sel_vdir
= vfs_path_from_str (sel_dir
);
163 do_cd (sel_vdir
, cd_exact
);
164 vfs_path_free (sel_vdir
);
169 /* --------------------------------------------------------------------------------------------- */
171 #ifdef LISTMODE_EDITOR
177 if (get_current_type () != view_listing
)
180 newmode
= listmode_edit (current_panel
->user_format
);
184 g_free (current_panel
->user_format
);
185 current_panel
->list_format
= list_user
;
186 current_panel
->user_format
= newmode
;
187 set_panel_formats (current_panel
);
191 #endif /* LISTMODE_EDITOR */
193 /* --------------------------------------------------------------------------------------------- */
196 create_panel_menu (void)
198 GList
*entries
= NULL
;
200 entries
= g_list_prepend (entries
, menu_entry_create (_("File listin&g"), CK_PanelListing
));
201 entries
= g_list_prepend (entries
, menu_entry_create (_("&Quick view"), CK_PanelQuickView
));
202 entries
= g_list_prepend (entries
, menu_entry_create (_("&Info"), CK_PanelInfo
));
203 entries
= g_list_prepend (entries
, menu_entry_create (_("&Tree"), CK_PanelTree
));
204 entries
= g_list_prepend (entries
, menu_separator_create ());
206 g_list_prepend (entries
,
207 menu_entry_create (_("&Listing format..."), CK_SetupListingFormat
));
208 entries
= g_list_prepend (entries
, menu_entry_create (_("&Sort order..."), CK_Sort
));
209 entries
= g_list_prepend (entries
, menu_entry_create (_("&Filter..."), CK_Filter
));
211 entries
= g_list_prepend (entries
, menu_entry_create (_("&Encoding..."), CK_SelectCodepage
));
213 entries
= g_list_prepend (entries
, menu_separator_create ());
214 #ifdef ENABLE_VFS_FTP
215 entries
= g_list_prepend (entries
, menu_entry_create (_("FT&P link..."), CK_ConnectFtp
));
217 #ifdef ENABLE_VFS_FISH
218 entries
= g_list_prepend (entries
, menu_entry_create (_("S&hell link..."), CK_ConnectFish
));
220 #ifdef ENABLE_VFS_SFTP
221 entries
= g_list_prepend (entries
, menu_entry_create (_("S&FTP link..."), CK_ConnectSftp
));
223 #ifdef ENABLE_VFS_SMB
224 entries
= g_list_prepend (entries
, menu_entry_create (_("SM&B link..."), CK_ConnectSmb
));
226 entries
= g_list_prepend (entries
, menu_entry_create (_("Paneli&ze"), CK_Panelize
));
227 entries
= g_list_prepend (entries
, menu_separator_create ());
228 entries
= g_list_prepend (entries
, menu_entry_create (_("&Rescan"), CK_Reread
));
230 return g_list_reverse (entries
);
233 /* --------------------------------------------------------------------------------------------- */
236 create_file_menu (void)
238 GList
*entries
= NULL
;
240 entries
= g_list_prepend (entries
, menu_entry_create (_("&View"), CK_View
));
241 entries
= g_list_prepend (entries
, menu_entry_create (_("Vie&w file..."), CK_ViewFile
));
242 entries
= g_list_prepend (entries
, menu_entry_create (_("&Filtered view"), CK_ViewFiltered
));
243 entries
= g_list_prepend (entries
, menu_entry_create (_("&Edit"), CK_Edit
));
244 entries
= g_list_prepend (entries
, menu_entry_create (_("&Copy"), CK_Copy
));
245 entries
= g_list_prepend (entries
, menu_entry_create (_("C&hmod"), CK_ChangeMode
));
246 entries
= g_list_prepend (entries
, menu_entry_create (_("&Link"), CK_Link
));
247 entries
= g_list_prepend (entries
, menu_entry_create (_("&Symlink"), CK_LinkSymbolic
));
249 g_list_prepend (entries
,
250 menu_entry_create (_("Relative symlin&k"), CK_LinkSymbolicRelative
));
251 entries
= g_list_prepend (entries
, menu_entry_create (_("Edit s&ymlink"), CK_LinkSymbolicEdit
));
252 entries
= g_list_prepend (entries
, menu_entry_create (_("Ch&own"), CK_ChangeOwn
));
254 g_list_prepend (entries
, menu_entry_create (_("&Advanced chown"), CK_ChangeOwnAdvanced
));
255 entries
= g_list_prepend (entries
, menu_entry_create (_("&Rename/Move"), CK_Move
));
256 entries
= g_list_prepend (entries
, menu_entry_create (_("&Mkdir"), CK_MakeDir
));
257 entries
= g_list_prepend (entries
, menu_entry_create (_("&Delete"), CK_Delete
));
258 entries
= g_list_prepend (entries
, menu_entry_create (_("&Quick cd"), CK_CdQuick
));
259 entries
= g_list_prepend (entries
, menu_separator_create ());
260 entries
= g_list_prepend (entries
, menu_entry_create (_("Select &group"), CK_Select
));
261 entries
= g_list_prepend (entries
, menu_entry_create (_("U&nselect group"), CK_Unselect
));
262 entries
= g_list_prepend (entries
, menu_entry_create (_("&Invert selection"), CK_SelectInvert
));
263 entries
= g_list_prepend (entries
, menu_separator_create ());
264 entries
= g_list_prepend (entries
, menu_entry_create (_("E&xit"), CK_Quit
));
266 return g_list_reverse (entries
);
269 /* --------------------------------------------------------------------------------------------- */
272 create_command_menu (void)
274 /* I know, I'm lazy, but the tree widget when it's not running
275 * as a panel still has some problems, I have not yet finished
276 * the WTree widget port, sorry.
278 GList
*entries
= NULL
;
280 entries
= g_list_prepend (entries
, menu_entry_create (_("&User menu"), CK_UserMenu
));
281 entries
= g_list_prepend (entries
, menu_entry_create (_("&Directory tree"), CK_Tree
));
282 entries
= g_list_prepend (entries
, menu_entry_create (_("&Find file"), CK_Find
));
283 entries
= g_list_prepend (entries
, menu_entry_create (_("S&wap panels"), CK_Swap
));
284 entries
= g_list_prepend (entries
, menu_entry_create (_("Switch &panels on/off"), CK_Shell
));
286 g_list_prepend (entries
, menu_entry_create (_("&Compare directories"), CK_CompareDirs
));
288 entries
= g_list_prepend (entries
, menu_entry_create (_("C&ompare files"), CK_CompareFiles
));
291 g_list_prepend (entries
, menu_entry_create (_("E&xternal panelize"), CK_ExternalPanelize
));
292 entries
= g_list_prepend (entries
, menu_entry_create (_("Show directory s&izes"), CK_DirSize
));
293 entries
= g_list_prepend (entries
, menu_separator_create ());
294 entries
= g_list_prepend (entries
, menu_entry_create (_("Command &history"), CK_History
));
296 g_list_prepend (entries
,
297 menu_entry_create (_("Viewed/edited files hi&story"),
298 CK_EditorViewerHistory
));
299 entries
= g_list_prepend (entries
, menu_entry_create (_("Di&rectory hotlist"), CK_HotList
));
301 entries
= g_list_prepend (entries
, menu_entry_create (_("&Active VFS list"), CK_VfsList
));
303 #ifdef ENABLE_BACKGROUND
304 entries
= g_list_prepend (entries
, menu_entry_create (_("&Background jobs"), CK_Jobs
));
306 entries
= g_list_prepend (entries
, menu_entry_create (_("Screen lis&t"), CK_ScreenList
));
307 entries
= g_list_prepend (entries
, menu_separator_create ());
308 #ifdef ENABLE_VFS_UNDELFS
310 g_list_prepend (entries
,
311 menu_entry_create (_("&Undelete files (ext2fs only)"), CK_Undelete
));
313 #ifdef LISTMODE_EDITOR
314 entries
= g_list_prepend (entries
, menu_entry_create (_("&Listing format edit"), CK_ListMode
));
316 #if defined (ENABLE_VFS_UNDELFS) || defined (LISTMODE_EDITOR)
317 entries
= g_list_prepend (entries
, menu_separator_create ());
320 g_list_prepend (entries
,
321 menu_entry_create (_("Edit &extension file"), CK_EditExtensionsFile
));
322 entries
= g_list_prepend (entries
, menu_entry_create (_("Edit &menu file"), CK_EditUserMenu
));
324 g_list_prepend (entries
,
325 menu_entry_create (_("Edit hi&ghlighting group file"),
326 CK_EditFileHighlightFile
));
328 return g_list_reverse (entries
);
331 /* --------------------------------------------------------------------------------------------- */
334 create_options_menu (void)
336 GList
*entries
= NULL
;
338 entries
= g_list_prepend (entries
, menu_entry_create (_("&Configuration..."), CK_Options
));
339 entries
= g_list_prepend (entries
, menu_entry_create (_("&Layout..."), CK_OptionsLayout
));
340 entries
= g_list_prepend (entries
, menu_entry_create (_("&Panel options..."), CK_OptionsPanel
));
342 g_list_prepend (entries
, menu_entry_create (_("C&onfirmation..."), CK_OptionsConfirm
));
344 g_list_prepend (entries
, menu_entry_create (_("&Appearance..."), CK_OptionsAppearance
));
346 g_list_prepend (entries
, menu_entry_create (_("&Display bits..."), CK_OptionsDisplayBits
));
347 entries
= g_list_prepend (entries
, menu_entry_create (_("Learn &keys..."), CK_LearnKeys
));
349 entries
= g_list_prepend (entries
, menu_entry_create (_("&Virtual FS..."), CK_OptionsVfs
));
351 entries
= g_list_prepend (entries
, menu_separator_create ());
352 entries
= g_list_prepend (entries
, menu_entry_create (_("&Save setup"), CK_SaveSetup
));
354 return g_list_reverse (entries
);
357 /* --------------------------------------------------------------------------------------------- */
362 left_menu
= create_menu ("", create_panel_menu (), "[Left and Right Menus]");
363 menubar_add_menu (the_menubar
, left_menu
);
364 menubar_add_menu (the_menubar
, create_menu (_("&File"), create_file_menu (), "[File Menu]"));
365 menubar_add_menu (the_menubar
,
366 create_menu (_("&Command"), create_command_menu (), "[Command Menu]"));
367 menubar_add_menu (the_menubar
,
368 create_menu (_("&Options"), create_options_menu (), "[Options Menu]"));
369 right_menu
= create_menu ("", create_panel_menu (), "[Left and Right Menus]");
370 menubar_add_menu (the_menubar
, right_menu
);
374 /* --------------------------------------------------------------------------------------------- */
377 menu_last_selected_cmd (void)
379 menubar_activate (the_menubar
, drop_menus
, -1);
382 /* --------------------------------------------------------------------------------------------- */
389 if ((get_current_index () == 0) == (current_panel
->active
!= 0))
392 selected
= g_list_length (the_menubar
->menu
) - 1;
394 menubar_activate (the_menubar
, drop_menus
, selected
);
397 /* --------------------------------------------------------------------------------------------- */
403 const panel_field_t
*sort_order
;
405 if (!SELECTED_IS_PANEL
)
409 sort_order
= sort_box (&p
->sort_info
, p
->sort_field
);
410 panel_set_sort_order (p
, sort_order
);
413 /* --------------------------------------------------------------------------------------------- */
416 midnight_get_shortcut (long command
)
419 const char *shortcut
= NULL
;
421 shortcut
= keybind_lookup_keymap_shortcut (main_map
, command
);
422 if (shortcut
!= NULL
)
423 return g_strdup (shortcut
);
425 shortcut
= keybind_lookup_keymap_shortcut (panel_map
, command
);
426 if (shortcut
!= NULL
)
427 return g_strdup (shortcut
);
429 ext_map
= keybind_lookup_keymap_shortcut (main_map
, CK_ExtendedKeyMap
);
431 shortcut
= keybind_lookup_keymap_shortcut (main_x_map
, command
);
432 if (shortcut
!= NULL
)
433 return g_strdup_printf ("%s %s", ext_map
, shortcut
);
438 /* --------------------------------------------------------------------------------------------- */
441 midnight_get_title (const WDialog
* h
, size_t len
)
449 title_path_prepare (&path
, &login
);
451 p
= g_strdup_printf ("%s [%s]:%s", _("Panels:"), login
, path
);
454 path
= g_strdup (str_trunc (p
, len
- 4));
460 /* --------------------------------------------------------------------------------------------- */
463 toggle_panels_split (void)
465 panels_layout
.horizontal_split
= !panels_layout
.horizontal_split
;
470 /* --------------------------------------------------------------------------------------------- */
475 check_panel_timestamp (const WPanel
* panel
, panel_view_mode_t mode
, struct vfs_class
*vclass
,
478 if (mode
== view_listing
)
480 const vfs_path_element_t
*path_element
;
482 path_element
= vfs_path_get_by_index (panel
->cwd_vpath
, -1);
484 if (path_element
->class != vclass
)
487 if (vfs_getid (panel
->cwd_vpath
) != id
)
493 /* --------------------------------------------------------------------------------------------- */
497 check_current_panel_timestamp (const gchar
* event_group_name
, const gchar
* event_name
,
498 gpointer init_data
, gpointer data
)
500 ev_vfs_stamp_create_t
*event_data
= (ev_vfs_stamp_create_t
*) data
;
502 (void) event_group_name
;
507 check_panel_timestamp (current_panel
, get_current_type (), event_data
->vclass
,
509 return !event_data
->ret
;
512 /* --------------------------------------------------------------------------------------------- */
516 check_other_panel_timestamp (const gchar
* event_group_name
, const gchar
* event_name
,
517 gpointer init_data
, gpointer data
)
519 ev_vfs_stamp_create_t
*event_data
= (ev_vfs_stamp_create_t
*) data
;
521 (void) event_group_name
;
526 check_panel_timestamp (other_panel
, get_other_type (), event_data
->vclass
, event_data
->id
);
527 return !event_data
->ret
;
529 #endif /* ENABLE_VFS */
531 /* --------------------------------------------------------------------------------------------- */
535 print_vfs_message (const gchar
* event_group_name
, const gchar
* event_name
,
536 gpointer init_data
, gpointer data
)
538 ev_vfs_print_message_t
*event_data
= (ev_vfs_print_message_t
*) data
;
540 (void) event_group_name
;
544 if (mc_global
.midnight_shutdown
)
547 if (!mc_global
.message_visible
|| the_hint
== NULL
|| WIDGET (the_hint
)->owner
== NULL
)
551 if (!nice_rotating_dash
|| (ok_to_refresh
<= 0))
554 /* Preserve current cursor position */
555 tty_getyx (&row
, &col
);
558 tty_setcolor (NORMAL_COLOR
);
559 tty_print_string (str_fit_to_term (event_data
->msg
, COLS
- 1, J_LEFT
));
561 /* Restore cursor position */
562 tty_gotoyx (row
, col
);
567 if (mc_global
.message_visible
)
568 set_hintbar (event_data
->msg
);
571 MC_PTR_FREE (event_data
->msg
);
575 /* --------------------------------------------------------------------------------------------- */
580 int current_index
, other_index
;
581 panel_view_mode_t current_mode
, other_mode
;
582 char *current_dir
, *other_dir
;
583 vfs_path_t
*original_dir
;
586 * Following cases from command line are possible:
587 * 'mc' (no arguments): mc_run_param0 == NULL, mc_run_param1 == NULL
588 * active panel uses current directory
589 * passive panel uses "other_dir" from panels.ini
591 * 'mc dir1 dir2' (two arguments): mc_run_param0 != NULL, mc_run_param1 != NULL
592 * active panel uses mc_run_param0
593 * passive panel uses mc_run_param1
595 * 'mc dir1' (single argument): mc_run_param0 != NULL, mc_run_param1 == NULL
596 * active panel uses mc_run_param0
597 * passive panel uses "other_dir" from panels.ini
600 /* Set up panel directories */
601 if (boot_current_is_left
)
603 /* left panel is active */
606 current_mode
= startup_left_mode
;
607 other_mode
= startup_right_mode
;
609 if (mc_run_param0
== NULL
&& mc_run_param1
== NULL
)
612 current_dir
= NULL
; /* assume current dir */
613 other_dir
= saved_other_dir
; /* from ini */
615 else if (mc_run_param0
!= NULL
&& mc_run_param1
!= NULL
)
618 current_dir
= (char *) mc_run_param0
;
619 other_dir
= mc_run_param1
;
621 else /* mc_run_param0 != NULL && mc_run_param1 == NULL */
624 current_dir
= (char *) mc_run_param0
;
625 other_dir
= saved_other_dir
; /* from ini */
630 /* right panel is active */
633 current_mode
= startup_right_mode
;
634 other_mode
= startup_left_mode
;
636 if (mc_run_param0
== NULL
&& mc_run_param1
== NULL
)
639 current_dir
= NULL
; /* assume current dir */
640 other_dir
= saved_other_dir
; /* from ini */
642 else if (mc_run_param0
!= NULL
&& mc_run_param1
!= NULL
)
645 current_dir
= (char *) mc_run_param0
;
646 other_dir
= mc_run_param1
;
648 else /* mc_run_param0 != NULL && mc_run_param1 == NULL */
651 current_dir
= (char *) mc_run_param0
;
652 other_dir
= saved_other_dir
; /* from ini */
656 /* 1. Get current dir */
657 original_dir
= vfs_path_clone (vfs_get_raw_current_dir ());
659 /* 2. Create passive panel */
660 if (other_dir
!= NULL
)
664 if (g_path_is_absolute (other_dir
))
665 vpath
= vfs_path_from_str (other_dir
);
667 vpath
= vfs_path_append_new (original_dir
, other_dir
, (char *) NULL
);
669 vfs_path_free (vpath
);
671 create_panel (other_index
, other_mode
);
673 /* 3. Create active panel */
674 if (current_dir
== NULL
)
675 mc_chdir (original_dir
);
680 if (g_path_is_absolute (current_dir
))
681 vpath
= vfs_path_from_str (current_dir
);
683 vpath
= vfs_path_append_new (original_dir
, current_dir
, (char *) NULL
);
685 vfs_path_free (vpath
);
687 create_panel (current_index
, current_mode
);
689 if (startup_left_mode
== view_listing
)
690 current_panel
= left_panel
;
691 else if (right_panel
!= NULL
)
692 current_panel
= right_panel
;
694 current_panel
= left_panel
;
696 vfs_path_free (original_dir
);
699 mc_event_add (MCEVENT_GROUP_CORE
, "vfs_timestamp", check_other_panel_timestamp
, NULL
, NULL
);
700 mc_event_add (MCEVENT_GROUP_CORE
, "vfs_timestamp", check_current_panel_timestamp
, NULL
, NULL
);
701 #endif /* ENABLE_VFS */
703 mc_event_add (MCEVENT_GROUP_CORE
, "vfs_print_message", print_vfs_message
, NULL
, NULL
);
706 /* --------------------------------------------------------------------------------------------- */
709 midnight_put_panel_path (WPanel
* panel
)
711 vfs_path_t
*cwd_vpath
;
712 const char *cwd_vpath_str
;
718 cwd_vpath
= remove_encoding_from_path (panel
->cwd_vpath
);
720 cwd_vpath
= vfs_path_clone (panel
->cwd_vpath
);
723 cwd_vpath_str
= vfs_path_as_str (cwd_vpath
);
725 command_insert (cmdline
, cwd_vpath_str
, FALSE
);
727 if (!IS_PATH_SEP (cwd_vpath_str
[strlen (cwd_vpath_str
) - 1]))
728 command_insert (cmdline
, PATH_SEP_STR
, FALSE
);
730 vfs_path_free (cwd_vpath
);
733 /* --------------------------------------------------------------------------------------------- */
736 put_link (WPanel
* panel
)
740 if (S_ISLNK (selection (panel
)->st
.st_mode
))
742 char buffer
[MC_MAXPATHLEN
];
746 vpath
= vfs_path_append_new (panel
->cwd_vpath
, selection (panel
)->fname
, (char *) NULL
);
747 i
= mc_readlink (vpath
, buffer
, sizeof (buffer
) - 1);
748 vfs_path_free (vpath
);
753 command_insert (cmdline
, buffer
, TRUE
);
758 /* --------------------------------------------------------------------------------------------- */
761 put_current_link (void)
763 put_link (current_panel
);
766 /* --------------------------------------------------------------------------------------------- */
769 put_other_link (void)
771 if (get_other_type () == view_listing
)
772 put_link (other_panel
);
775 /* --------------------------------------------------------------------------------------------- */
777 /** Insert the selected file name into the input line */
779 put_current_selected (void)
786 if (get_current_type () == view_tree
)
789 const vfs_path_t
*selected_name
;
791 tree
= (WTree
*) get_panel_widget (get_current_index ());
792 selected_name
= tree_selected_name (tree
);
793 tmp
= vfs_path_as_str (selected_name
);
796 tmp
= selection (current_panel
)->fname
;
798 command_insert (cmdline
, tmp
, TRUE
);
801 /* --------------------------------------------------------------------------------------------- */
804 put_tagged (WPanel
* panel
)
808 input_disable_update (cmdline
);
813 for (i
= 0; i
< panel
->dir
.len
; i
++)
815 if (panel
->dir
.list
[i
].f
.marked
)
816 command_insert (cmdline
, panel
->dir
.list
[i
].fname
, TRUE
);
821 command_insert (cmdline
, panel
->dir
.list
[panel
->selected
].fname
, TRUE
);
823 input_enable_update (cmdline
);
826 /* --------------------------------------------------------------------------------------------- */
829 put_current_tagged (void)
831 put_tagged (current_panel
);
834 /* --------------------------------------------------------------------------------------------- */
837 put_other_tagged (void)
839 if (get_other_type () == view_listing
)
840 put_tagged (other_panel
);
843 /* --------------------------------------------------------------------------------------------- */
848 ctl_x_map_enabled
= TRUE
;
851 /* --------------------------------------------------------------------------------------------- */
858 tty_display_8bit (TRUE
);
860 tty_display_8bit (mc_global
.full_eight_bits
);
861 #endif /* HAVE_CHARSET */
863 #else /* HAVE_SLANG */
866 tty_display_8bit (TRUE
);
868 tty_display_8bit (mc_global
.eight_bit_clean
);
869 #endif /* HAVE_CHARSET */
870 #endif /* HAVE_SLANG */
872 #ifdef ENABLE_SUBSHELL
873 if (mc_global
.tty
.use_subshell
)
874 add_select_channel (mc_global
.tty
.subshell_pty
, load_prompt
, NULL
);
875 #endif /* !ENABLE_SUBSHELL */
877 if ((tty_baudrate () < 9600) || mc_global
.tty
.slow_terminal
)
881 /* --------------------------------------------------------------------------------------------- */
884 setup_dummy_mc (void)
892 vpath
= vfs_path_from_str (d
);
893 ret
= mc_chdir (vpath
);
895 vfs_path_free (vpath
);
899 /* --------------------------------------------------------------------------------------------- */
906 * We sync the profiles since the hotlist may have changed, while
907 * we only change the setup data if we have the auto save feature set
910 save_setup (auto_save_setup
, panels_options
.auto_save_setup
);
912 vfs_stamp_path (vfs_get_raw_current_dir ());
915 /* --------------------------------------------------------------------------------------------- */
918 create_file_manager (void)
920 WGroup
*g
= GROUP (midnight_dlg
);
922 midnight_dlg
->get_shortcut
= midnight_get_shortcut
;
923 midnight_dlg
->get_title
= midnight_get_title
;
924 /* allow rebind tab */
925 widget_want_tab (WIDGET (midnight_dlg
), TRUE
);
927 the_menubar
= menubar_new (NULL
, menubar_visible
);
928 group_add_widget (g
, the_menubar
);
932 group_add_widget (g
, get_panel_widget (0));
933 group_add_widget (g
, get_panel_widget (1));
935 the_hint
= label_new (0, 0, 0);
936 the_hint
->transparent
= TRUE
;
937 the_hint
->auto_adjust_cols
= 0;
938 WIDGET (the_hint
)->cols
= COLS
;
939 group_add_widget (g
, the_hint
);
941 cmdline
= command_new (0, 0, 0);
942 group_add_widget (g
, cmdline
);
944 the_prompt
= label_new (0, 0, mc_prompt
);
945 the_prompt
->transparent
= TRUE
;
946 group_add_widget (g
, the_prompt
);
948 the_bar
= buttonbar_new (mc_global
.keybar_visible
);
949 group_add_widget (g
, the_bar
);
950 midnight_set_buttonbar (the_bar
);
953 /* --------------------------------------------------------------------------------------------- */
955 /** result must be free'd (I think this should go in util.c) */
957 prepend_cwd_on_local (const char *filename
)
961 vpath
= vfs_path_from_str (filename
);
962 if (!vfs_file_is_local (vpath
) || g_path_is_absolute (filename
))
965 vfs_path_free (vpath
);
967 return vfs_path_append_new (vfs_get_raw_current_dir (), filename
, (char *) NULL
);
970 /* --------------------------------------------------------------------------------------------- */
972 /** Invoke the internal view/edit routine with:
973 * the default processing and forcing the internal viewer/editor
976 mc_maybe_editor_or_viewer (void)
980 switch (mc_global
.mc_run_mode
)
982 #ifdef USE_INTERNAL_EDIT
984 ret
= edit_files ((GList
*) mc_run_param0
);
986 #endif /* USE_INTERNAL_EDIT */
989 vfs_path_t
*vpath
= NULL
;
991 if (mc_run_param0
!= NULL
&& *(char *) mc_run_param0
!= '\0')
992 vpath
= prepend_cwd_on_local ((char *) mc_run_param0
);
994 ret
= view_file (vpath
, FALSE
, TRUE
);
995 vfs_path_free (vpath
);
999 case MC_RUN_DIFFVIEWER
:
1000 ret
= dview_diff_cmd (mc_run_param0
, mc_run_param1
);
1002 #endif /* USE_DIFF_VIEW */
1010 /* --------------------------------------------------------------------------------------------- */
1013 show_editor_viewer_history (void)
1018 s
= show_file_history (WIDGET (midnight_dlg
), &act
);
1021 vfs_path_t
*s_vpath
;
1026 s_vpath
= vfs_path_from_str (s
);
1027 edit_file_at_line (s_vpath
, use_internal_edit
, 0);
1031 s_vpath
= vfs_path_from_str (s
);
1032 view_file (s_vpath
, use_internal_view
, 0);
1039 d
= g_path_get_dirname (s
);
1040 s_vpath
= vfs_path_from_str (d
);
1041 do_cd (s_vpath
, cd_exact
);
1042 try_to_select (current_panel
, s
);
1048 vfs_path_free (s_vpath
);
1052 /* --------------------------------------------------------------------------------------------- */
1055 quit_cmd_internal (int quiet
)
1060 n
= dialog_switch_num () - 1;
1063 char msg
[BUF_MEDIUM
];
1065 g_snprintf (msg
, sizeof (msg
),
1066 ngettext ("You have %zu opened screen. Quit anyway?",
1067 "You have %zu opened screens. Quit anyway?", n
), n
);
1069 if (query_dialog (_("The Midnight Commander"), msg
, D_NORMAL
, 2, _("&Yes"), _("&No")) != 0)
1073 else if (quiet
|| !confirm_exit
)
1075 else if (query_dialog (_("The Midnight Commander"),
1076 _("Do you really want to quit the Midnight Commander?"),
1077 D_NORMAL
, 2, _("&Yes"), _("&No")) == 0)
1082 #ifdef ENABLE_SUBSHELL
1083 if (!mc_global
.tty
.use_subshell
)
1085 else if ((q
= exit_subshell ()? 1 : 0) != 0)
1095 /* --------------------------------------------------------------------------------------------- */
1100 return quit_cmd_internal (0);
1103 /* --------------------------------------------------------------------------------------------- */
1106 * Repaint the contents of the panels without frames. To schedule panel
1107 * for repainting, set panel->dirty to 1. There are many reasons why
1108 * the panels need to be repainted, and this is a costly operation, so
1109 * it's done once per event.
1113 update_dirty_panels (void)
1115 if (get_current_type () == view_listing
&& current_panel
->dirty
)
1116 widget_draw (WIDGET (current_panel
));
1118 if (get_other_type () == view_listing
&& other_panel
->dirty
)
1119 widget_draw (WIDGET (other_panel
));
1122 /* --------------------------------------------------------------------------------------------- */
1125 toggle_show_hidden (void)
1127 panels_options
.show_dot_files
= !panels_options
.show_dot_files
;
1128 update_panels (UP_RELOAD
, UP_KEEPSEL
);
1129 /* redraw panels forced */
1130 update_dirty_panels ();
1133 /* --------------------------------------------------------------------------------------------- */
1136 midnight_execute_cmd (Widget
* sender
, long command
)
1138 cb_ret_t res
= MSG_HANDLED
;
1142 /* stop quick search before executing any command */
1143 send_message (current_panel
, NULL
, MSG_ACTION
, CK_SearchStop
, NULL
);
1147 case CK_ChangePanel
:
1153 case CK_SetupListingFormat
:
1154 setup_listing_format_cmd ();
1162 case CK_ChangeOwnAdvanced
:
1163 advanced_chown_cmd ();
1165 case CK_CompareDirs
:
1166 compare_dirs_cmd ();
1173 configure_vfs_box ();
1176 case CK_OptionsConfirm
:
1182 case CK_PutCurrentPath
:
1183 midnight_put_panel_path (current_panel
);
1185 case CK_PutCurrentSelected
:
1186 put_current_selected ();
1188 case CK_PutCurrentFullSelected
:
1189 midnight_put_panel_path (current_panel
);
1190 put_current_selected ();
1192 case CK_PutCurrentLink
:
1193 put_current_link ();
1195 case CK_PutCurrentTagged
:
1196 put_current_tagged ();
1198 case CK_PutOtherPath
:
1199 if (get_other_type () == view_listing
)
1200 midnight_put_panel_path (other_panel
);
1202 case CK_PutOtherLink
:
1205 case CK_PutOtherTagged
:
1206 put_other_tagged ();
1212 dialog_switch_list ();
1214 #ifdef USE_DIFF_VIEW
1215 case CK_CompareFiles
:
1219 case CK_OptionsDisplayBits
:
1220 display_bits_box ();
1225 #ifdef USE_INTERNAL_EDIT
1226 case CK_EditForceInternal
:
1227 edit_cmd_force_internal ();
1230 case CK_EditExtensionsFile
:
1233 case CK_EditFileHighlightFile
:
1236 case CK_EditUserMenu
:
1237 edit_mc_menu_cmd ();
1239 case CK_LinkSymbolicEdit
:
1240 edit_symlink_cmd ();
1242 case CK_ExternalPanelize
:
1243 external_panelize ();
1248 case CK_ViewFiltered
:
1249 view_filtered_cmd ();
1254 #ifdef ENABLE_VFS_FISH
1255 case CK_ConnectFish
:
1259 #ifdef ENABLE_VFS_FTP
1264 #ifdef ENABLE_VFS_SFTP
1265 case CK_ConnectSftp
:
1269 #ifdef ENABLE_VFS_SMB
1273 #endif /* ENABLE_VFS_SMB */
1281 /* show the history of command line widget */
1282 send_message (cmdline
, NULL
, MSG_ACTION
, CK_History
, NULL
);
1285 if (sender
== WIDGET (the_menubar
))
1286 info_cmd (); /* menu */
1288 info_cmd_no_menu (); /* shortcut or buttonbar */
1290 #ifdef ENABLE_BACKGROUND
1295 case CK_OptionsLayout
:
1298 case CK_OptionsAppearance
:
1305 link_cmd (LINK_HARDLINK
);
1307 case CK_PanelListing
:
1310 #ifdef LISTMODE_EDITOR
1318 case CK_MenuLastSelected
:
1319 menu_last_selected_cmd ();
1324 case CK_OptionsPanel
:
1325 panel_options_box ();
1328 case CK_SelectCodepage
:
1338 case CK_PanelQuickView
:
1339 if (sender
== WIDGET (the_menubar
))
1340 quick_view_cmd (); /* menu */
1342 quick_cmd_no_menu (); /* shortcut or buttonabr */
1350 case CK_LinkSymbolicRelative
:
1351 link_cmd (LINK_SYMLINK_RELATIVE
);
1369 case CK_SelectInvert
:
1370 res
= send_message (current_panel
, midnight_dlg
, MSG_ACTION
, command
, NULL
);
1376 smart_dirsize_cmd ();
1381 case CK_ExtendedKeyMap
:
1385 mc_event_raise (MCEVENT_GROUP_CORE
, "suspend", NULL
);
1390 case CK_LinkSymbolic
:
1391 link_cmd (LINK_SYMLINK_ABSOLUTE
);
1394 toggle_show_hidden ();
1396 case CK_SplitVertHoriz
:
1397 toggle_panels_split ();
1400 panels_split_equal ();
1403 panels_split_more ();
1406 panels_split_less ();
1414 #ifdef ENABLE_VFS_UNDELFS
1420 user_file_menu_cmd ();
1428 case CK_EditorViewerHistory
:
1429 show_editor_viewer_history ();
1432 /* don't close panels due to SIGINT */
1435 res
= MSG_NOT_HANDLED
;
1441 /* --------------------------------------------------------------------------------------------- */
1444 * Whether the command-line should not respond to key events.
1446 * This is TRUE if a QuickView or TreeView have the focus, as they're going
1447 * to consume some keys and there's no sense in passing to the command-line
1448 * just the leftovers.
1451 is_cmdline_mute (void)
1453 /* When one of panels is other than view_listing,
1454 current_panel points to view_listing panel all time independently of
1455 it's activity. Thus, we can't use get_current_type() here.
1456 current_panel should point to actualy current active panel
1457 independently of it's type. */
1458 return (current_panel
->active
== 0
1459 && (get_other_type () == view_quick
|| get_other_type () == view_tree
));
1462 /* --------------------------------------------------------------------------------------------- */
1465 * Handles the Enter key on the command-line.
1467 * Returns TRUE if non-whitespace was indeed processed.
1470 handle_cmdline_enter (void)
1474 for (i
= 0; cmdline
->buffer
[i
] != '\0' && whitespace (cmdline
->buffer
[i
]); i
++)
1477 if (cmdline
->buffer
[i
] != '\0')
1479 send_message (cmdline
, NULL
, MSG_KEY
, '\n', NULL
);
1483 input_insert (cmdline
, "", FALSE
);
1489 /* --------------------------------------------------------------------------------------------- */
1492 midnight_callback (Widget
* w
, Widget
* sender
, widget_msg_t msg
, int parm
, void *data
)
1505 /* We handle the special case of the output lines */
1506 if (mc_global
.tty
.console_flag
!= '\0' && output_lines
!= 0)
1508 unsigned char end_line
;
1510 end_line
= LINES
- (mc_global
.keybar_visible
? 1 : 0) - 1;
1511 show_console_contents (output_start_y
, end_line
- output_lines
, end_line
);
1516 widget_adjust_position (w
->pos_flags
, &w
->y
, &w
->x
, &w
->lines
, &w
->cols
);
1518 menubar_arrange (the_menubar
);
1522 /* We only need the first idle event to show user menu after start */
1523 widget_idle (w
, FALSE
);
1525 if (boot_current_is_left
)
1526 widget_select (get_panel_widget (0));
1528 widget_select (get_panel_widget (1));
1531 midnight_execute_cmd (NULL
, CK_UserMenu
);
1535 if (ctl_x_map_enabled
)
1537 ctl_x_map_enabled
= FALSE
;
1538 command
= keybind_lookup_keymap_command (main_x_map
, parm
);
1539 if (command
!= CK_IgnoreKey
)
1540 return midnight_execute_cmd (NULL
, command
);
1543 /* FIXME: should handle all menu shortcuts before this point */
1544 if (widget_get_state (WIDGET (the_menubar
), WST_FOCUSED
))
1545 return MSG_NOT_HANDLED
;
1547 if (parm
== '\n' && !is_cmdline_mute ())
1549 if (handle_cmdline_enter ())
1551 /* Else: the panel will handle it. */
1554 if ((!mc_global
.tty
.alternate_plus_minus
1555 || !(mc_global
.tty
.console_flag
!= '\0' || mc_global
.tty
.xterm_flag
)) && !quote
1556 && !current_panel
->searching
)
1558 if (!only_leading_plus_minus
)
1560 /* Special treatement, since the input line will eat them */
1562 return send_message (current_panel
, midnight_dlg
, MSG_ACTION
, CK_Select
, NULL
);
1564 if (parm
== '\\' || parm
== '-')
1565 return send_message (current_panel
, midnight_dlg
, MSG_ACTION
, CK_Unselect
,
1569 return send_message (current_panel
, midnight_dlg
, MSG_ACTION
, CK_SelectInvert
,
1572 else if (!command_prompt
|| input_is_empty (cmdline
))
1574 /* Special treatement '+', '-', '\', '*' only when this is
1575 * first char on input line
1578 return send_message (current_panel
, midnight_dlg
, MSG_ACTION
, CK_Select
, NULL
);
1580 if (parm
== '\\' || parm
== '-')
1581 return send_message (current_panel
, midnight_dlg
, MSG_ACTION
, CK_Unselect
,
1585 return send_message (current_panel
, midnight_dlg
, MSG_ACTION
, CK_SelectInvert
,
1589 return MSG_NOT_HANDLED
;
1591 case MSG_HOTKEY_HANDLED
:
1592 if ((get_current_type () == view_listing
) && current_panel
->searching
)
1594 current_panel
->dirty
= 1; /* FIXME: unneeded? */
1595 send_message (current_panel
, NULL
, MSG_ACTION
, CK_SearchStop
, NULL
);
1599 case MSG_UNHANDLED_KEY
:
1601 cb_ret_t v
= MSG_NOT_HANDLED
;
1603 if (ctl_x_map_enabled
)
1605 ctl_x_map_enabled
= FALSE
;
1606 command
= keybind_lookup_keymap_command (main_x_map
, parm
);
1609 command
= keybind_lookup_keymap_command (main_map
, parm
);
1611 if (command
!= CK_IgnoreKey
)
1612 v
= midnight_execute_cmd (NULL
, command
);
1614 if (v
== MSG_NOT_HANDLED
&& command_prompt
&& !is_cmdline_mute ())
1615 v
= send_message (cmdline
, NULL
, MSG_KEY
, parm
, NULL
);
1621 if (!widget_get_state (WIDGET (the_menubar
), WST_FOCUSED
))
1622 update_dirty_panels ();
1626 /* Handle shortcuts, menu, and buttonbar. */
1627 return midnight_execute_cmd (sender
, parm
);
1634 return dlg_default_callback (w
, sender
, msg
, parm
, data
);
1638 /* --------------------------------------------------------------------------------------------- */
1639 /*** public functions ****************************************************************************/
1640 /* --------------------------------------------------------------------------------------------- */
1645 menu_set_name (left_menu
, panels_layout
.horizontal_split
? _("&Above") : _("&Left"));
1646 menu_set_name (right_menu
, panels_layout
.horizontal_split
? _("&Below") : _("&Right"));
1647 menubar_arrange (the_menubar
);
1648 menubar_set_visible (the_menubar
, menubar_visible
);
1651 /* --------------------------------------------------------------------------------------------- */
1654 midnight_set_buttonbar (WButtonBar
* b
)
1656 buttonbar_set_label (b
, 1, Q_ ("ButtonBar|Help"), main_map
, NULL
);
1657 buttonbar_set_label (b
, 2, Q_ ("ButtonBar|Menu"), main_map
, NULL
);
1658 buttonbar_set_label (b
, 3, Q_ ("ButtonBar|View"), main_map
, NULL
);
1659 buttonbar_set_label (b
, 4, Q_ ("ButtonBar|Edit"), main_map
, NULL
);
1660 buttonbar_set_label (b
, 5, Q_ ("ButtonBar|Copy"), main_map
, NULL
);
1661 buttonbar_set_label (b
, 6, Q_ ("ButtonBar|RenMov"), main_map
, NULL
);
1662 buttonbar_set_label (b
, 7, Q_ ("ButtonBar|Mkdir"), main_map
, NULL
);
1663 buttonbar_set_label (b
, 8, Q_ ("ButtonBar|Delete"), main_map
, NULL
);
1664 buttonbar_set_label (b
, 9, Q_ ("ButtonBar|PullDn"), main_map
, NULL
);
1665 buttonbar_set_label (b
, 10, Q_ ("ButtonBar|Quit"), main_map
, NULL
);
1668 /* --------------------------------------------------------------------------------------------- */
1670 * Return a random hint. If force is TRUE, ignore the timeout.
1674 get_random_hint (gboolean force
)
1676 static const guint64 update_period
= 60 * G_USEC_PER_SEC
;
1677 static guint64 tv
= 0;
1679 char *data
, *result
= NULL
, *eop
;
1683 /* Do not change hints more often than one minute */
1684 if (!force
&& !mc_time_elapsed (&tv
, update_period
))
1685 return g_strdup ("");
1687 data
= load_mc_home_file (mc_global
.share_data_dir
, MC_HINT
, NULL
, &len
);
1691 /* get a random entry */
1692 srand ((unsigned int) (tv
/ G_USEC_PER_SEC
));
1693 start
= ((size_t) rand ()) % (len
- 1);
1695 /* Search the start of paragraph */
1696 for (; start
!= 0; start
--)
1697 if (data
[start
] == '\n' && data
[start
+ 1] == '\n')
1703 /* Search the end of paragraph */
1704 for (eop
= data
+ start
; *eop
!= '\0'; eop
++)
1706 if (*eop
== '\n' && *(eop
+ 1) == '\n')
1715 /* hint files are stored in utf-8 */
1716 /* try convert hint file from utf-8 to terminal encoding */
1717 conv
= str_crt_conv_from ("UTF-8");
1718 if (conv
!= INVALID_CONV
)
1722 buffer
= g_string_sized_new (len
- start
);
1723 if (str_convert (conv
, &data
[start
], buffer
) != ESTR_FAILURE
)
1724 result
= g_string_free (buffer
, FALSE
);
1726 g_string_free (buffer
, TRUE
);
1727 str_close_conv (conv
);
1730 result
= g_strndup (data
+ start
, len
- start
);
1737 /* --------------------------------------------------------------------------------------------- */
1739 * Load new hint and display it.
1740 * IF force is not 0, ignore the timeout.
1744 load_hint (gboolean force
)
1748 if (WIDGET (the_hint
)->owner
== NULL
)
1751 if (!mc_global
.message_visible
)
1753 label_set_text (the_hint
, NULL
);
1757 hint
= get_random_hint (force
);
1767 char text
[BUF_SMALL
];
1769 g_snprintf (text
, sizeof (text
), _("GNU Midnight Commander %s\n"), VERSION
);
1774 /* --------------------------------------------------------------------------------------------- */
1779 input_free_completions (cmdline
);
1780 group_select_next_widget (GROUP (midnight_dlg
));
1783 /* --------------------------------------------------------------------------------------------- */
1785 /** Save current stat of directories to avoid reloading the panels
1786 * when no modifications have taken place
1789 save_cwds_stat (void)
1791 if (panels_options
.fast_reload
)
1793 mc_stat (current_panel
->cwd_vpath
, &(current_panel
->dir_stat
));
1794 if (get_other_type () == view_listing
)
1795 mc_stat (other_panel
->cwd_vpath
, &(other_panel
->dir_stat
));
1799 /* --------------------------------------------------------------------------------------------- */
1802 quiet_quit_cmd (void)
1804 print_last_revert
= TRUE
;
1805 return quit_cmd_internal (1);
1808 /* --------------------------------------------------------------------------------------------- */
1810 /** Run the main dialog that occupies the whole screen */
1816 #ifdef USE_INTERNAL_EDIT
1820 midnight_dlg
= dlg_create (FALSE
, 0, 0, 1, 1, WPOS_FULLSCREEN
, FALSE
, dialog_colors
,
1821 midnight_callback
, NULL
, "[main]", NULL
);
1823 /* Check if we were invoked as an editor or file viewer */
1824 if (mc_global
.mc_run_mode
!= MC_RUN_FULL
)
1827 ret
= mc_maybe_editor_or_viewer ();
1831 /* We only need the first idle event to show user menu after start */
1832 widget_idle (WIDGET (midnight_dlg
), TRUE
);
1835 mc_filehighlight
= mc_fhl_new (TRUE
);
1837 create_file_manager ();
1838 (void) dlg_run (midnight_dlg
);
1840 mc_fhl_free (&mc_filehighlight
);
1844 /* dlg_destroy destroys even current_panel->cwd_vpath, so we have to save a copy :) */
1845 if (mc_args__last_wd_file
!= NULL
&& vfs_current_is_local ())
1846 last_wd_string
= g_strdup (vfs_path_as_str (current_panel
->cwd_vpath
));
1848 /* don't handle VFS timestamps for dirs opened in panels */
1849 mc_event_destroy (MCEVENT_GROUP_CORE
, "vfs_timestamp");
1851 dir_list_free_list (&panelized_panel
.list
);
1855 mc_global
.midnight_shutdown
= TRUE
;
1856 dialog_switch_shutdown ();
1858 dlg_destroy (midnight_dlg
);
1859 current_panel
= NULL
;
1861 #ifdef USE_INTERNAL_EDIT
1865 if ((quit
& SUBSHELL_EXIT
) == 0)
1871 /* --------------------------------------------------------------------------------------------- */