a7073813eda06a598e79b7a8d3597b30a4fc278c
[midnight-commander.git] / src / filemanager / midnight.c
bloba7073813eda06a598e79b7a8d3597b30a4fc278c
1 /*
2 Main dialog (file panels) of the Midnight Commander
4 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
5 2003, 2004, 2005, 2006, 2007, 2009, 2010, 2011
6 The Free Software Foundation, Inc.
8 Written by:
9 Miguel de Icaza, 1994, 1995, 1996, 1997
10 Janne Kukonlehto, 1994, 1995
11 Norbert Warmuth, 1997
12 Andrew Borodin <aborodin@vmail.ru>, 2009, 2010
14 This file is part of the Midnight Commander.
16 The Midnight Commander is free software: you can redistribute it
17 and/or modify it under the terms of the GNU General Public License as
18 published by the Free Software Foundation, either version 3 of the License,
19 or (at your option) any later version.
21 The Midnight Commander is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program. If not, see <http://www.gnu.org/licenses/>.
30 /** \file main.c
31 * \brief Source: main dialog (file panels) of the Midnight Commander
34 #include <config.h>
36 #include <ctype.h>
37 #include <errno.h>
38 #include <locale.h>
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <string.h>
42 #include <fcntl.h>
43 #include <sys/types.h>
44 #include <sys/stat.h>
45 #include <sys/wait.h>
46 #include <pwd.h> /* for username in xterm title */
48 #include "lib/global.h"
50 #include "lib/tty/tty.h"
51 #include "lib/tty/key.h" /* KEY_M_* masks */
52 #include "lib/skin.h"
53 #include "lib/util.h"
55 #include "lib/vfs/vfs.h"
57 #include "src/args.h"
58 #ifdef ENABLE_SUBSHELL
59 #include "src/subshell.h"
60 #endif
61 #include "src/setup.h" /* variables */
62 #include "src/learn.h" /* learn_keys() */
63 #include "src/keybind-defaults.h"
64 #include "lib/keybind.h"
65 #include "lib/event.h"
67 #include "option.h" /* configure_box() */
68 #include "tree.h"
69 #include "boxes.h" /* sort_box(), tree_box() */
70 #include "layout.h"
71 #include "cmd.h" /* commands */
72 #include "hotlist.h"
73 #include "panelize.h"
74 #include "command.h" /* cmdline */
75 #include "dir.h" /* clean_dir() */
77 #include "chmod.h"
78 #include "chown.h"
79 #include "achown.h"
81 #ifdef USE_INTERNAL_EDIT
82 #include "src/editor/edit.h"
83 #endif
85 #ifdef USE_DIFF_VIEW
86 #include "src/diffviewer/ydiff.h"
87 #endif
89 #include "src/consaver/cons.saver.h" /* show_console_contents */
91 #include "midnight.h"
93 /* TODO: merge content of layout.c here */
94 extern int ok_to_refresh;
96 /*** global variables ****************************************************************************/
98 /* When the modes are active, left_panel, right_panel and tree_panel */
99 /* point to a proper data structure. You should check with the functions */
100 /* get_current_type and get_other_type the types of the panels before using */
101 /* this pointer variables */
103 /* The structures for the panels */
104 WPanel *left_panel = NULL;
105 WPanel *right_panel = NULL;
106 /* Pointer to the selected and unselected panel */
107 WPanel *current_panel = NULL;
109 /* The Menubar */
110 WMenuBar *the_menubar = NULL;
111 /* The widget where we draw the prompt */
112 WLabel *the_prompt;
113 /* The hint bar */
114 WLabel *the_hint;
115 /* The button bar */
116 WButtonBar *the_bar;
118 /*** file scope macro definitions ****************************************************************/
120 #ifdef HAVE_CHARSET
122 * Don't restrict the output on the screen manager level,
123 * the translation tables take care of it.
125 #endif /* !HAVE_CHARSET */
127 /*** file scope type declarations ****************************************************************/
129 /*** file scope variables ************************************************************************/
131 static menu_t *left_menu, *right_menu;
133 static gboolean ctl_x_map_enabled = FALSE;
135 /*** file scope functions ************************************************************************/
137 /** Stop MC main dialog and the current dialog if it exists.
138 * Needed to provide fast exit from MC viewer or editor on shell exit */
139 static void
140 stop_dialogs (void)
142 midnight_dlg->state = DLG_CLOSED;
144 if ((top_dlg != NULL) && (top_dlg->data != NULL))
145 DIALOG (top_dlg->data)->state = DLG_CLOSED;
148 /* --------------------------------------------------------------------------------------------- */
150 static void
151 treebox_cmd (void)
153 char *sel_dir;
155 sel_dir = tree_box (selection (current_panel)->fname);
156 if (sel_dir != NULL)
158 vfs_path_t *sel_vdir;
160 sel_vdir = vfs_path_from_str (sel_dir);
161 do_cd (sel_vdir, cd_exact);
162 vfs_path_free (sel_vdir);
163 g_free (sel_dir);
167 /* --------------------------------------------------------------------------------------------- */
169 #ifdef LISTMODE_EDITOR
170 static void
171 listmode_cmd (void)
173 char *newmode;
175 if (get_current_type () != view_listing)
176 return;
178 newmode = listmode_edit (current_panel->user_format);
179 if (!newmode)
180 return;
182 g_free (current_panel->user_format);
183 current_panel->list_type = list_user;
184 current_panel->user_format = newmode;
185 set_panel_formats (current_panel);
187 do_refresh ();
189 #endif /* LISTMODE_EDITOR */
191 /* --------------------------------------------------------------------------------------------- */
193 static GList *
194 create_panel_menu (void)
196 GList *entries = NULL;
198 entries = g_list_prepend (entries, menu_entry_create (_("File listin&g"), CK_PanelListing));
199 entries = g_list_prepend (entries, menu_entry_create (_("&Quick view"), CK_PanelQuickView));
200 entries = g_list_prepend (entries, menu_entry_create (_("&Info"), CK_PanelInfo));
201 entries = g_list_prepend (entries, menu_entry_create (_("&Tree"), CK_PanelTree));
202 entries = g_list_prepend (entries, menu_separator_create ());
203 entries =
204 g_list_prepend (entries, menu_entry_create (_("&Listing mode..."), CK_PanelListingChange));
205 entries = g_list_prepend (entries, menu_entry_create (_("&Sort order..."), CK_Sort));
206 entries = g_list_prepend (entries, menu_entry_create (_("&Filter..."), CK_Filter));
207 #ifdef HAVE_CHARSET
208 entries = g_list_prepend (entries, menu_entry_create (_("&Encoding..."), CK_SelectCodepage));
209 #endif
210 entries = g_list_prepend (entries, menu_separator_create ());
211 #ifdef ENABLE_VFS_FTP
212 entries = g_list_prepend (entries, menu_entry_create (_("FT&P link..."), CK_ConnectFtp));
213 #endif
214 #ifdef ENABLE_VFS_FISH
215 entries = g_list_prepend (entries, menu_entry_create (_("S&hell link..."), CK_ConnectFish));
216 #endif
217 #ifdef ENABLE_VFS_SFTP
218 entries = g_list_prepend (entries, menu_entry_create (_("S&FTP link..."), CK_ConnectSftp));
219 #endif
220 #ifdef ENABLE_VFS_SMB
221 entries = g_list_prepend (entries, menu_entry_create (_("SM&B link..."), CK_ConnectSmb));
222 #endif
223 entries = g_list_prepend (entries, menu_entry_create (_("Paneli&ze"), CK_Panelize));
224 entries = g_list_prepend (entries, menu_separator_create ());
225 entries = g_list_prepend (entries, menu_entry_create (_("&Rescan"), CK_Reread));
227 return g_list_reverse (entries);
230 /* --------------------------------------------------------------------------------------------- */
232 static GList *
233 create_file_menu (void)
235 GList *entries = NULL;
237 entries = g_list_prepend (entries, menu_entry_create (_("&View"), CK_View));
238 entries = g_list_prepend (entries, menu_entry_create (_("Vie&w file..."), CK_ViewFile));
239 entries = g_list_prepend (entries, menu_entry_create (_("&Filtered view"), CK_ViewFiltered));
240 entries = g_list_prepend (entries, menu_entry_create (_("&Edit"), CK_Edit));
241 entries = g_list_prepend (entries, menu_entry_create (_("&Copy"), CK_Copy));
242 entries = g_list_prepend (entries, menu_entry_create (_("C&hmod"), CK_ChangeMode));
243 entries = g_list_prepend (entries, menu_entry_create (_("&Link"), CK_Link));
244 entries = g_list_prepend (entries, menu_entry_create (_("&Symlink"), CK_LinkSymbolic));
245 entries =
246 g_list_prepend (entries,
247 menu_entry_create (_("Relative symlin&k"), CK_LinkSymbolicRelative));
248 entries = g_list_prepend (entries, menu_entry_create (_("Edit s&ymlink"), CK_LinkSymbolicEdit));
249 entries = g_list_prepend (entries, menu_entry_create (_("Ch&own"), CK_ChangeOwn));
250 entries =
251 g_list_prepend (entries, menu_entry_create (_("&Advanced chown"), CK_ChangeOwnAdvanced));
252 entries = g_list_prepend (entries, menu_entry_create (_("&Rename/Move"), CK_Move));
253 entries = g_list_prepend (entries, menu_entry_create (_("&Mkdir"), CK_MakeDir));
254 entries = g_list_prepend (entries, menu_entry_create (_("&Delete"), CK_Delete));
255 entries = g_list_prepend (entries, menu_entry_create (_("&Quick cd"), CK_CdQuick));
256 entries = g_list_prepend (entries, menu_separator_create ());
257 entries = g_list_prepend (entries, menu_entry_create (_("Select &group"), CK_Select));
258 entries = g_list_prepend (entries, menu_entry_create (_("U&nselect group"), CK_Unselect));
259 entries = g_list_prepend (entries, menu_entry_create (_("&Invert selection"), CK_SelectInvert));
260 entries = g_list_prepend (entries, menu_separator_create ());
261 entries = g_list_prepend (entries, menu_entry_create (_("E&xit"), CK_Quit));
263 return g_list_reverse (entries);
266 /* --------------------------------------------------------------------------------------------- */
268 static GList *
269 create_command_menu (void)
271 /* I know, I'm lazy, but the tree widget when it's not running
272 * as a panel still has some problems, I have not yet finished
273 * the WTree widget port, sorry.
275 GList *entries = NULL;
277 entries = g_list_prepend (entries, menu_entry_create (_("&User menu"), CK_UserMenu));
278 entries = g_list_prepend (entries, menu_entry_create (_("&Directory tree"), CK_Tree));
279 entries = g_list_prepend (entries, menu_entry_create (_("&Find file"), CK_Find));
280 entries = g_list_prepend (entries, menu_entry_create (_("S&wap panels"), CK_Swap));
281 entries = g_list_prepend (entries, menu_entry_create (_("Switch &panels on/off"), CK_Shell));
282 entries =
283 g_list_prepend (entries, menu_entry_create (_("&Compare directories"), CK_CompareDirs));
284 #ifdef USE_DIFF_VIEW
285 entries = g_list_prepend (entries, menu_entry_create (_("C&ompare files"), CK_CompareFiles));
286 #endif
287 entries =
288 g_list_prepend (entries, menu_entry_create (_("E&xternal panelize"), CK_ExternalPanelize));
289 entries = g_list_prepend (entries, menu_entry_create (_("Show directory s&izes"), CK_DirSize));
290 entries = g_list_prepend (entries, menu_separator_create ());
291 entries = g_list_prepend (entries, menu_entry_create (_("Command &history"), CK_History));
292 entries = g_list_prepend (entries, menu_entry_create (_("Di&rectory hotlist"), CK_HotList));
293 #ifdef ENABLE_VFS
294 entries = g_list_prepend (entries, menu_entry_create (_("&Active VFS list"), CK_VfsList));
295 #endif
296 #ifdef ENABLE_BACKGROUND
297 entries = g_list_prepend (entries, menu_entry_create (_("&Background jobs"), CK_Jobs));
298 #endif
299 entries = g_list_prepend (entries, menu_entry_create (_("Screen lis&t"), CK_ScreenList));
300 entries = g_list_prepend (entries, menu_separator_create ());
301 #ifdef ENABLE_VFS_UNDELFS
302 entries =
303 g_list_prepend (entries,
304 menu_entry_create (_("&Undelete files (ext2fs only)"), CK_Undelete));
305 #endif
306 #ifdef LISTMODE_EDITOR
307 entries = g_list_prepend (entries, menu_entry_create (_("&Listing format edit"), CK_ListMode));
308 #endif
309 #if defined (ENABLE_VFS_UNDELFS) || defined (LISTMODE_EDITOR)
310 entries = g_list_prepend (entries, menu_separator_create ());
311 #endif
312 entries =
313 g_list_prepend (entries,
314 menu_entry_create (_("Edit &extension file"), CK_EditExtensionsFile));
315 entries = g_list_prepend (entries, menu_entry_create (_("Edit &menu file"), CK_EditUserMenu));
316 entries =
317 g_list_prepend (entries,
318 menu_entry_create (_("Edit hi&ghlighting group file"),
319 CK_EditFileHighlightFile));
321 return g_list_reverse (entries);
324 /* --------------------------------------------------------------------------------------------- */
326 static GList *
327 create_options_menu (void)
329 GList *entries = NULL;
331 entries = g_list_prepend (entries, menu_entry_create (_("&Configuration..."), CK_Options));
332 entries = g_list_prepend (entries, menu_entry_create (_("&Layout..."), CK_OptionsLayout));
333 entries = g_list_prepend (entries, menu_entry_create (_("&Panel options..."), CK_OptionsPanel));
334 entries =
335 g_list_prepend (entries, menu_entry_create (_("C&onfirmation..."), CK_OptionsConfirm));
336 entries =
337 g_list_prepend (entries, menu_entry_create (_("&Display bits..."), CK_OptionsDisplayBits));
338 entries = g_list_prepend (entries, menu_entry_create (_("Learn &keys..."), CK_LearnKeys));
339 #ifdef ENABLE_VFS
340 entries = g_list_prepend (entries, menu_entry_create (_("&Virtual FS..."), CK_OptionsVfs));
341 #endif
342 entries = g_list_prepend (entries, menu_separator_create ());
343 entries = g_list_prepend (entries, menu_entry_create (_("&Save setup"), CK_SaveSetup));
345 return g_list_reverse (entries);
348 /* --------------------------------------------------------------------------------------------- */
350 static void
351 init_menu (void)
353 left_menu = create_menu ("", create_panel_menu (), "[Left and Right Menus]");
354 menubar_add_menu (the_menubar, left_menu);
355 menubar_add_menu (the_menubar, create_menu (_("&File"), create_file_menu (), "[File Menu]"));
356 menubar_add_menu (the_menubar,
357 create_menu (_("&Command"), create_command_menu (), "[Command Menu]"));
358 menubar_add_menu (the_menubar,
359 create_menu (_("&Options"), create_options_menu (), "[Options Menu]"));
360 right_menu = create_menu ("", create_panel_menu (), "[Left and Right Menus]");
361 menubar_add_menu (the_menubar, right_menu);
362 update_menu ();
365 /* --------------------------------------------------------------------------------------------- */
367 static void
368 menu_last_selected_cmd (void)
370 the_menubar->is_active = TRUE;
371 the_menubar->is_dropped = (drop_menus != 0);
372 the_menubar->previous_widget = dlg_get_current_widget_id (midnight_dlg);
373 dlg_select_widget (the_menubar);
376 /* --------------------------------------------------------------------------------------------- */
378 static void
379 menu_cmd (void)
381 if (the_menubar->is_active)
382 return;
384 if ((get_current_index () == 0) == (current_panel->active != 0))
385 the_menubar->selected = 0;
386 else
387 the_menubar->selected = g_list_length (the_menubar->menu) - 1;
388 menu_last_selected_cmd ();
391 /* --------------------------------------------------------------------------------------------- */
393 static void
394 sort_cmd (void)
396 WPanel *p;
397 const panel_field_t *sort_order;
399 if (!SELECTED_IS_PANEL)
400 return;
402 p = MENU_PANEL;
403 sort_order = sort_box (&p->sort_info);
404 panel_set_sort_order (p, sort_order);
407 /* --------------------------------------------------------------------------------------------- */
409 static char *
410 midnight_get_shortcut (unsigned long command)
412 const char *ext_map;
413 const char *shortcut = NULL;
415 shortcut = keybind_lookup_keymap_shortcut (main_map, command);
416 if (shortcut != NULL)
417 return g_strdup (shortcut);
419 shortcut = keybind_lookup_keymap_shortcut (panel_map, command);
420 if (shortcut != NULL)
421 return g_strdup (shortcut);
423 ext_map = keybind_lookup_keymap_shortcut (main_map, CK_ExtendedKeyMap);
424 if (ext_map != NULL)
425 shortcut = keybind_lookup_keymap_shortcut (main_x_map, command);
426 if (shortcut != NULL)
427 return g_strdup_printf ("%s %s", ext_map, shortcut);
429 return NULL;
432 /* --------------------------------------------------------------------------------------------- */
434 static char *
435 midnight_get_title (const WDialog * h, size_t len)
437 char *path;
438 char *login;
439 char *p;
441 (void) h;
443 title_path_prepare (&path, &login);
445 p = g_strdup_printf ("%s [%s]:%s", _("Panels:"), login, path);
446 g_free (path);
447 g_free (login);
448 path = g_strdup (str_trunc (p, len - 4));
449 g_free (p);
451 return path;
454 /* --------------------------------------------------------------------------------------------- */
456 static void
457 toggle_panels_split (void)
459 panels_layout.horizontal_split = !panels_layout.horizontal_split;
460 layout_change ();
461 do_refresh ();
464 /* --------------------------------------------------------------------------------------------- */
466 #ifdef ENABLE_VFS
467 /* event helper */
468 static gboolean
469 check_panel_timestamp (const WPanel * panel, panel_view_mode_t mode, struct vfs_class *vclass,
470 vfsid id)
472 if (mode == view_listing)
474 const vfs_path_element_t *path_element;
476 path_element = vfs_path_get_by_index (panel->cwd_vpath, -1);
478 if (path_element->class != vclass)
479 return FALSE;
481 if (vfs_getid (panel->cwd_vpath) != id)
482 return FALSE;
484 return TRUE;
487 /* --------------------------------------------------------------------------------------------- */
489 /* event callback */
490 static gboolean
491 check_current_panel_timestamp (const gchar * event_group_name, const gchar * event_name,
492 gpointer init_data, gpointer data)
494 ev_vfs_stamp_create_t *event_data = (ev_vfs_stamp_create_t *) data;
496 (void) event_group_name;
497 (void) event_name;
498 (void) init_data;
500 event_data->ret =
501 check_panel_timestamp (current_panel, get_current_type (), event_data->vclass,
502 event_data->id);
503 return !event_data->ret;
506 /* --------------------------------------------------------------------------------------------- */
508 /* event callback */
509 static gboolean
510 check_other_panel_timestamp (const gchar * event_group_name, const gchar * event_name,
511 gpointer init_data, gpointer data)
513 ev_vfs_stamp_create_t *event_data = (ev_vfs_stamp_create_t *) data;
515 (void) event_group_name;
516 (void) event_name;
517 (void) init_data;
519 event_data->ret =
520 check_panel_timestamp (other_panel, get_other_type (), event_data->vclass, event_data->id);
521 return !event_data->ret;
523 #endif /* ENABLE_VFS */
525 /* --------------------------------------------------------------------------------------------- */
527 /* event callback */
528 static gboolean
529 print_vfs_message (const gchar * event_group_name, const gchar * event_name,
530 gpointer init_data, gpointer data)
532 char str[128];
533 ev_vfs_print_message_t *event_data = (ev_vfs_print_message_t *) data;
535 (void) event_group_name;
536 (void) event_name;
537 (void) init_data;
539 g_vsnprintf (str, sizeof (str), event_data->msg, event_data->ap);
541 if (mc_global.midnight_shutdown)
542 return TRUE;
544 if (!mc_global.message_visible || the_hint == NULL || WIDGET (the_hint)->owner == NULL)
546 int col, row;
548 if (!nice_rotating_dash || (ok_to_refresh <= 0))
549 return TRUE;
551 /* Preserve current cursor position */
552 tty_getyx (&row, &col);
554 tty_gotoyx (0, 0);
555 tty_setcolor (NORMAL_COLOR);
556 tty_print_string (str_fit_to_term (str, COLS - 1, J_LEFT));
558 /* Restore cursor position */
559 tty_gotoyx (row, col);
560 mc_refresh ();
561 return TRUE;
564 if (mc_global.message_visible)
565 set_hintbar (str);
567 return TRUE;
570 /* --------------------------------------------------------------------------------------------- */
572 static void
573 create_panels (void)
575 int current_index, other_index;
576 panel_view_mode_t current_mode, other_mode;
577 char *current_dir, *other_dir;
578 vfs_path_t *original_dir;
580 if (boot_current_is_left)
582 /* left panel is active */
583 current_index = 0;
584 other_index = 1;
585 current_mode = startup_left_mode;
586 other_mode = startup_right_mode;
587 /* if mc_run_param0 is NULL, working directory will be used for the left panel */
588 current_dir = (char *) mc_run_param0;
589 /* mc_run_param1 is never NULL. It is setup from command line or from panels.ini
590 * (value of other_dir). mc_run_param1 will be used for the right panel */
591 other_dir = mc_run_param1;
593 else
595 /* right panel is active */
596 current_index = 1;
597 other_index = 0;
598 current_mode = startup_right_mode;
599 other_mode = startup_left_mode;
601 /* if mc_run_param0 is not NULL (it was setup from command line), it will be used
602 * for the left panel, working directory will be used for the right one;
603 * if mc_run_param0 is NULL, working directory will be used for the right (active) panel,
604 * mc_run_param1 will be used for the left one */
605 if (mc_run_param0 != NULL)
607 current_dir = NULL;
608 other_dir = (char *) mc_run_param0;
610 else
612 current_dir = NULL;
613 other_dir = mc_run_param1;
617 /* 1. Get current dir */
618 original_dir = vfs_path_clone (vfs_get_raw_current_dir ());
620 /* 2. Create passive panel */
621 if (other_dir != NULL)
623 vfs_path_t *vpath;
625 if (g_path_is_absolute (other_dir))
626 vpath = vfs_path_from_str (other_dir);
627 else
628 vpath = vfs_path_append_new (original_dir, other_dir, (char *) NULL);
629 mc_chdir (vpath);
630 vfs_path_free (vpath);
632 set_display_type (other_index, other_mode);
634 /* 3. Create active panel */
635 if (current_dir == NULL)
636 mc_chdir (original_dir);
637 else
639 vfs_path_t *vpath;
641 if (g_path_is_absolute (current_dir))
642 vpath = vfs_path_from_str (current_dir);
643 else
644 vpath = vfs_path_append_new (original_dir, current_dir, (char *) NULL);
645 mc_chdir (vpath);
646 vfs_path_free (vpath);
648 set_display_type (current_index, current_mode);
650 if (startup_left_mode == view_listing)
651 current_panel = left_panel;
652 else if (right_panel != NULL)
653 current_panel = right_panel;
654 else
655 current_panel = left_panel;
657 vfs_path_free (original_dir);
659 #ifdef ENABLE_VFS
660 mc_event_add (MCEVENT_GROUP_CORE, "vfs_timestamp", check_other_panel_timestamp, NULL, NULL);
661 mc_event_add (MCEVENT_GROUP_CORE, "vfs_timestamp", check_current_panel_timestamp, NULL, NULL);
662 #endif /* ENABLE_VFS */
664 mc_event_add (MCEVENT_GROUP_CORE, "vfs_print_message", print_vfs_message, NULL, NULL);
666 /* Create the nice widgets */
667 cmdline = command_new (0, 0, 0);
668 the_prompt = label_new (0, 0, mc_prompt);
669 the_prompt->transparent = 1;
670 the_bar = buttonbar_new (mc_global.keybar_visible);
672 the_hint = label_new (0, 0, 0);
673 the_hint->transparent = 1;
674 the_hint->auto_adjust_cols = 0;
675 WIDGET (the_hint)->cols = COLS;
677 the_menubar = menubar_new (0, 0, COLS, NULL);
680 /* --------------------------------------------------------------------------------------------- */
682 static void
683 put_current_path (void)
685 char *cwd_path;
687 if (!command_prompt)
688 return;
690 #ifdef HAVE_CHARSET
692 vfs_path_t *cwd_vpath;
694 cwd_vpath = remove_encoding_from_path (current_panel->cwd_vpath);
695 cwd_path = vfs_path_to_str (cwd_vpath);
696 vfs_path_free (cwd_vpath);
698 #else
699 cwd_path = vfs_path_to_str (current_panel->cwd_vpath);
700 #endif
702 command_insert (cmdline, cwd_path, FALSE);
703 if (cwd_path[strlen (cwd_path) - 1] != PATH_SEP)
704 command_insert (cmdline, PATH_SEP_STR, FALSE);
706 g_free (cwd_path);
709 /* --------------------------------------------------------------------------------------------- */
711 static void
712 put_other_path (void)
714 char *cwd_path;
716 if (get_other_type () != view_listing)
717 return;
719 if (!command_prompt)
720 return;
722 #ifdef HAVE_CHARSET
724 vfs_path_t *cwd_vpath;
726 cwd_vpath = remove_encoding_from_path (other_panel->cwd_vpath);
727 cwd_path = vfs_path_to_str (cwd_vpath);
728 vfs_path_free (cwd_vpath);
730 #else
731 cwd_path = vfs_path_to_str (other_panel->cwd_vpath);
732 #endif
734 command_insert (cmdline, cwd_path, FALSE);
735 if (cwd_path[strlen (cwd_path) - 1] != PATH_SEP)
736 command_insert (cmdline, PATH_SEP_STR, FALSE);
738 g_free (cwd_path);
741 /* --------------------------------------------------------------------------------------------- */
743 static void
744 put_link (WPanel * panel)
746 if (!command_prompt)
747 return;
748 if (S_ISLNK (selection (panel)->st.st_mode))
750 char buffer[MC_MAXPATHLEN];
751 vfs_path_t *vpath;
752 int i;
754 vpath = vfs_path_append_new (panel->cwd_vpath, selection (panel)->fname, NULL);
755 i = mc_readlink (vpath, buffer, MC_MAXPATHLEN - 1);
756 vfs_path_free (vpath);
758 if (i > 0)
760 buffer[i] = '\0';
761 command_insert (cmdline, buffer, TRUE);
766 /* --------------------------------------------------------------------------------------------- */
768 static void
769 put_current_link (void)
771 put_link (current_panel);
774 /* --------------------------------------------------------------------------------------------- */
776 static void
777 put_other_link (void)
779 if (get_other_type () == view_listing)
780 put_link (other_panel);
783 /* --------------------------------------------------------------------------------------------- */
785 /** Insert the selected file name into the input line */
786 static void
787 put_prog_name (void)
789 char *tmp;
790 if (!command_prompt)
791 return;
793 if (get_current_type () == view_tree)
795 WTree *tree = (WTree *) get_panel_widget (get_current_index ());
797 tmp = vfs_path_to_str (tree_selected_name (tree));
799 else
800 tmp = g_strdup (selection (current_panel)->fname);
802 command_insert (cmdline, tmp, TRUE);
803 g_free (tmp);
806 /* --------------------------------------------------------------------------------------------- */
808 static void
809 put_tagged (WPanel * panel)
811 int i;
813 if (!command_prompt)
814 return;
815 input_disable_update (cmdline);
816 if (panel->marked)
818 for (i = 0; i < panel->count; i++)
820 if (panel->dir.list[i].f.marked)
821 command_insert (cmdline, panel->dir.list[i].fname, TRUE);
824 else
826 command_insert (cmdline, panel->dir.list[panel->selected].fname, TRUE);
828 input_enable_update (cmdline);
831 /* --------------------------------------------------------------------------------------------- */
833 static void
834 put_current_tagged (void)
836 put_tagged (current_panel);
839 /* --------------------------------------------------------------------------------------------- */
841 static void
842 put_other_tagged (void)
844 if (get_other_type () == view_listing)
845 put_tagged (other_panel);
848 /* --------------------------------------------------------------------------------------------- */
850 static void
851 ctl_x_cmd (void)
853 ctl_x_map_enabled = TRUE;
856 /* --------------------------------------------------------------------------------------------- */
858 static void
859 setup_mc (void)
861 #ifdef HAVE_SLANG
862 #ifdef HAVE_CHARSET
863 tty_display_8bit (TRUE);
864 #else
865 tty_display_8bit (mc_global.full_eight_bits != 0);
866 #endif /* HAVE_CHARSET */
868 #else /* HAVE_SLANG */
870 #ifdef HAVE_CHARSET
871 tty_display_8bit (TRUE);
872 #else
873 tty_display_8bit (mc_global.eight_bit_clean != 0);
874 #endif /* HAVE_CHARSET */
875 #endif /* HAVE_SLANG */
877 #ifdef ENABLE_SUBSHELL
878 if (mc_global.tty.use_subshell)
879 add_select_channel (mc_global.tty.subshell_pty, load_prompt, 0);
880 #endif /* !ENABLE_SUBSHELL */
882 if ((tty_baudrate () < 9600) || mc_global.tty.slow_terminal)
883 verbose = 0;
886 /* --------------------------------------------------------------------------------------------- */
888 static void
889 setup_dummy_mc (void)
891 vfs_path_t *vpath;
892 char *d;
893 int ret;
895 d = _vfs_get_cwd ();
896 setup_mc ();
897 vpath = vfs_path_from_str (d);
898 ret = mc_chdir (vpath);
899 vfs_path_free (vpath);
900 g_free (d);
903 /* --------------------------------------------------------------------------------------------- */
905 static void
906 done_mc (void)
908 /* Setup shutdown
910 * We sync the profiles since the hotlist may have changed, while
911 * we only change the setup data if we have the auto save feature set
913 char *curr_dir;
915 save_setup (auto_save_setup, panels_options.auto_save_setup);
917 curr_dir = vfs_get_current_dir ();
918 vfs_stamp_path (curr_dir);
919 g_free (curr_dir);
921 if ((current_panel != NULL) && (get_current_type () == view_listing))
923 char *tmp_path;
925 tmp_path = vfs_path_to_str (current_panel->cwd_vpath);
926 vfs_stamp_path (tmp_path);
927 g_free (tmp_path);
930 if ((other_panel != NULL) && (get_other_type () == view_listing))
932 char *tmp_path;
934 tmp_path = vfs_path_to_str (other_panel->cwd_vpath);
935 vfs_stamp_path (tmp_path);
936 g_free (tmp_path);
940 /* --------------------------------------------------------------------------------------------- */
942 static void
943 create_panels_and_run_mc (void)
945 midnight_dlg->get_shortcut = midnight_get_shortcut;
946 midnight_dlg->get_title = midnight_get_title;
948 create_panels ();
950 add_widget (midnight_dlg, the_menubar);
951 init_menu ();
953 add_widget (midnight_dlg, get_panel_widget (0));
954 add_widget (midnight_dlg, get_panel_widget (1));
956 add_widget (midnight_dlg, the_hint);
957 add_widget (midnight_dlg, cmdline);
958 add_widget (midnight_dlg, the_prompt);
960 add_widget (midnight_dlg, the_bar);
961 midnight_set_buttonbar (the_bar);
963 /* Run the Midnight Commander if no file was specified in the command line */
964 run_dlg (midnight_dlg);
967 /* --------------------------------------------------------------------------------------------- */
969 /** result must be free'd (I think this should go in util.c) */
970 static vfs_path_t *
971 prepend_cwd_on_local (const char *filename)
973 vfs_path_t *vpath;
975 vpath = vfs_path_from_str (filename);
976 if (!vfs_file_is_local (vpath) || g_path_is_absolute (filename))
977 return vpath;
979 vfs_path_free (vpath);
981 return vfs_path_append_new (vfs_get_raw_current_dir (), filename, NULL);
984 /* --------------------------------------------------------------------------------------------- */
986 /** Invoke the internal view/edit routine with:
987 * the default processing and forcing the internal viewer/editor
989 static gboolean
990 mc_maybe_editor_or_viewer (void)
992 gboolean ret;
994 switch (mc_global.mc_run_mode)
996 #ifdef USE_INTERNAL_EDIT
997 case MC_RUN_EDITOR:
998 ret = edit_files ((GList *) mc_run_param0);
999 break;
1000 #endif /* USE_INTERNAL_EDIT */
1001 case MC_RUN_VIEWER:
1003 vfs_path_t *vpath = NULL;
1005 if (mc_run_param0 != NULL && *(char *) mc_run_param0 != '\0')
1006 vpath = prepend_cwd_on_local ((char *) mc_run_param0);
1008 ret = view_file (vpath, 0, 1);
1009 vfs_path_free (vpath);
1010 break;
1012 #ifdef USE_DIFF_VIEW
1013 case MC_RUN_DIFFVIEWER:
1014 ret = dview_diff_cmd (mc_run_param0, mc_run_param1);
1015 break;
1016 #endif /* USE_DIFF_VIEW */
1017 default:
1018 ret = FALSE;
1021 return ret;
1024 /* --------------------------------------------------------------------------------------------- */
1026 static gboolean
1027 quit_cmd_internal (int quiet)
1029 int q = quit;
1030 size_t n;
1032 n = dialog_switch_num () - 1;
1033 if (n != 0)
1035 char msg[BUF_MEDIUM];
1037 g_snprintf (msg, sizeof (msg),
1038 ngettext ("You have %zd opened screen. Quit anyway?",
1039 "You have %zd opened screens. Quit anyway?", n), n);
1041 if (query_dialog (_("The Midnight Commander"), msg, D_NORMAL, 2, _("&Yes"), _("&No")) != 0)
1042 return FALSE;
1043 q = 1;
1045 else if (quiet || !confirm_exit)
1046 q = 1;
1047 else if (query_dialog (_("The Midnight Commander"),
1048 _("Do you really want to quit the Midnight Commander?"),
1049 D_NORMAL, 2, _("&Yes"), _("&No")) == 0)
1050 q = 1;
1052 if (q != 0)
1054 #ifdef ENABLE_SUBSHELL
1055 if (!mc_global.tty.use_subshell)
1056 stop_dialogs ();
1057 else if ((q = exit_subshell ()? 1 : 0) != 0)
1058 #endif
1059 stop_dialogs ();
1062 if (q != 0)
1063 quit |= 1;
1064 return (quit != 0);
1067 /* --------------------------------------------------------------------------------------------- */
1069 static gboolean
1070 quit_cmd (void)
1072 return quit_cmd_internal (0);
1075 /* --------------------------------------------------------------------------------------------- */
1077 static void
1078 toggle_show_hidden (void)
1080 panels_options.show_dot_files = !panels_options.show_dot_files;
1081 update_panels (UP_RELOAD, UP_KEEPSEL);
1084 /* --------------------------------------------------------------------------------------------- */
1087 * Repaint the contents of the panels without frames. To schedule panel
1088 * for repainting, set panel->dirty to 1. There are many reasons why
1089 * the panels need to be repainted, and this is a costly operation, so
1090 * it's done once per event.
1093 static void
1094 update_dirty_panels (void)
1096 if (get_current_type () == view_listing && current_panel->dirty)
1097 send_message (current_panel, NULL, MSG_DRAW, 0, NULL);
1099 if (get_other_type () == view_listing && other_panel->dirty)
1100 send_message (other_panel, NULL, MSG_DRAW, 0, NULL);
1103 /* --------------------------------------------------------------------------------------------- */
1105 static cb_ret_t
1106 midnight_execute_cmd (Widget * sender, unsigned long command)
1108 cb_ret_t res = MSG_HANDLED;
1110 (void) sender;
1112 /* stop quick search before executing any command */
1113 send_message (current_panel, NULL, MSG_ACTION, CK_SearchStop, NULL);
1115 switch (command)
1117 case CK_HotListAdd:
1118 add2hotlist_cmd ();
1119 break;
1120 case CK_PanelListingChange:
1121 change_listing_cmd ();
1122 break;
1123 case CK_ChangeMode:
1124 chmod_cmd ();
1125 break;
1126 case CK_ChangeOwn:
1127 chown_cmd ();
1128 break;
1129 case CK_ChangeOwnAdvanced:
1130 chown_advanced_cmd ();
1131 break;
1132 case CK_CompareDirs:
1133 compare_dirs_cmd ();
1134 break;
1135 case CK_Options:
1136 configure_box ();
1137 break;
1138 #ifdef ENABLE_VFS
1139 case CK_OptionsVfs:
1140 configure_vfs ();
1141 break;
1142 #endif
1143 case CK_OptionsConfirm:
1144 confirm_box ();
1145 break;
1146 case CK_Copy:
1147 copy_cmd ();
1148 break;
1149 case CK_PutCurrentPath:
1150 put_current_path ();
1151 break;
1152 case CK_PutCurrentLink:
1153 put_current_link ();
1154 break;
1155 case CK_PutCurrentTagged:
1156 put_current_tagged ();
1157 break;
1158 case CK_PutOtherPath:
1159 put_other_path ();
1160 break;
1161 case CK_PutOtherLink:
1162 put_other_link ();
1163 break;
1164 case CK_PutOtherTagged:
1165 put_other_tagged ();
1166 break;
1167 case CK_Delete:
1168 delete_cmd ();
1169 break;
1170 case CK_ScreenList:
1171 dialog_switch_list ();
1172 break;
1173 #ifdef USE_DIFF_VIEW
1174 case CK_CompareFiles:
1175 diff_view_cmd ();
1176 break;
1177 #endif
1178 case CK_OptionsDisplayBits:
1179 display_bits_box ();
1180 break;
1181 case CK_Edit:
1182 edit_cmd ();
1183 break;
1184 #ifdef USE_INTERNAL_EDIT
1185 case CK_EditForceInternal:
1186 edit_cmd_force_internal ();
1187 break;
1188 #endif
1189 case CK_EditExtensionsFile:
1190 ext_cmd ();
1191 break;
1192 case CK_EditFileHighlightFile:
1193 edit_fhl_cmd ();
1194 break;
1195 case CK_EditUserMenu:
1196 edit_mc_menu_cmd ();
1197 break;
1198 case CK_LinkSymbolicEdit:
1199 edit_symlink_cmd ();
1200 break;
1201 case CK_ExternalPanelize:
1202 external_panelize ();
1203 break;
1204 case CK_Filter:
1205 filter_cmd ();
1206 break;
1207 case CK_ViewFiltered:
1208 view_filtered_cmd ();
1209 break;
1210 case CK_Find:
1211 find_cmd ();
1212 break;
1213 #ifdef ENABLE_VFS_FISH
1214 case CK_ConnectFish:
1215 fishlink_cmd ();
1216 break;
1217 #endif
1218 #ifdef ENABLE_VFS_FTP
1219 case CK_ConnectFtp:
1220 ftplink_cmd ();
1221 break;
1222 #endif
1223 #ifdef ENABLE_VFS_SFTP
1224 case CK_ConnectSftp:
1225 sftplink_cmd ();
1226 break;
1227 #endif
1228 #ifdef ENABLE_VFS_SMB
1229 case CK_ConnectSmb:
1230 smblink_cmd ();
1231 break;
1232 #endif /* ENABLE_VFS_SMB */
1233 case CK_Panelize:
1234 cd_panelize_cmd ();
1235 break;
1236 case CK_Help:
1237 help_cmd ();
1238 break;
1239 case CK_History:
1240 /* show the history of command line widget */
1241 send_message (cmdline, NULL, MSG_ACTION, CK_History, NULL);
1242 break;
1243 case CK_PanelInfo:
1244 if (sender == WIDGET (the_menubar))
1245 info_cmd (); /* menu */
1246 else
1247 info_cmd_no_menu (); /* shortcut or buttonbar */
1248 break;
1249 #ifdef ENABLE_BACKGROUND
1250 case CK_Jobs:
1251 jobs_cmd ();
1252 break;
1253 #endif
1254 case CK_OptionsLayout:
1255 layout_box ();
1256 break;
1257 case CK_LearnKeys:
1258 learn_keys ();
1259 break;
1260 case CK_Link:
1261 link_cmd (LINK_HARDLINK);
1262 break;
1263 case CK_PanelListing:
1264 listing_cmd ();
1265 break;
1266 #ifdef LISTMODE_EDITOR
1267 case CK_ListMode:
1268 listmode_cmd ();
1269 break;
1270 #endif
1271 case CK_Menu:
1272 menu_cmd ();
1273 break;
1274 case CK_MenuLastSelected:
1275 menu_last_selected_cmd ();
1276 break;
1277 case CK_MakeDir:
1278 mkdir_cmd ();
1279 break;
1280 case CK_OptionsPanel:
1281 panel_options_box ();
1282 break;
1283 #ifdef HAVE_CHARSET
1284 case CK_SelectCodepage:
1285 encoding_cmd ();
1286 break;
1287 #endif
1288 case CK_CdQuick:
1289 quick_cd_cmd ();
1290 break;
1291 case CK_HotList:
1292 hotlist_cmd ();
1293 break;
1294 case CK_PanelQuickView:
1295 if (sender == WIDGET (the_menubar))
1296 quick_view_cmd (); /* menu */
1297 else
1298 quick_cmd_no_menu (); /* shortcut or buttonabr */
1299 break;
1300 case CK_QuitQuiet:
1301 quiet_quit_cmd ();
1302 break;
1303 case CK_Quit:
1304 quit_cmd ();
1305 break;
1306 case CK_LinkSymbolicRelative:
1307 link_cmd (LINK_SYMLINK_RELATIVE);
1308 break;
1309 case CK_Move:
1310 rename_cmd ();
1311 break;
1312 case CK_Reread:
1313 reread_cmd ();
1314 break;
1315 #ifdef ENABLE_VFS
1316 case CK_VfsList:
1317 vfs_list ();
1318 break;
1319 #endif
1320 case CK_SelectInvert:
1321 select_invert_cmd ();
1322 break;
1323 case CK_SaveSetup:
1324 save_setup_cmd ();
1325 break;
1326 case CK_Select:
1327 select_cmd ();
1328 break;
1329 case CK_Shell:
1330 view_other_cmd ();
1331 break;
1332 case CK_DirSize:
1333 smart_dirsize_cmd ();
1334 break;
1335 case CK_Sort:
1336 sort_cmd ();
1337 break;
1338 case CK_ExtendedKeyMap:
1339 ctl_x_cmd ();
1340 break;
1341 case CK_Suspend:
1342 mc_event_raise (MCEVENT_GROUP_CORE, "suspend", NULL);
1343 break;
1344 case CK_Swap:
1345 swap_cmd ();
1346 break;
1347 case CK_LinkSymbolic:
1348 link_cmd (LINK_SYMLINK_ABSOLUTE);
1349 break;
1350 case CK_PanelListingSwitch:
1351 toggle_listing_cmd ();
1352 break;
1353 case CK_ShowHidden:
1354 toggle_show_hidden ();
1355 break;
1356 case CK_SplitVertHoriz:
1357 toggle_panels_split ();
1358 break;
1359 case CK_SplitEqual:
1360 panels_split_equal ();
1361 break;
1362 case CK_SplitMore:
1363 panels_split_more ();
1364 break;
1365 case CK_SplitLess:
1366 panels_split_less ();
1367 break;
1368 case CK_PanelTree:
1369 panel_tree_cmd ();
1370 break;
1371 case CK_Tree:
1372 treebox_cmd ();
1373 break;
1374 #ifdef ENABLE_VFS_UNDELFS
1375 case CK_Undelete:
1376 undelete_cmd ();
1377 break;
1378 #endif
1379 case CK_Unselect:
1380 unselect_cmd ();
1381 break;
1382 case CK_UserMenu:
1383 user_file_menu_cmd ();
1384 break;
1385 case CK_View:
1386 view_cmd ();
1387 break;
1388 case CK_ViewFile:
1389 view_file_cmd ();
1390 break;
1391 case CK_Cancel:
1392 /* don't close panels due to SIGINT */
1393 break;
1394 default:
1395 res = MSG_NOT_HANDLED;
1398 return res;
1401 /* --------------------------------------------------------------------------------------------- */
1403 static cb_ret_t
1404 midnight_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
1406 unsigned long command;
1408 switch (msg)
1410 case MSG_INIT:
1411 panel_init ();
1412 setup_panels ();
1413 return MSG_HANDLED;
1415 case MSG_DRAW:
1416 load_hint (1);
1417 /* We handle the special case of the output lines */
1418 if (mc_global.tty.console_flag != '\0' && output_lines)
1419 show_console_contents (output_start_y,
1420 LINES - output_lines - mc_global.keybar_visible -
1421 1, LINES - mc_global.keybar_visible - 1);
1422 return MSG_HANDLED;
1424 case MSG_RESIZE:
1425 setup_panels ();
1426 menubar_arrange (the_menubar);
1427 return MSG_HANDLED;
1429 case MSG_IDLE:
1430 /* We only need the first idle event to show user menu after start */
1431 widget_want_idle (w, FALSE);
1433 if (boot_current_is_left)
1434 dlg_select_widget (get_panel_widget (0));
1435 else
1436 dlg_select_widget (get_panel_widget (1));
1438 if (auto_menu)
1439 midnight_execute_cmd (NULL, CK_UserMenu);
1440 return MSG_HANDLED;
1442 case MSG_KEY:
1443 if (ctl_x_map_enabled)
1445 ctl_x_map_enabled = FALSE;
1446 command = keybind_lookup_keymap_command (main_x_map, parm);
1447 if (command != CK_IgnoreKey)
1448 return midnight_execute_cmd (NULL, command);
1451 /* FIXME: should handle all menu shortcuts before this point */
1452 if (the_menubar->is_active)
1453 return MSG_NOT_HANDLED;
1455 if (parm == '\t')
1456 input_free_completions (cmdline);
1458 if (parm == '\n')
1460 size_t i;
1462 for (i = 0; cmdline->buffer[i] != '\0' &&
1463 (cmdline->buffer[i] == ' ' || cmdline->buffer[i] == '\t'); i++)
1466 if (cmdline->buffer[i] != '\0')
1468 send_message (cmdline, NULL, MSG_KEY, parm, NULL);
1469 return MSG_HANDLED;
1472 input_insert (cmdline, "", FALSE);
1473 cmdline->point = 0;
1476 /* Ctrl-Enter and Alt-Enter */
1477 if (((parm & ~(KEY_M_CTRL | KEY_M_ALT)) == '\n') && (parm & (KEY_M_CTRL | KEY_M_ALT)))
1479 put_prog_name ();
1480 return MSG_HANDLED;
1483 /* Ctrl-Shift-Enter */
1484 if (parm == (KEY_M_CTRL | KEY_M_SHIFT | '\n'))
1486 put_current_path ();
1487 put_prog_name ();
1488 return MSG_HANDLED;
1491 if ((!mc_global.tty.alternate_plus_minus
1492 || !(mc_global.tty.console_flag != '\0' || mc_global.tty.xterm_flag)) && !quote
1493 && !current_panel->searching)
1495 if (!only_leading_plus_minus)
1497 /* Special treatement, since the input line will eat them */
1498 if (parm == '+')
1500 select_cmd ();
1501 return MSG_HANDLED;
1504 if (parm == '\\' || parm == '-')
1506 unselect_cmd ();
1507 return MSG_HANDLED;
1510 if (parm == '*')
1512 select_invert_cmd ();
1513 return MSG_HANDLED;
1516 else if (!command_prompt || !cmdline->buffer[0])
1518 /* Special treatement '+', '-', '\', '*' only when this is
1519 * first char on input line
1522 if (parm == '+')
1524 select_cmd ();
1525 return MSG_HANDLED;
1528 if (parm == '\\' || parm == '-')
1530 unselect_cmd ();
1531 return MSG_HANDLED;
1534 if (parm == '*')
1536 select_invert_cmd ();
1537 return MSG_HANDLED;
1541 return MSG_NOT_HANDLED;
1543 case MSG_HOTKEY_HANDLED:
1544 if ((get_current_type () == view_listing) && current_panel->searching)
1546 current_panel->dirty = 1; /* FIXME: unneeded? */
1547 send_message (current_panel, NULL, MSG_ACTION, CK_SearchStop, NULL);
1549 return MSG_HANDLED;
1551 case MSG_UNHANDLED_KEY:
1553 cb_ret_t v = MSG_NOT_HANDLED;
1555 if (ctl_x_map_enabled)
1557 ctl_x_map_enabled = FALSE;
1558 command = keybind_lookup_keymap_command (main_x_map, parm);
1560 else
1561 command = keybind_lookup_keymap_command (main_map, parm);
1563 if (command != CK_IgnoreKey)
1564 v = midnight_execute_cmd (NULL, command);
1566 if (v == MSG_NOT_HANDLED && command_prompt)
1567 v = send_message (cmdline, NULL, MSG_KEY, parm, NULL);
1569 return v;
1572 case MSG_POST_KEY:
1573 if (!the_menubar->is_active)
1574 update_dirty_panels ();
1575 return MSG_HANDLED;
1577 case MSG_ACTION:
1578 /* shortcut */
1579 if (sender == NULL)
1580 return midnight_execute_cmd (NULL, parm);
1581 /* message from menu */
1582 if (sender == WIDGET (the_menubar))
1583 return midnight_execute_cmd (sender, parm);
1584 /* message from buttonbar */
1585 if (sender == WIDGET (the_bar))
1587 if (data != NULL)
1588 return send_message (data, NULL, MSG_ACTION, parm, NULL);
1589 return midnight_execute_cmd (sender, parm);
1591 return MSG_NOT_HANDLED;
1593 case MSG_END:
1594 panel_deinit ();
1595 return MSG_HANDLED;
1597 default:
1598 return dlg_default_callback (w, sender, msg, parm, data);
1602 /* --------------------------------------------------------------------------------------------- */
1604 static int
1605 midnight_event (Gpm_Event * event, void *data)
1607 Widget *wh = WIDGET (data);
1608 int ret = MOU_UNHANDLED;
1610 if (event->y == wh->y + 1)
1612 /* menubar */
1613 if (menubar_visible || the_menubar->is_active)
1614 ret = WIDGET (the_menubar)->mouse (event, the_menubar);
1615 else
1617 Widget *w;
1619 w = get_panel_widget (0);
1620 if (w->mouse != NULL)
1621 ret = w->mouse (event, w);
1623 if (ret == MOU_UNHANDLED)
1625 w = get_panel_widget (1);
1626 if (w->mouse != NULL)
1627 ret = w->mouse (event, w);
1630 if (ret == MOU_UNHANDLED)
1631 ret = WIDGET (the_menubar)->mouse (event, the_menubar);
1635 return ret;
1638 /* --------------------------------------------------------------------------------------------- */
1639 /*** public functions ****************************************************************************/
1640 /* --------------------------------------------------------------------------------------------- */
1642 void
1643 update_menu (void)
1645 menu_set_name (left_menu, panels_layout.horizontal_split ? _("&Above") : _("&Left"));
1646 menu_set_name (right_menu, panels_layout.horizontal_split ? _("&Below") : _("&Right"));
1647 menubar_arrange (the_menubar);
1648 menubar_set_visible (the_menubar, menubar_visible);
1651 /* --------------------------------------------------------------------------------------------- */
1653 void
1654 midnight_set_buttonbar (WButtonBar * b)
1656 buttonbar_set_label (b, 1, Q_ ("ButtonBar|Help"), main_map, NULL);
1657 buttonbar_set_label (b, 2, Q_ ("ButtonBar|Menu"), main_map, NULL);
1658 buttonbar_set_label (b, 3, Q_ ("ButtonBar|View"), main_map, NULL);
1659 buttonbar_set_label (b, 4, Q_ ("ButtonBar|Edit"), main_map, NULL);
1660 buttonbar_set_label (b, 5, Q_ ("ButtonBar|Copy"), main_map, NULL);
1661 buttonbar_set_label (b, 6, Q_ ("ButtonBar|RenMov"), main_map, NULL);
1662 buttonbar_set_label (b, 7, Q_ ("ButtonBar|Mkdir"), main_map, NULL);
1663 buttonbar_set_label (b, 8, Q_ ("ButtonBar|Delete"), main_map, NULL);
1664 buttonbar_set_label (b, 9, Q_ ("ButtonBar|PullDn"), main_map, NULL);
1665 buttonbar_set_label (b, 10, Q_ ("ButtonBar|Quit"), main_map, NULL);
1668 /* --------------------------------------------------------------------------------------------- */
1670 * Load new hint and display it.
1671 * IF force is not 0, ignore the timeout.
1674 void
1675 load_hint (gboolean force)
1677 char *hint;
1679 if (WIDGET (the_hint)->owner == NULL)
1680 return;
1682 if (!mc_global.message_visible)
1684 label_set_text (the_hint, NULL);
1685 return;
1688 hint = get_random_hint (force);
1690 if (hint != NULL)
1692 if (*hint != '\0')
1693 set_hintbar (hint);
1694 g_free (hint);
1696 else
1698 char text[BUF_SMALL];
1700 g_snprintf (text, sizeof (text), _("GNU Midnight Commander %s\n"), VERSION);
1701 set_hintbar (text);
1705 /* --------------------------------------------------------------------------------------------- */
1707 void
1708 change_panel (void)
1710 input_free_completions (cmdline);
1711 dlg_one_down (midnight_dlg);
1714 /* --------------------------------------------------------------------------------------------- */
1716 /** Save current stat of directories to avoid reloading the panels
1717 * when no modifications have taken place
1719 void
1720 save_cwds_stat (void)
1722 if (panels_options.fast_reload)
1724 mc_stat (current_panel->cwd_vpath, &(current_panel->dir_stat));
1725 if (get_other_type () == view_listing)
1726 mc_stat (other_panel->cwd_vpath, &(other_panel->dir_stat));
1730 /* --------------------------------------------------------------------------------------------- */
1732 gboolean
1733 quiet_quit_cmd (void)
1735 print_last_revert = TRUE;
1736 return quit_cmd_internal (1);
1739 /* --------------------------------------------------------------------------------------------- */
1741 /** Run the main dialog that occupies the whole screen */
1742 gboolean
1743 do_nc (void)
1745 gboolean ret;
1747 dlg_colors_t midnight_colors;
1749 midnight_colors[DLG_COLOR_NORMAL] = mc_skin_color_get ("dialog", "_default_");
1750 midnight_colors[DLG_COLOR_FOCUS] = mc_skin_color_get ("dialog", "focus");
1751 midnight_colors[DLG_COLOR_HOT_NORMAL] = mc_skin_color_get ("dialog", "hotnormal");
1752 midnight_colors[DLG_COLOR_HOT_FOCUS] = mc_skin_color_get ("dialog", "hotfocus");
1753 midnight_colors[DLG_COLOR_TITLE] = mc_skin_color_get ("dialog", "title");
1755 #ifdef USE_INTERNAL_EDIT
1756 edit_stack_init ();
1757 #endif
1759 midnight_dlg = create_dlg (FALSE, 0, 0, LINES, COLS, midnight_colors, midnight_callback,
1760 midnight_event, "[main]", NULL, DLG_NONE);
1762 /* Check if we were invoked as an editor or file viewer */
1763 if (mc_global.mc_run_mode != MC_RUN_FULL)
1765 setup_dummy_mc ();
1766 ret = mc_maybe_editor_or_viewer ();
1768 else
1770 /* We only need the first idle event to show user menu after start */
1771 widget_want_idle (WIDGET (midnight_dlg), TRUE);
1773 setup_mc ();
1774 mc_filehighlight = mc_fhl_new (TRUE);
1775 create_panels_and_run_mc ();
1776 mc_fhl_free (&mc_filehighlight);
1778 ret = TRUE;
1780 /* destroy_dlg destroys even current_panel->cwd_vpath, so we have to save a copy :) */
1781 if (mc_args__last_wd_file != NULL && vfs_current_is_local ())
1782 last_wd_string = vfs_path_to_str (current_panel->cwd_vpath);
1784 /* don't handle VFS timestamps for dirs opened in panels */
1785 mc_event_destroy (MCEVENT_GROUP_CORE, "vfs_timestamp");
1787 clean_dir (&panelized_panel.list, panelized_panel.count);
1790 /* Program end */
1791 mc_global.midnight_shutdown = TRUE;
1792 dialog_switch_shutdown ();
1793 done_mc ();
1794 destroy_dlg (midnight_dlg);
1795 current_panel = NULL;
1797 #ifdef USE_INTERNAL_EDIT
1798 edit_stack_free ();
1799 #endif
1801 if ((quit & SUBSHELL_EXIT) == 0)
1802 clr_scr ();
1804 return ret;
1807 /* --------------------------------------------------------------------------------------------- */