2008-06-05 15:08:46 +00:00
|
|
|
/**
|
|
|
|
* \file GuiInfo.cpp
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Abdelrazak Younes
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "GuiInfo.h"
|
|
|
|
|
|
|
|
#include "qt_helpers.h"
|
|
|
|
|
|
|
|
#include "Buffer.h"
|
|
|
|
#include "buffer_funcs.h"
|
|
|
|
#include "BufferParams.h"
|
|
|
|
#include "BufferView.h"
|
|
|
|
#include "Cursor.h"
|
|
|
|
#include "FuncRequest.h"
|
|
|
|
|
|
|
|
#include "insets/InsetInfo.h"
|
|
|
|
|
|
|
|
#include "support/debug.h"
|
2008-06-06 04:10:42 +00:00
|
|
|
#include "support/lstrings.h"
|
2008-06-05 15:08:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
2008-06-06 04:10:42 +00:00
|
|
|
using namespace lyx::support;
|
2008-06-05 15:08:46 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// GuiInfo
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////
|
|
|
|
|
2008-06-06 04:10:42 +00:00
|
|
|
char const * info_types[] =
|
|
|
|
{ "unknown", "shortcut", "shortcuts", "lyxrc", "package", "textclass", "menu", "icon", "buffer", "" };
|
|
|
|
|
|
|
|
char const * info_types_gui[] =
|
|
|
|
{ N_("unknown"), N_("shortcut"), N_("shortcuts"), N_("lyxrc"), N_("package"), N_("textclass"),
|
|
|
|
N_("menu"), N_("icon"), N_("buffer"), ""};
|
|
|
|
|
|
|
|
|
2008-06-05 15:08:46 +00:00
|
|
|
GuiInfo::GuiInfo(GuiView & lv)
|
|
|
|
: DialogView(lv, "info", qt_("Info"))
|
|
|
|
{
|
|
|
|
setupUi(this);
|
2008-06-06 04:10:42 +00:00
|
|
|
|
2008-06-06 08:45:58 +00:00
|
|
|
typeCO->blockSignals(true);
|
2008-06-06 04:10:42 +00:00
|
|
|
for (int n = 0; info_types[n][0]; ++n)
|
|
|
|
typeCO->addItem(qt_(info_types_gui[n]));
|
2008-06-06 08:45:58 +00:00
|
|
|
typeCO->blockSignals(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiInfo::on_newPB_clicked()
|
|
|
|
{
|
|
|
|
dialogToParams();
|
|
|
|
docstring const argument = qstring_to_ucs4(type_ + ' ' + name_);
|
|
|
|
dispatch(FuncRequest(LFUN_INFO_INSERT, argument));
|
2008-06-05 15:08:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-06 08:45:58 +00:00
|
|
|
void GuiInfo::on_closePB_clicked()
|
2008-06-05 15:08:46 +00:00
|
|
|
{
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-06 08:45:58 +00:00
|
|
|
void GuiInfo::on_typeCO_currentIndexChanged(int)
|
|
|
|
{
|
|
|
|
applyView();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiInfo::on_nameLE_textChanged(QString const &)
|
|
|
|
{
|
|
|
|
applyView();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-05 15:08:46 +00:00
|
|
|
void GuiInfo::applyView()
|
|
|
|
{
|
2008-12-22 18:18:47 +00:00
|
|
|
InsetInfo const * ii = dynamic_cast<InsetInfo const *>(inset(INFO_CODE));
|
2009-06-29 23:43:23 +00:00
|
|
|
if (!ii)
|
2008-06-05 15:08:46 +00:00
|
|
|
return;
|
|
|
|
|
2008-06-06 08:45:58 +00:00
|
|
|
dialogToParams();
|
|
|
|
docstring const argument = qstring_to_ucs4(type_ + ' ' + name_);
|
|
|
|
if (!ii->validate(argument))
|
|
|
|
return;
|
2008-06-05 15:08:46 +00:00
|
|
|
|
2010-01-11 15:50:07 +00:00
|
|
|
dispatch(FuncRequest(LFUN_INSET_MODIFY, argument));
|
2008-06-06 08:45:58 +00:00
|
|
|
// FIXME: update the inset contents
|
2009-03-12 20:02:12 +00:00
|
|
|
bufferview()->buffer().updateLabels();
|
2008-06-05 15:08:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiInfo::updateView()
|
|
|
|
{
|
2008-12-22 18:18:47 +00:00
|
|
|
InsetInfo const * ii = dynamic_cast<InsetInfo const *>(inset(INFO_CODE));
|
2008-06-05 15:08:46 +00:00
|
|
|
if (!ii) {
|
|
|
|
enableView(false);
|
|
|
|
return;
|
|
|
|
}
|
2008-06-06 04:10:42 +00:00
|
|
|
|
2008-06-06 08:45:58 +00:00
|
|
|
type_ = toqstr(ii->infoType());
|
|
|
|
name_ = toqstr(ii->infoName());
|
|
|
|
paramsToDialog();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiInfo::paramsToDialog()
|
|
|
|
{
|
|
|
|
typeCO->blockSignals(true);
|
|
|
|
nameLE->blockSignals(true);
|
|
|
|
int type = findToken(info_types, fromqstr(type_));
|
2008-06-06 04:10:42 +00:00
|
|
|
typeCO->setCurrentIndex(type >= 0 ? type : 0);
|
2008-08-03 22:26:01 +00:00
|
|
|
// Without this test, 'math-insert' (name_) will replace 'math-insert '
|
|
|
|
// in nameLE and effectively disallow the input of spaces after a LFUN.
|
|
|
|
if (nameLE->text().trimmed() != name_)
|
|
|
|
nameLE->setText(name_);
|
2008-06-06 08:45:58 +00:00
|
|
|
typeCO->blockSignals(false);
|
|
|
|
nameLE->blockSignals(false);
|
2008-06-05 15:08:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-06 08:45:58 +00:00
|
|
|
void GuiInfo::dialogToParams()
|
2008-06-05 15:08:46 +00:00
|
|
|
{
|
2008-06-06 08:45:58 +00:00
|
|
|
int type = typeCO->currentIndex();
|
|
|
|
if (type != -1)
|
|
|
|
type_ = info_types[type];
|
|
|
|
name_ = nameLE->text();
|
2008-06-05 15:08:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-06 08:45:58 +00:00
|
|
|
void GuiInfo::enableView(bool enable)
|
2008-06-05 15:08:46 +00:00
|
|
|
{
|
2008-06-06 08:45:58 +00:00
|
|
|
typeCO->setEnabled(enable);
|
|
|
|
nameLE->setEnabled(enable);
|
|
|
|
newPB->setEnabled(!enable);
|
2008-06-05 15:08:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Dialog * createGuiInfo(GuiView & lv) { return new GuiInfo(lv); }
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
|
|
|
|
2008-11-14 14:28:50 +00:00
|
|
|
#include "moc_GuiInfo.cpp"
|