cppcheck: reduce variable scope.
[midnight-commander.git] / src / filemanager / midnight.c
blobf3ba77495a48edac3b1284198bb959e4052de1bf
1 /*
2 Main dialog (file panels) of the Midnight Commander
4 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
5 2003, 2004, 2005, 2006, 2007, 2009, 2010, 2011, 2013
6 The Free Software Foundation, Inc.
8 Written by:
9 Miguel de Icaza, 1994, 1995, 1996, 1997
10 Janne Kukonlehto, 1994, 1995
11 Norbert Warmuth, 1997
12 Andrew Borodin <aborodin@vmail.ru>, 2009, 2010, 2012, 2013
13 Slava Zanko <slavazanko@gmail.com>, 2013
15 This file is part of the Midnight Commander.
17 The Midnight Commander is free software: you can redistribute it
18 and/or modify it under the terms of the GNU General Public License as
19 published by the Free Software Foundation, either version 3 of the License,
20 or (at your option) any later version.
22 The Midnight Commander is distributed in the hope that it will be useful,
23 but WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 GNU General Public License for more details.
27 You should have received a copy of the GNU General Public License
28 along with this program. If not, see <http://www.gnu.org/licenses/>.
31 /** \file main.c
32 * \brief Source: main dialog (file panels) of the Midnight Commander
35 #include <config.h>
37 #include <ctype.h>
38 #include <errno.h>
39 #include <locale.h>
40 #include <stdio.h>
41 #include <stdlib.h>
42 #include <string.h>
43 #include <fcntl.h>
44 #include <sys/types.h>
45 #include <sys/stat.h>
46 #include <sys/wait.h>
47 #include <pwd.h> /* for username in xterm title */
49 #include "lib/global.h"
51 #include "lib/tty/tty.h"
52 #include "lib/tty/key.h" /* KEY_M_* masks */
53 #include "lib/skin.h"
54 #include "lib/util.h"
56 #include "lib/vfs/vfs.h"
58 #include "src/args.h"
59 #ifdef ENABLE_SUBSHELL
60 #include "src/subshell.h"
61 #endif
62 #include "src/setup.h" /* variables */
63 #include "src/learn.h" /* learn_keys() */
64 #include "src/keybind-defaults.h"
65 #include "lib/keybind.h"
66 #include "lib/event.h"
68 #include "tree.h"
69 #include "boxes.h" /* sort_box(), tree_box() */
70 #include "layout.h"
71 #include "cmd.h" /* commands */
72 #include "hotlist.h"
73 #include "panelize.h"
74 #include "command.h" /* cmdline */
75 #include "dir.h" /* dir_list_clean() */
77 #include "chmod.h"
78 #include "chown.h"
79 #include "achown.h"
81 #ifdef USE_INTERNAL_EDIT
82 #include "src/editor/edit.h"
83 #endif
85 #ifdef USE_DIFF_VIEW
86 #include "src/diffviewer/ydiff.h"
87 #endif
89 #include "src/consaver/cons.saver.h" /* show_console_contents */
91 #include "midnight.h"
93 /* TODO: merge content of layout.c here */
94 extern int ok_to_refresh;
96 /*** global variables ****************************************************************************/
98 /* When the modes are active, left_panel, right_panel and tree_panel */
99 /* point to a proper data structure. You should check with the functions */
100 /* get_current_type and get_other_type the types of the panels before using */
101 /* this pointer variables */
103 /* The structures for the panels */
104 WPanel *left_panel = NULL;
105 WPanel *right_panel = NULL;
106 /* Pointer to the selected and unselected panel */
107 WPanel *current_panel = NULL;
109 /* The Menubar */
110 WMenuBar *the_menubar = NULL;
111 /* The widget where we draw the prompt */
112 WLabel *the_prompt;
113 /* The hint bar */
114 WLabel *the_hint;
115 /* The button bar */
116 WButtonBar *the_bar;
118 /* The prompt */
119 const char *mc_prompt = NULL;
121 /*** file scope macro definitions ****************************************************************/
123 #ifdef HAVE_CHARSET
125 * Don't restrict the output on the screen manager level,
126 * the translation tables take care of it.
128 #endif /* !HAVE_CHARSET */
130 /*** file scope type declarations ****************************************************************/
132 /*** file scope variables ************************************************************************/
134 static menu_t *left_menu, *right_menu;
136 static gboolean ctl_x_map_enabled = FALSE;
138 /*** file scope functions ************************************************************************/
140 /** Stop MC main dialog and the current dialog if it exists.
141 * Needed to provide fast exit from MC viewer or editor on shell exit */
142 static void
143 stop_dialogs (void)
145 midnight_dlg->state = DLG_CLOSED;
147 if ((top_dlg != NULL) && (top_dlg->data != NULL))
148 DIALOG (top_dlg->data)->state = DLG_CLOSED;
151 /* --------------------------------------------------------------------------------------------- */
153 static void
154 treebox_cmd (void)
156 char *sel_dir;
158 sel_dir = tree_box (selection (current_panel)->fname);
159 if (sel_dir != NULL)
161 vfs_path_t *sel_vdir;
163 sel_vdir = vfs_path_from_str (sel_dir);
164 do_cd (sel_vdir, cd_exact);
165 vfs_path_free (sel_vdir);
166 g_free (sel_dir);
170 /* --------------------------------------------------------------------------------------------- */
172 #ifdef LISTMODE_EDITOR
173 static void
174 listmode_cmd (void)
176 char *newmode;
178 if (get_current_type () != view_listing)
179 return;
181 newmode = listmode_edit (current_panel->user_format);
182 if (!newmode)
183 return;
185 g_free (current_panel->user_format);
186 current_panel->list_type = list_user;
187 current_panel->user_format = newmode;
188 set_panel_formats (current_panel);
190 do_refresh ();
192 #endif /* LISTMODE_EDITOR */
194 /* --------------------------------------------------------------------------------------------- */
196 static GList *
197 create_panel_menu (void)
199 GList *entries = NULL;
201 entries = g_list_prepend (entries, menu_entry_create (_("File listin&g"), CK_PanelListing));
202 entries = g_list_prepend (entries, menu_entry_create (_("&Quick view"), CK_PanelQuickView));
203 entries = g_list_prepend (entries, menu_entry_create (_("&Info"), CK_PanelInfo));
204 entries = g_list_prepend (entries, menu_entry_create (_("&Tree"), CK_PanelTree));
205 entries = g_list_prepend (entries, menu_separator_create ());
206 entries =
207 g_list_prepend (entries, menu_entry_create (_("&Listing mode..."), CK_PanelListingChange));
208 entries = g_list_prepend (entries, menu_entry_create (_("&Sort order..."), CK_Sort));
209 entries = g_list_prepend (entries, menu_entry_create (_("&Filter..."), CK_Filter));
210 #ifdef HAVE_CHARSET
211 entries = g_list_prepend (entries, menu_entry_create (_("&Encoding..."), CK_SelectCodepage));
212 #endif
213 entries = g_list_prepend (entries, menu_separator_create ());
214 #ifdef ENABLE_VFS_FTP
215 entries = g_list_prepend (entries, menu_entry_create (_("FT&P link..."), CK_ConnectFtp));
216 #endif
217 #ifdef ENABLE_VFS_FISH
218 entries = g_list_prepend (entries, menu_entry_create (_("S&hell link..."), CK_ConnectFish));
219 #endif
220 #ifdef ENABLE_VFS_SFTP
221 entries = g_list_prepend (entries, menu_entry_create (_("S&FTP link..."), CK_ConnectSftp));
222 #endif
223 #ifdef ENABLE_VFS_SMB
224 entries = g_list_prepend (entries, menu_entry_create (_("SM&B link..."), CK_ConnectSmb));
225 #endif
226 entries = g_list_prepend (entries, menu_entry_create (_("Paneli&ze"), CK_Panelize));
227 entries = g_list_prepend (entries, menu_separator_create ());
228 entries = g_list_prepend (entries, menu_entry_create (_("&Rescan"), CK_Reread));
230 return g_list_reverse (entries);
233 /* --------------------------------------------------------------------------------------------- */
235 static GList *
236 create_file_menu (void)
238 GList *entries = NULL;
240 entries = g_list_prepend (entries, menu_entry_create (_("&View"), CK_View));
241 entries = g_list_prepend (entries, menu_entry_create (_("Vie&w file..."), CK_ViewFile));
242 entries = g_list_prepend (entries, menu_entry_create (_("&Filtered view"), CK_ViewFiltered));
243 entries = g_list_prepend (entries, menu_entry_create (_("&Edit"), CK_Edit));
244 entries = g_list_prepend (entries, menu_entry_create (_("&Copy"), CK_Copy));
245 entries = g_list_prepend (entries, menu_entry_create (_("C&hmod"), CK_ChangeMode));
246 entries = g_list_prepend (entries, menu_entry_create (_("&Link"), CK_Link));
247 entries = g_list_prepend (entries, menu_entry_create (_("&Symlink"), CK_LinkSymbolic));
248 entries =
249 g_list_prepend (entries,
250 menu_entry_create (_("Relative symlin&k"), CK_LinkSymbolicRelative));
251 entries = g_list_prepend (entries, menu_entry_create (_("Edit s&ymlink"), CK_LinkSymbolicEdit));
252 entries = g_list_prepend (entries, menu_entry_create (_("Ch&own"), CK_ChangeOwn));
253 entries =
254 g_list_prepend (entries, menu_entry_create (_("&Advanced chown"), CK_ChangeOwnAdvanced));
255 entries = g_list_prepend (entries, menu_entry_create (_("&Rename/Move"), CK_Move));
256 entries = g_list_prepend (entries, menu_entry_create (_("&Mkdir"), CK_MakeDir));
257 entries = g_list_prepend (entries, menu_entry_create (_("&Delete"), CK_Delete));
258 entries = g_list_prepend (entries, menu_entry_create (_("&Quick cd"), CK_CdQuick));
259 entries = g_list_prepend (entries, menu_separator_create ());
260 entries = g_list_prepend (entries, menu_entry_create (_("Select &group"), CK_Select));
261 entries = g_list_prepend (entries, menu_entry_create (_("U&nselect group"), CK_Unselect));
262 entries = g_list_prepend (entries, menu_entry_create (_("&Invert selection"), CK_SelectInvert));
263 entries = g_list_prepend (entries, menu_separator_create ());
264 entries = g_list_prepend (entries, menu_entry_create (_("E&xit"), CK_Quit));
266 return g_list_reverse (entries);
269 /* --------------------------------------------------------------------------------------------- */
271 static GList *
272 create_command_menu (void)
274 /* I know, I'm lazy, but the tree widget when it's not running
275 * as a panel still has some problems, I have not yet finished
276 * the WTree widget port, sorry.
278 GList *entries = NULL;
280 entries = g_list_prepend (entries, menu_entry_create (_("&User menu"), CK_UserMenu));
281 entries = g_list_prepend (entries, menu_entry_create (_("&Directory tree"), CK_Tree));
282 entries = g_list_prepend (entries, menu_entry_create (_("&Find file"), CK_Find));
283 entries = g_list_prepend (entries, menu_entry_create (_("S&wap panels"), CK_Swap));
284 entries = g_list_prepend (entries, menu_entry_create (_("Switch &panels on/off"), CK_Shell));
285 entries =
286 g_list_prepend (entries, menu_entry_create (_("&Compare directories"), CK_CompareDirs));
287 #ifdef USE_DIFF_VIEW
288 entries = g_list_prepend (entries, menu_entry_create (_("C&ompare files"), CK_CompareFiles));
289 #endif
290 entries =
291 g_list_prepend (entries, menu_entry_create (_("E&xternal panelize"), CK_ExternalPanelize));
292 entries = g_list_prepend (entries, menu_entry_create (_("Show directory s&izes"), CK_DirSize));
293 entries = g_list_prepend (entries, menu_separator_create ());
294 entries = g_list_prepend (entries, menu_entry_create (_("Command &history"), CK_History));
295 entries = g_list_prepend (entries, menu_entry_create (_("Di&rectory hotlist"), CK_HotList));
296 #ifdef ENABLE_VFS
297 entries = g_list_prepend (entries, menu_entry_create (_("&Active VFS list"), CK_VfsList));
298 #endif
299 #ifdef ENABLE_BACKGROUND
300 entries = g_list_prepend (entries, menu_entry_create (_("&Background jobs"), CK_Jobs));
301 #endif
302 entries = g_list_prepend (entries, menu_entry_create (_("Screen lis&t"), CK_ScreenList));
303 entries = g_list_prepend (entries, menu_separator_create ());
304 #ifdef ENABLE_VFS_UNDELFS
305 entries =
306 g_list_prepend (entries,
307 menu_entry_create (_("&Undelete files (ext2fs only)"), CK_Undelete));
308 #endif
309 #ifdef LISTMODE_EDITOR
310 entries = g_list_prepend (entries, menu_entry_create (_("&Listing format edit"), CK_ListMode));
311 #endif
312 #if defined (ENABLE_VFS_UNDELFS) || defined (LISTMODE_EDITOR)
313 entries = g_list_prepend (entries, menu_separator_create ());
314 #endif
315 entries =
316 g_list_prepend (entries,
317 menu_entry_create (_("Edit &extension file"), CK_EditExtensionsFile));
318 entries = g_list_prepend (entries, menu_entry_create (_("Edit &menu file"), CK_EditUserMenu));
319 entries =
320 g_list_prepend (entries,
321 menu_entry_create (_("Edit hi&ghlighting group file"),
322 CK_EditFileHighlightFile));
324 return g_list_reverse (entries);
327 /* --------------------------------------------------------------------------------------------- */
329 static GList *
330 create_options_menu (void)
332 GList *entries = NULL;
334 entries = g_list_prepend (entries, menu_entry_create (_("&Configuration..."), CK_Options));
335 entries = g_list_prepend (entries, menu_entry_create (_("&Layout..."), CK_OptionsLayout));
336 entries = g_list_prepend (entries, menu_entry_create (_("&Panel options..."), CK_OptionsPanel));
337 entries =
338 g_list_prepend (entries, menu_entry_create (_("C&onfirmation..."), CK_OptionsConfirm));
339 entries =
340 g_list_prepend (entries, menu_entry_create (_("&Display bits..."), CK_OptionsDisplayBits));
341 entries = g_list_prepend (entries, menu_entry_create (_("Learn &keys..."), CK_LearnKeys));
342 #ifdef ENABLE_VFS
343 entries = g_list_prepend (entries, menu_entry_create (_("&Virtual FS..."), CK_OptionsVfs));
344 #endif
345 entries = g_list_prepend (entries, menu_separator_create ());
346 entries = g_list_prepend (entries, menu_entry_create (_("&Save setup"), CK_SaveSetup));
348 return g_list_reverse (entries);
351 /* --------------------------------------------------------------------------------------------- */
353 static void
354 init_menu (void)
356 left_menu = create_menu ("", create_panel_menu (), "[Left and Right Menus]");
357 menubar_add_menu (the_menubar, left_menu);
358 menubar_add_menu (the_menubar, create_menu (_("&File"), create_file_menu (), "[File Menu]"));
359 menubar_add_menu (the_menubar,
360 create_menu (_("&Command"), create_command_menu (), "[Command Menu]"));
361 menubar_add_menu (the_menubar,
362 create_menu (_("&Options"), create_options_menu (), "[Options Menu]"));
363 right_menu = create_menu ("", create_panel_menu (), "[Left and Right Menus]");
364 menubar_add_menu (the_menubar, right_menu);
365 update_menu ();
368 /* --------------------------------------------------------------------------------------------- */
370 static void
371 menu_last_selected_cmd (void)
373 the_menubar->is_active = TRUE;
374 the_menubar->is_dropped = (drop_menus != 0);
375 the_menubar->previous_widget = dlg_get_current_widget_id (midnight_dlg);
376 dlg_select_widget (the_menubar);
379 /* --------------------------------------------------------------------------------------------- */
381 static void
382 menu_cmd (void)
384 if (the_menubar->is_active)
385 return;
387 if ((get_current_index () == 0) == (current_panel->active != 0))
388 the_menubar->selected = 0;
389 else
390 the_menubar->selected = g_list_length (the_menubar->menu) - 1;
391 menu_last_selected_cmd ();
394 /* --------------------------------------------------------------------------------------------- */
396 static void
397 sort_cmd (void)
399 WPanel *p;
400 const panel_field_t *sort_order;
402 if (!SELECTED_IS_PANEL)
403 return;
405 p = MENU_PANEL;
406 sort_order = sort_box (&p->sort_info, p->sort_field);
407 panel_set_sort_order (p, sort_order);
410 /* --------------------------------------------------------------------------------------------- */
412 static char *
413 midnight_get_shortcut (unsigned long command)
415 const char *ext_map;
416 const char *shortcut = NULL;
418 shortcut = keybind_lookup_keymap_shortcut (main_map, command);
419 if (shortcut != NULL)
420 return g_strdup (shortcut);
422 shortcut = keybind_lookup_keymap_shortcut (panel_map, command);
423 if (shortcut != NULL)
424 return g_strdup (shortcut);
426 ext_map = keybind_lookup_keymap_shortcut (main_map, CK_ExtendedKeyMap);
427 if (ext_map != NULL)
428 shortcut = keybind_lookup_keymap_shortcut (main_x_map, command);
429 if (shortcut != NULL)
430 return g_strdup_printf ("%s %s", ext_map, shortcut);
432 return NULL;
435 /* --------------------------------------------------------------------------------------------- */
437 static char *
438 midnight_get_title (const WDialog * h, size_t len)
440 char *path;
441 char *login;
442 char *p;
444 (void) h;
446 title_path_prepare (&path, &login);
448 p = g_strdup_printf ("%s [%s]:%s", _("Panels:"), login, path);
449 g_free (path);
450 g_free (login);
451 path = g_strdup (str_trunc (p, len - 4));
452 g_free (p);
454 return path;
457 /* --------------------------------------------------------------------------------------------- */
459 static void
460 toggle_panels_split (void)
462 panels_layout.horizontal_split = !panels_layout.horizontal_split;
463 layout_change ();
464 do_refresh ();
467 /* --------------------------------------------------------------------------------------------- */
469 #ifdef 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 const vfs_path_element_t *path_element;
479 path_element = vfs_path_get_by_index (panel->cwd_vpath, -1);
481 if (path_element->class != vclass)
482 return FALSE;
484 if (vfs_getid (panel->cwd_vpath) != id)
485 return FALSE;
487 return TRUE;
490 /* --------------------------------------------------------------------------------------------- */
492 /* event callback */
493 static gboolean
494 check_current_panel_timestamp (const gchar * event_group_name, const gchar * event_name,
495 gpointer init_data, gpointer data)
497 ev_vfs_stamp_create_t *event_data = (ev_vfs_stamp_create_t *) data;
499 (void) event_group_name;
500 (void) event_name;
501 (void) init_data;
503 event_data->ret =
504 check_panel_timestamp (current_panel, get_current_type (), event_data->vclass,
505 event_data->id);
506 return !event_data->ret;
509 /* --------------------------------------------------------------------------------------------- */
511 /* event callback */
512 static gboolean
513 check_other_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 (other_panel, get_other_type (), event_data->vclass, event_data->id);
524 return !event_data->ret;
526 #endif /* ENABLE_VFS */
528 /* --------------------------------------------------------------------------------------------- */
530 /* event callback */
531 static gboolean
532 print_vfs_message (const gchar * event_group_name, const gchar * event_name,
533 gpointer init_data, gpointer data)
535 char str[128];
536 ev_vfs_print_message_t *event_data = (ev_vfs_print_message_t *) data;
538 (void) event_group_name;
539 (void) event_name;
540 (void) init_data;
542 g_vsnprintf (str, sizeof (str), event_data->msg, event_data->ap);
544 if (mc_global.midnight_shutdown)
545 return TRUE;
547 if (!mc_global.message_visible || the_hint == NULL || WIDGET (the_hint)->owner == NULL)
549 int col, row;
551 if (!nice_rotating_dash || (ok_to_refresh <= 0))
552 return TRUE;
554 /* Preserve current cursor position */
555 tty_getyx (&row, &col);
557 tty_gotoyx (0, 0);
558 tty_setcolor (NORMAL_COLOR);
559 tty_print_string (str_fit_to_term (str, COLS - 1, J_LEFT));
561 /* Restore cursor position */
562 tty_gotoyx (row, col);
563 mc_refresh ();
564 return TRUE;
567 if (mc_global.message_visible)
568 set_hintbar (str);
570 return TRUE;
573 /* --------------------------------------------------------------------------------------------- */
575 static void
576 create_panels (void)
578 int current_index, other_index;
579 panel_view_mode_t current_mode, other_mode;
580 char *current_dir, *other_dir;
581 vfs_path_t *original_dir;
584 * Following cases from command line are possible:
585 * 'mc' (no arguments): mc_run_param0 == NULL, mc_run_param1 == NULL
586 * active panel uses current directory
587 * passive panel uses "other_dir" from panels.ini
589 * 'mc dir1 dir2' (two arguments): mc_run_param0 != NULL, mc_run_param1 != NULL
590 * active panel uses mc_run_param0
591 * passive panel uses mc_run_param1
593 * 'mc dir1' (single argument): mc_run_param0 != NULL, mc_run_param1 == NULL
594 * active panel uses mc_run_param0
595 * passive panel uses "other_dir" from panels.ini
598 /* Set up panel directories */
599 if (boot_current_is_left)
601 /* left panel is active */
602 current_index = 0;
603 other_index = 1;
604 current_mode = startup_left_mode;
605 other_mode = startup_right_mode;
607 if (mc_run_param0 == NULL && mc_run_param1 == NULL)
609 /* no arguments */
610 current_dir = NULL; /* assume current dir */
611 other_dir = saved_other_dir; /* from ini */
613 else if (mc_run_param0 != NULL && mc_run_param1 != NULL)
615 /* two arguments */
616 current_dir = (char *) mc_run_param0;
617 other_dir = mc_run_param1;
619 else /* mc_run_param0 != NULL && mc_run_param1 == NULL */
621 /* one argument */
622 current_dir = (char *) mc_run_param0;
623 other_dir = saved_other_dir; /* from ini */
626 else
628 /* right panel is active */
629 current_index = 1;
630 other_index = 0;
631 current_mode = startup_right_mode;
632 other_mode = startup_left_mode;
634 if (mc_run_param0 == NULL && mc_run_param1 == NULL)
636 /* no arguments */
637 current_dir = NULL; /* assume current dir */
638 other_dir = saved_other_dir; /* from ini */
640 else if (mc_run_param0 != NULL && mc_run_param1 != NULL)
642 /* two arguments */
643 current_dir = (char *) mc_run_param0;
644 other_dir = mc_run_param1;
646 else /* mc_run_param0 != NULL && mc_run_param1 == NULL */
648 /* one argument */
649 current_dir = (char *) mc_run_param0;
650 other_dir = saved_other_dir; /* from ini */
654 /* 1. Get current dir */
655 original_dir = vfs_path_clone (vfs_get_raw_current_dir ());
657 /* 2. Create passive panel */
658 if (other_dir != NULL)
660 vfs_path_t *vpath;
662 if (g_path_is_absolute (other_dir))
663 vpath = vfs_path_from_str (other_dir);
664 else
665 vpath = vfs_path_append_new (original_dir, other_dir, (char *) NULL);
666 mc_chdir (vpath);
667 vfs_path_free (vpath);
669 set_display_type (other_index, other_mode);
671 /* 3. Create active panel */
672 if (current_dir == NULL)
673 mc_chdir (original_dir);
674 else
676 vfs_path_t *vpath;
678 if (g_path_is_absolute (current_dir))
679 vpath = vfs_path_from_str (current_dir);
680 else
681 vpath = vfs_path_append_new (original_dir, current_dir, (char *) NULL);
682 mc_chdir (vpath);
683 vfs_path_free (vpath);
685 set_display_type (current_index, current_mode);
687 if (startup_left_mode == view_listing)
688 current_panel = left_panel;
689 else if (right_panel != NULL)
690 current_panel = right_panel;
691 else
692 current_panel = left_panel;
694 vfs_path_free (original_dir);
696 #ifdef ENABLE_VFS
697 mc_event_add (MCEVENT_GROUP_CORE, "vfs_timestamp", check_other_panel_timestamp, NULL, NULL);
698 mc_event_add (MCEVENT_GROUP_CORE, "vfs_timestamp", check_current_panel_timestamp, NULL, NULL);
699 #endif /* ENABLE_VFS */
701 mc_event_add (MCEVENT_GROUP_CORE, "vfs_print_message", print_vfs_message, NULL, NULL);
703 /* Create the nice widgets */
704 cmdline = command_new (0, 0, 0);
705 the_prompt = label_new (0, 0, mc_prompt);
706 the_prompt->transparent = 1;
707 the_bar = buttonbar_new (mc_global.keybar_visible);
709 the_hint = label_new (0, 0, 0);
710 the_hint->transparent = 1;
711 the_hint->auto_adjust_cols = 0;
712 WIDGET (the_hint)->cols = COLS;
714 the_menubar = menubar_new (0, 0, COLS, NULL, menubar_visible);
717 /* --------------------------------------------------------------------------------------------- */
719 static void
720 midnight_put_panel_path (WPanel * panel)
722 vfs_path_t *cwd_vpath;
723 const char *cwd_vpath_str;
725 if (!command_prompt)
726 return;
728 #ifdef HAVE_CHARSET
729 cwd_vpath = remove_encoding_from_path (panel->cwd_vpath);
730 #else
731 cwd_vpath = vfs_path_clone (panel->cwd_vpath);
732 #endif
734 cwd_vpath_str = vfs_path_as_str (cwd_vpath);
736 command_insert (cmdline, cwd_vpath_str, FALSE);
738 if (cwd_vpath_str[strlen (cwd_vpath_str) - 1] != PATH_SEP)
739 command_insert (cmdline, PATH_SEP_STR, FALSE);
741 vfs_path_free (cwd_vpath);
744 /* --------------------------------------------------------------------------------------------- */
746 static void
747 put_link (WPanel * panel)
749 if (!command_prompt)
750 return;
751 if (S_ISLNK (selection (panel)->st.st_mode))
753 char buffer[MC_MAXPATHLEN];
754 vfs_path_t *vpath;
755 int i;
757 vpath = vfs_path_append_new (panel->cwd_vpath, selection (panel)->fname, NULL);
758 i = mc_readlink (vpath, buffer, MC_MAXPATHLEN - 1);
759 vfs_path_free (vpath);
761 if (i > 0)
763 buffer[i] = '\0';
764 command_insert (cmdline, buffer, TRUE);
769 /* --------------------------------------------------------------------------------------------- */
771 static void
772 put_current_link (void)
774 put_link (current_panel);
777 /* --------------------------------------------------------------------------------------------- */
779 static void
780 put_other_link (void)
782 if (get_other_type () == view_listing)
783 put_link (other_panel);
786 /* --------------------------------------------------------------------------------------------- */
788 /** Insert the selected file name into the input line */
789 static void
790 put_prog_name (void)
792 char *tmp;
793 if (!command_prompt)
794 return;
796 if (get_current_type () == view_tree)
798 WTree *tree;
799 vfs_path_t *selected_name;
801 tree = (WTree *) get_panel_widget (get_current_index ());
802 selected_name = tree_selected_name (tree);
803 tmp = g_strdup (vfs_path_as_str (selected_name));
805 else
806 tmp = g_strdup (selection (current_panel)->fname);
808 command_insert (cmdline, tmp, TRUE);
809 g_free (tmp);
812 /* --------------------------------------------------------------------------------------------- */
814 static void
815 put_tagged (WPanel * panel)
817 if (!command_prompt)
818 return;
819 input_disable_update (cmdline);
820 if (panel->marked)
822 int i;
824 for (i = 0; i < panel->dir.len; i++)
826 if (panel->dir.list[i].f.marked)
827 command_insert (cmdline, panel->dir.list[i].fname, TRUE);
830 else
832 command_insert (cmdline, panel->dir.list[panel->selected].fname, TRUE);
834 input_enable_update (cmdline);
837 /* --------------------------------------------------------------------------------------------- */
839 static void
840 put_current_tagged (void)
842 put_tagged (current_panel);
845 /* --------------------------------------------------------------------------------------------- */
847 static void
848 put_other_tagged (void)
850 if (get_other_type () == view_listing)
851 put_tagged (other_panel);
854 /* --------------------------------------------------------------------------------------------- */
856 static void
857 ctl_x_cmd (void)
859 ctl_x_map_enabled = TRUE;
862 /* --------------------------------------------------------------------------------------------- */
864 static void
865 setup_mc (void)
867 #ifdef HAVE_SLANG
868 #ifdef HAVE_CHARSET
869 tty_display_8bit (TRUE);
870 #else
871 tty_display_8bit (mc_global.full_eight_bits != 0);
872 #endif /* HAVE_CHARSET */
874 #else /* HAVE_SLANG */
876 #ifdef HAVE_CHARSET
877 tty_display_8bit (TRUE);
878 #else
879 tty_display_8bit (mc_global.eight_bit_clean != 0);
880 #endif /* HAVE_CHARSET */
881 #endif /* HAVE_SLANG */
883 #ifdef ENABLE_SUBSHELL
884 if (mc_global.tty.use_subshell)
885 add_select_channel (mc_global.tty.subshell_pty, load_prompt, 0);
886 #endif /* !ENABLE_SUBSHELL */
888 if ((tty_baudrate () < 9600) || mc_global.tty.slow_terminal)
889 verbose = 0;
892 /* --------------------------------------------------------------------------------------------- */
894 static void
895 setup_dummy_mc (void)
897 vfs_path_t *vpath;
898 char *d;
899 int ret;
901 d = _vfs_get_cwd ();
902 setup_mc ();
903 vpath = vfs_path_from_str (d);
904 ret = mc_chdir (vpath);
905 (void) ret;
906 vfs_path_free (vpath);
907 g_free (d);
910 /* --------------------------------------------------------------------------------------------- */
912 static void
913 done_mc (void)
915 /* Setup shutdown
917 * We sync the profiles since the hotlist may have changed, while
918 * we only change the setup data if we have the auto save feature set
920 char *curr_dir;
922 save_setup (auto_save_setup, panels_options.auto_save_setup);
924 curr_dir = vfs_get_current_dir ();
925 vfs_stamp_path (curr_dir);
926 g_free (curr_dir);
928 if ((current_panel != NULL) && (get_current_type () == view_listing))
929 vfs_stamp_path (vfs_path_as_str (current_panel->cwd_vpath));
931 if ((other_panel != NULL) && (get_other_type () == view_listing))
932 vfs_stamp_path (vfs_path_as_str (other_panel->cwd_vpath));
935 /* --------------------------------------------------------------------------------------------- */
937 static void
938 create_panels_and_run_mc (void)
940 midnight_dlg->get_shortcut = midnight_get_shortcut;
941 midnight_dlg->get_title = midnight_get_title;
943 create_panels ();
945 add_widget (midnight_dlg, the_menubar);
946 init_menu ();
948 add_widget (midnight_dlg, get_panel_widget (0));
949 add_widget (midnight_dlg, get_panel_widget (1));
951 add_widget (midnight_dlg, the_hint);
952 add_widget (midnight_dlg, cmdline);
953 add_widget (midnight_dlg, the_prompt);
955 add_widget (midnight_dlg, the_bar);
956 midnight_set_buttonbar (the_bar);
958 /* Run the Midnight Commander if no file was specified in the command line */
959 dlg_run (midnight_dlg);
962 /* --------------------------------------------------------------------------------------------- */
964 /** result must be free'd (I think this should go in util.c) */
965 static vfs_path_t *
966 prepend_cwd_on_local (const char *filename)
968 vfs_path_t *vpath;
970 vpath = vfs_path_from_str (filename);
971 if (!vfs_file_is_local (vpath) || g_path_is_absolute (filename))
972 return vpath;
974 vfs_path_free (vpath);
976 return vfs_path_append_new (vfs_get_raw_current_dir (), filename, NULL);
979 /* --------------------------------------------------------------------------------------------- */
981 /** Invoke the internal view/edit routine with:
982 * the default processing and forcing the internal viewer/editor
984 static gboolean
985 mc_maybe_editor_or_viewer (void)
987 gboolean ret;
989 switch (mc_global.mc_run_mode)
991 #ifdef USE_INTERNAL_EDIT
992 case MC_RUN_EDITOR:
993 ret = edit_files ((GList *) mc_run_param0);
994 break;
995 #endif /* USE_INTERNAL_EDIT */
996 case MC_RUN_VIEWER:
998 vfs_path_t *vpath = NULL;
1000 if (mc_run_param0 != NULL && *(char *) mc_run_param0 != '\0')
1001 vpath = prepend_cwd_on_local ((char *) mc_run_param0);
1003 ret = view_file (vpath, 0, 1);
1004 vfs_path_free (vpath);
1005 break;
1007 #ifdef USE_DIFF_VIEW
1008 case MC_RUN_DIFFVIEWER:
1009 ret = dview_diff_cmd (mc_run_param0, mc_run_param1);
1010 break;
1011 #endif /* USE_DIFF_VIEW */
1012 default:
1013 ret = FALSE;
1016 return ret;
1019 /* --------------------------------------------------------------------------------------------- */
1021 static gboolean
1022 quit_cmd_internal (int quiet)
1024 int q = quit;
1025 size_t n;
1027 n = dialog_switch_num () - 1;
1028 if (n != 0)
1030 char msg[BUF_MEDIUM];
1032 g_snprintf (msg, sizeof (msg),
1033 ngettext ("You have %zd opened screen. Quit anyway?",
1034 "You have %zd opened screens. Quit anyway?", n), n);
1036 if (query_dialog (_("The Midnight Commander"), msg, D_NORMAL, 2, _("&Yes"), _("&No")) != 0)
1037 return FALSE;
1038 q = 1;
1040 else if (quiet || !confirm_exit)
1041 q = 1;
1042 else if (query_dialog (_("The Midnight Commander"),
1043 _("Do you really want to quit the Midnight Commander?"),
1044 D_NORMAL, 2, _("&Yes"), _("&No")) == 0)
1045 q = 1;
1047 if (q != 0)
1049 #ifdef ENABLE_SUBSHELL
1050 if (!mc_global.tty.use_subshell)
1051 stop_dialogs ();
1052 else if ((q = exit_subshell ()? 1 : 0) != 0)
1053 #endif
1054 stop_dialogs ();
1057 if (q != 0)
1058 quit |= 1;
1059 return (quit != 0);
1062 /* --------------------------------------------------------------------------------------------- */
1064 static gboolean
1065 quit_cmd (void)
1067 return quit_cmd_internal (0);
1070 /* --------------------------------------------------------------------------------------------- */
1072 static void
1073 toggle_show_hidden (void)
1075 panels_options.show_dot_files = !panels_options.show_dot_files;
1076 update_panels (UP_RELOAD, UP_KEEPSEL);
1079 /* --------------------------------------------------------------------------------------------- */
1082 * Repaint the contents of the panels without frames. To schedule panel
1083 * for repainting, set panel->dirty to 1. There are many reasons why
1084 * the panels need to be repainted, and this is a costly operation, so
1085 * it's done once per event.
1088 static void
1089 update_dirty_panels (void)
1091 if (get_current_type () == view_listing && current_panel->dirty)
1092 widget_redraw (WIDGET (current_panel));
1094 if (get_other_type () == view_listing && other_panel->dirty)
1095 widget_redraw (WIDGET (other_panel));
1098 /* --------------------------------------------------------------------------------------------- */
1100 static cb_ret_t
1101 midnight_execute_cmd (Widget * sender, unsigned long command)
1103 cb_ret_t res = MSG_HANDLED;
1105 (void) sender;
1107 /* stop quick search before executing any command */
1108 send_message (current_panel, NULL, MSG_ACTION, CK_SearchStop, NULL);
1110 switch (command)
1112 case CK_HotListAdd:
1113 add2hotlist_cmd ();
1114 break;
1115 case CK_PanelListingChange:
1116 change_listing_cmd ();
1117 break;
1118 case CK_ChangeMode:
1119 chmod_cmd ();
1120 break;
1121 case CK_ChangeOwn:
1122 chown_cmd ();
1123 break;
1124 case CK_ChangeOwnAdvanced:
1125 chown_advanced_cmd ();
1126 break;
1127 case CK_CompareDirs:
1128 compare_dirs_cmd ();
1129 break;
1130 case CK_Options:
1131 configure_box ();
1132 break;
1133 #ifdef ENABLE_VFS
1134 case CK_OptionsVfs:
1135 configure_vfs ();
1136 break;
1137 #endif
1138 case CK_OptionsConfirm:
1139 confirm_box ();
1140 break;
1141 case CK_Copy:
1142 copy_cmd ();
1143 break;
1144 case CK_PutCurrentPath:
1145 midnight_put_panel_path (current_panel);
1146 break;
1147 case CK_PutCurrentLink:
1148 put_current_link ();
1149 break;
1150 case CK_PutCurrentTagged:
1151 put_current_tagged ();
1152 break;
1153 case CK_PutOtherPath:
1154 if (get_other_type () == view_listing)
1155 midnight_put_panel_path (other_panel);
1156 break;
1157 case CK_PutOtherLink:
1158 put_other_link ();
1159 break;
1160 case CK_PutOtherTagged:
1161 put_other_tagged ();
1162 break;
1163 case CK_Delete:
1164 delete_cmd ();
1165 break;
1166 case CK_ScreenList:
1167 dialog_switch_list ();
1168 break;
1169 #ifdef USE_DIFF_VIEW
1170 case CK_CompareFiles:
1171 diff_view_cmd ();
1172 break;
1173 #endif
1174 case CK_OptionsDisplayBits:
1175 display_bits_box ();
1176 break;
1177 case CK_Edit:
1178 edit_cmd ();
1179 break;
1180 #ifdef USE_INTERNAL_EDIT
1181 case CK_EditForceInternal:
1182 edit_cmd_force_internal ();
1183 break;
1184 #endif
1185 case CK_EditExtensionsFile:
1186 ext_cmd ();
1187 break;
1188 case CK_EditFileHighlightFile:
1189 edit_fhl_cmd ();
1190 break;
1191 case CK_EditUserMenu:
1192 edit_mc_menu_cmd ();
1193 break;
1194 case CK_LinkSymbolicEdit:
1195 edit_symlink_cmd ();
1196 break;
1197 case CK_ExternalPanelize:
1198 external_panelize ();
1199 break;
1200 case CK_Filter:
1201 filter_cmd ();
1202 break;
1203 case CK_ViewFiltered:
1204 view_filtered_cmd ();
1205 break;
1206 case CK_Find:
1207 find_cmd ();
1208 break;
1209 #ifdef ENABLE_VFS_FISH
1210 case CK_ConnectFish:
1211 fishlink_cmd ();
1212 break;
1213 #endif
1214 #ifdef ENABLE_VFS_FTP
1215 case CK_ConnectFtp:
1216 ftplink_cmd ();
1217 break;
1218 #endif
1219 #ifdef ENABLE_VFS_SFTP
1220 case CK_ConnectSftp:
1221 sftplink_cmd ();
1222 break;
1223 #endif
1224 #ifdef ENABLE_VFS_SMB
1225 case CK_ConnectSmb:
1226 smblink_cmd ();
1227 break;
1228 #endif /* ENABLE_VFS_SMB */
1229 case CK_Panelize:
1230 cd_panelize_cmd ();
1231 break;
1232 case CK_Help:
1233 help_cmd ();
1234 break;
1235 case CK_History:
1236 /* show the history of command line widget */
1237 send_message (cmdline, NULL, MSG_ACTION, CK_History, NULL);
1238 break;
1239 case CK_PanelInfo:
1240 if (sender == WIDGET (the_menubar))
1241 info_cmd (); /* menu */
1242 else
1243 info_cmd_no_menu (); /* shortcut or buttonbar */
1244 break;
1245 #ifdef ENABLE_BACKGROUND
1246 case CK_Jobs:
1247 jobs_cmd ();
1248 break;
1249 #endif
1250 case CK_OptionsLayout:
1251 layout_box ();
1252 break;
1253 case CK_LearnKeys:
1254 learn_keys ();
1255 break;
1256 case CK_Link:
1257 link_cmd (LINK_HARDLINK);
1258 break;
1259 case CK_PanelListing:
1260 listing_cmd ();
1261 break;
1262 #ifdef LISTMODE_EDITOR
1263 case CK_ListMode:
1264 listmode_cmd ();
1265 break;
1266 #endif
1267 case CK_Menu:
1268 menu_cmd ();
1269 break;
1270 case CK_MenuLastSelected:
1271 menu_last_selected_cmd ();
1272 break;
1273 case CK_MakeDir:
1274 mkdir_cmd ();
1275 break;
1276 case CK_OptionsPanel:
1277 panel_options_box ();
1278 break;
1279 #ifdef HAVE_CHARSET
1280 case CK_SelectCodepage:
1281 encoding_cmd ();
1282 break;
1283 #endif
1284 case CK_CdQuick:
1285 quick_cd_cmd ();
1286 break;
1287 case CK_HotList:
1288 hotlist_cmd ();
1289 break;
1290 case CK_PanelQuickView:
1291 if (sender == WIDGET (the_menubar))
1292 quick_view_cmd (); /* menu */
1293 else
1294 quick_cmd_no_menu (); /* shortcut or buttonabr */
1295 break;
1296 case CK_QuitQuiet:
1297 quiet_quit_cmd ();
1298 break;
1299 case CK_Quit:
1300 quit_cmd ();
1301 break;
1302 case CK_LinkSymbolicRelative:
1303 link_cmd (LINK_SYMLINK_RELATIVE);
1304 break;
1305 case CK_Move:
1306 rename_cmd ();
1307 break;
1308 case CK_Reread:
1309 reread_cmd ();
1310 break;
1311 #ifdef ENABLE_VFS
1312 case CK_VfsList:
1313 vfs_list ();
1314 break;
1315 #endif
1316 case CK_SelectInvert:
1317 select_invert_cmd ();
1318 break;
1319 case CK_SaveSetup:
1320 save_setup_cmd ();
1321 break;
1322 case CK_Select:
1323 select_cmd ();
1324 break;
1325 case CK_Shell:
1326 view_other_cmd ();
1327 break;
1328 case CK_DirSize:
1329 smart_dirsize_cmd ();
1330 break;
1331 case CK_Sort:
1332 sort_cmd ();
1333 break;
1334 case CK_ExtendedKeyMap:
1335 ctl_x_cmd ();
1336 break;
1337 case CK_Suspend:
1338 mc_event_raise (MCEVENT_GROUP_CORE, "suspend", NULL);
1339 break;
1340 case CK_Swap:
1341 swap_cmd ();
1342 break;
1343 case CK_LinkSymbolic:
1344 link_cmd (LINK_SYMLINK_ABSOLUTE);
1345 break;
1346 case CK_PanelListingSwitch:
1347 toggle_listing_cmd ();
1348 break;
1349 case CK_ShowHidden:
1350 toggle_show_hidden ();
1351 break;
1352 case CK_SplitVertHoriz:
1353 toggle_panels_split ();
1354 break;
1355 case CK_SplitEqual:
1356 panels_split_equal ();
1357 break;
1358 case CK_SplitMore:
1359 panels_split_more ();
1360 break;
1361 case CK_SplitLess:
1362 panels_split_less ();
1363 break;
1364 case CK_PanelTree:
1365 panel_tree_cmd ();
1366 break;
1367 case CK_Tree:
1368 treebox_cmd ();
1369 break;
1370 #ifdef ENABLE_VFS_UNDELFS
1371 case CK_Undelete:
1372 undelete_cmd ();
1373 break;
1374 #endif
1375 case CK_Unselect:
1376 unselect_cmd ();
1377 break;
1378 case CK_UserMenu:
1379 user_file_menu_cmd ();
1380 break;
1381 case CK_View:
1382 view_cmd ();
1383 break;
1384 case CK_ViewFile:
1385 view_file_cmd ();
1386 break;
1387 case CK_Cancel:
1388 /* don't close panels due to SIGINT */
1389 break;
1390 default:
1391 res = MSG_NOT_HANDLED;
1394 return res;
1397 /* --------------------------------------------------------------------------------------------- */
1399 static cb_ret_t
1400 midnight_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
1402 unsigned long command;
1404 switch (msg)
1406 case MSG_INIT:
1407 panel_init ();
1408 setup_panels ();
1409 return MSG_HANDLED;
1411 case MSG_DRAW:
1412 load_hint (1);
1413 /* We handle the special case of the output lines */
1414 if (mc_global.tty.console_flag != '\0' && output_lines)
1415 show_console_contents (output_start_y,
1416 LINES - output_lines - mc_global.keybar_visible -
1417 1, LINES - mc_global.keybar_visible - 1);
1418 return MSG_HANDLED;
1420 case MSG_RESIZE:
1421 /* dlg_set_size() is surplus for this case */
1422 w->lines = LINES;
1423 w->cols = COLS;
1424 setup_panels ();
1425 menubar_arrange (the_menubar);
1426 return MSG_HANDLED;
1428 case MSG_IDLE:
1429 /* We only need the first idle event to show user menu after start */
1430 widget_want_idle (w, FALSE);
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 MSG_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 (cmdline, NULL, MSG_KEY, parm, NULL);
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 midnight_put_panel_path (current_panel);
1486 put_prog_name ();
1487 return MSG_HANDLED;
1490 if ((!mc_global.tty.alternate_plus_minus
1491 || !(mc_global.tty.console_flag != '\0' || mc_global.tty.xterm_flag)) && !quote
1492 && !current_panel->searching)
1494 if (!only_leading_plus_minus)
1496 /* Special treatement, since the input line will eat them */
1497 if (parm == '+')
1499 select_cmd ();
1500 return MSG_HANDLED;
1503 if (parm == '\\' || parm == '-')
1505 unselect_cmd ();
1506 return MSG_HANDLED;
1509 if (parm == '*')
1511 select_invert_cmd ();
1512 return MSG_HANDLED;
1515 else if (!command_prompt || !cmdline->buffer[0])
1517 /* Special treatement '+', '-', '\', '*' only when this is
1518 * first char on input line
1521 if (parm == '+')
1523 select_cmd ();
1524 return MSG_HANDLED;
1527 if (parm == '\\' || parm == '-')
1529 unselect_cmd ();
1530 return MSG_HANDLED;
1533 if (parm == '*')
1535 select_invert_cmd ();
1536 return MSG_HANDLED;
1540 return MSG_NOT_HANDLED;
1542 case MSG_HOTKEY_HANDLED:
1543 if ((get_current_type () == view_listing) && current_panel->searching)
1545 current_panel->dirty = 1; /* FIXME: unneeded? */
1546 send_message (current_panel, NULL, MSG_ACTION, CK_SearchStop, NULL);
1548 return MSG_HANDLED;
1550 case MSG_UNHANDLED_KEY:
1552 cb_ret_t v = MSG_NOT_HANDLED;
1554 if (ctl_x_map_enabled)
1556 ctl_x_map_enabled = FALSE;
1557 command = keybind_lookup_keymap_command (main_x_map, parm);
1559 else
1560 command = keybind_lookup_keymap_command (main_map, parm);
1562 if (command != CK_IgnoreKey)
1563 v = midnight_execute_cmd (NULL, command);
1565 if (v == MSG_NOT_HANDLED && command_prompt)
1566 v = send_message (cmdline, NULL, MSG_KEY, parm, NULL);
1568 return v;
1571 case MSG_POST_KEY:
1572 if (!the_menubar->is_active)
1573 update_dirty_panels ();
1574 return MSG_HANDLED;
1576 case MSG_ACTION:
1577 /* shortcut */
1578 if (sender == NULL)
1579 return midnight_execute_cmd (NULL, parm);
1580 /* message from menu */
1581 if (sender == WIDGET (the_menubar))
1582 return midnight_execute_cmd (sender, parm);
1583 /* message from buttonbar */
1584 if (sender == WIDGET (the_bar))
1586 if (data != NULL)
1587 return send_message (data, NULL, MSG_ACTION, parm, NULL);
1588 return midnight_execute_cmd (sender, parm);
1590 return MSG_NOT_HANDLED;
1592 case MSG_END:
1593 panel_deinit ();
1594 return MSG_HANDLED;
1596 default:
1597 return dlg_default_callback (w, sender, msg, parm, data);
1601 /* --------------------------------------------------------------------------------------------- */
1603 static int
1604 midnight_event (Gpm_Event * event, void *data)
1606 Widget *wh = WIDGET (data);
1607 int ret = MOU_UNHANDLED;
1609 if (event->y == wh->y + 1)
1611 /* menubar */
1612 if (menubar_visible || the_menubar->is_active)
1613 ret = WIDGET (the_menubar)->mouse (event, the_menubar);
1614 else
1616 Widget *w;
1618 w = get_panel_widget (0);
1619 if (w->mouse != NULL)
1620 ret = w->mouse (event, w);
1622 if (ret == MOU_UNHANDLED)
1624 w = get_panel_widget (1);
1625 if (w->mouse != NULL)
1626 ret = w->mouse (event, w);
1629 if (ret == MOU_UNHANDLED)
1630 ret = WIDGET (the_menubar)->mouse (event, the_menubar);
1634 return ret;
1637 /* --------------------------------------------------------------------------------------------- */
1638 /*** public functions ****************************************************************************/
1639 /* --------------------------------------------------------------------------------------------- */
1641 void
1642 update_menu (void)
1644 menu_set_name (left_menu, panels_layout.horizontal_split ? _("&Above") : _("&Left"));
1645 menu_set_name (right_menu, panels_layout.horizontal_split ? _("&Below") : _("&Right"));
1646 menubar_arrange (the_menubar);
1647 menubar_set_visible (the_menubar, menubar_visible);
1650 /* --------------------------------------------------------------------------------------------- */
1652 void
1653 midnight_set_buttonbar (WButtonBar * b)
1655 buttonbar_set_label (b, 1, Q_ ("ButtonBar|Help"), main_map, NULL);
1656 buttonbar_set_label (b, 2, Q_ ("ButtonBar|Menu"), main_map, NULL);
1657 buttonbar_set_label (b, 3, Q_ ("ButtonBar|View"), main_map, NULL);
1658 buttonbar_set_label (b, 4, Q_ ("ButtonBar|Edit"), main_map, NULL);
1659 buttonbar_set_label (b, 5, Q_ ("ButtonBar|Copy"), main_map, NULL);
1660 buttonbar_set_label (b, 6, Q_ ("ButtonBar|RenMov"), main_map, NULL);
1661 buttonbar_set_label (b, 7, Q_ ("ButtonBar|Mkdir"), main_map, NULL);
1662 buttonbar_set_label (b, 8, Q_ ("ButtonBar|Delete"), main_map, NULL);
1663 buttonbar_set_label (b, 9, Q_ ("ButtonBar|PullDn"), main_map, NULL);
1664 buttonbar_set_label (b, 10, Q_ ("ButtonBar|Quit"), main_map, NULL);
1667 /* --------------------------------------------------------------------------------------------- */
1669 * Load new hint and display it.
1670 * IF force is not 0, ignore the timeout.
1673 void
1674 load_hint (gboolean force)
1676 char *hint;
1678 if (WIDGET (the_hint)->owner == NULL)
1679 return;
1681 if (!mc_global.message_visible)
1683 label_set_text (the_hint, NULL);
1684 return;
1687 hint = get_random_hint (force);
1689 if (hint != NULL)
1691 if (*hint != '\0')
1692 set_hintbar (hint);
1693 g_free (hint);
1695 else
1697 char text[BUF_SMALL];
1699 g_snprintf (text, sizeof (text), _("GNU Midnight Commander %s\n"), VERSION);
1700 set_hintbar (text);
1704 /* --------------------------------------------------------------------------------------------- */
1706 void
1707 change_panel (void)
1709 input_free_completions (cmdline);
1710 dlg_one_down (midnight_dlg);
1713 /* --------------------------------------------------------------------------------------------- */
1715 /** Save current stat of directories to avoid reloading the panels
1716 * when no modifications have taken place
1718 void
1719 save_cwds_stat (void)
1721 if (panels_options.fast_reload)
1723 mc_stat (current_panel->cwd_vpath, &(current_panel->dir_stat));
1724 if (get_other_type () == view_listing)
1725 mc_stat (other_panel->cwd_vpath, &(other_panel->dir_stat));
1729 /* --------------------------------------------------------------------------------------------- */
1731 gboolean
1732 quiet_quit_cmd (void)
1734 print_last_revert = TRUE;
1735 return quit_cmd_internal (1);
1738 /* --------------------------------------------------------------------------------------------- */
1740 /** Run the main dialog that occupies the whole screen */
1741 gboolean
1742 do_nc (void)
1744 gboolean ret;
1746 dlg_colors_t midnight_colors;
1748 midnight_colors[DLG_COLOR_NORMAL] = mc_skin_color_get ("dialog", "_default_");
1749 midnight_colors[DLG_COLOR_FOCUS] = mc_skin_color_get ("dialog", "focus");
1750 midnight_colors[DLG_COLOR_HOT_NORMAL] = mc_skin_color_get ("dialog", "hotnormal");
1751 midnight_colors[DLG_COLOR_HOT_FOCUS] = mc_skin_color_get ("dialog", "hotfocus");
1752 midnight_colors[DLG_COLOR_TITLE] = mc_skin_color_get ("dialog", "title");
1754 #ifdef USE_INTERNAL_EDIT
1755 edit_stack_init ();
1756 #endif
1758 midnight_dlg = dlg_create (FALSE, 0, 0, LINES, COLS, midnight_colors, midnight_callback,
1759 midnight_event, "[main]", NULL, DLG_NONE);
1761 /* Check if we were invoked as an editor or file viewer */
1762 if (mc_global.mc_run_mode != MC_RUN_FULL)
1764 setup_dummy_mc ();
1765 ret = mc_maybe_editor_or_viewer ();
1767 else
1769 /* We only need the first idle event to show user menu after start */
1770 widget_want_idle (WIDGET (midnight_dlg), TRUE);
1772 setup_mc ();
1773 mc_filehighlight = mc_fhl_new (TRUE);
1774 create_panels_and_run_mc ();
1775 mc_fhl_free (&mc_filehighlight);
1777 ret = TRUE;
1779 /* dlg_destroy destroys even current_panel->cwd_vpath, so we have to save a copy :) */
1780 if (mc_args__last_wd_file != NULL && vfs_current_is_local ())
1781 last_wd_string = g_strdup (vfs_path_as_str (current_panel->cwd_vpath));
1783 /* don't handle VFS timestamps for dirs opened in panels */
1784 mc_event_destroy (MCEVENT_GROUP_CORE, "vfs_timestamp");
1786 dir_list_clean (&panelized_panel.list);
1789 /* Program end */
1790 mc_global.midnight_shutdown = TRUE;
1791 dialog_switch_shutdown ();
1792 done_mc ();
1793 dlg_destroy (midnight_dlg);
1794 current_panel = NULL;
1796 #ifdef USE_INTERNAL_EDIT
1797 edit_stack_free ();
1798 #endif
1800 if ((quit & SUBSHELL_EXIT) == 0)
1801 clr_scr ();
1803 return ret;
1806 /* --------------------------------------------------------------------------------------------- */