2 * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
4 * Copyright (C) 2003-2005, Evan Battaglia <gtoevan@gmx.net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "vikfileentry.h"
26 static void choose_file ( VikFileEntry
*vfe
);
28 struct _VikFileEntry
{
30 GtkWidget
*entry
, *button
;
31 GtkWidget
*file_selector
;
34 GType
vik_file_entry_get_type (void)
36 static GType vs_type
= 0;
40 static const GTypeInfo vs_info
=
42 sizeof (VikFileEntryClass
),
44 NULL
, /* base_finalize */
45 NULL
, /* class init */
46 NULL
, /* class_finalize */
47 NULL
, /* class_data */
48 sizeof (VikFileEntry
),
50 NULL
/* instance init */
52 vs_type
= g_type_register_static ( GTK_TYPE_HBOX
, "VikFileEntry", &vs_info
, 0 );
58 GtkWidget
*vik_file_entry_new ()
60 VikFileEntry
*vfe
= VIK_FILE_ENTRY ( g_object_new ( VIK_FILE_ENTRY_TYPE
, NULL
) );
61 vfe
->entry
= gtk_entry_new ();
62 vfe
->button
= gtk_button_new_with_label ( "Browse..." );
63 g_signal_connect_swapped ( G_OBJECT(vfe
->button
), "clicked", G_CALLBACK(choose_file
), vfe
);
65 gtk_box_pack_start ( GTK_BOX(vfe
), vfe
->entry
, TRUE
, TRUE
, 3 );
66 gtk_box_pack_start ( GTK_BOX(vfe
), vfe
->button
, FALSE
, FALSE
, 3 );
68 vfe
->file_selector
= NULL
;
70 return GTK_WIDGET(vfe
);
73 G_CONST_RETURN gchar
*vik_file_entry_get_filename ( VikFileEntry
*vfe
)
75 return gtk_entry_get_text ( GTK_ENTRY(vfe
->entry
) );
78 void vik_file_entry_set_filename ( VikFileEntry
*vfe
, const gchar
*filename
)
80 gtk_entry_set_text ( GTK_ENTRY(vfe
->entry
), filename
);
83 static void choose_file ( VikFileEntry
*vfe
)
85 if ( ! vfe
->file_selector
)
88 g_assert ( (win
= gtk_widget_get_toplevel(GTK_WIDGET(vfe
))) );
89 vfe
->file_selector
= gtk_file_selection_new ("Choose file");
90 gtk_window_set_transient_for ( GTK_WINDOW(vfe
->file_selector
), GTK_WINDOW(win
) );
91 gtk_window_set_destroy_with_parent ( GTK_WINDOW(vfe
->file_selector
), TRUE
);
94 if ( gtk_dialog_run ( GTK_DIALOG(vfe
->file_selector
) ) == GTK_RESPONSE_OK
)
95 gtk_entry_set_text ( GTK_ENTRY (vfe
->entry
), gtk_file_selection_get_filename ( GTK_FILE_SELECTION(vfe
->file_selector
) ) );
96 gtk_widget_hide ( vfe
->file_selector
);