mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-07 02:28:35 +00:00
Introduce Inset::asInsetGraphics.
Then use it to avoid explicit LyXCode checks in the graphic group code.
This commit is contained in:
parent
af424cf1a1
commit
f8ca747109
@ -44,6 +44,7 @@ class FuncStatus;
|
||||
class InsetArgument;
|
||||
class InsetCollapsible;
|
||||
class InsetCommand;
|
||||
class InsetGraphics;
|
||||
class InsetIterator;
|
||||
class InsetLayout;
|
||||
class InsetList;
|
||||
@ -158,6 +159,10 @@ public:
|
||||
virtual InsetCommand const * asInsetCommand() const { return 0; }
|
||||
/// is this inset based on the InsetArgument class?
|
||||
virtual InsetArgument const * asInsetArgument() const { return nullptr; }
|
||||
/// is this inset based on the InsetGraphics class?
|
||||
virtual InsetGraphics * asInsetGraphics() { return 0; }
|
||||
/// is this inset based on the InsetGraphics class?
|
||||
virtual InsetGraphics const * asInsetGraphics() const { return 0; }
|
||||
|
||||
/// the real dispatcher
|
||||
void dispatch(Cursor & cur, FuncRequest & cmd);
|
||||
|
@ -1096,13 +1096,14 @@ void getGraphicsGroups(Buffer const & b, set<string> & ids)
|
||||
Inset & inset = b.inset();
|
||||
InsetIterator it = inset_iterator_begin(inset);
|
||||
InsetIterator const end = inset_iterator_end(inset);
|
||||
for (; it != end; ++it)
|
||||
if (it->lyxCode() == GRAPHICS_CODE) {
|
||||
InsetGraphics & ins = static_cast<InsetGraphics &>(*it);
|
||||
InsetGraphicsParams inspar = ins.getParams();
|
||||
if (!inspar.groupId.empty())
|
||||
ids.insert(inspar.groupId);
|
||||
}
|
||||
for (; it != end; ++it) {
|
||||
InsetGraphics const * ins = it->asInsetGraphics();
|
||||
if (!ins)
|
||||
continue;
|
||||
InsetGraphicsParams const & inspar = ins->getParams();
|
||||
if (!inspar.groupId.empty())
|
||||
ids.insert(inspar.groupId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1114,12 +1115,13 @@ int countGroupMembers(Buffer const & b, string const & groupId)
|
||||
Inset & inset = b.inset();
|
||||
InsetIterator it = inset_iterator_begin(inset);
|
||||
InsetIterator const end = inset_iterator_end(inset);
|
||||
for (; it != end; ++it)
|
||||
if (it->lyxCode() == GRAPHICS_CODE) {
|
||||
InsetGraphics & ins = static_cast<InsetGraphics &>(*it);
|
||||
if (ins.getParams().groupId == groupId)
|
||||
++n;
|
||||
}
|
||||
for (; it != end; ++it) {
|
||||
InsetGraphics const * ins = it->asInsetGraphics();
|
||||
if (!ins)
|
||||
continue;
|
||||
if (ins->getParams().groupId == groupId)
|
||||
++n;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
@ -1131,16 +1133,17 @@ string getGroupParams(Buffer const & b, string const & groupId)
|
||||
Inset & inset = b.inset();
|
||||
InsetIterator it = inset_iterator_begin(inset);
|
||||
InsetIterator const end = inset_iterator_end(inset);
|
||||
for (; it != end; ++it)
|
||||
if (it->lyxCode() == GRAPHICS_CODE) {
|
||||
InsetGraphics & ins = static_cast<InsetGraphics &>(*it);
|
||||
InsetGraphicsParams inspar = ins.getParams();
|
||||
if (inspar.groupId == groupId) {
|
||||
InsetGraphicsParams tmp = inspar;
|
||||
tmp.filename.erase();
|
||||
return InsetGraphics::params2string(tmp, b);
|
||||
}
|
||||
for (; it != end; ++it) {
|
||||
InsetGraphics const * ins = it->asInsetGraphics();
|
||||
if (!ins)
|
||||
continue;
|
||||
InsetGraphicsParams const & inspar = ins->getParams();
|
||||
if (inspar.groupId == groupId) {
|
||||
InsetGraphicsParams tmp = inspar;
|
||||
tmp.filename.erase();
|
||||
return InsetGraphics::params2string(tmp, b);
|
||||
}
|
||||
}
|
||||
return string();
|
||||
}
|
||||
|
||||
@ -1156,14 +1159,14 @@ void unifyGraphicsGroups(Buffer & b, string const & argument)
|
||||
InsetIterator it = inset_iterator_begin(inset);
|
||||
InsetIterator const end = inset_iterator_end(inset);
|
||||
for (; it != end; ++it) {
|
||||
if (it->lyxCode() == GRAPHICS_CODE) {
|
||||
InsetGraphics & ins = static_cast<InsetGraphics &>(*it);
|
||||
InsetGraphicsParams inspar = ins.getParams();
|
||||
if (params.groupId == inspar.groupId) {
|
||||
CursorData(it).recordUndo();
|
||||
params.filename = inspar.filename;
|
||||
ins.setParams(params);
|
||||
}
|
||||
InsetGraphics * ins = it->asInsetGraphics();
|
||||
if (!ins)
|
||||
continue;
|
||||
InsetGraphicsParams const & inspar = ins->getParams();
|
||||
if (params.groupId == inspar.groupId) {
|
||||
CursorData(it).recordUndo();
|
||||
params.filename = inspar.filename;
|
||||
ins->setParams(params);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1172,12 +1175,12 @@ void unifyGraphicsGroups(Buffer & b, string const & argument)
|
||||
InsetGraphics * getCurrentGraphicsInset(Cursor const & cur)
|
||||
{
|
||||
Inset * instmp = &cur.inset();
|
||||
if (instmp->lyxCode() != GRAPHICS_CODE)
|
||||
if (!instmp->asInsetGraphics())
|
||||
instmp = cur.nextInset();
|
||||
if (!instmp || instmp->lyxCode() != GRAPHICS_CODE)
|
||||
if (!instmp || !instmp->asInsetGraphics())
|
||||
return 0;
|
||||
|
||||
return static_cast<InsetGraphics *>(instmp);
|
||||
return instmp->asInsetGraphics();
|
||||
}
|
||||
|
||||
} // namespace graphics
|
||||
|
@ -55,7 +55,11 @@ public:
|
||||
///
|
||||
bool clickable(BufferView const &, int, int) const { return true; }
|
||||
///
|
||||
bool canPaintChange(BufferView const &) const { return true; };
|
||||
bool canPaintChange(BufferView const &) const { return true; }
|
||||
///
|
||||
InsetGraphics * asInsetGraphics() { return this; }
|
||||
///
|
||||
InsetGraphics const * asInsetGraphics() const { return this; }
|
||||
|
||||
private:
|
||||
///
|
||||
|
Loading…
Reference in New Issue
Block a user