* Move handling of LFUN_INSET_SETTINGS to Inset,

* Remove the EDITABLE enum,
* add functions hasSettings() for all insets.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@29375 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Vincent van Ravesteijn 2009-04-22 20:55:13 +00:00
parent 4d121bafde
commit 4c9fe33c83
49 changed files with 105 additions and 93 deletions

View File

@ -729,7 +729,7 @@ bool BufferView::moveToPosition(pit_type bottom_pit, pos_type bottom_pos,
// insets.
size_t const n = dit.depth();
for (size_t i = 0; i < n; ++i)
if (dit[i].inset().editable() != Inset::HIGHLY_EDITABLE) {
if (!dit[i].inset().editable()) {
dit.resize(i);
break;
}

View File

@ -315,7 +315,7 @@ void DocIterator::forwardPosIgnoreCollapsed()
// FIXME: the check for asInsetMath() shouldn't be necessary
// but math insets do not return a sensible editable() state yet.
if (nextinset && !nextinset->asInsetMath()
&& nextinset->editable() != Inset::HIGHLY_EDITABLE) {
&& !nextinset->editable()) {
++top().pos();
return;
}

View File

@ -573,7 +573,7 @@ bool Text::checkAndActivateInset(Cursor & cur, bool front)
if (!front && cur.pos() == 0)
return false;
Inset * inset = front ? cur.nextInset() : cur.prevInset();
if (!inset || inset->editable() != Inset::HIGHLY_EDITABLE)
if (!inset || !inset->editable())
return false;
/*
* Apparently, when entering an inset we are expected to be positioned
@ -599,7 +599,7 @@ bool Text::checkAndActivateInsetVisual(Cursor & cur, bool movingForward, bool mo
return false;
Paragraph & par = cur.paragraph();
Inset * inset = par.isInset(cur.pos()) ? par.getInset(cur.pos()) : 0;
if (!inset || inset->editable() != Inset::HIGHLY_EDITABLE)
if (!inset || !inset->editable())
return false;
inset->edit(cur, movingForward,
movingLeft ? Inset::ENTRY_DIRECTION_RIGHT : Inset::ENTRY_DIRECTION_LEFT);

View File

@ -223,15 +223,19 @@ void Inset::doDispatch(Cursor & cur, FuncRequest &cmd)
case LFUN_MOUSE_RELEASE:
// if the derived inset did not explicitly handle mouse_release,
// we assume we request the settings dialog
if (!cur.selection() && cmd.button() == mouse_button::button1) {
if (!cur.selection() && cmd.button() == mouse_button::button1
&& hasSettings()) {
FuncRequest tmpcmd(LFUN_INSET_SETTINGS);
dispatch(cur, tmpcmd);
}
break;
case LFUN_INSET_SETTINGS:
showInsetDialog(&cur.bv());
cur.dispatched();
if (cmd.argument().empty() || cmd.getArg(0) == insetName(lyxCode())) {
showInsetDialog(&cur.bv());
cur.dispatched();
} else
cur.undispatched();
break;
default:
@ -269,8 +273,14 @@ bool Inset::getStatus(Cursor &, FuncRequest const & cmd,
return true;
case LFUN_INSET_SETTINGS:
flag.setEnabled(false);
return true;
if (cmd.argument().empty() || cmd.getArg(0) == insetName(lyxCode())) {
bool const enable = hasSettings();
flag.setEnabled(enable);
return true;
} else {
flag.setEnabled(false);
return false;
}
default:
break;
@ -326,12 +336,19 @@ bool Inset::directWrite() const
}
Inset::EDITABLE Inset::editable() const
bool Inset::editable() const
{
return NOT_EDITABLE;
return false;
}
bool Inset::hasSettings() const
{
return false;
}
bool Inset::autoDelete() const
{
return false;

View File

@ -213,9 +213,6 @@ public:
/// Force inset into LTR environment if surroundings are RTL?
virtual bool forceLTR() const { return false; }
/// is this an inset that can be moved into?
/// FIXME: merge with editable()
virtual bool isActive() const { return nargs() > 0; }
/// Where should we go when we press the up or down cursor key?
virtual bool idxUpDown(Cursor & cur, bool up) const;
/// Move one cell backwards
@ -301,27 +298,21 @@ public:
/// the string that is passed to the TOC
virtual void tocString(odocstream &) const {}
/** This enum indicates by which means the inset can be modified:
- NOT_EDITABLE: the inset's content cannot be modified at all
(e.g. printindex, insetspecialchar)
- IS_EDITABLE: content can be edited via dialog (e.g. bibtex, index, href)
- HIGHLY_EDITABLE: content can be edited on screen (normally means that
insettext is contained, e.g. collapsables, tabular) */
// FIXME: This has not yet been fully implemented to math insets
enum EDITABLE {
///
NOT_EDITABLE = 0,
///
IS_EDITABLE,
///
HIGHLY_EDITABLE
};
/// what appears in the minibuffer when opening
virtual docstring editMessage() const;
///
virtual EDITABLE editable() const;
/// can the contents of the inset be edited on screen ?
// true for InsetCollapsables (not ButtonOnly) (not InsetInfo), InsetText
virtual bool editable() const;
/// has the Inset settings that can be modified in a dialog ?
virtual bool hasSettings() const;
/// can we go further down on mouse click?
// true for InsetCaption, InsetCollapsables (not ButtonOnly), InsetTabular
virtual bool descendable() const { return false; }
/// is this an inset that can be moved into?
/// FIXME: merge with editable()
// true for InsetTabular & InsetText
virtual bool isActive() const { return nargs() > 0; }
/// does this contain text that can be change track marked in DVI?
virtual bool canTrackChanges() const { return false; }
/// return true if the inset should be removed automatically

View File

@ -53,7 +53,7 @@ private:
///
docstring screenLabel() const;
///
EDITABLE editable() const { return IS_EDITABLE; }
bool hasSettings() const { return true; }
///
InsetCode lyxCode() const { return BIBITEM_CODE; }
///

View File

@ -34,7 +34,7 @@ public:
///
docstring toolTip(BufferView const & bv, int x, int y) const;
///
EDITABLE editable() const { return IS_EDITABLE; }
bool hasSettings() const { return true; }
///
InsetCode lyxCode() const { return BIBTEX_CODE; }
///

View File

@ -239,7 +239,6 @@ bool InsetBox::getStatus(Cursor & cur, FuncRequest const & cmd,
return true;
case LFUN_INSET_DIALOG_UPDATE:
case LFUN_INSET_SETTINGS:
flag.setEnabled(true);
return true;

View File

@ -176,7 +176,6 @@ bool InsetBranch::getStatus(Cursor & cur, FuncRequest const & cmd,
switch (cmd.action) {
case LFUN_INSET_MODIFY:
case LFUN_INSET_DIALOG_UPDATE:
case LFUN_INSET_SETTINGS:
flag.setEnabled(true);
break;

View File

@ -38,7 +38,7 @@ public:
///
docstring screenLabel() const;
///
EDITABLE editable() const { return IS_EDITABLE; }
bool hasSettings() const { return true; }
///
docstring toolTip(BufferView const & bv, int x, int y) const;
///

View File

@ -437,9 +437,9 @@ void InsetCollapsable::cursorPos(BufferView const & bv,
}
Inset::EDITABLE InsetCollapsable::editable() const
bool InsetCollapsable::editable() const
{
return geometry() != ButtonOnly ? HIGHLY_EDITABLE : IS_EDITABLE;
return geometry() != ButtonOnly;
}

View File

@ -74,7 +74,9 @@ public:
///
docstring const getNewLabel(docstring const & l) const;
///
EDITABLE editable() const;
bool editable() const;
///
bool hasSettings() const { return true; }
/// can we go further down on mouse click?
bool descendable() const;
///

View File

@ -52,7 +52,7 @@ InsetCommand::~InsetCommand()
void InsetCommand::metrics(MetricsInfo & mi, Dimension & dim) const
{
button_.update(screenLabel(), editable() != NOT_EDITABLE);
button_.update(screenLabel(), editable() || hasSettings());
button_.metrics(mi, dim);
}
@ -163,7 +163,6 @@ bool InsetCommand::getStatus(Cursor & cur, FuncRequest const & cmd,
status.setEnabled(true);
return true;
case LFUN_INSET_SETTINGS:
case LFUN_INSET_DIALOG_UPDATE:
status.setEnabled(true);
return true;

View File

@ -137,7 +137,6 @@ bool InsetERT::getStatus(Cursor & cur, FuncRequest const & cmd,
case LFUN_PASTE:
case LFUN_PRIMARY_SELECTION_PASTE:
case LFUN_QUOTE_INSERT:
case LFUN_INSET_SETTINGS:
status.setEnabled(true);
return true;

View File

@ -428,7 +428,6 @@ bool InsetExternal::getStatus(Cursor & cur, FuncRequest const & cmd,
case LFUN_INSET_EDIT:
case LFUN_INSET_MODIFY:
case LFUN_INSET_DIALOG_UPDATE:
case LFUN_INSET_SETTINGS:
flag.setEnabled(true);
return true;

View File

@ -120,7 +120,7 @@ private:
///
InsetCode lyxCode() const { return EXTERNAL_CODE; }
///
EDITABLE editable() const { return IS_EDITABLE; }
bool hasSettings() const { return true; }
///
void metrics(MetricsInfo &, Dimension &) const;
///

View File

@ -34,6 +34,8 @@ public:
void write(std::ostream &) const;
/// should paragraph indendation be ommitted in any case?
bool neverIndent() const { return true; }
///
bool hasSettings() const { return false; }
protected:
InsetFlex(InsetFlex const &);

View File

@ -183,7 +183,6 @@ bool InsetFloat::getStatus(Cursor & cur, FuncRequest const & cmd,
case LFUN_INSET_MODIFY:
case LFUN_INSET_DIALOG_UPDATE:
case LFUN_INSET_SETTINGS:
flag.setEnabled(true);
return true;

View File

@ -29,8 +29,6 @@ public:
///
docstring screenLabel() const;
///
EDITABLE editable() const { return NOT_EDITABLE; }
///
InsetCode lyxCode() const { return FLOAT_LIST_CODE; }
///
DisplayType display() const { return AlignCenter; }

View File

@ -24,6 +24,8 @@ class InsetFootlike : public InsetCollapsable {
public:
///
InsetFootlike(Buffer const &);
///
bool hasSettings() const { return false; }
private:
///
void metrics(MetricsInfo &, Dimension &) const;

View File

@ -230,7 +230,6 @@ bool InsetGraphics::getStatus(Cursor & cur, FuncRequest const & cmd,
case LFUN_INSET_EDIT:
case LFUN_INSET_MODIFY:
case LFUN_INSET_DIALOG_UPDATE:
case LFUN_INSET_SETTINGS:
flag.setEnabled(true);
return true;
@ -261,12 +260,6 @@ void InsetGraphics::draw(PainterInfo & pi, int x, int y) const
}
Inset::EDITABLE InsetGraphics::editable() const
{
return IS_EDITABLE;
}
void InsetGraphics::write(ostream & os) const
{
os << "Graphics\n";

View File

@ -60,7 +60,7 @@ private:
bool isLabeled() const { return true; }
void metrics(MetricsInfo &, Dimension &) const;
///
EDITABLE editable() const;
bool hasSettings() const { return true; }
///
void write(std::ostream &) const;
///

View File

@ -31,7 +31,7 @@ public:
///
docstring screenLabel() const;
///
EDITABLE editable() const { return IS_EDITABLE; }
bool hasSettings() const { return true; }
///
DisplayType display() const { return Inline; }
///

View File

@ -299,6 +299,7 @@ void InsetInclude::editIncluded(string const & file)
bool InsetInclude::getStatus(Cursor & cur, FuncRequest const & cmd,
FuncStatus & flag) const
{
LYXERR0(cmd.action);
switch (cmd.action) {
case LFUN_INSET_EDIT:

View File

@ -72,7 +72,7 @@ public:
support::FileNameList const &
getBibfilesCache() const;
///
EDITABLE editable() const { return IS_EDITABLE; }
bool hasSettings() const { return true; }
///
int latex(odocstream &, OutputParams const &) const;
///

View File

@ -181,6 +181,8 @@ bool InsetIndex::showInsetDialog(BufferView * bv) const
void InsetIndex::doDispatch(Cursor & cur, FuncRequest & cmd)
{
LYXERR0( cmd.action);
LYXERR0( cmd.getArg(0));
switch (cmd.action) {
case LFUN_INSET_MODIFY: {
@ -210,6 +212,8 @@ void InsetIndex::doDispatch(Cursor & cur, FuncRequest & cmd)
bool InsetIndex::getStatus(Cursor & cur, FuncRequest const & cmd,
FuncStatus & flag) const
{
LYXERR0( cmd.action);
LYXERR0( cmd.getArg(0));
switch (cmd.action) {
case LFUN_INSET_MODIFY:
@ -226,8 +230,7 @@ bool InsetIndex::getStatus(Cursor & cur, FuncRequest const & cmd,
flag.setEnabled(true);
return true;
case LFUN_INSET_DIALOG_UPDATE:
case LFUN_INSET_SETTINGS: {
case LFUN_INSET_DIALOG_UPDATE: {
Buffer const & realbuffer = *buffer().masterBuffer();
flag.setEnabled(realbuffer.params().use_indices);
return true;
@ -340,6 +343,21 @@ docstring InsetIndex::contextMenu(BufferView const &, int, int) const
}
bool InsetIndex::hasSettings() const
{
return buffer().masterBuffer()->params().use_indices;
}
/////////////////////////////////////////////////////////////////////
//
// InsetIndexParams
//
///////////////////////////////////////////////////////////////////////
void InsetIndexParams::write(ostream & os) const
{
os << ' ';
@ -446,8 +464,7 @@ bool InsetPrintIndex::getStatus(Cursor & cur, FuncRequest const & cmd,
return InsetCommand::getStatus(cur, cmd, status);
}
case LFUN_INSET_DIALOG_UPDATE:
case LFUN_INSET_SETTINGS: {
case LFUN_INSET_DIALOG_UPDATE: {
Buffer const & realbuffer = *buffer().masterBuffer();
status.setEnabled(realbuffer.params().use_indices);
return true;
@ -486,10 +503,9 @@ docstring InsetPrintIndex::contextMenu(BufferView const &, int, int) const
}
Inset::EDITABLE InsetPrintIndex::editable() const
bool InsetPrintIndex::hasSettings() const
{
return buffer().masterBuffer()->params().use_indices ?
IS_EDITABLE : NOT_EDITABLE;
return buffer().masterBuffer()->params().use_indices;
}

View File

@ -45,7 +45,7 @@ public:
static void string2params(std::string const &, InsetIndexParams &);
private:
///
EDITABLE editable() const { return HIGHLY_EDITABLE; }
bool hasSettings() const;
///
InsetCode lyxCode() const { return INDEX_CODE; }
///
@ -112,7 +112,8 @@ private:
/// Updates needed features for this inset.
void validate(LaTeXFeatures & features) const;
///
EDITABLE editable() const;
bool hasSettings() const;
///
DisplayType display() const { return AlignCenter; }
///

View File

@ -100,7 +100,9 @@ public:
///
Inset * editXY(Cursor & cur, int x, int y);
///
EDITABLE editable() const { return IS_EDITABLE; }
bool editable() const { return false; }
///
bool hasSettings() const { return true; }
///
void read(Lexer & lex);
///

View File

@ -34,7 +34,7 @@ public:
///
docstring screenLabel() const;
///
EDITABLE editable() const { return IS_EDITABLE; }
bool hasSettings() const { return true; }
///
InsetCode lyxCode() const { return LABEL_CODE; }
///

View File

@ -18,7 +18,6 @@
#include "BufferParams.h"
#include "Counters.h"
#include "Cursor.h"
#include "CutAndPaste.h"
#include "DispatchResult.h"
#include "Encoding.h"
#include "FuncRequest.h"
@ -387,7 +386,6 @@ bool InsetListings::getStatus(Cursor & cur, FuncRequest const & cmd,
switch (cmd.action) {
case LFUN_INSET_MODIFY:
case LFUN_INSET_DIALOG_UPDATE:
case LFUN_INSET_SETTINGS:
status.setEnabled(true);
return true;
case LFUN_CAPTION_INSERT:

View File

@ -32,7 +32,7 @@ public:
///
docstring toolTip(BufferView const & bv, int x, int y) const;
///
EDITABLE editable() const { return IS_EDITABLE; }
bool hasSettings() const { return true; }
/// Updates needed features for this inset.
void validate(LaTeXFeatures & features) const;
///
@ -66,8 +66,6 @@ public:
// Currently the width can be read from file and written, but not
// changed.
///
EDITABLE editable() const { return NOT_EDITABLE; }
///
int docbook(odocstream &, OutputParams const &) const;
///
InsetCode lyxCode() const;

View File

@ -211,7 +211,6 @@ bool InsetNote::getStatus(Cursor & cur, FuncRequest const & cmd,
}
return true;
case LFUN_INSET_SETTINGS:
case LFUN_INSET_DIALOG_UPDATE:
flag.setEnabled(true);
return true;

View File

@ -31,6 +31,8 @@ public:
/// Outputting the optional parameter of a LaTeX command
int latexOptional(odocstream &, OutputParams const &) const;
///
bool hasSettings() const { return false; }
private:
/// code of the inset

View File

@ -293,7 +293,6 @@ bool InsetPhantom::getStatus(Cursor & cur, FuncRequest const & cmd,
flag.setEnabled(true);
return true;
case LFUN_INSET_SETTINGS:
case LFUN_INSET_DIALOG_UPDATE:
flag.setEnabled(true);
return true;

View File

@ -43,7 +43,7 @@ public:
///
docstring screenLabel() const;
///
EDITABLE editable() const { return IS_EDITABLE; }
bool hasSettings() const { return true; }
///
InsetCode lyxCode() const { return REF_CODE; }
///

View File

@ -172,7 +172,6 @@ bool InsetSpace::getStatus(Cursor & cur, FuncRequest const & cmd,
status.setOnOff(params_.kind == params.kind);
}
// fall through
case LFUN_INSET_SETTINGS:
case LFUN_INSET_DIALOG_UPDATE:
status.setEnabled(true);
return true;

View File

@ -133,7 +133,7 @@ public:
/// the string that is passed to the TOC
void tocString(odocstream &) const;
///
EDITABLE editable() const { return IS_EDITABLE; }
bool hasSettings() const { return true; }
///
InsetCode lyxCode() const { return SPACE_CODE; }
/// is this an expandible space (rubber length)?

View File

@ -26,8 +26,6 @@ public:
///
docstring screenLabel() const;
///
EDITABLE editable() const { return NOT_EDITABLE; }
///
InsetCode lyxCode() const { return TOC_CODE; }
///
DisplayType display() const { return AlignCenter; }

View File

@ -4075,6 +4075,9 @@ bool InsetTabular::getStatus(Cursor & cur, FuncRequest const & cmd,
return cell(cur.idx())->getStatus(cur, cmd, status);
case LFUN_INSET_SETTINGS:
// relay this lfun to Inset, not to the cell.
return Inset::getStatus(cur, cmd, status);
case LFUN_INSET_MODIFY:
if (insetCode(cmd.getArg(0)) == TABULAR_CODE) {
status.setEnabled(true);

View File

@ -736,7 +736,9 @@ public:
///
docstring editMessage() const;
///
EDITABLE editable() const { return HIGHLY_EDITABLE; }
bool editable() const { return true; }
///
bool hasSettings() const { return true; }
///
bool insetAllowed(InsetCode code) const;
///

View File

@ -64,7 +64,7 @@ public:
///
docstring editMessage() const;
///
EDITABLE editable() const { return HIGHLY_EDITABLE; }
bool editable() const { return true; }
///
bool canTrackChanges() const { return true; }
///

View File

@ -87,10 +87,6 @@ bool InsetVSpace::getStatus(Cursor & cur, FuncRequest const & cmd,
status.setEnabled(true);
return true;
case LFUN_INSET_SETTINGS:
status.setEnabled(true);
return true;
default:
return Inset::getStatus(cur, cmd, status);
}

View File

@ -32,7 +32,7 @@ public:
///
InsetCode lyxCode() const { return VSPACE_CODE; }
///
EDITABLE editable() const { return IS_EDITABLE; }
bool hasSettings() const { return true; }
///
docstring contextMenu(BufferView const & bv, int x, int y) const;
///

View File

@ -107,7 +107,6 @@ bool InsetWrap::getStatus(Cursor & cur, FuncRequest const & cmd,
switch (cmd.action) {
case LFUN_INSET_MODIFY:
case LFUN_INSET_DIALOG_UPDATE:
case LFUN_INSET_SETTINGS:
flag.setEnabled(true);
return true;

View File

@ -55,7 +55,7 @@ public:
///
docstring const & getInsetName() const { return name_; }
///
EDITABLE editable() const { return HIGHLY_EDITABLE; }
bool editable() const { return true; }
private:
///
MathAtom & tmpl() const;

View File

@ -212,7 +212,7 @@ public:
///
virtual void revealCodes(Cursor & cur) const;
///
EDITABLE editable() const { return HIGHLY_EDITABLE; }
bool editable() const { return true; }
///
void edit(Cursor & cur, bool front,
EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);

View File

@ -56,7 +56,7 @@ public:
/// generate something that will be understood by the Dialogs.
std::string const createDialogStr() const;
///
EDITABLE editable() const { return IS_EDITABLE; }
bool hasSettings() const { return true; }
///
docstring contextMenu(BufferView const &, int, int) const;
///

View File

@ -36,7 +36,7 @@ public:
///
explicit MathMacroTemplate(const docstring & str);
///
EDITABLE editable() const { return HIGHLY_EDITABLE; }
bool editable() const { return true; }
///
void edit(Cursor & cur, bool front, EntryDirection entry_from);
///

View File

@ -772,7 +772,7 @@ void RowPainter::paintText()
Inset const * inset = par_.getInset(pos);
bool const highly_editable_inset = inset
&& inset->editable() == Inset::HIGHLY_EDITABLE;
&& inset->editable();
// If we reach the end of a change or if the author changes, paint it.
// We also don't paint across things like tables