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 do_cd (sel_dir
, cd_exact
);
161 /* --------------------------------------------------------------------------------------------- */
163 #ifdef LISTMODE_EDITOR
169 if (get_current_type () != view_listing
)
172 newmode
= listmode_edit (current_panel
->user_format
);
176 g_free (current_panel
->user_format
);
177 current_panel
->list_type
= list_user
;
178 current_panel
->user_format
= newmode
;
179 set_panel_formats (current_panel
);
183 #endif /* LISTMODE_EDITOR */
185 /* --------------------------------------------------------------------------------------------- */
188 create_panel_menu (void)
190 GList
*entries
= NULL
;
192 entries
= g_list_prepend (entries
, menu_entry_create (_("File listin&g"), CK_PanelListing
));
193 entries
= g_list_prepend (entries
, menu_entry_create (_("&Quick view"), CK_PanelQuickView
));
194 entries
= g_list_prepend (entries
, menu_entry_create (_("&Info"), CK_PanelInfo
));
195 entries
= g_list_prepend (entries
, menu_entry_create (_("&Tree"), CK_PanelTree
));
196 entries
= g_list_prepend (entries
, menu_separator_create ());
198 g_list_prepend (entries
, menu_entry_create (_("&Listing mode..."), CK_PanelListingChange
));
199 entries
= g_list_prepend (entries
, menu_entry_create (_("&Sort order..."), CK_Sort
));
200 entries
= g_list_prepend (entries
, menu_entry_create (_("&Filter..."), CK_Filter
));
202 entries
= g_list_prepend (entries
, menu_entry_create (_("&Encoding..."), CK_SelectCodepage
));
204 entries
= g_list_prepend (entries
, menu_separator_create ());
205 #ifdef ENABLE_VFS_FTP
206 entries
= g_list_prepend (entries
, menu_entry_create (_("FT&P link..."), CK_ConnectFtp
));
208 #ifdef ENABLE_VFS_FISH
209 entries
= g_list_prepend (entries
, menu_entry_create (_("S&hell link..."), CK_ConnectFish
));
211 #ifdef ENABLE_VFS_SMB
212 entries
= g_list_prepend (entries
, menu_entry_create (_("SM&B link..."), CK_ConnectSmb
));
214 entries
= g_list_prepend (entries
, menu_entry_create (_("Paneli&ze"), CK_Panelize
));
215 entries
= g_list_prepend (entries
, menu_separator_create ());
216 entries
= g_list_prepend (entries
, menu_entry_create (_("&Rescan"), CK_Reread
));
218 return g_list_reverse (entries
);
221 /* --------------------------------------------------------------------------------------------- */
224 create_file_menu (void)
226 GList
*entries
= NULL
;
228 entries
= g_list_prepend (entries
, menu_entry_create (_("&View"), CK_View
));
229 entries
= g_list_prepend (entries
, menu_entry_create (_("Vie&w file..."), CK_ViewFile
));
230 entries
= g_list_prepend (entries
, menu_entry_create (_("&Filtered view"), CK_ViewFiltered
));
231 entries
= g_list_prepend (entries
, menu_entry_create (_("&Edit"), CK_Edit
));
232 entries
= g_list_prepend (entries
, menu_entry_create (_("&Copy"), CK_Copy
));
233 entries
= g_list_prepend (entries
, menu_entry_create (_("C&hmod"), CK_ChangeMode
));
234 entries
= g_list_prepend (entries
, menu_entry_create (_("&Link"), CK_Link
));
235 entries
= g_list_prepend (entries
, menu_entry_create (_("&Symlink"), CK_LinkSymbolic
));
237 g_list_prepend (entries
,
238 menu_entry_create (_("Relative symlin&k"), CK_LinkSymbolicRelative
));
239 entries
= g_list_prepend (entries
, menu_entry_create (_("Edit s&ymlink"), CK_LinkSymbolicEdit
));
240 entries
= g_list_prepend (entries
, menu_entry_create (_("Ch&own"), CK_ChangeOwn
));
242 g_list_prepend (entries
, menu_entry_create (_("&Advanced chown"), CK_ChangeOwnAdvanced
));
243 entries
= g_list_prepend (entries
, menu_entry_create (_("&Rename/Move"), CK_Move
));
244 entries
= g_list_prepend (entries
, menu_entry_create (_("&Mkdir"), CK_MakeDir
));
245 entries
= g_list_prepend (entries
, menu_entry_create (_("&Delete"), CK_Delete
));
246 entries
= g_list_prepend (entries
, menu_entry_create (_("&Quick cd"), CK_CdQuick
));
247 entries
= g_list_prepend (entries
, menu_separator_create ());
248 entries
= g_list_prepend (entries
, menu_entry_create (_("Select &group"), CK_Select
));
249 entries
= g_list_prepend (entries
, menu_entry_create (_("U&nselect group"), CK_Unselect
));
250 entries
= g_list_prepend (entries
, menu_entry_create (_("&Invert selection"), CK_SelectInvert
));
251 entries
= g_list_prepend (entries
, menu_separator_create ());
252 entries
= g_list_prepend (entries
, menu_entry_create (_("E&xit"), CK_Quit
));
254 return g_list_reverse (entries
);
257 /* --------------------------------------------------------------------------------------------- */
260 create_command_menu (void)
262 /* I know, I'm lazy, but the tree widget when it's not running
263 * as a panel still has some problems, I have not yet finished
264 * the WTree widget port, sorry.
266 GList
*entries
= NULL
;
268 entries
= g_list_prepend (entries
, menu_entry_create (_("&User menu"), CK_UserMenu
));
269 entries
= g_list_prepend (entries
, menu_entry_create (_("&Directory tree"), CK_Tree
));
270 entries
= g_list_prepend (entries
, menu_entry_create (_("&Find file"), CK_Find
));
271 entries
= g_list_prepend (entries
, menu_entry_create (_("S&wap panels"), CK_Swap
));
272 entries
= g_list_prepend (entries
, menu_entry_create (_("Switch &panels on/off"), CK_Shell
));
274 g_list_prepend (entries
, menu_entry_create (_("&Compare directories"), CK_CompareDirs
));
276 entries
= g_list_prepend (entries
, menu_entry_create (_("C&ompare files"), CK_CompareFiles
));
279 g_list_prepend (entries
, menu_entry_create (_("E&xternal panelize"), CK_ExternalPanelize
));
280 entries
= g_list_prepend (entries
, menu_entry_create (_("Show directory s&izes"), CK_DirSize
));
281 entries
= g_list_prepend (entries
, menu_separator_create ());
282 entries
= g_list_prepend (entries
, menu_entry_create (_("Command &history"), CK_History
));
283 entries
= g_list_prepend (entries
, menu_entry_create (_("Di&rectory hotlist"), CK_HotList
));
285 entries
= g_list_prepend (entries
, menu_entry_create (_("&Active VFS list"), CK_VfsList
));
287 #ifdef ENABLE_BACKGROUND
288 entries
= g_list_prepend (entries
, menu_entry_create (_("&Background jobs"), CK_Jobs
));
290 entries
= g_list_prepend (entries
, menu_entry_create (_("Screen lis&t"), CK_ScreenList
));
291 entries
= g_list_prepend (entries
, menu_separator_create ());
292 #ifdef ENABLE_VFS_UNDELFS
294 g_list_prepend (entries
,
295 menu_entry_create (_("&Undelete files (ext2fs only)"), CK_Undelete
));
297 #ifdef LISTMODE_EDITOR
298 entries
= g_list_prepend (entries
, menu_entry_create (_("&Listing format edit"), CK_ListMode
));
300 #if defined (ENABLE_VFS_UNDELFS) || defined (LISTMODE_EDITOR)
301 entries
= g_list_prepend (entries
, menu_separator_create ());
304 g_list_prepend (entries
,
305 menu_entry_create (_("Edit &extension file"), CK_EditExtensionsFile
));
306 entries
= g_list_prepend (entries
, menu_entry_create (_("Edit &menu file"), CK_EditUserMenu
));
308 g_list_prepend (entries
,
309 menu_entry_create (_("Edit hi&ghlighting group file"),
310 CK_EditFileHighlightFile
));
312 return g_list_reverse (entries
);
315 /* --------------------------------------------------------------------------------------------- */
318 create_options_menu (void)
320 GList
*entries
= NULL
;
322 entries
= g_list_prepend (entries
, menu_entry_create (_("&Configuration..."), CK_Options
));
323 entries
= g_list_prepend (entries
, menu_entry_create (_("&Layout..."), CK_OptionsLayout
));
324 entries
= g_list_prepend (entries
, menu_entry_create (_("&Panel options..."), CK_OptionsPanel
));
326 g_list_prepend (entries
, menu_entry_create (_("C&onfirmation..."), CK_OptionsConfirm
));
328 g_list_prepend (entries
, menu_entry_create (_("&Display bits..."), CK_OptionsDisplayBits
));
329 entries
= g_list_prepend (entries
, menu_entry_create (_("Learn &keys..."), CK_LearnKeys
));
331 entries
= g_list_prepend (entries
, menu_entry_create (_("&Virtual FS..."), CK_OptionsVfs
));
333 entries
= g_list_prepend (entries
, menu_separator_create ());
334 entries
= g_list_prepend (entries
, menu_entry_create (_("&Save setup"), CK_SaveSetup
));
336 return g_list_reverse (entries
);
339 /* --------------------------------------------------------------------------------------------- */
344 left_menu
= create_menu ("", create_panel_menu (), "[Left and Right Menus]");
345 menubar_add_menu (the_menubar
, left_menu
);
346 menubar_add_menu (the_menubar
, create_menu (_("&File"), create_file_menu (), "[File Menu]"));
347 menubar_add_menu (the_menubar
,
348 create_menu (_("&Command"), create_command_menu (), "[Command Menu]"));
349 menubar_add_menu (the_menubar
,
350 create_menu (_("&Options"), create_options_menu (), "[Options Menu]"));
351 right_menu
= create_menu ("", create_panel_menu (), "[Left and Right Menus]");
352 menubar_add_menu (the_menubar
, right_menu
);
356 /* --------------------------------------------------------------------------------------------- */
359 menu_last_selected_cmd (void)
361 the_menubar
->is_active
= TRUE
;
362 the_menubar
->is_dropped
= (drop_menus
!= 0);
363 the_menubar
->previous_widget
= dlg_get_current_widget_id (midnight_dlg
);
364 dlg_select_widget (the_menubar
);
367 /* --------------------------------------------------------------------------------------------- */
372 if (the_menubar
->is_active
)
375 if ((get_current_index () == 0) == (current_panel
->active
!= 0))
376 the_menubar
->selected
= 0;
378 the_menubar
->selected
= g_list_length (the_menubar
->menu
) - 1;
379 menu_last_selected_cmd ();
382 /* --------------------------------------------------------------------------------------------- */
388 const panel_field_t
*sort_order
;
390 if (!SELECTED_IS_PANEL
)
394 sort_order
= sort_box (&p
->sort_info
);
395 panel_set_sort_order (p
, sort_order
);
398 /* --------------------------------------------------------------------------------------------- */
401 midnight_get_shortcut (unsigned long command
)
404 const char *shortcut
= NULL
;
406 shortcut
= keybind_lookup_keymap_shortcut (main_map
, command
);
407 if (shortcut
!= NULL
)
408 return g_strdup (shortcut
);
410 shortcut
= keybind_lookup_keymap_shortcut (panel_map
, command
);
411 if (shortcut
!= NULL
)
412 return g_strdup (shortcut
);
414 ext_map
= keybind_lookup_keymap_shortcut (main_map
, CK_ExtendedKeyMap
);
416 shortcut
= keybind_lookup_keymap_shortcut (main_x_map
, command
);
417 if (shortcut
!= NULL
)
418 return g_strdup_printf ("%s %s", ext_map
, shortcut
);
423 /* --------------------------------------------------------------------------------------------- */
426 midnight_get_title (const Dlg_head
* h
, size_t len
)
428 /* TODO: share code with update_xterm_title_path() */
433 struct passwd
*pw
= NULL
;
439 path
= strip_home_and_password (current_panel
->cwd
);
440 res
= gethostname (host
, sizeof (host
));
444 host
[sizeof (host
) - 1] = '\0';
446 pw
= getpwuid (getuid ());
448 login
= g_strdup_printf ("%s@%s", pw
->pw_name
, host
);
450 login
= g_strdup (host
);
452 p
= g_strdup_printf ("%s [%s]:%s", _("Panels:"), login
, path
);
453 path
= str_trunc (p
, len
- 4);
457 return g_strdup (path
);
460 /* --------------------------------------------------------------------------------------------- */
463 toggle_panels_split (void)
465 panels_layout
.horizontal_split
= !panels_layout
.horizontal_split
;
470 /* --------------------------------------------------------------------------------------------- */
475 check_panel_timestamp (const WPanel
* panel
, panel_view_mode_t mode
, struct vfs_class
*vclass
,
478 if (mode
== view_listing
)
481 vfs_path_element_t
*path_element
;
483 vpath
= vfs_path_from_str (panel
->cwd
);
484 path_element
= vfs_path_get_by_index (vpath
, -1);
486 if (path_element
->class != vclass
)
488 vfs_path_free (vpath
);
492 if (vfs_getid (vpath
) != id
)
494 vfs_path_free (vpath
);
497 vfs_path_free (vpath
);
502 /* --------------------------------------------------------------------------------------------- */
506 check_current_panel_timestamp (const gchar
* event_group_name
, const gchar
* event_name
,
507 gpointer init_data
, gpointer data
)
509 ev_vfs_stamp_create_t
*event_data
= (ev_vfs_stamp_create_t
*) data
;
511 (void) event_group_name
;
516 check_panel_timestamp (current_panel
, get_current_type (), event_data
->vclass
,
518 return !event_data
->ret
;
521 /* --------------------------------------------------------------------------------------------- */
525 check_other_panel_timestamp (const gchar
* event_group_name
, const gchar
* event_name
,
526 gpointer init_data
, gpointer data
)
528 ev_vfs_stamp_create_t
*event_data
= (ev_vfs_stamp_create_t
*) data
;
530 (void) event_group_name
;
535 check_panel_timestamp (other_panel
, get_other_type (), event_data
->vclass
, event_data
->id
);
536 return !event_data
->ret
;
538 #endif /* ENABLE_VFS */
540 /* --------------------------------------------------------------------------------------------- */
544 print_vfs_message (const gchar
* event_group_name
, const gchar
* event_name
,
545 gpointer init_data
, gpointer data
)
548 ev_vfs_print_message_t
*event_data
= (ev_vfs_print_message_t
*) data
;
550 (void) event_group_name
;
554 g_vsnprintf (str
, sizeof (str
), event_data
->msg
, event_data
->ap
);
556 if (mc_global
.midnight_shutdown
)
559 if (!mc_global
.message_visible
|| !the_hint
|| !the_hint
->widget
.owner
)
563 if (!nice_rotating_dash
|| (ok_to_refresh
<= 0))
566 /* Preserve current cursor position */
567 tty_getyx (&row
, &col
);
570 tty_setcolor (NORMAL_COLOR
);
571 tty_print_string (str_fit_to_term (str
, COLS
- 1, J_LEFT
));
573 /* Restore cursor position */
574 tty_gotoyx (row
, col
);
579 if (mc_global
.message_visible
)
585 /* --------------------------------------------------------------------------------------------- */
592 panel_view_mode_t current_mode
, other_mode
;
593 char original_dir
[BUF_1K
] = "\0";
595 if (boot_current_is_left
)
599 current_mode
= startup_left_mode
;
600 other_mode
= startup_right_mode
;
606 current_mode
= startup_right_mode
;
607 other_mode
= startup_left_mode
;
609 /* Creates the left panel */
610 if (mc_run_param0
!= NULL
)
614 if (mc_run_param1
!= NULL
)
616 /* Ok, user has specified two dirs, save the original one,
617 * since we may not be able to chdir to the proper
618 * second directory later
620 mc_get_current_wd (original_dir
, sizeof (original_dir
) - 2);
622 vpath
= vfs_path_from_str (mc_run_param0
);
624 vfs_path_free (vpath
);
626 set_display_type (current_index
, current_mode
);
628 /* The other panel */
629 if (mc_run_param1
!= NULL
)
631 const char *cd_dir
= (original_dir
!= NULL
) ? original_dir
: mc_run_param1
;
634 vpath
= vfs_path_from_str (cd_dir
);
636 vfs_path_free (vpath
);
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
);
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
);
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_build_filename (panel
->cwd
, 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 ());
761 tmp
= tree_selected_name (tree
);
764 tmp
= selection (current_panel
)->fname
;
766 command_insert (cmdline
, tmp
, TRUE
);
769 /* --------------------------------------------------------------------------------------------- */
772 put_tagged (WPanel
* panel
)
778 input_disable_update (cmdline
);
781 for (i
= 0; i
< panel
->count
; i
++)
783 if (panel
->dir
.list
[i
].f
.marked
)
784 command_insert (cmdline
, panel
->dir
.list
[i
].fname
, TRUE
);
789 command_insert (cmdline
, panel
->dir
.list
[panel
->selected
].fname
, TRUE
);
791 input_enable_update (cmdline
);
794 /* --------------------------------------------------------------------------------------------- */
797 put_current_tagged (void)
799 put_tagged (current_panel
);
802 /* --------------------------------------------------------------------------------------------- */
805 put_other_tagged (void)
807 if (get_other_type () == view_listing
)
808 put_tagged (other_panel
);
811 /* --------------------------------------------------------------------------------------------- */
816 ctl_x_map_enabled
= TRUE
;
819 /* --------------------------------------------------------------------------------------------- */
826 tty_display_8bit (TRUE
);
828 tty_display_8bit (mc_global
.full_eight_bits
!= 0);
829 #endif /* HAVE_CHARSET */
831 #else /* HAVE_SLANG */
834 tty_display_8bit (TRUE
);
836 tty_display_8bit (mc_global
.eight_bit_clean
!= 0);
837 #endif /* HAVE_CHARSET */
838 #endif /* HAVE_SLANG */
840 #ifdef HAVE_SUBSHELL_SUPPORT
841 if (mc_global
.tty
.use_subshell
)
842 add_select_channel (mc_global
.tty
.subshell_pty
, load_prompt
, 0);
843 #endif /* !HAVE_SUBSHELL_SUPPORT */
845 if ((tty_baudrate () < 9600) || mc_global
.tty
.slow_terminal
)
849 /* --------------------------------------------------------------------------------------------- */
852 setup_dummy_mc (void)
855 char d
[MC_MAXPATHLEN
];
858 mc_get_current_wd (d
, MC_MAXPATHLEN
);
860 vpath
= vfs_path_from_str (d
);
861 ret
= mc_chdir (vpath
);
862 vfs_path_free (vpath
);
865 /* --------------------------------------------------------------------------------------------- */
872 * We sync the profiles since the hotlist may have changed, while
873 * we only change the setup data if we have the auto save feature set
877 save_setup (auto_save_setup
, panels_options
.auto_save_setup
);
879 curr_dir
= vfs_get_current_dir ();
880 vfs_stamp_path (curr_dir
);
883 if ((current_panel
!= NULL
) && (get_current_type () == view_listing
))
884 vfs_stamp_path (current_panel
->cwd
);
886 if ((other_panel
!= NULL
) && (get_other_type () == view_listing
))
887 vfs_stamp_path (other_panel
->cwd
);
890 /* --------------------------------------------------------------------------------------------- */
893 create_panels_and_run_mc (void)
895 midnight_dlg
->get_shortcut
= midnight_get_shortcut
;
896 midnight_dlg
->get_title
= midnight_get_title
;
900 add_widget (midnight_dlg
, the_menubar
);
903 add_widget (midnight_dlg
, get_panel_widget (0));
904 add_widget (midnight_dlg
, get_panel_widget (1));
906 add_widget (midnight_dlg
, the_hint
);
907 add_widget (midnight_dlg
, cmdline
);
908 add_widget (midnight_dlg
, the_prompt
);
910 add_widget (midnight_dlg
, the_bar
);
911 midnight_set_buttonbar (the_bar
);
913 /* Run the Midnight Commander if no file was specified in the command line */
914 run_dlg (midnight_dlg
);
917 /* --------------------------------------------------------------------------------------------- */
919 /** result must be free'd (I think this should go in util.c) */
921 prepend_cwd_on_local (const char *filename
)
927 vpath
= vfs_path_from_str (filename
);
928 if (!vfs_file_is_local (vpath
) || g_path_is_absolute (filename
))
930 vfs_path_free (vpath
);
931 return g_strdup (filename
);
933 vfs_path_free (vpath
);
935 d
= g_malloc (MC_MAXPATHLEN
+ strlen (filename
) + 2);
936 mc_get_current_wd (d
, MC_MAXPATHLEN
);
939 strcpy (d
+ l
, filename
);
940 canonicalize_pathname (d
);
944 /* --------------------------------------------------------------------------------------------- */
946 /** Invoke the internal view/edit routine with:
947 * the default processing and forcing the internal viewer/editor
950 mc_maybe_editor_or_viewer (void)
954 switch (mc_global
.mc_run_mode
)
956 #ifdef USE_INTERNAL_EDIT
958 ret
= edit_file (mc_run_param0
, mc_args__edit_start_line
);
960 #endif /* USE_INTERNAL_EDIT */
965 path
= prepend_cwd_on_local (mc_run_param0
);
966 view_file (path
, 0, 1);
972 case MC_RUN_DIFFVIEWER
:
973 ret
= diff_view (mc_run_param0
, mc_run_param1
, mc_run_param0
, mc_run_param1
);
975 #endif /* USE_DIFF_VIEW */
983 /* --------------------------------------------------------------------------------------------- */
986 quit_cmd_internal (int quiet
)
991 n
= dialog_switch_num () - 1;
994 char msg
[BUF_MEDIUM
];
996 g_snprintf (msg
, sizeof (msg
),
997 ngettext ("You have %zd opened screen. Quit anyway?",
998 "You have %zd opened screens. Quit anyway?", n
), n
);
1000 if (query_dialog (_("The Midnight Commander"), msg
, D_NORMAL
, 2, _("&Yes"), _("&No")) != 0)
1004 else if (quiet
|| !confirm_exit
)
1006 else if (query_dialog (_("The Midnight Commander"),
1007 _("Do you really want to quit the Midnight Commander?"),
1008 D_NORMAL
, 2, _("&Yes"), _("&No")) == 0)
1013 #ifdef HAVE_SUBSHELL_SUPPORT
1014 if (!mc_global
.tty
.use_subshell
)
1016 else if ((q
= exit_subshell ()))
1026 /* --------------------------------------------------------------------------------------------- */
1031 return quit_cmd_internal (0);
1034 /* --------------------------------------------------------------------------------------------- */
1037 toggle_show_hidden (void)
1039 panels_options
.show_dot_files
= !panels_options
.show_dot_files
;
1040 update_panels (UP_RELOAD
, UP_KEEPSEL
);
1043 /* --------------------------------------------------------------------------------------------- */
1046 * Repaint the contents of the panels without frames. To schedule panel
1047 * for repainting, set panel->dirty to 1. There are many reasons why
1048 * the panels need to be repainted, and this is a costly operation, so
1049 * it's done once per event.
1053 update_dirty_panels (void)
1055 if (get_current_type () == view_listing
&& current_panel
->dirty
)
1056 send_message ((Widget
*) current_panel
, WIDGET_DRAW
, 0);
1058 if (get_other_type () == view_listing
&& other_panel
->dirty
)
1059 send_message ((Widget
*) other_panel
, WIDGET_DRAW
, 0);
1062 /* --------------------------------------------------------------------------------------------- */
1065 midnight_execute_cmd (Widget
* sender
, unsigned long command
)
1067 cb_ret_t res
= MSG_HANDLED
;
1071 /* stop quick search before executing any command */
1072 send_message ((Widget
*) current_panel
, WIDGET_COMMAND
, CK_SearchStop
);
1079 case CK_PanelListingChange
:
1080 change_listing_cmd ();
1088 case CK_ChangeOwnAdvanced
:
1089 chown_advanced_cmd ();
1091 case CK_CompareDirs
:
1092 compare_dirs_cmd ();
1102 case CK_OptionsConfirm
:
1108 case CK_PutCurrentPath
:
1109 put_current_path ();
1111 case CK_PutCurrentLink
:
1112 put_current_link ();
1114 case CK_PutCurrentTagged
:
1115 put_current_tagged ();
1117 case CK_PutOtherPath
:
1120 case CK_PutOtherLink
:
1123 case CK_PutOtherTagged
:
1124 put_other_tagged ();
1130 dialog_switch_list ();
1132 #ifdef USE_DIFF_VIEW
1133 case CK_CompareFiles
:
1137 case CK_OptionsDisplayBits
:
1138 display_bits_box ();
1143 #ifdef USE_INTERNAL_EDIT
1144 case CK_EditForceInternal
:
1145 edit_cmd_force_internal ();
1148 case CK_EditExtensionsFile
:
1151 case CK_EditFileHighlightFile
:
1154 case CK_EditUserMenu
:
1155 edit_mc_menu_cmd ();
1157 case CK_LinkSymbolicEdit
:
1158 edit_symlink_cmd ();
1160 case CK_ExternalPanelize
:
1161 external_panelize ();
1166 case CK_ViewFiltered
:
1167 view_filtered_cmd ();
1172 #ifdef ENABLE_VFS_FISH
1173 case CK_ConnectFish
:
1177 #ifdef ENABLE_VFS_FTP
1182 #ifdef ENABLE_VFS_SMB
1186 #endif /* ENABLE_VFS_SMB */
1194 /* show the history of command line widget */
1195 send_message (&cmdline
->widget
, WIDGET_COMMAND
, CK_History
);
1198 if (sender
== (Widget
*) the_menubar
)
1199 info_cmd (); /* menu */
1201 info_cmd_no_menu (); /* shortcut or buttonbar */
1203 #ifdef ENABLE_BACKGROUND
1208 case CK_OptionsLayout
:
1215 link_cmd (LINK_HARDLINK
);
1217 case CK_PanelListing
:
1220 #ifdef LISTMODE_EDITOR
1228 case CK_MenuLastSelected
:
1229 menu_last_selected_cmd ();
1234 case CK_OptionsPanel
:
1235 panel_options_box ();
1238 case CK_SelectCodepage
:
1248 case CK_PanelQuickView
:
1249 if (sender
== (Widget
*) the_menubar
)
1250 quick_view_cmd (); /* menu */
1252 quick_cmd_no_menu (); /* shortcut or buttonabr */
1260 case CK_LinkSymbolicRelative
:
1261 link_cmd (LINK_SYMLINK_RELATIVE
);
1274 case CK_SelectInvert
:
1275 select_invert_cmd ();
1287 smart_dirsize_cmd ();
1292 case CK_ExtendedKeyMap
:
1296 mc_event_raise (MCEVENT_GROUP_CORE
, "suspend", NULL
);
1301 case CK_LinkSymbolic
:
1302 link_cmd (LINK_SYMLINK_ABSOLUTE
);
1304 case CK_PanelListingSwitch
:
1305 toggle_listing_cmd ();
1308 toggle_show_hidden ();
1310 case CK_SplitVertHoriz
:
1311 toggle_panels_split ();
1319 #ifdef ENABLE_VFS_UNDELFS
1328 user_file_menu_cmd ();
1337 /* don't close panels due to SIGINT */
1340 res
= MSG_NOT_HANDLED
;
1346 /* --------------------------------------------------------------------------------------------- */
1349 midnight_callback (Dlg_head
* h
, Widget
* sender
, dlg_msg_t msg
, int parm
, void *data
)
1351 unsigned long command
;
1362 /* We handle the special case of the output lines */
1363 if (mc_global
.tty
.console_flag
!= '\0' && output_lines
)
1364 show_console_contents (output_start_y
,
1365 LINES
- output_lines
- mc_global
.keybar_visible
-
1366 1, LINES
- mc_global
.keybar_visible
- 1);
1371 menubar_arrange (the_menubar
);
1375 /* We only need the first idle event to show user menu after start */
1376 set_idle_proc (h
, 0);
1378 if (boot_current_is_left
)
1379 dlg_select_widget (get_panel_widget (0));
1381 dlg_select_widget (get_panel_widget (1));
1384 midnight_execute_cmd (NULL
, CK_UserMenu
);
1388 if (ctl_x_map_enabled
)
1390 ctl_x_map_enabled
= FALSE
;
1391 command
= keybind_lookup_keymap_command (main_x_map
, parm
);
1392 if (command
!= CK_IgnoreKey
)
1393 return midnight_execute_cmd (NULL
, command
);
1396 /* FIXME: should handle all menu shortcuts before this point */
1397 if (the_menubar
->is_active
)
1398 return MSG_NOT_HANDLED
;
1401 input_free_completions (cmdline
);
1407 for (i
= 0; cmdline
->buffer
[i
] != '\0' &&
1408 (cmdline
->buffer
[i
] == ' ' || cmdline
->buffer
[i
] == '\t'); i
++)
1411 if (cmdline
->buffer
[i
] != '\0')
1413 send_message ((Widget
*) cmdline
, WIDGET_KEY
, parm
);
1417 input_insert (cmdline
, "", FALSE
);
1421 /* Ctrl-Enter and Alt-Enter */
1422 if (((parm
& ~(KEY_M_CTRL
| KEY_M_ALT
)) == '\n') && (parm
& (KEY_M_CTRL
| KEY_M_ALT
)))
1428 /* Ctrl-Shift-Enter */
1429 if (parm
== (KEY_M_CTRL
| KEY_M_SHIFT
| '\n'))
1431 put_current_path ();
1436 if ((!mc_global
.tty
.alternate_plus_minus
1437 || !(mc_global
.tty
.console_flag
!= '\0' || mc_global
.tty
.xterm_flag
)) && !quote
1438 && !current_panel
->searching
)
1440 if (!only_leading_plus_minus
)
1442 /* Special treatement, since the input line will eat them */
1449 if (parm
== '\\' || parm
== '-')
1457 select_invert_cmd ();
1461 else if (!command_prompt
|| !cmdline
->buffer
[0])
1463 /* Special treatement '+', '-', '\', '*' only when this is
1464 * first char on input line
1473 if (parm
== '\\' || parm
== '-')
1481 select_invert_cmd ();
1486 return MSG_NOT_HANDLED
;
1488 case DLG_HOTKEY_HANDLED
:
1489 if ((get_current_type () == view_listing
) && current_panel
->searching
)
1491 current_panel
->dirty
= 1; /* FIXME: unneeded? */
1492 send_message ((Widget
*) current_panel
, WIDGET_COMMAND
, CK_SearchStop
);
1496 case DLG_UNHANDLED_KEY
:
1498 cb_ret_t v
= MSG_NOT_HANDLED
;
1500 if (ctl_x_map_enabled
)
1502 ctl_x_map_enabled
= FALSE
;
1503 command
= keybind_lookup_keymap_command (main_x_map
, parm
);
1506 command
= keybind_lookup_keymap_command (main_map
, parm
);
1508 if (command
!= CK_IgnoreKey
)
1509 v
= midnight_execute_cmd (NULL
, command
);
1511 if (v
== MSG_NOT_HANDLED
&& command_prompt
)
1512 v
= send_message ((Widget
*) cmdline
, WIDGET_KEY
, parm
);
1518 if (!the_menubar
->is_active
)
1519 update_dirty_panels ();
1525 return midnight_execute_cmd (NULL
, parm
);
1526 /* message from menu */
1527 if (sender
== (Widget
*) the_menubar
)
1528 return midnight_execute_cmd (sender
, parm
);
1529 /* message from buttonbar */
1530 if (sender
== (Widget
*) the_bar
)
1533 return send_message ((Widget
*) data
, WIDGET_COMMAND
, parm
);
1534 return midnight_execute_cmd (sender
, parm
);
1536 return MSG_NOT_HANDLED
;
1543 return default_dlg_callback (h
, sender
, msg
, parm
, data
);
1547 /* --------------------------------------------------------------------------------------------- */
1548 /*** public functions ****************************************************************************/
1549 /* --------------------------------------------------------------------------------------------- */
1554 menu_set_name (left_menu
, panels_layout
.horizontal_split
? _("&Above") : _("&Left"));
1555 menu_set_name (right_menu
, panels_layout
.horizontal_split
? _("&Below") : _("&Right"));
1556 menubar_arrange (the_menubar
);
1557 menubar_set_visible (the_menubar
, menubar_visible
);
1561 midnight_set_buttonbar (WButtonBar
* b
)
1563 buttonbar_set_label (b
, 1, Q_ ("ButtonBar|Help"), main_map
, NULL
);
1564 buttonbar_set_label (b
, 2, Q_ ("ButtonBar|Menu"), main_map
, NULL
);
1565 buttonbar_set_label (b
, 3, Q_ ("ButtonBar|View"), main_map
, NULL
);
1566 buttonbar_set_label (b
, 4, Q_ ("ButtonBar|Edit"), main_map
, NULL
);
1567 buttonbar_set_label (b
, 5, Q_ ("ButtonBar|Copy"), main_map
, NULL
);
1568 buttonbar_set_label (b
, 6, Q_ ("ButtonBar|RenMov"), main_map
, NULL
);
1569 buttonbar_set_label (b
, 7, Q_ ("ButtonBar|Mkdir"), main_map
, NULL
);
1570 buttonbar_set_label (b
, 8, Q_ ("ButtonBar|Delete"), main_map
, NULL
);
1571 buttonbar_set_label (b
, 9, Q_ ("ButtonBar|PullDn"), main_map
, NULL
);
1572 buttonbar_set_label (b
, 10, Q_ ("ButtonBar|Quit"), main_map
, NULL
);
1575 /* --------------------------------------------------------------------------------------------- */
1577 * Load new hint and display it.
1578 * IF force is not 0, ignore the timeout.
1582 load_hint (gboolean force
)
1586 if (the_hint
->widget
.owner
== NULL
)
1589 if (!mc_global
.message_visible
)
1591 label_set_text (the_hint
, NULL
);
1595 hint
= get_random_hint (force
);
1605 char text
[BUF_SMALL
];
1607 g_snprintf (text
, sizeof (text
), _("GNU Midnight Commander %s\n"), VERSION
);
1612 /* --------------------------------------------------------------------------------------------- */
1617 input_free_completions (cmdline
);
1618 dlg_one_down (midnight_dlg
);
1621 /* --------------------------------------------------------------------------------------------- */
1623 /** Save current stat of directories to avoid reloading the panels
1624 * when no modifications have taken place
1627 save_cwds_stat (void)
1629 if (panels_options
.fast_reload
)
1633 vpath
= vfs_path_from_str (current_panel
->cwd
);
1634 mc_stat (vpath
, &(current_panel
->dir_stat
));
1635 vfs_path_free (vpath
);
1636 if (get_other_type () == view_listing
)
1638 vpath
= vfs_path_from_str (other_panel
->cwd
);
1639 mc_stat (vpath
, &(other_panel
->dir_stat
));
1640 vfs_path_free (vpath
);
1645 /* --------------------------------------------------------------------------------------------- */
1648 quiet_quit_cmd (void)
1650 print_last_revert
= TRUE
;
1651 return quit_cmd_internal (1);
1654 /* --------------------------------------------------------------------------------------------- */
1656 /** Run the main dialog that occupies the whole screen */
1662 dlg_colors_t midnight_colors
;
1664 midnight_colors
[DLG_COLOR_NORMAL
] = mc_skin_color_get ("dialog", "_default_");
1665 midnight_colors
[DLG_COLOR_FOCUS
] = mc_skin_color_get ("dialog", "focus");
1666 midnight_colors
[DLG_COLOR_HOT_NORMAL
] = mc_skin_color_get ("dialog", "hotnormal");
1667 midnight_colors
[DLG_COLOR_HOT_FOCUS
] = mc_skin_color_get ("dialog", "hotfocus");
1668 midnight_colors
[DLG_COLOR_TITLE
] = mc_skin_color_get ("dialog", "title");
1670 #ifdef USE_INTERNAL_EDIT
1674 midnight_dlg
= create_dlg (FALSE
, 0, 0, LINES
, COLS
, midnight_colors
, midnight_callback
,
1675 "[main]", NULL
, DLG_WANT_IDLE
);
1677 if (mc_global
.mc_run_mode
== MC_RUN_FULL
)
1682 /* Check if we were invoked as an editor or file viewer */
1683 if (mc_global
.mc_run_mode
!= MC_RUN_FULL
)
1684 ret
= mc_maybe_editor_or_viewer ();
1687 create_panels_and_run_mc ();
1690 /* destroy_dlg destroys even current_panel->cwd, so we have to save a copy :) */
1691 if (mc_args__last_wd_file
!= NULL
&& vfs_current_is_local ())
1692 last_wd_string
= g_strdup (current_panel
->cwd
);
1694 /* don't handle VFS timestamps for dirs opened in panels */
1695 mc_event_destroy (MCEVENT_GROUP_CORE
, "vfs_timestamp");
1697 clean_dir (&panelized_panel
.list
, panelized_panel
.count
);
1701 mc_global
.midnight_shutdown
= TRUE
;
1702 dialog_switch_shutdown ();
1704 destroy_dlg (midnight_dlg
);
1705 current_panel
= NULL
;
1707 #ifdef USE_INTERNAL_EDIT
1711 if ((quit
& SUBSHELL_EXIT
) == 0)
1717 /* --------------------------------------------------------------------------------------------- */