From: Pavel Sanda Date: Tue, 6 May 2008 21:13:09 +0000 (+0000) Subject: Introduce groups for graphics insets. That includes: X-Git-Tag: 1.6.10~4872 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=13e42a8c73327c9174061c5c881a4e79406c9be3;p=features.git Introduce groups for graphics insets. That includes: - GuiGraphics dialog field for setup new groups. - Graphics context menu for assigning to certain group. - Fileformat change for groupId field in Graphics inset. - Undo mechanism added to inset-apply, for catching changes in preference dialog. - Qt designer 4.4 used now. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@24644 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/development/FORMAT b/development/FORMAT index 4a957b527e..aba24ce190 100644 --- a/development/FORMAT +++ b/development/FORMAT @@ -1,5 +1,7 @@ LyX file-format changes ----------------------- +2008-05-06 Pavel Sanda + * Format incremented to 332: Added groupId for graphics insets. 2008-25-04 Helge Hafting * Format incremented to 330: More horizontal fills diff --git a/lib/lyx2lyx/LyX.py b/lib/lyx2lyx/LyX.py index c7bf9b8875..2a85e44612 100644 --- a/lib/lyx2lyx/LyX.py +++ b/lib/lyx2lyx/LyX.py @@ -80,7 +80,7 @@ format_relation = [("0_06", [200], minor_versions("0.6" , 4)), ("1_3", [221], minor_versions("1.3" , 7)), ("1_4", range(222,246), minor_versions("1.4" , 5)), ("1_5", range(246,277), minor_versions("1.5" , 2)), - ("1_6", range(277,332), minor_versions("1.6" , 0))] + ("1_6", range(277,333), minor_versions("1.6" , 0))] def formats_list(): diff --git a/lib/lyx2lyx/lyx_1_6.py b/lib/lyx2lyx/lyx_1_6.py index fc94c6aef5..c8bc593777 100644 --- a/lib/lyx2lyx/lyx_1_6.py +++ b/lib/lyx2lyx/lyx_1_6.py @@ -2188,6 +2188,26 @@ def revert_master(document): del document.header[i] +def revert_graphics_group(document): + ' Revert group information from graphics insets ' + i = 0 + while 1: + i = find_token(document.body, "\\begin_inset Graphics", i) + if i == -1: + return + j = find_end_of_inset(document.body, i) + if j == -1: + document.warning("Malformed lyx document: Missing '\\end_inset'.") + i = i + 1 + continue + k = find_token(document.body, " groupId", i, j) + if k == -1: + i = i + 1 + continue + del document.body[k] + i = i + 1 + + ## # Conversion hub # @@ -2248,9 +2268,11 @@ convert = [[277, [fix_wrong_tables]], [329, []], [330, []], [331, [convert_ltcaption]], + [332, []], ] -revert = [[330, [revert_ltcaption]], +revert = [[331, [revert_graphics_group]], + [330, [revert_ltcaption]], [329, [revert_leftarrowfill, revert_rightarrowfill, revert_upbracefill, revert_downbracefill]], [328, [revert_master]], [327, []], diff --git a/lib/ui/stdcontext.inc b/lib/ui/stdcontext.inc index 58bdf1008e..cf801ef70a 100644 --- a/lib/ui/stdcontext.inc +++ b/lib/ui/stdcontext.inc @@ -300,6 +300,7 @@ Menuset Item "Settings...|S" "next-inset-toggle" Separator Item "Edit externally...|x" "inset-edit" + GraphicsGroups End # diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 86b93ce9d5..b6e234b752 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -115,7 +115,7 @@ namespace os = support::os; namespace { -int const LYX_FORMAT = 331; +int const LYX_FORMAT = 332; //ps, graphgroups typedef map DepClean; typedef map > RefCache; diff --git a/src/FuncCode.h b/src/FuncCode.h index 4619551357..0b51047d75 100644 --- a/src/FuncCode.h +++ b/src/FuncCode.h @@ -409,6 +409,8 @@ enum FuncCode LFUN_COMPLETION_COMPLETE, // 315 LFUN_NEXT_INSET_MODIFY, // JSpitzm 20080323 + LFUN_GRAPHICS_GROUPS_UNIFY, + LFUN_SET_GRAPHICS_GROUP, LFUN_LASTACTION // end of the table }; diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp index 2bd439c188..d584783b61 100644 --- a/src/LyXAction.cpp +++ b/src/LyXAction.cpp @@ -1239,6 +1239,27 @@ void LyXAction::init() * \endvar */ { LFUN_ALL_INSETS_TOGGLE, "all-insets-toggle", ReadOnly, Edit }, +/*! + * \var lyx::FuncCode lyx::LFUN_GRAPHICS_GROUPS_UNIFY + * \li Action: Unify all graphics insets with the one given as an parameter. + * \li Notion: This is internally used for synchronize certain group of graphics insets. + * \li Syntax: graphics-groups-unigfy + * \li Params: : Parameters for graphics inset + (syntax can be seen in .lyx files). + * \li Origin: sanda, 6 May 2008 + * \endvar + */ + { LFUN_GRAPHICS_GROUPS_UNIFY, "graphics-groups-unify", ReadOnly, Edit }, +/*! + * \var lyx::FuncCode lyx::LFUN_SET_GRAPHICS_GROUP + * \li Action: Set the group for the graphics inset on the cursor position. + * \li Syntax: set-graphics-group [] + * \li Params: : Id for an existing group. In case tthe Id is an empty string, + the graphics inset is removed from the current group. + * \li Origin: sanda, 6 May 2008 + * \endvar + */ + { LFUN_SET_GRAPHICS_GROUP, "set-graphics-group", ReadOnly, Edit }, /*! * \var lyx::FuncCode lyx::LFUN_FINISHED_FORWARD diff --git a/src/LyXFunc.cpp b/src/LyXFunc.cpp index c5d376686a..7bbeba7aef 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,16 @@ void LyXFunc::dispatch(FuncRequest const & cmd) break; } + case LFUN_GRAPHICS_GROUPS_UNIFY: { + LASSERT(lyx_view_, /**/); + if (argument.empty() || !lyx_view_->buffer()) break; + //view()->cursor().recordUndoFullDocument(); let inset-apply do that job + InsetGraphics::unifyGraphicsGroups(*lyx_view_->buffer(), argument); + lyx_view_->buffer()->markDirty(); + updateFlags = Update::Force | Update::FitCursor; + break; + } + case LFUN_BUFFER_LANGUAGE: { LASSERT(lyx_view_, /**/); Buffer & buffer = *lyx_view_->buffer(); diff --git a/src/Text3.cpp b/src/Text3.cpp index b5bdc3b4ec..3dd736b9dd 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -57,6 +57,8 @@ #include "insets/InsetSpecialChar.h" #include "insets/InsetText.h" #include "insets/InsetInfo.h" +#include "insets/InsetGraphics.h" +#include "insets/InsetGraphicsParams.h" #include "support/convert.h" #include "support/debug.h" @@ -890,6 +892,30 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) break; } + case LFUN_SET_GRAPHICS_GROUP: { + Inset * instmp = &cur.inset(); + if (instmp->lyxCode() != GRAPHICS_CODE) instmp = cur.nextInset(); + if (!instmp || instmp->lyxCode() != GRAPHICS_CODE) break; + + cur.recordUndoFullDocument(); + Inset & inset = *instmp; + InsetGraphics & ins = static_cast(inset); + + string id = to_utf8(cmd.argument()); + string grp = InsetGraphics::getGroupParams(bv->buffer(), id); + InsetGraphicsParams tmp, inspar = ins.getParams(); + + if (id.empty()) + inspar.groupId = to_utf8(cmd.argument()); + else { + InsetGraphics::string2params(grp, bv->buffer(), tmp); + tmp.filename = inspar.filename; + inspar = tmp; + } + + ins.setParams(inspar); + } + case LFUN_SPACE_INSERT: if (cur.paragraph().layout().free_spacing) insertChar(cur, ' '); @@ -2251,6 +2277,7 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd, case LFUN_BUFFER_BEGIN_SELECT: case LFUN_BUFFER_END_SELECT: case LFUN_UNICODE_INSERT: + case LFUN_SET_GRAPHICS_GROUP: // these are handled in our dispatch() enable = true; break; diff --git a/src/frontends/qt4/GuiGraphics.cpp b/src/frontends/qt4/GuiGraphics.cpp index e2740bab35..774c0f0578 100644 --- a/src/frontends/qt4/GuiGraphics.cpp +++ b/src/frontends/qt4/GuiGraphics.cpp @@ -539,6 +539,8 @@ void GuiGraphics::paramsToDialog(InsetGraphicsParams const & igp) scaleCB->blockSignals(false); Scale->setEnabled(scaleChecked); + groupId->setText(toqstr(igp.groupId)); + lengthAutoToWidgets(Width, widthUnit, igp.width, unitDefault); bool const widthChecked = !Width->text().isEmpty() && @@ -682,6 +684,8 @@ void GuiGraphics::applyView() // more latex options igp.special = fromqstr(latexoptions->text()); + + igp.groupId = fromqstr(groupId->text()); } @@ -732,6 +736,9 @@ 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/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index 65704847e4..2711b4826a 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -1844,6 +1844,7 @@ bool GuiView::dispatch(FuncRequest const & cmd) } case LFUN_INSET_APPLY: { + view()->cursor().recordUndoFullDocument(); string const name = cmd.getArg(0); Inset * inset = getOpenInset(name); if (inset) { diff --git a/src/frontends/qt4/Menus.cpp b/src/frontends/qt4/Menus.cpp index 62423d42a3..51ef148db9 100644 --- a/src/frontends/qt4/Menus.cpp +++ b/src/frontends/qt4/Menus.cpp @@ -49,6 +49,7 @@ #include "insets/Inset.h" #include "insets/InsetCitation.h" +#include "insets/InsetGraphics.h" #include "support/lassert.h" #include "support/convert.h" @@ -137,7 +138,9 @@ public: /** Available branches in document */ Branches, /** Available citation styles for a given citation */ - CiteStyles + CiteStyles, + /** Available graphics groups */ + GraphicsGroups }; explicit MenuItem(Kind kind) : kind_(kind), optional_(false) {} @@ -290,6 +293,7 @@ public: void expandToolbars(); void expandBranches(Buffer const * buf); void expandCiteStyles(BufferView const *); + void expandGraphicsGroups(Buffer const * buf); /// ItemList items_; /// @@ -390,7 +394,8 @@ void MenuDefinition::read(Lexer & lex) md_floatlistinsert, md_floatinsert, md_pasterecent, - md_toolbars + md_toolbars, + md_graphicsgroups }; LexerKeyword menutags[] = { @@ -405,6 +410,7 @@ void MenuDefinition::read(Lexer & lex) { "exportformats", md_exportformats }, { "floatinsert", md_floatinsert }, { "floatlistinsert", md_floatlistinsert }, + { "graphicsgroups", md_graphicsgroups }, { "importformats", md_importformats }, { "item", md_item }, { "lastfiles", md_lastfiles }, @@ -513,6 +519,10 @@ void MenuDefinition::read(Lexer & lex) add(MenuItem(MenuItem::CiteStyles)); break; + case md_graphicsgroups: + add(MenuItem(MenuItem::GraphicsGroups)); + break; + case md_optsubmenu: optional = true; // fallback to md_submenu @@ -623,6 +633,21 @@ QString limitStringLength(docstring const & str) } +void MenuDefinition::expandGraphicsGroups(Buffer const * buf) +{ + set grp; + InsetGraphics::getGraphicsGroups(*buf, grp); + set::const_iterator it = grp.begin(); + set::const_iterator end = grp.end(); + if (grp.empty()) return; + + add(MenuItem(MenuItem::Separator)); + add(MenuItem(MenuItem::Command, qt_("Clear group"), FuncRequest(LFUN_SET_GRAPHICS_GROUP))); + for (; it != end; it++) { + add(MenuItem(MenuItem::Command, toqstr(*it), FuncRequest(LFUN_SET_GRAPHICS_GROUP, *it))); + } +} + void MenuDefinition::expandLastfiles() { LastFilesSection::LastFiles const & lf = LyX::cref().session().lastFiles().lastFiles(); @@ -1396,6 +1421,10 @@ void Menus::Impl::expand(MenuDefinition const & frommenu, tomenu.expandToc(buf); break; + case MenuItem::GraphicsGroups: + tomenu.expandGraphicsGroups(buf); + break; + case MenuItem::Submenu: { MenuItem item(*cit); item.setSubmenu(MenuDefinition(cit->submenuname())); diff --git a/src/frontends/qt4/ui/GraphicsUi.ui b/src/frontends/qt4/ui/GraphicsUi.ui index 642681fc53..2ae6fad529 100644 --- a/src/frontends/qt4/ui/GraphicsUi.ui +++ b/src/frontends/qt4/ui/GraphicsUi.ui @@ -5,14 +5,12 @@ 0 0 - 481 - 354 + 584 + 373 - - 1 - 1 + 0 0 @@ -30,8 +28,95 @@ 6 + + + + 6 + + + 0 + + + + + &Restore + + + false + + + false + + + + + + + Qt::Horizontal + + + QSizePolicy::MinimumExpanding + + + + 20 + 20 + + + + + + + + &OK + + + true + + + true + + + + + + + + 0 + 0 + + + + &Apply + + + false + + + false + + + + + + + + 0 + 0 + + + + Close + + + false + + + + + - + @@ -39,6 +124,14 @@ 0 + + + 0 + 0 + 562 + 293 + + &Graphics @@ -86,9 +179,7 @@ true - - 1 - 0 + 0 0 @@ -103,7 +194,7 @@ Qt::Horizontal - + 61 20 @@ -120,9 +211,7 @@ true - - 1 - 0 + 0 0 @@ -229,9 +318,7 @@ - - 3 - 0 + 0 0 @@ -280,6 +367,14 @@ + + + 0 + 0 + 100 + 30 + + &Clipping @@ -295,7 +390,7 @@ Qt::Vertical - + 20 40 @@ -319,9 +414,7 @@ true - - 5 - 1 + 0 0 @@ -423,7 +516,7 @@ Qt::Horizontal - + 181 20 @@ -444,17 +537,65 @@ + + + 0 + 0 + 562 + 293 + + LaTe&X and LyX options - - 9 - - - 6 - - + + + + Additional LaTeX options + + + LaTeX &options: + + + latexoptions + + + + + + + + 0 + 0 + + + + Additional LaTeX options + + + + + + + Draft mode + + + &Draft mode + + + + + + + Don't uncompress image before exporting to LaTeX + + + Don't un&zip on export + + + + Qt::StrongFocus @@ -480,7 +621,7 @@ Qt::Horizontal - + 40 20 @@ -494,9 +635,7 @@ true - - 1 - 0 + 0 0 @@ -552,172 +691,59 @@ Screen display - &Display: + Scr&een Display: showCB + + + + + 0 + 0 + + + + Initialize Group-Id: + + + + + + + + 87 + 0 + + + + Group-id to be set up from the current parameters + + + - + Qt::Vertical - + - 20 - 41 + 354 + 81 - - - - Don't uncompress image before exporting to LaTeX - - - Don't un&zip on export - - - - - - - - 3 - 0 - 0 - 0 - - - - Additional LaTeX options - - - - - - - Additional LaTeX options - - - LaTeX &options: - - - latexoptions - - - - - - - Draft mode - - - &Draft mode - - - - - - - 0 - - - 6 - - - - - &Restore - - - false - - - false - - - - - - - Qt::Horizontal - - - QSizePolicy::MinimumExpanding - - - - 20 - 20 - - - - - - - - &OK - - - true - - - true - - - - - - - - 1 - 0 - 0 - 0 - - - - &Apply - - - false - - - false - - - - - - - - 1 - 0 - 0 - 0 - - - - Close - - - false - - - - - @@ -728,7 +754,7 @@ - TabWidget + tabWidget filename browsePB scaleCB diff --git a/src/insets/InsetGraphics.cpp b/src/insets/InsetGraphics.cpp index 2f6f4ab2ea..f280818a24 100644 --- a/src/insets/InsetGraphics.cpp +++ b/src/insets/InsetGraphics.cpp @@ -67,6 +67,7 @@ TODO #include "OutputParams.h" #include "sgml.h" #include "TocBackend.h" +#include "InsetIterator.h" #include "frontends/alert.h" #include "frontends/Application.h" @@ -949,4 +950,61 @@ string InsetGraphics::params2string(InsetGraphicsParams const & params, } +void InsetGraphics::getGraphicsGroups(Buffer const & b, std::set & 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(*it); + InsetGraphicsParams inspar = ins.getParams(); + if (!inspar.groupId.empty()) { + ids.insert(inspar.groupId); + } + } +} + + +string InsetGraphics::getGroupParams(Buffer const & b, std::string const & groupId) +{ + if (groupId.empty()) return string(); + 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(*it); + InsetGraphicsParams inspar = ins.getParams(); + if (inspar.groupId == groupId) { + InsetGraphicsParams tmp = inspar; + tmp.filename.erase(); + return params2string(tmp, b); + } + } + return string(); +} + +void InsetGraphics::unifyGraphicsGroups(Buffer const & b, std::string const & argument) +{ + InsetGraphicsParams params; + InsetGraphics::string2params(argument, b, params); + + 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(*it); + InsetGraphicsParams inspar = ins.getParams(); + if (params.groupId == inspar.groupId) { + params.filename = inspar.filename; + ins.setParams(params); + } + } + } + +} + + } // namespace lyx diff --git a/src/insets/InsetGraphics.h b/src/insets/InsetGraphics.h index dae9a701d2..2c601567b7 100644 --- a/src/insets/InsetGraphics.h +++ b/src/insets/InsetGraphics.h @@ -13,6 +13,7 @@ #ifndef INSET_GRAPHICS_H #define INSET_GRAPHICS_H +#include #include "Inset.h" #include "InsetGraphicsParams.h" @@ -47,11 +48,23 @@ public: /// static std::string params2string(InsetGraphicsParams const &, Buffer const &); + /// Saves the list of currently used groups in the document. + static void getGraphicsGroups(Buffer const &, std::set &); + /// Returns parameters of a given graphics group (except filename). + static std::string getGroupParams(Buffer const &, + std::string const &); + /** Synchronize all Graphics insets of the group. + Both groupId and params are taken from argument. + */ + static void unifyGraphicsGroups(Buffer const &, std::string const &); + /** Set the inset parameters, used by the GUIndependent dialog. Return true of new params are different from what was so far. */ bool setParams(InsetGraphicsParams const & params); + InsetGraphicsParams getParams() const { return params_;} + private: /// InsetGraphics(InsetGraphics const &); diff --git a/src/insets/InsetGraphicsParams.cpp b/src/insets/InsetGraphicsParams.cpp index 35fb9bcb51..b2b15f0ad3 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 f3429afe9b..6cff596533 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();