Ticket #1668: Screen and input corruption under xterm [non-UTF]
[midnight-commander.git] / src / filemanager / midnight.c
blob9d54096056ba263fae79cd1b9cd3876ba88fc71c
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 <unistd.h>
41 #include <pwd.h> /* for username in xterm title */
43 #include "lib/global.h"
45 #include "lib/tty/tty.h"
46 #include "lib/tty/key.h" /* For init_key() */
47 #include "lib/tty/mouse.h"
48 #include "lib/tty/win.h" /* xterm_flag */
49 #include "lib/skin.h"
50 #include "lib/util.h"
52 #include "lib/vfs/mc-vfs/vfs.h" /* vfs_translate_url() */
54 #include "src/args.h"
55 #include "src/subshell.h"
56 #include "src/setup.h" /* variables */
57 #include "src/learn.h" /* learn_keys() */
58 #include "src/execute.h" /* suspend_cmd() */
59 #include "src/keybind-defaults.h"
60 #include "src/main.h" /* quit */
62 #include "option.h" /* configure_box() */
63 #include "tree.h"
64 #include "boxes.h" /* sort_box(), tree_box() */
65 #include "layout.h"
66 #include "cmd.h" /* commands */
67 #include "hotlist.h"
68 #include "panelize.h"
69 #include "command.h" /* cmdline */
70 #include "lib/keybind.h"
72 #include "chmod.h"
73 #include "chown.h"
74 #include "achown.h"
76 #ifdef USE_INTERNAL_EDIT
77 #include "src/editor/edit.h"
78 #endif
80 #ifdef USE_DIFF_VIEW
81 #include "src/diffviewer/ydiff.h"
82 #endif
84 #include "src/consaver/cons.saver.h" /* console_flag */
86 #include "midnight.h"
88 /* TODO: merge content of layout.c here */
90 /*** global variables ****************************************************************************/
92 /* When the modes are active, left_panel, right_panel and tree_panel */
93 /* point to a proper data structure. You should check with the functions */
94 /* get_current_type and get_other_type the types of the panels before using */
95 /* this pointer variables */
97 /* The structures for the panels */
98 WPanel *left_panel = NULL;
99 WPanel *right_panel = NULL;
100 /* Pointer to the selected and unselected panel */
101 WPanel *current_panel = NULL;
103 /* Set if the command is being run from the "Right" menu */
104 int is_right = 0;
106 /* The Menubar */
107 WMenuBar *the_menubar = NULL;
108 /* The widget where we draw the prompt */
109 WLabel *the_prompt;
110 /* The hint bar */
111 WLabel *the_hint;
112 /* The button bar */
113 WButtonBar *the_bar;
115 /* The dialog handle for the main program */
116 Dlg_head *midnight_dlg = NULL;
118 /*** file scope macro definitions ****************************************************************/
120 #ifdef HAVE_CHARSET
122 * Don't restrict the output on the screen manager level,
123 * the translation tables take care of it.
125 #define full_eight_bits (1)
126 #define eight_bit_clean (1)
127 #endif /* !HAVE_CHARSET */
129 /*** file scope type declarations ****************************************************************/
131 /*** file scope variables ************************************************************************/
133 static Menu *left_menu, *right_menu;
135 static gboolean ctl_x_map_enabled = FALSE;
137 /*** file scope functions ************************************************************************/
139 /** Stop MC main dialog and the current dialog if it exists.
140 * Needed to provide fast exit from MC viewer or editor on shell exit */
141 static void
142 stop_dialogs (void)
144 midnight_dlg->state = DLG_CLOSED;
146 if ((top_dlg != NULL) && (top_dlg->data != NULL))
147 ((Dlg_head *) top_dlg->data)->state = DLG_CLOSED;
150 /* --------------------------------------------------------------------------------------------- */
152 static void
153 treebox_cmd (void)
155 char *sel_dir;
157 sel_dir = tree_box (selection (current_panel)->fname);
158 if (sel_dir)
160 do_cd (sel_dir, cd_exact);
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_append (entries, menu_entry_create (_("File listin&g"), CK_ListingCmd));
197 entries = g_list_append (entries, menu_entry_create (_("&Quick view"), CK_QuickViewCmd));
198 entries = g_list_append (entries, menu_entry_create (_("&Info"), CK_InfoCmd));
199 entries = g_list_append (entries, menu_entry_create (_("&Tree"), CK_TreeCmd));
200 entries = g_list_append (entries, menu_separator_create ());
201 entries =
202 g_list_append (entries, menu_entry_create (_("&Listing mode..."), CK_ChangeListingCmd));
203 entries = g_list_append (entries, menu_entry_create (_("&Sort order..."), CK_Sort));
204 entries = g_list_append (entries, menu_entry_create (_("&Filter..."), CK_FilterCmd));
205 #ifdef HAVE_CHARSET
206 entries =
207 g_list_append (entries, menu_entry_create (_("&Encoding..."), CK_PanelSetPanelEncoding));
208 #endif
209 #ifdef ENABLE_VFS_NET
210 entries = g_list_append (entries, menu_separator_create ());
211 #ifdef ENABLE_VFS_FTP
212 entries = g_list_append (entries, menu_entry_create (_("FT&P link..."), CK_FtplinkCmd));
213 #endif
214 #ifdef ENABLE_VFS_FISH
215 entries = g_list_append (entries, menu_entry_create (_("S&hell link..."), CK_FishlinkCmd));
216 #endif
217 #ifdef ENABLE_VFS_SMB
218 entries = g_list_append (entries, menu_entry_create (_("SM&B link..."), CK_SmblinkCmd));
219 #endif
220 #endif /* ENABLE_VFS_NET */
221 entries = g_list_append (entries, menu_separator_create ());
222 entries = g_list_append (entries, menu_entry_create (_("&Rescan"), CK_RereadCmd));
224 return entries;
227 /* --------------------------------------------------------------------------------------------- */
229 static GList *
230 create_file_menu (void)
232 GList *entries = NULL;
234 entries = g_list_append (entries, menu_entry_create (_("&View"), CK_ViewCmd));
235 entries = g_list_append (entries, menu_entry_create (_("Vie&w file..."), CK_ViewFileCmd));
236 entries = g_list_append (entries, menu_entry_create (_("&Filtered view"), CK_FilteredViewCmd));
237 entries = g_list_append (entries, menu_entry_create (_("&Edit"), CK_EditCmd));
238 entries = g_list_append (entries, menu_entry_create (_("&Copy"), CK_CopyCmd));
239 entries = g_list_append (entries, menu_entry_create (_("C&hmod"), CK_ChmodCmd));
240 entries = g_list_append (entries, menu_entry_create (_("&Link"), CK_LinkCmd));
241 entries = g_list_append (entries, menu_entry_create (_("&Symlink"), CK_SymlinkCmd));
242 entries =
243 g_list_append (entries, menu_entry_create (_("Relative symlin&k"), CK_RelativeSymlinkCmd));
244 entries = g_list_append (entries, menu_entry_create (_("Edit s&ymlink"), CK_EditSymlinkCmd));
245 entries = g_list_append (entries, menu_entry_create (_("Ch&own"), CK_ChownCmd));
246 entries =
247 g_list_append (entries, menu_entry_create (_("&Advanced chown"), CK_ChownAdvancedCmd));
248 entries = g_list_append (entries, menu_entry_create (_("&Rename/Move"), CK_RenameCmd));
249 entries = g_list_append (entries, menu_entry_create (_("&Mkdir"), CK_MkdirCmd));
250 entries = g_list_append (entries, menu_entry_create (_("&Delete"), CK_DeleteCmd));
251 entries = g_list_append (entries, menu_entry_create (_("&Quick cd"), CK_QuickCdCmd));
252 entries = g_list_append (entries, menu_separator_create ());
253 entries = g_list_append (entries, menu_entry_create (_("Select &group"), CK_SelectCmd));
254 entries = g_list_append (entries, menu_entry_create (_("U&nselect group"), CK_UnselectCmd));
255 entries =
256 g_list_append (entries,
257 menu_entry_create (_("Reverse selec&tion"), CK_ReverseSelectionCmd));
258 entries = g_list_append (entries, menu_separator_create ());
259 entries = g_list_append (entries, menu_entry_create (_("E&xit"), CK_QuitCmd));
261 return entries;
264 /* --------------------------------------------------------------------------------------------- */
266 static GList *
267 create_command_menu (void)
269 /* I know, I'm lazy, but the tree widget when it's not running
270 * as a panel still has some problems, I have not yet finished
271 * the WTree widget port, sorry.
273 GList *entries = NULL;
275 entries = g_list_append (entries, menu_entry_create (_("&User menu"), CK_UserMenuCmd));
276 entries = g_list_append (entries, menu_entry_create (_("&Directory tree"), CK_TreeBoxCmd));
277 entries = g_list_append (entries, menu_entry_create (_("&Find file"), CK_FindCmd));
278 entries = g_list_append (entries, menu_entry_create (_("S&wap panels"), CK_SwapCmd));
279 entries =
280 g_list_append (entries, menu_entry_create (_("Switch &panels on/off"), CK_ShowCommandLine));
281 entries =
282 g_list_append (entries, menu_entry_create (_("&Compare directories"), CK_CompareDirsCmd));
283 #ifdef USE_DIFF_VIEW
284 entries = g_list_append (entries, menu_entry_create (_("&View diff files"), CK_DiffViewCmd));
285 #endif
286 entries =
287 g_list_append (entries, menu_entry_create (_("E&xternal panelize"), CK_ExternalPanelize));
288 entries =
289 g_list_append (entries,
290 menu_entry_create (_("Show directory s&izes"), CK_SingleDirsizeCmd));
291 entries = g_list_append (entries, menu_separator_create ());
292 entries = g_list_append (entries, menu_entry_create (_("Command &history"), CK_HistoryCmd));
293 entries =
294 g_list_append (entries, menu_entry_create (_("Di&rectory hotlist"), CK_QuickChdirCmd));
295 #ifdef ENABLE_VFS
296 entries = g_list_append (entries, menu_entry_create (_("&Active VFS list"), CK_ReselectVfs));
297 #endif
298 #ifdef WITH_BACKGROUND
299 entries = g_list_append (entries, menu_entry_create (_("&Background jobs"), CK_JobsCmd));
300 #endif
301 entries = g_list_append (entries, menu_entry_create (_("Screen lis&t"), CK_DialogListCmd));
302 entries = g_list_append (entries, menu_separator_create ());
303 #ifdef ENABLE_VFS_UNDELFS
304 entries =
305 g_list_append (entries,
306 menu_entry_create (_("&Undelete files (ext2fs only)"), CK_UndeleteCmd));
307 #endif
308 #ifdef LISTMODE_EDITOR
309 entries =
310 g_list_append (entries, menu_entry_create (_("&Listing format edit"), CK_ListmodeCmd));
311 #endif
312 #if defined (ENABLE_VFS_UNDELFS) || defined (LISTMODE_EDITOR)
313 entries = g_list_append (entries, menu_separator_create ());
314 #endif
315 entries =
316 g_list_append (entries, menu_entry_create (_("Edit &extension file"), CK_EditExtFileCmd));
317 entries = g_list_append (entries, menu_entry_create (_("Edit &menu file"), CK_EditMcMenuCmd));
318 entries =
319 g_list_append (entries,
320 menu_entry_create (_("Edit hi&ghlighting group file"), CK_EditFhlFileCmd));
322 return entries;
325 /* --------------------------------------------------------------------------------------------- */
327 static GList *
328 create_options_menu (void)
330 GList *entries = NULL;
332 entries = g_list_append (entries, menu_entry_create (_("&Configuration..."), CK_ConfigureBox));
333 entries = g_list_append (entries, menu_entry_create (_("&Layout..."), CK_LayoutBox));
334 entries =
335 g_list_append (entries, menu_entry_create (_("&Panel options..."), CK_PanelOptionsBox));
336 entries = g_list_append (entries, menu_entry_create (_("C&onfirmation..."), CK_ConfirmBox));
337 entries = g_list_append (entries, menu_entry_create (_("&Display bits..."), CK_DisplayBitsBox));
338 entries = g_list_append (entries, menu_entry_create (_("Learn &keys..."), CK_LearnKeys));
339 #ifdef ENABLE_VFS
340 entries = g_list_append (entries, menu_entry_create (_("&Virtual FS..."), CK_ConfigureVfs));
341 #endif
342 entries = g_list_append (entries, menu_separator_create ());
343 entries = g_list_append (entries, menu_entry_create (_("&Save setup"), CK_SaveSetupCmd));
345 return entries;
348 /* --------------------------------------------------------------------------------------------- */
350 static void
351 init_menu (void)
353 left_menu = create_menu ("", create_panel_menu (), "[Left and Right Menus]");
354 menubar_add_menu (the_menubar, left_menu);
355 menubar_add_menu (the_menubar, create_menu (_("&File"), create_file_menu (), "[File Menu]"));
356 menubar_add_menu (the_menubar,
357 create_menu (_("&Command"), create_command_menu (), "[Command Menu]"));
358 menubar_add_menu (the_menubar,
359 create_menu (_("&Options"), create_options_menu (), "[Options Menu]"));
360 right_menu = create_menu ("", create_panel_menu (), "[Left and Right Menus]");
361 menubar_add_menu (the_menubar, right_menu);
362 update_menu ();
365 /* --------------------------------------------------------------------------------------------- */
367 static void
368 menu_last_selected_cmd (void)
370 the_menubar->is_active = TRUE;
371 the_menubar->is_dropped = (drop_menus != 0);
372 the_menubar->previous_widget = dlg_get_current_widget_id (midnight_dlg);
373 dlg_select_widget (the_menubar);
376 /* --------------------------------------------------------------------------------------------- */
378 static void
379 menu_cmd (void)
381 if (the_menubar->is_active)
382 return;
384 if ((get_current_index () == 0) == (current_panel->active != 0))
385 the_menubar->selected = 0;
386 else
387 the_menubar->selected = g_list_length (the_menubar->menu) - 1;
388 menu_last_selected_cmd ();
391 /* --------------------------------------------------------------------------------------------- */
393 static void
394 sort_cmd (void)
396 WPanel *p;
397 const panel_field_t *sort_order;
399 if (!SELECTED_IS_PANEL)
400 return;
402 p = MENU_PANEL;
403 sort_order = sort_box (&p->sort_info);
404 panel_set_sort_order (p, sort_order);
407 /* --------------------------------------------------------------------------------------------- */
409 static char *
410 midnight_get_shortcut (unsigned long command)
412 const char *ext_map;
413 const char *shortcut = NULL;
415 shortcut = keybind_lookup_keymap_shortcut (main_map, command);
416 if (shortcut != NULL)
417 return g_strdup (shortcut);
419 shortcut = keybind_lookup_keymap_shortcut (panel_map, command);
420 if (shortcut != NULL)
421 return g_strdup (shortcut);
423 ext_map = keybind_lookup_keymap_shortcut (main_map, CK_StartExtMap1);
424 if (ext_map != NULL)
425 shortcut = keybind_lookup_keymap_shortcut (main_x_map, command);
426 if (shortcut != NULL)
427 return g_strdup_printf ("%s %s", ext_map, shortcut);
429 return NULL;
432 /* --------------------------------------------------------------------------------------------- */
434 static char *
435 midnight_get_title (const Dlg_head * h, size_t len)
437 /* TODO: share code with update_xterm_title_path() */
439 const char *path;
440 char host[BUF_TINY];
441 char *p;
442 struct passwd *pw = NULL;
443 char *login = NULL;
444 int res = 0;
446 (void) h;
448 path = strip_home_and_password (current_panel->cwd);
449 res = gethostname (host, sizeof (host));
450 if (res != 0)
451 host[0] = '\0';
452 else
453 host[sizeof (host) - 1] = '\0';
455 pw = getpwuid (getuid ());
456 if (pw != NULL)
457 login = g_strdup_printf ("%s@%s", pw->pw_name, host);
458 else
459 login = g_strdup (host);
461 p = g_strdup_printf ("%s [%s]:%s", _("Panels:"), login, path);
462 path = str_trunc (p, len - 4);
463 g_free (login);
464 g_free (p);
466 return g_strdup (path);
469 /* --------------------------------------------------------------------------------------------- */
471 static void
472 toggle_panels_split (void)
474 horizontal_split = !horizontal_split;
475 layout_change ();
476 do_refresh ();
479 /* --------------------------------------------------------------------------------------------- */
482 * Just a hack for allowing url-like pathnames to be accepted from the
483 * command line.
485 static void
486 translated_mc_chdir (char *dir)
488 char *newdir;
489 int ret;
491 newdir = vfs_translate_url (dir);
492 ret = mc_chdir (newdir);
493 g_free (newdir);
496 /* --------------------------------------------------------------------------------------------- */
498 static void
499 create_panels (void)
501 int current_index;
502 int other_index;
503 panel_view_mode_t current_mode, other_mode;
504 char original_dir[BUF_1K] = "\0";
506 if (boot_current_is_left)
508 current_index = 0;
509 other_index = 1;
510 current_mode = startup_left_mode;
511 other_mode = startup_right_mode;
513 else
515 current_index = 1;
516 other_index = 0;
517 current_mode = startup_right_mode;
518 other_mode = startup_left_mode;
520 /* Creates the left panel */
521 if (mc_run_param0 != NULL)
523 if (mc_run_param1 != NULL)
525 /* Ok, user has specified two dirs, save the original one,
526 * since we may not be able to chdir to the proper
527 * second directory later
529 mc_get_current_wd (original_dir, sizeof (original_dir) - 2);
531 translated_mc_chdir (mc_run_param0);
533 set_display_type (current_index, current_mode);
535 /* The other panel */
536 if (mc_run_param1 != NULL)
538 if (original_dir[0] != '\0')
539 translated_mc_chdir (original_dir);
540 translated_mc_chdir (mc_run_param1);
542 set_display_type (other_index, other_mode);
544 if (startup_left_mode == view_listing)
546 current_panel = left_panel;
548 else
550 if (right_panel)
551 current_panel = right_panel;
552 else
553 current_panel = left_panel;
556 /* Create the nice widgets */
557 cmdline = command_new (0, 0, 0);
558 the_prompt = label_new (0, 0, mc_prompt);
559 the_prompt->transparent = 1;
560 the_bar = buttonbar_new (keybar_visible);
562 the_hint = label_new (0, 0, 0);
563 the_hint->transparent = 1;
564 the_hint->auto_adjust_cols = 0;
565 the_hint->widget.cols = COLS;
567 the_menubar = menubar_new (0, 0, COLS, NULL);
570 /* --------------------------------------------------------------------------------------------- */
572 static void
573 copy_current_pathname (void)
575 char *cwd_path;
576 if (!command_prompt)
577 return;
579 cwd_path = remove_encoding_from_path (current_panel->cwd);
580 command_insert (cmdline, cwd_path, FALSE);
582 if (cwd_path[strlen (cwd_path) - 1] != PATH_SEP)
583 command_insert (cmdline, PATH_SEP_STR, FALSE);
584 g_free (cwd_path);
587 /* --------------------------------------------------------------------------------------------- */
589 static void
590 copy_other_pathname (void)
592 char *cwd_path;
594 if (get_other_type () != view_listing)
595 return;
597 if (!command_prompt)
598 return;
600 cwd_path = remove_encoding_from_path (other_panel->cwd);
601 command_insert (cmdline, cwd_path, FALSE);
603 if (cwd_path[strlen (cwd_path) - 1] != PATH_SEP)
604 command_insert (cmdline, PATH_SEP_STR, FALSE);
605 g_free (cwd_path);
608 /* --------------------------------------------------------------------------------------------- */
610 static void
611 copy_readlink (WPanel * panel)
613 if (!command_prompt)
614 return;
615 if (S_ISLNK (selection (panel)->st.st_mode))
617 char buffer[MC_MAXPATHLEN];
618 char *p = concat_dir_and_file (panel->cwd, selection (panel)->fname);
619 int i;
621 i = mc_readlink (p, buffer, MC_MAXPATHLEN - 1);
622 g_free (p);
623 if (i > 0)
625 buffer[i] = 0;
626 command_insert (cmdline, buffer, TRUE);
631 /* --------------------------------------------------------------------------------------------- */
633 static void
634 copy_current_readlink (void)
636 copy_readlink (current_panel);
639 /* --------------------------------------------------------------------------------------------- */
641 static void
642 copy_other_readlink (void)
644 if (get_other_type () == view_listing)
645 copy_readlink (other_panel);
648 /* --------------------------------------------------------------------------------------------- */
650 /** Insert the selected file name into the input line */
651 static void
652 copy_prog_name (void)
654 char *tmp;
655 if (!command_prompt)
656 return;
658 if (get_current_type () == view_tree)
660 WTree *tree = (WTree *) get_panel_widget (get_current_index ());
661 tmp = tree_selected_name (tree);
663 else
664 tmp = selection (current_panel)->fname;
666 command_insert (cmdline, tmp, TRUE);
669 /* --------------------------------------------------------------------------------------------- */
671 static void
672 copy_tagged (WPanel * panel)
674 int i;
676 if (!command_prompt)
677 return;
678 input_disable_update (cmdline);
679 if (panel->marked)
681 for (i = 0; i < panel->count; i++)
683 if (panel->dir.list[i].f.marked)
684 command_insert (cmdline, panel->dir.list[i].fname, TRUE);
687 else
689 command_insert (cmdline, panel->dir.list[panel->selected].fname, TRUE);
691 input_enable_update (cmdline);
694 /* --------------------------------------------------------------------------------------------- */
696 static void
697 copy_current_tagged (void)
699 copy_tagged (current_panel);
702 /* --------------------------------------------------------------------------------------------- */
704 static void
705 copy_other_tagged (void)
707 if (get_other_type () == view_listing)
708 copy_tagged (other_panel);
711 /* --------------------------------------------------------------------------------------------- */
713 static void
714 ctl_x_cmd (void)
716 ctl_x_map_enabled = TRUE;
719 /* --------------------------------------------------------------------------------------------- */
721 static void
722 init_xterm_support (void)
724 const char *termvalue;
726 termvalue = getenv ("TERM");
727 if (!termvalue || !(*termvalue))
729 fputs (_("The TERM environment variable is unset!\n"), stderr);
730 exit (EXIT_FAILURE);
733 /* Check mouse capabilities */
734 xmouse_seq = tty_tgetstr ("Km");
736 if (strcmp (termvalue, "cygwin") == 0)
738 mc_args__force_xterm = 1;
739 use_mouse_p = MOUSE_DISABLED;
742 if (mc_args__force_xterm || strncmp (termvalue, "xterm", 5) == 0
743 || strncmp (termvalue, "konsole", 7) == 0
744 || strncmp (termvalue, "rxvt", 4) == 0
745 || strcmp (termvalue, "Eterm") == 0 || strcmp (termvalue, "dtterm") == 0)
747 xterm_flag = 1;
749 #ifdef HAVE_SLANG
750 /* For 8-bit locales, NCurses handles 154 (0x9A) symbol properly, while S-Lang
751 * requires SLsmg_Display_Eight_Bit >= 154 (OR manual filtering if xterm display
752 * detected - but checking TERM would fail under screen, OR running xterm
753 * with allowC1Printable).
755 tty_display_8bit (FALSE);
756 #endif
758 /* Default to the standard xterm sequence */
759 if (!xmouse_seq)
761 xmouse_seq = ESC_STR "[M";
764 /* Enable mouse unless explicitly disabled by --nomouse */
765 if (use_mouse_p != MOUSE_DISABLED)
767 const char *color_term = getenv ("COLORTERM");
768 if (strncmp (termvalue, "rxvt", 4) == 0 ||
769 (color_term != NULL && strncmp (color_term, "rxvt", 4) == 0) ||
770 strcmp (termvalue, "Eterm") == 0)
772 use_mouse_p = MOUSE_XTERM_NORMAL_TRACKING;
774 else
776 use_mouse_p = MOUSE_XTERM_BUTTON_EVENT_TRACKING;
782 /* --------------------------------------------------------------------------------------------- */
784 static void
785 setup_mc (void)
787 #ifdef HAVE_SLANG
788 tty_display_8bit (full_eight_bits != 0);
789 #else
790 tty_display_8bit (eight_bit_clean != 0);
791 #endif
793 #ifdef HAVE_SUBSHELL_SUPPORT
794 if (use_subshell)
795 add_select_channel (subshell_pty, load_prompt, 0);
796 #endif /* !HAVE_SUBSHELL_SUPPORT */
798 tty_setup_sigwinch (sigwinch_handler);
800 if ((tty_baudrate () < 9600) || tty_is_slow ())
801 verbose = 0;
803 init_xterm_support ();
804 init_mouse ();
807 /* --------------------------------------------------------------------------------------------- */
809 static void
810 setup_dummy_mc (void)
812 char d[MC_MAXPATHLEN];
813 int ret;
815 mc_get_current_wd (d, MC_MAXPATHLEN);
816 setup_mc ();
817 ret = mc_chdir (d);
820 /* --------------------------------------------------------------------------------------------- */
822 static void
823 done_screen (void)
825 if ((quit & SUBSHELL_EXIT) == 0)
826 clr_scr ();
827 tty_reset_shell_mode ();
828 tty_noraw_mode ();
829 tty_keypad (FALSE);
832 /* --------------------------------------------------------------------------------------------- */
834 static void
835 done_mc (void)
837 disable_mouse ();
839 /* Setup shutdown
841 * We sync the profiles since the hotlist may have changed, while
842 * we only change the setup data if we have the auto save feature set
845 save_setup (auto_save_setup, panels_options.auto_save_setup);
846 done_screen ();
848 vfs_stamp_path (vfs_get_current_dir ());
850 if ((current_panel != NULL) && (get_current_type () == view_listing))
851 vfs_stamp_path (current_panel->cwd);
853 if ((other_panel != NULL) && (get_other_type () == view_listing))
854 vfs_stamp_path (other_panel->cwd);
857 /* --------------------------------------------------------------------------------------------- */
859 static void
860 create_panels_and_run_mc (void)
862 midnight_dlg->get_shortcut = midnight_get_shortcut;
863 midnight_dlg->get_title = midnight_get_title;
865 create_panels ();
867 add_widget (midnight_dlg, the_menubar);
868 init_menu ();
870 add_widget (midnight_dlg, get_panel_widget (0));
871 add_widget (midnight_dlg, get_panel_widget (1));
873 add_widget (midnight_dlg, the_hint);
874 add_widget (midnight_dlg, cmdline);
875 add_widget (midnight_dlg, the_prompt);
877 add_widget (midnight_dlg, the_bar);
878 midnight_set_buttonbar (the_bar);
880 /* Run the Midnight Commander if no file was specified in the command line */
881 run_dlg (midnight_dlg);
884 /* --------------------------------------------------------------------------------------------- */
886 /** result must be free'd (I think this should go in util.c) */
887 static char *
888 prepend_cwd_on_local (const char *filename)
890 char *d;
891 size_t l;
893 if (!vfs_file_is_local (filename) || g_path_is_absolute (filename))
894 return g_strdup (filename);
896 d = g_malloc (MC_MAXPATHLEN + strlen (filename) + 2);
897 mc_get_current_wd (d, MC_MAXPATHLEN);
898 l = strlen (d);
899 d[l++] = PATH_SEP;
900 strcpy (d + l, filename);
901 canonicalize_pathname (d);
902 return d;
905 /* --------------------------------------------------------------------------------------------- */
907 /** Invoke the internal view/edit routine with:
908 * the default processing and forcing the internal viewer/editor
910 static void
911 mc_maybe_editor_or_viewer (void)
913 switch (mc_run_mode)
915 #ifdef USE_INTERNAL_EDIT
916 case MC_RUN_EDITOR:
917 edit_file (mc_run_param0, mc_args__edit_start_line);
918 break;
919 #endif /* USE_INTERNAL_EDIT */
920 case MC_RUN_VIEWER:
922 char *path;
923 path = prepend_cwd_on_local (mc_run_param0);
924 view_file (path, 0, 1);
925 g_free (path);
926 break;
928 #ifdef USE_DIFF_VIEW
929 case MC_RUN_DIFFVIEWER:
930 diff_view (mc_run_param0, mc_run_param1, mc_run_param0, mc_run_param1);
931 break;
932 #endif /* USE_DIFF_VIEW */
933 default:
934 break;
938 /* --------------------------------------------------------------------------------------------- */
940 static gboolean
941 quit_cmd_internal (int quiet)
943 int q = quit;
944 size_t n;
946 n = dialog_switch_num () - 1;
947 if (n != 0)
949 char msg[BUF_MEDIUM];
951 g_snprintf (msg, sizeof (msg),
952 ngettext ("You have %zd opened screen. Quit anyway?",
953 "You have %zd opened screens. Quit anyway?", n), n);
955 if (query_dialog (_("The Midnight Commander"), msg, D_NORMAL, 2, _("&Yes"), _("&No")) != 0)
956 return FALSE;
957 q = 1;
959 else if (quiet || !confirm_exit)
960 q = 1;
961 else if (query_dialog (_("The Midnight Commander"),
962 _("Do you really want to quit the Midnight Commander?"),
963 D_NORMAL, 2, _("&Yes"), _("&No")) == 0)
964 q = 1;
966 if (q != 0)
968 #ifdef HAVE_SUBSHELL_SUPPORT
969 if (!use_subshell)
970 stop_dialogs ();
971 else if ((q = exit_subshell ()))
972 #endif
973 stop_dialogs ();
976 if (q != 0)
977 quit |= 1;
978 return (quit != 0);
981 /* --------------------------------------------------------------------------------------------- */
983 static gboolean
984 quit_cmd (void)
986 return quit_cmd_internal (0);
989 /* --------------------------------------------------------------------------------------------- */
991 static void
992 toggle_show_hidden (void)
994 panels_options.show_dot_files = !panels_options.show_dot_files;
995 update_panels (UP_RELOAD, UP_KEEPSEL);
998 /* --------------------------------------------------------------------------------------------- */
1001 * Repaint the contents of the panels without frames. To schedule panel
1002 * for repainting, set panel->dirty to 1. There are many reasons why
1003 * the panels need to be repainted, and this is a costly operation, so
1004 * it's done once per event.
1007 static void
1008 update_dirty_panels (void)
1010 if (get_current_type () == view_listing && current_panel->dirty)
1011 send_message ((Widget *) current_panel, WIDGET_DRAW, 0);
1013 if (get_other_type () == view_listing && other_panel->dirty)
1014 send_message ((Widget *) other_panel, WIDGET_DRAW, 0);
1017 /* --------------------------------------------------------------------------------------------- */
1019 static cb_ret_t
1020 midnight_execute_cmd (Widget * sender, unsigned long command)
1022 cb_ret_t res = MSG_HANDLED;
1024 (void) sender;
1026 /* stop quick search before executing any command */
1027 send_message ((Widget *) current_panel, WIDGET_COMMAND, CK_PanelStopSearch);
1029 switch (command)
1031 case CK_AddHotlist:
1032 add2hotlist_cmd ();
1033 break;
1034 case CK_ChangeListingCmd:
1035 change_listing_cmd ();
1036 break;
1037 case CK_ChmodCmd:
1038 chmod_cmd ();
1039 break;
1040 case CK_ChownCmd:
1041 chown_cmd ();
1042 break;
1043 case CK_ChownAdvancedCmd:
1044 chown_advanced_cmd ();
1045 break;
1046 case CK_CompareDirsCmd:
1047 compare_dirs_cmd ();
1048 break;
1049 case CK_ConfigureBox:
1050 configure_box ();
1051 break;
1052 #ifdef ENABLE_VFS
1053 case CK_ConfigureVfs:
1054 configure_vfs ();
1055 break;
1056 #endif
1057 case CK_ConfirmBox:
1058 confirm_box ();
1059 break;
1060 case CK_CopyCmd:
1061 copy_cmd ();
1062 break;
1063 case CK_CopyCurrentPathname:
1064 copy_current_pathname ();
1065 break;
1066 case CK_CopyCurrentReadlink:
1067 copy_current_readlink ();
1068 break;
1069 case CK_CopyCurrentTagged:
1070 copy_current_tagged ();
1071 break;
1072 case CK_CopyOtherPathname:
1073 copy_other_pathname ();
1074 break;
1075 case CK_CopyOtherReadlink:
1076 copy_other_readlink ();
1077 break;
1078 case CK_CopyOtherTagged:
1079 copy_other_tagged ();
1080 break;
1081 case CK_DeleteCmd:
1082 delete_cmd ();
1083 break;
1084 case CK_DialogListCmd:
1085 dialog_switch_list ();
1086 break;
1087 #ifdef USE_DIFF_VIEW
1088 case CK_DiffViewCmd:
1089 diff_view_cmd ();
1090 break;
1091 #endif
1092 case CK_DisplayBitsBox:
1093 display_bits_box ();
1094 break;
1095 case CK_EditCmd:
1096 edit_cmd ();
1097 break;
1098 #ifdef USE_INTERNAL_EDIT
1099 case CK_EditForceInternalCmd:
1100 edit_cmd_force_internal ();
1101 break;
1102 #endif
1103 case CK_EditExtFileCmd:
1104 ext_cmd ();
1105 break;
1106 case CK_EditFhlFileCmd:
1107 edit_fhl_cmd ();
1108 break;
1109 case CK_EditMcMenuCmd:
1110 edit_mc_menu_cmd ();
1111 break;
1112 case CK_EditSymlinkCmd:
1113 edit_symlink_cmd ();
1114 break;
1115 case CK_ExternalPanelize:
1116 external_panelize ();
1117 break;
1118 case CK_FilterCmd:
1119 filter_cmd ();
1120 break;
1121 case CK_FilteredViewCmd:
1122 filtered_view_cmd ();
1123 break;
1124 case CK_FindCmd:
1125 find_cmd ();
1126 break;
1127 #ifdef ENABLE_VFS_FISH
1128 case CK_FishlinkCmd:
1129 fishlink_cmd ();
1130 break;
1131 #endif
1132 #ifdef ENABLE_VFS_FTP
1133 case CK_FtplinkCmd:
1134 ftplink_cmd ();
1135 break;
1136 #endif
1137 case CK_HelpCmd:
1138 help_cmd ();
1139 break;
1140 case CK_HistoryCmd:
1141 history_cmd ();
1142 break;
1143 case CK_InfoCmd:
1144 if (sender == (Widget *) the_menubar)
1145 info_cmd (); /* mwnu */
1146 else
1147 info_cmd_no_menu (); /* shortcut or buttonbar */
1148 break;
1149 #ifdef WITH_BACKGROUND
1150 case CK_JobsCmd:
1151 jobs_cmd ();
1152 break;
1153 #endif
1154 case CK_LayoutBox:
1155 layout_box ();
1156 break;
1157 case CK_LearnKeys:
1158 learn_keys ();
1159 break;
1160 case CK_LinkCmd:
1161 link_cmd (LINK_HARDLINK);
1162 break;
1163 case CK_ListingCmd:
1164 listing_cmd ();
1165 break;
1166 #ifdef LISTMODE_EDITOR
1167 case CK_ListmodeCmd:
1168 listmode_cmd ();
1169 break;
1170 #endif
1171 case CK_MenuCmd:
1172 menu_cmd ();
1173 break;
1174 case CK_MenuLastSelectedCmd:
1175 menu_last_selected_cmd ();
1176 break;
1177 case CK_MkdirCmd:
1178 mkdir_cmd ();
1179 break;
1180 case CK_PanelOptionsBox:
1181 panel_options_box ();
1182 break;
1183 #ifdef HAVE_CHARSET
1184 case CK_PanelSetPanelEncoding:
1185 encoding_cmd ();
1186 break;
1187 #endif
1188 case CK_QuickCdCmd:
1189 quick_cd_cmd ();
1190 break;
1191 case CK_QuickChdirCmd:
1192 quick_chdir_cmd ();
1193 break;
1194 case CK_QuickViewCmd:
1195 if (sender == (Widget *) the_menubar)
1196 quick_view_cmd (); /* menu */
1197 else
1198 quick_cmd_no_menu (); /* shortcut or buttonabr */
1199 break;
1200 case CK_QuietQuitCmd:
1201 quiet_quit_cmd ();
1202 break;
1203 case CK_QuitCmd:
1204 quit_cmd ();
1205 break;
1206 case CK_RelativeSymlinkCmd:
1207 link_cmd (LINK_SYMLINK_RELATIVE);
1208 break;
1209 case CK_RenameCmd:
1210 rename_cmd ();
1211 break;
1212 case CK_RereadCmd:
1213 reread_cmd ();
1214 break;
1215 #ifdef ENABLE_VFS
1216 case CK_ReselectVfs:
1217 reselect_vfs ();
1218 break;
1219 #endif
1220 case CK_ReverseSelectionCmd:
1221 reverse_selection_cmd ();
1222 break;
1223 case CK_SaveSetupCmd:
1224 save_setup_cmd ();
1225 break;
1226 case CK_SelectCmd:
1227 select_cmd ();
1228 break;
1229 case CK_ShowCommandLine:
1230 view_other_cmd ();
1231 break;
1232 case CK_SingleDirsizeCmd:
1233 smart_dirsize_cmd ();
1234 break;
1235 #ifdef ENABLE_VFS_SMB
1236 case CK_SmblinkCmd:
1237 smblink_cmd ();
1238 break;
1239 #endif /* ENABLE_VFS_SMB */
1240 case CK_Sort:
1241 sort_cmd ();
1242 break;
1243 case CK_StartExtMap1:
1244 ctl_x_cmd ();
1245 break;
1246 case CK_SuspendCmd:
1247 suspend_cmd ();
1248 break;
1249 case CK_SwapCmd:
1250 swap_cmd ();
1251 break;
1252 case CK_SymlinkCmd:
1253 link_cmd (LINK_SYMLINK_ABSOLUTE);
1254 break;
1255 case CK_ToggleListingCmd:
1256 toggle_listing_cmd ();
1257 break;
1258 case CK_ToggleShowHidden:
1259 toggle_show_hidden ();
1260 break;
1261 case CK_TogglePanelsSplit:
1262 toggle_panels_split ();
1263 break;
1264 case CK_TreeCmd:
1265 tree_cmd ();
1266 break;
1267 case CK_TreeBoxCmd:
1268 treebox_cmd ();
1269 break;
1270 #ifdef ENABLE_VFS_UNDELFS
1271 case CK_UndeleteCmd:
1272 undelete_cmd ();
1273 break;
1274 #endif
1275 case CK_UnselectCmd:
1276 unselect_cmd ();
1277 break;
1278 case CK_UserMenuCmd:
1279 user_file_menu_cmd ();
1280 break;
1281 case CK_ViewCmd:
1282 view_cmd ();
1283 break;
1284 case CK_ViewFileCmd:
1285 view_file_cmd ();
1286 break;
1287 case CK_DialogCancel:
1288 /* don't close panels due to SIGINT */
1289 break;
1290 default:
1291 res = MSG_NOT_HANDLED;
1294 return res;
1297 /* --------------------------------------------------------------------------------------------- */
1299 static cb_ret_t
1300 midnight_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
1302 unsigned long command;
1304 switch (msg)
1306 case DLG_INIT:
1307 panel_init ();
1308 setup_panels ();
1309 return MSG_HANDLED;
1311 case DLG_DRAW:
1312 load_hint (1);
1313 /* We handle the special case of the output lines */
1314 if (console_flag && output_lines)
1315 show_console_contents (output_start_y,
1316 LINES - output_lines - keybar_visible -
1317 1, LINES - keybar_visible - 1);
1318 return MSG_HANDLED;
1320 case DLG_RESIZE:
1321 setup_panels ();
1322 menubar_arrange (the_menubar);
1323 return MSG_HANDLED;
1325 case DLG_IDLE:
1326 /* We only need the first idle event to show user menu after start */
1327 set_idle_proc (h, 0);
1329 if (boot_current_is_left)
1330 dlg_select_widget (get_panel_widget (0));
1331 else
1332 dlg_select_widget (get_panel_widget (1));
1334 if (auto_menu)
1335 midnight_execute_cmd (NULL, CK_UserMenuCmd);
1336 return MSG_HANDLED;
1338 case DLG_KEY:
1339 if (ctl_x_map_enabled)
1341 ctl_x_map_enabled = FALSE;
1342 command = keybind_lookup_keymap_command (main_x_map, parm);
1343 if (command != CK_Ignore_Key)
1344 return midnight_execute_cmd (NULL, command);
1347 /* FIXME: should handle all menu shortcuts before this point */
1348 if (the_menubar->is_active)
1349 return MSG_NOT_HANDLED;
1351 if (parm == '\t')
1352 input_free_completions (cmdline);
1354 if (parm == '\n')
1356 size_t i;
1358 for (i = 0; cmdline->buffer[i] != '\0' &&
1359 (cmdline->buffer[i] == ' ' || cmdline->buffer[i] == '\t'); i++)
1362 if (cmdline->buffer[i] != '\0')
1364 send_message ((Widget *) cmdline, WIDGET_KEY, parm);
1365 return MSG_HANDLED;
1368 input_insert (cmdline, "", FALSE);
1369 cmdline->point = 0;
1372 /* Ctrl-Enter and Alt-Enter */
1373 if (((parm & ~(KEY_M_CTRL | KEY_M_ALT)) == '\n') && (parm & (KEY_M_CTRL | KEY_M_ALT)))
1375 copy_prog_name ();
1376 return MSG_HANDLED;
1379 /* Ctrl-Shift-Enter */
1380 if (parm == (KEY_M_CTRL | KEY_M_SHIFT | '\n'))
1382 copy_current_pathname ();
1383 copy_prog_name ();
1384 return MSG_HANDLED;
1387 if ((!alternate_plus_minus || !(console_flag || xterm_flag))
1388 && !quote && !current_panel->searching)
1390 if (!only_leading_plus_minus)
1392 /* Special treatement, since the input line will eat them */
1393 if (parm == '+')
1395 select_cmd ();
1396 return MSG_HANDLED;
1399 if (parm == '\\' || parm == '-')
1401 unselect_cmd ();
1402 return MSG_HANDLED;
1405 if (parm == '*')
1407 reverse_selection_cmd ();
1408 return MSG_HANDLED;
1411 else if (!command_prompt || !cmdline->buffer[0])
1413 /* Special treatement '+', '-', '\', '*' only when this is
1414 * first char on input line
1417 if (parm == '+')
1419 select_cmd ();
1420 return MSG_HANDLED;
1423 if (parm == '\\' || parm == '-')
1425 unselect_cmd ();
1426 return MSG_HANDLED;
1429 if (parm == '*')
1431 reverse_selection_cmd ();
1432 return MSG_HANDLED;
1436 return MSG_NOT_HANDLED;
1438 case DLG_HOTKEY_HANDLED:
1439 if ((get_current_type () == view_listing) && current_panel->searching)
1441 current_panel->dirty = 1; /* FIXME: unneeded? */
1442 send_message ((Widget *) current_panel, WIDGET_COMMAND, CK_PanelStopSearch);
1444 return MSG_HANDLED;
1446 case DLG_UNHANDLED_KEY:
1447 if (command_prompt)
1449 cb_ret_t v;
1451 v = send_message ((Widget *) cmdline, WIDGET_KEY, parm);
1452 if (v == MSG_HANDLED)
1453 return MSG_HANDLED;
1456 if (ctl_x_map_enabled)
1458 ctl_x_map_enabled = FALSE;
1459 command = keybind_lookup_keymap_command (main_x_map, parm);
1461 else
1462 command = keybind_lookup_keymap_command (main_map, parm);
1464 return (command == CK_Ignore_Key) ? MSG_NOT_HANDLED : midnight_execute_cmd (NULL, command);
1466 case DLG_POST_KEY:
1467 if (!the_menubar->is_active)
1468 update_dirty_panels ();
1469 return MSG_HANDLED;
1471 case DLG_ACTION:
1472 /* shortcut */
1473 if (sender == NULL)
1474 return midnight_execute_cmd (NULL, parm);
1475 /* message from menu */
1476 if (sender == (Widget *) the_menubar)
1477 return midnight_execute_cmd (sender, parm);
1478 /* message from buttonbar */
1479 if (sender == (Widget *) the_bar)
1481 if (data != NULL)
1482 return send_message ((Widget *) data, WIDGET_COMMAND, parm);
1483 return midnight_execute_cmd (sender, parm);
1485 return MSG_NOT_HANDLED;
1487 case DLG_END:
1488 panel_deinit ();
1489 return MSG_HANDLED;
1491 default:
1492 return default_dlg_callback (h, sender, msg, parm, data);
1496 /* --------------------------------------------------------------------------------------------- */
1497 /*** public functions ****************************************************************************/
1498 /* --------------------------------------------------------------------------------------------- */
1500 void
1501 update_menu (void)
1503 menu_set_name (left_menu, horizontal_split ? _("&Above") : _("&Left"));
1504 menu_set_name (right_menu, horizontal_split ? _("&Below") : _("&Right"));
1505 menubar_arrange (the_menubar);
1506 menubar_set_visible (the_menubar, menubar_visible);
1509 void
1510 midnight_set_buttonbar (WButtonBar * b)
1512 buttonbar_set_label (b, 1, Q_ ("ButtonBar|Help"), main_map, NULL);
1513 buttonbar_set_label (b, 2, Q_ ("ButtonBar|Menu"), main_map, NULL);
1514 buttonbar_set_label (b, 3, Q_ ("ButtonBar|View"), main_map, NULL);
1515 buttonbar_set_label (b, 4, Q_ ("ButtonBar|Edit"), main_map, NULL);
1516 buttonbar_set_label (b, 5, Q_ ("ButtonBar|Copy"), main_map, NULL);
1517 buttonbar_set_label (b, 6, Q_ ("ButtonBar|RenMov"), main_map, NULL);
1518 buttonbar_set_label (b, 7, Q_ ("ButtonBar|Mkdir"), main_map, NULL);
1519 buttonbar_set_label (b, 8, Q_ ("ButtonBar|Delete"), main_map, NULL);
1520 buttonbar_set_label (b, 9, Q_ ("ButtonBar|PullDn"), main_map, NULL);
1521 buttonbar_set_label (b, 10, Q_ ("ButtonBar|Quit"), main_map, NULL);
1524 /* --------------------------------------------------------------------------------------------- */
1526 * Load new hint and display it.
1527 * IF force is not 0, ignore the timeout.
1530 void
1531 load_hint (gboolean force)
1533 char *hint;
1535 if (the_hint->widget.owner == NULL)
1536 return;
1538 if (!message_visible)
1540 label_set_text (the_hint, NULL);
1541 return;
1544 hint = get_random_hint (force);
1546 if (hint != NULL)
1548 if (*hint != '\0')
1549 set_hintbar (hint);
1550 g_free (hint);
1552 else
1554 char text[BUF_SMALL];
1556 g_snprintf (text, sizeof (text), _("GNU Midnight Commander %s\n"), VERSION);
1557 set_hintbar (text);
1561 /* --------------------------------------------------------------------------------------------- */
1563 void
1564 change_panel (void)
1566 input_free_completions (cmdline);
1567 dlg_one_down (midnight_dlg);
1570 /* --------------------------------------------------------------------------------------------- */
1572 /** Save current stat of directories to avoid reloading the panels
1573 * when no modifications have taken place
1575 void
1576 save_cwds_stat (void)
1578 if (panels_options.fast_reload)
1580 mc_stat (current_panel->cwd, &(current_panel->dir_stat));
1581 if (get_other_type () == view_listing)
1582 mc_stat (other_panel->cwd, &(other_panel->dir_stat));
1586 /* --------------------------------------------------------------------------------------------- */
1588 gboolean
1589 quiet_quit_cmd (void)
1591 print_last_revert = TRUE;
1592 return quit_cmd_internal (1);
1595 /* --------------------------------------------------------------------------------------------- */
1597 /** Run the main dialog that occupies the whole screen */
1598 void
1599 do_nc (void)
1601 dlg_colors_t midnight_colors;
1603 midnight_colors[DLG_COLOR_NORMAL] = mc_skin_color_get ("dialog", "_default_");
1604 midnight_colors[DLG_COLOR_FOCUS] = mc_skin_color_get ("dialog", "focus");
1605 midnight_colors[DLG_COLOR_HOT_NORMAL] = mc_skin_color_get ("dialog", "hotnormal");
1606 midnight_colors[DLG_COLOR_HOT_FOCUS] = mc_skin_color_get ("dialog", "hotfocus");
1607 midnight_colors[DLG_COLOR_TITLE] = mc_skin_color_get ("dialog", "title");
1609 #ifdef USE_INTERNAL_EDIT
1610 edit_stack_init ();
1611 #endif
1613 midnight_dlg = create_dlg (FALSE, 0, 0, LINES, COLS, midnight_colors, midnight_callback,
1614 "[main]", NULL, DLG_WANT_IDLE);
1616 if (mc_run_mode == MC_RUN_FULL)
1617 setup_mc ();
1618 else
1619 setup_dummy_mc ();
1621 /* Check if we were invoked as an editor or file viewer */
1622 if (mc_run_mode != MC_RUN_FULL)
1623 mc_maybe_editor_or_viewer ();
1624 else
1626 create_panels_and_run_mc ();
1628 /* destroy_dlg destroys even current_panel->cwd, so we have to save a copy :) */
1629 if (mc_args__last_wd_file != NULL && vfs_current_is_local ())
1630 last_wd_string = g_strdup (current_panel->cwd);
1633 /* Program end */
1634 midnight_shutdown = 1;
1635 dialog_switch_shutdown ();
1636 done_mc ();
1637 destroy_dlg (midnight_dlg);
1638 current_panel = NULL;
1640 #ifdef USE_INTERNAL_EDIT
1641 edit_stack_free ();
1642 #endif
1645 /* --------------------------------------------------------------------------------------------- */