Tweak background operations support.
[midnight-commander.git] / src / filemanager / midnight.c
blob6c365c70ea7bbcda8d9d9edfba48fa606815ad95
1 /*
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.
8 Written by:
9 Miguel de Icaza, 1994, 1995, 1996, 1997
10 Janne Kukonlehto, 1994, 1995
11 Norbert Warmuth, 1997
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/>.
30 /** \file main.c
31 * \brief Source: main dialog (file panels) of the Midnight Commander
34 #include <config.h>
36 #include <ctype.h>
37 #include <errno.h>
38 #include <locale.h>
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <string.h>
42 #include <fcntl.h>
43 #include <sys/types.h>
44 #include <sys/stat.h>
45 #include <sys/wait.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 */
52 #include "lib/skin.h"
53 #include "lib/util.h"
55 #include "lib/vfs/vfs.h"
57 #include "src/args.h"
58 #include "src/subshell.h"
59 #include "src/setup.h" /* variables */
60 #include "src/learn.h" /* learn_keys() */
61 #include "src/keybind-defaults.h"
62 #include "lib/keybind.h"
63 #include "lib/event.h"
65 #include "option.h" /* configure_box() */
66 #include "tree.h"
67 #include "boxes.h" /* sort_box(), tree_box() */
68 #include "layout.h"
69 #include "cmd.h" /* commands */
70 #include "hotlist.h"
71 #include "panelize.h"
72 #include "command.h" /* cmdline */
73 #include "dir.h" /* clean_dir() */
75 #include "chmod.h"
76 #include "chown.h"
77 #include "achown.h"
79 #ifdef USE_INTERNAL_EDIT
80 #include "src/editor/edit.h"
81 #endif
83 #ifdef USE_DIFF_VIEW
84 #include "src/diffviewer/ydiff.h"
85 #endif
87 #include "src/consaver/cons.saver.h" /* show_console_contents */
89 #include "midnight.h"
91 /* TODO: merge content of layout.c here */
92 extern int ok_to_refresh;
94 /*** global variables ****************************************************************************/
96 /* When the modes are active, left_panel, right_panel and tree_panel */
97 /* point to a proper data structure. You should check with the functions */
98 /* get_current_type and get_other_type the types of the panels before using */
99 /* this pointer variables */
101 /* The structures for the panels */
102 WPanel *left_panel = NULL;
103 WPanel *right_panel = NULL;
104 /* Pointer to the selected and unselected panel */
105 WPanel *current_panel = NULL;
107 /* The Menubar */
108 WMenuBar *the_menubar = NULL;
109 /* The widget where we draw the prompt */
110 WLabel *the_prompt;
111 /* The hint bar */
112 WLabel *the_hint;
113 /* The button bar */
114 WButtonBar *the_bar;
116 /*** file scope macro definitions ****************************************************************/
118 #ifdef HAVE_CHARSET
120 * Don't restrict the output on the screen manager level,
121 * the translation tables take care of it.
123 #endif /* !HAVE_CHARSET */
125 /*** file scope type declarations ****************************************************************/
127 /*** file scope variables ************************************************************************/
129 static Menu *left_menu, *right_menu;
131 static gboolean ctl_x_map_enabled = FALSE;
133 /*** file scope functions ************************************************************************/
135 /** Stop MC main dialog and the current dialog if it exists.
136 * Needed to provide fast exit from MC viewer or editor on shell exit */
137 static void
138 stop_dialogs (void)
140 midnight_dlg->state = DLG_CLOSED;
142 if ((top_dlg != NULL) && (top_dlg->data != NULL))
143 ((Dlg_head *) top_dlg->data)->state = DLG_CLOSED;
146 /* --------------------------------------------------------------------------------------------- */
148 static void
149 treebox_cmd (void)
151 char *sel_dir;
153 sel_dir = tree_box (selection (current_panel)->fname);
154 if (sel_dir != NULL)
156 vfs_path_t *sel_vdir;
158 sel_vdir = vfs_path_from_str (sel_dir);
159 do_cd (sel_vdir, cd_exact);
160 vfs_path_free (sel_vdir);
161 g_free (sel_dir);
165 /* --------------------------------------------------------------------------------------------- */
167 #ifdef LISTMODE_EDITOR
168 static void
169 listmode_cmd (void)
171 char *newmode;
173 if (get_current_type () != view_listing)
174 return;
176 newmode = listmode_edit (current_panel->user_format);
177 if (!newmode)
178 return;
180 g_free (current_panel->user_format);
181 current_panel->list_type = list_user;
182 current_panel->user_format = newmode;
183 set_panel_formats (current_panel);
185 do_refresh ();
187 #endif /* LISTMODE_EDITOR */
189 /* --------------------------------------------------------------------------------------------- */
191 static GList *
192 create_panel_menu (void)
194 GList *entries = NULL;
196 entries = g_list_prepend (entries, menu_entry_create (_("File listin&g"), CK_PanelListing));
197 entries = g_list_prepend (entries, menu_entry_create (_("&Quick view"), CK_PanelQuickView));
198 entries = g_list_prepend (entries, menu_entry_create (_("&Info"), CK_PanelInfo));
199 entries = g_list_prepend (entries, menu_entry_create (_("&Tree"), CK_PanelTree));
200 entries = g_list_prepend (entries, menu_separator_create ());
201 entries =
202 g_list_prepend (entries, menu_entry_create (_("&Listing mode..."), CK_PanelListingChange));
203 entries = g_list_prepend (entries, menu_entry_create (_("&Sort order..."), CK_Sort));
204 entries = g_list_prepend (entries, menu_entry_create (_("&Filter..."), CK_Filter));
205 #ifdef HAVE_CHARSET
206 entries = g_list_prepend (entries, menu_entry_create (_("&Encoding..."), CK_SelectCodepage));
207 #endif
208 entries = g_list_prepend (entries, menu_separator_create ());
209 #ifdef ENABLE_VFS_FTP
210 entries = g_list_prepend (entries, menu_entry_create (_("FT&P link..."), CK_ConnectFtp));
211 #endif
212 #ifdef ENABLE_VFS_FISH
213 entries = g_list_prepend (entries, menu_entry_create (_("S&hell link..."), CK_ConnectFish));
214 #endif
215 #ifdef ENABLE_VFS_SMB
216 entries = g_list_prepend (entries, menu_entry_create (_("SM&B link..."), CK_ConnectSmb));
217 #endif
218 entries = g_list_prepend (entries, menu_entry_create (_("Paneli&ze"), CK_Panelize));
219 entries = g_list_prepend (entries, menu_separator_create ());
220 entries = g_list_prepend (entries, menu_entry_create (_("&Rescan"), CK_Reread));
222 return g_list_reverse (entries);
225 /* --------------------------------------------------------------------------------------------- */
227 static GList *
228 create_file_menu (void)
230 GList *entries = NULL;
232 entries = g_list_prepend (entries, menu_entry_create (_("&View"), CK_View));
233 entries = g_list_prepend (entries, menu_entry_create (_("Vie&w file..."), CK_ViewFile));
234 entries = g_list_prepend (entries, menu_entry_create (_("&Filtered view"), CK_ViewFiltered));
235 entries = g_list_prepend (entries, menu_entry_create (_("&Edit"), CK_Edit));
236 entries = g_list_prepend (entries, menu_entry_create (_("&Copy"), CK_Copy));
237 entries = g_list_prepend (entries, menu_entry_create (_("C&hmod"), CK_ChangeMode));
238 entries = g_list_prepend (entries, menu_entry_create (_("&Link"), CK_Link));
239 entries = g_list_prepend (entries, menu_entry_create (_("&Symlink"), CK_LinkSymbolic));
240 entries =
241 g_list_prepend (entries,
242 menu_entry_create (_("Relative symlin&k"), CK_LinkSymbolicRelative));
243 entries = g_list_prepend (entries, menu_entry_create (_("Edit s&ymlink"), CK_LinkSymbolicEdit));
244 entries = g_list_prepend (entries, menu_entry_create (_("Ch&own"), CK_ChangeOwn));
245 entries =
246 g_list_prepend (entries, menu_entry_create (_("&Advanced chown"), CK_ChangeOwnAdvanced));
247 entries = g_list_prepend (entries, menu_entry_create (_("&Rename/Move"), CK_Move));
248 entries = g_list_prepend (entries, menu_entry_create (_("&Mkdir"), CK_MakeDir));
249 entries = g_list_prepend (entries, menu_entry_create (_("&Delete"), CK_Delete));
250 entries = g_list_prepend (entries, menu_entry_create (_("&Quick cd"), CK_CdQuick));
251 entries = g_list_prepend (entries, menu_separator_create ());
252 entries = g_list_prepend (entries, menu_entry_create (_("Select &group"), CK_Select));
253 entries = g_list_prepend (entries, menu_entry_create (_("U&nselect group"), CK_Unselect));
254 entries = g_list_prepend (entries, menu_entry_create (_("&Invert selection"), CK_SelectInvert));
255 entries = g_list_prepend (entries, menu_separator_create ());
256 entries = g_list_prepend (entries, menu_entry_create (_("E&xit"), CK_Quit));
258 return g_list_reverse (entries);
261 /* --------------------------------------------------------------------------------------------- */
263 static GList *
264 create_command_menu (void)
266 /* I know, I'm lazy, but the tree widget when it's not running
267 * as a panel still has some problems, I have not yet finished
268 * the WTree widget port, sorry.
270 GList *entries = NULL;
272 entries = g_list_prepend (entries, menu_entry_create (_("&User menu"), CK_UserMenu));
273 entries = g_list_prepend (entries, menu_entry_create (_("&Directory tree"), CK_Tree));
274 entries = g_list_prepend (entries, menu_entry_create (_("&Find file"), CK_Find));
275 entries = g_list_prepend (entries, menu_entry_create (_("S&wap panels"), CK_Swap));
276 entries = g_list_prepend (entries, menu_entry_create (_("Switch &panels on/off"), CK_Shell));
277 entries =
278 g_list_prepend (entries, menu_entry_create (_("&Compare directories"), CK_CompareDirs));
279 #ifdef USE_DIFF_VIEW
280 entries = g_list_prepend (entries, menu_entry_create (_("C&ompare files"), CK_CompareFiles));
281 #endif
282 entries =
283 g_list_prepend (entries, menu_entry_create (_("E&xternal panelize"), CK_ExternalPanelize));
284 entries = g_list_prepend (entries, menu_entry_create (_("Show directory s&izes"), CK_DirSize));
285 entries = g_list_prepend (entries, menu_separator_create ());
286 entries = g_list_prepend (entries, menu_entry_create (_("Command &history"), CK_History));
287 entries = g_list_prepend (entries, menu_entry_create (_("Di&rectory hotlist"), CK_HotList));
288 #ifdef ENABLE_VFS
289 entries = g_list_prepend (entries, menu_entry_create (_("&Active VFS list"), CK_VfsList));
290 #endif
291 #ifdef ENABLE_BACKGROUND
292 entries = g_list_prepend (entries, menu_entry_create (_("&Background jobs"), CK_Jobs));
293 #endif
294 entries = g_list_prepend (entries, menu_entry_create (_("Screen lis&t"), CK_ScreenList));
295 entries = g_list_prepend (entries, menu_separator_create ());
296 #ifdef ENABLE_VFS_UNDELFS
297 entries =
298 g_list_prepend (entries,
299 menu_entry_create (_("&Undelete files (ext2fs only)"), CK_Undelete));
300 #endif
301 #ifdef LISTMODE_EDITOR
302 entries = g_list_prepend (entries, menu_entry_create (_("&Listing format edit"), CK_ListMode));
303 #endif
304 #if defined (ENABLE_VFS_UNDELFS) || defined (LISTMODE_EDITOR)
305 entries = g_list_prepend (entries, menu_separator_create ());
306 #endif
307 entries =
308 g_list_prepend (entries,
309 menu_entry_create (_("Edit &extension file"), CK_EditExtensionsFile));
310 entries = g_list_prepend (entries, menu_entry_create (_("Edit &menu file"), CK_EditUserMenu));
311 entries =
312 g_list_prepend (entries,
313 menu_entry_create (_("Edit hi&ghlighting group file"),
314 CK_EditFileHighlightFile));
316 return g_list_reverse (entries);
319 /* --------------------------------------------------------------------------------------------- */
321 static GList *
322 create_options_menu (void)
324 GList *entries = NULL;
326 entries = g_list_prepend (entries, menu_entry_create (_("&Configuration..."), CK_Options));
327 entries = g_list_prepend (entries, menu_entry_create (_("&Layout..."), CK_OptionsLayout));
328 entries = g_list_prepend (entries, menu_entry_create (_("&Panel options..."), CK_OptionsPanel));
329 entries =
330 g_list_prepend (entries, menu_entry_create (_("C&onfirmation..."), CK_OptionsConfirm));
331 entries =
332 g_list_prepend (entries, menu_entry_create (_("&Display bits..."), CK_OptionsDisplayBits));
333 entries = g_list_prepend (entries, menu_entry_create (_("Learn &keys..."), CK_LearnKeys));
334 #ifdef ENABLE_VFS
335 entries = g_list_prepend (entries, menu_entry_create (_("&Virtual FS..."), CK_OptionsVfs));
336 #endif
337 entries = g_list_prepend (entries, menu_separator_create ());
338 entries = g_list_prepend (entries, menu_entry_create (_("&Save setup"), CK_SaveSetup));
340 return g_list_reverse (entries);
343 /* --------------------------------------------------------------------------------------------- */
345 static void
346 init_menu (void)
348 left_menu = create_menu ("", create_panel_menu (), "[Left and Right Menus]");
349 menubar_add_menu (the_menubar, left_menu);
350 menubar_add_menu (the_menubar, create_menu (_("&File"), create_file_menu (), "[File Menu]"));
351 menubar_add_menu (the_menubar,
352 create_menu (_("&Command"), create_command_menu (), "[Command Menu]"));
353 menubar_add_menu (the_menubar,
354 create_menu (_("&Options"), create_options_menu (), "[Options Menu]"));
355 right_menu = create_menu ("", create_panel_menu (), "[Left and Right Menus]");
356 menubar_add_menu (the_menubar, right_menu);
357 update_menu ();
360 /* --------------------------------------------------------------------------------------------- */
362 static void
363 menu_last_selected_cmd (void)
365 the_menubar->is_active = TRUE;
366 the_menubar->is_dropped = (drop_menus != 0);
367 the_menubar->previous_widget = dlg_get_current_widget_id (midnight_dlg);
368 dlg_select_widget (the_menubar);
371 /* --------------------------------------------------------------------------------------------- */
373 static void
374 menu_cmd (void)
376 if (the_menubar->is_active)
377 return;
379 if ((get_current_index () == 0) == (current_panel->active != 0))
380 the_menubar->selected = 0;
381 else
382 the_menubar->selected = g_list_length (the_menubar->menu) - 1;
383 menu_last_selected_cmd ();
386 /* --------------------------------------------------------------------------------------------- */
388 static void
389 sort_cmd (void)
391 WPanel *p;
392 const panel_field_t *sort_order;
394 if (!SELECTED_IS_PANEL)
395 return;
397 p = MENU_PANEL;
398 sort_order = sort_box (&p->sort_info);
399 panel_set_sort_order (p, sort_order);
402 /* --------------------------------------------------------------------------------------------- */
404 static char *
405 midnight_get_shortcut (unsigned long command)
407 const char *ext_map;
408 const char *shortcut = NULL;
410 shortcut = keybind_lookup_keymap_shortcut (main_map, command);
411 if (shortcut != NULL)
412 return g_strdup (shortcut);
414 shortcut = keybind_lookup_keymap_shortcut (panel_map, command);
415 if (shortcut != NULL)
416 return g_strdup (shortcut);
418 ext_map = keybind_lookup_keymap_shortcut (main_map, CK_ExtendedKeyMap);
419 if (ext_map != NULL)
420 shortcut = keybind_lookup_keymap_shortcut (main_x_map, command);
421 if (shortcut != NULL)
422 return g_strdup_printf ("%s %s", ext_map, shortcut);
424 return NULL;
427 /* --------------------------------------------------------------------------------------------- */
429 static char *
430 midnight_get_title (const Dlg_head * h, size_t len)
432 char *path;
433 char *login;
434 char *p;
436 (void) h;
438 title_path_prepare (&path, &login);
440 p = g_strdup_printf ("%s [%s]:%s", _("Panels:"), login, path);
441 g_free (path);
442 g_free (login);
443 path = g_strdup (str_trunc (p, len - 4));
444 g_free (p);
446 return path;
449 /* --------------------------------------------------------------------------------------------- */
451 static void
452 toggle_panels_split (void)
454 panels_layout.horizontal_split = !panels_layout.horizontal_split;
455 layout_change ();
456 do_refresh ();
459 /* --------------------------------------------------------------------------------------------- */
461 #if ENABLE_VFS
463 /* event helper */
464 static gboolean
465 check_panel_timestamp (const WPanel * panel, panel_view_mode_t mode, struct vfs_class *vclass,
466 vfsid id)
468 if (mode == view_listing)
470 const vfs_path_element_t *path_element;
472 path_element = vfs_path_get_by_index (panel->cwd_vpath, -1);
474 if (path_element->class != vclass)
475 return FALSE;
477 if (vfs_getid (panel->cwd_vpath) != id)
478 return FALSE;
480 return TRUE;
483 /* --------------------------------------------------------------------------------------------- */
485 /* event callback */
486 static gboolean
487 check_current_panel_timestamp (const gchar * event_group_name, const gchar * event_name,
488 gpointer init_data, gpointer data)
490 ev_vfs_stamp_create_t *event_data = (ev_vfs_stamp_create_t *) data;
492 (void) event_group_name;
493 (void) event_name;
494 (void) init_data;
496 event_data->ret =
497 check_panel_timestamp (current_panel, get_current_type (), event_data->vclass,
498 event_data->id);
499 return !event_data->ret;
502 /* --------------------------------------------------------------------------------------------- */
504 /* event callback */
505 static gboolean
506 check_other_panel_timestamp (const gchar * event_group_name, const gchar * event_name,
507 gpointer init_data, gpointer data)
509 ev_vfs_stamp_create_t *event_data = (ev_vfs_stamp_create_t *) data;
511 (void) event_group_name;
512 (void) event_name;
513 (void) init_data;
515 event_data->ret =
516 check_panel_timestamp (other_panel, get_other_type (), event_data->vclass, event_data->id);
517 return !event_data->ret;
519 #endif /* ENABLE_VFS */
521 /* --------------------------------------------------------------------------------------------- */
523 /* event callback */
524 static gboolean
525 print_vfs_message (const gchar * event_group_name, const gchar * event_name,
526 gpointer init_data, gpointer data)
528 char str[128];
529 ev_vfs_print_message_t *event_data = (ev_vfs_print_message_t *) data;
531 (void) event_group_name;
532 (void) event_name;
533 (void) init_data;
535 g_vsnprintf (str, sizeof (str), event_data->msg, event_data->ap);
537 if (mc_global.widget.midnight_shutdown)
538 return TRUE;
540 if (!mc_global.message_visible || !the_hint || !the_hint->widget.owner)
542 int col, row;
544 if (!nice_rotating_dash || (ok_to_refresh <= 0))
545 return TRUE;
547 /* Preserve current cursor position */
548 tty_getyx (&row, &col);
550 tty_gotoyx (0, 0);
551 tty_setcolor (NORMAL_COLOR);
552 tty_print_string (str_fit_to_term (str, COLS - 1, J_LEFT));
554 /* Restore cursor position */
555 tty_gotoyx (row, col);
556 mc_refresh ();
557 return TRUE;
560 if (mc_global.message_visible)
561 set_hintbar (str);
563 return TRUE;
566 /* --------------------------------------------------------------------------------------------- */
568 static void
569 create_panels (void)
571 int current_index;
572 int other_index;
573 panel_view_mode_t current_mode, other_mode;
574 char *original_dir = NULL;
576 if (boot_current_is_left)
578 current_index = 0;
579 other_index = 1;
580 current_mode = startup_left_mode;
581 other_mode = startup_right_mode;
583 else
585 current_index = 1;
586 other_index = 0;
587 current_mode = startup_right_mode;
588 other_mode = startup_left_mode;
590 /* Creates the left panel */
591 if (mc_run_param0 != NULL)
593 vfs_path_t *vpath;
595 if (mc_run_param1 != NULL)
597 /* Ok, user has specified two dirs, save the original one,
598 * since we may not be able to chdir to the proper
599 * second directory later
601 original_dir = vfs_get_current_dir ();
603 vpath = vfs_path_from_str (mc_run_param0);
604 mc_chdir (vpath);
605 vfs_path_free (vpath);
607 set_display_type (current_index, current_mode);
609 /* The other panel */
610 if (mc_run_param1 != NULL)
612 const char *cd_dir = (original_dir != NULL) ? original_dir : mc_run_param1;
613 vfs_path_t *vpath;
615 vpath = vfs_path_from_str (cd_dir);
616 mc_chdir (vpath);
617 vfs_path_free (vpath);
619 g_free (original_dir);
620 set_display_type (other_index, other_mode);
622 if (startup_left_mode == view_listing)
623 current_panel = left_panel;
624 else if (right_panel != NULL)
625 current_panel = right_panel;
626 else
627 current_panel = left_panel;
629 #if ENABLE_VFS
630 mc_event_add (MCEVENT_GROUP_CORE, "vfs_timestamp", check_other_panel_timestamp, NULL, NULL);
631 mc_event_add (MCEVENT_GROUP_CORE, "vfs_timestamp", check_current_panel_timestamp, NULL, NULL);
632 #endif /* ENABLE_VFS */
634 mc_event_add (MCEVENT_GROUP_CORE, "vfs_print_message", print_vfs_message, NULL, NULL);
636 /* Create the nice widgets */
637 cmdline = command_new (0, 0, 0);
638 the_prompt = label_new (0, 0, mc_prompt);
639 the_prompt->transparent = 1;
640 the_bar = buttonbar_new (mc_global.keybar_visible);
642 the_hint = label_new (0, 0, 0);
643 the_hint->transparent = 1;
644 the_hint->auto_adjust_cols = 0;
645 the_hint->widget.cols = COLS;
647 the_menubar = menubar_new (0, 0, COLS, NULL);
650 /* --------------------------------------------------------------------------------------------- */
652 static void
653 put_current_path (void)
655 char *cwd_path;
656 vfs_path_t *cwd_vpath;
658 if (!command_prompt)
659 return;
661 cwd_vpath = remove_encoding_from_path (current_panel->cwd_vpath);
662 cwd_path = vfs_path_to_str (cwd_vpath);
663 command_insert (cmdline, cwd_path, FALSE);
665 if (cwd_path[strlen (cwd_path) - 1] != PATH_SEP)
666 command_insert (cmdline, PATH_SEP_STR, FALSE);
668 g_free (cwd_path);
669 vfs_path_free (cwd_vpath);
672 /* --------------------------------------------------------------------------------------------- */
674 static void
675 put_other_path (void)
677 char *cwd_path;
678 vfs_path_t *cwd_vpath;
680 if (get_other_type () != view_listing)
681 return;
683 if (!command_prompt)
684 return;
686 cwd_vpath = remove_encoding_from_path (other_panel->cwd_vpath);
687 cwd_path = vfs_path_to_str (cwd_vpath);
688 command_insert (cmdline, cwd_path, FALSE);
690 if (cwd_path[strlen (cwd_path) - 1] != PATH_SEP)
691 command_insert (cmdline, PATH_SEP_STR, FALSE);
693 g_free (cwd_path);
694 vfs_path_free (cwd_vpath);
697 /* --------------------------------------------------------------------------------------------- */
699 static void
700 put_link (WPanel * panel)
702 if (!command_prompt)
703 return;
704 if (S_ISLNK (selection (panel)->st.st_mode))
706 char buffer[MC_MAXPATHLEN];
707 vfs_path_t *vpath;
708 int i;
710 vpath = vfs_path_append_new (panel->cwd_vpath, selection (panel)->fname, NULL);
711 i = mc_readlink (vpath, buffer, MC_MAXPATHLEN - 1);
712 vfs_path_free (vpath);
714 if (i > 0)
716 buffer[i] = '\0';
717 command_insert (cmdline, buffer, TRUE);
722 /* --------------------------------------------------------------------------------------------- */
724 static void
725 put_current_link (void)
727 put_link (current_panel);
730 /* --------------------------------------------------------------------------------------------- */
732 static void
733 put_other_link (void)
735 if (get_other_type () == view_listing)
736 put_link (other_panel);
739 /* --------------------------------------------------------------------------------------------- */
741 /** Insert the selected file name into the input line */
742 static void
743 put_prog_name (void)
745 char *tmp;
746 if (!command_prompt)
747 return;
749 if (get_current_type () == view_tree)
751 WTree *tree = (WTree *) get_panel_widget (get_current_index ());
753 tmp = vfs_path_to_str (tree_selected_name (tree));
755 else
756 tmp = g_strdup (selection (current_panel)->fname);
758 command_insert (cmdline, tmp, TRUE);
759 g_free (tmp);
762 /* --------------------------------------------------------------------------------------------- */
764 static void
765 put_tagged (WPanel * panel)
767 int i;
769 if (!command_prompt)
770 return;
771 input_disable_update (cmdline);
772 if (panel->marked)
774 for (i = 0; i < panel->count; i++)
776 if (panel->dir.list[i].f.marked)
777 command_insert (cmdline, panel->dir.list[i].fname, TRUE);
780 else
782 command_insert (cmdline, panel->dir.list[panel->selected].fname, TRUE);
784 input_enable_update (cmdline);
787 /* --------------------------------------------------------------------------------------------- */
789 static void
790 put_current_tagged (void)
792 put_tagged (current_panel);
795 /* --------------------------------------------------------------------------------------------- */
797 static void
798 put_other_tagged (void)
800 if (get_other_type () == view_listing)
801 put_tagged (other_panel);
804 /* --------------------------------------------------------------------------------------------- */
806 static void
807 ctl_x_cmd (void)
809 ctl_x_map_enabled = TRUE;
812 /* --------------------------------------------------------------------------------------------- */
814 static void
815 setup_mc (void)
817 #ifdef HAVE_SLANG
818 #ifdef HAVE_CHARSET
819 tty_display_8bit (TRUE);
820 #else
821 tty_display_8bit (mc_global.full_eight_bits != 0);
822 #endif /* HAVE_CHARSET */
824 #else /* HAVE_SLANG */
826 #ifdef HAVE_CHARSET
827 tty_display_8bit (TRUE);
828 #else
829 tty_display_8bit (mc_global.eight_bit_clean != 0);
830 #endif /* HAVE_CHARSET */
831 #endif /* HAVE_SLANG */
833 #ifdef HAVE_SUBSHELL_SUPPORT
834 if (mc_global.tty.use_subshell)
835 add_select_channel (mc_global.tty.subshell_pty, load_prompt, 0);
836 #endif /* !HAVE_SUBSHELL_SUPPORT */
838 if ((tty_baudrate () < 9600) || mc_global.tty.slow_terminal)
839 verbose = 0;
842 /* --------------------------------------------------------------------------------------------- */
844 static void
845 setup_dummy_mc (void)
847 vfs_path_t *vpath;
848 char *d;
849 int ret;
851 d = _vfs_get_cwd ();
852 setup_mc ();
853 vpath = vfs_path_from_str (d);
854 ret = mc_chdir (vpath);
855 vfs_path_free (vpath);
856 g_free (d);
859 /* --------------------------------------------------------------------------------------------- */
861 static void
862 done_mc (void)
864 /* Setup shutdown
866 * We sync the profiles since the hotlist may have changed, while
867 * we only change the setup data if we have the auto save feature set
869 char *curr_dir;
871 save_setup (auto_save_setup, panels_options.auto_save_setup);
873 curr_dir = vfs_get_current_dir ();
874 vfs_stamp_path (curr_dir);
875 g_free (curr_dir);
877 if ((current_panel != NULL) && (get_current_type () == view_listing))
879 char *tmp_path;
881 tmp_path = vfs_path_to_str (current_panel->cwd_vpath);
882 vfs_stamp_path (tmp_path);
883 g_free (tmp_path);
886 if ((other_panel != NULL) && (get_other_type () == view_listing))
888 char *tmp_path;
890 tmp_path = vfs_path_to_str (other_panel->cwd_vpath);
891 vfs_stamp_path (tmp_path);
892 g_free (tmp_path);
896 /* --------------------------------------------------------------------------------------------- */
898 static void
899 create_panels_and_run_mc (void)
901 midnight_dlg->get_shortcut = midnight_get_shortcut;
902 midnight_dlg->get_title = midnight_get_title;
904 create_panels ();
906 add_widget (midnight_dlg, the_menubar);
907 init_menu ();
909 add_widget (midnight_dlg, get_panel_widget (0));
910 add_widget (midnight_dlg, get_panel_widget (1));
912 add_widget (midnight_dlg, the_hint);
913 add_widget (midnight_dlg, cmdline);
914 add_widget (midnight_dlg, the_prompt);
916 add_widget (midnight_dlg, the_bar);
917 midnight_set_buttonbar (the_bar);
919 /* Run the Midnight Commander if no file was specified in the command line */
920 run_dlg (midnight_dlg);
923 /* --------------------------------------------------------------------------------------------- */
925 /** result must be free'd (I think this should go in util.c) */
926 static vfs_path_t *
927 prepend_cwd_on_local (const char *filename)
929 vfs_path_t *vpath;
931 vpath = vfs_path_from_str (filename);
932 if (!vfs_file_is_local (vpath) || g_path_is_absolute (filename))
933 return vpath;
935 vfs_path_free (vpath);
937 return vfs_path_append_new (vfs_get_raw_current_dir (), filename, NULL);
940 /* --------------------------------------------------------------------------------------------- */
942 /** Invoke the internal view/edit routine with:
943 * the default processing and forcing the internal viewer/editor
945 static gboolean
946 mc_maybe_editor_or_viewer (void)
948 int ret;
950 switch (mc_global.mc_run_mode)
952 #ifdef USE_INTERNAL_EDIT
953 case MC_RUN_EDITOR:
955 vfs_path_t *param_vpath;
957 param_vpath = vfs_path_from_str (mc_run_param0);
958 ret = edit_file (param_vpath, mc_args__edit_start_line);
959 vfs_path_free (param_vpath);
961 break;
962 #endif /* USE_INTERNAL_EDIT */
963 case MC_RUN_VIEWER:
965 vfs_path_t *vpath;
967 vpath = prepend_cwd_on_local (mc_run_param0);
968 view_file (vpath, 0, 1);
969 vfs_path_free (vpath);
970 ret = 1;
971 break;
973 #ifdef USE_DIFF_VIEW
974 case MC_RUN_DIFFVIEWER:
975 ret = diff_view (mc_run_param0, mc_run_param1, mc_run_param0, mc_run_param1);
976 break;
977 #endif /* USE_DIFF_VIEW */
978 default:
979 ret = 0;
982 return (ret != 0);
985 /* --------------------------------------------------------------------------------------------- */
987 static gboolean
988 quit_cmd_internal (int quiet)
990 int q = quit;
991 size_t n;
993 n = dialog_switch_num () - 1;
994 if (n != 0)
996 char msg[BUF_MEDIUM];
998 g_snprintf (msg, sizeof (msg),
999 ngettext ("You have %zd opened screen. Quit anyway?",
1000 "You have %zd opened screens. Quit anyway?", n), n);
1002 if (query_dialog (_("The Midnight Commander"), msg, D_NORMAL, 2, _("&Yes"), _("&No")) != 0)
1003 return FALSE;
1004 q = 1;
1006 else if (quiet || !confirm_exit)
1007 q = 1;
1008 else if (query_dialog (_("The Midnight Commander"),
1009 _("Do you really want to quit the Midnight Commander?"),
1010 D_NORMAL, 2, _("&Yes"), _("&No")) == 0)
1011 q = 1;
1013 if (q != 0)
1015 #ifdef HAVE_SUBSHELL_SUPPORT
1016 if (!mc_global.tty.use_subshell)
1017 stop_dialogs ();
1018 else if ((q = exit_subshell ()))
1019 #endif
1020 stop_dialogs ();
1023 if (q != 0)
1024 quit |= 1;
1025 return (quit != 0);
1028 /* --------------------------------------------------------------------------------------------- */
1030 static gboolean
1031 quit_cmd (void)
1033 return quit_cmd_internal (0);
1036 /* --------------------------------------------------------------------------------------------- */
1038 static void
1039 toggle_show_hidden (void)
1041 panels_options.show_dot_files = !panels_options.show_dot_files;
1042 update_panels (UP_RELOAD, UP_KEEPSEL);
1045 /* --------------------------------------------------------------------------------------------- */
1048 * Repaint the contents of the panels without frames. To schedule panel
1049 * for repainting, set panel->dirty to 1. There are many reasons why
1050 * the panels need to be repainted, and this is a costly operation, so
1051 * it's done once per event.
1054 static void
1055 update_dirty_panels (void)
1057 if (get_current_type () == view_listing && current_panel->dirty)
1058 send_message ((Widget *) current_panel, WIDGET_DRAW, 0);
1060 if (get_other_type () == view_listing && other_panel->dirty)
1061 send_message ((Widget *) other_panel, WIDGET_DRAW, 0);
1064 /* --------------------------------------------------------------------------------------------- */
1066 static cb_ret_t
1067 midnight_execute_cmd (Widget * sender, unsigned long command)
1069 cb_ret_t res = MSG_HANDLED;
1071 (void) sender;
1073 /* stop quick search before executing any command */
1074 send_message ((Widget *) current_panel, WIDGET_COMMAND, CK_SearchStop);
1076 switch (command)
1078 case CK_HotListAdd:
1079 add2hotlist_cmd ();
1080 break;
1081 case CK_PanelListingChange:
1082 change_listing_cmd ();
1083 break;
1084 case CK_ChangeMode:
1085 chmod_cmd ();
1086 break;
1087 case CK_ChangeOwn:
1088 chown_cmd ();
1089 break;
1090 case CK_ChangeOwnAdvanced:
1091 chown_advanced_cmd ();
1092 break;
1093 case CK_CompareDirs:
1094 compare_dirs_cmd ();
1095 break;
1096 case CK_Options:
1097 configure_box ();
1098 break;
1099 #ifdef ENABLE_VFS
1100 case CK_OptionsVfs:
1101 configure_vfs ();
1102 break;
1103 #endif
1104 case CK_OptionsConfirm:
1105 confirm_box ();
1106 break;
1107 case CK_Copy:
1108 copy_cmd ();
1109 break;
1110 case CK_PutCurrentPath:
1111 put_current_path ();
1112 break;
1113 case CK_PutCurrentLink:
1114 put_current_link ();
1115 break;
1116 case CK_PutCurrentTagged:
1117 put_current_tagged ();
1118 break;
1119 case CK_PutOtherPath:
1120 put_other_path ();
1121 break;
1122 case CK_PutOtherLink:
1123 put_other_link ();
1124 break;
1125 case CK_PutOtherTagged:
1126 put_other_tagged ();
1127 break;
1128 case CK_Delete:
1129 delete_cmd ();
1130 break;
1131 case CK_ScreenList:
1132 dialog_switch_list ();
1133 break;
1134 #ifdef USE_DIFF_VIEW
1135 case CK_CompareFiles:
1136 diff_view_cmd ();
1137 break;
1138 #endif
1139 case CK_OptionsDisplayBits:
1140 display_bits_box ();
1141 break;
1142 case CK_Edit:
1143 edit_cmd ();
1144 break;
1145 #ifdef USE_INTERNAL_EDIT
1146 case CK_EditForceInternal:
1147 edit_cmd_force_internal ();
1148 break;
1149 #endif
1150 case CK_EditExtensionsFile:
1151 ext_cmd ();
1152 break;
1153 case CK_EditFileHighlightFile:
1154 edit_fhl_cmd ();
1155 break;
1156 case CK_EditUserMenu:
1157 edit_mc_menu_cmd ();
1158 break;
1159 case CK_LinkSymbolicEdit:
1160 edit_symlink_cmd ();
1161 break;
1162 case CK_ExternalPanelize:
1163 external_panelize ();
1164 break;
1165 case CK_Filter:
1166 filter_cmd ();
1167 break;
1168 case CK_ViewFiltered:
1169 view_filtered_cmd ();
1170 break;
1171 case CK_Find:
1172 find_cmd ();
1173 break;
1174 #ifdef ENABLE_VFS_FISH
1175 case CK_ConnectFish:
1176 fishlink_cmd ();
1177 break;
1178 #endif
1179 #ifdef ENABLE_VFS_FTP
1180 case CK_ConnectFtp:
1181 ftplink_cmd ();
1182 break;
1183 #endif
1184 #ifdef ENABLE_VFS_SMB
1185 case CK_ConnectSmb:
1186 smblink_cmd ();
1187 break;
1188 #endif /* ENABLE_VFS_SMB */
1189 case CK_Panelize:
1190 cd_panelize_cmd ();
1191 break;
1192 case CK_Help:
1193 help_cmd ();
1194 break;
1195 case CK_History:
1196 /* show the history of command line widget */
1197 send_message (&cmdline->widget, WIDGET_COMMAND, CK_History);
1198 break;
1199 case CK_PanelInfo:
1200 if (sender == (Widget *) the_menubar)
1201 info_cmd (); /* menu */
1202 else
1203 info_cmd_no_menu (); /* shortcut or buttonbar */
1204 break;
1205 #ifdef ENABLE_BACKGROUND
1206 case CK_Jobs:
1207 jobs_cmd ();
1208 break;
1209 #endif
1210 case CK_OptionsLayout:
1211 layout_box ();
1212 break;
1213 case CK_LearnKeys:
1214 learn_keys ();
1215 break;
1216 case CK_Link:
1217 link_cmd (LINK_HARDLINK);
1218 break;
1219 case CK_PanelListing:
1220 listing_cmd ();
1221 break;
1222 #ifdef LISTMODE_EDITOR
1223 case CK_ListMode:
1224 listmode_cmd ();
1225 break;
1226 #endif
1227 case CK_Menu:
1228 menu_cmd ();
1229 break;
1230 case CK_MenuLastSelected:
1231 menu_last_selected_cmd ();
1232 break;
1233 case CK_MakeDir:
1234 mkdir_cmd ();
1235 break;
1236 case CK_OptionsPanel:
1237 panel_options_box ();
1238 break;
1239 #ifdef HAVE_CHARSET
1240 case CK_SelectCodepage:
1241 encoding_cmd ();
1242 break;
1243 #endif
1244 case CK_CdQuick:
1245 quick_cd_cmd ();
1246 break;
1247 case CK_HotList:
1248 hotlist_cmd ();
1249 break;
1250 case CK_PanelQuickView:
1251 if (sender == (Widget *) the_menubar)
1252 quick_view_cmd (); /* menu */
1253 else
1254 quick_cmd_no_menu (); /* shortcut or buttonabr */
1255 break;
1256 case CK_QuitQuiet:
1257 quiet_quit_cmd ();
1258 break;
1259 case CK_Quit:
1260 quit_cmd ();
1261 break;
1262 case CK_LinkSymbolicRelative:
1263 link_cmd (LINK_SYMLINK_RELATIVE);
1264 break;
1265 case CK_Move:
1266 rename_cmd ();
1267 break;
1268 case CK_Reread:
1269 reread_cmd ();
1270 break;
1271 #ifdef ENABLE_VFS
1272 case CK_VfsList:
1273 vfs_list ();
1274 break;
1275 #endif
1276 case CK_SelectInvert:
1277 select_invert_cmd ();
1278 break;
1279 case CK_SaveSetup:
1280 save_setup_cmd ();
1281 break;
1282 case CK_Select:
1283 select_cmd ();
1284 break;
1285 case CK_Shell:
1286 view_other_cmd ();
1287 break;
1288 case CK_DirSize:
1289 smart_dirsize_cmd ();
1290 break;
1291 case CK_Sort:
1292 sort_cmd ();
1293 break;
1294 case CK_ExtendedKeyMap:
1295 ctl_x_cmd ();
1296 break;
1297 case CK_Suspend:
1298 mc_event_raise (MCEVENT_GROUP_CORE, "suspend", NULL);
1299 break;
1300 case CK_Swap:
1301 swap_cmd ();
1302 break;
1303 case CK_LinkSymbolic:
1304 link_cmd (LINK_SYMLINK_ABSOLUTE);
1305 break;
1306 case CK_PanelListingSwitch:
1307 toggle_listing_cmd ();
1308 break;
1309 case CK_ShowHidden:
1310 toggle_show_hidden ();
1311 break;
1312 case CK_SplitVertHoriz:
1313 toggle_panels_split ();
1314 break;
1315 case CK_SplitEqual:
1316 panels_split_equal ();
1317 break;
1318 case CK_SplitMore:
1319 panels_split_more ();
1320 break;
1321 case CK_SplitLess:
1322 panels_split_less ();
1323 break;
1324 case CK_PanelTree:
1325 panel_tree_cmd ();
1326 break;
1327 case CK_Tree:
1328 treebox_cmd ();
1329 break;
1330 #ifdef ENABLE_VFS_UNDELFS
1331 case CK_Undelete:
1332 undelete_cmd ();
1333 break;
1334 #endif
1335 case CK_Unselect:
1336 unselect_cmd ();
1337 break;
1338 case CK_UserMenu:
1339 user_file_menu_cmd ();
1340 break;
1341 case CK_View:
1342 view_cmd ();
1343 break;
1344 case CK_ViewFile:
1345 view_file_cmd ();
1346 break;
1347 case CK_Cancel:
1348 /* don't close panels due to SIGINT */
1349 break;
1350 default:
1351 res = MSG_NOT_HANDLED;
1354 return res;
1357 /* --------------------------------------------------------------------------------------------- */
1359 static cb_ret_t
1360 midnight_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
1362 unsigned long command;
1364 switch (msg)
1366 case DLG_INIT:
1367 panel_init ();
1368 setup_panels ();
1369 return MSG_HANDLED;
1371 case DLG_DRAW:
1372 load_hint (1);
1373 /* We handle the special case of the output lines */
1374 if (mc_global.tty.console_flag != '\0' && output_lines)
1375 show_console_contents (output_start_y,
1376 LINES - output_lines - mc_global.keybar_visible -
1377 1, LINES - mc_global.keybar_visible - 1);
1378 return MSG_HANDLED;
1380 case DLG_RESIZE:
1381 setup_panels ();
1382 menubar_arrange (the_menubar);
1383 return MSG_HANDLED;
1385 case DLG_IDLE:
1386 /* We only need the first idle event to show user menu after start */
1387 set_idle_proc (h, 0);
1389 if (boot_current_is_left)
1390 dlg_select_widget (get_panel_widget (0));
1391 else
1392 dlg_select_widget (get_panel_widget (1));
1394 if (auto_menu)
1395 midnight_execute_cmd (NULL, CK_UserMenu);
1396 return MSG_HANDLED;
1398 case DLG_KEY:
1399 if (ctl_x_map_enabled)
1401 ctl_x_map_enabled = FALSE;
1402 command = keybind_lookup_keymap_command (main_x_map, parm);
1403 if (command != CK_IgnoreKey)
1404 return midnight_execute_cmd (NULL, command);
1407 /* FIXME: should handle all menu shortcuts before this point */
1408 if (the_menubar->is_active)
1409 return MSG_NOT_HANDLED;
1411 if (parm == '\t')
1412 input_free_completions (cmdline);
1414 if (parm == '\n')
1416 size_t i;
1418 for (i = 0; cmdline->buffer[i] != '\0' &&
1419 (cmdline->buffer[i] == ' ' || cmdline->buffer[i] == '\t'); i++)
1422 if (cmdline->buffer[i] != '\0')
1424 send_message ((Widget *) cmdline, WIDGET_KEY, parm);
1425 return MSG_HANDLED;
1428 input_insert (cmdline, "", FALSE);
1429 cmdline->point = 0;
1432 /* Ctrl-Enter and Alt-Enter */
1433 if (((parm & ~(KEY_M_CTRL | KEY_M_ALT)) == '\n') && (parm & (KEY_M_CTRL | KEY_M_ALT)))
1435 put_prog_name ();
1436 return MSG_HANDLED;
1439 /* Ctrl-Shift-Enter */
1440 if (parm == (KEY_M_CTRL | KEY_M_SHIFT | '\n'))
1442 put_current_path ();
1443 put_prog_name ();
1444 return MSG_HANDLED;
1447 if ((!mc_global.tty.alternate_plus_minus
1448 || !(mc_global.tty.console_flag != '\0' || mc_global.tty.xterm_flag)) && !quote
1449 && !current_panel->searching)
1451 if (!only_leading_plus_minus)
1453 /* Special treatement, since the input line will eat them */
1454 if (parm == '+')
1456 select_cmd ();
1457 return MSG_HANDLED;
1460 if (parm == '\\' || parm == '-')
1462 unselect_cmd ();
1463 return MSG_HANDLED;
1466 if (parm == '*')
1468 select_invert_cmd ();
1469 return MSG_HANDLED;
1472 else if (!command_prompt || !cmdline->buffer[0])
1474 /* Special treatement '+', '-', '\', '*' only when this is
1475 * first char on input line
1478 if (parm == '+')
1480 select_cmd ();
1481 return MSG_HANDLED;
1484 if (parm == '\\' || parm == '-')
1486 unselect_cmd ();
1487 return MSG_HANDLED;
1490 if (parm == '*')
1492 select_invert_cmd ();
1493 return MSG_HANDLED;
1497 return MSG_NOT_HANDLED;
1499 case DLG_HOTKEY_HANDLED:
1500 if ((get_current_type () == view_listing) && current_panel->searching)
1502 current_panel->dirty = 1; /* FIXME: unneeded? */
1503 send_message ((Widget *) current_panel, WIDGET_COMMAND, CK_SearchStop);
1505 return MSG_HANDLED;
1507 case DLG_UNHANDLED_KEY:
1508 if (command_prompt)
1510 cb_ret_t v;
1512 v = send_message ((Widget *) cmdline, WIDGET_KEY, parm);
1513 if (v == MSG_HANDLED)
1514 return MSG_HANDLED;
1517 if (ctl_x_map_enabled)
1519 ctl_x_map_enabled = FALSE;
1520 command = keybind_lookup_keymap_command (main_x_map, parm);
1522 else
1523 command = keybind_lookup_keymap_command (main_map, parm);
1525 return (command == CK_IgnoreKey) ? MSG_NOT_HANDLED : midnight_execute_cmd (NULL, command);
1527 case DLG_POST_KEY:
1528 if (!the_menubar->is_active)
1529 update_dirty_panels ();
1530 return MSG_HANDLED;
1532 case DLG_ACTION:
1533 /* shortcut */
1534 if (sender == NULL)
1535 return midnight_execute_cmd (NULL, parm);
1536 /* message from menu */
1537 if (sender == (Widget *) the_menubar)
1538 return midnight_execute_cmd (sender, parm);
1539 /* message from buttonbar */
1540 if (sender == (Widget *) the_bar)
1542 if (data != NULL)
1543 return send_message ((Widget *) data, WIDGET_COMMAND, parm);
1544 return midnight_execute_cmd (sender, parm);
1546 return MSG_NOT_HANDLED;
1548 case DLG_END:
1549 panel_deinit ();
1550 return MSG_HANDLED;
1552 default:
1553 return default_dlg_callback (h, sender, msg, parm, data);
1557 /* --------------------------------------------------------------------------------------------- */
1558 /*** public functions ****************************************************************************/
1559 /* --------------------------------------------------------------------------------------------- */
1561 void
1562 update_menu (void)
1564 menu_set_name (left_menu, panels_layout.horizontal_split ? _("&Above") : _("&Left"));
1565 menu_set_name (right_menu, panels_layout.horizontal_split ? _("&Below") : _("&Right"));
1566 menubar_arrange (the_menubar);
1567 menubar_set_visible (the_menubar, menubar_visible);
1570 void
1571 midnight_set_buttonbar (WButtonBar * b)
1573 buttonbar_set_label (b, 1, Q_ ("ButtonBar|Help"), main_map, NULL);
1574 buttonbar_set_label (b, 2, Q_ ("ButtonBar|Menu"), main_map, NULL);
1575 buttonbar_set_label (b, 3, Q_ ("ButtonBar|View"), main_map, NULL);
1576 buttonbar_set_label (b, 4, Q_ ("ButtonBar|Edit"), main_map, NULL);
1577 buttonbar_set_label (b, 5, Q_ ("ButtonBar|Copy"), main_map, NULL);
1578 buttonbar_set_label (b, 6, Q_ ("ButtonBar|RenMov"), main_map, NULL);
1579 buttonbar_set_label (b, 7, Q_ ("ButtonBar|Mkdir"), main_map, NULL);
1580 buttonbar_set_label (b, 8, Q_ ("ButtonBar|Delete"), main_map, NULL);
1581 buttonbar_set_label (b, 9, Q_ ("ButtonBar|PullDn"), main_map, NULL);
1582 buttonbar_set_label (b, 10, Q_ ("ButtonBar|Quit"), main_map, NULL);
1585 /* --------------------------------------------------------------------------------------------- */
1587 * Load new hint and display it.
1588 * IF force is not 0, ignore the timeout.
1591 void
1592 load_hint (gboolean force)
1594 char *hint;
1596 if (the_hint->widget.owner == NULL)
1597 return;
1599 if (!mc_global.message_visible)
1601 label_set_text (the_hint, NULL);
1602 return;
1605 hint = get_random_hint (force);
1607 if (hint != NULL)
1609 if (*hint != '\0')
1610 set_hintbar (hint);
1611 g_free (hint);
1613 else
1615 char text[BUF_SMALL];
1617 g_snprintf (text, sizeof (text), _("GNU Midnight Commander %s\n"), VERSION);
1618 set_hintbar (text);
1622 /* --------------------------------------------------------------------------------------------- */
1624 void
1625 change_panel (void)
1627 input_free_completions (cmdline);
1628 dlg_one_down (midnight_dlg);
1631 /* --------------------------------------------------------------------------------------------- */
1633 /** Save current stat of directories to avoid reloading the panels
1634 * when no modifications have taken place
1636 void
1637 save_cwds_stat (void)
1639 if (panels_options.fast_reload)
1641 mc_stat (current_panel->cwd_vpath, &(current_panel->dir_stat));
1642 if (get_other_type () == view_listing)
1643 mc_stat (other_panel->cwd_vpath, &(other_panel->dir_stat));
1647 /* --------------------------------------------------------------------------------------------- */
1649 gboolean
1650 quiet_quit_cmd (void)
1652 print_last_revert = TRUE;
1653 return quit_cmd_internal (1);
1656 /* --------------------------------------------------------------------------------------------- */
1658 /** Run the main dialog that occupies the whole screen */
1659 gboolean
1660 do_nc (void)
1662 gboolean ret;
1664 dlg_colors_t midnight_colors;
1666 midnight_colors[DLG_COLOR_NORMAL] = mc_skin_color_get ("dialog", "_default_");
1667 midnight_colors[DLG_COLOR_FOCUS] = mc_skin_color_get ("dialog", "focus");
1668 midnight_colors[DLG_COLOR_HOT_NORMAL] = mc_skin_color_get ("dialog", "hotnormal");
1669 midnight_colors[DLG_COLOR_HOT_FOCUS] = mc_skin_color_get ("dialog", "hotfocus");
1670 midnight_colors[DLG_COLOR_TITLE] = mc_skin_color_get ("dialog", "title");
1672 #ifdef USE_INTERNAL_EDIT
1673 edit_stack_init ();
1674 #endif
1676 midnight_dlg = create_dlg (FALSE, 0, 0, LINES, COLS, midnight_colors, midnight_callback,
1677 "[main]", NULL, DLG_WANT_IDLE);
1679 if (mc_global.mc_run_mode == MC_RUN_FULL)
1680 setup_mc ();
1681 else
1682 setup_dummy_mc ();
1684 /* Check if we were invoked as an editor or file viewer */
1685 if (mc_global.mc_run_mode != MC_RUN_FULL)
1686 ret = mc_maybe_editor_or_viewer ();
1687 else
1689 create_panels_and_run_mc ();
1690 ret = TRUE;
1692 /* destroy_dlg destroys even current_panel->cwd_vpath, so we have to save a copy :) */
1693 if (mc_args__last_wd_file != NULL && vfs_current_is_local ())
1694 last_wd_string = vfs_path_to_str (current_panel->cwd_vpath);
1696 /* don't handle VFS timestamps for dirs opened in panels */
1697 mc_event_destroy (MCEVENT_GROUP_CORE, "vfs_timestamp");
1699 clean_dir (&panelized_panel.list, panelized_panel.count);
1702 /* Program end */
1703 mc_global.widget.midnight_shutdown = TRUE;
1704 dialog_switch_shutdown ();
1705 done_mc ();
1706 destroy_dlg (midnight_dlg);
1707 current_panel = NULL;
1709 #ifdef USE_INTERNAL_EDIT
1710 edit_stack_free ();
1711 #endif
1713 if ((quit & SUBSHELL_EXIT) == 0)
1714 clr_scr ();
1716 return ret;
1719 /* --------------------------------------------------------------------------------------------- */