f0cc137b7d08b581ce98aa38a7f555ecddc41498
[synfig.git] / synfig-studio / trunk / 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 #include "general.h"
38
39 #endif
40
41 /* === U S I N G =========================================================== */
42
43 using namespace std;
44 //using namespace etl;
45 //using namespace synfig;
46 using namespace studio;
47
48 /* === M A C R O S ========================================================= */
49
50 /* === G L O B A L S ======================================================= */
51
52 /* === P R O C E D U R E S ================================================= */
53
54 /* === M E T H O D S ======================================================= */
55
56 Widget_Filename::Widget_Filename()
57 {
58         entry_filename=manage(new Gtk::Entry());
59         button_choose=manage(new Gtk::Button(_("Find")));
60
61         pack_start(*entry_filename);
62         pack_start(*button_choose);
63         entry_filename->show();
64         button_choose->show();
65
66         button_choose->signal_clicked().connect(sigc::mem_fun(*this, &studio::Widget_Filename::on_button_choose_pressed));
67         //entry_filename->signal_value_changed().connect(sigc::mem_fun(*this, &studio::Widget_Filename::on_value_changed));
68         entry_filename->signal_activate().connect(sigc::mem_fun(*this, &studio::Widget_Filename::on_value_changed));
69 }
70
71 Widget_Filename::~Widget_Filename()
72 {
73 }
74
75 void
76 Widget_Filename::set_has_frame(bool x)
77 {
78         entry_filename->set_has_frame(x);
79 }
80
81
82 void
83 Widget_Filename::set_value(const std::string &data)
84 {
85         entry_filename->set_text(data);
86 }
87
88 string
89 Widget_Filename::get_value() const
90 {
91         try
92         {
93                 return entry_filename->get_text();
94         }
95         catch(...)
96         {
97                 throw string("Caught unknown exception");
98         }
99 }
100
101 void
102 Widget_Filename::on_value_changed()
103 {
104         signal_value_changed()();
105 }
106
107 void
108 Widget_Filename::on_button_choose_pressed()
109 {
110         string filename=entry_filename->get_text();
111         if(filename.empty())
112                 filename=".";
113         if(App::dialog_open_file(_("Choose File"), filename, MISC_DIR_PREFERENCE))
114                 entry_filename->set_text(filename);
115 }