Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-studio / tags / synfigstudio_0_61_07 / src / gtkmm / widget_filename.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file widget_filename.cpp
3 **      \brief Template File
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **
10 **      This package is free software; you can redistribute it and/or
11 **      modify it under the terms of the GNU General Public License as
12 **      published by the Free Software Foundation; either version 2 of
13 **      the License, or (at your option) any later version.
14 **
15 **      This package is distributed in the hope that it will be useful,
16 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
17 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 **      General Public License for more details.
19 **      \endlegal
20 */
21 /* ========================================================================= */
22
23 /* === H E A D E R S ======================================================= */
24
25 #ifdef USING_PCH
26 #       include "pch.h"
27 #else
28 #ifdef HAVE_CONFIG_H
29 #       include <config.h>
30 #endif
31
32 #include <gtkmm/entry.h>
33 #include <gtkmm/button.h>
34 #include "widget_filename.h"
35 #include "app.h"
36
37 #endif
38
39 /* === U S I N G =========================================================== */
40
41 using namespace std;
42 //using namespace etl;
43 //using namespace synfig;
44 using namespace studio;
45
46 /* === M A C R O S ========================================================= */
47
48 #if ! defined(_)
49 #define _(x)    (x)
50 #endif
51
52 /* === G L O B A L S ======================================================= */
53
54 /* === P R O C E D U R E S ================================================= */
55
56 /* === M E T H O D S ======================================================= */
57
58 Widget_Filename::Widget_Filename()
59 {
60         entry_filename=manage(new Gtk::Entry());
61         button_choose=manage(new Gtk::Button(_("Find")));
62
63         pack_start(*entry_filename);
64         pack_start(*button_choose);
65         entry_filename->show();
66         button_choose->show();
67
68         button_choose->signal_clicked().connect(sigc::mem_fun(*this, &studio::Widget_Filename::on_button_choose_pressed));
69         //entry_filename->signal_value_changed().connect(sigc::mem_fun(*this, &studio::Widget_Filename::on_value_changed));
70         entry_filename->signal_activate().connect(sigc::mem_fun(*this, &studio::Widget_Filename::on_value_changed));
71 }
72
73 Widget_Filename::~Widget_Filename()
74 {
75 }
76
77 void
78 Widget_Filename::set_has_frame(bool x)
79 {
80         entry_filename->set_has_frame(x);
81 }
82
83
84 void
85 Widget_Filename::set_value(const string &data)
86 {
87         entry_filename->set_text(data);
88 }
89
90 string
91 Widget_Filename::get_value() const
92 {
93         try
94         {
95                 return entry_filename->get_text();
96         }
97         catch(...)
98         {
99                 throw string("Caught unknown exception");
100         }
101 }
102
103 void
104 Widget_Filename::on_value_changed()
105 {
106         signal_value_changed()();
107 }
108
109 void
110 Widget_Filename::on_button_choose_pressed()
111 {
112         string filename=entry_filename->get_text();
113         if(filename.empty())
114                 filename=".";
115         if(App::dialog_open_file(_("Choose File"),filename))
116                 entry_filename->set_text(filename);
117 }