This source file includes following definitions.
- stop_dialogs
- treebox_cmd
- listmode_cmd
- create_panel_menu
- create_file_menu
- create_command_menu
- create_options_menu
- init_menu
- menu_last_selected_cmd
- menu_cmd
- sort_cmd
- midnight_get_shortcut
- midnight_get_title
- toggle_panels_split
- check_panel_timestamp
- check_current_panel_timestamp
- check_other_panel_timestamp
- print_vfs_message
- create_panels
- midnight_put_panel_path
- put_link
- put_current_link
- put_other_link
- put_current_selected
- put_tagged
- put_current_tagged
- put_other_tagged
- setup_mc
- setup_dummy_mc
- done_mc
- create_file_manager
- prepend_cwd_on_local
- mc_maybe_editor_or_viewer
- show_editor_viewer_history
- quit_cmd_internal
- quit_cmd
- update_dirty_panels
- toggle_show_hidden
- midnight_execute_cmd
- is_cmdline_mute
- handle_cmdline_enter
- midnight_callback
- update_menu
- midnight_set_buttonbar
- get_random_hint
- load_hint
- change_panel
- save_cwds_stat
- quiet_quit_cmd
- do_nc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 #include <config.h>
35
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 <sys/types.h>
43 #include <sys/stat.h>
44 #include <sys/wait.h>
45 #include <pwd.h>
46
47 #include "lib/global.h"
48 #include "lib/fileloc.h"
49
50 #include "lib/tty/tty.h"
51 #include "lib/tty/key.h"
52 #include "lib/skin.h"
53 #include "lib/util.h"
54
55 #include "lib/vfs/vfs.h"
56
57 #include "src/args.h"
58 #ifdef ENABLE_SUBSHELL
59 #include "src/subshell/subshell.h"
60 #endif
61 #include "src/execute.h"
62 #include "src/setup.h"
63 #include "src/learn.h"
64 #include "src/keymap.h"
65 #include "lib/fileloc.h"
66 #include "lib/keybind.h"
67 #include "lib/event.h"
68
69 #include "tree.h"
70 #include "boxes.h"
71 #include "layout.h"
72 #include "cmd.h"
73 #include "hotlist.h"
74 #include "panelize.h"
75 #include "command.h"
76 #include "dir.h"
77
78 #ifdef USE_INTERNAL_EDIT
79 #include "src/editor/edit.h"
80 #endif
81
82 #ifdef USE_DIFF_VIEW
83 #include "src/diffviewer/ydiff.h"
84 #endif
85
86 #include "src/consaver/cons.saver.h"
87 #include "src/file_history.h"
88
89 #include "filemanager.h"
90
91
92
93
94
95
96
97
98
99 WPanel *left_panel = NULL;
100 WPanel *right_panel = NULL;
101
102 WPanel *current_panel = NULL;
103
104
105 WMenuBar *the_menubar = NULL;
106
107 WLabel *the_prompt;
108
109 WLabel *the_hint;
110
111 WButtonBar *the_bar;
112
113
114 const char *mc_prompt = NULL;
115
116
117
118 #ifdef HAVE_CHARSET
119
120
121
122
123 #endif
124
125
126
127
128
129 static menu_t *left_menu, *right_menu;
130
131
132
133
134
135 static void
136 stop_dialogs (void)
137 {
138 dlg_stop (filemanager);
139
140 if (top_dlg != NULL)
141 dlg_stop (DIALOG (top_dlg->data));
142 }
143
144
145
146 static void
147 treebox_cmd (void)
148 {
149 char *sel_dir;
150
151 sel_dir = tree_box (selection (current_panel)->fname->str);
152 if (sel_dir != NULL)
153 {
154 vfs_path_t *sel_vdir;
155
156 sel_vdir = vfs_path_from_str (sel_dir);
157 panel_cd (current_panel, sel_vdir, cd_exact);
158 vfs_path_free (sel_vdir, TRUE);
159 g_free (sel_dir);
160 }
161 }
162
163
164
165 #ifdef LISTMODE_EDITOR
166 static void
167 listmode_cmd (void)
168 {
169 char *newmode;
170
171 if (get_current_type () != view_listing)
172 return;
173
174 newmode = listmode_edit (current_panel->user_format);
175 if (!newmode)
176 return;
177
178 g_free (current_panel->user_format);
179 current_panel->list_format = list_user;
180 current_panel->user_format = newmode;
181 set_panel_formats (current_panel);
182
183 do_refresh ();
184 }
185 #endif
186
187
188
189 static GList *
190 create_panel_menu (void)
191 {
192 GList *entries = NULL;
193
194 entries = g_list_prepend (entries, menu_entry_create (_("File listin&g"), CK_PanelListing));
195 entries = g_list_prepend (entries, menu_entry_create (_("&Quick view"), CK_PanelQuickView));
196 entries = g_list_prepend (entries, menu_entry_create (_("&Info"), CK_PanelInfo));
197 entries = g_list_prepend (entries, menu_entry_create (_("&Tree"), CK_PanelTree));
198 entries = g_list_prepend (entries, menu_separator_create ());
199 entries =
200 g_list_prepend (entries,
201 menu_entry_create (_("&Listing format..."), CK_SetupListingFormat));
202 entries = g_list_prepend (entries, menu_entry_create (_("S&ort order..."), CK_Sort));
203 entries = g_list_prepend (entries, menu_entry_create (_("&Filter..."), CK_Filter));
204 #ifdef HAVE_CHARSET
205 entries = g_list_prepend (entries, menu_entry_create (_("&Encoding..."), CK_SelectCodepage));
206 #endif
207 entries = g_list_prepend (entries, menu_separator_create ());
208 #ifdef ENABLE_VFS_FTP
209 entries = g_list_prepend (entries, menu_entry_create (_("FT&P link..."), CK_ConnectFtp));
210 #endif
211 #ifdef ENABLE_VFS_FISH
212 entries = g_list_prepend (entries, menu_entry_create (_("S&hell link..."), CK_ConnectFish));
213 #endif
214 #ifdef ENABLE_VFS_SFTP
215 entries = g_list_prepend (entries, menu_entry_create (_("&SFTP link..."), CK_ConnectSftp));
216 #endif
217 entries = g_list_prepend (entries, menu_entry_create (_("Paneli&ze"), CK_Panelize));
218 entries = g_list_prepend (entries, menu_separator_create ());
219 entries = g_list_prepend (entries, menu_entry_create (_("&Rescan"), CK_Reread));
220
221 return g_list_reverse (entries);
222 }
223
224
225
226 static GList *
227 create_file_menu (void)
228 {
229 GList *entries = NULL;
230
231 entries = g_list_prepend (entries, menu_entry_create (_("&View"), CK_View));
232 entries = g_list_prepend (entries, menu_entry_create (_("Vie&w file..."), CK_ViewFile));
233 entries = g_list_prepend (entries, menu_entry_create (_("&Filtered view"), CK_ViewFiltered));
234 entries = g_list_prepend (entries, menu_entry_create (_("&Edit"), CK_Edit));
235 entries = g_list_prepend (entries, menu_entry_create (_("&Copy"), CK_Copy));
236 entries = g_list_prepend (entries, menu_entry_create (_("C&hmod"), CK_ChangeMode));
237 entries = g_list_prepend (entries, menu_entry_create (_("&Link"), CK_Link));
238 entries = g_list_prepend (entries, menu_entry_create (_("&Symlink"), CK_LinkSymbolic));
239 entries =
240 g_list_prepend (entries,
241 menu_entry_create (_("Relative symlin&k"), CK_LinkSymbolicRelative));
242 entries = g_list_prepend (entries, menu_entry_create (_("Edit s&ymlink"), CK_LinkSymbolicEdit));
243 entries = g_list_prepend (entries, menu_entry_create (_("Ch&own"), CK_ChangeOwn));
244 entries =
245 g_list_prepend (entries, menu_entry_create (_("&Advanced chown"), CK_ChangeOwnAdvanced));
246 #ifdef ENABLE_EXT2FS_ATTR
247 entries = g_list_prepend (entries, menu_entry_create (_("Cha&ttr"), CK_ChangeAttributes));
248 #endif
249 entries = g_list_prepend (entries, menu_entry_create (_("&Rename/Move"), CK_Move));
250 entries = g_list_prepend (entries, menu_entry_create (_("&Mkdir"), CK_MakeDir));
251 entries = g_list_prepend (entries, menu_entry_create (_("&Delete"), CK_Delete));
252 entries = g_list_prepend (entries, menu_entry_create (_("&Quick cd"), CK_CdQuick));
253 entries = g_list_prepend (entries, menu_separator_create ());
254 entries = g_list_prepend (entries, menu_entry_create (_("Select &group"), CK_Select));
255 entries = g_list_prepend (entries, menu_entry_create (_("U&nselect group"), CK_Unselect));
256 entries = g_list_prepend (entries, menu_entry_create (_("&Invert selection"), CK_SelectInvert));
257 entries = g_list_prepend (entries, menu_separator_create ());
258 entries = g_list_prepend (entries, menu_entry_create (_("E&xit"), CK_Quit));
259
260 return g_list_reverse (entries);
261 }
262
263
264
265 static GList *
266 create_command_menu (void)
267 {
268
269
270
271
272 GList *entries = NULL;
273
274 entries = g_list_prepend (entries, menu_entry_create (_("&User menu"), CK_UserMenu));
275 entries = g_list_prepend (entries, menu_entry_create (_("&Directory tree"), CK_Tree));
276 entries = g_list_prepend (entries, menu_entry_create (_("&Find file"), CK_Find));
277 entries = g_list_prepend (entries, menu_entry_create (_("S&wap panels"), CK_Swap));
278 entries = g_list_prepend (entries, menu_entry_create (_("Switch &panels on/off"), CK_Shell));
279 entries =
280 g_list_prepend (entries, menu_entry_create (_("&Compare directories"), CK_CompareDirs));
281 #ifdef USE_DIFF_VIEW
282 entries = g_list_prepend (entries, menu_entry_create (_("C&ompare files"), CK_CompareFiles));
283 #endif
284 entries =
285 g_list_prepend (entries, menu_entry_create (_("E&xternal panelize"), CK_ExternalPanelize));
286 entries = g_list_prepend (entries, menu_entry_create (_("Show directory s&izes"), CK_DirSize));
287 entries = g_list_prepend (entries, menu_separator_create ());
288 entries = g_list_prepend (entries, menu_entry_create (_("Command &history"), CK_History));
289 entries =
290 g_list_prepend (entries,
291 menu_entry_create (_("Viewed/edited files hi&story"),
292 CK_EditorViewerHistory));
293 entries = g_list_prepend (entries, menu_entry_create (_("Di&rectory hotlist"), CK_HotList));
294 #ifdef ENABLE_VFS
295 entries = g_list_prepend (entries, menu_entry_create (_("&Active VFS list"), CK_VfsList));
296 #endif
297 #ifdef ENABLE_BACKGROUND
298 entries = g_list_prepend (entries, menu_entry_create (_("&Background jobs"), CK_Jobs));
299 #endif
300 entries = g_list_prepend (entries, menu_entry_create (_("Screen lis&t"), CK_ScreenList));
301 entries = g_list_prepend (entries, menu_separator_create ());
302 #ifdef ENABLE_VFS_UNDELFS
303 entries =
304 g_list_prepend (entries,
305 menu_entry_create (_("&Undelete files (ext2fs only)"), CK_Undelete));
306 #endif
307 #ifdef LISTMODE_EDITOR
308 entries = g_list_prepend (entries, menu_entry_create (_("&Listing format edit"), CK_ListMode));
309 #endif
310 #if defined (ENABLE_VFS_UNDELFS) || defined (LISTMODE_EDITOR)
311 entries = g_list_prepend (entries, menu_separator_create ());
312 #endif
313 entries =
314 g_list_prepend (entries,
315 menu_entry_create (_("Edit &extension file"), CK_EditExtensionsFile));
316 entries = g_list_prepend (entries, menu_entry_create (_("Edit &menu file"), CK_EditUserMenu));
317 entries =
318 g_list_prepend (entries,
319 menu_entry_create (_("Edit hi&ghlighting group file"),
320 CK_EditFileHighlightFile));
321
322 return g_list_reverse (entries);
323 }
324
325
326
327 static GList *
328 create_options_menu (void)
329 {
330 GList *entries = NULL;
331
332 entries = g_list_prepend (entries, menu_entry_create (_("&Configuration..."), CK_Options));
333 entries = g_list_prepend (entries, menu_entry_create (_("&Layout..."), CK_OptionsLayout));
334 entries = g_list_prepend (entries, menu_entry_create (_("&Panel options..."), CK_OptionsPanel));
335 entries =
336 g_list_prepend (entries, menu_entry_create (_("C&onfirmation..."), CK_OptionsConfirm));
337 entries =
338 g_list_prepend (entries, menu_entry_create (_("&Appearance..."), CK_OptionsAppearance));
339 entries =
340 g_list_prepend (entries, menu_entry_create (_("&Display bits..."), CK_OptionsDisplayBits));
341 entries = g_list_prepend (entries, menu_entry_create (_("Learn &keys..."), CK_LearnKeys));
342 #ifdef ENABLE_VFS
343 entries = g_list_prepend (entries, menu_entry_create (_("&Virtual FS..."), CK_OptionsVfs));
344 #endif
345 entries = g_list_prepend (entries, menu_separator_create ());
346 entries = g_list_prepend (entries, menu_entry_create (_("&Save setup"), CK_SaveSetup));
347
348 return g_list_reverse (entries);
349 }
350
351
352
353 static void
354 init_menu (void)
355 {
356 left_menu = create_menu ("", create_panel_menu (), "[Left and Right Menus]");
357 menubar_add_menu (the_menubar, left_menu);
358 menubar_add_menu (the_menubar, create_menu (_("&File"), create_file_menu (), "[File Menu]"));
359 menubar_add_menu (the_menubar,
360 create_menu (_("&Command"), create_command_menu (), "[Command Menu]"));
361 menubar_add_menu (the_menubar,
362 create_menu (_("&Options"), create_options_menu (), "[Options Menu]"));
363 right_menu = create_menu ("", create_panel_menu (), "[Left and Right Menus]");
364 menubar_add_menu (the_menubar, right_menu);
365 update_menu ();
366 }
367
368
369
370 static void
371 menu_last_selected_cmd (void)
372 {
373 menubar_activate (the_menubar, drop_menus, -1);
374 }
375
376
377
378 static void
379 menu_cmd (void)
380 {
381 int selected;
382
383 if ((get_current_index () == 0) == current_panel->active)
384 selected = 0;
385 else
386 selected = g_list_length (the_menubar->menu) - 1;
387
388 menubar_activate (the_menubar, drop_menus, selected);
389 }
390
391
392
393 static void
394 sort_cmd (void)
395 {
396 WPanel *p;
397 const panel_field_t *sort_order;
398
399 if (!SELECTED_IS_PANEL)
400 return;
401
402 p = MENU_PANEL;
403 sort_order = sort_box (&p->sort_info, p->sort_field);
404 panel_set_sort_order (p, sort_order);
405 }
406
407
408
409 static char *
410 midnight_get_shortcut (long command)
411 {
412 const char *ext_map;
413 const char *shortcut = NULL;
414
415 shortcut = keybind_lookup_keymap_shortcut (filemanager_map, command);
416 if (shortcut != NULL)
417 return g_strdup (shortcut);
418
419 shortcut = keybind_lookup_keymap_shortcut (panel_map, command);
420 if (shortcut != NULL)
421 return g_strdup (shortcut);
422
423 ext_map = keybind_lookup_keymap_shortcut (filemanager_map, CK_ExtendedKeyMap);
424 if (ext_map != NULL)
425 shortcut = keybind_lookup_keymap_shortcut (filemanager_x_map, command);
426 if (shortcut != NULL)
427 return g_strdup_printf ("%s %s", ext_map, shortcut);
428
429 return NULL;
430 }
431
432
433
434 static char *
435 midnight_get_title (const WDialog * h, size_t len)
436 {
437 char *path;
438 char *login;
439 char *p;
440
441 (void) h;
442
443 title_path_prepare (&path, &login);
444
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);
450
451 return path;
452 }
453
454
455
456 static void
457 toggle_panels_split (void)
458 {
459 panels_layout.horizontal_split = !panels_layout.horizontal_split;
460 layout_change ();
461 do_refresh ();
462 }
463
464
465
466 #ifdef ENABLE_VFS
467
468 static gboolean
469 check_panel_timestamp (const WPanel * panel, panel_view_mode_t mode, struct vfs_class *vclass,
470 vfsid id)
471 {
472 if (mode == view_listing)
473 {
474 const vfs_path_element_t *path_element;
475
476 path_element = vfs_path_get_by_index (panel->cwd_vpath, -1);
477
478 if (path_element->class != vclass)
479 return FALSE;
480
481 if (vfs_getid (panel->cwd_vpath) != id)
482 return FALSE;
483 }
484 return TRUE;
485 }
486
487
488
489
490 static gboolean
491 check_current_panel_timestamp (const gchar * event_group_name, const gchar * event_name,
492 gpointer init_data, gpointer data)
493 {
494 ev_vfs_stamp_create_t *event_data = (ev_vfs_stamp_create_t *) data;
495
496 (void) event_group_name;
497 (void) event_name;
498 (void) init_data;
499
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;
504 }
505
506
507
508
509 static gboolean
510 check_other_panel_timestamp (const gchar * event_group_name, const gchar * event_name,
511 gpointer init_data, gpointer data)
512 {
513 ev_vfs_stamp_create_t *event_data = (ev_vfs_stamp_create_t *) data;
514
515 (void) event_group_name;
516 (void) event_name;
517 (void) init_data;
518
519 event_data->ret =
520 check_panel_timestamp (other_panel, get_other_type (), event_data->vclass, event_data->id);
521 return !event_data->ret;
522 }
523 #endif
524
525
526
527
528 static gboolean
529 print_vfs_message (const gchar * event_group_name, const gchar * event_name,
530 gpointer init_data, gpointer data)
531 {
532 ev_vfs_print_message_t *event_data = (ev_vfs_print_message_t *) data;
533
534 (void) event_group_name;
535 (void) event_name;
536 (void) init_data;
537
538 if (mc_global.midnight_shutdown)
539 goto ret;
540
541 if (!mc_global.message_visible || the_hint == NULL || WIDGET (the_hint)->owner == NULL)
542 {
543 int col, row;
544
545 if (!nice_rotating_dash || (ok_to_refresh <= 0))
546 goto ret;
547
548
549 tty_getyx (&row, &col);
550
551 tty_gotoyx (0, 0);
552 tty_setcolor (NORMAL_COLOR);
553 tty_print_string (str_fit_to_term (event_data->msg, COLS - 1, J_LEFT));
554
555
556 tty_gotoyx (row, col);
557 mc_refresh ();
558 goto ret;
559 }
560
561 if (mc_global.message_visible)
562 set_hintbar (event_data->msg);
563
564 ret:
565 MC_PTR_FREE (event_data->msg);
566 return TRUE;
567 }
568
569
570
571 static void
572 create_panels (void)
573 {
574 int current_index, other_index;
575 panel_view_mode_t current_mode, other_mode;
576 char *current_dir, *other_dir;
577 vfs_path_t *original_dir;
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595 if (boot_current_is_left)
596 {
597
598 current_index = 0;
599 other_index = 1;
600 current_mode = startup_left_mode;
601 other_mode = startup_right_mode;
602
603 if (mc_run_param0 == NULL && mc_run_param1 == NULL)
604 {
605
606 current_dir = NULL;
607 other_dir = saved_other_dir;
608 }
609 else if (mc_run_param0 != NULL && mc_run_param1 != NULL)
610 {
611
612 current_dir = (char *) mc_run_param0;
613 other_dir = mc_run_param1;
614 }
615 else
616 {
617
618 current_dir = (char *) mc_run_param0;
619 other_dir = saved_other_dir;
620 }
621 }
622 else
623 {
624
625 current_index = 1;
626 other_index = 0;
627 current_mode = startup_right_mode;
628 other_mode = startup_left_mode;
629
630 if (mc_run_param0 == NULL && mc_run_param1 == NULL)
631 {
632
633 current_dir = NULL;
634 other_dir = saved_other_dir;
635 }
636 else if (mc_run_param0 != NULL && mc_run_param1 != NULL)
637 {
638
639 current_dir = (char *) mc_run_param0;
640 other_dir = mc_run_param1;
641 }
642 else
643 {
644
645 current_dir = (char *) mc_run_param0;
646 other_dir = saved_other_dir;
647 }
648 }
649
650
651 original_dir = vfs_path_clone (vfs_get_raw_current_dir ());
652
653
654 if (other_dir != NULL)
655 {
656 vfs_path_t *vpath;
657
658 if (g_path_is_absolute (other_dir))
659 vpath = vfs_path_from_str (other_dir);
660 else
661 vpath = vfs_path_append_new (original_dir, other_dir, (char *) NULL);
662 mc_chdir (vpath);
663 vfs_path_free (vpath, TRUE);
664 }
665 create_panel (other_index, other_mode);
666
667
668 if (current_dir == NULL)
669 mc_chdir (original_dir);
670 else
671 {
672 vfs_path_t *vpath;
673
674 if (g_path_is_absolute (current_dir))
675 vpath = vfs_path_from_str (current_dir);
676 else
677 vpath = vfs_path_append_new (original_dir, current_dir, (char *) NULL);
678 mc_chdir (vpath);
679 vfs_path_free (vpath, TRUE);
680 }
681 create_panel (current_index, current_mode);
682
683 if (startup_left_mode == view_listing)
684 current_panel = left_panel;
685 else if (right_panel != NULL)
686 current_panel = right_panel;
687 else
688 current_panel = left_panel;
689
690 vfs_path_free (original_dir, TRUE);
691
692 #ifdef ENABLE_VFS
693 mc_event_add (MCEVENT_GROUP_CORE, "vfs_timestamp", check_other_panel_timestamp, NULL, NULL);
694 mc_event_add (MCEVENT_GROUP_CORE, "vfs_timestamp", check_current_panel_timestamp, NULL, NULL);
695 #endif
696
697 mc_event_add (MCEVENT_GROUP_CORE, "vfs_print_message", print_vfs_message, NULL, NULL);
698 }
699
700
701
702 static void
703 midnight_put_panel_path (WPanel * panel)
704 {
705 vfs_path_t *cwd_vpath;
706 const char *cwd_vpath_str;
707
708 if (!command_prompt)
709 return;
710
711 #ifdef HAVE_CHARSET
712 cwd_vpath = remove_encoding_from_path (panel->cwd_vpath);
713 #else
714 cwd_vpath = vfs_path_clone (panel->cwd_vpath);
715 #endif
716
717 cwd_vpath_str = vfs_path_as_str (cwd_vpath);
718
719 command_insert (cmdline, cwd_vpath_str, FALSE);
720
721 if (!IS_PATH_SEP (cwd_vpath_str[strlen (cwd_vpath_str) - 1]))
722 command_insert (cmdline, PATH_SEP_STR, FALSE);
723
724 vfs_path_free (cwd_vpath, TRUE);
725 }
726
727
728
729 static void
730 put_link (WPanel * panel)
731 {
732 if (!command_prompt)
733 return;
734 if (S_ISLNK (selection (panel)->st.st_mode))
735 {
736 char buffer[MC_MAXPATHLEN];
737 vfs_path_t *vpath;
738 int i;
739
740 vpath =
741 vfs_path_append_new (panel->cwd_vpath, selection (panel)->fname->str, (char *) NULL);
742 i = mc_readlink (vpath, buffer, sizeof (buffer) - 1);
743 vfs_path_free (vpath, TRUE);
744
745 if (i > 0)
746 {
747 buffer[i] = '\0';
748 command_insert (cmdline, buffer, TRUE);
749 }
750 }
751 }
752
753
754
755 static void
756 put_current_link (void)
757 {
758 put_link (current_panel);
759 }
760
761
762
763 static void
764 put_other_link (void)
765 {
766 if (get_other_type () == view_listing)
767 put_link (other_panel);
768 }
769
770
771
772
773 static void
774 put_current_selected (void)
775 {
776 const char *tmp;
777
778 if (!command_prompt)
779 return;
780
781 if (get_current_type () == view_tree)
782 {
783 WTree *tree;
784 const vfs_path_t *selected_name;
785
786 tree = (WTree *) get_panel_widget (get_current_index ());
787 selected_name = tree_selected_name (tree);
788 tmp = vfs_path_as_str (selected_name);
789 }
790 else
791 tmp = selection (current_panel)->fname->str;
792
793 command_insert (cmdline, tmp, TRUE);
794 }
795
796
797
798 static void
799 put_tagged (WPanel * panel)
800 {
801 if (!command_prompt)
802 return;
803 input_disable_update (cmdline);
804 if (panel->marked)
805 {
806 int i;
807
808 for (i = 0; i < panel->dir.len; i++)
809 {
810 if (panel->dir.list[i].f.marked)
811 command_insert (cmdline, panel->dir.list[i].fname->str, TRUE);
812 }
813 }
814 else
815 {
816 command_insert (cmdline, panel->dir.list[panel->selected].fname->str, TRUE);
817 }
818 input_enable_update (cmdline);
819 }
820
821
822
823 static void
824 put_current_tagged (void)
825 {
826 put_tagged (current_panel);
827 }
828
829
830
831 static void
832 put_other_tagged (void)
833 {
834 if (get_other_type () == view_listing)
835 put_tagged (other_panel);
836 }
837
838
839
840 static void
841 setup_mc (void)
842 {
843 #ifdef HAVE_SLANG
844 #ifdef HAVE_CHARSET
845 tty_display_8bit (TRUE);
846 #else
847 tty_display_8bit (mc_global.full_eight_bits);
848 #endif
849
850 #else
851
852 #ifdef HAVE_CHARSET
853 tty_display_8bit (TRUE);
854 #else
855 tty_display_8bit (mc_global.eight_bit_clean);
856 #endif
857 #endif
858
859 if ((tty_baudrate () < 9600) || mc_global.tty.slow_terminal)
860 verbose = FALSE;
861 }
862
863
864
865 static void
866 setup_dummy_mc (void)
867 {
868 vfs_path_t *vpath;
869 char *d;
870 int ret;
871
872 d = _vfs_get_cwd ();
873 setup_mc ();
874 vpath = vfs_path_from_str (d);
875 ret = mc_chdir (vpath);
876 (void) ret;
877 vfs_path_free (vpath, TRUE);
878 g_free (d);
879 }
880
881
882
883 static void
884 done_mc (void)
885 {
886
887
888
889
890
891
892 save_setup (auto_save_setup, panels_options.auto_save_setup);
893
894 vfs_stamp_path (vfs_get_raw_current_dir ());
895 }
896
897
898
899 static void
900 create_file_manager (void)
901 {
902 Widget *w = WIDGET (filemanager);
903 WGroup *g = GROUP (filemanager);
904
905 w->keymap = filemanager_map;
906 w->ext_keymap = filemanager_x_map;
907
908 filemanager->get_shortcut = midnight_get_shortcut;
909 filemanager->get_title = midnight_get_title;
910
911 widget_want_tab (w, TRUE);
912
913 the_menubar = menubar_new (NULL);
914 group_add_widget (g, the_menubar);
915 init_menu ();
916
917 create_panels ();
918 group_add_widget (g, get_panel_widget (0));
919 group_add_widget (g, get_panel_widget (1));
920
921 the_hint = label_new (0, 0, 0);
922 the_hint->transparent = TRUE;
923 the_hint->auto_adjust_cols = 0;
924 WIDGET (the_hint)->rect.cols = COLS;
925 group_add_widget (g, the_hint);
926
927 cmdline = command_new (0, 0, 0);
928 group_add_widget (g, cmdline);
929
930 the_prompt = label_new (0, 0, mc_prompt);
931 the_prompt->transparent = TRUE;
932 group_add_widget (g, the_prompt);
933
934 the_bar = buttonbar_new ();
935 group_add_widget (g, the_bar);
936 midnight_set_buttonbar (the_bar);
937
938 #ifdef ENABLE_SUBSHELL
939
940
941 if (mc_global.tty.use_subshell)
942 add_select_channel (mc_global.tty.subshell_pty, load_prompt, NULL);
943 #endif
944 }
945
946
947
948
949 static vfs_path_t *
950 prepend_cwd_on_local (const char *filename)
951 {
952 vfs_path_t *vpath;
953
954 vpath = vfs_path_from_str (filename);
955 if (!vfs_file_is_local (vpath) || g_path_is_absolute (filename))
956 return vpath;
957
958 vfs_path_free (vpath, TRUE);
959
960 return vfs_path_append_new (vfs_get_raw_current_dir (), filename, (char *) NULL);
961 }
962
963
964
965
966
967
968 static gboolean
969 mc_maybe_editor_or_viewer (void)
970 {
971 gboolean ret;
972
973 switch (mc_global.mc_run_mode)
974 {
975 #ifdef USE_INTERNAL_EDIT
976 case MC_RUN_EDITOR:
977 ret = edit_files ((GList *) mc_run_param0);
978 break;
979 #endif
980 case MC_RUN_VIEWER:
981 {
982 vfs_path_t *vpath = NULL;
983
984 if (mc_run_param0 != NULL && *(char *) mc_run_param0 != '\0')
985 vpath = prepend_cwd_on_local ((char *) mc_run_param0);
986
987 ret = view_file (vpath, FALSE, TRUE);
988 vfs_path_free (vpath, TRUE);
989 break;
990 }
991 #ifdef USE_DIFF_VIEW
992 case MC_RUN_DIFFVIEWER:
993 ret = dview_diff_cmd (mc_run_param0, mc_run_param1);
994 break;
995 #endif
996 default:
997 ret = FALSE;
998 }
999
1000 return ret;
1001 }
1002
1003
1004
1005 static void
1006 show_editor_viewer_history (void)
1007 {
1008 char *s;
1009 int act;
1010
1011 s = show_file_history (WIDGET (filemanager), &act);
1012 if (s != NULL)
1013 {
1014 vfs_path_t *s_vpath;
1015
1016 switch (act)
1017 {
1018 case CK_Edit:
1019 s_vpath = vfs_path_from_str (s);
1020 edit_file_at_line (s_vpath, use_internal_edit, 0);
1021 break;
1022
1023 case CK_View:
1024 s_vpath = vfs_path_from_str (s);
1025 view_file (s_vpath, use_internal_view, FALSE);
1026 break;
1027
1028 default:
1029 {
1030 char *d;
1031
1032 d = g_path_get_dirname (s);
1033 s_vpath = vfs_path_from_str (d);
1034 panel_cd (current_panel, s_vpath, cd_exact);
1035 try_to_select (current_panel, s);
1036 g_free (d);
1037 }
1038 }
1039
1040 g_free (s);
1041 vfs_path_free (s_vpath, TRUE);
1042 }
1043 }
1044
1045
1046
1047 static gboolean
1048 quit_cmd_internal (int quiet)
1049 {
1050 int q = quit;
1051 size_t n;
1052
1053 n = dialog_switch_num () - 1;
1054 if (n != 0)
1055 {
1056 char msg[BUF_MEDIUM];
1057
1058 g_snprintf (msg, sizeof (msg),
1059 ngettext ("You have %zu opened screen. Quit anyway?",
1060 "You have %zu opened screens. Quit anyway?", n), n);
1061
1062 if (query_dialog (_("The Midnight Commander"), msg, D_NORMAL, 2, _("&Yes"), _("&No")) != 0)
1063 return FALSE;
1064 q = 1;
1065 }
1066 else if (quiet || !confirm_exit)
1067 q = 1;
1068 else if (query_dialog (_("The Midnight Commander"),
1069 _("Do you really want to quit the Midnight Commander?"),
1070 D_NORMAL, 2, _("&Yes"), _("&No")) == 0)
1071 q = 1;
1072
1073 if (q != 0)
1074 {
1075 #ifdef ENABLE_SUBSHELL
1076 if (!mc_global.tty.use_subshell)
1077 stop_dialogs ();
1078 else if ((q = exit_subshell ()? 1 : 0) != 0)
1079 #endif
1080 stop_dialogs ();
1081 }
1082
1083 if (q != 0)
1084 quit |= 1;
1085 return (quit != 0);
1086 }
1087
1088
1089
1090 static gboolean
1091 quit_cmd (void)
1092 {
1093 return quit_cmd_internal (0);
1094 }
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105 static void
1106 update_dirty_panels (void)
1107 {
1108 if (get_current_type () == view_listing && current_panel->dirty)
1109 widget_draw (WIDGET (current_panel));
1110
1111 if (get_other_type () == view_listing && other_panel->dirty)
1112 widget_draw (WIDGET (other_panel));
1113 }
1114
1115
1116
1117 static void
1118 toggle_show_hidden (void)
1119 {
1120 panels_options.show_dot_files = !panels_options.show_dot_files;
1121 update_panels (UP_RELOAD, UP_KEEPSEL);
1122
1123 update_dirty_panels ();
1124 }
1125
1126
1127
1128 static cb_ret_t
1129 midnight_execute_cmd (Widget * sender, long command)
1130 {
1131 cb_ret_t res = MSG_HANDLED;
1132
1133 (void) sender;
1134
1135
1136 send_message (current_panel, NULL, MSG_ACTION, CK_SearchStop, NULL);
1137
1138 switch (command)
1139 {
1140 case CK_ChangePanel:
1141 (void) change_panel ();
1142 break;
1143 case CK_HotListAdd:
1144 add2hotlist_cmd (current_panel);
1145 break;
1146 case CK_SetupListingFormat:
1147 setup_listing_format_cmd ();
1148 break;
1149 case CK_ChangeMode:
1150 chmod_cmd (current_panel);
1151 break;
1152 case CK_ChangeOwn:
1153 chown_cmd (current_panel);
1154 break;
1155 case CK_ChangeOwnAdvanced:
1156 advanced_chown_cmd (current_panel);
1157 break;
1158 #ifdef ENABLE_EXT2FS_ATTR
1159 case CK_ChangeAttributes:
1160 chattr_cmd (current_panel);
1161 break;
1162 #endif
1163 case CK_CompareDirs:
1164 compare_dirs_cmd ();
1165 break;
1166 case CK_Options:
1167 configure_box ();
1168 break;
1169 #ifdef ENABLE_VFS
1170 case CK_OptionsVfs:
1171 configure_vfs_box ();
1172 break;
1173 #endif
1174 case CK_OptionsConfirm:
1175 confirm_box ();
1176 break;
1177 case CK_Copy:
1178 copy_cmd (current_panel);
1179 break;
1180 case CK_PutCurrentPath:
1181 midnight_put_panel_path (current_panel);
1182 break;
1183 case CK_PutCurrentSelected:
1184 put_current_selected ();
1185 break;
1186 case CK_PutCurrentFullSelected:
1187 midnight_put_panel_path (current_panel);
1188 put_current_selected ();
1189 break;
1190 case CK_PutCurrentLink:
1191 put_current_link ();
1192 break;
1193 case CK_PutCurrentTagged:
1194 put_current_tagged ();
1195 break;
1196 case CK_PutOtherPath:
1197 if (get_other_type () == view_listing)
1198 midnight_put_panel_path (other_panel);
1199 break;
1200 case CK_PutOtherLink:
1201 put_other_link ();
1202 break;
1203 case CK_PutOtherTagged:
1204 put_other_tagged ();
1205 break;
1206 case CK_Delete:
1207 delete_cmd (current_panel);
1208 break;
1209 case CK_ScreenList:
1210 dialog_switch_list ();
1211 break;
1212 #ifdef USE_DIFF_VIEW
1213 case CK_CompareFiles:
1214 diff_view_cmd ();
1215 break;
1216 #endif
1217 case CK_OptionsDisplayBits:
1218 display_bits_box ();
1219 break;
1220 case CK_Edit:
1221 edit_cmd (current_panel);
1222 break;
1223 #ifdef USE_INTERNAL_EDIT
1224 case CK_EditForceInternal:
1225 edit_cmd_force_internal (current_panel);
1226 break;
1227 #endif
1228 case CK_EditExtensionsFile:
1229 ext_cmd ();
1230 break;
1231 case CK_EditFileHighlightFile:
1232 edit_fhl_cmd ();
1233 break;
1234 case CK_EditUserMenu:
1235 edit_mc_menu_cmd ();
1236 break;
1237 case CK_LinkSymbolicEdit:
1238 edit_symlink_cmd ();
1239 break;
1240 case CK_ExternalPanelize:
1241 external_panelize ();
1242 break;
1243 case CK_ViewFiltered:
1244 view_filtered_cmd (current_panel);
1245 break;
1246 case CK_Find:
1247 find_cmd (current_panel);
1248 break;
1249 #ifdef ENABLE_VFS_FISH
1250 case CK_ConnectFish:
1251 fishlink_cmd ();
1252 break;
1253 #endif
1254 #ifdef ENABLE_VFS_FTP
1255 case CK_ConnectFtp:
1256 ftplink_cmd ();
1257 break;
1258 #endif
1259 #ifdef ENABLE_VFS_SFTP
1260 case CK_ConnectSftp:
1261 sftplink_cmd ();
1262 break;
1263 #endif
1264 case CK_Panelize:
1265 cd_panelize_cmd ();
1266 break;
1267 case CK_Help:
1268 help_cmd ();
1269 break;
1270 case CK_History:
1271
1272 send_message (cmdline, NULL, MSG_ACTION, CK_History, NULL);
1273 break;
1274 case CK_PanelInfo:
1275 if (sender == WIDGET (the_menubar))
1276 info_cmd ();
1277 else
1278 info_cmd_no_menu ();
1279 break;
1280 #ifdef ENABLE_BACKGROUND
1281 case CK_Jobs:
1282 jobs_box ();
1283 break;
1284 #endif
1285 case CK_OptionsLayout:
1286 layout_box ();
1287 break;
1288 case CK_OptionsAppearance:
1289 appearance_box ();
1290 break;
1291 case CK_LearnKeys:
1292 learn_keys ();
1293 break;
1294 case CK_Link:
1295 link_cmd (LINK_HARDLINK);
1296 break;
1297 case CK_PanelListing:
1298 listing_cmd ();
1299 break;
1300 #ifdef LISTMODE_EDITOR
1301 case CK_ListMode:
1302 listmode_cmd ();
1303 break;
1304 #endif
1305 case CK_Menu:
1306 menu_cmd ();
1307 break;
1308 case CK_MenuLastSelected:
1309 menu_last_selected_cmd ();
1310 break;
1311 case CK_MakeDir:
1312 mkdir_cmd (current_panel);
1313 break;
1314 case CK_OptionsPanel:
1315 panel_options_box ();
1316 break;
1317 #ifdef HAVE_CHARSET
1318 case CK_SelectCodepage:
1319 encoding_cmd ();
1320 break;
1321 #endif
1322 case CK_CdQuick:
1323 quick_cd_cmd (current_panel);
1324 break;
1325 case CK_HotList:
1326 hotlist_cmd (current_panel);
1327 break;
1328 case CK_PanelQuickView:
1329 if (sender == WIDGET (the_menubar))
1330 quick_view_cmd ();
1331 else
1332 quick_cmd_no_menu ();
1333 break;
1334 case CK_QuitQuiet:
1335 quiet_quit_cmd ();
1336 break;
1337 case CK_Quit:
1338 quit_cmd ();
1339 break;
1340 case CK_LinkSymbolicRelative:
1341 link_cmd (LINK_SYMLINK_RELATIVE);
1342 break;
1343 case CK_Move:
1344 rename_cmd (current_panel);
1345 break;
1346 case CK_Reread:
1347 reread_cmd ();
1348 break;
1349 #ifdef ENABLE_VFS
1350 case CK_VfsList:
1351 vfs_list (current_panel);
1352 break;
1353 #endif
1354 case CK_SaveSetup:
1355 save_setup_cmd ();
1356 break;
1357 case CK_Select:
1358 case CK_Unselect:
1359 case CK_SelectInvert:
1360 case CK_Filter:
1361 res = send_message (current_panel, filemanager, MSG_ACTION, command, NULL);
1362 break;
1363 case CK_Shell:
1364 toggle_subshell ();
1365 break;
1366 case CK_DirSize:
1367 smart_dirsize_cmd (current_panel);
1368 break;
1369 case CK_Sort:
1370 sort_cmd ();
1371 break;
1372 case CK_ExtendedKeyMap:
1373 WIDGET (filemanager)->ext_mode = TRUE;
1374 break;
1375 case CK_Suspend:
1376 mc_event_raise (MCEVENT_GROUP_CORE, "suspend", NULL);
1377 break;
1378 case CK_Swap:
1379 swap_cmd ();
1380 break;
1381 case CK_LinkSymbolic:
1382 link_cmd (LINK_SYMLINK_ABSOLUTE);
1383 break;
1384 case CK_ShowHidden:
1385 toggle_show_hidden ();
1386 break;
1387 case CK_SplitVertHoriz:
1388 toggle_panels_split ();
1389 break;
1390 case CK_SplitEqual:
1391 panels_split_equal ();
1392 break;
1393 case CK_SplitMore:
1394 panels_split_more ();
1395 break;
1396 case CK_SplitLess:
1397 panels_split_less ();
1398 break;
1399 case CK_PanelTree:
1400 panel_tree_cmd ();
1401 break;
1402 case CK_Tree:
1403 treebox_cmd ();
1404 break;
1405 #ifdef ENABLE_VFS_UNDELFS
1406 case CK_Undelete:
1407 undelete_cmd ();
1408 break;
1409 #endif
1410 case CK_UserMenu:
1411 user_file_menu_cmd ();
1412 break;
1413 case CK_View:
1414 view_cmd (current_panel);
1415 break;
1416 case CK_ViewFile:
1417 view_file_cmd (current_panel);
1418 break;
1419 case CK_EditorViewerHistory:
1420 show_editor_viewer_history ();
1421 break;
1422 case CK_Cancel:
1423
1424 break;
1425 default:
1426 res = MSG_NOT_HANDLED;
1427 }
1428
1429 return res;
1430 }
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441 static gboolean
1442 is_cmdline_mute (void)
1443 {
1444
1445
1446
1447
1448
1449 return (!current_panel->active
1450 && (get_other_type () == view_quick || get_other_type () == view_tree));
1451 }
1452
1453
1454
1455
1456
1457
1458
1459
1460 static gboolean
1461 handle_cmdline_enter (void)
1462 {
1463 size_t i;
1464
1465 for (i = 0; i < cmdline->buffer->len && whitespace (cmdline->buffer->str[i]); i++)
1466 ;
1467
1468 if (i != cmdline->buffer->len)
1469 {
1470 send_message (cmdline, NULL, MSG_KEY, '\n', NULL);
1471 return TRUE;
1472 }
1473
1474 input_insert (cmdline, "", FALSE);
1475 cmdline->point = 0;
1476
1477 return FALSE;
1478 }
1479
1480
1481
1482 static cb_ret_t
1483 midnight_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
1484 {
1485 long command;
1486
1487 switch (msg)
1488 {
1489 case MSG_INIT:
1490 panel_init ();
1491 setup_panels ();
1492 return MSG_HANDLED;
1493
1494 case MSG_DRAW:
1495 load_hint (TRUE);
1496 group_default_callback (w, NULL, MSG_DRAW, 0, NULL);
1497
1498 if (mc_global.tty.console_flag != '\0' && output_lines != 0)
1499 {
1500 unsigned char end_line;
1501
1502 end_line = LINES - (mc_global.keybar_visible ? 1 : 0) - 1;
1503 show_console_contents (output_start_y, end_line - output_lines, end_line);
1504 }
1505 return MSG_HANDLED;
1506
1507 case MSG_RESIZE:
1508 widget_adjust_position (w->pos_flags, &w->rect);
1509 setup_panels ();
1510 menubar_arrange (the_menubar);
1511 return MSG_HANDLED;
1512
1513 case MSG_IDLE:
1514
1515 widget_idle (w, FALSE);
1516
1517 if (boot_current_is_left)
1518 widget_select (get_panel_widget (0));
1519 else
1520 widget_select (get_panel_widget (1));
1521
1522 if (auto_menu)
1523 midnight_execute_cmd (NULL, CK_UserMenu);
1524 return MSG_HANDLED;
1525
1526 case MSG_KEY:
1527 if (w->ext_mode)
1528 {
1529 command = widget_lookup_key (w, parm);
1530 if (command != CK_IgnoreKey)
1531 return midnight_execute_cmd (NULL, command);
1532 }
1533
1534
1535 if (widget_get_state (WIDGET (the_menubar), WST_FOCUSED))
1536 return MSG_NOT_HANDLED;
1537
1538 if (parm == '\n' && !is_cmdline_mute ())
1539 {
1540 if (handle_cmdline_enter ())
1541 return MSG_HANDLED;
1542
1543 }
1544
1545 if ((!mc_global.tty.alternate_plus_minus
1546 || !(mc_global.tty.console_flag != '\0' || mc_global.tty.xterm_flag)) && !quote
1547 && !current_panel->quick_search.active)
1548 {
1549 if (!only_leading_plus_minus)
1550 {
1551
1552 if (parm == '+')
1553 return send_message (current_panel, filemanager, MSG_ACTION, CK_Select, NULL);
1554
1555 if (parm == '\\' || parm == '-')
1556 return send_message (current_panel, filemanager, MSG_ACTION, CK_Unselect, NULL);
1557
1558 if (parm == '*')
1559 return send_message (current_panel, filemanager, MSG_ACTION, CK_SelectInvert,
1560 NULL);
1561 }
1562 else if (!command_prompt || input_is_empty (cmdline))
1563 {
1564
1565
1566
1567 if (parm == '+')
1568 return send_message (current_panel, filemanager, MSG_ACTION, CK_Select, NULL);
1569
1570 if (parm == '\\' || parm == '-')
1571 return send_message (current_panel, filemanager, MSG_ACTION, CK_Unselect, NULL);
1572
1573 if (parm == '*')
1574 return send_message (current_panel, filemanager, MSG_ACTION, CK_SelectInvert,
1575 NULL);
1576 }
1577 }
1578 return MSG_NOT_HANDLED;
1579
1580 case MSG_HOTKEY_HANDLED:
1581 if ((get_current_type () == view_listing) && current_panel->quick_search.active)
1582 {
1583 current_panel->dirty = TRUE;
1584 send_message (current_panel, NULL, MSG_ACTION, CK_SearchStop, NULL);
1585 }
1586 return MSG_HANDLED;
1587
1588 case MSG_UNHANDLED_KEY:
1589 {
1590 cb_ret_t v = MSG_NOT_HANDLED;
1591
1592 command = widget_lookup_key (w, parm);
1593 if (command != CK_IgnoreKey)
1594 v = midnight_execute_cmd (NULL, command);
1595
1596 if (v == MSG_NOT_HANDLED && command_prompt && !is_cmdline_mute ())
1597 v = send_message (cmdline, NULL, MSG_KEY, parm, NULL);
1598
1599 return v;
1600 }
1601
1602 case MSG_POST_KEY:
1603 if (!widget_get_state (WIDGET (the_menubar), WST_FOCUSED))
1604 update_dirty_panels ();
1605 return MSG_HANDLED;
1606
1607 case MSG_ACTION:
1608
1609 return midnight_execute_cmd (sender, parm);
1610
1611 case MSG_DESTROY:
1612 panel_deinit ();
1613 return MSG_HANDLED;
1614
1615 default:
1616 return dlg_default_callback (w, sender, msg, parm, data);
1617 }
1618 }
1619
1620
1621
1622
1623
1624 void
1625 update_menu (void)
1626 {
1627 menu_set_name (left_menu, panels_layout.horizontal_split ? _("&Above") : _("&Left"));
1628 menu_set_name (right_menu, panels_layout.horizontal_split ? _("&Below") : _("&Right"));
1629 menubar_arrange (the_menubar);
1630 widget_set_visibility (WIDGET (the_menubar), menubar_visible);
1631 }
1632
1633
1634
1635 void
1636 midnight_set_buttonbar (WButtonBar * b)
1637 {
1638 Widget *w = WIDGET (filemanager);
1639
1640 buttonbar_set_label (b, 1, Q_ ("ButtonBar|Help"), w->keymap, NULL);
1641 buttonbar_set_label (b, 2, Q_ ("ButtonBar|Menu"), w->keymap, NULL);
1642 buttonbar_set_label (b, 3, Q_ ("ButtonBar|View"), w->keymap, NULL);
1643 buttonbar_set_label (b, 4, Q_ ("ButtonBar|Edit"), w->keymap, NULL);
1644 buttonbar_set_label (b, 5, Q_ ("ButtonBar|Copy"), w->keymap, NULL);
1645 buttonbar_set_label (b, 6, Q_ ("ButtonBar|RenMov"), w->keymap, NULL);
1646 buttonbar_set_label (b, 7, Q_ ("ButtonBar|Mkdir"), w->keymap, NULL);
1647 buttonbar_set_label (b, 8, Q_ ("ButtonBar|Delete"), w->keymap, NULL);
1648 buttonbar_set_label (b, 9, Q_ ("ButtonBar|PullDn"), w->keymap, NULL);
1649 buttonbar_set_label (b, 10, Q_ ("ButtonBar|Quit"), w->keymap, NULL);
1650 }
1651
1652
1653
1654
1655
1656
1657 char *
1658 get_random_hint (gboolean force)
1659 {
1660 static const gint64 update_period = 60 * G_USEC_PER_SEC;
1661 static gint64 tv = 0;
1662
1663 char *data, *result, *eop;
1664 size_t len, start;
1665 GIConv conv;
1666
1667
1668 if (!force && !mc_time_elapsed (&tv, update_period))
1669 return g_strdup ("");
1670
1671 data = load_mc_home_file (mc_global.share_data_dir, MC_HINT, NULL, &len);
1672 if (data == NULL)
1673 return NULL;
1674
1675
1676 srand ((unsigned int) (tv / G_USEC_PER_SEC));
1677 start = ((size_t) rand ()) % (len - 1);
1678
1679
1680 for (; start != 0; start--)
1681 if (data[start] == '\n' && data[start + 1] == '\n')
1682 {
1683 start += 2;
1684 break;
1685 }
1686
1687
1688 for (eop = data + start; *eop != '\0'; eop++)
1689 {
1690 if (*eop == '\n' && *(eop + 1) == '\n')
1691 {
1692 *eop = '\0';
1693 break;
1694 }
1695 if (*eop == '\n')
1696 *eop = ' ';
1697 }
1698
1699
1700
1701 conv = str_crt_conv_from ("UTF-8");
1702 if (conv == INVALID_CONV)
1703 result = g_strndup (data + start, len - start);
1704 else
1705 {
1706 GString *buffer;
1707 gboolean nok;
1708
1709 buffer = g_string_sized_new (len - start);
1710 nok = (str_convert (conv, data + start, buffer) == ESTR_FAILURE);
1711 result = g_string_free (buffer, nok);
1712 str_close_conv (conv);
1713 }
1714
1715 g_free (data);
1716 return result;
1717 }
1718
1719
1720
1721
1722
1723
1724
1725
1726 void
1727 load_hint (gboolean force)
1728 {
1729 char *hint;
1730
1731 if (WIDGET (the_hint)->owner == NULL)
1732 return;
1733
1734 if (!mc_global.message_visible)
1735 {
1736 label_set_text (the_hint, NULL);
1737 return;
1738 }
1739
1740 hint = get_random_hint (force);
1741
1742 if (hint != NULL)
1743 {
1744 if (*hint != '\0')
1745 set_hintbar (hint);
1746 g_free (hint);
1747 }
1748 else
1749 {
1750 char text[BUF_SMALL];
1751
1752 g_snprintf (text, sizeof (text), _("GNU Midnight Commander %s\n"), mc_global.mc_version);
1753 set_hintbar (text);
1754 }
1755 }
1756
1757
1758
1759
1760
1761
1762
1763
1764 WPanel *
1765 change_panel (void)
1766 {
1767 input_complete_free (cmdline);
1768 group_select_next_widget (GROUP (filemanager));
1769 return current_panel;
1770 }
1771
1772
1773
1774
1775
1776
1777 void
1778 save_cwds_stat (void)
1779 {
1780 if (panels_options.fast_reload)
1781 {
1782 mc_stat (current_panel->cwd_vpath, &(current_panel->dir_stat));
1783 if (get_other_type () == view_listing)
1784 mc_stat (other_panel->cwd_vpath, &(other_panel->dir_stat));
1785 }
1786 }
1787
1788
1789
1790 gboolean
1791 quiet_quit_cmd (void)
1792 {
1793 print_last_revert = TRUE;
1794 return quit_cmd_internal (1);
1795 }
1796
1797
1798
1799
1800 gboolean
1801 do_nc (void)
1802 {
1803 gboolean ret;
1804
1805 #ifdef USE_INTERNAL_EDIT
1806 edit_stack_init ();
1807 #endif
1808
1809 filemanager = dlg_create (FALSE, 0, 0, 1, 1, WPOS_FULLSCREEN, FALSE, dialog_colors,
1810 midnight_callback, NULL, "[main]", NULL);
1811
1812
1813 if (mc_global.mc_run_mode != MC_RUN_FULL)
1814 {
1815 setup_dummy_mc ();
1816 ret = mc_maybe_editor_or_viewer ();
1817 }
1818 else
1819 {
1820
1821 widget_idle (WIDGET (filemanager), TRUE);
1822
1823 setup_mc ();
1824 mc_filehighlight = mc_fhl_new (TRUE);
1825
1826 create_file_manager ();
1827 (void) dlg_run (filemanager);
1828
1829 mc_fhl_free (&mc_filehighlight);
1830
1831 ret = TRUE;
1832
1833
1834 if (mc_args__last_wd_file != NULL && vfs_current_is_local ())
1835 last_wd_string = g_strdup (vfs_path_as_str (current_panel->cwd_vpath));
1836
1837
1838 mc_event_destroy (MCEVENT_GROUP_CORE, "vfs_timestamp");
1839
1840 dir_list_free_list (&panelized_panel.list);
1841 }
1842
1843
1844 mc_global.midnight_shutdown = TRUE;
1845 dialog_switch_shutdown ();
1846 done_mc ();
1847 widget_destroy (WIDGET (filemanager));
1848 current_panel = NULL;
1849
1850 #ifdef USE_INTERNAL_EDIT
1851 edit_stack_free ();
1852 #endif
1853
1854 if ((quit & SUBSHELL_EXIT) == 0)
1855 tty_clear_screen ();
1856
1857 return ret;
1858 }
1859
1860