Merge src/filemanager/option.[ch] to src/filemanager/boxes.[ch].
[midnight-commander.git] / src / filemanager / midnight.c
blob06f729f14c3ce87ba7c1147671bc3030432e6d90
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 "tree.h"
68 #include "boxes.h" /* sort_box(), tree_box() */
69 #include "layout.h"
70 #include "cmd.h" /* commands */
71 #include "hotlist.h"
72 #include "panelize.h"
73 #include "command.h" /* cmdline */
74 #include "dir.h" /* clean_dir() */
76 #include "chmod.h"
77 #include "chown.h"
78 #include "achown.h"
80 #ifdef USE_INTERNAL_EDIT
81 #include "src/editor/edit.h"
82 #endif
84 #ifdef USE_DIFF_VIEW
85 #include "src/diffviewer/ydiff.h"
86 #endif
88 #include "src/consaver/cons.saver.h" /* show_console_contents */
90 #include "midnight.h"
92 /* TODO: merge content of layout.c here */
93 extern int ok_to_refresh;
95 /*** global variables ****************************************************************************/
97 /* When the modes are active, left_panel, right_panel and tree_panel */
98 /* point to a proper data structure. You should check with the functions */
99 /* get_current_type and get_other_type the types of the panels before using */
100 /* this pointer variables */
102 /* The structures for the panels */
103 WPanel *left_panel = NULL;
104 WPanel *right_panel = NULL;
105 /* Pointer to the selected and unselected panel */
106 WPanel *current_panel = NULL;
108 /* The Menubar */
109 WMenuBar *the_menubar = NULL;
110 /* The widget where we draw the prompt */
111 WLabel *the_prompt;
112 /* The hint bar */
113 WLabel *the_hint;
114 /* The button bar */
115 WButtonBar *the_bar;
117 /* The prompt */
118 const char *mc_prompt = NULL;
120 /*** file scope macro definitions ****************************************************************/
122 #ifdef HAVE_CHARSET
124 * Don't restrict the output on the screen manager level,
125 * the translation tables take care of it.
127 #endif /* !HAVE_CHARSET */
129 /*** file scope type declarations ****************************************************************/
131 /*** file scope variables ************************************************************************/
133 static menu_t *left_menu, *right_menu;
135 static gboolean ctl_x_map_enabled = FALSE;
137 /*** file scope functions ************************************************************************/
139 /** Stop MC main dialog and the current dialog if it exists.
140 * Needed to provide fast exit from MC viewer or editor on shell exit */
141 static void
142 stop_dialogs (void)
144 midnight_dlg->state = DLG_CLOSED;
146 if ((top_dlg != NULL) && (top_dlg->data != NULL))
147 DIALOG (top_dlg->data)->state = DLG_CLOSED;
150 /* --------------------------------------------------------------------------------------------- */
152 static void
153 treebox_cmd (void)
155 char *sel_dir;
157 sel_dir = tree_box (selection (current_panel)->fname);
158 if (sel_dir != NULL)
160 vfs_path_t *sel_vdir;
162 sel_vdir = vfs_path_from_str (sel_dir);
163 do_cd (sel_vdir, cd_exact);
164 vfs_path_free (sel_vdir);
165 g_free (sel_dir);
169 /* --------------------------------------------------------------------------------------------- */
171 #ifdef LISTMODE_EDITOR
172 static void
173 listmode_cmd (void)
175 char *newmode;
177 if (get_current_type () != view_listing)
178 return;
180 newmode = listmode_edit (current_panel->user_format);
181 if (!newmode)
182 return;
184 g_free (current_panel->user_format);
185 current_panel->list_type = list_user;
186 current_panel->user_format = newmode;
187 set_panel_formats (current_panel);
189 do_refresh ();
191 #endif /* LISTMODE_EDITOR */
193 /* --------------------------------------------------------------------------------------------- */
195 static GList *
196 create_panel_menu (void)
198 GList *entries = NULL;
200 entries = g_list_prepend (entries, menu_entry_create (_("File listin&g"), CK_PanelListing));
201 entries = g_list_prepend (entries, menu_entry_create (_("&Quick view"), CK_PanelQuickView));
202 entries = g_list_prepend (entries, menu_entry_create (_("&Info"), CK_PanelInfo));
203 entries = g_list_prepend (entries, menu_entry_create (_("&Tree"), CK_PanelTree));
204 entries = g_list_prepend (entries, menu_separator_create ());
205 entries =
206 g_list_prepend (entries, menu_entry_create (_("&Listing mode..."), CK_PanelListingChange));
207 entries = g_list_prepend (entries, menu_entry_create (_("&Sort order..."), CK_Sort));
208 entries = g_list_prepend (entries, menu_entry_create (_("&Filter..."), CK_Filter));
209 #ifdef HAVE_CHARSET
210 entries = g_list_prepend (entries, menu_entry_create (_("&Encoding..."), CK_SelectCodepage));
211 #endif
212 entries = g_list_prepend (entries, menu_separator_create ());
213 #ifdef ENABLE_VFS_FTP
214 entries = g_list_prepend (entries, menu_entry_create (_("FT&P link..."), CK_ConnectFtp));
215 #endif
216 #ifdef ENABLE_VFS_FISH
217 entries = g_list_prepend (entries, menu_entry_create (_("S&hell link..."), CK_ConnectFish));
218 #endif
219 #ifdef ENABLE_VFS_SFTP
220 entries = g_list_prepend (entries, menu_entry_create (_("S&FTP link..."), CK_ConnectSftp));
221 #endif
222 #ifdef ENABLE_VFS_SMB
223 entries = g_list_prepend (entries, menu_entry_create (_("SM&B link..."), CK_ConnectSmb));
224 #endif
225 entries = g_list_prepend (entries, menu_entry_create (_("Paneli&ze"), CK_Panelize));
226 entries = g_list_prepend (entries, menu_separator_create ());
227 entries = g_list_prepend (entries, menu_entry_create (_("&Rescan"), CK_Reread));
229 return g_list_reverse (entries);
232 /* --------------------------------------------------------------------------------------------- */
234 static GList *
235 create_file_menu (void)
237 GList *entries = NULL;
239 entries = g_list_prepend (entries, menu_entry_create (_("&View"), CK_View));
240 entries = g_list_prepend (entries, menu_entry_create (_("Vie&w file..."), CK_ViewFile));
241 entries = g_list_prepend (entries, menu_entry_create (_("&Filtered view"), CK_ViewFiltered));
242 entries = g_list_prepend (entries, menu_entry_create (_("&Edit"), CK_Edit));
243 entries = g_list_prepend (entries, menu_entry_create (_("&Copy"), CK_Copy));
244 entries = g_list_prepend (entries, menu_entry_create (_("C&hmod"), CK_ChangeMode));
245 entries = g_list_prepend (entries, menu_entry_create (_("&Link"), CK_Link));
246 entries = g_list_prepend (entries, menu_entry_create (_("&Symlink"), CK_LinkSymbolic));
247 entries =
248 g_list_prepend (entries,
249 menu_entry_create (_("Relative symlin&k"), CK_LinkSymbolicRelative));
250 entries = g_list_prepend (entries, menu_entry_create (_("Edit s&ymlink"), CK_LinkSymbolicEdit));
251 entries = g_list_prepend (entries, menu_entry_create (_("Ch&own"), CK_ChangeOwn));
252 entries =
253 g_list_prepend (entries, menu_entry_create (_("&Advanced chown"), CK_ChangeOwnAdvanced));
254 entries = g_list_prepend (entries, menu_entry_create (_("&Rename/Move"), CK_Move));
255 entries = g_list_prepend (entries, menu_entry_create (_("&Mkdir"), CK_MakeDir));
256 entries = g_list_prepend (entries, menu_entry_create (_("&Delete"), CK_Delete));
257 entries = g_list_prepend (entries, menu_entry_create (_("&Quick cd"), CK_CdQuick));
258 entries = g_list_prepend (entries, menu_separator_create ());
259 entries = g_list_prepend (entries, menu_entry_create (_("Select &group"), CK_Select));
260 entries = g_list_prepend (entries, menu_entry_create (_("U&nselect group"), CK_Unselect));
261 entries = g_list_prepend (entries, menu_entry_create (_("&Invert selection"), CK_SelectInvert));
262 entries = g_list_prepend (entries, menu_separator_create ());
263 entries = g_list_prepend (entries, menu_entry_create (_("E&xit"), CK_Quit));
265 return g_list_reverse (entries);
268 /* --------------------------------------------------------------------------------------------- */
270 static GList *
271 create_command_menu (void)
273 /* I know, I'm lazy, but the tree widget when it's not running
274 * as a panel still has some problems, I have not yet finished
275 * the WTree widget port, sorry.
277 GList *entries = NULL;
279 entries = g_list_prepend (entries, menu_entry_create (_("&User menu"), CK_UserMenu));
280 entries = g_list_prepend (entries, menu_entry_create (_("&Directory tree"), CK_Tree));
281 entries = g_list_prepend (entries, menu_entry_create (_("&Find file"), CK_Find));
282 entries = g_list_prepend (entries, menu_entry_create (_("S&wap panels"), CK_Swap));
283 entries = g_list_prepend (entries, menu_entry_create (_("Switch &panels on/off"), CK_Shell));
284 entries =
285 g_list_prepend (entries, menu_entry_create (_("&Compare directories"), CK_CompareDirs));
286 #ifdef USE_DIFF_VIEW
287 entries = g_list_prepend (entries, menu_entry_create (_("C&ompare files"), CK_CompareFiles));
288 #endif
289 entries =
290 g_list_prepend (entries, menu_entry_create (_("E&xternal panelize"), CK_ExternalPanelize));
291 entries = g_list_prepend (entries, menu_entry_create (_("Show directory s&izes"), CK_DirSize));
292 entries = g_list_prepend (entries, menu_separator_create ());
293 entries = g_list_prepend (entries, menu_entry_create (_("Command &history"), CK_History));
294 entries = g_list_prepend (entries, menu_entry_create (_("Di&rectory hotlist"), CK_HotList));
295 #ifdef ENABLE_VFS
296 entries = g_list_prepend (entries, menu_entry_create (_("&Active VFS list"), CK_VfsList));
297 #endif
298 #ifdef ENABLE_BACKGROUND
299 entries = g_list_prepend (entries, menu_entry_create (_("&Background jobs"), CK_Jobs));
300 #endif
301 entries = g_list_prepend (entries, menu_entry_create (_("Screen lis&t"), CK_ScreenList));
302 entries = g_list_prepend (entries, menu_separator_create ());
303 #ifdef ENABLE_VFS_UNDELFS
304 entries =
305 g_list_prepend (entries,
306 menu_entry_create (_("&Undelete files (ext2fs only)"), CK_Undelete));
307 #endif
308 #ifdef LISTMODE_EDITOR
309 entries = g_list_prepend (entries, menu_entry_create (_("&Listing format edit"), CK_ListMode));
310 #endif
311 #if defined (ENABLE_VFS_UNDELFS) || defined (LISTMODE_EDITOR)
312 entries = g_list_prepend (entries, menu_separator_create ());
313 #endif
314 entries =
315 g_list_prepend (entries,
316 menu_entry_create (_("Edit &extension file"), CK_EditExtensionsFile));
317 entries = g_list_prepend (entries, menu_entry_create (_("Edit &menu file"), CK_EditUserMenu));
318 entries =
319 g_list_prepend (entries,
320 menu_entry_create (_("Edit hi&ghlighting group file"),
321 CK_EditFileHighlightFile));
323 return g_list_reverse (entries);
326 /* --------------------------------------------------------------------------------------------- */
328 static GList *
329 create_options_menu (void)
331 GList *entries = NULL;
333 entries = g_list_prepend (entries, menu_entry_create (_("&Configuration..."), CK_Options));
334 entries = g_list_prepend (entries, menu_entry_create (_("&Layout..."), CK_OptionsLayout));
335 entries = g_list_prepend (entries, menu_entry_create (_("&Panel options..."), CK_OptionsPanel));
336 entries =
337 g_list_prepend (entries, menu_entry_create (_("C&onfirmation..."), CK_OptionsConfirm));
338 entries =
339 g_list_prepend (entries, menu_entry_create (_("&Display bits..."), CK_OptionsDisplayBits));
340 entries = g_list_prepend (entries, menu_entry_create (_("Learn &keys..."), CK_LearnKeys));
341 #ifdef ENABLE_VFS
342 entries = g_list_prepend (entries, menu_entry_create (_("&Virtual FS..."), CK_OptionsVfs));
343 #endif
344 entries = g_list_prepend (entries, menu_separator_create ());
345 entries = g_list_prepend (entries, menu_entry_create (_("&Save setup"), CK_SaveSetup));
347 return g_list_reverse (entries);
350 /* --------------------------------------------------------------------------------------------- */
352 static void
353 init_menu (void)
355 left_menu = create_menu ("", create_panel_menu (), "[Left and Right Menus]");
356 menubar_add_menu (the_menubar, left_menu);
357 menubar_add_menu (the_menubar, create_menu (_("&File"), create_file_menu (), "[File Menu]"));
358 menubar_add_menu (the_menubar,
359 create_menu (_("&Command"), create_command_menu (), "[Command Menu]"));
360 menubar_add_menu (the_menubar,
361 create_menu (_("&Options"), create_options_menu (), "[Options Menu]"));
362 right_menu = create_menu ("", create_panel_menu (), "[Left and Right Menus]");
363 menubar_add_menu (the_menubar, right_menu);
364 update_menu ();
367 /* --------------------------------------------------------------------------------------------- */
369 static void
370 menu_last_selected_cmd (void)
372 the_menubar->is_active = TRUE;
373 the_menubar->is_dropped = (drop_menus != 0);
374 the_menubar->previous_widget = dlg_get_current_widget_id (midnight_dlg);
375 dlg_select_widget (the_menubar);
378 /* --------------------------------------------------------------------------------------------- */
380 static void
381 menu_cmd (void)
383 if (the_menubar->is_active)
384 return;
386 if ((get_current_index () == 0) == (current_panel->active != 0))
387 the_menubar->selected = 0;
388 else
389 the_menubar->selected = g_list_length (the_menubar->menu) - 1;
390 menu_last_selected_cmd ();
393 /* --------------------------------------------------------------------------------------------- */
395 static void
396 sort_cmd (void)
398 WPanel *p;
399 const panel_field_t *sort_order;
401 if (!SELECTED_IS_PANEL)
402 return;
404 p = MENU_PANEL;
405 sort_order = sort_box (&p->sort_info);
406 panel_set_sort_order (p, sort_order);
409 /* --------------------------------------------------------------------------------------------- */
411 static char *
412 midnight_get_shortcut (unsigned long command)
414 const char *ext_map;
415 const char *shortcut = NULL;
417 shortcut = keybind_lookup_keymap_shortcut (main_map, command);
418 if (shortcut != NULL)
419 return g_strdup (shortcut);
421 shortcut = keybind_lookup_keymap_shortcut (panel_map, command);
422 if (shortcut != NULL)
423 return g_strdup (shortcut);
425 ext_map = keybind_lookup_keymap_shortcut (main_map, CK_ExtendedKeyMap);
426 if (ext_map != NULL)
427 shortcut = keybind_lookup_keymap_shortcut (main_x_map, command);
428 if (shortcut != NULL)
429 return g_strdup_printf ("%s %s", ext_map, shortcut);
431 return NULL;
434 /* --------------------------------------------------------------------------------------------- */
436 static char *
437 midnight_get_title (const WDialog * h, size_t len)
439 char *path;
440 char *login;
441 char *p;
443 (void) h;
445 title_path_prepare (&path, &login);
447 p = g_strdup_printf ("%s [%s]:%s", _("Panels:"), login, path);
448 g_free (path);
449 g_free (login);
450 path = g_strdup (str_trunc (p, len - 4));
451 g_free (p);
453 return path;
456 /* --------------------------------------------------------------------------------------------- */
458 static void
459 toggle_panels_split (void)
461 panels_layout.horizontal_split = !panels_layout.horizontal_split;
462 layout_change ();
463 do_refresh ();
466 /* --------------------------------------------------------------------------------------------- */
468 #ifdef ENABLE_VFS
469 /* event helper */
470 static gboolean
471 check_panel_timestamp (const WPanel * panel, panel_view_mode_t mode, struct vfs_class *vclass,
472 vfsid id)
474 if (mode == view_listing)
476 const vfs_path_element_t *path_element;
478 path_element = vfs_path_get_by_index (panel->cwd_vpath, -1);
480 if (path_element->class != vclass)
481 return FALSE;
483 if (vfs_getid (panel->cwd_vpath) != id)
484 return FALSE;
486 return TRUE;
489 /* --------------------------------------------------------------------------------------------- */
491 /* event callback */
492 static gboolean
493 check_current_panel_timestamp (const gchar * event_group_name, const gchar * event_name,
494 gpointer init_data, gpointer data)
496 ev_vfs_stamp_create_t *event_data = (ev_vfs_stamp_create_t *) data;
498 (void) event_group_name;
499 (void) event_name;
500 (void) init_data;
502 event_data->ret =
503 check_panel_timestamp (current_panel, get_current_type (), event_data->vclass,
504 event_data->id);
505 return !event_data->ret;
508 /* --------------------------------------------------------------------------------------------- */
510 /* event callback */
511 static gboolean
512 check_other_panel_timestamp (const gchar * event_group_name, const gchar * event_name,
513 gpointer init_data, gpointer data)
515 ev_vfs_stamp_create_t *event_data = (ev_vfs_stamp_create_t *) data;
517 (void) event_group_name;
518 (void) event_name;
519 (void) init_data;
521 event_data->ret =
522 check_panel_timestamp (other_panel, get_other_type (), event_data->vclass, event_data->id);
523 return !event_data->ret;
525 #endif /* ENABLE_VFS */
527 /* --------------------------------------------------------------------------------------------- */
529 /* event callback */
530 static gboolean
531 print_vfs_message (const gchar * event_group_name, const gchar * event_name,
532 gpointer init_data, gpointer data)
534 char str[128];
535 ev_vfs_print_message_t *event_data = (ev_vfs_print_message_t *) data;
537 (void) event_group_name;
538 (void) event_name;
539 (void) init_data;
541 g_vsnprintf (str, sizeof (str), event_data->msg, event_data->ap);
543 if (mc_global.midnight_shutdown)
544 return TRUE;
546 if (!mc_global.message_visible || the_hint == NULL || WIDGET (the_hint)->owner == NULL)
548 int col, row;
550 if (!nice_rotating_dash || (ok_to_refresh <= 0))
551 return TRUE;
553 /* Preserve current cursor position */
554 tty_getyx (&row, &col);
556 tty_gotoyx (0, 0);
557 tty_setcolor (NORMAL_COLOR);
558 tty_print_string (str_fit_to_term (str, COLS - 1, J_LEFT));
560 /* Restore cursor position */
561 tty_gotoyx (row, col);
562 mc_refresh ();
563 return TRUE;
566 if (mc_global.message_visible)
567 set_hintbar (str);
569 return TRUE;
572 /* --------------------------------------------------------------------------------------------- */
574 static void
575 create_panels (void)
577 int current_index, other_index;
578 panel_view_mode_t current_mode, other_mode;
579 char *current_dir, *other_dir;
580 vfs_path_t *original_dir;
582 if (boot_current_is_left)
584 /* left panel is active */
585 current_index = 0;
586 other_index = 1;
587 current_mode = startup_left_mode;
588 other_mode = startup_right_mode;
589 /* if mc_run_param0 is NULL, working directory will be used for the left panel */
590 current_dir = (char *) mc_run_param0;
591 /* mc_run_param1 is never NULL. It is setup from command line or from panels.ini
592 * (value of other_dir). mc_run_param1 will be used for the right panel */
593 other_dir = mc_run_param1;
595 else
597 /* right panel is active */
598 current_index = 1;
599 other_index = 0;
600 current_mode = startup_right_mode;
601 other_mode = startup_left_mode;
603 /* if mc_run_param0 is not NULL (it was setup from command line), it will be used
604 * for the left panel, working directory will be used for the right one;
605 * if mc_run_param0 is NULL, working directory will be used for the right (active) panel,
606 * mc_run_param1 will be used for the left one */
607 if (mc_run_param0 != NULL)
609 current_dir = NULL;
610 other_dir = (char *) mc_run_param0;
612 else
614 current_dir = NULL;
615 other_dir = mc_run_param1;
619 /* 1. Get current dir */
620 original_dir = vfs_path_clone (vfs_get_raw_current_dir ());
622 /* 2. Create passive panel */
623 if (other_dir != NULL)
625 vfs_path_t *vpath;
627 if (g_path_is_absolute (other_dir))
628 vpath = vfs_path_from_str (other_dir);
629 else
630 vpath = vfs_path_append_new (original_dir, other_dir, (char *) NULL);
631 mc_chdir (vpath);
632 vfs_path_free (vpath);
634 set_display_type (other_index, other_mode);
636 /* 3. Create active panel */
637 if (current_dir == NULL)
638 mc_chdir (original_dir);
639 else
641 vfs_path_t *vpath;
643 if (g_path_is_absolute (current_dir))
644 vpath = vfs_path_from_str (current_dir);
645 else
646 vpath = vfs_path_append_new (original_dir, current_dir, (char *) NULL);
647 mc_chdir (vpath);
648 vfs_path_free (vpath);
650 set_display_type (current_index, current_mode);
652 if (startup_left_mode == view_listing)
653 current_panel = left_panel;
654 else if (right_panel != NULL)
655 current_panel = right_panel;
656 else
657 current_panel = left_panel;
659 vfs_path_free (original_dir);
661 #ifdef ENABLE_VFS
662 mc_event_add (MCEVENT_GROUP_CORE, "vfs_timestamp", check_other_panel_timestamp, NULL, NULL);
663 mc_event_add (MCEVENT_GROUP_CORE, "vfs_timestamp", check_current_panel_timestamp, NULL, NULL);
664 #endif /* ENABLE_VFS */
666 mc_event_add (MCEVENT_GROUP_CORE, "vfs_print_message", print_vfs_message, NULL, NULL);
668 /* Create the nice widgets */
669 cmdline = command_new (0, 0, 0);
670 the_prompt = label_new (0, 0, mc_prompt);
671 the_prompt->transparent = 1;
672 the_bar = buttonbar_new (mc_global.keybar_visible);
674 the_hint = label_new (0, 0, 0);
675 the_hint->transparent = 1;
676 the_hint->auto_adjust_cols = 0;
677 WIDGET (the_hint)->cols = COLS;
679 the_menubar = menubar_new (0, 0, COLS, NULL);
682 /* --------------------------------------------------------------------------------------------- */
684 static void
685 put_current_path (void)
687 char *cwd_path;
689 if (!command_prompt)
690 return;
692 #ifdef HAVE_CHARSET
694 vfs_path_t *cwd_vpath;
696 cwd_vpath = remove_encoding_from_path (current_panel->cwd_vpath);
697 cwd_path = vfs_path_to_str (cwd_vpath);
698 vfs_path_free (cwd_vpath);
700 #else
701 cwd_path = vfs_path_to_str (current_panel->cwd_vpath);
702 #endif
704 command_insert (cmdline, cwd_path, FALSE);
705 if (cwd_path[strlen (cwd_path) - 1] != PATH_SEP)
706 command_insert (cmdline, PATH_SEP_STR, FALSE);
708 g_free (cwd_path);
711 /* --------------------------------------------------------------------------------------------- */
713 static void
714 put_other_path (void)
716 char *cwd_path;
718 if (get_other_type () != view_listing)
719 return;
721 if (!command_prompt)
722 return;
724 #ifdef HAVE_CHARSET
726 vfs_path_t *cwd_vpath;
728 cwd_vpath = remove_encoding_from_path (other_panel->cwd_vpath);
729 cwd_path = vfs_path_to_str (cwd_vpath);
730 vfs_path_free (cwd_vpath);
732 #else
733 cwd_path = vfs_path_to_str (other_panel->cwd_vpath);
734 #endif
736 command_insert (cmdline, cwd_path, FALSE);
737 if (cwd_path[strlen (cwd_path) - 1] != PATH_SEP)
738 command_insert (cmdline, PATH_SEP_STR, FALSE);
740 g_free (cwd_path);
743 /* --------------------------------------------------------------------------------------------- */
745 static void
746 put_link (WPanel * panel)
748 if (!command_prompt)
749 return;
750 if (S_ISLNK (selection (panel)->st.st_mode))
752 char buffer[MC_MAXPATHLEN];
753 vfs_path_t *vpath;
754 int i;
756 vpath = vfs_path_append_new (panel->cwd_vpath, selection (panel)->fname, NULL);
757 i = mc_readlink (vpath, buffer, MC_MAXPATHLEN - 1);
758 vfs_path_free (vpath);
760 if (i > 0)
762 buffer[i] = '\0';
763 command_insert (cmdline, buffer, TRUE);
768 /* --------------------------------------------------------------------------------------------- */
770 static void
771 put_current_link (void)
773 put_link (current_panel);
776 /* --------------------------------------------------------------------------------------------- */
778 static void
779 put_other_link (void)
781 if (get_other_type () == view_listing)
782 put_link (other_panel);
785 /* --------------------------------------------------------------------------------------------- */
787 /** Insert the selected file name into the input line */
788 static void
789 put_prog_name (void)
791 char *tmp;
792 if (!command_prompt)
793 return;
795 if (get_current_type () == view_tree)
797 WTree *tree = (WTree *) get_panel_widget (get_current_index ());
799 tmp = vfs_path_to_str (tree_selected_name (tree));
801 else
802 tmp = g_strdup (selection (current_panel)->fname);
804 command_insert (cmdline, tmp, TRUE);
805 g_free (tmp);
808 /* --------------------------------------------------------------------------------------------- */
810 static void
811 put_tagged (WPanel * panel)
813 int i;
815 if (!command_prompt)
816 return;
817 input_disable_update (cmdline);
818 if (panel->marked)
820 for (i = 0; i < panel->count; i++)
822 if (panel->dir.list[i].f.marked)
823 command_insert (cmdline, panel->dir.list[i].fname, TRUE);
826 else
828 command_insert (cmdline, panel->dir.list[panel->selected].fname, TRUE);
830 input_enable_update (cmdline);
833 /* --------------------------------------------------------------------------------------------- */
835 static void
836 put_current_tagged (void)
838 put_tagged (current_panel);
841 /* --------------------------------------------------------------------------------------------- */
843 static void
844 put_other_tagged (void)
846 if (get_other_type () == view_listing)
847 put_tagged (other_panel);
850 /* --------------------------------------------------------------------------------------------- */
852 static void
853 ctl_x_cmd (void)
855 ctl_x_map_enabled = TRUE;
858 /* --------------------------------------------------------------------------------------------- */
860 static void
861 setup_mc (void)
863 #ifdef HAVE_SLANG
864 #ifdef HAVE_CHARSET
865 tty_display_8bit (TRUE);
866 #else
867 tty_display_8bit (mc_global.full_eight_bits != 0);
868 #endif /* HAVE_CHARSET */
870 #else /* HAVE_SLANG */
872 #ifdef HAVE_CHARSET
873 tty_display_8bit (TRUE);
874 #else
875 tty_display_8bit (mc_global.eight_bit_clean != 0);
876 #endif /* HAVE_CHARSET */
877 #endif /* HAVE_SLANG */
879 #ifdef ENABLE_SUBSHELL
880 if (mc_global.tty.use_subshell)
881 add_select_channel (mc_global.tty.subshell_pty, load_prompt, 0);
882 #endif /* !ENABLE_SUBSHELL */
884 if ((tty_baudrate () < 9600) || mc_global.tty.slow_terminal)
885 verbose = 0;
888 /* --------------------------------------------------------------------------------------------- */
890 static void
891 setup_dummy_mc (void)
893 vfs_path_t *vpath;
894 char *d;
895 int ret;
897 d = _vfs_get_cwd ();
898 setup_mc ();
899 vpath = vfs_path_from_str (d);
900 ret = mc_chdir (vpath);
901 vfs_path_free (vpath);
902 g_free (d);
905 /* --------------------------------------------------------------------------------------------- */
907 static void
908 done_mc (void)
910 /* Setup shutdown
912 * We sync the profiles since the hotlist may have changed, while
913 * we only change the setup data if we have the auto save feature set
915 char *curr_dir;
917 save_setup (auto_save_setup, panels_options.auto_save_setup);
919 curr_dir = vfs_get_current_dir ();
920 vfs_stamp_path (curr_dir);
921 g_free (curr_dir);
923 if ((current_panel != NULL) && (get_current_type () == view_listing))
925 char *tmp_path;
927 tmp_path = vfs_path_to_str (current_panel->cwd_vpath);
928 vfs_stamp_path (tmp_path);
929 g_free (tmp_path);
932 if ((other_panel != NULL) && (get_other_type () == view_listing))
934 char *tmp_path;
936 tmp_path = vfs_path_to_str (other_panel->cwd_vpath);
937 vfs_stamp_path (tmp_path);
938 g_free (tmp_path);
942 /* --------------------------------------------------------------------------------------------- */
944 static void
945 create_panels_and_run_mc (void)
947 midnight_dlg->get_shortcut = midnight_get_shortcut;
948 midnight_dlg->get_title = midnight_get_title;
950 create_panels ();
952 add_widget (midnight_dlg, the_menubar);
953 init_menu ();
955 add_widget (midnight_dlg, get_panel_widget (0));
956 add_widget (midnight_dlg, get_panel_widget (1));
958 add_widget (midnight_dlg, the_hint);
959 add_widget (midnight_dlg, cmdline);
960 add_widget (midnight_dlg, the_prompt);
962 add_widget (midnight_dlg, the_bar);
963 midnight_set_buttonbar (the_bar);
965 /* Run the Midnight Commander if no file was specified in the command line */
966 run_dlg (midnight_dlg);
969 /* --------------------------------------------------------------------------------------------- */
971 /** result must be free'd (I think this should go in util.c) */
972 static vfs_path_t *
973 prepend_cwd_on_local (const char *filename)
975 vfs_path_t *vpath;
977 vpath = vfs_path_from_str (filename);
978 if (!vfs_file_is_local (vpath) || g_path_is_absolute (filename))
979 return vpath;
981 vfs_path_free (vpath);
983 return vfs_path_append_new (vfs_get_raw_current_dir (), filename, NULL);
986 /* --------------------------------------------------------------------------------------------- */
988 /** Invoke the internal view/edit routine with:
989 * the default processing and forcing the internal viewer/editor
991 static gboolean
992 mc_maybe_editor_or_viewer (void)
994 gboolean ret;
996 switch (mc_global.mc_run_mode)
998 #ifdef USE_INTERNAL_EDIT
999 case MC_RUN_EDITOR:
1000 ret = edit_files ((GList *) mc_run_param0);
1001 break;
1002 #endif /* USE_INTERNAL_EDIT */
1003 case MC_RUN_VIEWER:
1005 vfs_path_t *vpath = NULL;
1007 if (mc_run_param0 != NULL && *(char *) mc_run_param0 != '\0')
1008 vpath = prepend_cwd_on_local ((char *) mc_run_param0);
1010 ret = view_file (vpath, 0, 1);
1011 vfs_path_free (vpath);
1012 break;
1014 #ifdef USE_DIFF_VIEW
1015 case MC_RUN_DIFFVIEWER:
1016 ret = dview_diff_cmd (mc_run_param0, mc_run_param1);
1017 break;
1018 #endif /* USE_DIFF_VIEW */
1019 default:
1020 ret = FALSE;
1023 return ret;
1026 /* --------------------------------------------------------------------------------------------- */
1028 static gboolean
1029 quit_cmd_internal (int quiet)
1031 int q = quit;
1032 size_t n;
1034 n = dialog_switch_num () - 1;
1035 if (n != 0)
1037 char msg[BUF_MEDIUM];
1039 g_snprintf (msg, sizeof (msg),
1040 ngettext ("You have %zd opened screen. Quit anyway?",
1041 "You have %zd opened screens. Quit anyway?", n), n);
1043 if (query_dialog (_("The Midnight Commander"), msg, D_NORMAL, 2, _("&Yes"), _("&No")) != 0)
1044 return FALSE;
1045 q = 1;
1047 else if (quiet || !confirm_exit)
1048 q = 1;
1049 else if (query_dialog (_("The Midnight Commander"),
1050 _("Do you really want to quit the Midnight Commander?"),
1051 D_NORMAL, 2, _("&Yes"), _("&No")) == 0)
1052 q = 1;
1054 if (q != 0)
1056 #ifdef ENABLE_SUBSHELL
1057 if (!mc_global.tty.use_subshell)
1058 stop_dialogs ();
1059 else if ((q = exit_subshell ()? 1 : 0) != 0)
1060 #endif
1061 stop_dialogs ();
1064 if (q != 0)
1065 quit |= 1;
1066 return (quit != 0);
1069 /* --------------------------------------------------------------------------------------------- */
1071 static gboolean
1072 quit_cmd (void)
1074 return quit_cmd_internal (0);
1077 /* --------------------------------------------------------------------------------------------- */
1079 static void
1080 toggle_show_hidden (void)
1082 panels_options.show_dot_files = !panels_options.show_dot_files;
1083 update_panels (UP_RELOAD, UP_KEEPSEL);
1086 /* --------------------------------------------------------------------------------------------- */
1089 * Repaint the contents of the panels without frames. To schedule panel
1090 * for repainting, set panel->dirty to 1. There are many reasons why
1091 * the panels need to be repainted, and this is a costly operation, so
1092 * it's done once per event.
1095 static void
1096 update_dirty_panels (void)
1098 if (get_current_type () == view_listing && current_panel->dirty)
1099 send_message (current_panel, NULL, MSG_DRAW, 0, NULL);
1101 if (get_other_type () == view_listing && other_panel->dirty)
1102 send_message (other_panel, NULL, MSG_DRAW, 0, NULL);
1105 /* --------------------------------------------------------------------------------------------- */
1107 static cb_ret_t
1108 midnight_execute_cmd (Widget * sender, unsigned long command)
1110 cb_ret_t res = MSG_HANDLED;
1112 (void) sender;
1114 /* stop quick search before executing any command */
1115 send_message (current_panel, NULL, MSG_ACTION, CK_SearchStop, NULL);
1117 switch (command)
1119 case CK_HotListAdd:
1120 add2hotlist_cmd ();
1121 break;
1122 case CK_PanelListingChange:
1123 change_listing_cmd ();
1124 break;
1125 case CK_ChangeMode:
1126 chmod_cmd ();
1127 break;
1128 case CK_ChangeOwn:
1129 chown_cmd ();
1130 break;
1131 case CK_ChangeOwnAdvanced:
1132 chown_advanced_cmd ();
1133 break;
1134 case CK_CompareDirs:
1135 compare_dirs_cmd ();
1136 break;
1137 case CK_Options:
1138 configure_box ();
1139 break;
1140 #ifdef ENABLE_VFS
1141 case CK_OptionsVfs:
1142 configure_vfs ();
1143 break;
1144 #endif
1145 case CK_OptionsConfirm:
1146 confirm_box ();
1147 break;
1148 case CK_Copy:
1149 copy_cmd ();
1150 break;
1151 case CK_PutCurrentPath:
1152 put_current_path ();
1153 break;
1154 case CK_PutCurrentLink:
1155 put_current_link ();
1156 break;
1157 case CK_PutCurrentTagged:
1158 put_current_tagged ();
1159 break;
1160 case CK_PutOtherPath:
1161 put_other_path ();
1162 break;
1163 case CK_PutOtherLink:
1164 put_other_link ();
1165 break;
1166 case CK_PutOtherTagged:
1167 put_other_tagged ();
1168 break;
1169 case CK_Delete:
1170 delete_cmd ();
1171 break;
1172 case CK_ScreenList:
1173 dialog_switch_list ();
1174 break;
1175 #ifdef USE_DIFF_VIEW
1176 case CK_CompareFiles:
1177 diff_view_cmd ();
1178 break;
1179 #endif
1180 case CK_OptionsDisplayBits:
1181 display_bits_box ();
1182 break;
1183 case CK_Edit:
1184 edit_cmd ();
1185 break;
1186 #ifdef USE_INTERNAL_EDIT
1187 case CK_EditForceInternal:
1188 edit_cmd_force_internal ();
1189 break;
1190 #endif
1191 case CK_EditExtensionsFile:
1192 ext_cmd ();
1193 break;
1194 case CK_EditFileHighlightFile:
1195 edit_fhl_cmd ();
1196 break;
1197 case CK_EditUserMenu:
1198 edit_mc_menu_cmd ();
1199 break;
1200 case CK_LinkSymbolicEdit:
1201 edit_symlink_cmd ();
1202 break;
1203 case CK_ExternalPanelize:
1204 external_panelize ();
1205 break;
1206 case CK_Filter:
1207 filter_cmd ();
1208 break;
1209 case CK_ViewFiltered:
1210 view_filtered_cmd ();
1211 break;
1212 case CK_Find:
1213 find_cmd ();
1214 break;
1215 #ifdef ENABLE_VFS_FISH
1216 case CK_ConnectFish:
1217 fishlink_cmd ();
1218 break;
1219 #endif
1220 #ifdef ENABLE_VFS_FTP
1221 case CK_ConnectFtp:
1222 ftplink_cmd ();
1223 break;
1224 #endif
1225 #ifdef ENABLE_VFS_SFTP
1226 case CK_ConnectSftp:
1227 sftplink_cmd ();
1228 break;
1229 #endif
1230 #ifdef ENABLE_VFS_SMB
1231 case CK_ConnectSmb:
1232 smblink_cmd ();
1233 break;
1234 #endif /* ENABLE_VFS_SMB */
1235 case CK_Panelize:
1236 cd_panelize_cmd ();
1237 break;
1238 case CK_Help:
1239 help_cmd ();
1240 break;
1241 case CK_History:
1242 /* show the history of command line widget */
1243 send_message (cmdline, NULL, MSG_ACTION, CK_History, NULL);
1244 break;
1245 case CK_PanelInfo:
1246 if (sender == WIDGET (the_menubar))
1247 info_cmd (); /* menu */
1248 else
1249 info_cmd_no_menu (); /* shortcut or buttonbar */
1250 break;
1251 #ifdef ENABLE_BACKGROUND
1252 case CK_Jobs:
1253 jobs_cmd ();
1254 break;
1255 #endif
1256 case CK_OptionsLayout:
1257 layout_box ();
1258 break;
1259 case CK_LearnKeys:
1260 learn_keys ();
1261 break;
1262 case CK_Link:
1263 link_cmd (LINK_HARDLINK);
1264 break;
1265 case CK_PanelListing:
1266 listing_cmd ();
1267 break;
1268 #ifdef LISTMODE_EDITOR
1269 case CK_ListMode:
1270 listmode_cmd ();
1271 break;
1272 #endif
1273 case CK_Menu:
1274 menu_cmd ();
1275 break;
1276 case CK_MenuLastSelected:
1277 menu_last_selected_cmd ();
1278 break;
1279 case CK_MakeDir:
1280 mkdir_cmd ();
1281 break;
1282 case CK_OptionsPanel:
1283 panel_options_box ();
1284 break;
1285 #ifdef HAVE_CHARSET
1286 case CK_SelectCodepage:
1287 encoding_cmd ();
1288 break;
1289 #endif
1290 case CK_CdQuick:
1291 quick_cd_cmd ();
1292 break;
1293 case CK_HotList:
1294 hotlist_cmd ();
1295 break;
1296 case CK_PanelQuickView:
1297 if (sender == WIDGET (the_menubar))
1298 quick_view_cmd (); /* menu */
1299 else
1300 quick_cmd_no_menu (); /* shortcut or buttonabr */
1301 break;
1302 case CK_QuitQuiet:
1303 quiet_quit_cmd ();
1304 break;
1305 case CK_Quit:
1306 quit_cmd ();
1307 break;
1308 case CK_LinkSymbolicRelative:
1309 link_cmd (LINK_SYMLINK_RELATIVE);
1310 break;
1311 case CK_Move:
1312 rename_cmd ();
1313 break;
1314 case CK_Reread:
1315 reread_cmd ();
1316 break;
1317 #ifdef ENABLE_VFS
1318 case CK_VfsList:
1319 vfs_list ();
1320 break;
1321 #endif
1322 case CK_SelectInvert:
1323 select_invert_cmd ();
1324 break;
1325 case CK_SaveSetup:
1326 save_setup_cmd ();
1327 break;
1328 case CK_Select:
1329 select_cmd ();
1330 break;
1331 case CK_Shell:
1332 view_other_cmd ();
1333 break;
1334 case CK_DirSize:
1335 smart_dirsize_cmd ();
1336 break;
1337 case CK_Sort:
1338 sort_cmd ();
1339 break;
1340 case CK_ExtendedKeyMap:
1341 ctl_x_cmd ();
1342 break;
1343 case CK_Suspend:
1344 mc_event_raise (MCEVENT_GROUP_CORE, "suspend", NULL);
1345 break;
1346 case CK_Swap:
1347 swap_cmd ();
1348 break;
1349 case CK_LinkSymbolic:
1350 link_cmd (LINK_SYMLINK_ABSOLUTE);
1351 break;
1352 case CK_PanelListingSwitch:
1353 toggle_listing_cmd ();
1354 break;
1355 case CK_ShowHidden:
1356 toggle_show_hidden ();
1357 break;
1358 case CK_SplitVertHoriz:
1359 toggle_panels_split ();
1360 break;
1361 case CK_SplitEqual:
1362 panels_split_equal ();
1363 break;
1364 case CK_SplitMore:
1365 panels_split_more ();
1366 break;
1367 case CK_SplitLess:
1368 panels_split_less ();
1369 break;
1370 case CK_PanelTree:
1371 panel_tree_cmd ();
1372 break;
1373 case CK_Tree:
1374 treebox_cmd ();
1375 break;
1376 #ifdef ENABLE_VFS_UNDELFS
1377 case CK_Undelete:
1378 undelete_cmd ();
1379 break;
1380 #endif
1381 case CK_Unselect:
1382 unselect_cmd ();
1383 break;
1384 case CK_UserMenu:
1385 user_file_menu_cmd ();
1386 break;
1387 case CK_View:
1388 view_cmd ();
1389 break;
1390 case CK_ViewFile:
1391 view_file_cmd ();
1392 break;
1393 case CK_Cancel:
1394 /* don't close panels due to SIGINT */
1395 break;
1396 default:
1397 res = MSG_NOT_HANDLED;
1400 return res;
1403 /* --------------------------------------------------------------------------------------------- */
1405 static cb_ret_t
1406 midnight_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
1408 unsigned long command;
1410 switch (msg)
1412 case MSG_INIT:
1413 panel_init ();
1414 setup_panels ();
1415 return MSG_HANDLED;
1417 case MSG_DRAW:
1418 load_hint (1);
1419 /* We handle the special case of the output lines */
1420 if (mc_global.tty.console_flag != '\0' && output_lines)
1421 show_console_contents (output_start_y,
1422 LINES - output_lines - mc_global.keybar_visible -
1423 1, LINES - mc_global.keybar_visible - 1);
1424 return MSG_HANDLED;
1426 case MSG_RESIZE:
1427 setup_panels ();
1428 menubar_arrange (the_menubar);
1429 return MSG_HANDLED;
1431 case MSG_IDLE:
1432 /* We only need the first idle event to show user menu after start */
1433 widget_want_idle (w, FALSE);
1435 if (boot_current_is_left)
1436 dlg_select_widget (get_panel_widget (0));
1437 else
1438 dlg_select_widget (get_panel_widget (1));
1440 if (auto_menu)
1441 midnight_execute_cmd (NULL, CK_UserMenu);
1442 return MSG_HANDLED;
1444 case MSG_KEY:
1445 if (ctl_x_map_enabled)
1447 ctl_x_map_enabled = FALSE;
1448 command = keybind_lookup_keymap_command (main_x_map, parm);
1449 if (command != CK_IgnoreKey)
1450 return midnight_execute_cmd (NULL, command);
1453 /* FIXME: should handle all menu shortcuts before this point */
1454 if (the_menubar->is_active)
1455 return MSG_NOT_HANDLED;
1457 if (parm == '\t')
1458 input_free_completions (cmdline);
1460 if (parm == '\n')
1462 size_t i;
1464 for (i = 0; cmdline->buffer[i] != '\0' &&
1465 (cmdline->buffer[i] == ' ' || cmdline->buffer[i] == '\t'); i++)
1468 if (cmdline->buffer[i] != '\0')
1470 send_message (cmdline, NULL, MSG_KEY, parm, NULL);
1471 return MSG_HANDLED;
1474 input_insert (cmdline, "", FALSE);
1475 cmdline->point = 0;
1478 /* Ctrl-Enter and Alt-Enter */
1479 if (((parm & ~(KEY_M_CTRL | KEY_M_ALT)) == '\n') && (parm & (KEY_M_CTRL | KEY_M_ALT)))
1481 put_prog_name ();
1482 return MSG_HANDLED;
1485 /* Ctrl-Shift-Enter */
1486 if (parm == (KEY_M_CTRL | KEY_M_SHIFT | '\n'))
1488 put_current_path ();
1489 put_prog_name ();
1490 return MSG_HANDLED;
1493 if ((!mc_global.tty.alternate_plus_minus
1494 || !(mc_global.tty.console_flag != '\0' || mc_global.tty.xterm_flag)) && !quote
1495 && !current_panel->searching)
1497 if (!only_leading_plus_minus)
1499 /* Special treatement, since the input line will eat them */
1500 if (parm == '+')
1502 select_cmd ();
1503 return MSG_HANDLED;
1506 if (parm == '\\' || parm == '-')
1508 unselect_cmd ();
1509 return MSG_HANDLED;
1512 if (parm == '*')
1514 select_invert_cmd ();
1515 return MSG_HANDLED;
1518 else if (!command_prompt || !cmdline->buffer[0])
1520 /* Special treatement '+', '-', '\', '*' only when this is
1521 * first char on input line
1524 if (parm == '+')
1526 select_cmd ();
1527 return MSG_HANDLED;
1530 if (parm == '\\' || parm == '-')
1532 unselect_cmd ();
1533 return MSG_HANDLED;
1536 if (parm == '*')
1538 select_invert_cmd ();
1539 return MSG_HANDLED;
1543 return MSG_NOT_HANDLED;
1545 case MSG_HOTKEY_HANDLED:
1546 if ((get_current_type () == view_listing) && current_panel->searching)
1548 current_panel->dirty = 1; /* FIXME: unneeded? */
1549 send_message (current_panel, NULL, MSG_ACTION, CK_SearchStop, NULL);
1551 return MSG_HANDLED;
1553 case MSG_UNHANDLED_KEY:
1555 cb_ret_t v = MSG_NOT_HANDLED;
1557 if (ctl_x_map_enabled)
1559 ctl_x_map_enabled = FALSE;
1560 command = keybind_lookup_keymap_command (main_x_map, parm);
1562 else
1563 command = keybind_lookup_keymap_command (main_map, parm);
1565 if (command != CK_IgnoreKey)
1566 v = midnight_execute_cmd (NULL, command);
1568 if (v == MSG_NOT_HANDLED && command_prompt)
1569 v = send_message (cmdline, NULL, MSG_KEY, parm, NULL);
1571 return v;
1574 case MSG_POST_KEY:
1575 if (!the_menubar->is_active)
1576 update_dirty_panels ();
1577 return MSG_HANDLED;
1579 case MSG_ACTION:
1580 /* shortcut */
1581 if (sender == NULL)
1582 return midnight_execute_cmd (NULL, parm);
1583 /* message from menu */
1584 if (sender == WIDGET (the_menubar))
1585 return midnight_execute_cmd (sender, parm);
1586 /* message from buttonbar */
1587 if (sender == WIDGET (the_bar))
1589 if (data != NULL)
1590 return send_message (data, NULL, MSG_ACTION, parm, NULL);
1591 return midnight_execute_cmd (sender, parm);
1593 return MSG_NOT_HANDLED;
1595 case MSG_END:
1596 panel_deinit ();
1597 return MSG_HANDLED;
1599 default:
1600 return dlg_default_callback (w, sender, msg, parm, data);
1604 /* --------------------------------------------------------------------------------------------- */
1606 static int
1607 midnight_event (Gpm_Event * event, void *data)
1609 Widget *wh = WIDGET (data);
1610 int ret = MOU_UNHANDLED;
1612 if (event->y == wh->y + 1)
1614 /* menubar */
1615 if (menubar_visible || the_menubar->is_active)
1616 ret = WIDGET (the_menubar)->mouse (event, the_menubar);
1617 else
1619 Widget *w;
1621 w = get_panel_widget (0);
1622 if (w->mouse != NULL)
1623 ret = w->mouse (event, w);
1625 if (ret == MOU_UNHANDLED)
1627 w = get_panel_widget (1);
1628 if (w->mouse != NULL)
1629 ret = w->mouse (event, w);
1632 if (ret == MOU_UNHANDLED)
1633 ret = WIDGET (the_menubar)->mouse (event, the_menubar);
1637 return ret;
1640 /* --------------------------------------------------------------------------------------------- */
1641 /*** public functions ****************************************************************************/
1642 /* --------------------------------------------------------------------------------------------- */
1644 void
1645 update_menu (void)
1647 menu_set_name (left_menu, panels_layout.horizontal_split ? _("&Above") : _("&Left"));
1648 menu_set_name (right_menu, panels_layout.horizontal_split ? _("&Below") : _("&Right"));
1649 menubar_arrange (the_menubar);
1650 menubar_set_visible (the_menubar, menubar_visible);
1653 /* --------------------------------------------------------------------------------------------- */
1655 void
1656 midnight_set_buttonbar (WButtonBar * b)
1658 buttonbar_set_label (b, 1, Q_ ("ButtonBar|Help"), main_map, NULL);
1659 buttonbar_set_label (b, 2, Q_ ("ButtonBar|Menu"), main_map, NULL);
1660 buttonbar_set_label (b, 3, Q_ ("ButtonBar|View"), main_map, NULL);
1661 buttonbar_set_label (b, 4, Q_ ("ButtonBar|Edit"), main_map, NULL);
1662 buttonbar_set_label (b, 5, Q_ ("ButtonBar|Copy"), main_map, NULL);
1663 buttonbar_set_label (b, 6, Q_ ("ButtonBar|RenMov"), main_map, NULL);
1664 buttonbar_set_label (b, 7, Q_ ("ButtonBar|Mkdir"), main_map, NULL);
1665 buttonbar_set_label (b, 8, Q_ ("ButtonBar|Delete"), main_map, NULL);
1666 buttonbar_set_label (b, 9, Q_ ("ButtonBar|PullDn"), main_map, NULL);
1667 buttonbar_set_label (b, 10, Q_ ("ButtonBar|Quit"), main_map, NULL);
1670 /* --------------------------------------------------------------------------------------------- */
1672 * Load new hint and display it.
1673 * IF force is not 0, ignore the timeout.
1676 void
1677 load_hint (gboolean force)
1679 char *hint;
1681 if (WIDGET (the_hint)->owner == NULL)
1682 return;
1684 if (!mc_global.message_visible)
1686 label_set_text (the_hint, NULL);
1687 return;
1690 hint = get_random_hint (force);
1692 if (hint != NULL)
1694 if (*hint != '\0')
1695 set_hintbar (hint);
1696 g_free (hint);
1698 else
1700 char text[BUF_SMALL];
1702 g_snprintf (text, sizeof (text), _("GNU Midnight Commander %s\n"), VERSION);
1703 set_hintbar (text);
1707 /* --------------------------------------------------------------------------------------------- */
1709 void
1710 change_panel (void)
1712 input_free_completions (cmdline);
1713 dlg_one_down (midnight_dlg);
1716 /* --------------------------------------------------------------------------------------------- */
1718 /** Save current stat of directories to avoid reloading the panels
1719 * when no modifications have taken place
1721 void
1722 save_cwds_stat (void)
1724 if (panels_options.fast_reload)
1726 mc_stat (current_panel->cwd_vpath, &(current_panel->dir_stat));
1727 if (get_other_type () == view_listing)
1728 mc_stat (other_panel->cwd_vpath, &(other_panel->dir_stat));
1732 /* --------------------------------------------------------------------------------------------- */
1734 gboolean
1735 quiet_quit_cmd (void)
1737 print_last_revert = TRUE;
1738 return quit_cmd_internal (1);
1741 /* --------------------------------------------------------------------------------------------- */
1743 /** Run the main dialog that occupies the whole screen */
1744 gboolean
1745 do_nc (void)
1747 gboolean ret;
1749 dlg_colors_t midnight_colors;
1751 midnight_colors[DLG_COLOR_NORMAL] = mc_skin_color_get ("dialog", "_default_");
1752 midnight_colors[DLG_COLOR_FOCUS] = mc_skin_color_get ("dialog", "focus");
1753 midnight_colors[DLG_COLOR_HOT_NORMAL] = mc_skin_color_get ("dialog", "hotnormal");
1754 midnight_colors[DLG_COLOR_HOT_FOCUS] = mc_skin_color_get ("dialog", "hotfocus");
1755 midnight_colors[DLG_COLOR_TITLE] = mc_skin_color_get ("dialog", "title");
1757 #ifdef USE_INTERNAL_EDIT
1758 edit_stack_init ();
1759 #endif
1761 midnight_dlg = create_dlg (FALSE, 0, 0, LINES, COLS, midnight_colors, midnight_callback,
1762 midnight_event, "[main]", NULL, DLG_NONE);
1764 /* Check if we were invoked as an editor or file viewer */
1765 if (mc_global.mc_run_mode != MC_RUN_FULL)
1767 setup_dummy_mc ();
1768 ret = mc_maybe_editor_or_viewer ();
1770 else
1772 /* We only need the first idle event to show user menu after start */
1773 widget_want_idle (WIDGET (midnight_dlg), TRUE);
1775 setup_mc ();
1776 mc_filehighlight = mc_fhl_new (TRUE);
1777 create_panels_and_run_mc ();
1778 mc_fhl_free (&mc_filehighlight);
1780 ret = TRUE;
1782 /* destroy_dlg destroys even current_panel->cwd_vpath, so we have to save a copy :) */
1783 if (mc_args__last_wd_file != NULL && vfs_current_is_local ())
1784 last_wd_string = vfs_path_to_str (current_panel->cwd_vpath);
1786 /* don't handle VFS timestamps for dirs opened in panels */
1787 mc_event_destroy (MCEVENT_GROUP_CORE, "vfs_timestamp");
1789 clean_dir (&panelized_panel.list, panelized_panel.count);
1792 /* Program end */
1793 mc_global.midnight_shutdown = TRUE;
1794 dialog_switch_shutdown ();
1795 done_mc ();
1796 destroy_dlg (midnight_dlg);
1797 current_panel = NULL;
1799 #ifdef USE_INTERNAL_EDIT
1800 edit_stack_free ();
1801 #endif
1803 if ((quit & SUBSHELL_EXIT) == 0)
1804 clr_scr ();
1806 return ret;
1809 /* --------------------------------------------------------------------------------------------- */