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