Changed type of WPanel::cwd (char *) and WPanel::lwd (char *)
[midnight-commander.git] / src / filemanager / midnight.c
blobb551418cefe7fad22daa32791c490e63f765a59e
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)
156 do_cd (sel_dir, cd_exact);
157 g_free (sel_dir);
161 /* --------------------------------------------------------------------------------------------- */
163 #ifdef LISTMODE_EDITOR
164 static void
165 listmode_cmd (void)
167 char *newmode;
169 if (get_current_type () != view_listing)
170 return;
172 newmode = listmode_edit (current_panel->user_format);
173 if (!newmode)
174 return;
176 g_free (current_panel->user_format);
177 current_panel->list_type = list_user;
178 current_panel->user_format = newmode;
179 set_panel_formats (current_panel);
181 do_refresh ();
183 #endif /* LISTMODE_EDITOR */
185 /* --------------------------------------------------------------------------------------------- */
187 static GList *
188 create_panel_menu (void)
190 GList *entries = NULL;
192 entries = g_list_prepend (entries, menu_entry_create (_("File listin&g"), CK_PanelListing));
193 entries = g_list_prepend (entries, menu_entry_create (_("&Quick view"), CK_PanelQuickView));
194 entries = g_list_prepend (entries, menu_entry_create (_("&Info"), CK_PanelInfo));
195 entries = g_list_prepend (entries, menu_entry_create (_("&Tree"), CK_PanelTree));
196 entries = g_list_prepend (entries, menu_separator_create ());
197 entries =
198 g_list_prepend (entries, menu_entry_create (_("&Listing mode..."), CK_PanelListingChange));
199 entries = g_list_prepend (entries, menu_entry_create (_("&Sort order..."), CK_Sort));
200 entries = g_list_prepend (entries, menu_entry_create (_("&Filter..."), CK_Filter));
201 #ifdef HAVE_CHARSET
202 entries = g_list_prepend (entries, menu_entry_create (_("&Encoding..."), CK_SelectCodepage));
203 #endif
204 entries = g_list_prepend (entries, menu_separator_create ());
205 #ifdef ENABLE_VFS_FTP
206 entries = g_list_prepend (entries, menu_entry_create (_("FT&P link..."), CK_ConnectFtp));
207 #endif
208 #ifdef ENABLE_VFS_FISH
209 entries = g_list_prepend (entries, menu_entry_create (_("S&hell link..."), CK_ConnectFish));
210 #endif
211 #ifdef ENABLE_VFS_SMB
212 entries = g_list_prepend (entries, menu_entry_create (_("SM&B link..."), CK_ConnectSmb));
213 #endif
214 entries = g_list_prepend (entries, menu_entry_create (_("Paneli&ze"), CK_Panelize));
215 entries = g_list_prepend (entries, menu_separator_create ());
216 entries = g_list_prepend (entries, menu_entry_create (_("&Rescan"), CK_Reread));
218 return g_list_reverse (entries);
221 /* --------------------------------------------------------------------------------------------- */
223 static GList *
224 create_file_menu (void)
226 GList *entries = NULL;
228 entries = g_list_prepend (entries, menu_entry_create (_("&View"), CK_View));
229 entries = g_list_prepend (entries, menu_entry_create (_("Vie&w file..."), CK_ViewFile));
230 entries = g_list_prepend (entries, menu_entry_create (_("&Filtered view"), CK_ViewFiltered));
231 entries = g_list_prepend (entries, menu_entry_create (_("&Edit"), CK_Edit));
232 entries = g_list_prepend (entries, menu_entry_create (_("&Copy"), CK_Copy));
233 entries = g_list_prepend (entries, menu_entry_create (_("C&hmod"), CK_ChangeMode));
234 entries = g_list_prepend (entries, menu_entry_create (_("&Link"), CK_Link));
235 entries = g_list_prepend (entries, menu_entry_create (_("&Symlink"), CK_LinkSymbolic));
236 entries =
237 g_list_prepend (entries,
238 menu_entry_create (_("Relative symlin&k"), CK_LinkSymbolicRelative));
239 entries = g_list_prepend (entries, menu_entry_create (_("Edit s&ymlink"), CK_LinkSymbolicEdit));
240 entries = g_list_prepend (entries, menu_entry_create (_("Ch&own"), CK_ChangeOwn));
241 entries =
242 g_list_prepend (entries, menu_entry_create (_("&Advanced chown"), CK_ChangeOwnAdvanced));
243 entries = g_list_prepend (entries, menu_entry_create (_("&Rename/Move"), CK_Move));
244 entries = g_list_prepend (entries, menu_entry_create (_("&Mkdir"), CK_MakeDir));
245 entries = g_list_prepend (entries, menu_entry_create (_("&Delete"), CK_Delete));
246 entries = g_list_prepend (entries, menu_entry_create (_("&Quick cd"), CK_CdQuick));
247 entries = g_list_prepend (entries, menu_separator_create ());
248 entries = g_list_prepend (entries, menu_entry_create (_("Select &group"), CK_Select));
249 entries = g_list_prepend (entries, menu_entry_create (_("U&nselect group"), CK_Unselect));
250 entries = g_list_prepend (entries, menu_entry_create (_("&Invert selection"), CK_SelectInvert));
251 entries = g_list_prepend (entries, menu_separator_create ());
252 entries = g_list_prepend (entries, menu_entry_create (_("E&xit"), CK_Quit));
254 return g_list_reverse (entries);
257 /* --------------------------------------------------------------------------------------------- */
259 static GList *
260 create_command_menu (void)
262 /* I know, I'm lazy, but the tree widget when it's not running
263 * as a panel still has some problems, I have not yet finished
264 * the WTree widget port, sorry.
266 GList *entries = NULL;
268 entries = g_list_prepend (entries, menu_entry_create (_("&User menu"), CK_UserMenu));
269 entries = g_list_prepend (entries, menu_entry_create (_("&Directory tree"), CK_Tree));
270 entries = g_list_prepend (entries, menu_entry_create (_("&Find file"), CK_Find));
271 entries = g_list_prepend (entries, menu_entry_create (_("S&wap panels"), CK_Swap));
272 entries = g_list_prepend (entries, menu_entry_create (_("Switch &panels on/off"), CK_Shell));
273 entries =
274 g_list_prepend (entries, menu_entry_create (_("&Compare directories"), CK_CompareDirs));
275 #ifdef USE_DIFF_VIEW
276 entries = g_list_prepend (entries, menu_entry_create (_("C&ompare files"), CK_CompareFiles));
277 #endif
278 entries =
279 g_list_prepend (entries, menu_entry_create (_("E&xternal panelize"), CK_ExternalPanelize));
280 entries = g_list_prepend (entries, menu_entry_create (_("Show directory s&izes"), CK_DirSize));
281 entries = g_list_prepend (entries, menu_separator_create ());
282 entries = g_list_prepend (entries, menu_entry_create (_("Command &history"), CK_History));
283 entries = g_list_prepend (entries, menu_entry_create (_("Di&rectory hotlist"), CK_HotList));
284 #ifdef ENABLE_VFS
285 entries = g_list_prepend (entries, menu_entry_create (_("&Active VFS list"), CK_VfsList));
286 #endif
287 #ifdef ENABLE_BACKGROUND
288 entries = g_list_prepend (entries, menu_entry_create (_("&Background jobs"), CK_Jobs));
289 #endif
290 entries = g_list_prepend (entries, menu_entry_create (_("Screen lis&t"), CK_ScreenList));
291 entries = g_list_prepend (entries, menu_separator_create ());
292 #ifdef ENABLE_VFS_UNDELFS
293 entries =
294 g_list_prepend (entries,
295 menu_entry_create (_("&Undelete files (ext2fs only)"), CK_Undelete));
296 #endif
297 #ifdef LISTMODE_EDITOR
298 entries = g_list_prepend (entries, menu_entry_create (_("&Listing format edit"), CK_ListMode));
299 #endif
300 #if defined (ENABLE_VFS_UNDELFS) || defined (LISTMODE_EDITOR)
301 entries = g_list_prepend (entries, menu_separator_create ());
302 #endif
303 entries =
304 g_list_prepend (entries,
305 menu_entry_create (_("Edit &extension file"), CK_EditExtensionsFile));
306 entries = g_list_prepend (entries, menu_entry_create (_("Edit &menu file"), CK_EditUserMenu));
307 entries =
308 g_list_prepend (entries,
309 menu_entry_create (_("Edit hi&ghlighting group file"),
310 CK_EditFileHighlightFile));
312 return g_list_reverse (entries);
315 /* --------------------------------------------------------------------------------------------- */
317 static GList *
318 create_options_menu (void)
320 GList *entries = NULL;
322 entries = g_list_prepend (entries, menu_entry_create (_("&Configuration..."), CK_Options));
323 entries = g_list_prepend (entries, menu_entry_create (_("&Layout..."), CK_OptionsLayout));
324 entries = g_list_prepend (entries, menu_entry_create (_("&Panel options..."), CK_OptionsPanel));
325 entries =
326 g_list_prepend (entries, menu_entry_create (_("C&onfirmation..."), CK_OptionsConfirm));
327 entries =
328 g_list_prepend (entries, menu_entry_create (_("&Display bits..."), CK_OptionsDisplayBits));
329 entries = g_list_prepend (entries, menu_entry_create (_("Learn &keys..."), CK_LearnKeys));
330 #ifdef ENABLE_VFS
331 entries = g_list_prepend (entries, menu_entry_create (_("&Virtual FS..."), CK_OptionsVfs));
332 #endif
333 entries = g_list_prepend (entries, menu_separator_create ());
334 entries = g_list_prepend (entries, menu_entry_create (_("&Save setup"), CK_SaveSetup));
336 return g_list_reverse (entries);
339 /* --------------------------------------------------------------------------------------------- */
341 static void
342 init_menu (void)
344 left_menu = create_menu ("", create_panel_menu (), "[Left and Right Menus]");
345 menubar_add_menu (the_menubar, left_menu);
346 menubar_add_menu (the_menubar, create_menu (_("&File"), create_file_menu (), "[File Menu]"));
347 menubar_add_menu (the_menubar,
348 create_menu (_("&Command"), create_command_menu (), "[Command Menu]"));
349 menubar_add_menu (the_menubar,
350 create_menu (_("&Options"), create_options_menu (), "[Options Menu]"));
351 right_menu = create_menu ("", create_panel_menu (), "[Left and Right Menus]");
352 menubar_add_menu (the_menubar, right_menu);
353 update_menu ();
356 /* --------------------------------------------------------------------------------------------- */
358 static void
359 menu_last_selected_cmd (void)
361 the_menubar->is_active = TRUE;
362 the_menubar->is_dropped = (drop_menus != 0);
363 the_menubar->previous_widget = dlg_get_current_widget_id (midnight_dlg);
364 dlg_select_widget (the_menubar);
367 /* --------------------------------------------------------------------------------------------- */
369 static void
370 menu_cmd (void)
372 if (the_menubar->is_active)
373 return;
375 if ((get_current_index () == 0) == (current_panel->active != 0))
376 the_menubar->selected = 0;
377 else
378 the_menubar->selected = g_list_length (the_menubar->menu) - 1;
379 menu_last_selected_cmd ();
382 /* --------------------------------------------------------------------------------------------- */
384 static void
385 sort_cmd (void)
387 WPanel *p;
388 const panel_field_t *sort_order;
390 if (!SELECTED_IS_PANEL)
391 return;
393 p = MENU_PANEL;
394 sort_order = sort_box (&p->sort_info);
395 panel_set_sort_order (p, sort_order);
398 /* --------------------------------------------------------------------------------------------- */
400 static char *
401 midnight_get_shortcut (unsigned long command)
403 const char *ext_map;
404 const char *shortcut = NULL;
406 shortcut = keybind_lookup_keymap_shortcut (main_map, command);
407 if (shortcut != NULL)
408 return g_strdup (shortcut);
410 shortcut = keybind_lookup_keymap_shortcut (panel_map, command);
411 if (shortcut != NULL)
412 return g_strdup (shortcut);
414 ext_map = keybind_lookup_keymap_shortcut (main_map, CK_ExtendedKeyMap);
415 if (ext_map != NULL)
416 shortcut = keybind_lookup_keymap_shortcut (main_x_map, command);
417 if (shortcut != NULL)
418 return g_strdup_printf ("%s %s", ext_map, shortcut);
420 return NULL;
423 /* --------------------------------------------------------------------------------------------- */
425 static char *
426 midnight_get_title (const Dlg_head * h, size_t len)
428 /* TODO: share code with update_xterm_title_path() */
430 const char *path;
431 char host[BUF_TINY];
432 char *p;
433 struct passwd *pw = NULL;
434 char *login = NULL;
435 int res = 0;
437 (void) h;
439 p = vfs_path_to_str (current_panel->cwd_vpath);
440 path = strip_home_and_password (p);
441 g_free (p);
442 res = gethostname (host, sizeof (host));
443 if (res != 0)
444 host[0] = '\0';
445 else
446 host[sizeof (host) - 1] = '\0';
448 pw = getpwuid (getuid ());
449 if (pw != NULL)
450 login = g_strdup_printf ("%s@%s", pw->pw_name, host);
451 else
452 login = g_strdup (host);
454 p = g_strdup_printf ("%s [%s]:%s", _("Panels:"), login, path);
455 path = str_trunc (p, len - 4);
456 g_free (login);
457 g_free (p);
459 return g_strdup (path);
462 /* --------------------------------------------------------------------------------------------- */
464 static void
465 toggle_panels_split (void)
467 panels_layout.horizontal_split = !panels_layout.horizontal_split;
468 layout_change ();
469 do_refresh ();
472 /* --------------------------------------------------------------------------------------------- */
474 #ifdef ENABLE_VFS
475 /* event helper */
476 static gboolean
477 check_panel_timestamp (const WPanel * panel, panel_view_mode_t mode, struct vfs_class *vclass,
478 vfsid id)
480 if (mode == view_listing)
482 vfs_path_element_t *path_element;
484 path_element = vfs_path_get_by_index (panel->cwd_vpath, -1);
486 if (path_element->class != vclass)
487 return FALSE;
489 if (vfs_getid (panel->cwd_vpath) != id)
490 return FALSE;
492 return TRUE;
495 /* --------------------------------------------------------------------------------------------- */
497 /* event callback */
498 static gboolean
499 check_current_panel_timestamp (const gchar * event_group_name, const gchar * event_name,
500 gpointer init_data, gpointer data)
502 ev_vfs_stamp_create_t *event_data = (ev_vfs_stamp_create_t *) data;
504 (void) event_group_name;
505 (void) event_name;
506 (void) init_data;
508 event_data->ret =
509 check_panel_timestamp (current_panel, get_current_type (), event_data->vclass,
510 event_data->id);
511 return !event_data->ret;
514 /* --------------------------------------------------------------------------------------------- */
516 /* event callback */
517 static gboolean
518 check_other_panel_timestamp (const gchar * event_group_name, const gchar * event_name,
519 gpointer init_data, gpointer data)
521 ev_vfs_stamp_create_t *event_data = (ev_vfs_stamp_create_t *) data;
523 (void) event_group_name;
524 (void) event_name;
525 (void) init_data;
527 event_data->ret =
528 check_panel_timestamp (other_panel, get_other_type (), event_data->vclass, event_data->id);
529 return !event_data->ret;
531 #endif /* ENABLE_VFS */
533 /* --------------------------------------------------------------------------------------------- */
535 /* event callback */
536 static gboolean
537 print_vfs_message (const gchar * event_group_name, const gchar * event_name,
538 gpointer init_data, gpointer data)
540 char str[128];
541 ev_vfs_print_message_t *event_data = (ev_vfs_print_message_t *) data;
543 (void) event_group_name;
544 (void) event_name;
545 (void) init_data;
547 g_vsnprintf (str, sizeof (str), event_data->msg, event_data->ap);
549 if (mc_global.midnight_shutdown)
550 return TRUE;
552 if (!mc_global.message_visible || !the_hint || !the_hint->widget.owner)
554 int col, row;
556 if (!nice_rotating_dash || (ok_to_refresh <= 0))
557 return TRUE;
559 /* Preserve current cursor position */
560 tty_getyx (&row, &col);
562 tty_gotoyx (0, 0);
563 tty_setcolor (NORMAL_COLOR);
564 tty_print_string (str_fit_to_term (str, COLS - 1, J_LEFT));
566 /* Restore cursor position */
567 tty_gotoyx (row, col);
568 mc_refresh ();
569 return TRUE;
572 if (mc_global.message_visible)
573 set_hintbar (str);
575 return TRUE;
578 /* --------------------------------------------------------------------------------------------- */
580 static void
581 create_panels (void)
583 int current_index;
584 int other_index;
585 panel_view_mode_t current_mode, other_mode;
586 char *original_dir = NULL;
588 if (boot_current_is_left)
590 current_index = 0;
591 other_index = 1;
592 current_mode = startup_left_mode;
593 other_mode = startup_right_mode;
595 else
597 current_index = 1;
598 other_index = 0;
599 current_mode = startup_right_mode;
600 other_mode = startup_left_mode;
602 /* Creates the left panel */
603 if (mc_run_param0 != NULL)
605 vfs_path_t *vpath;
607 if (mc_run_param1 != NULL)
609 /* Ok, user has specified two dirs, save the original one,
610 * since we may not be able to chdir to the proper
611 * second directory later
613 original_dir = vfs_get_current_dir ();
615 vpath = vfs_path_from_str (mc_run_param0);
616 mc_chdir (vpath);
617 vfs_path_free (vpath);
619 set_display_type (current_index, current_mode);
621 /* The other panel */
622 if (mc_run_param1 != NULL)
624 const char *cd_dir = (original_dir != NULL) ? original_dir : mc_run_param1;
625 vfs_path_t *vpath;
627 vpath = vfs_path_from_str (cd_dir);
628 mc_chdir (vpath);
629 vfs_path_free (vpath);
631 g_free (original_dir);
632 set_display_type (other_index, other_mode);
634 if (startup_left_mode == view_listing)
635 current_panel = left_panel;
636 else if (right_panel != NULL)
637 current_panel = right_panel;
638 else
639 current_panel = left_panel;
641 #ifdef ENABLE_VFS
642 mc_event_add (MCEVENT_GROUP_CORE, "vfs_timestamp", check_other_panel_timestamp, NULL, NULL);
643 mc_event_add (MCEVENT_GROUP_CORE, "vfs_timestamp", check_current_panel_timestamp, NULL, NULL);
644 #endif /* ENABLE_VFS */
646 mc_event_add (MCEVENT_GROUP_CORE, "vfs_print_message", print_vfs_message, NULL, NULL);
648 /* Create the nice widgets */
649 cmdline = command_new (0, 0, 0);
650 the_prompt = label_new (0, 0, mc_prompt);
651 the_prompt->transparent = 1;
652 the_bar = buttonbar_new (mc_global.keybar_visible);
654 the_hint = label_new (0, 0, 0);
655 the_hint->transparent = 1;
656 the_hint->auto_adjust_cols = 0;
657 the_hint->widget.cols = COLS;
659 the_menubar = menubar_new (0, 0, COLS, NULL);
662 /* --------------------------------------------------------------------------------------------- */
664 static void
665 put_current_path (void)
667 char *cwd_path;
668 if (!command_prompt)
669 return;
671 cwd_path = remove_encoding_from_path (current_panel->cwd_vpath);
672 command_insert (cmdline, cwd_path, FALSE);
674 if (cwd_path[strlen (cwd_path) - 1] != PATH_SEP)
675 command_insert (cmdline, PATH_SEP_STR, FALSE);
676 g_free (cwd_path);
679 /* --------------------------------------------------------------------------------------------- */
681 static void
682 put_other_path (void)
684 char *cwd_path;
686 if (get_other_type () != view_listing)
687 return;
689 if (!command_prompt)
690 return;
692 cwd_path = remove_encoding_from_path (other_panel->cwd_vpath);
693 command_insert (cmdline, cwd_path, FALSE);
695 if (cwd_path[strlen (cwd_path) - 1] != PATH_SEP)
696 command_insert (cmdline, PATH_SEP_STR, FALSE);
697 g_free (cwd_path);
700 /* --------------------------------------------------------------------------------------------- */
702 static void
703 put_link (WPanel * panel)
705 if (!command_prompt)
706 return;
707 if (S_ISLNK (selection (panel)->st.st_mode))
709 char buffer[MC_MAXPATHLEN];
710 vfs_path_t *vpath;
711 int i;
713 vpath = vfs_path_append_new (panel->cwd_vpath, selection (panel)->fname, NULL);
714 i = mc_readlink (vpath, buffer, MC_MAXPATHLEN - 1);
715 vfs_path_free (vpath);
717 if (i > 0)
719 buffer[i] = '\0';
720 command_insert (cmdline, buffer, TRUE);
725 /* --------------------------------------------------------------------------------------------- */
727 static void
728 put_current_link (void)
730 put_link (current_panel);
733 /* --------------------------------------------------------------------------------------------- */
735 static void
736 put_other_link (void)
738 if (get_other_type () == view_listing)
739 put_link (other_panel);
742 /* --------------------------------------------------------------------------------------------- */
744 /** Insert the selected file name into the input line */
745 static void
746 put_prog_name (void)
748 char *tmp;
749 if (!command_prompt)
750 return;
752 if (get_current_type () == view_tree)
754 WTree *tree = (WTree *) get_panel_widget (get_current_index ());
755 tmp = tree_selected_name (tree);
757 else
758 tmp = selection (current_panel)->fname;
760 command_insert (cmdline, tmp, TRUE);
763 /* --------------------------------------------------------------------------------------------- */
765 static void
766 put_tagged (WPanel * panel)
768 int i;
770 if (!command_prompt)
771 return;
772 input_disable_update (cmdline);
773 if (panel->marked)
775 for (i = 0; i < panel->count; i++)
777 if (panel->dir.list[i].f.marked)
778 command_insert (cmdline, panel->dir.list[i].fname, TRUE);
781 else
783 command_insert (cmdline, panel->dir.list[panel->selected].fname, TRUE);
785 input_enable_update (cmdline);
788 /* --------------------------------------------------------------------------------------------- */
790 static void
791 put_current_tagged (void)
793 put_tagged (current_panel);
796 /* --------------------------------------------------------------------------------------------- */
798 static void
799 put_other_tagged (void)
801 if (get_other_type () == view_listing)
802 put_tagged (other_panel);
805 /* --------------------------------------------------------------------------------------------- */
807 static void
808 ctl_x_cmd (void)
810 ctl_x_map_enabled = TRUE;
813 /* --------------------------------------------------------------------------------------------- */
815 static void
816 setup_mc (void)
818 #ifdef HAVE_SLANG
819 #ifdef HAVE_CHARSET
820 tty_display_8bit (TRUE);
821 #else
822 tty_display_8bit (mc_global.full_eight_bits != 0);
823 #endif /* HAVE_CHARSET */
825 #else /* HAVE_SLANG */
827 #ifdef HAVE_CHARSET
828 tty_display_8bit (TRUE);
829 #else
830 tty_display_8bit (mc_global.eight_bit_clean != 0);
831 #endif /* HAVE_CHARSET */
832 #endif /* HAVE_SLANG */
834 #ifdef HAVE_SUBSHELL_SUPPORT
835 if (mc_global.tty.use_subshell)
836 add_select_channel (mc_global.tty.subshell_pty, load_prompt, 0);
837 #endif /* !HAVE_SUBSHELL_SUPPORT */
839 if ((tty_baudrate () < 9600) || mc_global.tty.slow_terminal)
840 verbose = 0;
843 /* --------------------------------------------------------------------------------------------- */
845 static void
846 setup_dummy_mc (void)
848 vfs_path_t *vpath;
849 char *d;
850 int ret;
852 d = _vfs_get_cwd ();
853 setup_mc ();
854 vpath = vfs_path_from_str (d);
855 ret = mc_chdir (vpath);
856 vfs_path_free (vpath);
857 g_free (d);
860 /* --------------------------------------------------------------------------------------------- */
862 static void
863 done_mc (void)
865 /* Setup shutdown
867 * We sync the profiles since the hotlist may have changed, while
868 * we only change the setup data if we have the auto save feature set
870 char *curr_dir;
872 save_setup (auto_save_setup, panels_options.auto_save_setup);
874 curr_dir = vfs_get_current_dir ();
875 vfs_stamp_path (curr_dir);
876 g_free (curr_dir);
878 if ((current_panel != NULL) && (get_current_type () == view_listing))
880 char *tmp_path;
882 tmp_path = vfs_path_to_str (current_panel->cwd_vpath);
883 vfs_stamp_path (tmp_path);
884 g_free (tmp_path);
887 if ((other_panel != NULL) && (get_other_type () == view_listing))
889 char *tmp_path;
891 tmp_path = vfs_path_to_str (other_panel->cwd_vpath);
892 vfs_stamp_path (tmp_path);
893 g_free (tmp_path);
897 /* --------------------------------------------------------------------------------------------- */
899 static void
900 create_panels_and_run_mc (void)
902 midnight_dlg->get_shortcut = midnight_get_shortcut;
903 midnight_dlg->get_title = midnight_get_title;
905 create_panels ();
907 add_widget (midnight_dlg, the_menubar);
908 init_menu ();
910 add_widget (midnight_dlg, get_panel_widget (0));
911 add_widget (midnight_dlg, get_panel_widget (1));
913 add_widget (midnight_dlg, the_hint);
914 add_widget (midnight_dlg, cmdline);
915 add_widget (midnight_dlg, the_prompt);
917 add_widget (midnight_dlg, the_bar);
918 midnight_set_buttonbar (the_bar);
920 /* Run the Midnight Commander if no file was specified in the command line */
921 run_dlg (midnight_dlg);
924 /* --------------------------------------------------------------------------------------------- */
926 /** result must be free'd (I think this should go in util.c) */
927 static char *
928 prepend_cwd_on_local (const char *filename)
930 char *d;
931 size_t l;
932 vfs_path_t *vpath;
934 vpath = vfs_path_from_str (filename);
935 if (!vfs_file_is_local (vpath) || g_path_is_absolute (filename))
937 vfs_path_free (vpath);
938 return g_strdup (filename);
940 vfs_path_free (vpath);
942 d = _vfs_get_cwd ();
943 l = strlen (d);
944 d[l++] = PATH_SEP;
945 strcpy (d + l, filename);
946 canonicalize_pathname (d);
947 return d;
950 /* --------------------------------------------------------------------------------------------- */
952 /** Invoke the internal view/edit routine with:
953 * the default processing and forcing the internal viewer/editor
955 static gboolean
956 mc_maybe_editor_or_viewer (void)
958 int ret;
960 switch (mc_global.mc_run_mode)
962 #ifdef USE_INTERNAL_EDIT
963 case MC_RUN_EDITOR:
964 ret = edit_file (mc_run_param0, mc_args__edit_start_line);
965 break;
966 #endif /* USE_INTERNAL_EDIT */
967 case MC_RUN_VIEWER:
969 char *path;
971 path = prepend_cwd_on_local (mc_run_param0);
972 view_file (path, 0, 1);
973 g_free (path);
974 ret = 1;
975 break;
977 #ifdef USE_DIFF_VIEW
978 case MC_RUN_DIFFVIEWER:
979 ret = diff_view (mc_run_param0, mc_run_param1, mc_run_param0, mc_run_param1);
980 break;
981 #endif /* USE_DIFF_VIEW */
982 default:
983 ret = 0;
986 return (ret != 0);
989 /* --------------------------------------------------------------------------------------------- */
991 static gboolean
992 quit_cmd_internal (int quiet)
994 int q = quit;
995 size_t n;
997 n = dialog_switch_num () - 1;
998 if (n != 0)
1000 char msg[BUF_MEDIUM];
1002 g_snprintf (msg, sizeof (msg),
1003 ngettext ("You have %zd opened screen. Quit anyway?",
1004 "You have %zd opened screens. Quit anyway?", n), n);
1006 if (query_dialog (_("The Midnight Commander"), msg, D_NORMAL, 2, _("&Yes"), _("&No")) != 0)
1007 return FALSE;
1008 q = 1;
1010 else if (quiet || !confirm_exit)
1011 q = 1;
1012 else if (query_dialog (_("The Midnight Commander"),
1013 _("Do you really want to quit the Midnight Commander?"),
1014 D_NORMAL, 2, _("&Yes"), _("&No")) == 0)
1015 q = 1;
1017 if (q != 0)
1019 #ifdef HAVE_SUBSHELL_SUPPORT
1020 if (!mc_global.tty.use_subshell)
1021 stop_dialogs ();
1022 else if ((q = exit_subshell ()))
1023 #endif
1024 stop_dialogs ();
1027 if (q != 0)
1028 quit |= 1;
1029 return (quit != 0);
1032 /* --------------------------------------------------------------------------------------------- */
1034 static gboolean
1035 quit_cmd (void)
1037 return quit_cmd_internal (0);
1040 /* --------------------------------------------------------------------------------------------- */
1042 static void
1043 toggle_show_hidden (void)
1045 panels_options.show_dot_files = !panels_options.show_dot_files;
1046 update_panels (UP_RELOAD, UP_KEEPSEL);
1049 /* --------------------------------------------------------------------------------------------- */
1052 * Repaint the contents of the panels without frames. To schedule panel
1053 * for repainting, set panel->dirty to 1. There are many reasons why
1054 * the panels need to be repainted, and this is a costly operation, so
1055 * it's done once per event.
1058 static void
1059 update_dirty_panels (void)
1061 if (get_current_type () == view_listing && current_panel->dirty)
1062 send_message ((Widget *) current_panel, WIDGET_DRAW, 0);
1064 if (get_other_type () == view_listing && other_panel->dirty)
1065 send_message ((Widget *) other_panel, WIDGET_DRAW, 0);
1068 /* --------------------------------------------------------------------------------------------- */
1070 static cb_ret_t
1071 midnight_execute_cmd (Widget * sender, unsigned long command)
1073 cb_ret_t res = MSG_HANDLED;
1075 (void) sender;
1077 /* stop quick search before executing any command */
1078 send_message ((Widget *) current_panel, WIDGET_COMMAND, CK_SearchStop);
1080 switch (command)
1082 case CK_HotListAdd:
1083 add2hotlist_cmd ();
1084 break;
1085 case CK_PanelListingChange:
1086 change_listing_cmd ();
1087 break;
1088 case CK_ChangeMode:
1089 chmod_cmd ();
1090 break;
1091 case CK_ChangeOwn:
1092 chown_cmd ();
1093 break;
1094 case CK_ChangeOwnAdvanced:
1095 chown_advanced_cmd ();
1096 break;
1097 case CK_CompareDirs:
1098 compare_dirs_cmd ();
1099 break;
1100 case CK_Options:
1101 configure_box ();
1102 break;
1103 #ifdef ENABLE_VFS
1104 case CK_OptionsVfs:
1105 configure_vfs ();
1106 break;
1107 #endif
1108 case CK_OptionsConfirm:
1109 confirm_box ();
1110 break;
1111 case CK_Copy:
1112 copy_cmd ();
1113 break;
1114 case CK_PutCurrentPath:
1115 put_current_path ();
1116 break;
1117 case CK_PutCurrentLink:
1118 put_current_link ();
1119 break;
1120 case CK_PutCurrentTagged:
1121 put_current_tagged ();
1122 break;
1123 case CK_PutOtherPath:
1124 put_other_path ();
1125 break;
1126 case CK_PutOtherLink:
1127 put_other_link ();
1128 break;
1129 case CK_PutOtherTagged:
1130 put_other_tagged ();
1131 break;
1132 case CK_Delete:
1133 delete_cmd ();
1134 break;
1135 case CK_ScreenList:
1136 dialog_switch_list ();
1137 break;
1138 #ifdef USE_DIFF_VIEW
1139 case CK_CompareFiles:
1140 diff_view_cmd ();
1141 break;
1142 #endif
1143 case CK_OptionsDisplayBits:
1144 display_bits_box ();
1145 break;
1146 case CK_Edit:
1147 edit_cmd ();
1148 break;
1149 #ifdef USE_INTERNAL_EDIT
1150 case CK_EditForceInternal:
1151 edit_cmd_force_internal ();
1152 break;
1153 #endif
1154 case CK_EditExtensionsFile:
1155 ext_cmd ();
1156 break;
1157 case CK_EditFileHighlightFile:
1158 edit_fhl_cmd ();
1159 break;
1160 case CK_EditUserMenu:
1161 edit_mc_menu_cmd ();
1162 break;
1163 case CK_LinkSymbolicEdit:
1164 edit_symlink_cmd ();
1165 break;
1166 case CK_ExternalPanelize:
1167 external_panelize ();
1168 break;
1169 case CK_Filter:
1170 filter_cmd ();
1171 break;
1172 case CK_ViewFiltered:
1173 view_filtered_cmd ();
1174 break;
1175 case CK_Find:
1176 find_cmd ();
1177 break;
1178 #ifdef ENABLE_VFS_FISH
1179 case CK_ConnectFish:
1180 fishlink_cmd ();
1181 break;
1182 #endif
1183 #ifdef ENABLE_VFS_FTP
1184 case CK_ConnectFtp:
1185 ftplink_cmd ();
1186 break;
1187 #endif
1188 #ifdef ENABLE_VFS_SMB
1189 case CK_ConnectSmb:
1190 smblink_cmd ();
1191 break;
1192 #endif /* ENABLE_VFS_SMB */
1193 case CK_Panelize:
1194 cd_panelize_cmd ();
1195 break;
1196 case CK_Help:
1197 help_cmd ();
1198 break;
1199 case CK_History:
1200 /* show the history of command line widget */
1201 send_message (&cmdline->widget, WIDGET_COMMAND, CK_History);
1202 break;
1203 case CK_PanelInfo:
1204 if (sender == (Widget *) the_menubar)
1205 info_cmd (); /* menu */
1206 else
1207 info_cmd_no_menu (); /* shortcut or buttonbar */
1208 break;
1209 #ifdef ENABLE_BACKGROUND
1210 case CK_Jobs:
1211 jobs_cmd ();
1212 break;
1213 #endif
1214 case CK_OptionsLayout:
1215 layout_box ();
1216 break;
1217 case CK_LearnKeys:
1218 learn_keys ();
1219 break;
1220 case CK_Link:
1221 link_cmd (LINK_HARDLINK);
1222 break;
1223 case CK_PanelListing:
1224 listing_cmd ();
1225 break;
1226 #ifdef LISTMODE_EDITOR
1227 case CK_ListMode:
1228 listmode_cmd ();
1229 break;
1230 #endif
1231 case CK_Menu:
1232 menu_cmd ();
1233 break;
1234 case CK_MenuLastSelected:
1235 menu_last_selected_cmd ();
1236 break;
1237 case CK_MakeDir:
1238 mkdir_cmd ();
1239 break;
1240 case CK_OptionsPanel:
1241 panel_options_box ();
1242 break;
1243 #ifdef HAVE_CHARSET
1244 case CK_SelectCodepage:
1245 encoding_cmd ();
1246 break;
1247 #endif
1248 case CK_CdQuick:
1249 quick_cd_cmd ();
1250 break;
1251 case CK_HotList:
1252 hotlist_cmd ();
1253 break;
1254 case CK_PanelQuickView:
1255 if (sender == (Widget *) the_menubar)
1256 quick_view_cmd (); /* menu */
1257 else
1258 quick_cmd_no_menu (); /* shortcut or buttonabr */
1259 break;
1260 case CK_QuitQuiet:
1261 quiet_quit_cmd ();
1262 break;
1263 case CK_Quit:
1264 quit_cmd ();
1265 break;
1266 case CK_LinkSymbolicRelative:
1267 link_cmd (LINK_SYMLINK_RELATIVE);
1268 break;
1269 case CK_Move:
1270 rename_cmd ();
1271 break;
1272 case CK_Reread:
1273 reread_cmd ();
1274 break;
1275 #ifdef ENABLE_VFS
1276 case CK_VfsList:
1277 vfs_list ();
1278 break;
1279 #endif
1280 case CK_SelectInvert:
1281 select_invert_cmd ();
1282 break;
1283 case CK_SaveSetup:
1284 save_setup_cmd ();
1285 break;
1286 case CK_Select:
1287 select_cmd ();
1288 break;
1289 case CK_Shell:
1290 view_other_cmd ();
1291 break;
1292 case CK_DirSize:
1293 smart_dirsize_cmd ();
1294 break;
1295 case CK_Sort:
1296 sort_cmd ();
1297 break;
1298 case CK_ExtendedKeyMap:
1299 ctl_x_cmd ();
1300 break;
1301 case CK_Suspend:
1302 mc_event_raise (MCEVENT_GROUP_CORE, "suspend", NULL);
1303 break;
1304 case CK_Swap:
1305 swap_cmd ();
1306 break;
1307 case CK_LinkSymbolic:
1308 link_cmd (LINK_SYMLINK_ABSOLUTE);
1309 break;
1310 case CK_PanelListingSwitch:
1311 toggle_listing_cmd ();
1312 break;
1313 case CK_ShowHidden:
1314 toggle_show_hidden ();
1315 break;
1316 case CK_SplitVertHoriz:
1317 toggle_panels_split ();
1318 break;
1319 case CK_PanelTree:
1320 panel_tree_cmd ();
1321 break;
1322 case CK_Tree:
1323 treebox_cmd ();
1324 break;
1325 #ifdef ENABLE_VFS_UNDELFS
1326 case CK_Undelete:
1327 undelete_cmd ();
1328 break;
1329 #endif
1330 case CK_Unselect:
1331 unselect_cmd ();
1332 break;
1333 case CK_UserMenu:
1334 user_file_menu_cmd ();
1335 break;
1336 case CK_View:
1337 view_cmd ();
1338 break;
1339 case CK_ViewFile:
1340 view_file_cmd ();
1341 break;
1342 case CK_Cancel:
1343 /* don't close panels due to SIGINT */
1344 break;
1345 default:
1346 res = MSG_NOT_HANDLED;
1349 return res;
1352 /* --------------------------------------------------------------------------------------------- */
1354 static cb_ret_t
1355 midnight_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
1357 unsigned long command;
1359 switch (msg)
1361 case DLG_INIT:
1362 panel_init ();
1363 setup_panels ();
1364 return MSG_HANDLED;
1366 case DLG_DRAW:
1367 load_hint (1);
1368 /* We handle the special case of the output lines */
1369 if (mc_global.tty.console_flag != '\0' && output_lines)
1370 show_console_contents (output_start_y,
1371 LINES - output_lines - mc_global.keybar_visible -
1372 1, LINES - mc_global.keybar_visible - 1);
1373 return MSG_HANDLED;
1375 case DLG_RESIZE:
1376 setup_panels ();
1377 menubar_arrange (the_menubar);
1378 return MSG_HANDLED;
1380 case DLG_IDLE:
1381 /* We only need the first idle event to show user menu after start */
1382 set_idle_proc (h, 0);
1384 if (boot_current_is_left)
1385 dlg_select_widget (get_panel_widget (0));
1386 else
1387 dlg_select_widget (get_panel_widget (1));
1389 if (auto_menu)
1390 midnight_execute_cmd (NULL, CK_UserMenu);
1391 return MSG_HANDLED;
1393 case DLG_KEY:
1394 if (ctl_x_map_enabled)
1396 ctl_x_map_enabled = FALSE;
1397 command = keybind_lookup_keymap_command (main_x_map, parm);
1398 if (command != CK_IgnoreKey)
1399 return midnight_execute_cmd (NULL, command);
1402 /* FIXME: should handle all menu shortcuts before this point */
1403 if (the_menubar->is_active)
1404 return MSG_NOT_HANDLED;
1406 if (parm == '\t')
1407 input_free_completions (cmdline);
1409 if (parm == '\n')
1411 size_t i;
1413 for (i = 0; cmdline->buffer[i] != '\0' &&
1414 (cmdline->buffer[i] == ' ' || cmdline->buffer[i] == '\t'); i++)
1417 if (cmdline->buffer[i] != '\0')
1419 send_message ((Widget *) cmdline, WIDGET_KEY, parm);
1420 return MSG_HANDLED;
1423 input_insert (cmdline, "", FALSE);
1424 cmdline->point = 0;
1427 /* Ctrl-Enter and Alt-Enter */
1428 if (((parm & ~(KEY_M_CTRL | KEY_M_ALT)) == '\n') && (parm & (KEY_M_CTRL | KEY_M_ALT)))
1430 put_prog_name ();
1431 return MSG_HANDLED;
1434 /* Ctrl-Shift-Enter */
1435 if (parm == (KEY_M_CTRL | KEY_M_SHIFT | '\n'))
1437 put_current_path ();
1438 put_prog_name ();
1439 return MSG_HANDLED;
1442 if ((!mc_global.tty.alternate_plus_minus
1443 || !(mc_global.tty.console_flag != '\0' || mc_global.tty.xterm_flag)) && !quote
1444 && !current_panel->searching)
1446 if (!only_leading_plus_minus)
1448 /* Special treatement, since the input line will eat them */
1449 if (parm == '+')
1451 select_cmd ();
1452 return MSG_HANDLED;
1455 if (parm == '\\' || parm == '-')
1457 unselect_cmd ();
1458 return MSG_HANDLED;
1461 if (parm == '*')
1463 select_invert_cmd ();
1464 return MSG_HANDLED;
1467 else if (!command_prompt || !cmdline->buffer[0])
1469 /* Special treatement '+', '-', '\', '*' only when this is
1470 * first char on input line
1473 if (parm == '+')
1475 select_cmd ();
1476 return MSG_HANDLED;
1479 if (parm == '\\' || parm == '-')
1481 unselect_cmd ();
1482 return MSG_HANDLED;
1485 if (parm == '*')
1487 select_invert_cmd ();
1488 return MSG_HANDLED;
1492 return MSG_NOT_HANDLED;
1494 case DLG_HOTKEY_HANDLED:
1495 if ((get_current_type () == view_listing) && current_panel->searching)
1497 current_panel->dirty = 1; /* FIXME: unneeded? */
1498 send_message ((Widget *) current_panel, WIDGET_COMMAND, CK_SearchStop);
1500 return MSG_HANDLED;
1502 case DLG_UNHANDLED_KEY:
1504 cb_ret_t v = MSG_NOT_HANDLED;
1506 if (ctl_x_map_enabled)
1508 ctl_x_map_enabled = FALSE;
1509 command = keybind_lookup_keymap_command (main_x_map, parm);
1511 else
1512 command = keybind_lookup_keymap_command (main_map, parm);
1514 if (command != CK_IgnoreKey)
1515 v = midnight_execute_cmd (NULL, command);
1517 if (v == MSG_NOT_HANDLED && command_prompt)
1518 v = send_message ((Widget *) cmdline, WIDGET_KEY, parm);
1520 return v;
1523 case DLG_POST_KEY:
1524 if (!the_menubar->is_active)
1525 update_dirty_panels ();
1526 return MSG_HANDLED;
1528 case DLG_ACTION:
1529 /* shortcut */
1530 if (sender == NULL)
1531 return midnight_execute_cmd (NULL, parm);
1532 /* message from menu */
1533 if (sender == (Widget *) the_menubar)
1534 return midnight_execute_cmd (sender, parm);
1535 /* message from buttonbar */
1536 if (sender == (Widget *) the_bar)
1538 if (data != NULL)
1539 return send_message ((Widget *) data, WIDGET_COMMAND, parm);
1540 return midnight_execute_cmd (sender, parm);
1542 return MSG_NOT_HANDLED;
1544 case DLG_END:
1545 panel_deinit ();
1546 return MSG_HANDLED;
1548 default:
1549 return default_dlg_callback (h, sender, msg, parm, data);
1553 /* --------------------------------------------------------------------------------------------- */
1554 /*** public functions ****************************************************************************/
1555 /* --------------------------------------------------------------------------------------------- */
1557 void
1558 update_menu (void)
1560 menu_set_name (left_menu, panels_layout.horizontal_split ? _("&Above") : _("&Left"));
1561 menu_set_name (right_menu, panels_layout.horizontal_split ? _("&Below") : _("&Right"));
1562 menubar_arrange (the_menubar);
1563 menubar_set_visible (the_menubar, menubar_visible);
1566 void
1567 midnight_set_buttonbar (WButtonBar * b)
1569 buttonbar_set_label (b, 1, Q_ ("ButtonBar|Help"), main_map, NULL);
1570 buttonbar_set_label (b, 2, Q_ ("ButtonBar|Menu"), main_map, NULL);
1571 buttonbar_set_label (b, 3, Q_ ("ButtonBar|View"), main_map, NULL);
1572 buttonbar_set_label (b, 4, Q_ ("ButtonBar|Edit"), main_map, NULL);
1573 buttonbar_set_label (b, 5, Q_ ("ButtonBar|Copy"), main_map, NULL);
1574 buttonbar_set_label (b, 6, Q_ ("ButtonBar|RenMov"), main_map, NULL);
1575 buttonbar_set_label (b, 7, Q_ ("ButtonBar|Mkdir"), main_map, NULL);
1576 buttonbar_set_label (b, 8, Q_ ("ButtonBar|Delete"), main_map, NULL);
1577 buttonbar_set_label (b, 9, Q_ ("ButtonBar|PullDn"), main_map, NULL);
1578 buttonbar_set_label (b, 10, Q_ ("ButtonBar|Quit"), main_map, NULL);
1581 /* --------------------------------------------------------------------------------------------- */
1583 * Load new hint and display it.
1584 * IF force is not 0, ignore the timeout.
1587 void
1588 load_hint (gboolean force)
1590 char *hint;
1592 if (the_hint->widget.owner == NULL)
1593 return;
1595 if (!mc_global.message_visible)
1597 label_set_text (the_hint, NULL);
1598 return;
1601 hint = get_random_hint (force);
1603 if (hint != NULL)
1605 if (*hint != '\0')
1606 set_hintbar (hint);
1607 g_free (hint);
1609 else
1611 char text[BUF_SMALL];
1613 g_snprintf (text, sizeof (text), _("GNU Midnight Commander %s\n"), VERSION);
1614 set_hintbar (text);
1618 /* --------------------------------------------------------------------------------------------- */
1620 void
1621 change_panel (void)
1623 input_free_completions (cmdline);
1624 dlg_one_down (midnight_dlg);
1627 /* --------------------------------------------------------------------------------------------- */
1629 /** Save current stat of directories to avoid reloading the panels
1630 * when no modifications have taken place
1632 void
1633 save_cwds_stat (void)
1635 if (panels_options.fast_reload)
1637 mc_stat (current_panel->cwd_vpath, &(current_panel->dir_stat));
1638 if (get_other_type () == view_listing)
1639 mc_stat (other_panel->cwd_vpath, &(other_panel->dir_stat));
1643 /* --------------------------------------------------------------------------------------------- */
1645 gboolean
1646 quiet_quit_cmd (void)
1648 print_last_revert = TRUE;
1649 return quit_cmd_internal (1);
1652 /* --------------------------------------------------------------------------------------------- */
1654 /** Run the main dialog that occupies the whole screen */
1655 gboolean
1656 do_nc (void)
1658 gboolean ret;
1660 dlg_colors_t midnight_colors;
1662 midnight_colors[DLG_COLOR_NORMAL] = mc_skin_color_get ("dialog", "_default_");
1663 midnight_colors[DLG_COLOR_FOCUS] = mc_skin_color_get ("dialog", "focus");
1664 midnight_colors[DLG_COLOR_HOT_NORMAL] = mc_skin_color_get ("dialog", "hotnormal");
1665 midnight_colors[DLG_COLOR_HOT_FOCUS] = mc_skin_color_get ("dialog", "hotfocus");
1666 midnight_colors[DLG_COLOR_TITLE] = mc_skin_color_get ("dialog", "title");
1668 #ifdef USE_INTERNAL_EDIT
1669 edit_stack_init ();
1670 #endif
1672 midnight_dlg = create_dlg (FALSE, 0, 0, LINES, COLS, midnight_colors, midnight_callback,
1673 "[main]", NULL, DLG_WANT_IDLE);
1675 if (mc_global.mc_run_mode == MC_RUN_FULL)
1676 setup_mc ();
1677 else
1678 setup_dummy_mc ();
1680 /* Check if we were invoked as an editor or file viewer */
1681 if (mc_global.mc_run_mode != MC_RUN_FULL)
1682 ret = mc_maybe_editor_or_viewer ();
1683 else
1685 create_panels_and_run_mc ();
1686 ret = TRUE;
1688 /* destroy_dlg destroys even current_panel->cwd_vpath, so we have to save a copy :) */
1689 if (mc_args__last_wd_file != NULL && vfs_current_is_local ())
1690 last_wd_string = vfs_path_to_str (current_panel->cwd_vpath);
1692 /* don't handle VFS timestamps for dirs opened in panels */
1693 mc_event_destroy (MCEVENT_GROUP_CORE, "vfs_timestamp");
1695 clean_dir (&panelized_panel.list, panelized_panel.count);
1698 /* Program end */
1699 mc_global.midnight_shutdown = TRUE;
1700 dialog_switch_shutdown ();
1701 done_mc ();
1702 destroy_dlg (midnight_dlg);
1703 current_panel = NULL;
1705 #ifdef USE_INTERNAL_EDIT
1706 edit_stack_free ();
1707 #endif
1709 if ((quit & SUBSHELL_EXIT) == 0)
1710 clr_scr ();
1712 return ret;
1715 /* --------------------------------------------------------------------------------------------- */