2 Main dialog (file panels) of the Midnight Commander
4 Copyright (C) 1994-2016
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 midnight_dlg
->state
= DLG_CLOSED
;
143 if ((top_dlg
!= NULL
) && (top_dlg
->data
!= NULL
))
144 DIALOG (top_dlg
->data
)->state
= DLG_CLOSED
;
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
!= 0, -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
!= 0, 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
, 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 */
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
!= 0);
866 #endif /* HAVE_CHARSET */
868 #else /* HAVE_SLANG */
871 tty_display_8bit (TRUE
);
873 tty_display_8bit (mc_global
.eight_bit_clean
!= 0);
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
;
938 add_widget (midnight_dlg
, the_menubar
);
941 add_widget (midnight_dlg
, get_panel_widget (0));
942 add_widget (midnight_dlg
, get_panel_widget (1));
944 add_widget (midnight_dlg
, the_hint
);
945 add_widget (midnight_dlg
, cmdline
);
946 add_widget (midnight_dlg
, the_prompt
);
948 add_widget (midnight_dlg
, the_bar
);
949 midnight_set_buttonbar (the_bar
);
951 /* Run the Midnight Commander if no file was specified in the command line */
952 dlg_run (midnight_dlg
);
955 /* --------------------------------------------------------------------------------------------- */
957 /** result must be free'd (I think this should go in util.c) */
959 prepend_cwd_on_local (const char *filename
)
963 vpath
= vfs_path_from_str (filename
);
964 if (!vfs_file_is_local (vpath
) || g_path_is_absolute (filename
))
967 vfs_path_free (vpath
);
969 return vfs_path_append_new (vfs_get_raw_current_dir (), filename
, NULL
);
972 /* --------------------------------------------------------------------------------------------- */
974 /** Invoke the internal view/edit routine with:
975 * the default processing and forcing the internal viewer/editor
978 mc_maybe_editor_or_viewer (void)
982 switch (mc_global
.mc_run_mode
)
984 #ifdef USE_INTERNAL_EDIT
986 ret
= edit_files ((GList
*) mc_run_param0
);
988 #endif /* USE_INTERNAL_EDIT */
991 vfs_path_t
*vpath
= NULL
;
993 if (mc_run_param0
!= NULL
&& *(char *) mc_run_param0
!= '\0')
994 vpath
= prepend_cwd_on_local ((char *) mc_run_param0
);
996 ret
= view_file (vpath
, FALSE
, TRUE
);
997 vfs_path_free (vpath
);
1000 #ifdef USE_DIFF_VIEW
1001 case MC_RUN_DIFFVIEWER
:
1002 ret
= dview_diff_cmd (mc_run_param0
, mc_run_param1
);
1004 #endif /* USE_DIFF_VIEW */
1012 /* --------------------------------------------------------------------------------------------- */
1015 quit_cmd_internal (int quiet
)
1020 n
= dialog_switch_num () - 1;
1023 char msg
[BUF_MEDIUM
];
1025 g_snprintf (msg
, sizeof (msg
),
1026 ngettext ("You have %zd opened screen. Quit anyway?",
1027 "You have %zd opened screens. Quit anyway?", n
), n
);
1029 if (query_dialog (_("The Midnight Commander"), msg
, D_NORMAL
, 2, _("&Yes"), _("&No")) != 0)
1033 else if (quiet
|| !confirm_exit
)
1035 else if (query_dialog (_("The Midnight Commander"),
1036 _("Do you really want to quit the Midnight Commander?"),
1037 D_NORMAL
, 2, _("&Yes"), _("&No")) == 0)
1042 #ifdef ENABLE_SUBSHELL
1043 if (!mc_global
.tty
.use_subshell
)
1045 else if ((q
= exit_subshell ()? 1 : 0) != 0)
1055 /* --------------------------------------------------------------------------------------------- */
1060 return quit_cmd_internal (0);
1063 /* --------------------------------------------------------------------------------------------- */
1066 * Repaint the contents of the panels without frames. To schedule panel
1067 * for repainting, set panel->dirty to 1. There are many reasons why
1068 * the panels need to be repainted, and this is a costly operation, so
1069 * it's done once per event.
1073 update_dirty_panels (void)
1075 if (get_current_type () == view_listing
&& current_panel
->dirty
)
1076 widget_redraw (WIDGET (current_panel
));
1078 if (get_other_type () == view_listing
&& other_panel
->dirty
)
1079 widget_redraw (WIDGET (other_panel
));
1082 /* --------------------------------------------------------------------------------------------- */
1085 toggle_show_hidden (void)
1087 panels_options
.show_dot_files
= !panels_options
.show_dot_files
;
1088 update_panels (UP_RELOAD
, UP_KEEPSEL
);
1089 /* redraw panels forced */
1090 update_dirty_panels ();
1093 /* --------------------------------------------------------------------------------------------- */
1096 midnight_execute_cmd (Widget
* sender
, long command
)
1098 cb_ret_t res
= MSG_HANDLED
;
1102 /* stop quick search before executing any command */
1103 send_message (current_panel
, NULL
, MSG_ACTION
, CK_SearchStop
, NULL
);
1110 case CK_PanelListingChange
:
1111 change_listing_cmd ();
1119 case CK_ChangeOwnAdvanced
:
1120 chown_advanced_cmd ();
1122 case CK_CompareDirs
:
1123 compare_dirs_cmd ();
1133 case CK_OptionsConfirm
:
1139 case CK_PutCurrentPath
:
1140 midnight_put_panel_path (current_panel
);
1142 case CK_PutCurrentLink
:
1143 put_current_link ();
1145 case CK_PutCurrentTagged
:
1146 put_current_tagged ();
1148 case CK_PutOtherPath
:
1149 if (get_other_type () == view_listing
)
1150 midnight_put_panel_path (other_panel
);
1152 case CK_PutOtherLink
:
1155 case CK_PutOtherTagged
:
1156 put_other_tagged ();
1162 dialog_switch_list ();
1164 #ifdef USE_DIFF_VIEW
1165 case CK_CompareFiles
:
1169 case CK_OptionsDisplayBits
:
1170 display_bits_box ();
1175 #ifdef USE_INTERNAL_EDIT
1176 case CK_EditForceInternal
:
1177 edit_cmd_force_internal ();
1180 case CK_EditExtensionsFile
:
1183 case CK_EditFileHighlightFile
:
1186 case CK_EditUserMenu
:
1187 edit_mc_menu_cmd ();
1189 case CK_LinkSymbolicEdit
:
1190 edit_symlink_cmd ();
1192 case CK_ExternalPanelize
:
1193 external_panelize ();
1198 case CK_ViewFiltered
:
1199 view_filtered_cmd ();
1204 #ifdef ENABLE_VFS_FISH
1205 case CK_ConnectFish
:
1209 #ifdef ENABLE_VFS_FTP
1214 #ifdef ENABLE_VFS_SFTP
1215 case CK_ConnectSftp
:
1219 #ifdef ENABLE_VFS_SMB
1223 #endif /* ENABLE_VFS_SMB */
1231 /* show the history of command line widget */
1232 send_message (cmdline
, NULL
, MSG_ACTION
, CK_History
, NULL
);
1235 if (sender
== WIDGET (the_menubar
))
1236 info_cmd (); /* menu */
1238 info_cmd_no_menu (); /* shortcut or buttonbar */
1240 #ifdef ENABLE_BACKGROUND
1245 case CK_OptionsLayout
:
1248 case CK_OptionsAppearance
:
1255 link_cmd (LINK_HARDLINK
);
1257 case CK_PanelListing
:
1260 #ifdef LISTMODE_EDITOR
1268 case CK_MenuLastSelected
:
1269 menu_last_selected_cmd ();
1274 case CK_OptionsPanel
:
1275 panel_options_box ();
1278 case CK_SelectCodepage
:
1288 case CK_PanelQuickView
:
1289 if (sender
== WIDGET (the_menubar
))
1290 quick_view_cmd (); /* menu */
1292 quick_cmd_no_menu (); /* shortcut or buttonabr */
1300 case CK_LinkSymbolicRelative
:
1301 link_cmd (LINK_SYMLINK_RELATIVE
);
1319 case CK_SelectInvert
:
1320 res
= send_message (current_panel
, midnight_dlg
, MSG_ACTION
, command
, NULL
);
1326 smart_dirsize_cmd ();
1331 case CK_ExtendedKeyMap
:
1335 mc_event_raise (MCEVENT_GROUP_CORE
, "suspend", NULL
);
1340 case CK_LinkSymbolic
:
1341 link_cmd (LINK_SYMLINK_ABSOLUTE
);
1343 case CK_PanelListingSwitch
:
1344 toggle_listing_cmd ();
1347 toggle_show_hidden ();
1349 case CK_SplitVertHoriz
:
1350 toggle_panels_split ();
1353 panels_split_equal ();
1356 panels_split_more ();
1359 panels_split_less ();
1367 #ifdef ENABLE_VFS_UNDELFS
1373 user_file_menu_cmd ();
1382 /* don't close panels due to SIGINT */
1385 res
= MSG_NOT_HANDLED
;
1391 /* --------------------------------------------------------------------------------------------- */
1394 midnight_callback (Widget
* w
, Widget
* sender
, widget_msg_t msg
, int parm
, void *data
)
1407 /* We handle the special case of the output lines */
1408 if (mc_global
.tty
.console_flag
!= '\0' && output_lines
)
1409 show_console_contents (output_start_y
,
1410 LINES
- output_lines
- mc_global
.keybar_visible
-
1411 1, LINES
- mc_global
.keybar_visible
- 1);
1415 /* dlg_set_size() is surplus for this case */
1419 menubar_arrange (the_menubar
);
1423 /* We only need the first idle event to show user menu after start */
1424 widget_want_idle (w
, FALSE
);
1426 if (boot_current_is_left
)
1427 dlg_select_widget (get_panel_widget (0));
1429 dlg_select_widget (get_panel_widget (1));
1432 midnight_execute_cmd (NULL
, CK_UserMenu
);
1436 if (ctl_x_map_enabled
)
1438 ctl_x_map_enabled
= FALSE
;
1439 command
= keybind_lookup_keymap_command (main_x_map
, parm
);
1440 if (command
!= CK_IgnoreKey
)
1441 return midnight_execute_cmd (NULL
, command
);
1444 /* FIXME: should handle all menu shortcuts before this point */
1445 if (the_menubar
->is_active
)
1446 return MSG_NOT_HANDLED
;
1449 input_free_completions (cmdline
);
1455 /* HACK: don't execute command in the command line if Enter was pressed
1456 in the quick viewer panel. */
1457 /* TODO: currently, when one of panels is other than view_listing,
1458 current_panel points to view_listing panel all time independently of
1459 it's activity. Thus, we can't use get_current_type() here.
1460 current_panel should point to actualy current active panel
1461 independently of it's type. */
1462 if (current_panel
->active
== 0 && get_other_type () == view_quick
)
1463 return MSG_NOT_HANDLED
;
1465 for (i
= 0; cmdline
->buffer
[i
] != '\0' &&
1466 (cmdline
->buffer
[i
] == ' ' || cmdline
->buffer
[i
] == '\t'); i
++)
1469 if (cmdline
->buffer
[i
] != '\0')
1471 send_message (cmdline
, NULL
, MSG_KEY
, parm
, NULL
);
1475 input_insert (cmdline
, "", FALSE
);
1479 /* Ctrl-Enter and Alt-Enter */
1480 if (((parm
& ~(KEY_M_CTRL
| KEY_M_ALT
)) == '\n') && (parm
& (KEY_M_CTRL
| KEY_M_ALT
)))
1486 /* Ctrl-Shift-Enter */
1487 if (parm
== (KEY_M_CTRL
| KEY_M_SHIFT
| '\n'))
1489 midnight_put_panel_path (current_panel
);
1494 if ((!mc_global
.tty
.alternate_plus_minus
1495 || !(mc_global
.tty
.console_flag
!= '\0' || mc_global
.tty
.xterm_flag
)) && !quote
1496 && !current_panel
->searching
)
1498 if (!only_leading_plus_minus
)
1500 /* Special treatement, since the input line will eat them */
1502 return send_message (current_panel
, midnight_dlg
, MSG_ACTION
, CK_Select
, NULL
);
1504 if (parm
== '\\' || parm
== '-')
1505 return send_message (current_panel
, midnight_dlg
, MSG_ACTION
, CK_Unselect
,
1509 return send_message (current_panel
, midnight_dlg
, MSG_ACTION
, CK_SelectInvert
,
1512 else if (!command_prompt
|| cmdline
->buffer
[0] == '\0')
1514 /* Special treatement '+', '-', '\', '*' only when this is
1515 * first char on input line
1518 return send_message (current_panel
, midnight_dlg
, MSG_ACTION
, CK_Select
, NULL
);
1520 if (parm
== '\\' || parm
== '-')
1521 return send_message (current_panel
, midnight_dlg
, MSG_ACTION
, CK_Unselect
,
1525 return send_message (current_panel
, midnight_dlg
, MSG_ACTION
, CK_SelectInvert
,
1529 return MSG_NOT_HANDLED
;
1531 case MSG_HOTKEY_HANDLED
:
1532 if ((get_current_type () == view_listing
) && current_panel
->searching
)
1534 current_panel
->dirty
= 1; /* FIXME: unneeded? */
1535 send_message (current_panel
, NULL
, MSG_ACTION
, CK_SearchStop
, NULL
);
1539 case MSG_UNHANDLED_KEY
:
1541 cb_ret_t v
= MSG_NOT_HANDLED
;
1543 if (ctl_x_map_enabled
)
1545 ctl_x_map_enabled
= FALSE
;
1546 command
= keybind_lookup_keymap_command (main_x_map
, parm
);
1549 command
= keybind_lookup_keymap_command (main_map
, parm
);
1551 if (command
!= CK_IgnoreKey
)
1552 v
= midnight_execute_cmd (NULL
, command
);
1554 if (v
== MSG_NOT_HANDLED
&& command_prompt
)
1555 v
= send_message (cmdline
, NULL
, MSG_KEY
, parm
, NULL
);
1561 if (!the_menubar
->is_active
)
1562 update_dirty_panels ();
1566 /* Handle shortcuts, menu, and buttonbar. */
1567 return midnight_execute_cmd (sender
, parm
);
1574 return dlg_default_callback (w
, sender
, msg
, parm
, data
);
1578 /* --------------------------------------------------------------------------------------------- */
1579 /*** public functions ****************************************************************************/
1580 /* --------------------------------------------------------------------------------------------- */
1585 menu_set_name (left_menu
, panels_layout
.horizontal_split
? _("&Above") : _("&Left"));
1586 menu_set_name (right_menu
, panels_layout
.horizontal_split
? _("&Below") : _("&Right"));
1587 menubar_arrange (the_menubar
);
1588 menubar_set_visible (the_menubar
, menubar_visible
);
1591 /* --------------------------------------------------------------------------------------------- */
1594 midnight_set_buttonbar (WButtonBar
* b
)
1596 buttonbar_set_label (b
, 1, Q_ ("ButtonBar|Help"), main_map
, NULL
);
1597 buttonbar_set_label (b
, 2, Q_ ("ButtonBar|Menu"), main_map
, NULL
);
1598 buttonbar_set_label (b
, 3, Q_ ("ButtonBar|View"), main_map
, NULL
);
1599 buttonbar_set_label (b
, 4, Q_ ("ButtonBar|Edit"), main_map
, NULL
);
1600 buttonbar_set_label (b
, 5, Q_ ("ButtonBar|Copy"), main_map
, NULL
);
1601 buttonbar_set_label (b
, 6, Q_ ("ButtonBar|RenMov"), main_map
, NULL
);
1602 buttonbar_set_label (b
, 7, Q_ ("ButtonBar|Mkdir"), main_map
, NULL
);
1603 buttonbar_set_label (b
, 8, Q_ ("ButtonBar|Delete"), main_map
, NULL
);
1604 buttonbar_set_label (b
, 9, Q_ ("ButtonBar|PullDn"), main_map
, NULL
);
1605 buttonbar_set_label (b
, 10, Q_ ("ButtonBar|Quit"), main_map
, NULL
);
1608 /* --------------------------------------------------------------------------------------------- */
1610 * Return a random hint. If force is TRUE, ignore the timeout.
1614 get_random_hint (gboolean force
)
1616 static const guint64 update_period
= 60 * G_USEC_PER_SEC
;
1617 static guint64 tv
= 0;
1619 char *data
, *result
= NULL
, *eop
;
1623 /* Do not change hints more often than one minute */
1624 if (!force
&& !mc_time_elapsed (&tv
, update_period
))
1625 return g_strdup ("");
1627 data
= load_mc_home_file (mc_global
.share_data_dir
, MC_HINT
, NULL
, &len
);
1631 /* get a random entry */
1632 srand ((unsigned int) (tv
/ G_USEC_PER_SEC
));
1633 start
= ((size_t) rand ()) % (len
- 1);
1635 /* Search the start of paragraph */
1636 for (; start
!= 0; start
--)
1637 if (data
[start
] == '\n' && data
[start
+ 1] == '\n')
1643 /* Search the end of paragraph */
1644 for (eop
= data
+ start
; *eop
!= '\0'; eop
++)
1646 if (*eop
== '\n' && *(eop
+ 1) == '\n')
1655 /* hint files are stored in utf-8 */
1656 /* try convert hint file from utf-8 to terminal encoding */
1657 conv
= str_crt_conv_from ("UTF-8");
1658 if (conv
!= INVALID_CONV
)
1662 buffer
= g_string_sized_new (len
- start
);
1663 if (str_convert (conv
, &data
[start
], buffer
) != ESTR_FAILURE
)
1664 result
= g_string_free (buffer
, FALSE
);
1666 g_string_free (buffer
, TRUE
);
1667 str_close_conv (conv
);
1670 result
= g_strndup (data
+ start
, len
- start
);
1677 /* --------------------------------------------------------------------------------------------- */
1679 * Load new hint and display it.
1680 * IF force is not 0, ignore the timeout.
1684 load_hint (gboolean force
)
1688 if (WIDGET (the_hint
)->owner
== NULL
)
1691 if (!mc_global
.message_visible
)
1693 label_set_text (the_hint
, NULL
);
1697 hint
= get_random_hint (force
);
1707 char text
[BUF_SMALL
];
1709 g_snprintf (text
, sizeof (text
), _("GNU Midnight Commander %s\n"), VERSION
);
1714 /* --------------------------------------------------------------------------------------------- */
1719 input_free_completions (cmdline
);
1720 dlg_one_down (midnight_dlg
);
1723 /* --------------------------------------------------------------------------------------------- */
1725 /** Save current stat of directories to avoid reloading the panels
1726 * when no modifications have taken place
1729 save_cwds_stat (void)
1731 if (panels_options
.fast_reload
)
1733 mc_stat (current_panel
->cwd_vpath
, &(current_panel
->dir_stat
));
1734 if (get_other_type () == view_listing
)
1735 mc_stat (other_panel
->cwd_vpath
, &(other_panel
->dir_stat
));
1739 /* --------------------------------------------------------------------------------------------- */
1742 quiet_quit_cmd (void)
1744 print_last_revert
= TRUE
;
1745 return quit_cmd_internal (1);
1748 /* --------------------------------------------------------------------------------------------- */
1750 /** Run the main dialog that occupies the whole screen */
1756 #ifdef USE_INTERNAL_EDIT
1760 midnight_dlg
= dlg_create (FALSE
, 0, 0, LINES
, COLS
, dialog_colors
, midnight_callback
, NULL
,
1761 "[main]", NULL
, DLG_NONE
);
1763 /* Check if we were invoked as an editor or file viewer */
1764 if (mc_global
.mc_run_mode
!= MC_RUN_FULL
)
1767 ret
= mc_maybe_editor_or_viewer ();
1771 /* We only need the first idle event to show user menu after start */
1772 widget_want_idle (WIDGET (midnight_dlg
), TRUE
);
1775 mc_filehighlight
= mc_fhl_new (TRUE
);
1776 create_panels_and_run_mc ();
1777 mc_fhl_free (&mc_filehighlight
);
1781 /* dlg_destroy destroys even current_panel->cwd_vpath, so we have to save a copy :) */
1782 if (mc_args__last_wd_file
!= NULL
&& vfs_current_is_local ())
1783 last_wd_string
= g_strdup (vfs_path_as_str (current_panel
->cwd_vpath
));
1785 /* don't handle VFS timestamps for dirs opened in panels */
1786 mc_event_destroy (MCEVENT_GROUP_CORE
, "vfs_timestamp");
1788 dir_list_clean (&panelized_panel
.list
);
1792 mc_global
.midnight_shutdown
= TRUE
;
1793 dialog_switch_shutdown ();
1795 dlg_destroy (midnight_dlg
);
1796 current_panel
= NULL
;
1798 #ifdef USE_INTERNAL_EDIT
1802 if ((quit
& SUBSHELL_EXIT
) == 0)
1808 /* --------------------------------------------------------------------------------------------- */