Moved xterm_flag global variable to mc_global.tty.xterm_flag
[midnight-commander.git] / src / filemanager / midnight.c
blob5e5645b231e4809d0f74ce788e6a7e5a761aae6d
1 /* Main dialog (file panels) of the Midnight Commander
2 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003, 2004, 2005, 2006, 2007, 2009, 2010 Free Software Foundation, Inc.
5 Written by: 1994, 1995, 1996, 1997 Miguel de Icaza
6 1994, 1995 Janne Kukonlehto
7 1997 Norbert Warmuth
8 2009, 2010 Andrew Borodin
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
24 /** \file main.c
25 * \brief Source: main dialog (file panels) of the Midnight Commander
28 #include <config.h>
30 #include <ctype.h>
31 #include <errno.h>
32 #include <locale.h>
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <string.h>
36 #include <fcntl.h>
37 #include <sys/types.h>
38 #include <sys/stat.h>
39 #include <sys/wait.h>
40 #include <pwd.h> /* for username in xterm title */
42 #include "lib/global.h"
44 #include "lib/tty/tty.h"
45 #include "lib/tty/key.h" /* KEY_M_* masks */
46 #include "lib/skin.h"
47 #include "lib/util.h"
49 #include "lib/vfs/vfs.h"
51 #include "src/args.h"
52 #include "src/subshell.h"
53 #include "src/setup.h" /* variables */
54 #include "src/learn.h" /* learn_keys() */
55 #include "src/keybind-defaults.h"
56 #include "lib/keybind.h"
57 #include "lib/event.h"
59 #include "option.h" /* configure_box() */
60 #include "tree.h"
61 #include "boxes.h" /* sort_box(), tree_box() */
62 #include "layout.h"
63 #include "cmd.h" /* commands */
64 #include "hotlist.h"
65 #include "panelize.h"
66 #include "command.h" /* cmdline */
68 #include "chmod.h"
69 #include "chown.h"
70 #include "achown.h"
72 #ifdef USE_INTERNAL_EDIT
73 #include "src/editor/edit.h"
74 #endif
76 #ifdef USE_DIFF_VIEW
77 #include "src/diffviewer/ydiff.h"
78 #endif
80 #include "src/consaver/cons.saver.h" /* show_console_contents */
82 #include "midnight.h"
84 /* TODO: merge content of layout.c here */
85 extern int ok_to_refresh;
87 /*** global variables ****************************************************************************/
89 /* When the modes are active, left_panel, right_panel and tree_panel */
90 /* point to a proper data structure. You should check with the functions */
91 /* get_current_type and get_other_type the types of the panels before using */
92 /* this pointer variables */
94 /* The structures for the panels */
95 WPanel *left_panel = NULL;
96 WPanel *right_panel = NULL;
97 /* Pointer to the selected and unselected panel */
98 WPanel *current_panel = NULL;
100 /* The Menubar */
101 WMenuBar *the_menubar = NULL;
102 /* The widget where we draw the prompt */
103 WLabel *the_prompt;
104 /* The hint bar */
105 WLabel *the_hint;
106 /* The button bar */
107 WButtonBar *the_bar;
109 /*** file scope macro definitions ****************************************************************/
111 #ifdef HAVE_CHARSET
113 * Don't restrict the output on the screen manager level,
114 * the translation tables take care of it.
116 #endif /* !HAVE_CHARSET */
118 /*** file scope type declarations ****************************************************************/
120 /*** file scope variables ************************************************************************/
122 static Menu *left_menu, *right_menu;
124 static gboolean ctl_x_map_enabled = FALSE;
126 /*** file scope functions ************************************************************************/
128 /** Stop MC main dialog and the current dialog if it exists.
129 * Needed to provide fast exit from MC viewer or editor on shell exit */
130 static void
131 stop_dialogs (void)
133 midnight_dlg->state = DLG_CLOSED;
135 if ((top_dlg != NULL) && (top_dlg->data != NULL))
136 ((Dlg_head *) top_dlg->data)->state = DLG_CLOSED;
139 /* --------------------------------------------------------------------------------------------- */
141 static void
142 treebox_cmd (void)
144 char *sel_dir;
146 sel_dir = tree_box (selection (current_panel)->fname);
147 if (sel_dir)
149 do_cd (sel_dir, cd_exact);
150 g_free (sel_dir);
154 /* --------------------------------------------------------------------------------------------- */
156 #ifdef LISTMODE_EDITOR
157 static void
158 listmode_cmd (void)
160 char *newmode;
162 if (get_current_type () != view_listing)
163 return;
165 newmode = listmode_edit (current_panel->user_format);
166 if (!newmode)
167 return;
169 g_free (current_panel->user_format);
170 current_panel->list_type = list_user;
171 current_panel->user_format = newmode;
172 set_panel_formats (current_panel);
174 do_refresh ();
176 #endif /* LISTMODE_EDITOR */
178 /* --------------------------------------------------------------------------------------------- */
180 static GList *
181 create_panel_menu (void)
183 GList *entries = NULL;
185 entries = g_list_append (entries, menu_entry_create (_("File listin&g"), CK_PanelListing));
186 entries = g_list_append (entries, menu_entry_create (_("&Quick view"), CK_PanelQuickView));
187 entries = g_list_append (entries, menu_entry_create (_("&Info"), CK_PanelInfo));
188 entries = g_list_append (entries, menu_entry_create (_("&Tree"), CK_PanelTree));
189 entries = g_list_append (entries, menu_separator_create ());
190 entries =
191 g_list_append (entries, menu_entry_create (_("&Listing mode..."), CK_PanelListingChange));
192 entries = g_list_append (entries, menu_entry_create (_("&Sort order..."), CK_Sort));
193 entries = g_list_append (entries, menu_entry_create (_("&Filter..."), CK_Filter));
194 #ifdef HAVE_CHARSET
195 entries = g_list_append (entries, menu_entry_create (_("&Encoding..."), CK_SelectCodepage));
196 #endif
197 #ifdef ENABLE_VFS_NET
198 entries = g_list_append (entries, menu_separator_create ());
199 #ifdef ENABLE_VFS_FTP
200 entries = g_list_append (entries, menu_entry_create (_("FT&P link..."), CK_ConnectFtp));
201 #endif
202 #ifdef ENABLE_VFS_FISH
203 entries = g_list_append (entries, menu_entry_create (_("S&hell link..."), CK_ConnectFish));
204 #endif
205 #ifdef ENABLE_VFS_SMB
206 entries = g_list_append (entries, menu_entry_create (_("SM&B link..."), CK_ConnectSmb));
207 #endif
208 #endif /* ENABLE_VFS_NET */
209 entries = g_list_append (entries, menu_separator_create ());
210 entries = g_list_append (entries, menu_entry_create (_("&Rescan"), CK_Reread));
212 return entries;
215 /* --------------------------------------------------------------------------------------------- */
217 static GList *
218 create_file_menu (void)
220 GList *entries = NULL;
222 entries = g_list_append (entries, menu_entry_create (_("&View"), CK_View));
223 entries = g_list_append (entries, menu_entry_create (_("Vie&w file..."), CK_ViewFile));
224 entries = g_list_append (entries, menu_entry_create (_("&Filtered view"), CK_ViewFiltered));
225 entries = g_list_append (entries, menu_entry_create (_("&Edit"), CK_Edit));
226 entries = g_list_append (entries, menu_entry_create (_("&Copy"), CK_Copy));
227 entries = g_list_append (entries, menu_entry_create (_("C&hmod"), CK_ChangeMode));
228 entries = g_list_append (entries, menu_entry_create (_("&Link"), CK_Link));
229 entries = g_list_append (entries, menu_entry_create (_("&Symlink"), CK_LinkSymbolic));
230 entries =
231 g_list_append (entries,
232 menu_entry_create (_("Relative symlin&k"), CK_LinkSymbolicRelative));
233 entries = g_list_append (entries, menu_entry_create (_("Edit s&ymlink"), CK_LinkSymbolicEdit));
234 entries = g_list_append (entries, menu_entry_create (_("Ch&own"), CK_ChangeOwn));
235 entries =
236 g_list_append (entries, menu_entry_create (_("&Advanced chown"), CK_ChangeOwnAdvanced));
237 entries = g_list_append (entries, menu_entry_create (_("&Rename/Move"), CK_Move));
238 entries = g_list_append (entries, menu_entry_create (_("&Mkdir"), CK_MakeDir));
239 entries = g_list_append (entries, menu_entry_create (_("&Delete"), CK_Delete));
240 entries = g_list_append (entries, menu_entry_create (_("&Quick cd"), CK_CdQuick));
241 entries = g_list_append (entries, menu_separator_create ());
242 entries = g_list_append (entries, menu_entry_create (_("Select &group"), CK_Select));
243 entries = g_list_append (entries, menu_entry_create (_("U&nselect group"), CK_Unselect));
244 entries = g_list_append (entries, menu_entry_create (_("&Invert selection"), CK_SelectInvert));
245 entries = g_list_append (entries, menu_separator_create ());
246 entries = g_list_append (entries, menu_entry_create (_("E&xit"), CK_Quit));
248 return entries;
251 /* --------------------------------------------------------------------------------------------- */
253 static GList *
254 create_command_menu (void)
256 /* I know, I'm lazy, but the tree widget when it's not running
257 * as a panel still has some problems, I have not yet finished
258 * the WTree widget port, sorry.
260 GList *entries = NULL;
262 entries = g_list_append (entries, menu_entry_create (_("&User menu"), CK_UserMenu));
263 entries = g_list_append (entries, menu_entry_create (_("&Directory tree"), CK_Tree));
264 entries = g_list_append (entries, menu_entry_create (_("&Find file"), CK_Find));
265 entries = g_list_append (entries, menu_entry_create (_("S&wap panels"), CK_Swap));
266 entries = g_list_append (entries, menu_entry_create (_("Switch &panels on/off"), CK_Shell));
267 entries =
268 g_list_append (entries, menu_entry_create (_("&Compare directories"), CK_CompareDirs));
269 #ifdef USE_DIFF_VIEW
270 entries = g_list_append (entries, menu_entry_create (_("C&ompare files"), CK_CompareFiles));
271 #endif
272 entries =
273 g_list_append (entries, menu_entry_create (_("E&xternal panelize"), CK_ExternalPanelize));
274 entries = g_list_append (entries, menu_entry_create (_("Show directory s&izes"), CK_DirSize));
275 entries = g_list_append (entries, menu_separator_create ());
276 entries = g_list_append (entries, menu_entry_create (_("Command &history"), CK_History));
277 entries = g_list_append (entries, menu_entry_create (_("Di&rectory hotlist"), CK_HotList));
278 #ifdef ENABLE_VFS
279 entries = g_list_append (entries, menu_entry_create (_("&Active VFS list"), CK_VfsList));
280 #endif
281 #ifdef WITH_BACKGROUND
282 entries = g_list_append (entries, menu_entry_create (_("&Background jobs"), CK_Jobs));
283 #endif
284 entries = g_list_append (entries, menu_entry_create (_("Screen lis&t"), CK_ScreenList));
285 entries = g_list_append (entries, menu_separator_create ());
286 #ifdef ENABLE_VFS_UNDELFS
287 entries =
288 g_list_append (entries,
289 menu_entry_create (_("&Undelete files (ext2fs only)"), CK_Undelete));
290 #endif
291 #ifdef LISTMODE_EDITOR
292 entries = g_list_append (entries, menu_entry_create (_("&Listing format edit"), CK_ListMode));
293 #endif
294 #if defined (ENABLE_VFS_UNDELFS) || defined (LISTMODE_EDITOR)
295 entries = g_list_append (entries, menu_separator_create ());
296 #endif
297 entries =
298 g_list_append (entries,
299 menu_entry_create (_("Edit &extension file"), CK_EditExtensionsFile));
300 entries = g_list_append (entries, menu_entry_create (_("Edit &menu file"), CK_EditUserMenu));
301 entries =
302 g_list_append (entries,
303 menu_entry_create (_("Edit hi&ghlighting group file"),
304 CK_EditFileHighlightFile));
306 return entries;
309 /* --------------------------------------------------------------------------------------------- */
311 static GList *
312 create_options_menu (void)
314 GList *entries = NULL;
316 entries = g_list_append (entries, menu_entry_create (_("&Configuration..."), CK_Options));
317 entries = g_list_append (entries, menu_entry_create (_("&Layout..."), CK_OptionsLayout));
318 entries = g_list_append (entries, menu_entry_create (_("&Panel options..."), CK_OptionsPanel));
319 entries = g_list_append (entries, menu_entry_create (_("C&onfirmation..."), CK_OptionsConfirm));
320 entries =
321 g_list_append (entries, menu_entry_create (_("&Display bits..."), CK_OptionsDisplayBits));
322 entries = g_list_append (entries, menu_entry_create (_("Learn &keys..."), CK_LearnKeys));
323 #ifdef ENABLE_VFS
324 entries = g_list_append (entries, menu_entry_create (_("&Virtual FS..."), CK_OptionsVfs));
325 #endif
326 entries = g_list_append (entries, menu_separator_create ());
327 entries = g_list_append (entries, menu_entry_create (_("&Save setup"), CK_SaveSetup));
329 return entries;
332 /* --------------------------------------------------------------------------------------------- */
334 static void
335 init_menu (void)
337 left_menu = create_menu ("", create_panel_menu (), "[Left and Right Menus]");
338 menubar_add_menu (the_menubar, left_menu);
339 menubar_add_menu (the_menubar, create_menu (_("&File"), create_file_menu (), "[File Menu]"));
340 menubar_add_menu (the_menubar,
341 create_menu (_("&Command"), create_command_menu (), "[Command Menu]"));
342 menubar_add_menu (the_menubar,
343 create_menu (_("&Options"), create_options_menu (), "[Options Menu]"));
344 right_menu = create_menu ("", create_panel_menu (), "[Left and Right Menus]");
345 menubar_add_menu (the_menubar, right_menu);
346 update_menu ();
349 /* --------------------------------------------------------------------------------------------- */
351 static void
352 menu_last_selected_cmd (void)
354 the_menubar->is_active = TRUE;
355 the_menubar->is_dropped = (drop_menus != 0);
356 the_menubar->previous_widget = dlg_get_current_widget_id (midnight_dlg);
357 dlg_select_widget (the_menubar);
360 /* --------------------------------------------------------------------------------------------- */
362 static void
363 menu_cmd (void)
365 if (the_menubar->is_active)
366 return;
368 if ((get_current_index () == 0) == (current_panel->active != 0))
369 the_menubar->selected = 0;
370 else
371 the_menubar->selected = g_list_length (the_menubar->menu) - 1;
372 menu_last_selected_cmd ();
375 /* --------------------------------------------------------------------------------------------- */
377 static void
378 sort_cmd (void)
380 WPanel *p;
381 const panel_field_t *sort_order;
383 if (!SELECTED_IS_PANEL)
384 return;
386 p = MENU_PANEL;
387 sort_order = sort_box (&p->sort_info);
388 panel_set_sort_order (p, sort_order);
391 /* --------------------------------------------------------------------------------------------- */
393 static char *
394 midnight_get_shortcut (unsigned long command)
396 const char *ext_map;
397 const char *shortcut = NULL;
399 shortcut = keybind_lookup_keymap_shortcut (main_map, command);
400 if (shortcut != NULL)
401 return g_strdup (shortcut);
403 shortcut = keybind_lookup_keymap_shortcut (panel_map, command);
404 if (shortcut != NULL)
405 return g_strdup (shortcut);
407 ext_map = keybind_lookup_keymap_shortcut (main_map, CK_ExtendedKeyMap);
408 if (ext_map != NULL)
409 shortcut = keybind_lookup_keymap_shortcut (main_x_map, command);
410 if (shortcut != NULL)
411 return g_strdup_printf ("%s %s", ext_map, shortcut);
413 return NULL;
416 /* --------------------------------------------------------------------------------------------- */
418 static char *
419 midnight_get_title (const Dlg_head * h, size_t len)
421 /* TODO: share code with update_xterm_title_path() */
423 const char *path;
424 char host[BUF_TINY];
425 char *p;
426 struct passwd *pw = NULL;
427 char *login = NULL;
428 int res = 0;
430 (void) h;
432 path = strip_home_and_password (current_panel->cwd);
433 res = gethostname (host, sizeof (host));
434 if (res != 0)
435 host[0] = '\0';
436 else
437 host[sizeof (host) - 1] = '\0';
439 pw = getpwuid (getuid ());
440 if (pw != NULL)
441 login = g_strdup_printf ("%s@%s", pw->pw_name, host);
442 else
443 login = g_strdup (host);
445 p = g_strdup_printf ("%s [%s]:%s", _("Panels:"), login, path);
446 path = str_trunc (p, len - 4);
447 g_free (login);
448 g_free (p);
450 return g_strdup (path);
453 /* --------------------------------------------------------------------------------------------- */
455 static void
456 toggle_panels_split (void)
458 horizontal_split = !horizontal_split;
459 layout_change ();
460 do_refresh ();
463 /* --------------------------------------------------------------------------------------------- */
465 #if ENABLE_VFS
467 /* event helper */
468 static gboolean
469 check_panel_timestamp (const WPanel * panel, panel_view_mode_t mode, struct vfs_class *vclass,
470 vfsid id)
472 if (mode == view_listing)
474 vfs_path_t *vpath;
475 vfs_path_element_t *path_element;
477 vpath = vfs_path_from_str (panel->cwd);
478 path_element = vfs_path_get_by_index (vpath, -1);
480 if (path_element->class != vclass)
482 vfs_path_free (vpath);
483 return FALSE;
486 if (vfs_getid (vpath) != id)
488 vfs_path_free (vpath);
489 return FALSE;
491 vfs_path_free (vpath);
493 return TRUE;
496 /* --------------------------------------------------------------------------------------------- */
498 /* event callback */
499 static gboolean
500 check_current_panel_timestamp (const gchar * event_group_name, const gchar * event_name,
501 gpointer init_data, gpointer data)
503 ev_vfs_stamp_create_t *event_data = (ev_vfs_stamp_create_t *) data;
505 (void) event_group_name;
506 (void) event_name;
507 (void) init_data;
509 event_data->ret =
510 check_panel_timestamp (current_panel, get_current_type (), event_data->vclass,
511 event_data->id);
512 return !event_data->ret;
515 /* --------------------------------------------------------------------------------------------- */
517 /* event callback */
518 static gboolean
519 check_other_panel_timestamp (const gchar * event_group_name, const gchar * event_name,
520 gpointer init_data, gpointer data)
522 ev_vfs_stamp_create_t *event_data = (ev_vfs_stamp_create_t *) data;
524 (void) event_group_name;
525 (void) event_name;
526 (void) init_data;
528 event_data->ret =
529 check_panel_timestamp (other_panel, get_other_type (), event_data->vclass, event_data->id);
530 return !event_data->ret;
532 #endif /* ENABLE_VFS */
534 /* --------------------------------------------------------------------------------------------- */
536 /* event callback */
537 static gboolean
538 print_vfs_message (const gchar * event_group_name, const gchar * event_name,
539 gpointer init_data, gpointer data)
541 char str[128];
542 ev_vfs_print_message_t *event_data = (ev_vfs_print_message_t *) data;
544 (void) event_group_name;
545 (void) event_name;
546 (void) init_data;
548 g_vsnprintf (str, sizeof (str), event_data->msg, event_data->ap);
550 if (mc_global.widget.midnight_shutdown)
551 return TRUE;
553 if (!mc_global.message_visible || !the_hint || !the_hint->widget.owner)
555 int col, row;
557 if (!nice_rotating_dash || (ok_to_refresh <= 0))
558 return TRUE;
560 /* Preserve current cursor position */
561 tty_getyx (&row, &col);
563 tty_gotoyx (0, 0);
564 tty_setcolor (NORMAL_COLOR);
565 tty_print_string (str_fit_to_term (str, COLS - 1, J_LEFT));
567 /* Restore cursor position */
568 tty_gotoyx (row, col);
569 mc_refresh ();
570 return TRUE;
573 if (mc_global.message_visible)
574 set_hintbar (str);
576 return TRUE;
579 /* --------------------------------------------------------------------------------------------- */
581 static void
582 create_panels (void)
584 int current_index;
585 int other_index;
586 panel_view_mode_t current_mode, other_mode;
587 char original_dir[BUF_1K] = "\0";
589 if (boot_current_is_left)
591 current_index = 0;
592 other_index = 1;
593 current_mode = startup_left_mode;
594 other_mode = startup_right_mode;
596 else
598 current_index = 1;
599 other_index = 0;
600 current_mode = startup_right_mode;
601 other_mode = startup_left_mode;
603 /* Creates the left panel */
604 if (mc_run_param0 != NULL)
606 if (mc_run_param1 != NULL)
608 /* Ok, user has specified two dirs, save the original one,
609 * since we may not be able to chdir to the proper
610 * second directory later
612 mc_get_current_wd (original_dir, sizeof (original_dir) - 2);
614 mc_chdir (mc_run_param0);
616 set_display_type (current_index, current_mode);
618 /* The other panel */
619 if (mc_run_param1 != NULL)
621 if (original_dir[0] != '\0')
622 mc_chdir (original_dir);
623 mc_chdir (mc_run_param1);
625 set_display_type (other_index, other_mode);
627 if (startup_left_mode == view_listing)
628 current_panel = left_panel;
629 else if (right_panel != NULL)
630 current_panel = right_panel;
631 else
632 current_panel = left_panel;
634 #if 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 if (!command_prompt)
662 return;
664 cwd_path = remove_encoding_from_path (current_panel->cwd);
665 command_insert (cmdline, cwd_path, FALSE);
667 if (cwd_path[strlen (cwd_path) - 1] != PATH_SEP)
668 command_insert (cmdline, PATH_SEP_STR, FALSE);
669 g_free (cwd_path);
672 /* --------------------------------------------------------------------------------------------- */
674 static void
675 put_other_path (void)
677 char *cwd_path;
679 if (get_other_type () != view_listing)
680 return;
682 if (!command_prompt)
683 return;
685 cwd_path = remove_encoding_from_path (other_panel->cwd);
686 command_insert (cmdline, cwd_path, FALSE);
688 if (cwd_path[strlen (cwd_path) - 1] != PATH_SEP)
689 command_insert (cmdline, PATH_SEP_STR, FALSE);
690 g_free (cwd_path);
693 /* --------------------------------------------------------------------------------------------- */
695 static void
696 put_link (WPanel * panel)
698 if (!command_prompt)
699 return;
700 if (S_ISLNK (selection (panel)->st.st_mode))
702 char buffer[MC_MAXPATHLEN];
703 char *p;
704 int i;
706 p = concat_dir_and_file (panel->cwd, selection (panel)->fname);
707 i = mc_readlink (p, buffer, MC_MAXPATHLEN - 1);
708 g_free (p);
709 if (i > 0)
711 buffer[i] = '\0';
712 command_insert (cmdline, buffer, TRUE);
717 /* --------------------------------------------------------------------------------------------- */
719 static void
720 put_current_link (void)
722 put_link (current_panel);
725 /* --------------------------------------------------------------------------------------------- */
727 static void
728 put_other_link (void)
730 if (get_other_type () == view_listing)
731 put_link (other_panel);
734 /* --------------------------------------------------------------------------------------------- */
736 /** Insert the selected file name into the input line */
737 static void
738 put_prog_name (void)
740 char *tmp;
741 if (!command_prompt)
742 return;
744 if (get_current_type () == view_tree)
746 WTree *tree = (WTree *) get_panel_widget (get_current_index ());
747 tmp = tree_selected_name (tree);
749 else
750 tmp = selection (current_panel)->fname;
752 command_insert (cmdline, tmp, TRUE);
755 /* --------------------------------------------------------------------------------------------- */
757 static void
758 put_tagged (WPanel * panel)
760 int i;
762 if (!command_prompt)
763 return;
764 input_disable_update (cmdline);
765 if (panel->marked)
767 for (i = 0; i < panel->count; i++)
769 if (panel->dir.list[i].f.marked)
770 command_insert (cmdline, panel->dir.list[i].fname, TRUE);
773 else
775 command_insert (cmdline, panel->dir.list[panel->selected].fname, TRUE);
777 input_enable_update (cmdline);
780 /* --------------------------------------------------------------------------------------------- */
782 static void
783 put_current_tagged (void)
785 put_tagged (current_panel);
788 /* --------------------------------------------------------------------------------------------- */
790 static void
791 put_other_tagged (void)
793 if (get_other_type () == view_listing)
794 put_tagged (other_panel);
797 /* --------------------------------------------------------------------------------------------- */
799 static void
800 ctl_x_cmd (void)
802 ctl_x_map_enabled = TRUE;
805 /* --------------------------------------------------------------------------------------------- */
807 static void
808 setup_mc (void)
810 #ifdef HAVE_SLANG
811 #ifdef HAVE_CHARSET
812 tty_display_8bit (TRUE);
813 #else
814 tty_display_8bit (full_eight_bits != 0);
815 #endif /* HAVE_CHARSET */
816 #else
818 #ifdef HAVE_CHARSET
819 tty_display_8bit (TRUE);
820 #else
821 tty_display_8bit (eight_bit_clean != 0);
822 #endif /* HAVE_CHARSET */
824 #endif
826 #ifdef HAVE_SUBSHELL_SUPPORT
827 if (mc_global.tty.use_subshell)
828 add_select_channel (mc_global.tty.subshell_pty, load_prompt, 0);
829 #endif /* !HAVE_SUBSHELL_SUPPORT */
831 if ((tty_baudrate () < 9600) || tty_is_slow ())
832 verbose = 0;
835 /* --------------------------------------------------------------------------------------------- */
837 static void
838 setup_dummy_mc (void)
840 char d[MC_MAXPATHLEN];
841 int ret;
843 mc_get_current_wd (d, MC_MAXPATHLEN);
844 setup_mc ();
845 ret = mc_chdir (d);
848 /* --------------------------------------------------------------------------------------------- */
850 static void
851 done_mc (void)
853 /* Setup shutdown
855 * We sync the profiles since the hotlist may have changed, while
856 * we only change the setup data if we have the auto save feature set
858 char *curr_dir;
860 save_setup (auto_save_setup, panels_options.auto_save_setup);
862 curr_dir = vfs_get_current_dir ();
863 vfs_stamp_path (curr_dir);
864 g_free (curr_dir);
866 if ((current_panel != NULL) && (get_current_type () == view_listing))
867 vfs_stamp_path (current_panel->cwd);
869 if ((other_panel != NULL) && (get_other_type () == view_listing))
870 vfs_stamp_path (other_panel->cwd);
873 /* --------------------------------------------------------------------------------------------- */
875 static void
876 create_panels_and_run_mc (void)
878 midnight_dlg->get_shortcut = midnight_get_shortcut;
879 midnight_dlg->get_title = midnight_get_title;
881 create_panels ();
883 add_widget (midnight_dlg, the_menubar);
884 init_menu ();
886 add_widget (midnight_dlg, get_panel_widget (0));
887 add_widget (midnight_dlg, get_panel_widget (1));
889 add_widget (midnight_dlg, the_hint);
890 add_widget (midnight_dlg, cmdline);
891 add_widget (midnight_dlg, the_prompt);
893 add_widget (midnight_dlg, the_bar);
894 midnight_set_buttonbar (the_bar);
896 /* Run the Midnight Commander if no file was specified in the command line */
897 run_dlg (midnight_dlg);
900 /* --------------------------------------------------------------------------------------------- */
902 /** result must be free'd (I think this should go in util.c) */
903 static char *
904 prepend_cwd_on_local (const char *filename)
906 char *d;
907 size_t l;
908 vfs_path_t *vpath;
910 vpath = vfs_path_from_str (filename);
911 if (!vfs_file_is_local (vpath) || g_path_is_absolute (filename))
913 vfs_path_free (vpath);
914 return g_strdup (filename);
916 vfs_path_free (vpath);
918 d = g_malloc (MC_MAXPATHLEN + strlen (filename) + 2);
919 mc_get_current_wd (d, MC_MAXPATHLEN);
920 l = strlen (d);
921 d[l++] = PATH_SEP;
922 strcpy (d + l, filename);
923 canonicalize_pathname (d);
924 return d;
927 /* --------------------------------------------------------------------------------------------- */
929 /** Invoke the internal view/edit routine with:
930 * the default processing and forcing the internal viewer/editor
932 static void
933 mc_maybe_editor_or_viewer (void)
935 switch (mc_global.mc_run_mode)
937 #ifdef USE_INTERNAL_EDIT
938 case MC_RUN_EDITOR:
939 edit_file (mc_run_param0, mc_args__edit_start_line);
940 break;
941 #endif /* USE_INTERNAL_EDIT */
942 case MC_RUN_VIEWER:
944 char *path;
945 path = prepend_cwd_on_local (mc_run_param0);
946 view_file (path, 0, 1);
947 g_free (path);
948 break;
950 #ifdef USE_DIFF_VIEW
951 case MC_RUN_DIFFVIEWER:
952 diff_view (mc_run_param0, mc_run_param1, mc_run_param0, mc_run_param1);
953 break;
954 #endif /* USE_DIFF_VIEW */
955 default:
956 break;
960 /* --------------------------------------------------------------------------------------------- */
962 static gboolean
963 quit_cmd_internal (int quiet)
965 int q = quit;
966 size_t n;
968 n = dialog_switch_num () - 1;
969 if (n != 0)
971 char msg[BUF_MEDIUM];
973 g_snprintf (msg, sizeof (msg),
974 ngettext ("You have %zd opened screen. Quit anyway?",
975 "You have %zd opened screens. Quit anyway?", n), n);
977 if (query_dialog (_("The Midnight Commander"), msg, D_NORMAL, 2, _("&Yes"), _("&No")) != 0)
978 return FALSE;
979 q = 1;
981 else if (quiet || !confirm_exit)
982 q = 1;
983 else if (query_dialog (_("The Midnight Commander"),
984 _("Do you really want to quit the Midnight Commander?"),
985 D_NORMAL, 2, _("&Yes"), _("&No")) == 0)
986 q = 1;
988 if (q != 0)
990 #ifdef HAVE_SUBSHELL_SUPPORT
991 if (!mc_global.tty.use_subshell)
992 stop_dialogs ();
993 else if ((q = exit_subshell ()))
994 #endif
995 stop_dialogs ();
998 if (q != 0)
999 quit |= 1;
1000 return (quit != 0);
1003 /* --------------------------------------------------------------------------------------------- */
1005 static gboolean
1006 quit_cmd (void)
1008 return quit_cmd_internal (0);
1011 /* --------------------------------------------------------------------------------------------- */
1013 static void
1014 toggle_show_hidden (void)
1016 panels_options.show_dot_files = !panels_options.show_dot_files;
1017 update_panels (UP_RELOAD, UP_KEEPSEL);
1020 /* --------------------------------------------------------------------------------------------- */
1023 * Repaint the contents of the panels without frames. To schedule panel
1024 * for repainting, set panel->dirty to 1. There are many reasons why
1025 * the panels need to be repainted, and this is a costly operation, so
1026 * it's done once per event.
1029 static void
1030 update_dirty_panels (void)
1032 if (get_current_type () == view_listing && current_panel->dirty)
1033 send_message ((Widget *) current_panel, WIDGET_DRAW, 0);
1035 if (get_other_type () == view_listing && other_panel->dirty)
1036 send_message ((Widget *) other_panel, WIDGET_DRAW, 0);
1039 /* --------------------------------------------------------------------------------------------- */
1041 static cb_ret_t
1042 midnight_execute_cmd (Widget * sender, unsigned long command)
1044 cb_ret_t res = MSG_HANDLED;
1046 (void) sender;
1048 /* stop quick search before executing any command */
1049 send_message ((Widget *) current_panel, WIDGET_COMMAND, CK_SearchStop);
1051 switch (command)
1053 case CK_HotListAdd:
1054 add2hotlist_cmd ();
1055 break;
1056 case CK_PanelListingChange:
1057 change_listing_cmd ();
1058 break;
1059 case CK_ChangeMode:
1060 chmod_cmd ();
1061 break;
1062 case CK_ChangeOwn:
1063 chown_cmd ();
1064 break;
1065 case CK_ChangeOwnAdvanced:
1066 chown_advanced_cmd ();
1067 break;
1068 case CK_CompareDirs:
1069 compare_dirs_cmd ();
1070 break;
1071 case CK_Options:
1072 configure_box ();
1073 break;
1074 #ifdef ENABLE_VFS
1075 case CK_OptionsVfs:
1076 configure_vfs ();
1077 break;
1078 #endif
1079 case CK_OptionsConfirm:
1080 confirm_box ();
1081 break;
1082 case CK_Copy:
1083 copy_cmd ();
1084 break;
1085 case CK_PutCurrentPath:
1086 put_current_path ();
1087 break;
1088 case CK_PutCurrentLink:
1089 put_current_link ();
1090 break;
1091 case CK_PutCurrentTagged:
1092 put_current_tagged ();
1093 break;
1094 case CK_PutOtherPath:
1095 put_other_path ();
1096 break;
1097 case CK_PutOtherLink:
1098 put_other_link ();
1099 break;
1100 case CK_PutOtherTagged:
1101 put_other_tagged ();
1102 break;
1103 case CK_Delete:
1104 delete_cmd ();
1105 break;
1106 case CK_ScreenList:
1107 dialog_switch_list ();
1108 break;
1109 #ifdef USE_DIFF_VIEW
1110 case CK_CompareFiles:
1111 diff_view_cmd ();
1112 break;
1113 #endif
1114 case CK_OptionsDisplayBits:
1115 display_bits_box ();
1116 break;
1117 case CK_Edit:
1118 edit_cmd ();
1119 break;
1120 #ifdef USE_INTERNAL_EDIT
1121 case CK_EditForceInternal:
1122 edit_cmd_force_internal ();
1123 break;
1124 #endif
1125 case CK_EditExtensionsFile:
1126 ext_cmd ();
1127 break;
1128 case CK_EditFileHighlightFile:
1129 edit_fhl_cmd ();
1130 break;
1131 case CK_EditUserMenu:
1132 edit_mc_menu_cmd ();
1133 break;
1134 case CK_LinkSymbolicEdit:
1135 edit_symlink_cmd ();
1136 break;
1137 case CK_ExternalPanelize:
1138 external_panelize ();
1139 break;
1140 case CK_Filter:
1141 filter_cmd ();
1142 break;
1143 case CK_ViewFiltered:
1144 view_filtered_cmd ();
1145 break;
1146 case CK_Find:
1147 find_cmd ();
1148 break;
1149 #ifdef ENABLE_VFS_FISH
1150 case CK_ConnectFish:
1151 fishlink_cmd ();
1152 break;
1153 #endif
1154 #ifdef ENABLE_VFS_FTP
1155 case CK_ConnectFtp:
1156 ftplink_cmd ();
1157 break;
1158 #endif
1159 #ifdef ENABLE_VFS_SMB
1160 case CK_ConnectSmb:
1161 smblink_cmd ();
1162 break;
1163 #endif /* ENABLE_VFS_SMB */
1164 case CK_Help:
1165 help_cmd ();
1166 break;
1167 case CK_History:
1168 /* show the history of command line widget */
1169 send_message (&cmdline->widget, WIDGET_COMMAND, CK_History);
1170 break;
1171 case CK_PanelInfo:
1172 if (sender == (Widget *) the_menubar)
1173 info_cmd (); /* menu */
1174 else
1175 info_cmd_no_menu (); /* shortcut or buttonbar */
1176 break;
1177 #ifdef WITH_BACKGROUND
1178 case CK_Jobs:
1179 jobs_cmd ();
1180 break;
1181 #endif
1182 case CK_OptionsLayout:
1183 layout_box ();
1184 break;
1185 case CK_LearnKeys:
1186 learn_keys ();
1187 break;
1188 case CK_Link:
1189 link_cmd (LINK_HARDLINK);
1190 break;
1191 case CK_PanelListing:
1192 listing_cmd ();
1193 break;
1194 #ifdef LISTMODE_EDITOR
1195 case CK_ListMode:
1196 listmode_cmd ();
1197 break;
1198 #endif
1199 case CK_Menu:
1200 menu_cmd ();
1201 break;
1202 case CK_MenuLastSelected:
1203 menu_last_selected_cmd ();
1204 break;
1205 case CK_MakeDir:
1206 mkdir_cmd ();
1207 break;
1208 case CK_OptionsPanel:
1209 panel_options_box ();
1210 break;
1211 #ifdef HAVE_CHARSET
1212 case CK_SelectCodepage:
1213 encoding_cmd ();
1214 break;
1215 #endif
1216 case CK_CdQuick:
1217 quick_cd_cmd ();
1218 break;
1219 case CK_HotList:
1220 hotlist_cmd ();
1221 break;
1222 case CK_PanelQuickView:
1223 if (sender == (Widget *) the_menubar)
1224 quick_view_cmd (); /* menu */
1225 else
1226 quick_cmd_no_menu (); /* shortcut or buttonabr */
1227 break;
1228 case CK_QuitQuiet:
1229 quiet_quit_cmd ();
1230 break;
1231 case CK_Quit:
1232 quit_cmd ();
1233 break;
1234 case CK_LinkSymbolicRelative:
1235 link_cmd (LINK_SYMLINK_RELATIVE);
1236 break;
1237 case CK_Move:
1238 rename_cmd ();
1239 break;
1240 case CK_Reread:
1241 reread_cmd ();
1242 break;
1243 #ifdef ENABLE_VFS
1244 case CK_VfsList:
1245 vfs_list ();
1246 break;
1247 #endif
1248 case CK_SelectInvert:
1249 select_invert_cmd ();
1250 break;
1251 case CK_SaveSetup:
1252 save_setup_cmd ();
1253 break;
1254 case CK_Select:
1255 select_cmd ();
1256 break;
1257 case CK_Shell:
1258 view_other_cmd ();
1259 break;
1260 case CK_DirSize:
1261 smart_dirsize_cmd ();
1262 break;
1263 case CK_Sort:
1264 sort_cmd ();
1265 break;
1266 case CK_ExtendedKeyMap:
1267 ctl_x_cmd ();
1268 break;
1269 case CK_Suspend:
1270 mc_event_raise (MCEVENT_GROUP_CORE, "suspend", NULL);
1271 break;
1272 case CK_Swap:
1273 swap_cmd ();
1274 break;
1275 case CK_LinkSymbolic:
1276 link_cmd (LINK_SYMLINK_ABSOLUTE);
1277 break;
1278 case CK_PanelListingSwitch:
1279 toggle_listing_cmd ();
1280 break;
1281 case CK_ShowHidden:
1282 toggle_show_hidden ();
1283 break;
1284 case CK_SplitVertHoriz:
1285 toggle_panels_split ();
1286 break;
1287 case CK_PanelTree:
1288 panel_tree_cmd ();
1289 break;
1290 case CK_Tree:
1291 treebox_cmd ();
1292 break;
1293 #ifdef ENABLE_VFS_UNDELFS
1294 case CK_Undelete:
1295 undelete_cmd ();
1296 break;
1297 #endif
1298 case CK_Unselect:
1299 unselect_cmd ();
1300 break;
1301 case CK_UserMenu:
1302 user_file_menu_cmd ();
1303 break;
1304 case CK_View:
1305 view_cmd ();
1306 break;
1307 case CK_ViewFile:
1308 view_file_cmd ();
1309 break;
1310 case CK_Cancel:
1311 /* don't close panels due to SIGINT */
1312 break;
1313 default:
1314 res = MSG_NOT_HANDLED;
1317 return res;
1320 /* --------------------------------------------------------------------------------------------- */
1322 static cb_ret_t
1323 midnight_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
1325 unsigned long command;
1327 switch (msg)
1329 case DLG_INIT:
1330 panel_init ();
1331 setup_panels ();
1332 return MSG_HANDLED;
1334 case DLG_DRAW:
1335 load_hint (1);
1336 /* We handle the special case of the output lines */
1337 if (mc_global.tty.console_flag && output_lines)
1338 show_console_contents (output_start_y,
1339 LINES - output_lines - mc_global.keybar_visible -
1340 1, LINES - mc_global.keybar_visible - 1);
1341 return MSG_HANDLED;
1343 case DLG_RESIZE:
1344 setup_panels ();
1345 menubar_arrange (the_menubar);
1346 return MSG_HANDLED;
1348 case DLG_IDLE:
1349 /* We only need the first idle event to show user menu after start */
1350 set_idle_proc (h, 0);
1352 if (boot_current_is_left)
1353 dlg_select_widget (get_panel_widget (0));
1354 else
1355 dlg_select_widget (get_panel_widget (1));
1357 if (auto_menu)
1358 midnight_execute_cmd (NULL, CK_UserMenu);
1359 return MSG_HANDLED;
1361 case DLG_KEY:
1362 if (ctl_x_map_enabled)
1364 ctl_x_map_enabled = FALSE;
1365 command = keybind_lookup_keymap_command (main_x_map, parm);
1366 if (command != CK_IgnoreKey)
1367 return midnight_execute_cmd (NULL, command);
1370 /* FIXME: should handle all menu shortcuts before this point */
1371 if (the_menubar->is_active)
1372 return MSG_NOT_HANDLED;
1374 if (parm == '\t')
1375 input_free_completions (cmdline);
1377 if (parm == '\n')
1379 size_t i;
1381 for (i = 0; cmdline->buffer[i] != '\0' &&
1382 (cmdline->buffer[i] == ' ' || cmdline->buffer[i] == '\t'); i++)
1385 if (cmdline->buffer[i] != '\0')
1387 send_message ((Widget *) cmdline, WIDGET_KEY, parm);
1388 return MSG_HANDLED;
1391 input_insert (cmdline, "", FALSE);
1392 cmdline->point = 0;
1395 /* Ctrl-Enter and Alt-Enter */
1396 if (((parm & ~(KEY_M_CTRL | KEY_M_ALT)) == '\n') && (parm & (KEY_M_CTRL | KEY_M_ALT)))
1398 put_prog_name ();
1399 return MSG_HANDLED;
1402 /* Ctrl-Shift-Enter */
1403 if (parm == (KEY_M_CTRL | KEY_M_SHIFT | '\n'))
1405 put_current_path ();
1406 put_prog_name ();
1407 return MSG_HANDLED;
1410 if ((!alternate_plus_minus || !(mc_global.tty.console_flag || mc_global.tty.xterm_flag))
1411 && !quote && !current_panel->searching)
1413 if (!only_leading_plus_minus)
1415 /* Special treatement, since the input line will eat them */
1416 if (parm == '+')
1418 select_cmd ();
1419 return MSG_HANDLED;
1422 if (parm == '\\' || parm == '-')
1424 unselect_cmd ();
1425 return MSG_HANDLED;
1428 if (parm == '*')
1430 select_invert_cmd ();
1431 return MSG_HANDLED;
1434 else if (!command_prompt || !cmdline->buffer[0])
1436 /* Special treatement '+', '-', '\', '*' only when this is
1437 * first char on input line
1440 if (parm == '+')
1442 select_cmd ();
1443 return MSG_HANDLED;
1446 if (parm == '\\' || parm == '-')
1448 unselect_cmd ();
1449 return MSG_HANDLED;
1452 if (parm == '*')
1454 select_invert_cmd ();
1455 return MSG_HANDLED;
1459 return MSG_NOT_HANDLED;
1461 case DLG_HOTKEY_HANDLED:
1462 if ((get_current_type () == view_listing) && current_panel->searching)
1464 current_panel->dirty = 1; /* FIXME: unneeded? */
1465 send_message ((Widget *) current_panel, WIDGET_COMMAND, CK_SearchStop);
1467 return MSG_HANDLED;
1469 case DLG_UNHANDLED_KEY:
1470 if (command_prompt)
1472 cb_ret_t v;
1474 v = send_message ((Widget *) cmdline, WIDGET_KEY, parm);
1475 if (v == MSG_HANDLED)
1476 return MSG_HANDLED;
1479 if (ctl_x_map_enabled)
1481 ctl_x_map_enabled = FALSE;
1482 command = keybind_lookup_keymap_command (main_x_map, parm);
1484 else
1485 command = keybind_lookup_keymap_command (main_map, parm);
1487 return (command == CK_IgnoreKey) ? MSG_NOT_HANDLED : midnight_execute_cmd (NULL, command);
1489 case DLG_POST_KEY:
1490 if (!the_menubar->is_active)
1491 update_dirty_panels ();
1492 return MSG_HANDLED;
1494 case DLG_ACTION:
1495 /* shortcut */
1496 if (sender == NULL)
1497 return midnight_execute_cmd (NULL, parm);
1498 /* message from menu */
1499 if (sender == (Widget *) the_menubar)
1500 return midnight_execute_cmd (sender, parm);
1501 /* message from buttonbar */
1502 if (sender == (Widget *) the_bar)
1504 if (data != NULL)
1505 return send_message ((Widget *) data, WIDGET_COMMAND, parm);
1506 return midnight_execute_cmd (sender, parm);
1508 return MSG_NOT_HANDLED;
1510 case DLG_END:
1511 panel_deinit ();
1512 return MSG_HANDLED;
1514 default:
1515 return default_dlg_callback (h, sender, msg, parm, data);
1519 /* --------------------------------------------------------------------------------------------- */
1520 /*** public functions ****************************************************************************/
1521 /* --------------------------------------------------------------------------------------------- */
1523 void
1524 update_menu (void)
1526 menu_set_name (left_menu, horizontal_split ? _("&Above") : _("&Left"));
1527 menu_set_name (right_menu, horizontal_split ? _("&Below") : _("&Right"));
1528 menubar_arrange (the_menubar);
1529 menubar_set_visible (the_menubar, menubar_visible);
1532 void
1533 midnight_set_buttonbar (WButtonBar * b)
1535 buttonbar_set_label (b, 1, Q_ ("ButtonBar|Help"), main_map, NULL);
1536 buttonbar_set_label (b, 2, Q_ ("ButtonBar|Menu"), main_map, NULL);
1537 buttonbar_set_label (b, 3, Q_ ("ButtonBar|View"), main_map, NULL);
1538 buttonbar_set_label (b, 4, Q_ ("ButtonBar|Edit"), main_map, NULL);
1539 buttonbar_set_label (b, 5, Q_ ("ButtonBar|Copy"), main_map, NULL);
1540 buttonbar_set_label (b, 6, Q_ ("ButtonBar|RenMov"), main_map, NULL);
1541 buttonbar_set_label (b, 7, Q_ ("ButtonBar|Mkdir"), main_map, NULL);
1542 buttonbar_set_label (b, 8, Q_ ("ButtonBar|Delete"), main_map, NULL);
1543 buttonbar_set_label (b, 9, Q_ ("ButtonBar|PullDn"), main_map, NULL);
1544 buttonbar_set_label (b, 10, Q_ ("ButtonBar|Quit"), main_map, NULL);
1547 /* --------------------------------------------------------------------------------------------- */
1549 * Load new hint and display it.
1550 * IF force is not 0, ignore the timeout.
1553 void
1554 load_hint (gboolean force)
1556 char *hint;
1558 if (the_hint->widget.owner == NULL)
1559 return;
1561 if (!mc_global.message_visible)
1563 label_set_text (the_hint, NULL);
1564 return;
1567 hint = get_random_hint (force);
1569 if (hint != NULL)
1571 if (*hint != '\0')
1572 set_hintbar (hint);
1573 g_free (hint);
1575 else
1577 char text[BUF_SMALL];
1579 g_snprintf (text, sizeof (text), _("GNU Midnight Commander %s\n"), VERSION);
1580 set_hintbar (text);
1584 /* --------------------------------------------------------------------------------------------- */
1586 void
1587 change_panel (void)
1589 input_free_completions (cmdline);
1590 dlg_one_down (midnight_dlg);
1593 /* --------------------------------------------------------------------------------------------- */
1595 /** Save current stat of directories to avoid reloading the panels
1596 * when no modifications have taken place
1598 void
1599 save_cwds_stat (void)
1601 if (panels_options.fast_reload)
1603 mc_stat (current_panel->cwd, &(current_panel->dir_stat));
1604 if (get_other_type () == view_listing)
1605 mc_stat (other_panel->cwd, &(other_panel->dir_stat));
1609 /* --------------------------------------------------------------------------------------------- */
1611 gboolean
1612 quiet_quit_cmd (void)
1614 print_last_revert = TRUE;
1615 return quit_cmd_internal (1);
1618 /* --------------------------------------------------------------------------------------------- */
1620 /** Run the main dialog that occupies the whole screen */
1621 void
1622 do_nc (void)
1624 dlg_colors_t midnight_colors;
1626 midnight_colors[DLG_COLOR_NORMAL] = mc_skin_color_get ("dialog", "_default_");
1627 midnight_colors[DLG_COLOR_FOCUS] = mc_skin_color_get ("dialog", "focus");
1628 midnight_colors[DLG_COLOR_HOT_NORMAL] = mc_skin_color_get ("dialog", "hotnormal");
1629 midnight_colors[DLG_COLOR_HOT_FOCUS] = mc_skin_color_get ("dialog", "hotfocus");
1630 midnight_colors[DLG_COLOR_TITLE] = mc_skin_color_get ("dialog", "title");
1632 #ifdef USE_INTERNAL_EDIT
1633 edit_stack_init ();
1634 #endif
1636 midnight_dlg = create_dlg (FALSE, 0, 0, LINES, COLS, midnight_colors, midnight_callback,
1637 "[main]", NULL, DLG_WANT_IDLE);
1639 if (mc_global.mc_run_mode == MC_RUN_FULL)
1640 setup_mc ();
1641 else
1642 setup_dummy_mc ();
1644 /* Check if we were invoked as an editor or file viewer */
1645 if (mc_global.mc_run_mode != MC_RUN_FULL)
1646 mc_maybe_editor_or_viewer ();
1647 else
1649 create_panels_and_run_mc ();
1651 /* destroy_dlg destroys even current_panel->cwd, so we have to save a copy :) */
1652 if (mc_args__last_wd_file != NULL && vfs_current_is_local ())
1653 last_wd_string = g_strdup (current_panel->cwd);
1655 /* don't handle VFS timestamps for dirs opened in panels */
1656 mc_event_destroy (MCEVENT_GROUP_CORE, "vfs_timestamp");
1659 /* Program end */
1660 mc_global.widget.midnight_shutdown = TRUE;
1661 dialog_switch_shutdown ();
1662 done_mc ();
1663 destroy_dlg (midnight_dlg);
1664 current_panel = NULL;
1666 #ifdef USE_INTERNAL_EDIT
1667 edit_stack_free ();
1668 #endif
1670 if ((quit & SUBSHELL_EXIT) == 0)
1671 clr_scr ();
1674 /* --------------------------------------------------------------------------------------------- */