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/vfs.h"
55 #include "src/subshell.h"
56 #include "src/setup.h" /* variables */
57 #include "src/learn.h" /* learn_keys() */
58 #include "src/keybind-defaults.h"
59 #include "lib/keybind.h"
60 #include "lib/event.h"
62 #include "option.h" /* configure_box() */
64 #include "boxes.h" /* sort_box(), tree_box() */
66 #include "cmd.h" /* commands */
69 #include "command.h" /* cmdline */
75 #ifdef USE_INTERNAL_EDIT
76 #include "src/editor/edit.h"
80 #include "src/diffviewer/ydiff.h"
83 #include "src/consaver/cons.saver.h" /* show_console_contents */
87 /* TODO: merge content of layout.c here */
88 extern int ok_to_refresh
;
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
;
104 WMenuBar
*the_menubar
= NULL
;
105 /* The widget where we draw the prompt */
112 /*** file scope macro definitions ****************************************************************/
116 * Don't restrict the output on the screen manager level,
117 * the translation tables take care of it.
119 #endif /* !HAVE_CHARSET */
121 /*** file scope type declarations ****************************************************************/
123 /*** file scope variables ************************************************************************/
125 static Menu
*left_menu
, *right_menu
;
127 static gboolean ctl_x_map_enabled
= FALSE
;
129 /*** file scope functions ************************************************************************/
131 /** Stop MC main dialog and the current dialog if it exists.
132 * Needed to provide fast exit from MC viewer or editor on shell exit */
136 midnight_dlg
->state
= DLG_CLOSED
;
138 if ((top_dlg
!= NULL
) && (top_dlg
->data
!= NULL
))
139 ((Dlg_head
*) top_dlg
->data
)->state
= DLG_CLOSED
;
142 /* --------------------------------------------------------------------------------------------- */
149 sel_dir
= tree_box (selection (current_panel
)->fname
);
152 do_cd (sel_dir
, cd_exact
);
157 /* --------------------------------------------------------------------------------------------- */
159 #ifdef LISTMODE_EDITOR
165 if (get_current_type () != view_listing
)
168 newmode
= listmode_edit (current_panel
->user_format
);
172 g_free (current_panel
->user_format
);
173 current_panel
->list_type
= list_user
;
174 current_panel
->user_format
= newmode
;
175 set_panel_formats (current_panel
);
179 #endif /* LISTMODE_EDITOR */
181 /* --------------------------------------------------------------------------------------------- */
184 create_panel_menu (void)
186 GList
*entries
= NULL
;
188 entries
= g_list_append (entries
, menu_entry_create (_("File listin&g"), CK_PanelListing
));
189 entries
= g_list_append (entries
, menu_entry_create (_("&Quick view"), CK_PanelQuickView
));
190 entries
= g_list_append (entries
, menu_entry_create (_("&Info"), CK_PanelInfo
));
191 entries
= g_list_append (entries
, menu_entry_create (_("&Tree"), CK_PanelTree
));
192 entries
= g_list_append (entries
, menu_separator_create ());
194 g_list_append (entries
, menu_entry_create (_("&Listing mode..."), CK_PanelListingChange
));
195 entries
= g_list_append (entries
, menu_entry_create (_("&Sort order..."), CK_Sort
));
196 entries
= g_list_append (entries
, menu_entry_create (_("&Filter..."), CK_Filter
));
198 entries
= g_list_append (entries
, menu_entry_create (_("&Encoding..."), CK_SelectCodepage
));
200 #ifdef ENABLE_VFS_NET
201 entries
= g_list_append (entries
, menu_separator_create ());
202 #ifdef ENABLE_VFS_FTP
203 entries
= g_list_append (entries
, menu_entry_create (_("FT&P link..."), CK_ConnectFtp
));
205 #ifdef ENABLE_VFS_FISH
206 entries
= g_list_append (entries
, menu_entry_create (_("S&hell link..."), CK_ConnectFish
));
208 #ifdef ENABLE_VFS_SMB
209 entries
= g_list_append (entries
, menu_entry_create (_("SM&B link..."), CK_ConnectSmb
));
211 #endif /* ENABLE_VFS_NET */
212 entries
= g_list_append (entries
, menu_separator_create ());
213 entries
= g_list_append (entries
, menu_entry_create (_("&Rescan"), CK_Reread
));
218 /* --------------------------------------------------------------------------------------------- */
221 create_file_menu (void)
223 GList
*entries
= NULL
;
225 entries
= g_list_append (entries
, menu_entry_create (_("&View"), CK_View
));
226 entries
= g_list_append (entries
, menu_entry_create (_("Vie&w file..."), CK_ViewFile
));
227 entries
= g_list_append (entries
, menu_entry_create (_("&Filtered view"), CK_ViewFiltered
));
228 entries
= g_list_append (entries
, menu_entry_create (_("&Edit"), CK_Edit
));
229 entries
= g_list_append (entries
, menu_entry_create (_("&Copy"), CK_Copy
));
230 entries
= g_list_append (entries
, menu_entry_create (_("C&hmod"), CK_ChangeMode
));
231 entries
= g_list_append (entries
, menu_entry_create (_("&Link"), CK_Link
));
232 entries
= g_list_append (entries
, menu_entry_create (_("&Symlink"), CK_LinkSymbolic
));
234 g_list_append (entries
,
235 menu_entry_create (_("Relative symlin&k"), CK_LinkSymbolicRelative
));
236 entries
= g_list_append (entries
, menu_entry_create (_("Edit s&ymlink"), CK_LinkSymbolicEdit
));
237 entries
= g_list_append (entries
, menu_entry_create (_("Ch&own"), CK_ChangeOwn
));
239 g_list_append (entries
, menu_entry_create (_("&Advanced chown"), CK_ChangeOwnAdvanced
));
240 entries
= g_list_append (entries
, menu_entry_create (_("&Rename/Move"), CK_Move
));
241 entries
= g_list_append (entries
, menu_entry_create (_("&Mkdir"), CK_MakeDir
));
242 entries
= g_list_append (entries
, menu_entry_create (_("&Delete"), CK_Delete
));
243 entries
= g_list_append (entries
, menu_entry_create (_("&Quick cd"), CK_CdQuick
));
244 entries
= g_list_append (entries
, menu_separator_create ());
245 entries
= g_list_append (entries
, menu_entry_create (_("Select &group"), CK_Select
));
246 entries
= g_list_append (entries
, menu_entry_create (_("U&nselect group"), CK_Unselect
));
247 entries
= g_list_append (entries
, menu_entry_create (_("&Invert selection"), CK_SelectInvert
));
248 entries
= g_list_append (entries
, menu_separator_create ());
249 entries
= g_list_append (entries
, menu_entry_create (_("E&xit"), CK_Quit
));
254 /* --------------------------------------------------------------------------------------------- */
257 create_command_menu (void)
259 /* I know, I'm lazy, but the tree widget when it's not running
260 * as a panel still has some problems, I have not yet finished
261 * the WTree widget port, sorry.
263 GList
*entries
= NULL
;
265 entries
= g_list_append (entries
, menu_entry_create (_("&User menu"), CK_UserMenu
));
266 entries
= g_list_append (entries
, menu_entry_create (_("&Directory tree"), CK_Tree
));
267 entries
= g_list_append (entries
, menu_entry_create (_("&Find file"), CK_Find
));
268 entries
= g_list_append (entries
, menu_entry_create (_("S&wap panels"), CK_Swap
));
269 entries
= g_list_append (entries
, menu_entry_create (_("Switch &panels on/off"), CK_Shell
));
271 g_list_append (entries
, menu_entry_create (_("&Compare directories"), CK_CompareDirs
));
273 entries
= g_list_append (entries
, menu_entry_create (_("C&ompare files"), CK_CompareFiles
));
276 g_list_append (entries
, menu_entry_create (_("E&xternal panelize"), CK_ExternalPanelize
));
277 entries
= g_list_append (entries
, menu_entry_create (_("Show directory s&izes"), CK_DirSize
));
278 entries
= g_list_append (entries
, menu_separator_create ());
279 entries
= g_list_append (entries
, menu_entry_create (_("Command &history"), CK_History
));
280 entries
= g_list_append (entries
, menu_entry_create (_("Di&rectory hotlist"), CK_HotList
));
282 entries
= g_list_append (entries
, menu_entry_create (_("&Active VFS list"), CK_VfsList
));
284 #ifdef WITH_BACKGROUND
285 entries
= g_list_append (entries
, menu_entry_create (_("&Background jobs"), CK_Jobs
));
287 entries
= g_list_append (entries
, menu_entry_create (_("Screen lis&t"), CK_ScreenList
));
288 entries
= g_list_append (entries
, menu_separator_create ());
289 #ifdef ENABLE_VFS_UNDELFS
291 g_list_append (entries
,
292 menu_entry_create (_("&Undelete files (ext2fs only)"), CK_Undelete
));
294 #ifdef LISTMODE_EDITOR
295 entries
= g_list_append (entries
, menu_entry_create (_("&Listing format edit"), CK_ListMode
));
297 #if defined (ENABLE_VFS_UNDELFS) || defined (LISTMODE_EDITOR)
298 entries
= g_list_append (entries
, menu_separator_create ());
301 g_list_append (entries
,
302 menu_entry_create (_("Edit &extension file"), CK_EditExtensionsFile
));
303 entries
= g_list_append (entries
, menu_entry_create (_("Edit &menu file"), CK_EditUserMenu
));
305 g_list_append (entries
,
306 menu_entry_create (_("Edit hi&ghlighting group file"),
307 CK_EditFileHighlightFile
));
312 /* --------------------------------------------------------------------------------------------- */
315 create_options_menu (void)
317 GList
*entries
= NULL
;
319 entries
= g_list_append (entries
, menu_entry_create (_("&Configuration..."), CK_Options
));
320 entries
= g_list_append (entries
, menu_entry_create (_("&Layout..."), CK_OptionsLayout
));
321 entries
= g_list_append (entries
, menu_entry_create (_("&Panel options..."), CK_OptionsPanel
));
322 entries
= g_list_append (entries
, menu_entry_create (_("C&onfirmation..."), CK_OptionsConfirm
));
324 g_list_append (entries
, menu_entry_create (_("&Display bits..."), CK_OptionsDisplayBits
));
325 entries
= g_list_append (entries
, menu_entry_create (_("Learn &keys..."), CK_LearnKeys
));
327 entries
= g_list_append (entries
, menu_entry_create (_("&Virtual FS..."), CK_OptionsVfs
));
329 entries
= g_list_append (entries
, menu_separator_create ());
330 entries
= g_list_append (entries
, menu_entry_create (_("&Save setup"), CK_SaveSetup
));
335 /* --------------------------------------------------------------------------------------------- */
340 left_menu
= create_menu ("", create_panel_menu (), "[Left and Right Menus]");
341 menubar_add_menu (the_menubar
, left_menu
);
342 menubar_add_menu (the_menubar
, create_menu (_("&File"), create_file_menu (), "[File Menu]"));
343 menubar_add_menu (the_menubar
,
344 create_menu (_("&Command"), create_command_menu (), "[Command Menu]"));
345 menubar_add_menu (the_menubar
,
346 create_menu (_("&Options"), create_options_menu (), "[Options Menu]"));
347 right_menu
= create_menu ("", create_panel_menu (), "[Left and Right Menus]");
348 menubar_add_menu (the_menubar
, right_menu
);
352 /* --------------------------------------------------------------------------------------------- */
355 menu_last_selected_cmd (void)
357 the_menubar
->is_active
= TRUE
;
358 the_menubar
->is_dropped
= (drop_menus
!= 0);
359 the_menubar
->previous_widget
= dlg_get_current_widget_id (midnight_dlg
);
360 dlg_select_widget (the_menubar
);
363 /* --------------------------------------------------------------------------------------------- */
368 if (the_menubar
->is_active
)
371 if ((get_current_index () == 0) == (current_panel
->active
!= 0))
372 the_menubar
->selected
= 0;
374 the_menubar
->selected
= g_list_length (the_menubar
->menu
) - 1;
375 menu_last_selected_cmd ();
378 /* --------------------------------------------------------------------------------------------- */
384 const panel_field_t
*sort_order
;
386 if (!SELECTED_IS_PANEL
)
390 sort_order
= sort_box (&p
->sort_info
);
391 panel_set_sort_order (p
, sort_order
);
394 /* --------------------------------------------------------------------------------------------- */
397 midnight_get_shortcut (unsigned long command
)
400 const char *shortcut
= NULL
;
402 shortcut
= keybind_lookup_keymap_shortcut (main_map
, command
);
403 if (shortcut
!= NULL
)
404 return g_strdup (shortcut
);
406 shortcut
= keybind_lookup_keymap_shortcut (panel_map
, command
);
407 if (shortcut
!= NULL
)
408 return g_strdup (shortcut
);
410 ext_map
= keybind_lookup_keymap_shortcut (main_map
, CK_ExtendedKeyMap
);
412 shortcut
= keybind_lookup_keymap_shortcut (main_x_map
, command
);
413 if (shortcut
!= NULL
)
414 return g_strdup_printf ("%s %s", ext_map
, shortcut
);
419 /* --------------------------------------------------------------------------------------------- */
422 midnight_get_title (const Dlg_head
* h
, size_t len
)
424 /* TODO: share code with update_xterm_title_path() */
429 struct passwd
*pw
= NULL
;
435 path
= strip_home_and_password (current_panel
->cwd
);
436 res
= gethostname (host
, sizeof (host
));
440 host
[sizeof (host
) - 1] = '\0';
442 pw
= getpwuid (getuid ());
444 login
= g_strdup_printf ("%s@%s", pw
->pw_name
, host
);
446 login
= g_strdup (host
);
448 p
= g_strdup_printf ("%s [%s]:%s", _("Panels:"), login
, path
);
449 path
= str_trunc (p
, len
- 4);
453 return g_strdup (path
);
456 /* --------------------------------------------------------------------------------------------- */
459 toggle_panels_split (void)
461 horizontal_split
= !horizontal_split
;
466 /* --------------------------------------------------------------------------------------------- */
472 check_panel_timestamp (const WPanel
* panel
, panel_view_mode_t mode
, struct vfs_class
*vclass
,
475 if (mode
== view_listing
)
478 vfs_path_element_t
*path_element
;
480 vpath
= vfs_path_from_str (panel
->cwd
);
481 path_element
= vfs_path_get_by_index (vpath
, -1);
483 if (path_element
->class != vclass
)
486 if (vfs_getid (vpath
) != id
)
492 /* --------------------------------------------------------------------------------------------- */
496 check_current_panel_timestamp (const gchar
* event_group_name
, const gchar
* event_name
,
497 gpointer init_data
, gpointer data
)
499 ev_vfs_stamp_create_t
*event_data
= (ev_vfs_stamp_create_t
*) data
;
501 (void) event_group_name
;
506 check_panel_timestamp (current_panel
, get_current_type (), event_data
->vclass
,
508 return !event_data
->ret
;
511 /* --------------------------------------------------------------------------------------------- */
515 check_other_panel_timestamp (const gchar
* event_group_name
, const gchar
* event_name
,
516 gpointer init_data
, gpointer data
)
518 ev_vfs_stamp_create_t
*event_data
= (ev_vfs_stamp_create_t
*) data
;
520 (void) event_group_name
;
525 check_panel_timestamp (other_panel
, get_other_type (), event_data
->vclass
, event_data
->id
);
526 return !event_data
->ret
;
528 #endif /* ENABLE_VFS */
530 /* --------------------------------------------------------------------------------------------- */
534 print_vfs_message (const gchar
* event_group_name
, const gchar
* event_name
,
535 gpointer init_data
, gpointer data
)
538 ev_vfs_print_message_t
*event_data
= (ev_vfs_print_message_t
*) data
;
540 (void) event_group_name
;
544 g_vsnprintf (str
, sizeof (str
), event_data
->msg
, event_data
->ap
);
546 if (mc_global
.widget
.midnight_shutdown
)
549 if (!mc_global
.message_visible
|| !the_hint
|| !the_hint
->widget
.owner
)
553 if (!nice_rotating_dash
|| (ok_to_refresh
<= 0))
556 /* Preserve current cursor position */
557 tty_getyx (&row
, &col
);
560 tty_setcolor (NORMAL_COLOR
);
561 tty_print_string (str_fit_to_term (str
, COLS
- 1, J_LEFT
));
563 /* Restore cursor position */
564 tty_gotoyx (row
, col
);
569 if (mc_global
.message_visible
)
575 /* --------------------------------------------------------------------------------------------- */
582 panel_view_mode_t current_mode
, other_mode
;
583 char original_dir
[BUF_1K
] = "\0";
585 if (boot_current_is_left
)
589 current_mode
= startup_left_mode
;
590 other_mode
= startup_right_mode
;
596 current_mode
= startup_right_mode
;
597 other_mode
= startup_left_mode
;
599 /* Creates the left panel */
600 if (mc_run_param0
!= NULL
)
602 if (mc_run_param1
!= NULL
)
604 /* Ok, user has specified two dirs, save the original one,
605 * since we may not be able to chdir to the proper
606 * second directory later
608 mc_get_current_wd (original_dir
, sizeof (original_dir
) - 2);
610 mc_chdir (mc_run_param0
);
612 set_display_type (current_index
, current_mode
);
614 /* The other panel */
615 if (mc_run_param1
!= NULL
)
617 if (original_dir
[0] != '\0')
618 mc_chdir (original_dir
);
619 mc_chdir (mc_run_param1
);
621 set_display_type (other_index
, other_mode
);
623 if (startup_left_mode
== view_listing
)
624 current_panel
= left_panel
;
625 else if (right_panel
!= NULL
)
626 current_panel
= right_panel
;
628 current_panel
= left_panel
;
631 mc_event_add (MCEVENT_GROUP_CORE
, "vfs_timestamp", check_other_panel_timestamp
, NULL
, NULL
);
632 mc_event_add (MCEVENT_GROUP_CORE
, "vfs_timestamp", check_current_panel_timestamp
, NULL
, NULL
);
633 #endif /* ENABLE_VFS */
635 mc_event_add (MCEVENT_GROUP_CORE
, "vfs_print_message", print_vfs_message
, NULL
, NULL
);
637 /* Create the nice widgets */
638 cmdline
= command_new (0, 0, 0);
639 the_prompt
= label_new (0, 0, mc_prompt
);
640 the_prompt
->transparent
= 1;
641 the_bar
= buttonbar_new (mc_global
.keybar_visible
);
643 the_hint
= label_new (0, 0, 0);
644 the_hint
->transparent
= 1;
645 the_hint
->auto_adjust_cols
= 0;
646 the_hint
->widget
.cols
= COLS
;
648 the_menubar
= menubar_new (0, 0, COLS
, NULL
);
651 /* --------------------------------------------------------------------------------------------- */
654 put_current_path (void)
660 cwd_path
= remove_encoding_from_path (current_panel
->cwd
);
661 command_insert (cmdline
, cwd_path
, FALSE
);
663 if (cwd_path
[strlen (cwd_path
) - 1] != PATH_SEP
)
664 command_insert (cmdline
, PATH_SEP_STR
, FALSE
);
668 /* --------------------------------------------------------------------------------------------- */
671 put_other_path (void)
675 if (get_other_type () != view_listing
)
681 cwd_path
= remove_encoding_from_path (other_panel
->cwd
);
682 command_insert (cmdline
, cwd_path
, FALSE
);
684 if (cwd_path
[strlen (cwd_path
) - 1] != PATH_SEP
)
685 command_insert (cmdline
, PATH_SEP_STR
, FALSE
);
689 /* --------------------------------------------------------------------------------------------- */
692 put_link (WPanel
* panel
)
696 if (S_ISLNK (selection (panel
)->st
.st_mode
))
698 char buffer
[MC_MAXPATHLEN
];
702 p
= concat_dir_and_file (panel
->cwd
, selection (panel
)->fname
);
703 i
= mc_readlink (p
, buffer
, MC_MAXPATHLEN
- 1);
708 command_insert (cmdline
, buffer
, TRUE
);
713 /* --------------------------------------------------------------------------------------------- */
716 put_current_link (void)
718 put_link (current_panel
);
721 /* --------------------------------------------------------------------------------------------- */
724 put_other_link (void)
726 if (get_other_type () == view_listing
)
727 put_link (other_panel
);
730 /* --------------------------------------------------------------------------------------------- */
732 /** Insert the selected file name into the input line */
740 if (get_current_type () == view_tree
)
742 WTree
*tree
= (WTree
*) get_panel_widget (get_current_index ());
743 tmp
= tree_selected_name (tree
);
746 tmp
= selection (current_panel
)->fname
;
748 command_insert (cmdline
, tmp
, TRUE
);
751 /* --------------------------------------------------------------------------------------------- */
754 put_tagged (WPanel
* panel
)
760 input_disable_update (cmdline
);
763 for (i
= 0; i
< panel
->count
; i
++)
765 if (panel
->dir
.list
[i
].f
.marked
)
766 command_insert (cmdline
, panel
->dir
.list
[i
].fname
, TRUE
);
771 command_insert (cmdline
, panel
->dir
.list
[panel
->selected
].fname
, TRUE
);
773 input_enable_update (cmdline
);
776 /* --------------------------------------------------------------------------------------------- */
779 put_current_tagged (void)
781 put_tagged (current_panel
);
784 /* --------------------------------------------------------------------------------------------- */
787 put_other_tagged (void)
789 if (get_other_type () == view_listing
)
790 put_tagged (other_panel
);
793 /* --------------------------------------------------------------------------------------------- */
798 ctl_x_map_enabled
= TRUE
;
801 /* --------------------------------------------------------------------------------------------- */
804 init_xterm_support (void)
806 const char *termvalue
;
808 termvalue
= getenv ("TERM");
809 if (!termvalue
|| !(*termvalue
))
811 fputs (_("The TERM environment variable is unset!\n"), stderr
);
815 /* Check mouse capabilities */
816 xmouse_seq
= tty_tgetstr ("Km");
818 if (strcmp (termvalue
, "cygwin") == 0)
820 mc_args__force_xterm
= 1;
821 use_mouse_p
= MOUSE_DISABLED
;
824 if (mc_args__force_xterm
|| strncmp (termvalue
, "xterm", 5) == 0
825 || strncmp (termvalue
, "konsole", 7) == 0
826 || strncmp (termvalue
, "rxvt", 4) == 0
827 || strcmp (termvalue
, "Eterm") == 0 || strcmp (termvalue
, "dtterm") == 0)
832 /* For 8-bit locales, NCurses handles 154 (0x9A) symbol properly, while S-Lang
833 * requires SLsmg_Display_Eight_Bit >= 154 (OR manual filtering if xterm display
834 * detected - but checking TERM would fail under screen, OR running xterm
835 * with allowC1Printable).
837 tty_display_8bit (FALSE
);
840 /* Default to the standard xterm sequence */
843 xmouse_seq
= ESC_STR
"[M";
846 /* Enable mouse unless explicitly disabled by --nomouse */
847 if (use_mouse_p
!= MOUSE_DISABLED
)
849 const char *color_term
= getenv ("COLORTERM");
850 if (strncmp (termvalue
, "rxvt", 4) == 0 ||
851 (color_term
!= NULL
&& strncmp (color_term
, "rxvt", 4) == 0) ||
852 strcmp (termvalue
, "Eterm") == 0)
854 use_mouse_p
= MOUSE_XTERM_NORMAL_TRACKING
;
858 use_mouse_p
= MOUSE_XTERM_BUTTON_EVENT_TRACKING
;
864 /* --------------------------------------------------------------------------------------------- */
871 tty_display_8bit (TRUE
);
873 tty_display_8bit (full_eight_bits
!= 0);
874 #endif /* HAVE_CHARSET */
878 tty_display_8bit (TRUE
);
880 tty_display_8bit (eight_bit_clean
!= 0);
881 #endif /* HAVE_CHARSET */
885 #ifdef HAVE_SUBSHELL_SUPPORT
886 if (mc_global
.tty
.use_subshell
)
887 add_select_channel (mc_global
.tty
.subshell_pty
, load_prompt
, 0);
888 #endif /* !HAVE_SUBSHELL_SUPPORT */
890 tty_setup_sigwinch (sigwinch_handler
);
892 if ((tty_baudrate () < 9600) || tty_is_slow ())
895 init_xterm_support ();
899 /* --------------------------------------------------------------------------------------------- */
902 setup_dummy_mc (void)
904 char d
[MC_MAXPATHLEN
];
907 mc_get_current_wd (d
, MC_MAXPATHLEN
);
912 /* --------------------------------------------------------------------------------------------- */
917 if ((quit
& SUBSHELL_EXIT
) == 0)
919 tty_reset_shell_mode ();
924 /* --------------------------------------------------------------------------------------------- */
933 * We sync the profiles since the hotlist may have changed, while
934 * we only change the setup data if we have the auto save feature set
937 save_setup (auto_save_setup
, panels_options
.auto_save_setup
);
941 char *curr_dir
= vfs_get_current_dir ();
942 vfs_stamp_path (curr_dir
);
946 if ((current_panel
!= NULL
) && (get_current_type () == view_listing
))
947 vfs_stamp_path (current_panel
->cwd
);
949 if ((other_panel
!= NULL
) && (get_other_type () == view_listing
))
950 vfs_stamp_path (other_panel
->cwd
);
953 /* --------------------------------------------------------------------------------------------- */
956 create_panels_and_run_mc (void)
958 midnight_dlg
->get_shortcut
= midnight_get_shortcut
;
959 midnight_dlg
->get_title
= midnight_get_title
;
963 add_widget (midnight_dlg
, the_menubar
);
966 add_widget (midnight_dlg
, get_panel_widget (0));
967 add_widget (midnight_dlg
, get_panel_widget (1));
969 add_widget (midnight_dlg
, the_hint
);
970 add_widget (midnight_dlg
, cmdline
);
971 add_widget (midnight_dlg
, the_prompt
);
973 add_widget (midnight_dlg
, the_bar
);
974 midnight_set_buttonbar (the_bar
);
976 /* Run the Midnight Commander if no file was specified in the command line */
977 run_dlg (midnight_dlg
);
980 /* --------------------------------------------------------------------------------------------- */
982 /** result must be free'd (I think this should go in util.c) */
984 prepend_cwd_on_local (const char *filename
)
990 vpath
= vfs_path_from_str (filename
);
991 if (!vfs_file_is_local (vpath
) || g_path_is_absolute (filename
))
993 vfs_path_free (vpath
);
994 return g_strdup (filename
);
996 vfs_path_free (vpath
);
998 d
= g_malloc (MC_MAXPATHLEN
+ strlen (filename
) + 2);
999 mc_get_current_wd (d
, MC_MAXPATHLEN
);
1002 strcpy (d
+ l
, filename
);
1003 canonicalize_pathname (d
);
1007 /* --------------------------------------------------------------------------------------------- */
1009 /** Invoke the internal view/edit routine with:
1010 * the default processing and forcing the internal viewer/editor
1013 mc_maybe_editor_or_viewer (void)
1015 switch (mc_global
.mc_run_mode
)
1017 #ifdef USE_INTERNAL_EDIT
1019 edit_file (mc_run_param0
, mc_args__edit_start_line
);
1021 #endif /* USE_INTERNAL_EDIT */
1025 path
= prepend_cwd_on_local (mc_run_param0
);
1026 view_file (path
, 0, 1);
1030 #ifdef USE_DIFF_VIEW
1031 case MC_RUN_DIFFVIEWER
:
1032 diff_view (mc_run_param0
, mc_run_param1
, mc_run_param0
, mc_run_param1
);
1034 #endif /* USE_DIFF_VIEW */
1040 /* --------------------------------------------------------------------------------------------- */
1043 quit_cmd_internal (int quiet
)
1048 n
= dialog_switch_num () - 1;
1051 char msg
[BUF_MEDIUM
];
1053 g_snprintf (msg
, sizeof (msg
),
1054 ngettext ("You have %zd opened screen. Quit anyway?",
1055 "You have %zd opened screens. Quit anyway?", n
), n
);
1057 if (query_dialog (_("The Midnight Commander"), msg
, D_NORMAL
, 2, _("&Yes"), _("&No")) != 0)
1061 else if (quiet
|| !confirm_exit
)
1063 else if (query_dialog (_("The Midnight Commander"),
1064 _("Do you really want to quit the Midnight Commander?"),
1065 D_NORMAL
, 2, _("&Yes"), _("&No")) == 0)
1070 #ifdef HAVE_SUBSHELL_SUPPORT
1071 if (!mc_global
.tty
.use_subshell
)
1073 else if ((q
= exit_subshell ()))
1083 /* --------------------------------------------------------------------------------------------- */
1088 return quit_cmd_internal (0);
1091 /* --------------------------------------------------------------------------------------------- */
1094 toggle_show_hidden (void)
1096 panels_options
.show_dot_files
= !panels_options
.show_dot_files
;
1097 update_panels (UP_RELOAD
, UP_KEEPSEL
);
1100 /* --------------------------------------------------------------------------------------------- */
1103 * Repaint the contents of the panels without frames. To schedule panel
1104 * for repainting, set panel->dirty to 1. There are many reasons why
1105 * the panels need to be repainted, and this is a costly operation, so
1106 * it's done once per event.
1110 update_dirty_panels (void)
1112 if (get_current_type () == view_listing
&& current_panel
->dirty
)
1113 send_message ((Widget
*) current_panel
, WIDGET_DRAW
, 0);
1115 if (get_other_type () == view_listing
&& other_panel
->dirty
)
1116 send_message ((Widget
*) other_panel
, WIDGET_DRAW
, 0);
1119 /* --------------------------------------------------------------------------------------------- */
1122 midnight_execute_cmd (Widget
* sender
, unsigned long command
)
1124 cb_ret_t res
= MSG_HANDLED
;
1128 /* stop quick search before executing any command */
1129 send_message ((Widget
*) current_panel
, WIDGET_COMMAND
, CK_SearchStop
);
1136 case CK_PanelListingChange
:
1137 change_listing_cmd ();
1145 case CK_ChangeOwnAdvanced
:
1146 chown_advanced_cmd ();
1148 case CK_CompareDirs
:
1149 compare_dirs_cmd ();
1159 case CK_OptionsConfirm
:
1165 case CK_PutCurrentPath
:
1166 put_current_path ();
1168 case CK_PutCurrentLink
:
1169 put_current_link ();
1171 case CK_PutCurrentTagged
:
1172 put_current_tagged ();
1174 case CK_PutOtherPath
:
1177 case CK_PutOtherLink
:
1180 case CK_PutOtherTagged
:
1181 put_other_tagged ();
1187 dialog_switch_list ();
1189 #ifdef USE_DIFF_VIEW
1190 case CK_CompareFiles
:
1194 case CK_OptionsDisplayBits
:
1195 display_bits_box ();
1200 #ifdef USE_INTERNAL_EDIT
1201 case CK_EditForceInternal
:
1202 edit_cmd_force_internal ();
1205 case CK_EditExtensionsFile
:
1208 case CK_EditFileHighlightFile
:
1211 case CK_EditUserMenu
:
1212 edit_mc_menu_cmd ();
1214 case CK_LinkSymbolicEdit
:
1215 edit_symlink_cmd ();
1217 case CK_ExternalPanelize
:
1218 external_panelize ();
1223 case CK_ViewFiltered
:
1224 view_filtered_cmd ();
1229 #ifdef ENABLE_VFS_FISH
1230 case CK_ConnectFish
:
1234 #ifdef ENABLE_VFS_FTP
1239 #ifdef ENABLE_VFS_SMB
1243 #endif /* ENABLE_VFS_SMB */
1248 /* show the history of command line widget */
1249 send_message (&cmdline
->widget
, WIDGET_COMMAND
, CK_History
);
1252 if (sender
== (Widget
*) the_menubar
)
1253 info_cmd (); /* menu */
1255 info_cmd_no_menu (); /* shortcut or buttonbar */
1257 #ifdef WITH_BACKGROUND
1262 case CK_OptionsLayout
:
1269 link_cmd (LINK_HARDLINK
);
1271 case CK_PanelListing
:
1274 #ifdef LISTMODE_EDITOR
1282 case CK_MenuLastSelected
:
1283 menu_last_selected_cmd ();
1288 case CK_OptionsPanel
:
1289 panel_options_box ();
1292 case CK_SelectCodepage
:
1302 case CK_PanelQuickView
:
1303 if (sender
== (Widget
*) the_menubar
)
1304 quick_view_cmd (); /* menu */
1306 quick_cmd_no_menu (); /* shortcut or buttonabr */
1314 case CK_LinkSymbolicRelative
:
1315 link_cmd (LINK_SYMLINK_RELATIVE
);
1328 case CK_SelectInvert
:
1329 select_invert_cmd ();
1341 smart_dirsize_cmd ();
1346 case CK_ExtendedKeyMap
:
1350 mc_event_raise (MCEVENT_GROUP_CORE
, "suspend", NULL
);
1355 case CK_LinkSymbolic
:
1356 link_cmd (LINK_SYMLINK_ABSOLUTE
);
1358 case CK_PanelListingSwitch
:
1359 toggle_listing_cmd ();
1362 toggle_show_hidden ();
1364 case CK_SplitVertHoriz
:
1365 toggle_panels_split ();
1373 #ifdef ENABLE_VFS_UNDELFS
1382 user_file_menu_cmd ();
1391 /* don't close panels due to SIGINT */
1394 res
= MSG_NOT_HANDLED
;
1400 /* --------------------------------------------------------------------------------------------- */
1403 midnight_callback (Dlg_head
* h
, Widget
* sender
, dlg_msg_t msg
, int parm
, void *data
)
1405 unsigned long command
;
1416 /* We handle the special case of the output lines */
1417 if (mc_global
.tty
.console_flag
&& output_lines
)
1418 show_console_contents (output_start_y
,
1419 LINES
- output_lines
- mc_global
.keybar_visible
-
1420 1, LINES
- mc_global
.keybar_visible
- 1);
1425 menubar_arrange (the_menubar
);
1429 /* We only need the first idle event to show user menu after start */
1430 set_idle_proc (h
, 0);
1432 if (boot_current_is_left
)
1433 dlg_select_widget (get_panel_widget (0));
1435 dlg_select_widget (get_panel_widget (1));
1438 midnight_execute_cmd (NULL
, CK_UserMenu
);
1442 if (ctl_x_map_enabled
)
1444 ctl_x_map_enabled
= FALSE
;
1445 command
= keybind_lookup_keymap_command (main_x_map
, parm
);
1446 if (command
!= CK_IgnoreKey
)
1447 return midnight_execute_cmd (NULL
, command
);
1450 /* FIXME: should handle all menu shortcuts before this point */
1451 if (the_menubar
->is_active
)
1452 return MSG_NOT_HANDLED
;
1455 input_free_completions (cmdline
);
1461 for (i
= 0; cmdline
->buffer
[i
] != '\0' &&
1462 (cmdline
->buffer
[i
] == ' ' || cmdline
->buffer
[i
] == '\t'); i
++)
1465 if (cmdline
->buffer
[i
] != '\0')
1467 send_message ((Widget
*) cmdline
, WIDGET_KEY
, parm
);
1471 input_insert (cmdline
, "", FALSE
);
1475 /* Ctrl-Enter and Alt-Enter */
1476 if (((parm
& ~(KEY_M_CTRL
| KEY_M_ALT
)) == '\n') && (parm
& (KEY_M_CTRL
| KEY_M_ALT
)))
1482 /* Ctrl-Shift-Enter */
1483 if (parm
== (KEY_M_CTRL
| KEY_M_SHIFT
| '\n'))
1485 put_current_path ();
1490 if ((!alternate_plus_minus
|| !(mc_global
.tty
.console_flag
|| xterm_flag
))
1491 && !quote
&& !current_panel
->searching
)
1493 if (!only_leading_plus_minus
)
1495 /* Special treatement, since the input line will eat them */
1502 if (parm
== '\\' || parm
== '-')
1510 select_invert_cmd ();
1514 else if (!command_prompt
|| !cmdline
->buffer
[0])
1516 /* Special treatement '+', '-', '\', '*' only when this is
1517 * first char on input line
1526 if (parm
== '\\' || parm
== '-')
1534 select_invert_cmd ();
1539 return MSG_NOT_HANDLED
;
1541 case DLG_HOTKEY_HANDLED
:
1542 if ((get_current_type () == view_listing
) && current_panel
->searching
)
1544 current_panel
->dirty
= 1; /* FIXME: unneeded? */
1545 send_message ((Widget
*) current_panel
, WIDGET_COMMAND
, CK_SearchStop
);
1549 case DLG_UNHANDLED_KEY
:
1554 v
= send_message ((Widget
*) cmdline
, WIDGET_KEY
, parm
);
1555 if (v
== MSG_HANDLED
)
1559 if (ctl_x_map_enabled
)
1561 ctl_x_map_enabled
= FALSE
;
1562 command
= keybind_lookup_keymap_command (main_x_map
, parm
);
1565 command
= keybind_lookup_keymap_command (main_map
, parm
);
1567 return (command
== CK_IgnoreKey
) ? MSG_NOT_HANDLED
: midnight_execute_cmd (NULL
, command
);
1570 if (!the_menubar
->is_active
)
1571 update_dirty_panels ();
1577 return midnight_execute_cmd (NULL
, parm
);
1578 /* message from menu */
1579 if (sender
== (Widget
*) the_menubar
)
1580 return midnight_execute_cmd (sender
, parm
);
1581 /* message from buttonbar */
1582 if (sender
== (Widget
*) the_bar
)
1585 return send_message ((Widget
*) data
, WIDGET_COMMAND
, parm
);
1586 return midnight_execute_cmd (sender
, parm
);
1588 return MSG_NOT_HANDLED
;
1595 return default_dlg_callback (h
, sender
, msg
, parm
, data
);
1599 /* --------------------------------------------------------------------------------------------- */
1600 /*** public functions ****************************************************************************/
1601 /* --------------------------------------------------------------------------------------------- */
1606 menu_set_name (left_menu
, horizontal_split
? _("&Above") : _("&Left"));
1607 menu_set_name (right_menu
, horizontal_split
? _("&Below") : _("&Right"));
1608 menubar_arrange (the_menubar
);
1609 menubar_set_visible (the_menubar
, menubar_visible
);
1613 midnight_set_buttonbar (WButtonBar
* b
)
1615 buttonbar_set_label (b
, 1, Q_ ("ButtonBar|Help"), main_map
, NULL
);
1616 buttonbar_set_label (b
, 2, Q_ ("ButtonBar|Menu"), main_map
, NULL
);
1617 buttonbar_set_label (b
, 3, Q_ ("ButtonBar|View"), main_map
, NULL
);
1618 buttonbar_set_label (b
, 4, Q_ ("ButtonBar|Edit"), main_map
, NULL
);
1619 buttonbar_set_label (b
, 5, Q_ ("ButtonBar|Copy"), main_map
, NULL
);
1620 buttonbar_set_label (b
, 6, Q_ ("ButtonBar|RenMov"), main_map
, NULL
);
1621 buttonbar_set_label (b
, 7, Q_ ("ButtonBar|Mkdir"), main_map
, NULL
);
1622 buttonbar_set_label (b
, 8, Q_ ("ButtonBar|Delete"), main_map
, NULL
);
1623 buttonbar_set_label (b
, 9, Q_ ("ButtonBar|PullDn"), main_map
, NULL
);
1624 buttonbar_set_label (b
, 10, Q_ ("ButtonBar|Quit"), main_map
, NULL
);
1627 /* --------------------------------------------------------------------------------------------- */
1629 * Load new hint and display it.
1630 * IF force is not 0, ignore the timeout.
1634 load_hint (gboolean force
)
1638 if (the_hint
->widget
.owner
== NULL
)
1641 if (!mc_global
.message_visible
)
1643 label_set_text (the_hint
, NULL
);
1647 hint
= get_random_hint (force
);
1657 char text
[BUF_SMALL
];
1659 g_snprintf (text
, sizeof (text
), _("GNU Midnight Commander %s\n"), VERSION
);
1664 /* --------------------------------------------------------------------------------------------- */
1669 input_free_completions (cmdline
);
1670 dlg_one_down (midnight_dlg
);
1673 /* --------------------------------------------------------------------------------------------- */
1675 /** Save current stat of directories to avoid reloading the panels
1676 * when no modifications have taken place
1679 save_cwds_stat (void)
1681 if (panels_options
.fast_reload
)
1683 mc_stat (current_panel
->cwd
, &(current_panel
->dir_stat
));
1684 if (get_other_type () == view_listing
)
1685 mc_stat (other_panel
->cwd
, &(other_panel
->dir_stat
));
1689 /* --------------------------------------------------------------------------------------------- */
1692 quiet_quit_cmd (void)
1694 print_last_revert
= TRUE
;
1695 return quit_cmd_internal (1);
1698 /* --------------------------------------------------------------------------------------------- */
1700 /** Run the main dialog that occupies the whole screen */
1704 dlg_colors_t midnight_colors
;
1706 midnight_colors
[DLG_COLOR_NORMAL
] = mc_skin_color_get ("dialog", "_default_");
1707 midnight_colors
[DLG_COLOR_FOCUS
] = mc_skin_color_get ("dialog", "focus");
1708 midnight_colors
[DLG_COLOR_HOT_NORMAL
] = mc_skin_color_get ("dialog", "hotnormal");
1709 midnight_colors
[DLG_COLOR_HOT_FOCUS
] = mc_skin_color_get ("dialog", "hotfocus");
1710 midnight_colors
[DLG_COLOR_TITLE
] = mc_skin_color_get ("dialog", "title");
1712 #ifdef USE_INTERNAL_EDIT
1716 midnight_dlg
= create_dlg (FALSE
, 0, 0, LINES
, COLS
, midnight_colors
, midnight_callback
,
1717 "[main]", NULL
, DLG_WANT_IDLE
);
1719 if (mc_global
.mc_run_mode
== MC_RUN_FULL
)
1724 /* Check if we were invoked as an editor or file viewer */
1725 if (mc_global
.mc_run_mode
!= MC_RUN_FULL
)
1726 mc_maybe_editor_or_viewer ();
1729 create_panels_and_run_mc ();
1731 /* destroy_dlg destroys even current_panel->cwd, so we have to save a copy :) */
1732 if (mc_args__last_wd_file
!= NULL
&& vfs_current_is_local ())
1733 last_wd_string
= g_strdup (current_panel
->cwd
);
1735 /* don't handle VFS timestamps for dirs opened in panels */
1736 mc_event_destroy (MCEVENT_GROUP_CORE
, "vfs_timestamp");
1740 mc_global
.widget
.midnight_shutdown
= TRUE
;
1741 dialog_switch_shutdown ();
1743 destroy_dlg (midnight_dlg
);
1744 current_panel
= NULL
;
1746 #ifdef USE_INTERNAL_EDIT
1751 /* --------------------------------------------------------------------------------------------- */