]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/ghelpers.C
Change glob() API to accept a dir parameter.
[lyx.git] / src / frontends / gtk / ghelpers.C
1 /**
2  * \file ghelpers.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming
7  * \author John Spray
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 // Too hard to make concept checks work with this file
15 #ifdef _GLIBCPP_CONCEPT_CHECKS
16 #undef _GLIBCPP_CONCEPT_CHECKS
17 #endif
18
19 #include "ghelpers.h"
20
21 #include "lyxrc.h"
22 #include "funcrequest.h"
23 #include "debug.h"
24
25 #include "support/filetools.h"
26 #include "support/path_defines.h"
27
28 using std::string;
29 using std::vector;
30
31 namespace lyx {
32 namespace frontend {
33
34 Gtk::BuiltinStockID getGTKStockIcon(FuncRequest const & func)
35 {
36         switch (func.action) {
37
38                 case LFUN_MENUWRITE: return Gtk::Stock::SAVE;
39                 case LFUN_MENUNEW: return Gtk::Stock::NEW;
40                 case LFUN_WRITEAS: return Gtk::Stock::SAVE_AS;
41
42                 case LFUN_CENTER: return Gtk::Stock::JUSTIFY_CENTER;
43                 case LFUN_TOCVIEW: return Gtk::Stock::INDEX;
44                 case LFUN_CLOSEBUFFER: return Gtk::Stock::CLOSE;
45                 case LFUN_QUIT: return Gtk::Stock::QUIT;
46                 case LFUN_UNDO: return Gtk::Stock::UNDO;
47                 case LFUN_REDO: return Gtk::Stock::REDO;
48                 case LFUN_PASTE: return Gtk::Stock::PASTE;
49                 case LFUN_PASTESELECTION: return Gtk::Stock::PASTE;
50                 case LFUN_CUT: return Gtk::Stock::CUT;
51                 case LFUN_COPY: return Gtk::Stock::COPY;
52                 case LFUN_BOLD: return Gtk::Stock::BOLD;
53                 case LFUN_ITAL: return Gtk::Stock::ITALIC;
54                 case LFUN_FILE_OPEN: return Gtk::Stock::OPEN;
55                 case LFUN_RECONFIGURE: return Gtk::Stock::REFRESH;
56                 case LFUN_DIALOG_SHOW:
57                         if (func.argument == "findreplace")
58                                 return Gtk::Stock::FIND_AND_REPLACE;
59                         else if (func.argument == "print")
60                                 return Gtk::Stock::PRINT;
61                         else if (func.argument == "spellchecker")
62                                 return Gtk::Stock::SPELL_CHECK;
63                         else if (func.argument == "prefs")
64                                 return Gtk::Stock::PREFERENCES;
65                         else
66                                 return Gtk::Stock::MISSING_IMAGE;
67                         break;
68                 default: return Gtk::Stock::MISSING_IMAGE;
69         }
70 }
71
72 string const getDefaultUnit()
73 {
74         switch (lyxrc.default_papersize) {
75                 case PAPER_DEFAULT: return "cm";
76                 case PAPER_USLETTER:
77                 case PAPER_LEGALPAPER:
78                 case PAPER_EXECUTIVEPAPER: return "in"; break;
79                 case PAPER_A3PAPER:
80                 case PAPER_A4PAPER:
81                 case PAPER_A5PAPER:
82                 case PAPER_B5PAPER: return "cm"; break;
83         }
84 }
85
86
87 void unitsComboFromLength(Gtk::ComboBox * combo,
88                            Gtk::TreeModelColumn<Glib::ustring> const & stringcol,
89                            LyXLength const & len,
90                            std::string defunit)
91 {
92         string unit = stringFromUnit(len.unit());
93         if (unit.empty())
94                 unit = defunit;
95
96         Gtk::TreeModel::iterator it = combo->get_model()->children().begin();
97         Gtk::TreeModel::iterator end = combo->get_model()->children().end();
98         for (; it != end ; ++it) {
99                 if ((*it)[stringcol] == unit) {
100                         combo->set_active(it);
101                         return;
102                 }
103         }
104
105         // Fallen through, we didn't find the target length!
106         combo->set_active(0);
107         lyxerr << "unitsComboFromLength: couldn't find "
108                 "target unit '" << unit << "'\n";
109 }
110
111
112 vector<string> const buildLengthUnitList()
113 {
114         vector<string> data(unit_name_gui, unit_name_gui + num_units);
115
116         return data;
117 }
118
119
120 vector<string> const buildLengthNoRelUnitList()
121 {
122         vector<string> data;
123         for (int i = 0; i < num_units; ++i) {
124                 string str(unit_name_gui[i]);
125                 if (str.find("%") == -1)
126                         data.push_back(unit_name_gui[i]);
127         }
128
129         return data;
130 }
131
132
133 string const findGladeFile(string const & name)
134 {
135         // First, search in the installation directories.
136
137         string filename = lyx::support::LibFileSearch("glade", name, "glade");
138
139         if (!filename.empty())
140                 return filename;
141
142         // Second, search in the src tree.
143         string const dir =
144                 lyx::support::AddPath(lyx::support::top_srcdir(),
145                                       "src/frontends/gtk/glade");
146
147         filename = lyx::support::ChangeExtension(name, ".glade");
148         filename = lyx::support::AddName(dir, filename);
149
150         if (!lyx::support::IsFileReadable(filename)) {
151                 lyxerr << "Unable to find glade file \"" << name
152                        << "\". libglade is going to crash..." << std::endl;
153         }
154
155         return filename;
156 }
157
158 } // namespace frontend
159 } // namespace lyx