2 Main dialog (file panels) of the Midnight Commander
4 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
5 2003, 2004, 2005, 2006, 2007, 2009, 2010, 2011, 2013
6 The Free Software Foundation, Inc.
9 Miguel de Icaza, 1994, 1995, 1996, 1997
10 Janne Kukonlehto, 1994, 1995
12 Andrew Borodin <aborodin@vmail.ru>, 2009, 2010, 2012, 2013
13 Slava Zanko <slavazanko@gmail.com>, 2013
15 This file is part of the Midnight Commander.
17 The Midnight Commander is free software: you can redistribute it
18 and/or modify it under the terms of the GNU General Public License as
19 published by the Free Software Foundation, either version 3 of the License,
20 or (at your option) any later version.
22 The Midnight Commander is distributed in the hope that it will be useful,
23 but WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 GNU General Public License for more details.
27 You should have received a copy of the GNU General Public License
28 along with this program. If not, see <http://www.gnu.org/licenses/>.
32 * \brief Source: main dialog (file panels) of the Midnight Commander
44 #include <sys/types.h>
47 #include <pwd.h> /* for username in xterm title */
49 #include "lib/global.h"
51 #include "lib/tty/tty.h"
52 #include "lib/tty/key.h" /* KEY_M_* masks */
56 #include "lib/vfs/vfs.h"
59 #ifdef ENABLE_SUBSHELL
60 #include "src/subshell.h"
62 #include "src/setup.h" /* variables */
63 #include "src/learn.h" /* learn_keys() */
64 #include "src/keybind-defaults.h"
65 #include "lib/keybind.h"
66 #include "lib/event.h"
69 #include "boxes.h" /* sort_box(), tree_box() */
71 #include "cmd.h" /* commands */
74 #include "command.h" /* cmdline */
75 #include "dir.h" /* dir_list_clean() */
81 #ifdef USE_INTERNAL_EDIT
82 #include "src/editor/edit.h"
86 #include "src/diffviewer/ydiff.h"
89 #include "src/consaver/cons.saver.h" /* show_console_contents */
93 /* TODO: merge content of layout.c here */
94 extern int ok_to_refresh
;
96 /*** global variables ****************************************************************************/
98 /* When the modes are active, left_panel, right_panel and tree_panel */
99 /* point to a proper data structure. You should check with the functions */
100 /* get_current_type and get_other_type the types of the panels before using */
101 /* this pointer variables */
103 /* The structures for the panels */
104 WPanel
*left_panel
= NULL
;
105 WPanel
*right_panel
= NULL
;
106 /* Pointer to the selected and unselected panel */
107 WPanel
*current_panel
= NULL
;
110 WMenuBar
*the_menubar
= NULL
;
111 /* The widget where we draw the prompt */
119 const char *mc_prompt
= NULL
;
121 /*** file scope macro definitions ****************************************************************/
125 * Don't restrict the output on the screen manager level,
126 * the translation tables take care of it.
128 #endif /* !HAVE_CHARSET */
130 /*** file scope type declarations ****************************************************************/
132 /*** file scope variables ************************************************************************/
134 static menu_t
*left_menu
, *right_menu
;
136 static gboolean ctl_x_map_enabled
= FALSE
;
138 /*** file scope functions ************************************************************************/
140 /** Stop MC main dialog and the current dialog if it exists.
141 * Needed to provide fast exit from MC viewer or editor on shell exit */
145 midnight_dlg
->state
= DLG_CLOSED
;
147 if ((top_dlg
!= NULL
) && (top_dlg
->data
!= NULL
))
148 DIALOG (top_dlg
->data
)->state
= DLG_CLOSED
;
151 /* --------------------------------------------------------------------------------------------- */
158 sel_dir
= tree_box (selection (current_panel
)->fname
);
161 vfs_path_t
*sel_vdir
;
163 sel_vdir
= vfs_path_from_str (sel_dir
);
164 do_cd (sel_vdir
, cd_exact
);
165 vfs_path_free (sel_vdir
);
170 /* --------------------------------------------------------------------------------------------- */
172 #ifdef LISTMODE_EDITOR
178 if (get_current_type () != view_listing
)
181 newmode
= listmode_edit (current_panel
->user_format
);
185 g_free (current_panel
->user_format
);
186 current_panel
->list_type
= list_user
;
187 current_panel
->user_format
= newmode
;
188 set_panel_formats (current_panel
);
192 #endif /* LISTMODE_EDITOR */
194 /* --------------------------------------------------------------------------------------------- */
197 create_panel_menu (void)
199 GList
*entries
= NULL
;
201 entries
= g_list_prepend (entries
, menu_entry_create (_("File listin&g"), CK_PanelListing
));
202 entries
= g_list_prepend (entries
, menu_entry_create (_("&Quick view"), CK_PanelQuickView
));
203 entries
= g_list_prepend (entries
, menu_entry_create (_("&Info"), CK_PanelInfo
));
204 entries
= g_list_prepend (entries
, menu_entry_create (_("&Tree"), CK_PanelTree
));
205 entries
= g_list_prepend (entries
, menu_separator_create ());
207 g_list_prepend (entries
, menu_entry_create (_("&Listing mode..."), CK_PanelListingChange
));
208 entries
= g_list_prepend (entries
, menu_entry_create (_("&Sort order..."), CK_Sort
));
209 entries
= g_list_prepend (entries
, menu_entry_create (_("&Filter..."), CK_Filter
));
211 entries
= g_list_prepend (entries
, menu_entry_create (_("&Encoding..."), CK_SelectCodepage
));
213 entries
= g_list_prepend (entries
, menu_separator_create ());
214 #ifdef ENABLE_VFS_FTP
215 entries
= g_list_prepend (entries
, menu_entry_create (_("FT&P link..."), CK_ConnectFtp
));
217 #ifdef ENABLE_VFS_FISH
218 entries
= g_list_prepend (entries
, menu_entry_create (_("S&hell link..."), CK_ConnectFish
));
220 #ifdef ENABLE_VFS_SFTP
221 entries
= g_list_prepend (entries
, menu_entry_create (_("S&FTP link..."), CK_ConnectSftp
));
223 #ifdef ENABLE_VFS_SMB
224 entries
= g_list_prepend (entries
, menu_entry_create (_("SM&B link..."), CK_ConnectSmb
));
226 entries
= g_list_prepend (entries
, menu_entry_create (_("Paneli&ze"), CK_Panelize
));
227 entries
= g_list_prepend (entries
, menu_separator_create ());
228 entries
= g_list_prepend (entries
, menu_entry_create (_("&Rescan"), CK_Reread
));
230 return g_list_reverse (entries
);
233 /* --------------------------------------------------------------------------------------------- */
236 create_file_menu (void)
238 GList
*entries
= NULL
;
240 entries
= g_list_prepend (entries
, menu_entry_create (_("&View"), CK_View
));
241 entries
= g_list_prepend (entries
, menu_entry_create (_("Vie&w file..."), CK_ViewFile
));
242 entries
= g_list_prepend (entries
, menu_entry_create (_("&Filtered view"), CK_ViewFiltered
));
243 entries
= g_list_prepend (entries
, menu_entry_create (_("&Edit"), CK_Edit
));
244 entries
= g_list_prepend (entries
, menu_entry_create (_("&Copy"), CK_Copy
));
245 entries
= g_list_prepend (entries
, menu_entry_create (_("C&hmod"), CK_ChangeMode
));
246 entries
= g_list_prepend (entries
, menu_entry_create (_("&Link"), CK_Link
));
247 entries
= g_list_prepend (entries
, menu_entry_create (_("&Symlink"), CK_LinkSymbolic
));
249 g_list_prepend (entries
,
250 menu_entry_create (_("Relative symlin&k"), CK_LinkSymbolicRelative
));
251 entries
= g_list_prepend (entries
, menu_entry_create (_("Edit s&ymlink"), CK_LinkSymbolicEdit
));
252 entries
= g_list_prepend (entries
, menu_entry_create (_("Ch&own"), CK_ChangeOwn
));
254 g_list_prepend (entries
, menu_entry_create (_("&Advanced chown"), CK_ChangeOwnAdvanced
));
255 entries
= g_list_prepend (entries
, menu_entry_create (_("&Rename/Move"), CK_Move
));
256 entries
= g_list_prepend (entries
, menu_entry_create (_("&Mkdir"), CK_MakeDir
));
257 entries
= g_list_prepend (entries
, menu_entry_create (_("&Delete"), CK_Delete
));
258 entries
= g_list_prepend (entries
, menu_entry_create (_("&Quick cd"), CK_CdQuick
));
259 entries
= g_list_prepend (entries
, menu_separator_create ());
260 entries
= g_list_prepend (entries
, menu_entry_create (_("Select &group"), CK_Select
));
261 entries
= g_list_prepend (entries
, menu_entry_create (_("U&nselect group"), CK_Unselect
));
262 entries
= g_list_prepend (entries
, menu_entry_create (_("&Invert selection"), CK_SelectInvert
));
263 entries
= g_list_prepend (entries
, menu_separator_create ());
264 entries
= g_list_prepend (entries
, menu_entry_create (_("E&xit"), CK_Quit
));
266 return g_list_reverse (entries
);
269 /* --------------------------------------------------------------------------------------------- */
272 create_command_menu (void)
274 /* I know, I'm lazy, but the tree widget when it's not running
275 * as a panel still has some problems, I have not yet finished
276 * the WTree widget port, sorry.
278 GList
*entries
= NULL
;
280 entries
= g_list_prepend (entries
, menu_entry_create (_("&User menu"), CK_UserMenu
));
281 entries
= g_list_prepend (entries
, menu_entry_create (_("&Directory tree"), CK_Tree
));
282 entries
= g_list_prepend (entries
, menu_entry_create (_("&Find file"), CK_Find
));
283 entries
= g_list_prepend (entries
, menu_entry_create (_("S&wap panels"), CK_Swap
));
284 entries
= g_list_prepend (entries
, menu_entry_create (_("Switch &panels on/off"), CK_Shell
));
286 g_list_prepend (entries
, menu_entry_create (_("&Compare directories"), CK_CompareDirs
));
288 entries
= g_list_prepend (entries
, menu_entry_create (_("C&ompare files"), CK_CompareFiles
));
291 g_list_prepend (entries
, menu_entry_create (_("E&xternal panelize"), CK_ExternalPanelize
));
292 entries
= g_list_prepend (entries
, menu_entry_create (_("Show directory s&izes"), CK_DirSize
));
293 entries
= g_list_prepend (entries
, menu_separator_create ());
294 entries
= g_list_prepend (entries
, menu_entry_create (_("Command &history"), CK_History
));
295 entries
= g_list_prepend (entries
, menu_entry_create (_("Di&rectory hotlist"), CK_HotList
));
297 entries
= g_list_prepend (entries
, menu_entry_create (_("&Active VFS list"), CK_VfsList
));
299 #ifdef ENABLE_BACKGROUND
300 entries
= g_list_prepend (entries
, menu_entry_create (_("&Background jobs"), CK_Jobs
));
302 entries
= g_list_prepend (entries
, menu_entry_create (_("Screen lis&t"), CK_ScreenList
));
303 entries
= g_list_prepend (entries
, menu_separator_create ());
304 #ifdef ENABLE_VFS_UNDELFS
306 g_list_prepend (entries
,
307 menu_entry_create (_("&Undelete files (ext2fs only)"), CK_Undelete
));
309 #ifdef LISTMODE_EDITOR
310 entries
= g_list_prepend (entries
, menu_entry_create (_("&Listing format edit"), CK_ListMode
));
312 #if defined (ENABLE_VFS_UNDELFS) || defined (LISTMODE_EDITOR)
313 entries
= g_list_prepend (entries
, menu_separator_create ());
316 g_list_prepend (entries
,
317 menu_entry_create (_("Edit &extension file"), CK_EditExtensionsFile
));
318 entries
= g_list_prepend (entries
, menu_entry_create (_("Edit &menu file"), CK_EditUserMenu
));
320 g_list_prepend (entries
,
321 menu_entry_create (_("Edit hi&ghlighting group file"),
322 CK_EditFileHighlightFile
));
324 return g_list_reverse (entries
);
327 /* --------------------------------------------------------------------------------------------- */
330 create_options_menu (void)
332 GList
*entries
= NULL
;
334 entries
= g_list_prepend (entries
, menu_entry_create (_("&Configuration..."), CK_Options
));
335 entries
= g_list_prepend (entries
, menu_entry_create (_("&Layout..."), CK_OptionsLayout
));
336 entries
= g_list_prepend (entries
, menu_entry_create (_("&Panel options..."), CK_OptionsPanel
));
338 g_list_prepend (entries
, menu_entry_create (_("C&onfirmation..."), CK_OptionsConfirm
));
340 g_list_prepend (entries
, menu_entry_create (_("&Display bits..."), CK_OptionsDisplayBits
));
341 entries
= g_list_prepend (entries
, menu_entry_create (_("Learn &keys..."), CK_LearnKeys
));
343 entries
= g_list_prepend (entries
, menu_entry_create (_("&Virtual FS..."), CK_OptionsVfs
));
345 entries
= g_list_prepend (entries
, menu_separator_create ());
346 entries
= g_list_prepend (entries
, menu_entry_create (_("&Save setup"), CK_SaveSetup
));
348 return g_list_reverse (entries
);
351 /* --------------------------------------------------------------------------------------------- */
356 left_menu
= create_menu ("", create_panel_menu (), "[Left and Right Menus]");
357 menubar_add_menu (the_menubar
, left_menu
);
358 menubar_add_menu (the_menubar
, create_menu (_("&File"), create_file_menu (), "[File Menu]"));
359 menubar_add_menu (the_menubar
,
360 create_menu (_("&Command"), create_command_menu (), "[Command Menu]"));
361 menubar_add_menu (the_menubar
,
362 create_menu (_("&Options"), create_options_menu (), "[Options Menu]"));
363 right_menu
= create_menu ("", create_panel_menu (), "[Left and Right Menus]");
364 menubar_add_menu (the_menubar
, right_menu
);
368 /* --------------------------------------------------------------------------------------------- */
371 menu_last_selected_cmd (void)
373 the_menubar
->is_active
= TRUE
;
374 the_menubar
->is_dropped
= (drop_menus
!= 0);
375 the_menubar
->previous_widget
= dlg_get_current_widget_id (midnight_dlg
);
376 dlg_select_widget (the_menubar
);
379 /* --------------------------------------------------------------------------------------------- */
384 if (the_menubar
->is_active
)
387 if ((get_current_index () == 0) == (current_panel
->active
!= 0))
388 the_menubar
->selected
= 0;
390 the_menubar
->selected
= g_list_length (the_menubar
->menu
) - 1;
391 menu_last_selected_cmd ();
394 /* --------------------------------------------------------------------------------------------- */
400 const panel_field_t
*sort_order
;
402 if (!SELECTED_IS_PANEL
)
406 sort_order
= sort_box (&p
->sort_info
, p
->sort_field
);
407 panel_set_sort_order (p
, sort_order
);
410 /* --------------------------------------------------------------------------------------------- */
413 midnight_get_shortcut (unsigned long command
)
416 const char *shortcut
= NULL
;
418 shortcut
= keybind_lookup_keymap_shortcut (main_map
, command
);
419 if (shortcut
!= NULL
)
420 return g_strdup (shortcut
);
422 shortcut
= keybind_lookup_keymap_shortcut (panel_map
, command
);
423 if (shortcut
!= NULL
)
424 return g_strdup (shortcut
);
426 ext_map
= keybind_lookup_keymap_shortcut (main_map
, CK_ExtendedKeyMap
);
428 shortcut
= keybind_lookup_keymap_shortcut (main_x_map
, command
);
429 if (shortcut
!= NULL
)
430 return g_strdup_printf ("%s %s", ext_map
, shortcut
);
435 /* --------------------------------------------------------------------------------------------- */
438 midnight_get_title (const WDialog
* h
, size_t len
)
446 title_path_prepare (&path
, &login
);
448 p
= g_strdup_printf ("%s [%s]:%s", _("Panels:"), login
, path
);
451 path
= g_strdup (str_trunc (p
, len
- 4));
457 /* --------------------------------------------------------------------------------------------- */
460 toggle_panels_split (void)
462 panels_layout
.horizontal_split
= !panels_layout
.horizontal_split
;
467 /* --------------------------------------------------------------------------------------------- */
472 check_panel_timestamp (const WPanel
* panel
, panel_view_mode_t mode
, struct vfs_class
*vclass
,
475 if (mode
== view_listing
)
477 const vfs_path_element_t
*path_element
;
479 path_element
= vfs_path_get_by_index (panel
->cwd_vpath
, -1);
481 if (path_element
->class != vclass
)
484 if (vfs_getid (panel
->cwd_vpath
) != id
)
490 /* --------------------------------------------------------------------------------------------- */
494 check_current_panel_timestamp (const gchar
* event_group_name
, const gchar
* event_name
,
495 gpointer init_data
, gpointer data
)
497 ev_vfs_stamp_create_t
*event_data
= (ev_vfs_stamp_create_t
*) data
;
499 (void) event_group_name
;
504 check_panel_timestamp (current_panel
, get_current_type (), event_data
->vclass
,
506 return !event_data
->ret
;
509 /* --------------------------------------------------------------------------------------------- */
513 check_other_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 (other_panel
, get_other_type (), event_data
->vclass
, event_data
->id
);
524 return !event_data
->ret
;
526 #endif /* ENABLE_VFS */
528 /* --------------------------------------------------------------------------------------------- */
532 print_vfs_message (const gchar
* event_group_name
, const gchar
* event_name
,
533 gpointer init_data
, gpointer data
)
536 ev_vfs_print_message_t
*event_data
= (ev_vfs_print_message_t
*) data
;
538 (void) event_group_name
;
542 g_vsnprintf (str
, sizeof (str
), event_data
->msg
, event_data
->ap
);
544 if (mc_global
.midnight_shutdown
)
547 if (!mc_global
.message_visible
|| the_hint
== NULL
|| WIDGET (the_hint
)->owner
== NULL
)
551 if (!nice_rotating_dash
|| (ok_to_refresh
<= 0))
554 /* Preserve current cursor position */
555 tty_getyx (&row
, &col
);
558 tty_setcolor (NORMAL_COLOR
);
559 tty_print_string (str_fit_to_term (str
, COLS
- 1, J_LEFT
));
561 /* Restore cursor position */
562 tty_gotoyx (row
, col
);
567 if (mc_global
.message_visible
)
573 /* --------------------------------------------------------------------------------------------- */
578 int current_index
, other_index
;
579 panel_view_mode_t current_mode
, other_mode
;
580 char *current_dir
, *other_dir
;
581 vfs_path_t
*original_dir
;
584 * Following cases from command line are possible:
585 * 'mc' (no arguments): mc_run_param0 == NULL, mc_run_param1 == NULL
586 * active panel uses current directory
587 * passive panel uses "other_dir" from panels.ini
589 * 'mc dir1 dir2' (two arguments): mc_run_param0 != NULL, mc_run_param1 != NULL
590 * active panel uses mc_run_param0
591 * passive panel uses mc_run_param1
593 * 'mc dir1' (single argument): mc_run_param0 != NULL, mc_run_param1 == NULL
594 * active panel uses mc_run_param0
595 * passive panel uses "other_dir" from panels.ini
598 /* Set up panel directories */
599 if (boot_current_is_left
)
601 /* left panel is active */
604 current_mode
= startup_left_mode
;
605 other_mode
= startup_right_mode
;
607 if (mc_run_param0
== NULL
&& mc_run_param1
== NULL
)
610 current_dir
= NULL
; /* assume current dir */
611 other_dir
= saved_other_dir
; /* from ini */
613 else if (mc_run_param0
!= NULL
&& mc_run_param1
!= NULL
)
616 current_dir
= (char *) mc_run_param0
;
617 other_dir
= mc_run_param1
;
619 else /* mc_run_param0 != NULL && mc_run_param1 == NULL */
622 current_dir
= (char *) mc_run_param0
;
623 other_dir
= saved_other_dir
; /* from ini */
628 /* right panel is active */
631 current_mode
= startup_right_mode
;
632 other_mode
= startup_left_mode
;
634 if (mc_run_param0
== NULL
&& mc_run_param1
== NULL
)
637 current_dir
= NULL
; /* assume current dir */
638 other_dir
= saved_other_dir
; /* from ini */
640 else if (mc_run_param0
!= NULL
&& mc_run_param1
!= NULL
)
643 current_dir
= (char *) mc_run_param0
;
644 other_dir
= mc_run_param1
;
646 else /* mc_run_param0 != NULL && mc_run_param1 == NULL */
649 current_dir
= (char *) mc_run_param0
;
650 other_dir
= saved_other_dir
; /* from ini */
654 /* 1. Get current dir */
655 original_dir
= vfs_path_clone (vfs_get_raw_current_dir ());
657 /* 2. Create passive panel */
658 if (other_dir
!= NULL
)
662 if (g_path_is_absolute (other_dir
))
663 vpath
= vfs_path_from_str (other_dir
);
665 vpath
= vfs_path_append_new (original_dir
, other_dir
, (char *) NULL
);
667 vfs_path_free (vpath
);
669 set_display_type (other_index
, other_mode
);
671 /* 3. Create active panel */
672 if (current_dir
== NULL
)
673 mc_chdir (original_dir
);
678 if (g_path_is_absolute (current_dir
))
679 vpath
= vfs_path_from_str (current_dir
);
681 vpath
= vfs_path_append_new (original_dir
, current_dir
, (char *) NULL
);
683 vfs_path_free (vpath
);
685 set_display_type (current_index
, current_mode
);
687 if (startup_left_mode
== view_listing
)
688 current_panel
= left_panel
;
689 else if (right_panel
!= NULL
)
690 current_panel
= right_panel
;
692 current_panel
= left_panel
;
694 vfs_path_free (original_dir
);
697 mc_event_add (MCEVENT_GROUP_CORE
, "vfs_timestamp", check_other_panel_timestamp
, NULL
, NULL
);
698 mc_event_add (MCEVENT_GROUP_CORE
, "vfs_timestamp", check_current_panel_timestamp
, NULL
, NULL
);
699 #endif /* ENABLE_VFS */
701 mc_event_add (MCEVENT_GROUP_CORE
, "vfs_print_message", print_vfs_message
, NULL
, NULL
);
703 /* Create the nice widgets */
704 cmdline
= command_new (0, 0, 0);
705 the_prompt
= label_new (0, 0, mc_prompt
);
706 the_prompt
->transparent
= 1;
707 the_bar
= buttonbar_new (mc_global
.keybar_visible
);
709 the_hint
= label_new (0, 0, 0);
710 the_hint
->transparent
= 1;
711 the_hint
->auto_adjust_cols
= 0;
712 WIDGET (the_hint
)->cols
= COLS
;
714 the_menubar
= menubar_new (0, 0, COLS
, NULL
, menubar_visible
);
717 /* --------------------------------------------------------------------------------------------- */
720 midnight_put_panel_path (WPanel
* panel
)
722 vfs_path_t
*cwd_vpath
;
723 const char *cwd_vpath_str
;
729 cwd_vpath
= remove_encoding_from_path (panel
->cwd_vpath
);
731 cwd_vpath
= vfs_path_clone (panel
->cwd_vpath
);
734 cwd_vpath_str
= vfs_path_as_str (cwd_vpath
);
736 command_insert (cmdline
, cwd_vpath_str
, FALSE
);
738 if (cwd_vpath_str
[strlen (cwd_vpath_str
) - 1] != PATH_SEP
)
739 command_insert (cmdline
, PATH_SEP_STR
, FALSE
);
741 vfs_path_free (cwd_vpath
);
744 /* --------------------------------------------------------------------------------------------- */
747 put_link (WPanel
* panel
)
751 if (S_ISLNK (selection (panel
)->st
.st_mode
))
753 char buffer
[MC_MAXPATHLEN
];
757 vpath
= vfs_path_append_new (panel
->cwd_vpath
, selection (panel
)->fname
, NULL
);
758 i
= mc_readlink (vpath
, buffer
, MC_MAXPATHLEN
- 1);
759 vfs_path_free (vpath
);
764 command_insert (cmdline
, buffer
, TRUE
);
769 /* --------------------------------------------------------------------------------------------- */
772 put_current_link (void)
774 put_link (current_panel
);
777 /* --------------------------------------------------------------------------------------------- */
780 put_other_link (void)
782 if (get_other_type () == view_listing
)
783 put_link (other_panel
);
786 /* --------------------------------------------------------------------------------------------- */
788 /** Insert the selected file name into the input line */
796 if (get_current_type () == view_tree
)
799 vfs_path_t
*selected_name
;
801 tree
= (WTree
*) get_panel_widget (get_current_index ());
802 selected_name
= tree_selected_name (tree
);
803 tmp
= g_strdup (vfs_path_as_str (selected_name
));
806 tmp
= g_strdup (selection (current_panel
)->fname
);
808 command_insert (cmdline
, tmp
, TRUE
);
812 /* --------------------------------------------------------------------------------------------- */
815 put_tagged (WPanel
* panel
)
819 input_disable_update (cmdline
);
824 for (i
= 0; i
< panel
->dir
.len
; i
++)
826 if (panel
->dir
.list
[i
].f
.marked
)
827 command_insert (cmdline
, panel
->dir
.list
[i
].fname
, TRUE
);
832 command_insert (cmdline
, panel
->dir
.list
[panel
->selected
].fname
, TRUE
);
834 input_enable_update (cmdline
);
837 /* --------------------------------------------------------------------------------------------- */
840 put_current_tagged (void)
842 put_tagged (current_panel
);
845 /* --------------------------------------------------------------------------------------------- */
848 put_other_tagged (void)
850 if (get_other_type () == view_listing
)
851 put_tagged (other_panel
);
854 /* --------------------------------------------------------------------------------------------- */
859 ctl_x_map_enabled
= TRUE
;
862 /* --------------------------------------------------------------------------------------------- */
869 tty_display_8bit (TRUE
);
871 tty_display_8bit (mc_global
.full_eight_bits
!= 0);
872 #endif /* HAVE_CHARSET */
874 #else /* HAVE_SLANG */
877 tty_display_8bit (TRUE
);
879 tty_display_8bit (mc_global
.eight_bit_clean
!= 0);
880 #endif /* HAVE_CHARSET */
881 #endif /* HAVE_SLANG */
883 #ifdef ENABLE_SUBSHELL
884 if (mc_global
.tty
.use_subshell
)
885 add_select_channel (mc_global
.tty
.subshell_pty
, load_prompt
, 0);
886 #endif /* !ENABLE_SUBSHELL */
888 if ((tty_baudrate () < 9600) || mc_global
.tty
.slow_terminal
)
892 /* --------------------------------------------------------------------------------------------- */
895 setup_dummy_mc (void)
903 vpath
= vfs_path_from_str (d
);
904 ret
= mc_chdir (vpath
);
906 vfs_path_free (vpath
);
910 /* --------------------------------------------------------------------------------------------- */
917 * We sync the profiles since the hotlist may have changed, while
918 * we only change the setup data if we have the auto save feature set
922 save_setup (auto_save_setup
, panels_options
.auto_save_setup
);
924 curr_dir
= vfs_get_current_dir ();
925 vfs_stamp_path (curr_dir
);
928 if ((current_panel
!= NULL
) && (get_current_type () == view_listing
))
929 vfs_stamp_path (vfs_path_as_str (current_panel
->cwd_vpath
));
931 if ((other_panel
!= NULL
) && (get_other_type () == view_listing
))
932 vfs_stamp_path (vfs_path_as_str (other_panel
->cwd_vpath
));
935 /* --------------------------------------------------------------------------------------------- */
938 create_panels_and_run_mc (void)
940 midnight_dlg
->get_shortcut
= midnight_get_shortcut
;
941 midnight_dlg
->get_title
= midnight_get_title
;
945 add_widget (midnight_dlg
, the_menubar
);
948 add_widget (midnight_dlg
, get_panel_widget (0));
949 add_widget (midnight_dlg
, get_panel_widget (1));
951 add_widget (midnight_dlg
, the_hint
);
952 add_widget (midnight_dlg
, cmdline
);
953 add_widget (midnight_dlg
, the_prompt
);
955 add_widget (midnight_dlg
, the_bar
);
956 midnight_set_buttonbar (the_bar
);
958 /* Run the Midnight Commander if no file was specified in the command line */
959 dlg_run (midnight_dlg
);
962 /* --------------------------------------------------------------------------------------------- */
964 /** result must be free'd (I think this should go in util.c) */
966 prepend_cwd_on_local (const char *filename
)
970 vpath
= vfs_path_from_str (filename
);
971 if (!vfs_file_is_local (vpath
) || g_path_is_absolute (filename
))
974 vfs_path_free (vpath
);
976 return vfs_path_append_new (vfs_get_raw_current_dir (), filename
, NULL
);
979 /* --------------------------------------------------------------------------------------------- */
981 /** Invoke the internal view/edit routine with:
982 * the default processing and forcing the internal viewer/editor
985 mc_maybe_editor_or_viewer (void)
989 switch (mc_global
.mc_run_mode
)
991 #ifdef USE_INTERNAL_EDIT
993 ret
= edit_files ((GList
*) mc_run_param0
);
995 #endif /* USE_INTERNAL_EDIT */
998 vfs_path_t
*vpath
= NULL
;
1000 if (mc_run_param0
!= NULL
&& *(char *) mc_run_param0
!= '\0')
1001 vpath
= prepend_cwd_on_local ((char *) mc_run_param0
);
1003 ret
= view_file (vpath
, 0, 1);
1004 vfs_path_free (vpath
);
1007 #ifdef USE_DIFF_VIEW
1008 case MC_RUN_DIFFVIEWER
:
1009 ret
= dview_diff_cmd (mc_run_param0
, mc_run_param1
);
1011 #endif /* USE_DIFF_VIEW */
1019 /* --------------------------------------------------------------------------------------------- */
1022 quit_cmd_internal (int quiet
)
1027 n
= dialog_switch_num () - 1;
1030 char msg
[BUF_MEDIUM
];
1032 g_snprintf (msg
, sizeof (msg
),
1033 ngettext ("You have %zd opened screen. Quit anyway?",
1034 "You have %zd opened screens. Quit anyway?", n
), n
);
1036 if (query_dialog (_("The Midnight Commander"), msg
, D_NORMAL
, 2, _("&Yes"), _("&No")) != 0)
1040 else if (quiet
|| !confirm_exit
)
1042 else if (query_dialog (_("The Midnight Commander"),
1043 _("Do you really want to quit the Midnight Commander?"),
1044 D_NORMAL
, 2, _("&Yes"), _("&No")) == 0)
1049 #ifdef ENABLE_SUBSHELL
1050 if (!mc_global
.tty
.use_subshell
)
1052 else if ((q
= exit_subshell ()? 1 : 0) != 0)
1062 /* --------------------------------------------------------------------------------------------- */
1067 return quit_cmd_internal (0);
1070 /* --------------------------------------------------------------------------------------------- */
1073 toggle_show_hidden (void)
1075 panels_options
.show_dot_files
= !panels_options
.show_dot_files
;
1076 update_panels (UP_RELOAD
, UP_KEEPSEL
);
1079 /* --------------------------------------------------------------------------------------------- */
1082 * Repaint the contents of the panels without frames. To schedule panel
1083 * for repainting, set panel->dirty to 1. There are many reasons why
1084 * the panels need to be repainted, and this is a costly operation, so
1085 * it's done once per event.
1089 update_dirty_panels (void)
1091 if (get_current_type () == view_listing
&& current_panel
->dirty
)
1092 widget_redraw (WIDGET (current_panel
));
1094 if (get_other_type () == view_listing
&& other_panel
->dirty
)
1095 widget_redraw (WIDGET (other_panel
));
1098 /* --------------------------------------------------------------------------------------------- */
1101 midnight_execute_cmd (Widget
* sender
, unsigned long command
)
1103 cb_ret_t res
= MSG_HANDLED
;
1107 /* stop quick search before executing any command */
1108 send_message (current_panel
, NULL
, MSG_ACTION
, CK_SearchStop
, NULL
);
1115 case CK_PanelListingChange
:
1116 change_listing_cmd ();
1124 case CK_ChangeOwnAdvanced
:
1125 chown_advanced_cmd ();
1127 case CK_CompareDirs
:
1128 compare_dirs_cmd ();
1138 case CK_OptionsConfirm
:
1144 case CK_PutCurrentPath
:
1145 midnight_put_panel_path (current_panel
);
1147 case CK_PutCurrentLink
:
1148 put_current_link ();
1150 case CK_PutCurrentTagged
:
1151 put_current_tagged ();
1153 case CK_PutOtherPath
:
1154 if (get_other_type () == view_listing
)
1155 midnight_put_panel_path (other_panel
);
1157 case CK_PutOtherLink
:
1160 case CK_PutOtherTagged
:
1161 put_other_tagged ();
1167 dialog_switch_list ();
1169 #ifdef USE_DIFF_VIEW
1170 case CK_CompareFiles
:
1174 case CK_OptionsDisplayBits
:
1175 display_bits_box ();
1180 #ifdef USE_INTERNAL_EDIT
1181 case CK_EditForceInternal
:
1182 edit_cmd_force_internal ();
1185 case CK_EditExtensionsFile
:
1188 case CK_EditFileHighlightFile
:
1191 case CK_EditUserMenu
:
1192 edit_mc_menu_cmd ();
1194 case CK_LinkSymbolicEdit
:
1195 edit_symlink_cmd ();
1197 case CK_ExternalPanelize
:
1198 external_panelize ();
1203 case CK_ViewFiltered
:
1204 view_filtered_cmd ();
1209 #ifdef ENABLE_VFS_FISH
1210 case CK_ConnectFish
:
1214 #ifdef ENABLE_VFS_FTP
1219 #ifdef ENABLE_VFS_SFTP
1220 case CK_ConnectSftp
:
1224 #ifdef ENABLE_VFS_SMB
1228 #endif /* ENABLE_VFS_SMB */
1236 /* show the history of command line widget */
1237 send_message (cmdline
, NULL
, MSG_ACTION
, CK_History
, NULL
);
1240 if (sender
== WIDGET (the_menubar
))
1241 info_cmd (); /* menu */
1243 info_cmd_no_menu (); /* shortcut or buttonbar */
1245 #ifdef ENABLE_BACKGROUND
1250 case CK_OptionsLayout
:
1257 link_cmd (LINK_HARDLINK
);
1259 case CK_PanelListing
:
1262 #ifdef LISTMODE_EDITOR
1270 case CK_MenuLastSelected
:
1271 menu_last_selected_cmd ();
1276 case CK_OptionsPanel
:
1277 panel_options_box ();
1280 case CK_SelectCodepage
:
1290 case CK_PanelQuickView
:
1291 if (sender
== WIDGET (the_menubar
))
1292 quick_view_cmd (); /* menu */
1294 quick_cmd_no_menu (); /* shortcut or buttonabr */
1302 case CK_LinkSymbolicRelative
:
1303 link_cmd (LINK_SYMLINK_RELATIVE
);
1316 case CK_SelectInvert
:
1317 select_invert_cmd ();
1329 smart_dirsize_cmd ();
1334 case CK_ExtendedKeyMap
:
1338 mc_event_raise (MCEVENT_GROUP_CORE
, "suspend", NULL
);
1343 case CK_LinkSymbolic
:
1344 link_cmd (LINK_SYMLINK_ABSOLUTE
);
1346 case CK_PanelListingSwitch
:
1347 toggle_listing_cmd ();
1350 toggle_show_hidden ();
1352 case CK_SplitVertHoriz
:
1353 toggle_panels_split ();
1356 panels_split_equal ();
1359 panels_split_more ();
1362 panels_split_less ();
1370 #ifdef ENABLE_VFS_UNDELFS
1379 user_file_menu_cmd ();
1388 /* don't close panels due to SIGINT */
1391 res
= MSG_NOT_HANDLED
;
1397 /* --------------------------------------------------------------------------------------------- */
1400 midnight_callback (Widget
* w
, Widget
* sender
, widget_msg_t msg
, int parm
, void *data
)
1402 unsigned long command
;
1413 /* We handle the special case of the output lines */
1414 if (mc_global
.tty
.console_flag
!= '\0' && output_lines
)
1415 show_console_contents (output_start_y
,
1416 LINES
- output_lines
- mc_global
.keybar_visible
-
1417 1, LINES
- mc_global
.keybar_visible
- 1);
1421 /* dlg_set_size() is surplus for this case */
1425 menubar_arrange (the_menubar
);
1429 /* We only need the first idle event to show user menu after start */
1430 widget_want_idle (w
, FALSE
);
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 (cmdline
, NULL
, MSG_KEY
, parm
, NULL
);
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 midnight_put_panel_path (current_panel
);
1490 if ((!mc_global
.tty
.alternate_plus_minus
1491 || !(mc_global
.tty
.console_flag
!= '\0' || mc_global
.tty
.xterm_flag
)) && !quote
1492 && !current_panel
->searching
)
1494 if (!only_leading_plus_minus
)
1496 /* Special treatement, since the input line will eat them */
1503 if (parm
== '\\' || parm
== '-')
1511 select_invert_cmd ();
1515 else if (!command_prompt
|| !cmdline
->buffer
[0])
1517 /* Special treatement '+', '-', '\', '*' only when this is
1518 * first char on input line
1527 if (parm
== '\\' || parm
== '-')
1535 select_invert_cmd ();
1540 return MSG_NOT_HANDLED
;
1542 case MSG_HOTKEY_HANDLED
:
1543 if ((get_current_type () == view_listing
) && current_panel
->searching
)
1545 current_panel
->dirty
= 1; /* FIXME: unneeded? */
1546 send_message (current_panel
, NULL
, MSG_ACTION
, CK_SearchStop
, NULL
);
1550 case MSG_UNHANDLED_KEY
:
1552 cb_ret_t v
= MSG_NOT_HANDLED
;
1554 if (ctl_x_map_enabled
)
1556 ctl_x_map_enabled
= FALSE
;
1557 command
= keybind_lookup_keymap_command (main_x_map
, parm
);
1560 command
= keybind_lookup_keymap_command (main_map
, parm
);
1562 if (command
!= CK_IgnoreKey
)
1563 v
= midnight_execute_cmd (NULL
, command
);
1565 if (v
== MSG_NOT_HANDLED
&& command_prompt
)
1566 v
= send_message (cmdline
, NULL
, MSG_KEY
, parm
, NULL
);
1572 if (!the_menubar
->is_active
)
1573 update_dirty_panels ();
1579 return midnight_execute_cmd (NULL
, parm
);
1580 /* message from menu */
1581 if (sender
== WIDGET (the_menubar
))
1582 return midnight_execute_cmd (sender
, parm
);
1583 /* message from buttonbar */
1584 if (sender
== WIDGET (the_bar
))
1587 return send_message (data
, NULL
, MSG_ACTION
, parm
, NULL
);
1588 return midnight_execute_cmd (sender
, parm
);
1590 return MSG_NOT_HANDLED
;
1597 return dlg_default_callback (w
, sender
, msg
, parm
, data
);
1601 /* --------------------------------------------------------------------------------------------- */
1604 midnight_event (Gpm_Event
* event
, void *data
)
1606 Widget
*wh
= WIDGET (data
);
1607 int ret
= MOU_UNHANDLED
;
1609 if (event
->y
== wh
->y
+ 1)
1612 if (menubar_visible
|| the_menubar
->is_active
)
1613 ret
= WIDGET (the_menubar
)->mouse (event
, the_menubar
);
1618 w
= get_panel_widget (0);
1619 if (w
->mouse
!= NULL
)
1620 ret
= w
->mouse (event
, w
);
1622 if (ret
== MOU_UNHANDLED
)
1624 w
= get_panel_widget (1);
1625 if (w
->mouse
!= NULL
)
1626 ret
= w
->mouse (event
, w
);
1629 if (ret
== MOU_UNHANDLED
)
1630 ret
= WIDGET (the_menubar
)->mouse (event
, the_menubar
);
1637 /* --------------------------------------------------------------------------------------------- */
1638 /*** public functions ****************************************************************************/
1639 /* --------------------------------------------------------------------------------------------- */
1644 menu_set_name (left_menu
, panels_layout
.horizontal_split
? _("&Above") : _("&Left"));
1645 menu_set_name (right_menu
, panels_layout
.horizontal_split
? _("&Below") : _("&Right"));
1646 menubar_arrange (the_menubar
);
1647 menubar_set_visible (the_menubar
, menubar_visible
);
1650 /* --------------------------------------------------------------------------------------------- */
1653 midnight_set_buttonbar (WButtonBar
* b
)
1655 buttonbar_set_label (b
, 1, Q_ ("ButtonBar|Help"), main_map
, NULL
);
1656 buttonbar_set_label (b
, 2, Q_ ("ButtonBar|Menu"), main_map
, NULL
);
1657 buttonbar_set_label (b
, 3, Q_ ("ButtonBar|View"), main_map
, NULL
);
1658 buttonbar_set_label (b
, 4, Q_ ("ButtonBar|Edit"), main_map
, NULL
);
1659 buttonbar_set_label (b
, 5, Q_ ("ButtonBar|Copy"), main_map
, NULL
);
1660 buttonbar_set_label (b
, 6, Q_ ("ButtonBar|RenMov"), main_map
, NULL
);
1661 buttonbar_set_label (b
, 7, Q_ ("ButtonBar|Mkdir"), main_map
, NULL
);
1662 buttonbar_set_label (b
, 8, Q_ ("ButtonBar|Delete"), main_map
, NULL
);
1663 buttonbar_set_label (b
, 9, Q_ ("ButtonBar|PullDn"), main_map
, NULL
);
1664 buttonbar_set_label (b
, 10, Q_ ("ButtonBar|Quit"), main_map
, NULL
);
1667 /* --------------------------------------------------------------------------------------------- */
1669 * Load new hint and display it.
1670 * IF force is not 0, ignore the timeout.
1674 load_hint (gboolean force
)
1678 if (WIDGET (the_hint
)->owner
== NULL
)
1681 if (!mc_global
.message_visible
)
1683 label_set_text (the_hint
, NULL
);
1687 hint
= get_random_hint (force
);
1697 char text
[BUF_SMALL
];
1699 g_snprintf (text
, sizeof (text
), _("GNU Midnight Commander %s\n"), VERSION
);
1704 /* --------------------------------------------------------------------------------------------- */
1709 input_free_completions (cmdline
);
1710 dlg_one_down (midnight_dlg
);
1713 /* --------------------------------------------------------------------------------------------- */
1715 /** Save current stat of directories to avoid reloading the panels
1716 * when no modifications have taken place
1719 save_cwds_stat (void)
1721 if (panels_options
.fast_reload
)
1723 mc_stat (current_panel
->cwd_vpath
, &(current_panel
->dir_stat
));
1724 if (get_other_type () == view_listing
)
1725 mc_stat (other_panel
->cwd_vpath
, &(other_panel
->dir_stat
));
1729 /* --------------------------------------------------------------------------------------------- */
1732 quiet_quit_cmd (void)
1734 print_last_revert
= TRUE
;
1735 return quit_cmd_internal (1);
1738 /* --------------------------------------------------------------------------------------------- */
1740 /** Run the main dialog that occupies the whole screen */
1746 dlg_colors_t midnight_colors
;
1748 midnight_colors
[DLG_COLOR_NORMAL
] = mc_skin_color_get ("dialog", "_default_");
1749 midnight_colors
[DLG_COLOR_FOCUS
] = mc_skin_color_get ("dialog", "focus");
1750 midnight_colors
[DLG_COLOR_HOT_NORMAL
] = mc_skin_color_get ("dialog", "hotnormal");
1751 midnight_colors
[DLG_COLOR_HOT_FOCUS
] = mc_skin_color_get ("dialog", "hotfocus");
1752 midnight_colors
[DLG_COLOR_TITLE
] = mc_skin_color_get ("dialog", "title");
1754 #ifdef USE_INTERNAL_EDIT
1758 midnight_dlg
= dlg_create (FALSE
, 0, 0, LINES
, COLS
, midnight_colors
, midnight_callback
,
1759 midnight_event
, "[main]", NULL
, DLG_NONE
);
1761 /* Check if we were invoked as an editor or file viewer */
1762 if (mc_global
.mc_run_mode
!= MC_RUN_FULL
)
1765 ret
= mc_maybe_editor_or_viewer ();
1769 /* We only need the first idle event to show user menu after start */
1770 widget_want_idle (WIDGET (midnight_dlg
), TRUE
);
1773 mc_filehighlight
= mc_fhl_new (TRUE
);
1774 create_panels_and_run_mc ();
1775 mc_fhl_free (&mc_filehighlight
);
1779 /* dlg_destroy destroys even current_panel->cwd_vpath, so we have to save a copy :) */
1780 if (mc_args__last_wd_file
!= NULL
&& vfs_current_is_local ())
1781 last_wd_string
= g_strdup (vfs_path_as_str (current_panel
->cwd_vpath
));
1783 /* don't handle VFS timestamps for dirs opened in panels */
1784 mc_event_destroy (MCEVENT_GROUP_CORE
, "vfs_timestamp");
1786 dir_list_clean (&panelized_panel
.list
);
1790 mc_global
.midnight_shutdown
= TRUE
;
1791 dialog_switch_shutdown ();
1793 dlg_destroy (midnight_dlg
);
1794 current_panel
= NULL
;
1796 #ifdef USE_INTERNAL_EDIT
1800 if ((quit
& SUBSHELL_EXIT
) == 0)
1806 /* --------------------------------------------------------------------------------------------- */