Refactoring.
[midnight-commander/osp/fridrivaxxx.git] / src / filemanager / midnight.c
blobf7b3c51a0b6786d715601e5600f55891d41afe2e
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 /* Mouse type: GPM, xterm or none */
116 Mouse_Type use_mouse_p = MOUSE_NONE;
118 /* The dialog handle for the main program */
119 Dlg_head *midnight_dlg = NULL;
121 /*** file scope macro definitions ****************************************************************/
123 #ifdef HAVE_CHARSET
125 * Don't restrict the output on the screen manager level,
126 * the translation tables take care of it.
128 #define full_eight_bits (1)
129 #define eight_bit_clean (1)
130 #endif /* !HAVE_CHARSET */
132 /*** file scope type declarations ****************************************************************/
134 /*** file scope variables ************************************************************************/
136 static Menu *left_menu, *right_menu;
138 static gboolean ctl_x_map_enabled = FALSE;
140 /*** file scope functions ************************************************************************/
142 /** Stop MC main dialog and the current dialog if it exists.
143 * Needed to provide fast exit from MC viewer or editor on shell exit */
144 static void
145 stop_dialogs (void)
147 midnight_dlg->state = DLG_CLOSED;
149 if ((top_dlg != NULL) && (top_dlg->data != NULL))
150 ((Dlg_head *) top_dlg->data)->state = DLG_CLOSED;
153 /* --------------------------------------------------------------------------------------------- */
155 static void
156 treebox_cmd (void)
158 char *sel_dir;
160 sel_dir = tree_box (selection (current_panel)->fname);
161 if (sel_dir)
163 do_cd (sel_dir, cd_exact);
164 g_free (sel_dir);
168 /* --------------------------------------------------------------------------------------------- */
170 #ifdef LISTMODE_EDITOR
171 static void
172 listmode_cmd (void)
174 char *newmode;
176 if (get_current_type () != view_listing)
177 return;
179 newmode = listmode_edit (current_panel->user_format);
180 if (!newmode)
181 return;
183 g_free (current_panel->user_format);
184 current_panel->list_type = list_user;
185 current_panel->user_format = newmode;
186 set_panel_formats (current_panel);
188 do_refresh ();
190 #endif /* LISTMODE_EDITOR */
192 /* --------------------------------------------------------------------------------------------- */
194 static GList *
195 create_panel_menu (void)
197 GList *entries = NULL;
199 entries = g_list_append (entries, menu_entry_create (_("File listin&g"), CK_ListingCmd));
200 entries = g_list_append (entries, menu_entry_create (_("&Quick view"), CK_QuickViewCmd));
201 entries = g_list_append (entries, menu_entry_create (_("&Info"), CK_InfoCmd));
202 entries = g_list_append (entries, menu_entry_create (_("&Tree"), CK_TreeCmd));
203 entries = g_list_append (entries, menu_separator_create ());
204 entries =
205 g_list_append (entries, menu_entry_create (_("&Listing mode..."), CK_ChangeListingCmd));
206 entries = g_list_append (entries, menu_entry_create (_("&Sort order..."), CK_Sort));
207 entries = g_list_append (entries, menu_entry_create (_("&Filter..."), CK_FilterCmd));
208 #ifdef HAVE_CHARSET
209 entries =
210 g_list_append (entries, menu_entry_create (_("&Encoding..."), CK_PanelSetPanelEncoding));
211 #endif
212 #ifdef ENABLE_VFS_NET
213 entries = g_list_append (entries, menu_separator_create ());
214 #ifdef ENABLE_VFS_FTP
215 entries = g_list_append (entries, menu_entry_create (_("FT&P link..."), CK_FtplinkCmd));
216 #endif
217 #ifdef ENABLE_VFS_FISH
218 entries = g_list_append (entries, menu_entry_create (_("S&hell link..."), CK_FishlinkCmd));
219 #endif
220 #ifdef ENABLE_VFS_SMB
221 entries = g_list_append (entries, menu_entry_create (_("SM&B link..."), CK_SmblinkCmd));
222 #endif
223 #endif /* ENABLE_VFS_NET */
224 entries = g_list_append (entries, menu_separator_create ());
225 entries = g_list_append (entries, menu_entry_create (_("&Rescan"), CK_RereadCmd));
227 return entries;
230 /* --------------------------------------------------------------------------------------------- */
232 static GList *
233 create_file_menu (void)
235 GList *entries = NULL;
237 entries = g_list_append (entries, menu_entry_create (_("&View"), CK_ViewCmd));
238 entries = g_list_append (entries, menu_entry_create (_("Vie&w file..."), CK_ViewFileCmd));
239 entries = g_list_append (entries, menu_entry_create (_("&Filtered view"), CK_FilteredViewCmd));
240 entries = g_list_append (entries, menu_entry_create (_("&Edit"), CK_EditCmd));
241 entries = g_list_append (entries, menu_entry_create (_("&Copy"), CK_CopyCmd));
242 entries = g_list_append (entries, menu_entry_create (_("C&hmod"), CK_ChmodCmd));
243 entries = g_list_append (entries, menu_entry_create (_("&Link"), CK_LinkCmd));
244 entries = g_list_append (entries, menu_entry_create (_("&Symlink"), CK_SymlinkCmd));
245 entries =
246 g_list_append (entries, menu_entry_create (_("Relative symlin&k"), CK_RelativeSymlinkCmd));
247 entries = g_list_append (entries, menu_entry_create (_("Edit s&ymlink"), CK_EditSymlinkCmd));
248 entries = g_list_append (entries, menu_entry_create (_("Ch&own"), CK_ChownCmd));
249 entries =
250 g_list_append (entries, menu_entry_create (_("&Advanced chown"), CK_ChownAdvancedCmd));
251 entries = g_list_append (entries, menu_entry_create (_("&Rename/Move"), CK_RenameCmd));
252 entries = g_list_append (entries, menu_entry_create (_("&Mkdir"), CK_MkdirCmd));
253 entries = g_list_append (entries, menu_entry_create (_("&Delete"), CK_DeleteCmd));
254 entries = g_list_append (entries, menu_entry_create (_("&Quick cd"), CK_QuickCdCmd));
255 entries = g_list_append (entries, menu_separator_create ());
256 entries = g_list_append (entries, menu_entry_create (_("Select &group"), CK_SelectCmd));
257 entries = g_list_append (entries, menu_entry_create (_("U&nselect group"), CK_UnselectCmd));
258 entries =
259 g_list_append (entries,
260 menu_entry_create (_("Reverse selec&tion"), CK_ReverseSelectionCmd));
261 entries = g_list_append (entries, menu_separator_create ());
262 entries = g_list_append (entries, menu_entry_create (_("E&xit"), CK_QuitCmd));
264 return entries;
267 /* --------------------------------------------------------------------------------------------- */
269 static GList *
270 create_command_menu (void)
272 /* I know, I'm lazy, but the tree widget when it's not running
273 * as a panel still has some problems, I have not yet finished
274 * the WTree widget port, sorry.
276 GList *entries = NULL;
278 entries = g_list_append (entries, menu_entry_create (_("&User menu"), CK_UserMenuCmd));
279 entries = g_list_append (entries, menu_entry_create (_("&Directory tree"), CK_TreeBoxCmd));
280 entries = g_list_append (entries, menu_entry_create (_("&Find file"), CK_FindCmd));
281 entries = g_list_append (entries, menu_entry_create (_("S&wap panels"), CK_SwapCmd));
282 entries =
283 g_list_append (entries, menu_entry_create (_("Switch &panels on/off"), CK_ShowCommandLine));
284 entries =
285 g_list_append (entries, menu_entry_create (_("&Compare directories"), CK_CompareDirsCmd));
286 #ifdef USE_DIFF_VIEW
287 entries = g_list_append (entries, menu_entry_create (_("&View diff files"), CK_DiffViewCmd));
288 #endif
289 entries =
290 g_list_append (entries, menu_entry_create (_("E&xternal panelize"), CK_ExternalPanelize));
291 entries =
292 g_list_append (entries,
293 menu_entry_create (_("Show directory s&izes"), CK_SingleDirsizeCmd));
294 entries = g_list_append (entries, menu_separator_create ());
295 entries = g_list_append (entries, menu_entry_create (_("Command &history"), CK_HistoryCmd));
296 entries =
297 g_list_append (entries, menu_entry_create (_("Di&rectory hotlist"), CK_QuickChdirCmd));
298 #ifdef ENABLE_VFS
299 entries = g_list_append (entries, menu_entry_create (_("&Active VFS list"), CK_ReselectVfs));
300 #endif
301 #ifdef WITH_BACKGROUND
302 entries = g_list_append (entries, menu_entry_create (_("&Background jobs"), CK_JobsCmd));
303 #endif
304 entries = g_list_append (entries, menu_entry_create (_("Screen lis&t"), CK_DialogListCmd));
305 entries = g_list_append (entries, menu_separator_create ());
306 #ifdef ENABLE_VFS_UNDELFS
307 entries =
308 g_list_append (entries,
309 menu_entry_create (_("&Undelete files (ext2fs only)"), CK_UndeleteCmd));
310 #endif
311 #ifdef LISTMODE_EDITOR
312 entries =
313 g_list_append (entries, menu_entry_create (_("&Listing format edit"), CK_ListmodeCmd));
314 #endif
315 #if defined (ENABLE_VFS_UNDELFS) || defined (LISTMODE_EDITOR)
316 entries = g_list_append (entries, menu_separator_create ());
317 #endif
318 entries =
319 g_list_append (entries, menu_entry_create (_("Edit &extension file"), CK_EditExtFileCmd));
320 entries = g_list_append (entries, menu_entry_create (_("Edit &menu file"), CK_EditMcMenuCmd));
321 entries =
322 g_list_append (entries,
323 menu_entry_create (_("Edit hi&ghlighting group file"), CK_EditFhlFileCmd));
325 return entries;
328 /* --------------------------------------------------------------------------------------------- */
330 static GList *
331 create_options_menu (void)
333 GList *entries = NULL;
335 entries = g_list_append (entries, menu_entry_create (_("&Configuration..."), CK_ConfigureBox));
336 entries = g_list_append (entries, menu_entry_create (_("&Layout..."), CK_LayoutBox));
337 entries =
338 g_list_append (entries, menu_entry_create (_("&Panel options..."), CK_PanelOptionsBox));
339 entries = g_list_append (entries, menu_entry_create (_("C&onfirmation..."), CK_ConfirmBox));
340 entries = g_list_append (entries, menu_entry_create (_("&Display bits..."), CK_DisplayBitsBox));
341 entries = g_list_append (entries, menu_entry_create (_("Learn &keys..."), CK_LearnKeys));
342 #ifdef ENABLE_VFS
343 entries = g_list_append (entries, menu_entry_create (_("&Virtual FS..."), CK_ConfigureVfs));
344 #endif
345 entries = g_list_append (entries, menu_separator_create ());
346 entries = g_list_append (entries, menu_entry_create (_("&Save setup"), CK_SaveSetupCmd));
348 return entries;
351 /* --------------------------------------------------------------------------------------------- */
353 static void
354 init_menu (void)
356 left_menu = create_menu ("", create_panel_menu (), "[Left and Right Menus]");
357 menubar_add_menu (the_menubar, left_menu);
358 menubar_add_menu (the_menubar, create_menu (_("&File"), create_file_menu (), "[File Menu]"));
359 menubar_add_menu (the_menubar,
360 create_menu (_("&Command"), create_command_menu (), "[Command Menu]"));
361 menubar_add_menu (the_menubar,
362 create_menu (_("&Options"), create_options_menu (), "[Options Menu]"));
363 right_menu = create_menu ("", create_panel_menu (), "[Left and Right Menus]");
364 menubar_add_menu (the_menubar, right_menu);
365 update_menu ();
368 /* --------------------------------------------------------------------------------------------- */
370 static void
371 menu_last_selected_cmd (void)
373 the_menubar->is_active = TRUE;
374 the_menubar->is_dropped = (drop_menus != 0);
375 the_menubar->previous_widget = dlg_get_current_widget_id (midnight_dlg);
376 dlg_select_widget (the_menubar);
379 /* --------------------------------------------------------------------------------------------- */
381 static void
382 menu_cmd (void)
384 if (the_menubar->is_active)
385 return;
387 if ((get_current_index () == 0) == (current_panel->active != 0))
388 the_menubar->selected = 0;
389 else
390 the_menubar->selected = g_list_length (the_menubar->menu) - 1;
391 menu_last_selected_cmd ();
394 /* --------------------------------------------------------------------------------------------- */
396 static void
397 sort_cmd (void)
399 WPanel *p;
400 const panel_field_t *sort_order;
402 if (!SELECTED_IS_PANEL)
403 return;
405 p = MENU_PANEL;
406 sort_order = sort_box (&p->sort_info);
407 panel_set_sort_order (p, sort_order);
410 /* --------------------------------------------------------------------------------------------- */
412 static char *
413 midnight_get_shortcut (unsigned long command)
415 const char *ext_map;
416 const char *shortcut = NULL;
418 shortcut = keybind_lookup_keymap_shortcut (main_map, command);
419 if (shortcut != NULL)
420 return g_strdup (shortcut);
422 shortcut = keybind_lookup_keymap_shortcut (panel_map, command);
423 if (shortcut != NULL)
424 return g_strdup (shortcut);
426 ext_map = keybind_lookup_keymap_shortcut (main_map, CK_StartExtMap1);
427 if (ext_map != NULL)
428 shortcut = keybind_lookup_keymap_shortcut (main_x_map, command);
429 if (shortcut != NULL)
430 return g_strdup_printf ("%s %s", ext_map, shortcut);
432 return NULL;
435 /* --------------------------------------------------------------------------------------------- */
437 static char *
438 midnight_get_title (const Dlg_head * h, size_t len)
440 /* TODO: share code with update_xterm_title_path() */
442 const char *path;
443 char host[BUF_TINY];
444 char *p;
445 struct passwd *pw = NULL;
446 char *login = NULL;
447 int res = 0;
449 (void) h;
451 path = strip_home_and_password (current_panel->cwd);
452 res = gethostname (host, sizeof (host));
453 if (res != 0)
454 host[0] = '\0';
455 else
456 host[sizeof (host) - 1] = '\0';
458 pw = getpwuid (getuid ());
459 if (pw != NULL)
460 login = g_strdup_printf ("%s@%s", pw->pw_name, host);
461 else
462 login = g_strdup (host);
464 p = g_strdup_printf ("%s [%s]:%s", _("Panels:"), login, path);
465 path = str_trunc (p, len - 4);
466 g_free (login);
467 g_free (p);
469 return g_strdup (path);
472 /* --------------------------------------------------------------------------------------------- */
474 static void
475 toggle_panels_split (void)
477 horizontal_split = !horizontal_split;
478 layout_change ();
479 do_refresh ();
482 /* --------------------------------------------------------------------------------------------- */
485 * Just a hack for allowing url-like pathnames to be accepted from the
486 * command line.
488 static void
489 translated_mc_chdir (char *dir)
491 char *newdir;
492 int ret;
494 newdir = vfs_translate_url (dir);
495 ret = mc_chdir (newdir);
496 g_free (newdir);
499 /* --------------------------------------------------------------------------------------------- */
501 static void
502 create_panels (void)
504 int current_index;
505 int other_index;
506 panel_view_mode_t current_mode, other_mode;
507 char original_dir[BUF_1K] = "\0";
509 if (boot_current_is_left)
511 current_index = 0;
512 other_index = 1;
513 current_mode = startup_left_mode;
514 other_mode = startup_right_mode;
516 else
518 current_index = 1;
519 other_index = 0;
520 current_mode = startup_right_mode;
521 other_mode = startup_left_mode;
523 /* Creates the left panel */
524 if (mc_run_param0 != NULL)
526 if (mc_run_param1 != NULL)
528 /* Ok, user has specified two dirs, save the original one,
529 * since we may not be able to chdir to the proper
530 * second directory later
532 mc_get_current_wd (original_dir, sizeof (original_dir) - 2);
534 translated_mc_chdir (mc_run_param0);
536 set_display_type (current_index, current_mode);
538 /* The other panel */
539 if (mc_run_param1 != NULL)
541 if (original_dir[0] != '\0')
542 translated_mc_chdir (original_dir);
543 translated_mc_chdir (mc_run_param1);
545 set_display_type (other_index, other_mode);
547 if (startup_left_mode == view_listing)
549 current_panel = left_panel;
551 else
553 if (right_panel)
554 current_panel = right_panel;
555 else
556 current_panel = left_panel;
559 /* Create the nice widgets */
560 cmdline = command_new (0, 0, 0);
561 the_prompt = label_new (0, 0, mc_prompt);
562 the_prompt->transparent = 1;
563 the_bar = buttonbar_new (keybar_visible);
565 the_hint = label_new (0, 0, 0);
566 the_hint->transparent = 1;
567 the_hint->auto_adjust_cols = 0;
568 the_hint->widget.cols = COLS;
570 the_menubar = menubar_new (0, 0, COLS, NULL);
573 /* --------------------------------------------------------------------------------------------- */
575 static void
576 copy_current_pathname (void)
578 char *cwd_path;
579 if (!command_prompt)
580 return;
582 cwd_path = remove_encoding_from_path (current_panel->cwd);
583 command_insert (cmdline, cwd_path, FALSE);
585 if (cwd_path[strlen (cwd_path) - 1] != PATH_SEP)
586 command_insert (cmdline, PATH_SEP_STR, FALSE);
587 g_free (cwd_path);
590 /* --------------------------------------------------------------------------------------------- */
592 static void
593 copy_other_pathname (void)
595 char *cwd_path;
597 if (get_other_type () != view_listing)
598 return;
600 if (!command_prompt)
601 return;
603 cwd_path = remove_encoding_from_path (other_panel->cwd);
604 command_insert (cmdline, cwd_path, FALSE);
606 if (cwd_path[strlen (cwd_path) - 1] != PATH_SEP)
607 command_insert (cmdline, PATH_SEP_STR, FALSE);
608 g_free (cwd_path);
611 /* --------------------------------------------------------------------------------------------- */
613 static void
614 copy_readlink (WPanel * panel)
616 if (!command_prompt)
617 return;
618 if (S_ISLNK (selection (panel)->st.st_mode))
620 char buffer[MC_MAXPATHLEN];
621 char *p = concat_dir_and_file (panel->cwd, selection (panel)->fname);
622 int i;
624 i = mc_readlink (p, buffer, MC_MAXPATHLEN - 1);
625 g_free (p);
626 if (i > 0)
628 buffer[i] = 0;
629 command_insert (cmdline, buffer, TRUE);
634 /* --------------------------------------------------------------------------------------------- */
636 static void
637 copy_current_readlink (void)
639 copy_readlink (current_panel);
642 /* --------------------------------------------------------------------------------------------- */
644 static void
645 copy_other_readlink (void)
647 if (get_other_type () == view_listing)
648 copy_readlink (other_panel);
651 /* --------------------------------------------------------------------------------------------- */
653 /** Insert the selected file name into the input line */
654 static void
655 copy_prog_name (void)
657 char *tmp;
658 if (!command_prompt)
659 return;
661 if (get_current_type () == view_tree)
663 WTree *tree = (WTree *) get_panel_widget (get_current_index ());
664 tmp = tree_selected_name (tree);
666 else
667 tmp = selection (current_panel)->fname;
669 command_insert (cmdline, tmp, TRUE);
672 /* --------------------------------------------------------------------------------------------- */
674 static void
675 copy_tagged (WPanel * panel)
677 int i;
679 if (!command_prompt)
680 return;
681 input_disable_update (cmdline);
682 if (panel->marked)
684 for (i = 0; i < panel->count; i++)
686 if (panel->dir.list[i].f.marked)
687 command_insert (cmdline, panel->dir.list[i].fname, TRUE);
690 else
692 command_insert (cmdline, panel->dir.list[panel->selected].fname, TRUE);
694 input_enable_update (cmdline);
697 /* --------------------------------------------------------------------------------------------- */
699 static void
700 copy_current_tagged (void)
702 copy_tagged (current_panel);
705 /* --------------------------------------------------------------------------------------------- */
707 static void
708 copy_other_tagged (void)
710 if (get_other_type () == view_listing)
711 copy_tagged (other_panel);
714 /* --------------------------------------------------------------------------------------------- */
716 static void
717 ctl_x_cmd (void)
719 ctl_x_map_enabled = TRUE;
722 /* --------------------------------------------------------------------------------------------- */
724 static void
725 init_xterm_support (void)
727 const char *termvalue;
729 termvalue = getenv ("TERM");
730 if (!termvalue || !(*termvalue))
732 fputs (_("The TERM environment variable is unset!\n"), stderr);
733 exit (EXIT_FAILURE);
736 /* Check mouse capabilities */
737 xmouse_seq = tty_tgetstr ("Km");
739 if (strcmp (termvalue, "cygwin") == 0)
741 mc_args__force_xterm = 1;
742 use_mouse_p = MOUSE_DISABLED;
745 if (mc_args__force_xterm || strncmp (termvalue, "xterm", 5) == 0
746 || strncmp (termvalue, "konsole", 7) == 0
747 || strncmp (termvalue, "rxvt", 4) == 0
748 || strcmp (termvalue, "Eterm") == 0 || strcmp (termvalue, "dtterm") == 0)
750 xterm_flag = 1;
752 /* Default to the standard xterm sequence */
753 if (!xmouse_seq)
755 xmouse_seq = ESC_STR "[M";
758 /* Enable mouse unless explicitly disabled by --nomouse */
759 if (use_mouse_p != MOUSE_DISABLED)
761 const char *color_term = getenv ("COLORTERM");
762 if (strncmp (termvalue, "rxvt", 4) == 0 ||
763 (color_term != NULL && strncmp (color_term, "rxvt", 4) == 0) ||
764 strcmp (termvalue, "Eterm") == 0)
766 use_mouse_p = MOUSE_XTERM_NORMAL_TRACKING;
768 else
770 use_mouse_p = MOUSE_XTERM_BUTTON_EVENT_TRACKING;
776 /* --------------------------------------------------------------------------------------------- */
778 static void
779 setup_mc (void)
781 #ifdef HAVE_SLANG
782 tty_display_8bit (full_eight_bits != 0);
783 #else
784 tty_display_8bit (eight_bit_clean != 0);
785 #endif
787 #ifdef HAVE_SUBSHELL_SUPPORT
788 if (use_subshell)
789 add_select_channel (subshell_pty, load_prompt, 0);
790 #endif /* !HAVE_SUBSHELL_SUPPORT */
792 tty_setup_sigwinch (sigwinch_handler);
794 if ((tty_baudrate () < 9600) || tty_is_slow ())
795 verbose = 0;
797 init_xterm_support ();
798 init_mouse ();
801 /* --------------------------------------------------------------------------------------------- */
803 static void
804 setup_dummy_mc (void)
806 char d[MC_MAXPATHLEN];
807 int ret;
809 mc_get_current_wd (d, MC_MAXPATHLEN);
810 setup_mc ();
811 ret = mc_chdir (d);
814 /* --------------------------------------------------------------------------------------------- */
816 static void
817 done_screen (void)
819 if ((quit & SUBSHELL_EXIT) == 0)
820 clr_scr ();
821 tty_reset_shell_mode ();
822 tty_noraw_mode ();
823 tty_keypad (FALSE);
826 /* --------------------------------------------------------------------------------------------- */
828 static void
829 done_mc (void)
831 disable_mouse ();
833 /* Setup shutdown
835 * We sync the profiles since the hotlist may have changed, while
836 * we only change the setup data if we have the auto save feature set
839 save_setup (auto_save_setup, panels_options.auto_save_setup);
840 done_screen ();
842 vfs_stamp_path (vfs_get_current_dir ());
844 if ((current_panel != NULL) && (get_current_type () == view_listing))
845 vfs_stamp_path (current_panel->cwd);
847 if ((other_panel != NULL) && (get_other_type () == view_listing))
848 vfs_stamp_path (other_panel->cwd);
851 /* --------------------------------------------------------------------------------------------- */
853 static void
854 create_panels_and_run_mc (void)
856 midnight_dlg->get_shortcut = midnight_get_shortcut;
857 midnight_dlg->get_title = midnight_get_title;
859 create_panels ();
861 add_widget (midnight_dlg, the_menubar);
862 init_menu ();
864 add_widget (midnight_dlg, get_panel_widget (0));
865 add_widget (midnight_dlg, get_panel_widget (1));
867 add_widget (midnight_dlg, the_hint);
868 add_widget (midnight_dlg, cmdline);
869 add_widget (midnight_dlg, the_prompt);
871 add_widget (midnight_dlg, the_bar);
872 midnight_set_buttonbar (the_bar);
874 /* Run the Midnight Commander if no file was specified in the command line */
875 run_dlg (midnight_dlg);
878 /* --------------------------------------------------------------------------------------------- */
880 /** result must be free'd (I think this should go in util.c) */
881 static char *
882 prepend_cwd_on_local (const char *filename)
884 char *d;
885 size_t l;
887 if (!vfs_file_is_local (filename) || g_path_is_absolute (filename))
888 return g_strdup (filename);
890 d = g_malloc (MC_MAXPATHLEN + strlen (filename) + 2);
891 mc_get_current_wd (d, MC_MAXPATHLEN);
892 l = strlen (d);
893 d[l++] = PATH_SEP;
894 strcpy (d + l, filename);
895 canonicalize_pathname (d);
896 return d;
899 /* --------------------------------------------------------------------------------------------- */
901 /** Invoke the internal view/edit routine with:
902 * the default processing and forcing the internal viewer/editor
904 static void
905 mc_maybe_editor_or_viewer (void)
907 switch (mc_run_mode)
909 #ifdef USE_INTERNAL_EDIT
910 case MC_RUN_EDITOR:
911 edit_file (mc_run_param0, mc_args__edit_start_line);
912 break;
913 #endif /* USE_INTERNAL_EDIT */
914 case MC_RUN_VIEWER:
916 char *path;
917 path = prepend_cwd_on_local (mc_run_param0);
918 view_file (path, 0, 1);
919 g_free (path);
920 break;
922 #ifdef USE_DIFF_VIEW
923 case MC_RUN_DIFFVIEWER:
924 diff_view (mc_run_param0, mc_run_param1, mc_run_param0, mc_run_param1);
925 break;
926 #endif /* USE_DIFF_VIEW */
927 default:
928 break;
932 /* --------------------------------------------------------------------------------------------- */
934 static gboolean
935 quit_cmd_internal (int quiet)
937 int q = quit;
938 size_t n;
940 n = dialog_switch_num () - 1;
941 if (n != 0)
943 char msg[BUF_MEDIUM];
945 g_snprintf (msg, sizeof (msg),
946 ngettext ("You have %zd opened screen. Quit anyway?",
947 "You have %zd opened screens. Quit anyway?", n), n);
949 if (query_dialog (_("The Midnight Commander"), msg, D_NORMAL, 2, _("&Yes"), _("&No")) != 0)
950 return FALSE;
951 q = 1;
953 else if (quiet || !confirm_exit)
954 q = 1;
955 else if (query_dialog (_("The Midnight Commander"),
956 _("Do you really want to quit the Midnight Commander?"),
957 D_NORMAL, 2, _("&Yes"), _("&No")) == 0)
958 q = 1;
960 if (q != 0)
962 #ifdef HAVE_SUBSHELL_SUPPORT
963 if (!use_subshell)
964 stop_dialogs ();
965 else if ((q = exit_subshell ()))
966 #endif
967 stop_dialogs ();
970 if (q != 0)
971 quit |= 1;
972 return (quit != 0);
975 /* --------------------------------------------------------------------------------------------- */
977 static gboolean
978 quit_cmd (void)
980 return quit_cmd_internal (0);
983 /* --------------------------------------------------------------------------------------------- */
985 static void
986 toggle_show_hidden (void)
988 panels_options.show_dot_files = !panels_options.show_dot_files;
989 update_panels (UP_RELOAD, UP_KEEPSEL);
992 /* --------------------------------------------------------------------------------------------- */
995 * Repaint the contents of the panels without frames. To schedule panel
996 * for repainting, set panel->dirty to 1. There are many reasons why
997 * the panels need to be repainted, and this is a costly operation, so
998 * it's done once per event.
1001 static void
1002 update_dirty_panels (void)
1004 if (get_current_type () == view_listing && current_panel->dirty)
1005 send_message ((Widget *) current_panel, WIDGET_DRAW, 0);
1007 if (get_other_type () == view_listing && other_panel->dirty)
1008 send_message ((Widget *) other_panel, WIDGET_DRAW, 0);
1011 /* --------------------------------------------------------------------------------------------- */
1013 static cb_ret_t
1014 midnight_execute_cmd (Widget * sender, unsigned long command)
1016 cb_ret_t res = MSG_HANDLED;
1018 (void) sender;
1020 /* stop quick search before executing any command */
1021 send_message ((Widget *) current_panel, WIDGET_COMMAND, CK_PanelStopSearch);
1023 switch (command)
1025 case CK_AddHotlist:
1026 add2hotlist_cmd ();
1027 break;
1028 case CK_ChangeListingCmd:
1029 change_listing_cmd ();
1030 break;
1031 case CK_ChmodCmd:
1032 chmod_cmd ();
1033 break;
1034 case CK_ChownCmd:
1035 chown_cmd ();
1036 break;
1037 case CK_ChownAdvancedCmd:
1038 chown_advanced_cmd ();
1039 break;
1040 case CK_CompareDirsCmd:
1041 compare_dirs_cmd ();
1042 break;
1043 case CK_ConfigureBox:
1044 configure_box ();
1045 break;
1046 #ifdef ENABLE_VFS
1047 case CK_ConfigureVfs:
1048 configure_vfs ();
1049 break;
1050 #endif
1051 case CK_ConfirmBox:
1052 confirm_box ();
1053 break;
1054 case CK_CopyCmd:
1055 copy_cmd ();
1056 break;
1057 case CK_CopyCurrentPathname:
1058 copy_current_pathname ();
1059 break;
1060 case CK_CopyCurrentReadlink:
1061 copy_current_readlink ();
1062 break;
1063 case CK_CopyCurrentTagged:
1064 copy_current_tagged ();
1065 break;
1066 case CK_CopyOtherPathname:
1067 copy_other_pathname ();
1068 break;
1069 case CK_CopyOtherReadlink:
1070 copy_other_readlink ();
1071 break;
1072 case CK_CopyOtherTagged:
1073 copy_other_tagged ();
1074 break;
1075 case CK_DeleteCmd:
1076 delete_cmd ();
1077 break;
1078 case CK_DialogListCmd:
1079 dialog_switch_list ();
1080 break;
1081 #ifdef USE_DIFF_VIEW
1082 case CK_DiffViewCmd:
1083 diff_view_cmd ();
1084 break;
1085 #endif
1086 case CK_DisplayBitsBox:
1087 display_bits_box ();
1088 break;
1089 case CK_EditCmd:
1090 edit_cmd ();
1091 break;
1092 #ifdef USE_INTERNAL_EDIT
1093 case CK_EditForceInternalCmd:
1094 edit_cmd_force_internal ();
1095 break;
1096 #endif
1097 case CK_EditExtFileCmd:
1098 ext_cmd ();
1099 break;
1100 case CK_EditFhlFileCmd:
1101 edit_fhl_cmd ();
1102 break;
1103 case CK_EditMcMenuCmd:
1104 edit_mc_menu_cmd ();
1105 break;
1106 case CK_EditSymlinkCmd:
1107 edit_symlink_cmd ();
1108 break;
1109 case CK_ExternalPanelize:
1110 external_panelize ();
1111 break;
1112 case CK_FilterCmd:
1113 filter_cmd ();
1114 break;
1115 case CK_FilteredViewCmd:
1116 filtered_view_cmd ();
1117 break;
1118 case CK_FindCmd:
1119 find_cmd ();
1120 break;
1121 #ifdef ENABLE_VFS_FISH
1122 case CK_FishlinkCmd:
1123 fishlink_cmd ();
1124 break;
1125 #endif
1126 #ifdef ENABLE_VFS_FTP
1127 case CK_FtplinkCmd:
1128 ftplink_cmd ();
1129 break;
1130 #endif
1131 case CK_HelpCmd:
1132 help_cmd ();
1133 break;
1134 case CK_HistoryCmd:
1135 history_cmd ();
1136 break;
1137 case CK_InfoCmd:
1138 if (sender == (Widget *) the_menubar)
1139 info_cmd (); /* mwnu */
1140 else
1141 info_cmd_no_menu (); /* shortcut or buttonbar */
1142 break;
1143 #ifdef WITH_BACKGROUND
1144 case CK_JobsCmd:
1145 jobs_cmd ();
1146 break;
1147 #endif
1148 case CK_LayoutBox:
1149 layout_box ();
1150 break;
1151 case CK_LearnKeys:
1152 learn_keys ();
1153 break;
1154 case CK_LinkCmd:
1155 link_cmd (LINK_HARDLINK);
1156 break;
1157 case CK_ListingCmd:
1158 listing_cmd ();
1159 break;
1160 #ifdef LISTMODE_EDITOR
1161 case CK_ListmodeCmd:
1162 listmode_cmd ();
1163 break;
1164 #endif
1165 case CK_MenuCmd:
1166 menu_cmd ();
1167 break;
1168 case CK_MenuLastSelectedCmd:
1169 menu_last_selected_cmd ();
1170 break;
1171 case CK_MkdirCmd:
1172 mkdir_cmd ();
1173 break;
1174 case CK_PanelOptionsBox:
1175 panel_options_box ();
1176 break;
1177 #ifdef HAVE_CHARSET
1178 case CK_PanelSetPanelEncoding:
1179 encoding_cmd ();
1180 break;
1181 #endif
1182 case CK_QuickCdCmd:
1183 quick_cd_cmd ();
1184 break;
1185 case CK_QuickChdirCmd:
1186 quick_chdir_cmd ();
1187 break;
1188 case CK_QuickViewCmd:
1189 if (sender == (Widget *) the_menubar)
1190 quick_view_cmd (); /* menu */
1191 else
1192 quick_cmd_no_menu (); /* shortcut or buttonabr */
1193 break;
1194 case CK_QuietQuitCmd:
1195 quiet_quit_cmd ();
1196 break;
1197 case CK_QuitCmd:
1198 quit_cmd ();
1199 break;
1200 case CK_RelativeSymlinkCmd:
1201 link_cmd (LINK_SYMLINK_RELATIVE);
1202 break;
1203 case CK_RenameCmd:
1204 rename_cmd ();
1205 break;
1206 case CK_RereadCmd:
1207 reread_cmd ();
1208 break;
1209 #ifdef ENABLE_VFS
1210 case CK_ReselectVfs:
1211 reselect_vfs ();
1212 break;
1213 #endif
1214 case CK_ReverseSelectionCmd:
1215 reverse_selection_cmd ();
1216 break;
1217 case CK_SaveSetupCmd:
1218 save_setup_cmd ();
1219 break;
1220 case CK_SelectCmd:
1221 select_cmd ();
1222 break;
1223 case CK_ShowCommandLine:
1224 view_other_cmd ();
1225 break;
1226 case CK_SingleDirsizeCmd:
1227 smart_dirsize_cmd ();
1228 break;
1229 #ifdef ENABLE_VFS_SMB
1230 case CK_SmblinkCmd:
1231 smblink_cmd ();
1232 break;
1233 #endif /* ENABLE_VFS_SMB */
1234 case CK_Sort:
1235 sort_cmd ();
1236 break;
1237 case CK_StartExtMap1:
1238 ctl_x_cmd ();
1239 break;
1240 case CK_SuspendCmd:
1241 suspend_cmd ();
1242 break;
1243 case CK_SwapCmd:
1244 swap_cmd ();
1245 break;
1246 case CK_SymlinkCmd:
1247 link_cmd (LINK_SYMLINK_ABSOLUTE);
1248 break;
1249 case CK_ToggleListingCmd:
1250 toggle_listing_cmd ();
1251 break;
1252 case CK_ToggleShowHidden:
1253 toggle_show_hidden ();
1254 break;
1255 case CK_TogglePanelsSplit:
1256 toggle_panels_split ();
1257 break;
1258 case CK_TreeCmd:
1259 tree_cmd ();
1260 break;
1261 case CK_TreeBoxCmd:
1262 treebox_cmd ();
1263 break;
1264 #ifdef ENABLE_VFS_UNDELFS
1265 case CK_UndeleteCmd:
1266 undelete_cmd ();
1267 break;
1268 #endif
1269 case CK_UnselectCmd:
1270 unselect_cmd ();
1271 break;
1272 case CK_UserMenuCmd:
1273 user_file_menu_cmd ();
1274 break;
1275 case CK_ViewCmd:
1276 view_cmd ();
1277 break;
1278 case CK_ViewFileCmd:
1279 view_file_cmd ();
1280 break;
1281 default:
1282 res = MSG_NOT_HANDLED;
1285 return res;
1288 /* --------------------------------------------------------------------------------------------- */
1290 static cb_ret_t
1291 midnight_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
1293 unsigned long command;
1295 switch (msg)
1297 case DLG_INIT:
1298 panel_init ();
1299 setup_panels ();
1300 return MSG_HANDLED;
1302 case DLG_DRAW:
1303 load_hint (1);
1304 /* We handle the special case of the output lines */
1305 if (console_flag && output_lines)
1306 show_console_contents (output_start_y,
1307 LINES - output_lines - keybar_visible -
1308 1, LINES - keybar_visible - 1);
1309 return MSG_HANDLED;
1311 case DLG_RESIZE:
1312 setup_panels ();
1313 menubar_arrange (the_menubar);
1314 return MSG_HANDLED;
1316 case DLG_IDLE:
1317 /* We only need the first idle event to show user menu after start */
1318 set_idle_proc (h, 0);
1320 if (boot_current_is_left)
1321 dlg_select_widget (get_panel_widget (0));
1322 else
1323 dlg_select_widget (get_panel_widget (1));
1325 if (auto_menu)
1326 midnight_execute_cmd (NULL, CK_UserMenuCmd);
1327 return MSG_HANDLED;
1329 case DLG_KEY:
1330 if (ctl_x_map_enabled)
1332 ctl_x_map_enabled = FALSE;
1333 command = keybind_lookup_keymap_command (main_x_map, parm);
1334 if (command != CK_Ignore_Key)
1335 return midnight_execute_cmd (NULL, command);
1338 /* FIXME: should handle all menu shortcuts before this point */
1339 if (the_menubar->is_active)
1340 return MSG_NOT_HANDLED;
1342 if (parm == '\t')
1343 input_free_completions (cmdline);
1345 if (parm == '\n')
1347 size_t i;
1349 for (i = 0; cmdline->buffer[i] != '\0' &&
1350 (cmdline->buffer[i] == ' ' || cmdline->buffer[i] == '\t'); i++)
1353 if (cmdline->buffer[i] != '\0')
1355 send_message ((Widget *) cmdline, WIDGET_KEY, parm);
1356 return MSG_HANDLED;
1359 input_insert (cmdline, "", FALSE);
1360 cmdline->point = 0;
1363 /* Ctrl-Enter and Alt-Enter */
1364 if (((parm & ~(KEY_M_CTRL | KEY_M_ALT)) == '\n') && (parm & (KEY_M_CTRL | KEY_M_ALT)))
1366 copy_prog_name ();
1367 return MSG_HANDLED;
1370 /* Ctrl-Shift-Enter */
1371 if (parm == (KEY_M_CTRL | KEY_M_SHIFT | '\n'))
1373 copy_current_pathname ();
1374 copy_prog_name ();
1375 return MSG_HANDLED;
1378 if ((!alternate_plus_minus || !(console_flag || xterm_flag))
1379 && !quote && !current_panel->searching)
1381 if (!only_leading_plus_minus)
1383 /* Special treatement, since the input line will eat them */
1384 if (parm == '+')
1386 select_cmd ();
1387 return MSG_HANDLED;
1390 if (parm == '\\' || parm == '-')
1392 unselect_cmd ();
1393 return MSG_HANDLED;
1396 if (parm == '*')
1398 reverse_selection_cmd ();
1399 return MSG_HANDLED;
1402 else if (!command_prompt || !cmdline->buffer[0])
1404 /* Special treatement '+', '-', '\', '*' only when this is
1405 * first char on input line
1408 if (parm == '+')
1410 select_cmd ();
1411 return MSG_HANDLED;
1414 if (parm == '\\' || parm == '-')
1416 unselect_cmd ();
1417 return MSG_HANDLED;
1420 if (parm == '*')
1422 reverse_selection_cmd ();
1423 return MSG_HANDLED;
1427 return MSG_NOT_HANDLED;
1429 case DLG_HOTKEY_HANDLED:
1430 if ((get_current_type () == view_listing) && current_panel->searching)
1432 current_panel->dirty = 1; /* FIXME: unneeded? */
1433 send_message ((Widget *) current_panel, WIDGET_COMMAND, CK_PanelStopSearch);
1435 return MSG_HANDLED;
1437 case DLG_UNHANDLED_KEY:
1438 if (command_prompt)
1440 cb_ret_t v;
1442 v = send_message ((Widget *) cmdline, WIDGET_KEY, parm);
1443 if (v == MSG_HANDLED)
1444 return MSG_HANDLED;
1447 if (ctl_x_map_enabled)
1449 ctl_x_map_enabled = FALSE;
1450 command = keybind_lookup_keymap_command (main_x_map, parm);
1452 else
1453 command = keybind_lookup_keymap_command (main_map, parm);
1455 return (command == CK_Ignore_Key) ? MSG_NOT_HANDLED : midnight_execute_cmd (NULL, command);
1457 case DLG_POST_KEY:
1458 if (!the_menubar->is_active)
1459 update_dirty_panels ();
1460 return MSG_HANDLED;
1462 case DLG_ACTION:
1463 /* shortcut */
1464 if (sender == NULL)
1465 midnight_execute_cmd (NULL, parm);
1466 /* message from menu */
1467 else if (sender == (Widget *) the_menubar)
1468 midnight_execute_cmd (sender, parm);
1469 /* message from buttonbar */
1470 else if (sender == (Widget *) the_bar)
1472 if (data == NULL)
1473 midnight_execute_cmd (sender, parm);
1474 else
1475 send_message ((Widget *) data, WIDGET_COMMAND, parm);
1477 return MSG_HANDLED;
1479 case DLG_END:
1480 panel_deinit ();
1481 return MSG_HANDLED;
1483 default:
1484 return default_dlg_callback (h, sender, msg, parm, data);
1488 /* --------------------------------------------------------------------------------------------- */
1489 /*** public functions ****************************************************************************/
1490 /* --------------------------------------------------------------------------------------------- */
1492 void
1493 update_menu (void)
1495 menu_set_name (left_menu, horizontal_split ? _("&Above") : _("&Left"));
1496 menu_set_name (right_menu, horizontal_split ? _("&Below") : _("&Right"));
1497 menubar_arrange (the_menubar);
1498 menubar_set_visible (the_menubar, menubar_visible);
1501 void
1502 midnight_set_buttonbar (WButtonBar * b)
1504 buttonbar_set_label (b, 1, Q_ ("ButtonBar|Help"), main_map, NULL);
1505 buttonbar_set_label (b, 2, Q_ ("ButtonBar|Menu"), main_map, NULL);
1506 buttonbar_set_label (b, 3, Q_ ("ButtonBar|View"), main_map, NULL);
1507 buttonbar_set_label (b, 4, Q_ ("ButtonBar|Edit"), main_map, NULL);
1508 buttonbar_set_label (b, 5, Q_ ("ButtonBar|Copy"), main_map, NULL);
1509 buttonbar_set_label (b, 6, Q_ ("ButtonBar|RenMov"), main_map, NULL);
1510 buttonbar_set_label (b, 7, Q_ ("ButtonBar|Mkdir"), main_map, NULL);
1511 buttonbar_set_label (b, 8, Q_ ("ButtonBar|Delete"), main_map, NULL);
1512 buttonbar_set_label (b, 9, Q_ ("ButtonBar|PullDn"), main_map, NULL);
1513 buttonbar_set_label (b, 10, Q_ ("ButtonBar|Quit"), main_map, NULL);
1516 /* --------------------------------------------------------------------------------------------- */
1518 * Load new hint and display it.
1519 * IF force is not 0, ignore the timeout.
1522 void
1523 load_hint (gboolean force)
1525 char *hint;
1527 if (the_hint->widget.owner == NULL)
1528 return;
1530 if (!message_visible)
1532 label_set_text (the_hint, NULL);
1533 return;
1536 hint = get_random_hint (force);
1538 if (hint != NULL)
1540 if (*hint != '\0')
1541 set_hintbar (hint);
1542 g_free (hint);
1544 else
1546 char text[BUF_SMALL];
1548 g_snprintf (text, sizeof (text), _("GNU Midnight Commander %s\n"), VERSION);
1549 set_hintbar (text);
1553 /* --------------------------------------------------------------------------------------------- */
1555 void
1556 change_panel (void)
1558 input_free_completions (cmdline);
1559 dlg_one_down (midnight_dlg);
1562 /* --------------------------------------------------------------------------------------------- */
1564 /** Save current stat of directories to avoid reloading the panels
1565 * when no modifications have taken place
1567 void
1568 save_cwds_stat (void)
1570 if (panels_options.fast_reload)
1572 mc_stat (current_panel->cwd, &(current_panel->dir_stat));
1573 if (get_other_type () == view_listing)
1574 mc_stat (other_panel->cwd, &(other_panel->dir_stat));
1578 /* --------------------------------------------------------------------------------------------- */
1580 gboolean
1581 quiet_quit_cmd (void)
1583 print_last_revert = TRUE;
1584 return quit_cmd_internal (1);
1587 /* --------------------------------------------------------------------------------------------- */
1589 /** Run the main dialog that occupies the whole screen */
1590 void
1591 do_nc (void)
1593 dlg_colors_t midnight_colors;
1595 midnight_colors[DLG_COLOR_NORMAL] = mc_skin_color_get ("dialog", "_default_");
1596 midnight_colors[DLG_COLOR_FOCUS] = mc_skin_color_get ("dialog", "focus");
1597 midnight_colors[DLG_COLOR_HOT_NORMAL] = mc_skin_color_get ("dialog", "hotnormal");
1598 midnight_colors[DLG_COLOR_HOT_FOCUS] = mc_skin_color_get ("dialog", "hotfocus");
1599 midnight_colors[DLG_COLOR_TITLE] = mc_skin_color_get ("dialog", "title");
1601 #ifdef USE_INTERNAL_EDIT
1602 edit_stack_init ();
1603 #endif
1605 midnight_dlg = create_dlg (FALSE, 0, 0, LINES, COLS, midnight_colors, midnight_callback,
1606 "[main]", NULL, DLG_WANT_IDLE);
1608 if (mc_run_mode == MC_RUN_FULL)
1609 setup_mc ();
1610 else
1611 setup_dummy_mc ();
1613 /* Check if we were invoked as an editor or file viewer */
1614 if (mc_run_mode != MC_RUN_FULL)
1615 mc_maybe_editor_or_viewer ();
1616 else
1618 create_panels_and_run_mc ();
1620 /* destroy_dlg destroys even current_panel->cwd, so we have to save a copy :) */
1621 if (mc_args__last_wd_file != NULL && vfs_current_is_local ())
1622 last_wd_string = g_strdup (current_panel->cwd);
1625 /* Program end */
1626 midnight_shutdown = 1;
1627 dialog_switch_shutdown ();
1628 done_mc ();
1629 destroy_dlg (midnight_dlg);
1630 current_panel = NULL;
1632 #ifdef USE_INTERNAL_EDIT
1633 edit_stack_free ();
1634 #endif
1637 /* --------------------------------------------------------------------------------------------- */