2 Main dialog (file panels) of the Midnight Commander
4 Copyright (C) 1994-2017
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_type
= 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
, menu_entry_create (_("&Listing mode..."), CK_PanelListingChange
));
204 entries
= g_list_prepend (entries
, menu_entry_create (_("&Sort order..."), CK_Sort
));
205 entries
= g_list_prepend (entries
, menu_entry_create (_("&Filter..."), CK_Filter
));
207 entries
= g_list_prepend (entries
, menu_entry_create (_("&Encoding..."), CK_SelectCodepage
));
209 entries
= g_list_prepend (entries
, menu_separator_create ());
210 #ifdef ENABLE_VFS_FTP
211 entries
= g_list_prepend (entries
, menu_entry_create (_("FT&P link..."), CK_ConnectFtp
));
213 #ifdef ENABLE_VFS_FISH
214 entries
= g_list_prepend (entries
, menu_entry_create (_("S&hell link..."), CK_ConnectFish
));
216 #ifdef ENABLE_VFS_SFTP
217 entries
= g_list_prepend (entries
, menu_entry_create (_("S&FTP link..."), CK_ConnectSftp
));
219 #ifdef ENABLE_VFS_SMB
220 entries
= g_list_prepend (entries
, menu_entry_create (_("SM&B link..."), CK_ConnectSmb
));
222 entries
= g_list_prepend (entries
, menu_entry_create (_("Paneli&ze"), CK_Panelize
));
223 entries
= g_list_prepend (entries
, menu_separator_create ());
224 entries
= g_list_prepend (entries
, menu_entry_create (_("&Rescan"), CK_Reread
));
226 return g_list_reverse (entries
);
229 /* --------------------------------------------------------------------------------------------- */
232 create_file_menu (void)
234 GList
*entries
= NULL
;
236 entries
= g_list_prepend (entries
, menu_entry_create (_("&View"), CK_View
));
237 entries
= g_list_prepend (entries
, menu_entry_create (_("Vie&w file..."), CK_ViewFile
));
238 entries
= g_list_prepend (entries
, menu_entry_create (_("&Filtered view"), CK_ViewFiltered
));
239 entries
= g_list_prepend (entries
, menu_entry_create (_("&Edit"), CK_Edit
));
240 entries
= g_list_prepend (entries
, menu_entry_create (_("&Copy"), CK_Copy
));
241 entries
= g_list_prepend (entries
, menu_entry_create (_("C&hmod"), CK_ChangeMode
));
242 entries
= g_list_prepend (entries
, menu_entry_create (_("&Link"), CK_Link
));
243 entries
= g_list_prepend (entries
, menu_entry_create (_("&Symlink"), CK_LinkSymbolic
));
245 g_list_prepend (entries
,
246 menu_entry_create (_("Relative symlin&k"), CK_LinkSymbolicRelative
));
247 entries
= g_list_prepend (entries
, menu_entry_create (_("Edit s&ymlink"), CK_LinkSymbolicEdit
));
248 entries
= g_list_prepend (entries
, menu_entry_create (_("Ch&own"), CK_ChangeOwn
));
250 g_list_prepend (entries
, menu_entry_create (_("&Advanced chown"), CK_ChangeOwnAdvanced
));
251 entries
= g_list_prepend (entries
, menu_entry_create (_("&Rename/Move"), CK_Move
));
252 entries
= g_list_prepend (entries
, menu_entry_create (_("&Mkdir"), CK_MakeDir
));
253 entries
= g_list_prepend (entries
, menu_entry_create (_("&Delete"), CK_Delete
));
254 entries
= g_list_prepend (entries
, menu_entry_create (_("&Quick cd"), CK_CdQuick
));
255 entries
= g_list_prepend (entries
, menu_separator_create ());
256 entries
= g_list_prepend (entries
, menu_entry_create (_("Select &group"), CK_Select
));
257 entries
= g_list_prepend (entries
, menu_entry_create (_("U&nselect group"), CK_Unselect
));
258 entries
= g_list_prepend (entries
, menu_entry_create (_("&Invert selection"), CK_SelectInvert
));
259 entries
= g_list_prepend (entries
, menu_separator_create ());
260 entries
= g_list_prepend (entries
, menu_entry_create (_("E&xit"), CK_Quit
));
262 return g_list_reverse (entries
);
265 /* --------------------------------------------------------------------------------------------- */
268 create_command_menu (void)
270 /* I know, I'm lazy, but the tree widget when it's not running
271 * as a panel still has some problems, I have not yet finished
272 * the WTree widget port, sorry.
274 GList
*entries
= NULL
;
276 entries
= g_list_prepend (entries
, menu_entry_create (_("&User menu"), CK_UserMenu
));
277 entries
= g_list_prepend (entries
, menu_entry_create (_("&Directory tree"), CK_Tree
));
278 entries
= g_list_prepend (entries
, menu_entry_create (_("&Find file"), CK_Find
));
279 entries
= g_list_prepend (entries
, menu_entry_create (_("S&wap panels"), CK_Swap
));
280 entries
= g_list_prepend (entries
, menu_entry_create (_("Switch &panels on/off"), CK_Shell
));
282 g_list_prepend (entries
, menu_entry_create (_("&Compare directories"), CK_CompareDirs
));
284 entries
= g_list_prepend (entries
, menu_entry_create (_("C&ompare files"), CK_CompareFiles
));
287 g_list_prepend (entries
, menu_entry_create (_("E&xternal panelize"), CK_ExternalPanelize
));
288 entries
= g_list_prepend (entries
, menu_entry_create (_("Show directory s&izes"), CK_DirSize
));
289 entries
= g_list_prepend (entries
, menu_separator_create ());
290 entries
= g_list_prepend (entries
, menu_entry_create (_("Command &history"), CK_History
));
291 entries
= g_list_prepend (entries
, menu_entry_create (_("Di&rectory hotlist"), CK_HotList
));
293 entries
= g_list_prepend (entries
, menu_entry_create (_("&Active VFS list"), CK_VfsList
));
295 #ifdef ENABLE_BACKGROUND
296 entries
= g_list_prepend (entries
, menu_entry_create (_("&Background jobs"), CK_Jobs
));
298 entries
= g_list_prepend (entries
, menu_entry_create (_("Screen lis&t"), CK_ScreenList
));
299 entries
= g_list_prepend (entries
, menu_separator_create ());
300 #ifdef ENABLE_VFS_UNDELFS
302 g_list_prepend (entries
,
303 menu_entry_create (_("&Undelete files (ext2fs only)"), CK_Undelete
));
305 #ifdef LISTMODE_EDITOR
306 entries
= g_list_prepend (entries
, menu_entry_create (_("&Listing format edit"), CK_ListMode
));
308 #if defined (ENABLE_VFS_UNDELFS) || defined (LISTMODE_EDITOR)
309 entries
= g_list_prepend (entries
, menu_separator_create ());
312 g_list_prepend (entries
,
313 menu_entry_create (_("Edit &extension file"), CK_EditExtensionsFile
));
314 entries
= g_list_prepend (entries
, menu_entry_create (_("Edit &menu file"), CK_EditUserMenu
));
316 g_list_prepend (entries
,
317 menu_entry_create (_("Edit hi&ghlighting group file"),
318 CK_EditFileHighlightFile
));
320 return g_list_reverse (entries
);
323 /* --------------------------------------------------------------------------------------------- */
326 create_options_menu (void)
328 GList
*entries
= NULL
;
330 entries
= g_list_prepend (entries
, menu_entry_create (_("&Configuration..."), CK_Options
));
331 entries
= g_list_prepend (entries
, menu_entry_create (_("&Layout..."), CK_OptionsLayout
));
332 entries
= g_list_prepend (entries
, menu_entry_create (_("&Panel options..."), CK_OptionsPanel
));
334 g_list_prepend (entries
, menu_entry_create (_("C&onfirmation..."), CK_OptionsConfirm
));
336 g_list_prepend (entries
, menu_entry_create (_("&Appearance..."), CK_OptionsAppearance
));
338 g_list_prepend (entries
, menu_entry_create (_("&Display bits..."), CK_OptionsDisplayBits
));
339 entries
= g_list_prepend (entries
, menu_entry_create (_("Learn &keys..."), CK_LearnKeys
));
341 entries
= g_list_prepend (entries
, menu_entry_create (_("&Virtual FS..."), CK_OptionsVfs
));
343 entries
= g_list_prepend (entries
, menu_separator_create ());
344 entries
= g_list_prepend (entries
, menu_entry_create (_("&Save setup"), CK_SaveSetup
));
346 return g_list_reverse (entries
);
349 /* --------------------------------------------------------------------------------------------- */
354 left_menu
= create_menu ("", create_panel_menu (), "[Left and Right Menus]");
355 menubar_add_menu (the_menubar
, left_menu
);
356 menubar_add_menu (the_menubar
, create_menu (_("&File"), create_file_menu (), "[File Menu]"));
357 menubar_add_menu (the_menubar
,
358 create_menu (_("&Command"), create_command_menu (), "[Command Menu]"));
359 menubar_add_menu (the_menubar
,
360 create_menu (_("&Options"), create_options_menu (), "[Options Menu]"));
361 right_menu
= create_menu ("", create_panel_menu (), "[Left and Right Menus]");
362 menubar_add_menu (the_menubar
, right_menu
);
366 /* --------------------------------------------------------------------------------------------- */
369 menu_last_selected_cmd (void)
371 menubar_activate (the_menubar
, drop_menus
, -1);
374 /* --------------------------------------------------------------------------------------------- */
381 if ((get_current_index () == 0) == (current_panel
->active
!= 0))
384 selected
= g_list_length (the_menubar
->menu
) - 1;
386 menubar_activate (the_menubar
, drop_menus
, selected
);
389 /* --------------------------------------------------------------------------------------------- */
395 const panel_field_t
*sort_order
;
397 if (!SELECTED_IS_PANEL
)
401 sort_order
= sort_box (&p
->sort_info
, p
->sort_field
);
402 panel_set_sort_order (p
, sort_order
);
405 /* --------------------------------------------------------------------------------------------- */
408 midnight_get_shortcut (long command
)
411 const char *shortcut
= NULL
;
413 shortcut
= keybind_lookup_keymap_shortcut (main_map
, command
);
414 if (shortcut
!= NULL
)
415 return g_strdup (shortcut
);
417 shortcut
= keybind_lookup_keymap_shortcut (panel_map
, command
);
418 if (shortcut
!= NULL
)
419 return g_strdup (shortcut
);
421 ext_map
= keybind_lookup_keymap_shortcut (main_map
, CK_ExtendedKeyMap
);
423 shortcut
= keybind_lookup_keymap_shortcut (main_x_map
, command
);
424 if (shortcut
!= NULL
)
425 return g_strdup_printf ("%s %s", ext_map
, shortcut
);
430 /* --------------------------------------------------------------------------------------------- */
433 midnight_get_title (const WDialog
* h
, size_t len
)
441 title_path_prepare (&path
, &login
);
443 p
= g_strdup_printf ("%s [%s]:%s", _("Panels:"), login
, path
);
446 path
= g_strdup (str_trunc (p
, len
- 4));
452 /* --------------------------------------------------------------------------------------------- */
455 toggle_panels_split (void)
457 panels_layout
.horizontal_split
= !panels_layout
.horizontal_split
;
462 /* --------------------------------------------------------------------------------------------- */
467 check_panel_timestamp (const WPanel
* panel
, panel_view_mode_t mode
, struct vfs_class
*vclass
,
470 if (mode
== view_listing
)
472 const vfs_path_element_t
*path_element
;
474 path_element
= vfs_path_get_by_index (panel
->cwd_vpath
, -1);
476 if (path_element
->class != vclass
)
479 if (vfs_getid (panel
->cwd_vpath
) != id
)
485 /* --------------------------------------------------------------------------------------------- */
489 check_current_panel_timestamp (const gchar
* event_group_name
, const gchar
* event_name
,
490 gpointer init_data
, gpointer data
)
492 ev_vfs_stamp_create_t
*event_data
= (ev_vfs_stamp_create_t
*) data
;
494 (void) event_group_name
;
499 check_panel_timestamp (current_panel
, get_current_type (), event_data
->vclass
,
501 return !event_data
->ret
;
504 /* --------------------------------------------------------------------------------------------- */
508 check_other_panel_timestamp (const gchar
* event_group_name
, const gchar
* event_name
,
509 gpointer init_data
, gpointer data
)
511 ev_vfs_stamp_create_t
*event_data
= (ev_vfs_stamp_create_t
*) data
;
513 (void) event_group_name
;
518 check_panel_timestamp (other_panel
, get_other_type (), event_data
->vclass
, event_data
->id
);
519 return !event_data
->ret
;
521 #endif /* ENABLE_VFS */
523 /* --------------------------------------------------------------------------------------------- */
527 print_vfs_message (const gchar
* event_group_name
, const gchar
* event_name
,
528 gpointer init_data
, gpointer data
)
530 ev_vfs_print_message_t
*event_data
= (ev_vfs_print_message_t
*) data
;
532 (void) event_group_name
;
536 if (mc_global
.midnight_shutdown
)
539 if (!mc_global
.message_visible
|| the_hint
== NULL
|| WIDGET (the_hint
)->owner
== NULL
)
543 if (!nice_rotating_dash
|| (ok_to_refresh
<= 0))
546 /* Preserve current cursor position */
547 tty_getyx (&row
, &col
);
550 tty_setcolor (NORMAL_COLOR
);
551 tty_print_string (str_fit_to_term (event_data
->msg
, COLS
- 1, J_LEFT
));
553 /* Restore cursor position */
554 tty_gotoyx (row
, col
);
559 if (mc_global
.message_visible
)
560 set_hintbar (event_data
->msg
);
563 MC_PTR_FREE (event_data
->msg
);
567 /* --------------------------------------------------------------------------------------------- */
572 int current_index
, other_index
;
573 panel_view_mode_t current_mode
, other_mode
;
574 char *current_dir
, *other_dir
;
575 vfs_path_t
*original_dir
;
578 * Following cases from command line are possible:
579 * 'mc' (no arguments): mc_run_param0 == NULL, mc_run_param1 == NULL
580 * active panel uses current directory
581 * passive panel uses "other_dir" from panels.ini
583 * 'mc dir1 dir2' (two arguments): mc_run_param0 != NULL, mc_run_param1 != NULL
584 * active panel uses mc_run_param0
585 * passive panel uses mc_run_param1
587 * 'mc dir1' (single argument): mc_run_param0 != NULL, mc_run_param1 == NULL
588 * active panel uses mc_run_param0
589 * passive panel uses "other_dir" from panels.ini
592 /* Set up panel directories */
593 if (boot_current_is_left
)
595 /* left panel is active */
598 current_mode
= startup_left_mode
;
599 other_mode
= startup_right_mode
;
601 if (mc_run_param0
== NULL
&& mc_run_param1
== NULL
)
604 current_dir
= NULL
; /* assume current dir */
605 other_dir
= saved_other_dir
; /* from ini */
607 else if (mc_run_param0
!= NULL
&& mc_run_param1
!= NULL
)
610 current_dir
= (char *) mc_run_param0
;
611 other_dir
= mc_run_param1
;
613 else /* mc_run_param0 != NULL && mc_run_param1 == NULL */
616 current_dir
= (char *) mc_run_param0
;
617 other_dir
= saved_other_dir
; /* from ini */
622 /* right panel is active */
625 current_mode
= startup_right_mode
;
626 other_mode
= startup_left_mode
;
628 if (mc_run_param0
== NULL
&& mc_run_param1
== NULL
)
631 current_dir
= NULL
; /* assume current dir */
632 other_dir
= saved_other_dir
; /* from ini */
634 else if (mc_run_param0
!= NULL
&& mc_run_param1
!= NULL
)
637 current_dir
= (char *) mc_run_param0
;
638 other_dir
= mc_run_param1
;
640 else /* mc_run_param0 != NULL && mc_run_param1 == NULL */
643 current_dir
= (char *) mc_run_param0
;
644 other_dir
= saved_other_dir
; /* from ini */
648 /* 1. Get current dir */
649 original_dir
= vfs_path_clone (vfs_get_raw_current_dir ());
651 /* 2. Create passive panel */
652 if (other_dir
!= NULL
)
656 if (g_path_is_absolute (other_dir
))
657 vpath
= vfs_path_from_str (other_dir
);
659 vpath
= vfs_path_append_new (original_dir
, other_dir
, (char *) NULL
);
661 vfs_path_free (vpath
);
663 set_display_type (other_index
, other_mode
);
665 /* 3. Create active panel */
666 if (current_dir
== NULL
)
667 mc_chdir (original_dir
);
672 if (g_path_is_absolute (current_dir
))
673 vpath
= vfs_path_from_str (current_dir
);
675 vpath
= vfs_path_append_new (original_dir
, current_dir
, (char *) NULL
);
677 vfs_path_free (vpath
);
679 set_display_type (current_index
, current_mode
);
681 if (startup_left_mode
== view_listing
)
682 current_panel
= left_panel
;
683 else if (right_panel
!= NULL
)
684 current_panel
= right_panel
;
686 current_panel
= left_panel
;
688 vfs_path_free (original_dir
);
691 mc_event_add (MCEVENT_GROUP_CORE
, "vfs_timestamp", check_other_panel_timestamp
, NULL
, NULL
);
692 mc_event_add (MCEVENT_GROUP_CORE
, "vfs_timestamp", check_current_panel_timestamp
, NULL
, NULL
);
693 #endif /* ENABLE_VFS */
695 mc_event_add (MCEVENT_GROUP_CORE
, "vfs_print_message", print_vfs_message
, NULL
, NULL
);
697 /* Create the nice widgets */
698 cmdline
= command_new (0, 0, 0);
699 the_prompt
= label_new (0, 0, mc_prompt
);
700 the_prompt
->transparent
= 1;
701 the_bar
= buttonbar_new (mc_global
.keybar_visible
);
703 the_hint
= label_new (0, 0, 0);
704 the_hint
->transparent
= 1;
705 the_hint
->auto_adjust_cols
= 0;
706 WIDGET (the_hint
)->cols
= COLS
;
708 the_menubar
= menubar_new (0, 0, COLS
, NULL
, menubar_visible
);
711 /* --------------------------------------------------------------------------------------------- */
714 midnight_put_panel_path (WPanel
* panel
)
716 vfs_path_t
*cwd_vpath
;
717 const char *cwd_vpath_str
;
723 cwd_vpath
= remove_encoding_from_path (panel
->cwd_vpath
);
725 cwd_vpath
= vfs_path_clone (panel
->cwd_vpath
);
728 cwd_vpath_str
= vfs_path_as_str (cwd_vpath
);
730 command_insert (cmdline
, cwd_vpath_str
, FALSE
);
732 if (!IS_PATH_SEP (cwd_vpath_str
[strlen (cwd_vpath_str
) - 1]))
733 command_insert (cmdline
, PATH_SEP_STR
, FALSE
);
735 vfs_path_free (cwd_vpath
);
738 /* --------------------------------------------------------------------------------------------- */
741 put_link (WPanel
* panel
)
745 if (S_ISLNK (selection (panel
)->st
.st_mode
))
747 char buffer
[MC_MAXPATHLEN
];
751 vpath
= vfs_path_append_new (panel
->cwd_vpath
, selection (panel
)->fname
, (char *) NULL
);
752 i
= mc_readlink (vpath
, buffer
, sizeof (buffer
) - 1);
753 vfs_path_free (vpath
);
758 command_insert (cmdline
, buffer
, TRUE
);
763 /* --------------------------------------------------------------------------------------------- */
766 put_current_link (void)
768 put_link (current_panel
);
771 /* --------------------------------------------------------------------------------------------- */
774 put_other_link (void)
776 if (get_other_type () == view_listing
)
777 put_link (other_panel
);
780 /* --------------------------------------------------------------------------------------------- */
782 /** Insert the selected file name into the input line */
784 put_current_selected (void)
791 if (get_current_type () == view_tree
)
794 const vfs_path_t
*selected_name
;
796 tree
= (WTree
*) get_panel_widget (get_current_index ());
797 selected_name
= tree_selected_name (tree
);
798 tmp
= vfs_path_as_str (selected_name
);
801 tmp
= selection (current_panel
)->fname
;
803 command_insert (cmdline
, tmp
, TRUE
);
806 /* --------------------------------------------------------------------------------------------- */
809 put_tagged (WPanel
* panel
)
813 input_disable_update (cmdline
);
818 for (i
= 0; i
< panel
->dir
.len
; i
++)
820 if (panel
->dir
.list
[i
].f
.marked
)
821 command_insert (cmdline
, panel
->dir
.list
[i
].fname
, TRUE
);
826 command_insert (cmdline
, panel
->dir
.list
[panel
->selected
].fname
, TRUE
);
828 input_enable_update (cmdline
);
831 /* --------------------------------------------------------------------------------------------- */
834 put_current_tagged (void)
836 put_tagged (current_panel
);
839 /* --------------------------------------------------------------------------------------------- */
842 put_other_tagged (void)
844 if (get_other_type () == view_listing
)
845 put_tagged (other_panel
);
848 /* --------------------------------------------------------------------------------------------- */
853 ctl_x_map_enabled
= TRUE
;
856 /* --------------------------------------------------------------------------------------------- */
863 tty_display_8bit (TRUE
);
865 tty_display_8bit (mc_global
.full_eight_bits
);
866 #endif /* HAVE_CHARSET */
868 #else /* HAVE_SLANG */
871 tty_display_8bit (TRUE
);
873 tty_display_8bit (mc_global
.eight_bit_clean
);
874 #endif /* HAVE_CHARSET */
875 #endif /* HAVE_SLANG */
877 #ifdef ENABLE_SUBSHELL
878 if (mc_global
.tty
.use_subshell
)
879 add_select_channel (mc_global
.tty
.subshell_pty
, load_prompt
, 0);
880 #endif /* !ENABLE_SUBSHELL */
882 if ((tty_baudrate () < 9600) || mc_global
.tty
.slow_terminal
)
886 /* --------------------------------------------------------------------------------------------- */
889 setup_dummy_mc (void)
897 vpath
= vfs_path_from_str (d
);
898 ret
= mc_chdir (vpath
);
900 vfs_path_free (vpath
);
904 /* --------------------------------------------------------------------------------------------- */
911 * We sync the profiles since the hotlist may have changed, while
912 * we only change the setup data if we have the auto save feature set
914 const char *curr_dir
;
916 save_setup (auto_save_setup
, panels_options
.auto_save_setup
);
918 curr_dir
= vfs_get_current_dir ();
919 vfs_stamp_path (curr_dir
);
921 if ((current_panel
!= NULL
) && (get_current_type () == view_listing
))
922 vfs_stamp_path (vfs_path_as_str (current_panel
->cwd_vpath
));
924 if ((other_panel
!= NULL
) && (get_other_type () == view_listing
))
925 vfs_stamp_path (vfs_path_as_str (other_panel
->cwd_vpath
));
928 /* --------------------------------------------------------------------------------------------- */
931 create_panels_and_run_mc (void)
933 midnight_dlg
->get_shortcut
= midnight_get_shortcut
;
934 midnight_dlg
->get_title
= midnight_get_title
;
935 /* allow rebind tab */
936 widget_want_tab (WIDGET (midnight_dlg
), TRUE
);
940 add_widget (midnight_dlg
, the_menubar
);
943 add_widget (midnight_dlg
, get_panel_widget (0));
944 add_widget (midnight_dlg
, get_panel_widget (1));
946 add_widget (midnight_dlg
, the_hint
);
947 add_widget (midnight_dlg
, cmdline
);
948 add_widget (midnight_dlg
, the_prompt
);
950 add_widget (midnight_dlg
, the_bar
);
951 midnight_set_buttonbar (the_bar
);
953 /* Run the Midnight Commander if no file was specified in the command line */
954 dlg_run (midnight_dlg
);
957 /* --------------------------------------------------------------------------------------------- */
959 /** result must be free'd (I think this should go in util.c) */
961 prepend_cwd_on_local (const char *filename
)
965 vpath
= vfs_path_from_str (filename
);
966 if (!vfs_file_is_local (vpath
) || g_path_is_absolute (filename
))
969 vfs_path_free (vpath
);
971 return vfs_path_append_new (vfs_get_raw_current_dir (), filename
, (char *) NULL
);
974 /* --------------------------------------------------------------------------------------------- */
976 /** Invoke the internal view/edit routine with:
977 * the default processing and forcing the internal viewer/editor
980 mc_maybe_editor_or_viewer (void)
984 switch (mc_global
.mc_run_mode
)
986 #ifdef USE_INTERNAL_EDIT
988 ret
= edit_files ((GList
*) mc_run_param0
);
990 #endif /* USE_INTERNAL_EDIT */
993 vfs_path_t
*vpath
= NULL
;
995 if (mc_run_param0
!= NULL
&& *(char *) mc_run_param0
!= '\0')
996 vpath
= prepend_cwd_on_local ((char *) mc_run_param0
);
998 ret
= view_file (vpath
, FALSE
, TRUE
);
999 vfs_path_free (vpath
);
1002 #ifdef USE_DIFF_VIEW
1003 case MC_RUN_DIFFVIEWER
:
1004 ret
= dview_diff_cmd (mc_run_param0
, mc_run_param1
);
1006 #endif /* USE_DIFF_VIEW */
1014 /* --------------------------------------------------------------------------------------------- */
1017 quit_cmd_internal (int quiet
)
1022 n
= dialog_switch_num () - 1;
1025 char msg
[BUF_MEDIUM
];
1027 g_snprintf (msg
, sizeof (msg
),
1028 ngettext ("You have %zu opened screen. Quit anyway?",
1029 "You have %zu opened screens. Quit anyway?", n
), n
);
1031 if (query_dialog (_("The Midnight Commander"), msg
, D_NORMAL
, 2, _("&Yes"), _("&No")) != 0)
1035 else if (quiet
|| !confirm_exit
)
1037 else if (query_dialog (_("The Midnight Commander"),
1038 _("Do you really want to quit the Midnight Commander?"),
1039 D_NORMAL
, 2, _("&Yes"), _("&No")) == 0)
1044 #ifdef ENABLE_SUBSHELL
1045 if (!mc_global
.tty
.use_subshell
)
1047 else if ((q
= exit_subshell ()? 1 : 0) != 0)
1057 /* --------------------------------------------------------------------------------------------- */
1062 return quit_cmd_internal (0);
1065 /* --------------------------------------------------------------------------------------------- */
1068 * Repaint the contents of the panels without frames. To schedule panel
1069 * for repainting, set panel->dirty to 1. There are many reasons why
1070 * the panels need to be repainted, and this is a costly operation, so
1071 * it's done once per event.
1075 update_dirty_panels (void)
1077 if (get_current_type () == view_listing
&& current_panel
->dirty
)
1078 widget_redraw (WIDGET (current_panel
));
1080 if (get_other_type () == view_listing
&& other_panel
->dirty
)
1081 widget_redraw (WIDGET (other_panel
));
1084 /* --------------------------------------------------------------------------------------------- */
1087 toggle_show_hidden (void)
1089 panels_options
.show_dot_files
= !panels_options
.show_dot_files
;
1090 update_panels (UP_RELOAD
, UP_KEEPSEL
);
1091 /* redraw panels forced */
1092 update_dirty_panels ();
1095 /* --------------------------------------------------------------------------------------------- */
1098 midnight_execute_cmd (Widget
* sender
, long command
)
1100 cb_ret_t res
= MSG_HANDLED
;
1104 /* stop quick search before executing any command */
1105 send_message (current_panel
, NULL
, MSG_ACTION
, CK_SearchStop
, NULL
);
1109 case CK_ChangePanel
:
1115 case CK_PanelListingChange
:
1116 change_listing_cmd ();
1124 case CK_ChangeOwnAdvanced
:
1125 chown_advanced_cmd ();
1127 case CK_CompareDirs
:
1128 compare_dirs_cmd ();
1138 case CK_OptionsConfirm
:
1144 case CK_PutCurrentPath
:
1145 midnight_put_panel_path (current_panel
);
1147 case CK_PutCurrentSelected
:
1148 put_current_selected ();
1150 case CK_PutCurrentFullSelected
:
1151 midnight_put_panel_path (current_panel
);
1152 put_current_selected ();
1154 case CK_PutCurrentLink
:
1155 put_current_link ();
1157 case CK_PutCurrentTagged
:
1158 put_current_tagged ();
1160 case CK_PutOtherPath
:
1161 if (get_other_type () == view_listing
)
1162 midnight_put_panel_path (other_panel
);
1164 case CK_PutOtherLink
:
1167 case CK_PutOtherTagged
:
1168 put_other_tagged ();
1174 dialog_switch_list ();
1176 #ifdef USE_DIFF_VIEW
1177 case CK_CompareFiles
:
1181 case CK_OptionsDisplayBits
:
1182 display_bits_box ();
1187 #ifdef USE_INTERNAL_EDIT
1188 case CK_EditForceInternal
:
1189 edit_cmd_force_internal ();
1192 case CK_EditExtensionsFile
:
1195 case CK_EditFileHighlightFile
:
1198 case CK_EditUserMenu
:
1199 edit_mc_menu_cmd ();
1201 case CK_LinkSymbolicEdit
:
1202 edit_symlink_cmd ();
1204 case CK_ExternalPanelize
:
1205 external_panelize ();
1210 case CK_ViewFiltered
:
1211 view_filtered_cmd ();
1216 #ifdef ENABLE_VFS_FISH
1217 case CK_ConnectFish
:
1221 #ifdef ENABLE_VFS_FTP
1226 #ifdef ENABLE_VFS_SFTP
1227 case CK_ConnectSftp
:
1231 #ifdef ENABLE_VFS_SMB
1235 #endif /* ENABLE_VFS_SMB */
1243 /* show the history of command line widget */
1244 send_message (cmdline
, NULL
, MSG_ACTION
, CK_History
, NULL
);
1247 if (sender
== WIDGET (the_menubar
))
1248 info_cmd (); /* menu */
1250 info_cmd_no_menu (); /* shortcut or buttonbar */
1252 #ifdef ENABLE_BACKGROUND
1257 case CK_OptionsLayout
:
1260 case CK_OptionsAppearance
:
1267 link_cmd (LINK_HARDLINK
);
1269 case CK_PanelListing
:
1272 #ifdef LISTMODE_EDITOR
1280 case CK_MenuLastSelected
:
1281 menu_last_selected_cmd ();
1286 case CK_OptionsPanel
:
1287 panel_options_box ();
1290 case CK_SelectCodepage
:
1300 case CK_PanelQuickView
:
1301 if (sender
== WIDGET (the_menubar
))
1302 quick_view_cmd (); /* menu */
1304 quick_cmd_no_menu (); /* shortcut or buttonabr */
1312 case CK_LinkSymbolicRelative
:
1313 link_cmd (LINK_SYMLINK_RELATIVE
);
1331 case CK_SelectInvert
:
1332 res
= send_message (current_panel
, midnight_dlg
, MSG_ACTION
, command
, NULL
);
1338 smart_dirsize_cmd ();
1343 case CK_ExtendedKeyMap
:
1347 mc_event_raise (MCEVENT_GROUP_CORE
, "suspend", NULL
);
1352 case CK_LinkSymbolic
:
1353 link_cmd (LINK_SYMLINK_ABSOLUTE
);
1356 toggle_show_hidden ();
1358 case CK_SplitVertHoriz
:
1359 toggle_panels_split ();
1362 panels_split_equal ();
1365 panels_split_more ();
1368 panels_split_less ();
1376 #ifdef ENABLE_VFS_UNDELFS
1382 user_file_menu_cmd ();
1391 /* don't close panels due to SIGINT */
1394 res
= MSG_NOT_HANDLED
;
1400 /* --------------------------------------------------------------------------------------------- */
1403 midnight_callback (Widget
* w
, Widget
* sender
, widget_msg_t msg
, int parm
, void *data
)
1416 /* We handle the special case of the output lines */
1417 if (mc_global
.tty
.console_flag
!= '\0' && output_lines
)
1418 show_console_contents (output_start_y
,
1419 LINES
- output_lines
- mc_global
.keybar_visible
-
1420 1, LINES
- mc_global
.keybar_visible
- 1);
1424 /* dlg_set_size() is surplus for this case */
1428 menubar_arrange (the_menubar
);
1432 /* We only need the first idle event to show user menu after start */
1433 widget_idle (w
, FALSE
);
1435 if (boot_current_is_left
)
1436 widget_select (get_panel_widget (0));
1438 widget_select (get_panel_widget (1));
1441 midnight_execute_cmd (NULL
, CK_UserMenu
);
1445 if (ctl_x_map_enabled
)
1447 ctl_x_map_enabled
= FALSE
;
1448 command
= keybind_lookup_keymap_command (main_x_map
, parm
);
1449 if (command
!= CK_IgnoreKey
)
1450 return midnight_execute_cmd (NULL
, command
);
1453 /* FIXME: should handle all menu shortcuts before this point */
1454 if (widget_get_state (WIDGET (the_menubar
), WST_FOCUSED
))
1455 return MSG_NOT_HANDLED
;
1461 /* HACK: don't execute command in the command line if Enter was pressed
1462 in the quick viewer panel. */
1463 /* TODO: currently, when one of panels is other than view_listing,
1464 current_panel points to view_listing panel all time independently of
1465 it's activity. Thus, we can't use get_current_type() here.
1466 current_panel should point to actualy current active panel
1467 independently of it's type. */
1468 if (current_panel
->active
== 0 && get_other_type () == view_quick
)
1469 return MSG_NOT_HANDLED
;
1471 for (i
= 0; cmdline
->buffer
[i
] != '\0' && whitespace (cmdline
->buffer
[i
]); i
++)
1474 if (cmdline
->buffer
[i
] != '\0')
1476 send_message (cmdline
, NULL
, MSG_KEY
, parm
, NULL
);
1480 input_insert (cmdline
, "", FALSE
);
1484 if ((!mc_global
.tty
.alternate_plus_minus
1485 || !(mc_global
.tty
.console_flag
!= '\0' || mc_global
.tty
.xterm_flag
)) && !quote
1486 && !current_panel
->searching
)
1488 if (!only_leading_plus_minus
)
1490 /* Special treatement, since the input line will eat them */
1492 return send_message (current_panel
, midnight_dlg
, MSG_ACTION
, CK_Select
, NULL
);
1494 if (parm
== '\\' || parm
== '-')
1495 return send_message (current_panel
, midnight_dlg
, MSG_ACTION
, CK_Unselect
,
1499 return send_message (current_panel
, midnight_dlg
, MSG_ACTION
, CK_SelectInvert
,
1502 else if (!command_prompt
|| cmdline
->buffer
[0] == '\0')
1504 /* Special treatement '+', '-', '\', '*' only when this is
1505 * first char on input line
1508 return send_message (current_panel
, midnight_dlg
, MSG_ACTION
, CK_Select
, NULL
);
1510 if (parm
== '\\' || parm
== '-')
1511 return send_message (current_panel
, midnight_dlg
, MSG_ACTION
, CK_Unselect
,
1515 return send_message (current_panel
, midnight_dlg
, MSG_ACTION
, CK_SelectInvert
,
1519 return MSG_NOT_HANDLED
;
1521 case MSG_HOTKEY_HANDLED
:
1522 if ((get_current_type () == view_listing
) && current_panel
->searching
)
1524 current_panel
->dirty
= 1; /* FIXME: unneeded? */
1525 send_message (current_panel
, NULL
, MSG_ACTION
, CK_SearchStop
, NULL
);
1529 case MSG_UNHANDLED_KEY
:
1531 cb_ret_t v
= MSG_NOT_HANDLED
;
1533 if (ctl_x_map_enabled
)
1535 ctl_x_map_enabled
= FALSE
;
1536 command
= keybind_lookup_keymap_command (main_x_map
, parm
);
1539 command
= keybind_lookup_keymap_command (main_map
, parm
);
1541 if (command
!= CK_IgnoreKey
)
1542 v
= midnight_execute_cmd (NULL
, command
);
1544 if (v
== MSG_NOT_HANDLED
&& command_prompt
)
1545 v
= send_message (cmdline
, NULL
, MSG_KEY
, parm
, NULL
);
1551 if (!widget_get_state (WIDGET (the_menubar
), WST_FOCUSED
))
1552 update_dirty_panels ();
1556 /* Handle shortcuts, menu, and buttonbar. */
1557 return midnight_execute_cmd (sender
, parm
);
1564 return dlg_default_callback (w
, sender
, msg
, parm
, data
);
1568 /* --------------------------------------------------------------------------------------------- */
1569 /*** public functions ****************************************************************************/
1570 /* --------------------------------------------------------------------------------------------- */
1575 menu_set_name (left_menu
, panels_layout
.horizontal_split
? _("&Above") : _("&Left"));
1576 menu_set_name (right_menu
, panels_layout
.horizontal_split
? _("&Below") : _("&Right"));
1577 menubar_arrange (the_menubar
);
1578 menubar_set_visible (the_menubar
, menubar_visible
);
1581 /* --------------------------------------------------------------------------------------------- */
1584 midnight_set_buttonbar (WButtonBar
* b
)
1586 buttonbar_set_label (b
, 1, Q_ ("ButtonBar|Help"), main_map
, NULL
);
1587 buttonbar_set_label (b
, 2, Q_ ("ButtonBar|Menu"), main_map
, NULL
);
1588 buttonbar_set_label (b
, 3, Q_ ("ButtonBar|View"), main_map
, NULL
);
1589 buttonbar_set_label (b
, 4, Q_ ("ButtonBar|Edit"), main_map
, NULL
);
1590 buttonbar_set_label (b
, 5, Q_ ("ButtonBar|Copy"), main_map
, NULL
);
1591 buttonbar_set_label (b
, 6, Q_ ("ButtonBar|RenMov"), main_map
, NULL
);
1592 buttonbar_set_label (b
, 7, Q_ ("ButtonBar|Mkdir"), main_map
, NULL
);
1593 buttonbar_set_label (b
, 8, Q_ ("ButtonBar|Delete"), main_map
, NULL
);
1594 buttonbar_set_label (b
, 9, Q_ ("ButtonBar|PullDn"), main_map
, NULL
);
1595 buttonbar_set_label (b
, 10, Q_ ("ButtonBar|Quit"), main_map
, NULL
);
1598 /* --------------------------------------------------------------------------------------------- */
1600 * Return a random hint. If force is TRUE, ignore the timeout.
1604 get_random_hint (gboolean force
)
1606 static const guint64 update_period
= 60 * G_USEC_PER_SEC
;
1607 static guint64 tv
= 0;
1609 char *data
, *result
= NULL
, *eop
;
1613 /* Do not change hints more often than one minute */
1614 if (!force
&& !mc_time_elapsed (&tv
, update_period
))
1615 return g_strdup ("");
1617 data
= load_mc_home_file (mc_global
.share_data_dir
, MC_HINT
, NULL
, &len
);
1621 /* get a random entry */
1622 srand ((unsigned int) (tv
/ G_USEC_PER_SEC
));
1623 start
= ((size_t) rand ()) % (len
- 1);
1625 /* Search the start of paragraph */
1626 for (; start
!= 0; start
--)
1627 if (data
[start
] == '\n' && data
[start
+ 1] == '\n')
1633 /* Search the end of paragraph */
1634 for (eop
= data
+ start
; *eop
!= '\0'; eop
++)
1636 if (*eop
== '\n' && *(eop
+ 1) == '\n')
1645 /* hint files are stored in utf-8 */
1646 /* try convert hint file from utf-8 to terminal encoding */
1647 conv
= str_crt_conv_from ("UTF-8");
1648 if (conv
!= INVALID_CONV
)
1652 buffer
= g_string_sized_new (len
- start
);
1653 if (str_convert (conv
, &data
[start
], buffer
) != ESTR_FAILURE
)
1654 result
= g_string_free (buffer
, FALSE
);
1656 g_string_free (buffer
, TRUE
);
1657 str_close_conv (conv
);
1660 result
= g_strndup (data
+ start
, len
- start
);
1667 /* --------------------------------------------------------------------------------------------- */
1669 * Load new hint and display it.
1670 * IF force is not 0, ignore the timeout.
1674 load_hint (gboolean force
)
1678 if (WIDGET (the_hint
)->owner
== NULL
)
1681 if (!mc_global
.message_visible
)
1683 label_set_text (the_hint
, NULL
);
1687 hint
= get_random_hint (force
);
1697 char text
[BUF_SMALL
];
1699 g_snprintf (text
, sizeof (text
), _("GNU Midnight Commander %s\n"), VERSION
);
1704 /* --------------------------------------------------------------------------------------------- */
1709 input_free_completions (cmdline
);
1710 dlg_select_next_widget (midnight_dlg
);
1713 /* --------------------------------------------------------------------------------------------- */
1715 /** Save current stat of directories to avoid reloading the panels
1716 * when no modifications have taken place
1719 save_cwds_stat (void)
1721 if (panels_options
.fast_reload
)
1723 mc_stat (current_panel
->cwd_vpath
, &(current_panel
->dir_stat
));
1724 if (get_other_type () == view_listing
)
1725 mc_stat (other_panel
->cwd_vpath
, &(other_panel
->dir_stat
));
1729 /* --------------------------------------------------------------------------------------------- */
1732 quiet_quit_cmd (void)
1734 print_last_revert
= TRUE
;
1735 return quit_cmd_internal (1);
1738 /* --------------------------------------------------------------------------------------------- */
1740 /** Run the main dialog that occupies the whole screen */
1746 #ifdef USE_INTERNAL_EDIT
1750 midnight_dlg
= dlg_create (FALSE
, 0, 0, 1, 1, WPOS_FULLSCREEN
, FALSE
, dialog_colors
,
1751 midnight_callback
, NULL
, "[main]", NULL
);
1753 /* Check if we were invoked as an editor or file viewer */
1754 if (mc_global
.mc_run_mode
!= MC_RUN_FULL
)
1757 ret
= mc_maybe_editor_or_viewer ();
1761 /* We only need the first idle event to show user menu after start */
1762 widget_idle (WIDGET (midnight_dlg
), TRUE
);
1765 mc_filehighlight
= mc_fhl_new (TRUE
);
1766 create_panels_and_run_mc ();
1767 mc_fhl_free (&mc_filehighlight
);
1771 /* dlg_destroy destroys even current_panel->cwd_vpath, so we have to save a copy :) */
1772 if (mc_args__last_wd_file
!= NULL
&& vfs_current_is_local ())
1773 last_wd_string
= g_strdup (vfs_path_as_str (current_panel
->cwd_vpath
));
1775 /* don't handle VFS timestamps for dirs opened in panels */
1776 mc_event_destroy (MCEVENT_GROUP_CORE
, "vfs_timestamp");
1778 dir_list_clean (&panelized_panel
.list
);
1782 mc_global
.midnight_shutdown
= TRUE
;
1783 dialog_switch_shutdown ();
1785 dlg_destroy (midnight_dlg
);
1786 current_panel
= NULL
;
1788 #ifdef USE_INTERNAL_EDIT
1792 if ((quit
& SUBSHELL_EXIT
) == 0)
1798 /* --------------------------------------------------------------------------------------------- */