filename | src/gtkui/gtk_path.c |
changeset | 1036:af7b0c5905dd |
prev | 763:b3ce4448f200 |
next | 1041:5fcc39857c5c |
author | nkeynes |
date | Wed Jun 24 06:06:40 2009 +0000 (13 years ago) |
permissions | -rw-r--r-- |
last change | Support shell substitutions in config paths Keep track of last folder in file dialogs Fix out-of-dateness in GTK path dialog |
view | annotate | diff | log | raw |
1 /**
2 * $Id$
3 *
4 * Define the main (emu) GTK window, along with its menubars,
5 * toolbars, etc.
6 *
7 * Copyright (c) 2005 Nathan Keynes.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 */
20 #include <assert.h>
21 #include <gtk/gtk.h>
23 #include "lxdream.h"
24 #include "dreamcast.h"
25 #include "config.h"
26 #include "gtkui/gtkui.h"
28 static GtkWidget *path_entry[CONFIG_KEY_MAX];
30 static gboolean path_file_button_clicked( GtkWidget *button, gpointer user_data )
31 {
32 GtkWidget *entry = GTK_WIDGET(user_data);
33 GtkWidget *file = gtk_file_chooser_dialog_new( _("Select file"), NULL,
34 GTK_FILE_CHOOSER_ACTION_OPEN,
35 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
36 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
37 NULL );
38 gchar *filename = get_expanded_path(gtk_entry_get_text(GTK_ENTRY(entry)));
39 gtk_file_chooser_set_filename( GTK_FILE_CHOOSER(file), filename );
40 gtk_window_set_modal( GTK_WINDOW(file), TRUE );
41 gtk_widget_show_all( file );
42 gint result = gtk_dialog_run(GTK_DIALOG(file));
43 g_free(filename);
44 if( result == GTK_RESPONSE_ACCEPT ) {
45 filename = get_escaped_path(gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) ));
46 gtk_entry_set_text(GTK_ENTRY(entry), filename);
47 g_free(filename);
48 }
49 gtk_widget_destroy(file);
50 return TRUE;
51 }
53 static gboolean path_dir_button_clicked( GtkWidget *button, gpointer user_data )
54 {
55 GtkWidget *entry = GTK_WIDGET(user_data);
56 GtkWidget *file = gtk_file_chooser_dialog_new( _("Select file"), NULL,
57 GTK_FILE_CHOOSER_ACTION_OPEN,
58 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
59 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
60 NULL );
61 gchar *filename = get_expanded_path(gtk_entry_get_text(GTK_ENTRY(entry)));
62 gtk_file_chooser_set_action( GTK_FILE_CHOOSER(file), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER );
63 gtk_file_chooser_set_filename( GTK_FILE_CHOOSER(file), filename );
64 gtk_window_set_modal( GTK_WINDOW(file), TRUE );
65 gtk_widget_show_all( file );
66 gint result = gtk_dialog_run(GTK_DIALOG(file));
67 g_free(filename);
68 if( result == GTK_RESPONSE_ACCEPT ) {
69 filename = get_escaped_path(gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) ));
70 gtk_entry_set_text(GTK_ENTRY(entry), filename);
71 g_free(filename);
72 }
73 gtk_widget_destroy(file);
74 return TRUE;
75 }
77 GtkWidget *path_panel_new(void)
78 {
79 int i, y=0;
80 GtkWidget *table = gtk_table_new( CONFIG_KEY_MAX, 3, FALSE );
81 for( i=0; i<CONFIG_KEY_MAX; i++ ) {
82 const struct lxdream_config_entry *entry = lxdream_get_global_config_entry(i);
83 if( entry->label != NULL ) {
84 GtkWidget *text = path_entry[i] = gtk_entry_new();
85 GtkWidget *button = gtk_button_new();
86 gtk_table_attach( GTK_TABLE(table), gtk_label_new(Q_(entry->label)), 0, 1, y, y+1,
87 GTK_SHRINK, GTK_SHRINK, 0, 0);
88 gtk_entry_set_text( GTK_ENTRY(text), lxdream_get_global_config_value(i) );
89 gtk_entry_set_width_chars( GTK_ENTRY(text), 48 );
90 gtk_table_attach_defaults( GTK_TABLE(table), text, 1, 2, y, y+1 );
91 gtk_table_attach( GTK_TABLE(table), button, 2, 3, y, y+1, GTK_SHRINK, GTK_SHRINK, 0, 0 );
92 if( entry->type == CONFIG_TYPE_FILE ) {
93 GtkWidget *image = gtk_image_new_from_stock(GTK_STOCK_FILE, GTK_ICON_SIZE_MENU);
94 gtk_button_set_image( GTK_BUTTON(button), image );
95 g_signal_connect( button, "clicked", G_CALLBACK(path_file_button_clicked), text );
96 } else {
97 GtkWidget *image = gtk_image_new_from_stock(GTK_STOCK_DIRECTORY, GTK_ICON_SIZE_MENU);
98 gtk_button_set_image( GTK_BUTTON(button), image );
99 g_signal_connect( button, "clicked", G_CALLBACK(path_dir_button_clicked), text );
100 }
101 y++;
102 }
103 }
104 gtk_table_resize( GTK_TABLE(table), y, 3 );
105 return table;
107 }
109 void path_panel_done( GtkWidget *panel, gboolean isOK )
110 {
111 if( isOK ) {
112 int i;
113 for(i=0; i<CONFIG_KEY_MAX; i++ ) {
114 if( path_entry[i] != NULL ) {
115 const char *filename = gtk_entry_get_text( GTK_ENTRY(path_entry[i]) );
116 lxdream_set_global_config_value( i, filename );
117 }
118 }
120 lxdream_save_config();
121 dreamcast_config_changed();
122 gui_config_paths_changed();
123 gtk_gui_update();
124 }
125 }
127 void path_dialog_run( void )
128 {
129 gtk_gui_run_property_dialog( _("Path Settings"), path_panel_new(), path_panel_done );
130 }
.