ru.po: Corrections from Evgeny Bulgakov <bgav@netvision.net.il>
[midnight-commander.git] / gnome / glayout.c
bloba7baeb6b5a17eb9a6a4a29fcc2ab6d13fc8028eb
1 /*
2 * Layout routines for the GNOME edition of the GNU Midnight Commander
4 * (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 <unistd.h>
13 #include "global.h"
14 #include "dir.h"
15 #include "panel.h"
16 #include "gscreen.h"
17 #include "main.h"
18 #include "gmain.h"
19 #include "cmd.h"
20 #include "dialog.h"
21 #include "boxes.h"
22 #include "panelize.h"
23 #include "gcmd.h"
24 #include "gcliplabel.h"
25 #include "gdesktop.h"
26 #include "setup.h"
27 #include "../vfs/vfs.h"
28 #include "gprefs.h"
29 #include "gsession.h"
30 #include "listing-iconic.xpm"
31 #include "listing-brief-list.xpm"
32 #include "listing-list.xpm"
33 #include "listing-custom.xpm"
36 #define UNDEFINED_INDEX -1
38 /* Keep these two arrays in sync! */
40 GnomeUIInfo panel_view_menu_uiinfo[] = {
41 GNOMEUIINFO_RADIOITEM (N_("_Icon View"),
42 N_("Switch view to an icon display"),
43 gnome_icon_view_cmd, NULL),
44 GNOMEUIINFO_RADIOITEM (N_("_Brief View"),
45 N_("Switch view to show just file name and type"),
46 gnome_brief_view_cmd, NULL),
47 GNOMEUIINFO_RADIOITEM (N_("_Detailed View"),
48 N_("Switch view to show detailed file statistics"),
49 gnome_detailed_view_cmd, NULL),
50 GNOMEUIINFO_RADIOITEM (N_("_Custom View"),
51 N_("Switch view to show user-defined statistics"),
52 gnome_custom_view_cmd, NULL),
53 GNOMEUIINFO_END
56 GnomeUIInfo panel_view_toolbar_uiinfo[] = {
57 GNOMEUIINFO_RADIOITEM (N_("Icons"),
58 N_("Switch view to an icon display"),
59 gnome_icon_view_cmd, listing_iconic_xpm),
60 GNOMEUIINFO_RADIOITEM (N_("Brief"),
61 N_("Switch view to show just file name and type"),
62 gnome_brief_view_cmd, listing_brief_list_xpm),
63 GNOMEUIINFO_RADIOITEM (N_("Detailed"),
64 N_("Switch view to show detailed file statistics"),
65 gnome_detailed_view_cmd, listing_list_xpm),
66 GNOMEUIINFO_RADIOITEM (N_("Custom"),
67 N_("Switch view to show user-defined statistics"),
68 gnome_custom_view_cmd, listing_custom_xpm),
69 GNOMEUIINFO_END
72 GList *containers = 0;
74 int output_lines = 0;
75 int command_prompt = 1;
76 int keybar_visible = 1;
77 int message_visible = 1;
78 int xterm_hintbar = 0;
80 PanelContainer *current_panel_ptr, *other_panel_ptr;
82 WPanel *
83 get_current_panel (void)
85 if (current_panel_ptr)
86 return current_panel_ptr->panel;
87 else
88 return NULL;
91 WPanel *
92 get_other_panel (void)
94 if (other_panel_ptr)
95 return other_panel_ptr->panel;
96 else
97 return NULL;
100 /* FIXME: we probably want to get rid of this code */
102 get_current_index (void)
104 GList *p;
105 int i;
107 for (i = 0, p = containers; p; p = p->next, i++){
108 if (p->data == current_panel_ptr)
109 return i;
111 printf ("FATAL: current panel is not in the list\n");
112 g_assert_not_reached ();
113 return -1; /* keep -Wall happy */
117 get_other_index (void)
119 GList *p;
120 int i;
122 for (i = 0, p = containers; p; p = p->next, i++){
123 if (p->data == other_panel_ptr)
124 return i;
126 return UNDEFINED_INDEX;
129 void
130 set_current_panel (WPanel *panel)
132 GList *p;
134 if (g_list_length (containers) > 1)
135 other_panel_ptr = current_panel_ptr;
137 for (p = containers; p; p = p->next){
138 if (((PanelContainer *)p->data)->panel == panel){
139 current_panel_ptr = p->data;
140 break;
146 * Tries to assign other_panel (ie, if there is anything to assign to
148 static void
149 assign_other (void)
151 GList *p;
153 other_panel_ptr = NULL;
154 for (p = containers; p; p = p->next)
155 if (p->data != current_panel_ptr){
156 other_panel_ptr = p->data;
157 break;
162 * This keeps track of the current_panel_ptr and other_panel_ptr as
163 * well as the list of active containers
165 void
166 layout_panel_gone (WPanel *panel)
168 PanelContainer *pc_holder = 0;
169 int len = g_list_length (containers);
170 GList *p;
172 for (p = containers; p; p = p->next){
173 PanelContainer *pc = p->data;
175 if (pc->panel == panel){
176 pc_holder = pc;
177 break;
181 if (len > 1){
182 containers = g_list_remove (containers, pc_holder);
185 /* Check if this is not the current panel */
186 if (current_panel_ptr->panel == panel){
187 if (other_panel_ptr){
188 current_panel_ptr = other_panel_ptr;
189 assign_other ();
190 } else {
191 current_panel_ptr = NULL;
193 } else if (other_panel_ptr->panel == panel){
194 /* Check if it was the other panel */
195 if (len == 1){
196 other_panel_ptr = 0;
197 } else
198 assign_other ();
199 } else {
202 if (len == 1){
203 g_free (containers->data);
204 g_list_free (containers);
205 containers = NULL;
206 } else
207 g_free (pc_holder);
210 void
211 set_hintbar (char *str)
213 /*gtk_label_set (GTK_LABEL (current_panel_ptr->panel->status), str);*/
214 /* x_flush_events (); */
217 void
218 print_vfs_message (char *msg, ...)
220 va_list ap;
221 char str [256];
223 va_start(ap, msg);
224 vsprintf(str, msg, ap);
225 va_end(ap);
226 if (midnight_shutdown)
227 return;
229 set_hintbar(str);
232 void
233 rotate_dash (void)
238 get_current_type (void)
240 return view_listing;
245 get_other_type (void)
247 return other_panel_ptr ? view_listing : view_nothing;
251 get_display_type (int index)
253 GList *p;
255 if (index == UNDEFINED_INDEX)
256 return -1;
258 p = g_list_nth (containers, index);
259 if (p)
260 return ((PanelContainer *)p->data)->panel->list_type;
261 else
262 return -1;
265 void
266 use_dash (int ignore)
268 /* we dont care in the gnome edition */
271 Widget *
272 get_panel_widget (int index)
274 GList *p;
276 for (p = containers; index; p = p->next)
277 index--;
278 return (Widget *) ((PanelContainer *)p->data)->panel;
281 /* FIXME: This routine is wrong. It should follow what the original save_panel_types
282 * does. I can not remember which problem the original routine was trying to address
283 * when I did the "New {Left|Rigth} Panel" sections.
285 void
286 save_panel_types (void)
288 GList *p;
290 for (p = containers; p; p = p->next){
291 PanelContainer *pc = p->data;
293 if (!is_a_desktop_panel (pc->panel))
294 panel_save_setup (pc->panel, pc->panel->panel_name);
297 static void
298 run_cmd (void)
300 char *cmd;
302 cmd = input_dialog (_("Enter command to run"), _("Enter command to run"), "");
303 if (cmd && *cmd){
304 my_system (EXECUTE_AS_SHELL, shell, cmd);
308 static void
309 gnome_exit (void)
311 GtkWidget *w;
312 int v;
314 w = gnome_message_box_new (
315 _("Notice that if you choose to terminate the file manager, you will\n"
316 "also terminate the GNOME desktop handler.\n\n"
317 "Are you sure you want to exit?"),
318 GNOME_MESSAGE_BOX_WARNING,
319 GNOME_STOCK_BUTTON_YES,
320 GNOME_STOCK_BUTTON_NO,
321 NULL);
322 v = gnome_dialog_run (GNOME_DIALOG (w));
323 if (v != 0)
324 return;
326 w = gnome_message_box_new (
327 _("The file manager and the desktop handler are now terminating\n\n"
328 "If you want to start up again the desktop handler or the file manager\n"
329 "you can launch it from the Panel, or you can run the UNIX command `gmc'\n\n"
330 "Press OK to terminate the application, or cancel to continue using it."),
331 GNOME_MESSAGE_BOX_INFO,
332 GNOME_STOCK_BUTTON_OK,
333 GNOME_STOCK_BUTTON_CANCEL,
334 NULL);
335 v = gnome_dialog_run (GNOME_DIALOG (w));
336 if (v == 0) {
338 * We do not want to be restarted by the session manager now
340 session_set_restart (FALSE);
341 gmc_do_quit ();
345 static void
346 do_rescan_desktop (void)
348 desktop_reload_icons (FALSE, 0, 0);
351 static void
352 gnome_launch_mime_editor (void)
354 my_system (EXECUTE_AS_SHELL, shell, "mime-type-capplet");
357 void configure_box (void);
359 GtkCheckMenuItem *gnome_toggle_snap (void);
361 static GnomeUIInfo gnome_panel_new_menu [] = {
362 GNOMEUIINFO_ITEM_NONE(N_("_Terminal"),
363 N_("Launch a new terminal in the current directory"), gnome_open_terminal),
364 /* If this ever changes, make sure you update create_new_menu accordingly. */
365 GNOMEUIINFO_ITEM_NONE(N_("_Directory..."),
366 N_("Creates a new directory"), gnome_mkdir_cmd),
367 GNOMEUIINFO_ITEM_NONE(N_("_File..."),
368 N_("Creates a new file in this directory"), gnome_newfile_cmd),
369 GNOMEUIINFO_END
373 GnomeUIInfo gnome_panel_file_menu [] = {
374 GNOMEUIINFO_MENU_NEW_WINDOW_ITEM(gnome_open_panel, NULL),
375 /*GNOMEUIINFO_MENU_NEW_ITEM(N_("New _Window"), N_("Opens a new window"), gnome_open_panel, NULL),*/
377 /* We want to make a new menu entry here... */
378 /* For example: */
379 /* New-> */
380 /* Command Prompt */
381 /* Gimp Image */
382 /* Gnumeric Spreadsheet */
383 /* Text Document */
384 /* etc... */
385 GNOMEUIINFO_MENU_NEW_SUBTREE(gnome_panel_new_menu),
386 GNOMEUIINFO_SEPARATOR,
387 GNOMEUIINFO_MENU_OPEN_ITEM(gnome_open_files, NULL),
388 /* GNOMEUIINFO_ITEM_NONE(N_("Open _FTP site"), N_("Opens an FTP site"), ftplink_cmd },*/
389 GNOMEUIINFO_ITEM_STOCK(N_("_Copy..."), N_("Copy files"), copy_cmd, GNOME_STOCK_PIXMAP_COPY),
390 GNOMEUIINFO_ITEM_STOCK(N_("_Delete..."), N_("Delete files"), delete_cmd, GNOME_STOCK_PIXMAP_TRASH),
391 GNOMEUIINFO_ITEM_NONE(N_("_Move..."), N_("Rename or move files"), ren_cmd),
392 GNOMEUIINFO_SEPARATOR,
393 GNOMEUIINFO_ITEM_NONE(N_("Show directory sizes"), N_("Shows the disk space used by each directory"), dirsizes_cmd),
394 GNOMEUIINFO_SEPARATOR,
395 { GNOME_APP_UI_ITEM, N_("Close window"), N_("Closes this window"),
396 gnome_close_panel, NULL, NULL, GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_PIXMAP_CLOSE,
397 'w', GDK_CONTROL_MASK, NULL },
398 GNOMEUIINFO_END
401 GnomeUIInfo gnome_panel_edit_menu [] = {
402 { GNOME_APP_UI_ITEM, N_("Select _All"), N_("Select all files in the current Panel"), gnome_select_all_cmd,
403 NULL, NULL, 0, NULL, 'a', GDK_CONTROL_MASK },
404 GNOMEUIINFO_ITEM_NONE(N_("_Select Files..."), N_("Select a group of files"), gnome_select),
405 GNOMEUIINFO_ITEM_NONE(N_("_Invert Selection"), N_("Reverses the list of tagged files"),
406 gnome_reverse_selection_cmd_panel),
407 GNOMEUIINFO_SEPARATOR,
408 { GNOME_APP_UI_ITEM, N_("Search"), N_("Search for a file in the current Panel"), gnome_start_search,
409 NULL, NULL, 0, NULL, 's', GDK_CONTROL_MASK },
410 GNOMEUIINFO_SEPARATOR,
411 GNOMEUIINFO_ITEM_NONE(N_("_Rescan Directory"), N_("Rescan the directory contents"), reread_cmd),
412 GNOMEUIINFO_END
415 GnomeUIInfo gnome_panel_settings_menu [] = {
416 GNOMEUIINFO_MENU_PREFERENCES_ITEM(gnome_configure_box, NULL),
417 GNOMEUIINFO_END
420 GnomeUIInfo gnome_panel_layout_menu [] = {
421 GNOMEUIINFO_ITEM_NONE(N_("_Sort By..."), N_("Confirmation settings"), gnome_sort_cmd),
422 GNOMEUIINFO_ITEM_NONE(N_("_Filter View..."), N_("Global option settings"), gnome_filter_cmd),
423 GNOMEUIINFO_SEPARATOR,
424 GNOMEUIINFO_RADIOLIST(panel_view_menu_uiinfo),
425 GNOMEUIINFO_END
428 GnomeUIInfo gnome_panel_commands_menu [] = {
429 GNOMEUIINFO_ITEM_STOCK(N_("_Find File..."), N_("Locate files on disk"), find_cmd, GNOME_STOCK_MENU_JUMP_TO),
431 /* { GNOME_APP_UI_ITEM, N_("_Compare panels..."), N_("Compare two panel contents"), gnome_compare_panels },*/
432 GNOMEUIINFO_ITEM_NONE(N_("_Edit mime types..."), N_("Edits the MIME type bindings"),
433 gnome_launch_mime_editor),
434 { GNOME_APP_UI_ITEM, N_("_Run Command..."), N_("Runs a command"), run_cmd, NULL,
435 NULL, GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_OPEN, GDK_F2, 0 },
436 GNOMEUIINFO_ITEM_NONE(N_("_Run Command in panel..."),N_("Run a command and put the results in a panel"), gnome_external_panelize),
438 #ifdef USE_VFS
439 /* GNOMEUIINFO_ITEM_NONE(N_("_Active VFS list..."),N_("List of active virtual file systems"), reselect_vfs), */
440 #endif
441 #ifdef USE_EXT2FSLIB
442 /*does this do anything?*/
443 /* GNOMEUIINFO_ITEM_NONE(N_("_Undelete files (ext2fs only)..."), N_("Recover deleted files"), undelete_cmd),*/
444 #endif
445 #ifdef WITH_BACKGROUND
446 GNOMEUIINFO_ITEM_NONE(N_("_Background jobs..."), N_("List of background operations"), jobs_cmd),
447 #endif
448 GNOMEUIINFO_SEPARATOR,
449 GNOMEUIINFO_ITEM_STOCK (N_("Exit"), N_("Terminates the file manager and the desktop"),
450 gnome_exit, GNOME_STOCK_PIXMAP_QUIT),
451 GNOMEUIINFO_END
455 GnomeUIInfo gnome_panel_about_menu [] = {
456 GNOMEUIINFO_MENU_ABOUT_ITEM(gnome_about_cmd, NULL),
457 GNOMEUIINFO_HELP ("gmc"),
458 GNOMEUIINFO_END
461 GnomeUIInfo gnome_panel_desktop_menu [] = {
462 GNOMEUIINFO_SUBTREE(N_("_Arrange Icons"), desktop_arrange_icons_items),
463 GNOMEUIINFO_SEPARATOR,
464 GNOMEUIINFO_ITEM_NONE (N_("Rescan _Desktop Directory"), NULL, do_rescan_desktop),
465 GNOMEUIINFO_ITEM_NONE (N_("Rescan De_vices"), NULL, desktop_rescan_devices),
466 GNOMEUIINFO_ITEM_NONE (N_("Recreate Default _Icons"), NULL, desktop_recreate_default_icons),
467 GNOMEUIINFO_END
470 GnomeUIInfo gnome_panel_menu_with_desktop [] = {
471 GNOMEUIINFO_MENU_FILE_TREE(gnome_panel_file_menu),
472 GNOMEUIINFO_MENU_EDIT_TREE(gnome_panel_edit_menu),
473 GNOMEUIINFO_SUBTREE(N_("_Settings"),gnome_panel_settings_menu),
474 GNOMEUIINFO_SUBTREE(N_("_Layout"),gnome_panel_layout_menu),
475 GNOMEUIINFO_SUBTREE(N_("_Commands"),gnome_panel_commands_menu),
476 GNOMEUIINFO_SUBTREE(N_("_Desktop"), gnome_panel_desktop_menu),
477 GNOMEUIINFO_SUBTREE(N_("_Help"), gnome_panel_about_menu),
478 GNOMEUIINFO_END
481 GnomeUIInfo gnome_panel_menu_without_desktop [] = {
482 GNOMEUIINFO_MENU_FILE_TREE(gnome_panel_file_menu),
483 GNOMEUIINFO_MENU_EDIT_TREE(gnome_panel_edit_menu),
484 GNOMEUIINFO_SUBTREE(N_("_Settings"),gnome_panel_settings_menu),
485 GNOMEUIINFO_SUBTREE(N_("_Layout"),gnome_panel_layout_menu),
486 GNOMEUIINFO_SUBTREE(N_("_Commands"),gnome_panel_commands_menu),
487 GNOMEUIINFO_SUBTREE(N_("_Help"), gnome_panel_about_menu),
488 GNOMEUIINFO_END
491 GtkCheckMenuItem *
492 gnome_toggle_snap (void)
494 return NULL; /*GTK_CHECK_MENU_ITEM (gnome_panel_desktop_menu [1].widget);*/
497 void
498 gnome_init_panels (void)
500 current_panel_ptr = NULL;
501 other_panel_ptr = NULL;
504 static int
505 gnome_close_panel_event (GtkWidget *widget, GdkEvent *event, WPanel *panel)
507 gnome_close_panel (widget, panel);
508 return TRUE;
511 static void
512 panel_enter_event (GtkWidget *widget, GdkEvent *event, WPanel *panel)
514 /* Avoid unnecessary code execution */
515 if (get_current_panel () == panel)
516 return;
518 set_current_panel (panel);
519 dlg_select_widget (panel->widget.parent, panel);
520 send_message (panel->widget.parent, (Widget *) panel, WIDGET_FOCUS, 0);
523 void
524 destroy_gde (GtkWidget *unused, void *data)
526 gnome_desktop_entry_free ((GnomeDesktopEntry *) (data));
529 gint
530 create_new_menu_from (char *file, GtkWidget *shell, gint pos)
532 DIR *dir;
533 struct stat filedata;
534 gboolean add_separator = TRUE;
535 struct dirent *dirstruc;
536 GnomeDesktopEntry *gde;
537 GtkWidget *menu;
538 char *file2;
540 g_return_val_if_fail (shell != NULL, pos);
542 dir = opendir (file);
543 if (dir == NULL)
544 return pos;
546 if (shell == NULL){
547 closedir (dir);
548 return pos;
551 while ((dirstruc = readdir (dir)) != NULL){
552 if (dirstruc->d_name[0] == '.')
553 continue;
555 file2 = g_concat_dir_and_file (file, dirstruc->d_name);
557 if ((stat (file2, &filedata) != -1) && (S_ISREG (filedata.st_mode))){
558 char *path;
559 int len;
560 const int desktoplen = sizeof (".desktop") - 1;
562 len = strlen (dirstruc->d_name);
563 if (strcmp (dirstruc->d_name + len - desktoplen, ".desktop") != 0) {
564 g_free (file2);
565 continue;
568 gde = gnome_desktop_entry_load (file2);
569 if (gde == NULL) {
570 g_free (file2);
571 continue;
574 path = gnome_is_program_in_path (gde->tryexec);
575 g_free (path);
576 if (!path){
577 gnome_desktop_entry_free (gde);
578 g_free (file2);
579 continue;
582 if (add_separator) {
583 menu = gtk_menu_item_new ();
584 gtk_widget_show (menu);
585 gtk_menu_shell_insert (GTK_MENU_SHELL (shell), menu, pos++);
586 add_separator = !add_separator;
589 menu = gtk_menu_item_new_with_label (gde->name);
590 gtk_widget_show (menu);
591 gtk_menu_shell_insert (GTK_MENU_SHELL (shell), menu, pos++);
593 /* This is really bad, but it works. */
594 /* FIXME: it doesn't work if we free the gde below. --
595 * need to do this right sometime -jrb
597 if (gde->comment)
598 gtk_object_set_data (GTK_OBJECT (menu),
599 "apphelper_statusbar_hint",
600 gde->comment);
601 gtk_signal_connect (GTK_OBJECT (menu), "activate",
602 GTK_SIGNAL_FUNC (gnome_run_new),
603 gde);
604 gtk_signal_connect (GTK_OBJECT (menu), "destroy",
605 GTK_SIGNAL_FUNC (destroy_gde),
606 gde);
608 g_free (file2);
610 closedir (dir);
612 return pos;
616 * create_new_menu:
618 * Creates the child New menu items
620 static void
621 create_new_menu (GnomeApp *app, WPanel *panel)
623 gchar *file, *file2;
624 gint pos;
625 GtkWidget *shell;
627 shell = gnome_app_find_menu_pos (app->menubar, _("File/New/Directory..."), &pos);
629 file = gnome_unconditional_datadir_file ("mc/templates");
630 pos = create_new_menu_from (file, shell, pos);
632 file2 = gnome_datadir_file ("mc/templates");
633 if (file2 != NULL){
634 if (strcmp (file, file2) != 0)
635 create_new_menu_from (file2, shell, pos);
638 g_free (file);
639 g_free (file2);
643 * This routine is a menu relay.
645 * This is called before the actual command specified in the GnomeUIInfo
646 * structure. This allows me to select the panel (ie, set the global cpanel
647 * variable to which this menu is bound).
649 * This is important, as we can have a menu tearoffed. And the current hack
650 * of setting cpanel on the focus-in event wont work.
653 static void
654 panel_menu_relay (GtkObject *object, WPanel *panel)
656 void (*real_func)(GtkObject *object, WPanel *panel);
658 real_func = gtk_object_get_user_data (object);
659 set_current_panel (panel);
660 (*real_func)(object, panel);
663 static void
664 my_menu_signal_connect (GnomeUIInfo *uiinfo, gchar *signal_name,
665 GnomeUIBuilderData *uibdata)
667 gtk_object_set_user_data (GTK_OBJECT (uiinfo->widget), uiinfo->moreinfo);
668 gtk_signal_connect (GTK_OBJECT (uiinfo->widget),
669 signal_name, panel_menu_relay, uibdata->data ?
670 uibdata->data : uiinfo->user_data);
673 static void
674 my_app_create_menus (GnomeApp *app, GnomeUIInfo *uiinfo, void *data)
676 GnomeUIBuilderData uibdata;
678 g_return_if_fail (app != NULL);
679 g_return_if_fail (GNOME_IS_APP (app));
680 g_return_if_fail (uiinfo != NULL);
682 uibdata.connect_func = my_menu_signal_connect;
683 uibdata.data = data;
684 uibdata.is_interp = FALSE;
685 uibdata.relay_func = NULL;
686 uibdata.destroy_func = NULL;
688 gnome_app_create_menus_custom (app, uiinfo, &uibdata);
692 * copy_uiinfo_widgets:
693 * @uiinfo: A GnomeUIInfo array
695 * Allocates an array of widgets and copies the widgets from the uiinfo array to
696 * it. The array will be NULL-terminated.
698 * Returns: The allocated array of widgets.
700 gpointer *
701 copy_uiinfo_widgets (GnomeUIInfo *uiinfo)
703 gpointer *dest;
704 int n;
705 int i;
707 g_return_val_if_fail (uiinfo != NULL, NULL);
709 /* Count number of items */
711 for (n = 0; uiinfo[n].type != GNOME_APP_UI_ENDOFINFO; n++);
713 /* Copy the widgets */
715 dest = g_new (gpointer, n + 1);
717 for (i = 0; i < n; i++)
718 dest[i] = uiinfo[i].widget;
720 dest[i] = NULL;
722 return dest;
725 WPanel *
726 create_container (Dlg_head *h, const char *name, const char *geometry)
728 PanelContainer *container;
729 WPanel *panel;
730 GtkWidget *app, *vbox;
731 int xpos, ypos, width, height;
732 GnomeUIInfo *uiinfo;
733 char buf[50];
735 container = g_new (PanelContainer, 1);
737 gnome_parse_geometry (geometry, &xpos, &ypos, &width, &height);
739 container->splitted = 0;
740 app = gnome_app_new ("gmc", name);
742 /* Geometry configuration */
743 if (width != -1 && height != -1)
744 gtk_window_set_default_size (GTK_WINDOW (app), width, height);
745 else
746 gtk_window_set_default_size (GTK_WINDOW (app), 540, 360);
748 if (xpos != -1 && ypos != -1)
749 gtk_widget_set_uposition (GTK_WIDGET (app), xpos, ypos);
751 panel = panel_new (name);
753 /* Set the unique name for session management */
755 sprintf (buf, "%d", panel->id);
756 gtk_window_set_wmclass (GTK_WINDOW (app), "gmc", buf);
758 /* Create the holder for the contents */
760 vbox = gtk_vbox_new (FALSE, 0);
761 gtk_container_set_border_width (GTK_CONTAINER (vbox), 0);
762 gnome_app_set_contents (GNOME_APP (app), vbox);
764 if (desktop_wm_is_gnome_compliant == 1)
765 uiinfo = gnome_panel_menu_without_desktop;
766 else
767 uiinfo = gnome_panel_menu_with_desktop;
769 my_app_create_menus (GNOME_APP (app), uiinfo, panel);
770 panel->view_menu_items = copy_uiinfo_widgets (panel_view_menu_uiinfo);
772 create_new_menu (GNOME_APP (app), panel);
774 panel->ministatus = GNOME_APPBAR(gnome_appbar_new(FALSE, TRUE, GNOME_PREFERENCES_NEVER));
775 gnome_app_set_statusbar(GNOME_APP (app), GTK_WIDGET(panel->ministatus));
777 if (desktop_wm_is_gnome_compliant)
778 gnome_app_install_menu_hints (GNOME_APP (app), gnome_panel_menu_without_desktop);
779 else
780 gnome_app_install_menu_hints (GNOME_APP (app), gnome_panel_menu_with_desktop);
782 gtk_signal_connect (GTK_OBJECT (app),
783 "enter_notify_event",
784 GTK_SIGNAL_FUNC (panel_enter_event),
785 panel);
786 gtk_signal_connect (GTK_OBJECT (app),
787 "delete_event",
788 GTK_SIGNAL_FUNC (gnome_close_panel_event),
789 panel);
790 /* Ultra nasty hack follows:
791 * I am setting the panel->widget.wdata value here before the
792 * panel X stuff gets created in the INIT message section of the
793 * widget. There I put a pointer to the vbox where the panel
794 * should pack itself
796 panel->widget.wdata = (widget_data) vbox;
797 container->panel = panel;
799 containers = g_list_append (containers, container);
801 if (!current_panel_ptr){
802 current_panel_ptr = container;
803 } else if (!other_panel_ptr)
804 other_panel_ptr = container;
806 bind_gtk_keys (GTK_WIDGET (app), h);
807 return panel;
810 WPanel *
811 new_panel_with_geometry_at (const char *dir, const char *geometry)
813 WPanel *panel;
815 mc_chdir ((char *) dir);
816 panel = create_container (desktop_dlg, dir, geometry);
817 set_current_panel (panel);
818 add_widget (desktop_dlg, panel);
819 #if 0
820 x_flush_events ();
821 #endif
823 return panel;
826 WPanel *
827 new_panel_at (const char *dir)
829 return new_panel_with_geometry_at (dir, NULL);
832 void
833 setup_panels (void)
835 load_hint ();
839 * GNOME's implementation of the update_panels routine
841 void
842 update_panels (int force_update, char *current_file)
844 int reload_others = !(force_update & UP_ONLY_CURRENT);
845 GList *p;
847 /* Test if there are panels open */
848 if (!cpanel)
849 return;
851 if (!is_a_desktop_panel (cpanel))
852 update_one_panel_widget (cpanel, force_update, current_file);
854 if (reload_others){
855 for (p = containers; p; p = p->next){
856 PanelContainer *pc = p->data;
858 if (p->data == current_panel_ptr)
859 continue;
861 if (!is_a_desktop_panel (pc->panel))
862 update_one_panel_widget (pc->panel, force_update, UP_KEEPSEL);
865 mc_chdir (cpanel->cwd);