Codepage messages related translated & other stuff...
[midnight-commander.git] / gnome / gcmd.c
blob59d74016f2729940350cefeb71e207421e472aef
1 /*
2 * Various Menu-invoked Command implementations specific to the GNOME port
4 * Copyright (C) 1998 the Free Software Foundation
6 * Author: Miguel de Icaza (miguel@kernel.org)
7 */
8 #include <config.h>
9 #include "x.h"
10 #include <stdio.h>
11 #include <sys/stat.h>
12 #include "dir.h"
13 #include "panel.h"
14 #include "gscreen.h"
15 #include "main.h"
16 #include "gmain.h"
17 #include "cmd.h"
18 #include "boxes.h"
19 #include "profile.h"
20 #include "setup.h"
21 #include "panelize.h"
22 #include "gcmd.h"
23 #include "dialog.h"
24 #include "layout.h"
25 #include "gdesktop.h"
26 #include "gmain.h"
27 #include "file.h"
28 #include "../vfs/vfs.h"
30 static char *panelize_section = "Panelize";
32 void
33 gnome_open_terminal_with_cmd (const char *command)
35 char *p;
36 int quote_all = 0;
38 if (!(p = gnome_is_program_in_path ("gnome-terminal"))){
39 if (!(p = gnome_is_program_in_path ("dtterm")))
40 if (!(p = gnome_is_program_in_path ("nxterm")))
41 if (!(p = gnome_is_program_in_path ("color-xterm")))
42 if (!(p = gnome_is_program_in_path ("rxvt")))
43 p = gnome_is_program_in_path ("xterm");
44 } else
45 quote_all = 1;
47 if (p){
48 if (command){
49 char *q;
51 if (quote_all)
52 q = g_strconcat (p, " --start-factory-server --use-factory -e '", command, "'", NULL);
53 else
54 q = g_strconcat (p, " -e ", command, NULL);
55 my_system (EXECUTE_AS_SHELL, shell, q);
56 g_free (q);
57 } else
58 my_system (EXECUTE_AS_SHELL, shell, p);
60 g_free (p);
61 } else
62 message (1, MSG_ERROR, _(" Could not start a terminal "));
65 void
66 gnome_open_terminal (void)
68 gnome_open_terminal_with_cmd (NULL);
71 void
72 gnome_about_cmd (void)
74 GtkWidget *about;
75 static int translated;
76 static const gchar *authors[] = {
77 N_("The Midnight Commander Team"),
78 "http://www.gnome.org/mc/",
79 N_("bug reports: http://bugs.gnome.org, or use gnome-bug"),
80 NULL
83 if (!translated){
84 int i;
86 for (i = 0; authors [i]; i++)
87 authors [i] = _(authors [i]);
88 translated = TRUE;
91 about = gnome_about_new (_("GNU Midnight Commander"), VERSION,
92 "Copyright 1994-1999 the Free Software Foundation",
93 authors,
94 _("The GNOME edition of the Midnight Commander file manager."),
95 NULL);
96 gtk_widget_show (about);
99 void
100 gnome_open_panel (GtkWidget *widget, WPanel *panel)
102 new_panel_at (panel->cwd);
105 void
106 gnome_close_panel (GtkWidget *widget, WPanel *panel)
108 Dlg_head *h = panel->widget.parent;
109 if (panel->timer_id){
110 gtk_timeout_remove (panel->timer_id);
111 panel->timer_id = -1;
114 /* Remove the widgets from the dialog head */
115 remove_widget (h, panel->current_dir);
116 remove_widget (h, panel);
118 /* Free our own internal stuff */
119 g_free (panel->view_menu_items);
120 g_free (panel->view_toolbar_items);
122 /* Kill the widgets */
123 destroy_widget (panel->current_dir);
124 destroy_widget ((Widget *)panel);
126 layout_panel_gone (panel);
127 mc_chdir ("/");
130 static void
131 set_list_type (GtkWidget *widget, WPanel *panel, enum list_types type)
133 int i;
135 /* This is kind of a hack to see whether we need to do something or not.
136 * This function (or at least the callback that calls it) can refer to a
137 * radio menu item or a radio button, so we need to see if it is active.
140 if (GTK_OBJECT_TYPE (widget) == gtk_radio_menu_item_get_type ()) {
141 if (!GTK_CHECK_MENU_ITEM (widget)->active)
142 return;
143 } else if (GTK_OBJECT_TYPE (widget) == gtk_radio_button_get_type ()) {
144 if (!GTK_TOGGLE_BUTTON (widget)->active)
145 return;
146 } else
147 g_assert_not_reached ();
149 /* Worth the effort? */
151 if (panel->list_type == type)
152 return;
154 /* Set the list type */
156 panel->list_type = type;
157 set_panel_formats (panel);
158 paint_panel (panel);
159 do_refresh ();
161 /* Synchronize the widgets */
163 for (i = 0; panel->view_menu_items[i] && panel->view_toolbar_items[i]; i++)
164 if (widget == panel->view_menu_items[i]) {
165 gtk_signal_handler_block_by_data (
166 GTK_OBJECT (panel->view_toolbar_items[i]), panel);
167 gtk_toggle_button_set_active (
168 GTK_TOGGLE_BUTTON (panel->view_toolbar_items[i]), TRUE);
169 gtk_signal_handler_unblock_by_data (
170 GTK_OBJECT (panel->view_toolbar_items[i]), panel);
171 return;
172 } else if (widget == panel->view_toolbar_items[i]) {
173 gtk_signal_handler_block_by_data (
174 GTK_OBJECT (panel->view_menu_items[i]), panel);
175 gtk_check_menu_item_set_active (
176 GTK_CHECK_MENU_ITEM (panel->view_menu_items[i]), TRUE);
177 gtk_signal_handler_unblock_by_data (
178 GTK_OBJECT (panel->view_menu_items[i]), panel);
179 return;
182 g_assert_not_reached ();
185 void
186 gnome_icon_view_cmd (GtkWidget *widget, WPanel *panel)
188 set_list_type (widget, panel, list_icons);
191 void
192 gnome_brief_view_cmd (GtkWidget *widget, WPanel *panel)
194 set_list_type (widget, panel, list_brief);
197 void
198 gnome_detailed_view_cmd (GtkWidget *widget, WPanel *panel)
200 set_list_type (widget, panel, list_full);
203 void
204 gnome_custom_view_cmd (GtkWidget *widget, WPanel *panel)
206 set_list_type (widget, panel, list_user);
209 static void
210 sort_callback (GtkWidget *menu_item, GtkWidget *cbox1)
212 if (gtk_object_get_data (GTK_OBJECT (menu_item), "SORT_ORDER_CODE") == SORT_NAME)
213 gtk_widget_set_sensitive (cbox1, TRUE);
214 else
215 gtk_widget_set_sensitive (cbox1, FALSE);
218 /* Returns a sort function based on its type */
219 sortfn *
220 sort_get_func_from_type (SortType type)
222 sortfn *sfn = NULL;
224 switch (type) {
225 case SORT_NAME:
226 sfn = (sortfn *) sort_name;
227 break;
229 case SORT_EXTENSION:
230 sfn = (sortfn *) sort_ext;
231 break;
233 case SORT_ACCESS:
234 sfn = (sortfn *) sort_atime;
235 break;
237 case SORT_MODIFY:
238 sfn = (sortfn *) sort_time;
239 break;
241 case SORT_CHANGE:
242 sfn = (sortfn *) sort_ctime;
243 break;
245 case SORT_SIZE:
246 sfn = (sortfn *) sort_size;
247 break;
249 default:
250 g_assert_not_reached ();
253 return sfn;
256 void
257 gnome_sort_cmd (GtkWidget *widget, WPanel *panel)
259 GtkWidget *sort_box;
260 GtkWidget *hbox;
261 GtkWidget *omenu;
262 GtkWidget *menu;
263 GtkWidget *menu_item;
264 GtkWidget *cbox1, *cbox2;
265 sortfn *sfn = NULL;
267 sort_box = gnome_dialog_new (_("Sort By"), GNOME_STOCK_BUTTON_OK,
268 GNOME_STOCK_BUTTON_CANCEL, NULL);
269 gmc_window_setup_from_panel (GNOME_DIALOG (sort_box), panel);
271 /* we define this up here so we can pass it in to our callback */
272 cbox1 = gtk_check_button_new_with_label (_("Ignore case sensitivity."));
273 hbox = gtk_hbox_new (FALSE, 0);
274 gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (sort_box)->vbox), hbox, FALSE, FALSE, 0);
275 gtk_box_pack_start (GTK_BOX (hbox), gtk_label_new (_("Sort files by ")), FALSE, FALSE, 0);
277 omenu = gtk_option_menu_new ();
278 gtk_box_pack_start (GTK_BOX (hbox), omenu, FALSE, FALSE, 0);
279 menu = gtk_menu_new ();
280 menu_item = gtk_menu_item_new_with_label ( _("Name"));
281 /* FIXME: we want to set the option menu to be the correct ordering. */
282 gtk_menu_append (GTK_MENU (menu), menu_item);
283 gtk_object_set_data (GTK_OBJECT (menu_item), "SORT_ORDER_CODE", (gpointer) SORT_NAME);
284 gtk_signal_connect (GTK_OBJECT (menu_item), "activate",
285 GTK_SIGNAL_FUNC (sort_callback), cbox1);
287 menu_item = gtk_menu_item_new_with_label ( _("File Type"));
288 gtk_menu_append (GTK_MENU (menu), menu_item);
289 gtk_object_set_data (GTK_OBJECT (menu_item), "SORT_ORDER_CODE", (gpointer) SORT_EXTENSION);
290 gtk_signal_connect (GTK_OBJECT (menu_item), "activate",
291 GTK_SIGNAL_FUNC (sort_callback), cbox1);
293 menu_item = gtk_menu_item_new_with_label ( _("Size"));
294 gtk_menu_append (GTK_MENU (menu), menu_item);
295 gtk_object_set_data (GTK_OBJECT (menu_item), "SORT_ORDER_CODE", (gpointer) SORT_SIZE);
296 gtk_signal_connect (GTK_OBJECT (menu_item), "activate",
297 GTK_SIGNAL_FUNC (sort_callback), cbox1);
299 menu_item = gtk_menu_item_new_with_label ( _("Time Last Accessed"));
300 gtk_menu_append (GTK_MENU (menu), menu_item);
301 gtk_object_set_data (GTK_OBJECT (menu_item), "SORT_ORDER_CODE", (gpointer) SORT_ACCESS);
302 gtk_signal_connect (GTK_OBJECT (menu_item), "activate",
303 GTK_SIGNAL_FUNC (sort_callback), cbox1);
305 menu_item = gtk_menu_item_new_with_label ( _("Time Last Modified"));
306 gtk_menu_append (GTK_MENU (menu), menu_item);
307 gtk_object_set_data (GTK_OBJECT (menu_item), "SORT_ORDER_CODE", (gpointer) SORT_MODIFY);
308 gtk_signal_connect (GTK_OBJECT (menu_item), "activate",
309 GTK_SIGNAL_FUNC (sort_callback), cbox1);
311 menu_item = gtk_menu_item_new_with_label ( _("Time Last Changed"));
312 gtk_menu_append (GTK_MENU (menu), menu_item);
313 gtk_object_set_data (GTK_OBJECT (menu_item), "SORT_ORDER_CODE", (gpointer) SORT_CHANGE);
314 gtk_signal_connect (GTK_OBJECT (menu_item), "activate",
315 GTK_SIGNAL_FUNC (sort_callback), cbox1);
317 gtk_widget_show_all (menu);
318 gtk_option_menu_set_menu (GTK_OPTION_MENU (omenu), menu);
321 gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (cbox1), panel->case_sensitive);
322 gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (sort_box)->vbox),
323 cbox1, FALSE, FALSE, 0);
325 cbox2 = gtk_check_button_new_with_label (_("Reverse the order."));
326 gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (cbox2), panel->reverse);
327 gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (sort_box)->vbox),
328 cbox2, FALSE, FALSE, 0);
329 /* off to the races */
330 gtk_widget_show_all (GNOME_DIALOG (sort_box)->vbox);
331 switch (gnome_dialog_run (GNOME_DIALOG (sort_box))) {
332 case 0:
333 sfn = sort_get_func_from_type(
334 GPOINTER_TO_UINT(gtk_object_get_data (GTK_OBJECT
335 (GTK_OPTION_MENU
336 (omenu)->menu_item),
337 "SORT_ORDER_CODE")));
338 /* case sensitive */
339 panel->case_sensitive = GTK_TOGGLE_BUTTON (cbox1)->active;
340 /* Reverse order */
341 panel->reverse = GTK_TOGGLE_BUTTON (cbox2)->active;
343 panel_set_sort_order (panel, sfn);
344 break;
345 case 1:
346 break;
347 default:
348 return;
350 gtk_widget_destroy (sort_box);
353 typedef struct ep_dlg_data {
354 GtkWidget *ep_dlg;
355 GtkWidget *clist;
356 GtkWidget *entry;
357 GtkWidget *add_button;
358 GtkWidget *remove_button;
359 gboolean setting_text;
360 gint selected; /* if this is -1 then nothing is selected, otherwise, it's the row selected */
361 } ep_dlg_data;
363 static gchar *
364 get_nickname (gchar *text)
366 GtkWidget *dlg;
367 GtkWidget *entry;
368 GtkWidget *label;
369 gchar *retval = NULL;
370 int destroy;
372 dlg = gnome_dialog_new (_("Enter name."), GNOME_STOCK_BUTTON_OK,
373 GNOME_STOCK_BUTTON_CANCEL, NULL);
374 gtk_window_set_position (GTK_WINDOW (dlg), GTK_WIN_POS_MOUSE);
375 entry = gtk_entry_new ();
376 if (text)
377 gtk_entry_set_text (GTK_ENTRY (entry), text);
378 label = gtk_label_new (_("Enter label for command:"));
379 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
380 gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (dlg)->vbox),
381 label, FALSE, FALSE, 0);
382 gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (dlg)->vbox),
383 entry, FALSE, FALSE, 0);
384 gtk_widget_show_all (GNOME_DIALOG (dlg)->vbox);
385 destroy = TRUE;
386 switch (gnome_dialog_run (GNOME_DIALOG (dlg))) {
387 case -1:
388 destroy = FALSE;
389 break;
390 case 0:
391 retval = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry)));
392 break;
393 case 1:
394 default:
396 if (destroy)
397 gtk_widget_destroy (dlg);
399 return retval;
402 static void
403 ep_add_callback (GtkWidget *widget, ep_dlg_data *data)
405 gint i;
406 gchar *insert_tab[1];
408 insert_tab[0] = get_nickname (NULL);
409 if (insert_tab[0] == NULL)
410 return;
411 i = gtk_clist_append (GTK_CLIST (data->clist), insert_tab);
412 gtk_clist_set_row_data (GTK_CLIST (data->clist), i,
413 g_strdup (gtk_entry_get_text (GTK_ENTRY (data->entry))));
414 g_free (insert_tab [0]);
415 data->selected = -1;
416 gtk_widget_set_sensitive (data->add_button, FALSE);
417 gtk_entry_set_text (GTK_ENTRY (data->entry), "");
420 static void
421 ep_remove_callback (GtkWidget *widget, ep_dlg_data *data)
423 if (data->selected > -1) {
424 g_free (gtk_clist_get_row_data (GTK_CLIST (data->clist), data->selected));
425 gtk_clist_remove (GTK_CLIST (data->clist), data->selected);
426 data->selected = -1;
427 gtk_entry_set_text (GTK_ENTRY (data->entry), "");
429 gtk_widget_set_sensitive (data->remove_button, FALSE);
432 static void
433 ep_select_callback (GtkWidget *widget,
434 gint row,
435 gint column,
436 GdkEventButton *event,
437 ep_dlg_data *data)
439 if (event && event->type == GDK_2BUTTON_PRESS) {
440 gchar *nick;
442 gtk_clist_get_text (GTK_CLIST (widget), row, 0, &nick);
443 /* ugly but correct... (: */
444 nick = get_nickname (nick);
445 gtk_clist_set_text (GTK_CLIST (data->clist), row, 0, nick);
446 gtk_clist_select_row (GTK_CLIST (data->clist), row, 0);
447 } else {
448 data->setting_text = TRUE;
449 gtk_entry_set_text (GTK_ENTRY (data->entry),
450 (gchar *) gtk_clist_get_row_data (GTK_CLIST (widget), row));
451 data->setting_text = FALSE;
452 data->selected = row;
453 gtk_widget_set_sensitive (data->remove_button, TRUE);
454 gtk_widget_set_sensitive (data->add_button, FALSE);
458 static void
459 ep_text_changed_callback (GtkWidget *widget, ep_dlg_data *data)
461 if (data->setting_text)
462 /* we don't want to deselect text if we just clicked on something */
463 return;
464 if (data->selected > -1) {
465 gtk_clist_unselect_row (GTK_CLIST (data->clist), data->selected, 0);
466 data->selected = -1;
468 gtk_widget_set_sensitive (data->remove_button, FALSE);
469 gtk_widget_set_sensitive (data->add_button, TRUE);
472 static void
473 load_settings (GtkCList *clist)
475 gchar *insert_tab[1];
476 void *profile_keys;
477 gchar *key, *value;
478 gint i = 0;
480 profile_keys = profile_init_iterator (panelize_section, profile_name);
482 if (!profile_keys){
483 insert_tab[0] = _("Find all core files");
484 i = gtk_clist_insert (clist, i, insert_tab);
485 gtk_clist_set_row_data (clist, i, g_strdup ("find / -name core"));
486 insert_tab[0] = _("Find rejects after patching");
487 i = gtk_clist_insert (clist, i, insert_tab);
488 gtk_clist_set_row_data (clist, i, g_strdup ("find . -name \\*.rej -print"));
489 } else {
490 while (profile_keys) {
491 profile_keys = profile_iterator_next (profile_keys, &key, &value);
492 insert_tab[0] = key;
493 i = gtk_clist_insert (clist, i, insert_tab);
494 gtk_clist_set_row_data (clist, i, g_strdup (value));
499 static void
500 save_settings (GtkCList *clist)
502 gint i;
503 gchar *text;
505 profile_clean_section (panelize_section, profile_name);
506 for (i = 0; i < GTK_CLIST (clist)->rows; i++) {
507 gtk_clist_get_text (GTK_CLIST (clist), i, 0, &text);
508 WritePrivateProfileString (panelize_section,
509 text,
510 (gchar *) gtk_clist_get_row_data (GTK_CLIST (clist), i),
511 profile_name);
513 sync_profiles ();
516 void
517 gnome_external_panelize (GtkWidget *widget, WPanel *panel)
519 ep_dlg_data *data;
520 GtkWidget *frame;
521 GtkWidget *sw;
522 GtkWidget *vbox;
523 GtkWidget *hbox;
524 gint i;
525 gchar *row_data;
526 int destroy;
528 data = g_new0 (ep_dlg_data, 1);
529 data->setting_text = FALSE;
530 data->selected = -1;
531 data->ep_dlg = gnome_dialog_new (_("Run Command"), GNOME_STOCK_BUTTON_OK,
532 GNOME_STOCK_BUTTON_CANCEL, NULL);
533 gtk_window_set_position (GTK_WINDOW (data->ep_dlg), GTK_WIN_POS_MOUSE);
535 /* Frame 1 */
536 frame = gtk_frame_new (_("Preset Commands"));
537 gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (data->ep_dlg)->vbox),
538 frame, FALSE, FALSE, 0);
539 data->clist = gtk_clist_new (1);
540 load_settings (GTK_CLIST (data->clist));
541 gtk_signal_connect (GTK_OBJECT (data->clist), "select_row", GTK_SIGNAL_FUNC (ep_select_callback), (gpointer) data);
542 vbox = gtk_vbox_new (FALSE, GNOME_PAD_SMALL);
543 gtk_clist_columns_autosize (GTK_CLIST (data->clist));
544 gtk_clist_set_auto_sort (GTK_CLIST (data->clist), TRUE);
545 gtk_container_set_border_width (GTK_CONTAINER (vbox), GNOME_PAD_SMALL);
546 sw = gtk_scrolled_window_new (GTK_CLIST (data->clist)->hadjustment, GTK_CLIST (data->clist)->vadjustment);
547 gtk_widget_set_usize (sw, 300, 100);
548 gtk_container_add (GTK_CONTAINER (sw), data->clist);
549 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
550 gtk_box_pack_start (GTK_BOX (vbox), sw, TRUE, TRUE, 0);
551 gtk_container_add (GTK_CONTAINER (frame), vbox);
552 hbox = gtk_hbox_new (FALSE, GNOME_PAD_SMALL);
553 data->add_button = gtk_button_new_with_label (_("Add"));
554 gtk_signal_connect (GTK_OBJECT (data->add_button), "clicked", GTK_SIGNAL_FUNC (ep_add_callback), (gpointer) data);
555 gtk_widget_set_usize (data->add_button, 75, 25);
556 gtk_box_pack_end (GTK_BOX (hbox), data->add_button, FALSE, FALSE, 0);
557 data->remove_button = gtk_button_new_with_label (_("Remove"));
558 gtk_widget_set_sensitive (data->remove_button, FALSE);
559 gtk_signal_connect (GTK_OBJECT (data->remove_button), "clicked", GTK_SIGNAL_FUNC (ep_remove_callback), (gpointer) data);
560 gtk_widget_set_usize (data->remove_button, 75, 25);
561 gtk_box_pack_end (GTK_BOX (hbox), data->remove_button, FALSE, FALSE, 0);
562 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
564 /* Frame 2 */
565 frame = gtk_frame_new (_("Run this Command"));
566 gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (data->ep_dlg)->vbox),
567 frame, FALSE, FALSE, 0);
568 data->entry = gtk_entry_new ();
569 gtk_signal_connect (GTK_OBJECT (data->entry), "changed", GTK_SIGNAL_FUNC (ep_text_changed_callback), (gpointer) data);
570 hbox = gtk_hbox_new (FALSE, GNOME_PAD_SMALL);
571 gtk_container_set_border_width (GTK_CONTAINER (hbox), GNOME_PAD_SMALL);
572 gtk_box_pack_start (GTK_BOX (hbox), gtk_label_new (_("Command: ")), FALSE, FALSE, 0);
573 gtk_box_pack_start (GTK_BOX (hbox), data->entry, TRUE, TRUE, 0);
574 gtk_container_add (GTK_CONTAINER (frame), hbox);
575 gtk_widget_show_all (GNOME_DIALOG (data->ep_dlg)->vbox);
577 destroy = TRUE;
579 switch (gnome_dialog_run (GNOME_DIALOG (data->ep_dlg))) {
580 case 0:
581 gtk_widget_hide (data->ep_dlg);
582 while (gtk_events_pending () )
583 gtk_main_iteration ();
585 do_external_panelize (gtk_entry_get_text (GTK_ENTRY (data->entry)));
586 save_settings (GTK_CLIST (data->clist));
587 break;
588 case 1:
589 break;
590 case -1:
591 destroy = FALSE;
592 break;
593 default:
595 for (i = 0; i < GTK_CLIST (data->clist)->rows; i++) {
596 row_data = gtk_clist_get_row_data (GTK_CLIST (data->clist), i);
597 if (row_data)
598 g_free (row_data);
601 if (destroy)
602 gtk_widget_destroy (GTK_WIDGET (data->ep_dlg));
603 g_free (data);
607 static WPanel *
608 create_trash_panel (void)
610 WPanel *retval;
611 gchar *trash_dir;
613 is_trash_panel = TRUE;
614 trash_dir = g_strconcat (gnome_user_home_dir, "/",
615 DESKTOP_DIR_NAME, "/",
616 "Trash.gmc",
617 NULL);
618 retval = new_panel_at (trash_dir);
619 g_free (trash_dir);
620 is_trash_panel = FALSE;
622 return retval;
625 void
626 gnome_empty_trash (GtkWidget *widget, WPanel *panel)
628 WPanel *trash_panel;
629 gint i;
631 trash_panel = create_trash_panel ();
632 for (i = 0; i < trash_panel->count; i++){
633 if (!strcmp (trash_panel->dir.list [i].fname, "..")) {
634 continue;
636 do_file_mark (trash_panel, i, 1);
639 panel_operate (trash_panel, OP_DELETE, NULL, FALSE);
641 gnome_close_panel (NULL, trash_panel);
642 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
643 do_refresh ();
647 void
648 gnome_select_all_cmd (GtkWidget *widget, WPanel *panel)
650 gint i;
651 for (i = 0; i < panel->count; i++){
652 if (!strcmp (panel->dir.list [i].fname, "..")) {
653 continue;
655 do_file_mark (panel, i, 1);
657 paint_panel (panel);
658 do_refresh ();
661 void
662 gnome_start_search (GtkWidget *widget, WPanel *panel)
664 start_search (panel);
667 void
668 gnome_reverse_selection_cmd_panel (GtkWidget *widget, WPanel *panel)
670 file_entry *file;
671 int i;
673 for (i = 0; i < panel->count; i++) {
674 if (!strcmp (panel->dir.list [i].fname, ".."))
675 continue;
677 file = &panel->dir.list [i];
678 do_file_mark (panel, i, !file->f.marked);
681 paint_panel (panel);
684 void
685 gnome_filter_cmd (GtkWidget *widget, WPanel *panel)
687 GtkWidget *filter_dlg;
688 GtkWidget *entry;
689 GtkWidget *label;
690 gchar *text1, *text2, *text3;
692 filter_dlg = gnome_dialog_new (_("Set Filter"), GNOME_STOCK_BUTTON_OK,
693 GNOME_STOCK_BUTTON_CANCEL, NULL);
694 gtk_window_set_position (GTK_WINDOW (filter_dlg), GTK_WIN_POS_MOUSE);
695 if (easy_patterns) {
696 text1 = "mc_filter_globs";
697 text3 = _("Show all files");
698 if (panel->filter && (strcmp (panel->filter, "*")))
699 text2 = panel->filter;
700 else
701 text2 = NULL;
702 } else {
703 text1 = "mc_filter_regexps";
704 text3 = "^.*$";
705 if (!panel->filter)
706 text2 = NULL;
707 else
708 text2 = panel->filter;
710 entry = gnome_entry_new (text1);
711 gnome_entry_load_history (GNOME_ENTRY (entry));
713 if (text2) {
714 gtk_entry_set_text (GTK_ENTRY (gnome_entry_gtk_entry (GNOME_ENTRY (entry))), text2);
715 gnome_entry_prepend_history (GNOME_ENTRY (entry), FALSE, text3);
716 } else
717 gtk_entry_set_text (GTK_ENTRY (gnome_entry_gtk_entry (GNOME_ENTRY (entry))), text3);
719 if (easy_patterns)
720 label = gtk_label_new (_("Enter a filter here for files in the panel view.\n\nFor example:\n*.png will show just png images"));
721 else
722 label = gtk_label_new (_("Enter a Regular Expression to filter files in the panel view."));
723 gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
724 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
726 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
727 gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (filter_dlg)->vbox), label, FALSE, FALSE, 0);
728 gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (filter_dlg)->vbox), entry, FALSE, FALSE, 0);
729 gtk_widget_show_all (GNOME_DIALOG (filter_dlg)->vbox);
730 switch (gnome_dialog_run (GNOME_DIALOG (filter_dlg))) {
731 case 0:
732 gtk_widget_hide (filter_dlg);
733 if (panel->filter) {
734 g_free (panel->filter);
735 panel->filter = NULL;
737 panel->filter = g_strdup (gtk_entry_get_text (GTK_ENTRY (gnome_entry_gtk_entry (GNOME_ENTRY (entry)))));
738 if (!strcmp (_("Show all files"), panel->filter)) {
739 g_free (panel->filter);
740 panel->filter = NULL;
741 gtk_entry_set_text (GTK_ENTRY (gnome_entry_gtk_entry (GNOME_ENTRY (entry))),
742 "");
743 gtk_label_set_text (GTK_LABEL (panel->status), _("Show all files"));
744 } else if (!strcmp ("*", panel->filter)) {
745 g_free (panel->filter);
746 panel->filter = NULL;
747 gtk_label_set_text (GTK_LABEL (panel->status), _("Show all files"));
748 } else
749 gtk_label_set_text (GTK_LABEL (panel->status), panel->filter);
751 gnome_entry_save_history (GNOME_ENTRY (entry));
752 x_filter_changed (panel);
753 reread_cmd ();
754 break;
756 case -1:
757 return;
759 gtk_widget_destroy (filter_dlg);
762 void
763 gnome_open_files (GtkWidget *widget, WPanel *panel)
765 GList *later = NULL;
766 #if 0
767 GList *now;
768 #endif
769 gint i;
771 /* FIXME: this is the easy way to do things. We want the
772 * hard way sometime. */
773 for (i = 0; i < panel->count; i++) {
774 if (panel->dir.list [i].f.marked)
775 if (!do_enter_on_file_entry ((panel->dir.list) + i))
776 later = g_list_prepend (later, panel->dir.list + i);
778 #if 0
779 /* This is sorta ugly. Should we just skip these? There should be a better way. */
780 for (now = later; now; now = now->next) {
781 gchar *command;
782 command = input_expand_dialog (_(" Open with..."),
783 _("Enter extra arguments:"), (WPanel *) now->data);
784 if (!command)
785 /* we break out. */
786 break;
787 execute (command);
788 g_free (command);
790 #endif
791 g_list_free (later);
795 void
796 gnome_run_new (GtkWidget *widget, GnomeDesktopEntry *gde)
798 gnome_desktop_entry_launch (gde);
801 void
802 gnome_mkdir_cmd (GtkWidget *widget, WPanel *panel)
804 mkdir_cmd (panel);
807 void
808 gnome_newfile_cmd (GtkWidget *widget, WPanel *panel)
810 mc_chdir (panel->cwd);
811 gmc_edit ("");
814 static void
815 dentry_apply_callback(GtkWidget *widget, int page, gpointer data)
817 GnomeDesktopEntry *dentry;
818 gchar *desktop_directory;
820 if (page != -1)
821 return;
823 g_return_if_fail(data!=NULL);
824 g_return_if_fail(GNOME_IS_DENTRY_EDIT(data));
825 dentry = gnome_dentry_get_dentry(GNOME_DENTRY_EDIT(data));
827 if (getenv ("GNOME_DESKTOP_DIR") != NULL)
828 desktop_directory = g_strconcat (getenv ("GNOME_DESKTOP_DIR"),
829 "/",
830 dentry->name, ".desktop",
831 NULL);
832 else
833 desktop_directory = g_strconcat (gnome_user_home_dir, "/",
834 DESKTOP_DIR_NAME, "/",
835 dentry->name, ".desktop",
836 NULL);
838 dentry->location = desktop_directory;
839 gnome_desktop_entry_save(dentry);
840 gnome_desktop_entry_free(dentry);
841 gnome_config_sync ();
842 desktop_reload_icons (FALSE, 0, 0);
846 void
847 gnome_new_launcher (GtkWidget *widget, WPanel *panel)
849 GtkWidget *dialog;
850 GtkObject *dentry;
852 dialog = gnome_property_box_new ();
853 gtk_window_set_title(GTK_WINDOW(dialog), _("Desktop entry properties"));
854 gtk_window_set_policy(GTK_WINDOW(dialog), FALSE, FALSE, TRUE);
855 dentry = gnome_dentry_edit_new_notebook(GTK_NOTEBOOK(GNOME_PROPERTY_BOX(dialog)->notebook));
856 gtk_signal_connect_object(GTK_OBJECT(dentry), "changed",
857 GTK_SIGNAL_FUNC(gnome_property_box_changed),
858 GTK_OBJECT(dialog));
860 gtk_signal_connect(GTK_OBJECT(dialog), "apply",
861 GTK_SIGNAL_FUNC(dentry_apply_callback),
862 dentry);
863 gtk_widget_show(dialog);
867 void
868 gnome_select (GtkWidget *widget, WPanel *panel)
870 char *reg_exp, *reg_exp_t;
871 int i;
872 int c;
873 int dirflag = 0;
874 GtkWidget *select_dialog;
875 GtkWidget *entry;
876 GtkWidget *label;
877 int run;
879 select_dialog = gnome_dialog_new (_("Select File"), GNOME_STOCK_BUTTON_OK,
880 GNOME_STOCK_BUTTON_CANCEL, NULL);
881 gtk_window_set_position (GTK_WINDOW (select_dialog), GTK_WIN_POS_MOUSE);
882 entry = gnome_entry_new ("mc_select");
883 gtk_entry_set_text (GTK_ENTRY (gnome_entry_gtk_entry (GNOME_ENTRY (entry))), easy_patterns ? "*" : ".");
884 gnome_entry_load_history (GNOME_ENTRY (entry));
886 if (easy_patterns)
887 label = gtk_label_new (_("Enter a filter here to select files in the panel view with.\n\nFor example:\n*.png will select all png images"));
888 else
889 label = gtk_label_new (_("Enter a regular expression here to select files in the panel view with."));
891 gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
892 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
894 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
895 gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (select_dialog)->vbox), label, FALSE, FALSE, 0);
896 gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (select_dialog)->vbox), entry, FALSE, FALSE, 0);
897 gtk_widget_show_all (GNOME_DIALOG (select_dialog)->vbox);
898 reg_exp = NULL;
899 run = gnome_dialog_run (GNOME_DIALOG (select_dialog));
900 if (run == 0) {
901 gtk_widget_hide (select_dialog);
902 reg_exp = g_strdup (gtk_entry_get_text (GTK_ENTRY (gnome_entry_gtk_entry (GNOME_ENTRY (entry)))));
904 if (run != -1)
905 gtk_widget_destroy (select_dialog);
907 if ((reg_exp == NULL) || (*reg_exp == '\000')) {
908 g_free (reg_exp);
909 return;
911 reg_exp_t = reg_exp;
913 /* Check if they specified a directory */
914 if (*reg_exp_t == PATH_SEP){
915 dirflag = 1;
916 reg_exp_t++;
918 if (reg_exp_t [strlen(reg_exp_t) - 1] == PATH_SEP){
919 dirflag = 1;
920 reg_exp_t [strlen(reg_exp_t) - 1] = 0;
923 for (i = 0; i < panel->count; i++){
924 if (!strcmp (panel->dir.list [i].fname, ".."))
925 continue;
926 if (S_ISDIR (panel->dir.list [i].buf.st_mode)){
927 if (!dirflag)
928 continue;
929 } else {
930 if (dirflag)
931 continue;
933 c = regexp_match (reg_exp_t, panel->dir.list [i].fname, match_file);
934 if (c == -1){
935 message (1, MSG_ERROR, _(" Malformed regular expression "));
936 g_free (reg_exp);
937 return;
939 if (c){
940 do_file_mark (panel, i, 1);
943 paint_panel (panel);
944 g_free (reg_exp);
946 void
947 set_cursor_busy (WPanel *panel)
949 GdkCursor *cursor;
951 if (is_a_desktop_panel (panel))
952 return;
954 cursor = gdk_cursor_new (GDK_WATCH);
955 gdk_window_set_cursor (GTK_WIDGET (panel->xwindow)->window, cursor);
956 gdk_cursor_destroy (cursor);
957 gdk_flush ();
960 void
961 set_cursor_normal (WPanel *panel)
963 if (is_a_desktop_panel (panel))
964 return;
966 gdk_window_set_cursor (GTK_WIDGET (panel->xwindow)->window, NULL);
967 gdk_flush ();
970 void
971 gnome_new_link (GtkWidget *widget, WPanel *panel)
973 char *template;
974 char *url;
976 url = input_expand_dialog (_("Creating a desktop link"),
977 _("Enter the URL:"), "");
978 if (!url)
979 return;
981 template = g_concat_dir_and_file (desktop_directory, "urlXXXXXX");
983 if (mktemp (template)) {
984 char *icon;
986 icon = g_concat_dir_and_file (ICONDIR, "gnome-http-url.png");
987 desktop_create_url (template, url, url, icon);
988 g_free (icon);
990 g_free (template);
991 g_free (url);