Ticket #2762: mc ignores second directory argument.
[midnight-commander.git] / src / filemanager / midnight.c
blobe22ded8bde84f2b95f923c44c4d3b8e31c609407
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 #ifdef ENABLE_VFS
462 /* event helper */
463 static gboolean
464 check_panel_timestamp (const WPanel * panel, panel_view_mode_t mode, struct vfs_class *vclass,
465 vfsid id)
467 if (mode == view_listing)
469 const vfs_path_element_t *path_element;
471 path_element = vfs_path_get_by_index (panel->cwd_vpath, -1);
473 if (path_element->class != vclass)
474 return FALSE;
476 if (vfs_getid (panel->cwd_vpath) != id)
477 return FALSE;
479 return TRUE;
482 /* --------------------------------------------------------------------------------------------- */
484 /* event callback */
485 static gboolean
486 check_current_panel_timestamp (const gchar * event_group_name, const gchar * event_name,
487 gpointer init_data, gpointer data)
489 ev_vfs_stamp_create_t *event_data = (ev_vfs_stamp_create_t *) data;
491 (void) event_group_name;
492 (void) event_name;
493 (void) init_data;
495 event_data->ret =
496 check_panel_timestamp (current_panel, get_current_type (), event_data->vclass,
497 event_data->id);
498 return !event_data->ret;
501 /* --------------------------------------------------------------------------------------------- */
503 /* event callback */
504 static gboolean
505 check_other_panel_timestamp (const gchar * event_group_name, const gchar * event_name,
506 gpointer init_data, gpointer data)
508 ev_vfs_stamp_create_t *event_data = (ev_vfs_stamp_create_t *) data;
510 (void) event_group_name;
511 (void) event_name;
512 (void) init_data;
514 event_data->ret =
515 check_panel_timestamp (other_panel, get_other_type (), event_data->vclass, event_data->id);
516 return !event_data->ret;
518 #endif /* ENABLE_VFS */
520 /* --------------------------------------------------------------------------------------------- */
522 /* event callback */
523 static gboolean
524 print_vfs_message (const gchar * event_group_name, const gchar * event_name,
525 gpointer init_data, gpointer data)
527 char str[128];
528 ev_vfs_print_message_t *event_data = (ev_vfs_print_message_t *) data;
530 (void) event_group_name;
531 (void) event_name;
532 (void) init_data;
534 g_vsnprintf (str, sizeof (str), event_data->msg, event_data->ap);
536 if (mc_global.midnight_shutdown)
537 return TRUE;
539 if (!mc_global.message_visible || !the_hint || !the_hint->widget.owner)
541 int col, row;
543 if (!nice_rotating_dash || (ok_to_refresh <= 0))
544 return TRUE;
546 /* Preserve current cursor position */
547 tty_getyx (&row, &col);
549 tty_gotoyx (0, 0);
550 tty_setcolor (NORMAL_COLOR);
551 tty_print_string (str_fit_to_term (str, COLS - 1, J_LEFT));
553 /* Restore cursor position */
554 tty_gotoyx (row, col);
555 mc_refresh ();
556 return TRUE;
559 if (mc_global.message_visible)
560 set_hintbar (str);
562 return TRUE;
565 /* --------------------------------------------------------------------------------------------- */
567 static void
568 create_panels (void)
570 int current_index;
571 int other_index;
572 panel_view_mode_t current_mode, other_mode;
573 char *original_dir = NULL;
575 if (boot_current_is_left)
577 current_index = 0;
578 other_index = 1;
579 current_mode = startup_left_mode;
580 other_mode = startup_right_mode;
582 else
584 current_index = 1;
585 other_index = 0;
586 current_mode = startup_right_mode;
587 other_mode = startup_left_mode;
589 /* Creates the left panel */
590 if (mc_run_param0 != NULL)
592 vfs_path_t *vpath;
594 if (mc_run_param1 != NULL)
596 /* Ok, user has specified two dirs, save the original one,
597 * since we may not be able to chdir to the proper
598 * second directory later
600 original_dir = vfs_get_current_dir ();
602 vpath = vfs_path_from_str (mc_run_param0);
603 mc_chdir (vpath);
604 vfs_path_free (vpath);
606 set_display_type (current_index, current_mode);
608 /* The other panel */
609 if (mc_run_param1 != NULL)
611 vfs_path_t *vpath;
613 if (original_dir != NULL)
615 vpath = vfs_path_from_str (original_dir);
616 mc_chdir (vpath);
617 vfs_path_free (vpath);
620 vpath = vfs_path_from_str (mc_run_param1);
621 mc_chdir (vpath);
622 vfs_path_free (vpath);
624 g_free (original_dir);
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;
631 else
632 current_panel = left_panel;
634 #ifdef ENABLE_VFS
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 /* --------------------------------------------------------------------------------------------- */
657 static void
658 put_current_path (void)
660 char *cwd_path;
661 vfs_path_t *cwd_vpath;
663 if (!command_prompt)
664 return;
666 cwd_vpath = remove_encoding_from_path (current_panel->cwd_vpath);
667 cwd_path = vfs_path_to_str (cwd_vpath);
668 command_insert (cmdline, cwd_path, FALSE);
670 if (cwd_path[strlen (cwd_path) - 1] != PATH_SEP)
671 command_insert (cmdline, PATH_SEP_STR, FALSE);
673 g_free (cwd_path);
674 vfs_path_free (cwd_vpath);
677 /* --------------------------------------------------------------------------------------------- */
679 static void
680 put_other_path (void)
682 char *cwd_path;
683 vfs_path_t *cwd_vpath;
685 if (get_other_type () != view_listing)
686 return;
688 if (!command_prompt)
689 return;
691 cwd_vpath = remove_encoding_from_path (other_panel->cwd_vpath);
692 cwd_path = vfs_path_to_str (cwd_vpath);
693 command_insert (cmdline, cwd_path, FALSE);
695 if (cwd_path[strlen (cwd_path) - 1] != PATH_SEP)
696 command_insert (cmdline, PATH_SEP_STR, FALSE);
698 g_free (cwd_path);
699 vfs_path_free (cwd_vpath);
702 /* --------------------------------------------------------------------------------------------- */
704 static void
705 put_link (WPanel * panel)
707 if (!command_prompt)
708 return;
709 if (S_ISLNK (selection (panel)->st.st_mode))
711 char buffer[MC_MAXPATHLEN];
712 vfs_path_t *vpath;
713 int i;
715 vpath = vfs_path_append_new (panel->cwd_vpath, selection (panel)->fname, NULL);
716 i = mc_readlink (vpath, buffer, MC_MAXPATHLEN - 1);
717 vfs_path_free (vpath);
719 if (i > 0)
721 buffer[i] = '\0';
722 command_insert (cmdline, buffer, TRUE);
727 /* --------------------------------------------------------------------------------------------- */
729 static void
730 put_current_link (void)
732 put_link (current_panel);
735 /* --------------------------------------------------------------------------------------------- */
737 static void
738 put_other_link (void)
740 if (get_other_type () == view_listing)
741 put_link (other_panel);
744 /* --------------------------------------------------------------------------------------------- */
746 /** Insert the selected file name into the input line */
747 static void
748 put_prog_name (void)
750 char *tmp;
751 if (!command_prompt)
752 return;
754 if (get_current_type () == view_tree)
756 WTree *tree = (WTree *) get_panel_widget (get_current_index ());
758 tmp = vfs_path_to_str (tree_selected_name (tree));
760 else
761 tmp = g_strdup (selection (current_panel)->fname);
763 command_insert (cmdline, tmp, TRUE);
764 g_free (tmp);
767 /* --------------------------------------------------------------------------------------------- */
769 static void
770 put_tagged (WPanel * panel)
772 int i;
774 if (!command_prompt)
775 return;
776 input_disable_update (cmdline);
777 if (panel->marked)
779 for (i = 0; i < panel->count; i++)
781 if (panel->dir.list[i].f.marked)
782 command_insert (cmdline, panel->dir.list[i].fname, TRUE);
785 else
787 command_insert (cmdline, panel->dir.list[panel->selected].fname, TRUE);
789 input_enable_update (cmdline);
792 /* --------------------------------------------------------------------------------------------- */
794 static void
795 put_current_tagged (void)
797 put_tagged (current_panel);
800 /* --------------------------------------------------------------------------------------------- */
802 static void
803 put_other_tagged (void)
805 if (get_other_type () == view_listing)
806 put_tagged (other_panel);
809 /* --------------------------------------------------------------------------------------------- */
811 static void
812 ctl_x_cmd (void)
814 ctl_x_map_enabled = TRUE;
817 /* --------------------------------------------------------------------------------------------- */
819 static void
820 setup_mc (void)
822 #ifdef HAVE_SLANG
823 #ifdef HAVE_CHARSET
824 tty_display_8bit (TRUE);
825 #else
826 tty_display_8bit (mc_global.full_eight_bits != 0);
827 #endif /* HAVE_CHARSET */
829 #else /* HAVE_SLANG */
831 #ifdef HAVE_CHARSET
832 tty_display_8bit (TRUE);
833 #else
834 tty_display_8bit (mc_global.eight_bit_clean != 0);
835 #endif /* HAVE_CHARSET */
836 #endif /* HAVE_SLANG */
838 #ifdef HAVE_SUBSHELL_SUPPORT
839 if (mc_global.tty.use_subshell)
840 add_select_channel (mc_global.tty.subshell_pty, load_prompt, 0);
841 #endif /* !HAVE_SUBSHELL_SUPPORT */
843 if ((tty_baudrate () < 9600) || mc_global.tty.slow_terminal)
844 verbose = 0;
847 /* --------------------------------------------------------------------------------------------- */
849 static void
850 setup_dummy_mc (void)
852 vfs_path_t *vpath;
853 char *d;
854 int ret;
856 d = _vfs_get_cwd ();
857 setup_mc ();
858 vpath = vfs_path_from_str (d);
859 ret = mc_chdir (vpath);
860 vfs_path_free (vpath);
861 g_free (d);
864 /* --------------------------------------------------------------------------------------------- */
866 static void
867 done_mc (void)
869 /* Setup shutdown
871 * We sync the profiles since the hotlist may have changed, while
872 * we only change the setup data if we have the auto save feature set
874 char *curr_dir;
876 save_setup (auto_save_setup, panels_options.auto_save_setup);
878 curr_dir = vfs_get_current_dir ();
879 vfs_stamp_path (curr_dir);
880 g_free (curr_dir);
882 if ((current_panel != NULL) && (get_current_type () == view_listing))
884 char *tmp_path;
886 tmp_path = vfs_path_to_str (current_panel->cwd_vpath);
887 vfs_stamp_path (tmp_path);
888 g_free (tmp_path);
891 if ((other_panel != NULL) && (get_other_type () == view_listing))
893 char *tmp_path;
895 tmp_path = vfs_path_to_str (other_panel->cwd_vpath);
896 vfs_stamp_path (tmp_path);
897 g_free (tmp_path);
901 /* --------------------------------------------------------------------------------------------- */
903 static void
904 create_panels_and_run_mc (void)
906 midnight_dlg->get_shortcut = midnight_get_shortcut;
907 midnight_dlg->get_title = midnight_get_title;
909 create_panels ();
911 add_widget (midnight_dlg, the_menubar);
912 init_menu ();
914 add_widget (midnight_dlg, get_panel_widget (0));
915 add_widget (midnight_dlg, get_panel_widget (1));
917 add_widget (midnight_dlg, the_hint);
918 add_widget (midnight_dlg, cmdline);
919 add_widget (midnight_dlg, the_prompt);
921 add_widget (midnight_dlg, the_bar);
922 midnight_set_buttonbar (the_bar);
924 /* Run the Midnight Commander if no file was specified in the command line */
925 run_dlg (midnight_dlg);
928 /* --------------------------------------------------------------------------------------------- */
930 /** result must be free'd (I think this should go in util.c) */
931 static vfs_path_t *
932 prepend_cwd_on_local (const char *filename)
934 vfs_path_t *vpath;
936 vpath = vfs_path_from_str (filename);
937 if (!vfs_file_is_local (vpath) || g_path_is_absolute (filename))
938 return vpath;
940 vfs_path_free (vpath);
942 return vfs_path_append_new (vfs_get_raw_current_dir (), filename, NULL);
945 /* --------------------------------------------------------------------------------------------- */
947 /** Invoke the internal view/edit routine with:
948 * the default processing and forcing the internal viewer/editor
950 static gboolean
951 mc_maybe_editor_or_viewer (void)
953 int ret;
955 switch (mc_global.mc_run_mode)
957 #ifdef USE_INTERNAL_EDIT
958 case MC_RUN_EDITOR:
960 vfs_path_t *param_vpath;
962 param_vpath = vfs_path_from_str (mc_run_param0);
963 ret = edit_file (param_vpath, mc_args__edit_start_line);
964 vfs_path_free (param_vpath);
966 break;
967 #endif /* USE_INTERNAL_EDIT */
968 case MC_RUN_VIEWER:
970 vfs_path_t *vpath;
972 vpath = prepend_cwd_on_local (mc_run_param0);
973 view_file (vpath, 0, 1);
974 vfs_path_free (vpath);
975 ret = 1;
976 break;
978 #ifdef USE_DIFF_VIEW
979 case MC_RUN_DIFFVIEWER:
980 ret = diff_view (mc_run_param0, mc_run_param1, mc_run_param0, mc_run_param1);
981 break;
982 #endif /* USE_DIFF_VIEW */
983 default:
984 ret = 0;
987 return (ret != 0);
990 /* --------------------------------------------------------------------------------------------- */
992 static gboolean
993 quit_cmd_internal (int quiet)
995 int q = quit;
996 size_t n;
998 n = dialog_switch_num () - 1;
999 if (n != 0)
1001 char msg[BUF_MEDIUM];
1003 g_snprintf (msg, sizeof (msg),
1004 ngettext ("You have %zd opened screen. Quit anyway?",
1005 "You have %zd opened screens. Quit anyway?", n), n);
1007 if (query_dialog (_("The Midnight Commander"), msg, D_NORMAL, 2, _("&Yes"), _("&No")) != 0)
1008 return FALSE;
1009 q = 1;
1011 else if (quiet || !confirm_exit)
1012 q = 1;
1013 else if (query_dialog (_("The Midnight Commander"),
1014 _("Do you really want to quit the Midnight Commander?"),
1015 D_NORMAL, 2, _("&Yes"), _("&No")) == 0)
1016 q = 1;
1018 if (q != 0)
1020 #ifdef HAVE_SUBSHELL_SUPPORT
1021 if (!mc_global.tty.use_subshell)
1022 stop_dialogs ();
1023 else if ((q = exit_subshell ()))
1024 #endif
1025 stop_dialogs ();
1028 if (q != 0)
1029 quit |= 1;
1030 return (quit != 0);
1033 /* --------------------------------------------------------------------------------------------- */
1035 static gboolean
1036 quit_cmd (void)
1038 return quit_cmd_internal (0);
1041 /* --------------------------------------------------------------------------------------------- */
1043 static void
1044 toggle_show_hidden (void)
1046 panels_options.show_dot_files = !panels_options.show_dot_files;
1047 update_panels (UP_RELOAD, UP_KEEPSEL);
1050 /* --------------------------------------------------------------------------------------------- */
1053 * Repaint the contents of the panels without frames. To schedule panel
1054 * for repainting, set panel->dirty to 1. There are many reasons why
1055 * the panels need to be repainted, and this is a costly operation, so
1056 * it's done once per event.
1059 static void
1060 update_dirty_panels (void)
1062 if (get_current_type () == view_listing && current_panel->dirty)
1063 send_message ((Widget *) current_panel, WIDGET_DRAW, 0);
1065 if (get_other_type () == view_listing && other_panel->dirty)
1066 send_message ((Widget *) other_panel, WIDGET_DRAW, 0);
1069 /* --------------------------------------------------------------------------------------------- */
1071 static cb_ret_t
1072 midnight_execute_cmd (Widget * sender, unsigned long command)
1074 cb_ret_t res = MSG_HANDLED;
1076 (void) sender;
1078 /* stop quick search before executing any command */
1079 send_message ((Widget *) current_panel, WIDGET_COMMAND, CK_SearchStop);
1081 switch (command)
1083 case CK_HotListAdd:
1084 add2hotlist_cmd ();
1085 break;
1086 case CK_PanelListingChange:
1087 change_listing_cmd ();
1088 break;
1089 case CK_ChangeMode:
1090 chmod_cmd ();
1091 break;
1092 case CK_ChangeOwn:
1093 chown_cmd ();
1094 break;
1095 case CK_ChangeOwnAdvanced:
1096 chown_advanced_cmd ();
1097 break;
1098 case CK_CompareDirs:
1099 compare_dirs_cmd ();
1100 break;
1101 case CK_Options:
1102 configure_box ();
1103 break;
1104 #ifdef ENABLE_VFS
1105 case CK_OptionsVfs:
1106 configure_vfs ();
1107 break;
1108 #endif
1109 case CK_OptionsConfirm:
1110 confirm_box ();
1111 break;
1112 case CK_Copy:
1113 copy_cmd ();
1114 break;
1115 case CK_PutCurrentPath:
1116 put_current_path ();
1117 break;
1118 case CK_PutCurrentLink:
1119 put_current_link ();
1120 break;
1121 case CK_PutCurrentTagged:
1122 put_current_tagged ();
1123 break;
1124 case CK_PutOtherPath:
1125 put_other_path ();
1126 break;
1127 case CK_PutOtherLink:
1128 put_other_link ();
1129 break;
1130 case CK_PutOtherTagged:
1131 put_other_tagged ();
1132 break;
1133 case CK_Delete:
1134 delete_cmd ();
1135 break;
1136 case CK_ScreenList:
1137 dialog_switch_list ();
1138 break;
1139 #ifdef USE_DIFF_VIEW
1140 case CK_CompareFiles:
1141 diff_view_cmd ();
1142 break;
1143 #endif
1144 case CK_OptionsDisplayBits:
1145 display_bits_box ();
1146 break;
1147 case CK_Edit:
1148 edit_cmd ();
1149 break;
1150 #ifdef USE_INTERNAL_EDIT
1151 case CK_EditForceInternal:
1152 edit_cmd_force_internal ();
1153 break;
1154 #endif
1155 case CK_EditExtensionsFile:
1156 ext_cmd ();
1157 break;
1158 case CK_EditFileHighlightFile:
1159 edit_fhl_cmd ();
1160 break;
1161 case CK_EditUserMenu:
1162 edit_mc_menu_cmd ();
1163 break;
1164 case CK_LinkSymbolicEdit:
1165 edit_symlink_cmd ();
1166 break;
1167 case CK_ExternalPanelize:
1168 external_panelize ();
1169 break;
1170 case CK_Filter:
1171 filter_cmd ();
1172 break;
1173 case CK_ViewFiltered:
1174 view_filtered_cmd ();
1175 break;
1176 case CK_Find:
1177 find_cmd ();
1178 break;
1179 #ifdef ENABLE_VFS_FISH
1180 case CK_ConnectFish:
1181 fishlink_cmd ();
1182 break;
1183 #endif
1184 #ifdef ENABLE_VFS_FTP
1185 case CK_ConnectFtp:
1186 ftplink_cmd ();
1187 break;
1188 #endif
1189 #ifdef ENABLE_VFS_SMB
1190 case CK_ConnectSmb:
1191 smblink_cmd ();
1192 break;
1193 #endif /* ENABLE_VFS_SMB */
1194 case CK_Panelize:
1195 cd_panelize_cmd ();
1196 break;
1197 case CK_Help:
1198 help_cmd ();
1199 break;
1200 case CK_History:
1201 /* show the history of command line widget */
1202 send_message (&cmdline->widget, WIDGET_COMMAND, CK_History);
1203 break;
1204 case CK_PanelInfo:
1205 if (sender == (Widget *) the_menubar)
1206 info_cmd (); /* menu */
1207 else
1208 info_cmd_no_menu (); /* shortcut or buttonbar */
1209 break;
1210 #ifdef ENABLE_BACKGROUND
1211 case CK_Jobs:
1212 jobs_cmd ();
1213 break;
1214 #endif
1215 case CK_OptionsLayout:
1216 layout_box ();
1217 break;
1218 case CK_LearnKeys:
1219 learn_keys ();
1220 break;
1221 case CK_Link:
1222 link_cmd (LINK_HARDLINK);
1223 break;
1224 case CK_PanelListing:
1225 listing_cmd ();
1226 break;
1227 #ifdef LISTMODE_EDITOR
1228 case CK_ListMode:
1229 listmode_cmd ();
1230 break;
1231 #endif
1232 case CK_Menu:
1233 menu_cmd ();
1234 break;
1235 case CK_MenuLastSelected:
1236 menu_last_selected_cmd ();
1237 break;
1238 case CK_MakeDir:
1239 mkdir_cmd ();
1240 break;
1241 case CK_OptionsPanel:
1242 panel_options_box ();
1243 break;
1244 #ifdef HAVE_CHARSET
1245 case CK_SelectCodepage:
1246 encoding_cmd ();
1247 break;
1248 #endif
1249 case CK_CdQuick:
1250 quick_cd_cmd ();
1251 break;
1252 case CK_HotList:
1253 hotlist_cmd ();
1254 break;
1255 case CK_PanelQuickView:
1256 if (sender == (Widget *) the_menubar)
1257 quick_view_cmd (); /* menu */
1258 else
1259 quick_cmd_no_menu (); /* shortcut or buttonabr */
1260 break;
1261 case CK_QuitQuiet:
1262 quiet_quit_cmd ();
1263 break;
1264 case CK_Quit:
1265 quit_cmd ();
1266 break;
1267 case CK_LinkSymbolicRelative:
1268 link_cmd (LINK_SYMLINK_RELATIVE);
1269 break;
1270 case CK_Move:
1271 rename_cmd ();
1272 break;
1273 case CK_Reread:
1274 reread_cmd ();
1275 break;
1276 #ifdef ENABLE_VFS
1277 case CK_VfsList:
1278 vfs_list ();
1279 break;
1280 #endif
1281 case CK_SelectInvert:
1282 select_invert_cmd ();
1283 break;
1284 case CK_SaveSetup:
1285 save_setup_cmd ();
1286 break;
1287 case CK_Select:
1288 select_cmd ();
1289 break;
1290 case CK_Shell:
1291 view_other_cmd ();
1292 break;
1293 case CK_DirSize:
1294 smart_dirsize_cmd ();
1295 break;
1296 case CK_Sort:
1297 sort_cmd ();
1298 break;
1299 case CK_ExtendedKeyMap:
1300 ctl_x_cmd ();
1301 break;
1302 case CK_Suspend:
1303 mc_event_raise (MCEVENT_GROUP_CORE, "suspend", NULL);
1304 break;
1305 case CK_Swap:
1306 swap_cmd ();
1307 break;
1308 case CK_LinkSymbolic:
1309 link_cmd (LINK_SYMLINK_ABSOLUTE);
1310 break;
1311 case CK_PanelListingSwitch:
1312 toggle_listing_cmd ();
1313 break;
1314 case CK_ShowHidden:
1315 toggle_show_hidden ();
1316 break;
1317 case CK_SplitVertHoriz:
1318 toggle_panels_split ();
1319 break;
1320 case CK_PanelTree:
1321 panel_tree_cmd ();
1322 break;
1323 case CK_Tree:
1324 treebox_cmd ();
1325 break;
1326 #ifdef ENABLE_VFS_UNDELFS
1327 case CK_Undelete:
1328 undelete_cmd ();
1329 break;
1330 #endif
1331 case CK_Unselect:
1332 unselect_cmd ();
1333 break;
1334 case CK_UserMenu:
1335 user_file_menu_cmd ();
1336 break;
1337 case CK_View:
1338 view_cmd ();
1339 break;
1340 case CK_ViewFile:
1341 view_file_cmd ();
1342 break;
1343 case CK_Cancel:
1344 /* don't close panels due to SIGINT */
1345 break;
1346 default:
1347 res = MSG_NOT_HANDLED;
1350 return res;
1353 /* --------------------------------------------------------------------------------------------- */
1355 static cb_ret_t
1356 midnight_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
1358 unsigned long command;
1360 switch (msg)
1362 case DLG_INIT:
1363 panel_init ();
1364 setup_panels ();
1365 return MSG_HANDLED;
1367 case DLG_DRAW:
1368 load_hint (1);
1369 /* We handle the special case of the output lines */
1370 if (mc_global.tty.console_flag != '\0' && output_lines)
1371 show_console_contents (output_start_y,
1372 LINES - output_lines - mc_global.keybar_visible -
1373 1, LINES - mc_global.keybar_visible - 1);
1374 return MSG_HANDLED;
1376 case DLG_RESIZE:
1377 setup_panels ();
1378 menubar_arrange (the_menubar);
1379 return MSG_HANDLED;
1381 case DLG_IDLE:
1382 /* We only need the first idle event to show user menu after start */
1383 set_idle_proc (h, 0);
1385 if (boot_current_is_left)
1386 dlg_select_widget (get_panel_widget (0));
1387 else
1388 dlg_select_widget (get_panel_widget (1));
1390 if (auto_menu)
1391 midnight_execute_cmd (NULL, CK_UserMenu);
1392 return MSG_HANDLED;
1394 case DLG_KEY:
1395 if (ctl_x_map_enabled)
1397 ctl_x_map_enabled = FALSE;
1398 command = keybind_lookup_keymap_command (main_x_map, parm);
1399 if (command != CK_IgnoreKey)
1400 return midnight_execute_cmd (NULL, command);
1403 /* FIXME: should handle all menu shortcuts before this point */
1404 if (the_menubar->is_active)
1405 return MSG_NOT_HANDLED;
1407 if (parm == '\t')
1408 input_free_completions (cmdline);
1410 if (parm == '\n')
1412 size_t i;
1414 for (i = 0; cmdline->buffer[i] != '\0' &&
1415 (cmdline->buffer[i] == ' ' || cmdline->buffer[i] == '\t'); i++)
1418 if (cmdline->buffer[i] != '\0')
1420 send_message ((Widget *) cmdline, WIDGET_KEY, parm);
1421 return MSG_HANDLED;
1424 input_insert (cmdline, "", FALSE);
1425 cmdline->point = 0;
1428 /* Ctrl-Enter and Alt-Enter */
1429 if (((parm & ~(KEY_M_CTRL | KEY_M_ALT)) == '\n') && (parm & (KEY_M_CTRL | KEY_M_ALT)))
1431 put_prog_name ();
1432 return MSG_HANDLED;
1435 /* Ctrl-Shift-Enter */
1436 if (parm == (KEY_M_CTRL | KEY_M_SHIFT | '\n'))
1438 put_current_path ();
1439 put_prog_name ();
1440 return MSG_HANDLED;
1443 if ((!mc_global.tty.alternate_plus_minus
1444 || !(mc_global.tty.console_flag != '\0' || mc_global.tty.xterm_flag)) && !quote
1445 && !current_panel->searching)
1447 if (!only_leading_plus_minus)
1449 /* Special treatement, since the input line will eat them */
1450 if (parm == '+')
1452 select_cmd ();
1453 return MSG_HANDLED;
1456 if (parm == '\\' || parm == '-')
1458 unselect_cmd ();
1459 return MSG_HANDLED;
1462 if (parm == '*')
1464 select_invert_cmd ();
1465 return MSG_HANDLED;
1468 else if (!command_prompt || !cmdline->buffer[0])
1470 /* Special treatement '+', '-', '\', '*' only when this is
1471 * first char on input line
1474 if (parm == '+')
1476 select_cmd ();
1477 return MSG_HANDLED;
1480 if (parm == '\\' || parm == '-')
1482 unselect_cmd ();
1483 return MSG_HANDLED;
1486 if (parm == '*')
1488 select_invert_cmd ();
1489 return MSG_HANDLED;
1493 return MSG_NOT_HANDLED;
1495 case DLG_HOTKEY_HANDLED:
1496 if ((get_current_type () == view_listing) && current_panel->searching)
1498 current_panel->dirty = 1; /* FIXME: unneeded? */
1499 send_message ((Widget *) current_panel, WIDGET_COMMAND, CK_SearchStop);
1501 return MSG_HANDLED;
1503 case DLG_UNHANDLED_KEY:
1505 cb_ret_t v = MSG_NOT_HANDLED;
1507 if (ctl_x_map_enabled)
1509 ctl_x_map_enabled = FALSE;
1510 command = keybind_lookup_keymap_command (main_x_map, parm);
1512 else
1513 command = keybind_lookup_keymap_command (main_map, parm);
1515 if (command != CK_IgnoreKey)
1516 v = midnight_execute_cmd (NULL, command);
1518 if (v == MSG_NOT_HANDLED && command_prompt)
1519 v = send_message ((Widget *) cmdline, WIDGET_KEY, parm);
1521 return v;
1524 case DLG_POST_KEY:
1525 if (!the_menubar->is_active)
1526 update_dirty_panels ();
1527 return MSG_HANDLED;
1529 case DLG_ACTION:
1530 /* shortcut */
1531 if (sender == NULL)
1532 return midnight_execute_cmd (NULL, parm);
1533 /* message from menu */
1534 if (sender == (Widget *) the_menubar)
1535 return midnight_execute_cmd (sender, parm);
1536 /* message from buttonbar */
1537 if (sender == (Widget *) the_bar)
1539 if (data != NULL)
1540 return send_message ((Widget *) data, WIDGET_COMMAND, parm);
1541 return midnight_execute_cmd (sender, parm);
1543 return MSG_NOT_HANDLED;
1545 case DLG_END:
1546 panel_deinit ();
1547 return MSG_HANDLED;
1549 default:
1550 return default_dlg_callback (h, sender, msg, parm, data);
1554 /* --------------------------------------------------------------------------------------------- */
1555 /*** public functions ****************************************************************************/
1556 /* --------------------------------------------------------------------------------------------- */
1558 void
1559 update_menu (void)
1561 menu_set_name (left_menu, panels_layout.horizontal_split ? _("&Above") : _("&Left"));
1562 menu_set_name (right_menu, panels_layout.horizontal_split ? _("&Below") : _("&Right"));
1563 menubar_arrange (the_menubar);
1564 menubar_set_visible (the_menubar, menubar_visible);
1567 void
1568 midnight_set_buttonbar (WButtonBar * b)
1570 buttonbar_set_label (b, 1, Q_ ("ButtonBar|Help"), main_map, NULL);
1571 buttonbar_set_label (b, 2, Q_ ("ButtonBar|Menu"), main_map, NULL);
1572 buttonbar_set_label (b, 3, Q_ ("ButtonBar|View"), main_map, NULL);
1573 buttonbar_set_label (b, 4, Q_ ("ButtonBar|Edit"), main_map, NULL);
1574 buttonbar_set_label (b, 5, Q_ ("ButtonBar|Copy"), main_map, NULL);
1575 buttonbar_set_label (b, 6, Q_ ("ButtonBar|RenMov"), main_map, NULL);
1576 buttonbar_set_label (b, 7, Q_ ("ButtonBar|Mkdir"), main_map, NULL);
1577 buttonbar_set_label (b, 8, Q_ ("ButtonBar|Delete"), main_map, NULL);
1578 buttonbar_set_label (b, 9, Q_ ("ButtonBar|PullDn"), main_map, NULL);
1579 buttonbar_set_label (b, 10, Q_ ("ButtonBar|Quit"), main_map, NULL);
1582 /* --------------------------------------------------------------------------------------------- */
1584 * Load new hint and display it.
1585 * IF force is not 0, ignore the timeout.
1588 void
1589 load_hint (gboolean force)
1591 char *hint;
1593 if (the_hint->widget.owner == NULL)
1594 return;
1596 if (!mc_global.message_visible)
1598 label_set_text (the_hint, NULL);
1599 return;
1602 hint = get_random_hint (force);
1604 if (hint != NULL)
1606 if (*hint != '\0')
1607 set_hintbar (hint);
1608 g_free (hint);
1610 else
1612 char text[BUF_SMALL];
1614 g_snprintf (text, sizeof (text), _("GNU Midnight Commander %s\n"), VERSION);
1615 set_hintbar (text);
1619 /* --------------------------------------------------------------------------------------------- */
1621 void
1622 change_panel (void)
1624 input_free_completions (cmdline);
1625 dlg_one_down (midnight_dlg);
1628 /* --------------------------------------------------------------------------------------------- */
1630 /** Save current stat of directories to avoid reloading the panels
1631 * when no modifications have taken place
1633 void
1634 save_cwds_stat (void)
1636 if (panels_options.fast_reload)
1638 mc_stat (current_panel->cwd_vpath, &(current_panel->dir_stat));
1639 if (get_other_type () == view_listing)
1640 mc_stat (other_panel->cwd_vpath, &(other_panel->dir_stat));
1644 /* --------------------------------------------------------------------------------------------- */
1646 gboolean
1647 quiet_quit_cmd (void)
1649 print_last_revert = TRUE;
1650 return quit_cmd_internal (1);
1653 /* --------------------------------------------------------------------------------------------- */
1655 /** Run the main dialog that occupies the whole screen */
1656 gboolean
1657 do_nc (void)
1659 gboolean ret;
1661 dlg_colors_t midnight_colors;
1663 midnight_colors[DLG_COLOR_NORMAL] = mc_skin_color_get ("dialog", "_default_");
1664 midnight_colors[DLG_COLOR_FOCUS] = mc_skin_color_get ("dialog", "focus");
1665 midnight_colors[DLG_COLOR_HOT_NORMAL] = mc_skin_color_get ("dialog", "hotnormal");
1666 midnight_colors[DLG_COLOR_HOT_FOCUS] = mc_skin_color_get ("dialog", "hotfocus");
1667 midnight_colors[DLG_COLOR_TITLE] = mc_skin_color_get ("dialog", "title");
1669 #ifdef USE_INTERNAL_EDIT
1670 edit_stack_init ();
1671 #endif
1673 midnight_dlg = create_dlg (FALSE, 0, 0, LINES, COLS, midnight_colors, midnight_callback,
1674 "[main]", NULL, DLG_WANT_IDLE);
1676 if (mc_global.mc_run_mode == MC_RUN_FULL)
1677 setup_mc ();
1678 else
1679 setup_dummy_mc ();
1681 /* Check if we were invoked as an editor or file viewer */
1682 if (mc_global.mc_run_mode != MC_RUN_FULL)
1683 ret = mc_maybe_editor_or_viewer ();
1684 else
1686 create_panels_and_run_mc ();
1687 ret = TRUE;
1689 /* destroy_dlg destroys even current_panel->cwd_vpath, so we have to save a copy :) */
1690 if (mc_args__last_wd_file != NULL && vfs_current_is_local ())
1691 last_wd_string = vfs_path_to_str (current_panel->cwd_vpath);
1693 /* don't handle VFS timestamps for dirs opened in panels */
1694 mc_event_destroy (MCEVENT_GROUP_CORE, "vfs_timestamp");
1696 clean_dir (&panelized_panel.list, panelized_panel.count);
1699 /* Program end */
1700 mc_global.midnight_shutdown = TRUE;
1701 dialog_switch_shutdown ();
1702 done_mc ();
1703 destroy_dlg (midnight_dlg);
1704 current_panel = NULL;
1706 #ifdef USE_INTERNAL_EDIT
1707 edit_stack_free ();
1708 #endif
1710 if ((quit & SUBSHELL_EXIT) == 0)
1711 clr_scr ();
1713 return ret;
1716 /* --------------------------------------------------------------------------------------------- */