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
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
14 This file is part of the Midnight Commander.
16 The Midnight Commander is free software: you can redistribute it
17 and/or modify it under the terms of the GNU General Public License as
18 published by the Free Software Foundation, either version 3 of the License,
19 or (at your option) any later version.
21 The Midnight Commander is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program. If not, see <http://www.gnu.org/licenses/>.
31 * \brief Source: main dialog (file panels) of the Midnight Commander
43 #include <sys/types.h>
46 #include <pwd.h> /* for username in xterm title */
48 #include "lib/global.h"
50 #include "lib/tty/tty.h"
51 #include "lib/tty/key.h" /* KEY_M_* masks */
55 #include "lib/vfs/vfs.h"
58 #ifdef ENABLE_SUBSHELL
59 #include "src/subshell.h"
61 #include "src/setup.h" /* variables */
62 #include "src/learn.h" /* learn_keys() */
63 #include "src/keybind-defaults.h"
64 #include "lib/keybind.h"
65 #include "lib/event.h"
67 #include "option.h" /* configure_box() */
69 #include "boxes.h" /* sort_box(), tree_box() */
71 #include "cmd.h" /* commands */
74 #include "command.h" /* cmdline */
75 #include "dir.h" /* clean_dir() */
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 */
118 /*** file scope macro definitions ****************************************************************/
122 * Don't restrict the output on the screen manager level,
123 * the translation tables take care of it.
125 #endif /* !HAVE_CHARSET */
127 /*** file scope type declarations ****************************************************************/
129 /*** file scope variables ************************************************************************/
131 static Menu
*left_menu
, *right_menu
;
133 static gboolean ctl_x_map_enabled
= FALSE
;
135 /*** file scope functions ************************************************************************/
137 /** Stop MC main dialog and the current dialog if it exists.
138 * Needed to provide fast exit from MC viewer or editor on shell exit */
142 midnight_dlg
->state
= DLG_CLOSED
;
144 if ((top_dlg
!= NULL
) && (top_dlg
->data
!= NULL
))
145 ((Dlg_head
*) top_dlg
->data
)->state
= DLG_CLOSED
;
148 /* --------------------------------------------------------------------------------------------- */
155 sel_dir
= tree_box (selection (current_panel
)->fname
);
158 vfs_path_t
*sel_vdir
;
160 sel_vdir
= vfs_path_from_str (sel_dir
);
161 do_cd (sel_vdir
, cd_exact
);
162 vfs_path_free (sel_vdir
);
167 /* --------------------------------------------------------------------------------------------- */
169 #ifdef LISTMODE_EDITOR
175 if (get_current_type () != view_listing
)
178 newmode
= listmode_edit (current_panel
->user_format
);
182 g_free (current_panel
->user_format
);
183 current_panel
->list_type
= list_user
;
184 current_panel
->user_format
= newmode
;
185 set_panel_formats (current_panel
);
189 #endif /* LISTMODE_EDITOR */
191 /* --------------------------------------------------------------------------------------------- */
194 create_panel_menu (void)
196 GList
*entries
= NULL
;
198 entries
= g_list_prepend (entries
, menu_entry_create (_("File listin&g"), CK_PanelListing
));
199 entries
= g_list_prepend (entries
, menu_entry_create (_("&Quick view"), CK_PanelQuickView
));
200 entries
= g_list_prepend (entries
, menu_entry_create (_("&Info"), CK_PanelInfo
));
201 entries
= g_list_prepend (entries
, menu_entry_create (_("&Tree"), CK_PanelTree
));
202 entries
= g_list_prepend (entries
, menu_separator_create ());
204 g_list_prepend (entries
, menu_entry_create (_("&Listing mode..."), CK_PanelListingChange
));
205 entries
= g_list_prepend (entries
, menu_entry_create (_("&Sort order..."), CK_Sort
));
206 entries
= g_list_prepend (entries
, menu_entry_create (_("&Filter..."), CK_Filter
));
208 entries
= g_list_prepend (entries
, menu_entry_create (_("&Encoding..."), CK_SelectCodepage
));
210 entries
= g_list_prepend (entries
, menu_separator_create ());
211 #ifdef ENABLE_VFS_FTP
212 entries
= g_list_prepend (entries
, menu_entry_create (_("FT&P link..."), CK_ConnectFtp
));
214 #ifdef ENABLE_VFS_FISH
215 entries
= g_list_prepend (entries
, menu_entry_create (_("S&hell link..."), CK_ConnectFish
));
217 #ifdef ENABLE_VFS_SFTP
218 entries
= g_list_prepend (entries
, menu_entry_create (_("S&FTP link..."), CK_ConnectSftp
));
220 #ifdef ENABLE_VFS_SMB
221 entries
= g_list_prepend (entries
, menu_entry_create (_("SM&B link..."), CK_ConnectSmb
));
223 entries
= g_list_prepend (entries
, menu_entry_create (_("Paneli&ze"), CK_Panelize
));
224 entries
= g_list_prepend (entries
, menu_separator_create ());
225 entries
= g_list_prepend (entries
, menu_entry_create (_("&Rescan"), CK_Reread
));
227 return g_list_reverse (entries
);
230 /* --------------------------------------------------------------------------------------------- */
233 create_file_menu (void)
235 GList
*entries
= NULL
;
237 entries
= g_list_prepend (entries
, menu_entry_create (_("&View"), CK_View
));
238 entries
= g_list_prepend (entries
, menu_entry_create (_("Vie&w file..."), CK_ViewFile
));
239 entries
= g_list_prepend (entries
, menu_entry_create (_("&Filtered view"), CK_ViewFiltered
));
240 entries
= g_list_prepend (entries
, menu_entry_create (_("&Edit"), CK_Edit
));
241 entries
= g_list_prepend (entries
, menu_entry_create (_("&Copy"), CK_Copy
));
242 entries
= g_list_prepend (entries
, menu_entry_create (_("C&hmod"), CK_ChangeMode
));
243 entries
= g_list_prepend (entries
, menu_entry_create (_("&Link"), CK_Link
));
244 entries
= g_list_prepend (entries
, menu_entry_create (_("&Symlink"), CK_LinkSymbolic
));
246 g_list_prepend (entries
,
247 menu_entry_create (_("Relative symlin&k"), CK_LinkSymbolicRelative
));
248 entries
= g_list_prepend (entries
, menu_entry_create (_("Edit s&ymlink"), CK_LinkSymbolicEdit
));
249 entries
= g_list_prepend (entries
, menu_entry_create (_("Ch&own"), CK_ChangeOwn
));
251 g_list_prepend (entries
, menu_entry_create (_("&Advanced chown"), CK_ChangeOwnAdvanced
));
252 entries
= g_list_prepend (entries
, menu_entry_create (_("&Rename/Move"), CK_Move
));
253 entries
= g_list_prepend (entries
, menu_entry_create (_("&Mkdir"), CK_MakeDir
));
254 entries
= g_list_prepend (entries
, menu_entry_create (_("&Delete"), CK_Delete
));
255 entries
= g_list_prepend (entries
, menu_entry_create (_("&Quick cd"), CK_CdQuick
));
256 entries
= g_list_prepend (entries
, menu_separator_create ());
257 entries
= g_list_prepend (entries
, menu_entry_create (_("Select &group"), CK_Select
));
258 entries
= g_list_prepend (entries
, menu_entry_create (_("U&nselect group"), CK_Unselect
));
259 entries
= g_list_prepend (entries
, menu_entry_create (_("&Invert selection"), CK_SelectInvert
));
260 entries
= g_list_prepend (entries
, menu_separator_create ());
261 entries
= g_list_prepend (entries
, menu_entry_create (_("E&xit"), CK_Quit
));
263 return g_list_reverse (entries
);
266 /* --------------------------------------------------------------------------------------------- */
269 create_command_menu (void)
271 /* I know, I'm lazy, but the tree widget when it's not running
272 * as a panel still has some problems, I have not yet finished
273 * the WTree widget port, sorry.
275 GList
*entries
= NULL
;
277 entries
= g_list_prepend (entries
, menu_entry_create (_("&User menu"), CK_UserMenu
));
278 entries
= g_list_prepend (entries
, menu_entry_create (_("&Directory tree"), CK_Tree
));
279 entries
= g_list_prepend (entries
, menu_entry_create (_("&Find file"), CK_Find
));
280 entries
= g_list_prepend (entries
, menu_entry_create (_("S&wap panels"), CK_Swap
));
281 entries
= g_list_prepend (entries
, menu_entry_create (_("Switch &panels on/off"), CK_Shell
));
283 g_list_prepend (entries
, menu_entry_create (_("&Compare directories"), CK_CompareDirs
));
285 entries
= g_list_prepend (entries
, menu_entry_create (_("C&ompare files"), CK_CompareFiles
));
288 g_list_prepend (entries
, menu_entry_create (_("E&xternal panelize"), CK_ExternalPanelize
));
289 entries
= g_list_prepend (entries
, menu_entry_create (_("Show directory s&izes"), CK_DirSize
));
290 entries
= g_list_prepend (entries
, menu_separator_create ());
291 entries
= g_list_prepend (entries
, menu_entry_create (_("Command &history"), CK_History
));
292 entries
= g_list_prepend (entries
, menu_entry_create (_("Di&rectory hotlist"), CK_HotList
));
294 entries
= g_list_prepend (entries
, menu_entry_create (_("&Active VFS list"), CK_VfsList
));
296 #ifdef ENABLE_BACKGROUND
297 entries
= g_list_prepend (entries
, menu_entry_create (_("&Background jobs"), CK_Jobs
));
299 entries
= g_list_prepend (entries
, menu_entry_create (_("Screen lis&t"), CK_ScreenList
));
300 entries
= g_list_prepend (entries
, menu_separator_create ());
301 #ifdef ENABLE_VFS_UNDELFS
303 g_list_prepend (entries
,
304 menu_entry_create (_("&Undelete files (ext2fs only)"), CK_Undelete
));
306 #ifdef LISTMODE_EDITOR
307 entries
= g_list_prepend (entries
, menu_entry_create (_("&Listing format edit"), CK_ListMode
));
309 #if defined (ENABLE_VFS_UNDELFS) || defined (LISTMODE_EDITOR)
310 entries
= g_list_prepend (entries
, menu_separator_create ());
313 g_list_prepend (entries
,
314 menu_entry_create (_("Edit &extension file"), CK_EditExtensionsFile
));
315 entries
= g_list_prepend (entries
, menu_entry_create (_("Edit &menu file"), CK_EditUserMenu
));
317 g_list_prepend (entries
,
318 menu_entry_create (_("Edit hi&ghlighting group file"),
319 CK_EditFileHighlightFile
));
321 return g_list_reverse (entries
);
324 /* --------------------------------------------------------------------------------------------- */
327 create_options_menu (void)
329 GList
*entries
= NULL
;
331 entries
= g_list_prepend (entries
, menu_entry_create (_("&Configuration..."), CK_Options
));
332 entries
= g_list_prepend (entries
, menu_entry_create (_("&Layout..."), CK_OptionsLayout
));
333 entries
= g_list_prepend (entries
, menu_entry_create (_("&Panel options..."), CK_OptionsPanel
));
335 g_list_prepend (entries
, menu_entry_create (_("C&onfirmation..."), CK_OptionsConfirm
));
337 g_list_prepend (entries
, menu_entry_create (_("&Display bits..."), CK_OptionsDisplayBits
));
338 entries
= g_list_prepend (entries
, menu_entry_create (_("Learn &keys..."), CK_LearnKeys
));
340 entries
= g_list_prepend (entries
, menu_entry_create (_("&Virtual FS..."), CK_OptionsVfs
));
342 entries
= g_list_prepend (entries
, menu_separator_create ());
343 entries
= g_list_prepend (entries
, menu_entry_create (_("&Save setup"), CK_SaveSetup
));
345 return g_list_reverse (entries
);
348 /* --------------------------------------------------------------------------------------------- */
353 left_menu
= create_menu ("", create_panel_menu (), "[Left and Right Menus]");
354 menubar_add_menu (the_menubar
, left_menu
);
355 menubar_add_menu (the_menubar
, create_menu (_("&File"), create_file_menu (), "[File Menu]"));
356 menubar_add_menu (the_menubar
,
357 create_menu (_("&Command"), create_command_menu (), "[Command Menu]"));
358 menubar_add_menu (the_menubar
,
359 create_menu (_("&Options"), create_options_menu (), "[Options Menu]"));
360 right_menu
= create_menu ("", create_panel_menu (), "[Left and Right Menus]");
361 menubar_add_menu (the_menubar
, right_menu
);
365 /* --------------------------------------------------------------------------------------------- */
368 menu_last_selected_cmd (void)
370 the_menubar
->is_active
= TRUE
;
371 the_menubar
->is_dropped
= (drop_menus
!= 0);
372 the_menubar
->previous_widget
= dlg_get_current_widget_id (midnight_dlg
);
373 dlg_select_widget (the_menubar
);
376 /* --------------------------------------------------------------------------------------------- */
381 if (the_menubar
->is_active
)
384 if ((get_current_index () == 0) == (current_panel
->active
!= 0))
385 the_menubar
->selected
= 0;
387 the_menubar
->selected
= g_list_length (the_menubar
->menu
) - 1;
388 menu_last_selected_cmd ();
391 /* --------------------------------------------------------------------------------------------- */
397 const panel_field_t
*sort_order
;
399 if (!SELECTED_IS_PANEL
)
403 sort_order
= sort_box (&p
->sort_info
);
404 panel_set_sort_order (p
, sort_order
);
407 /* --------------------------------------------------------------------------------------------- */
410 midnight_get_shortcut (unsigned long command
)
413 const char *shortcut
= NULL
;
415 shortcut
= keybind_lookup_keymap_shortcut (main_map
, command
);
416 if (shortcut
!= NULL
)
417 return g_strdup (shortcut
);
419 shortcut
= keybind_lookup_keymap_shortcut (panel_map
, command
);
420 if (shortcut
!= NULL
)
421 return g_strdup (shortcut
);
423 ext_map
= keybind_lookup_keymap_shortcut (main_map
, CK_ExtendedKeyMap
);
425 shortcut
= keybind_lookup_keymap_shortcut (main_x_map
, command
);
426 if (shortcut
!= NULL
)
427 return g_strdup_printf ("%s %s", ext_map
, shortcut
);
432 /* --------------------------------------------------------------------------------------------- */
435 midnight_get_title (const Dlg_head
* h
, size_t len
)
443 title_path_prepare (&path
, &login
);
445 p
= g_strdup_printf ("%s [%s]:%s", _("Panels:"), login
, path
);
448 path
= g_strdup (str_trunc (p
, len
- 4));
454 /* --------------------------------------------------------------------------------------------- */
457 toggle_panels_split (void)
459 panels_layout
.horizontal_split
= !panels_layout
.horizontal_split
;
464 /* --------------------------------------------------------------------------------------------- */
469 check_panel_timestamp (const WPanel
* panel
, panel_view_mode_t mode
, struct vfs_class
*vclass
,
472 if (mode
== view_listing
)
474 const vfs_path_element_t
*path_element
;
476 path_element
= vfs_path_get_by_index (panel
->cwd_vpath
, -1);
478 if (path_element
->class != vclass
)
481 if (vfs_getid (panel
->cwd_vpath
) != id
)
487 /* --------------------------------------------------------------------------------------------- */
491 check_current_panel_timestamp (const gchar
* event_group_name
, const gchar
* event_name
,
492 gpointer init_data
, gpointer data
)
494 ev_vfs_stamp_create_t
*event_data
= (ev_vfs_stamp_create_t
*) data
;
496 (void) event_group_name
;
501 check_panel_timestamp (current_panel
, get_current_type (), event_data
->vclass
,
503 return !event_data
->ret
;
506 /* --------------------------------------------------------------------------------------------- */
510 check_other_panel_timestamp (const gchar
* event_group_name
, const gchar
* event_name
,
511 gpointer init_data
, gpointer data
)
513 ev_vfs_stamp_create_t
*event_data
= (ev_vfs_stamp_create_t
*) data
;
515 (void) event_group_name
;
520 check_panel_timestamp (other_panel
, get_other_type (), event_data
->vclass
, event_data
->id
);
521 return !event_data
->ret
;
523 #endif /* ENABLE_VFS */
525 /* --------------------------------------------------------------------------------------------- */
529 print_vfs_message (const gchar
* event_group_name
, const gchar
* event_name
,
530 gpointer init_data
, gpointer data
)
533 ev_vfs_print_message_t
*event_data
= (ev_vfs_print_message_t
*) data
;
535 (void) event_group_name
;
539 g_vsnprintf (str
, sizeof (str
), event_data
->msg
, event_data
->ap
);
541 if (mc_global
.midnight_shutdown
)
544 if (!mc_global
.message_visible
|| !the_hint
|| !the_hint
->widget
.owner
)
548 if (!nice_rotating_dash
|| (ok_to_refresh
<= 0))
551 /* Preserve current cursor position */
552 tty_getyx (&row
, &col
);
555 tty_setcolor (NORMAL_COLOR
);
556 tty_print_string (str_fit_to_term (str
, COLS
- 1, J_LEFT
));
558 /* Restore cursor position */
559 tty_gotoyx (row
, col
);
564 if (mc_global
.message_visible
)
570 /* --------------------------------------------------------------------------------------------- */
575 int current_index
, other_index
;
576 panel_view_mode_t current_mode
, other_mode
;
577 char *current_dir
, *other_dir
;
578 vfs_path_t
*original_dir
;
580 if (boot_current_is_left
)
582 /* left panel is active */
585 current_mode
= startup_left_mode
;
586 other_mode
= startup_right_mode
;
587 /* if mc_run_param0 is NULL, working directory will be used for the left panel */
588 current_dir
= (char *) mc_run_param0
;
589 /* mc_run_param1 is never NULL. It is setup from command line or from panels.ini
590 * (value of other_dir). mc_run_param1 will be used for the right panel */
591 other_dir
= mc_run_param1
;
595 /* right panel is active */
598 current_mode
= startup_right_mode
;
599 other_mode
= startup_left_mode
;
601 /* if mc_run_param0 is not NULL (it was setup from command line), it will be used
602 * for the left panel, working directory will be used for the right one;
603 * if mc_run_param0 is NULL, working directory will be used for the right (active) panel,
604 * mc_run_param1 will be used for the left one */
605 if (mc_run_param0
!= NULL
)
608 other_dir
= (char *) mc_run_param0
;
613 other_dir
= mc_run_param1
;
617 /* 1. Get current dir */
618 original_dir
= vfs_path_clone (vfs_get_raw_current_dir ());
620 /* 2. Create passive panel */
621 if (other_dir
!= NULL
)
625 if (g_path_is_absolute (other_dir
))
626 vpath
= vfs_path_from_str (other_dir
);
628 vpath
= vfs_path_append_new (original_dir
, other_dir
, (char *) NULL
);
630 vfs_path_free (vpath
);
632 set_display_type (other_index
, other_mode
);
634 /* 3. Create active panel */
635 if (current_dir
== NULL
)
636 mc_chdir (original_dir
);
641 if (g_path_is_absolute (current_dir
))
642 vpath
= vfs_path_from_str (current_dir
);
644 vpath
= vfs_path_append_new (original_dir
, current_dir
, (char *) NULL
);
646 vfs_path_free (vpath
);
648 set_display_type (current_index
, current_mode
);
650 if (startup_left_mode
== view_listing
)
651 current_panel
= left_panel
;
652 else if (right_panel
!= NULL
)
653 current_panel
= right_panel
;
655 current_panel
= left_panel
;
657 vfs_path_free (original_dir
);
660 mc_event_add (MCEVENT_GROUP_CORE
, "vfs_timestamp", check_other_panel_timestamp
, NULL
, NULL
);
661 mc_event_add (MCEVENT_GROUP_CORE
, "vfs_timestamp", check_current_panel_timestamp
, NULL
, NULL
);
662 #endif /* ENABLE_VFS */
664 mc_event_add (MCEVENT_GROUP_CORE
, "vfs_print_message", print_vfs_message
, NULL
, NULL
);
666 /* Create the nice widgets */
667 cmdline
= command_new (0, 0, 0);
668 the_prompt
= label_new (0, 0, mc_prompt
);
669 the_prompt
->transparent
= 1;
670 the_bar
= buttonbar_new (mc_global
.keybar_visible
);
672 the_hint
= label_new (0, 0, 0);
673 the_hint
->transparent
= 1;
674 the_hint
->auto_adjust_cols
= 0;
675 the_hint
->widget
.cols
= COLS
;
677 the_menubar
= menubar_new (0, 0, COLS
, NULL
);
680 /* --------------------------------------------------------------------------------------------- */
683 put_current_path (void)
692 vfs_path_t
*cwd_vpath
;
694 cwd_vpath
= remove_encoding_from_path (current_panel
->cwd_vpath
);
695 cwd_path
= vfs_path_to_str (cwd_vpath
);
696 vfs_path_free (cwd_vpath
);
699 cwd_path
= vfs_path_to_str (current_panel
->cwd_vpath
);
702 command_insert (cmdline
, cwd_path
, FALSE
);
703 if (cwd_path
[strlen (cwd_path
) - 1] != PATH_SEP
)
704 command_insert (cmdline
, PATH_SEP_STR
, FALSE
);
709 /* --------------------------------------------------------------------------------------------- */
712 put_other_path (void)
716 if (get_other_type () != view_listing
)
724 vfs_path_t
*cwd_vpath
;
726 cwd_vpath
= remove_encoding_from_path (other_panel
->cwd_vpath
);
727 cwd_path
= vfs_path_to_str (cwd_vpath
);
728 vfs_path_free (cwd_vpath
);
731 cwd_path
= vfs_path_to_str (other_panel
->cwd_vpath
);
734 command_insert (cmdline
, cwd_path
, FALSE
);
735 if (cwd_path
[strlen (cwd_path
) - 1] != PATH_SEP
)
736 command_insert (cmdline
, PATH_SEP_STR
, FALSE
);
741 /* --------------------------------------------------------------------------------------------- */
744 put_link (WPanel
* panel
)
748 if (S_ISLNK (selection (panel
)->st
.st_mode
))
750 char buffer
[MC_MAXPATHLEN
];
754 vpath
= vfs_path_append_new (panel
->cwd_vpath
, selection (panel
)->fname
, NULL
);
755 i
= mc_readlink (vpath
, buffer
, MC_MAXPATHLEN
- 1);
756 vfs_path_free (vpath
);
761 command_insert (cmdline
, buffer
, TRUE
);
766 /* --------------------------------------------------------------------------------------------- */
769 put_current_link (void)
771 put_link (current_panel
);
774 /* --------------------------------------------------------------------------------------------- */
777 put_other_link (void)
779 if (get_other_type () == view_listing
)
780 put_link (other_panel
);
783 /* --------------------------------------------------------------------------------------------- */
785 /** Insert the selected file name into the input line */
793 if (get_current_type () == view_tree
)
795 WTree
*tree
= (WTree
*) get_panel_widget (get_current_index ());
797 tmp
= vfs_path_to_str (tree_selected_name (tree
));
800 tmp
= g_strdup (selection (current_panel
)->fname
);
802 command_insert (cmdline
, tmp
, TRUE
);
806 /* --------------------------------------------------------------------------------------------- */
809 put_tagged (WPanel
* panel
)
815 input_disable_update (cmdline
);
818 for (i
= 0; i
< panel
->count
; i
++)
820 if (panel
->dir
.list
[i
].f
.marked
)
821 command_insert (cmdline
, panel
->dir
.list
[i
].fname
, TRUE
);
826 command_insert (cmdline
, panel
->dir
.list
[panel
->selected
].fname
, TRUE
);
828 input_enable_update (cmdline
);
831 /* --------------------------------------------------------------------------------------------- */
834 put_current_tagged (void)
836 put_tagged (current_panel
);
839 /* --------------------------------------------------------------------------------------------- */
842 put_other_tagged (void)
844 if (get_other_type () == view_listing
)
845 put_tagged (other_panel
);
848 /* --------------------------------------------------------------------------------------------- */
853 ctl_x_map_enabled
= TRUE
;
856 /* --------------------------------------------------------------------------------------------- */
863 tty_display_8bit (TRUE
);
865 tty_display_8bit (mc_global
.full_eight_bits
!= 0);
866 #endif /* HAVE_CHARSET */
868 #else /* HAVE_SLANG */
871 tty_display_8bit (TRUE
);
873 tty_display_8bit (mc_global
.eight_bit_clean
!= 0);
874 #endif /* HAVE_CHARSET */
875 #endif /* HAVE_SLANG */
877 #ifdef ENABLE_SUBSHELL
878 if (mc_global
.tty
.use_subshell
)
879 add_select_channel (mc_global
.tty
.subshell_pty
, load_prompt
, 0);
880 #endif /* !ENABLE_SUBSHELL */
882 if ((tty_baudrate () < 9600) || mc_global
.tty
.slow_terminal
)
886 /* --------------------------------------------------------------------------------------------- */
889 setup_dummy_mc (void)
897 vpath
= vfs_path_from_str (d
);
898 ret
= mc_chdir (vpath
);
899 vfs_path_free (vpath
);
903 /* --------------------------------------------------------------------------------------------- */
910 * We sync the profiles since the hotlist may have changed, while
911 * we only change the setup data if we have the auto save feature set
915 save_setup (auto_save_setup
, panels_options
.auto_save_setup
);
917 curr_dir
= vfs_get_current_dir ();
918 vfs_stamp_path (curr_dir
);
921 if ((current_panel
!= NULL
) && (get_current_type () == view_listing
))
925 tmp_path
= vfs_path_to_str (current_panel
->cwd_vpath
);
926 vfs_stamp_path (tmp_path
);
930 if ((other_panel
!= NULL
) && (get_other_type () == view_listing
))
934 tmp_path
= vfs_path_to_str (other_panel
->cwd_vpath
);
935 vfs_stamp_path (tmp_path
);
940 /* --------------------------------------------------------------------------------------------- */
943 create_panels_and_run_mc (void)
945 midnight_dlg
->get_shortcut
= midnight_get_shortcut
;
946 midnight_dlg
->get_title
= midnight_get_title
;
950 add_widget (midnight_dlg
, the_menubar
);
953 add_widget (midnight_dlg
, get_panel_widget (0));
954 add_widget (midnight_dlg
, get_panel_widget (1));
956 add_widget (midnight_dlg
, the_hint
);
957 add_widget (midnight_dlg
, cmdline
);
958 add_widget (midnight_dlg
, the_prompt
);
960 add_widget (midnight_dlg
, the_bar
);
961 midnight_set_buttonbar (the_bar
);
963 /* Run the Midnight Commander if no file was specified in the command line */
964 run_dlg (midnight_dlg
);
967 /* --------------------------------------------------------------------------------------------- */
969 /** result must be free'd (I think this should go in util.c) */
971 prepend_cwd_on_local (const char *filename
)
975 vpath
= vfs_path_from_str (filename
);
976 if (!vfs_file_is_local (vpath
) || g_path_is_absolute (filename
))
979 vfs_path_free (vpath
);
981 return vfs_path_append_new (vfs_get_raw_current_dir (), filename
, NULL
);
984 /* --------------------------------------------------------------------------------------------- */
986 /** Invoke the internal view/edit routine with:
987 * the default processing and forcing the internal viewer/editor
990 mc_maybe_editor_or_viewer (void)
994 switch (mc_global
.mc_run_mode
)
996 #ifdef USE_INTERNAL_EDIT
998 ret
= edit_files ((GList
*) mc_run_param0
);
1000 #endif /* USE_INTERNAL_EDIT */
1003 vfs_path_t
*vpath
= NULL
;
1005 if (mc_run_param0
!= NULL
&& *(char *) mc_run_param0
!= '\0')
1006 vpath
= prepend_cwd_on_local ((char *) mc_run_param0
);
1008 ret
= view_file (vpath
, 0, 1);
1009 vfs_path_free (vpath
);
1012 #ifdef USE_DIFF_VIEW
1013 case MC_RUN_DIFFVIEWER
:
1014 ret
= dview_diff_cmd (mc_run_param0
, mc_run_param1
);
1016 #endif /* USE_DIFF_VIEW */
1024 /* --------------------------------------------------------------------------------------------- */
1027 quit_cmd_internal (int quiet
)
1032 n
= dialog_switch_num () - 1;
1035 char msg
[BUF_MEDIUM
];
1037 g_snprintf (msg
, sizeof (msg
),
1038 ngettext ("You have %zd opened screen. Quit anyway?",
1039 "You have %zd opened screens. Quit anyway?", n
), n
);
1041 if (query_dialog (_("The Midnight Commander"), msg
, D_NORMAL
, 2, _("&Yes"), _("&No")) != 0)
1045 else if (quiet
|| !confirm_exit
)
1047 else if (query_dialog (_("The Midnight Commander"),
1048 _("Do you really want to quit the Midnight Commander?"),
1049 D_NORMAL
, 2, _("&Yes"), _("&No")) == 0)
1054 #ifdef ENABLE_SUBSHELL
1055 if (!mc_global
.tty
.use_subshell
)
1057 else if ((q
= exit_subshell ()? 1 : 0) != 0)
1067 /* --------------------------------------------------------------------------------------------- */
1072 return quit_cmd_internal (0);
1075 /* --------------------------------------------------------------------------------------------- */
1078 toggle_show_hidden (void)
1080 panels_options
.show_dot_files
= !panels_options
.show_dot_files
;
1081 update_panels (UP_RELOAD
, UP_KEEPSEL
);
1084 /* --------------------------------------------------------------------------------------------- */
1087 * Repaint the contents of the panels without frames. To schedule panel
1088 * for repainting, set panel->dirty to 1. There are many reasons why
1089 * the panels need to be repainted, and this is a costly operation, so
1090 * it's done once per event.
1094 update_dirty_panels (void)
1096 if (get_current_type () == view_listing
&& current_panel
->dirty
)
1097 send_message ((Widget
*) current_panel
, WIDGET_DRAW
, 0);
1099 if (get_other_type () == view_listing
&& other_panel
->dirty
)
1100 send_message ((Widget
*) other_panel
, WIDGET_DRAW
, 0);
1103 /* --------------------------------------------------------------------------------------------- */
1106 midnight_execute_cmd (Widget
* sender
, unsigned long command
)
1108 cb_ret_t res
= MSG_HANDLED
;
1112 /* stop quick search before executing any command */
1113 send_message ((Widget
*) current_panel
, WIDGET_COMMAND
, CK_SearchStop
);
1120 case CK_PanelListingChange
:
1121 change_listing_cmd ();
1129 case CK_ChangeOwnAdvanced
:
1130 chown_advanced_cmd ();
1132 case CK_CompareDirs
:
1133 compare_dirs_cmd ();
1143 case CK_OptionsConfirm
:
1149 case CK_PutCurrentPath
:
1150 put_current_path ();
1152 case CK_PutCurrentLink
:
1153 put_current_link ();
1155 case CK_PutCurrentTagged
:
1156 put_current_tagged ();
1158 case CK_PutOtherPath
:
1161 case CK_PutOtherLink
:
1164 case CK_PutOtherTagged
:
1165 put_other_tagged ();
1171 dialog_switch_list ();
1173 #ifdef USE_DIFF_VIEW
1174 case CK_CompareFiles
:
1178 case CK_OptionsDisplayBits
:
1179 display_bits_box ();
1184 #ifdef USE_INTERNAL_EDIT
1185 case CK_EditForceInternal
:
1186 edit_cmd_force_internal ();
1189 case CK_EditExtensionsFile
:
1192 case CK_EditFileHighlightFile
:
1195 case CK_EditUserMenu
:
1196 edit_mc_menu_cmd ();
1198 case CK_LinkSymbolicEdit
:
1199 edit_symlink_cmd ();
1201 case CK_ExternalPanelize
:
1202 external_panelize ();
1207 case CK_ViewFiltered
:
1208 view_filtered_cmd ();
1213 #ifdef ENABLE_VFS_FISH
1214 case CK_ConnectFish
:
1218 #ifdef ENABLE_VFS_FTP
1223 #ifdef ENABLE_VFS_SFTP
1224 case CK_ConnectSftp
:
1228 #ifdef ENABLE_VFS_SMB
1232 #endif /* ENABLE_VFS_SMB */
1240 /* show the history of command line widget */
1241 send_message (&cmdline
->widget
, WIDGET_COMMAND
, CK_History
);
1244 if (sender
== (Widget
*) the_menubar
)
1245 info_cmd (); /* menu */
1247 info_cmd_no_menu (); /* shortcut or buttonbar */
1249 #ifdef ENABLE_BACKGROUND
1254 case CK_OptionsLayout
:
1261 link_cmd (LINK_HARDLINK
);
1263 case CK_PanelListing
:
1266 #ifdef LISTMODE_EDITOR
1274 case CK_MenuLastSelected
:
1275 menu_last_selected_cmd ();
1280 case CK_OptionsPanel
:
1281 panel_options_box ();
1284 case CK_SelectCodepage
:
1294 case CK_PanelQuickView
:
1295 if (sender
== (Widget
*) the_menubar
)
1296 quick_view_cmd (); /* menu */
1298 quick_cmd_no_menu (); /* shortcut or buttonabr */
1306 case CK_LinkSymbolicRelative
:
1307 link_cmd (LINK_SYMLINK_RELATIVE
);
1320 case CK_SelectInvert
:
1321 select_invert_cmd ();
1333 smart_dirsize_cmd ();
1338 case CK_ExtendedKeyMap
:
1342 mc_event_raise (MCEVENT_GROUP_CORE
, "suspend", NULL
);
1347 case CK_LinkSymbolic
:
1348 link_cmd (LINK_SYMLINK_ABSOLUTE
);
1350 case CK_PanelListingSwitch
:
1351 toggle_listing_cmd ();
1354 toggle_show_hidden ();
1356 case CK_SplitVertHoriz
:
1357 toggle_panels_split ();
1360 panels_split_equal ();
1363 panels_split_more ();
1366 panels_split_less ();
1374 #ifdef ENABLE_VFS_UNDELFS
1383 user_file_menu_cmd ();
1392 /* don't close panels due to SIGINT */
1395 res
= MSG_NOT_HANDLED
;
1401 /* --------------------------------------------------------------------------------------------- */
1404 midnight_callback (Dlg_head
* h
, Widget
* sender
, dlg_msg_t msg
, int parm
, void *data
)
1406 unsigned long command
;
1417 /* We handle the special case of the output lines */
1418 if (mc_global
.tty
.console_flag
!= '\0' && output_lines
)
1419 show_console_contents (output_start_y
,
1420 LINES
- output_lines
- mc_global
.keybar_visible
-
1421 1, LINES
- mc_global
.keybar_visible
- 1);
1426 menubar_arrange (the_menubar
);
1430 /* We only need the first idle event to show user menu after start */
1431 set_idle_proc (h
, 0);
1433 if (boot_current_is_left
)
1434 dlg_select_widget (get_panel_widget (0));
1436 dlg_select_widget (get_panel_widget (1));
1439 midnight_execute_cmd (NULL
, CK_UserMenu
);
1443 if (ctl_x_map_enabled
)
1445 ctl_x_map_enabled
= FALSE
;
1446 command
= keybind_lookup_keymap_command (main_x_map
, parm
);
1447 if (command
!= CK_IgnoreKey
)
1448 return midnight_execute_cmd (NULL
, command
);
1451 /* FIXME: should handle all menu shortcuts before this point */
1452 if (the_menubar
->is_active
)
1453 return MSG_NOT_HANDLED
;
1456 input_free_completions (cmdline
);
1462 for (i
= 0; cmdline
->buffer
[i
] != '\0' &&
1463 (cmdline
->buffer
[i
] == ' ' || cmdline
->buffer
[i
] == '\t'); i
++)
1466 if (cmdline
->buffer
[i
] != '\0')
1468 send_message ((Widget
*) cmdline
, WIDGET_KEY
, parm
);
1472 input_insert (cmdline
, "", FALSE
);
1476 /* Ctrl-Enter and Alt-Enter */
1477 if (((parm
& ~(KEY_M_CTRL
| KEY_M_ALT
)) == '\n') && (parm
& (KEY_M_CTRL
| KEY_M_ALT
)))
1483 /* Ctrl-Shift-Enter */
1484 if (parm
== (KEY_M_CTRL
| KEY_M_SHIFT
| '\n'))
1486 put_current_path ();
1491 if ((!mc_global
.tty
.alternate_plus_minus
1492 || !(mc_global
.tty
.console_flag
!= '\0' || mc_global
.tty
.xterm_flag
)) && !quote
1493 && !current_panel
->searching
)
1495 if (!only_leading_plus_minus
)
1497 /* Special treatement, since the input line will eat them */
1504 if (parm
== '\\' || parm
== '-')
1512 select_invert_cmd ();
1516 else if (!command_prompt
|| !cmdline
->buffer
[0])
1518 /* Special treatement '+', '-', '\', '*' only when this is
1519 * first char on input line
1528 if (parm
== '\\' || parm
== '-')
1536 select_invert_cmd ();
1541 return MSG_NOT_HANDLED
;
1543 case DLG_HOTKEY_HANDLED
:
1544 if ((get_current_type () == view_listing
) && current_panel
->searching
)
1546 current_panel
->dirty
= 1; /* FIXME: unneeded? */
1547 send_message ((Widget
*) current_panel
, WIDGET_COMMAND
, CK_SearchStop
);
1551 case DLG_UNHANDLED_KEY
:
1553 cb_ret_t v
= MSG_NOT_HANDLED
;
1555 if (ctl_x_map_enabled
)
1557 ctl_x_map_enabled
= FALSE
;
1558 command
= keybind_lookup_keymap_command (main_x_map
, parm
);
1561 command
= keybind_lookup_keymap_command (main_map
, parm
);
1563 if (command
!= CK_IgnoreKey
)
1564 v
= midnight_execute_cmd (NULL
, command
);
1566 if (v
== MSG_NOT_HANDLED
&& command_prompt
)
1567 v
= send_message ((Widget
*) cmdline
, WIDGET_KEY
, parm
);
1573 if (!the_menubar
->is_active
)
1574 update_dirty_panels ();
1580 return midnight_execute_cmd (NULL
, parm
);
1581 /* message from menu */
1582 if (sender
== (Widget
*) the_menubar
)
1583 return midnight_execute_cmd (sender
, parm
);
1584 /* message from buttonbar */
1585 if (sender
== (Widget
*) the_bar
)
1588 return send_message ((Widget
*) data
, WIDGET_COMMAND
, parm
);
1589 return midnight_execute_cmd (sender
, parm
);
1591 return MSG_NOT_HANDLED
;
1598 return default_dlg_callback (h
, sender
, msg
, parm
, data
);
1602 /* --------------------------------------------------------------------------------------------- */
1605 midnight_event (Gpm_Event
* event
, void *data
)
1607 Dlg_head
*h
= (Dlg_head
*) data
;
1608 int ret
= MOU_UNHANDLED
;
1610 if (event
->y
== h
->y
+ 1)
1613 if (menubar_visible
|| the_menubar
->is_active
)
1614 ret
= ((Widget
*) the_menubar
)->mouse (event
, the_menubar
);
1619 w
= get_panel_widget (0);
1620 if (w
->mouse
!= NULL
)
1621 ret
= w
->mouse (event
, w
);
1623 if (ret
== MOU_UNHANDLED
)
1625 w
= get_panel_widget (1);
1626 if (w
->mouse
!= NULL
)
1627 ret
= w
->mouse (event
, w
);
1630 if (ret
== MOU_UNHANDLED
)
1631 ret
= ((Widget
*) the_menubar
)->mouse (event
, the_menubar
);
1638 /* --------------------------------------------------------------------------------------------- */
1639 /*** public functions ****************************************************************************/
1640 /* --------------------------------------------------------------------------------------------- */
1645 menu_set_name (left_menu
, panels_layout
.horizontal_split
? _("&Above") : _("&Left"));
1646 menu_set_name (right_menu
, panels_layout
.horizontal_split
? _("&Below") : _("&Right"));
1647 menubar_arrange (the_menubar
);
1648 menubar_set_visible (the_menubar
, menubar_visible
);
1651 /* --------------------------------------------------------------------------------------------- */
1654 midnight_set_buttonbar (WButtonBar
* b
)
1656 buttonbar_set_label (b
, 1, Q_ ("ButtonBar|Help"), main_map
, NULL
);
1657 buttonbar_set_label (b
, 2, Q_ ("ButtonBar|Menu"), main_map
, NULL
);
1658 buttonbar_set_label (b
, 3, Q_ ("ButtonBar|View"), main_map
, NULL
);
1659 buttonbar_set_label (b
, 4, Q_ ("ButtonBar|Edit"), main_map
, NULL
);
1660 buttonbar_set_label (b
, 5, Q_ ("ButtonBar|Copy"), main_map
, NULL
);
1661 buttonbar_set_label (b
, 6, Q_ ("ButtonBar|RenMov"), main_map
, NULL
);
1662 buttonbar_set_label (b
, 7, Q_ ("ButtonBar|Mkdir"), main_map
, NULL
);
1663 buttonbar_set_label (b
, 8, Q_ ("ButtonBar|Delete"), main_map
, NULL
);
1664 buttonbar_set_label (b
, 9, Q_ ("ButtonBar|PullDn"), main_map
, NULL
);
1665 buttonbar_set_label (b
, 10, Q_ ("ButtonBar|Quit"), main_map
, NULL
);
1668 /* --------------------------------------------------------------------------------------------- */
1670 * Load new hint and display it.
1671 * IF force is not 0, ignore the timeout.
1675 load_hint (gboolean force
)
1679 if (the_hint
->widget
.owner
== NULL
)
1682 if (!mc_global
.message_visible
)
1684 label_set_text (the_hint
, NULL
);
1688 hint
= get_random_hint (force
);
1698 char text
[BUF_SMALL
];
1700 g_snprintf (text
, sizeof (text
), _("GNU Midnight Commander %s\n"), VERSION
);
1705 /* --------------------------------------------------------------------------------------------- */
1710 input_free_completions (cmdline
);
1711 dlg_one_down (midnight_dlg
);
1714 /* --------------------------------------------------------------------------------------------- */
1716 /** Save current stat of directories to avoid reloading the panels
1717 * when no modifications have taken place
1720 save_cwds_stat (void)
1722 if (panels_options
.fast_reload
)
1724 mc_stat (current_panel
->cwd_vpath
, &(current_panel
->dir_stat
));
1725 if (get_other_type () == view_listing
)
1726 mc_stat (other_panel
->cwd_vpath
, &(other_panel
->dir_stat
));
1730 /* --------------------------------------------------------------------------------------------- */
1733 quiet_quit_cmd (void)
1735 print_last_revert
= TRUE
;
1736 return quit_cmd_internal (1);
1739 /* --------------------------------------------------------------------------------------------- */
1741 /** Run the main dialog that occupies the whole screen */
1747 dlg_colors_t midnight_colors
;
1749 midnight_colors
[DLG_COLOR_NORMAL
] = mc_skin_color_get ("dialog", "_default_");
1750 midnight_colors
[DLG_COLOR_FOCUS
] = mc_skin_color_get ("dialog", "focus");
1751 midnight_colors
[DLG_COLOR_HOT_NORMAL
] = mc_skin_color_get ("dialog", "hotnormal");
1752 midnight_colors
[DLG_COLOR_HOT_FOCUS
] = mc_skin_color_get ("dialog", "hotfocus");
1753 midnight_colors
[DLG_COLOR_TITLE
] = mc_skin_color_get ("dialog", "title");
1755 #ifdef USE_INTERNAL_EDIT
1759 midnight_dlg
= create_dlg (FALSE
, 0, 0, LINES
, COLS
, midnight_colors
, midnight_callback
,
1760 midnight_event
, "[main]", NULL
, DLG_WANT_IDLE
);
1762 /* Check if we were invoked as an editor or file viewer */
1763 if (mc_global
.mc_run_mode
!= MC_RUN_FULL
)
1766 ret
= mc_maybe_editor_or_viewer ();
1771 mc_filehighlight
= mc_fhl_new (TRUE
);
1772 create_panels_and_run_mc ();
1773 mc_fhl_free (&mc_filehighlight
);
1777 /* destroy_dlg destroys even current_panel->cwd_vpath, so we have to save a copy :) */
1778 if (mc_args__last_wd_file
!= NULL
&& vfs_current_is_local ())
1779 last_wd_string
= vfs_path_to_str (current_panel
->cwd_vpath
);
1781 /* don't handle VFS timestamps for dirs opened in panels */
1782 mc_event_destroy (MCEVENT_GROUP_CORE
, "vfs_timestamp");
1784 clean_dir (&panelized_panel
.list
, panelized_panel
.count
);
1788 mc_global
.midnight_shutdown
= TRUE
;
1789 dialog_switch_shutdown ();
1791 destroy_dlg (midnight_dlg
);
1792 current_panel
= NULL
;
1794 #ifdef USE_INTERNAL_EDIT
1798 if ((quit
& SUBSHELL_EXIT
) == 0)
1804 /* --------------------------------------------------------------------------------------------- */