Ticket #2944: code cleanup before 4.8.8 release.
[midnight-commander.git] / src / filemanager / midnight.c
blob7d1f2a26be6f07ea085e3de95a9ed56d9d49fd30
1 /*
2 Main dialog (file panels) of the Midnight Commander
4 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
5 2003, 2004, 2005, 2006, 2007, 2009, 2010, 2011
6 The Free Software Foundation, Inc.
8 Written by:
9 Miguel de Icaza, 1994, 1995, 1996, 1997
10 Janne Kukonlehto, 1994, 1995
11 Norbert Warmuth, 1997
12 Andrew Borodin <aborodin@vmail.ru>, 2009, 2010
14 This file is part of the Midnight Commander.
16 The Midnight Commander is free software: you can redistribute it
17 and/or modify it under the terms of the GNU General Public License as
18 published by the Free Software Foundation, either version 3 of the License,
19 or (at your option) any later version.
21 The Midnight Commander is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program. If not, see <http://www.gnu.org/licenses/>.
30 /** \file main.c
31 * \brief Source: main dialog (file panels) of the Midnight Commander
34 #include <config.h>
36 #include <ctype.h>
37 #include <errno.h>
38 #include <locale.h>
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <string.h>
42 #include <fcntl.h>
43 #include <sys/types.h>
44 #include <sys/stat.h>
45 #include <sys/wait.h>
46 #include <pwd.h> /* for username in xterm title */
48 #include "lib/global.h"
50 #include "lib/tty/tty.h"
51 #include "lib/tty/key.h" /* KEY_M_* masks */
52 #include "lib/skin.h"
53 #include "lib/util.h"
55 #include "lib/vfs/vfs.h"
57 #include "src/args.h"
58 #ifdef ENABLE_SUBSHELL
59 #include "src/subshell.h"
60 #endif
61 #include "src/setup.h" /* variables */
62 #include "src/learn.h" /* learn_keys() */
63 #include "src/keybind-defaults.h"
64 #include "lib/keybind.h"
65 #include "lib/event.h"
67 #include "option.h" /* configure_box() */
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" /* clean_dir() */
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);
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;
583 if (boot_current_is_left)
585 /* left panel is active */
586 current_index = 0;
587 other_index = 1;
588 current_mode = startup_left_mode;
589 other_mode = startup_right_mode;
590 /* if mc_run_param0 is NULL, working directory will be used for the left panel */
591 current_dir = (char *) mc_run_param0;
592 /* mc_run_param1 is never NULL. It is setup from command line or from panels.ini
593 * (value of other_dir). mc_run_param1 will be used for the right panel */
594 other_dir = mc_run_param1;
596 else
598 /* right panel is active */
599 current_index = 1;
600 other_index = 0;
601 current_mode = startup_right_mode;
602 other_mode = startup_left_mode;
604 /* if mc_run_param0 is not NULL (it was setup from command line), it will be used
605 * for the left panel, working directory will be used for the right one;
606 * if mc_run_param0 is NULL, working directory will be used for the right (active) panel,
607 * mc_run_param1 will be used for the left one */
608 if (mc_run_param0 != NULL)
610 current_dir = NULL;
611 other_dir = (char *) mc_run_param0;
613 else
615 current_dir = NULL;
616 other_dir = mc_run_param1;
620 /* 1. Get current dir */
621 original_dir = vfs_path_clone (vfs_get_raw_current_dir ());
623 /* 2. Create passive panel */
624 if (other_dir != NULL)
626 vfs_path_t *vpath;
628 if (g_path_is_absolute (other_dir))
629 vpath = vfs_path_from_str (other_dir);
630 else
631 vpath = vfs_path_append_new (original_dir, other_dir, (char *) NULL);
632 mc_chdir (vpath);
633 vfs_path_free (vpath);
635 set_display_type (other_index, other_mode);
637 /* 3. Create active panel */
638 if (current_dir == NULL)
639 mc_chdir (original_dir);
640 else
642 vfs_path_t *vpath;
644 if (g_path_is_absolute (current_dir))
645 vpath = vfs_path_from_str (current_dir);
646 else
647 vpath = vfs_path_append_new (original_dir, current_dir, (char *) NULL);
648 mc_chdir (vpath);
649 vfs_path_free (vpath);
651 set_display_type (current_index, current_mode);
653 if (startup_left_mode == view_listing)
654 current_panel = left_panel;
655 else if (right_panel != NULL)
656 current_panel = right_panel;
657 else
658 current_panel = left_panel;
660 vfs_path_free (original_dir);
662 #ifdef ENABLE_VFS
663 mc_event_add (MCEVENT_GROUP_CORE, "vfs_timestamp", check_other_panel_timestamp, NULL, NULL);
664 mc_event_add (MCEVENT_GROUP_CORE, "vfs_timestamp", check_current_panel_timestamp, NULL, NULL);
665 #endif /* ENABLE_VFS */
667 mc_event_add (MCEVENT_GROUP_CORE, "vfs_print_message", print_vfs_message, NULL, NULL);
669 /* Create the nice widgets */
670 cmdline = command_new (0, 0, 0);
671 the_prompt = label_new (0, 0, mc_prompt);
672 the_prompt->transparent = 1;
673 the_bar = buttonbar_new (mc_global.keybar_visible);
675 the_hint = label_new (0, 0, 0);
676 the_hint->transparent = 1;
677 the_hint->auto_adjust_cols = 0;
678 WIDGET (the_hint)->cols = COLS;
680 the_menubar = menubar_new (0, 0, COLS, NULL);
683 /* --------------------------------------------------------------------------------------------- */
685 static void
686 put_current_path (void)
688 char *cwd_path;
690 if (!command_prompt)
691 return;
693 #ifdef HAVE_CHARSET
695 vfs_path_t *cwd_vpath;
697 cwd_vpath = remove_encoding_from_path (current_panel->cwd_vpath);
698 cwd_path = vfs_path_to_str (cwd_vpath);
699 vfs_path_free (cwd_vpath);
701 #else
702 cwd_path = vfs_path_to_str (current_panel->cwd_vpath);
703 #endif
705 command_insert (cmdline, cwd_path, FALSE);
706 if (cwd_path[strlen (cwd_path) - 1] != PATH_SEP)
707 command_insert (cmdline, PATH_SEP_STR, FALSE);
709 g_free (cwd_path);
712 /* --------------------------------------------------------------------------------------------- */
714 static void
715 put_other_path (void)
717 char *cwd_path;
719 if (get_other_type () != view_listing)
720 return;
722 if (!command_prompt)
723 return;
725 #ifdef HAVE_CHARSET
727 vfs_path_t *cwd_vpath;
729 cwd_vpath = remove_encoding_from_path (other_panel->cwd_vpath);
730 cwd_path = vfs_path_to_str (cwd_vpath);
731 vfs_path_free (cwd_vpath);
733 #else
734 cwd_path = vfs_path_to_str (other_panel->cwd_vpath);
735 #endif
737 command_insert (cmdline, cwd_path, FALSE);
738 if (cwd_path[strlen (cwd_path) - 1] != PATH_SEP)
739 command_insert (cmdline, PATH_SEP_STR, FALSE);
741 g_free (cwd_path);
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 = (WTree *) get_panel_widget (get_current_index ());
800 tmp = vfs_path_to_str (tree_selected_name (tree));
802 else
803 tmp = g_strdup (selection (current_panel)->fname);
805 command_insert (cmdline, tmp, TRUE);
806 g_free (tmp);
809 /* --------------------------------------------------------------------------------------------- */
811 static void
812 put_tagged (WPanel * panel)
814 int i;
816 if (!command_prompt)
817 return;
818 input_disable_update (cmdline);
819 if (panel->marked)
821 for (i = 0; i < panel->count; i++)
823 if (panel->dir.list[i].f.marked)
824 command_insert (cmdline, panel->dir.list[i].fname, TRUE);
827 else
829 command_insert (cmdline, panel->dir.list[panel->selected].fname, TRUE);
831 input_enable_update (cmdline);
834 /* --------------------------------------------------------------------------------------------- */
836 static void
837 put_current_tagged (void)
839 put_tagged (current_panel);
842 /* --------------------------------------------------------------------------------------------- */
844 static void
845 put_other_tagged (void)
847 if (get_other_type () == view_listing)
848 put_tagged (other_panel);
851 /* --------------------------------------------------------------------------------------------- */
853 static void
854 ctl_x_cmd (void)
856 ctl_x_map_enabled = TRUE;
859 /* --------------------------------------------------------------------------------------------- */
861 static void
862 setup_mc (void)
864 #ifdef HAVE_SLANG
865 #ifdef HAVE_CHARSET
866 tty_display_8bit (TRUE);
867 #else
868 tty_display_8bit (mc_global.full_eight_bits != 0);
869 #endif /* HAVE_CHARSET */
871 #else /* HAVE_SLANG */
873 #ifdef HAVE_CHARSET
874 tty_display_8bit (TRUE);
875 #else
876 tty_display_8bit (mc_global.eight_bit_clean != 0);
877 #endif /* HAVE_CHARSET */
878 #endif /* HAVE_SLANG */
880 #ifdef ENABLE_SUBSHELL
881 if (mc_global.tty.use_subshell)
882 add_select_channel (mc_global.tty.subshell_pty, load_prompt, 0);
883 #endif /* !ENABLE_SUBSHELL */
885 if ((tty_baudrate () < 9600) || mc_global.tty.slow_terminal)
886 verbose = 0;
889 /* --------------------------------------------------------------------------------------------- */
891 static void
892 setup_dummy_mc (void)
894 vfs_path_t *vpath;
895 char *d;
896 int ret;
898 d = _vfs_get_cwd ();
899 setup_mc ();
900 vpath = vfs_path_from_str (d);
901 ret = mc_chdir (vpath);
902 vfs_path_free (vpath);
903 g_free (d);
906 /* --------------------------------------------------------------------------------------------- */
908 static void
909 done_mc (void)
911 /* Setup shutdown
913 * We sync the profiles since the hotlist may have changed, while
914 * we only change the setup data if we have the auto save feature set
916 char *curr_dir;
918 save_setup (auto_save_setup, panels_options.auto_save_setup);
920 curr_dir = vfs_get_current_dir ();
921 vfs_stamp_path (curr_dir);
922 g_free (curr_dir);
924 if ((current_panel != NULL) && (get_current_type () == view_listing))
926 char *tmp_path;
928 tmp_path = vfs_path_to_str (current_panel->cwd_vpath);
929 vfs_stamp_path (tmp_path);
930 g_free (tmp_path);
933 if ((other_panel != NULL) && (get_other_type () == view_listing))
935 char *tmp_path;
937 tmp_path = vfs_path_to_str (other_panel->cwd_vpath);
938 vfs_stamp_path (tmp_path);
939 g_free (tmp_path);
943 /* --------------------------------------------------------------------------------------------- */
945 static void
946 create_panels_and_run_mc (void)
948 midnight_dlg->get_shortcut = midnight_get_shortcut;
949 midnight_dlg->get_title = midnight_get_title;
951 create_panels ();
953 add_widget (midnight_dlg, the_menubar);
954 init_menu ();
956 add_widget (midnight_dlg, get_panel_widget (0));
957 add_widget (midnight_dlg, get_panel_widget (1));
959 add_widget (midnight_dlg, the_hint);
960 add_widget (midnight_dlg, cmdline);
961 add_widget (midnight_dlg, the_prompt);
963 add_widget (midnight_dlg, the_bar);
964 midnight_set_buttonbar (the_bar);
966 /* Run the Midnight Commander if no file was specified in the command line */
967 run_dlg (midnight_dlg);
970 /* --------------------------------------------------------------------------------------------- */
972 /** result must be free'd (I think this should go in util.c) */
973 static vfs_path_t *
974 prepend_cwd_on_local (const char *filename)
976 vfs_path_t *vpath;
978 vpath = vfs_path_from_str (filename);
979 if (!vfs_file_is_local (vpath) || g_path_is_absolute (filename))
980 return vpath;
982 vfs_path_free (vpath);
984 return vfs_path_append_new (vfs_get_raw_current_dir (), filename, NULL);
987 /* --------------------------------------------------------------------------------------------- */
989 /** Invoke the internal view/edit routine with:
990 * the default processing and forcing the internal viewer/editor
992 static gboolean
993 mc_maybe_editor_or_viewer (void)
995 gboolean ret;
997 switch (mc_global.mc_run_mode)
999 #ifdef USE_INTERNAL_EDIT
1000 case MC_RUN_EDITOR:
1001 ret = edit_files ((GList *) mc_run_param0);
1002 break;
1003 #endif /* USE_INTERNAL_EDIT */
1004 case MC_RUN_VIEWER:
1006 vfs_path_t *vpath = NULL;
1008 if (mc_run_param0 != NULL && *(char *) mc_run_param0 != '\0')
1009 vpath = prepend_cwd_on_local ((char *) mc_run_param0);
1011 ret = view_file (vpath, 0, 1);
1012 vfs_path_free (vpath);
1013 break;
1015 #ifdef USE_DIFF_VIEW
1016 case MC_RUN_DIFFVIEWER:
1017 ret = dview_diff_cmd (mc_run_param0, mc_run_param1);
1018 break;
1019 #endif /* USE_DIFF_VIEW */
1020 default:
1021 ret = FALSE;
1024 return ret;
1027 /* --------------------------------------------------------------------------------------------- */
1029 static gboolean
1030 quit_cmd_internal (int quiet)
1032 int q = quit;
1033 size_t n;
1035 n = dialog_switch_num () - 1;
1036 if (n != 0)
1038 char msg[BUF_MEDIUM];
1040 g_snprintf (msg, sizeof (msg),
1041 ngettext ("You have %zd opened screen. Quit anyway?",
1042 "You have %zd opened screens. Quit anyway?", n), n);
1044 if (query_dialog (_("The Midnight Commander"), msg, D_NORMAL, 2, _("&Yes"), _("&No")) != 0)
1045 return FALSE;
1046 q = 1;
1048 else if (quiet || !confirm_exit)
1049 q = 1;
1050 else if (query_dialog (_("The Midnight Commander"),
1051 _("Do you really want to quit the Midnight Commander?"),
1052 D_NORMAL, 2, _("&Yes"), _("&No")) == 0)
1053 q = 1;
1055 if (q != 0)
1057 #ifdef ENABLE_SUBSHELL
1058 if (!mc_global.tty.use_subshell)
1059 stop_dialogs ();
1060 else if ((q = exit_subshell ()? 1 : 0) != 0)
1061 #endif
1062 stop_dialogs ();
1065 if (q != 0)
1066 quit |= 1;
1067 return (quit != 0);
1070 /* --------------------------------------------------------------------------------------------- */
1072 static gboolean
1073 quit_cmd (void)
1075 return quit_cmd_internal (0);
1078 /* --------------------------------------------------------------------------------------------- */
1080 static void
1081 toggle_show_hidden (void)
1083 panels_options.show_dot_files = !panels_options.show_dot_files;
1084 update_panels (UP_RELOAD, UP_KEEPSEL);
1087 /* --------------------------------------------------------------------------------------------- */
1090 * Repaint the contents of the panels without frames. To schedule panel
1091 * for repainting, set panel->dirty to 1. There are many reasons why
1092 * the panels need to be repainted, and this is a costly operation, so
1093 * it's done once per event.
1096 static void
1097 update_dirty_panels (void)
1099 if (get_current_type () == view_listing && current_panel->dirty)
1100 send_message (current_panel, NULL, MSG_DRAW, 0, NULL);
1102 if (get_other_type () == view_listing && other_panel->dirty)
1103 send_message (other_panel, NULL, MSG_DRAW, 0, NULL);
1106 /* --------------------------------------------------------------------------------------------- */
1108 static cb_ret_t
1109 midnight_execute_cmd (Widget * sender, unsigned long command)
1111 cb_ret_t res = MSG_HANDLED;
1113 (void) sender;
1115 /* stop quick search before executing any command */
1116 send_message (current_panel, NULL, MSG_ACTION, CK_SearchStop, NULL);
1118 switch (command)
1120 case CK_HotListAdd:
1121 add2hotlist_cmd ();
1122 break;
1123 case CK_PanelListingChange:
1124 change_listing_cmd ();
1125 break;
1126 case CK_ChangeMode:
1127 chmod_cmd ();
1128 break;
1129 case CK_ChangeOwn:
1130 chown_cmd ();
1131 break;
1132 case CK_ChangeOwnAdvanced:
1133 chown_advanced_cmd ();
1134 break;
1135 case CK_CompareDirs:
1136 compare_dirs_cmd ();
1137 break;
1138 case CK_Options:
1139 configure_box ();
1140 break;
1141 #ifdef ENABLE_VFS
1142 case CK_OptionsVfs:
1143 configure_vfs ();
1144 break;
1145 #endif
1146 case CK_OptionsConfirm:
1147 confirm_box ();
1148 break;
1149 case CK_Copy:
1150 copy_cmd ();
1151 break;
1152 case CK_PutCurrentPath:
1153 put_current_path ();
1154 break;
1155 case CK_PutCurrentLink:
1156 put_current_link ();
1157 break;
1158 case CK_PutCurrentTagged:
1159 put_current_tagged ();
1160 break;
1161 case CK_PutOtherPath:
1162 put_other_path ();
1163 break;
1164 case CK_PutOtherLink:
1165 put_other_link ();
1166 break;
1167 case CK_PutOtherTagged:
1168 put_other_tagged ();
1169 break;
1170 case CK_Delete:
1171 delete_cmd ();
1172 break;
1173 case CK_ScreenList:
1174 dialog_switch_list ();
1175 break;
1176 #ifdef USE_DIFF_VIEW
1177 case CK_CompareFiles:
1178 diff_view_cmd ();
1179 break;
1180 #endif
1181 case CK_OptionsDisplayBits:
1182 display_bits_box ();
1183 break;
1184 case CK_Edit:
1185 edit_cmd ();
1186 break;
1187 #ifdef USE_INTERNAL_EDIT
1188 case CK_EditForceInternal:
1189 edit_cmd_force_internal ();
1190 break;
1191 #endif
1192 case CK_EditExtensionsFile:
1193 ext_cmd ();
1194 break;
1195 case CK_EditFileHighlightFile:
1196 edit_fhl_cmd ();
1197 break;
1198 case CK_EditUserMenu:
1199 edit_mc_menu_cmd ();
1200 break;
1201 case CK_LinkSymbolicEdit:
1202 edit_symlink_cmd ();
1203 break;
1204 case CK_ExternalPanelize:
1205 external_panelize ();
1206 break;
1207 case CK_Filter:
1208 filter_cmd ();
1209 break;
1210 case CK_ViewFiltered:
1211 view_filtered_cmd ();
1212 break;
1213 case CK_Find:
1214 find_cmd ();
1215 break;
1216 #ifdef ENABLE_VFS_FISH
1217 case CK_ConnectFish:
1218 fishlink_cmd ();
1219 break;
1220 #endif
1221 #ifdef ENABLE_VFS_FTP
1222 case CK_ConnectFtp:
1223 ftplink_cmd ();
1224 break;
1225 #endif
1226 #ifdef ENABLE_VFS_SFTP
1227 case CK_ConnectSftp:
1228 sftplink_cmd ();
1229 break;
1230 #endif
1231 #ifdef ENABLE_VFS_SMB
1232 case CK_ConnectSmb:
1233 smblink_cmd ();
1234 break;
1235 #endif /* ENABLE_VFS_SMB */
1236 case CK_Panelize:
1237 cd_panelize_cmd ();
1238 break;
1239 case CK_Help:
1240 help_cmd ();
1241 break;
1242 case CK_History:
1243 /* show the history of command line widget */
1244 send_message (cmdline, NULL, MSG_ACTION, CK_History, NULL);
1245 break;
1246 case CK_PanelInfo:
1247 if (sender == WIDGET (the_menubar))
1248 info_cmd (); /* menu */
1249 else
1250 info_cmd_no_menu (); /* shortcut or buttonbar */
1251 break;
1252 #ifdef ENABLE_BACKGROUND
1253 case CK_Jobs:
1254 jobs_cmd ();
1255 break;
1256 #endif
1257 case CK_OptionsLayout:
1258 layout_box ();
1259 break;
1260 case CK_LearnKeys:
1261 learn_keys ();
1262 break;
1263 case CK_Link:
1264 link_cmd (LINK_HARDLINK);
1265 break;
1266 case CK_PanelListing:
1267 listing_cmd ();
1268 break;
1269 #ifdef LISTMODE_EDITOR
1270 case CK_ListMode:
1271 listmode_cmd ();
1272 break;
1273 #endif
1274 case CK_Menu:
1275 menu_cmd ();
1276 break;
1277 case CK_MenuLastSelected:
1278 menu_last_selected_cmd ();
1279 break;
1280 case CK_MakeDir:
1281 mkdir_cmd ();
1282 break;
1283 case CK_OptionsPanel:
1284 panel_options_box ();
1285 break;
1286 #ifdef HAVE_CHARSET
1287 case CK_SelectCodepage:
1288 encoding_cmd ();
1289 break;
1290 #endif
1291 case CK_CdQuick:
1292 quick_cd_cmd ();
1293 break;
1294 case CK_HotList:
1295 hotlist_cmd ();
1296 break;
1297 case CK_PanelQuickView:
1298 if (sender == WIDGET (the_menubar))
1299 quick_view_cmd (); /* menu */
1300 else
1301 quick_cmd_no_menu (); /* shortcut or buttonabr */
1302 break;
1303 case CK_QuitQuiet:
1304 quiet_quit_cmd ();
1305 break;
1306 case CK_Quit:
1307 quit_cmd ();
1308 break;
1309 case CK_LinkSymbolicRelative:
1310 link_cmd (LINK_SYMLINK_RELATIVE);
1311 break;
1312 case CK_Move:
1313 rename_cmd ();
1314 break;
1315 case CK_Reread:
1316 reread_cmd ();
1317 break;
1318 #ifdef ENABLE_VFS
1319 case CK_VfsList:
1320 vfs_list ();
1321 break;
1322 #endif
1323 case CK_SelectInvert:
1324 select_invert_cmd ();
1325 break;
1326 case CK_SaveSetup:
1327 save_setup_cmd ();
1328 break;
1329 case CK_Select:
1330 select_cmd ();
1331 break;
1332 case CK_Shell:
1333 view_other_cmd ();
1334 break;
1335 case CK_DirSize:
1336 smart_dirsize_cmd ();
1337 break;
1338 case CK_Sort:
1339 sort_cmd ();
1340 break;
1341 case CK_ExtendedKeyMap:
1342 ctl_x_cmd ();
1343 break;
1344 case CK_Suspend:
1345 mc_event_raise (MCEVENT_GROUP_CORE, "suspend", NULL);
1346 break;
1347 case CK_Swap:
1348 swap_cmd ();
1349 break;
1350 case CK_LinkSymbolic:
1351 link_cmd (LINK_SYMLINK_ABSOLUTE);
1352 break;
1353 case CK_PanelListingSwitch:
1354 toggle_listing_cmd ();
1355 break;
1356 case CK_ShowHidden:
1357 toggle_show_hidden ();
1358 break;
1359 case CK_SplitVertHoriz:
1360 toggle_panels_split ();
1361 break;
1362 case CK_SplitEqual:
1363 panels_split_equal ();
1364 break;
1365 case CK_SplitMore:
1366 panels_split_more ();
1367 break;
1368 case CK_SplitLess:
1369 panels_split_less ();
1370 break;
1371 case CK_PanelTree:
1372 panel_tree_cmd ();
1373 break;
1374 case CK_Tree:
1375 treebox_cmd ();
1376 break;
1377 #ifdef ENABLE_VFS_UNDELFS
1378 case CK_Undelete:
1379 undelete_cmd ();
1380 break;
1381 #endif
1382 case CK_Unselect:
1383 unselect_cmd ();
1384 break;
1385 case CK_UserMenu:
1386 user_file_menu_cmd ();
1387 break;
1388 case CK_View:
1389 view_cmd ();
1390 break;
1391 case CK_ViewFile:
1392 view_file_cmd ();
1393 break;
1394 case CK_Cancel:
1395 /* don't close panels due to SIGINT */
1396 break;
1397 default:
1398 res = MSG_NOT_HANDLED;
1401 return res;
1404 /* --------------------------------------------------------------------------------------------- */
1406 static cb_ret_t
1407 midnight_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
1409 unsigned long command;
1411 switch (msg)
1413 case MSG_INIT:
1414 panel_init ();
1415 setup_panels ();
1416 return MSG_HANDLED;
1418 case MSG_DRAW:
1419 load_hint (1);
1420 /* We handle the special case of the output lines */
1421 if (mc_global.tty.console_flag != '\0' && output_lines)
1422 show_console_contents (output_start_y,
1423 LINES - output_lines - mc_global.keybar_visible -
1424 1, LINES - mc_global.keybar_visible - 1);
1425 return MSG_HANDLED;
1427 case MSG_RESIZE:
1428 setup_panels ();
1429 menubar_arrange (the_menubar);
1430 return MSG_HANDLED;
1432 case MSG_IDLE:
1433 /* We only need the first idle event to show user menu after start */
1434 widget_want_idle (w, FALSE);
1436 if (boot_current_is_left)
1437 dlg_select_widget (get_panel_widget (0));
1438 else
1439 dlg_select_widget (get_panel_widget (1));
1441 if (auto_menu)
1442 midnight_execute_cmd (NULL, CK_UserMenu);
1443 return MSG_HANDLED;
1445 case MSG_KEY:
1446 if (ctl_x_map_enabled)
1448 ctl_x_map_enabled = FALSE;
1449 command = keybind_lookup_keymap_command (main_x_map, parm);
1450 if (command != CK_IgnoreKey)
1451 return midnight_execute_cmd (NULL, command);
1454 /* FIXME: should handle all menu shortcuts before this point */
1455 if (the_menubar->is_active)
1456 return MSG_NOT_HANDLED;
1458 if (parm == '\t')
1459 input_free_completions (cmdline);
1461 if (parm == '\n')
1463 size_t i;
1465 for (i = 0; cmdline->buffer[i] != '\0' &&
1466 (cmdline->buffer[i] == ' ' || cmdline->buffer[i] == '\t'); i++)
1469 if (cmdline->buffer[i] != '\0')
1471 send_message (cmdline, NULL, MSG_KEY, parm, NULL);
1472 return MSG_HANDLED;
1475 input_insert (cmdline, "", FALSE);
1476 cmdline->point = 0;
1479 /* Ctrl-Enter and Alt-Enter */
1480 if (((parm & ~(KEY_M_CTRL | KEY_M_ALT)) == '\n') && (parm & (KEY_M_CTRL | KEY_M_ALT)))
1482 put_prog_name ();
1483 return MSG_HANDLED;
1486 /* Ctrl-Shift-Enter */
1487 if (parm == (KEY_M_CTRL | KEY_M_SHIFT | '\n'))
1489 put_current_path ();
1490 put_prog_name ();
1491 return MSG_HANDLED;
1494 if ((!mc_global.tty.alternate_plus_minus
1495 || !(mc_global.tty.console_flag != '\0' || mc_global.tty.xterm_flag)) && !quote
1496 && !current_panel->searching)
1498 if (!only_leading_plus_minus)
1500 /* Special treatement, since the input line will eat them */
1501 if (parm == '+')
1503 select_cmd ();
1504 return MSG_HANDLED;
1507 if (parm == '\\' || parm == '-')
1509 unselect_cmd ();
1510 return MSG_HANDLED;
1513 if (parm == '*')
1515 select_invert_cmd ();
1516 return MSG_HANDLED;
1519 else if (!command_prompt || !cmdline->buffer[0])
1521 /* Special treatement '+', '-', '\', '*' only when this is
1522 * first char on input line
1525 if (parm == '+')
1527 select_cmd ();
1528 return MSG_HANDLED;
1531 if (parm == '\\' || parm == '-')
1533 unselect_cmd ();
1534 return MSG_HANDLED;
1537 if (parm == '*')
1539 select_invert_cmd ();
1540 return MSG_HANDLED;
1544 return MSG_NOT_HANDLED;
1546 case MSG_HOTKEY_HANDLED:
1547 if ((get_current_type () == view_listing) && current_panel->searching)
1549 current_panel->dirty = 1; /* FIXME: unneeded? */
1550 send_message (current_panel, NULL, MSG_ACTION, CK_SearchStop, NULL);
1552 return MSG_HANDLED;
1554 case MSG_UNHANDLED_KEY:
1556 cb_ret_t v = MSG_NOT_HANDLED;
1558 if (ctl_x_map_enabled)
1560 ctl_x_map_enabled = FALSE;
1561 command = keybind_lookup_keymap_command (main_x_map, parm);
1563 else
1564 command = keybind_lookup_keymap_command (main_map, parm);
1566 if (command != CK_IgnoreKey)
1567 v = midnight_execute_cmd (NULL, command);
1569 if (v == MSG_NOT_HANDLED && command_prompt)
1570 v = send_message (cmdline, NULL, MSG_KEY, parm, NULL);
1572 return v;
1575 case MSG_POST_KEY:
1576 if (!the_menubar->is_active)
1577 update_dirty_panels ();
1578 return MSG_HANDLED;
1580 case MSG_ACTION:
1581 /* shortcut */
1582 if (sender == NULL)
1583 return midnight_execute_cmd (NULL, parm);
1584 /* message from menu */
1585 if (sender == WIDGET (the_menubar))
1586 return midnight_execute_cmd (sender, parm);
1587 /* message from buttonbar */
1588 if (sender == WIDGET (the_bar))
1590 if (data != NULL)
1591 return send_message (data, NULL, MSG_ACTION, parm, NULL);
1592 return midnight_execute_cmd (sender, parm);
1594 return MSG_NOT_HANDLED;
1596 case MSG_END:
1597 panel_deinit ();
1598 return MSG_HANDLED;
1600 default:
1601 return dlg_default_callback (w, sender, msg, parm, data);
1605 /* --------------------------------------------------------------------------------------------- */
1607 static int
1608 midnight_event (Gpm_Event * event, void *data)
1610 Widget *wh = WIDGET (data);
1611 int ret = MOU_UNHANDLED;
1613 if (event->y == wh->y + 1)
1615 /* menubar */
1616 if (menubar_visible || the_menubar->is_active)
1617 ret = WIDGET (the_menubar)->mouse (event, the_menubar);
1618 else
1620 Widget *w;
1622 w = get_panel_widget (0);
1623 if (w->mouse != NULL)
1624 ret = w->mouse (event, w);
1626 if (ret == MOU_UNHANDLED)
1628 w = get_panel_widget (1);
1629 if (w->mouse != NULL)
1630 ret = w->mouse (event, w);
1633 if (ret == MOU_UNHANDLED)
1634 ret = WIDGET (the_menubar)->mouse (event, the_menubar);
1638 return ret;
1641 /* --------------------------------------------------------------------------------------------- */
1642 /*** public functions ****************************************************************************/
1643 /* --------------------------------------------------------------------------------------------- */
1645 void
1646 update_menu (void)
1648 menu_set_name (left_menu, panels_layout.horizontal_split ? _("&Above") : _("&Left"));
1649 menu_set_name (right_menu, panels_layout.horizontal_split ? _("&Below") : _("&Right"));
1650 menubar_arrange (the_menubar);
1651 menubar_set_visible (the_menubar, menubar_visible);
1654 /* --------------------------------------------------------------------------------------------- */
1656 void
1657 midnight_set_buttonbar (WButtonBar * b)
1659 buttonbar_set_label (b, 1, Q_ ("ButtonBar|Help"), main_map, NULL);
1660 buttonbar_set_label (b, 2, Q_ ("ButtonBar|Menu"), main_map, NULL);
1661 buttonbar_set_label (b, 3, Q_ ("ButtonBar|View"), main_map, NULL);
1662 buttonbar_set_label (b, 4, Q_ ("ButtonBar|Edit"), main_map, NULL);
1663 buttonbar_set_label (b, 5, Q_ ("ButtonBar|Copy"), main_map, NULL);
1664 buttonbar_set_label (b, 6, Q_ ("ButtonBar|RenMov"), main_map, NULL);
1665 buttonbar_set_label (b, 7, Q_ ("ButtonBar|Mkdir"), main_map, NULL);
1666 buttonbar_set_label (b, 8, Q_ ("ButtonBar|Delete"), main_map, NULL);
1667 buttonbar_set_label (b, 9, Q_ ("ButtonBar|PullDn"), main_map, NULL);
1668 buttonbar_set_label (b, 10, Q_ ("ButtonBar|Quit"), main_map, NULL);
1671 /* --------------------------------------------------------------------------------------------- */
1673 * Load new hint and display it.
1674 * IF force is not 0, ignore the timeout.
1677 void
1678 load_hint (gboolean force)
1680 char *hint;
1682 if (WIDGET (the_hint)->owner == NULL)
1683 return;
1685 if (!mc_global.message_visible)
1687 label_set_text (the_hint, NULL);
1688 return;
1691 hint = get_random_hint (force);
1693 if (hint != NULL)
1695 if (*hint != '\0')
1696 set_hintbar (hint);
1697 g_free (hint);
1699 else
1701 char text[BUF_SMALL];
1703 g_snprintf (text, sizeof (text), _("GNU Midnight Commander %s\n"), VERSION);
1704 set_hintbar (text);
1708 /* --------------------------------------------------------------------------------------------- */
1710 void
1711 change_panel (void)
1713 input_free_completions (cmdline);
1714 dlg_one_down (midnight_dlg);
1717 /* --------------------------------------------------------------------------------------------- */
1719 /** Save current stat of directories to avoid reloading the panels
1720 * when no modifications have taken place
1722 void
1723 save_cwds_stat (void)
1725 if (panels_options.fast_reload)
1727 mc_stat (current_panel->cwd_vpath, &(current_panel->dir_stat));
1728 if (get_other_type () == view_listing)
1729 mc_stat (other_panel->cwd_vpath, &(other_panel->dir_stat));
1733 /* --------------------------------------------------------------------------------------------- */
1735 gboolean
1736 quiet_quit_cmd (void)
1738 print_last_revert = TRUE;
1739 return quit_cmd_internal (1);
1742 /* --------------------------------------------------------------------------------------------- */
1744 /** Run the main dialog that occupies the whole screen */
1745 gboolean
1746 do_nc (void)
1748 gboolean ret;
1750 dlg_colors_t midnight_colors;
1752 midnight_colors[DLG_COLOR_NORMAL] = mc_skin_color_get ("dialog", "_default_");
1753 midnight_colors[DLG_COLOR_FOCUS] = mc_skin_color_get ("dialog", "focus");
1754 midnight_colors[DLG_COLOR_HOT_NORMAL] = mc_skin_color_get ("dialog", "hotnormal");
1755 midnight_colors[DLG_COLOR_HOT_FOCUS] = mc_skin_color_get ("dialog", "hotfocus");
1756 midnight_colors[DLG_COLOR_TITLE] = mc_skin_color_get ("dialog", "title");
1758 #ifdef USE_INTERNAL_EDIT
1759 edit_stack_init ();
1760 #endif
1762 midnight_dlg = create_dlg (FALSE, 0, 0, LINES, COLS, midnight_colors, midnight_callback,
1763 midnight_event, "[main]", NULL, DLG_NONE);
1765 /* Check if we were invoked as an editor or file viewer */
1766 if (mc_global.mc_run_mode != MC_RUN_FULL)
1768 setup_dummy_mc ();
1769 ret = mc_maybe_editor_or_viewer ();
1771 else
1773 /* We only need the first idle event to show user menu after start */
1774 widget_want_idle (WIDGET (midnight_dlg), TRUE);
1776 setup_mc ();
1777 mc_filehighlight = mc_fhl_new (TRUE);
1778 create_panels_and_run_mc ();
1779 mc_fhl_free (&mc_filehighlight);
1781 ret = TRUE;
1783 /* destroy_dlg destroys even current_panel->cwd_vpath, so we have to save a copy :) */
1784 if (mc_args__last_wd_file != NULL && vfs_current_is_local ())
1785 last_wd_string = vfs_path_to_str (current_panel->cwd_vpath);
1787 /* don't handle VFS timestamps for dirs opened in panels */
1788 mc_event_destroy (MCEVENT_GROUP_CORE, "vfs_timestamp");
1790 clean_dir (&panelized_panel.list, panelized_panel.count);
1793 /* Program end */
1794 mc_global.midnight_shutdown = TRUE;
1795 dialog_switch_shutdown ();
1796 done_mc ();
1797 destroy_dlg (midnight_dlg);
1798 current_panel = NULL;
1800 #ifdef USE_INTERNAL_EDIT
1801 edit_stack_free ();
1802 #endif
1804 if ((quit & SUBSHELL_EXIT) == 0)
1805 clr_scr ();
1807 return ret;
1810 /* --------------------------------------------------------------------------------------------- */