Changed interface of mc_stat() and mc_lstat() functions
[midnight-commander.git] / src / filemanager / midnight.c
blob719d456e58c5237b3257375262eee423671311d6
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_prepend (entries, menu_entry_create (_("File listin&g"), CK_PanelListing));
193 entries = g_list_prepend (entries, menu_entry_create (_("&Quick view"), CK_PanelQuickView));
194 entries = g_list_prepend (entries, menu_entry_create (_("&Info"), CK_PanelInfo));
195 entries = g_list_prepend (entries, menu_entry_create (_("&Tree"), CK_PanelTree));
196 entries = g_list_prepend (entries, menu_separator_create ());
197 entries =
198 g_list_prepend (entries, menu_entry_create (_("&Listing mode..."), CK_PanelListingChange));
199 entries = g_list_prepend (entries, menu_entry_create (_("&Sort order..."), CK_Sort));
200 entries = g_list_prepend (entries, menu_entry_create (_("&Filter..."), CK_Filter));
201 #ifdef HAVE_CHARSET
202 entries = g_list_prepend (entries, menu_entry_create (_("&Encoding..."), CK_SelectCodepage));
203 #endif
204 entries = g_list_prepend (entries, menu_separator_create ());
205 #ifdef ENABLE_VFS_FTP
206 entries = g_list_prepend (entries, menu_entry_create (_("FT&P link..."), CK_ConnectFtp));
207 #endif
208 #ifdef ENABLE_VFS_FISH
209 entries = g_list_prepend (entries, menu_entry_create (_("S&hell link..."), CK_ConnectFish));
210 #endif
211 #ifdef ENABLE_VFS_SMB
212 entries = g_list_prepend (entries, menu_entry_create (_("SM&B link..."), CK_ConnectSmb));
213 #endif
214 entries = g_list_prepend (entries, menu_entry_create (_("Paneli&ze"), CK_Panelize));
215 entries = g_list_prepend (entries, menu_separator_create ());
216 entries = g_list_prepend (entries, menu_entry_create (_("&Rescan"), CK_Reread));
218 return g_list_reverse (entries);
221 /* --------------------------------------------------------------------------------------------- */
223 static GList *
224 create_file_menu (void)
226 GList *entries = NULL;
228 entries = g_list_prepend (entries, menu_entry_create (_("&View"), CK_View));
229 entries = g_list_prepend (entries, menu_entry_create (_("Vie&w file..."), CK_ViewFile));
230 entries = g_list_prepend (entries, menu_entry_create (_("&Filtered view"), CK_ViewFiltered));
231 entries = g_list_prepend (entries, menu_entry_create (_("&Edit"), CK_Edit));
232 entries = g_list_prepend (entries, menu_entry_create (_("&Copy"), CK_Copy));
233 entries = g_list_prepend (entries, menu_entry_create (_("C&hmod"), CK_ChangeMode));
234 entries = g_list_prepend (entries, menu_entry_create (_("&Link"), CK_Link));
235 entries = g_list_prepend (entries, menu_entry_create (_("&Symlink"), CK_LinkSymbolic));
236 entries =
237 g_list_prepend (entries,
238 menu_entry_create (_("Relative symlin&k"), CK_LinkSymbolicRelative));
239 entries = g_list_prepend (entries, menu_entry_create (_("Edit s&ymlink"), CK_LinkSymbolicEdit));
240 entries = g_list_prepend (entries, menu_entry_create (_("Ch&own"), CK_ChangeOwn));
241 entries =
242 g_list_prepend (entries, menu_entry_create (_("&Advanced chown"), CK_ChangeOwnAdvanced));
243 entries = g_list_prepend (entries, menu_entry_create (_("&Rename/Move"), CK_Move));
244 entries = g_list_prepend (entries, menu_entry_create (_("&Mkdir"), CK_MakeDir));
245 entries = g_list_prepend (entries, menu_entry_create (_("&Delete"), CK_Delete));
246 entries = g_list_prepend (entries, menu_entry_create (_("&Quick cd"), CK_CdQuick));
247 entries = g_list_prepend (entries, menu_separator_create ());
248 entries = g_list_prepend (entries, menu_entry_create (_("Select &group"), CK_Select));
249 entries = g_list_prepend (entries, menu_entry_create (_("U&nselect group"), CK_Unselect));
250 entries = g_list_prepend (entries, menu_entry_create (_("&Invert selection"), CK_SelectInvert));
251 entries = g_list_prepend (entries, menu_separator_create ());
252 entries = g_list_prepend (entries, menu_entry_create (_("E&xit"), CK_Quit));
254 return g_list_reverse (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_prepend (entries, menu_entry_create (_("&User menu"), CK_UserMenu));
269 entries = g_list_prepend (entries, menu_entry_create (_("&Directory tree"), CK_Tree));
270 entries = g_list_prepend (entries, menu_entry_create (_("&Find file"), CK_Find));
271 entries = g_list_prepend (entries, menu_entry_create (_("S&wap panels"), CK_Swap));
272 entries = g_list_prepend (entries, menu_entry_create (_("Switch &panels on/off"), CK_Shell));
273 entries =
274 g_list_prepend (entries, menu_entry_create (_("&Compare directories"), CK_CompareDirs));
275 #ifdef USE_DIFF_VIEW
276 entries = g_list_prepend (entries, menu_entry_create (_("C&ompare files"), CK_CompareFiles));
277 #endif
278 entries =
279 g_list_prepend (entries, menu_entry_create (_("E&xternal panelize"), CK_ExternalPanelize));
280 entries = g_list_prepend (entries, menu_entry_create (_("Show directory s&izes"), CK_DirSize));
281 entries = g_list_prepend (entries, menu_separator_create ());
282 entries = g_list_prepend (entries, menu_entry_create (_("Command &history"), CK_History));
283 entries = g_list_prepend (entries, menu_entry_create (_("Di&rectory hotlist"), CK_HotList));
284 #ifdef ENABLE_VFS
285 entries = g_list_prepend (entries, menu_entry_create (_("&Active VFS list"), CK_VfsList));
286 #endif
287 #ifdef WITH_BACKGROUND
288 entries = g_list_prepend (entries, menu_entry_create (_("&Background jobs"), CK_Jobs));
289 #endif
290 entries = g_list_prepend (entries, menu_entry_create (_("Screen lis&t"), CK_ScreenList));
291 entries = g_list_prepend (entries, menu_separator_create ());
292 #ifdef ENABLE_VFS_UNDELFS
293 entries =
294 g_list_prepend (entries,
295 menu_entry_create (_("&Undelete files (ext2fs only)"), CK_Undelete));
296 #endif
297 #ifdef LISTMODE_EDITOR
298 entries = g_list_prepend (entries, menu_entry_create (_("&Listing format edit"), CK_ListMode));
299 #endif
300 #if defined (ENABLE_VFS_UNDELFS) || defined (LISTMODE_EDITOR)
301 entries = g_list_prepend (entries, menu_separator_create ());
302 #endif
303 entries =
304 g_list_prepend (entries,
305 menu_entry_create (_("Edit &extension file"), CK_EditExtensionsFile));
306 entries = g_list_prepend (entries, menu_entry_create (_("Edit &menu file"), CK_EditUserMenu));
307 entries =
308 g_list_prepend (entries,
309 menu_entry_create (_("Edit hi&ghlighting group file"),
310 CK_EditFileHighlightFile));
312 return g_list_reverse (entries);
315 /* --------------------------------------------------------------------------------------------- */
317 static GList *
318 create_options_menu (void)
320 GList *entries = NULL;
322 entries = g_list_prepend (entries, menu_entry_create (_("&Configuration..."), CK_Options));
323 entries = g_list_prepend (entries, menu_entry_create (_("&Layout..."), CK_OptionsLayout));
324 entries = g_list_prepend (entries, menu_entry_create (_("&Panel options..."), CK_OptionsPanel));
325 entries =
326 g_list_prepend (entries, menu_entry_create (_("C&onfirmation..."), CK_OptionsConfirm));
327 entries =
328 g_list_prepend (entries, menu_entry_create (_("&Display bits..."), CK_OptionsDisplayBits));
329 entries = g_list_prepend (entries, menu_entry_create (_("Learn &keys..."), CK_LearnKeys));
330 #ifdef ENABLE_VFS
331 entries = g_list_prepend (entries, menu_entry_create (_("&Virtual FS..."), CK_OptionsVfs));
332 #endif
333 entries = g_list_prepend (entries, menu_separator_create ());
334 entries = g_list_prepend (entries, menu_entry_create (_("&Save setup"), CK_SaveSetup));
336 return g_list_reverse (entries);
339 /* --------------------------------------------------------------------------------------------- */
341 static void
342 init_menu (void)
344 left_menu = create_menu ("", create_panel_menu (), "[Left and Right Menus]");
345 menubar_add_menu (the_menubar, left_menu);
346 menubar_add_menu (the_menubar, create_menu (_("&File"), create_file_menu (), "[File Menu]"));
347 menubar_add_menu (the_menubar,
348 create_menu (_("&Command"), create_command_menu (), "[Command Menu]"));
349 menubar_add_menu (the_menubar,
350 create_menu (_("&Options"), create_options_menu (), "[Options Menu]"));
351 right_menu = create_menu ("", create_panel_menu (), "[Left and Right Menus]");
352 menubar_add_menu (the_menubar, right_menu);
353 update_menu ();
356 /* --------------------------------------------------------------------------------------------- */
358 static void
359 menu_last_selected_cmd (void)
361 the_menubar->is_active = TRUE;
362 the_menubar->is_dropped = (drop_menus != 0);
363 the_menubar->previous_widget = dlg_get_current_widget_id (midnight_dlg);
364 dlg_select_widget (the_menubar);
367 /* --------------------------------------------------------------------------------------------- */
369 static void
370 menu_cmd (void)
372 if (the_menubar->is_active)
373 return;
375 if ((get_current_index () == 0) == (current_panel->active != 0))
376 the_menubar->selected = 0;
377 else
378 the_menubar->selected = g_list_length (the_menubar->menu) - 1;
379 menu_last_selected_cmd ();
382 /* --------------------------------------------------------------------------------------------- */
384 static void
385 sort_cmd (void)
387 WPanel *p;
388 const panel_field_t *sort_order;
390 if (!SELECTED_IS_PANEL)
391 return;
393 p = MENU_PANEL;
394 sort_order = sort_box (&p->sort_info);
395 panel_set_sort_order (p, sort_order);
398 /* --------------------------------------------------------------------------------------------- */
400 static char *
401 midnight_get_shortcut (unsigned long command)
403 const char *ext_map;
404 const char *shortcut = NULL;
406 shortcut = keybind_lookup_keymap_shortcut (main_map, command);
407 if (shortcut != NULL)
408 return g_strdup (shortcut);
410 shortcut = keybind_lookup_keymap_shortcut (panel_map, command);
411 if (shortcut != NULL)
412 return g_strdup (shortcut);
414 ext_map = keybind_lookup_keymap_shortcut (main_map, CK_ExtendedKeyMap);
415 if (ext_map != NULL)
416 shortcut = keybind_lookup_keymap_shortcut (main_x_map, command);
417 if (shortcut != NULL)
418 return g_strdup_printf ("%s %s", ext_map, shortcut);
420 return NULL;
423 /* --------------------------------------------------------------------------------------------- */
425 static char *
426 midnight_get_title (const Dlg_head * h, size_t len)
428 /* TODO: share code with update_xterm_title_path() */
430 const char *path;
431 char host[BUF_TINY];
432 char *p;
433 struct passwd *pw = NULL;
434 char *login = NULL;
435 int res = 0;
437 (void) h;
439 path = strip_home_and_password (current_panel->cwd);
440 res = gethostname (host, sizeof (host));
441 if (res != 0)
442 host[0] = '\0';
443 else
444 host[sizeof (host) - 1] = '\0';
446 pw = getpwuid (getuid ());
447 if (pw != NULL)
448 login = g_strdup_printf ("%s@%s", pw->pw_name, host);
449 else
450 login = g_strdup (host);
452 p = g_strdup_printf ("%s [%s]:%s", _("Panels:"), login, path);
453 path = str_trunc (p, len - 4);
454 g_free (login);
455 g_free (p);
457 return g_strdup (path);
460 /* --------------------------------------------------------------------------------------------- */
462 static void
463 toggle_panels_split (void)
465 panels_layout.horizontal_split = !panels_layout.horizontal_split;
466 layout_change ();
467 do_refresh ();
470 /* --------------------------------------------------------------------------------------------- */
472 #if ENABLE_VFS
474 /* event helper */
475 static gboolean
476 check_panel_timestamp (const WPanel * panel, panel_view_mode_t mode, struct vfs_class *vclass,
477 vfsid id)
479 if (mode == view_listing)
481 vfs_path_t *vpath;
482 vfs_path_element_t *path_element;
484 vpath = vfs_path_from_str (panel->cwd);
485 path_element = vfs_path_get_by_index (vpath, -1);
487 if (path_element->class != vclass)
489 vfs_path_free (vpath);
490 return FALSE;
493 if (vfs_getid (vpath) != id)
495 vfs_path_free (vpath);
496 return FALSE;
498 vfs_path_free (vpath);
500 return TRUE;
503 /* --------------------------------------------------------------------------------------------- */
505 /* event callback */
506 static gboolean
507 check_current_panel_timestamp (const gchar * event_group_name, const gchar * event_name,
508 gpointer init_data, gpointer data)
510 ev_vfs_stamp_create_t *event_data = (ev_vfs_stamp_create_t *) data;
512 (void) event_group_name;
513 (void) event_name;
514 (void) init_data;
516 event_data->ret =
517 check_panel_timestamp (current_panel, get_current_type (), event_data->vclass,
518 event_data->id);
519 return !event_data->ret;
522 /* --------------------------------------------------------------------------------------------- */
524 /* event callback */
525 static gboolean
526 check_other_panel_timestamp (const gchar * event_group_name, const gchar * event_name,
527 gpointer init_data, gpointer data)
529 ev_vfs_stamp_create_t *event_data = (ev_vfs_stamp_create_t *) data;
531 (void) event_group_name;
532 (void) event_name;
533 (void) init_data;
535 event_data->ret =
536 check_panel_timestamp (other_panel, get_other_type (), event_data->vclass, event_data->id);
537 return !event_data->ret;
539 #endif /* ENABLE_VFS */
541 /* --------------------------------------------------------------------------------------------- */
543 /* event callback */
544 static gboolean
545 print_vfs_message (const gchar * event_group_name, const gchar * event_name,
546 gpointer init_data, gpointer data)
548 char str[128];
549 ev_vfs_print_message_t *event_data = (ev_vfs_print_message_t *) data;
551 (void) event_group_name;
552 (void) event_name;
553 (void) init_data;
555 g_vsnprintf (str, sizeof (str), event_data->msg, event_data->ap);
557 if (mc_global.widget.midnight_shutdown)
558 return TRUE;
560 if (!mc_global.message_visible || !the_hint || !the_hint->widget.owner)
562 int col, row;
564 if (!nice_rotating_dash || (ok_to_refresh <= 0))
565 return TRUE;
567 /* Preserve current cursor position */
568 tty_getyx (&row, &col);
570 tty_gotoyx (0, 0);
571 tty_setcolor (NORMAL_COLOR);
572 tty_print_string (str_fit_to_term (str, COLS - 1, J_LEFT));
574 /* Restore cursor position */
575 tty_gotoyx (row, col);
576 mc_refresh ();
577 return TRUE;
580 if (mc_global.message_visible)
581 set_hintbar (str);
583 return TRUE;
586 /* --------------------------------------------------------------------------------------------- */
588 static void
589 create_panels (void)
591 int current_index;
592 int other_index;
593 panel_view_mode_t current_mode, other_mode;
594 char original_dir[BUF_1K] = "\0";
596 if (boot_current_is_left)
598 current_index = 0;
599 other_index = 1;
600 current_mode = startup_left_mode;
601 other_mode = startup_right_mode;
603 else
605 current_index = 1;
606 other_index = 0;
607 current_mode = startup_right_mode;
608 other_mode = startup_left_mode;
610 /* Creates the left panel */
611 if (mc_run_param0 != NULL)
613 vfs_path_t *vpath;
615 if (mc_run_param1 != NULL)
617 /* Ok, user has specified two dirs, save the original one,
618 * since we may not be able to chdir to the proper
619 * second directory later
621 mc_get_current_wd (original_dir, sizeof (original_dir) - 2);
623 vpath = vfs_path_from_str (mc_run_param0);
624 mc_chdir (vpath);
625 vfs_path_free (vpath);
627 set_display_type (current_index, current_mode);
629 /* The other panel */
630 if (mc_run_param1 != NULL)
632 const char *cd_dir = (original_dir != NULL) ? original_dir : mc_run_param1;
633 vfs_path_t *vpath;
635 vpath = vfs_path_from_str (cd_dir);
636 mc_chdir (vpath);
637 vfs_path_free (vpath);
639 set_display_type (other_index, other_mode);
641 if (startup_left_mode == view_listing)
642 current_panel = left_panel;
643 else if (right_panel != NULL)
644 current_panel = right_panel;
645 else
646 current_panel = left_panel;
648 #if ENABLE_VFS
649 mc_event_add (MCEVENT_GROUP_CORE, "vfs_timestamp", check_other_panel_timestamp, NULL, NULL);
650 mc_event_add (MCEVENT_GROUP_CORE, "vfs_timestamp", check_current_panel_timestamp, NULL, NULL);
651 #endif /* ENABLE_VFS */
653 mc_event_add (MCEVENT_GROUP_CORE, "vfs_print_message", print_vfs_message, NULL, NULL);
655 /* Create the nice widgets */
656 cmdline = command_new (0, 0, 0);
657 the_prompt = label_new (0, 0, mc_prompt);
658 the_prompt->transparent = 1;
659 the_bar = buttonbar_new (mc_global.keybar_visible);
661 the_hint = label_new (0, 0, 0);
662 the_hint->transparent = 1;
663 the_hint->auto_adjust_cols = 0;
664 the_hint->widget.cols = COLS;
666 the_menubar = menubar_new (0, 0, COLS, NULL);
669 /* --------------------------------------------------------------------------------------------- */
671 static void
672 put_current_path (void)
674 char *cwd_path;
675 if (!command_prompt)
676 return;
678 cwd_path = remove_encoding_from_path (current_panel->cwd);
679 command_insert (cmdline, cwd_path, FALSE);
681 if (cwd_path[strlen (cwd_path) - 1] != PATH_SEP)
682 command_insert (cmdline, PATH_SEP_STR, FALSE);
683 g_free (cwd_path);
686 /* --------------------------------------------------------------------------------------------- */
688 static void
689 put_other_path (void)
691 char *cwd_path;
693 if (get_other_type () != view_listing)
694 return;
696 if (!command_prompt)
697 return;
699 cwd_path = remove_encoding_from_path (other_panel->cwd);
700 command_insert (cmdline, cwd_path, FALSE);
702 if (cwd_path[strlen (cwd_path) - 1] != PATH_SEP)
703 command_insert (cmdline, PATH_SEP_STR, FALSE);
704 g_free (cwd_path);
707 /* --------------------------------------------------------------------------------------------- */
709 static void
710 put_link (WPanel * panel)
712 if (!command_prompt)
713 return;
714 if (S_ISLNK (selection (panel)->st.st_mode))
716 char buffer[MC_MAXPATHLEN];
717 char *p;
718 int i;
720 p = concat_dir_and_file (panel->cwd, selection (panel)->fname);
721 i = mc_readlink (p, buffer, MC_MAXPATHLEN - 1);
722 g_free (p);
723 if (i > 0)
725 buffer[i] = '\0';
726 command_insert (cmdline, buffer, TRUE);
731 /* --------------------------------------------------------------------------------------------- */
733 static void
734 put_current_link (void)
736 put_link (current_panel);
739 /* --------------------------------------------------------------------------------------------- */
741 static void
742 put_other_link (void)
744 if (get_other_type () == view_listing)
745 put_link (other_panel);
748 /* --------------------------------------------------------------------------------------------- */
750 /** Insert the selected file name into the input line */
751 static void
752 put_prog_name (void)
754 char *tmp;
755 if (!command_prompt)
756 return;
758 if (get_current_type () == view_tree)
760 WTree *tree = (WTree *) get_panel_widget (get_current_index ());
761 tmp = tree_selected_name (tree);
763 else
764 tmp = selection (current_panel)->fname;
766 command_insert (cmdline, tmp, TRUE);
769 /* --------------------------------------------------------------------------------------------- */
771 static void
772 put_tagged (WPanel * panel)
774 int i;
776 if (!command_prompt)
777 return;
778 input_disable_update (cmdline);
779 if (panel->marked)
781 for (i = 0; i < panel->count; i++)
783 if (panel->dir.list[i].f.marked)
784 command_insert (cmdline, panel->dir.list[i].fname, TRUE);
787 else
789 command_insert (cmdline, panel->dir.list[panel->selected].fname, TRUE);
791 input_enable_update (cmdline);
794 /* --------------------------------------------------------------------------------------------- */
796 static void
797 put_current_tagged (void)
799 put_tagged (current_panel);
802 /* --------------------------------------------------------------------------------------------- */
804 static void
805 put_other_tagged (void)
807 if (get_other_type () == view_listing)
808 put_tagged (other_panel);
811 /* --------------------------------------------------------------------------------------------- */
813 static void
814 ctl_x_cmd (void)
816 ctl_x_map_enabled = TRUE;
819 /* --------------------------------------------------------------------------------------------- */
821 static void
822 setup_mc (void)
824 #ifdef HAVE_SLANG
825 #ifdef HAVE_CHARSET
826 tty_display_8bit (TRUE);
827 #else
828 tty_display_8bit (mc_global.full_eight_bits != 0);
829 #endif /* HAVE_CHARSET */
831 #else /* HAVE_SLANG */
833 #ifdef HAVE_CHARSET
834 tty_display_8bit (TRUE);
835 #else
836 tty_display_8bit (mc_global.eight_bit_clean != 0);
837 #endif /* HAVE_CHARSET */
838 #endif /* HAVE_SLANG */
840 #ifdef HAVE_SUBSHELL_SUPPORT
841 if (mc_global.tty.use_subshell)
842 add_select_channel (mc_global.tty.subshell_pty, load_prompt, 0);
843 #endif /* !HAVE_SUBSHELL_SUPPORT */
845 if ((tty_baudrate () < 9600) || mc_global.tty.slow_terminal)
846 verbose = 0;
849 /* --------------------------------------------------------------------------------------------- */
851 static void
852 setup_dummy_mc (void)
854 vfs_path_t *vpath;
855 char d[MC_MAXPATHLEN];
856 int ret;
858 mc_get_current_wd (d, MC_MAXPATHLEN);
859 setup_mc ();
860 vpath = vfs_path_from_str (d);
861 ret = mc_chdir (vpath);
862 vfs_path_free (vpath);
865 /* --------------------------------------------------------------------------------------------- */
867 static void
868 done_mc (void)
870 /* Setup shutdown
872 * We sync the profiles since the hotlist may have changed, while
873 * we only change the setup data if we have the auto save feature set
875 char *curr_dir;
877 save_setup (auto_save_setup, panels_options.auto_save_setup);
879 curr_dir = vfs_get_current_dir ();
880 vfs_stamp_path (curr_dir);
881 g_free (curr_dir);
883 if ((current_panel != NULL) && (get_current_type () == view_listing))
884 vfs_stamp_path (current_panel->cwd);
886 if ((other_panel != NULL) && (get_other_type () == view_listing))
887 vfs_stamp_path (other_panel->cwd);
890 /* --------------------------------------------------------------------------------------------- */
892 static void
893 create_panels_and_run_mc (void)
895 midnight_dlg->get_shortcut = midnight_get_shortcut;
896 midnight_dlg->get_title = midnight_get_title;
898 create_panels ();
900 add_widget (midnight_dlg, the_menubar);
901 init_menu ();
903 add_widget (midnight_dlg, get_panel_widget (0));
904 add_widget (midnight_dlg, get_panel_widget (1));
906 add_widget (midnight_dlg, the_hint);
907 add_widget (midnight_dlg, cmdline);
908 add_widget (midnight_dlg, the_prompt);
910 add_widget (midnight_dlg, the_bar);
911 midnight_set_buttonbar (the_bar);
913 /* Run the Midnight Commander if no file was specified in the command line */
914 run_dlg (midnight_dlg);
917 /* --------------------------------------------------------------------------------------------- */
919 /** result must be free'd (I think this should go in util.c) */
920 static char *
921 prepend_cwd_on_local (const char *filename)
923 char *d;
924 size_t l;
925 vfs_path_t *vpath;
927 vpath = vfs_path_from_str (filename);
928 if (!vfs_file_is_local (vpath) || g_path_is_absolute (filename))
930 vfs_path_free (vpath);
931 return g_strdup (filename);
933 vfs_path_free (vpath);
935 d = g_malloc (MC_MAXPATHLEN + strlen (filename) + 2);
936 mc_get_current_wd (d, MC_MAXPATHLEN);
937 l = strlen (d);
938 d[l++] = PATH_SEP;
939 strcpy (d + l, filename);
940 canonicalize_pathname (d);
941 return d;
944 /* --------------------------------------------------------------------------------------------- */
946 /** Invoke the internal view/edit routine with:
947 * the default processing and forcing the internal viewer/editor
949 static void
950 mc_maybe_editor_or_viewer (void)
952 switch (mc_global.mc_run_mode)
954 #ifdef USE_INTERNAL_EDIT
955 case MC_RUN_EDITOR:
956 edit_file (mc_run_param0, mc_args__edit_start_line);
957 break;
958 #endif /* USE_INTERNAL_EDIT */
959 case MC_RUN_VIEWER:
961 char *path;
962 path = prepend_cwd_on_local (mc_run_param0);
963 view_file (path, 0, 1);
964 g_free (path);
965 break;
967 #ifdef USE_DIFF_VIEW
968 case MC_RUN_DIFFVIEWER:
969 diff_view (mc_run_param0, mc_run_param1, mc_run_param0, mc_run_param1);
970 break;
971 #endif /* USE_DIFF_VIEW */
972 default:
973 break;
977 /* --------------------------------------------------------------------------------------------- */
979 static gboolean
980 quit_cmd_internal (int quiet)
982 int q = quit;
983 size_t n;
985 n = dialog_switch_num () - 1;
986 if (n != 0)
988 char msg[BUF_MEDIUM];
990 g_snprintf (msg, sizeof (msg),
991 ngettext ("You have %zd opened screen. Quit anyway?",
992 "You have %zd opened screens. Quit anyway?", n), n);
994 if (query_dialog (_("The Midnight Commander"), msg, D_NORMAL, 2, _("&Yes"), _("&No")) != 0)
995 return FALSE;
996 q = 1;
998 else if (quiet || !confirm_exit)
999 q = 1;
1000 else if (query_dialog (_("The Midnight Commander"),
1001 _("Do you really want to quit the Midnight Commander?"),
1002 D_NORMAL, 2, _("&Yes"), _("&No")) == 0)
1003 q = 1;
1005 if (q != 0)
1007 #ifdef HAVE_SUBSHELL_SUPPORT
1008 if (!mc_global.tty.use_subshell)
1009 stop_dialogs ();
1010 else if ((q = exit_subshell ()))
1011 #endif
1012 stop_dialogs ();
1015 if (q != 0)
1016 quit |= 1;
1017 return (quit != 0);
1020 /* --------------------------------------------------------------------------------------------- */
1022 static gboolean
1023 quit_cmd (void)
1025 return quit_cmd_internal (0);
1028 /* --------------------------------------------------------------------------------------------- */
1030 static void
1031 toggle_show_hidden (void)
1033 panels_options.show_dot_files = !panels_options.show_dot_files;
1034 update_panels (UP_RELOAD, UP_KEEPSEL);
1037 /* --------------------------------------------------------------------------------------------- */
1040 * Repaint the contents of the panels without frames. To schedule panel
1041 * for repainting, set panel->dirty to 1. There are many reasons why
1042 * the panels need to be repainted, and this is a costly operation, so
1043 * it's done once per event.
1046 static void
1047 update_dirty_panels (void)
1049 if (get_current_type () == view_listing && current_panel->dirty)
1050 send_message ((Widget *) current_panel, WIDGET_DRAW, 0);
1052 if (get_other_type () == view_listing && other_panel->dirty)
1053 send_message ((Widget *) other_panel, WIDGET_DRAW, 0);
1056 /* --------------------------------------------------------------------------------------------- */
1058 static cb_ret_t
1059 midnight_execute_cmd (Widget * sender, unsigned long command)
1061 cb_ret_t res = MSG_HANDLED;
1063 (void) sender;
1065 /* stop quick search before executing any command */
1066 send_message ((Widget *) current_panel, WIDGET_COMMAND, CK_SearchStop);
1068 switch (command)
1070 case CK_HotListAdd:
1071 add2hotlist_cmd ();
1072 break;
1073 case CK_PanelListingChange:
1074 change_listing_cmd ();
1075 break;
1076 case CK_ChangeMode:
1077 chmod_cmd ();
1078 break;
1079 case CK_ChangeOwn:
1080 chown_cmd ();
1081 break;
1082 case CK_ChangeOwnAdvanced:
1083 chown_advanced_cmd ();
1084 break;
1085 case CK_CompareDirs:
1086 compare_dirs_cmd ();
1087 break;
1088 case CK_Options:
1089 configure_box ();
1090 break;
1091 #ifdef ENABLE_VFS
1092 case CK_OptionsVfs:
1093 configure_vfs ();
1094 break;
1095 #endif
1096 case CK_OptionsConfirm:
1097 confirm_box ();
1098 break;
1099 case CK_Copy:
1100 copy_cmd ();
1101 break;
1102 case CK_PutCurrentPath:
1103 put_current_path ();
1104 break;
1105 case CK_PutCurrentLink:
1106 put_current_link ();
1107 break;
1108 case CK_PutCurrentTagged:
1109 put_current_tagged ();
1110 break;
1111 case CK_PutOtherPath:
1112 put_other_path ();
1113 break;
1114 case CK_PutOtherLink:
1115 put_other_link ();
1116 break;
1117 case CK_PutOtherTagged:
1118 put_other_tagged ();
1119 break;
1120 case CK_Delete:
1121 delete_cmd ();
1122 break;
1123 case CK_ScreenList:
1124 dialog_switch_list ();
1125 break;
1126 #ifdef USE_DIFF_VIEW
1127 case CK_CompareFiles:
1128 diff_view_cmd ();
1129 break;
1130 #endif
1131 case CK_OptionsDisplayBits:
1132 display_bits_box ();
1133 break;
1134 case CK_Edit:
1135 edit_cmd ();
1136 break;
1137 #ifdef USE_INTERNAL_EDIT
1138 case CK_EditForceInternal:
1139 edit_cmd_force_internal ();
1140 break;
1141 #endif
1142 case CK_EditExtensionsFile:
1143 ext_cmd ();
1144 break;
1145 case CK_EditFileHighlightFile:
1146 edit_fhl_cmd ();
1147 break;
1148 case CK_EditUserMenu:
1149 edit_mc_menu_cmd ();
1150 break;
1151 case CK_LinkSymbolicEdit:
1152 edit_symlink_cmd ();
1153 break;
1154 case CK_ExternalPanelize:
1155 external_panelize ();
1156 break;
1157 case CK_Filter:
1158 filter_cmd ();
1159 break;
1160 case CK_ViewFiltered:
1161 view_filtered_cmd ();
1162 break;
1163 case CK_Find:
1164 find_cmd ();
1165 break;
1166 #ifdef ENABLE_VFS_FISH
1167 case CK_ConnectFish:
1168 fishlink_cmd ();
1169 break;
1170 #endif
1171 #ifdef ENABLE_VFS_FTP
1172 case CK_ConnectFtp:
1173 ftplink_cmd ();
1174 break;
1175 #endif
1176 #ifdef ENABLE_VFS_SMB
1177 case CK_ConnectSmb:
1178 smblink_cmd ();
1179 break;
1180 #endif /* ENABLE_VFS_SMB */
1181 case CK_Panelize:
1182 cd_panelize_cmd ();
1183 break;
1184 case CK_Help:
1185 help_cmd ();
1186 break;
1187 case CK_History:
1188 /* show the history of command line widget */
1189 send_message (&cmdline->widget, WIDGET_COMMAND, CK_History);
1190 break;
1191 case CK_PanelInfo:
1192 if (sender == (Widget *) the_menubar)
1193 info_cmd (); /* menu */
1194 else
1195 info_cmd_no_menu (); /* shortcut or buttonbar */
1196 break;
1197 #ifdef WITH_BACKGROUND
1198 case CK_Jobs:
1199 jobs_cmd ();
1200 break;
1201 #endif
1202 case CK_OptionsLayout:
1203 layout_box ();
1204 break;
1205 case CK_LearnKeys:
1206 learn_keys ();
1207 break;
1208 case CK_Link:
1209 link_cmd (LINK_HARDLINK);
1210 break;
1211 case CK_PanelListing:
1212 listing_cmd ();
1213 break;
1214 #ifdef LISTMODE_EDITOR
1215 case CK_ListMode:
1216 listmode_cmd ();
1217 break;
1218 #endif
1219 case CK_Menu:
1220 menu_cmd ();
1221 break;
1222 case CK_MenuLastSelected:
1223 menu_last_selected_cmd ();
1224 break;
1225 case CK_MakeDir:
1226 mkdir_cmd ();
1227 break;
1228 case CK_OptionsPanel:
1229 panel_options_box ();
1230 break;
1231 #ifdef HAVE_CHARSET
1232 case CK_SelectCodepage:
1233 encoding_cmd ();
1234 break;
1235 #endif
1236 case CK_CdQuick:
1237 quick_cd_cmd ();
1238 break;
1239 case CK_HotList:
1240 hotlist_cmd ();
1241 break;
1242 case CK_PanelQuickView:
1243 if (sender == (Widget *) the_menubar)
1244 quick_view_cmd (); /* menu */
1245 else
1246 quick_cmd_no_menu (); /* shortcut or buttonabr */
1247 break;
1248 case CK_QuitQuiet:
1249 quiet_quit_cmd ();
1250 break;
1251 case CK_Quit:
1252 quit_cmd ();
1253 break;
1254 case CK_LinkSymbolicRelative:
1255 link_cmd (LINK_SYMLINK_RELATIVE);
1256 break;
1257 case CK_Move:
1258 rename_cmd ();
1259 break;
1260 case CK_Reread:
1261 reread_cmd ();
1262 break;
1263 #ifdef ENABLE_VFS
1264 case CK_VfsList:
1265 vfs_list ();
1266 break;
1267 #endif
1268 case CK_SelectInvert:
1269 select_invert_cmd ();
1270 break;
1271 case CK_SaveSetup:
1272 save_setup_cmd ();
1273 break;
1274 case CK_Select:
1275 select_cmd ();
1276 break;
1277 case CK_Shell:
1278 view_other_cmd ();
1279 break;
1280 case CK_DirSize:
1281 smart_dirsize_cmd ();
1282 break;
1283 case CK_Sort:
1284 sort_cmd ();
1285 break;
1286 case CK_ExtendedKeyMap:
1287 ctl_x_cmd ();
1288 break;
1289 case CK_Suspend:
1290 mc_event_raise (MCEVENT_GROUP_CORE, "suspend", NULL);
1291 break;
1292 case CK_Swap:
1293 swap_cmd ();
1294 break;
1295 case CK_LinkSymbolic:
1296 link_cmd (LINK_SYMLINK_ABSOLUTE);
1297 break;
1298 case CK_PanelListingSwitch:
1299 toggle_listing_cmd ();
1300 break;
1301 case CK_ShowHidden:
1302 toggle_show_hidden ();
1303 break;
1304 case CK_SplitVertHoriz:
1305 toggle_panels_split ();
1306 break;
1307 case CK_SplitEqual:
1308 panels_split_equal ();
1309 break;
1310 case CK_SplitMore:
1311 panels_split_more ();
1312 break;
1313 case CK_SplitLess:
1314 panels_split_less ();
1315 break;
1316 case CK_PanelTree:
1317 panel_tree_cmd ();
1318 break;
1319 case CK_Tree:
1320 treebox_cmd ();
1321 break;
1322 #ifdef ENABLE_VFS_UNDELFS
1323 case CK_Undelete:
1324 undelete_cmd ();
1325 break;
1326 #endif
1327 case CK_Unselect:
1328 unselect_cmd ();
1329 break;
1330 case CK_UserMenu:
1331 user_file_menu_cmd ();
1332 break;
1333 case CK_View:
1334 view_cmd ();
1335 break;
1336 case CK_ViewFile:
1337 view_file_cmd ();
1338 break;
1339 case CK_Cancel:
1340 /* don't close panels due to SIGINT */
1341 break;
1342 default:
1343 res = MSG_NOT_HANDLED;
1346 return res;
1349 /* --------------------------------------------------------------------------------------------- */
1351 static cb_ret_t
1352 midnight_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
1354 unsigned long command;
1356 switch (msg)
1358 case DLG_INIT:
1359 panel_init ();
1360 setup_panels ();
1361 return MSG_HANDLED;
1363 case DLG_DRAW:
1364 load_hint (1);
1365 /* We handle the special case of the output lines */
1366 if (mc_global.tty.console_flag != '\0' && output_lines)
1367 show_console_contents (output_start_y,
1368 LINES - output_lines - mc_global.keybar_visible -
1369 1, LINES - mc_global.keybar_visible - 1);
1370 return MSG_HANDLED;
1372 case DLG_RESIZE:
1373 setup_panels ();
1374 menubar_arrange (the_menubar);
1375 return MSG_HANDLED;
1377 case DLG_IDLE:
1378 /* We only need the first idle event to show user menu after start */
1379 set_idle_proc (h, 0);
1381 if (boot_current_is_left)
1382 dlg_select_widget (get_panel_widget (0));
1383 else
1384 dlg_select_widget (get_panel_widget (1));
1386 if (auto_menu)
1387 midnight_execute_cmd (NULL, CK_UserMenu);
1388 return MSG_HANDLED;
1390 case DLG_KEY:
1391 if (ctl_x_map_enabled)
1393 ctl_x_map_enabled = FALSE;
1394 command = keybind_lookup_keymap_command (main_x_map, parm);
1395 if (command != CK_IgnoreKey)
1396 return midnight_execute_cmd (NULL, command);
1399 /* FIXME: should handle all menu shortcuts before this point */
1400 if (the_menubar->is_active)
1401 return MSG_NOT_HANDLED;
1403 if (parm == '\t')
1404 input_free_completions (cmdline);
1406 if (parm == '\n')
1408 size_t i;
1410 for (i = 0; cmdline->buffer[i] != '\0' &&
1411 (cmdline->buffer[i] == ' ' || cmdline->buffer[i] == '\t'); i++)
1414 if (cmdline->buffer[i] != '\0')
1416 send_message ((Widget *) cmdline, WIDGET_KEY, parm);
1417 return MSG_HANDLED;
1420 input_insert (cmdline, "", FALSE);
1421 cmdline->point = 0;
1424 /* Ctrl-Enter and Alt-Enter */
1425 if (((parm & ~(KEY_M_CTRL | KEY_M_ALT)) == '\n') && (parm & (KEY_M_CTRL | KEY_M_ALT)))
1427 put_prog_name ();
1428 return MSG_HANDLED;
1431 /* Ctrl-Shift-Enter */
1432 if (parm == (KEY_M_CTRL | KEY_M_SHIFT | '\n'))
1434 put_current_path ();
1435 put_prog_name ();
1436 return MSG_HANDLED;
1439 if ((!mc_global.tty.alternate_plus_minus
1440 || !(mc_global.tty.console_flag != '\0' || mc_global.tty.xterm_flag)) && !quote
1441 && !current_panel->searching)
1443 if (!only_leading_plus_minus)
1445 /* Special treatement, since the input line will eat them */
1446 if (parm == '+')
1448 select_cmd ();
1449 return MSG_HANDLED;
1452 if (parm == '\\' || parm == '-')
1454 unselect_cmd ();
1455 return MSG_HANDLED;
1458 if (parm == '*')
1460 select_invert_cmd ();
1461 return MSG_HANDLED;
1464 else if (!command_prompt || !cmdline->buffer[0])
1466 /* Special treatement '+', '-', '\', '*' only when this is
1467 * first char on input line
1470 if (parm == '+')
1472 select_cmd ();
1473 return MSG_HANDLED;
1476 if (parm == '\\' || parm == '-')
1478 unselect_cmd ();
1479 return MSG_HANDLED;
1482 if (parm == '*')
1484 select_invert_cmd ();
1485 return MSG_HANDLED;
1489 return MSG_NOT_HANDLED;
1491 case DLG_HOTKEY_HANDLED:
1492 if ((get_current_type () == view_listing) && current_panel->searching)
1494 current_panel->dirty = 1; /* FIXME: unneeded? */
1495 send_message ((Widget *) current_panel, WIDGET_COMMAND, CK_SearchStop);
1497 return MSG_HANDLED;
1499 case DLG_UNHANDLED_KEY:
1500 if (command_prompt)
1502 cb_ret_t v;
1504 v = send_message ((Widget *) cmdline, WIDGET_KEY, parm);
1505 if (v == MSG_HANDLED)
1506 return MSG_HANDLED;
1509 if (ctl_x_map_enabled)
1511 ctl_x_map_enabled = FALSE;
1512 command = keybind_lookup_keymap_command (main_x_map, parm);
1514 else
1515 command = keybind_lookup_keymap_command (main_map, parm);
1517 return (command == CK_IgnoreKey) ? MSG_NOT_HANDLED : midnight_execute_cmd (NULL, command);
1519 case DLG_POST_KEY:
1520 if (!the_menubar->is_active)
1521 update_dirty_panels ();
1522 return MSG_HANDLED;
1524 case DLG_ACTION:
1525 /* shortcut */
1526 if (sender == NULL)
1527 return midnight_execute_cmd (NULL, parm);
1528 /* message from menu */
1529 if (sender == (Widget *) the_menubar)
1530 return midnight_execute_cmd (sender, parm);
1531 /* message from buttonbar */
1532 if (sender == (Widget *) the_bar)
1534 if (data != NULL)
1535 return send_message ((Widget *) data, WIDGET_COMMAND, parm);
1536 return midnight_execute_cmd (sender, parm);
1538 return MSG_NOT_HANDLED;
1540 case DLG_END:
1541 panel_deinit ();
1542 return MSG_HANDLED;
1544 default:
1545 return default_dlg_callback (h, sender, msg, parm, data);
1549 /* --------------------------------------------------------------------------------------------- */
1550 /*** public functions ****************************************************************************/
1551 /* --------------------------------------------------------------------------------------------- */
1553 void
1554 update_menu (void)
1556 menu_set_name (left_menu, panels_layout.horizontal_split ? _("&Above") : _("&Left"));
1557 menu_set_name (right_menu, panels_layout.horizontal_split ? _("&Below") : _("&Right"));
1558 menubar_arrange (the_menubar);
1559 menubar_set_visible (the_menubar, menubar_visible);
1562 void
1563 midnight_set_buttonbar (WButtonBar * b)
1565 buttonbar_set_label (b, 1, Q_ ("ButtonBar|Help"), main_map, NULL);
1566 buttonbar_set_label (b, 2, Q_ ("ButtonBar|Menu"), main_map, NULL);
1567 buttonbar_set_label (b, 3, Q_ ("ButtonBar|View"), main_map, NULL);
1568 buttonbar_set_label (b, 4, Q_ ("ButtonBar|Edit"), main_map, NULL);
1569 buttonbar_set_label (b, 5, Q_ ("ButtonBar|Copy"), main_map, NULL);
1570 buttonbar_set_label (b, 6, Q_ ("ButtonBar|RenMov"), main_map, NULL);
1571 buttonbar_set_label (b, 7, Q_ ("ButtonBar|Mkdir"), main_map, NULL);
1572 buttonbar_set_label (b, 8, Q_ ("ButtonBar|Delete"), main_map, NULL);
1573 buttonbar_set_label (b, 9, Q_ ("ButtonBar|PullDn"), main_map, NULL);
1574 buttonbar_set_label (b, 10, Q_ ("ButtonBar|Quit"), main_map, NULL);
1577 /* --------------------------------------------------------------------------------------------- */
1579 * Load new hint and display it.
1580 * IF force is not 0, ignore the timeout.
1583 void
1584 load_hint (gboolean force)
1586 char *hint;
1588 if (the_hint->widget.owner == NULL)
1589 return;
1591 if (!mc_global.message_visible)
1593 label_set_text (the_hint, NULL);
1594 return;
1597 hint = get_random_hint (force);
1599 if (hint != NULL)
1601 if (*hint != '\0')
1602 set_hintbar (hint);
1603 g_free (hint);
1605 else
1607 char text[BUF_SMALL];
1609 g_snprintf (text, sizeof (text), _("GNU Midnight Commander %s\n"), VERSION);
1610 set_hintbar (text);
1614 /* --------------------------------------------------------------------------------------------- */
1616 void
1617 change_panel (void)
1619 input_free_completions (cmdline);
1620 dlg_one_down (midnight_dlg);
1623 /* --------------------------------------------------------------------------------------------- */
1625 /** Save current stat of directories to avoid reloading the panels
1626 * when no modifications have taken place
1628 void
1629 save_cwds_stat (void)
1631 if (panels_options.fast_reload)
1633 vfs_path_t *vpath;
1635 vpath = vfs_path_from_str (current_panel->cwd);
1636 mc_stat (vpath, &(current_panel->dir_stat));
1637 vfs_path_free (vpath);
1638 if (get_other_type () == view_listing)
1640 vpath = vfs_path_from_str (other_panel->cwd);
1641 mc_stat (vpath, &(other_panel->dir_stat));
1642 vfs_path_free (vpath);
1647 /* --------------------------------------------------------------------------------------------- */
1649 gboolean
1650 quiet_quit_cmd (void)
1652 print_last_revert = TRUE;
1653 return quit_cmd_internal (1);
1656 /* --------------------------------------------------------------------------------------------- */
1658 /** Run the main dialog that occupies the whole screen */
1659 void
1660 do_nc (void)
1662 dlg_colors_t midnight_colors;
1664 midnight_colors[DLG_COLOR_NORMAL] = mc_skin_color_get ("dialog", "_default_");
1665 midnight_colors[DLG_COLOR_FOCUS] = mc_skin_color_get ("dialog", "focus");
1666 midnight_colors[DLG_COLOR_HOT_NORMAL] = mc_skin_color_get ("dialog", "hotnormal");
1667 midnight_colors[DLG_COLOR_HOT_FOCUS] = mc_skin_color_get ("dialog", "hotfocus");
1668 midnight_colors[DLG_COLOR_TITLE] = mc_skin_color_get ("dialog", "title");
1670 #ifdef USE_INTERNAL_EDIT
1671 edit_stack_init ();
1672 #endif
1674 midnight_dlg = create_dlg (FALSE, 0, 0, LINES, COLS, midnight_colors, midnight_callback,
1675 "[main]", NULL, DLG_WANT_IDLE);
1677 if (mc_global.mc_run_mode == MC_RUN_FULL)
1678 setup_mc ();
1679 else
1680 setup_dummy_mc ();
1682 /* Check if we were invoked as an editor or file viewer */
1683 if (mc_global.mc_run_mode != MC_RUN_FULL)
1684 mc_maybe_editor_or_viewer ();
1685 else
1687 create_panels_and_run_mc ();
1689 /* destroy_dlg destroys even current_panel->cwd, so we have to save a copy :) */
1690 if (mc_args__last_wd_file != NULL && vfs_current_is_local ())
1691 last_wd_string = g_strdup (current_panel->cwd);
1693 /* don't handle VFS timestamps for dirs opened in panels */
1694 mc_event_destroy (MCEVENT_GROUP_CORE, "vfs_timestamp");
1696 clean_dir (&panelized_panel.list, panelized_panel.count);
1699 /* Program end */
1700 mc_global.widget.midnight_shutdown = TRUE;
1701 dialog_switch_shutdown ();
1702 done_mc ();
1703 destroy_dlg (midnight_dlg);
1704 current_panel = NULL;
1706 #ifdef USE_INTERNAL_EDIT
1707 edit_stack_free ();
1708 #endif
1710 if ((quit & SUBSHELL_EXIT) == 0)
1711 clr_scr ();
1714 /* --------------------------------------------------------------------------------------------- */