]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/GSendto.C
gtk sendto dialog
[lyx.git] / src / frontends / gtk / GSendto.C
1 /**
2  * \file GSendto.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Spray
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "GSendto.h"
14 #include "ControlSendto.h"
15 #include "ghelpers.h"
16
17 #include "format.h"
18
19 #include <libglademm.h>
20
21 using std::string;
22 using std::vector;
23
24 namespace lyx {
25 namespace frontend {
26
27 GSendto::GSendto(Dialog & parent)
28         : GViewCB<ControlSendto, GViewGladeB>(parent, _("Send document to command"), false)
29 {}
30
31
32 void GSendto::doBuild()
33 {
34         string const gladeName = findGladeFile("sendto");
35         xml_ = Gnome::Glade::Xml::create(gladeName);
36
37         Gtk::Button * button;
38         xml_->get_widget("Close", button);
39         setCancel(button);
40         xml_->get_widget("Execute", button);
41         setOK(button);
42
43         xml_->get_widget("Format", formatview_);
44         xml_->get_widget("Command", commandentry_);
45
46         cols_.add(stringcol_);
47         cols_.add(indexcol_);
48
49         formatstore_ = Gtk::ListStore::create(cols_);
50         formatview_->set_model(formatstore_);
51         formatview_->append_column("Format", stringcol_);
52         formatview_->get_selection()->set_mode(Gtk::SELECTION_BROWSE);
53
54         commandentry_->signal_changed().connect(
55                 sigc::mem_fun(*this, &GSendto::onCommandEntryChanged));
56 }
57
58
59 void GSendto::onCommandEntryChanged()
60 {
61         bc().valid(!commandentry_->get_text().empty());
62 }
63
64
65 void GSendto::update()
66 {
67         vector<Format const *> new_formats;
68         new_formats = controller().allFormats();
69
70         if (new_formats == all_formats_)
71                 return;
72
73         all_formats_ = new_formats;
74
75         vector<string> keys;
76         keys.resize(all_formats_.size());
77
78         vector<string>::iterator result = keys.begin();
79         vector<Format const *>::const_iterator it  = all_formats_.begin();
80         vector<Format const *>::const_iterator end = all_formats_.end();
81         for (; it != end; ++it, ++result) {
82                 *result = (*it)->prettyname();
83         }
84
85         formatstore_->clear();
86
87         vector<string>::const_iterator keyend = keys.end();
88         vector<string>::const_iterator keyit = keys.begin();
89         for (int rowindex = 0;
90              keyit < keyend; ++keyit, ++rowindex) {
91                 Gtk::TreeModel::iterator row = formatstore_->append();
92                 (*row)[stringcol_] = *keyit;
93                 (*row)[indexcol_] = rowindex;
94         }
95
96         commandentry_->set_text(controller().getCommand());
97 }
98
99
100 void GSendto::apply()
101 {
102         int const line =
103                 (*formatview_->get_selection()->get_selected())[indexcol_];
104
105         string const cmd = commandentry_->get_text();
106
107         controller().setFormat(all_formats_[line]);
108         controller().setCommand(cmd);
109 }
110
111 } // namespace frontend
112 } // namespace lyx