Fix mouse event handling in menu that overlaps buttonbar.
[midnight-commander.git] / src / filemanager / midnight.c
blob0ba2fd8e29ac2f7f2cead7552b7b1aa4a4c5cbc9
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 #include "src/subshell.h"
59 #include "src/setup.h" /* variables */
60 #include "src/learn.h" /* learn_keys() */
61 #include "src/keybind-defaults.h"
62 #include "lib/keybind.h"
63 #include "lib/event.h"
65 #include "option.h" /* configure_box() */
66 #include "tree.h"
67 #include "boxes.h" /* sort_box(), tree_box() */
68 #include "layout.h"
69 #include "cmd.h" /* commands */
70 #include "hotlist.h"
71 #include "panelize.h"
72 #include "command.h" /* cmdline */
73 #include "dir.h" /* clean_dir() */
75 #include "chmod.h"
76 #include "chown.h"
77 #include "achown.h"
79 #ifdef USE_INTERNAL_EDIT
80 #include "src/editor/edit.h"
81 #endif
83 #ifdef USE_DIFF_VIEW
84 #include "src/diffviewer/ydiff.h"
85 #endif
87 #include "src/consaver/cons.saver.h" /* show_console_contents */
89 #include "midnight.h"
91 /* TODO: merge content of layout.c here */
92 extern int ok_to_refresh;
94 /*** global variables ****************************************************************************/
96 /* When the modes are active, left_panel, right_panel and tree_panel */
97 /* point to a proper data structure. You should check with the functions */
98 /* get_current_type and get_other_type the types of the panels before using */
99 /* this pointer variables */
101 /* The structures for the panels */
102 WPanel *left_panel = NULL;
103 WPanel *right_panel = NULL;
104 /* Pointer to the selected and unselected panel */
105 WPanel *current_panel = NULL;
107 /* The Menubar */
108 WMenuBar *the_menubar = NULL;
109 /* The widget where we draw the prompt */
110 WLabel *the_prompt;
111 /* The hint bar */
112 WLabel *the_hint;
113 /* The button bar */
114 WButtonBar *the_bar;
116 /*** file scope macro definitions ****************************************************************/
118 #ifdef HAVE_CHARSET
120 * Don't restrict the output on the screen manager level,
121 * the translation tables take care of it.
123 #endif /* !HAVE_CHARSET */
125 /*** file scope type declarations ****************************************************************/
127 /*** file scope variables ************************************************************************/
129 static Menu *left_menu, *right_menu;
131 static gboolean ctl_x_map_enabled = FALSE;
133 /*** file scope functions ************************************************************************/
135 /** Stop MC main dialog and the current dialog if it exists.
136 * Needed to provide fast exit from MC viewer or editor on shell exit */
137 static void
138 stop_dialogs (void)
140 midnight_dlg->state = DLG_CLOSED;
142 if ((top_dlg != NULL) && (top_dlg->data != NULL))
143 ((Dlg_head *) top_dlg->data)->state = DLG_CLOSED;
146 /* --------------------------------------------------------------------------------------------- */
148 static void
149 treebox_cmd (void)
151 char *sel_dir;
153 sel_dir = tree_box (selection (current_panel)->fname);
154 if (sel_dir != NULL)
156 vfs_path_t *sel_vdir;
158 sel_vdir = vfs_path_from_str (sel_dir);
159 do_cd (sel_vdir, cd_exact);
160 vfs_path_free (sel_vdir);
161 g_free (sel_dir);
165 /* --------------------------------------------------------------------------------------------- */
167 #ifdef LISTMODE_EDITOR
168 static void
169 listmode_cmd (void)
171 char *newmode;
173 if (get_current_type () != view_listing)
174 return;
176 newmode = listmode_edit (current_panel->user_format);
177 if (!newmode)
178 return;
180 g_free (current_panel->user_format);
181 current_panel->list_type = list_user;
182 current_panel->user_format = newmode;
183 set_panel_formats (current_panel);
185 do_refresh ();
187 #endif /* LISTMODE_EDITOR */
189 /* --------------------------------------------------------------------------------------------- */
191 static GList *
192 create_panel_menu (void)
194 GList *entries = NULL;
196 entries = g_list_prepend (entries, menu_entry_create (_("File listin&g"), CK_PanelListing));
197 entries = g_list_prepend (entries, menu_entry_create (_("&Quick view"), CK_PanelQuickView));
198 entries = g_list_prepend (entries, menu_entry_create (_("&Info"), CK_PanelInfo));
199 entries = g_list_prepend (entries, menu_entry_create (_("&Tree"), CK_PanelTree));
200 entries = g_list_prepend (entries, menu_separator_create ());
201 entries =
202 g_list_prepend (entries, menu_entry_create (_("&Listing mode..."), CK_PanelListingChange));
203 entries = g_list_prepend (entries, menu_entry_create (_("&Sort order..."), CK_Sort));
204 entries = g_list_prepend (entries, menu_entry_create (_("&Filter..."), CK_Filter));
205 #ifdef HAVE_CHARSET
206 entries = g_list_prepend (entries, menu_entry_create (_("&Encoding..."), CK_SelectCodepage));
207 #endif
208 entries = g_list_prepend (entries, menu_separator_create ());
209 #ifdef ENABLE_VFS_FTP
210 entries = g_list_prepend (entries, menu_entry_create (_("FT&P link..."), CK_ConnectFtp));
211 #endif
212 #ifdef ENABLE_VFS_FISH
213 entries = g_list_prepend (entries, menu_entry_create (_("S&hell link..."), CK_ConnectFish));
214 #endif
215 #ifdef ENABLE_VFS_SFTP
216 entries = g_list_prepend (entries, menu_entry_create (_("S&FTP link..."), CK_ConnectSftp));
217 #endif
218 #ifdef ENABLE_VFS_SMB
219 entries = g_list_prepend (entries, menu_entry_create (_("SM&B link..."), CK_ConnectSmb));
220 #endif
221 entries = g_list_prepend (entries, menu_entry_create (_("Paneli&ze"), CK_Panelize));
222 entries = g_list_prepend (entries, menu_separator_create ());
223 entries = g_list_prepend (entries, menu_entry_create (_("&Rescan"), CK_Reread));
225 return g_list_reverse (entries);
228 /* --------------------------------------------------------------------------------------------- */
230 static GList *
231 create_file_menu (void)
233 GList *entries = NULL;
235 entries = g_list_prepend (entries, menu_entry_create (_("&View"), CK_View));
236 entries = g_list_prepend (entries, menu_entry_create (_("Vie&w file..."), CK_ViewFile));
237 entries = g_list_prepend (entries, menu_entry_create (_("&Filtered view"), CK_ViewFiltered));
238 entries = g_list_prepend (entries, menu_entry_create (_("&Edit"), CK_Edit));
239 entries = g_list_prepend (entries, menu_entry_create (_("&Copy"), CK_Copy));
240 entries = g_list_prepend (entries, menu_entry_create (_("C&hmod"), CK_ChangeMode));
241 entries = g_list_prepend (entries, menu_entry_create (_("&Link"), CK_Link));
242 entries = g_list_prepend (entries, menu_entry_create (_("&Symlink"), CK_LinkSymbolic));
243 entries =
244 g_list_prepend (entries,
245 menu_entry_create (_("Relative symlin&k"), CK_LinkSymbolicRelative));
246 entries = g_list_prepend (entries, menu_entry_create (_("Edit s&ymlink"), CK_LinkSymbolicEdit));
247 entries = g_list_prepend (entries, menu_entry_create (_("Ch&own"), CK_ChangeOwn));
248 entries =
249 g_list_prepend (entries, menu_entry_create (_("&Advanced chown"), CK_ChangeOwnAdvanced));
250 entries = g_list_prepend (entries, menu_entry_create (_("&Rename/Move"), CK_Move));
251 entries = g_list_prepend (entries, menu_entry_create (_("&Mkdir"), CK_MakeDir));
252 entries = g_list_prepend (entries, menu_entry_create (_("&Delete"), CK_Delete));
253 entries = g_list_prepend (entries, menu_entry_create (_("&Quick cd"), CK_CdQuick));
254 entries = g_list_prepend (entries, menu_separator_create ());
255 entries = g_list_prepend (entries, menu_entry_create (_("Select &group"), CK_Select));
256 entries = g_list_prepend (entries, menu_entry_create (_("U&nselect group"), CK_Unselect));
257 entries = g_list_prepend (entries, menu_entry_create (_("&Invert selection"), CK_SelectInvert));
258 entries = g_list_prepend (entries, menu_separator_create ());
259 entries = g_list_prepend (entries, menu_entry_create (_("E&xit"), CK_Quit));
261 return g_list_reverse (entries);
264 /* --------------------------------------------------------------------------------------------- */
266 static GList *
267 create_command_menu (void)
269 /* I know, I'm lazy, but the tree widget when it's not running
270 * as a panel still has some problems, I have not yet finished
271 * the WTree widget port, sorry.
273 GList *entries = NULL;
275 entries = g_list_prepend (entries, menu_entry_create (_("&User menu"), CK_UserMenu));
276 entries = g_list_prepend (entries, menu_entry_create (_("&Directory tree"), CK_Tree));
277 entries = g_list_prepend (entries, menu_entry_create (_("&Find file"), CK_Find));
278 entries = g_list_prepend (entries, menu_entry_create (_("S&wap panels"), CK_Swap));
279 entries = g_list_prepend (entries, menu_entry_create (_("Switch &panels on/off"), CK_Shell));
280 entries =
281 g_list_prepend (entries, menu_entry_create (_("&Compare directories"), CK_CompareDirs));
282 #ifdef USE_DIFF_VIEW
283 entries = g_list_prepend (entries, menu_entry_create (_("C&ompare files"), CK_CompareFiles));
284 #endif
285 entries =
286 g_list_prepend (entries, menu_entry_create (_("E&xternal panelize"), CK_ExternalPanelize));
287 entries = g_list_prepend (entries, menu_entry_create (_("Show directory s&izes"), CK_DirSize));
288 entries = g_list_prepend (entries, menu_separator_create ());
289 entries = g_list_prepend (entries, menu_entry_create (_("Command &history"), CK_History));
290 entries = g_list_prepend (entries, menu_entry_create (_("Di&rectory hotlist"), CK_HotList));
291 #ifdef ENABLE_VFS
292 entries = g_list_prepend (entries, menu_entry_create (_("&Active VFS list"), CK_VfsList));
293 #endif
294 #ifdef ENABLE_BACKGROUND
295 entries = g_list_prepend (entries, menu_entry_create (_("&Background jobs"), CK_Jobs));
296 #endif
297 entries = g_list_prepend (entries, menu_entry_create (_("Screen lis&t"), CK_ScreenList));
298 entries = g_list_prepend (entries, menu_separator_create ());
299 #ifdef ENABLE_VFS_UNDELFS
300 entries =
301 g_list_prepend (entries,
302 menu_entry_create (_("&Undelete files (ext2fs only)"), CK_Undelete));
303 #endif
304 #ifdef LISTMODE_EDITOR
305 entries = g_list_prepend (entries, menu_entry_create (_("&Listing format edit"), CK_ListMode));
306 #endif
307 #if defined (ENABLE_VFS_UNDELFS) || defined (LISTMODE_EDITOR)
308 entries = g_list_prepend (entries, menu_separator_create ());
309 #endif
310 entries =
311 g_list_prepend (entries,
312 menu_entry_create (_("Edit &extension file"), CK_EditExtensionsFile));
313 entries = g_list_prepend (entries, menu_entry_create (_("Edit &menu file"), CK_EditUserMenu));
314 entries =
315 g_list_prepend (entries,
316 menu_entry_create (_("Edit hi&ghlighting group file"),
317 CK_EditFileHighlightFile));
319 return g_list_reverse (entries);
322 /* --------------------------------------------------------------------------------------------- */
324 static GList *
325 create_options_menu (void)
327 GList *entries = NULL;
329 entries = g_list_prepend (entries, menu_entry_create (_("&Configuration..."), CK_Options));
330 entries = g_list_prepend (entries, menu_entry_create (_("&Layout..."), CK_OptionsLayout));
331 entries = g_list_prepend (entries, menu_entry_create (_("&Panel options..."), CK_OptionsPanel));
332 entries =
333 g_list_prepend (entries, menu_entry_create (_("C&onfirmation..."), CK_OptionsConfirm));
334 entries =
335 g_list_prepend (entries, menu_entry_create (_("&Display bits..."), CK_OptionsDisplayBits));
336 entries = g_list_prepend (entries, menu_entry_create (_("Learn &keys..."), CK_LearnKeys));
337 #ifdef ENABLE_VFS
338 entries = g_list_prepend (entries, menu_entry_create (_("&Virtual FS..."), CK_OptionsVfs));
339 #endif
340 entries = g_list_prepend (entries, menu_separator_create ());
341 entries = g_list_prepend (entries, menu_entry_create (_("&Save setup"), CK_SaveSetup));
343 return g_list_reverse (entries);
346 /* --------------------------------------------------------------------------------------------- */
348 static void
349 init_menu (void)
351 left_menu = create_menu ("", create_panel_menu (), "[Left and Right Menus]");
352 menubar_add_menu (the_menubar, left_menu);
353 menubar_add_menu (the_menubar, create_menu (_("&File"), create_file_menu (), "[File Menu]"));
354 menubar_add_menu (the_menubar,
355 create_menu (_("&Command"), create_command_menu (), "[Command Menu]"));
356 menubar_add_menu (the_menubar,
357 create_menu (_("&Options"), create_options_menu (), "[Options Menu]"));
358 right_menu = create_menu ("", create_panel_menu (), "[Left and Right Menus]");
359 menubar_add_menu (the_menubar, right_menu);
360 update_menu ();
363 /* --------------------------------------------------------------------------------------------- */
365 static void
366 menu_last_selected_cmd (void)
368 the_menubar->is_active = TRUE;
369 the_menubar->is_dropped = (drop_menus != 0);
370 the_menubar->previous_widget = dlg_get_current_widget_id (midnight_dlg);
371 dlg_select_widget (the_menubar);
374 /* --------------------------------------------------------------------------------------------- */
376 static void
377 menu_cmd (void)
379 if (the_menubar->is_active)
380 return;
382 if ((get_current_index () == 0) == (current_panel->active != 0))
383 the_menubar->selected = 0;
384 else
385 the_menubar->selected = g_list_length (the_menubar->menu) - 1;
386 menu_last_selected_cmd ();
389 /* --------------------------------------------------------------------------------------------- */
391 static void
392 sort_cmd (void)
394 WPanel *p;
395 const panel_field_t *sort_order;
397 if (!SELECTED_IS_PANEL)
398 return;
400 p = MENU_PANEL;
401 sort_order = sort_box (&p->sort_info);
402 panel_set_sort_order (p, sort_order);
405 /* --------------------------------------------------------------------------------------------- */
407 static char *
408 midnight_get_shortcut (unsigned long command)
410 const char *ext_map;
411 const char *shortcut = NULL;
413 shortcut = keybind_lookup_keymap_shortcut (main_map, command);
414 if (shortcut != NULL)
415 return g_strdup (shortcut);
417 shortcut = keybind_lookup_keymap_shortcut (panel_map, command);
418 if (shortcut != NULL)
419 return g_strdup (shortcut);
421 ext_map = keybind_lookup_keymap_shortcut (main_map, CK_ExtendedKeyMap);
422 if (ext_map != NULL)
423 shortcut = keybind_lookup_keymap_shortcut (main_x_map, command);
424 if (shortcut != NULL)
425 return g_strdup_printf ("%s %s", ext_map, shortcut);
427 return NULL;
430 /* --------------------------------------------------------------------------------------------- */
432 static char *
433 midnight_get_title (const Dlg_head * h, size_t len)
435 char *path;
436 char *login;
437 char *p;
439 (void) h;
441 title_path_prepare (&path, &login);
443 p = g_strdup_printf ("%s [%s]:%s", _("Panels:"), login, path);
444 g_free (path);
445 g_free (login);
446 path = g_strdup (str_trunc (p, len - 4));
447 g_free (p);
449 return path;
452 /* --------------------------------------------------------------------------------------------- */
454 static void
455 toggle_panels_split (void)
457 panels_layout.horizontal_split = !panels_layout.horizontal_split;
458 layout_change ();
459 do_refresh ();
462 /* --------------------------------------------------------------------------------------------- */
464 #ifdef ENABLE_VFS
465 /* event helper */
466 static gboolean
467 check_panel_timestamp (const WPanel * panel, panel_view_mode_t mode, struct vfs_class *vclass,
468 vfsid id)
470 if (mode == view_listing)
472 const vfs_path_element_t *path_element;
474 path_element = vfs_path_get_by_index (panel->cwd_vpath, -1);
476 if (path_element->class != vclass)
477 return FALSE;
479 if (vfs_getid (panel->cwd_vpath) != id)
480 return FALSE;
482 return TRUE;
485 /* --------------------------------------------------------------------------------------------- */
487 /* event callback */
488 static gboolean
489 check_current_panel_timestamp (const gchar * event_group_name, const gchar * event_name,
490 gpointer init_data, gpointer data)
492 ev_vfs_stamp_create_t *event_data = (ev_vfs_stamp_create_t *) data;
494 (void) event_group_name;
495 (void) event_name;
496 (void) init_data;
498 event_data->ret =
499 check_panel_timestamp (current_panel, get_current_type (), event_data->vclass,
500 event_data->id);
501 return !event_data->ret;
504 /* --------------------------------------------------------------------------------------------- */
506 /* event callback */
507 static gboolean
508 check_other_panel_timestamp (const gchar * event_group_name, const gchar * event_name,
509 gpointer init_data, gpointer data)
511 ev_vfs_stamp_create_t *event_data = (ev_vfs_stamp_create_t *) data;
513 (void) event_group_name;
514 (void) event_name;
515 (void) init_data;
517 event_data->ret =
518 check_panel_timestamp (other_panel, get_other_type (), event_data->vclass, event_data->id);
519 return !event_data->ret;
521 #endif /* ENABLE_VFS */
523 /* --------------------------------------------------------------------------------------------- */
525 /* event callback */
526 static gboolean
527 print_vfs_message (const gchar * event_group_name, const gchar * event_name,
528 gpointer init_data, gpointer data)
530 char str[128];
531 ev_vfs_print_message_t *event_data = (ev_vfs_print_message_t *) data;
533 (void) event_group_name;
534 (void) event_name;
535 (void) init_data;
537 g_vsnprintf (str, sizeof (str), event_data->msg, event_data->ap);
539 if (mc_global.midnight_shutdown)
540 return TRUE;
542 if (!mc_global.message_visible || !the_hint || !the_hint->widget.owner)
544 int col, row;
546 if (!nice_rotating_dash || (ok_to_refresh <= 0))
547 return TRUE;
549 /* Preserve current cursor position */
550 tty_getyx (&row, &col);
552 tty_gotoyx (0, 0);
553 tty_setcolor (NORMAL_COLOR);
554 tty_print_string (str_fit_to_term (str, COLS - 1, J_LEFT));
556 /* Restore cursor position */
557 tty_gotoyx (row, col);
558 mc_refresh ();
559 return TRUE;
562 if (mc_global.message_visible)
563 set_hintbar (str);
565 return TRUE;
568 /* --------------------------------------------------------------------------------------------- */
570 static void
571 create_panels (void)
573 int current_index, other_index;
574 panel_view_mode_t current_mode, other_mode;
575 char *current_dir, *other_dir;
576 vfs_path_t *original_dir;
578 if (boot_current_is_left)
580 /* left panel is active */
581 current_index = 0;
582 other_index = 1;
583 current_mode = startup_left_mode;
584 other_mode = startup_right_mode;
585 /* if mc_run_param0 is NULL, working directory will be used for the left panel */
586 current_dir = (char *) mc_run_param0;
587 /* mc_run_param1 is never NULL. It is setup from command line or from panels.ini
588 * (value of other_dir). mc_run_param1 will be used for the right panel */
589 other_dir = mc_run_param1;
591 else
593 /* right panel is active */
594 current_index = 1;
595 other_index = 0;
596 current_mode = startup_right_mode;
597 other_mode = startup_left_mode;
599 /* if mc_run_param0 is not NULL (it was setup from command line), it will be used
600 * for the left panel, working directory will be used for the right one;
601 * if mc_run_param0 is NULL, working directory will be used for the right (active) panel,
602 * mc_run_param1 will be used for the left one */
603 if (mc_run_param0 != NULL)
605 current_dir = NULL;
606 other_dir = (char *) mc_run_param0;
608 else
610 current_dir = NULL;
611 other_dir = mc_run_param1;
615 /* 1. Get current dir */
616 original_dir = vfs_path_clone (vfs_get_raw_current_dir ());
618 /* 2. Create passive panel */
619 if (other_dir != NULL)
621 vfs_path_t *vpath;
623 if (g_path_is_absolute (other_dir))
624 vpath = vfs_path_from_str (other_dir);
625 else
626 vpath = vfs_path_append_new (original_dir, other_dir, (char *) NULL);
627 mc_chdir (vpath);
628 vfs_path_free (vpath);
630 set_display_type (other_index, other_mode);
632 /* 3. Create active panel */
633 if (current_dir == NULL)
634 mc_chdir (original_dir);
635 else
637 vfs_path_t *vpath;
639 if (g_path_is_absolute (current_dir))
640 vpath = vfs_path_from_str (current_dir);
641 else
642 vpath = vfs_path_append_new (original_dir, current_dir, (char *) NULL);
643 mc_chdir (vpath);
644 vfs_path_free (vpath);
646 set_display_type (current_index, current_mode);
648 if (startup_left_mode == view_listing)
649 current_panel = left_panel;
650 else if (right_panel != NULL)
651 current_panel = right_panel;
652 else
653 current_panel = left_panel;
655 vfs_path_free (original_dir);
657 #ifdef ENABLE_VFS
658 mc_event_add (MCEVENT_GROUP_CORE, "vfs_timestamp", check_other_panel_timestamp, NULL, NULL);
659 mc_event_add (MCEVENT_GROUP_CORE, "vfs_timestamp", check_current_panel_timestamp, NULL, NULL);
660 #endif /* ENABLE_VFS */
662 mc_event_add (MCEVENT_GROUP_CORE, "vfs_print_message", print_vfs_message, NULL, NULL);
664 /* Create the nice widgets */
665 cmdline = command_new (0, 0, 0);
666 the_prompt = label_new (0, 0, mc_prompt);
667 the_prompt->transparent = 1;
668 the_bar = buttonbar_new (mc_global.keybar_visible);
670 the_hint = label_new (0, 0, 0);
671 the_hint->transparent = 1;
672 the_hint->auto_adjust_cols = 0;
673 the_hint->widget.cols = COLS;
675 the_menubar = menubar_new (0, 0, COLS, NULL);
678 /* --------------------------------------------------------------------------------------------- */
680 static void
681 put_current_path (void)
683 char *cwd_path;
685 if (!command_prompt)
686 return;
688 #ifdef HAVE_CHARSET
690 vfs_path_t *cwd_vpath;
692 cwd_vpath = remove_encoding_from_path (current_panel->cwd_vpath);
693 cwd_path = vfs_path_to_str (cwd_vpath);
694 vfs_path_free (cwd_vpath);
696 #else
697 cwd_path = vfs_path_to_str (current_panel->cwd_vpath);
698 #endif
700 command_insert (cmdline, cwd_path, FALSE);
701 if (cwd_path[strlen (cwd_path) - 1] != PATH_SEP)
702 command_insert (cmdline, PATH_SEP_STR, FALSE);
704 g_free (cwd_path);
707 /* --------------------------------------------------------------------------------------------- */
709 static void
710 put_other_path (void)
712 char *cwd_path;
714 if (get_other_type () != view_listing)
715 return;
717 if (!command_prompt)
718 return;
720 #ifdef HAVE_CHARSET
722 vfs_path_t *cwd_vpath;
724 cwd_vpath = remove_encoding_from_path (other_panel->cwd_vpath);
725 cwd_path = vfs_path_to_str (cwd_vpath);
726 vfs_path_free (cwd_vpath);
728 #else
729 cwd_path = vfs_path_to_str (other_panel->cwd_vpath);
730 #endif
732 command_insert (cmdline, cwd_path, FALSE);
733 if (cwd_path[strlen (cwd_path) - 1] != PATH_SEP)
734 command_insert (cmdline, PATH_SEP_STR, FALSE);
736 g_free (cwd_path);
739 /* --------------------------------------------------------------------------------------------- */
741 static void
742 put_link (WPanel * panel)
744 if (!command_prompt)
745 return;
746 if (S_ISLNK (selection (panel)->st.st_mode))
748 char buffer[MC_MAXPATHLEN];
749 vfs_path_t *vpath;
750 int i;
752 vpath = vfs_path_append_new (panel->cwd_vpath, selection (panel)->fname, NULL);
753 i = mc_readlink (vpath, buffer, MC_MAXPATHLEN - 1);
754 vfs_path_free (vpath);
756 if (i > 0)
758 buffer[i] = '\0';
759 command_insert (cmdline, buffer, TRUE);
764 /* --------------------------------------------------------------------------------------------- */
766 static void
767 put_current_link (void)
769 put_link (current_panel);
772 /* --------------------------------------------------------------------------------------------- */
774 static void
775 put_other_link (void)
777 if (get_other_type () == view_listing)
778 put_link (other_panel);
781 /* --------------------------------------------------------------------------------------------- */
783 /** Insert the selected file name into the input line */
784 static void
785 put_prog_name (void)
787 char *tmp;
788 if (!command_prompt)
789 return;
791 if (get_current_type () == view_tree)
793 WTree *tree = (WTree *) get_panel_widget (get_current_index ());
795 tmp = vfs_path_to_str (tree_selected_name (tree));
797 else
798 tmp = g_strdup (selection (current_panel)->fname);
800 command_insert (cmdline, tmp, TRUE);
801 g_free (tmp);
804 /* --------------------------------------------------------------------------------------------- */
806 static void
807 put_tagged (WPanel * panel)
809 int i;
811 if (!command_prompt)
812 return;
813 input_disable_update (cmdline);
814 if (panel->marked)
816 for (i = 0; i < panel->count; i++)
818 if (panel->dir.list[i].f.marked)
819 command_insert (cmdline, panel->dir.list[i].fname, TRUE);
822 else
824 command_insert (cmdline, panel->dir.list[panel->selected].fname, TRUE);
826 input_enable_update (cmdline);
829 /* --------------------------------------------------------------------------------------------- */
831 static void
832 put_current_tagged (void)
834 put_tagged (current_panel);
837 /* --------------------------------------------------------------------------------------------- */
839 static void
840 put_other_tagged (void)
842 if (get_other_type () == view_listing)
843 put_tagged (other_panel);
846 /* --------------------------------------------------------------------------------------------- */
848 static void
849 ctl_x_cmd (void)
851 ctl_x_map_enabled = TRUE;
854 /* --------------------------------------------------------------------------------------------- */
856 static void
857 setup_mc (void)
859 #ifdef HAVE_SLANG
860 #ifdef HAVE_CHARSET
861 tty_display_8bit (TRUE);
862 #else
863 tty_display_8bit (mc_global.full_eight_bits != 0);
864 #endif /* HAVE_CHARSET */
866 #else /* HAVE_SLANG */
868 #ifdef HAVE_CHARSET
869 tty_display_8bit (TRUE);
870 #else
871 tty_display_8bit (mc_global.eight_bit_clean != 0);
872 #endif /* HAVE_CHARSET */
873 #endif /* HAVE_SLANG */
875 #ifdef HAVE_SUBSHELL_SUPPORT
876 if (mc_global.tty.use_subshell)
877 add_select_channel (mc_global.tty.subshell_pty, load_prompt, 0);
878 #endif /* !HAVE_SUBSHELL_SUPPORT */
880 if ((tty_baudrate () < 9600) || mc_global.tty.slow_terminal)
881 verbose = 0;
884 /* --------------------------------------------------------------------------------------------- */
886 static void
887 setup_dummy_mc (void)
889 vfs_path_t *vpath;
890 char *d;
891 int ret;
893 d = _vfs_get_cwd ();
894 setup_mc ();
895 vpath = vfs_path_from_str (d);
896 ret = mc_chdir (vpath);
897 vfs_path_free (vpath);
898 g_free (d);
901 /* --------------------------------------------------------------------------------------------- */
903 static void
904 done_mc (void)
906 /* Setup shutdown
908 * We sync the profiles since the hotlist may have changed, while
909 * we only change the setup data if we have the auto save feature set
911 char *curr_dir;
913 save_setup (auto_save_setup, panels_options.auto_save_setup);
915 curr_dir = vfs_get_current_dir ();
916 vfs_stamp_path (curr_dir);
917 g_free (curr_dir);
919 if ((current_panel != NULL) && (get_current_type () == view_listing))
921 char *tmp_path;
923 tmp_path = vfs_path_to_str (current_panel->cwd_vpath);
924 vfs_stamp_path (tmp_path);
925 g_free (tmp_path);
928 if ((other_panel != NULL) && (get_other_type () == view_listing))
930 char *tmp_path;
932 tmp_path = vfs_path_to_str (other_panel->cwd_vpath);
933 vfs_stamp_path (tmp_path);
934 g_free (tmp_path);
938 /* --------------------------------------------------------------------------------------------- */
940 static void
941 create_panels_and_run_mc (void)
943 midnight_dlg->get_shortcut = midnight_get_shortcut;
944 midnight_dlg->get_title = midnight_get_title;
946 create_panels ();
948 add_widget (midnight_dlg, the_menubar);
949 init_menu ();
951 add_widget (midnight_dlg, get_panel_widget (0));
952 add_widget (midnight_dlg, get_panel_widget (1));
954 add_widget (midnight_dlg, the_hint);
955 add_widget (midnight_dlg, cmdline);
956 add_widget (midnight_dlg, the_prompt);
958 add_widget (midnight_dlg, the_bar);
959 midnight_set_buttonbar (the_bar);
961 /* Run the Midnight Commander if no file was specified in the command line */
962 run_dlg (midnight_dlg);
965 /* --------------------------------------------------------------------------------------------- */
967 /** result must be free'd (I think this should go in util.c) */
968 static vfs_path_t *
969 prepend_cwd_on_local (const char *filename)
971 vfs_path_t *vpath;
973 vpath = vfs_path_from_str (filename);
974 if (!vfs_file_is_local (vpath) || g_path_is_absolute (filename))
975 return vpath;
977 vfs_path_free (vpath);
979 return vfs_path_append_new (vfs_get_raw_current_dir (), filename, NULL);
982 /* --------------------------------------------------------------------------------------------- */
984 /** Invoke the internal view/edit routine with:
985 * the default processing and forcing the internal viewer/editor
987 static gboolean
988 mc_maybe_editor_or_viewer (void)
990 gboolean ret;
992 switch (mc_global.mc_run_mode)
994 #ifdef USE_INTERNAL_EDIT
995 case MC_RUN_EDITOR:
996 ret = edit_files ((GList *) mc_run_param0);
997 break;
998 #endif /* USE_INTERNAL_EDIT */
999 case MC_RUN_VIEWER:
1001 vfs_path_t *vpath = NULL;
1003 if (mc_run_param0 != NULL && *(char *) mc_run_param0 != '\0')
1004 vpath = prepend_cwd_on_local ((char *) mc_run_param0);
1006 ret = view_file (vpath, 0, 1);
1007 vfs_path_free (vpath);
1008 break;
1010 #ifdef USE_DIFF_VIEW
1011 case MC_RUN_DIFFVIEWER:
1012 ret = dview_diff_cmd (mc_run_param0, mc_run_param1);
1013 break;
1014 #endif /* USE_DIFF_VIEW */
1015 default:
1016 ret = FALSE;
1019 return ret;
1022 /* --------------------------------------------------------------------------------------------- */
1024 static gboolean
1025 quit_cmd_internal (int quiet)
1027 int q = quit;
1028 size_t n;
1030 n = dialog_switch_num () - 1;
1031 if (n != 0)
1033 char msg[BUF_MEDIUM];
1035 g_snprintf (msg, sizeof (msg),
1036 ngettext ("You have %zd opened screen. Quit anyway?",
1037 "You have %zd opened screens. Quit anyway?", n), n);
1039 if (query_dialog (_("The Midnight Commander"), msg, D_NORMAL, 2, _("&Yes"), _("&No")) != 0)
1040 return FALSE;
1041 q = 1;
1043 else if (quiet || !confirm_exit)
1044 q = 1;
1045 else if (query_dialog (_("The Midnight Commander"),
1046 _("Do you really want to quit the Midnight Commander?"),
1047 D_NORMAL, 2, _("&Yes"), _("&No")) == 0)
1048 q = 1;
1050 if (q != 0)
1052 #ifdef HAVE_SUBSHELL_SUPPORT
1053 if (!mc_global.tty.use_subshell)
1054 stop_dialogs ();
1055 else if ((q = exit_subshell ()))
1056 #endif
1057 stop_dialogs ();
1060 if (q != 0)
1061 quit |= 1;
1062 return (quit != 0);
1065 /* --------------------------------------------------------------------------------------------- */
1067 static gboolean
1068 quit_cmd (void)
1070 return quit_cmd_internal (0);
1073 /* --------------------------------------------------------------------------------------------- */
1075 static void
1076 toggle_show_hidden (void)
1078 panels_options.show_dot_files = !panels_options.show_dot_files;
1079 update_panels (UP_RELOAD, UP_KEEPSEL);
1082 /* --------------------------------------------------------------------------------------------- */
1085 * Repaint the contents of the panels without frames. To schedule panel
1086 * for repainting, set panel->dirty to 1. There are many reasons why
1087 * the panels need to be repainted, and this is a costly operation, so
1088 * it's done once per event.
1091 static void
1092 update_dirty_panels (void)
1094 if (get_current_type () == view_listing && current_panel->dirty)
1095 send_message ((Widget *) current_panel, WIDGET_DRAW, 0);
1097 if (get_other_type () == view_listing && other_panel->dirty)
1098 send_message ((Widget *) other_panel, WIDGET_DRAW, 0);
1101 /* --------------------------------------------------------------------------------------------- */
1103 static cb_ret_t
1104 midnight_execute_cmd (Widget * sender, unsigned long command)
1106 cb_ret_t res = MSG_HANDLED;
1108 (void) sender;
1110 /* stop quick search before executing any command */
1111 send_message ((Widget *) current_panel, WIDGET_COMMAND, CK_SearchStop);
1113 switch (command)
1115 case CK_HotListAdd:
1116 add2hotlist_cmd ();
1117 break;
1118 case CK_PanelListingChange:
1119 change_listing_cmd ();
1120 break;
1121 case CK_ChangeMode:
1122 chmod_cmd ();
1123 break;
1124 case CK_ChangeOwn:
1125 chown_cmd ();
1126 break;
1127 case CK_ChangeOwnAdvanced:
1128 chown_advanced_cmd ();
1129 break;
1130 case CK_CompareDirs:
1131 compare_dirs_cmd ();
1132 break;
1133 case CK_Options:
1134 configure_box ();
1135 break;
1136 #ifdef ENABLE_VFS
1137 case CK_OptionsVfs:
1138 configure_vfs ();
1139 break;
1140 #endif
1141 case CK_OptionsConfirm:
1142 confirm_box ();
1143 break;
1144 case CK_Copy:
1145 copy_cmd ();
1146 break;
1147 case CK_PutCurrentPath:
1148 put_current_path ();
1149 break;
1150 case CK_PutCurrentLink:
1151 put_current_link ();
1152 break;
1153 case CK_PutCurrentTagged:
1154 put_current_tagged ();
1155 break;
1156 case CK_PutOtherPath:
1157 put_other_path ();
1158 break;
1159 case CK_PutOtherLink:
1160 put_other_link ();
1161 break;
1162 case CK_PutOtherTagged:
1163 put_other_tagged ();
1164 break;
1165 case CK_Delete:
1166 delete_cmd ();
1167 break;
1168 case CK_ScreenList:
1169 dialog_switch_list ();
1170 break;
1171 #ifdef USE_DIFF_VIEW
1172 case CK_CompareFiles:
1173 diff_view_cmd ();
1174 break;
1175 #endif
1176 case CK_OptionsDisplayBits:
1177 display_bits_box ();
1178 break;
1179 case CK_Edit:
1180 edit_cmd ();
1181 break;
1182 #ifdef USE_INTERNAL_EDIT
1183 case CK_EditForceInternal:
1184 edit_cmd_force_internal ();
1185 break;
1186 #endif
1187 case CK_EditExtensionsFile:
1188 ext_cmd ();
1189 break;
1190 case CK_EditFileHighlightFile:
1191 edit_fhl_cmd ();
1192 break;
1193 case CK_EditUserMenu:
1194 edit_mc_menu_cmd ();
1195 break;
1196 case CK_LinkSymbolicEdit:
1197 edit_symlink_cmd ();
1198 break;
1199 case CK_ExternalPanelize:
1200 external_panelize ();
1201 break;
1202 case CK_Filter:
1203 filter_cmd ();
1204 break;
1205 case CK_ViewFiltered:
1206 view_filtered_cmd ();
1207 break;
1208 case CK_Find:
1209 find_cmd ();
1210 break;
1211 #ifdef ENABLE_VFS_FISH
1212 case CK_ConnectFish:
1213 fishlink_cmd ();
1214 break;
1215 #endif
1216 #ifdef ENABLE_VFS_FTP
1217 case CK_ConnectFtp:
1218 ftplink_cmd ();
1219 break;
1220 #endif
1221 #ifdef ENABLE_VFS_SFTP
1222 case CK_ConnectSftp:
1223 sftplink_cmd ();
1224 break;
1225 #endif
1226 #ifdef ENABLE_VFS_SMB
1227 case CK_ConnectSmb:
1228 smblink_cmd ();
1229 break;
1230 #endif /* ENABLE_VFS_SMB */
1231 case CK_Panelize:
1232 cd_panelize_cmd ();
1233 break;
1234 case CK_Help:
1235 help_cmd ();
1236 break;
1237 case CK_History:
1238 /* show the history of command line widget */
1239 send_message (&cmdline->widget, WIDGET_COMMAND, CK_History);
1240 break;
1241 case CK_PanelInfo:
1242 if (sender == (Widget *) the_menubar)
1243 info_cmd (); /* menu */
1244 else
1245 info_cmd_no_menu (); /* shortcut or buttonbar */
1246 break;
1247 #ifdef ENABLE_BACKGROUND
1248 case CK_Jobs:
1249 jobs_cmd ();
1250 break;
1251 #endif
1252 case CK_OptionsLayout:
1253 layout_box ();
1254 break;
1255 case CK_LearnKeys:
1256 learn_keys ();
1257 break;
1258 case CK_Link:
1259 link_cmd (LINK_HARDLINK);
1260 break;
1261 case CK_PanelListing:
1262 listing_cmd ();
1263 break;
1264 #ifdef LISTMODE_EDITOR
1265 case CK_ListMode:
1266 listmode_cmd ();
1267 break;
1268 #endif
1269 case CK_Menu:
1270 menu_cmd ();
1271 break;
1272 case CK_MenuLastSelected:
1273 menu_last_selected_cmd ();
1274 break;
1275 case CK_MakeDir:
1276 mkdir_cmd ();
1277 break;
1278 case CK_OptionsPanel:
1279 panel_options_box ();
1280 break;
1281 #ifdef HAVE_CHARSET
1282 case CK_SelectCodepage:
1283 encoding_cmd ();
1284 break;
1285 #endif
1286 case CK_CdQuick:
1287 quick_cd_cmd ();
1288 break;
1289 case CK_HotList:
1290 hotlist_cmd ();
1291 break;
1292 case CK_PanelQuickView:
1293 if (sender == (Widget *) the_menubar)
1294 quick_view_cmd (); /* menu */
1295 else
1296 quick_cmd_no_menu (); /* shortcut or buttonabr */
1297 break;
1298 case CK_QuitQuiet:
1299 quiet_quit_cmd ();
1300 break;
1301 case CK_Quit:
1302 quit_cmd ();
1303 break;
1304 case CK_LinkSymbolicRelative:
1305 link_cmd (LINK_SYMLINK_RELATIVE);
1306 break;
1307 case CK_Move:
1308 rename_cmd ();
1309 break;
1310 case CK_Reread:
1311 reread_cmd ();
1312 break;
1313 #ifdef ENABLE_VFS
1314 case CK_VfsList:
1315 vfs_list ();
1316 break;
1317 #endif
1318 case CK_SelectInvert:
1319 select_invert_cmd ();
1320 break;
1321 case CK_SaveSetup:
1322 save_setup_cmd ();
1323 break;
1324 case CK_Select:
1325 select_cmd ();
1326 break;
1327 case CK_Shell:
1328 view_other_cmd ();
1329 break;
1330 case CK_DirSize:
1331 smart_dirsize_cmd ();
1332 break;
1333 case CK_Sort:
1334 sort_cmd ();
1335 break;
1336 case CK_ExtendedKeyMap:
1337 ctl_x_cmd ();
1338 break;
1339 case CK_Suspend:
1340 mc_event_raise (MCEVENT_GROUP_CORE, "suspend", NULL);
1341 break;
1342 case CK_Swap:
1343 swap_cmd ();
1344 break;
1345 case CK_LinkSymbolic:
1346 link_cmd (LINK_SYMLINK_ABSOLUTE);
1347 break;
1348 case CK_PanelListingSwitch:
1349 toggle_listing_cmd ();
1350 break;
1351 case CK_ShowHidden:
1352 toggle_show_hidden ();
1353 break;
1354 case CK_SplitVertHoriz:
1355 toggle_panels_split ();
1356 break;
1357 case CK_SplitEqual:
1358 panels_split_equal ();
1359 break;
1360 case CK_SplitMore:
1361 panels_split_more ();
1362 break;
1363 case CK_SplitLess:
1364 panels_split_less ();
1365 break;
1366 case CK_PanelTree:
1367 panel_tree_cmd ();
1368 break;
1369 case CK_Tree:
1370 treebox_cmd ();
1371 break;
1372 #ifdef ENABLE_VFS_UNDELFS
1373 case CK_Undelete:
1374 undelete_cmd ();
1375 break;
1376 #endif
1377 case CK_Unselect:
1378 unselect_cmd ();
1379 break;
1380 case CK_UserMenu:
1381 user_file_menu_cmd ();
1382 break;
1383 case CK_View:
1384 view_cmd ();
1385 break;
1386 case CK_ViewFile:
1387 view_file_cmd ();
1388 break;
1389 case CK_Cancel:
1390 /* don't close panels due to SIGINT */
1391 break;
1392 default:
1393 res = MSG_NOT_HANDLED;
1396 return res;
1399 /* --------------------------------------------------------------------------------------------- */
1401 static cb_ret_t
1402 midnight_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
1404 unsigned long command;
1406 switch (msg)
1408 case DLG_INIT:
1409 panel_init ();
1410 setup_panels ();
1411 return MSG_HANDLED;
1413 case DLG_DRAW:
1414 load_hint (1);
1415 /* We handle the special case of the output lines */
1416 if (mc_global.tty.console_flag != '\0' && output_lines)
1417 show_console_contents (output_start_y,
1418 LINES - output_lines - mc_global.keybar_visible -
1419 1, LINES - mc_global.keybar_visible - 1);
1420 return MSG_HANDLED;
1422 case DLG_RESIZE:
1423 setup_panels ();
1424 menubar_arrange (the_menubar);
1425 return MSG_HANDLED;
1427 case DLG_IDLE:
1428 /* We only need the first idle event to show user menu after start */
1429 set_idle_proc (h, 0);
1431 if (boot_current_is_left)
1432 dlg_select_widget (get_panel_widget (0));
1433 else
1434 dlg_select_widget (get_panel_widget (1));
1436 if (auto_menu)
1437 midnight_execute_cmd (NULL, CK_UserMenu);
1438 return MSG_HANDLED;
1440 case DLG_KEY:
1441 if (ctl_x_map_enabled)
1443 ctl_x_map_enabled = FALSE;
1444 command = keybind_lookup_keymap_command (main_x_map, parm);
1445 if (command != CK_IgnoreKey)
1446 return midnight_execute_cmd (NULL, command);
1449 /* FIXME: should handle all menu shortcuts before this point */
1450 if (the_menubar->is_active)
1451 return MSG_NOT_HANDLED;
1453 if (parm == '\t')
1454 input_free_completions (cmdline);
1456 if (parm == '\n')
1458 size_t i;
1460 for (i = 0; cmdline->buffer[i] != '\0' &&
1461 (cmdline->buffer[i] == ' ' || cmdline->buffer[i] == '\t'); i++)
1464 if (cmdline->buffer[i] != '\0')
1466 send_message ((Widget *) cmdline, WIDGET_KEY, parm);
1467 return MSG_HANDLED;
1470 input_insert (cmdline, "", FALSE);
1471 cmdline->point = 0;
1474 /* Ctrl-Enter and Alt-Enter */
1475 if (((parm & ~(KEY_M_CTRL | KEY_M_ALT)) == '\n') && (parm & (KEY_M_CTRL | KEY_M_ALT)))
1477 put_prog_name ();
1478 return MSG_HANDLED;
1481 /* Ctrl-Shift-Enter */
1482 if (parm == (KEY_M_CTRL | KEY_M_SHIFT | '\n'))
1484 put_current_path ();
1485 put_prog_name ();
1486 return MSG_HANDLED;
1489 if ((!mc_global.tty.alternate_plus_minus
1490 || !(mc_global.tty.console_flag != '\0' || mc_global.tty.xterm_flag)) && !quote
1491 && !current_panel->searching)
1493 if (!only_leading_plus_minus)
1495 /* Special treatement, since the input line will eat them */
1496 if (parm == '+')
1498 select_cmd ();
1499 return MSG_HANDLED;
1502 if (parm == '\\' || parm == '-')
1504 unselect_cmd ();
1505 return MSG_HANDLED;
1508 if (parm == '*')
1510 select_invert_cmd ();
1511 return MSG_HANDLED;
1514 else if (!command_prompt || !cmdline->buffer[0])
1516 /* Special treatement '+', '-', '\', '*' only when this is
1517 * first char on input line
1520 if (parm == '+')
1522 select_cmd ();
1523 return MSG_HANDLED;
1526 if (parm == '\\' || parm == '-')
1528 unselect_cmd ();
1529 return MSG_HANDLED;
1532 if (parm == '*')
1534 select_invert_cmd ();
1535 return MSG_HANDLED;
1539 return MSG_NOT_HANDLED;
1541 case DLG_HOTKEY_HANDLED:
1542 if ((get_current_type () == view_listing) && current_panel->searching)
1544 current_panel->dirty = 1; /* FIXME: unneeded? */
1545 send_message ((Widget *) current_panel, WIDGET_COMMAND, CK_SearchStop);
1547 return MSG_HANDLED;
1549 case DLG_UNHANDLED_KEY:
1551 cb_ret_t v = MSG_NOT_HANDLED;
1553 if (ctl_x_map_enabled)
1555 ctl_x_map_enabled = FALSE;
1556 command = keybind_lookup_keymap_command (main_x_map, parm);
1558 else
1559 command = keybind_lookup_keymap_command (main_map, parm);
1561 if (command != CK_IgnoreKey)
1562 v = midnight_execute_cmd (NULL, command);
1564 if (v == MSG_NOT_HANDLED && command_prompt)
1565 v = send_message ((Widget *) cmdline, WIDGET_KEY, parm);
1567 return v;
1570 case DLG_POST_KEY:
1571 if (!the_menubar->is_active)
1572 update_dirty_panels ();
1573 return MSG_HANDLED;
1575 case DLG_ACTION:
1576 /* shortcut */
1577 if (sender == NULL)
1578 return midnight_execute_cmd (NULL, parm);
1579 /* message from menu */
1580 if (sender == (Widget *) the_menubar)
1581 return midnight_execute_cmd (sender, parm);
1582 /* message from buttonbar */
1583 if (sender == (Widget *) the_bar)
1585 if (data != NULL)
1586 return send_message ((Widget *) data, WIDGET_COMMAND, parm);
1587 return midnight_execute_cmd (sender, parm);
1589 return MSG_NOT_HANDLED;
1591 case DLG_END:
1592 panel_deinit ();
1593 return MSG_HANDLED;
1595 default:
1596 return default_dlg_callback (h, sender, msg, parm, data);
1600 /* --------------------------------------------------------------------------------------------- */
1602 static int
1603 midnight_event (Gpm_Event * event, void *data)
1605 Dlg_head *h = (Dlg_head *) data;
1606 int ret = MOU_UNHANDLED;
1608 if (event->y == h->y + 1)
1610 /* menubar */
1611 if (menubar_visible || the_menubar->is_active)
1612 ret = ((Widget *) the_menubar)->mouse (event, the_menubar);
1613 else
1615 Widget *w;
1617 w = get_panel_widget (0);
1618 if (w->mouse != NULL)
1619 ret = w->mouse (event, w);
1621 if (ret == MOU_UNHANDLED)
1623 w = get_panel_widget (1);
1624 if (w->mouse != NULL)
1625 ret = w->mouse (event, w);
1628 if (ret == MOU_UNHANDLED)
1629 ret = ((Widget *) the_menubar)->mouse (event, the_menubar);
1633 return ret;
1636 /* --------------------------------------------------------------------------------------------- */
1637 /*** public functions ****************************************************************************/
1638 /* --------------------------------------------------------------------------------------------- */
1640 void
1641 update_menu (void)
1643 menu_set_name (left_menu, panels_layout.horizontal_split ? _("&Above") : _("&Left"));
1644 menu_set_name (right_menu, panels_layout.horizontal_split ? _("&Below") : _("&Right"));
1645 menubar_arrange (the_menubar);
1646 menubar_set_visible (the_menubar, menubar_visible);
1649 /* --------------------------------------------------------------------------------------------- */
1651 void
1652 midnight_set_buttonbar (WButtonBar * b)
1654 buttonbar_set_label (b, 1, Q_ ("ButtonBar|Help"), main_map, NULL);
1655 buttonbar_set_label (b, 2, Q_ ("ButtonBar|Menu"), main_map, NULL);
1656 buttonbar_set_label (b, 3, Q_ ("ButtonBar|View"), main_map, NULL);
1657 buttonbar_set_label (b, 4, Q_ ("ButtonBar|Edit"), main_map, NULL);
1658 buttonbar_set_label (b, 5, Q_ ("ButtonBar|Copy"), main_map, NULL);
1659 buttonbar_set_label (b, 6, Q_ ("ButtonBar|RenMov"), main_map, NULL);
1660 buttonbar_set_label (b, 7, Q_ ("ButtonBar|Mkdir"), main_map, NULL);
1661 buttonbar_set_label (b, 8, Q_ ("ButtonBar|Delete"), main_map, NULL);
1662 buttonbar_set_label (b, 9, Q_ ("ButtonBar|PullDn"), main_map, NULL);
1663 buttonbar_set_label (b, 10, Q_ ("ButtonBar|Quit"), main_map, NULL);
1666 /* --------------------------------------------------------------------------------------------- */
1668 * Load new hint and display it.
1669 * IF force is not 0, ignore the timeout.
1672 void
1673 load_hint (gboolean force)
1675 char *hint;
1677 if (the_hint->widget.owner == NULL)
1678 return;
1680 if (!mc_global.message_visible)
1682 label_set_text (the_hint, NULL);
1683 return;
1686 hint = get_random_hint (force);
1688 if (hint != NULL)
1690 if (*hint != '\0')
1691 set_hintbar (hint);
1692 g_free (hint);
1694 else
1696 char text[BUF_SMALL];
1698 g_snprintf (text, sizeof (text), _("GNU Midnight Commander %s\n"), VERSION);
1699 set_hintbar (text);
1703 /* --------------------------------------------------------------------------------------------- */
1705 void
1706 change_panel (void)
1708 input_free_completions (cmdline);
1709 dlg_one_down (midnight_dlg);
1712 /* --------------------------------------------------------------------------------------------- */
1714 /** Save current stat of directories to avoid reloading the panels
1715 * when no modifications have taken place
1717 void
1718 save_cwds_stat (void)
1720 if (panels_options.fast_reload)
1722 mc_stat (current_panel->cwd_vpath, &(current_panel->dir_stat));
1723 if (get_other_type () == view_listing)
1724 mc_stat (other_panel->cwd_vpath, &(other_panel->dir_stat));
1728 /* --------------------------------------------------------------------------------------------- */
1730 gboolean
1731 quiet_quit_cmd (void)
1733 print_last_revert = TRUE;
1734 return quit_cmd_internal (1);
1737 /* --------------------------------------------------------------------------------------------- */
1739 /** Run the main dialog that occupies the whole screen */
1740 gboolean
1741 do_nc (void)
1743 gboolean ret;
1745 dlg_colors_t midnight_colors;
1747 midnight_colors[DLG_COLOR_NORMAL] = mc_skin_color_get ("dialog", "_default_");
1748 midnight_colors[DLG_COLOR_FOCUS] = mc_skin_color_get ("dialog", "focus");
1749 midnight_colors[DLG_COLOR_HOT_NORMAL] = mc_skin_color_get ("dialog", "hotnormal");
1750 midnight_colors[DLG_COLOR_HOT_FOCUS] = mc_skin_color_get ("dialog", "hotfocus");
1751 midnight_colors[DLG_COLOR_TITLE] = mc_skin_color_get ("dialog", "title");
1753 #ifdef USE_INTERNAL_EDIT
1754 edit_stack_init ();
1755 #endif
1757 midnight_dlg = create_dlg (FALSE, 0, 0, LINES, COLS, midnight_colors, midnight_callback,
1758 midnight_event, "[main]", NULL, DLG_WANT_IDLE);
1760 if (mc_global.mc_run_mode == MC_RUN_FULL)
1761 setup_mc ();
1762 else
1763 setup_dummy_mc ();
1765 /* Check if we were invoked as an editor or file viewer */
1766 if (mc_global.mc_run_mode != MC_RUN_FULL)
1767 ret = mc_maybe_editor_or_viewer ();
1768 else
1770 create_panels_and_run_mc ();
1771 ret = TRUE;
1773 /* destroy_dlg destroys even current_panel->cwd_vpath, so we have to save a copy :) */
1774 if (mc_args__last_wd_file != NULL && vfs_current_is_local ())
1775 last_wd_string = vfs_path_to_str (current_panel->cwd_vpath);
1777 /* don't handle VFS timestamps for dirs opened in panels */
1778 mc_event_destroy (MCEVENT_GROUP_CORE, "vfs_timestamp");
1780 clean_dir (&panelized_panel.list, panelized_panel.count);
1783 /* Program end */
1784 mc_global.midnight_shutdown = TRUE;
1785 dialog_switch_shutdown ();
1786 done_mc ();
1787 destroy_dlg (midnight_dlg);
1788 current_panel = NULL;
1790 #ifdef USE_INTERNAL_EDIT
1791 edit_stack_free ();
1792 #endif
1794 if ((quit & SUBSHELL_EXIT) == 0)
1795 clr_scr ();
1797 return ret;
1800 /* --------------------------------------------------------------------------------------------- */