]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/GSendto.C
Change glob() API to accept a dir parameter.
[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 // Too hard to make concept checks work with this file
14 #ifdef _GLIBCPP_CONCEPT_CHECKS
15 #undef _GLIBCPP_CONCEPT_CHECKS
16 #endif
17
18 #include "GSendto.h"
19 #include "ControlSendto.h"
20 #include "ghelpers.h"
21
22 #include "format.h"
23
24 #include <libglademm.h>
25
26 using std::string;
27 using std::vector;
28
29 namespace lyx {
30 namespace frontend {
31
32 GSendto::GSendto(Dialog & parent)
33         : GViewCB<ControlSendto, GViewGladeB>(parent, _("Send document to command"), false)
34 {}
35
36
37 void GSendto::doBuild()
38 {
39         string const gladeName = findGladeFile("sendto");
40         xml_ = Gnome::Glade::Xml::create(gladeName);
41
42         Gtk::Button * button;
43         xml_->get_widget("Close", button);
44         setCancel(button);
45         xml_->get_widget("Execute", button);
46         setOK(button);
47
48         xml_->get_widget("Format", formatview_);
49         xml_->get_widget("Command", commandentry_);
50
51         cols_.add(stringcol_);
52         cols_.add(indexcol_);
53
54         formatstore_ = Gtk::ListStore::create(cols_);
55         formatview_->set_model(formatstore_);
56         formatview_->append_column("Format", stringcol_);
57         formatview_->get_selection()->set_mode(Gtk::SELECTION_BROWSE);
58
59         commandentry_->signal_changed().connect(
60                 sigc::mem_fun(*this, &GSendto::onCommandEntryChanged));
61 }
62
63
64 void GSendto::onCommandEntryChanged()
65 {
66         bc().valid(!commandentry_->get_text().empty());
67 }
68
69
70 void GSendto::update()
71 {
72         vector<Format const *> new_formats;
73         new_formats = controller().allFormats();
74
75         if (new_formats == all_formats_)
76                 return;
77
78         all_formats_ = new_formats;
79
80         vector<string> keys;
81         keys.resize(all_formats_.size());
82
83         vector<string>::iterator result = keys.begin();
84         vector<Format const *>::const_iterator it  = all_formats_.begin();
85         vector<Format const *>::const_iterator end = all_formats_.end();
86         for (; it != end; ++it, ++result) {
87                 *result = (*it)->prettyname();
88         }
89
90         formatstore_->clear();
91
92         vector<string>::const_iterator keyend = keys.end();
93         vector<string>::const_iterator keyit = keys.begin();
94         for (int rowindex = 0;
95              keyit < keyend; ++keyit, ++rowindex) {
96                 Gtk::TreeModel::iterator row = formatstore_->append();
97                 (*row)[stringcol_] = *keyit;
98                 (*row)[indexcol_] = rowindex;
99         }
100
101         commandentry_->set_text(controller().getCommand());
102 }
103
104
105 void GSendto::apply()
106 {
107         int const line =
108                 (*formatview_->get_selection()->get_selected())[indexcol_];
109
110         string const cmd = commandentry_->get_text();
111
112         controller().setFormat(all_formats_[line]);
113         controller().setCommand(cmd);
114 }
115
116 } // namespace frontend
117 } // namespace lyx