1e94ef7023028041aba64d0703f97da4c6659355
[synfig.git] / synfig-studio / src / gui / 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 #include "canvasview.h"
38
39 #include "general.h"
40
41 #endif
42
43 /* === U S I N G =========================================================== */
44
45 using namespace std;
46 //using namespace etl;
47 //using namespace synfig;
48 using namespace studio;
49
50 /* === M A C R O S ========================================================= */
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         label_find= manage(new Gtk::Label(_("Find")));
62         button_choose=manage(new Gtk::Button());
63         Pango::AttrList attr_list;
64         {
65                 Pango::AttrInt pango_size(Pango::Attribute::create_attr_size(Pango::SCALE*7));
66                 pango_size.set_start_index(0);
67                 pango_size.set_end_index(64);
68                 attr_list.change(pango_size);
69         }
70         label_find->set_attributes(attr_list);
71         label_find->set_ellipsize(Pango::ELLIPSIZE_END);
72         button_choose->add(*label_find);
73
74         pack_start(*entry_filename);
75         pack_start(*button_choose);
76         entry_filename->show();
77         button_choose->show();
78         label_find->show();
79
80         button_choose->signal_clicked().connect(sigc::mem_fun(*this, &studio::Widget_Filename::on_button_choose_pressed));
81         //entry_filename->signal_value_changed().connect(sigc::mem_fun(*this, &studio::Widget_Filename::on_value_changed));
82         entry_filename->signal_activate().connect(sigc::mem_fun(*this, &studio::Widget_Filename::on_value_changed));
83 }
84
85 Widget_Filename::~Widget_Filename()
86 {
87 }
88
89 void
90 Widget_Filename::set_has_frame(bool x)
91 {
92         entry_filename->set_has_frame(x);
93 }
94
95
96 void
97 Widget_Filename::set_value(const std::string &data)
98 {
99         entry_filename->set_text(data);
100 }
101
102 string
103 Widget_Filename::get_value() const
104 {
105         try
106         {
107                 return entry_filename->get_text();
108         }
109         catch(...)
110         {
111                 throw string("Caught unknown exception");
112         }
113 }
114
115 void
116 Widget_Filename::on_value_changed()
117 {
118         signal_value_changed()();
119 }
120
121 void
122 Widget_Filename::on_button_choose_pressed()
123 {
124         string filename=entry_filename->get_text();
125         if(filename.empty())
126                 filename=".";
127         else
128                 filename = etl::absolute_path(
129                         etl::dirname(App::get_selected_canvas_view()->get_canvas()->get_file_name()) +
130                         ETL_DIRECTORY_SEPARATOR +
131                         filename);
132         if(App::dialog_open_file(_("Choose File"), filename, MISC_DIR_PREFERENCE))
133                 entry_filename->set_text(filename);
134 }