1 /* Main dialog (file panels) of the Midnight Commander
2 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003, 2004, 2005, 2006, 2007, 2009, 2010 Free Software Foundation, Inc.
5 Written by: 1994, 1995, 1996, 1997 Miguel de Icaza
6 1994, 1995 Janne Kukonlehto
8 2009, 2010 Andrew Borodin
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
25 * \brief Source: main dialog (file panels) of the Midnight Commander
37 #include <sys/types.h>
40 #include <pwd.h> /* for username in xterm title */
42 #include "lib/global.h"
44 #include "lib/tty/tty.h"
45 #include "lib/tty/mouse.h"
46 #include "lib/tty/key.h" /* For init_key() */
47 #include "lib/tty/win.h" /* xterm_flag */
51 #include "lib/vfs/mc-vfs/vfs.h" /* vfs_translate_url() */
54 #include "src/subshell.h"
55 #include "src/setup.h" /* variables */
56 #include "src/learn.h" /* learn_keys() */
57 #include "src/execute.h" /* suspend_cmd() */
58 #include "src/keybind-defaults.h"
59 #include "src/main.h" /* quit */
61 #include "option.h" /* configure_box() */
63 #include "boxes.h" /* sort_box(), tree_box() */
65 #include "cmd.h" /* commands */
68 #include "command.h" /* cmdline */
69 #include "lib/keybind.h"
75 #ifdef USE_INTERNAL_EDIT
76 #include "src/editor/edit.h"
80 #include "src/diffviewer/ydiff.h"
83 #include "src/consaver/cons.saver.h" /* console_flag */
87 /* TODO: merge content of layout.c here */
89 /*** global variables ****************************************************************************/
91 /* When the modes are active, left_panel, right_panel and tree_panel */
92 /* point to a proper data structure. You should check with the functions */
93 /* get_current_type and get_other_type the types of the panels before using */
94 /* this pointer variables */
96 /* The structures for the panels */
97 WPanel
*left_panel
= NULL
;
98 WPanel
*right_panel
= NULL
;
99 /* Pointer to the selected and unselected panel */
100 WPanel
*current_panel
= NULL
;
102 /* Set if the command is being run from the "Right" menu */
106 WMenuBar
*the_menubar
= NULL
;
107 /* The widget where we draw the prompt */
114 /* The dialog handle for the main program */
115 Dlg_head
*midnight_dlg
= 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 #define full_eight_bits (1)
125 #define eight_bit_clean (1)
126 #endif /* !HAVE_CHARSET */
128 /*** file scope type declarations ****************************************************************/
130 /*** file scope variables ************************************************************************/
132 static Menu
*left_menu
, *right_menu
;
134 static gboolean ctl_x_map_enabled
= FALSE
;
136 /*** file scope functions ************************************************************************/
138 /** Stop MC main dialog and the current dialog if it exists.
139 * Needed to provide fast exit from MC viewer or editor on shell exit */
143 midnight_dlg
->state
= DLG_CLOSED
;
145 if ((top_dlg
!= NULL
) && (top_dlg
->data
!= NULL
))
146 ((Dlg_head
*) top_dlg
->data
)->state
= DLG_CLOSED
;
149 /* --------------------------------------------------------------------------------------------- */
156 sel_dir
= tree_box (selection (current_panel
)->fname
);
159 do_cd (sel_dir
, cd_exact
);
164 /* --------------------------------------------------------------------------------------------- */
166 #ifdef LISTMODE_EDITOR
172 if (get_current_type () != view_listing
)
175 newmode
= listmode_edit (current_panel
->user_format
);
179 g_free (current_panel
->user_format
);
180 current_panel
->list_type
= list_user
;
181 current_panel
->user_format
= newmode
;
182 set_panel_formats (current_panel
);
186 #endif /* LISTMODE_EDITOR */
188 /* --------------------------------------------------------------------------------------------- */
191 create_panel_menu (void)
193 GList
*entries
= NULL
;
195 entries
= g_list_append (entries
, menu_entry_create (_("File listin&g"), CK_ListingCmd
));
196 entries
= g_list_append (entries
, menu_entry_create (_("&Quick view"), CK_QuickViewCmd
));
197 entries
= g_list_append (entries
, menu_entry_create (_("&Info"), CK_InfoCmd
));
198 entries
= g_list_append (entries
, menu_entry_create (_("&Tree"), CK_TreeCmd
));
199 entries
= g_list_append (entries
, menu_separator_create ());
201 g_list_append (entries
, menu_entry_create (_("&Listing mode..."), CK_ChangeListingCmd
));
202 entries
= g_list_append (entries
, menu_entry_create (_("&Sort order..."), CK_Sort
));
203 entries
= g_list_append (entries
, menu_entry_create (_("&Filter..."), CK_FilterCmd
));
206 g_list_append (entries
, menu_entry_create (_("&Encoding..."), CK_PanelSetPanelEncoding
));
208 #ifdef ENABLE_VFS_NET
209 entries
= g_list_append (entries
, menu_separator_create ());
210 #ifdef ENABLE_VFS_FTP
211 entries
= g_list_append (entries
, menu_entry_create (_("FT&P link..."), CK_FtplinkCmd
));
213 #ifdef ENABLE_VFS_FISH
214 entries
= g_list_append (entries
, menu_entry_create (_("S&hell link..."), CK_FishlinkCmd
));
216 #ifdef ENABLE_VFS_SMB
217 entries
= g_list_append (entries
, menu_entry_create (_("SM&B link..."), CK_SmblinkCmd
));
219 #endif /* ENABLE_VFS_NET */
220 entries
= g_list_append (entries
, menu_separator_create ());
221 entries
= g_list_append (entries
, menu_entry_create (_("&Rescan"), CK_RereadCmd
));
226 /* --------------------------------------------------------------------------------------------- */
229 create_file_menu (void)
231 GList
*entries
= NULL
;
233 entries
= g_list_append (entries
, menu_entry_create (_("&View"), CK_ViewCmd
));
234 entries
= g_list_append (entries
, menu_entry_create (_("Vie&w file..."), CK_ViewFileCmd
));
235 entries
= g_list_append (entries
, menu_entry_create (_("&Filtered view"), CK_FilteredViewCmd
));
236 entries
= g_list_append (entries
, menu_entry_create (_("&Edit"), CK_EditCmd
));
237 entries
= g_list_append (entries
, menu_entry_create (_("&Copy"), CK_CopyCmd
));
238 entries
= g_list_append (entries
, menu_entry_create (_("C&hmod"), CK_ChmodCmd
));
239 entries
= g_list_append (entries
, menu_entry_create (_("&Link"), CK_LinkCmd
));
240 entries
= g_list_append (entries
, menu_entry_create (_("&Symlink"), CK_SymlinkCmd
));
242 g_list_append (entries
, menu_entry_create (_("Relative symlin&k"), CK_RelativeSymlinkCmd
));
243 entries
= g_list_append (entries
, menu_entry_create (_("Edit s&ymlink"), CK_EditSymlinkCmd
));
244 entries
= g_list_append (entries
, menu_entry_create (_("Ch&own"), CK_ChownCmd
));
246 g_list_append (entries
, menu_entry_create (_("&Advanced chown"), CK_ChownAdvancedCmd
));
247 entries
= g_list_append (entries
, menu_entry_create (_("&Rename/Move"), CK_RenameCmd
));
248 entries
= g_list_append (entries
, menu_entry_create (_("&Mkdir"), CK_MkdirCmd
));
249 entries
= g_list_append (entries
, menu_entry_create (_("&Delete"), CK_DeleteCmd
));
250 entries
= g_list_append (entries
, menu_entry_create (_("&Quick cd"), CK_QuickCdCmd
));
251 entries
= g_list_append (entries
, menu_separator_create ());
252 entries
= g_list_append (entries
, menu_entry_create (_("Select &group"), CK_SelectCmd
));
253 entries
= g_list_append (entries
, menu_entry_create (_("U&nselect group"), CK_UnselectCmd
));
255 g_list_append (entries
,
256 menu_entry_create (_("Reverse selec&tion"), CK_ReverseSelectionCmd
));
257 entries
= g_list_append (entries
, menu_separator_create ());
258 entries
= g_list_append (entries
, menu_entry_create (_("E&xit"), CK_QuitCmd
));
263 /* --------------------------------------------------------------------------------------------- */
266 create_command_menu (void)
268 /* I know, I'm lazy, but the tree widget when it's not running
269 * as a panel still has some problems, I have not yet finished
270 * the WTree widget port, sorry.
272 GList
*entries
= NULL
;
274 entries
= g_list_append (entries
, menu_entry_create (_("&User menu"), CK_UserMenuCmd
));
275 entries
= g_list_append (entries
, menu_entry_create (_("&Directory tree"), CK_TreeBoxCmd
));
276 entries
= g_list_append (entries
, menu_entry_create (_("&Find file"), CK_FindCmd
));
277 entries
= g_list_append (entries
, menu_entry_create (_("S&wap panels"), CK_SwapCmd
));
279 g_list_append (entries
, menu_entry_create (_("Switch &panels on/off"), CK_ShowCommandLine
));
281 g_list_append (entries
, menu_entry_create (_("&Compare directories"), CK_CompareDirsCmd
));
283 entries
= g_list_append (entries
, menu_entry_create (_("&View diff files"), CK_DiffViewCmd
));
286 g_list_append (entries
, menu_entry_create (_("E&xternal panelize"), CK_ExternalPanelize
));
288 g_list_append (entries
,
289 menu_entry_create (_("Show directory s&izes"), CK_SingleDirsizeCmd
));
290 entries
= g_list_append (entries
, menu_separator_create ());
291 entries
= g_list_append (entries
, menu_entry_create (_("Command &history"), CK_HistoryCmd
));
293 g_list_append (entries
, menu_entry_create (_("Di&rectory hotlist"), CK_QuickChdirCmd
));
295 entries
= g_list_append (entries
, menu_entry_create (_("&Active VFS list"), CK_ReselectVfs
));
297 #ifdef WITH_BACKGROUND
298 entries
= g_list_append (entries
, menu_entry_create (_("&Background jobs"), CK_JobsCmd
));
300 entries
= g_list_append (entries
, menu_entry_create (_("Screen lis&t"), CK_DialogListCmd
));
301 entries
= g_list_append (entries
, menu_separator_create ());
302 #ifdef ENABLE_VFS_UNDELFS
304 g_list_append (entries
,
305 menu_entry_create (_("&Undelete files (ext2fs only)"), CK_UndeleteCmd
));
307 #ifdef LISTMODE_EDITOR
309 g_list_append (entries
, menu_entry_create (_("&Listing format edit"), CK_ListmodeCmd
));
311 #if defined (ENABLE_VFS_UNDELFS) || defined (LISTMODE_EDITOR)
312 entries
= g_list_append (entries
, menu_separator_create ());
315 g_list_append (entries
, menu_entry_create (_("Edit &extension file"), CK_EditExtFileCmd
));
316 entries
= g_list_append (entries
, menu_entry_create (_("Edit &menu file"), CK_EditMcMenuCmd
));
318 g_list_append (entries
,
319 menu_entry_create (_("Edit hi&ghlighting group file"), CK_EditFhlFileCmd
));
324 /* --------------------------------------------------------------------------------------------- */
327 create_options_menu (void)
329 GList
*entries
= NULL
;
331 entries
= g_list_append (entries
, menu_entry_create (_("&Configuration..."), CK_ConfigureBox
));
332 entries
= g_list_append (entries
, menu_entry_create (_("&Layout..."), CK_LayoutBox
));
334 g_list_append (entries
, menu_entry_create (_("&Panel options..."), CK_PanelOptionsBox
));
335 entries
= g_list_append (entries
, menu_entry_create (_("C&onfirmation..."), CK_ConfirmBox
));
336 entries
= g_list_append (entries
, menu_entry_create (_("&Display bits..."), CK_DisplayBitsBox
));
337 entries
= g_list_append (entries
, menu_entry_create (_("Learn &keys..."), CK_LearnKeys
));
339 entries
= g_list_append (entries
, menu_entry_create (_("&Virtual FS..."), CK_ConfigureVfs
));
341 entries
= g_list_append (entries
, menu_separator_create ());
342 entries
= g_list_append (entries
, menu_entry_create (_("&Save setup"), CK_SaveSetupCmd
));
347 /* --------------------------------------------------------------------------------------------- */
352 left_menu
= create_menu ("", create_panel_menu (), "[Left and Right Menus]");
353 menubar_add_menu (the_menubar
, left_menu
);
354 menubar_add_menu (the_menubar
, create_menu (_("&File"), create_file_menu (), "[File Menu]"));
355 menubar_add_menu (the_menubar
,
356 create_menu (_("&Command"), create_command_menu (), "[Command Menu]"));
357 menubar_add_menu (the_menubar
,
358 create_menu (_("&Options"), create_options_menu (), "[Options Menu]"));
359 right_menu
= create_menu ("", create_panel_menu (), "[Left and Right Menus]");
360 menubar_add_menu (the_menubar
, right_menu
);
364 /* --------------------------------------------------------------------------------------------- */
367 menu_last_selected_cmd (void)
369 the_menubar
->is_active
= TRUE
;
370 the_menubar
->is_dropped
= (drop_menus
!= 0);
371 the_menubar
->previous_widget
= dlg_get_current_widget_id (midnight_dlg
);
372 dlg_select_widget (the_menubar
);
375 /* --------------------------------------------------------------------------------------------- */
380 if (the_menubar
->is_active
)
383 if ((get_current_index () == 0) == (current_panel
->active
!= 0))
384 the_menubar
->selected
= 0;
386 the_menubar
->selected
= g_list_length (the_menubar
->menu
) - 1;
387 menu_last_selected_cmd ();
390 /* --------------------------------------------------------------------------------------------- */
396 const panel_field_t
*sort_order
;
398 if (!SELECTED_IS_PANEL
)
402 sort_order
= sort_box (&p
->sort_info
);
403 panel_set_sort_order (p
, sort_order
);
406 /* --------------------------------------------------------------------------------------------- */
409 midnight_get_shortcut (unsigned long command
)
412 const char *shortcut
= NULL
;
414 shortcut
= keybind_lookup_keymap_shortcut (main_map
, command
);
415 if (shortcut
!= NULL
)
416 return g_strdup (shortcut
);
418 shortcut
= keybind_lookup_keymap_shortcut (panel_map
, command
);
419 if (shortcut
!= NULL
)
420 return g_strdup (shortcut
);
422 ext_map
= keybind_lookup_keymap_shortcut (main_map
, CK_StartExtMap1
);
424 shortcut
= keybind_lookup_keymap_shortcut (main_x_map
, command
);
425 if (shortcut
!= NULL
)
426 return g_strdup_printf ("%s %s", ext_map
, shortcut
);
431 /* --------------------------------------------------------------------------------------------- */
434 midnight_get_title (const Dlg_head
* h
, size_t len
)
436 /* TODO: share code with update_xterm_title_path() */
441 struct passwd
*pw
= NULL
;
447 path
= strip_home_and_password (current_panel
->cwd
);
448 res
= gethostname (host
, sizeof (host
));
452 host
[sizeof (host
) - 1] = '\0';
454 pw
= getpwuid (getuid ());
456 login
= g_strdup_printf ("%s@%s", pw
->pw_name
, host
);
458 login
= g_strdup (host
);
460 p
= g_strdup_printf ("%s [%s]:%s", _("Panels:"), login
, path
);
461 path
= str_trunc (p
, len
- 4);
465 return g_strdup (path
);
468 /* --------------------------------------------------------------------------------------------- */
471 toggle_panels_split (void)
473 horizontal_split
= !horizontal_split
;
478 /* --------------------------------------------------------------------------------------------- */
481 * Just a hack for allowing url-like pathnames to be accepted from the
485 translated_mc_chdir (char *dir
)
490 newdir
= vfs_translate_url (dir
);
491 ret
= mc_chdir (newdir
);
495 /* --------------------------------------------------------------------------------------------- */
502 panel_view_mode_t current_mode
, other_mode
;
503 char original_dir
[BUF_1K
] = "\0";
505 if (boot_current_is_left
)
509 current_mode
= startup_left_mode
;
510 other_mode
= startup_right_mode
;
516 current_mode
= startup_right_mode
;
517 other_mode
= startup_left_mode
;
519 /* Creates the left panel */
520 if (mc_run_param0
!= NULL
)
522 if (mc_run_param1
!= NULL
)
524 /* Ok, user has specified two dirs, save the original one,
525 * since we may not be able to chdir to the proper
526 * second directory later
528 mc_get_current_wd (original_dir
, sizeof (original_dir
) - 2);
530 translated_mc_chdir (mc_run_param0
);
532 set_display_type (current_index
, current_mode
);
534 /* The other panel */
535 if (mc_run_param1
!= NULL
)
537 if (original_dir
[0] != '\0')
538 translated_mc_chdir (original_dir
);
539 translated_mc_chdir (mc_run_param1
);
541 set_display_type (other_index
, other_mode
);
543 if (startup_left_mode
== view_listing
)
545 current_panel
= left_panel
;
550 current_panel
= right_panel
;
552 current_panel
= left_panel
;
555 /* Create the nice widgets */
556 cmdline
= command_new (0, 0, 0);
557 the_prompt
= label_new (0, 0, mc_prompt
);
558 the_prompt
->transparent
= 1;
559 the_bar
= buttonbar_new (keybar_visible
);
561 the_hint
= label_new (0, 0, 0);
562 the_hint
->transparent
= 1;
563 the_hint
->auto_adjust_cols
= 0;
564 the_hint
->widget
.cols
= COLS
;
566 the_menubar
= menubar_new (0, 0, COLS
, NULL
);
569 /* --------------------------------------------------------------------------------------------- */
572 copy_current_pathname (void)
578 cwd_path
= remove_encoding_from_path (current_panel
->cwd
);
579 command_insert (cmdline
, cwd_path
, FALSE
);
581 if (cwd_path
[strlen (cwd_path
) - 1] != PATH_SEP
)
582 command_insert (cmdline
, PATH_SEP_STR
, FALSE
);
586 /* --------------------------------------------------------------------------------------------- */
589 copy_other_pathname (void)
593 if (get_other_type () != view_listing
)
599 cwd_path
= remove_encoding_from_path (other_panel
->cwd
);
600 command_insert (cmdline
, cwd_path
, FALSE
);
602 if (cwd_path
[strlen (cwd_path
) - 1] != PATH_SEP
)
603 command_insert (cmdline
, PATH_SEP_STR
, FALSE
);
607 /* --------------------------------------------------------------------------------------------- */
610 copy_readlink (WPanel
* panel
)
614 if (S_ISLNK (selection (panel
)->st
.st_mode
))
616 char buffer
[MC_MAXPATHLEN
];
617 char *p
= concat_dir_and_file (panel
->cwd
, selection (panel
)->fname
);
620 i
= mc_readlink (p
, buffer
, MC_MAXPATHLEN
- 1);
625 command_insert (cmdline
, buffer
, TRUE
);
630 /* --------------------------------------------------------------------------------------------- */
633 copy_current_readlink (void)
635 copy_readlink (current_panel
);
638 /* --------------------------------------------------------------------------------------------- */
641 copy_other_readlink (void)
643 if (get_other_type () == view_listing
)
644 copy_readlink (other_panel
);
647 /* --------------------------------------------------------------------------------------------- */
649 /** Insert the selected file name into the input line */
651 copy_prog_name (void)
657 if (get_current_type () == view_tree
)
659 WTree
*tree
= (WTree
*) get_panel_widget (get_current_index ());
660 tmp
= tree_selected_name (tree
);
663 tmp
= selection (current_panel
)->fname
;
665 command_insert (cmdline
, tmp
, TRUE
);
668 /* --------------------------------------------------------------------------------------------- */
671 copy_tagged (WPanel
* panel
)
677 input_disable_update (cmdline
);
680 for (i
= 0; i
< panel
->count
; i
++)
682 if (panel
->dir
.list
[i
].f
.marked
)
683 command_insert (cmdline
, panel
->dir
.list
[i
].fname
, TRUE
);
688 command_insert (cmdline
, panel
->dir
.list
[panel
->selected
].fname
, TRUE
);
690 input_enable_update (cmdline
);
693 /* --------------------------------------------------------------------------------------------- */
696 copy_current_tagged (void)
698 copy_tagged (current_panel
);
701 /* --------------------------------------------------------------------------------------------- */
704 copy_other_tagged (void)
706 if (get_other_type () == view_listing
)
707 copy_tagged (other_panel
);
710 /* --------------------------------------------------------------------------------------------- */
715 ctl_x_map_enabled
= TRUE
;
718 /* --------------------------------------------------------------------------------------------- */
724 tty_display_8bit (full_eight_bits
!= 0);
726 tty_display_8bit (eight_bit_clean
!= 0);
729 #ifdef HAVE_SUBSHELL_SUPPORT
731 add_select_channel (subshell_pty
, load_prompt
, 0);
732 #endif /* !HAVE_SUBSHELL_SUPPORT */
734 tty_setup_sigwinch (sigwinch_handler
);
736 if ((tty_baudrate () < 9600) || tty_is_slow ())
740 /* --------------------------------------------------------------------------------------------- */
743 setup_dummy_mc (void)
745 char d
[MC_MAXPATHLEN
];
748 mc_get_current_wd (d
, MC_MAXPATHLEN
);
753 /* --------------------------------------------------------------------------------------------- */
758 if ((quit
& SUBSHELL_EXIT
) == 0)
760 tty_reset_shell_mode ();
765 /* --------------------------------------------------------------------------------------------- */
774 * We sync the profiles since the hotlist may have changed, while
775 * we only change the setup data if we have the auto save feature set
778 save_setup (auto_save_setup
, panels_options
.auto_save_setup
);
781 vfs_stamp_path (vfs_get_current_dir ());
783 if ((current_panel
!= NULL
) && (get_current_type () == view_listing
))
784 vfs_stamp_path (current_panel
->cwd
);
786 if ((other_panel
!= NULL
) && (get_other_type () == view_listing
))
787 vfs_stamp_path (other_panel
->cwd
);
790 /* --------------------------------------------------------------------------------------------- */
793 create_panels_and_run_mc (void)
795 midnight_dlg
->get_shortcut
= midnight_get_shortcut
;
796 midnight_dlg
->get_title
= midnight_get_title
;
800 add_widget (midnight_dlg
, the_menubar
);
803 add_widget (midnight_dlg
, get_panel_widget (0));
804 add_widget (midnight_dlg
, get_panel_widget (1));
806 add_widget (midnight_dlg
, the_hint
);
807 add_widget (midnight_dlg
, cmdline
);
808 add_widget (midnight_dlg
, the_prompt
);
810 add_widget (midnight_dlg
, the_bar
);
811 midnight_set_buttonbar (the_bar
);
813 /* Run the Midnight Commander if no file was specified in the command line */
814 run_dlg (midnight_dlg
);
817 /* --------------------------------------------------------------------------------------------- */
819 /** result must be free'd (I think this should go in util.c) */
821 prepend_cwd_on_local (const char *filename
)
826 if (!vfs_file_is_local (filename
) || g_path_is_absolute (filename
))
827 return g_strdup (filename
);
829 d
= g_malloc (MC_MAXPATHLEN
+ strlen (filename
) + 2);
830 mc_get_current_wd (d
, MC_MAXPATHLEN
);
833 strcpy (d
+ l
, filename
);
834 canonicalize_pathname (d
);
838 /* --------------------------------------------------------------------------------------------- */
840 /** Invoke the internal view/edit routine with:
841 * the default processing and forcing the internal viewer/editor
844 mc_maybe_editor_or_viewer (void)
848 #ifdef USE_INTERNAL_EDIT
850 edit_file (mc_run_param0
, mc_args__edit_start_line
);
852 #endif /* USE_INTERNAL_EDIT */
856 path
= prepend_cwd_on_local (mc_run_param0
);
857 view_file (path
, 0, 1);
862 case MC_RUN_DIFFVIEWER
:
863 diff_view (mc_run_param0
, mc_run_param1
, mc_run_param0
, mc_run_param1
);
865 #endif /* USE_DIFF_VIEW */
871 /* --------------------------------------------------------------------------------------------- */
874 quit_cmd_internal (int quiet
)
879 n
= dialog_switch_num () - 1;
882 char msg
[BUF_MEDIUM
];
884 g_snprintf (msg
, sizeof (msg
),
885 ngettext ("You have %zd opened screen. Quit anyway?",
886 "You have %zd opened screens. Quit anyway?", n
), n
);
888 if (query_dialog (_("The Midnight Commander"), msg
, D_NORMAL
, 2, _("&Yes"), _("&No")) != 0)
892 else if (quiet
|| !confirm_exit
)
894 else if (query_dialog (_("The Midnight Commander"),
895 _("Do you really want to quit the Midnight Commander?"),
896 D_NORMAL
, 2, _("&Yes"), _("&No")) == 0)
901 #ifdef HAVE_SUBSHELL_SUPPORT
904 else if ((q
= exit_subshell ()))
914 /* --------------------------------------------------------------------------------------------- */
919 return quit_cmd_internal (0);
922 /* --------------------------------------------------------------------------------------------- */
925 toggle_show_hidden (void)
927 panels_options
.show_dot_files
= !panels_options
.show_dot_files
;
928 update_panels (UP_RELOAD
, UP_KEEPSEL
);
931 /* --------------------------------------------------------------------------------------------- */
934 * Repaint the contents of the panels without frames. To schedule panel
935 * for repainting, set panel->dirty to 1. There are many reasons why
936 * the panels need to be repainted, and this is a costly operation, so
937 * it's done once per event.
941 update_dirty_panels (void)
943 if (get_current_type () == view_listing
&& current_panel
->dirty
)
944 send_message ((Widget
*) current_panel
, WIDGET_DRAW
, 0);
946 if (get_other_type () == view_listing
&& other_panel
->dirty
)
947 send_message ((Widget
*) other_panel
, WIDGET_DRAW
, 0);
950 /* --------------------------------------------------------------------------------------------- */
953 midnight_execute_cmd (Widget
* sender
, unsigned long command
)
955 cb_ret_t res
= MSG_HANDLED
;
959 /* stop quick search before executing any command */
960 send_message ((Widget
*) current_panel
, WIDGET_COMMAND
, CK_PanelStopSearch
);
967 case CK_ChangeListingCmd
:
968 change_listing_cmd ();
976 case CK_ChownAdvancedCmd
:
977 chown_advanced_cmd ();
979 case CK_CompareDirsCmd
:
982 case CK_ConfigureBox
:
986 case CK_ConfigureVfs
:
996 case CK_CopyCurrentPathname
:
997 copy_current_pathname ();
999 case CK_CopyCurrentReadlink
:
1000 copy_current_readlink ();
1002 case CK_CopyCurrentTagged
:
1003 copy_current_tagged ();
1005 case CK_CopyOtherPathname
:
1006 copy_other_pathname ();
1008 case CK_CopyOtherReadlink
:
1009 copy_other_readlink ();
1011 case CK_CopyOtherTagged
:
1012 copy_other_tagged ();
1017 case CK_DialogListCmd
:
1018 dialog_switch_list ();
1020 #ifdef USE_DIFF_VIEW
1021 case CK_DiffViewCmd
:
1025 case CK_DisplayBitsBox
:
1026 display_bits_box ();
1031 #ifdef USE_INTERNAL_EDIT
1032 case CK_EditForceInternalCmd
:
1033 edit_cmd_force_internal ();
1036 case CK_EditExtFileCmd
:
1039 case CK_EditFhlFileCmd
:
1042 case CK_EditMcMenuCmd
:
1043 edit_mc_menu_cmd ();
1045 case CK_EditSymlinkCmd
:
1046 edit_symlink_cmd ();
1048 case CK_ExternalPanelize
:
1049 external_panelize ();
1054 case CK_FilteredViewCmd
:
1055 filtered_view_cmd ();
1060 #ifdef ENABLE_VFS_FISH
1061 case CK_FishlinkCmd
:
1065 #ifdef ENABLE_VFS_FTP
1077 if (sender
== (Widget
*) the_menubar
)
1078 info_cmd (); /* mwnu */
1080 info_cmd_no_menu (); /* shortcut or buttonbar */
1082 #ifdef WITH_BACKGROUND
1094 link_cmd (LINK_HARDLINK
);
1099 #ifdef LISTMODE_EDITOR
1100 case CK_ListmodeCmd
:
1107 case CK_MenuLastSelectedCmd
:
1108 menu_last_selected_cmd ();
1113 case CK_PanelOptionsBox
:
1114 panel_options_box ();
1117 case CK_PanelSetPanelEncoding
:
1124 case CK_QuickChdirCmd
:
1127 case CK_QuickViewCmd
:
1128 if (sender
== (Widget
*) the_menubar
)
1129 quick_view_cmd (); /* menu */
1131 quick_cmd_no_menu (); /* shortcut or buttonabr */
1133 case CK_QuietQuitCmd
:
1139 case CK_RelativeSymlinkCmd
:
1140 link_cmd (LINK_SYMLINK_RELATIVE
);
1149 case CK_ReselectVfs
:
1153 case CK_ReverseSelectionCmd
:
1154 reverse_selection_cmd ();
1156 case CK_SaveSetupCmd
:
1162 case CK_ShowCommandLine
:
1165 case CK_SingleDirsizeCmd
:
1166 smart_dirsize_cmd ();
1168 #ifdef ENABLE_VFS_SMB
1172 #endif /* ENABLE_VFS_SMB */
1176 case CK_StartExtMap1
:
1186 link_cmd (LINK_SYMLINK_ABSOLUTE
);
1188 case CK_ToggleListingCmd
:
1189 toggle_listing_cmd ();
1191 case CK_ToggleShowHidden
:
1192 toggle_show_hidden ();
1194 case CK_TogglePanelsSplit
:
1195 toggle_panels_split ();
1203 #ifdef ENABLE_VFS_UNDELFS
1204 case CK_UndeleteCmd
:
1208 case CK_UnselectCmd
:
1211 case CK_UserMenuCmd
:
1212 user_file_menu_cmd ();
1217 case CK_ViewFileCmd
:
1220 case CK_DialogCancel
:
1221 /* don't close panels due to SIGINT */
1224 res
= MSG_NOT_HANDLED
;
1230 /* --------------------------------------------------------------------------------------------- */
1233 midnight_callback (Dlg_head
* h
, Widget
* sender
, dlg_msg_t msg
, int parm
, void *data
)
1235 unsigned long command
;
1246 /* We handle the special case of the output lines */
1247 if (console_flag
&& output_lines
)
1248 show_console_contents (output_start_y
,
1249 LINES
- output_lines
- keybar_visible
-
1250 1, LINES
- keybar_visible
- 1);
1255 menubar_arrange (the_menubar
);
1259 /* We only need the first idle event to show user menu after start */
1260 set_idle_proc (h
, 0);
1262 if (boot_current_is_left
)
1263 dlg_select_widget (get_panel_widget (0));
1265 dlg_select_widget (get_panel_widget (1));
1268 midnight_execute_cmd (NULL
, CK_UserMenuCmd
);
1272 if (ctl_x_map_enabled
)
1274 ctl_x_map_enabled
= FALSE
;
1275 command
= keybind_lookup_keymap_command (main_x_map
, parm
);
1276 if (command
!= CK_Ignore_Key
)
1277 return midnight_execute_cmd (NULL
, command
);
1280 /* FIXME: should handle all menu shortcuts before this point */
1281 if (the_menubar
->is_active
)
1282 return MSG_NOT_HANDLED
;
1285 input_free_completions (cmdline
);
1291 for (i
= 0; cmdline
->buffer
[i
] != '\0' &&
1292 (cmdline
->buffer
[i
] == ' ' || cmdline
->buffer
[i
] == '\t'); i
++)
1295 if (cmdline
->buffer
[i
] != '\0')
1297 send_message ((Widget
*) cmdline
, WIDGET_KEY
, parm
);
1301 input_insert (cmdline
, "", FALSE
);
1305 /* Ctrl-Enter and Alt-Enter */
1306 if (((parm
& ~(KEY_M_CTRL
| KEY_M_ALT
)) == '\n') && (parm
& (KEY_M_CTRL
| KEY_M_ALT
)))
1312 /* Ctrl-Shift-Enter */
1313 if (parm
== (KEY_M_CTRL
| KEY_M_SHIFT
| '\n'))
1315 copy_current_pathname ();
1320 if ((!alternate_plus_minus
|| !(console_flag
|| xterm_flag
))
1321 && !quote
&& !current_panel
->searching
)
1323 if (!only_leading_plus_minus
)
1325 /* Special treatement, since the input line will eat them */
1332 if (parm
== '\\' || parm
== '-')
1340 reverse_selection_cmd ();
1344 else if (!command_prompt
|| !cmdline
->buffer
[0])
1346 /* Special treatement '+', '-', '\', '*' only when this is
1347 * first char on input line
1356 if (parm
== '\\' || parm
== '-')
1364 reverse_selection_cmd ();
1369 return MSG_NOT_HANDLED
;
1371 case DLG_HOTKEY_HANDLED
:
1372 if ((get_current_type () == view_listing
) && current_panel
->searching
)
1374 current_panel
->dirty
= 1; /* FIXME: unneeded? */
1375 send_message ((Widget
*) current_panel
, WIDGET_COMMAND
, CK_PanelStopSearch
);
1379 case DLG_UNHANDLED_KEY
:
1384 v
= send_message ((Widget
*) cmdline
, WIDGET_KEY
, parm
);
1385 if (v
== MSG_HANDLED
)
1389 if (ctl_x_map_enabled
)
1391 ctl_x_map_enabled
= FALSE
;
1392 command
= keybind_lookup_keymap_command (main_x_map
, parm
);
1395 command
= keybind_lookup_keymap_command (main_map
, parm
);
1397 return (command
== CK_Ignore_Key
) ? MSG_NOT_HANDLED
: midnight_execute_cmd (NULL
, command
);
1400 if (!the_menubar
->is_active
)
1401 update_dirty_panels ();
1407 return midnight_execute_cmd (NULL
, parm
);
1408 /* message from menu */
1409 if (sender
== (Widget
*) the_menubar
)
1410 return midnight_execute_cmd (sender
, parm
);
1411 /* message from buttonbar */
1412 if (sender
== (Widget
*) the_bar
)
1415 return send_message ((Widget
*) data
, WIDGET_COMMAND
, parm
);
1416 return midnight_execute_cmd (sender
, parm
);
1418 return MSG_NOT_HANDLED
;
1425 return default_dlg_callback (h
, sender
, msg
, parm
, data
);
1429 /* --------------------------------------------------------------------------------------------- */
1430 /*** public functions ****************************************************************************/
1431 /* --------------------------------------------------------------------------------------------- */
1436 menu_set_name (left_menu
, horizontal_split
? _("&Above") : _("&Left"));
1437 menu_set_name (right_menu
, horizontal_split
? _("&Below") : _("&Right"));
1438 menubar_arrange (the_menubar
);
1439 menubar_set_visible (the_menubar
, menubar_visible
);
1443 midnight_set_buttonbar (WButtonBar
* b
)
1445 buttonbar_set_label (b
, 1, Q_ ("ButtonBar|Help"), main_map
, NULL
);
1446 buttonbar_set_label (b
, 2, Q_ ("ButtonBar|Menu"), main_map
, NULL
);
1447 buttonbar_set_label (b
, 3, Q_ ("ButtonBar|View"), main_map
, NULL
);
1448 buttonbar_set_label (b
, 4, Q_ ("ButtonBar|Edit"), main_map
, NULL
);
1449 buttonbar_set_label (b
, 5, Q_ ("ButtonBar|Copy"), main_map
, NULL
);
1450 buttonbar_set_label (b
, 6, Q_ ("ButtonBar|RenMov"), main_map
, NULL
);
1451 buttonbar_set_label (b
, 7, Q_ ("ButtonBar|Mkdir"), main_map
, NULL
);
1452 buttonbar_set_label (b
, 8, Q_ ("ButtonBar|Delete"), main_map
, NULL
);
1453 buttonbar_set_label (b
, 9, Q_ ("ButtonBar|PullDn"), main_map
, NULL
);
1454 buttonbar_set_label (b
, 10, Q_ ("ButtonBar|Quit"), main_map
, NULL
);
1457 /* --------------------------------------------------------------------------------------------- */
1459 * Load new hint and display it.
1460 * IF force is not 0, ignore the timeout.
1464 load_hint (gboolean force
)
1468 if (the_hint
->widget
.owner
== NULL
)
1471 if (!message_visible
)
1473 label_set_text (the_hint
, NULL
);
1477 hint
= get_random_hint (force
);
1487 char text
[BUF_SMALL
];
1489 g_snprintf (text
, sizeof (text
), _("GNU Midnight Commander %s\n"), VERSION
);
1494 /* --------------------------------------------------------------------------------------------- */
1499 input_free_completions (cmdline
);
1500 dlg_one_down (midnight_dlg
);
1503 /* --------------------------------------------------------------------------------------------- */
1505 /** Save current stat of directories to avoid reloading the panels
1506 * when no modifications have taken place
1509 save_cwds_stat (void)
1511 if (panels_options
.fast_reload
)
1513 mc_stat (current_panel
->cwd
, &(current_panel
->dir_stat
));
1514 if (get_other_type () == view_listing
)
1515 mc_stat (other_panel
->cwd
, &(other_panel
->dir_stat
));
1519 /* --------------------------------------------------------------------------------------------- */
1522 quiet_quit_cmd (void)
1524 print_last_revert
= TRUE
;
1525 return quit_cmd_internal (1);
1528 /* --------------------------------------------------------------------------------------------- */
1530 /** Run the main dialog that occupies the whole screen */
1534 dlg_colors_t midnight_colors
;
1536 midnight_colors
[DLG_COLOR_NORMAL
] = mc_skin_color_get ("dialog", "_default_");
1537 midnight_colors
[DLG_COLOR_FOCUS
] = mc_skin_color_get ("dialog", "focus");
1538 midnight_colors
[DLG_COLOR_HOT_NORMAL
] = mc_skin_color_get ("dialog", "hotnormal");
1539 midnight_colors
[DLG_COLOR_HOT_FOCUS
] = mc_skin_color_get ("dialog", "hotfocus");
1540 midnight_colors
[DLG_COLOR_TITLE
] = mc_skin_color_get ("dialog", "title");
1542 #ifdef USE_INTERNAL_EDIT
1546 midnight_dlg
= create_dlg (FALSE
, 0, 0, LINES
, COLS
, midnight_colors
, midnight_callback
,
1547 "[main]", NULL
, DLG_WANT_IDLE
);
1549 if (mc_run_mode
== MC_RUN_FULL
)
1554 /* Check if we were invoked as an editor or file viewer */
1555 if (mc_run_mode
!= MC_RUN_FULL
)
1556 mc_maybe_editor_or_viewer ();
1559 create_panels_and_run_mc ();
1561 /* destroy_dlg destroys even current_panel->cwd, so we have to save a copy :) */
1562 if (mc_args__last_wd_file
!= NULL
&& vfs_current_is_local ())
1563 last_wd_string
= g_strdup (current_panel
->cwd
);
1567 midnight_shutdown
= 1;
1568 dialog_switch_shutdown ();
1570 destroy_dlg (midnight_dlg
);
1571 current_panel
= NULL
;
1573 #ifdef USE_INTERNAL_EDIT
1578 /* --------------------------------------------------------------------------------------------- */