2 Main dialog (file panels) of the Midnight Commander
4 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
5 2003, 2004, 2005, 2006, 2007, 2009, 2010, 2011
6 The Free Software Foundation, Inc.
9 Miguel de Icaza, 1994, 1995, 1996, 1997
10 Janne Kukonlehto, 1994, 1995
12 Andrew Borodin <aborodin@vmail.ru>, 2009, 2010
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
43 #include <sys/types.h>
46 #include <pwd.h> /* for username in xterm title */
48 #include "lib/global.h"
50 #include "lib/tty/tty.h"
51 #include "lib/tty/key.h" /* KEY_M_* masks */
55 #include "lib/vfs/vfs.h"
58 #include "src/subshell.h"
59 #include "src/setup.h" /* variables */
60 #include "src/learn.h" /* learn_keys() */
61 #include "src/keybind-defaults.h"
62 #include "lib/keybind.h"
63 #include "lib/event.h"
65 #include "option.h" /* configure_box() */
67 #include "boxes.h" /* sort_box(), tree_box() */
69 #include "cmd.h" /* commands */
72 #include "command.h" /* cmdline */
73 #include "dir.h" /* clean_dir() */
79 #ifdef USE_INTERNAL_EDIT
80 #include "src/editor/edit.h"
84 #include "src/diffviewer/ydiff.h"
87 #include "src/consaver/cons.saver.h" /* show_console_contents */
91 /* TODO: merge content of layout.c here */
92 extern int ok_to_refresh
;
94 /*** global variables ****************************************************************************/
96 /* When the modes are active, left_panel, right_panel and tree_panel */
97 /* point to a proper data structure. You should check with the functions */
98 /* get_current_type and get_other_type the types of the panels before using */
99 /* this pointer variables */
101 /* The structures for the panels */
102 WPanel
*left_panel
= NULL
;
103 WPanel
*right_panel
= NULL
;
104 /* Pointer to the selected and unselected panel */
105 WPanel
*current_panel
= NULL
;
108 WMenuBar
*the_menubar
= NULL
;
109 /* The widget where we draw the prompt */
116 /*** file scope macro definitions ****************************************************************/
120 * Don't restrict the output on the screen manager level,
121 * the translation tables take care of it.
123 #endif /* !HAVE_CHARSET */
125 /*** file scope type declarations ****************************************************************/
127 /*** file scope variables ************************************************************************/
129 static Menu
*left_menu
, *right_menu
;
131 static gboolean ctl_x_map_enabled
= FALSE
;
133 /*** file scope functions ************************************************************************/
135 /** Stop MC main dialog and the current dialog if it exists.
136 * Needed to provide fast exit from MC viewer or editor on shell exit */
140 midnight_dlg
->state
= DLG_CLOSED
;
142 if ((top_dlg
!= NULL
) && (top_dlg
->data
!= NULL
))
143 ((Dlg_head
*) top_dlg
->data
)->state
= DLG_CLOSED
;
146 /* --------------------------------------------------------------------------------------------- */
153 sel_dir
= tree_box (selection (current_panel
)->fname
);
156 vfs_path_t
*sel_vdir
;
158 sel_vdir
= vfs_path_from_str (sel_dir
);
159 do_cd (sel_vdir
, cd_exact
);
160 vfs_path_free (sel_vdir
);
165 /* --------------------------------------------------------------------------------------------- */
167 #ifdef LISTMODE_EDITOR
173 if (get_current_type () != view_listing
)
176 newmode
= listmode_edit (current_panel
->user_format
);
180 g_free (current_panel
->user_format
);
181 current_panel
->list_type
= list_user
;
182 current_panel
->user_format
= newmode
;
183 set_panel_formats (current_panel
);
187 #endif /* LISTMODE_EDITOR */
189 /* --------------------------------------------------------------------------------------------- */
192 create_panel_menu (void)
194 GList
*entries
= NULL
;
196 entries
= g_list_prepend (entries
, menu_entry_create (_("File listin&g"), CK_PanelListing
));
197 entries
= g_list_prepend (entries
, menu_entry_create (_("&Quick view"), CK_PanelQuickView
));
198 entries
= g_list_prepend (entries
, menu_entry_create (_("&Info"), CK_PanelInfo
));
199 entries
= g_list_prepend (entries
, menu_entry_create (_("&Tree"), CK_PanelTree
));
200 entries
= g_list_prepend (entries
, menu_separator_create ());
202 g_list_prepend (entries
, menu_entry_create (_("&Listing mode..."), CK_PanelListingChange
));
203 entries
= g_list_prepend (entries
, menu_entry_create (_("&Sort order..."), CK_Sort
));
204 entries
= g_list_prepend (entries
, menu_entry_create (_("&Filter..."), CK_Filter
));
206 entries
= g_list_prepend (entries
, menu_entry_create (_("&Encoding..."), CK_SelectCodepage
));
208 entries
= g_list_prepend (entries
, menu_separator_create ());
209 #ifdef ENABLE_VFS_FTP
210 entries
= g_list_prepend (entries
, menu_entry_create (_("FT&P link..."), CK_ConnectFtp
));
212 #ifdef ENABLE_VFS_FISH
213 entries
= g_list_prepend (entries
, menu_entry_create (_("S&hell link..."), CK_ConnectFish
));
215 #ifdef ENABLE_VFS_SMB
216 entries
= g_list_prepend (entries
, menu_entry_create (_("SM&B link..."), CK_ConnectSmb
));
218 entries
= g_list_prepend (entries
, menu_entry_create (_("Paneli&ze"), CK_Panelize
));
219 entries
= g_list_prepend (entries
, menu_separator_create ());
220 entries
= g_list_prepend (entries
, menu_entry_create (_("&Rescan"), CK_Reread
));
222 return g_list_reverse (entries
);
225 /* --------------------------------------------------------------------------------------------- */
228 create_file_menu (void)
230 GList
*entries
= NULL
;
232 entries
= g_list_prepend (entries
, menu_entry_create (_("&View"), CK_View
));
233 entries
= g_list_prepend (entries
, menu_entry_create (_("Vie&w file..."), CK_ViewFile
));
234 entries
= g_list_prepend (entries
, menu_entry_create (_("&Filtered view"), CK_ViewFiltered
));
235 entries
= g_list_prepend (entries
, menu_entry_create (_("&Edit"), CK_Edit
));
236 entries
= g_list_prepend (entries
, menu_entry_create (_("&Copy"), CK_Copy
));
237 entries
= g_list_prepend (entries
, menu_entry_create (_("C&hmod"), CK_ChangeMode
));
238 entries
= g_list_prepend (entries
, menu_entry_create (_("&Link"), CK_Link
));
239 entries
= g_list_prepend (entries
, menu_entry_create (_("&Symlink"), CK_LinkSymbolic
));
241 g_list_prepend (entries
,
242 menu_entry_create (_("Relative symlin&k"), CK_LinkSymbolicRelative
));
243 entries
= g_list_prepend (entries
, menu_entry_create (_("Edit s&ymlink"), CK_LinkSymbolicEdit
));
244 entries
= g_list_prepend (entries
, menu_entry_create (_("Ch&own"), CK_ChangeOwn
));
246 g_list_prepend (entries
, menu_entry_create (_("&Advanced chown"), CK_ChangeOwnAdvanced
));
247 entries
= g_list_prepend (entries
, menu_entry_create (_("&Rename/Move"), CK_Move
));
248 entries
= g_list_prepend (entries
, menu_entry_create (_("&Mkdir"), CK_MakeDir
));
249 entries
= g_list_prepend (entries
, menu_entry_create (_("&Delete"), CK_Delete
));
250 entries
= g_list_prepend (entries
, menu_entry_create (_("&Quick cd"), CK_CdQuick
));
251 entries
= g_list_prepend (entries
, menu_separator_create ());
252 entries
= g_list_prepend (entries
, menu_entry_create (_("Select &group"), CK_Select
));
253 entries
= g_list_prepend (entries
, menu_entry_create (_("U&nselect group"), CK_Unselect
));
254 entries
= g_list_prepend (entries
, menu_entry_create (_("&Invert selection"), CK_SelectInvert
));
255 entries
= g_list_prepend (entries
, menu_separator_create ());
256 entries
= g_list_prepend (entries
, menu_entry_create (_("E&xit"), CK_Quit
));
258 return g_list_reverse (entries
);
261 /* --------------------------------------------------------------------------------------------- */
264 create_command_menu (void)
266 /* I know, I'm lazy, but the tree widget when it's not running
267 * as a panel still has some problems, I have not yet finished
268 * the WTree widget port, sorry.
270 GList
*entries
= NULL
;
272 entries
= g_list_prepend (entries
, menu_entry_create (_("&User menu"), CK_UserMenu
));
273 entries
= g_list_prepend (entries
, menu_entry_create (_("&Directory tree"), CK_Tree
));
274 entries
= g_list_prepend (entries
, menu_entry_create (_("&Find file"), CK_Find
));
275 entries
= g_list_prepend (entries
, menu_entry_create (_("S&wap panels"), CK_Swap
));
276 entries
= g_list_prepend (entries
, menu_entry_create (_("Switch &panels on/off"), CK_Shell
));
278 g_list_prepend (entries
, menu_entry_create (_("&Compare directories"), CK_CompareDirs
));
280 entries
= g_list_prepend (entries
, menu_entry_create (_("C&ompare files"), CK_CompareFiles
));
283 g_list_prepend (entries
, menu_entry_create (_("E&xternal panelize"), CK_ExternalPanelize
));
284 entries
= g_list_prepend (entries
, menu_entry_create (_("Show directory s&izes"), CK_DirSize
));
285 entries
= g_list_prepend (entries
, menu_separator_create ());
286 entries
= g_list_prepend (entries
, menu_entry_create (_("Command &history"), CK_History
));
287 entries
= g_list_prepend (entries
, menu_entry_create (_("Di&rectory hotlist"), CK_HotList
));
289 entries
= g_list_prepend (entries
, menu_entry_create (_("&Active VFS list"), CK_VfsList
));
291 #ifdef WITH_BACKGROUND
292 entries
= g_list_prepend (entries
, menu_entry_create (_("&Background jobs"), CK_Jobs
));
294 entries
= g_list_prepend (entries
, menu_entry_create (_("Screen lis&t"), CK_ScreenList
));
295 entries
= g_list_prepend (entries
, menu_separator_create ());
296 #ifdef ENABLE_VFS_UNDELFS
298 g_list_prepend (entries
,
299 menu_entry_create (_("&Undelete files (ext2fs only)"), CK_Undelete
));
301 #ifdef LISTMODE_EDITOR
302 entries
= g_list_prepend (entries
, menu_entry_create (_("&Listing format edit"), CK_ListMode
));
304 #if defined (ENABLE_VFS_UNDELFS) || defined (LISTMODE_EDITOR)
305 entries
= g_list_prepend (entries
, menu_separator_create ());
308 g_list_prepend (entries
,
309 menu_entry_create (_("Edit &extension file"), CK_EditExtensionsFile
));
310 entries
= g_list_prepend (entries
, menu_entry_create (_("Edit &menu file"), CK_EditUserMenu
));
312 g_list_prepend (entries
,
313 menu_entry_create (_("Edit hi&ghlighting group file"),
314 CK_EditFileHighlightFile
));
316 return g_list_reverse (entries
);
319 /* --------------------------------------------------------------------------------------------- */
322 create_options_menu (void)
324 GList
*entries
= NULL
;
326 entries
= g_list_prepend (entries
, menu_entry_create (_("&Configuration..."), CK_Options
));
327 entries
= g_list_prepend (entries
, menu_entry_create (_("&Layout..."), CK_OptionsLayout
));
328 entries
= g_list_prepend (entries
, menu_entry_create (_("&Panel options..."), CK_OptionsPanel
));
330 g_list_prepend (entries
, menu_entry_create (_("C&onfirmation..."), CK_OptionsConfirm
));
332 g_list_prepend (entries
, menu_entry_create (_("&Display bits..."), CK_OptionsDisplayBits
));
333 entries
= g_list_prepend (entries
, menu_entry_create (_("Learn &keys..."), CK_LearnKeys
));
335 entries
= g_list_prepend (entries
, menu_entry_create (_("&Virtual FS..."), CK_OptionsVfs
));
337 entries
= g_list_prepend (entries
, menu_separator_create ());
338 entries
= g_list_prepend (entries
, menu_entry_create (_("&Save setup"), CK_SaveSetup
));
340 return g_list_reverse (entries
);
343 /* --------------------------------------------------------------------------------------------- */
348 left_menu
= create_menu ("", create_panel_menu (), "[Left and Right Menus]");
349 menubar_add_menu (the_menubar
, left_menu
);
350 menubar_add_menu (the_menubar
, create_menu (_("&File"), create_file_menu (), "[File Menu]"));
351 menubar_add_menu (the_menubar
,
352 create_menu (_("&Command"), create_command_menu (), "[Command Menu]"));
353 menubar_add_menu (the_menubar
,
354 create_menu (_("&Options"), create_options_menu (), "[Options Menu]"));
355 right_menu
= create_menu ("", create_panel_menu (), "[Left and Right Menus]");
356 menubar_add_menu (the_menubar
, right_menu
);
360 /* --------------------------------------------------------------------------------------------- */
363 menu_last_selected_cmd (void)
365 the_menubar
->is_active
= TRUE
;
366 the_menubar
->is_dropped
= (drop_menus
!= 0);
367 the_menubar
->previous_widget
= dlg_get_current_widget_id (midnight_dlg
);
368 dlg_select_widget (the_menubar
);
371 /* --------------------------------------------------------------------------------------------- */
376 if (the_menubar
->is_active
)
379 if ((get_current_index () == 0) == (current_panel
->active
!= 0))
380 the_menubar
->selected
= 0;
382 the_menubar
->selected
= g_list_length (the_menubar
->menu
) - 1;
383 menu_last_selected_cmd ();
386 /* --------------------------------------------------------------------------------------------- */
392 const panel_field_t
*sort_order
;
394 if (!SELECTED_IS_PANEL
)
398 sort_order
= sort_box (&p
->sort_info
);
399 panel_set_sort_order (p
, sort_order
);
402 /* --------------------------------------------------------------------------------------------- */
405 midnight_get_shortcut (unsigned long command
)
408 const char *shortcut
= NULL
;
410 shortcut
= keybind_lookup_keymap_shortcut (main_map
, command
);
411 if (shortcut
!= NULL
)
412 return g_strdup (shortcut
);
414 shortcut
= keybind_lookup_keymap_shortcut (panel_map
, command
);
415 if (shortcut
!= NULL
)
416 return g_strdup (shortcut
);
418 ext_map
= keybind_lookup_keymap_shortcut (main_map
, CK_ExtendedKeyMap
);
420 shortcut
= keybind_lookup_keymap_shortcut (main_x_map
, command
);
421 if (shortcut
!= NULL
)
422 return g_strdup_printf ("%s %s", ext_map
, shortcut
);
427 /* --------------------------------------------------------------------------------------------- */
430 midnight_get_title (const Dlg_head
* h
, size_t len
)
432 /* TODO: share code with update_xterm_title_path() */
434 char *path_origin
, *p
;
437 struct passwd
*pw
= NULL
;
444 vfs_path_to_str_flags (current_panel
->cwd_vpath
, 0, VPF_STRIP_HOME
| VPF_STRIP_PASSWORD
);
446 res
= gethostname (host
, sizeof (host
));
450 host
[sizeof (host
) - 1] = '\0';
452 pw
= getpwuid (getuid ());
454 login
= g_strdup_printf ("%s@%s", pw
->pw_name
, host
);
456 login
= g_strdup (host
);
458 p
= g_strdup_printf ("%s [%s]:%s", _("Panels:"), login
, path_origin
);
459 g_free (path_origin
);
460 path
= g_strdup (str_trunc (p
, len
- 4));
467 /* --------------------------------------------------------------------------------------------- */
470 toggle_panels_split (void)
472 panels_layout
.horizontal_split
= !panels_layout
.horizontal_split
;
477 /* --------------------------------------------------------------------------------------------- */
483 check_panel_timestamp (const WPanel
* panel
, panel_view_mode_t mode
, struct vfs_class
*vclass
,
486 if (mode
== view_listing
)
488 vfs_path_element_t
*path_element
;
490 path_element
= vfs_path_get_by_index (panel
->cwd_vpath
, -1);
492 if (path_element
->class != vclass
)
495 if (vfs_getid (panel
->cwd_vpath
) != id
)
501 /* --------------------------------------------------------------------------------------------- */
505 check_current_panel_timestamp (const gchar
* event_group_name
, const gchar
* event_name
,
506 gpointer init_data
, gpointer data
)
508 ev_vfs_stamp_create_t
*event_data
= (ev_vfs_stamp_create_t
*) data
;
510 (void) event_group_name
;
515 check_panel_timestamp (current_panel
, get_current_type (), event_data
->vclass
,
517 return !event_data
->ret
;
520 /* --------------------------------------------------------------------------------------------- */
524 check_other_panel_timestamp (const gchar
* event_group_name
, const gchar
* event_name
,
525 gpointer init_data
, gpointer data
)
527 ev_vfs_stamp_create_t
*event_data
= (ev_vfs_stamp_create_t
*) data
;
529 (void) event_group_name
;
534 check_panel_timestamp (other_panel
, get_other_type (), event_data
->vclass
, event_data
->id
);
535 return !event_data
->ret
;
537 #endif /* ENABLE_VFS */
539 /* --------------------------------------------------------------------------------------------- */
543 print_vfs_message (const gchar
* event_group_name
, const gchar
* event_name
,
544 gpointer init_data
, gpointer data
)
547 ev_vfs_print_message_t
*event_data
= (ev_vfs_print_message_t
*) data
;
549 (void) event_group_name
;
553 g_vsnprintf (str
, sizeof (str
), event_data
->msg
, event_data
->ap
);
555 if (mc_global
.widget
.midnight_shutdown
)
558 if (!mc_global
.message_visible
|| !the_hint
|| !the_hint
->widget
.owner
)
562 if (!nice_rotating_dash
|| (ok_to_refresh
<= 0))
565 /* Preserve current cursor position */
566 tty_getyx (&row
, &col
);
569 tty_setcolor (NORMAL_COLOR
);
570 tty_print_string (str_fit_to_term (str
, COLS
- 1, J_LEFT
));
572 /* Restore cursor position */
573 tty_gotoyx (row
, col
);
578 if (mc_global
.message_visible
)
584 /* --------------------------------------------------------------------------------------------- */
591 panel_view_mode_t current_mode
, other_mode
;
592 char *original_dir
= NULL
;
594 if (boot_current_is_left
)
598 current_mode
= startup_left_mode
;
599 other_mode
= startup_right_mode
;
605 current_mode
= startup_right_mode
;
606 other_mode
= startup_left_mode
;
608 /* Creates the left panel */
609 if (mc_run_param0
!= NULL
)
613 if (mc_run_param1
!= NULL
)
615 /* Ok, user has specified two dirs, save the original one,
616 * since we may not be able to chdir to the proper
617 * second directory later
619 original_dir
= vfs_get_current_dir ();
621 vpath
= vfs_path_from_str (mc_run_param0
);
623 vfs_path_free (vpath
);
625 set_display_type (current_index
, current_mode
);
627 /* The other panel */
628 if (mc_run_param1
!= NULL
)
630 const char *cd_dir
= (original_dir
!= NULL
) ? original_dir
: mc_run_param1
;
633 vpath
= vfs_path_from_str (cd_dir
);
635 vfs_path_free (vpath
);
637 g_free (original_dir
);
638 set_display_type (other_index
, other_mode
);
640 if (startup_left_mode
== view_listing
)
641 current_panel
= left_panel
;
642 else if (right_panel
!= NULL
)
643 current_panel
= right_panel
;
645 current_panel
= left_panel
;
648 mc_event_add (MCEVENT_GROUP_CORE
, "vfs_timestamp", check_other_panel_timestamp
, NULL
, NULL
);
649 mc_event_add (MCEVENT_GROUP_CORE
, "vfs_timestamp", check_current_panel_timestamp
, NULL
, NULL
);
650 #endif /* ENABLE_VFS */
652 mc_event_add (MCEVENT_GROUP_CORE
, "vfs_print_message", print_vfs_message
, NULL
, NULL
);
654 /* Create the nice widgets */
655 cmdline
= command_new (0, 0, 0);
656 the_prompt
= label_new (0, 0, mc_prompt
);
657 the_prompt
->transparent
= 1;
658 the_bar
= buttonbar_new (mc_global
.keybar_visible
);
660 the_hint
= label_new (0, 0, 0);
661 the_hint
->transparent
= 1;
662 the_hint
->auto_adjust_cols
= 0;
663 the_hint
->widget
.cols
= COLS
;
665 the_menubar
= menubar_new (0, 0, COLS
, NULL
);
668 /* --------------------------------------------------------------------------------------------- */
671 put_current_path (void)
677 cwd_path
= remove_encoding_from_path (current_panel
->cwd_vpath
);
678 command_insert (cmdline
, cwd_path
, FALSE
);
680 if (cwd_path
[strlen (cwd_path
) - 1] != PATH_SEP
)
681 command_insert (cmdline
, PATH_SEP_STR
, FALSE
);
685 /* --------------------------------------------------------------------------------------------- */
688 put_other_path (void)
692 if (get_other_type () != view_listing
)
698 cwd_path
= remove_encoding_from_path (other_panel
->cwd_vpath
);
699 command_insert (cmdline
, cwd_path
, FALSE
);
701 if (cwd_path
[strlen (cwd_path
) - 1] != PATH_SEP
)
702 command_insert (cmdline
, PATH_SEP_STR
, FALSE
);
706 /* --------------------------------------------------------------------------------------------- */
709 put_link (WPanel
* panel
)
713 if (S_ISLNK (selection (panel
)->st
.st_mode
))
715 char buffer
[MC_MAXPATHLEN
];
719 vpath
= vfs_path_append_new (panel
->cwd_vpath
, selection (panel
)->fname
, NULL
);
720 i
= mc_readlink (vpath
, buffer
, MC_MAXPATHLEN
- 1);
721 vfs_path_free (vpath
);
726 command_insert (cmdline
, buffer
, TRUE
);
731 /* --------------------------------------------------------------------------------------------- */
734 put_current_link (void)
736 put_link (current_panel
);
739 /* --------------------------------------------------------------------------------------------- */
742 put_other_link (void)
744 if (get_other_type () == view_listing
)
745 put_link (other_panel
);
748 /* --------------------------------------------------------------------------------------------- */
750 /** Insert the selected file name into the input line */
758 if (get_current_type () == view_tree
)
760 WTree
*tree
= (WTree
*) get_panel_widget (get_current_index ());
762 tmp
= vfs_path_to_str (tree_selected_name (tree
));
765 tmp
= g_strdup (selection (current_panel
)->fname
);
767 command_insert (cmdline
, tmp
, TRUE
);
771 /* --------------------------------------------------------------------------------------------- */
774 put_tagged (WPanel
* panel
)
780 input_disable_update (cmdline
);
783 for (i
= 0; i
< panel
->count
; i
++)
785 if (panel
->dir
.list
[i
].f
.marked
)
786 command_insert (cmdline
, panel
->dir
.list
[i
].fname
, TRUE
);
791 command_insert (cmdline
, panel
->dir
.list
[panel
->selected
].fname
, TRUE
);
793 input_enable_update (cmdline
);
796 /* --------------------------------------------------------------------------------------------- */
799 put_current_tagged (void)
801 put_tagged (current_panel
);
804 /* --------------------------------------------------------------------------------------------- */
807 put_other_tagged (void)
809 if (get_other_type () == view_listing
)
810 put_tagged (other_panel
);
813 /* --------------------------------------------------------------------------------------------- */
818 ctl_x_map_enabled
= TRUE
;
821 /* --------------------------------------------------------------------------------------------- */
828 tty_display_8bit (TRUE
);
830 tty_display_8bit (mc_global
.full_eight_bits
!= 0);
831 #endif /* HAVE_CHARSET */
833 #else /* HAVE_SLANG */
836 tty_display_8bit (TRUE
);
838 tty_display_8bit (mc_global
.eight_bit_clean
!= 0);
839 #endif /* HAVE_CHARSET */
840 #endif /* HAVE_SLANG */
842 #ifdef HAVE_SUBSHELL_SUPPORT
843 if (mc_global
.tty
.use_subshell
)
844 add_select_channel (mc_global
.tty
.subshell_pty
, load_prompt
, 0);
845 #endif /* !HAVE_SUBSHELL_SUPPORT */
847 if ((tty_baudrate () < 9600) || mc_global
.tty
.slow_terminal
)
851 /* --------------------------------------------------------------------------------------------- */
854 setup_dummy_mc (void)
862 vpath
= vfs_path_from_str (d
);
863 ret
= mc_chdir (vpath
);
864 vfs_path_free (vpath
);
868 /* --------------------------------------------------------------------------------------------- */
875 * We sync the profiles since the hotlist may have changed, while
876 * we only change the setup data if we have the auto save feature set
880 save_setup (auto_save_setup
, panels_options
.auto_save_setup
);
882 curr_dir
= vfs_get_current_dir ();
883 vfs_stamp_path (curr_dir
);
886 if ((current_panel
!= NULL
) && (get_current_type () == view_listing
))
890 tmp_path
= vfs_path_to_str (current_panel
->cwd_vpath
);
891 vfs_stamp_path (tmp_path
);
895 if ((other_panel
!= NULL
) && (get_other_type () == view_listing
))
899 tmp_path
= vfs_path_to_str (other_panel
->cwd_vpath
);
900 vfs_stamp_path (tmp_path
);
905 /* --------------------------------------------------------------------------------------------- */
908 create_panels_and_run_mc (void)
910 midnight_dlg
->get_shortcut
= midnight_get_shortcut
;
911 midnight_dlg
->get_title
= midnight_get_title
;
915 add_widget (midnight_dlg
, the_menubar
);
918 add_widget (midnight_dlg
, get_panel_widget (0));
919 add_widget (midnight_dlg
, get_panel_widget (1));
921 add_widget (midnight_dlg
, the_hint
);
922 add_widget (midnight_dlg
, cmdline
);
923 add_widget (midnight_dlg
, the_prompt
);
925 add_widget (midnight_dlg
, the_bar
);
926 midnight_set_buttonbar (the_bar
);
928 /* Run the Midnight Commander if no file was specified in the command line */
929 run_dlg (midnight_dlg
);
932 /* --------------------------------------------------------------------------------------------- */
934 /** result must be free'd (I think this should go in util.c) */
936 prepend_cwd_on_local (const char *filename
)
942 vpath
= vfs_path_from_str (filename
);
943 if (!vfs_file_is_local (vpath
) || g_path_is_absolute (filename
))
945 vfs_path_free (vpath
);
946 return g_strdup (filename
);
948 vfs_path_free (vpath
);
953 strcpy (d
+ l
, filename
);
954 canonicalize_pathname (d
);
958 /* --------------------------------------------------------------------------------------------- */
960 /** Invoke the internal view/edit routine with:
961 * the default processing and forcing the internal viewer/editor
964 mc_maybe_editor_or_viewer (void)
966 switch (mc_global
.mc_run_mode
)
968 #ifdef USE_INTERNAL_EDIT
971 vfs_path_t
*param_vpath
;
973 param_vpath
= vfs_path_from_str (mc_run_param0
);
974 edit_file (param_vpath
, mc_args__edit_start_line
);
975 vfs_path_free (param_vpath
);
978 #endif /* USE_INTERNAL_EDIT */
982 path
= prepend_cwd_on_local (mc_run_param0
);
983 view_file (path
, 0, 1);
988 case MC_RUN_DIFFVIEWER
:
989 diff_view (mc_run_param0
, mc_run_param1
, mc_run_param0
, mc_run_param1
);
991 #endif /* USE_DIFF_VIEW */
997 /* --------------------------------------------------------------------------------------------- */
1000 quit_cmd_internal (int quiet
)
1005 n
= dialog_switch_num () - 1;
1008 char msg
[BUF_MEDIUM
];
1010 g_snprintf (msg
, sizeof (msg
),
1011 ngettext ("You have %zd opened screen. Quit anyway?",
1012 "You have %zd opened screens. Quit anyway?", n
), n
);
1014 if (query_dialog (_("The Midnight Commander"), msg
, D_NORMAL
, 2, _("&Yes"), _("&No")) != 0)
1018 else if (quiet
|| !confirm_exit
)
1020 else if (query_dialog (_("The Midnight Commander"),
1021 _("Do you really want to quit the Midnight Commander?"),
1022 D_NORMAL
, 2, _("&Yes"), _("&No")) == 0)
1027 #ifdef HAVE_SUBSHELL_SUPPORT
1028 if (!mc_global
.tty
.use_subshell
)
1030 else if ((q
= exit_subshell ()))
1040 /* --------------------------------------------------------------------------------------------- */
1045 return quit_cmd_internal (0);
1048 /* --------------------------------------------------------------------------------------------- */
1051 toggle_show_hidden (void)
1053 panels_options
.show_dot_files
= !panels_options
.show_dot_files
;
1054 update_panels (UP_RELOAD
, UP_KEEPSEL
);
1057 /* --------------------------------------------------------------------------------------------- */
1060 * Repaint the contents of the panels without frames. To schedule panel
1061 * for repainting, set panel->dirty to 1. There are many reasons why
1062 * the panels need to be repainted, and this is a costly operation, so
1063 * it's done once per event.
1067 update_dirty_panels (void)
1069 if (get_current_type () == view_listing
&& current_panel
->dirty
)
1070 send_message ((Widget
*) current_panel
, WIDGET_DRAW
, 0);
1072 if (get_other_type () == view_listing
&& other_panel
->dirty
)
1073 send_message ((Widget
*) other_panel
, WIDGET_DRAW
, 0);
1076 /* --------------------------------------------------------------------------------------------- */
1079 midnight_execute_cmd (Widget
* sender
, unsigned long command
)
1081 cb_ret_t res
= MSG_HANDLED
;
1085 /* stop quick search before executing any command */
1086 send_message ((Widget
*) current_panel
, WIDGET_COMMAND
, CK_SearchStop
);
1093 case CK_PanelListingChange
:
1094 change_listing_cmd ();
1102 case CK_ChangeOwnAdvanced
:
1103 chown_advanced_cmd ();
1105 case CK_CompareDirs
:
1106 compare_dirs_cmd ();
1116 case CK_OptionsConfirm
:
1122 case CK_PutCurrentPath
:
1123 put_current_path ();
1125 case CK_PutCurrentLink
:
1126 put_current_link ();
1128 case CK_PutCurrentTagged
:
1129 put_current_tagged ();
1131 case CK_PutOtherPath
:
1134 case CK_PutOtherLink
:
1137 case CK_PutOtherTagged
:
1138 put_other_tagged ();
1144 dialog_switch_list ();
1146 #ifdef USE_DIFF_VIEW
1147 case CK_CompareFiles
:
1151 case CK_OptionsDisplayBits
:
1152 display_bits_box ();
1157 #ifdef USE_INTERNAL_EDIT
1158 case CK_EditForceInternal
:
1159 edit_cmd_force_internal ();
1162 case CK_EditExtensionsFile
:
1165 case CK_EditFileHighlightFile
:
1168 case CK_EditUserMenu
:
1169 edit_mc_menu_cmd ();
1171 case CK_LinkSymbolicEdit
:
1172 edit_symlink_cmd ();
1174 case CK_ExternalPanelize
:
1175 external_panelize ();
1180 case CK_ViewFiltered
:
1181 view_filtered_cmd ();
1186 #ifdef ENABLE_VFS_FISH
1187 case CK_ConnectFish
:
1191 #ifdef ENABLE_VFS_FTP
1196 #ifdef ENABLE_VFS_SMB
1200 #endif /* ENABLE_VFS_SMB */
1208 /* show the history of command line widget */
1209 send_message (&cmdline
->widget
, WIDGET_COMMAND
, CK_History
);
1212 if (sender
== (Widget
*) the_menubar
)
1213 info_cmd (); /* menu */
1215 info_cmd_no_menu (); /* shortcut or buttonbar */
1217 #ifdef WITH_BACKGROUND
1222 case CK_OptionsLayout
:
1229 link_cmd (LINK_HARDLINK
);
1231 case CK_PanelListing
:
1234 #ifdef LISTMODE_EDITOR
1242 case CK_MenuLastSelected
:
1243 menu_last_selected_cmd ();
1248 case CK_OptionsPanel
:
1249 panel_options_box ();
1252 case CK_SelectCodepage
:
1262 case CK_PanelQuickView
:
1263 if (sender
== (Widget
*) the_menubar
)
1264 quick_view_cmd (); /* menu */
1266 quick_cmd_no_menu (); /* shortcut or buttonabr */
1274 case CK_LinkSymbolicRelative
:
1275 link_cmd (LINK_SYMLINK_RELATIVE
);
1288 case CK_SelectInvert
:
1289 select_invert_cmd ();
1301 smart_dirsize_cmd ();
1306 case CK_ExtendedKeyMap
:
1310 mc_event_raise (MCEVENT_GROUP_CORE
, "suspend", NULL
);
1315 case CK_LinkSymbolic
:
1316 link_cmd (LINK_SYMLINK_ABSOLUTE
);
1318 case CK_PanelListingSwitch
:
1319 toggle_listing_cmd ();
1322 toggle_show_hidden ();
1324 case CK_SplitVertHoriz
:
1325 toggle_panels_split ();
1328 panels_split_equal ();
1331 panels_split_more ();
1334 panels_split_less ();
1342 #ifdef ENABLE_VFS_UNDELFS
1351 user_file_menu_cmd ();
1360 /* don't close panels due to SIGINT */
1363 res
= MSG_NOT_HANDLED
;
1369 /* --------------------------------------------------------------------------------------------- */
1372 midnight_callback (Dlg_head
* h
, Widget
* sender
, dlg_msg_t msg
, int parm
, void *data
)
1374 unsigned long command
;
1385 /* We handle the special case of the output lines */
1386 if (mc_global
.tty
.console_flag
!= '\0' && output_lines
)
1387 show_console_contents (output_start_y
,
1388 LINES
- output_lines
- mc_global
.keybar_visible
-
1389 1, LINES
- mc_global
.keybar_visible
- 1);
1394 menubar_arrange (the_menubar
);
1398 /* We only need the first idle event to show user menu after start */
1399 set_idle_proc (h
, 0);
1401 if (boot_current_is_left
)
1402 dlg_select_widget (get_panel_widget (0));
1404 dlg_select_widget (get_panel_widget (1));
1407 midnight_execute_cmd (NULL
, CK_UserMenu
);
1411 if (ctl_x_map_enabled
)
1413 ctl_x_map_enabled
= FALSE
;
1414 command
= keybind_lookup_keymap_command (main_x_map
, parm
);
1415 if (command
!= CK_IgnoreKey
)
1416 return midnight_execute_cmd (NULL
, command
);
1419 /* FIXME: should handle all menu shortcuts before this point */
1420 if (the_menubar
->is_active
)
1421 return MSG_NOT_HANDLED
;
1424 input_free_completions (cmdline
);
1430 for (i
= 0; cmdline
->buffer
[i
] != '\0' &&
1431 (cmdline
->buffer
[i
] == ' ' || cmdline
->buffer
[i
] == '\t'); i
++)
1434 if (cmdline
->buffer
[i
] != '\0')
1436 send_message ((Widget
*) cmdline
, WIDGET_KEY
, parm
);
1440 input_insert (cmdline
, "", FALSE
);
1444 /* Ctrl-Enter and Alt-Enter */
1445 if (((parm
& ~(KEY_M_CTRL
| KEY_M_ALT
)) == '\n') && (parm
& (KEY_M_CTRL
| KEY_M_ALT
)))
1451 /* Ctrl-Shift-Enter */
1452 if (parm
== (KEY_M_CTRL
| KEY_M_SHIFT
| '\n'))
1454 put_current_path ();
1459 if ((!mc_global
.tty
.alternate_plus_minus
1460 || !(mc_global
.tty
.console_flag
!= '\0' || mc_global
.tty
.xterm_flag
)) && !quote
1461 && !current_panel
->searching
)
1463 if (!only_leading_plus_minus
)
1465 /* Special treatement, since the input line will eat them */
1472 if (parm
== '\\' || parm
== '-')
1480 select_invert_cmd ();
1484 else if (!command_prompt
|| !cmdline
->buffer
[0])
1486 /* Special treatement '+', '-', '\', '*' only when this is
1487 * first char on input line
1496 if (parm
== '\\' || parm
== '-')
1504 select_invert_cmd ();
1509 return MSG_NOT_HANDLED
;
1511 case DLG_HOTKEY_HANDLED
:
1512 if ((get_current_type () == view_listing
) && current_panel
->searching
)
1514 current_panel
->dirty
= 1; /* FIXME: unneeded? */
1515 send_message ((Widget
*) current_panel
, WIDGET_COMMAND
, CK_SearchStop
);
1519 case DLG_UNHANDLED_KEY
:
1524 v
= send_message ((Widget
*) cmdline
, WIDGET_KEY
, parm
);
1525 if (v
== MSG_HANDLED
)
1529 if (ctl_x_map_enabled
)
1531 ctl_x_map_enabled
= FALSE
;
1532 command
= keybind_lookup_keymap_command (main_x_map
, parm
);
1535 command
= keybind_lookup_keymap_command (main_map
, parm
);
1537 return (command
== CK_IgnoreKey
) ? MSG_NOT_HANDLED
: midnight_execute_cmd (NULL
, command
);
1540 if (!the_menubar
->is_active
)
1541 update_dirty_panels ();
1547 return midnight_execute_cmd (NULL
, parm
);
1548 /* message from menu */
1549 if (sender
== (Widget
*) the_menubar
)
1550 return midnight_execute_cmd (sender
, parm
);
1551 /* message from buttonbar */
1552 if (sender
== (Widget
*) the_bar
)
1555 return send_message ((Widget
*) data
, WIDGET_COMMAND
, parm
);
1556 return midnight_execute_cmd (sender
, parm
);
1558 return MSG_NOT_HANDLED
;
1565 return default_dlg_callback (h
, sender
, msg
, parm
, data
);
1569 /* --------------------------------------------------------------------------------------------- */
1570 /*** public functions ****************************************************************************/
1571 /* --------------------------------------------------------------------------------------------- */
1576 menu_set_name (left_menu
, panels_layout
.horizontal_split
? _("&Above") : _("&Left"));
1577 menu_set_name (right_menu
, panels_layout
.horizontal_split
? _("&Below") : _("&Right"));
1578 menubar_arrange (the_menubar
);
1579 menubar_set_visible (the_menubar
, menubar_visible
);
1583 midnight_set_buttonbar (WButtonBar
* b
)
1585 buttonbar_set_label (b
, 1, Q_ ("ButtonBar|Help"), main_map
, NULL
);
1586 buttonbar_set_label (b
, 2, Q_ ("ButtonBar|Menu"), main_map
, NULL
);
1587 buttonbar_set_label (b
, 3, Q_ ("ButtonBar|View"), main_map
, NULL
);
1588 buttonbar_set_label (b
, 4, Q_ ("ButtonBar|Edit"), main_map
, NULL
);
1589 buttonbar_set_label (b
, 5, Q_ ("ButtonBar|Copy"), main_map
, NULL
);
1590 buttonbar_set_label (b
, 6, Q_ ("ButtonBar|RenMov"), main_map
, NULL
);
1591 buttonbar_set_label (b
, 7, Q_ ("ButtonBar|Mkdir"), main_map
, NULL
);
1592 buttonbar_set_label (b
, 8, Q_ ("ButtonBar|Delete"), main_map
, NULL
);
1593 buttonbar_set_label (b
, 9, Q_ ("ButtonBar|PullDn"), main_map
, NULL
);
1594 buttonbar_set_label (b
, 10, Q_ ("ButtonBar|Quit"), main_map
, NULL
);
1597 /* --------------------------------------------------------------------------------------------- */
1599 * Load new hint and display it.
1600 * IF force is not 0, ignore the timeout.
1604 load_hint (gboolean force
)
1608 if (the_hint
->widget
.owner
== NULL
)
1611 if (!mc_global
.message_visible
)
1613 label_set_text (the_hint
, NULL
);
1617 hint
= get_random_hint (force
);
1627 char text
[BUF_SMALL
];
1629 g_snprintf (text
, sizeof (text
), _("GNU Midnight Commander %s\n"), VERSION
);
1634 /* --------------------------------------------------------------------------------------------- */
1639 input_free_completions (cmdline
);
1640 dlg_one_down (midnight_dlg
);
1643 /* --------------------------------------------------------------------------------------------- */
1645 /** Save current stat of directories to avoid reloading the panels
1646 * when no modifications have taken place
1649 save_cwds_stat (void)
1651 if (panels_options
.fast_reload
)
1653 mc_stat (current_panel
->cwd_vpath
, &(current_panel
->dir_stat
));
1654 if (get_other_type () == view_listing
)
1655 mc_stat (other_panel
->cwd_vpath
, &(other_panel
->dir_stat
));
1659 /* --------------------------------------------------------------------------------------------- */
1662 quiet_quit_cmd (void)
1664 print_last_revert
= TRUE
;
1665 return quit_cmd_internal (1);
1668 /* --------------------------------------------------------------------------------------------- */
1670 /** Run the main dialog that occupies the whole screen */
1674 dlg_colors_t midnight_colors
;
1676 midnight_colors
[DLG_COLOR_NORMAL
] = mc_skin_color_get ("dialog", "_default_");
1677 midnight_colors
[DLG_COLOR_FOCUS
] = mc_skin_color_get ("dialog", "focus");
1678 midnight_colors
[DLG_COLOR_HOT_NORMAL
] = mc_skin_color_get ("dialog", "hotnormal");
1679 midnight_colors
[DLG_COLOR_HOT_FOCUS
] = mc_skin_color_get ("dialog", "hotfocus");
1680 midnight_colors
[DLG_COLOR_TITLE
] = mc_skin_color_get ("dialog", "title");
1682 #ifdef USE_INTERNAL_EDIT
1686 midnight_dlg
= create_dlg (FALSE
, 0, 0, LINES
, COLS
, midnight_colors
, midnight_callback
,
1687 "[main]", NULL
, DLG_WANT_IDLE
);
1689 if (mc_global
.mc_run_mode
== MC_RUN_FULL
)
1694 /* Check if we were invoked as an editor or file viewer */
1695 if (mc_global
.mc_run_mode
!= MC_RUN_FULL
)
1696 mc_maybe_editor_or_viewer ();
1699 create_panels_and_run_mc ();
1701 /* destroy_dlg destroys even current_panel->cwd_vpath, so we have to save a copy :) */
1702 if (mc_args__last_wd_file
!= NULL
&& vfs_current_is_local ())
1703 last_wd_string
= vfs_path_to_str (current_panel
->cwd_vpath
);
1705 /* don't handle VFS timestamps for dirs opened in panels */
1706 mc_event_destroy (MCEVENT_GROUP_CORE
, "vfs_timestamp");
1708 clean_dir (&panelized_panel
.list
, panelized_panel
.count
);
1712 mc_global
.widget
.midnight_shutdown
= TRUE
;
1713 dialog_switch_shutdown ();
1715 destroy_dlg (midnight_dlg
);
1716 current_panel
= NULL
;
1718 #ifdef USE_INTERNAL_EDIT
1722 if ((quit
& SUBSHELL_EXIT
) == 0)
1726 /* --------------------------------------------------------------------------------------------- */