New inset dialog for InsetIndex (only used with multiple indices)..

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@29285 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jürgen Spitzmüller 2009-04-17 09:22:44 +00:00
parent c090147654
commit de22184d97
11 changed files with 331 additions and 2 deletions

View File

@ -727,6 +727,7 @@ src_frontends_qt4_header_files = Split('''
GuiIdListModel.h
GuiImage.h
GuiInclude.h
GuiIndex.h
GuiIndices.h
GuiInfo.h
GuiKeySymbol.h
@ -820,6 +821,7 @@ src_frontends_qt4_files = Split('''
GuiIdListModel.cpp
GuiImage.cpp
GuiInclude.cpp
GuiIndex.cpp
GuiIndices.cpp
GuiInfo.cpp
GuiKeySymbol.cpp
@ -904,6 +906,7 @@ src_frontends_qt4_ui_files = Split('''
HSpaceUi.ui
HyperlinkUi.ui
IncludeUi.ui
IndexUi.ui
IndicesUi.ui
InfoUi.ui
LabelUi.ui

View File

@ -480,6 +480,8 @@ Menuset
OptItem "Close Inset|C" "inset-toggle close"
Separator
Item "Dissolve Inset|D" "inset-dissolve"
Separator
OptItem "Settings...|S" "inset-settings"
End
#

View File

@ -123,6 +123,7 @@ Menuset
OptItem "Phantom Settings...|h" "inset-settings phantom"
OptItem "Branch Settings...|B" "inset-settings branch"
OptItem "Box Settings...|x" "inset-settings box"
OptItem "Index Entry Settings...|C" "inset-settings inset"
OptItem "Listings Settings...|g" "inset-settings listings"
# Hey, guess what's broken ? Surprise surprise, it's tabular stuff
# This is in the Table submenu instead for now.

View File

@ -2246,11 +2246,11 @@ void LyXAction::init()
* \var lyx::FuncCode lyx::LFUN_INSET_SETTINGS
* \li Action: Open the inset's properties dialog.
* \li Notion: Used for bibitem, bibtex, box, branch, citation, ert, external,
* float, graphics, href, include, label, listings, note, phantom,
* float, graphics, href, include, index, label, listings, note, phantom,
* ref, space, tabular, vspace, wrap insets.
* \li Syntax: inset-settings <INSET>
* \li Params: <INSET>: <bibitem|bibtex|box|branch|citation|ert|external|float|
* graphics|href|include|label|listings|note|phantom|ref|
* graphics|href|include|index|label|listings|note|phantom|ref|
* space|tabular|vspace|wrap>.
* \endvar
*/

View File

@ -0,0 +1,107 @@
/**
* \file GuiIndex.cpp
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Angus Leeming
* \author Martin Vermeer
* \author Jürgen Spitzmüller
*
* Full author contact details are available in file CREDITS.
*/
#include <config.h>
#include "GuiIndex.h"
#include "qt_helpers.h"
#include "Buffer.h"
#include "BufferParams.h"
#include "FuncRequest.h"
#include "IndicesList.h"
#include "insets/InsetIndex.h"
#include <QPushButton>
using namespace std;
namespace lyx {
namespace frontend {
GuiIndex::GuiIndex(GuiView & lv)
: GuiDialog(lv, "index", qt_("Index Entry Settings"))
{
setupUi(this);
connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
connect(cancelPB, SIGNAL(clicked()), this, SLOT(slotClose()));
connect(indicesCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
bc().setOK(okPB);
bc().setCancel(cancelPB);
}
void GuiIndex::change_adaptor()
{
changed();
}
void GuiIndex::updateContents()
{
typedef IndicesList::const_iterator const_iterator;
IndicesList const & indiceslist = buffer().params().indiceslist();
docstring const cur_index = params_.index;
indicesCO->clear();
const_iterator const begin = indiceslist.begin();
const_iterator const end = indiceslist.end();
for (const_iterator it = begin; it != end; ++it)
indicesCO->addItem(toqstr(it->index()),
QVariant(toqstr(it->shortcut())));
int const pos = indicesCO->findData(toqstr(cur_index));
indicesCO->setCurrentIndex(pos);
}
void GuiIndex::applyView()
{
QString const index = indicesCO->itemData(
indicesCO->currentIndex()).toString();
params_.index = qstring_to_ucs4(index);
}
bool GuiIndex::initialiseParams(string const & data)
{
InsetIndex::string2params(data, params_);
return true;
}
void GuiIndex::clearParams()
{
params_ = InsetIndexParams();
}
void GuiIndex::dispatchParams()
{
dispatch(FuncRequest(getLfun(), InsetIndex::params2string(params_)));
}
Dialog * createGuiIndex(GuiView & lv) { return new GuiIndex(lv); }
} // namespace frontend
} // namespace lyx
#include "moc_GuiIndex.cpp"

View File

@ -0,0 +1,56 @@
// -*- C++ -*-
/**
* \file GuiIndex.h
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Angus Leeming
* \author Martin Vermeer
* \author Jürgen Spitzmüller
*
* Full author contact details are available in file CREDITS.
*/
#ifndef GUIINDEX_H
#define GUIINDEX_H
#include "GuiDialog.h"
#include "ui_IndexUi.h"
#include "insets/InsetIndex.h"
namespace lyx {
namespace frontend {
class GuiIndex : public GuiDialog, public Ui::IndexUi
{
Q_OBJECT
public:
GuiIndex(GuiView & lv);
private Q_SLOTS:
void change_adaptor();
private:
/// Apply changes
void applyView();
/// Update dialog before showing it
void updateContents();
///
bool initialiseParams(std::string const & data);
///
void clearParams();
///
void dispatchParams();
///
bool isBufferDependent() const { return true; }
///
InsetIndexParams params_;
};
} // namespace frontend
} // namespace lyx
#endif // GUIINDEX_H

View File

@ -2576,6 +2576,7 @@ Dialog * createGuiExternal(GuiView & lv);
Dialog * createGuiFloat(GuiView & lv);
Dialog * createGuiGraphics(GuiView & lv);
Dialog * createGuiInclude(GuiView & lv);
Dialog * createGuiIndex(GuiView & lv);
Dialog * createGuiInfo(GuiView & lv);
Dialog * createGuiLabel(GuiView & lv);
Dialog * createGuiListings(GuiView & lv);
@ -2647,6 +2648,8 @@ Dialog * GuiView::build(string const & name)
return createGuiGraphics(*this);
if (name == "include")
return createGuiInclude(*this);
if (name == "index")
return createGuiIndex(*this);
if (name == "info")
return createGuiInfo(*this);
if (name == "nomenclature")

View File

@ -90,6 +90,7 @@ SOURCEFILES = \
GuiIdListModel.cpp \
GuiImage.cpp \
GuiInclude.cpp \
GuiIndex.cpp \
GuiIndices.cpp \
GuiInfo.cpp \
GuiKeySymbol.cpp \
@ -187,6 +188,7 @@ MOCHEADER = \
GuiHSpace.h \
GuiHyperlink.h \
GuiInclude.h \
GuiIndex.h \
GuiIndices.h \
GuiInfo.h \
GuiLabel.h \
@ -256,6 +258,7 @@ UIFILES = \
HSpaceUi.ui \
HyperlinkUi.ui \
IncludeUi.ui \
IndexUi.ui \
IndicesUi.ui \
InfoUi.ui \
LabelUi.ui \

View File

@ -0,0 +1,97 @@
<ui version="4.0" >
<class>IndexUi</class>
<widget class="QDialog" name="IndexUi" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>262</width>
<height>108</height>
</rect>
</property>
<property name="windowTitle" >
<string/>
</property>
<property name="sizeGripEnabled" >
<bool>true</bool>
</property>
<layout class="QGridLayout" >
<property name="margin" >
<number>9</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item row="1" column="0" >
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>71</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="1" >
<widget class="QPushButton" name="okPB" >
<property name="text" >
<string>&amp;OK</string>
</property>
<property name="default" >
<bool>false</bool>
</property>
</widget>
</item>
<item row="0" column="0" colspan="3" >
<layout class="QVBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QLabel" name="indicesLA" >
<property name="text" >
<string>A&amp;vailable indices:</string>
</property>
<property name="buddy" >
<cstring>indicesCO</cstring>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="indicesCO" >
<property name="toolTip" >
<string>Select the index this entry should be listed in.</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="2" >
<widget class="QPushButton" name="cancelPB" >
<property name="text" >
<string>&amp;Cancel</string>
</property>
<property name="default" >
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>indicesCO</tabstop>
<tabstop>okPB</tabstop>
<tabstop>cancelPB</tabstop>
</tabstops>
<includes>
<include location="local" >qt_i18n.h</include>
</includes>
<resources/>
<connections/>
</ui>

View File

@ -14,6 +14,7 @@
#include "Buffer.h"
#include "BufferParams.h"
#include "BufferView.h"
#include "ColorSet.h"
#include "DispatchResult.h"
#include "Encoding.h"
@ -170,6 +171,14 @@ int InsetIndex::docbook(odocstream & os, OutputParams const & runparams) const
}
bool InsetIndex::showInsetDialog(BufferView * bv) const
{
bv->showDialog("index", params2string(params_),
const_cast<InsetIndex *>(this));
return true;
}
void InsetIndex::doDispatch(Cursor & cur, FuncRequest & cmd)
{
switch (cmd.action) {
@ -180,8 +189,17 @@ void InsetIndex::doDispatch(Cursor & cur, FuncRequest & cmd)
setLayout(cur.buffer()->params());
break;
}
InsetIndexParams params;
InsetIndex::string2params(to_utf8(cmd.argument()), params);
params_.index = params.index;
setLayout(cur.buffer()->params());
break;
}
case LFUN_INSET_DIALOG_UPDATE:
cur.bv().updateDialog("index", params2string(params_));
break;
default:
InsetCollapsable::doDispatch(cur, cmd);
break;
@ -205,6 +223,15 @@ bool InsetIndex::getStatus(Cursor & cur, FuncRequest const & cmd,
from_utf8(cmd.getArg(1)) == params_.index);
return true;
}
flag.setEnabled(true);
return true;
case LFUN_INSET_DIALOG_UPDATE:
case LFUN_INSET_SETTINGS: {
Buffer const & realbuffer = *buffer().masterBuffer();
flag.setEnabled(realbuffer.params().use_indices);
return true;
}
default:
return InsetCollapsable::getStatus(cur, cmd, flag);
@ -263,6 +290,30 @@ void InsetIndex::read(Lexer & lex)
}
string InsetIndex::params2string(InsetIndexParams const & params)
{
ostringstream data;
data << "index";
params.write(data);
return data.str();
}
void InsetIndex::string2params(string const & in, InsetIndexParams & params)
{
params = InsetIndexParams();
if (in.empty())
return;
istringstream data(in);
Lexer lex;
lex.setStream(data);
lex.setContext("InsetIndex::string2params");
lex >> "index";
params.read(lex);
}
void InsetIndex::addToToc(DocIterator const & cpit)
{
DocIterator pit = cpit;

View File

@ -39,6 +39,10 @@ class InsetIndex : public InsetCollapsable {
public:
///
InsetIndex(Buffer const &, InsetIndexParams const &);
///
static std::string params2string(InsetIndexParams const &);
///
static void string2params(std::string const &, InsetIndexParams &);
private:
///
EDITABLE editable() const { return HIGHLY_EDITABLE; }
@ -55,6 +59,8 @@ private:
///
int latex(odocstream &, OutputParams const &) const;
///
bool showInsetDialog(BufferView *) const;
///
bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
///
void doDispatch(Cursor & cur, FuncRequest & cmd);