]> git.lyx.org Git - features.git/commitdiff
* InsetGraphics.{cpp.h}:
authorJürgen Spitzmüller <spitz@lyx.org>
Sat, 17 Jan 2009 08:02:52 +0000 (08:02 +0000)
committerJürgen Spitzmüller <spitz@lyx.org>
Sat, 17 Jan 2009 08:02:52 +0000 (08:02 +0000)
- add possibility to count graphics group members.

* GuiGraphics.{cpp, h}:
- warning message if a deserted group is going to be dissolved

* GraphicsUI.ui:
- terminology.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@28198 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt4/GuiGraphics.cpp
src/frontends/qt4/GuiGraphics.h
src/frontends/qt4/ui/GraphicsUi.ui
src/insets/InsetGraphics.cpp
src/insets/InsetGraphics.h

index f4a3928feb1dbd10f86f7719059776530b2d7906..0ca3ebb55c715f391d8f385cc14c41e353f50f3f 100644 (file)
@@ -296,15 +296,53 @@ void GuiGraphics::change_adaptor()
 
 void GuiGraphics::change_group(int index)
 {
-       QString const group = groupCO->itemData(
+       QString const new_group = groupCO->itemData(
                groupCO->currentIndex()).toString();
+       
+       // check if the old group consisted only of this member
+       if (current_group_ != fromqstr(new_group)
+           && graphics::countGroupMembers(buffer(), current_group_) == 1) {
+               if (!new_group.isEmpty()) {
+                       if (Alert::prompt(_("Dissolve previous group?"), 
+                               bformat(_("If you assign this graphic to group '%2$s',\n"
+                                         "the previously assigned group '%1$s' will be dissolved,\n"
+                                         "because this graphic was its only member.\n"
+                                         "How do you want to proceed?"),
+                                       from_utf8(current_group_), qstring_to_ucs4(new_group)),
+                                       0, 0,
+                                       bformat(_("Stick with group '%1$s'"),
+                                               from_utf8(current_group_)),
+                                       bformat(_("Assign to group '%1$s' anyway"),
+                                               qstring_to_ucs4(new_group))) == 0) {
+                               groupCO->setCurrentIndex(
+                                       groupCO->findData(toqstr(current_group_), Qt::MatchExactly));
+                               return;
+                       }
+               } else {
+                       if (Alert::prompt(_("Dissolve previous group?"), 
+                       bformat(_("If you sign off this graphic from group '%1$s',\n"
+                                 "the group will be dissolved,\n"
+                                 "because this graphic was its only member.\n"
+                                 "How do you want to proceed?"),
+                               from_utf8(current_group_)),
+                               0, 0,
+                               bformat(_("Stick with group '%1$s'"),
+                               from_utf8(current_group_)),
+                               bformat(_("Sign off from group '%1$s'"),
+                               from_utf8(current_group_))) == 0) {
+                       groupCO->setCurrentIndex(
+                               groupCO->findData(toqstr(current_group_), Qt::MatchExactly));
+                       return;
+                       }
+               }
+       } 
 
-       if (group.isEmpty()) {
+       if (new_group.isEmpty()) {
                changed();
                return;
        }
 
-       string grp = graphics::getGroupParams(buffer(), fromqstr(group));
+       string grp = graphics::getGroupParams(buffer(), fromqstr(new_group));
        if (grp.empty()) {
                // group does not exist yet
                changed();
@@ -745,6 +783,7 @@ void GuiGraphics::applyView()
 
        igp.groupId = fromqstr(groupCO->itemData(
                groupCO->currentIndex()).toString());
+       current_group_ = igp.groupId;
 }
 
 
@@ -780,6 +819,7 @@ bool GuiGraphics::initialiseParams(string const & data)
 {
        InsetGraphics::string2params(data, buffer(), params_);
        paramsToDialog(params_);
+       current_group_ = params_.groupId;
        return true;
 }
 
index 3f91126d4ec15b73dacef83fa8506d225ef4a4e2..2fbd77989881c2788ba5a170cdfb6c3b30471638 100644 (file)
@@ -81,6 +81,8 @@ private:
        std::vector<std::string> origin_ltx;
        ///
        InsetGraphicsParams params_;
+       /// the current graphics group
+       std::string current_group_;
 };
 
 } // namespace frontend
index 8092f39d4b88d958a9022716bc031d52c0237acd..c320f2ae71efcdd3b4ca1bcb4372f0e7c845bbba 100644 (file)
              <string/>
             </property>
             <property name="text" >
-             <string>Assigned to grou&amp;p:</string>
+             <string>A&amp;ssigned to group:</string>
             </property>
             <property name="buddy" >
              <cstring>groupCO</cstring>
           <item row="1" column="1" >
            <widget class="QPushButton" name="newGroupPB" >
             <property name="toolTip" >
-             <string>Click to define a new graphics group</string>
+             <string>Click to define a new graphics group.</string>
             </property>
             <property name="text" >
-             <string>De&amp;fine new group...</string>
+             <string>O&amp;pen new group...</string>
             </property>
            </widget>
           </item>
index 1116a5f96a42005e753ec897a4db905b31d26c5c..4c8ecad020d9b4d492de9641fca486f8df742a2c 100644 (file)
@@ -970,6 +970,24 @@ void getGraphicsGroups(Buffer const & b, set<string> & ids)
 }
 
 
+int countGroupMembers(Buffer const & b, string const & groupId)
+{
+       int n = 0;
+       if (groupId.empty())
+               return n;
+       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;
+               }
+       return n;
+}
+
+
 string getGroupParams(Buffer const & b, string const & groupId)
 {
        if (groupId.empty())
index 73a5edcf998109e0358a45110f428385546b5d0b..e18d8c63cb57f0c52eb11b4f00f82064164c8491 100644 (file)
@@ -124,6 +124,9 @@ namespace graphics {
        /// Saves the list of currently used groups in the document.
        void getGraphicsGroups(Buffer const &, std::set<std::string> &);
 
+       /// how many members has the current group?
+       int countGroupMembers(Buffer const &, std::string const &);
+
        /// Returns parameters of a given graphics group (except filename).
        std::string getGroupParams(Buffer const &, std::string const &);