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>
40 #include <pwd.h> /* for username in xterm title */
42 #include "lib/global.h"
44 #include "lib/tty/tty.h"
45 #include "lib/tty/key.h" /* KEY_M_* masks */
49 #include "lib/vfs/vfs.h"
52 #include "src/subshell.h"
53 #include "src/setup.h" /* variables */
54 #include "src/learn.h" /* learn_keys() */
55 #include "src/keybind-defaults.h"
56 #include "lib/keybind.h"
57 #include "lib/event.h"
59 #include "option.h" /* configure_box() */
61 #include "boxes.h" /* sort_box(), tree_box() */
63 #include "cmd.h" /* commands */
66 #include "command.h" /* cmdline */
72 #ifdef USE_INTERNAL_EDIT
73 #include "src/editor/edit.h"
77 #include "src/diffviewer/ydiff.h"
80 #include "src/consaver/cons.saver.h" /* show_console_contents */
84 /* TODO: merge content of layout.c here */
85 extern int ok_to_refresh
;
87 /*** global variables ****************************************************************************/
89 /* When the modes are active, left_panel, right_panel and tree_panel */
90 /* point to a proper data structure. You should check with the functions */
91 /* get_current_type and get_other_type the types of the panels before using */
92 /* this pointer variables */
94 /* The structures for the panels */
95 WPanel
*left_panel
= NULL
;
96 WPanel
*right_panel
= NULL
;
97 /* Pointer to the selected and unselected panel */
98 WPanel
*current_panel
= NULL
;
101 WMenuBar
*the_menubar
= NULL
;
102 /* The widget where we draw the prompt */
109 /*** file scope macro definitions ****************************************************************/
113 * Don't restrict the output on the screen manager level,
114 * the translation tables take care of it.
116 #endif /* !HAVE_CHARSET */
118 /*** file scope type declarations ****************************************************************/
120 /*** file scope variables ************************************************************************/
122 static Menu
*left_menu
, *right_menu
;
124 static gboolean ctl_x_map_enabled
= FALSE
;
126 /*** file scope functions ************************************************************************/
128 /** Stop MC main dialog and the current dialog if it exists.
129 * Needed to provide fast exit from MC viewer or editor on shell exit */
133 midnight_dlg
->state
= DLG_CLOSED
;
135 if ((top_dlg
!= NULL
) && (top_dlg
->data
!= NULL
))
136 ((Dlg_head
*) top_dlg
->data
)->state
= DLG_CLOSED
;
139 /* --------------------------------------------------------------------------------------------- */
146 sel_dir
= tree_box (selection (current_panel
)->fname
);
149 do_cd (sel_dir
, cd_exact
);
154 /* --------------------------------------------------------------------------------------------- */
156 #ifdef LISTMODE_EDITOR
162 if (get_current_type () != view_listing
)
165 newmode
= listmode_edit (current_panel
->user_format
);
169 g_free (current_panel
->user_format
);
170 current_panel
->list_type
= list_user
;
171 current_panel
->user_format
= newmode
;
172 set_panel_formats (current_panel
);
176 #endif /* LISTMODE_EDITOR */
178 /* --------------------------------------------------------------------------------------------- */
181 create_panel_menu (void)
183 GList
*entries
= NULL
;
185 entries
= g_list_append (entries
, menu_entry_create (_("File listin&g"), CK_PanelListing
));
186 entries
= g_list_append (entries
, menu_entry_create (_("&Quick view"), CK_PanelQuickView
));
187 entries
= g_list_append (entries
, menu_entry_create (_("&Info"), CK_PanelInfo
));
188 entries
= g_list_append (entries
, menu_entry_create (_("&Tree"), CK_PanelTree
));
189 entries
= g_list_append (entries
, menu_separator_create ());
191 g_list_append (entries
, menu_entry_create (_("&Listing mode..."), CK_PanelListingChange
));
192 entries
= g_list_append (entries
, menu_entry_create (_("&Sort order..."), CK_Sort
));
193 entries
= g_list_append (entries
, menu_entry_create (_("&Filter..."), CK_Filter
));
195 entries
= g_list_append (entries
, menu_entry_create (_("&Encoding..."), CK_SelectCodepage
));
197 #ifdef ENABLE_VFS_NET
198 entries
= g_list_append (entries
, menu_separator_create ());
199 #ifdef ENABLE_VFS_FTP
200 entries
= g_list_append (entries
, menu_entry_create (_("FT&P link..."), CK_ConnectFtp
));
202 #ifdef ENABLE_VFS_FISH
203 entries
= g_list_append (entries
, menu_entry_create (_("S&hell link..."), CK_ConnectFish
));
205 #ifdef ENABLE_VFS_SMB
206 entries
= g_list_append (entries
, menu_entry_create (_("SM&B link..."), CK_ConnectSmb
));
208 #endif /* ENABLE_VFS_NET */
209 entries
= g_list_append (entries
, menu_separator_create ());
210 entries
= g_list_append (entries
, menu_entry_create (_("&Rescan"), CK_Reread
));
215 /* --------------------------------------------------------------------------------------------- */
218 create_file_menu (void)
220 GList
*entries
= NULL
;
222 entries
= g_list_append (entries
, menu_entry_create (_("&View"), CK_View
));
223 entries
= g_list_append (entries
, menu_entry_create (_("Vie&w file..."), CK_ViewFile
));
224 entries
= g_list_append (entries
, menu_entry_create (_("&Filtered view"), CK_ViewFiltered
));
225 entries
= g_list_append (entries
, menu_entry_create (_("&Edit"), CK_Edit
));
226 entries
= g_list_append (entries
, menu_entry_create (_("&Copy"), CK_Copy
));
227 entries
= g_list_append (entries
, menu_entry_create (_("C&hmod"), CK_ChangeMode
));
228 entries
= g_list_append (entries
, menu_entry_create (_("&Link"), CK_Link
));
229 entries
= g_list_append (entries
, menu_entry_create (_("&Symlink"), CK_LinkSymbolic
));
231 g_list_append (entries
,
232 menu_entry_create (_("Relative symlin&k"), CK_LinkSymbolicRelative
));
233 entries
= g_list_append (entries
, menu_entry_create (_("Edit s&ymlink"), CK_LinkSymbolicEdit
));
234 entries
= g_list_append (entries
, menu_entry_create (_("Ch&own"), CK_ChangeOwn
));
236 g_list_append (entries
, menu_entry_create (_("&Advanced chown"), CK_ChangeOwnAdvanced
));
237 entries
= g_list_append (entries
, menu_entry_create (_("&Rename/Move"), CK_Move
));
238 entries
= g_list_append (entries
, menu_entry_create (_("&Mkdir"), CK_MakeDir
));
239 entries
= g_list_append (entries
, menu_entry_create (_("&Delete"), CK_Delete
));
240 entries
= g_list_append (entries
, menu_entry_create (_("&Quick cd"), CK_CdQuick
));
241 entries
= g_list_append (entries
, menu_separator_create ());
242 entries
= g_list_append (entries
, menu_entry_create (_("Select &group"), CK_Select
));
243 entries
= g_list_append (entries
, menu_entry_create (_("U&nselect group"), CK_Unselect
));
244 entries
= g_list_append (entries
, menu_entry_create (_("&Invert selection"), CK_SelectInvert
));
245 entries
= g_list_append (entries
, menu_separator_create ());
246 entries
= g_list_append (entries
, menu_entry_create (_("E&xit"), CK_Quit
));
251 /* --------------------------------------------------------------------------------------------- */
254 create_command_menu (void)
256 /* I know, I'm lazy, but the tree widget when it's not running
257 * as a panel still has some problems, I have not yet finished
258 * the WTree widget port, sorry.
260 GList
*entries
= NULL
;
262 entries
= g_list_append (entries
, menu_entry_create (_("&User menu"), CK_UserMenu
));
263 entries
= g_list_append (entries
, menu_entry_create (_("&Directory tree"), CK_Tree
));
264 entries
= g_list_append (entries
, menu_entry_create (_("&Find file"), CK_Find
));
265 entries
= g_list_append (entries
, menu_entry_create (_("S&wap panels"), CK_Swap
));
266 entries
= g_list_append (entries
, menu_entry_create (_("Switch &panels on/off"), CK_Shell
));
268 g_list_append (entries
, menu_entry_create (_("&Compare directories"), CK_CompareDirs
));
270 entries
= g_list_append (entries
, menu_entry_create (_("C&ompare files"), CK_CompareFiles
));
273 g_list_append (entries
, menu_entry_create (_("E&xternal panelize"), CK_ExternalPanelize
));
274 entries
= g_list_append (entries
, menu_entry_create (_("Show directory s&izes"), CK_DirSize
));
275 entries
= g_list_append (entries
, menu_separator_create ());
276 entries
= g_list_append (entries
, menu_entry_create (_("Command &history"), CK_History
));
277 entries
= g_list_append (entries
, menu_entry_create (_("Di&rectory hotlist"), CK_HotList
));
279 entries
= g_list_append (entries
, menu_entry_create (_("&Active VFS list"), CK_VfsList
));
281 #ifdef WITH_BACKGROUND
282 entries
= g_list_append (entries
, menu_entry_create (_("&Background jobs"), CK_Jobs
));
284 entries
= g_list_append (entries
, menu_entry_create (_("Screen lis&t"), CK_ScreenList
));
285 entries
= g_list_append (entries
, menu_separator_create ());
286 #ifdef ENABLE_VFS_UNDELFS
288 g_list_append (entries
,
289 menu_entry_create (_("&Undelete files (ext2fs only)"), CK_Undelete
));
291 #ifdef LISTMODE_EDITOR
292 entries
= g_list_append (entries
, menu_entry_create (_("&Listing format edit"), CK_ListMode
));
294 #if defined (ENABLE_VFS_UNDELFS) || defined (LISTMODE_EDITOR)
295 entries
= g_list_append (entries
, menu_separator_create ());
298 g_list_append (entries
,
299 menu_entry_create (_("Edit &extension file"), CK_EditExtensionsFile
));
300 entries
= g_list_append (entries
, menu_entry_create (_("Edit &menu file"), CK_EditUserMenu
));
302 g_list_append (entries
,
303 menu_entry_create (_("Edit hi&ghlighting group file"),
304 CK_EditFileHighlightFile
));
309 /* --------------------------------------------------------------------------------------------- */
312 create_options_menu (void)
314 GList
*entries
= NULL
;
316 entries
= g_list_append (entries
, menu_entry_create (_("&Configuration..."), CK_Options
));
317 entries
= g_list_append (entries
, menu_entry_create (_("&Layout..."), CK_OptionsLayout
));
318 entries
= g_list_append (entries
, menu_entry_create (_("&Panel options..."), CK_OptionsPanel
));
319 entries
= g_list_append (entries
, menu_entry_create (_("C&onfirmation..."), CK_OptionsConfirm
));
321 g_list_append (entries
, menu_entry_create (_("&Display bits..."), CK_OptionsDisplayBits
));
322 entries
= g_list_append (entries
, menu_entry_create (_("Learn &keys..."), CK_LearnKeys
));
324 entries
= g_list_append (entries
, menu_entry_create (_("&Virtual FS..."), CK_OptionsVfs
));
326 entries
= g_list_append (entries
, menu_separator_create ());
327 entries
= g_list_append (entries
, menu_entry_create (_("&Save setup"), CK_SaveSetup
));
332 /* --------------------------------------------------------------------------------------------- */
337 left_menu
= create_menu ("", create_panel_menu (), "[Left and Right Menus]");
338 menubar_add_menu (the_menubar
, left_menu
);
339 menubar_add_menu (the_menubar
, create_menu (_("&File"), create_file_menu (), "[File Menu]"));
340 menubar_add_menu (the_menubar
,
341 create_menu (_("&Command"), create_command_menu (), "[Command Menu]"));
342 menubar_add_menu (the_menubar
,
343 create_menu (_("&Options"), create_options_menu (), "[Options Menu]"));
344 right_menu
= create_menu ("", create_panel_menu (), "[Left and Right Menus]");
345 menubar_add_menu (the_menubar
, right_menu
);
349 /* --------------------------------------------------------------------------------------------- */
352 menu_last_selected_cmd (void)
354 the_menubar
->is_active
= TRUE
;
355 the_menubar
->is_dropped
= (drop_menus
!= 0);
356 the_menubar
->previous_widget
= dlg_get_current_widget_id (midnight_dlg
);
357 dlg_select_widget (the_menubar
);
360 /* --------------------------------------------------------------------------------------------- */
365 if (the_menubar
->is_active
)
368 if ((get_current_index () == 0) == (current_panel
->active
!= 0))
369 the_menubar
->selected
= 0;
371 the_menubar
->selected
= g_list_length (the_menubar
->menu
) - 1;
372 menu_last_selected_cmd ();
375 /* --------------------------------------------------------------------------------------------- */
381 const panel_field_t
*sort_order
;
383 if (!SELECTED_IS_PANEL
)
387 sort_order
= sort_box (&p
->sort_info
);
388 panel_set_sort_order (p
, sort_order
);
391 /* --------------------------------------------------------------------------------------------- */
394 midnight_get_shortcut (unsigned long command
)
397 const char *shortcut
= NULL
;
399 shortcut
= keybind_lookup_keymap_shortcut (main_map
, command
);
400 if (shortcut
!= NULL
)
401 return g_strdup (shortcut
);
403 shortcut
= keybind_lookup_keymap_shortcut (panel_map
, command
);
404 if (shortcut
!= NULL
)
405 return g_strdup (shortcut
);
407 ext_map
= keybind_lookup_keymap_shortcut (main_map
, CK_ExtendedKeyMap
);
409 shortcut
= keybind_lookup_keymap_shortcut (main_x_map
, command
);
410 if (shortcut
!= NULL
)
411 return g_strdup_printf ("%s %s", ext_map
, shortcut
);
416 /* --------------------------------------------------------------------------------------------- */
419 midnight_get_title (const Dlg_head
* h
, size_t len
)
421 /* TODO: share code with update_xterm_title_path() */
426 struct passwd
*pw
= NULL
;
432 path
= strip_home_and_password (current_panel
->cwd
);
433 res
= gethostname (host
, sizeof (host
));
437 host
[sizeof (host
) - 1] = '\0';
439 pw
= getpwuid (getuid ());
441 login
= g_strdup_printf ("%s@%s", pw
->pw_name
, host
);
443 login
= g_strdup (host
);
445 p
= g_strdup_printf ("%s [%s]:%s", _("Panels:"), login
, path
);
446 path
= str_trunc (p
, len
- 4);
450 return g_strdup (path
);
453 /* --------------------------------------------------------------------------------------------- */
456 toggle_panels_split (void)
458 horizontal_split
= !horizontal_split
;
463 /* --------------------------------------------------------------------------------------------- */
469 check_panel_timestamp (const WPanel
* panel
, panel_view_mode_t mode
, struct vfs_class
*vclass
,
472 if (mode
== view_listing
)
475 vfs_path_element_t
*path_element
;
477 vpath
= vfs_path_from_str (panel
->cwd
);
478 path_element
= vfs_path_get_by_index (vpath
, -1);
480 if (path_element
->class != vclass
)
482 vfs_path_free (vpath
);
486 if (vfs_getid (vpath
) != id
)
488 vfs_path_free (vpath
);
491 vfs_path_free (vpath
);
496 /* --------------------------------------------------------------------------------------------- */
500 check_current_panel_timestamp (const gchar
* event_group_name
, const gchar
* event_name
,
501 gpointer init_data
, gpointer data
)
503 ev_vfs_stamp_create_t
*event_data
= (ev_vfs_stamp_create_t
*) data
;
505 (void) event_group_name
;
510 check_panel_timestamp (current_panel
, get_current_type (), event_data
->vclass
,
512 return !event_data
->ret
;
515 /* --------------------------------------------------------------------------------------------- */
519 check_other_panel_timestamp (const gchar
* event_group_name
, const gchar
* event_name
,
520 gpointer init_data
, gpointer data
)
522 ev_vfs_stamp_create_t
*event_data
= (ev_vfs_stamp_create_t
*) data
;
524 (void) event_group_name
;
529 check_panel_timestamp (other_panel
, get_other_type (), event_data
->vclass
, event_data
->id
);
530 return !event_data
->ret
;
532 #endif /* ENABLE_VFS */
534 /* --------------------------------------------------------------------------------------------- */
538 print_vfs_message (const gchar
* event_group_name
, const gchar
* event_name
,
539 gpointer init_data
, gpointer data
)
542 ev_vfs_print_message_t
*event_data
= (ev_vfs_print_message_t
*) data
;
544 (void) event_group_name
;
548 g_vsnprintf (str
, sizeof (str
), event_data
->msg
, event_data
->ap
);
550 if (mc_global
.widget
.midnight_shutdown
)
553 if (!mc_global
.message_visible
|| !the_hint
|| !the_hint
->widget
.owner
)
557 if (!nice_rotating_dash
|| (ok_to_refresh
<= 0))
560 /* Preserve current cursor position */
561 tty_getyx (&row
, &col
);
564 tty_setcolor (NORMAL_COLOR
);
565 tty_print_string (str_fit_to_term (str
, COLS
- 1, J_LEFT
));
567 /* Restore cursor position */
568 tty_gotoyx (row
, col
);
573 if (mc_global
.message_visible
)
579 /* --------------------------------------------------------------------------------------------- */
586 panel_view_mode_t current_mode
, other_mode
;
587 char original_dir
[BUF_1K
] = "\0";
589 if (boot_current_is_left
)
593 current_mode
= startup_left_mode
;
594 other_mode
= startup_right_mode
;
600 current_mode
= startup_right_mode
;
601 other_mode
= startup_left_mode
;
603 /* Creates the left panel */
604 if (mc_run_param0
!= NULL
)
606 if (mc_run_param1
!= NULL
)
608 /* Ok, user has specified two dirs, save the original one,
609 * since we may not be able to chdir to the proper
610 * second directory later
612 mc_get_current_wd (original_dir
, sizeof (original_dir
) - 2);
614 mc_chdir (mc_run_param0
);
616 set_display_type (current_index
, current_mode
);
618 /* The other panel */
619 if (mc_run_param1
!= NULL
)
621 if (original_dir
[0] != '\0')
622 mc_chdir (original_dir
);
623 mc_chdir (mc_run_param1
);
625 set_display_type (other_index
, other_mode
);
627 if (startup_left_mode
== view_listing
)
628 current_panel
= left_panel
;
629 else if (right_panel
!= NULL
)
630 current_panel
= right_panel
;
632 current_panel
= left_panel
;
635 mc_event_add (MCEVENT_GROUP_CORE
, "vfs_timestamp", check_other_panel_timestamp
, NULL
, NULL
);
636 mc_event_add (MCEVENT_GROUP_CORE
, "vfs_timestamp", check_current_panel_timestamp
, NULL
, NULL
);
637 #endif /* ENABLE_VFS */
639 mc_event_add (MCEVENT_GROUP_CORE
, "vfs_print_message", print_vfs_message
, NULL
, NULL
);
641 /* Create the nice widgets */
642 cmdline
= command_new (0, 0, 0);
643 the_prompt
= label_new (0, 0, mc_prompt
);
644 the_prompt
->transparent
= 1;
645 the_bar
= buttonbar_new (mc_global
.keybar_visible
);
647 the_hint
= label_new (0, 0, 0);
648 the_hint
->transparent
= 1;
649 the_hint
->auto_adjust_cols
= 0;
650 the_hint
->widget
.cols
= COLS
;
652 the_menubar
= menubar_new (0, 0, COLS
, NULL
);
655 /* --------------------------------------------------------------------------------------------- */
658 put_current_path (void)
664 cwd_path
= remove_encoding_from_path (current_panel
->cwd
);
665 command_insert (cmdline
, cwd_path
, FALSE
);
667 if (cwd_path
[strlen (cwd_path
) - 1] != PATH_SEP
)
668 command_insert (cmdline
, PATH_SEP_STR
, FALSE
);
672 /* --------------------------------------------------------------------------------------------- */
675 put_other_path (void)
679 if (get_other_type () != view_listing
)
685 cwd_path
= remove_encoding_from_path (other_panel
->cwd
);
686 command_insert (cmdline
, cwd_path
, FALSE
);
688 if (cwd_path
[strlen (cwd_path
) - 1] != PATH_SEP
)
689 command_insert (cmdline
, PATH_SEP_STR
, FALSE
);
693 /* --------------------------------------------------------------------------------------------- */
696 put_link (WPanel
* panel
)
700 if (S_ISLNK (selection (panel
)->st
.st_mode
))
702 char buffer
[MC_MAXPATHLEN
];
706 p
= concat_dir_and_file (panel
->cwd
, selection (panel
)->fname
);
707 i
= mc_readlink (p
, buffer
, MC_MAXPATHLEN
- 1);
712 command_insert (cmdline
, buffer
, TRUE
);
717 /* --------------------------------------------------------------------------------------------- */
720 put_current_link (void)
722 put_link (current_panel
);
725 /* --------------------------------------------------------------------------------------------- */
728 put_other_link (void)
730 if (get_other_type () == view_listing
)
731 put_link (other_panel
);
734 /* --------------------------------------------------------------------------------------------- */
736 /** Insert the selected file name into the input line */
744 if (get_current_type () == view_tree
)
746 WTree
*tree
= (WTree
*) get_panel_widget (get_current_index ());
747 tmp
= tree_selected_name (tree
);
750 tmp
= selection (current_panel
)->fname
;
752 command_insert (cmdline
, tmp
, TRUE
);
755 /* --------------------------------------------------------------------------------------------- */
758 put_tagged (WPanel
* panel
)
764 input_disable_update (cmdline
);
767 for (i
= 0; i
< panel
->count
; i
++)
769 if (panel
->dir
.list
[i
].f
.marked
)
770 command_insert (cmdline
, panel
->dir
.list
[i
].fname
, TRUE
);
775 command_insert (cmdline
, panel
->dir
.list
[panel
->selected
].fname
, TRUE
);
777 input_enable_update (cmdline
);
780 /* --------------------------------------------------------------------------------------------- */
783 put_current_tagged (void)
785 put_tagged (current_panel
);
788 /* --------------------------------------------------------------------------------------------- */
791 put_other_tagged (void)
793 if (get_other_type () == view_listing
)
794 put_tagged (other_panel
);
797 /* --------------------------------------------------------------------------------------------- */
802 ctl_x_map_enabled
= TRUE
;
805 /* --------------------------------------------------------------------------------------------- */
812 tty_display_8bit (TRUE
);
814 tty_display_8bit (full_eight_bits
!= 0);
815 #endif /* HAVE_CHARSET */
819 tty_display_8bit (TRUE
);
821 tty_display_8bit (eight_bit_clean
!= 0);
822 #endif /* HAVE_CHARSET */
826 #ifdef HAVE_SUBSHELL_SUPPORT
827 if (mc_global
.tty
.use_subshell
)
828 add_select_channel (mc_global
.tty
.subshell_pty
, load_prompt
, 0);
829 #endif /* !HAVE_SUBSHELL_SUPPORT */
831 if ((tty_baudrate () < 9600) || tty_is_slow ())
835 /* --------------------------------------------------------------------------------------------- */
838 setup_dummy_mc (void)
840 char d
[MC_MAXPATHLEN
];
843 mc_get_current_wd (d
, MC_MAXPATHLEN
);
848 /* --------------------------------------------------------------------------------------------- */
855 * We sync the profiles since the hotlist may have changed, while
856 * we only change the setup data if we have the auto save feature set
860 save_setup (auto_save_setup
, panels_options
.auto_save_setup
);
862 curr_dir
= vfs_get_current_dir ();
863 vfs_stamp_path (curr_dir
);
866 if ((current_panel
!= NULL
) && (get_current_type () == view_listing
))
867 vfs_stamp_path (current_panel
->cwd
);
869 if ((other_panel
!= NULL
) && (get_other_type () == view_listing
))
870 vfs_stamp_path (other_panel
->cwd
);
873 /* --------------------------------------------------------------------------------------------- */
876 create_panels_and_run_mc (void)
878 midnight_dlg
->get_shortcut
= midnight_get_shortcut
;
879 midnight_dlg
->get_title
= midnight_get_title
;
883 add_widget (midnight_dlg
, the_menubar
);
886 add_widget (midnight_dlg
, get_panel_widget (0));
887 add_widget (midnight_dlg
, get_panel_widget (1));
889 add_widget (midnight_dlg
, the_hint
);
890 add_widget (midnight_dlg
, cmdline
);
891 add_widget (midnight_dlg
, the_prompt
);
893 add_widget (midnight_dlg
, the_bar
);
894 midnight_set_buttonbar (the_bar
);
896 /* Run the Midnight Commander if no file was specified in the command line */
897 run_dlg (midnight_dlg
);
900 /* --------------------------------------------------------------------------------------------- */
902 /** result must be free'd (I think this should go in util.c) */
904 prepend_cwd_on_local (const char *filename
)
910 vpath
= vfs_path_from_str (filename
);
911 if (!vfs_file_is_local (vpath
) || g_path_is_absolute (filename
))
913 vfs_path_free (vpath
);
914 return g_strdup (filename
);
916 vfs_path_free (vpath
);
918 d
= g_malloc (MC_MAXPATHLEN
+ strlen (filename
) + 2);
919 mc_get_current_wd (d
, MC_MAXPATHLEN
);
922 strcpy (d
+ l
, filename
);
923 canonicalize_pathname (d
);
927 /* --------------------------------------------------------------------------------------------- */
929 /** Invoke the internal view/edit routine with:
930 * the default processing and forcing the internal viewer/editor
933 mc_maybe_editor_or_viewer (void)
935 switch (mc_global
.mc_run_mode
)
937 #ifdef USE_INTERNAL_EDIT
939 edit_file (mc_run_param0
, mc_args__edit_start_line
);
941 #endif /* USE_INTERNAL_EDIT */
945 path
= prepend_cwd_on_local (mc_run_param0
);
946 view_file (path
, 0, 1);
951 case MC_RUN_DIFFVIEWER
:
952 diff_view (mc_run_param0
, mc_run_param1
, mc_run_param0
, mc_run_param1
);
954 #endif /* USE_DIFF_VIEW */
960 /* --------------------------------------------------------------------------------------------- */
963 quit_cmd_internal (int quiet
)
968 n
= dialog_switch_num () - 1;
971 char msg
[BUF_MEDIUM
];
973 g_snprintf (msg
, sizeof (msg
),
974 ngettext ("You have %zd opened screen. Quit anyway?",
975 "You have %zd opened screens. Quit anyway?", n
), n
);
977 if (query_dialog (_("The Midnight Commander"), msg
, D_NORMAL
, 2, _("&Yes"), _("&No")) != 0)
981 else if (quiet
|| !confirm_exit
)
983 else if (query_dialog (_("The Midnight Commander"),
984 _("Do you really want to quit the Midnight Commander?"),
985 D_NORMAL
, 2, _("&Yes"), _("&No")) == 0)
990 #ifdef HAVE_SUBSHELL_SUPPORT
991 if (!mc_global
.tty
.use_subshell
)
993 else if ((q
= exit_subshell ()))
1003 /* --------------------------------------------------------------------------------------------- */
1008 return quit_cmd_internal (0);
1011 /* --------------------------------------------------------------------------------------------- */
1014 toggle_show_hidden (void)
1016 panels_options
.show_dot_files
= !panels_options
.show_dot_files
;
1017 update_panels (UP_RELOAD
, UP_KEEPSEL
);
1020 /* --------------------------------------------------------------------------------------------- */
1023 * Repaint the contents of the panels without frames. To schedule panel
1024 * for repainting, set panel->dirty to 1. There are many reasons why
1025 * the panels need to be repainted, and this is a costly operation, so
1026 * it's done once per event.
1030 update_dirty_panels (void)
1032 if (get_current_type () == view_listing
&& current_panel
->dirty
)
1033 send_message ((Widget
*) current_panel
, WIDGET_DRAW
, 0);
1035 if (get_other_type () == view_listing
&& other_panel
->dirty
)
1036 send_message ((Widget
*) other_panel
, WIDGET_DRAW
, 0);
1039 /* --------------------------------------------------------------------------------------------- */
1042 midnight_execute_cmd (Widget
* sender
, unsigned long command
)
1044 cb_ret_t res
= MSG_HANDLED
;
1048 /* stop quick search before executing any command */
1049 send_message ((Widget
*) current_panel
, WIDGET_COMMAND
, CK_SearchStop
);
1056 case CK_PanelListingChange
:
1057 change_listing_cmd ();
1065 case CK_ChangeOwnAdvanced
:
1066 chown_advanced_cmd ();
1068 case CK_CompareDirs
:
1069 compare_dirs_cmd ();
1079 case CK_OptionsConfirm
:
1085 case CK_PutCurrentPath
:
1086 put_current_path ();
1088 case CK_PutCurrentLink
:
1089 put_current_link ();
1091 case CK_PutCurrentTagged
:
1092 put_current_tagged ();
1094 case CK_PutOtherPath
:
1097 case CK_PutOtherLink
:
1100 case CK_PutOtherTagged
:
1101 put_other_tagged ();
1107 dialog_switch_list ();
1109 #ifdef USE_DIFF_VIEW
1110 case CK_CompareFiles
:
1114 case CK_OptionsDisplayBits
:
1115 display_bits_box ();
1120 #ifdef USE_INTERNAL_EDIT
1121 case CK_EditForceInternal
:
1122 edit_cmd_force_internal ();
1125 case CK_EditExtensionsFile
:
1128 case CK_EditFileHighlightFile
:
1131 case CK_EditUserMenu
:
1132 edit_mc_menu_cmd ();
1134 case CK_LinkSymbolicEdit
:
1135 edit_symlink_cmd ();
1137 case CK_ExternalPanelize
:
1138 external_panelize ();
1143 case CK_ViewFiltered
:
1144 view_filtered_cmd ();
1149 #ifdef ENABLE_VFS_FISH
1150 case CK_ConnectFish
:
1154 #ifdef ENABLE_VFS_FTP
1159 #ifdef ENABLE_VFS_SMB
1163 #endif /* ENABLE_VFS_SMB */
1168 /* show the history of command line widget */
1169 send_message (&cmdline
->widget
, WIDGET_COMMAND
, CK_History
);
1172 if (sender
== (Widget
*) the_menubar
)
1173 info_cmd (); /* menu */
1175 info_cmd_no_menu (); /* shortcut or buttonbar */
1177 #ifdef WITH_BACKGROUND
1182 case CK_OptionsLayout
:
1189 link_cmd (LINK_HARDLINK
);
1191 case CK_PanelListing
:
1194 #ifdef LISTMODE_EDITOR
1202 case CK_MenuLastSelected
:
1203 menu_last_selected_cmd ();
1208 case CK_OptionsPanel
:
1209 panel_options_box ();
1212 case CK_SelectCodepage
:
1222 case CK_PanelQuickView
:
1223 if (sender
== (Widget
*) the_menubar
)
1224 quick_view_cmd (); /* menu */
1226 quick_cmd_no_menu (); /* shortcut or buttonabr */
1234 case CK_LinkSymbolicRelative
:
1235 link_cmd (LINK_SYMLINK_RELATIVE
);
1248 case CK_SelectInvert
:
1249 select_invert_cmd ();
1261 smart_dirsize_cmd ();
1266 case CK_ExtendedKeyMap
:
1270 mc_event_raise (MCEVENT_GROUP_CORE
, "suspend", NULL
);
1275 case CK_LinkSymbolic
:
1276 link_cmd (LINK_SYMLINK_ABSOLUTE
);
1278 case CK_PanelListingSwitch
:
1279 toggle_listing_cmd ();
1282 toggle_show_hidden ();
1284 case CK_SplitVertHoriz
:
1285 toggle_panels_split ();
1293 #ifdef ENABLE_VFS_UNDELFS
1302 user_file_menu_cmd ();
1311 /* don't close panels due to SIGINT */
1314 res
= MSG_NOT_HANDLED
;
1320 /* --------------------------------------------------------------------------------------------- */
1323 midnight_callback (Dlg_head
* h
, Widget
* sender
, dlg_msg_t msg
, int parm
, void *data
)
1325 unsigned long command
;
1336 /* We handle the special case of the output lines */
1337 if (mc_global
.tty
.console_flag
&& output_lines
)
1338 show_console_contents (output_start_y
,
1339 LINES
- output_lines
- mc_global
.keybar_visible
-
1340 1, LINES
- mc_global
.keybar_visible
- 1);
1345 menubar_arrange (the_menubar
);
1349 /* We only need the first idle event to show user menu after start */
1350 set_idle_proc (h
, 0);
1352 if (boot_current_is_left
)
1353 dlg_select_widget (get_panel_widget (0));
1355 dlg_select_widget (get_panel_widget (1));
1358 midnight_execute_cmd (NULL
, CK_UserMenu
);
1362 if (ctl_x_map_enabled
)
1364 ctl_x_map_enabled
= FALSE
;
1365 command
= keybind_lookup_keymap_command (main_x_map
, parm
);
1366 if (command
!= CK_IgnoreKey
)
1367 return midnight_execute_cmd (NULL
, command
);
1370 /* FIXME: should handle all menu shortcuts before this point */
1371 if (the_menubar
->is_active
)
1372 return MSG_NOT_HANDLED
;
1375 input_free_completions (cmdline
);
1381 for (i
= 0; cmdline
->buffer
[i
] != '\0' &&
1382 (cmdline
->buffer
[i
] == ' ' || cmdline
->buffer
[i
] == '\t'); i
++)
1385 if (cmdline
->buffer
[i
] != '\0')
1387 send_message ((Widget
*) cmdline
, WIDGET_KEY
, parm
);
1391 input_insert (cmdline
, "", FALSE
);
1395 /* Ctrl-Enter and Alt-Enter */
1396 if (((parm
& ~(KEY_M_CTRL
| KEY_M_ALT
)) == '\n') && (parm
& (KEY_M_CTRL
| KEY_M_ALT
)))
1402 /* Ctrl-Shift-Enter */
1403 if (parm
== (KEY_M_CTRL
| KEY_M_SHIFT
| '\n'))
1405 put_current_path ();
1410 if ((!alternate_plus_minus
|| !(mc_global
.tty
.console_flag
|| mc_global
.tty
.xterm_flag
))
1411 && !quote
&& !current_panel
->searching
)
1413 if (!only_leading_plus_minus
)
1415 /* Special treatement, since the input line will eat them */
1422 if (parm
== '\\' || parm
== '-')
1430 select_invert_cmd ();
1434 else if (!command_prompt
|| !cmdline
->buffer
[0])
1436 /* Special treatement '+', '-', '\', '*' only when this is
1437 * first char on input line
1446 if (parm
== '\\' || parm
== '-')
1454 select_invert_cmd ();
1459 return MSG_NOT_HANDLED
;
1461 case DLG_HOTKEY_HANDLED
:
1462 if ((get_current_type () == view_listing
) && current_panel
->searching
)
1464 current_panel
->dirty
= 1; /* FIXME: unneeded? */
1465 send_message ((Widget
*) current_panel
, WIDGET_COMMAND
, CK_SearchStop
);
1469 case DLG_UNHANDLED_KEY
:
1474 v
= send_message ((Widget
*) cmdline
, WIDGET_KEY
, parm
);
1475 if (v
== MSG_HANDLED
)
1479 if (ctl_x_map_enabled
)
1481 ctl_x_map_enabled
= FALSE
;
1482 command
= keybind_lookup_keymap_command (main_x_map
, parm
);
1485 command
= keybind_lookup_keymap_command (main_map
, parm
);
1487 return (command
== CK_IgnoreKey
) ? MSG_NOT_HANDLED
: midnight_execute_cmd (NULL
, command
);
1490 if (!the_menubar
->is_active
)
1491 update_dirty_panels ();
1497 return midnight_execute_cmd (NULL
, parm
);
1498 /* message from menu */
1499 if (sender
== (Widget
*) the_menubar
)
1500 return midnight_execute_cmd (sender
, parm
);
1501 /* message from buttonbar */
1502 if (sender
== (Widget
*) the_bar
)
1505 return send_message ((Widget
*) data
, WIDGET_COMMAND
, parm
);
1506 return midnight_execute_cmd (sender
, parm
);
1508 return MSG_NOT_HANDLED
;
1515 return default_dlg_callback (h
, sender
, msg
, parm
, data
);
1519 /* --------------------------------------------------------------------------------------------- */
1520 /*** public functions ****************************************************************************/
1521 /* --------------------------------------------------------------------------------------------- */
1526 menu_set_name (left_menu
, horizontal_split
? _("&Above") : _("&Left"));
1527 menu_set_name (right_menu
, horizontal_split
? _("&Below") : _("&Right"));
1528 menubar_arrange (the_menubar
);
1529 menubar_set_visible (the_menubar
, menubar_visible
);
1533 midnight_set_buttonbar (WButtonBar
* b
)
1535 buttonbar_set_label (b
, 1, Q_ ("ButtonBar|Help"), main_map
, NULL
);
1536 buttonbar_set_label (b
, 2, Q_ ("ButtonBar|Menu"), main_map
, NULL
);
1537 buttonbar_set_label (b
, 3, Q_ ("ButtonBar|View"), main_map
, NULL
);
1538 buttonbar_set_label (b
, 4, Q_ ("ButtonBar|Edit"), main_map
, NULL
);
1539 buttonbar_set_label (b
, 5, Q_ ("ButtonBar|Copy"), main_map
, NULL
);
1540 buttonbar_set_label (b
, 6, Q_ ("ButtonBar|RenMov"), main_map
, NULL
);
1541 buttonbar_set_label (b
, 7, Q_ ("ButtonBar|Mkdir"), main_map
, NULL
);
1542 buttonbar_set_label (b
, 8, Q_ ("ButtonBar|Delete"), main_map
, NULL
);
1543 buttonbar_set_label (b
, 9, Q_ ("ButtonBar|PullDn"), main_map
, NULL
);
1544 buttonbar_set_label (b
, 10, Q_ ("ButtonBar|Quit"), main_map
, NULL
);
1547 /* --------------------------------------------------------------------------------------------- */
1549 * Load new hint and display it.
1550 * IF force is not 0, ignore the timeout.
1554 load_hint (gboolean force
)
1558 if (the_hint
->widget
.owner
== NULL
)
1561 if (!mc_global
.message_visible
)
1563 label_set_text (the_hint
, NULL
);
1567 hint
= get_random_hint (force
);
1577 char text
[BUF_SMALL
];
1579 g_snprintf (text
, sizeof (text
), _("GNU Midnight Commander %s\n"), VERSION
);
1584 /* --------------------------------------------------------------------------------------------- */
1589 input_free_completions (cmdline
);
1590 dlg_one_down (midnight_dlg
);
1593 /* --------------------------------------------------------------------------------------------- */
1595 /** Save current stat of directories to avoid reloading the panels
1596 * when no modifications have taken place
1599 save_cwds_stat (void)
1601 if (panels_options
.fast_reload
)
1603 mc_stat (current_panel
->cwd
, &(current_panel
->dir_stat
));
1604 if (get_other_type () == view_listing
)
1605 mc_stat (other_panel
->cwd
, &(other_panel
->dir_stat
));
1609 /* --------------------------------------------------------------------------------------------- */
1612 quiet_quit_cmd (void)
1614 print_last_revert
= TRUE
;
1615 return quit_cmd_internal (1);
1618 /* --------------------------------------------------------------------------------------------- */
1620 /** Run the main dialog that occupies the whole screen */
1624 dlg_colors_t midnight_colors
;
1626 midnight_colors
[DLG_COLOR_NORMAL
] = mc_skin_color_get ("dialog", "_default_");
1627 midnight_colors
[DLG_COLOR_FOCUS
] = mc_skin_color_get ("dialog", "focus");
1628 midnight_colors
[DLG_COLOR_HOT_NORMAL
] = mc_skin_color_get ("dialog", "hotnormal");
1629 midnight_colors
[DLG_COLOR_HOT_FOCUS
] = mc_skin_color_get ("dialog", "hotfocus");
1630 midnight_colors
[DLG_COLOR_TITLE
] = mc_skin_color_get ("dialog", "title");
1632 #ifdef USE_INTERNAL_EDIT
1636 midnight_dlg
= create_dlg (FALSE
, 0, 0, LINES
, COLS
, midnight_colors
, midnight_callback
,
1637 "[main]", NULL
, DLG_WANT_IDLE
);
1639 if (mc_global
.mc_run_mode
== MC_RUN_FULL
)
1644 /* Check if we were invoked as an editor or file viewer */
1645 if (mc_global
.mc_run_mode
!= MC_RUN_FULL
)
1646 mc_maybe_editor_or_viewer ();
1649 create_panels_and_run_mc ();
1651 /* destroy_dlg destroys even current_panel->cwd, so we have to save a copy :) */
1652 if (mc_args__last_wd_file
!= NULL
&& vfs_current_is_local ())
1653 last_wd_string
= g_strdup (current_panel
->cwd
);
1655 /* don't handle VFS timestamps for dirs opened in panels */
1656 mc_event_destroy (MCEVENT_GROUP_CORE
, "vfs_timestamp");
1660 mc_global
.widget
.midnight_shutdown
= TRUE
;
1661 dialog_switch_shutdown ();
1663 destroy_dlg (midnight_dlg
);
1664 current_panel
= NULL
;
1666 #ifdef USE_INTERNAL_EDIT
1670 if ((quit
& SUBSHELL_EXIT
) == 0)
1674 /* --------------------------------------------------------------------------------------------- */