]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiInfo.cpp
cafcca8634f7a69b54a04c65d784cb96af68bfa0
[lyx.git] / src / frontends / qt4 / GuiInfo.cpp
1 /**
2  * \file GuiInfo.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Abdelrazak Younes
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "GuiInfo.h"
14
15 #include "qt_helpers.h"
16
17 #include "Buffer.h"
18 #include "buffer_funcs.h"
19 #include "BufferParams.h"
20 #include "BufferView.h"
21 #include "Cursor.h"
22
23 #include "insets/InsetInfo.h"
24
25 #include "support/debug.h"
26 #include "support/gettext.h"
27 #include "support/lstrings.h"
28
29
30 using namespace std;
31 using namespace lyx::support;
32
33 namespace lyx {
34 namespace frontend {
35
36 /////////////////////////////////////////////////////////////////
37 //
38 // GuiInfo
39 //
40 /////////////////////////////////////////////////////////////////
41
42 char const * info_types[] =
43 { "unknown", "shortcut", "shortcuts", "lyxrc", "package", "textclass", "menu", "icon", "buffer", "vcs", "lyxinfo", "" };
44
45 char const * info_types_gui[] =
46 { N_("Unknown"), N_("Last Assigned Keyboard Shortcut"), N_("All Keyboard Shortcuts"),
47   N_("LyX Preferences Entry"),  N_("LaTeX Package Availability"), N_("LaTeX Class Availability"),
48   N_("LyX Menu Location"), N_("LyX Toolbar Icon"), N_("Document Information"),
49   N_("Version Control Information"), N_("LyX Application Information"), ""};
50
51 char const * info_name_gui[] =
52 { N_("Not Applicable"), N_("LyX Function"), N_("LyX Function"), N_("Preferences Key"),  N_("Package Name"),
53   N_("Class Name"), N_("LyX Function"), N_("LyX Function"), N_("Information"),
54   N_("Information"), N_("Information"), ""};
55
56 char const * info_tooltip[] =
57 { N_("Please select a valid type above"),
58   N_("Enter a function name such as 'math-insert \\alpha'. Please refer to Help > LyX Functions for a comprehensive list of functions. "
59      "The output is the most recently assigned keyboard shortcut for this function"),
60   N_("Enter a function name such as 'math-insert \\alpha'. Please refer to Help > LyX Functions for a comprehensive list of functions. "
61      "The output lists all possible keyboard shortcuts for this function"),
62   N_("Enter a LyX preferences key such as 'bind_file'. Please refer to src/LyXRC.h for available entries. "
63      "The output is the current setting of this preference."),
64   N_("Enter a LaTeX package name such as 'hyperref' (extension is optional). "
65      "The output will be 'Yes' (package available) or 'No' (package unavailable)."),
66   N_("Enter a LaTeX class name such as 'article' (extension is optional). "
67      "The output will be 'Yes' (class available) or 'No' (class unavailable)."),
68   N_("Enter a function name such as 'math-insert \\alpha'. Please refer to Help > LyX Functions for a comprehensive list of functions. "
69      "The output is the path to the function in the menu (using the current localization)."),
70   N_("Enter a function name such as 'math-insert \\alpha'. Please refer to Help > LyX Functions for a comprehensive list of functions. "
71      "The output is the toolbar icon for this function (using the active icon theme)."),
72   N_("Enter either 'name' (outputs the filename of the current document), 'path' (outputs the file path), or 'class' (outputs the text class)."),
73   N_("Enter either 'revision', 'tree-revision', 'author', 'time' or 'date'. If available, the respective version control information is output."),
74   N_("Currently supported information type: 'version' (outputs the current LyX version)."),
75   ""};
76
77
78 GuiInfo::GuiInfo(QWidget * parent) : InsetParamsWidget(parent)
79 {
80         setupUi(this);
81
82         typeCO->blockSignals(true);
83         for (int n = 0; info_types[n][0]; ++n)
84                 typeCO->addItem(qt_(info_types_gui[n]), info_types[n]);
85         typeCO->blockSignals(false);
86
87         connect(typeCO, SIGNAL(currentIndexChanged(int)), this, SIGNAL(changed()));
88         connect(nameLE, SIGNAL(textChanged(QString)), this, SIGNAL(changed()));
89 }
90
91
92 void GuiInfo::paramsToDialog(Inset const * inset)
93 {
94         InsetInfo const * ii = static_cast<InsetInfo const *>(inset);
95         QString const type = toqstr(ii->infoType());
96         QString const name = toqstr(ii->infoName());
97         typeCO->blockSignals(true);
98         nameLE->blockSignals(true);
99         int const i = typeCO->findData(type);
100         typeCO->setCurrentIndex(i);
101         // Without this test, 'math-insert' (name) will replace 'math-insert '
102         // in nameLE and effectively disallow the input of spaces after a LFUN.
103         if (nameLE->text().trimmed() != name)
104                 nameLE->setText(name);
105         typeCO->blockSignals(false);
106         nameLE->blockSignals(false);
107 }
108
109
110 docstring GuiInfo::dialogToParams() const
111 {
112         QString type =
113                 typeCO->itemData(typeCO->currentIndex()).toString();
114         QString const name = nameLE->text();
115         return qstring_to_ucs4(type + ' ' + name);
116 }
117
118
119 bool GuiInfo::checkWidgets(bool readonly) const
120 {
121         nameLE->setReadOnly(readonly);
122         typeCO->setEnabled(!readonly);
123         nameLA->setText(qt_(info_name_gui[typeCO->currentIndex()]) + toqstr(":"));
124         bool const type_enabled =
125                 typeCO->itemData(typeCO->currentIndex()).toString() != "unknown";
126         nameLA->setEnabled(type_enabled);
127         nameLE->setEnabled(type_enabled);
128         nameLE->setToolTip(qt_(info_tooltip[typeCO->currentIndex()]));
129
130         if (!InsetParamsWidget::checkWidgets())
131                 return false;
132         return !nameLE->text().isEmpty();
133 }
134
135
136 } // namespace frontend
137 } // namespace lyx
138
139 #include "moc_GuiInfo.cpp"