Following prototypes of functions was changed in VFS-module API:
[midnight-commander.git] / src / filemanager / midnight.c
blob67f44e7d1a894b12254cc128588cbd495e13277b
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" /* vfs_translate_url() */
54 #include "src/args.h"
55 #include "src/subshell.h"
56 #include "src/setup.h" /* variables */
57 #include "src/learn.h" /* learn_keys() */
58 #include "src/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 /* --------------------------------------------------------------------------------------------- */
469 * Just a hack for allowing url-like pathnames to be accepted from the
470 * command line.
472 static void
473 translated_mc_chdir (char *dir)
475 char *newdir;
476 int ret;
478 newdir = vfs_translate_url (dir);
479 ret = mc_chdir (newdir);
480 g_free (newdir);
483 /* --------------------------------------------------------------------------------------------- */
485 #if ENABLE_VFS
487 /* event helper */
488 static gboolean
489 check_panel_timestamp (const WPanel * panel, panel_view_mode_t mode, struct vfs_class *vclass,
490 vfsid id)
492 if (mode == view_listing)
494 vfs_path_t *vpath;
495 vfs_path_element_t *path_element;
497 vpath = vfs_path_from_str (panel->cwd);
498 path_element = vfs_path_get_by_index (vpath, vfs_path_length (vpath) - 1);
500 if (path_element->class != vclass)
501 return FALSE;
503 if (vfs_getid (vpath) != id)
504 return FALSE;
506 return TRUE;
509 /* --------------------------------------------------------------------------------------------- */
511 /* event callback */
512 static gboolean
513 check_current_panel_timestamp (const gchar * event_group_name, const gchar * event_name,
514 gpointer init_data, gpointer data)
516 ev_vfs_stamp_create_t *event_data = (ev_vfs_stamp_create_t *) data;
518 (void) event_group_name;
519 (void) event_name;
520 (void) init_data;
522 event_data->ret =
523 check_panel_timestamp (current_panel, get_current_type (), event_data->vclass,
524 event_data->id);
525 return !event_data->ret;
528 /* --------------------------------------------------------------------------------------------- */
530 /* event callback */
531 static gboolean
532 check_other_panel_timestamp (const gchar * event_group_name, const gchar * event_name,
533 gpointer init_data, gpointer data)
535 ev_vfs_stamp_create_t *event_data = (ev_vfs_stamp_create_t *) data;
537 (void) event_group_name;
538 (void) event_name;
539 (void) init_data;
541 event_data->ret =
542 check_panel_timestamp (other_panel, get_other_type (), event_data->vclass, event_data->id);
543 return !event_data->ret;
545 #endif /* ENABLE_VFS */
547 /* --------------------------------------------------------------------------------------------- */
549 /* event callback */
550 static gboolean
551 print_vfs_message (const gchar * event_group_name, const gchar * event_name,
552 gpointer init_data, gpointer data)
554 char str[128];
555 ev_vfs_print_message_t *event_data = (ev_vfs_print_message_t *) data;
557 (void) event_group_name;
558 (void) event_name;
559 (void) init_data;
561 g_vsnprintf (str, sizeof (str), event_data->msg, event_data->ap);
563 if (mc_global.widget.midnight_shutdown)
564 return TRUE;
566 if (!mc_global.message_visible || !the_hint || !the_hint->widget.owner)
568 int col, row;
570 if (!nice_rotating_dash || (ok_to_refresh <= 0))
571 return TRUE;
573 /* Preserve current cursor position */
574 tty_getyx (&row, &col);
576 tty_gotoyx (0, 0);
577 tty_setcolor (NORMAL_COLOR);
578 tty_print_string (str_fit_to_term (str, COLS - 1, J_LEFT));
580 /* Restore cursor position */
581 tty_gotoyx (row, col);
582 mc_refresh ();
583 return TRUE;
586 if (mc_global.message_visible)
587 set_hintbar (str);
589 return TRUE;
592 /* --------------------------------------------------------------------------------------------- */
594 static void
595 create_panels (void)
597 int current_index;
598 int other_index;
599 panel_view_mode_t current_mode, other_mode;
600 char original_dir[BUF_1K] = "\0";
602 if (boot_current_is_left)
604 current_index = 0;
605 other_index = 1;
606 current_mode = startup_left_mode;
607 other_mode = startup_right_mode;
609 else
611 current_index = 1;
612 other_index = 0;
613 current_mode = startup_right_mode;
614 other_mode = startup_left_mode;
616 /* Creates the left panel */
617 if (mc_run_param0 != NULL)
619 if (mc_run_param1 != NULL)
621 /* Ok, user has specified two dirs, save the original one,
622 * since we may not be able to chdir to the proper
623 * second directory later
625 mc_get_current_wd (original_dir, sizeof (original_dir) - 2);
627 translated_mc_chdir (mc_run_param0);
629 set_display_type (current_index, current_mode);
631 /* The other panel */
632 if (mc_run_param1 != NULL)
634 if (original_dir[0] != '\0')
635 translated_mc_chdir (original_dir);
636 translated_mc_chdir (mc_run_param1);
638 set_display_type (other_index, other_mode);
640 if (startup_left_mode == view_listing)
641 current_panel = left_panel;
642 else if (right_panel != NULL)
643 current_panel = right_panel;
644 else
645 current_panel = left_panel;
647 #if ENABLE_VFS
648 mc_event_add (MCEVENT_GROUP_CORE, "vfs_timestamp", check_other_panel_timestamp, NULL, NULL);
649 mc_event_add (MCEVENT_GROUP_CORE, "vfs_timestamp", check_current_panel_timestamp, NULL, NULL);
650 #endif /* ENABLE_VFS */
652 mc_event_add (MCEVENT_GROUP_CORE, "vfs_print_message", print_vfs_message, NULL, NULL);
654 /* Create the nice widgets */
655 cmdline = command_new (0, 0, 0);
656 the_prompt = label_new (0, 0, mc_prompt);
657 the_prompt->transparent = 1;
658 the_bar = buttonbar_new (mc_global.keybar_visible);
660 the_hint = label_new (0, 0, 0);
661 the_hint->transparent = 1;
662 the_hint->auto_adjust_cols = 0;
663 the_hint->widget.cols = COLS;
665 the_menubar = menubar_new (0, 0, COLS, NULL);
668 /* --------------------------------------------------------------------------------------------- */
670 static void
671 put_current_path (void)
673 char *cwd_path;
674 if (!command_prompt)
675 return;
677 cwd_path = remove_encoding_from_path (current_panel->cwd);
678 command_insert (cmdline, cwd_path, FALSE);
680 if (cwd_path[strlen (cwd_path) - 1] != PATH_SEP)
681 command_insert (cmdline, PATH_SEP_STR, FALSE);
682 g_free (cwd_path);
685 /* --------------------------------------------------------------------------------------------- */
687 static void
688 put_other_path (void)
690 char *cwd_path;
692 if (get_other_type () != view_listing)
693 return;
695 if (!command_prompt)
696 return;
698 cwd_path = remove_encoding_from_path (other_panel->cwd);
699 command_insert (cmdline, cwd_path, FALSE);
701 if (cwd_path[strlen (cwd_path) - 1] != PATH_SEP)
702 command_insert (cmdline, PATH_SEP_STR, FALSE);
703 g_free (cwd_path);
706 /* --------------------------------------------------------------------------------------------- */
708 static void
709 put_link (WPanel * panel)
711 if (!command_prompt)
712 return;
713 if (S_ISLNK (selection (panel)->st.st_mode))
715 char buffer[MC_MAXPATHLEN];
716 char *p;
717 int i;
719 p = concat_dir_and_file (panel->cwd, selection (panel)->fname);
720 i = mc_readlink (p, buffer, MC_MAXPATHLEN - 1);
721 g_free (p);
722 if (i > 0)
724 buffer[i] = '\0';
725 command_insert (cmdline, buffer, TRUE);
730 /* --------------------------------------------------------------------------------------------- */
732 static void
733 put_current_link (void)
735 put_link (current_panel);
738 /* --------------------------------------------------------------------------------------------- */
740 static void
741 put_other_link (void)
743 if (get_other_type () == view_listing)
744 put_link (other_panel);
747 /* --------------------------------------------------------------------------------------------- */
749 /** Insert the selected file name into the input line */
750 static void
751 put_prog_name (void)
753 char *tmp;
754 if (!command_prompt)
755 return;
757 if (get_current_type () == view_tree)
759 WTree *tree = (WTree *) get_panel_widget (get_current_index ());
760 tmp = tree_selected_name (tree);
762 else
763 tmp = selection (current_panel)->fname;
765 command_insert (cmdline, tmp, TRUE);
768 /* --------------------------------------------------------------------------------------------- */
770 static void
771 put_tagged (WPanel * panel)
773 int i;
775 if (!command_prompt)
776 return;
777 input_disable_update (cmdline);
778 if (panel->marked)
780 for (i = 0; i < panel->count; i++)
782 if (panel->dir.list[i].f.marked)
783 command_insert (cmdline, panel->dir.list[i].fname, TRUE);
786 else
788 command_insert (cmdline, panel->dir.list[panel->selected].fname, TRUE);
790 input_enable_update (cmdline);
793 /* --------------------------------------------------------------------------------------------- */
795 static void
796 put_current_tagged (void)
798 put_tagged (current_panel);
801 /* --------------------------------------------------------------------------------------------- */
803 static void
804 put_other_tagged (void)
806 if (get_other_type () == view_listing)
807 put_tagged (other_panel);
810 /* --------------------------------------------------------------------------------------------- */
812 static void
813 ctl_x_cmd (void)
815 ctl_x_map_enabled = TRUE;
818 /* --------------------------------------------------------------------------------------------- */
820 static void
821 init_xterm_support (void)
823 const char *termvalue;
825 termvalue = getenv ("TERM");
826 if (!termvalue || !(*termvalue))
828 fputs (_("The TERM environment variable is unset!\n"), stderr);
829 exit (EXIT_FAILURE);
832 /* Check mouse capabilities */
833 xmouse_seq = tty_tgetstr ("Km");
835 if (strcmp (termvalue, "cygwin") == 0)
837 mc_args__force_xterm = 1;
838 use_mouse_p = MOUSE_DISABLED;
841 if (mc_args__force_xterm || strncmp (termvalue, "xterm", 5) == 0
842 || strncmp (termvalue, "konsole", 7) == 0
843 || strncmp (termvalue, "rxvt", 4) == 0
844 || strcmp (termvalue, "Eterm") == 0 || strcmp (termvalue, "dtterm") == 0)
846 xterm_flag = 1;
848 #ifdef HAVE_SLANG
849 /* For 8-bit locales, NCurses handles 154 (0x9A) symbol properly, while S-Lang
850 * requires SLsmg_Display_Eight_Bit >= 154 (OR manual filtering if xterm display
851 * detected - but checking TERM would fail under screen, OR running xterm
852 * with allowC1Printable).
854 tty_display_8bit (FALSE);
855 #endif
857 /* Default to the standard xterm sequence */
858 if (!xmouse_seq)
860 xmouse_seq = ESC_STR "[M";
863 /* Enable mouse unless explicitly disabled by --nomouse */
864 if (use_mouse_p != MOUSE_DISABLED)
866 const char *color_term = getenv ("COLORTERM");
867 if (strncmp (termvalue, "rxvt", 4) == 0 ||
868 (color_term != NULL && strncmp (color_term, "rxvt", 4) == 0) ||
869 strcmp (termvalue, "Eterm") == 0)
871 use_mouse_p = MOUSE_XTERM_NORMAL_TRACKING;
873 else
875 use_mouse_p = MOUSE_XTERM_BUTTON_EVENT_TRACKING;
881 /* --------------------------------------------------------------------------------------------- */
883 static void
884 setup_mc (void)
886 #ifdef HAVE_SLANG
887 #ifdef HAVE_CHARSET
888 tty_display_8bit (TRUE);
889 #else
890 tty_display_8bit (full_eight_bits != 0);
891 #endif /* HAVE_CHARSET */
892 #else
894 #ifdef HAVE_CHARSET
895 tty_display_8bit (TRUE);
896 #else
897 tty_display_8bit (eight_bit_clean != 0);
898 #endif /* HAVE_CHARSET */
900 #endif
902 #ifdef HAVE_SUBSHELL_SUPPORT
903 if (mc_global.tty.use_subshell)
904 add_select_channel (mc_global.tty.subshell_pty, load_prompt, 0);
905 #endif /* !HAVE_SUBSHELL_SUPPORT */
907 tty_setup_sigwinch (sigwinch_handler);
909 if ((tty_baudrate () < 9600) || tty_is_slow ())
910 verbose = 0;
912 init_xterm_support ();
913 init_mouse ();
916 /* --------------------------------------------------------------------------------------------- */
918 static void
919 setup_dummy_mc (void)
921 char d[MC_MAXPATHLEN];
922 int ret;
924 mc_get_current_wd (d, MC_MAXPATHLEN);
925 setup_mc ();
926 ret = mc_chdir (d);
929 /* --------------------------------------------------------------------------------------------- */
931 static void
932 done_screen (void)
934 if ((quit & SUBSHELL_EXIT) == 0)
935 clr_scr ();
936 tty_reset_shell_mode ();
937 tty_noraw_mode ();
938 tty_keypad (FALSE);
941 /* --------------------------------------------------------------------------------------------- */
943 static void
944 done_mc (void)
946 disable_mouse ();
948 /* Setup shutdown
950 * We sync the profiles since the hotlist may have changed, while
951 * we only change the setup data if we have the auto save feature set
954 save_setup (auto_save_setup, panels_options.auto_save_setup);
955 done_screen ();
957 vfs_stamp_path (vfs_get_current_dir ());
959 if ((current_panel != NULL) && (get_current_type () == view_listing))
960 vfs_stamp_path (current_panel->cwd);
962 if ((other_panel != NULL) && (get_other_type () == view_listing))
963 vfs_stamp_path (other_panel->cwd);
966 /* --------------------------------------------------------------------------------------------- */
968 static void
969 create_panels_and_run_mc (void)
971 midnight_dlg->get_shortcut = midnight_get_shortcut;
972 midnight_dlg->get_title = midnight_get_title;
974 create_panels ();
976 add_widget (midnight_dlg, the_menubar);
977 init_menu ();
979 add_widget (midnight_dlg, get_panel_widget (0));
980 add_widget (midnight_dlg, get_panel_widget (1));
982 add_widget (midnight_dlg, the_hint);
983 add_widget (midnight_dlg, cmdline);
984 add_widget (midnight_dlg, the_prompt);
986 add_widget (midnight_dlg, the_bar);
987 midnight_set_buttonbar (the_bar);
989 /* Run the Midnight Commander if no file was specified in the command line */
990 run_dlg (midnight_dlg);
993 /* --------------------------------------------------------------------------------------------- */
995 /** result must be free'd (I think this should go in util.c) */
996 static char *
997 prepend_cwd_on_local (const char *filename)
999 char *d;
1000 size_t l;
1002 if (!vfs_file_is_local (filename) || g_path_is_absolute (filename))
1003 return g_strdup (filename);
1005 d = g_malloc (MC_MAXPATHLEN + strlen (filename) + 2);
1006 mc_get_current_wd (d, MC_MAXPATHLEN);
1007 l = strlen (d);
1008 d[l++] = PATH_SEP;
1009 strcpy (d + l, filename);
1010 canonicalize_pathname (d);
1011 return d;
1014 /* --------------------------------------------------------------------------------------------- */
1016 /** Invoke the internal view/edit routine with:
1017 * the default processing and forcing the internal viewer/editor
1019 static void
1020 mc_maybe_editor_or_viewer (void)
1022 switch (mc_global.mc_run_mode)
1024 #ifdef USE_INTERNAL_EDIT
1025 case MC_RUN_EDITOR:
1026 edit_file (mc_run_param0, mc_args__edit_start_line);
1027 break;
1028 #endif /* USE_INTERNAL_EDIT */
1029 case MC_RUN_VIEWER:
1031 char *path;
1032 path = prepend_cwd_on_local (mc_run_param0);
1033 view_file (path, 0, 1);
1034 g_free (path);
1035 break;
1037 #ifdef USE_DIFF_VIEW
1038 case MC_RUN_DIFFVIEWER:
1039 diff_view (mc_run_param0, mc_run_param1, mc_run_param0, mc_run_param1);
1040 break;
1041 #endif /* USE_DIFF_VIEW */
1042 default:
1043 break;
1047 /* --------------------------------------------------------------------------------------------- */
1049 static gboolean
1050 quit_cmd_internal (int quiet)
1052 int q = quit;
1053 size_t n;
1055 n = dialog_switch_num () - 1;
1056 if (n != 0)
1058 char msg[BUF_MEDIUM];
1060 g_snprintf (msg, sizeof (msg),
1061 ngettext ("You have %zd opened screen. Quit anyway?",
1062 "You have %zd opened screens. Quit anyway?", n), n);
1064 if (query_dialog (_("The Midnight Commander"), msg, D_NORMAL, 2, _("&Yes"), _("&No")) != 0)
1065 return FALSE;
1066 q = 1;
1068 else if (quiet || !confirm_exit)
1069 q = 1;
1070 else if (query_dialog (_("The Midnight Commander"),
1071 _("Do you really want to quit the Midnight Commander?"),
1072 D_NORMAL, 2, _("&Yes"), _("&No")) == 0)
1073 q = 1;
1075 if (q != 0)
1077 #ifdef HAVE_SUBSHELL_SUPPORT
1078 if (!mc_global.tty.use_subshell)
1079 stop_dialogs ();
1080 else if ((q = exit_subshell ()))
1081 #endif
1082 stop_dialogs ();
1085 if (q != 0)
1086 quit |= 1;
1087 return (quit != 0);
1090 /* --------------------------------------------------------------------------------------------- */
1092 static gboolean
1093 quit_cmd (void)
1095 return quit_cmd_internal (0);
1098 /* --------------------------------------------------------------------------------------------- */
1100 static void
1101 toggle_show_hidden (void)
1103 panels_options.show_dot_files = !panels_options.show_dot_files;
1104 update_panels (UP_RELOAD, UP_KEEPSEL);
1107 /* --------------------------------------------------------------------------------------------- */
1110 * Repaint the contents of the panels without frames. To schedule panel
1111 * for repainting, set panel->dirty to 1. There are many reasons why
1112 * the panels need to be repainted, and this is a costly operation, so
1113 * it's done once per event.
1116 static void
1117 update_dirty_panels (void)
1119 if (get_current_type () == view_listing && current_panel->dirty)
1120 send_message ((Widget *) current_panel, WIDGET_DRAW, 0);
1122 if (get_other_type () == view_listing && other_panel->dirty)
1123 send_message ((Widget *) other_panel, WIDGET_DRAW, 0);
1126 /* --------------------------------------------------------------------------------------------- */
1128 static cb_ret_t
1129 midnight_execute_cmd (Widget * sender, unsigned long command)
1131 cb_ret_t res = MSG_HANDLED;
1133 (void) sender;
1135 /* stop quick search before executing any command */
1136 send_message ((Widget *) current_panel, WIDGET_COMMAND, CK_SearchStop);
1138 switch (command)
1140 case CK_HotListAdd:
1141 add2hotlist_cmd ();
1142 break;
1143 case CK_PanelListingChange:
1144 change_listing_cmd ();
1145 break;
1146 case CK_ChangeMode:
1147 chmod_cmd ();
1148 break;
1149 case CK_ChangeOwn:
1150 chown_cmd ();
1151 break;
1152 case CK_ChangeOwnAdvanced:
1153 chown_advanced_cmd ();
1154 break;
1155 case CK_CompareDirs:
1156 compare_dirs_cmd ();
1157 break;
1158 case CK_Options:
1159 configure_box ();
1160 break;
1161 #ifdef ENABLE_VFS
1162 case CK_OptionsVfs:
1163 configure_vfs ();
1164 break;
1165 #endif
1166 case CK_OptionsConfirm:
1167 confirm_box ();
1168 break;
1169 case CK_Copy:
1170 copy_cmd ();
1171 break;
1172 case CK_PutCurrentPath:
1173 put_current_path ();
1174 break;
1175 case CK_PutCurrentLink:
1176 put_current_link ();
1177 break;
1178 case CK_PutCurrentTagged:
1179 put_current_tagged ();
1180 break;
1181 case CK_PutOtherPath:
1182 put_other_path ();
1183 break;
1184 case CK_PutOtherLink:
1185 put_other_link ();
1186 break;
1187 case CK_PutOtherTagged:
1188 put_other_tagged ();
1189 break;
1190 case CK_Delete:
1191 delete_cmd ();
1192 break;
1193 case CK_ScreenList:
1194 dialog_switch_list ();
1195 break;
1196 #ifdef USE_DIFF_VIEW
1197 case CK_CompareFiles:
1198 diff_view_cmd ();
1199 break;
1200 #endif
1201 case CK_OptionsDisplayBits:
1202 display_bits_box ();
1203 break;
1204 case CK_Edit:
1205 edit_cmd ();
1206 break;
1207 #ifdef USE_INTERNAL_EDIT
1208 case CK_EditForceInternal:
1209 edit_cmd_force_internal ();
1210 break;
1211 #endif
1212 case CK_EditExtensionsFile:
1213 ext_cmd ();
1214 break;
1215 case CK_EditFileHighlightFile:
1216 edit_fhl_cmd ();
1217 break;
1218 case CK_EditUserMenu:
1219 edit_mc_menu_cmd ();
1220 break;
1221 case CK_LinkSymbolicEdit:
1222 edit_symlink_cmd ();
1223 break;
1224 case CK_ExternalPanelize:
1225 external_panelize ();
1226 break;
1227 case CK_Filter:
1228 filter_cmd ();
1229 break;
1230 case CK_ViewFiltered:
1231 view_filtered_cmd ();
1232 break;
1233 case CK_Find:
1234 find_cmd ();
1235 break;
1236 #ifdef ENABLE_VFS_FISH
1237 case CK_ConnectFish:
1238 fishlink_cmd ();
1239 break;
1240 #endif
1241 #ifdef ENABLE_VFS_FTP
1242 case CK_ConnectFtp:
1243 ftplink_cmd ();
1244 break;
1245 #endif
1246 #ifdef ENABLE_VFS_SMB
1247 case CK_ConnectSmb:
1248 smblink_cmd ();
1249 break;
1250 #endif /* ENABLE_VFS_SMB */
1251 case CK_Help:
1252 help_cmd ();
1253 break;
1254 case CK_History:
1255 /* show the history of command line widget */
1256 send_message (&cmdline->widget, WIDGET_COMMAND, CK_History);
1257 break;
1258 case CK_PanelInfo:
1259 if (sender == (Widget *) the_menubar)
1260 info_cmd (); /* menu */
1261 else
1262 info_cmd_no_menu (); /* shortcut or buttonbar */
1263 break;
1264 #ifdef WITH_BACKGROUND
1265 case CK_Jobs:
1266 jobs_cmd ();
1267 break;
1268 #endif
1269 case CK_OptionsLayout:
1270 layout_box ();
1271 break;
1272 case CK_LearnKeys:
1273 learn_keys ();
1274 break;
1275 case CK_Link:
1276 link_cmd (LINK_HARDLINK);
1277 break;
1278 case CK_PanelListing:
1279 listing_cmd ();
1280 break;
1281 #ifdef LISTMODE_EDITOR
1282 case CK_ListMode:
1283 listmode_cmd ();
1284 break;
1285 #endif
1286 case CK_Menu:
1287 menu_cmd ();
1288 break;
1289 case CK_MenuLastSelected:
1290 menu_last_selected_cmd ();
1291 break;
1292 case CK_MakeDir:
1293 mkdir_cmd ();
1294 break;
1295 case CK_OptionsPanel:
1296 panel_options_box ();
1297 break;
1298 #ifdef HAVE_CHARSET
1299 case CK_SelectCodepage:
1300 encoding_cmd ();
1301 break;
1302 #endif
1303 case CK_CdQuick:
1304 quick_cd_cmd ();
1305 break;
1306 case CK_HotList:
1307 hotlist_cmd ();
1308 break;
1309 case CK_PanelQuickView:
1310 if (sender == (Widget *) the_menubar)
1311 quick_view_cmd (); /* menu */
1312 else
1313 quick_cmd_no_menu (); /* shortcut or buttonabr */
1314 break;
1315 case CK_QuitQuiet:
1316 quiet_quit_cmd ();
1317 break;
1318 case CK_Quit:
1319 quit_cmd ();
1320 break;
1321 case CK_LinkSymbolicRelative:
1322 link_cmd (LINK_SYMLINK_RELATIVE);
1323 break;
1324 case CK_Move:
1325 rename_cmd ();
1326 break;
1327 case CK_Reread:
1328 reread_cmd ();
1329 break;
1330 #ifdef ENABLE_VFS
1331 case CK_VfsList:
1332 vfs_list ();
1333 break;
1334 #endif
1335 case CK_SelectInvert:
1336 select_invert_cmd ();
1337 break;
1338 case CK_SaveSetup:
1339 save_setup_cmd ();
1340 break;
1341 case CK_Select:
1342 select_cmd ();
1343 break;
1344 case CK_Shell:
1345 view_other_cmd ();
1346 break;
1347 case CK_DirSize:
1348 smart_dirsize_cmd ();
1349 break;
1350 case CK_Sort:
1351 sort_cmd ();
1352 break;
1353 case CK_ExtendedKeyMap:
1354 ctl_x_cmd ();
1355 break;
1356 case CK_Suspend:
1357 mc_event_raise (MCEVENT_GROUP_CORE, "suspend", NULL);
1358 break;
1359 case CK_Swap:
1360 swap_cmd ();
1361 break;
1362 case CK_LinkSymbolic:
1363 link_cmd (LINK_SYMLINK_ABSOLUTE);
1364 break;
1365 case CK_PanelListingSwitch:
1366 toggle_listing_cmd ();
1367 break;
1368 case CK_ShowHidden:
1369 toggle_show_hidden ();
1370 break;
1371 case CK_SplitVertHoriz:
1372 toggle_panels_split ();
1373 break;
1374 case CK_PanelTree:
1375 panel_tree_cmd ();
1376 break;
1377 case CK_Tree:
1378 treebox_cmd ();
1379 break;
1380 #ifdef ENABLE_VFS_UNDELFS
1381 case CK_Undelete:
1382 undelete_cmd ();
1383 break;
1384 #endif
1385 case CK_Unselect:
1386 unselect_cmd ();
1387 break;
1388 case CK_UserMenu:
1389 user_file_menu_cmd ();
1390 break;
1391 case CK_View:
1392 view_cmd ();
1393 break;
1394 case CK_ViewFile:
1395 view_file_cmd ();
1396 break;
1397 case CK_Cancel:
1398 /* don't close panels due to SIGINT */
1399 break;
1400 default:
1401 res = MSG_NOT_HANDLED;
1404 return res;
1407 /* --------------------------------------------------------------------------------------------- */
1409 static cb_ret_t
1410 midnight_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
1412 unsigned long command;
1414 switch (msg)
1416 case DLG_INIT:
1417 panel_init ();
1418 setup_panels ();
1419 return MSG_HANDLED;
1421 case DLG_DRAW:
1422 load_hint (1);
1423 /* We handle the special case of the output lines */
1424 if (mc_global.tty.console_flag && output_lines)
1425 show_console_contents (output_start_y,
1426 LINES - output_lines - mc_global.keybar_visible -
1427 1, LINES - mc_global.keybar_visible - 1);
1428 return MSG_HANDLED;
1430 case DLG_RESIZE:
1431 setup_panels ();
1432 menubar_arrange (the_menubar);
1433 return MSG_HANDLED;
1435 case DLG_IDLE:
1436 /* We only need the first idle event to show user menu after start */
1437 set_idle_proc (h, 0);
1439 if (boot_current_is_left)
1440 dlg_select_widget (get_panel_widget (0));
1441 else
1442 dlg_select_widget (get_panel_widget (1));
1444 if (auto_menu)
1445 midnight_execute_cmd (NULL, CK_UserMenu);
1446 return MSG_HANDLED;
1448 case DLG_KEY:
1449 if (ctl_x_map_enabled)
1451 ctl_x_map_enabled = FALSE;
1452 command = keybind_lookup_keymap_command (main_x_map, parm);
1453 if (command != CK_IgnoreKey)
1454 return midnight_execute_cmd (NULL, command);
1457 /* FIXME: should handle all menu shortcuts before this point */
1458 if (the_menubar->is_active)
1459 return MSG_NOT_HANDLED;
1461 if (parm == '\t')
1462 input_free_completions (cmdline);
1464 if (parm == '\n')
1466 size_t i;
1468 for (i = 0; cmdline->buffer[i] != '\0' &&
1469 (cmdline->buffer[i] == ' ' || cmdline->buffer[i] == '\t'); i++)
1472 if (cmdline->buffer[i] != '\0')
1474 send_message ((Widget *) cmdline, WIDGET_KEY, parm);
1475 return MSG_HANDLED;
1478 input_insert (cmdline, "", FALSE);
1479 cmdline->point = 0;
1482 /* Ctrl-Enter and Alt-Enter */
1483 if (((parm & ~(KEY_M_CTRL | KEY_M_ALT)) == '\n') && (parm & (KEY_M_CTRL | KEY_M_ALT)))
1485 put_prog_name ();
1486 return MSG_HANDLED;
1489 /* Ctrl-Shift-Enter */
1490 if (parm == (KEY_M_CTRL | KEY_M_SHIFT | '\n'))
1492 put_current_path ();
1493 put_prog_name ();
1494 return MSG_HANDLED;
1497 if ((!alternate_plus_minus || !(mc_global.tty.console_flag || xterm_flag))
1498 && !quote && !current_panel->searching)
1500 if (!only_leading_plus_minus)
1502 /* Special treatement, since the input line will eat them */
1503 if (parm == '+')
1505 select_cmd ();
1506 return MSG_HANDLED;
1509 if (parm == '\\' || parm == '-')
1511 unselect_cmd ();
1512 return MSG_HANDLED;
1515 if (parm == '*')
1517 select_invert_cmd ();
1518 return MSG_HANDLED;
1521 else if (!command_prompt || !cmdline->buffer[0])
1523 /* Special treatement '+', '-', '\', '*' only when this is
1524 * first char on input line
1527 if (parm == '+')
1529 select_cmd ();
1530 return MSG_HANDLED;
1533 if (parm == '\\' || parm == '-')
1535 unselect_cmd ();
1536 return MSG_HANDLED;
1539 if (parm == '*')
1541 select_invert_cmd ();
1542 return MSG_HANDLED;
1546 return MSG_NOT_HANDLED;
1548 case DLG_HOTKEY_HANDLED:
1549 if ((get_current_type () == view_listing) && current_panel->searching)
1551 current_panel->dirty = 1; /* FIXME: unneeded? */
1552 send_message ((Widget *) current_panel, WIDGET_COMMAND, CK_SearchStop);
1554 return MSG_HANDLED;
1556 case DLG_UNHANDLED_KEY:
1557 if (command_prompt)
1559 cb_ret_t v;
1561 v = send_message ((Widget *) cmdline, WIDGET_KEY, parm);
1562 if (v == MSG_HANDLED)
1563 return MSG_HANDLED;
1566 if (ctl_x_map_enabled)
1568 ctl_x_map_enabled = FALSE;
1569 command = keybind_lookup_keymap_command (main_x_map, parm);
1571 else
1572 command = keybind_lookup_keymap_command (main_map, parm);
1574 return (command == CK_IgnoreKey) ? MSG_NOT_HANDLED : midnight_execute_cmd (NULL, command);
1576 case DLG_POST_KEY:
1577 if (!the_menubar->is_active)
1578 update_dirty_panels ();
1579 return MSG_HANDLED;
1581 case DLG_ACTION:
1582 /* shortcut */
1583 if (sender == NULL)
1584 return midnight_execute_cmd (NULL, parm);
1585 /* message from menu */
1586 if (sender == (Widget *) the_menubar)
1587 return midnight_execute_cmd (sender, parm);
1588 /* message from buttonbar */
1589 if (sender == (Widget *) the_bar)
1591 if (data != NULL)
1592 return send_message ((Widget *) data, WIDGET_COMMAND, parm);
1593 return midnight_execute_cmd (sender, parm);
1595 return MSG_NOT_HANDLED;
1597 case DLG_END:
1598 panel_deinit ();
1599 return MSG_HANDLED;
1601 default:
1602 return default_dlg_callback (h, sender, msg, parm, data);
1606 /* --------------------------------------------------------------------------------------------- */
1607 /*** public functions ****************************************************************************/
1608 /* --------------------------------------------------------------------------------------------- */
1610 void
1611 update_menu (void)
1613 menu_set_name (left_menu, horizontal_split ? _("&Above") : _("&Left"));
1614 menu_set_name (right_menu, horizontal_split ? _("&Below") : _("&Right"));
1615 menubar_arrange (the_menubar);
1616 menubar_set_visible (the_menubar, menubar_visible);
1619 void
1620 midnight_set_buttonbar (WButtonBar * b)
1622 buttonbar_set_label (b, 1, Q_ ("ButtonBar|Help"), main_map, NULL);
1623 buttonbar_set_label (b, 2, Q_ ("ButtonBar|Menu"), main_map, NULL);
1624 buttonbar_set_label (b, 3, Q_ ("ButtonBar|View"), main_map, NULL);
1625 buttonbar_set_label (b, 4, Q_ ("ButtonBar|Edit"), main_map, NULL);
1626 buttonbar_set_label (b, 5, Q_ ("ButtonBar|Copy"), main_map, NULL);
1627 buttonbar_set_label (b, 6, Q_ ("ButtonBar|RenMov"), main_map, NULL);
1628 buttonbar_set_label (b, 7, Q_ ("ButtonBar|Mkdir"), main_map, NULL);
1629 buttonbar_set_label (b, 8, Q_ ("ButtonBar|Delete"), main_map, NULL);
1630 buttonbar_set_label (b, 9, Q_ ("ButtonBar|PullDn"), main_map, NULL);
1631 buttonbar_set_label (b, 10, Q_ ("ButtonBar|Quit"), main_map, NULL);
1634 /* --------------------------------------------------------------------------------------------- */
1636 * Load new hint and display it.
1637 * IF force is not 0, ignore the timeout.
1640 void
1641 load_hint (gboolean force)
1643 char *hint;
1645 if (the_hint->widget.owner == NULL)
1646 return;
1648 if (!mc_global.message_visible)
1650 label_set_text (the_hint, NULL);
1651 return;
1654 hint = get_random_hint (force);
1656 if (hint != NULL)
1658 if (*hint != '\0')
1659 set_hintbar (hint);
1660 g_free (hint);
1662 else
1664 char text[BUF_SMALL];
1666 g_snprintf (text, sizeof (text), _("GNU Midnight Commander %s\n"), VERSION);
1667 set_hintbar (text);
1671 /* --------------------------------------------------------------------------------------------- */
1673 void
1674 change_panel (void)
1676 input_free_completions (cmdline);
1677 dlg_one_down (midnight_dlg);
1680 /* --------------------------------------------------------------------------------------------- */
1682 /** Save current stat of directories to avoid reloading the panels
1683 * when no modifications have taken place
1685 void
1686 save_cwds_stat (void)
1688 if (panels_options.fast_reload)
1690 mc_stat (current_panel->cwd, &(current_panel->dir_stat));
1691 if (get_other_type () == view_listing)
1692 mc_stat (other_panel->cwd, &(other_panel->dir_stat));
1696 /* --------------------------------------------------------------------------------------------- */
1698 gboolean
1699 quiet_quit_cmd (void)
1701 print_last_revert = TRUE;
1702 return quit_cmd_internal (1);
1705 /* --------------------------------------------------------------------------------------------- */
1707 /** Run the main dialog that occupies the whole screen */
1708 void
1709 do_nc (void)
1711 dlg_colors_t midnight_colors;
1713 midnight_colors[DLG_COLOR_NORMAL] = mc_skin_color_get ("dialog", "_default_");
1714 midnight_colors[DLG_COLOR_FOCUS] = mc_skin_color_get ("dialog", "focus");
1715 midnight_colors[DLG_COLOR_HOT_NORMAL] = mc_skin_color_get ("dialog", "hotnormal");
1716 midnight_colors[DLG_COLOR_HOT_FOCUS] = mc_skin_color_get ("dialog", "hotfocus");
1717 midnight_colors[DLG_COLOR_TITLE] = mc_skin_color_get ("dialog", "title");
1719 #ifdef USE_INTERNAL_EDIT
1720 edit_stack_init ();
1721 #endif
1723 midnight_dlg = create_dlg (FALSE, 0, 0, LINES, COLS, midnight_colors, midnight_callback,
1724 "[main]", NULL, DLG_WANT_IDLE);
1726 if (mc_global.mc_run_mode == MC_RUN_FULL)
1727 setup_mc ();
1728 else
1729 setup_dummy_mc ();
1731 /* Check if we were invoked as an editor or file viewer */
1732 if (mc_global.mc_run_mode != MC_RUN_FULL)
1733 mc_maybe_editor_or_viewer ();
1734 else
1736 create_panels_and_run_mc ();
1738 /* destroy_dlg destroys even current_panel->cwd, so we have to save a copy :) */
1739 if (mc_args__last_wd_file != NULL && vfs_current_is_local ())
1740 last_wd_string = g_strdup (current_panel->cwd);
1742 /* don't handle VFS timestamps for dirs opened in panels */
1743 mc_event_destroy (MCEVENT_GROUP_CORE, "vfs_timestamp");
1746 /* Program end */
1747 mc_global.widget.midnight_shutdown = TRUE;
1748 dialog_switch_shutdown ();
1749 done_mc ();
1750 destroy_dlg (midnight_dlg);
1751 current_panel = NULL;
1753 #ifdef USE_INTERNAL_EDIT
1754 edit_stack_free ();
1755 #endif
1758 /* --------------------------------------------------------------------------------------------- */