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 /* The dialog handle for the main program */
116 Dlg_head
*midnight_dlg
= NULL
;
118 /*** file scope macro definitions ****************************************************************/
122 * Don't restrict the output on the screen manager level,
123 * the translation tables take care of it.
125 #define full_eight_bits (1)
126 #define eight_bit_clean (1)
127 #endif /* !HAVE_CHARSET */
129 /*** file scope type declarations ****************************************************************/
131 /*** file scope variables ************************************************************************/
133 static Menu
*left_menu
, *right_menu
;
135 static gboolean ctl_x_map_enabled
= FALSE
;
137 /*** file scope functions ************************************************************************/
139 /** Stop MC main dialog and the current dialog if it exists.
140 * Needed to provide fast exit from MC viewer or editor on shell exit */
144 midnight_dlg
->state
= DLG_CLOSED
;
146 if ((top_dlg
!= NULL
) && (top_dlg
->data
!= NULL
))
147 ((Dlg_head
*) top_dlg
->data
)->state
= DLG_CLOSED
;
150 /* --------------------------------------------------------------------------------------------- */
157 sel_dir
= tree_box (selection (current_panel
)->fname
);
160 do_cd (sel_dir
, cd_exact
);
165 /* --------------------------------------------------------------------------------------------- */
167 #ifdef LISTMODE_EDITOR
173 if (get_current_type () != view_listing
)
176 newmode
= listmode_edit (current_panel
->user_format
);
180 g_free (current_panel
->user_format
);
181 current_panel
->list_type
= list_user
;
182 current_panel
->user_format
= newmode
;
183 set_panel_formats (current_panel
);
187 #endif /* LISTMODE_EDITOR */
189 /* --------------------------------------------------------------------------------------------- */
192 create_panel_menu (void)
194 GList
*entries
= NULL
;
196 entries
= g_list_append (entries
, menu_entry_create (_("File listin&g"), CK_ListingCmd
));
197 entries
= g_list_append (entries
, menu_entry_create (_("&Quick view"), CK_QuickViewCmd
));
198 entries
= g_list_append (entries
, menu_entry_create (_("&Info"), CK_InfoCmd
));
199 entries
= g_list_append (entries
, menu_entry_create (_("&Tree"), CK_TreeCmd
));
200 entries
= g_list_append (entries
, menu_separator_create ());
202 g_list_append (entries
, menu_entry_create (_("&Listing mode..."), CK_ChangeListingCmd
));
203 entries
= g_list_append (entries
, menu_entry_create (_("&Sort order..."), CK_Sort
));
204 entries
= g_list_append (entries
, menu_entry_create (_("&Filter..."), CK_FilterCmd
));
207 g_list_append (entries
, menu_entry_create (_("&Encoding..."), CK_PanelSetPanelEncoding
));
209 #ifdef ENABLE_VFS_NET
210 entries
= g_list_append (entries
, menu_separator_create ());
211 #ifdef ENABLE_VFS_FTP
212 entries
= g_list_append (entries
, menu_entry_create (_("FT&P link..."), CK_FtplinkCmd
));
214 #ifdef ENABLE_VFS_FISH
215 entries
= g_list_append (entries
, menu_entry_create (_("S&hell link..."), CK_FishlinkCmd
));
217 #ifdef ENABLE_VFS_SMB
218 entries
= g_list_append (entries
, menu_entry_create (_("SM&B link..."), CK_SmblinkCmd
));
220 #endif /* ENABLE_VFS_NET */
221 entries
= g_list_append (entries
, menu_separator_create ());
222 entries
= g_list_append (entries
, menu_entry_create (_("&Rescan"), CK_RereadCmd
));
227 /* --------------------------------------------------------------------------------------------- */
230 create_file_menu (void)
232 GList
*entries
= NULL
;
234 entries
= g_list_append (entries
, menu_entry_create (_("&View"), CK_ViewCmd
));
235 entries
= g_list_append (entries
, menu_entry_create (_("Vie&w file..."), CK_ViewFileCmd
));
236 entries
= g_list_append (entries
, menu_entry_create (_("&Filtered view"), CK_FilteredViewCmd
));
237 entries
= g_list_append (entries
, menu_entry_create (_("&Edit"), CK_EditCmd
));
238 entries
= g_list_append (entries
, menu_entry_create (_("&Copy"), CK_CopyCmd
));
239 entries
= g_list_append (entries
, menu_entry_create (_("C&hmod"), CK_ChmodCmd
));
240 entries
= g_list_append (entries
, menu_entry_create (_("&Link"), CK_LinkCmd
));
241 entries
= g_list_append (entries
, menu_entry_create (_("&Symlink"), CK_SymlinkCmd
));
243 g_list_append (entries
, menu_entry_create (_("Relative symlin&k"), CK_RelativeSymlinkCmd
));
244 entries
= g_list_append (entries
, menu_entry_create (_("Edit s&ymlink"), CK_EditSymlinkCmd
));
245 entries
= g_list_append (entries
, menu_entry_create (_("Ch&own"), CK_ChownCmd
));
247 g_list_append (entries
, menu_entry_create (_("&Advanced chown"), CK_ChownAdvancedCmd
));
248 entries
= g_list_append (entries
, menu_entry_create (_("&Rename/Move"), CK_RenameCmd
));
249 entries
= g_list_append (entries
, menu_entry_create (_("&Mkdir"), CK_MkdirCmd
));
250 entries
= g_list_append (entries
, menu_entry_create (_("&Delete"), CK_DeleteCmd
));
251 entries
= g_list_append (entries
, menu_entry_create (_("&Quick cd"), CK_QuickCdCmd
));
252 entries
= g_list_append (entries
, menu_separator_create ());
253 entries
= g_list_append (entries
, menu_entry_create (_("Select &group"), CK_SelectCmd
));
254 entries
= g_list_append (entries
, menu_entry_create (_("U&nselect group"), CK_UnselectCmd
));
256 g_list_append (entries
,
257 menu_entry_create (_("Reverse selec&tion"), CK_ReverseSelectionCmd
));
258 entries
= g_list_append (entries
, menu_separator_create ());
259 entries
= g_list_append (entries
, menu_entry_create (_("E&xit"), CK_QuitCmd
));
264 /* --------------------------------------------------------------------------------------------- */
267 create_command_menu (void)
269 /* I know, I'm lazy, but the tree widget when it's not running
270 * as a panel still has some problems, I have not yet finished
271 * the WTree widget port, sorry.
273 GList
*entries
= NULL
;
275 entries
= g_list_append (entries
, menu_entry_create (_("&User menu"), CK_UserMenuCmd
));
276 entries
= g_list_append (entries
, menu_entry_create (_("&Directory tree"), CK_TreeBoxCmd
));
277 entries
= g_list_append (entries
, menu_entry_create (_("&Find file"), CK_FindCmd
));
278 entries
= g_list_append (entries
, menu_entry_create (_("S&wap panels"), CK_SwapCmd
));
280 g_list_append (entries
, menu_entry_create (_("Switch &panels on/off"), CK_ShowCommandLine
));
282 g_list_append (entries
, menu_entry_create (_("&Compare directories"), CK_CompareDirsCmd
));
284 entries
= g_list_append (entries
, menu_entry_create (_("&View diff files"), CK_DiffViewCmd
));
287 g_list_append (entries
, menu_entry_create (_("E&xternal panelize"), CK_ExternalPanelize
));
289 g_list_append (entries
,
290 menu_entry_create (_("Show directory s&izes"), CK_SingleDirsizeCmd
));
291 entries
= g_list_append (entries
, menu_separator_create ());
292 entries
= g_list_append (entries
, menu_entry_create (_("Command &history"), CK_HistoryCmd
));
294 g_list_append (entries
, menu_entry_create (_("Di&rectory hotlist"), CK_QuickChdirCmd
));
296 entries
= g_list_append (entries
, menu_entry_create (_("&Active VFS list"), CK_ReselectVfs
));
298 #ifdef WITH_BACKGROUND
299 entries
= g_list_append (entries
, menu_entry_create (_("&Background jobs"), CK_JobsCmd
));
301 entries
= g_list_append (entries
, menu_entry_create (_("Screen lis&t"), CK_DialogListCmd
));
302 entries
= g_list_append (entries
, menu_separator_create ());
303 #ifdef ENABLE_VFS_UNDELFS
305 g_list_append (entries
,
306 menu_entry_create (_("&Undelete files (ext2fs only)"), CK_UndeleteCmd
));
308 #ifdef LISTMODE_EDITOR
310 g_list_append (entries
, menu_entry_create (_("&Listing format edit"), CK_ListmodeCmd
));
312 #if defined (ENABLE_VFS_UNDELFS) || defined (LISTMODE_EDITOR)
313 entries
= g_list_append (entries
, menu_separator_create ());
316 g_list_append (entries
, menu_entry_create (_("Edit &extension file"), CK_EditExtFileCmd
));
317 entries
= g_list_append (entries
, menu_entry_create (_("Edit &menu file"), CK_EditMcMenuCmd
));
319 g_list_append (entries
,
320 menu_entry_create (_("Edit hi&ghlighting group file"), CK_EditFhlFileCmd
));
325 /* --------------------------------------------------------------------------------------------- */
328 create_options_menu (void)
330 GList
*entries
= NULL
;
332 entries
= g_list_append (entries
, menu_entry_create (_("&Configuration..."), CK_ConfigureBox
));
333 entries
= g_list_append (entries
, menu_entry_create (_("&Layout..."), CK_LayoutBox
));
335 g_list_append (entries
, menu_entry_create (_("&Panel options..."), CK_PanelOptionsBox
));
336 entries
= g_list_append (entries
, menu_entry_create (_("C&onfirmation..."), CK_ConfirmBox
));
337 entries
= g_list_append (entries
, menu_entry_create (_("&Display bits..."), CK_DisplayBitsBox
));
338 entries
= g_list_append (entries
, menu_entry_create (_("Learn &keys..."), CK_LearnKeys
));
340 entries
= g_list_append (entries
, menu_entry_create (_("&Virtual FS..."), CK_ConfigureVfs
));
342 entries
= g_list_append (entries
, menu_separator_create ());
343 entries
= g_list_append (entries
, menu_entry_create (_("&Save setup"), CK_SaveSetupCmd
));
348 /* --------------------------------------------------------------------------------------------- */
353 left_menu
= create_menu ("", create_panel_menu (), "[Left and Right Menus]");
354 menubar_add_menu (the_menubar
, left_menu
);
355 menubar_add_menu (the_menubar
, create_menu (_("&File"), create_file_menu (), "[File Menu]"));
356 menubar_add_menu (the_menubar
,
357 create_menu (_("&Command"), create_command_menu (), "[Command Menu]"));
358 menubar_add_menu (the_menubar
,
359 create_menu (_("&Options"), create_options_menu (), "[Options Menu]"));
360 right_menu
= create_menu ("", create_panel_menu (), "[Left and Right Menus]");
361 menubar_add_menu (the_menubar
, right_menu
);
365 /* --------------------------------------------------------------------------------------------- */
368 menu_last_selected_cmd (void)
370 the_menubar
->is_active
= TRUE
;
371 the_menubar
->is_dropped
= (drop_menus
!= 0);
372 the_menubar
->previous_widget
= dlg_get_current_widget_id (midnight_dlg
);
373 dlg_select_widget (the_menubar
);
376 /* --------------------------------------------------------------------------------------------- */
381 if (the_menubar
->is_active
)
384 if ((get_current_index () == 0) == (current_panel
->active
!= 0))
385 the_menubar
->selected
= 0;
387 the_menubar
->selected
= g_list_length (the_menubar
->menu
) - 1;
388 menu_last_selected_cmd ();
391 /* --------------------------------------------------------------------------------------------- */
397 const panel_field_t
*sort_order
;
399 if (!SELECTED_IS_PANEL
)
403 sort_order
= sort_box (&p
->sort_info
);
404 panel_set_sort_order (p
, sort_order
);
407 /* --------------------------------------------------------------------------------------------- */
410 midnight_get_shortcut (unsigned long command
)
413 const char *shortcut
= NULL
;
415 shortcut
= keybind_lookup_keymap_shortcut (main_map
, command
);
416 if (shortcut
!= NULL
)
417 return g_strdup (shortcut
);
419 shortcut
= keybind_lookup_keymap_shortcut (panel_map
, command
);
420 if (shortcut
!= NULL
)
421 return g_strdup (shortcut
);
423 ext_map
= keybind_lookup_keymap_shortcut (main_map
, CK_StartExtMap1
);
425 shortcut
= keybind_lookup_keymap_shortcut (main_x_map
, command
);
426 if (shortcut
!= NULL
)
427 return g_strdup_printf ("%s %s", ext_map
, shortcut
);
432 /* --------------------------------------------------------------------------------------------- */
435 midnight_get_title (const Dlg_head
* h
, size_t len
)
437 /* TODO: share code with update_xterm_title_path() */
442 struct passwd
*pw
= NULL
;
448 path
= strip_home_and_password (current_panel
->cwd
);
449 res
= gethostname (host
, sizeof (host
));
453 host
[sizeof (host
) - 1] = '\0';
455 pw
= getpwuid (getuid ());
457 login
= g_strdup_printf ("%s@%s", pw
->pw_name
, host
);
459 login
= g_strdup (host
);
461 p
= g_strdup_printf ("%s [%s]:%s", _("Panels:"), login
, path
);
462 path
= str_trunc (p
, len
- 4);
466 return g_strdup (path
);
469 /* --------------------------------------------------------------------------------------------- */
472 toggle_panels_split (void)
474 horizontal_split
= !horizontal_split
;
479 /* --------------------------------------------------------------------------------------------- */
482 * Just a hack for allowing url-like pathnames to be accepted from the
486 translated_mc_chdir (char *dir
)
491 newdir
= vfs_translate_url (dir
);
492 ret
= mc_chdir (newdir
);
496 /* --------------------------------------------------------------------------------------------- */
503 panel_view_mode_t current_mode
, other_mode
;
504 char original_dir
[BUF_1K
] = "\0";
506 if (boot_current_is_left
)
510 current_mode
= startup_left_mode
;
511 other_mode
= startup_right_mode
;
517 current_mode
= startup_right_mode
;
518 other_mode
= startup_left_mode
;
520 /* Creates the left panel */
521 if (mc_run_param0
!= NULL
)
523 if (mc_run_param1
!= NULL
)
525 /* Ok, user has specified two dirs, save the original one,
526 * since we may not be able to chdir to the proper
527 * second directory later
529 mc_get_current_wd (original_dir
, sizeof (original_dir
) - 2);
531 translated_mc_chdir (mc_run_param0
);
533 set_display_type (current_index
, current_mode
);
535 /* The other panel */
536 if (mc_run_param1
!= NULL
)
538 if (original_dir
[0] != '\0')
539 translated_mc_chdir (original_dir
);
540 translated_mc_chdir (mc_run_param1
);
542 set_display_type (other_index
, other_mode
);
544 if (startup_left_mode
== view_listing
)
546 current_panel
= left_panel
;
551 current_panel
= right_panel
;
553 current_panel
= left_panel
;
556 /* Create the nice widgets */
557 cmdline
= command_new (0, 0, 0);
558 the_prompt
= label_new (0, 0, mc_prompt
);
559 the_prompt
->transparent
= 1;
560 the_bar
= buttonbar_new (keybar_visible
);
562 the_hint
= label_new (0, 0, 0);
563 the_hint
->transparent
= 1;
564 the_hint
->auto_adjust_cols
= 0;
565 the_hint
->widget
.cols
= COLS
;
567 the_menubar
= menubar_new (0, 0, COLS
, NULL
);
570 /* --------------------------------------------------------------------------------------------- */
573 copy_current_pathname (void)
579 cwd_path
= remove_encoding_from_path (current_panel
->cwd
);
580 command_insert (cmdline
, cwd_path
, FALSE
);
582 if (cwd_path
[strlen (cwd_path
) - 1] != PATH_SEP
)
583 command_insert (cmdline
, PATH_SEP_STR
, FALSE
);
587 /* --------------------------------------------------------------------------------------------- */
590 copy_other_pathname (void)
594 if (get_other_type () != view_listing
)
600 cwd_path
= remove_encoding_from_path (other_panel
->cwd
);
601 command_insert (cmdline
, cwd_path
, FALSE
);
603 if (cwd_path
[strlen (cwd_path
) - 1] != PATH_SEP
)
604 command_insert (cmdline
, PATH_SEP_STR
, FALSE
);
608 /* --------------------------------------------------------------------------------------------- */
611 copy_readlink (WPanel
* panel
)
615 if (S_ISLNK (selection (panel
)->st
.st_mode
))
617 char buffer
[MC_MAXPATHLEN
];
618 char *p
= concat_dir_and_file (panel
->cwd
, selection (panel
)->fname
);
621 i
= mc_readlink (p
, buffer
, MC_MAXPATHLEN
- 1);
626 command_insert (cmdline
, buffer
, TRUE
);
631 /* --------------------------------------------------------------------------------------------- */
634 copy_current_readlink (void)
636 copy_readlink (current_panel
);
639 /* --------------------------------------------------------------------------------------------- */
642 copy_other_readlink (void)
644 if (get_other_type () == view_listing
)
645 copy_readlink (other_panel
);
648 /* --------------------------------------------------------------------------------------------- */
650 /** Insert the selected file name into the input line */
652 copy_prog_name (void)
658 if (get_current_type () == view_tree
)
660 WTree
*tree
= (WTree
*) get_panel_widget (get_current_index ());
661 tmp
= tree_selected_name (tree
);
664 tmp
= selection (current_panel
)->fname
;
666 command_insert (cmdline
, tmp
, TRUE
);
669 /* --------------------------------------------------------------------------------------------- */
672 copy_tagged (WPanel
* panel
)
678 input_disable_update (cmdline
);
681 for (i
= 0; i
< panel
->count
; i
++)
683 if (panel
->dir
.list
[i
].f
.marked
)
684 command_insert (cmdline
, panel
->dir
.list
[i
].fname
, TRUE
);
689 command_insert (cmdline
, panel
->dir
.list
[panel
->selected
].fname
, TRUE
);
691 input_enable_update (cmdline
);
694 /* --------------------------------------------------------------------------------------------- */
697 copy_current_tagged (void)
699 copy_tagged (current_panel
);
702 /* --------------------------------------------------------------------------------------------- */
705 copy_other_tagged (void)
707 if (get_other_type () == view_listing
)
708 copy_tagged (other_panel
);
711 /* --------------------------------------------------------------------------------------------- */
716 ctl_x_map_enabled
= TRUE
;
719 /* --------------------------------------------------------------------------------------------- */
722 init_xterm_support (void)
724 const char *termvalue
;
726 termvalue
= getenv ("TERM");
727 if (!termvalue
|| !(*termvalue
))
729 fputs (_("The TERM environment variable is unset!\n"), stderr
);
733 /* Check mouse capabilities */
734 xmouse_seq
= tty_tgetstr ("Km");
736 if (strcmp (termvalue
, "cygwin") == 0)
738 mc_args__force_xterm
= 1;
739 use_mouse_p
= MOUSE_DISABLED
;
742 if (mc_args__force_xterm
|| strncmp (termvalue
, "xterm", 5) == 0
743 || strncmp (termvalue
, "konsole", 7) == 0
744 || strncmp (termvalue
, "rxvt", 4) == 0
745 || strcmp (termvalue
, "Eterm") == 0 || strcmp (termvalue
, "dtterm") == 0)
750 /* For 8-bit locales, NCurses handles 154 (0x9A) symbol properly, while S-Lang
751 * requires SLsmg_Display_Eight_Bit >= 154 (OR manual filtering if xterm display
752 * detected - but checking TERM would fail under screen, OR running xterm
753 * with allowC1Printable).
755 tty_display_8bit (FALSE
);
758 /* Default to the standard xterm sequence */
761 xmouse_seq
= ESC_STR
"[M";
764 /* Enable mouse unless explicitly disabled by --nomouse */
765 if (use_mouse_p
!= MOUSE_DISABLED
)
767 const char *color_term
= getenv ("COLORTERM");
768 if (strncmp (termvalue
, "rxvt", 4) == 0 ||
769 (color_term
!= NULL
&& strncmp (color_term
, "rxvt", 4) == 0) ||
770 strcmp (termvalue
, "Eterm") == 0)
772 use_mouse_p
= MOUSE_XTERM_NORMAL_TRACKING
;
776 use_mouse_p
= MOUSE_XTERM_BUTTON_EVENT_TRACKING
;
782 /* --------------------------------------------------------------------------------------------- */
788 tty_display_8bit (full_eight_bits
!= 0);
790 tty_display_8bit (eight_bit_clean
!= 0);
793 #ifdef HAVE_SUBSHELL_SUPPORT
795 add_select_channel (subshell_pty
, load_prompt
, 0);
796 #endif /* !HAVE_SUBSHELL_SUPPORT */
798 tty_setup_sigwinch (sigwinch_handler
);
800 if ((tty_baudrate () < 9600) || tty_is_slow ())
803 init_xterm_support ();
807 /* --------------------------------------------------------------------------------------------- */
810 setup_dummy_mc (void)
812 char d
[MC_MAXPATHLEN
];
815 mc_get_current_wd (d
, MC_MAXPATHLEN
);
820 /* --------------------------------------------------------------------------------------------- */
825 if ((quit
& SUBSHELL_EXIT
) == 0)
827 tty_reset_shell_mode ();
832 /* --------------------------------------------------------------------------------------------- */
841 * We sync the profiles since the hotlist may have changed, while
842 * we only change the setup data if we have the auto save feature set
845 save_setup (auto_save_setup
, panels_options
.auto_save_setup
);
848 vfs_stamp_path (vfs_get_current_dir ());
850 if ((current_panel
!= NULL
) && (get_current_type () == view_listing
))
851 vfs_stamp_path (current_panel
->cwd
);
853 if ((other_panel
!= NULL
) && (get_other_type () == view_listing
))
854 vfs_stamp_path (other_panel
->cwd
);
857 /* --------------------------------------------------------------------------------------------- */
860 create_panels_and_run_mc (void)
862 midnight_dlg
->get_shortcut
= midnight_get_shortcut
;
863 midnight_dlg
->get_title
= midnight_get_title
;
867 add_widget (midnight_dlg
, the_menubar
);
870 add_widget (midnight_dlg
, get_panel_widget (0));
871 add_widget (midnight_dlg
, get_panel_widget (1));
873 add_widget (midnight_dlg
, the_hint
);
874 add_widget (midnight_dlg
, cmdline
);
875 add_widget (midnight_dlg
, the_prompt
);
877 add_widget (midnight_dlg
, the_bar
);
878 midnight_set_buttonbar (the_bar
);
880 /* Run the Midnight Commander if no file was specified in the command line */
881 run_dlg (midnight_dlg
);
884 /* --------------------------------------------------------------------------------------------- */
886 /** result must be free'd (I think this should go in util.c) */
888 prepend_cwd_on_local (const char *filename
)
893 if (!vfs_file_is_local (filename
) || g_path_is_absolute (filename
))
894 return g_strdup (filename
);
896 d
= g_malloc (MC_MAXPATHLEN
+ strlen (filename
) + 2);
897 mc_get_current_wd (d
, MC_MAXPATHLEN
);
900 strcpy (d
+ l
, filename
);
901 canonicalize_pathname (d
);
905 /* --------------------------------------------------------------------------------------------- */
907 /** Invoke the internal view/edit routine with:
908 * the default processing and forcing the internal viewer/editor
911 mc_maybe_editor_or_viewer (void)
915 #ifdef USE_INTERNAL_EDIT
917 edit_file (mc_run_param0
, mc_args__edit_start_line
);
919 #endif /* USE_INTERNAL_EDIT */
923 path
= prepend_cwd_on_local (mc_run_param0
);
924 view_file (path
, 0, 1);
929 case MC_RUN_DIFFVIEWER
:
930 diff_view (mc_run_param0
, mc_run_param1
, mc_run_param0
, mc_run_param1
);
932 #endif /* USE_DIFF_VIEW */
938 /* --------------------------------------------------------------------------------------------- */
941 quit_cmd_internal (int quiet
)
946 n
= dialog_switch_num () - 1;
949 char msg
[BUF_MEDIUM
];
951 g_snprintf (msg
, sizeof (msg
),
952 ngettext ("You have %zd opened screen. Quit anyway?",
953 "You have %zd opened screens. Quit anyway?", n
), n
);
955 if (query_dialog (_("The Midnight Commander"), msg
, D_NORMAL
, 2, _("&Yes"), _("&No")) != 0)
959 else if (quiet
|| !confirm_exit
)
961 else if (query_dialog (_("The Midnight Commander"),
962 _("Do you really want to quit the Midnight Commander?"),
963 D_NORMAL
, 2, _("&Yes"), _("&No")) == 0)
968 #ifdef HAVE_SUBSHELL_SUPPORT
971 else if ((q
= exit_subshell ()))
981 /* --------------------------------------------------------------------------------------------- */
986 return quit_cmd_internal (0);
989 /* --------------------------------------------------------------------------------------------- */
992 toggle_show_hidden (void)
994 panels_options
.show_dot_files
= !panels_options
.show_dot_files
;
995 update_panels (UP_RELOAD
, UP_KEEPSEL
);
998 /* --------------------------------------------------------------------------------------------- */
1001 * Repaint the contents of the panels without frames. To schedule panel
1002 * for repainting, set panel->dirty to 1. There are many reasons why
1003 * the panels need to be repainted, and this is a costly operation, so
1004 * it's done once per event.
1008 update_dirty_panels (void)
1010 if (get_current_type () == view_listing
&& current_panel
->dirty
)
1011 send_message ((Widget
*) current_panel
, WIDGET_DRAW
, 0);
1013 if (get_other_type () == view_listing
&& other_panel
->dirty
)
1014 send_message ((Widget
*) other_panel
, WIDGET_DRAW
, 0);
1017 /* --------------------------------------------------------------------------------------------- */
1020 midnight_execute_cmd (Widget
* sender
, unsigned long command
)
1022 cb_ret_t res
= MSG_HANDLED
;
1026 /* stop quick search before executing any command */
1027 send_message ((Widget
*) current_panel
, WIDGET_COMMAND
, CK_PanelStopSearch
);
1034 case CK_ChangeListingCmd
:
1035 change_listing_cmd ();
1043 case CK_ChownAdvancedCmd
:
1044 chown_advanced_cmd ();
1046 case CK_CompareDirsCmd
:
1047 compare_dirs_cmd ();
1049 case CK_ConfigureBox
:
1053 case CK_ConfigureVfs
:
1063 case CK_CopyCurrentPathname
:
1064 copy_current_pathname ();
1066 case CK_CopyCurrentReadlink
:
1067 copy_current_readlink ();
1069 case CK_CopyCurrentTagged
:
1070 copy_current_tagged ();
1072 case CK_CopyOtherPathname
:
1073 copy_other_pathname ();
1075 case CK_CopyOtherReadlink
:
1076 copy_other_readlink ();
1078 case CK_CopyOtherTagged
:
1079 copy_other_tagged ();
1084 case CK_DialogListCmd
:
1085 dialog_switch_list ();
1087 #ifdef USE_DIFF_VIEW
1088 case CK_DiffViewCmd
:
1092 case CK_DisplayBitsBox
:
1093 display_bits_box ();
1098 #ifdef USE_INTERNAL_EDIT
1099 case CK_EditForceInternalCmd
:
1100 edit_cmd_force_internal ();
1103 case CK_EditExtFileCmd
:
1106 case CK_EditFhlFileCmd
:
1109 case CK_EditMcMenuCmd
:
1110 edit_mc_menu_cmd ();
1112 case CK_EditSymlinkCmd
:
1113 edit_symlink_cmd ();
1115 case CK_ExternalPanelize
:
1116 external_panelize ();
1121 case CK_FilteredViewCmd
:
1122 filtered_view_cmd ();
1127 #ifdef ENABLE_VFS_FISH
1128 case CK_FishlinkCmd
:
1132 #ifdef ENABLE_VFS_FTP
1144 if (sender
== (Widget
*) the_menubar
)
1145 info_cmd (); /* mwnu */
1147 info_cmd_no_menu (); /* shortcut or buttonbar */
1149 #ifdef WITH_BACKGROUND
1161 link_cmd (LINK_HARDLINK
);
1166 #ifdef LISTMODE_EDITOR
1167 case CK_ListmodeCmd
:
1174 case CK_MenuLastSelectedCmd
:
1175 menu_last_selected_cmd ();
1180 case CK_PanelOptionsBox
:
1181 panel_options_box ();
1184 case CK_PanelSetPanelEncoding
:
1191 case CK_QuickChdirCmd
:
1194 case CK_QuickViewCmd
:
1195 if (sender
== (Widget
*) the_menubar
)
1196 quick_view_cmd (); /* menu */
1198 quick_cmd_no_menu (); /* shortcut or buttonabr */
1200 case CK_QuietQuitCmd
:
1206 case CK_RelativeSymlinkCmd
:
1207 link_cmd (LINK_SYMLINK_RELATIVE
);
1216 case CK_ReselectVfs
:
1220 case CK_ReverseSelectionCmd
:
1221 reverse_selection_cmd ();
1223 case CK_SaveSetupCmd
:
1229 case CK_ShowCommandLine
:
1232 case CK_SingleDirsizeCmd
:
1233 smart_dirsize_cmd ();
1235 #ifdef ENABLE_VFS_SMB
1239 #endif /* ENABLE_VFS_SMB */
1243 case CK_StartExtMap1
:
1253 link_cmd (LINK_SYMLINK_ABSOLUTE
);
1255 case CK_ToggleListingCmd
:
1256 toggle_listing_cmd ();
1258 case CK_ToggleShowHidden
:
1259 toggle_show_hidden ();
1261 case CK_TogglePanelsSplit
:
1262 toggle_panels_split ();
1270 #ifdef ENABLE_VFS_UNDELFS
1271 case CK_UndeleteCmd
:
1275 case CK_UnselectCmd
:
1278 case CK_UserMenuCmd
:
1279 user_file_menu_cmd ();
1284 case CK_ViewFileCmd
:
1287 case CK_DialogCancel
:
1288 /* don't close panels due to SIGINT */
1291 res
= MSG_NOT_HANDLED
;
1297 /* --------------------------------------------------------------------------------------------- */
1300 midnight_callback (Dlg_head
* h
, Widget
* sender
, dlg_msg_t msg
, int parm
, void *data
)
1302 unsigned long command
;
1313 /* We handle the special case of the output lines */
1314 if (console_flag
&& output_lines
)
1315 show_console_contents (output_start_y
,
1316 LINES
- output_lines
- keybar_visible
-
1317 1, LINES
- keybar_visible
- 1);
1322 menubar_arrange (the_menubar
);
1326 /* We only need the first idle event to show user menu after start */
1327 set_idle_proc (h
, 0);
1329 if (boot_current_is_left
)
1330 dlg_select_widget (get_panel_widget (0));
1332 dlg_select_widget (get_panel_widget (1));
1335 midnight_execute_cmd (NULL
, CK_UserMenuCmd
);
1339 if (ctl_x_map_enabled
)
1341 ctl_x_map_enabled
= FALSE
;
1342 command
= keybind_lookup_keymap_command (main_x_map
, parm
);
1343 if (command
!= CK_Ignore_Key
)
1344 return midnight_execute_cmd (NULL
, command
);
1347 /* FIXME: should handle all menu shortcuts before this point */
1348 if (the_menubar
->is_active
)
1349 return MSG_NOT_HANDLED
;
1352 input_free_completions (cmdline
);
1358 for (i
= 0; cmdline
->buffer
[i
] != '\0' &&
1359 (cmdline
->buffer
[i
] == ' ' || cmdline
->buffer
[i
] == '\t'); i
++)
1362 if (cmdline
->buffer
[i
] != '\0')
1364 send_message ((Widget
*) cmdline
, WIDGET_KEY
, parm
);
1368 input_insert (cmdline
, "", FALSE
);
1372 /* Ctrl-Enter and Alt-Enter */
1373 if (((parm
& ~(KEY_M_CTRL
| KEY_M_ALT
)) == '\n') && (parm
& (KEY_M_CTRL
| KEY_M_ALT
)))
1379 /* Ctrl-Shift-Enter */
1380 if (parm
== (KEY_M_CTRL
| KEY_M_SHIFT
| '\n'))
1382 copy_current_pathname ();
1387 if ((!alternate_plus_minus
|| !(console_flag
|| xterm_flag
))
1388 && !quote
&& !current_panel
->searching
)
1390 if (!only_leading_plus_minus
)
1392 /* Special treatement, since the input line will eat them */
1399 if (parm
== '\\' || parm
== '-')
1407 reverse_selection_cmd ();
1411 else if (!command_prompt
|| !cmdline
->buffer
[0])
1413 /* Special treatement '+', '-', '\', '*' only when this is
1414 * first char on input line
1423 if (parm
== '\\' || parm
== '-')
1431 reverse_selection_cmd ();
1436 return MSG_NOT_HANDLED
;
1438 case DLG_HOTKEY_HANDLED
:
1439 if ((get_current_type () == view_listing
) && current_panel
->searching
)
1441 current_panel
->dirty
= 1; /* FIXME: unneeded? */
1442 send_message ((Widget
*) current_panel
, WIDGET_COMMAND
, CK_PanelStopSearch
);
1446 case DLG_UNHANDLED_KEY
:
1451 v
= send_message ((Widget
*) cmdline
, WIDGET_KEY
, parm
);
1452 if (v
== MSG_HANDLED
)
1456 if (ctl_x_map_enabled
)
1458 ctl_x_map_enabled
= FALSE
;
1459 command
= keybind_lookup_keymap_command (main_x_map
, parm
);
1462 command
= keybind_lookup_keymap_command (main_map
, parm
);
1464 return (command
== CK_Ignore_Key
) ? MSG_NOT_HANDLED
: midnight_execute_cmd (NULL
, command
);
1467 if (!the_menubar
->is_active
)
1468 update_dirty_panels ();
1474 return midnight_execute_cmd (NULL
, parm
);
1475 /* message from menu */
1476 if (sender
== (Widget
*) the_menubar
)
1477 return midnight_execute_cmd (sender
, parm
);
1478 /* message from buttonbar */
1479 if (sender
== (Widget
*) the_bar
)
1482 return send_message ((Widget
*) data
, WIDGET_COMMAND
, parm
);
1483 return midnight_execute_cmd (sender
, parm
);
1485 return MSG_NOT_HANDLED
;
1492 return default_dlg_callback (h
, sender
, msg
, parm
, data
);
1496 /* --------------------------------------------------------------------------------------------- */
1497 /*** public functions ****************************************************************************/
1498 /* --------------------------------------------------------------------------------------------- */
1503 menu_set_name (left_menu
, horizontal_split
? _("&Above") : _("&Left"));
1504 menu_set_name (right_menu
, horizontal_split
? _("&Below") : _("&Right"));
1505 menubar_arrange (the_menubar
);
1506 menubar_set_visible (the_menubar
, menubar_visible
);
1510 midnight_set_buttonbar (WButtonBar
* b
)
1512 buttonbar_set_label (b
, 1, Q_ ("ButtonBar|Help"), main_map
, NULL
);
1513 buttonbar_set_label (b
, 2, Q_ ("ButtonBar|Menu"), main_map
, NULL
);
1514 buttonbar_set_label (b
, 3, Q_ ("ButtonBar|View"), main_map
, NULL
);
1515 buttonbar_set_label (b
, 4, Q_ ("ButtonBar|Edit"), main_map
, NULL
);
1516 buttonbar_set_label (b
, 5, Q_ ("ButtonBar|Copy"), main_map
, NULL
);
1517 buttonbar_set_label (b
, 6, Q_ ("ButtonBar|RenMov"), main_map
, NULL
);
1518 buttonbar_set_label (b
, 7, Q_ ("ButtonBar|Mkdir"), main_map
, NULL
);
1519 buttonbar_set_label (b
, 8, Q_ ("ButtonBar|Delete"), main_map
, NULL
);
1520 buttonbar_set_label (b
, 9, Q_ ("ButtonBar|PullDn"), main_map
, NULL
);
1521 buttonbar_set_label (b
, 10, Q_ ("ButtonBar|Quit"), main_map
, NULL
);
1524 /* --------------------------------------------------------------------------------------------- */
1526 * Load new hint and display it.
1527 * IF force is not 0, ignore the timeout.
1531 load_hint (gboolean force
)
1535 if (the_hint
->widget
.owner
== NULL
)
1538 if (!message_visible
)
1540 label_set_text (the_hint
, NULL
);
1544 hint
= get_random_hint (force
);
1554 char text
[BUF_SMALL
];
1556 g_snprintf (text
, sizeof (text
), _("GNU Midnight Commander %s\n"), VERSION
);
1561 /* --------------------------------------------------------------------------------------------- */
1566 input_free_completions (cmdline
);
1567 dlg_one_down (midnight_dlg
);
1570 /* --------------------------------------------------------------------------------------------- */
1572 /** Save current stat of directories to avoid reloading the panels
1573 * when no modifications have taken place
1576 save_cwds_stat (void)
1578 if (panels_options
.fast_reload
)
1580 mc_stat (current_panel
->cwd
, &(current_panel
->dir_stat
));
1581 if (get_other_type () == view_listing
)
1582 mc_stat (other_panel
->cwd
, &(other_panel
->dir_stat
));
1586 /* --------------------------------------------------------------------------------------------- */
1589 quiet_quit_cmd (void)
1591 print_last_revert
= TRUE
;
1592 return quit_cmd_internal (1);
1595 /* --------------------------------------------------------------------------------------------- */
1597 /** Run the main dialog that occupies the whole screen */
1601 dlg_colors_t midnight_colors
;
1603 midnight_colors
[DLG_COLOR_NORMAL
] = mc_skin_color_get ("dialog", "_default_");
1604 midnight_colors
[DLG_COLOR_FOCUS
] = mc_skin_color_get ("dialog", "focus");
1605 midnight_colors
[DLG_COLOR_HOT_NORMAL
] = mc_skin_color_get ("dialog", "hotnormal");
1606 midnight_colors
[DLG_COLOR_HOT_FOCUS
] = mc_skin_color_get ("dialog", "hotfocus");
1607 midnight_colors
[DLG_COLOR_TITLE
] = mc_skin_color_get ("dialog", "title");
1609 #ifdef USE_INTERNAL_EDIT
1613 midnight_dlg
= create_dlg (FALSE
, 0, 0, LINES
, COLS
, midnight_colors
, midnight_callback
,
1614 "[main]", NULL
, DLG_WANT_IDLE
);
1616 if (mc_run_mode
== MC_RUN_FULL
)
1621 /* Check if we were invoked as an editor or file viewer */
1622 if (mc_run_mode
!= MC_RUN_FULL
)
1623 mc_maybe_editor_or_viewer ();
1626 create_panels_and_run_mc ();
1628 /* destroy_dlg destroys even current_panel->cwd, so we have to save a copy :) */
1629 if (mc_args__last_wd_file
!= NULL
&& vfs_current_is_local ())
1630 last_wd_string
= g_strdup (current_panel
->cwd
);
1634 midnight_shutdown
= 1;
1635 dialog_switch_shutdown ();
1637 destroy_dlg (midnight_dlg
);
1638 current_panel
= NULL
;
1640 #ifdef USE_INTERNAL_EDIT
1645 /* --------------------------------------------------------------------------------------------- */