]> git.lyx.org Git - features.git/commitdiff
Unify graphics-groups inside marked block functionality.
authorPavel Sanda <sanda@lyx.org>
Thu, 8 Feb 2018 20:33:37 +0000 (21:33 +0100)
committerPavel Sanda <sanda@lyx.org>
Thu, 15 Feb 2018 19:42:36 +0000 (20:42 +0100)
Fixes #11026.

https://www.mail-archive.com/lyx-devel@lists.lyx.org/msg203683.html

lib/ui/stdcontext.inc
src/BufferView.cpp
src/FuncCode.h
src/LyXAction.cpp

index 3e490927bec3092c9a670c0ccee97086b98c6647..9acf334562eab6471a87906774ebe2fc388af2d9 100644 (file)
@@ -358,6 +358,7 @@ Menuset
                Item "Apply Last Text Style|A" "textstyle-apply"
                Submenu "Text Style|x" "edit_textstyles"
                Item "Paragraph Settings...|P" "layout-paragraph"
+               OptItem "Unify Graphics Groups|U" "graphics-unify"
                LanguageSelector
                Separator
                Item "Fullscreen Mode" "ui-toggle fullscreen"
index 36ac46cddea813e17fd7b643573699edbfa98fb0..edea2eb3205fffd4216a53ce189c988a62d4856e 100644 (file)
@@ -1134,6 +1134,10 @@ bool BufferView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
                flag.setEnabled(true);
                break;
 
+       case LFUN_GRAPHICS_UNIFY:
+               flag.setEnabled(cur.selection());
+               break;
+
        case LFUN_WORD_FINDADV: {
                FindAndReplaceOptions opt;
                istringstream iss(to_utf8(cmd.argument()));
@@ -1655,6 +1659,47 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                break;
        }
 
+       case LFUN_GRAPHICS_UNIFY: {
+
+               cur.recordUndoFullBuffer();
+
+               DocIterator from, to;
+               from = cur.selectionBegin();
+               to = cur.selectionEnd();
+
+               string newId = cmd.getArg(0);
+               bool fetchId=newId.empty(); //if we wait for groupId from first graphics inset
+
+               InsetGraphicsParams grp_par;
+               InsetGraphics::string2params(graphics::getGroupParams(buffer_, newId), buffer_, grp_par);
+
+               if (!from.nextInset())  //move to closest inset
+                       from.forwardInset();
+
+               while (!from.empty() && from < to) {
+                       Inset * inset = from.nextInset();
+                       if (!inset)
+                               break;
+                       if (inset->lyxCode() == GRAPHICS_CODE) {
+                               InsetGraphics * ig = inset->asInsetGraphics();
+                               if (!ig)
+                                       break;
+                               InsetGraphicsParams inspar = ig->getParams();
+                               if (fetchId) {
+                                       grp_par = inspar;
+                                       fetchId = false;
+
+                               } else {
+                                       grp_par.filename = inspar.filename;
+                                       ig->setParams(grp_par);
+                               }
+                       }
+                       from.forwardInset();
+               }
+               dr.screenUpdate(Update::Force); //needed if triggered from context menu
+               break;
+       }
+
        case LFUN_STATISTICS: {
                DocIterator from, to;
                if (cur.selection()) {
index 4a5983147de7964bd26959d7a2b371cc5d4890e3..cce61f0df5bd9ef98430b422a83f1b4cbbfc74f8 100644 (file)
@@ -476,7 +476,8 @@ enum FuncCode
        LFUN_DEVEL_MODE_TOGGLE,         // lasgouttes 20170723
        //370
        LFUN_EXPORT_CANCEL,             // rgh, 20171227
-       LFUN_BUFFER_ANONYMIZE,             // sanda, 20180201
+       LFUN_BUFFER_ANONYMIZE,          // sanda, 20180201
+       LFUN_GRAPHICS_UNIFY,            // sanda, 20180207
        LFUN_LASTACTION                 // end of the table
 };
 
index 33d5100a823b1b76c5507a50b145f88caadfe79e..871612ed4a5aab263247ac22d0dca0ae0f6d912a 100644 (file)
@@ -3545,6 +3545,17 @@ void LyXAction::init()
  */
                { LFUN_SET_GRAPHICS_GROUP, "set-graphics-group", Noop, Edit },
 
+/*!
+ * \var lyx::FuncCode lyx::LFUN_GRAPHICS_UNIFY
+ * \li Action: Set the same group for all graphics insets in the marked block.
+ * \li Syntax: graphics-unify [<GROUP>]
+ * \li Params: <GROUP>: Id for an existing group. In case the Id is an empty string,
+                        the group Id from the first graphics inset will be used.
+ * \li Origin: sanda, 7 Feb 2018
+ * \endvar
+ */
+               { LFUN_GRAPHICS_UNIFY, "graphics-unify", Noop, Edit },
+
 
 /*!
  * \var lyx::FuncCode lyx::LFUN_SPACE_INSERT