]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiInfo.cpp
Inset::validateModifyArgument(): new virtual interface for using LFUN_INSET_MODIFY.
[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 #include "FuncRequest.h"
23
24 #include "insets/InsetInfo.h"
25
26 #include "support/debug.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", "" };
44
45 char const * info_types_gui[] =
46 { N_("unknown"), N_("shortcut"), N_("shortcuts"), N_("lyxrc"), N_("package"), N_("textclass"),
47   N_("menu"), N_("icon"), N_("buffer"), ""};
48
49
50 GuiInfo::GuiInfo(GuiView & lv)
51         : InsetDialog(lv, INFO_CODE, "info", qt_("Info"))
52 {
53         setupUi(this);
54
55         typeCO->blockSignals(true);
56         for (int n = 0; info_types[n][0]; ++n)
57                 typeCO->addItem(qt_(info_types_gui[n]));
58         typeCO->blockSignals(false);
59 }
60
61
62 void GuiInfo::on_newPB_clicked()
63 {
64         // FIXME: if we used a standard LFUN_INSET_INSERT command,
65         // This slot could be transferred to InsetDialog.
66         docstring const argument = dialogToParams();
67         dispatch(FuncRequest(LFUN_INFO_INSERT, argument));
68 }
69
70
71 void GuiInfo::on_typeCO_currentIndexChanged(int)
72 {
73         applyView();
74 }
75
76
77 void GuiInfo::on_nameLE_textChanged(QString const &)
78 {
79         applyView();
80 }
81
82
83 void GuiInfo::paramsToDialog(Inset const * inset)
84 {
85         InsetInfo const * ii = static_cast<InsetInfo const *>(inset);
86         QString const type = toqstr(ii->infoType());
87         QString const name = toqstr(ii->infoName());
88         typeCO->blockSignals(true);
89         nameLE->blockSignals(true);
90         int type_index = findToken(info_types, fromqstr(type));
91         typeCO->setCurrentIndex(type_index >= 0 ? type_index : 0);
92         // Without this test, 'math-insert' (name) will replace 'math-insert '
93         // in nameLE and effectively disallow the input of spaces after a LFUN.
94         if (nameLE->text().trimmed() != name)
95                 nameLE->setText(name);
96         typeCO->blockSignals(false);
97         nameLE->blockSignals(false);
98 }
99
100
101 docstring GuiInfo::dialogToParams() const
102 {
103         int type_index = typeCO->currentIndex();
104         QString type;
105         if (type_index != -1)
106                 type = info_types[type_index];
107         QString const name = nameLE->text();
108         return qstring_to_ucs4(type + ' ' + name);
109 }
110
111
112 void GuiInfo::enableView(bool enable)
113 {
114         typeCO->setEnabled(enable);
115         nameLE->setEnabled(enable);
116         newPB->setEnabled(!enable);
117 }
118
119
120 Dialog * createGuiInfo(GuiView & lv) { return new GuiInfo(lv); }
121
122
123 } // namespace frontend
124 } // namespace lyx
125
126 #include "moc_GuiInfo.cpp"