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" /* vfs_translate_url() */
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 /* --------------------------------------------------------------------------------------------- */
469 * Just a hack for allowing url-like pathnames to be accepted from the
473 translated_mc_chdir (char *dir
)
478 newdir
= vfs_translate_url (dir
);
479 ret
= mc_chdir (newdir
);
483 /* --------------------------------------------------------------------------------------------- */
489 check_panel_timestamp (const WPanel
* panel
, panel_view_mode_t mode
, struct vfs_class
*vclass
,
492 if (mode
== view_listing
)
495 vfs_path_element_t
*path_element
;
497 vpath
= vfs_path_from_str (panel
->cwd
);
498 path_element
= vfs_path_get_by_index (vpath
, vfs_path_length (vpath
) - 1);
500 if (path_element
->class != vclass
)
503 if (vfs_getid (vpath
) != id
)
509 /* --------------------------------------------------------------------------------------------- */
513 check_current_panel_timestamp (const gchar
* event_group_name
, const gchar
* event_name
,
514 gpointer init_data
, gpointer data
)
516 ev_vfs_stamp_create_t
*event_data
= (ev_vfs_stamp_create_t
*) data
;
518 (void) event_group_name
;
523 check_panel_timestamp (current_panel
, get_current_type (), event_data
->vclass
,
525 return !event_data
->ret
;
528 /* --------------------------------------------------------------------------------------------- */
532 check_other_panel_timestamp (const gchar
* event_group_name
, const gchar
* event_name
,
533 gpointer init_data
, gpointer data
)
535 ev_vfs_stamp_create_t
*event_data
= (ev_vfs_stamp_create_t
*) data
;
537 (void) event_group_name
;
542 check_panel_timestamp (other_panel
, get_other_type (), event_data
->vclass
, event_data
->id
);
543 return !event_data
->ret
;
545 #endif /* ENABLE_VFS */
547 /* --------------------------------------------------------------------------------------------- */
551 print_vfs_message (const gchar
* event_group_name
, const gchar
* event_name
,
552 gpointer init_data
, gpointer data
)
555 ev_vfs_print_message_t
*event_data
= (ev_vfs_print_message_t
*) data
;
557 (void) event_group_name
;
561 g_vsnprintf (str
, sizeof (str
), event_data
->msg
, event_data
->ap
);
563 if (mc_global
.widget
.midnight_shutdown
)
566 if (!mc_global
.message_visible
|| !the_hint
|| !the_hint
->widget
.owner
)
570 if (!nice_rotating_dash
|| (ok_to_refresh
<= 0))
573 /* Preserve current cursor position */
574 tty_getyx (&row
, &col
);
577 tty_setcolor (NORMAL_COLOR
);
578 tty_print_string (str_fit_to_term (str
, COLS
- 1, J_LEFT
));
580 /* Restore cursor position */
581 tty_gotoyx (row
, col
);
586 if (mc_global
.message_visible
)
592 /* --------------------------------------------------------------------------------------------- */
599 panel_view_mode_t current_mode
, other_mode
;
600 char original_dir
[BUF_1K
] = "\0";
602 if (boot_current_is_left
)
606 current_mode
= startup_left_mode
;
607 other_mode
= startup_right_mode
;
613 current_mode
= startup_right_mode
;
614 other_mode
= startup_left_mode
;
616 /* Creates the left panel */
617 if (mc_run_param0
!= NULL
)
619 if (mc_run_param1
!= NULL
)
621 /* Ok, user has specified two dirs, save the original one,
622 * since we may not be able to chdir to the proper
623 * second directory later
625 mc_get_current_wd (original_dir
, sizeof (original_dir
) - 2);
627 translated_mc_chdir (mc_run_param0
);
629 set_display_type (current_index
, current_mode
);
631 /* The other panel */
632 if (mc_run_param1
!= NULL
)
634 if (original_dir
[0] != '\0')
635 translated_mc_chdir (original_dir
);
636 translated_mc_chdir (mc_run_param1
);
638 set_display_type (other_index
, other_mode
);
640 if (startup_left_mode
== view_listing
)
641 current_panel
= left_panel
;
642 else if (right_panel
!= NULL
)
643 current_panel
= right_panel
;
645 current_panel
= left_panel
;
648 mc_event_add (MCEVENT_GROUP_CORE
, "vfs_timestamp", check_other_panel_timestamp
, NULL
, NULL
);
649 mc_event_add (MCEVENT_GROUP_CORE
, "vfs_timestamp", check_current_panel_timestamp
, NULL
, NULL
);
650 #endif /* ENABLE_VFS */
652 mc_event_add (MCEVENT_GROUP_CORE
, "vfs_print_message", print_vfs_message
, NULL
, NULL
);
654 /* Create the nice widgets */
655 cmdline
= command_new (0, 0, 0);
656 the_prompt
= label_new (0, 0, mc_prompt
);
657 the_prompt
->transparent
= 1;
658 the_bar
= buttonbar_new (mc_global
.keybar_visible
);
660 the_hint
= label_new (0, 0, 0);
661 the_hint
->transparent
= 1;
662 the_hint
->auto_adjust_cols
= 0;
663 the_hint
->widget
.cols
= COLS
;
665 the_menubar
= menubar_new (0, 0, COLS
, NULL
);
668 /* --------------------------------------------------------------------------------------------- */
671 put_current_path (void)
677 cwd_path
= remove_encoding_from_path (current_panel
->cwd
);
678 command_insert (cmdline
, cwd_path
, FALSE
);
680 if (cwd_path
[strlen (cwd_path
) - 1] != PATH_SEP
)
681 command_insert (cmdline
, PATH_SEP_STR
, FALSE
);
685 /* --------------------------------------------------------------------------------------------- */
688 put_other_path (void)
692 if (get_other_type () != view_listing
)
698 cwd_path
= remove_encoding_from_path (other_panel
->cwd
);
699 command_insert (cmdline
, cwd_path
, FALSE
);
701 if (cwd_path
[strlen (cwd_path
) - 1] != PATH_SEP
)
702 command_insert (cmdline
, PATH_SEP_STR
, FALSE
);
706 /* --------------------------------------------------------------------------------------------- */
709 put_link (WPanel
* panel
)
713 if (S_ISLNK (selection (panel
)->st
.st_mode
))
715 char buffer
[MC_MAXPATHLEN
];
719 p
= concat_dir_and_file (panel
->cwd
, selection (panel
)->fname
);
720 i
= mc_readlink (p
, buffer
, MC_MAXPATHLEN
- 1);
725 command_insert (cmdline
, buffer
, TRUE
);
730 /* --------------------------------------------------------------------------------------------- */
733 put_current_link (void)
735 put_link (current_panel
);
738 /* --------------------------------------------------------------------------------------------- */
741 put_other_link (void)
743 if (get_other_type () == view_listing
)
744 put_link (other_panel
);
747 /* --------------------------------------------------------------------------------------------- */
749 /** Insert the selected file name into the input line */
757 if (get_current_type () == view_tree
)
759 WTree
*tree
= (WTree
*) get_panel_widget (get_current_index ());
760 tmp
= tree_selected_name (tree
);
763 tmp
= selection (current_panel
)->fname
;
765 command_insert (cmdline
, tmp
, TRUE
);
768 /* --------------------------------------------------------------------------------------------- */
771 put_tagged (WPanel
* panel
)
777 input_disable_update (cmdline
);
780 for (i
= 0; i
< panel
->count
; i
++)
782 if (panel
->dir
.list
[i
].f
.marked
)
783 command_insert (cmdline
, panel
->dir
.list
[i
].fname
, TRUE
);
788 command_insert (cmdline
, panel
->dir
.list
[panel
->selected
].fname
, TRUE
);
790 input_enable_update (cmdline
);
793 /* --------------------------------------------------------------------------------------------- */
796 put_current_tagged (void)
798 put_tagged (current_panel
);
801 /* --------------------------------------------------------------------------------------------- */
804 put_other_tagged (void)
806 if (get_other_type () == view_listing
)
807 put_tagged (other_panel
);
810 /* --------------------------------------------------------------------------------------------- */
815 ctl_x_map_enabled
= TRUE
;
818 /* --------------------------------------------------------------------------------------------- */
821 init_xterm_support (void)
823 const char *termvalue
;
825 termvalue
= getenv ("TERM");
826 if (!termvalue
|| !(*termvalue
))
828 fputs (_("The TERM environment variable is unset!\n"), stderr
);
832 /* Check mouse capabilities */
833 xmouse_seq
= tty_tgetstr ("Km");
835 if (strcmp (termvalue
, "cygwin") == 0)
837 mc_args__force_xterm
= 1;
838 use_mouse_p
= MOUSE_DISABLED
;
841 if (mc_args__force_xterm
|| strncmp (termvalue
, "xterm", 5) == 0
842 || strncmp (termvalue
, "konsole", 7) == 0
843 || strncmp (termvalue
, "rxvt", 4) == 0
844 || strcmp (termvalue
, "Eterm") == 0 || strcmp (termvalue
, "dtterm") == 0)
849 /* For 8-bit locales, NCurses handles 154 (0x9A) symbol properly, while S-Lang
850 * requires SLsmg_Display_Eight_Bit >= 154 (OR manual filtering if xterm display
851 * detected - but checking TERM would fail under screen, OR running xterm
852 * with allowC1Printable).
854 tty_display_8bit (FALSE
);
857 /* Default to the standard xterm sequence */
860 xmouse_seq
= ESC_STR
"[M";
863 /* Enable mouse unless explicitly disabled by --nomouse */
864 if (use_mouse_p
!= MOUSE_DISABLED
)
866 const char *color_term
= getenv ("COLORTERM");
867 if (strncmp (termvalue
, "rxvt", 4) == 0 ||
868 (color_term
!= NULL
&& strncmp (color_term
, "rxvt", 4) == 0) ||
869 strcmp (termvalue
, "Eterm") == 0)
871 use_mouse_p
= MOUSE_XTERM_NORMAL_TRACKING
;
875 use_mouse_p
= MOUSE_XTERM_BUTTON_EVENT_TRACKING
;
881 /* --------------------------------------------------------------------------------------------- */
888 tty_display_8bit (TRUE
);
890 tty_display_8bit (full_eight_bits
!= 0);
891 #endif /* HAVE_CHARSET */
895 tty_display_8bit (TRUE
);
897 tty_display_8bit (eight_bit_clean
!= 0);
898 #endif /* HAVE_CHARSET */
902 #ifdef HAVE_SUBSHELL_SUPPORT
903 if (mc_global
.tty
.use_subshell
)
904 add_select_channel (mc_global
.tty
.subshell_pty
, load_prompt
, 0);
905 #endif /* !HAVE_SUBSHELL_SUPPORT */
907 tty_setup_sigwinch (sigwinch_handler
);
909 if ((tty_baudrate () < 9600) || tty_is_slow ())
912 init_xterm_support ();
916 /* --------------------------------------------------------------------------------------------- */
919 setup_dummy_mc (void)
921 char d
[MC_MAXPATHLEN
];
924 mc_get_current_wd (d
, MC_MAXPATHLEN
);
929 /* --------------------------------------------------------------------------------------------- */
934 if ((quit
& SUBSHELL_EXIT
) == 0)
936 tty_reset_shell_mode ();
941 /* --------------------------------------------------------------------------------------------- */
950 * We sync the profiles since the hotlist may have changed, while
951 * we only change the setup data if we have the auto save feature set
954 save_setup (auto_save_setup
, panels_options
.auto_save_setup
);
957 vfs_stamp_path (vfs_get_current_dir ());
959 if ((current_panel
!= NULL
) && (get_current_type () == view_listing
))
960 vfs_stamp_path (current_panel
->cwd
);
962 if ((other_panel
!= NULL
) && (get_other_type () == view_listing
))
963 vfs_stamp_path (other_panel
->cwd
);
966 /* --------------------------------------------------------------------------------------------- */
969 create_panels_and_run_mc (void)
971 midnight_dlg
->get_shortcut
= midnight_get_shortcut
;
972 midnight_dlg
->get_title
= midnight_get_title
;
976 add_widget (midnight_dlg
, the_menubar
);
979 add_widget (midnight_dlg
, get_panel_widget (0));
980 add_widget (midnight_dlg
, get_panel_widget (1));
982 add_widget (midnight_dlg
, the_hint
);
983 add_widget (midnight_dlg
, cmdline
);
984 add_widget (midnight_dlg
, the_prompt
);
986 add_widget (midnight_dlg
, the_bar
);
987 midnight_set_buttonbar (the_bar
);
989 /* Run the Midnight Commander if no file was specified in the command line */
990 run_dlg (midnight_dlg
);
993 /* --------------------------------------------------------------------------------------------- */
995 /** result must be free'd (I think this should go in util.c) */
997 prepend_cwd_on_local (const char *filename
)
1002 if (!vfs_file_is_local (filename
) || g_path_is_absolute (filename
))
1003 return g_strdup (filename
);
1005 d
= g_malloc (MC_MAXPATHLEN
+ strlen (filename
) + 2);
1006 mc_get_current_wd (d
, MC_MAXPATHLEN
);
1009 strcpy (d
+ l
, filename
);
1010 canonicalize_pathname (d
);
1014 /* --------------------------------------------------------------------------------------------- */
1016 /** Invoke the internal view/edit routine with:
1017 * the default processing and forcing the internal viewer/editor
1020 mc_maybe_editor_or_viewer (void)
1022 switch (mc_global
.mc_run_mode
)
1024 #ifdef USE_INTERNAL_EDIT
1026 edit_file (mc_run_param0
, mc_args__edit_start_line
);
1028 #endif /* USE_INTERNAL_EDIT */
1032 path
= prepend_cwd_on_local (mc_run_param0
);
1033 view_file (path
, 0, 1);
1037 #ifdef USE_DIFF_VIEW
1038 case MC_RUN_DIFFVIEWER
:
1039 diff_view (mc_run_param0
, mc_run_param1
, mc_run_param0
, mc_run_param1
);
1041 #endif /* USE_DIFF_VIEW */
1047 /* --------------------------------------------------------------------------------------------- */
1050 quit_cmd_internal (int quiet
)
1055 n
= dialog_switch_num () - 1;
1058 char msg
[BUF_MEDIUM
];
1060 g_snprintf (msg
, sizeof (msg
),
1061 ngettext ("You have %zd opened screen. Quit anyway?",
1062 "You have %zd opened screens. Quit anyway?", n
), n
);
1064 if (query_dialog (_("The Midnight Commander"), msg
, D_NORMAL
, 2, _("&Yes"), _("&No")) != 0)
1068 else if (quiet
|| !confirm_exit
)
1070 else if (query_dialog (_("The Midnight Commander"),
1071 _("Do you really want to quit the Midnight Commander?"),
1072 D_NORMAL
, 2, _("&Yes"), _("&No")) == 0)
1077 #ifdef HAVE_SUBSHELL_SUPPORT
1078 if (!mc_global
.tty
.use_subshell
)
1080 else if ((q
= exit_subshell ()))
1090 /* --------------------------------------------------------------------------------------------- */
1095 return quit_cmd_internal (0);
1098 /* --------------------------------------------------------------------------------------------- */
1101 toggle_show_hidden (void)
1103 panels_options
.show_dot_files
= !panels_options
.show_dot_files
;
1104 update_panels (UP_RELOAD
, UP_KEEPSEL
);
1107 /* --------------------------------------------------------------------------------------------- */
1110 * Repaint the contents of the panels without frames. To schedule panel
1111 * for repainting, set panel->dirty to 1. There are many reasons why
1112 * the panels need to be repainted, and this is a costly operation, so
1113 * it's done once per event.
1117 update_dirty_panels (void)
1119 if (get_current_type () == view_listing
&& current_panel
->dirty
)
1120 send_message ((Widget
*) current_panel
, WIDGET_DRAW
, 0);
1122 if (get_other_type () == view_listing
&& other_panel
->dirty
)
1123 send_message ((Widget
*) other_panel
, WIDGET_DRAW
, 0);
1126 /* --------------------------------------------------------------------------------------------- */
1129 midnight_execute_cmd (Widget
* sender
, unsigned long command
)
1131 cb_ret_t res
= MSG_HANDLED
;
1135 /* stop quick search before executing any command */
1136 send_message ((Widget
*) current_panel
, WIDGET_COMMAND
, CK_SearchStop
);
1143 case CK_PanelListingChange
:
1144 change_listing_cmd ();
1152 case CK_ChangeOwnAdvanced
:
1153 chown_advanced_cmd ();
1155 case CK_CompareDirs
:
1156 compare_dirs_cmd ();
1166 case CK_OptionsConfirm
:
1172 case CK_PutCurrentPath
:
1173 put_current_path ();
1175 case CK_PutCurrentLink
:
1176 put_current_link ();
1178 case CK_PutCurrentTagged
:
1179 put_current_tagged ();
1181 case CK_PutOtherPath
:
1184 case CK_PutOtherLink
:
1187 case CK_PutOtherTagged
:
1188 put_other_tagged ();
1194 dialog_switch_list ();
1196 #ifdef USE_DIFF_VIEW
1197 case CK_CompareFiles
:
1201 case CK_OptionsDisplayBits
:
1202 display_bits_box ();
1207 #ifdef USE_INTERNAL_EDIT
1208 case CK_EditForceInternal
:
1209 edit_cmd_force_internal ();
1212 case CK_EditExtensionsFile
:
1215 case CK_EditFileHighlightFile
:
1218 case CK_EditUserMenu
:
1219 edit_mc_menu_cmd ();
1221 case CK_LinkSymbolicEdit
:
1222 edit_symlink_cmd ();
1224 case CK_ExternalPanelize
:
1225 external_panelize ();
1230 case CK_ViewFiltered
:
1231 view_filtered_cmd ();
1236 #ifdef ENABLE_VFS_FISH
1237 case CK_ConnectFish
:
1241 #ifdef ENABLE_VFS_FTP
1246 #ifdef ENABLE_VFS_SMB
1250 #endif /* ENABLE_VFS_SMB */
1255 /* show the history of command line widget */
1256 send_message (&cmdline
->widget
, WIDGET_COMMAND
, CK_History
);
1259 if (sender
== (Widget
*) the_menubar
)
1260 info_cmd (); /* menu */
1262 info_cmd_no_menu (); /* shortcut or buttonbar */
1264 #ifdef WITH_BACKGROUND
1269 case CK_OptionsLayout
:
1276 link_cmd (LINK_HARDLINK
);
1278 case CK_PanelListing
:
1281 #ifdef LISTMODE_EDITOR
1289 case CK_MenuLastSelected
:
1290 menu_last_selected_cmd ();
1295 case CK_OptionsPanel
:
1296 panel_options_box ();
1299 case CK_SelectCodepage
:
1309 case CK_PanelQuickView
:
1310 if (sender
== (Widget
*) the_menubar
)
1311 quick_view_cmd (); /* menu */
1313 quick_cmd_no_menu (); /* shortcut or buttonabr */
1321 case CK_LinkSymbolicRelative
:
1322 link_cmd (LINK_SYMLINK_RELATIVE
);
1335 case CK_SelectInvert
:
1336 select_invert_cmd ();
1348 smart_dirsize_cmd ();
1353 case CK_ExtendedKeyMap
:
1357 mc_event_raise (MCEVENT_GROUP_CORE
, "suspend", NULL
);
1362 case CK_LinkSymbolic
:
1363 link_cmd (LINK_SYMLINK_ABSOLUTE
);
1365 case CK_PanelListingSwitch
:
1366 toggle_listing_cmd ();
1369 toggle_show_hidden ();
1371 case CK_SplitVertHoriz
:
1372 toggle_panels_split ();
1380 #ifdef ENABLE_VFS_UNDELFS
1389 user_file_menu_cmd ();
1398 /* don't close panels due to SIGINT */
1401 res
= MSG_NOT_HANDLED
;
1407 /* --------------------------------------------------------------------------------------------- */
1410 midnight_callback (Dlg_head
* h
, Widget
* sender
, dlg_msg_t msg
, int parm
, void *data
)
1412 unsigned long command
;
1423 /* We handle the special case of the output lines */
1424 if (mc_global
.tty
.console_flag
&& output_lines
)
1425 show_console_contents (output_start_y
,
1426 LINES
- output_lines
- mc_global
.keybar_visible
-
1427 1, LINES
- mc_global
.keybar_visible
- 1);
1432 menubar_arrange (the_menubar
);
1436 /* We only need the first idle event to show user menu after start */
1437 set_idle_proc (h
, 0);
1439 if (boot_current_is_left
)
1440 dlg_select_widget (get_panel_widget (0));
1442 dlg_select_widget (get_panel_widget (1));
1445 midnight_execute_cmd (NULL
, CK_UserMenu
);
1449 if (ctl_x_map_enabled
)
1451 ctl_x_map_enabled
= FALSE
;
1452 command
= keybind_lookup_keymap_command (main_x_map
, parm
);
1453 if (command
!= CK_IgnoreKey
)
1454 return midnight_execute_cmd (NULL
, command
);
1457 /* FIXME: should handle all menu shortcuts before this point */
1458 if (the_menubar
->is_active
)
1459 return MSG_NOT_HANDLED
;
1462 input_free_completions (cmdline
);
1468 for (i
= 0; cmdline
->buffer
[i
] != '\0' &&
1469 (cmdline
->buffer
[i
] == ' ' || cmdline
->buffer
[i
] == '\t'); i
++)
1472 if (cmdline
->buffer
[i
] != '\0')
1474 send_message ((Widget
*) cmdline
, WIDGET_KEY
, parm
);
1478 input_insert (cmdline
, "", FALSE
);
1482 /* Ctrl-Enter and Alt-Enter */
1483 if (((parm
& ~(KEY_M_CTRL
| KEY_M_ALT
)) == '\n') && (parm
& (KEY_M_CTRL
| KEY_M_ALT
)))
1489 /* Ctrl-Shift-Enter */
1490 if (parm
== (KEY_M_CTRL
| KEY_M_SHIFT
| '\n'))
1492 put_current_path ();
1497 if ((!alternate_plus_minus
|| !(mc_global
.tty
.console_flag
|| xterm_flag
))
1498 && !quote
&& !current_panel
->searching
)
1500 if (!only_leading_plus_minus
)
1502 /* Special treatement, since the input line will eat them */
1509 if (parm
== '\\' || parm
== '-')
1517 select_invert_cmd ();
1521 else if (!command_prompt
|| !cmdline
->buffer
[0])
1523 /* Special treatement '+', '-', '\', '*' only when this is
1524 * first char on input line
1533 if (parm
== '\\' || parm
== '-')
1541 select_invert_cmd ();
1546 return MSG_NOT_HANDLED
;
1548 case DLG_HOTKEY_HANDLED
:
1549 if ((get_current_type () == view_listing
) && current_panel
->searching
)
1551 current_panel
->dirty
= 1; /* FIXME: unneeded? */
1552 send_message ((Widget
*) current_panel
, WIDGET_COMMAND
, CK_SearchStop
);
1556 case DLG_UNHANDLED_KEY
:
1561 v
= send_message ((Widget
*) cmdline
, WIDGET_KEY
, parm
);
1562 if (v
== MSG_HANDLED
)
1566 if (ctl_x_map_enabled
)
1568 ctl_x_map_enabled
= FALSE
;
1569 command
= keybind_lookup_keymap_command (main_x_map
, parm
);
1572 command
= keybind_lookup_keymap_command (main_map
, parm
);
1574 return (command
== CK_IgnoreKey
) ? MSG_NOT_HANDLED
: midnight_execute_cmd (NULL
, command
);
1577 if (!the_menubar
->is_active
)
1578 update_dirty_panels ();
1584 return midnight_execute_cmd (NULL
, parm
);
1585 /* message from menu */
1586 if (sender
== (Widget
*) the_menubar
)
1587 return midnight_execute_cmd (sender
, parm
);
1588 /* message from buttonbar */
1589 if (sender
== (Widget
*) the_bar
)
1592 return send_message ((Widget
*) data
, WIDGET_COMMAND
, parm
);
1593 return midnight_execute_cmd (sender
, parm
);
1595 return MSG_NOT_HANDLED
;
1602 return default_dlg_callback (h
, sender
, msg
, parm
, data
);
1606 /* --------------------------------------------------------------------------------------------- */
1607 /*** public functions ****************************************************************************/
1608 /* --------------------------------------------------------------------------------------------- */
1613 menu_set_name (left_menu
, horizontal_split
? _("&Above") : _("&Left"));
1614 menu_set_name (right_menu
, horizontal_split
? _("&Below") : _("&Right"));
1615 menubar_arrange (the_menubar
);
1616 menubar_set_visible (the_menubar
, menubar_visible
);
1620 midnight_set_buttonbar (WButtonBar
* b
)
1622 buttonbar_set_label (b
, 1, Q_ ("ButtonBar|Help"), main_map
, NULL
);
1623 buttonbar_set_label (b
, 2, Q_ ("ButtonBar|Menu"), main_map
, NULL
);
1624 buttonbar_set_label (b
, 3, Q_ ("ButtonBar|View"), main_map
, NULL
);
1625 buttonbar_set_label (b
, 4, Q_ ("ButtonBar|Edit"), main_map
, NULL
);
1626 buttonbar_set_label (b
, 5, Q_ ("ButtonBar|Copy"), main_map
, NULL
);
1627 buttonbar_set_label (b
, 6, Q_ ("ButtonBar|RenMov"), main_map
, NULL
);
1628 buttonbar_set_label (b
, 7, Q_ ("ButtonBar|Mkdir"), main_map
, NULL
);
1629 buttonbar_set_label (b
, 8, Q_ ("ButtonBar|Delete"), main_map
, NULL
);
1630 buttonbar_set_label (b
, 9, Q_ ("ButtonBar|PullDn"), main_map
, NULL
);
1631 buttonbar_set_label (b
, 10, Q_ ("ButtonBar|Quit"), main_map
, NULL
);
1634 /* --------------------------------------------------------------------------------------------- */
1636 * Load new hint and display it.
1637 * IF force is not 0, ignore the timeout.
1641 load_hint (gboolean force
)
1645 if (the_hint
->widget
.owner
== NULL
)
1648 if (!mc_global
.message_visible
)
1650 label_set_text (the_hint
, NULL
);
1654 hint
= get_random_hint (force
);
1664 char text
[BUF_SMALL
];
1666 g_snprintf (text
, sizeof (text
), _("GNU Midnight Commander %s\n"), VERSION
);
1671 /* --------------------------------------------------------------------------------------------- */
1676 input_free_completions (cmdline
);
1677 dlg_one_down (midnight_dlg
);
1680 /* --------------------------------------------------------------------------------------------- */
1682 /** Save current stat of directories to avoid reloading the panels
1683 * when no modifications have taken place
1686 save_cwds_stat (void)
1688 if (panels_options
.fast_reload
)
1690 mc_stat (current_panel
->cwd
, &(current_panel
->dir_stat
));
1691 if (get_other_type () == view_listing
)
1692 mc_stat (other_panel
->cwd
, &(other_panel
->dir_stat
));
1696 /* --------------------------------------------------------------------------------------------- */
1699 quiet_quit_cmd (void)
1701 print_last_revert
= TRUE
;
1702 return quit_cmd_internal (1);
1705 /* --------------------------------------------------------------------------------------------- */
1707 /** Run the main dialog that occupies the whole screen */
1711 dlg_colors_t midnight_colors
;
1713 midnight_colors
[DLG_COLOR_NORMAL
] = mc_skin_color_get ("dialog", "_default_");
1714 midnight_colors
[DLG_COLOR_FOCUS
] = mc_skin_color_get ("dialog", "focus");
1715 midnight_colors
[DLG_COLOR_HOT_NORMAL
] = mc_skin_color_get ("dialog", "hotnormal");
1716 midnight_colors
[DLG_COLOR_HOT_FOCUS
] = mc_skin_color_get ("dialog", "hotfocus");
1717 midnight_colors
[DLG_COLOR_TITLE
] = mc_skin_color_get ("dialog", "title");
1719 #ifdef USE_INTERNAL_EDIT
1723 midnight_dlg
= create_dlg (FALSE
, 0, 0, LINES
, COLS
, midnight_colors
, midnight_callback
,
1724 "[main]", NULL
, DLG_WANT_IDLE
);
1726 if (mc_global
.mc_run_mode
== MC_RUN_FULL
)
1731 /* Check if we were invoked as an editor or file viewer */
1732 if (mc_global
.mc_run_mode
!= MC_RUN_FULL
)
1733 mc_maybe_editor_or_viewer ();
1736 create_panels_and_run_mc ();
1738 /* destroy_dlg destroys even current_panel->cwd, so we have to save a copy :) */
1739 if (mc_args__last_wd_file
!= NULL
&& vfs_current_is_local ())
1740 last_wd_string
= g_strdup (current_panel
->cwd
);
1742 /* don't handle VFS timestamps for dirs opened in panels */
1743 mc_event_destroy (MCEVENT_GROUP_CORE
, "vfs_timestamp");
1747 mc_global
.widget
.midnight_shutdown
= TRUE
;
1748 dialog_switch_shutdown ();
1750 destroy_dlg (midnight_dlg
);
1751 current_panel
= NULL
;
1753 #ifdef USE_INTERNAL_EDIT
1758 /* --------------------------------------------------------------------------------------------- */