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