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>
41 #include <pwd.h> /* for username in xterm title */
43 #include "lib/global.h"
45 #include "lib/tty/tty.h"
46 #include "lib/tty/key.h" /* For init_key() */
47 #include "lib/tty/mouse.h"
48 #include "lib/tty/win.h" /* xterm_flag */
52 #include "lib/vfs/mc-vfs/vfs.h" /* vfs_translate_url() */
55 #include "src/subshell.h"
56 #include "src/setup.h" /* variables */
57 #include "src/learn.h" /* learn_keys() */
58 #include "src/execute.h" /* suspend_cmd() */
59 #include "src/keybind-defaults.h"
60 #include "src/main.h" /* quit */
62 #include "option.h" /* configure_box() */
64 #include "boxes.h" /* sort_box(), tree_box() */
66 #include "cmd.h" /* commands */
69 #include "command.h" /* cmdline */
70 #include "lib/keybind.h"
76 #ifdef USE_INTERNAL_EDIT
77 #include "src/editor/edit.h"
81 #include "src/diffviewer/ydiff.h"
84 #include "src/consaver/cons.saver.h" /* console_flag */
88 /* TODO: merge content of layout.c here */
90 /*** global variables ****************************************************************************/
92 /* When the modes are active, left_panel, right_panel and tree_panel */
93 /* point to a proper data structure. You should check with the functions */
94 /* get_current_type and get_other_type the types of the panels before using */
95 /* this pointer variables */
97 /* The structures for the panels */
98 WPanel
*left_panel
= NULL
;
99 WPanel
*right_panel
= NULL
;
100 /* Pointer to the selected and unselected panel */
101 WPanel
*current_panel
= NULL
;
103 /* Set if the command is being run from the "Right" menu */
107 WMenuBar
*the_menubar
= NULL
;
108 /* The widget where we draw the prompt */
115 /* Mouse type: GPM, xterm or none */
116 Mouse_Type use_mouse_p
= MOUSE_NONE
;
118 /* The dialog handle for the main program */
119 Dlg_head
*midnight_dlg
= NULL
;
121 /*** file scope macro definitions ****************************************************************/
125 * Don't restrict the output on the screen manager level,
126 * the translation tables take care of it.
128 #define full_eight_bits (1)
129 #define eight_bit_clean (1)
130 #endif /* !HAVE_CHARSET */
132 /*** file scope type declarations ****************************************************************/
134 /*** file scope variables ************************************************************************/
136 static Menu
*left_menu
, *right_menu
;
138 static gboolean ctl_x_map_enabled
= FALSE
;
140 /*** file scope functions ************************************************************************/
142 /** Stop MC main dialog and the current dialog if it exists.
143 * Needed to provide fast exit from MC viewer or editor on shell exit */
147 midnight_dlg
->state
= DLG_CLOSED
;
149 if ((top_dlg
!= NULL
) && (top_dlg
->data
!= NULL
))
150 ((Dlg_head
*) top_dlg
->data
)->state
= DLG_CLOSED
;
153 /* --------------------------------------------------------------------------------------------- */
160 sel_dir
= tree_box (selection (current_panel
)->fname
);
163 do_cd (sel_dir
, cd_exact
);
168 /* --------------------------------------------------------------------------------------------- */
170 #ifdef LISTMODE_EDITOR
176 if (get_current_type () != view_listing
)
179 newmode
= listmode_edit (current_panel
->user_format
);
183 g_free (current_panel
->user_format
);
184 current_panel
->list_type
= list_user
;
185 current_panel
->user_format
= newmode
;
186 set_panel_formats (current_panel
);
190 #endif /* LISTMODE_EDITOR */
192 /* --------------------------------------------------------------------------------------------- */
195 create_panel_menu (void)
197 GList
*entries
= NULL
;
199 entries
= g_list_append (entries
, menu_entry_create (_("File listin&g"), CK_ListingCmd
));
200 entries
= g_list_append (entries
, menu_entry_create (_("&Quick view"), CK_QuickViewCmd
));
201 entries
= g_list_append (entries
, menu_entry_create (_("&Info"), CK_InfoCmd
));
202 entries
= g_list_append (entries
, menu_entry_create (_("&Tree"), CK_TreeCmd
));
203 entries
= g_list_append (entries
, menu_separator_create ());
205 g_list_append (entries
, menu_entry_create (_("&Listing mode..."), CK_ChangeListingCmd
));
206 entries
= g_list_append (entries
, menu_entry_create (_("&Sort order..."), CK_Sort
));
207 entries
= g_list_append (entries
, menu_entry_create (_("&Filter..."), CK_FilterCmd
));
210 g_list_append (entries
, menu_entry_create (_("&Encoding..."), CK_PanelSetPanelEncoding
));
212 #ifdef ENABLE_VFS_NET
213 entries
= g_list_append (entries
, menu_separator_create ());
214 #ifdef ENABLE_VFS_FTP
215 entries
= g_list_append (entries
, menu_entry_create (_("FT&P link..."), CK_FtplinkCmd
));
217 #ifdef ENABLE_VFS_FISH
218 entries
= g_list_append (entries
, menu_entry_create (_("S&hell link..."), CK_FishlinkCmd
));
220 #ifdef ENABLE_VFS_SMB
221 entries
= g_list_append (entries
, menu_entry_create (_("SM&B link..."), CK_SmblinkCmd
));
223 #endif /* ENABLE_VFS_NET */
224 entries
= g_list_append (entries
, menu_separator_create ());
225 entries
= g_list_append (entries
, menu_entry_create (_("&Rescan"), CK_RereadCmd
));
230 /* --------------------------------------------------------------------------------------------- */
233 create_file_menu (void)
235 GList
*entries
= NULL
;
237 entries
= g_list_append (entries
, menu_entry_create (_("&View"), CK_ViewCmd
));
238 entries
= g_list_append (entries
, menu_entry_create (_("Vie&w file..."), CK_ViewFileCmd
));
239 entries
= g_list_append (entries
, menu_entry_create (_("&Filtered view"), CK_FilteredViewCmd
));
240 entries
= g_list_append (entries
, menu_entry_create (_("&Edit"), CK_EditCmd
));
241 entries
= g_list_append (entries
, menu_entry_create (_("&Copy"), CK_CopyCmd
));
242 entries
= g_list_append (entries
, menu_entry_create (_("C&hmod"), CK_ChmodCmd
));
243 entries
= g_list_append (entries
, menu_entry_create (_("&Link"), CK_LinkCmd
));
244 entries
= g_list_append (entries
, menu_entry_create (_("&Symlink"), CK_SymlinkCmd
));
246 g_list_append (entries
, menu_entry_create (_("Relative symlin&k"), CK_RelativeSymlinkCmd
));
247 entries
= g_list_append (entries
, menu_entry_create (_("Edit s&ymlink"), CK_EditSymlinkCmd
));
248 entries
= g_list_append (entries
, menu_entry_create (_("Ch&own"), CK_ChownCmd
));
250 g_list_append (entries
, menu_entry_create (_("&Advanced chown"), CK_ChownAdvancedCmd
));
251 entries
= g_list_append (entries
, menu_entry_create (_("&Rename/Move"), CK_RenameCmd
));
252 entries
= g_list_append (entries
, menu_entry_create (_("&Mkdir"), CK_MkdirCmd
));
253 entries
= g_list_append (entries
, menu_entry_create (_("&Delete"), CK_DeleteCmd
));
254 entries
= g_list_append (entries
, menu_entry_create (_("&Quick cd"), CK_QuickCdCmd
));
255 entries
= g_list_append (entries
, menu_separator_create ());
256 entries
= g_list_append (entries
, menu_entry_create (_("Select &group"), CK_SelectCmd
));
257 entries
= g_list_append (entries
, menu_entry_create (_("U&nselect group"), CK_UnselectCmd
));
259 g_list_append (entries
,
260 menu_entry_create (_("Reverse selec&tion"), CK_ReverseSelectionCmd
));
261 entries
= g_list_append (entries
, menu_separator_create ());
262 entries
= g_list_append (entries
, menu_entry_create (_("E&xit"), CK_QuitCmd
));
267 /* --------------------------------------------------------------------------------------------- */
270 create_command_menu (void)
272 /* I know, I'm lazy, but the tree widget when it's not running
273 * as a panel still has some problems, I have not yet finished
274 * the WTree widget port, sorry.
276 GList
*entries
= NULL
;
278 entries
= g_list_append (entries
, menu_entry_create (_("&User menu"), CK_UserMenuCmd
));
279 entries
= g_list_append (entries
, menu_entry_create (_("&Directory tree"), CK_TreeBoxCmd
));
280 entries
= g_list_append (entries
, menu_entry_create (_("&Find file"), CK_FindCmd
));
281 entries
= g_list_append (entries
, menu_entry_create (_("S&wap panels"), CK_SwapCmd
));
283 g_list_append (entries
, menu_entry_create (_("Switch &panels on/off"), CK_ShowCommandLine
));
285 g_list_append (entries
, menu_entry_create (_("&Compare directories"), CK_CompareDirsCmd
));
287 entries
= g_list_append (entries
, menu_entry_create (_("&View diff files"), CK_DiffViewCmd
));
290 g_list_append (entries
, menu_entry_create (_("E&xternal panelize"), CK_ExternalPanelize
));
292 g_list_append (entries
,
293 menu_entry_create (_("Show directory s&izes"), CK_SingleDirsizeCmd
));
294 entries
= g_list_append (entries
, menu_separator_create ());
295 entries
= g_list_append (entries
, menu_entry_create (_("Command &history"), CK_HistoryCmd
));
297 g_list_append (entries
, menu_entry_create (_("Di&rectory hotlist"), CK_QuickChdirCmd
));
299 entries
= g_list_append (entries
, menu_entry_create (_("&Active VFS list"), CK_ReselectVfs
));
301 #ifdef WITH_BACKGROUND
302 entries
= g_list_append (entries
, menu_entry_create (_("&Background jobs"), CK_JobsCmd
));
304 entries
= g_list_append (entries
, menu_entry_create (_("Screen lis&t"), CK_DialogListCmd
));
305 entries
= g_list_append (entries
, menu_separator_create ());
306 #ifdef ENABLE_VFS_UNDELFS
308 g_list_append (entries
,
309 menu_entry_create (_("&Undelete files (ext2fs only)"), CK_UndeleteCmd
));
311 #ifdef LISTMODE_EDITOR
313 g_list_append (entries
, menu_entry_create (_("&Listing format edit"), CK_ListmodeCmd
));
315 #if defined (ENABLE_VFS_UNDELFS) || defined (LISTMODE_EDITOR)
316 entries
= g_list_append (entries
, menu_separator_create ());
319 g_list_append (entries
, menu_entry_create (_("Edit &extension file"), CK_EditExtFileCmd
));
320 entries
= g_list_append (entries
, menu_entry_create (_("Edit &menu file"), CK_EditMcMenuCmd
));
322 g_list_append (entries
,
323 menu_entry_create (_("Edit hi&ghlighting group file"), CK_EditFhlFileCmd
));
328 /* --------------------------------------------------------------------------------------------- */
331 create_options_menu (void)
333 GList
*entries
= NULL
;
335 entries
= g_list_append (entries
, menu_entry_create (_("&Configuration..."), CK_ConfigureBox
));
336 entries
= g_list_append (entries
, menu_entry_create (_("&Layout..."), CK_LayoutBox
));
338 g_list_append (entries
, menu_entry_create (_("&Panel options..."), CK_PanelOptionsBox
));
339 entries
= g_list_append (entries
, menu_entry_create (_("C&onfirmation..."), CK_ConfirmBox
));
340 entries
= g_list_append (entries
, menu_entry_create (_("&Display bits..."), CK_DisplayBitsBox
));
341 entries
= g_list_append (entries
, menu_entry_create (_("Learn &keys..."), CK_LearnKeys
));
343 entries
= g_list_append (entries
, menu_entry_create (_("&Virtual FS..."), CK_ConfigureVfs
));
345 entries
= g_list_append (entries
, menu_separator_create ());
346 entries
= g_list_append (entries
, menu_entry_create (_("&Save setup"), CK_SaveSetupCmd
));
351 /* --------------------------------------------------------------------------------------------- */
356 left_menu
= create_menu ("", create_panel_menu (), "[Left and Right Menus]");
357 menubar_add_menu (the_menubar
, left_menu
);
358 menubar_add_menu (the_menubar
, create_menu (_("&File"), create_file_menu (), "[File Menu]"));
359 menubar_add_menu (the_menubar
,
360 create_menu (_("&Command"), create_command_menu (), "[Command Menu]"));
361 menubar_add_menu (the_menubar
,
362 create_menu (_("&Options"), create_options_menu (), "[Options Menu]"));
363 right_menu
= create_menu ("", create_panel_menu (), "[Left and Right Menus]");
364 menubar_add_menu (the_menubar
, right_menu
);
368 /* --------------------------------------------------------------------------------------------- */
371 menu_last_selected_cmd (void)
373 the_menubar
->is_active
= TRUE
;
374 the_menubar
->is_dropped
= (drop_menus
!= 0);
375 the_menubar
->previous_widget
= dlg_get_current_widget_id (midnight_dlg
);
376 dlg_select_widget (the_menubar
);
379 /* --------------------------------------------------------------------------------------------- */
384 if (the_menubar
->is_active
)
387 if ((get_current_index () == 0) == (current_panel
->active
!= 0))
388 the_menubar
->selected
= 0;
390 the_menubar
->selected
= g_list_length (the_menubar
->menu
) - 1;
391 menu_last_selected_cmd ();
394 /* --------------------------------------------------------------------------------------------- */
400 const panel_field_t
*sort_order
;
402 if (!SELECTED_IS_PANEL
)
406 sort_order
= sort_box (&p
->sort_info
);
407 panel_set_sort_order (p
, sort_order
);
410 /* --------------------------------------------------------------------------------------------- */
413 midnight_get_shortcut (unsigned long command
)
416 const char *shortcut
= NULL
;
418 shortcut
= keybind_lookup_keymap_shortcut (main_map
, command
);
419 if (shortcut
!= NULL
)
420 return g_strdup (shortcut
);
422 shortcut
= keybind_lookup_keymap_shortcut (panel_map
, command
);
423 if (shortcut
!= NULL
)
424 return g_strdup (shortcut
);
426 ext_map
= keybind_lookup_keymap_shortcut (main_map
, CK_StartExtMap1
);
428 shortcut
= keybind_lookup_keymap_shortcut (main_x_map
, command
);
429 if (shortcut
!= NULL
)
430 return g_strdup_printf ("%s %s", ext_map
, shortcut
);
435 /* --------------------------------------------------------------------------------------------- */
438 midnight_get_title (const Dlg_head
* h
, size_t len
)
440 /* TODO: share code with update_xterm_title_path() */
445 struct passwd
*pw
= NULL
;
451 path
= strip_home_and_password (current_panel
->cwd
);
452 res
= gethostname (host
, sizeof (host
));
456 host
[sizeof (host
) - 1] = '\0';
458 pw
= getpwuid (getuid ());
460 login
= g_strdup_printf ("%s@%s", pw
->pw_name
, host
);
462 login
= g_strdup (host
);
464 p
= g_strdup_printf ("%s [%s]:%s", _("Panels:"), login
, path
);
465 path
= str_trunc (p
, len
- 4);
469 return g_strdup (path
);
472 /* --------------------------------------------------------------------------------------------- */
475 toggle_panels_split (void)
477 horizontal_split
= !horizontal_split
;
482 /* --------------------------------------------------------------------------------------------- */
485 * Just a hack for allowing url-like pathnames to be accepted from the
489 translated_mc_chdir (char *dir
)
494 newdir
= vfs_translate_url (dir
);
495 ret
= mc_chdir (newdir
);
499 /* --------------------------------------------------------------------------------------------- */
506 panel_view_mode_t current_mode
, other_mode
;
507 char original_dir
[BUF_1K
] = "\0";
509 if (boot_current_is_left
)
513 current_mode
= startup_left_mode
;
514 other_mode
= startup_right_mode
;
520 current_mode
= startup_right_mode
;
521 other_mode
= startup_left_mode
;
523 /* Creates the left panel */
524 if (mc_run_param0
!= NULL
)
526 if (mc_run_param1
!= NULL
)
528 /* Ok, user has specified two dirs, save the original one,
529 * since we may not be able to chdir to the proper
530 * second directory later
532 mc_get_current_wd (original_dir
, sizeof (original_dir
) - 2);
534 translated_mc_chdir (mc_run_param0
);
536 set_display_type (current_index
, current_mode
);
538 /* The other panel */
539 if (mc_run_param1
!= NULL
)
541 if (original_dir
[0] != '\0')
542 translated_mc_chdir (original_dir
);
543 translated_mc_chdir (mc_run_param1
);
545 set_display_type (other_index
, other_mode
);
547 if (startup_left_mode
== view_listing
)
549 current_panel
= left_panel
;
554 current_panel
= right_panel
;
556 current_panel
= left_panel
;
559 /* Create the nice widgets */
560 cmdline
= command_new (0, 0, 0);
561 the_prompt
= label_new (0, 0, mc_prompt
);
562 the_prompt
->transparent
= 1;
563 the_bar
= buttonbar_new (keybar_visible
);
565 the_hint
= label_new (0, 0, 0);
566 the_hint
->transparent
= 1;
567 the_hint
->auto_adjust_cols
= 0;
568 the_hint
->widget
.cols
= COLS
;
570 the_menubar
= menubar_new (0, 0, COLS
, NULL
);
573 /* --------------------------------------------------------------------------------------------- */
576 copy_current_pathname (void)
582 cwd_path
= remove_encoding_from_path (current_panel
->cwd
);
583 command_insert (cmdline
, cwd_path
, FALSE
);
585 if (cwd_path
[strlen (cwd_path
) - 1] != PATH_SEP
)
586 command_insert (cmdline
, PATH_SEP_STR
, FALSE
);
590 /* --------------------------------------------------------------------------------------------- */
593 copy_other_pathname (void)
597 if (get_other_type () != view_listing
)
603 cwd_path
= remove_encoding_from_path (other_panel
->cwd
);
604 command_insert (cmdline
, cwd_path
, FALSE
);
606 if (cwd_path
[strlen (cwd_path
) - 1] != PATH_SEP
)
607 command_insert (cmdline
, PATH_SEP_STR
, FALSE
);
611 /* --------------------------------------------------------------------------------------------- */
614 copy_readlink (WPanel
* panel
)
618 if (S_ISLNK (selection (panel
)->st
.st_mode
))
620 char buffer
[MC_MAXPATHLEN
];
621 char *p
= concat_dir_and_file (panel
->cwd
, selection (panel
)->fname
);
624 i
= mc_readlink (p
, buffer
, MC_MAXPATHLEN
- 1);
629 command_insert (cmdline
, buffer
, TRUE
);
634 /* --------------------------------------------------------------------------------------------- */
637 copy_current_readlink (void)
639 copy_readlink (current_panel
);
642 /* --------------------------------------------------------------------------------------------- */
645 copy_other_readlink (void)
647 if (get_other_type () == view_listing
)
648 copy_readlink (other_panel
);
651 /* --------------------------------------------------------------------------------------------- */
653 /** Insert the selected file name into the input line */
655 copy_prog_name (void)
661 if (get_current_type () == view_tree
)
663 WTree
*tree
= (WTree
*) get_panel_widget (get_current_index ());
664 tmp
= tree_selected_name (tree
);
667 tmp
= selection (current_panel
)->fname
;
669 command_insert (cmdline
, tmp
, TRUE
);
672 /* --------------------------------------------------------------------------------------------- */
675 copy_tagged (WPanel
* panel
)
681 input_disable_update (cmdline
);
684 for (i
= 0; i
< panel
->count
; i
++)
686 if (panel
->dir
.list
[i
].f
.marked
)
687 command_insert (cmdline
, panel
->dir
.list
[i
].fname
, TRUE
);
692 command_insert (cmdline
, panel
->dir
.list
[panel
->selected
].fname
, TRUE
);
694 input_enable_update (cmdline
);
697 /* --------------------------------------------------------------------------------------------- */
700 copy_current_tagged (void)
702 copy_tagged (current_panel
);
705 /* --------------------------------------------------------------------------------------------- */
708 copy_other_tagged (void)
710 if (get_other_type () == view_listing
)
711 copy_tagged (other_panel
);
714 /* --------------------------------------------------------------------------------------------- */
719 ctl_x_map_enabled
= TRUE
;
722 /* --------------------------------------------------------------------------------------------- */
725 init_xterm_support (void)
727 const char *termvalue
;
729 termvalue
= getenv ("TERM");
730 if (!termvalue
|| !(*termvalue
))
732 fputs (_("The TERM environment variable is unset!\n"), stderr
);
736 /* Check mouse capabilities */
737 xmouse_seq
= tty_tgetstr ("Km");
739 if (strcmp (termvalue
, "cygwin") == 0)
741 mc_args__force_xterm
= 1;
742 use_mouse_p
= MOUSE_DISABLED
;
745 if (mc_args__force_xterm
|| strncmp (termvalue
, "xterm", 5) == 0
746 || strncmp (termvalue
, "konsole", 7) == 0
747 || strncmp (termvalue
, "rxvt", 4) == 0
748 || strcmp (termvalue
, "Eterm") == 0 || strcmp (termvalue
, "dtterm") == 0)
752 /* Default to the standard xterm sequence */
755 xmouse_seq
= ESC_STR
"[M";
758 /* Enable mouse unless explicitly disabled by --nomouse */
759 if (use_mouse_p
!= MOUSE_DISABLED
)
761 const char *color_term
= getenv ("COLORTERM");
762 if (strncmp (termvalue
, "rxvt", 4) == 0 ||
763 (color_term
!= NULL
&& strncmp (color_term
, "rxvt", 4) == 0) ||
764 strcmp (termvalue
, "Eterm") == 0)
766 use_mouse_p
= MOUSE_XTERM_NORMAL_TRACKING
;
770 use_mouse_p
= MOUSE_XTERM_BUTTON_EVENT_TRACKING
;
776 /* --------------------------------------------------------------------------------------------- */
782 tty_display_8bit (full_eight_bits
!= 0);
784 tty_display_8bit (eight_bit_clean
!= 0);
787 #ifdef HAVE_SUBSHELL_SUPPORT
789 add_select_channel (subshell_pty
, load_prompt
, 0);
790 #endif /* !HAVE_SUBSHELL_SUPPORT */
792 tty_setup_sigwinch (sigwinch_handler
);
794 if ((tty_baudrate () < 9600) || tty_is_slow ())
797 init_xterm_support ();
801 /* --------------------------------------------------------------------------------------------- */
804 setup_dummy_mc (void)
806 char d
[MC_MAXPATHLEN
];
809 mc_get_current_wd (d
, MC_MAXPATHLEN
);
814 /* --------------------------------------------------------------------------------------------- */
819 if ((quit
& SUBSHELL_EXIT
) == 0)
821 tty_reset_shell_mode ();
826 /* --------------------------------------------------------------------------------------------- */
835 * We sync the profiles since the hotlist may have changed, while
836 * we only change the setup data if we have the auto save feature set
839 save_setup (auto_save_setup
, panels_options
.auto_save_setup
);
842 vfs_stamp_path (vfs_get_current_dir ());
844 if ((current_panel
!= NULL
) && (get_current_type () == view_listing
))
845 vfs_stamp_path (current_panel
->cwd
);
847 if ((other_panel
!= NULL
) && (get_other_type () == view_listing
))
848 vfs_stamp_path (other_panel
->cwd
);
851 /* --------------------------------------------------------------------------------------------- */
854 create_panels_and_run_mc (void)
856 midnight_dlg
->get_shortcut
= midnight_get_shortcut
;
857 midnight_dlg
->get_title
= midnight_get_title
;
861 add_widget (midnight_dlg
, the_menubar
);
864 add_widget (midnight_dlg
, get_panel_widget (0));
865 add_widget (midnight_dlg
, get_panel_widget (1));
867 add_widget (midnight_dlg
, the_hint
);
868 add_widget (midnight_dlg
, cmdline
);
869 add_widget (midnight_dlg
, the_prompt
);
871 add_widget (midnight_dlg
, the_bar
);
872 midnight_set_buttonbar (the_bar
);
874 /* Run the Midnight Commander if no file was specified in the command line */
875 run_dlg (midnight_dlg
);
878 /* --------------------------------------------------------------------------------------------- */
880 /** result must be free'd (I think this should go in util.c) */
882 prepend_cwd_on_local (const char *filename
)
887 if (!vfs_file_is_local (filename
) || g_path_is_absolute (filename
))
888 return g_strdup (filename
);
890 d
= g_malloc (MC_MAXPATHLEN
+ strlen (filename
) + 2);
891 mc_get_current_wd (d
, MC_MAXPATHLEN
);
894 strcpy (d
+ l
, filename
);
895 canonicalize_pathname (d
);
899 /* --------------------------------------------------------------------------------------------- */
901 /** Invoke the internal view/edit routine with:
902 * the default processing and forcing the internal viewer/editor
905 mc_maybe_editor_or_viewer (void)
909 #ifdef USE_INTERNAL_EDIT
911 edit_file (mc_run_param0
, mc_args__edit_start_line
);
913 #endif /* USE_INTERNAL_EDIT */
917 path
= prepend_cwd_on_local (mc_run_param0
);
918 view_file (path
, 0, 1);
923 case MC_RUN_DIFFVIEWER
:
924 diff_view (mc_run_param0
, mc_run_param1
, mc_run_param0
, mc_run_param1
);
926 #endif /* USE_DIFF_VIEW */
932 /* --------------------------------------------------------------------------------------------- */
935 quit_cmd_internal (int quiet
)
940 n
= dialog_switch_num () - 1;
943 char msg
[BUF_MEDIUM
];
945 g_snprintf (msg
, sizeof (msg
),
946 ngettext ("You have %zd opened screen. Quit anyway?",
947 "You have %zd opened screens. Quit anyway?", n
), n
);
949 if (query_dialog (_("The Midnight Commander"), msg
, D_NORMAL
, 2, _("&Yes"), _("&No")) != 0)
953 else if (quiet
|| !confirm_exit
)
955 else if (query_dialog (_("The Midnight Commander"),
956 _("Do you really want to quit the Midnight Commander?"),
957 D_NORMAL
, 2, _("&Yes"), _("&No")) == 0)
962 #ifdef HAVE_SUBSHELL_SUPPORT
965 else if ((q
= exit_subshell ()))
975 /* --------------------------------------------------------------------------------------------- */
980 return quit_cmd_internal (0);
983 /* --------------------------------------------------------------------------------------------- */
986 toggle_show_hidden (void)
988 panels_options
.show_dot_files
= !panels_options
.show_dot_files
;
989 update_panels (UP_RELOAD
, UP_KEEPSEL
);
992 /* --------------------------------------------------------------------------------------------- */
995 * Repaint the contents of the panels without frames. To schedule panel
996 * for repainting, set panel->dirty to 1. There are many reasons why
997 * the panels need to be repainted, and this is a costly operation, so
998 * it's done once per event.
1002 update_dirty_panels (void)
1004 if (get_current_type () == view_listing
&& current_panel
->dirty
)
1005 send_message ((Widget
*) current_panel
, WIDGET_DRAW
, 0);
1007 if (get_other_type () == view_listing
&& other_panel
->dirty
)
1008 send_message ((Widget
*) other_panel
, WIDGET_DRAW
, 0);
1011 /* --------------------------------------------------------------------------------------------- */
1014 midnight_execute_cmd (Widget
* sender
, unsigned long command
)
1016 cb_ret_t res
= MSG_HANDLED
;
1020 /* stop quick search before executing any command */
1021 send_message ((Widget
*) current_panel
, WIDGET_COMMAND
, CK_PanelStopSearch
);
1028 case CK_ChangeListingCmd
:
1029 change_listing_cmd ();
1037 case CK_ChownAdvancedCmd
:
1038 chown_advanced_cmd ();
1040 case CK_CompareDirsCmd
:
1041 compare_dirs_cmd ();
1043 case CK_ConfigureBox
:
1047 case CK_ConfigureVfs
:
1057 case CK_CopyCurrentPathname
:
1058 copy_current_pathname ();
1060 case CK_CopyCurrentReadlink
:
1061 copy_current_readlink ();
1063 case CK_CopyCurrentTagged
:
1064 copy_current_tagged ();
1066 case CK_CopyOtherPathname
:
1067 copy_other_pathname ();
1069 case CK_CopyOtherReadlink
:
1070 copy_other_readlink ();
1072 case CK_CopyOtherTagged
:
1073 copy_other_tagged ();
1078 case CK_DialogListCmd
:
1079 dialog_switch_list ();
1081 #ifdef USE_DIFF_VIEW
1082 case CK_DiffViewCmd
:
1086 case CK_DisplayBitsBox
:
1087 display_bits_box ();
1092 #ifdef USE_INTERNAL_EDIT
1093 case CK_EditForceInternalCmd
:
1094 edit_cmd_force_internal ();
1097 case CK_EditExtFileCmd
:
1100 case CK_EditFhlFileCmd
:
1103 case CK_EditMcMenuCmd
:
1104 edit_mc_menu_cmd ();
1106 case CK_EditSymlinkCmd
:
1107 edit_symlink_cmd ();
1109 case CK_ExternalPanelize
:
1110 external_panelize ();
1115 case CK_FilteredViewCmd
:
1116 filtered_view_cmd ();
1121 #ifdef ENABLE_VFS_FISH
1122 case CK_FishlinkCmd
:
1126 #ifdef ENABLE_VFS_FTP
1138 if (sender
== (Widget
*) the_menubar
)
1139 info_cmd (); /* mwnu */
1141 info_cmd_no_menu (); /* shortcut or buttonbar */
1143 #ifdef WITH_BACKGROUND
1155 link_cmd (LINK_HARDLINK
);
1160 #ifdef LISTMODE_EDITOR
1161 case CK_ListmodeCmd
:
1168 case CK_MenuLastSelectedCmd
:
1169 menu_last_selected_cmd ();
1174 case CK_PanelOptionsBox
:
1175 panel_options_box ();
1178 case CK_PanelSetPanelEncoding
:
1185 case CK_QuickChdirCmd
:
1188 case CK_QuickViewCmd
:
1189 if (sender
== (Widget
*) the_menubar
)
1190 quick_view_cmd (); /* menu */
1192 quick_cmd_no_menu (); /* shortcut or buttonabr */
1194 case CK_QuietQuitCmd
:
1200 case CK_RelativeSymlinkCmd
:
1201 link_cmd (LINK_SYMLINK_RELATIVE
);
1210 case CK_ReselectVfs
:
1214 case CK_ReverseSelectionCmd
:
1215 reverse_selection_cmd ();
1217 case CK_SaveSetupCmd
:
1223 case CK_ShowCommandLine
:
1226 case CK_SingleDirsizeCmd
:
1227 smart_dirsize_cmd ();
1229 #ifdef ENABLE_VFS_SMB
1233 #endif /* ENABLE_VFS_SMB */
1237 case CK_StartExtMap1
:
1247 link_cmd (LINK_SYMLINK_ABSOLUTE
);
1249 case CK_ToggleListingCmd
:
1250 toggle_listing_cmd ();
1252 case CK_ToggleShowHidden
:
1253 toggle_show_hidden ();
1255 case CK_TogglePanelsSplit
:
1256 toggle_panels_split ();
1264 #ifdef ENABLE_VFS_UNDELFS
1265 case CK_UndeleteCmd
:
1269 case CK_UnselectCmd
:
1272 case CK_UserMenuCmd
:
1273 user_file_menu_cmd ();
1278 case CK_ViewFileCmd
:
1282 res
= MSG_NOT_HANDLED
;
1288 /* --------------------------------------------------------------------------------------------- */
1291 midnight_callback (Dlg_head
* h
, Widget
* sender
, dlg_msg_t msg
, int parm
, void *data
)
1293 unsigned long command
;
1304 /* We handle the special case of the output lines */
1305 if (console_flag
&& output_lines
)
1306 show_console_contents (output_start_y
,
1307 LINES
- output_lines
- keybar_visible
-
1308 1, LINES
- keybar_visible
- 1);
1313 menubar_arrange (the_menubar
);
1317 /* We only need the first idle event to show user menu after start */
1318 set_idle_proc (h
, 0);
1320 if (boot_current_is_left
)
1321 dlg_select_widget (get_panel_widget (0));
1323 dlg_select_widget (get_panel_widget (1));
1326 midnight_execute_cmd (NULL
, CK_UserMenuCmd
);
1330 if (ctl_x_map_enabled
)
1332 ctl_x_map_enabled
= FALSE
;
1333 command
= keybind_lookup_keymap_command (main_x_map
, parm
);
1334 if (command
!= CK_Ignore_Key
)
1335 return midnight_execute_cmd (NULL
, command
);
1338 /* FIXME: should handle all menu shortcuts before this point */
1339 if (the_menubar
->is_active
)
1340 return MSG_NOT_HANDLED
;
1343 input_free_completions (cmdline
);
1349 for (i
= 0; cmdline
->buffer
[i
] != '\0' &&
1350 (cmdline
->buffer
[i
] == ' ' || cmdline
->buffer
[i
] == '\t'); i
++)
1353 if (cmdline
->buffer
[i
] != '\0')
1355 send_message ((Widget
*) cmdline
, WIDGET_KEY
, parm
);
1359 input_insert (cmdline
, "", FALSE
);
1363 /* Ctrl-Enter and Alt-Enter */
1364 if (((parm
& ~(KEY_M_CTRL
| KEY_M_ALT
)) == '\n') && (parm
& (KEY_M_CTRL
| KEY_M_ALT
)))
1370 /* Ctrl-Shift-Enter */
1371 if (parm
== (KEY_M_CTRL
| KEY_M_SHIFT
| '\n'))
1373 copy_current_pathname ();
1378 if ((!alternate_plus_minus
|| !(console_flag
|| xterm_flag
))
1379 && !quote
&& !current_panel
->searching
)
1381 if (!only_leading_plus_minus
)
1383 /* Special treatement, since the input line will eat them */
1390 if (parm
== '\\' || parm
== '-')
1398 reverse_selection_cmd ();
1402 else if (!command_prompt
|| !cmdline
->buffer
[0])
1404 /* Special treatement '+', '-', '\', '*' only when this is
1405 * first char on input line
1414 if (parm
== '\\' || parm
== '-')
1422 reverse_selection_cmd ();
1427 return MSG_NOT_HANDLED
;
1429 case DLG_HOTKEY_HANDLED
:
1430 if ((get_current_type () == view_listing
) && current_panel
->searching
)
1432 current_panel
->dirty
= 1; /* FIXME: unneeded? */
1433 send_message ((Widget
*) current_panel
, WIDGET_COMMAND
, CK_PanelStopSearch
);
1437 case DLG_UNHANDLED_KEY
:
1442 v
= send_message ((Widget
*) cmdline
, WIDGET_KEY
, parm
);
1443 if (v
== MSG_HANDLED
)
1447 if (ctl_x_map_enabled
)
1449 ctl_x_map_enabled
= FALSE
;
1450 command
= keybind_lookup_keymap_command (main_x_map
, parm
);
1453 command
= keybind_lookup_keymap_command (main_map
, parm
);
1455 return (command
== CK_Ignore_Key
) ? MSG_NOT_HANDLED
: midnight_execute_cmd (NULL
, command
);
1458 if (!the_menubar
->is_active
)
1459 update_dirty_panels ();
1465 midnight_execute_cmd (NULL
, parm
);
1466 /* message from menu */
1467 else if (sender
== (Widget
*) the_menubar
)
1468 midnight_execute_cmd (sender
, parm
);
1469 /* message from buttonbar */
1470 else if (sender
== (Widget
*) the_bar
)
1473 midnight_execute_cmd (sender
, parm
);
1475 send_message ((Widget
*) data
, WIDGET_COMMAND
, parm
);
1484 return default_dlg_callback (h
, sender
, msg
, parm
, data
);
1488 /* --------------------------------------------------------------------------------------------- */
1489 /*** public functions ****************************************************************************/
1490 /* --------------------------------------------------------------------------------------------- */
1495 menu_set_name (left_menu
, horizontal_split
? _("&Above") : _("&Left"));
1496 menu_set_name (right_menu
, horizontal_split
? _("&Below") : _("&Right"));
1497 menubar_arrange (the_menubar
);
1498 menubar_set_visible (the_menubar
, menubar_visible
);
1502 midnight_set_buttonbar (WButtonBar
* b
)
1504 buttonbar_set_label (b
, 1, Q_ ("ButtonBar|Help"), main_map
, NULL
);
1505 buttonbar_set_label (b
, 2, Q_ ("ButtonBar|Menu"), main_map
, NULL
);
1506 buttonbar_set_label (b
, 3, Q_ ("ButtonBar|View"), main_map
, NULL
);
1507 buttonbar_set_label (b
, 4, Q_ ("ButtonBar|Edit"), main_map
, NULL
);
1508 buttonbar_set_label (b
, 5, Q_ ("ButtonBar|Copy"), main_map
, NULL
);
1509 buttonbar_set_label (b
, 6, Q_ ("ButtonBar|RenMov"), main_map
, NULL
);
1510 buttonbar_set_label (b
, 7, Q_ ("ButtonBar|Mkdir"), main_map
, NULL
);
1511 buttonbar_set_label (b
, 8, Q_ ("ButtonBar|Delete"), main_map
, NULL
);
1512 buttonbar_set_label (b
, 9, Q_ ("ButtonBar|PullDn"), main_map
, NULL
);
1513 buttonbar_set_label (b
, 10, Q_ ("ButtonBar|Quit"), main_map
, NULL
);
1516 /* --------------------------------------------------------------------------------------------- */
1518 * Load new hint and display it.
1519 * IF force is not 0, ignore the timeout.
1523 load_hint (gboolean force
)
1527 if (the_hint
->widget
.owner
== NULL
)
1530 if (!message_visible
)
1532 label_set_text (the_hint
, NULL
);
1536 hint
= get_random_hint (force
);
1546 char text
[BUF_SMALL
];
1548 g_snprintf (text
, sizeof (text
), _("GNU Midnight Commander %s\n"), VERSION
);
1553 /* --------------------------------------------------------------------------------------------- */
1558 input_free_completions (cmdline
);
1559 dlg_one_down (midnight_dlg
);
1562 /* --------------------------------------------------------------------------------------------- */
1564 /** Save current stat of directories to avoid reloading the panels
1565 * when no modifications have taken place
1568 save_cwds_stat (void)
1570 if (panels_options
.fast_reload
)
1572 mc_stat (current_panel
->cwd
, &(current_panel
->dir_stat
));
1573 if (get_other_type () == view_listing
)
1574 mc_stat (other_panel
->cwd
, &(other_panel
->dir_stat
));
1578 /* --------------------------------------------------------------------------------------------- */
1581 quiet_quit_cmd (void)
1583 print_last_revert
= TRUE
;
1584 return quit_cmd_internal (1);
1587 /* --------------------------------------------------------------------------------------------- */
1589 /** Run the main dialog that occupies the whole screen */
1593 dlg_colors_t midnight_colors
;
1595 midnight_colors
[DLG_COLOR_NORMAL
] = mc_skin_color_get ("dialog", "_default_");
1596 midnight_colors
[DLG_COLOR_FOCUS
] = mc_skin_color_get ("dialog", "focus");
1597 midnight_colors
[DLG_COLOR_HOT_NORMAL
] = mc_skin_color_get ("dialog", "hotnormal");
1598 midnight_colors
[DLG_COLOR_HOT_FOCUS
] = mc_skin_color_get ("dialog", "hotfocus");
1599 midnight_colors
[DLG_COLOR_TITLE
] = mc_skin_color_get ("dialog", "title");
1601 #ifdef USE_INTERNAL_EDIT
1605 midnight_dlg
= create_dlg (FALSE
, 0, 0, LINES
, COLS
, midnight_colors
, midnight_callback
,
1606 "[main]", NULL
, DLG_WANT_IDLE
);
1608 if (mc_run_mode
== MC_RUN_FULL
)
1613 /* Check if we were invoked as an editor or file viewer */
1614 if (mc_run_mode
!= MC_RUN_FULL
)
1615 mc_maybe_editor_or_viewer ();
1618 create_panels_and_run_mc ();
1620 /* destroy_dlg destroys even current_panel->cwd, so we have to save a copy :) */
1621 if (mc_args__last_wd_file
!= NULL
&& vfs_current_is_local ())
1622 last_wd_string
= g_strdup (current_panel
->cwd
);
1626 midnight_shutdown
= 1;
1627 dialog_switch_shutdown ();
1629 destroy_dlg (midnight_dlg
);
1630 current_panel
= NULL
;
1632 #ifdef USE_INTERNAL_EDIT
1637 /* --------------------------------------------------------------------------------------------- */