Reorder VFS parser to work with VFS parameters:
[midnight-commander.git] / src / filemanager / midnight.c
blobf547683bc17fe32ed458c1925f6ccec2c3fa3c49
1 /* Main dialog (file panels) of the Midnight Commander
2 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003, 2004, 2005, 2006, 2007, 2009, 2010 Free Software Foundation, Inc.
5 Written by: 1994, 1995, 1996, 1997 Miguel de Icaza
6 1994, 1995 Janne Kukonlehto
7 1997 Norbert Warmuth
8 2009, 2010 Andrew Borodin
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
24 /** \file main.c
25 * \brief Source: main dialog (file panels) of the Midnight Commander
28 #include <config.h>
30 #include <ctype.h>
31 #include <errno.h>
32 #include <locale.h>
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <string.h>
36 #include <fcntl.h>
37 #include <sys/types.h>
38 #include <sys/stat.h>
39 #include <sys/wait.h>
40 #include <unistd.h>
41 #include <pwd.h> /* for username in xterm title */
43 #include "lib/global.h"
45 #include "lib/tty/tty.h"
46 #include "lib/tty/key.h" /* For init_key() */
47 #include "lib/tty/mouse.h"
48 #include "lib/tty/win.h" /* xterm_flag */
49 #include "lib/skin.h"
50 #include "lib/util.h"
52 #include "lib/vfs/vfs.h"
54 #include "src/args.h"
55 #include "src/subshell.h"
56 #include "src/setup.h" /* variables */
57 #include "src/learn.h" /* learn_keys() */
58 #include "src/keybind-defaults.h"
59 #include "lib/keybind.h"
60 #include "lib/event.h"
62 #include "option.h" /* configure_box() */
63 #include "tree.h"
64 #include "boxes.h" /* sort_box(), tree_box() */
65 #include "layout.h"
66 #include "cmd.h" /* commands */
67 #include "hotlist.h"
68 #include "panelize.h"
69 #include "command.h" /* cmdline */
71 #include "chmod.h"
72 #include "chown.h"
73 #include "achown.h"
75 #ifdef USE_INTERNAL_EDIT
76 #include "src/editor/edit.h"
77 #endif
79 #ifdef USE_DIFF_VIEW
80 #include "src/diffviewer/ydiff.h"
81 #endif
83 #include "src/consaver/cons.saver.h" /* show_console_contents */
85 #include "midnight.h"
87 /* TODO: merge content of layout.c here */
88 extern int ok_to_refresh;
90 /*** global variables ****************************************************************************/
92 /* When the modes are active, left_panel, right_panel and tree_panel */
93 /* point to a proper data structure. You should check with the functions */
94 /* get_current_type and get_other_type the types of the panels before using */
95 /* this pointer variables */
97 /* The structures for the panels */
98 WPanel *left_panel = NULL;
99 WPanel *right_panel = NULL;
100 /* Pointer to the selected and unselected panel */
101 WPanel *current_panel = NULL;
103 /* The Menubar */
104 WMenuBar *the_menubar = NULL;
105 /* The widget where we draw the prompt */
106 WLabel *the_prompt;
107 /* The hint bar */
108 WLabel *the_hint;
109 /* The button bar */
110 WButtonBar *the_bar;
112 /*** file scope macro definitions ****************************************************************/
114 #ifdef HAVE_CHARSET
116 * Don't restrict the output on the screen manager level,
117 * the translation tables take care of it.
119 #endif /* !HAVE_CHARSET */
121 /*** file scope type declarations ****************************************************************/
123 /*** file scope variables ************************************************************************/
125 static Menu *left_menu, *right_menu;
127 static gboolean ctl_x_map_enabled = FALSE;
129 /*** file scope functions ************************************************************************/
131 /** Stop MC main dialog and the current dialog if it exists.
132 * Needed to provide fast exit from MC viewer or editor on shell exit */
133 static void
134 stop_dialogs (void)
136 midnight_dlg->state = DLG_CLOSED;
138 if ((top_dlg != NULL) && (top_dlg->data != NULL))
139 ((Dlg_head *) top_dlg->data)->state = DLG_CLOSED;
142 /* --------------------------------------------------------------------------------------------- */
144 static void
145 treebox_cmd (void)
147 char *sel_dir;
149 sel_dir = tree_box (selection (current_panel)->fname);
150 if (sel_dir)
152 do_cd (sel_dir, cd_exact);
153 g_free (sel_dir);
157 /* --------------------------------------------------------------------------------------------- */
159 #ifdef LISTMODE_EDITOR
160 static void
161 listmode_cmd (void)
163 char *newmode;
165 if (get_current_type () != view_listing)
166 return;
168 newmode = listmode_edit (current_panel->user_format);
169 if (!newmode)
170 return;
172 g_free (current_panel->user_format);
173 current_panel->list_type = list_user;
174 current_panel->user_format = newmode;
175 set_panel_formats (current_panel);
177 do_refresh ();
179 #endif /* LISTMODE_EDITOR */
181 /* --------------------------------------------------------------------------------------------- */
183 static GList *
184 create_panel_menu (void)
186 GList *entries = NULL;
188 entries = g_list_append (entries, menu_entry_create (_("File listin&g"), CK_PanelListing));
189 entries = g_list_append (entries, menu_entry_create (_("&Quick view"), CK_PanelQuickView));
190 entries = g_list_append (entries, menu_entry_create (_("&Info"), CK_PanelInfo));
191 entries = g_list_append (entries, menu_entry_create (_("&Tree"), CK_PanelTree));
192 entries = g_list_append (entries, menu_separator_create ());
193 entries =
194 g_list_append (entries, menu_entry_create (_("&Listing mode..."), CK_PanelListingChange));
195 entries = g_list_append (entries, menu_entry_create (_("&Sort order..."), CK_Sort));
196 entries = g_list_append (entries, menu_entry_create (_("&Filter..."), CK_Filter));
197 #ifdef HAVE_CHARSET
198 entries = g_list_append (entries, menu_entry_create (_("&Encoding..."), CK_SelectCodepage));
199 #endif
200 #ifdef ENABLE_VFS_NET
201 entries = g_list_append (entries, menu_separator_create ());
202 #ifdef ENABLE_VFS_FTP
203 entries = g_list_append (entries, menu_entry_create (_("FT&P link..."), CK_ConnectFtp));
204 #endif
205 #ifdef ENABLE_VFS_FISH
206 entries = g_list_append (entries, menu_entry_create (_("S&hell link..."), CK_ConnectFish));
207 #endif
208 #ifdef ENABLE_VFS_SMB
209 entries = g_list_append (entries, menu_entry_create (_("SM&B link..."), CK_ConnectSmb));
210 #endif
211 #endif /* ENABLE_VFS_NET */
212 entries = g_list_append (entries, menu_separator_create ());
213 entries = g_list_append (entries, menu_entry_create (_("&Rescan"), CK_Reread));
215 return entries;
218 /* --------------------------------------------------------------------------------------------- */
220 static GList *
221 create_file_menu (void)
223 GList *entries = NULL;
225 entries = g_list_append (entries, menu_entry_create (_("&View"), CK_View));
226 entries = g_list_append (entries, menu_entry_create (_("Vie&w file..."), CK_ViewFile));
227 entries = g_list_append (entries, menu_entry_create (_("&Filtered view"), CK_ViewFiltered));
228 entries = g_list_append (entries, menu_entry_create (_("&Edit"), CK_Edit));
229 entries = g_list_append (entries, menu_entry_create (_("&Copy"), CK_Copy));
230 entries = g_list_append (entries, menu_entry_create (_("C&hmod"), CK_ChangeMode));
231 entries = g_list_append (entries, menu_entry_create (_("&Link"), CK_Link));
232 entries = g_list_append (entries, menu_entry_create (_("&Symlink"), CK_LinkSymbolic));
233 entries =
234 g_list_append (entries,
235 menu_entry_create (_("Relative symlin&k"), CK_LinkSymbolicRelative));
236 entries = g_list_append (entries, menu_entry_create (_("Edit s&ymlink"), CK_LinkSymbolicEdit));
237 entries = g_list_append (entries, menu_entry_create (_("Ch&own"), CK_ChangeOwn));
238 entries =
239 g_list_append (entries, menu_entry_create (_("&Advanced chown"), CK_ChangeOwnAdvanced));
240 entries = g_list_append (entries, menu_entry_create (_("&Rename/Move"), CK_Move));
241 entries = g_list_append (entries, menu_entry_create (_("&Mkdir"), CK_MakeDir));
242 entries = g_list_append (entries, menu_entry_create (_("&Delete"), CK_Delete));
243 entries = g_list_append (entries, menu_entry_create (_("&Quick cd"), CK_CdQuick));
244 entries = g_list_append (entries, menu_separator_create ());
245 entries = g_list_append (entries, menu_entry_create (_("Select &group"), CK_Select));
246 entries = g_list_append (entries, menu_entry_create (_("U&nselect group"), CK_Unselect));
247 entries = g_list_append (entries, menu_entry_create (_("&Invert selection"), CK_SelectInvert));
248 entries = g_list_append (entries, menu_separator_create ());
249 entries = g_list_append (entries, menu_entry_create (_("E&xit"), CK_Quit));
251 return entries;
254 /* --------------------------------------------------------------------------------------------- */
256 static GList *
257 create_command_menu (void)
259 /* I know, I'm lazy, but the tree widget when it's not running
260 * as a panel still has some problems, I have not yet finished
261 * the WTree widget port, sorry.
263 GList *entries = NULL;
265 entries = g_list_append (entries, menu_entry_create (_("&User menu"), CK_UserMenu));
266 entries = g_list_append (entries, menu_entry_create (_("&Directory tree"), CK_Tree));
267 entries = g_list_append (entries, menu_entry_create (_("&Find file"), CK_Find));
268 entries = g_list_append (entries, menu_entry_create (_("S&wap panels"), CK_Swap));
269 entries = g_list_append (entries, menu_entry_create (_("Switch &panels on/off"), CK_Shell));
270 entries =
271 g_list_append (entries, menu_entry_create (_("&Compare directories"), CK_CompareDirs));
272 #ifdef USE_DIFF_VIEW
273 entries = g_list_append (entries, menu_entry_create (_("C&ompare files"), CK_CompareFiles));
274 #endif
275 entries =
276 g_list_append (entries, menu_entry_create (_("E&xternal panelize"), CK_ExternalPanelize));
277 entries = g_list_append (entries, menu_entry_create (_("Show directory s&izes"), CK_DirSize));
278 entries = g_list_append (entries, menu_separator_create ());
279 entries = g_list_append (entries, menu_entry_create (_("Command &history"), CK_History));
280 entries = g_list_append (entries, menu_entry_create (_("Di&rectory hotlist"), CK_HotList));
281 #ifdef ENABLE_VFS
282 entries = g_list_append (entries, menu_entry_create (_("&Active VFS list"), CK_VfsList));
283 #endif
284 #ifdef WITH_BACKGROUND
285 entries = g_list_append (entries, menu_entry_create (_("&Background jobs"), CK_Jobs));
286 #endif
287 entries = g_list_append (entries, menu_entry_create (_("Screen lis&t"), CK_ScreenList));
288 entries = g_list_append (entries, menu_separator_create ());
289 #ifdef ENABLE_VFS_UNDELFS
290 entries =
291 g_list_append (entries,
292 menu_entry_create (_("&Undelete files (ext2fs only)"), CK_Undelete));
293 #endif
294 #ifdef LISTMODE_EDITOR
295 entries = g_list_append (entries, menu_entry_create (_("&Listing format edit"), CK_ListMode));
296 #endif
297 #if defined (ENABLE_VFS_UNDELFS) || defined (LISTMODE_EDITOR)
298 entries = g_list_append (entries, menu_separator_create ());
299 #endif
300 entries =
301 g_list_append (entries,
302 menu_entry_create (_("Edit &extension file"), CK_EditExtensionsFile));
303 entries = g_list_append (entries, menu_entry_create (_("Edit &menu file"), CK_EditUserMenu));
304 entries =
305 g_list_append (entries,
306 menu_entry_create (_("Edit hi&ghlighting group file"),
307 CK_EditFileHighlightFile));
309 return entries;
312 /* --------------------------------------------------------------------------------------------- */
314 static GList *
315 create_options_menu (void)
317 GList *entries = NULL;
319 entries = g_list_append (entries, menu_entry_create (_("&Configuration..."), CK_Options));
320 entries = g_list_append (entries, menu_entry_create (_("&Layout..."), CK_OptionsLayout));
321 entries = g_list_append (entries, menu_entry_create (_("&Panel options..."), CK_OptionsPanel));
322 entries = g_list_append (entries, menu_entry_create (_("C&onfirmation..."), CK_OptionsConfirm));
323 entries =
324 g_list_append (entries, menu_entry_create (_("&Display bits..."), CK_OptionsDisplayBits));
325 entries = g_list_append (entries, menu_entry_create (_("Learn &keys..."), CK_LearnKeys));
326 #ifdef ENABLE_VFS
327 entries = g_list_append (entries, menu_entry_create (_("&Virtual FS..."), CK_OptionsVfs));
328 #endif
329 entries = g_list_append (entries, menu_separator_create ());
330 entries = g_list_append (entries, menu_entry_create (_("&Save setup"), CK_SaveSetup));
332 return entries;
335 /* --------------------------------------------------------------------------------------------- */
337 static void
338 init_menu (void)
340 left_menu = create_menu ("", create_panel_menu (), "[Left and Right Menus]");
341 menubar_add_menu (the_menubar, left_menu);
342 menubar_add_menu (the_menubar, create_menu (_("&File"), create_file_menu (), "[File Menu]"));
343 menubar_add_menu (the_menubar,
344 create_menu (_("&Command"), create_command_menu (), "[Command Menu]"));
345 menubar_add_menu (the_menubar,
346 create_menu (_("&Options"), create_options_menu (), "[Options Menu]"));
347 right_menu = create_menu ("", create_panel_menu (), "[Left and Right Menus]");
348 menubar_add_menu (the_menubar, right_menu);
349 update_menu ();
352 /* --------------------------------------------------------------------------------------------- */
354 static void
355 menu_last_selected_cmd (void)
357 the_menubar->is_active = TRUE;
358 the_menubar->is_dropped = (drop_menus != 0);
359 the_menubar->previous_widget = dlg_get_current_widget_id (midnight_dlg);
360 dlg_select_widget (the_menubar);
363 /* --------------------------------------------------------------------------------------------- */
365 static void
366 menu_cmd (void)
368 if (the_menubar->is_active)
369 return;
371 if ((get_current_index () == 0) == (current_panel->active != 0))
372 the_menubar->selected = 0;
373 else
374 the_menubar->selected = g_list_length (the_menubar->menu) - 1;
375 menu_last_selected_cmd ();
378 /* --------------------------------------------------------------------------------------------- */
380 static void
381 sort_cmd (void)
383 WPanel *p;
384 const panel_field_t *sort_order;
386 if (!SELECTED_IS_PANEL)
387 return;
389 p = MENU_PANEL;
390 sort_order = sort_box (&p->sort_info);
391 panel_set_sort_order (p, sort_order);
394 /* --------------------------------------------------------------------------------------------- */
396 static char *
397 midnight_get_shortcut (unsigned long command)
399 const char *ext_map;
400 const char *shortcut = NULL;
402 shortcut = keybind_lookup_keymap_shortcut (main_map, command);
403 if (shortcut != NULL)
404 return g_strdup (shortcut);
406 shortcut = keybind_lookup_keymap_shortcut (panel_map, command);
407 if (shortcut != NULL)
408 return g_strdup (shortcut);
410 ext_map = keybind_lookup_keymap_shortcut (main_map, CK_ExtendedKeyMap);
411 if (ext_map != NULL)
412 shortcut = keybind_lookup_keymap_shortcut (main_x_map, command);
413 if (shortcut != NULL)
414 return g_strdup_printf ("%s %s", ext_map, shortcut);
416 return NULL;
419 /* --------------------------------------------------------------------------------------------- */
421 static char *
422 midnight_get_title (const Dlg_head * h, size_t len)
424 /* TODO: share code with update_xterm_title_path() */
426 const char *path;
427 char host[BUF_TINY];
428 char *p;
429 struct passwd *pw = NULL;
430 char *login = NULL;
431 int res = 0;
433 (void) h;
435 path = strip_home_and_password (current_panel->cwd);
436 res = gethostname (host, sizeof (host));
437 if (res != 0)
438 host[0] = '\0';
439 else
440 host[sizeof (host) - 1] = '\0';
442 pw = getpwuid (getuid ());
443 if (pw != NULL)
444 login = g_strdup_printf ("%s@%s", pw->pw_name, host);
445 else
446 login = g_strdup (host);
448 p = g_strdup_printf ("%s [%s]:%s", _("Panels:"), login, path);
449 path = str_trunc (p, len - 4);
450 g_free (login);
451 g_free (p);
453 return g_strdup (path);
456 /* --------------------------------------------------------------------------------------------- */
458 static void
459 toggle_panels_split (void)
461 horizontal_split = !horizontal_split;
462 layout_change ();
463 do_refresh ();
466 /* --------------------------------------------------------------------------------------------- */
468 #if ENABLE_VFS
470 /* event helper */
471 static gboolean
472 check_panel_timestamp (const WPanel * panel, panel_view_mode_t mode, struct vfs_class *vclass,
473 vfsid id)
475 if (mode == view_listing)
477 vfs_path_t *vpath;
478 vfs_path_element_t *path_element;
480 vpath = vfs_path_from_str (panel->cwd);
481 path_element = vfs_path_get_by_index (vpath, -1);
483 if (path_element->class != vclass)
484 return FALSE;
486 if (vfs_getid (vpath) != id)
487 return FALSE;
489 return TRUE;
492 /* --------------------------------------------------------------------------------------------- */
494 /* event callback */
495 static gboolean
496 check_current_panel_timestamp (const gchar * event_group_name, const gchar * event_name,
497 gpointer init_data, gpointer data)
499 ev_vfs_stamp_create_t *event_data = (ev_vfs_stamp_create_t *) data;
501 (void) event_group_name;
502 (void) event_name;
503 (void) init_data;
505 event_data->ret =
506 check_panel_timestamp (current_panel, get_current_type (), event_data->vclass,
507 event_data->id);
508 return !event_data->ret;
511 /* --------------------------------------------------------------------------------------------- */
513 /* event callback */
514 static gboolean
515 check_other_panel_timestamp (const gchar * event_group_name, const gchar * event_name,
516 gpointer init_data, gpointer data)
518 ev_vfs_stamp_create_t *event_data = (ev_vfs_stamp_create_t *) data;
520 (void) event_group_name;
521 (void) event_name;
522 (void) init_data;
524 event_data->ret =
525 check_panel_timestamp (other_panel, get_other_type (), event_data->vclass, event_data->id);
526 return !event_data->ret;
528 #endif /* ENABLE_VFS */
530 /* --------------------------------------------------------------------------------------------- */
532 /* event callback */
533 static gboolean
534 print_vfs_message (const gchar * event_group_name, const gchar * event_name,
535 gpointer init_data, gpointer data)
537 char str[128];
538 ev_vfs_print_message_t *event_data = (ev_vfs_print_message_t *) data;
540 (void) event_group_name;
541 (void) event_name;
542 (void) init_data;
544 g_vsnprintf (str, sizeof (str), event_data->msg, event_data->ap);
546 if (mc_global.widget.midnight_shutdown)
547 return TRUE;
549 if (!mc_global.message_visible || !the_hint || !the_hint->widget.owner)
551 int col, row;
553 if (!nice_rotating_dash || (ok_to_refresh <= 0))
554 return TRUE;
556 /* Preserve current cursor position */
557 tty_getyx (&row, &col);
559 tty_gotoyx (0, 0);
560 tty_setcolor (NORMAL_COLOR);
561 tty_print_string (str_fit_to_term (str, COLS - 1, J_LEFT));
563 /* Restore cursor position */
564 tty_gotoyx (row, col);
565 mc_refresh ();
566 return TRUE;
569 if (mc_global.message_visible)
570 set_hintbar (str);
572 return TRUE;
575 /* --------------------------------------------------------------------------------------------- */
577 static void
578 create_panels (void)
580 int current_index;
581 int other_index;
582 panel_view_mode_t current_mode, other_mode;
583 char original_dir[BUF_1K] = "\0";
585 if (boot_current_is_left)
587 current_index = 0;
588 other_index = 1;
589 current_mode = startup_left_mode;
590 other_mode = startup_right_mode;
592 else
594 current_index = 1;
595 other_index = 0;
596 current_mode = startup_right_mode;
597 other_mode = startup_left_mode;
599 /* Creates the left panel */
600 if (mc_run_param0 != NULL)
602 if (mc_run_param1 != NULL)
604 /* Ok, user has specified two dirs, save the original one,
605 * since we may not be able to chdir to the proper
606 * second directory later
608 mc_get_current_wd (original_dir, sizeof (original_dir) - 2);
610 mc_chdir (mc_run_param0);
612 set_display_type (current_index, current_mode);
614 /* The other panel */
615 if (mc_run_param1 != NULL)
617 if (original_dir[0] != '\0')
618 mc_chdir (original_dir);
619 mc_chdir (mc_run_param1);
621 set_display_type (other_index, other_mode);
623 if (startup_left_mode == view_listing)
624 current_panel = left_panel;
625 else if (right_panel != NULL)
626 current_panel = right_panel;
627 else
628 current_panel = left_panel;
630 #if ENABLE_VFS
631 mc_event_add (MCEVENT_GROUP_CORE, "vfs_timestamp", check_other_panel_timestamp, NULL, NULL);
632 mc_event_add (MCEVENT_GROUP_CORE, "vfs_timestamp", check_current_panel_timestamp, NULL, NULL);
633 #endif /* ENABLE_VFS */
635 mc_event_add (MCEVENT_GROUP_CORE, "vfs_print_message", print_vfs_message, NULL, NULL);
637 /* Create the nice widgets */
638 cmdline = command_new (0, 0, 0);
639 the_prompt = label_new (0, 0, mc_prompt);
640 the_prompt->transparent = 1;
641 the_bar = buttonbar_new (mc_global.keybar_visible);
643 the_hint = label_new (0, 0, 0);
644 the_hint->transparent = 1;
645 the_hint->auto_adjust_cols = 0;
646 the_hint->widget.cols = COLS;
648 the_menubar = menubar_new (0, 0, COLS, NULL);
651 /* --------------------------------------------------------------------------------------------- */
653 static void
654 put_current_path (void)
656 char *cwd_path;
657 if (!command_prompt)
658 return;
660 cwd_path = remove_encoding_from_path (current_panel->cwd);
661 command_insert (cmdline, cwd_path, FALSE);
663 if (cwd_path[strlen (cwd_path) - 1] != PATH_SEP)
664 command_insert (cmdline, PATH_SEP_STR, FALSE);
665 g_free (cwd_path);
668 /* --------------------------------------------------------------------------------------------- */
670 static void
671 put_other_path (void)
673 char *cwd_path;
675 if (get_other_type () != view_listing)
676 return;
678 if (!command_prompt)
679 return;
681 cwd_path = remove_encoding_from_path (other_panel->cwd);
682 command_insert (cmdline, cwd_path, FALSE);
684 if (cwd_path[strlen (cwd_path) - 1] != PATH_SEP)
685 command_insert (cmdline, PATH_SEP_STR, FALSE);
686 g_free (cwd_path);
689 /* --------------------------------------------------------------------------------------------- */
691 static void
692 put_link (WPanel * panel)
694 if (!command_prompt)
695 return;
696 if (S_ISLNK (selection (panel)->st.st_mode))
698 char buffer[MC_MAXPATHLEN];
699 char *p;
700 int i;
702 p = concat_dir_and_file (panel->cwd, selection (panel)->fname);
703 i = mc_readlink (p, buffer, MC_MAXPATHLEN - 1);
704 g_free (p);
705 if (i > 0)
707 buffer[i] = '\0';
708 command_insert (cmdline, buffer, TRUE);
713 /* --------------------------------------------------------------------------------------------- */
715 static void
716 put_current_link (void)
718 put_link (current_panel);
721 /* --------------------------------------------------------------------------------------------- */
723 static void
724 put_other_link (void)
726 if (get_other_type () == view_listing)
727 put_link (other_panel);
730 /* --------------------------------------------------------------------------------------------- */
732 /** Insert the selected file name into the input line */
733 static void
734 put_prog_name (void)
736 char *tmp;
737 if (!command_prompt)
738 return;
740 if (get_current_type () == view_tree)
742 WTree *tree = (WTree *) get_panel_widget (get_current_index ());
743 tmp = tree_selected_name (tree);
745 else
746 tmp = selection (current_panel)->fname;
748 command_insert (cmdline, tmp, TRUE);
751 /* --------------------------------------------------------------------------------------------- */
753 static void
754 put_tagged (WPanel * panel)
756 int i;
758 if (!command_prompt)
759 return;
760 input_disable_update (cmdline);
761 if (panel->marked)
763 for (i = 0; i < panel->count; i++)
765 if (panel->dir.list[i].f.marked)
766 command_insert (cmdline, panel->dir.list[i].fname, TRUE);
769 else
771 command_insert (cmdline, panel->dir.list[panel->selected].fname, TRUE);
773 input_enable_update (cmdline);
776 /* --------------------------------------------------------------------------------------------- */
778 static void
779 put_current_tagged (void)
781 put_tagged (current_panel);
784 /* --------------------------------------------------------------------------------------------- */
786 static void
787 put_other_tagged (void)
789 if (get_other_type () == view_listing)
790 put_tagged (other_panel);
793 /* --------------------------------------------------------------------------------------------- */
795 static void
796 ctl_x_cmd (void)
798 ctl_x_map_enabled = TRUE;
801 /* --------------------------------------------------------------------------------------------- */
803 static void
804 init_xterm_support (void)
806 const char *termvalue;
808 termvalue = getenv ("TERM");
809 if (!termvalue || !(*termvalue))
811 fputs (_("The TERM environment variable is unset!\n"), stderr);
812 exit (EXIT_FAILURE);
815 /* Check mouse capabilities */
816 xmouse_seq = tty_tgetstr ("Km");
818 if (strcmp (termvalue, "cygwin") == 0)
820 mc_args__force_xterm = 1;
821 use_mouse_p = MOUSE_DISABLED;
824 if (mc_args__force_xterm || strncmp (termvalue, "xterm", 5) == 0
825 || strncmp (termvalue, "konsole", 7) == 0
826 || strncmp (termvalue, "rxvt", 4) == 0
827 || strcmp (termvalue, "Eterm") == 0 || strcmp (termvalue, "dtterm") == 0)
829 xterm_flag = 1;
831 #ifdef HAVE_SLANG
832 /* For 8-bit locales, NCurses handles 154 (0x9A) symbol properly, while S-Lang
833 * requires SLsmg_Display_Eight_Bit >= 154 (OR manual filtering if xterm display
834 * detected - but checking TERM would fail under screen, OR running xterm
835 * with allowC1Printable).
837 tty_display_8bit (FALSE);
838 #endif
840 /* Default to the standard xterm sequence */
841 if (!xmouse_seq)
843 xmouse_seq = ESC_STR "[M";
846 /* Enable mouse unless explicitly disabled by --nomouse */
847 if (use_mouse_p != MOUSE_DISABLED)
849 const char *color_term = getenv ("COLORTERM");
850 if (strncmp (termvalue, "rxvt", 4) == 0 ||
851 (color_term != NULL && strncmp (color_term, "rxvt", 4) == 0) ||
852 strcmp (termvalue, "Eterm") == 0)
854 use_mouse_p = MOUSE_XTERM_NORMAL_TRACKING;
856 else
858 use_mouse_p = MOUSE_XTERM_BUTTON_EVENT_TRACKING;
864 /* --------------------------------------------------------------------------------------------- */
866 static void
867 setup_mc (void)
869 #ifdef HAVE_SLANG
870 #ifdef HAVE_CHARSET
871 tty_display_8bit (TRUE);
872 #else
873 tty_display_8bit (full_eight_bits != 0);
874 #endif /* HAVE_CHARSET */
875 #else
877 #ifdef HAVE_CHARSET
878 tty_display_8bit (TRUE);
879 #else
880 tty_display_8bit (eight_bit_clean != 0);
881 #endif /* HAVE_CHARSET */
883 #endif
885 #ifdef HAVE_SUBSHELL_SUPPORT
886 if (mc_global.tty.use_subshell)
887 add_select_channel (mc_global.tty.subshell_pty, load_prompt, 0);
888 #endif /* !HAVE_SUBSHELL_SUPPORT */
890 tty_setup_sigwinch (sigwinch_handler);
892 if ((tty_baudrate () < 9600) || tty_is_slow ())
893 verbose = 0;
895 init_xterm_support ();
896 init_mouse ();
899 /* --------------------------------------------------------------------------------------------- */
901 static void
902 setup_dummy_mc (void)
904 char d[MC_MAXPATHLEN];
905 int ret;
907 mc_get_current_wd (d, MC_MAXPATHLEN);
908 setup_mc ();
909 ret = mc_chdir (d);
912 /* --------------------------------------------------------------------------------------------- */
914 static void
915 done_screen (void)
917 if ((quit & SUBSHELL_EXIT) == 0)
918 clr_scr ();
919 tty_reset_shell_mode ();
920 tty_noraw_mode ();
921 tty_keypad (FALSE);
924 /* --------------------------------------------------------------------------------------------- */
926 static void
927 done_mc (void)
929 disable_mouse ();
931 /* Setup shutdown
933 * We sync the profiles since the hotlist may have changed, while
934 * we only change the setup data if we have the auto save feature set
937 save_setup (auto_save_setup, panels_options.auto_save_setup);
938 done_screen ();
941 char *curr_dir = vfs_get_current_dir ();
942 vfs_stamp_path (curr_dir);
943 g_free (curr_dir);
946 if ((current_panel != NULL) && (get_current_type () == view_listing))
947 vfs_stamp_path (current_panel->cwd);
949 if ((other_panel != NULL) && (get_other_type () == view_listing))
950 vfs_stamp_path (other_panel->cwd);
953 /* --------------------------------------------------------------------------------------------- */
955 static void
956 create_panels_and_run_mc (void)
958 midnight_dlg->get_shortcut = midnight_get_shortcut;
959 midnight_dlg->get_title = midnight_get_title;
961 create_panels ();
963 add_widget (midnight_dlg, the_menubar);
964 init_menu ();
966 add_widget (midnight_dlg, get_panel_widget (0));
967 add_widget (midnight_dlg, get_panel_widget (1));
969 add_widget (midnight_dlg, the_hint);
970 add_widget (midnight_dlg, cmdline);
971 add_widget (midnight_dlg, the_prompt);
973 add_widget (midnight_dlg, the_bar);
974 midnight_set_buttonbar (the_bar);
976 /* Run the Midnight Commander if no file was specified in the command line */
977 run_dlg (midnight_dlg);
980 /* --------------------------------------------------------------------------------------------- */
982 /** result must be free'd (I think this should go in util.c) */
983 static char *
984 prepend_cwd_on_local (const char *filename)
986 char *d;
987 size_t l;
988 vfs_path_t *vpath;
990 vpath = vfs_path_from_str (filename);
991 if (!vfs_file_is_local (vpath) || g_path_is_absolute (filename))
993 vfs_path_free (vpath);
994 return g_strdup (filename);
996 vfs_path_free (vpath);
998 d = g_malloc (MC_MAXPATHLEN + strlen (filename) + 2);
999 mc_get_current_wd (d, MC_MAXPATHLEN);
1000 l = strlen (d);
1001 d[l++] = PATH_SEP;
1002 strcpy (d + l, filename);
1003 canonicalize_pathname (d);
1004 return d;
1007 /* --------------------------------------------------------------------------------------------- */
1009 /** Invoke the internal view/edit routine with:
1010 * the default processing and forcing the internal viewer/editor
1012 static void
1013 mc_maybe_editor_or_viewer (void)
1015 switch (mc_global.mc_run_mode)
1017 #ifdef USE_INTERNAL_EDIT
1018 case MC_RUN_EDITOR:
1019 edit_file (mc_run_param0, mc_args__edit_start_line);
1020 break;
1021 #endif /* USE_INTERNAL_EDIT */
1022 case MC_RUN_VIEWER:
1024 char *path;
1025 path = prepend_cwd_on_local (mc_run_param0);
1026 view_file (path, 0, 1);
1027 g_free (path);
1028 break;
1030 #ifdef USE_DIFF_VIEW
1031 case MC_RUN_DIFFVIEWER:
1032 diff_view (mc_run_param0, mc_run_param1, mc_run_param0, mc_run_param1);
1033 break;
1034 #endif /* USE_DIFF_VIEW */
1035 default:
1036 break;
1040 /* --------------------------------------------------------------------------------------------- */
1042 static gboolean
1043 quit_cmd_internal (int quiet)
1045 int q = quit;
1046 size_t n;
1048 n = dialog_switch_num () - 1;
1049 if (n != 0)
1051 char msg[BUF_MEDIUM];
1053 g_snprintf (msg, sizeof (msg),
1054 ngettext ("You have %zd opened screen. Quit anyway?",
1055 "You have %zd opened screens. Quit anyway?", n), n);
1057 if (query_dialog (_("The Midnight Commander"), msg, D_NORMAL, 2, _("&Yes"), _("&No")) != 0)
1058 return FALSE;
1059 q = 1;
1061 else if (quiet || !confirm_exit)
1062 q = 1;
1063 else if (query_dialog (_("The Midnight Commander"),
1064 _("Do you really want to quit the Midnight Commander?"),
1065 D_NORMAL, 2, _("&Yes"), _("&No")) == 0)
1066 q = 1;
1068 if (q != 0)
1070 #ifdef HAVE_SUBSHELL_SUPPORT
1071 if (!mc_global.tty.use_subshell)
1072 stop_dialogs ();
1073 else if ((q = exit_subshell ()))
1074 #endif
1075 stop_dialogs ();
1078 if (q != 0)
1079 quit |= 1;
1080 return (quit != 0);
1083 /* --------------------------------------------------------------------------------------------- */
1085 static gboolean
1086 quit_cmd (void)
1088 return quit_cmd_internal (0);
1091 /* --------------------------------------------------------------------------------------------- */
1093 static void
1094 toggle_show_hidden (void)
1096 panels_options.show_dot_files = !panels_options.show_dot_files;
1097 update_panels (UP_RELOAD, UP_KEEPSEL);
1100 /* --------------------------------------------------------------------------------------------- */
1103 * Repaint the contents of the panels without frames. To schedule panel
1104 * for repainting, set panel->dirty to 1. There are many reasons why
1105 * the panels need to be repainted, and this is a costly operation, so
1106 * it's done once per event.
1109 static void
1110 update_dirty_panels (void)
1112 if (get_current_type () == view_listing && current_panel->dirty)
1113 send_message ((Widget *) current_panel, WIDGET_DRAW, 0);
1115 if (get_other_type () == view_listing && other_panel->dirty)
1116 send_message ((Widget *) other_panel, WIDGET_DRAW, 0);
1119 /* --------------------------------------------------------------------------------------------- */
1121 static cb_ret_t
1122 midnight_execute_cmd (Widget * sender, unsigned long command)
1124 cb_ret_t res = MSG_HANDLED;
1126 (void) sender;
1128 /* stop quick search before executing any command */
1129 send_message ((Widget *) current_panel, WIDGET_COMMAND, CK_SearchStop);
1131 switch (command)
1133 case CK_HotListAdd:
1134 add2hotlist_cmd ();
1135 break;
1136 case CK_PanelListingChange:
1137 change_listing_cmd ();
1138 break;
1139 case CK_ChangeMode:
1140 chmod_cmd ();
1141 break;
1142 case CK_ChangeOwn:
1143 chown_cmd ();
1144 break;
1145 case CK_ChangeOwnAdvanced:
1146 chown_advanced_cmd ();
1147 break;
1148 case CK_CompareDirs:
1149 compare_dirs_cmd ();
1150 break;
1151 case CK_Options:
1152 configure_box ();
1153 break;
1154 #ifdef ENABLE_VFS
1155 case CK_OptionsVfs:
1156 configure_vfs ();
1157 break;
1158 #endif
1159 case CK_OptionsConfirm:
1160 confirm_box ();
1161 break;
1162 case CK_Copy:
1163 copy_cmd ();
1164 break;
1165 case CK_PutCurrentPath:
1166 put_current_path ();
1167 break;
1168 case CK_PutCurrentLink:
1169 put_current_link ();
1170 break;
1171 case CK_PutCurrentTagged:
1172 put_current_tagged ();
1173 break;
1174 case CK_PutOtherPath:
1175 put_other_path ();
1176 break;
1177 case CK_PutOtherLink:
1178 put_other_link ();
1179 break;
1180 case CK_PutOtherTagged:
1181 put_other_tagged ();
1182 break;
1183 case CK_Delete:
1184 delete_cmd ();
1185 break;
1186 case CK_ScreenList:
1187 dialog_switch_list ();
1188 break;
1189 #ifdef USE_DIFF_VIEW
1190 case CK_CompareFiles:
1191 diff_view_cmd ();
1192 break;
1193 #endif
1194 case CK_OptionsDisplayBits:
1195 display_bits_box ();
1196 break;
1197 case CK_Edit:
1198 edit_cmd ();
1199 break;
1200 #ifdef USE_INTERNAL_EDIT
1201 case CK_EditForceInternal:
1202 edit_cmd_force_internal ();
1203 break;
1204 #endif
1205 case CK_EditExtensionsFile:
1206 ext_cmd ();
1207 break;
1208 case CK_EditFileHighlightFile:
1209 edit_fhl_cmd ();
1210 break;
1211 case CK_EditUserMenu:
1212 edit_mc_menu_cmd ();
1213 break;
1214 case CK_LinkSymbolicEdit:
1215 edit_symlink_cmd ();
1216 break;
1217 case CK_ExternalPanelize:
1218 external_panelize ();
1219 break;
1220 case CK_Filter:
1221 filter_cmd ();
1222 break;
1223 case CK_ViewFiltered:
1224 view_filtered_cmd ();
1225 break;
1226 case CK_Find:
1227 find_cmd ();
1228 break;
1229 #ifdef ENABLE_VFS_FISH
1230 case CK_ConnectFish:
1231 fishlink_cmd ();
1232 break;
1233 #endif
1234 #ifdef ENABLE_VFS_FTP
1235 case CK_ConnectFtp:
1236 ftplink_cmd ();
1237 break;
1238 #endif
1239 #ifdef ENABLE_VFS_SMB
1240 case CK_ConnectSmb:
1241 smblink_cmd ();
1242 break;
1243 #endif /* ENABLE_VFS_SMB */
1244 case CK_Help:
1245 help_cmd ();
1246 break;
1247 case CK_History:
1248 /* show the history of command line widget */
1249 send_message (&cmdline->widget, WIDGET_COMMAND, CK_History);
1250 break;
1251 case CK_PanelInfo:
1252 if (sender == (Widget *) the_menubar)
1253 info_cmd (); /* menu */
1254 else
1255 info_cmd_no_menu (); /* shortcut or buttonbar */
1256 break;
1257 #ifdef WITH_BACKGROUND
1258 case CK_Jobs:
1259 jobs_cmd ();
1260 break;
1261 #endif
1262 case CK_OptionsLayout:
1263 layout_box ();
1264 break;
1265 case CK_LearnKeys:
1266 learn_keys ();
1267 break;
1268 case CK_Link:
1269 link_cmd (LINK_HARDLINK);
1270 break;
1271 case CK_PanelListing:
1272 listing_cmd ();
1273 break;
1274 #ifdef LISTMODE_EDITOR
1275 case CK_ListMode:
1276 listmode_cmd ();
1277 break;
1278 #endif
1279 case CK_Menu:
1280 menu_cmd ();
1281 break;
1282 case CK_MenuLastSelected:
1283 menu_last_selected_cmd ();
1284 break;
1285 case CK_MakeDir:
1286 mkdir_cmd ();
1287 break;
1288 case CK_OptionsPanel:
1289 panel_options_box ();
1290 break;
1291 #ifdef HAVE_CHARSET
1292 case CK_SelectCodepage:
1293 encoding_cmd ();
1294 break;
1295 #endif
1296 case CK_CdQuick:
1297 quick_cd_cmd ();
1298 break;
1299 case CK_HotList:
1300 hotlist_cmd ();
1301 break;
1302 case CK_PanelQuickView:
1303 if (sender == (Widget *) the_menubar)
1304 quick_view_cmd (); /* menu */
1305 else
1306 quick_cmd_no_menu (); /* shortcut or buttonabr */
1307 break;
1308 case CK_QuitQuiet:
1309 quiet_quit_cmd ();
1310 break;
1311 case CK_Quit:
1312 quit_cmd ();
1313 break;
1314 case CK_LinkSymbolicRelative:
1315 link_cmd (LINK_SYMLINK_RELATIVE);
1316 break;
1317 case CK_Move:
1318 rename_cmd ();
1319 break;
1320 case CK_Reread:
1321 reread_cmd ();
1322 break;
1323 #ifdef ENABLE_VFS
1324 case CK_VfsList:
1325 vfs_list ();
1326 break;
1327 #endif
1328 case CK_SelectInvert:
1329 select_invert_cmd ();
1330 break;
1331 case CK_SaveSetup:
1332 save_setup_cmd ();
1333 break;
1334 case CK_Select:
1335 select_cmd ();
1336 break;
1337 case CK_Shell:
1338 view_other_cmd ();
1339 break;
1340 case CK_DirSize:
1341 smart_dirsize_cmd ();
1342 break;
1343 case CK_Sort:
1344 sort_cmd ();
1345 break;
1346 case CK_ExtendedKeyMap:
1347 ctl_x_cmd ();
1348 break;
1349 case CK_Suspend:
1350 mc_event_raise (MCEVENT_GROUP_CORE, "suspend", NULL);
1351 break;
1352 case CK_Swap:
1353 swap_cmd ();
1354 break;
1355 case CK_LinkSymbolic:
1356 link_cmd (LINK_SYMLINK_ABSOLUTE);
1357 break;
1358 case CK_PanelListingSwitch:
1359 toggle_listing_cmd ();
1360 break;
1361 case CK_ShowHidden:
1362 toggle_show_hidden ();
1363 break;
1364 case CK_SplitVertHoriz:
1365 toggle_panels_split ();
1366 break;
1367 case CK_PanelTree:
1368 panel_tree_cmd ();
1369 break;
1370 case CK_Tree:
1371 treebox_cmd ();
1372 break;
1373 #ifdef ENABLE_VFS_UNDELFS
1374 case CK_Undelete:
1375 undelete_cmd ();
1376 break;
1377 #endif
1378 case CK_Unselect:
1379 unselect_cmd ();
1380 break;
1381 case CK_UserMenu:
1382 user_file_menu_cmd ();
1383 break;
1384 case CK_View:
1385 view_cmd ();
1386 break;
1387 case CK_ViewFile:
1388 view_file_cmd ();
1389 break;
1390 case CK_Cancel:
1391 /* don't close panels due to SIGINT */
1392 break;
1393 default:
1394 res = MSG_NOT_HANDLED;
1397 return res;
1400 /* --------------------------------------------------------------------------------------------- */
1402 static cb_ret_t
1403 midnight_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
1405 unsigned long command;
1407 switch (msg)
1409 case DLG_INIT:
1410 panel_init ();
1411 setup_panels ();
1412 return MSG_HANDLED;
1414 case DLG_DRAW:
1415 load_hint (1);
1416 /* We handle the special case of the output lines */
1417 if (mc_global.tty.console_flag && output_lines)
1418 show_console_contents (output_start_y,
1419 LINES - output_lines - mc_global.keybar_visible -
1420 1, LINES - mc_global.keybar_visible - 1);
1421 return MSG_HANDLED;
1423 case DLG_RESIZE:
1424 setup_panels ();
1425 menubar_arrange (the_menubar);
1426 return MSG_HANDLED;
1428 case DLG_IDLE:
1429 /* We only need the first idle event to show user menu after start */
1430 set_idle_proc (h, 0);
1432 if (boot_current_is_left)
1433 dlg_select_widget (get_panel_widget (0));
1434 else
1435 dlg_select_widget (get_panel_widget (1));
1437 if (auto_menu)
1438 midnight_execute_cmd (NULL, CK_UserMenu);
1439 return MSG_HANDLED;
1441 case DLG_KEY:
1442 if (ctl_x_map_enabled)
1444 ctl_x_map_enabled = FALSE;
1445 command = keybind_lookup_keymap_command (main_x_map, parm);
1446 if (command != CK_IgnoreKey)
1447 return midnight_execute_cmd (NULL, command);
1450 /* FIXME: should handle all menu shortcuts before this point */
1451 if (the_menubar->is_active)
1452 return MSG_NOT_HANDLED;
1454 if (parm == '\t')
1455 input_free_completions (cmdline);
1457 if (parm == '\n')
1459 size_t i;
1461 for (i = 0; cmdline->buffer[i] != '\0' &&
1462 (cmdline->buffer[i] == ' ' || cmdline->buffer[i] == '\t'); i++)
1465 if (cmdline->buffer[i] != '\0')
1467 send_message ((Widget *) cmdline, WIDGET_KEY, parm);
1468 return MSG_HANDLED;
1471 input_insert (cmdline, "", FALSE);
1472 cmdline->point = 0;
1475 /* Ctrl-Enter and Alt-Enter */
1476 if (((parm & ~(KEY_M_CTRL | KEY_M_ALT)) == '\n') && (parm & (KEY_M_CTRL | KEY_M_ALT)))
1478 put_prog_name ();
1479 return MSG_HANDLED;
1482 /* Ctrl-Shift-Enter */
1483 if (parm == (KEY_M_CTRL | KEY_M_SHIFT | '\n'))
1485 put_current_path ();
1486 put_prog_name ();
1487 return MSG_HANDLED;
1490 if ((!alternate_plus_minus || !(mc_global.tty.console_flag || xterm_flag))
1491 && !quote && !current_panel->searching)
1493 if (!only_leading_plus_minus)
1495 /* Special treatement, since the input line will eat them */
1496 if (parm == '+')
1498 select_cmd ();
1499 return MSG_HANDLED;
1502 if (parm == '\\' || parm == '-')
1504 unselect_cmd ();
1505 return MSG_HANDLED;
1508 if (parm == '*')
1510 select_invert_cmd ();
1511 return MSG_HANDLED;
1514 else if (!command_prompt || !cmdline->buffer[0])
1516 /* Special treatement '+', '-', '\', '*' only when this is
1517 * first char on input line
1520 if (parm == '+')
1522 select_cmd ();
1523 return MSG_HANDLED;
1526 if (parm == '\\' || parm == '-')
1528 unselect_cmd ();
1529 return MSG_HANDLED;
1532 if (parm == '*')
1534 select_invert_cmd ();
1535 return MSG_HANDLED;
1539 return MSG_NOT_HANDLED;
1541 case DLG_HOTKEY_HANDLED:
1542 if ((get_current_type () == view_listing) && current_panel->searching)
1544 current_panel->dirty = 1; /* FIXME: unneeded? */
1545 send_message ((Widget *) current_panel, WIDGET_COMMAND, CK_SearchStop);
1547 return MSG_HANDLED;
1549 case DLG_UNHANDLED_KEY:
1550 if (command_prompt)
1552 cb_ret_t v;
1554 v = send_message ((Widget *) cmdline, WIDGET_KEY, parm);
1555 if (v == MSG_HANDLED)
1556 return MSG_HANDLED;
1559 if (ctl_x_map_enabled)
1561 ctl_x_map_enabled = FALSE;
1562 command = keybind_lookup_keymap_command (main_x_map, parm);
1564 else
1565 command = keybind_lookup_keymap_command (main_map, parm);
1567 return (command == CK_IgnoreKey) ? MSG_NOT_HANDLED : midnight_execute_cmd (NULL, command);
1569 case DLG_POST_KEY:
1570 if (!the_menubar->is_active)
1571 update_dirty_panels ();
1572 return MSG_HANDLED;
1574 case DLG_ACTION:
1575 /* shortcut */
1576 if (sender == NULL)
1577 return midnight_execute_cmd (NULL, parm);
1578 /* message from menu */
1579 if (sender == (Widget *) the_menubar)
1580 return midnight_execute_cmd (sender, parm);
1581 /* message from buttonbar */
1582 if (sender == (Widget *) the_bar)
1584 if (data != NULL)
1585 return send_message ((Widget *) data, WIDGET_COMMAND, parm);
1586 return midnight_execute_cmd (sender, parm);
1588 return MSG_NOT_HANDLED;
1590 case DLG_END:
1591 panel_deinit ();
1592 return MSG_HANDLED;
1594 default:
1595 return default_dlg_callback (h, sender, msg, parm, data);
1599 /* --------------------------------------------------------------------------------------------- */
1600 /*** public functions ****************************************************************************/
1601 /* --------------------------------------------------------------------------------------------- */
1603 void
1604 update_menu (void)
1606 menu_set_name (left_menu, horizontal_split ? _("&Above") : _("&Left"));
1607 menu_set_name (right_menu, horizontal_split ? _("&Below") : _("&Right"));
1608 menubar_arrange (the_menubar);
1609 menubar_set_visible (the_menubar, menubar_visible);
1612 void
1613 midnight_set_buttonbar (WButtonBar * b)
1615 buttonbar_set_label (b, 1, Q_ ("ButtonBar|Help"), main_map, NULL);
1616 buttonbar_set_label (b, 2, Q_ ("ButtonBar|Menu"), main_map, NULL);
1617 buttonbar_set_label (b, 3, Q_ ("ButtonBar|View"), main_map, NULL);
1618 buttonbar_set_label (b, 4, Q_ ("ButtonBar|Edit"), main_map, NULL);
1619 buttonbar_set_label (b, 5, Q_ ("ButtonBar|Copy"), main_map, NULL);
1620 buttonbar_set_label (b, 6, Q_ ("ButtonBar|RenMov"), main_map, NULL);
1621 buttonbar_set_label (b, 7, Q_ ("ButtonBar|Mkdir"), main_map, NULL);
1622 buttonbar_set_label (b, 8, Q_ ("ButtonBar|Delete"), main_map, NULL);
1623 buttonbar_set_label (b, 9, Q_ ("ButtonBar|PullDn"), main_map, NULL);
1624 buttonbar_set_label (b, 10, Q_ ("ButtonBar|Quit"), main_map, NULL);
1627 /* --------------------------------------------------------------------------------------------- */
1629 * Load new hint and display it.
1630 * IF force is not 0, ignore the timeout.
1633 void
1634 load_hint (gboolean force)
1636 char *hint;
1638 if (the_hint->widget.owner == NULL)
1639 return;
1641 if (!mc_global.message_visible)
1643 label_set_text (the_hint, NULL);
1644 return;
1647 hint = get_random_hint (force);
1649 if (hint != NULL)
1651 if (*hint != '\0')
1652 set_hintbar (hint);
1653 g_free (hint);
1655 else
1657 char text[BUF_SMALL];
1659 g_snprintf (text, sizeof (text), _("GNU Midnight Commander %s\n"), VERSION);
1660 set_hintbar (text);
1664 /* --------------------------------------------------------------------------------------------- */
1666 void
1667 change_panel (void)
1669 input_free_completions (cmdline);
1670 dlg_one_down (midnight_dlg);
1673 /* --------------------------------------------------------------------------------------------- */
1675 /** Save current stat of directories to avoid reloading the panels
1676 * when no modifications have taken place
1678 void
1679 save_cwds_stat (void)
1681 if (panels_options.fast_reload)
1683 mc_stat (current_panel->cwd, &(current_panel->dir_stat));
1684 if (get_other_type () == view_listing)
1685 mc_stat (other_panel->cwd, &(other_panel->dir_stat));
1689 /* --------------------------------------------------------------------------------------------- */
1691 gboolean
1692 quiet_quit_cmd (void)
1694 print_last_revert = TRUE;
1695 return quit_cmd_internal (1);
1698 /* --------------------------------------------------------------------------------------------- */
1700 /** Run the main dialog that occupies the whole screen */
1701 void
1702 do_nc (void)
1704 dlg_colors_t midnight_colors;
1706 midnight_colors[DLG_COLOR_NORMAL] = mc_skin_color_get ("dialog", "_default_");
1707 midnight_colors[DLG_COLOR_FOCUS] = mc_skin_color_get ("dialog", "focus");
1708 midnight_colors[DLG_COLOR_HOT_NORMAL] = mc_skin_color_get ("dialog", "hotnormal");
1709 midnight_colors[DLG_COLOR_HOT_FOCUS] = mc_skin_color_get ("dialog", "hotfocus");
1710 midnight_colors[DLG_COLOR_TITLE] = mc_skin_color_get ("dialog", "title");
1712 #ifdef USE_INTERNAL_EDIT
1713 edit_stack_init ();
1714 #endif
1716 midnight_dlg = create_dlg (FALSE, 0, 0, LINES, COLS, midnight_colors, midnight_callback,
1717 "[main]", NULL, DLG_WANT_IDLE);
1719 if (mc_global.mc_run_mode == MC_RUN_FULL)
1720 setup_mc ();
1721 else
1722 setup_dummy_mc ();
1724 /* Check if we were invoked as an editor or file viewer */
1725 if (mc_global.mc_run_mode != MC_RUN_FULL)
1726 mc_maybe_editor_or_viewer ();
1727 else
1729 create_panels_and_run_mc ();
1731 /* destroy_dlg destroys even current_panel->cwd, so we have to save a copy :) */
1732 if (mc_args__last_wd_file != NULL && vfs_current_is_local ())
1733 last_wd_string = g_strdup (current_panel->cwd);
1735 /* don't handle VFS timestamps for dirs opened in panels */
1736 mc_event_destroy (MCEVENT_GROUP_CORE, "vfs_timestamp");
1739 /* Program end */
1740 mc_global.widget.midnight_shutdown = TRUE;
1741 dialog_switch_shutdown ();
1742 done_mc ();
1743 destroy_dlg (midnight_dlg);
1744 current_panel = NULL;
1746 #ifdef USE_INTERNAL_EDIT
1747 edit_stack_free ();
1748 #endif
1751 /* --------------------------------------------------------------------------------------------- */