Ticket #275 (panelize enhancement)
[midnight-commander.git] / src / filemanager / midnight.c
blobc92fe539b868fdef4040a301cba8b9418a5eddf0
1 /*
2 Main dialog (file panels) of the Midnight Commander
4 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
5 2003, 2004, 2005, 2006, 2007, 2009, 2010, 2011
6 The Free Software Foundation, Inc.
8 Written by:
9 Miguel de Icaza, 1994, 1995, 1996, 1997
10 Janne Kukonlehto, 1994, 1995
11 Norbert Warmuth, 1997
12 Andrew Borodin <aborodin@vmail.ru>, 2009, 2010
14 This file is part of the Midnight Commander.
16 The Midnight Commander is free software: you can redistribute it
17 and/or modify it under the terms of the GNU General Public License as
18 published by the Free Software Foundation, either version 3 of the License,
19 or (at your option) any later version.
21 The Midnight Commander is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program. If not, see <http://www.gnu.org/licenses/>.
30 /** \file main.c
31 * \brief Source: main dialog (file panels) of the Midnight Commander
34 #include <config.h>
36 #include <ctype.h>
37 #include <errno.h>
38 #include <locale.h>
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <string.h>
42 #include <fcntl.h>
43 #include <sys/types.h>
44 #include <sys/stat.h>
45 #include <sys/wait.h>
46 #include <pwd.h> /* for username in xterm title */
48 #include "lib/global.h"
50 #include "lib/tty/tty.h"
51 #include "lib/tty/key.h" /* KEY_M_* masks */
52 #include "lib/skin.h"
53 #include "lib/util.h"
55 #include "lib/vfs/vfs.h"
57 #include "src/args.h"
58 #include "src/subshell.h"
59 #include "src/setup.h" /* variables */
60 #include "src/learn.h" /* learn_keys() */
61 #include "src/keybind-defaults.h"
62 #include "lib/keybind.h"
63 #include "lib/event.h"
65 #include "option.h" /* configure_box() */
66 #include "tree.h"
67 #include "boxes.h" /* sort_box(), tree_box() */
68 #include "layout.h"
69 #include "cmd.h" /* commands */
70 #include "hotlist.h"
71 #include "panelize.h"
72 #include "command.h" /* cmdline */
73 #include "dir.h" /* clean_dir() */
75 #include "chmod.h"
76 #include "chown.h"
77 #include "achown.h"
79 #ifdef USE_INTERNAL_EDIT
80 #include "src/editor/edit.h"
81 #endif
83 #ifdef USE_DIFF_VIEW
84 #include "src/diffviewer/ydiff.h"
85 #endif
87 #include "src/consaver/cons.saver.h" /* show_console_contents */
89 #include "midnight.h"
91 /* TODO: merge content of layout.c here */
92 extern int ok_to_refresh;
94 /*** global variables ****************************************************************************/
96 /* When the modes are active, left_panel, right_panel and tree_panel */
97 /* point to a proper data structure. You should check with the functions */
98 /* get_current_type and get_other_type the types of the panels before using */
99 /* this pointer variables */
101 /* The structures for the panels */
102 WPanel *left_panel = NULL;
103 WPanel *right_panel = NULL;
104 /* Pointer to the selected and unselected panel */
105 WPanel *current_panel = NULL;
107 /* The Menubar */
108 WMenuBar *the_menubar = NULL;
109 /* The widget where we draw the prompt */
110 WLabel *the_prompt;
111 /* The hint bar */
112 WLabel *the_hint;
113 /* The button bar */
114 WButtonBar *the_bar;
116 /*** file scope macro definitions ****************************************************************/
118 #ifdef HAVE_CHARSET
120 * Don't restrict the output on the screen manager level,
121 * the translation tables take care of it.
123 #endif /* !HAVE_CHARSET */
125 /*** file scope type declarations ****************************************************************/
127 /*** file scope variables ************************************************************************/
129 static Menu *left_menu, *right_menu;
131 static gboolean ctl_x_map_enabled = FALSE;
133 /*** file scope functions ************************************************************************/
135 /** Stop MC main dialog and the current dialog if it exists.
136 * Needed to provide fast exit from MC viewer or editor on shell exit */
137 static void
138 stop_dialogs (void)
140 midnight_dlg->state = DLG_CLOSED;
142 if ((top_dlg != NULL) && (top_dlg->data != NULL))
143 ((Dlg_head *) top_dlg->data)->state = DLG_CLOSED;
146 /* --------------------------------------------------------------------------------------------- */
148 static void
149 treebox_cmd (void)
151 char *sel_dir;
153 sel_dir = tree_box (selection (current_panel)->fname);
154 if (sel_dir)
156 do_cd (sel_dir, cd_exact);
157 g_free (sel_dir);
161 /* --------------------------------------------------------------------------------------------- */
163 #ifdef LISTMODE_EDITOR
164 static void
165 listmode_cmd (void)
167 char *newmode;
169 if (get_current_type () != view_listing)
170 return;
172 newmode = listmode_edit (current_panel->user_format);
173 if (!newmode)
174 return;
176 g_free (current_panel->user_format);
177 current_panel->list_type = list_user;
178 current_panel->user_format = newmode;
179 set_panel_formats (current_panel);
181 do_refresh ();
183 #endif /* LISTMODE_EDITOR */
185 /* --------------------------------------------------------------------------------------------- */
187 static GList *
188 create_panel_menu (void)
190 GList *entries = NULL;
192 entries = g_list_append (entries, menu_entry_create (_("File listin&g"), CK_PanelListing));
193 entries = g_list_append (entries, menu_entry_create (_("&Quick view"), CK_PanelQuickView));
194 entries = g_list_append (entries, menu_entry_create (_("&Info"), CK_PanelInfo));
195 entries = g_list_append (entries, menu_entry_create (_("&Tree"), CK_PanelTree));
196 entries = g_list_append (entries, menu_separator_create ());
197 entries =
198 g_list_append (entries, menu_entry_create (_("&Listing mode..."), CK_PanelListingChange));
199 entries = g_list_append (entries, menu_entry_create (_("&Sort order..."), CK_Sort));
200 entries = g_list_append (entries, menu_entry_create (_("&Filter..."), CK_Filter));
201 #ifdef HAVE_CHARSET
202 entries = g_list_append (entries, menu_entry_create (_("&Encoding..."), CK_SelectCodepage));
203 #endif
204 entries = g_list_append (entries, menu_separator_create ());
205 #ifdef ENABLE_VFS_FTP
206 entries = g_list_append (entries, menu_entry_create (_("FT&P link..."), CK_ConnectFtp));
207 #endif
208 #ifdef ENABLE_VFS_FISH
209 entries = g_list_append (entries, menu_entry_create (_("S&hell link..."), CK_ConnectFish));
210 #endif
211 #ifdef ENABLE_VFS_SMB
212 entries = g_list_append (entries, menu_entry_create (_("SM&B link..."), CK_ConnectSmb));
213 #endif
214 entries = g_list_append (entries, menu_entry_create (_("Panelize"), CK_Panelize));
215 entries = g_list_append (entries, menu_separator_create ());
216 entries = g_list_append (entries, menu_entry_create (_("&Rescan"), CK_Reread));
218 return entries;
221 /* --------------------------------------------------------------------------------------------- */
223 static GList *
224 create_file_menu (void)
226 GList *entries = NULL;
228 entries = g_list_append (entries, menu_entry_create (_("&View"), CK_View));
229 entries = g_list_append (entries, menu_entry_create (_("Vie&w file..."), CK_ViewFile));
230 entries = g_list_append (entries, menu_entry_create (_("&Filtered view"), CK_ViewFiltered));
231 entries = g_list_append (entries, menu_entry_create (_("&Edit"), CK_Edit));
232 entries = g_list_append (entries, menu_entry_create (_("&Copy"), CK_Copy));
233 entries = g_list_append (entries, menu_entry_create (_("C&hmod"), CK_ChangeMode));
234 entries = g_list_append (entries, menu_entry_create (_("&Link"), CK_Link));
235 entries = g_list_append (entries, menu_entry_create (_("&Symlink"), CK_LinkSymbolic));
236 entries =
237 g_list_append (entries,
238 menu_entry_create (_("Relative symlin&k"), CK_LinkSymbolicRelative));
239 entries = g_list_append (entries, menu_entry_create (_("Edit s&ymlink"), CK_LinkSymbolicEdit));
240 entries = g_list_append (entries, menu_entry_create (_("Ch&own"), CK_ChangeOwn));
241 entries =
242 g_list_append (entries, menu_entry_create (_("&Advanced chown"), CK_ChangeOwnAdvanced));
243 entries = g_list_append (entries, menu_entry_create (_("&Rename/Move"), CK_Move));
244 entries = g_list_append (entries, menu_entry_create (_("&Mkdir"), CK_MakeDir));
245 entries = g_list_append (entries, menu_entry_create (_("&Delete"), CK_Delete));
246 entries = g_list_append (entries, menu_entry_create (_("&Quick cd"), CK_CdQuick));
247 entries = g_list_append (entries, menu_separator_create ());
248 entries = g_list_append (entries, menu_entry_create (_("Select &group"), CK_Select));
249 entries = g_list_append (entries, menu_entry_create (_("U&nselect group"), CK_Unselect));
250 entries = g_list_append (entries, menu_entry_create (_("&Invert selection"), CK_SelectInvert));
251 entries = g_list_append (entries, menu_separator_create ());
252 entries = g_list_append (entries, menu_entry_create (_("E&xit"), CK_Quit));
254 return entries;
257 /* --------------------------------------------------------------------------------------------- */
259 static GList *
260 create_command_menu (void)
262 /* I know, I'm lazy, but the tree widget when it's not running
263 * as a panel still has some problems, I have not yet finished
264 * the WTree widget port, sorry.
266 GList *entries = NULL;
268 entries = g_list_append (entries, menu_entry_create (_("&User menu"), CK_UserMenu));
269 entries = g_list_append (entries, menu_entry_create (_("&Directory tree"), CK_Tree));
270 entries = g_list_append (entries, menu_entry_create (_("&Find file"), CK_Find));
271 entries = g_list_append (entries, menu_entry_create (_("S&wap panels"), CK_Swap));
272 entries = g_list_append (entries, menu_entry_create (_("Switch &panels on/off"), CK_Shell));
273 entries =
274 g_list_append (entries, menu_entry_create (_("&Compare directories"), CK_CompareDirs));
275 #ifdef USE_DIFF_VIEW
276 entries = g_list_append (entries, menu_entry_create (_("C&ompare files"), CK_CompareFiles));
277 #endif
278 entries =
279 g_list_append (entries, menu_entry_create (_("E&xternal panelize"), CK_ExternalPanelize));
280 entries = g_list_append (entries, menu_entry_create (_("Show directory s&izes"), CK_DirSize));
281 entries = g_list_append (entries, menu_separator_create ());
282 entries = g_list_append (entries, menu_entry_create (_("Command &history"), CK_History));
283 entries = g_list_append (entries, menu_entry_create (_("Di&rectory hotlist"), CK_HotList));
284 #ifdef ENABLE_VFS
285 entries = g_list_append (entries, menu_entry_create (_("&Active VFS list"), CK_VfsList));
286 #endif
287 #ifdef WITH_BACKGROUND
288 entries = g_list_append (entries, menu_entry_create (_("&Background jobs"), CK_Jobs));
289 #endif
290 entries = g_list_append (entries, menu_entry_create (_("Screen lis&t"), CK_ScreenList));
291 entries = g_list_append (entries, menu_separator_create ());
292 #ifdef ENABLE_VFS_UNDELFS
293 entries =
294 g_list_append (entries,
295 menu_entry_create (_("&Undelete files (ext2fs only)"), CK_Undelete));
296 #endif
297 #ifdef LISTMODE_EDITOR
298 entries = g_list_append (entries, menu_entry_create (_("&Listing format edit"), CK_ListMode));
299 #endif
300 #if defined (ENABLE_VFS_UNDELFS) || defined (LISTMODE_EDITOR)
301 entries = g_list_append (entries, menu_separator_create ());
302 #endif
303 entries =
304 g_list_append (entries,
305 menu_entry_create (_("Edit &extension file"), CK_EditExtensionsFile));
306 entries = g_list_append (entries, menu_entry_create (_("Edit &menu file"), CK_EditUserMenu));
307 entries =
308 g_list_append (entries,
309 menu_entry_create (_("Edit hi&ghlighting group file"),
310 CK_EditFileHighlightFile));
312 return entries;
315 /* --------------------------------------------------------------------------------------------- */
317 static GList *
318 create_options_menu (void)
320 GList *entries = NULL;
322 entries = g_list_append (entries, menu_entry_create (_("&Configuration..."), CK_Options));
323 entries = g_list_append (entries, menu_entry_create (_("&Layout..."), CK_OptionsLayout));
324 entries = g_list_append (entries, menu_entry_create (_("&Panel options..."), CK_OptionsPanel));
325 entries = g_list_append (entries, menu_entry_create (_("C&onfirmation..."), CK_OptionsConfirm));
326 entries =
327 g_list_append (entries, menu_entry_create (_("&Display bits..."), CK_OptionsDisplayBits));
328 entries = g_list_append (entries, menu_entry_create (_("Learn &keys..."), CK_LearnKeys));
329 #ifdef ENABLE_VFS
330 entries = g_list_append (entries, menu_entry_create (_("&Virtual FS..."), CK_OptionsVfs));
331 #endif
332 entries = g_list_append (entries, menu_separator_create ());
333 entries = g_list_append (entries, menu_entry_create (_("&Save setup"), CK_SaveSetup));
335 return entries;
338 /* --------------------------------------------------------------------------------------------- */
340 static void
341 init_menu (void)
343 left_menu = create_menu ("", create_panel_menu (), "[Left and Right Menus]");
344 menubar_add_menu (the_menubar, left_menu);
345 menubar_add_menu (the_menubar, create_menu (_("&File"), create_file_menu (), "[File Menu]"));
346 menubar_add_menu (the_menubar,
347 create_menu (_("&Command"), create_command_menu (), "[Command Menu]"));
348 menubar_add_menu (the_menubar,
349 create_menu (_("&Options"), create_options_menu (), "[Options Menu]"));
350 right_menu = create_menu ("", create_panel_menu (), "[Left and Right Menus]");
351 menubar_add_menu (the_menubar, right_menu);
352 update_menu ();
355 /* --------------------------------------------------------------------------------------------- */
357 static void
358 menu_last_selected_cmd (void)
360 the_menubar->is_active = TRUE;
361 the_menubar->is_dropped = (drop_menus != 0);
362 the_menubar->previous_widget = dlg_get_current_widget_id (midnight_dlg);
363 dlg_select_widget (the_menubar);
366 /* --------------------------------------------------------------------------------------------- */
368 static void
369 menu_cmd (void)
371 if (the_menubar->is_active)
372 return;
374 if ((get_current_index () == 0) == (current_panel->active != 0))
375 the_menubar->selected = 0;
376 else
377 the_menubar->selected = g_list_length (the_menubar->menu) - 1;
378 menu_last_selected_cmd ();
381 /* --------------------------------------------------------------------------------------------- */
383 static void
384 sort_cmd (void)
386 WPanel *p;
387 const panel_field_t *sort_order;
389 if (!SELECTED_IS_PANEL)
390 return;
392 p = MENU_PANEL;
393 sort_order = sort_box (&p->sort_info);
394 panel_set_sort_order (p, sort_order);
397 /* --------------------------------------------------------------------------------------------- */
399 static char *
400 midnight_get_shortcut (unsigned long command)
402 const char *ext_map;
403 const char *shortcut = NULL;
405 shortcut = keybind_lookup_keymap_shortcut (main_map, command);
406 if (shortcut != NULL)
407 return g_strdup (shortcut);
409 shortcut = keybind_lookup_keymap_shortcut (panel_map, command);
410 if (shortcut != NULL)
411 return g_strdup (shortcut);
413 ext_map = keybind_lookup_keymap_shortcut (main_map, CK_ExtendedKeyMap);
414 if (ext_map != NULL)
415 shortcut = keybind_lookup_keymap_shortcut (main_x_map, command);
416 if (shortcut != NULL)
417 return g_strdup_printf ("%s %s", ext_map, shortcut);
419 return NULL;
422 /* --------------------------------------------------------------------------------------------- */
424 static char *
425 midnight_get_title (const Dlg_head * h, size_t len)
427 /* TODO: share code with update_xterm_title_path() */
429 const char *path;
430 char host[BUF_TINY];
431 char *p;
432 struct passwd *pw = NULL;
433 char *login = NULL;
434 int res = 0;
436 (void) h;
438 path = strip_home_and_password (current_panel->cwd);
439 res = gethostname (host, sizeof (host));
440 if (res != 0)
441 host[0] = '\0';
442 else
443 host[sizeof (host) - 1] = '\0';
445 pw = getpwuid (getuid ());
446 if (pw != NULL)
447 login = g_strdup_printf ("%s@%s", pw->pw_name, host);
448 else
449 login = g_strdup (host);
451 p = g_strdup_printf ("%s [%s]:%s", _("Panels:"), login, path);
452 path = str_trunc (p, len - 4);
453 g_free (login);
454 g_free (p);
456 return g_strdup (path);
459 /* --------------------------------------------------------------------------------------------- */
461 static void
462 toggle_panels_split (void)
464 horizontal_split = !horizontal_split;
465 layout_change ();
466 do_refresh ();
469 /* --------------------------------------------------------------------------------------------- */
471 #if ENABLE_VFS
473 /* event helper */
474 static gboolean
475 check_panel_timestamp (const WPanel * panel, panel_view_mode_t mode, struct vfs_class *vclass,
476 vfsid id)
478 if (mode == view_listing)
480 vfs_path_t *vpath;
481 vfs_path_element_t *path_element;
483 vpath = vfs_path_from_str (panel->cwd);
484 path_element = vfs_path_get_by_index (vpath, -1);
486 if (path_element->class != vclass)
488 vfs_path_free (vpath);
489 return FALSE;
492 if (vfs_getid (vpath) != id)
494 vfs_path_free (vpath);
495 return FALSE;
497 vfs_path_free (vpath);
499 return TRUE;
502 /* --------------------------------------------------------------------------------------------- */
504 /* event callback */
505 static gboolean
506 check_current_panel_timestamp (const gchar * event_group_name, const gchar * event_name,
507 gpointer init_data, gpointer data)
509 ev_vfs_stamp_create_t *event_data = (ev_vfs_stamp_create_t *) data;
511 (void) event_group_name;
512 (void) event_name;
513 (void) init_data;
515 event_data->ret =
516 check_panel_timestamp (current_panel, get_current_type (), event_data->vclass,
517 event_data->id);
518 return !event_data->ret;
521 /* --------------------------------------------------------------------------------------------- */
523 /* event callback */
524 static gboolean
525 check_other_panel_timestamp (const gchar * event_group_name, const gchar * event_name,
526 gpointer init_data, gpointer data)
528 ev_vfs_stamp_create_t *event_data = (ev_vfs_stamp_create_t *) data;
530 (void) event_group_name;
531 (void) event_name;
532 (void) init_data;
534 event_data->ret =
535 check_panel_timestamp (other_panel, get_other_type (), event_data->vclass, event_data->id);
536 return !event_data->ret;
538 #endif /* ENABLE_VFS */
540 /* --------------------------------------------------------------------------------------------- */
542 /* event callback */
543 static gboolean
544 print_vfs_message (const gchar * event_group_name, const gchar * event_name,
545 gpointer init_data, gpointer data)
547 char str[128];
548 ev_vfs_print_message_t *event_data = (ev_vfs_print_message_t *) data;
550 (void) event_group_name;
551 (void) event_name;
552 (void) init_data;
554 g_vsnprintf (str, sizeof (str), event_data->msg, event_data->ap);
556 if (mc_global.widget.midnight_shutdown)
557 return TRUE;
559 if (!mc_global.message_visible || !the_hint || !the_hint->widget.owner)
561 int col, row;
563 if (!nice_rotating_dash || (ok_to_refresh <= 0))
564 return TRUE;
566 /* Preserve current cursor position */
567 tty_getyx (&row, &col);
569 tty_gotoyx (0, 0);
570 tty_setcolor (NORMAL_COLOR);
571 tty_print_string (str_fit_to_term (str, COLS - 1, J_LEFT));
573 /* Restore cursor position */
574 tty_gotoyx (row, col);
575 mc_refresh ();
576 return TRUE;
579 if (mc_global.message_visible)
580 set_hintbar (str);
582 return TRUE;
585 /* --------------------------------------------------------------------------------------------- */
587 static void
588 create_panels (void)
590 int current_index;
591 int other_index;
592 panel_view_mode_t current_mode, other_mode;
593 char original_dir[BUF_1K] = "\0";
595 if (boot_current_is_left)
597 current_index = 0;
598 other_index = 1;
599 current_mode = startup_left_mode;
600 other_mode = startup_right_mode;
602 else
604 current_index = 1;
605 other_index = 0;
606 current_mode = startup_right_mode;
607 other_mode = startup_left_mode;
609 /* Creates the left panel */
610 if (mc_run_param0 != NULL)
612 if (mc_run_param1 != NULL)
614 /* Ok, user has specified two dirs, save the original one,
615 * since we may not be able to chdir to the proper
616 * second directory later
618 mc_get_current_wd (original_dir, sizeof (original_dir) - 2);
620 mc_chdir (mc_run_param0);
622 set_display_type (current_index, current_mode);
624 /* The other panel */
625 if (mc_run_param1 != NULL)
627 if (original_dir[0] != '\0')
628 mc_chdir (original_dir);
629 mc_chdir (mc_run_param1);
631 set_display_type (other_index, other_mode);
633 if (startup_left_mode == view_listing)
634 current_panel = left_panel;
635 else if (right_panel != NULL)
636 current_panel = right_panel;
637 else
638 current_panel = left_panel;
640 #if ENABLE_VFS
641 mc_event_add (MCEVENT_GROUP_CORE, "vfs_timestamp", check_other_panel_timestamp, NULL, NULL);
642 mc_event_add (MCEVENT_GROUP_CORE, "vfs_timestamp", check_current_panel_timestamp, NULL, NULL);
643 #endif /* ENABLE_VFS */
645 mc_event_add (MCEVENT_GROUP_CORE, "vfs_print_message", print_vfs_message, NULL, NULL);
647 /* Create the nice widgets */
648 cmdline = command_new (0, 0, 0);
649 the_prompt = label_new (0, 0, mc_prompt);
650 the_prompt->transparent = 1;
651 the_bar = buttonbar_new (mc_global.keybar_visible);
653 the_hint = label_new (0, 0, 0);
654 the_hint->transparent = 1;
655 the_hint->auto_adjust_cols = 0;
656 the_hint->widget.cols = COLS;
658 the_menubar = menubar_new (0, 0, COLS, NULL);
661 /* --------------------------------------------------------------------------------------------- */
663 static void
664 put_current_path (void)
666 char *cwd_path;
667 if (!command_prompt)
668 return;
670 cwd_path = remove_encoding_from_path (current_panel->cwd);
671 command_insert (cmdline, cwd_path, FALSE);
673 if (cwd_path[strlen (cwd_path) - 1] != PATH_SEP)
674 command_insert (cmdline, PATH_SEP_STR, FALSE);
675 g_free (cwd_path);
678 /* --------------------------------------------------------------------------------------------- */
680 static void
681 put_other_path (void)
683 char *cwd_path;
685 if (get_other_type () != view_listing)
686 return;
688 if (!command_prompt)
689 return;
691 cwd_path = remove_encoding_from_path (other_panel->cwd);
692 command_insert (cmdline, cwd_path, FALSE);
694 if (cwd_path[strlen (cwd_path) - 1] != PATH_SEP)
695 command_insert (cmdline, PATH_SEP_STR, FALSE);
696 g_free (cwd_path);
699 /* --------------------------------------------------------------------------------------------- */
701 static void
702 put_link (WPanel * panel)
704 if (!command_prompt)
705 return;
706 if (S_ISLNK (selection (panel)->st.st_mode))
708 char buffer[MC_MAXPATHLEN];
709 char *p;
710 int i;
712 p = concat_dir_and_file (panel->cwd, selection (panel)->fname);
713 i = mc_readlink (p, buffer, MC_MAXPATHLEN - 1);
714 g_free (p);
715 if (i > 0)
717 buffer[i] = '\0';
718 command_insert (cmdline, buffer, TRUE);
723 /* --------------------------------------------------------------------------------------------- */
725 static void
726 put_current_link (void)
728 put_link (current_panel);
731 /* --------------------------------------------------------------------------------------------- */
733 static void
734 put_other_link (void)
736 if (get_other_type () == view_listing)
737 put_link (other_panel);
740 /* --------------------------------------------------------------------------------------------- */
742 /** Insert the selected file name into the input line */
743 static void
744 put_prog_name (void)
746 char *tmp;
747 if (!command_prompt)
748 return;
750 if (get_current_type () == view_tree)
752 WTree *tree = (WTree *) get_panel_widget (get_current_index ());
753 tmp = tree_selected_name (tree);
755 else
756 tmp = selection (current_panel)->fname;
758 command_insert (cmdline, tmp, TRUE);
761 /* --------------------------------------------------------------------------------------------- */
763 static void
764 put_tagged (WPanel * panel)
766 int i;
768 if (!command_prompt)
769 return;
770 input_disable_update (cmdline);
771 if (panel->marked)
773 for (i = 0; i < panel->count; i++)
775 if (panel->dir.list[i].f.marked)
776 command_insert (cmdline, panel->dir.list[i].fname, TRUE);
779 else
781 command_insert (cmdline, panel->dir.list[panel->selected].fname, TRUE);
783 input_enable_update (cmdline);
786 /* --------------------------------------------------------------------------------------------- */
788 static void
789 put_current_tagged (void)
791 put_tagged (current_panel);
794 /* --------------------------------------------------------------------------------------------- */
796 static void
797 put_other_tagged (void)
799 if (get_other_type () == view_listing)
800 put_tagged (other_panel);
803 /* --------------------------------------------------------------------------------------------- */
805 static void
806 ctl_x_cmd (void)
808 ctl_x_map_enabled = TRUE;
811 /* --------------------------------------------------------------------------------------------- */
813 static void
814 setup_mc (void)
816 #ifdef HAVE_SLANG
817 #ifdef HAVE_CHARSET
818 tty_display_8bit (TRUE);
819 #else
820 tty_display_8bit (mc_global.full_eight_bits != 0);
821 #endif /* HAVE_CHARSET */
823 #else /* HAVE_SLANG */
825 #ifdef HAVE_CHARSET
826 tty_display_8bit (TRUE);
827 #else
828 tty_display_8bit (mc_global.eight_bit_clean != 0);
829 #endif /* HAVE_CHARSET */
830 #endif /* HAVE_SLANG */
832 #ifdef HAVE_SUBSHELL_SUPPORT
833 if (mc_global.tty.use_subshell)
834 add_select_channel (mc_global.tty.subshell_pty, load_prompt, 0);
835 #endif /* !HAVE_SUBSHELL_SUPPORT */
837 if ((tty_baudrate () < 9600) || mc_global.tty.slow_terminal)
838 verbose = 0;
841 /* --------------------------------------------------------------------------------------------- */
843 static void
844 setup_dummy_mc (void)
846 char d[MC_MAXPATHLEN];
847 int ret;
849 mc_get_current_wd (d, MC_MAXPATHLEN);
850 setup_mc ();
851 ret = mc_chdir (d);
854 /* --------------------------------------------------------------------------------------------- */
856 static void
857 done_mc (void)
859 /* Setup shutdown
861 * We sync the profiles since the hotlist may have changed, while
862 * we only change the setup data if we have the auto save feature set
864 char *curr_dir;
866 save_setup (auto_save_setup, panels_options.auto_save_setup);
868 curr_dir = vfs_get_current_dir ();
869 vfs_stamp_path (curr_dir);
870 g_free (curr_dir);
872 if ((current_panel != NULL) && (get_current_type () == view_listing))
873 vfs_stamp_path (current_panel->cwd);
875 if ((other_panel != NULL) && (get_other_type () == view_listing))
876 vfs_stamp_path (other_panel->cwd);
879 /* --------------------------------------------------------------------------------------------- */
881 static void
882 create_panels_and_run_mc (void)
884 midnight_dlg->get_shortcut = midnight_get_shortcut;
885 midnight_dlg->get_title = midnight_get_title;
887 create_panels ();
889 add_widget (midnight_dlg, the_menubar);
890 init_menu ();
892 add_widget (midnight_dlg, get_panel_widget (0));
893 add_widget (midnight_dlg, get_panel_widget (1));
895 add_widget (midnight_dlg, the_hint);
896 add_widget (midnight_dlg, cmdline);
897 add_widget (midnight_dlg, the_prompt);
899 add_widget (midnight_dlg, the_bar);
900 midnight_set_buttonbar (the_bar);
902 /* Run the Midnight Commander if no file was specified in the command line */
903 run_dlg (midnight_dlg);
906 /* --------------------------------------------------------------------------------------------- */
908 /** result must be free'd (I think this should go in util.c) */
909 static char *
910 prepend_cwd_on_local (const char *filename)
912 char *d;
913 size_t l;
914 vfs_path_t *vpath;
916 vpath = vfs_path_from_str (filename);
917 if (!vfs_file_is_local (vpath) || g_path_is_absolute (filename))
919 vfs_path_free (vpath);
920 return g_strdup (filename);
922 vfs_path_free (vpath);
924 d = g_malloc (MC_MAXPATHLEN + strlen (filename) + 2);
925 mc_get_current_wd (d, MC_MAXPATHLEN);
926 l = strlen (d);
927 d[l++] = PATH_SEP;
928 strcpy (d + l, filename);
929 canonicalize_pathname (d);
930 return d;
933 /* --------------------------------------------------------------------------------------------- */
935 /** Invoke the internal view/edit routine with:
936 * the default processing and forcing the internal viewer/editor
938 static void
939 mc_maybe_editor_or_viewer (void)
941 switch (mc_global.mc_run_mode)
943 #ifdef USE_INTERNAL_EDIT
944 case MC_RUN_EDITOR:
945 edit_file (mc_run_param0, mc_args__edit_start_line);
946 break;
947 #endif /* USE_INTERNAL_EDIT */
948 case MC_RUN_VIEWER:
950 char *path;
951 path = prepend_cwd_on_local (mc_run_param0);
952 view_file (path, 0, 1);
953 g_free (path);
954 break;
956 #ifdef USE_DIFF_VIEW
957 case MC_RUN_DIFFVIEWER:
958 diff_view (mc_run_param0, mc_run_param1, mc_run_param0, mc_run_param1);
959 break;
960 #endif /* USE_DIFF_VIEW */
961 default:
962 break;
966 /* --------------------------------------------------------------------------------------------- */
968 static gboolean
969 quit_cmd_internal (int quiet)
971 int q = quit;
972 size_t n;
974 n = dialog_switch_num () - 1;
975 if (n != 0)
977 char msg[BUF_MEDIUM];
979 g_snprintf (msg, sizeof (msg),
980 ngettext ("You have %zd opened screen. Quit anyway?",
981 "You have %zd opened screens. Quit anyway?", n), n);
983 if (query_dialog (_("The Midnight Commander"), msg, D_NORMAL, 2, _("&Yes"), _("&No")) != 0)
984 return FALSE;
985 q = 1;
987 else if (quiet || !confirm_exit)
988 q = 1;
989 else if (query_dialog (_("The Midnight Commander"),
990 _("Do you really want to quit the Midnight Commander?"),
991 D_NORMAL, 2, _("&Yes"), _("&No")) == 0)
992 q = 1;
994 if (q != 0)
996 #ifdef HAVE_SUBSHELL_SUPPORT
997 if (!mc_global.tty.use_subshell)
998 stop_dialogs ();
999 else if ((q = exit_subshell ()))
1000 #endif
1001 stop_dialogs ();
1004 if (q != 0)
1005 quit |= 1;
1006 return (quit != 0);
1009 /* --------------------------------------------------------------------------------------------- */
1011 static gboolean
1012 quit_cmd (void)
1014 return quit_cmd_internal (0);
1017 /* --------------------------------------------------------------------------------------------- */
1019 static void
1020 toggle_show_hidden (void)
1022 panels_options.show_dot_files = !panels_options.show_dot_files;
1023 update_panels (UP_RELOAD, UP_KEEPSEL);
1026 /* --------------------------------------------------------------------------------------------- */
1029 * Repaint the contents of the panels without frames. To schedule panel
1030 * for repainting, set panel->dirty to 1. There are many reasons why
1031 * the panels need to be repainted, and this is a costly operation, so
1032 * it's done once per event.
1035 static void
1036 update_dirty_panels (void)
1038 if (get_current_type () == view_listing && current_panel->dirty)
1039 send_message ((Widget *) current_panel, WIDGET_DRAW, 0);
1041 if (get_other_type () == view_listing && other_panel->dirty)
1042 send_message ((Widget *) other_panel, WIDGET_DRAW, 0);
1045 /* --------------------------------------------------------------------------------------------- */
1047 static cb_ret_t
1048 midnight_execute_cmd (Widget * sender, unsigned long command)
1050 cb_ret_t res = MSG_HANDLED;
1052 (void) sender;
1054 /* stop quick search before executing any command */
1055 send_message ((Widget *) current_panel, WIDGET_COMMAND, CK_SearchStop);
1057 switch (command)
1059 case CK_HotListAdd:
1060 add2hotlist_cmd ();
1061 break;
1062 case CK_PanelListingChange:
1063 change_listing_cmd ();
1064 break;
1065 case CK_ChangeMode:
1066 chmod_cmd ();
1067 break;
1068 case CK_ChangeOwn:
1069 chown_cmd ();
1070 break;
1071 case CK_ChangeOwnAdvanced:
1072 chown_advanced_cmd ();
1073 break;
1074 case CK_CompareDirs:
1075 compare_dirs_cmd ();
1076 break;
1077 case CK_Options:
1078 configure_box ();
1079 break;
1080 #ifdef ENABLE_VFS
1081 case CK_OptionsVfs:
1082 configure_vfs ();
1083 break;
1084 #endif
1085 case CK_OptionsConfirm:
1086 confirm_box ();
1087 break;
1088 case CK_Copy:
1089 copy_cmd ();
1090 break;
1091 case CK_PutCurrentPath:
1092 put_current_path ();
1093 break;
1094 case CK_PutCurrentLink:
1095 put_current_link ();
1096 break;
1097 case CK_PutCurrentTagged:
1098 put_current_tagged ();
1099 break;
1100 case CK_PutOtherPath:
1101 put_other_path ();
1102 break;
1103 case CK_PutOtherLink:
1104 put_other_link ();
1105 break;
1106 case CK_PutOtherTagged:
1107 put_other_tagged ();
1108 break;
1109 case CK_Delete:
1110 delete_cmd ();
1111 break;
1112 case CK_ScreenList:
1113 dialog_switch_list ();
1114 break;
1115 #ifdef USE_DIFF_VIEW
1116 case CK_CompareFiles:
1117 diff_view_cmd ();
1118 break;
1119 #endif
1120 case CK_OptionsDisplayBits:
1121 display_bits_box ();
1122 break;
1123 case CK_Edit:
1124 edit_cmd ();
1125 break;
1126 #ifdef USE_INTERNAL_EDIT
1127 case CK_EditForceInternal:
1128 edit_cmd_force_internal ();
1129 break;
1130 #endif
1131 case CK_EditExtensionsFile:
1132 ext_cmd ();
1133 break;
1134 case CK_EditFileHighlightFile:
1135 edit_fhl_cmd ();
1136 break;
1137 case CK_EditUserMenu:
1138 edit_mc_menu_cmd ();
1139 break;
1140 case CK_LinkSymbolicEdit:
1141 edit_symlink_cmd ();
1142 break;
1143 case CK_ExternalPanelize:
1144 external_panelize ();
1145 break;
1146 case CK_Filter:
1147 filter_cmd ();
1148 break;
1149 case CK_ViewFiltered:
1150 view_filtered_cmd ();
1151 break;
1152 case CK_Find:
1153 find_cmd ();
1154 break;
1155 #ifdef ENABLE_VFS_FISH
1156 case CK_ConnectFish:
1157 fishlink_cmd ();
1158 break;
1159 #endif
1160 #ifdef ENABLE_VFS_FTP
1161 case CK_ConnectFtp:
1162 ftplink_cmd ();
1163 break;
1164 #endif
1165 #ifdef ENABLE_VFS_SMB
1166 case CK_ConnectSmb:
1167 smblink_cmd ();
1168 break;
1169 #endif /* ENABLE_VFS_SMB */
1170 case CK_Panelize:
1171 cd_panelize_cmd ();
1172 break;
1173 case CK_Help:
1174 help_cmd ();
1175 break;
1176 case CK_History:
1177 /* show the history of command line widget */
1178 send_message (&cmdline->widget, WIDGET_COMMAND, CK_History);
1179 break;
1180 case CK_PanelInfo:
1181 if (sender == (Widget *) the_menubar)
1182 info_cmd (); /* menu */
1183 else
1184 info_cmd_no_menu (); /* shortcut or buttonbar */
1185 break;
1186 #ifdef WITH_BACKGROUND
1187 case CK_Jobs:
1188 jobs_cmd ();
1189 break;
1190 #endif
1191 case CK_OptionsLayout:
1192 layout_box ();
1193 break;
1194 case CK_LearnKeys:
1195 learn_keys ();
1196 break;
1197 case CK_Link:
1198 link_cmd (LINK_HARDLINK);
1199 break;
1200 case CK_PanelListing:
1201 listing_cmd ();
1202 break;
1203 #ifdef LISTMODE_EDITOR
1204 case CK_ListMode:
1205 listmode_cmd ();
1206 break;
1207 #endif
1208 case CK_Menu:
1209 menu_cmd ();
1210 break;
1211 case CK_MenuLastSelected:
1212 menu_last_selected_cmd ();
1213 break;
1214 case CK_MakeDir:
1215 mkdir_cmd ();
1216 break;
1217 case CK_OptionsPanel:
1218 panel_options_box ();
1219 break;
1220 #ifdef HAVE_CHARSET
1221 case CK_SelectCodepage:
1222 encoding_cmd ();
1223 break;
1224 #endif
1225 case CK_CdQuick:
1226 quick_cd_cmd ();
1227 break;
1228 case CK_HotList:
1229 hotlist_cmd ();
1230 break;
1231 case CK_PanelQuickView:
1232 if (sender == (Widget *) the_menubar)
1233 quick_view_cmd (); /* menu */
1234 else
1235 quick_cmd_no_menu (); /* shortcut or buttonabr */
1236 break;
1237 case CK_QuitQuiet:
1238 quiet_quit_cmd ();
1239 break;
1240 case CK_Quit:
1241 quit_cmd ();
1242 break;
1243 case CK_LinkSymbolicRelative:
1244 link_cmd (LINK_SYMLINK_RELATIVE);
1245 break;
1246 case CK_Move:
1247 rename_cmd ();
1248 break;
1249 case CK_Reread:
1250 reread_cmd ();
1251 break;
1252 #ifdef ENABLE_VFS
1253 case CK_VfsList:
1254 vfs_list ();
1255 break;
1256 #endif
1257 case CK_SelectInvert:
1258 select_invert_cmd ();
1259 break;
1260 case CK_SaveSetup:
1261 save_setup_cmd ();
1262 break;
1263 case CK_Select:
1264 select_cmd ();
1265 break;
1266 case CK_Shell:
1267 view_other_cmd ();
1268 break;
1269 case CK_DirSize:
1270 smart_dirsize_cmd ();
1271 break;
1272 case CK_Sort:
1273 sort_cmd ();
1274 break;
1275 case CK_ExtendedKeyMap:
1276 ctl_x_cmd ();
1277 break;
1278 case CK_Suspend:
1279 mc_event_raise (MCEVENT_GROUP_CORE, "suspend", NULL);
1280 break;
1281 case CK_Swap:
1282 swap_cmd ();
1283 break;
1284 case CK_LinkSymbolic:
1285 link_cmd (LINK_SYMLINK_ABSOLUTE);
1286 break;
1287 case CK_PanelListingSwitch:
1288 toggle_listing_cmd ();
1289 break;
1290 case CK_ShowHidden:
1291 toggle_show_hidden ();
1292 break;
1293 case CK_SplitVertHoriz:
1294 toggle_panels_split ();
1295 break;
1296 case CK_PanelTree:
1297 panel_tree_cmd ();
1298 break;
1299 case CK_Tree:
1300 treebox_cmd ();
1301 break;
1302 #ifdef ENABLE_VFS_UNDELFS
1303 case CK_Undelete:
1304 undelete_cmd ();
1305 break;
1306 #endif
1307 case CK_Unselect:
1308 unselect_cmd ();
1309 break;
1310 case CK_UserMenu:
1311 user_file_menu_cmd ();
1312 break;
1313 case CK_View:
1314 view_cmd ();
1315 break;
1316 case CK_ViewFile:
1317 view_file_cmd ();
1318 break;
1319 case CK_Cancel:
1320 /* don't close panels due to SIGINT */
1321 break;
1322 default:
1323 res = MSG_NOT_HANDLED;
1326 return res;
1329 /* --------------------------------------------------------------------------------------------- */
1331 static cb_ret_t
1332 midnight_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
1334 unsigned long command;
1336 switch (msg)
1338 case DLG_INIT:
1339 panel_init ();
1340 setup_panels ();
1341 return MSG_HANDLED;
1343 case DLG_DRAW:
1344 load_hint (1);
1345 /* We handle the special case of the output lines */
1346 if (mc_global.tty.console_flag != '\0' && output_lines)
1347 show_console_contents (output_start_y,
1348 LINES - output_lines - mc_global.keybar_visible -
1349 1, LINES - mc_global.keybar_visible - 1);
1350 return MSG_HANDLED;
1352 case DLG_RESIZE:
1353 setup_panels ();
1354 menubar_arrange (the_menubar);
1355 return MSG_HANDLED;
1357 case DLG_IDLE:
1358 /* We only need the first idle event to show user menu after start */
1359 set_idle_proc (h, 0);
1361 if (boot_current_is_left)
1362 dlg_select_widget (get_panel_widget (0));
1363 else
1364 dlg_select_widget (get_panel_widget (1));
1366 if (auto_menu)
1367 midnight_execute_cmd (NULL, CK_UserMenu);
1368 return MSG_HANDLED;
1370 case DLG_KEY:
1371 if (ctl_x_map_enabled)
1373 ctl_x_map_enabled = FALSE;
1374 command = keybind_lookup_keymap_command (main_x_map, parm);
1375 if (command != CK_IgnoreKey)
1376 return midnight_execute_cmd (NULL, command);
1379 /* FIXME: should handle all menu shortcuts before this point */
1380 if (the_menubar->is_active)
1381 return MSG_NOT_HANDLED;
1383 if (parm == '\t')
1384 input_free_completions (cmdline);
1386 if (parm == '\n')
1388 size_t i;
1390 for (i = 0; cmdline->buffer[i] != '\0' &&
1391 (cmdline->buffer[i] == ' ' || cmdline->buffer[i] == '\t'); i++)
1394 if (cmdline->buffer[i] != '\0')
1396 send_message ((Widget *) cmdline, WIDGET_KEY, parm);
1397 return MSG_HANDLED;
1400 input_insert (cmdline, "", FALSE);
1401 cmdline->point = 0;
1404 /* Ctrl-Enter and Alt-Enter */
1405 if (((parm & ~(KEY_M_CTRL | KEY_M_ALT)) == '\n') && (parm & (KEY_M_CTRL | KEY_M_ALT)))
1407 put_prog_name ();
1408 return MSG_HANDLED;
1411 /* Ctrl-Shift-Enter */
1412 if (parm == (KEY_M_CTRL | KEY_M_SHIFT | '\n'))
1414 put_current_path ();
1415 put_prog_name ();
1416 return MSG_HANDLED;
1419 if ((!mc_global.tty.alternate_plus_minus
1420 || !(mc_global.tty.console_flag != '\0' || mc_global.tty.xterm_flag)) && !quote
1421 && !current_panel->searching)
1423 if (!only_leading_plus_minus)
1425 /* Special treatement, since the input line will eat them */
1426 if (parm == '+')
1428 select_cmd ();
1429 return MSG_HANDLED;
1432 if (parm == '\\' || parm == '-')
1434 unselect_cmd ();
1435 return MSG_HANDLED;
1438 if (parm == '*')
1440 select_invert_cmd ();
1441 return MSG_HANDLED;
1444 else if (!command_prompt || !cmdline->buffer[0])
1446 /* Special treatement '+', '-', '\', '*' only when this is
1447 * first char on input line
1450 if (parm == '+')
1452 select_cmd ();
1453 return MSG_HANDLED;
1456 if (parm == '\\' || parm == '-')
1458 unselect_cmd ();
1459 return MSG_HANDLED;
1462 if (parm == '*')
1464 select_invert_cmd ();
1465 return MSG_HANDLED;
1469 return MSG_NOT_HANDLED;
1471 case DLG_HOTKEY_HANDLED:
1472 if ((get_current_type () == view_listing) && current_panel->searching)
1474 current_panel->dirty = 1; /* FIXME: unneeded? */
1475 send_message ((Widget *) current_panel, WIDGET_COMMAND, CK_SearchStop);
1477 return MSG_HANDLED;
1479 case DLG_UNHANDLED_KEY:
1480 if (command_prompt)
1482 cb_ret_t v;
1484 v = send_message ((Widget *) cmdline, WIDGET_KEY, parm);
1485 if (v == MSG_HANDLED)
1486 return MSG_HANDLED;
1489 if (ctl_x_map_enabled)
1491 ctl_x_map_enabled = FALSE;
1492 command = keybind_lookup_keymap_command (main_x_map, parm);
1494 else
1495 command = keybind_lookup_keymap_command (main_map, parm);
1497 return (command == CK_IgnoreKey) ? MSG_NOT_HANDLED : midnight_execute_cmd (NULL, command);
1499 case DLG_POST_KEY:
1500 if (!the_menubar->is_active)
1501 update_dirty_panels ();
1502 return MSG_HANDLED;
1504 case DLG_ACTION:
1505 /* shortcut */
1506 if (sender == NULL)
1507 return midnight_execute_cmd (NULL, parm);
1508 /* message from menu */
1509 if (sender == (Widget *) the_menubar)
1510 return midnight_execute_cmd (sender, parm);
1511 /* message from buttonbar */
1512 if (sender == (Widget *) the_bar)
1514 if (data != NULL)
1515 return send_message ((Widget *) data, WIDGET_COMMAND, parm);
1516 return midnight_execute_cmd (sender, parm);
1518 return MSG_NOT_HANDLED;
1520 case DLG_END:
1521 panel_deinit ();
1522 return MSG_HANDLED;
1524 default:
1525 return default_dlg_callback (h, sender, msg, parm, data);
1529 /* --------------------------------------------------------------------------------------------- */
1530 /*** public functions ****************************************************************************/
1531 /* --------------------------------------------------------------------------------------------- */
1533 void
1534 update_menu (void)
1536 menu_set_name (left_menu, horizontal_split ? _("&Above") : _("&Left"));
1537 menu_set_name (right_menu, horizontal_split ? _("&Below") : _("&Right"));
1538 menubar_arrange (the_menubar);
1539 menubar_set_visible (the_menubar, menubar_visible);
1542 void
1543 midnight_set_buttonbar (WButtonBar * b)
1545 buttonbar_set_label (b, 1, Q_ ("ButtonBar|Help"), main_map, NULL);
1546 buttonbar_set_label (b, 2, Q_ ("ButtonBar|Menu"), main_map, NULL);
1547 buttonbar_set_label (b, 3, Q_ ("ButtonBar|View"), main_map, NULL);
1548 buttonbar_set_label (b, 4, Q_ ("ButtonBar|Edit"), main_map, NULL);
1549 buttonbar_set_label (b, 5, Q_ ("ButtonBar|Copy"), main_map, NULL);
1550 buttonbar_set_label (b, 6, Q_ ("ButtonBar|RenMov"), main_map, NULL);
1551 buttonbar_set_label (b, 7, Q_ ("ButtonBar|Mkdir"), main_map, NULL);
1552 buttonbar_set_label (b, 8, Q_ ("ButtonBar|Delete"), main_map, NULL);
1553 buttonbar_set_label (b, 9, Q_ ("ButtonBar|PullDn"), main_map, NULL);
1554 buttonbar_set_label (b, 10, Q_ ("ButtonBar|Quit"), main_map, NULL);
1557 /* --------------------------------------------------------------------------------------------- */
1559 * Load new hint and display it.
1560 * IF force is not 0, ignore the timeout.
1563 void
1564 load_hint (gboolean force)
1566 char *hint;
1568 if (the_hint->widget.owner == NULL)
1569 return;
1571 if (!mc_global.message_visible)
1573 label_set_text (the_hint, NULL);
1574 return;
1577 hint = get_random_hint (force);
1579 if (hint != NULL)
1581 if (*hint != '\0')
1582 set_hintbar (hint);
1583 g_free (hint);
1585 else
1587 char text[BUF_SMALL];
1589 g_snprintf (text, sizeof (text), _("GNU Midnight Commander %s\n"), VERSION);
1590 set_hintbar (text);
1594 /* --------------------------------------------------------------------------------------------- */
1596 void
1597 change_panel (void)
1599 input_free_completions (cmdline);
1600 dlg_one_down (midnight_dlg);
1603 /* --------------------------------------------------------------------------------------------- */
1605 /** Save current stat of directories to avoid reloading the panels
1606 * when no modifications have taken place
1608 void
1609 save_cwds_stat (void)
1611 if (panels_options.fast_reload)
1613 mc_stat (current_panel->cwd, &(current_panel->dir_stat));
1614 if (get_other_type () == view_listing)
1615 mc_stat (other_panel->cwd, &(other_panel->dir_stat));
1619 /* --------------------------------------------------------------------------------------------- */
1621 gboolean
1622 quiet_quit_cmd (void)
1624 print_last_revert = TRUE;
1625 return quit_cmd_internal (1);
1628 /* --------------------------------------------------------------------------------------------- */
1630 /** Run the main dialog that occupies the whole screen */
1631 void
1632 do_nc (void)
1634 dlg_colors_t midnight_colors;
1636 midnight_colors[DLG_COLOR_NORMAL] = mc_skin_color_get ("dialog", "_default_");
1637 midnight_colors[DLG_COLOR_FOCUS] = mc_skin_color_get ("dialog", "focus");
1638 midnight_colors[DLG_COLOR_HOT_NORMAL] = mc_skin_color_get ("dialog", "hotnormal");
1639 midnight_colors[DLG_COLOR_HOT_FOCUS] = mc_skin_color_get ("dialog", "hotfocus");
1640 midnight_colors[DLG_COLOR_TITLE] = mc_skin_color_get ("dialog", "title");
1642 #ifdef USE_INTERNAL_EDIT
1643 edit_stack_init ();
1644 #endif
1646 midnight_dlg = create_dlg (FALSE, 0, 0, LINES, COLS, midnight_colors, midnight_callback,
1647 "[main]", NULL, DLG_WANT_IDLE);
1649 if (mc_global.mc_run_mode == MC_RUN_FULL)
1650 setup_mc ();
1651 else
1652 setup_dummy_mc ();
1654 /* Check if we were invoked as an editor or file viewer */
1655 if (mc_global.mc_run_mode != MC_RUN_FULL)
1656 mc_maybe_editor_or_viewer ();
1657 else
1659 create_panels_and_run_mc ();
1661 /* destroy_dlg destroys even current_panel->cwd, so we have to save a copy :) */
1662 if (mc_args__last_wd_file != NULL && vfs_current_is_local ())
1663 last_wd_string = g_strdup (current_panel->cwd);
1665 /* don't handle VFS timestamps for dirs opened in panels */
1666 mc_event_destroy (MCEVENT_GROUP_CORE, "vfs_timestamp");
1668 clean_dir (&panelized_panel.list, panelized_panel.count);
1671 /* Program end */
1672 mc_global.widget.midnight_shutdown = TRUE;
1673 dialog_switch_shutdown ();
1674 done_mc ();
1675 destroy_dlg (midnight_dlg);
1676 current_panel = NULL;
1678 #ifdef USE_INTERNAL_EDIT
1679 edit_stack_free ();
1680 #endif
1682 if ((quit & SUBSHELL_EXIT) == 0)
1683 clr_scr ();
1686 /* --------------------------------------------------------------------------------------------- */