hi, i send quite preliminary patch (only informative one, bit hand polished etc) which will allow graphics insets to be joined into groups, which share the same settings, ie some kind of templates.
in the current situation group id can be assigned to images and changing settings of any picture from the group change also the settings from the rest of pictures from the group immeditaely after approving graphics settings for the current inset. now we need somehow to allow the user to assign picture to the existing group and i'm not sure how to proceed here. i see two possibilities: 1. modify how the context menu works, so we have dynamically created and shown list of groups for each call of context menu. choosing one group will simply add the picture to the group and change its settings accordingly. 2. add this list to graphics dialog (there is already one edit field for new id now) and let user choose here. i was thinking about this solution, but don't know how to fetch the requested list of groups into the dialog. calling some lfun won't help, because we need list of strings in return; expanding InsetGraphicsParams for this list is ugly and will need additional hacks so that it is not saved into lyx file. pah. any idea how to solve this better? pavel
diff --git a/src/FuncCode.h b/src/FuncCode.h index 4619551..428c1bb 100644 --- a/src/FuncCode.h +++ b/src/FuncCode.h @@ -409,6 +409,7 @@ enum FuncCode LFUN_COMPLETION_COMPLETE, // 315 LFUN_NEXT_INSET_MODIFY, // JSpitzm 20080323 + LFUN_GRAPHICS_GROUPS_UNIFY, LFUN_LASTACTION // end of the table }; diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp index 2bd439c..677dbef 100644 --- a/src/LyXAction.cpp +++ b/src/LyXAction.cpp @@ -1239,6 +1239,7 @@ void LyXAction::init() * \endvar */ { LFUN_ALL_INSETS_TOGGLE, "all-insets-toggle", ReadOnly, Edit }, + { LFUN_GRAPHICS_GROUPS_UNIFY, "graphics-groups-unify", ReadOnly, Edit }, /*! * \var lyx::FuncCode lyx::LFUN_FINISHED_FORWARD diff --git a/src/LyXFunc.cpp b/src/LyXFunc.cpp index c5d3766..9ee83f6 100644 --- a/src/LyXFunc.cpp +++ b/src/LyXFunc.cpp @@ -621,6 +621,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const case LFUN_MESSAGE: case LFUN_INSET_EDIT: case LFUN_ALL_INSETS_TOGGLE: + case LFUN_GRAPHICS_GROUPS_UNIFY: case LFUN_BUFFER_LANGUAGE: case LFUN_TEXTCLASS_APPLY: case LFUN_TEXTCLASS_LOAD: @@ -1462,6 +1463,34 @@ void LyXFunc::dispatch(FuncRequest const & cmd) break; } + case LFUN_GRAPHICS_GROUPS_UNIFY: { + LASSERT(lyx_view_, /**/); + if (argument.empty()) break; + + view()->cursor().recordUndoFullDocument(); + + InsetGraphicsParams params; + InsetGraphics::string2params(argument, *lyx_view_->buffer(), params); + //InsetGraphics::unifyGraphicsGroups(*lyx_view_->buffer(), argument); + + Inset & inset = lyx_view_->buffer()->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 (params.groupId == inspar.groupId) { + params.filename = inspar.filename; + ins.setParams(params); + } + } + } + lyx_view_->buffer()->markDirty(); + updateFlags = Update::Force | Update::FitCursor; //not enough + break; + } + case LFUN_BUFFER_LANGUAGE: { LASSERT(lyx_view_, /**/); Buffer & buffer = *lyx_view_->buffer(); diff --git a/src/frontends/qt4/GuiGraphics.cpp b/src/frontends/qt4/GuiGraphics.cpp index 6a17db6..a1d9abc 100644 --- a/src/frontends/qt4/GuiGraphics.cpp +++ b/src/frontends/qt4/GuiGraphics.cpp @@ -542,6 +542,8 @@ void GuiGraphics::updateContents() scaleCB->blockSignals(false); Scale->setEnabled(scaleChecked); + groupId->setText(toqstr(igp.groupId)); + lengthAutoToWidgets(Width, widthUnit, igp.width, unitDefault); bool const widthChecked = !Width->text().isEmpty() && @@ -685,6 +687,8 @@ void GuiGraphics::applyView() // more latex options igp.special = fromqstr(latexoptions->text()); + + igp.groupId = fromqstr(groupId->text()); } @@ -731,9 +735,12 @@ void GuiGraphics::clearParams() void GuiGraphics::dispatchParams() { InsetGraphicsParams tmp_params(params_); string const lfun = InsetGraphics::params2string(tmp_params, buffer()); dispatch(FuncRequest(getLfun(), lfun)); + if (!params_.groupId.empty()) + dispatch(FuncRequest(LFUN_GRAPHICS_GROUPS_UNIFY, InsetGraphics::params2string(params_, buffer()))); } diff --git a/src/insets/InsetGraphics.h b/src/insets/InsetGraphics.h index dae9a70..857f80d 100644 --- a/src/insets/InsetGraphics.h +++ b/src/insets/InsetGraphics.h @@ -51,6 +51,8 @@ public: Return true of new params are different from what was so far. */ bool setParams(InsetGraphicsParams const & params); + + InsetGraphicsParams getParams() const { return params_;} private: /// diff --git a/src/insets/InsetGraphicsParams.cpp b/src/insets/InsetGraphicsParams.cpp index 35fb9bc..b2b15f0 100644 --- a/src/insets/InsetGraphicsParams.cpp +++ b/src/insets/InsetGraphicsParams.cpp @@ -79,6 +79,7 @@ void InsetGraphicsParams::init() rotateAngle = "0"; // angle of rotation in degrees rotateOrigin.erase(); // Origin of rotation special.erase(); // additional userdefined stuff + groupId.clear(); } @@ -101,6 +102,7 @@ void InsetGraphicsParams::copy(InsetGraphicsParams const & igp) rotateAngle = igp.rotateAngle; rotateOrigin = igp.rotateOrigin; special = igp.special; + groupId = igp.groupId; } @@ -123,7 +125,8 @@ bool operator==(InsetGraphicsParams const & left, left.rotateAngle == right.rotateAngle && left.rotateOrigin == right.rotateOrigin && - left.special == right.special; + left.special == right.special && + left.groupId == right.groupId; } @@ -174,6 +177,8 @@ void InsetGraphicsParams::Write(ostream & os, Buffer const & buffer) const os << "\trotateOrigin " << rotateOrigin << '\n'; if (!special.empty()) os << "\tspecial " << special << '\n'; + if (!groupId.empty()) + os << "\tgroupId "<< groupId << '\n'; } @@ -227,6 +232,9 @@ bool InsetGraphicsParams::Read(Lexer & lex, string const & token, string const & } else if (token == "special") { lex.eatLine(); special = lex.getString(); + } else if (token == "groupId") { + lex.eatLine(); + groupId = lex.getString(); // catch and ignore following two old-format tokens and their arguments. // e.g. "size_kind scale" clashes with the setting of the diff --git a/src/insets/InsetGraphicsParams.h b/src/insets/InsetGraphicsParams.h index f3429af..6cff596 100644 --- a/src/insets/InsetGraphicsParams.h +++ b/src/insets/InsetGraphicsParams.h @@ -83,6 +83,8 @@ public: // to display or not. graphics::Params as_grfxParams() const; + // Identification of the graphics template. No template equals empty string. + std::string groupId; private: /// Initialize the object to a default status. void init();