]> git.lyx.org Git - features.git/commitdiff
* Add possibility to append active branch names to the output file name (#3105).
authorJürgen Spitzmüller <spitz@lyx.org>
Mon, 13 Jul 2009 14:30:08 +0000 (14:30 +0000)
committerJürgen Spitzmüller <spitz@lyx.org>
Mon, 13 Jul 2009 14:30:08 +0000 (14:30 +0000)
File format change.

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

development/FORMAT
lib/lyx2lyx/lyx_2_0.py
src/BranchList.cpp
src/BranchList.h
src/Buffer.cpp
src/Buffer.h
src/BufferParams.cpp
src/frontends/qt4/GuiBranches.cpp
src/frontends/qt4/GuiBranches.h
src/frontends/qt4/ui/BranchesUi.ui

index 43adc0a65367f96dd3ac0c0427c8e674eaaff508..5c36ddb90218b6d88fe11262364950411c97918f 100644 (file)
@@ -1,6 +1,10 @@
 LyX file-format changes
 -----------------------
 
+2009-07-13 Jürgen Spitzmüller <spitz@lyx.org>
+       * Format incremented to 364: add \filename_suffix parameter
+         to branches.
+
 2009-07-11 Uwe Stöhr <uwestoehr@web.de>
        * Format incremented to 363: support for horizontal longtable
          alignment.
index 9d3ed63bae5474a3dce1ecb4c80c0de5e813ca56..cb2461dd52f10b5267ed25bbfc611869d2b7010d 100644 (file)
@@ -750,6 +750,16 @@ def revert_longtable_align(document):
       i = i + 1
 
 
+def revert_branch_filename(document):
+    " Remove \\filename_suffix parameter from branches "
+    i = 0
+    while True:
+        i = find_token(document.header, "\\filename_suffix", i)
+        if i == -1:
+            return
+        del document.header[i]
+
+
 ##
 # Conversion hub
 #
@@ -772,10 +782,12 @@ convert = [[346, []],
            [360, []],
            [361, []],
            [362, []],
-           [363, []]
+           [363, []],
+           [364, []]
           ]
 
-revert =  [[362, [revert_longtable_align]],
+revert =  [[363, [revert_branch_filename]],
+           [362, [revert_longtable_align]],
            [361, [revert_applemac]],
            [360, []],
            [359, [revert_nomencl_cwidth]],
index 02f8b8688d4d377976588f7d58ec7fa7c0bdfca6..2afc765a3d53aba2b4d04a14f03c57a3d07f0015 100644 (file)
@@ -4,6 +4,7 @@
  * Licence details can be found in the file COPYING.
  *
  * \author Martin Vermeer
+ * \author Jürgen Spitzmüller
  *
  * Full author contact details are available in file CREDITS.
  */
@@ -15,6 +16,8 @@
 
 #include "frontends/Application.h"
 
+#include "support/lstrings.h"
+
 #include <algorithm>
 
 using namespace std;
@@ -39,7 +42,8 @@ private:
 }
 
 
-Branch::Branch() : selected_(false)
+Branch::Branch()
+       : selected_(false), filenameSuffix_(false)
 {
        // no theApp() with command line export
        if (theApp())
@@ -74,6 +78,18 @@ bool Branch::setSelected(bool b)
 }
 
 
+bool Branch::hasFilenameSuffix() const
+{
+       return filenameSuffix_;
+}
+
+
+void Branch::setFilenameSuffix(bool b)
+{
+       filenameSuffix_ = b;
+}
+
+
 RGBColor const & Branch::color() const
 {
        return color_;
@@ -132,6 +148,7 @@ bool BranchList::add(docstring const & s)
                        Branch br;
                        br.setBranch(name);
                        br.setSelected(false);
+                       br.setFilenameSuffix(false);
                        list.push_back(br);
                }
                if (j == docstring::npos)
@@ -171,4 +188,15 @@ bool BranchList::rename(docstring const & oldname,
 }
 
 
+docstring BranchList::getFilenameSuffix() const
+{
+       docstring result;
+       List::const_iterator it = list.begin();
+       for (; it != list.end(); ++it) {
+               if (it->isSelected() && it->hasFilenameSuffix())
+                       result += "-" + it->branch();
+       }
+       return support::subst(result, from_ascii("/"), from_ascii("_"));
+}
+
 } // namespace lyx
index 08a719a1c7cbb0c92076839cf330680eebc25478..21f8d05303d6b4fd86791bbdbe4ea58c14d2613e 100644 (file)
@@ -53,6 +53,12 @@ public:
         *  \return true if the selection status changes.
         */
        bool setSelected(bool);
+       /** If true, the branch name will be appended
+        *  to the output file name.
+        */
+       bool hasFilenameSuffix() const;
+       /// Select/deselect filename suffix property.
+       void setFilenameSuffix(bool);
        ///
        RGBColor const & color() const;
        ///
@@ -71,6 +77,8 @@ private:
        ///
        bool selected_;
        ///
+       bool filenameSuffix_;
+       ///
        RGBColor color_;
 };
 
@@ -111,6 +119,8 @@ public:
         * if a branch with the newname already exists.
         */
        bool rename(docstring const &, docstring const &, bool const merge = false);
+       /// get the complete filename suffix
+       docstring getFilenameSuffix() const;
 
 private:
        ///
index b72af58f79f8ee1e432f46efb257ae5ee1670114..979b37ed5f27d220bfce3cec9f8954e5a8a4fc5c 100644 (file)
@@ -127,7 +127,7 @@ namespace {
 
 // Do not remove the comment below, so we get merge conflict in
 // independent branches. Instead add your own.
-int const LYX_FORMAT = 363;  // uwestoehr: support for longtable alignment
+int const LYX_FORMAT = 364;  // spitz: branch suffixes for filenames
 
 typedef map<string, bool> DepClean;
 typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;
@@ -440,12 +440,29 @@ Undo & Buffer::undo()
 
 string Buffer::latexName(bool const no_path) const
 {
-       FileName latex_name = makeLatexName(d->filename);
+       FileName latex_name =
+               makeLatexName(exportFileName());
        return no_path ? latex_name.onlyFileName()
                : latex_name.absFilename();
 }
 
 
+FileName Buffer::exportFileName() const
+{
+       docstring const branch_suffix =
+               params().branchlist().getFilenameSuffix();
+       if (branch_suffix.empty())
+               return fileName();
+
+       string const name = fileName().onlyFileNameWithoutExt()
+               + to_utf8(branch_suffix);
+       FileName res(fileName().onlyPath().absFilename() + "/" + name);
+       res.changeExtension(fileName().extension());
+
+       return res;
+}
+
+
 string Buffer::logName(LogType * type) const
 {
        string const filename = latexName(false);
@@ -2958,7 +2975,7 @@ bool Buffer::doExport(string const & format, bool put_in_tempdir,
                return true;
        }
 
-       result_file = changeExtension(absFileName(), ext);
+       result_file = changeExtension(exportFileName().absFilename(), ext);
        // We need to copy referenced files (e. g. included graphics
        // if format == "dvi") to the result dir.
        vector<ExportedFile> const files =
index 71e8ac32c13ce92f42abfc2f3b86b2b074f610b4..6cb04bb7c0b72693b0bfe5a299554fb471ccaae6 100644 (file)
@@ -551,6 +551,11 @@ private:
        ReadStatus readFile(Lexer &, support::FileName const & filename,
                            bool fromString = false);
 
+       /** If we have branches that use the file suffix
+           feature, return the file name with suffix appended.
+       */
+       support::FileName exportFileName() const;
+
        /// Use the Pimpl idiom to hide the internals.
        class Impl;
        /// The pointer never changes although *pimpl_'s contents may.
index 72d1a93d1f724935a64600e8225515dc6d4381c4..1d54cd9fbaf984ee6d518cda54e15dbea601968d 100644 (file)
@@ -618,6 +618,11 @@ string BufferParams::readToken(Lexer & lex, string const & token,
                                if (branch_ptr)
                                        branch_ptr->setSelected(lex.getInteger());
                        }
+                       if (tok == "\\filename_suffix") {
+                               lex.next();
+                               if (branch_ptr)
+                                       branch_ptr->setFilenameSuffix(lex.getInteger());
+                       }
                        // not yet operational
                        if (tok == "\\color") {
                                lex.eatLine();
@@ -849,6 +854,7 @@ void BufferParams::writeFile(ostream & os) const
        for (; it != end; ++it) {
                os << "\\branch " << to_utf8(it->branch())
                   << "\n\\selected " << it->isSelected()
+                  << "\n\\filename_suffix " << it->hasFilenameSuffix()
                   << "\n\\color " << lyx::X11hexname(it->color())
                   << "\n\\end_branch"
                   << "\n";
index b3af3ed2936cb9f9ca0d979e7d1da38dd94b4684..5f9121dd640c5a032b67d6d0cd0f4a4c434618a1 100644 (file)
@@ -49,6 +49,7 @@ GuiBranches::GuiBranches(QWidget * parent)
        branchesTW->headerItem()->setText(0, qt_("Branch"));
        branchesTW->headerItem()->setText(1, qt_("Activated"));
        branchesTW->headerItem()->setText(2, qt_("Color"));
+       branchesTW->headerItem()->setText(3, qt_("Filename Suffix"));
        branchesTW->setSortingEnabled(true);
 
        undef_ = new BranchesUnknownDialog(this);
@@ -101,6 +102,7 @@ void GuiBranches::updateView()
                        coloritem.fill(itemcolor);
                        newItem->setIcon(2, QIcon(coloritem));
                }
+               newItem->setText(3, it->hasFilenameSuffix() ? qt_("Yes") : qt_("No"));
                // restore selected branch
                if (bname == sel_branch) {
                        branchesTW->setCurrentItem(newItem);
@@ -114,6 +116,7 @@ void GuiBranches::updateView()
        renamePB->setEnabled(have_sel);
        colorPB->setEnabled(have_sel);
        activatePB->setEnabled(have_sel);
+       suffixPB->setEnabled(have_sel);
        // emit signal
        changed();
 }
@@ -193,12 +196,20 @@ void GuiBranches::on_activatePB_pressed()
 }
 
 
+void GuiBranches::on_suffixPB_pressed()
+{
+       toggleSuffix(branchesTW->currentItem());
+}
+
+
 void GuiBranches::on_branchesTW_itemDoubleClicked(QTreeWidgetItem * item, int col)
 {
        if (col < 2)
                toggleBranch(item);
-       else
+       else if (col == 2)
                toggleColor(item);
+       else if (col == 3)
+               toggleSuffix(item);
 }
 
 
@@ -210,6 +221,7 @@ void GuiBranches::on_branchesTW_itemSelectionChanged()
        renamePB->setEnabled(have_sel);
        colorPB->setEnabled(have_sel);
        activatePB->setEnabled(have_sel);
+       suffixPB->setEnabled(have_sel);
 }
 
 
@@ -222,9 +234,8 @@ void GuiBranches::toggleBranch(QTreeWidgetItem * item)
        if (sel_branch.isEmpty())
                return;
 
-       bool const selected = (item->text(1) == qt_("Yes"));
        Branch * branch = branchlist_.find(qstring_to_ucs4(sel_branch));
-       if (branch && branch->setSelected(!selected)) {
+       if (branch && branch->setSelected(!branch->isSelected())) {
                newBranchLE->clear();
                updateView();
        }
@@ -263,6 +274,24 @@ void GuiBranches::toggleColor(QTreeWidgetItem * item)
 }
 
 
+void GuiBranches::toggleSuffix(QTreeWidgetItem * item)
+{
+       if (item == 0)
+               return;
+
+       QString sel_branch = item->text(0);
+       if (sel_branch.isEmpty())
+               return;
+
+       Branch * branch = branchlist_.find(qstring_to_ucs4(sel_branch));
+       if (branch) {
+               branch->setFilenameSuffix(!branch->hasFilenameSuffix());
+               newBranchLE->clear();
+               updateView();
+       }
+}
+
+
 void GuiBranches::on_unknownPB_pressed()
 {
        undef_->branchesLW->clear();
index b42cc5e3628bd53d6a13d014374aac5fd0e0bb87..0417e84b64368ccd491e2f55c1e150efc7dad33f 100644 (file)
@@ -55,6 +55,7 @@ Q_SIGNALS:
 protected:
        void toggleBranch(QTreeWidgetItem *);
        void toggleColor(QTreeWidgetItem *);
+       void toggleSuffix(QTreeWidgetItem *);
        void updateView();
 
 protected Q_SLOTS:
@@ -65,6 +66,7 @@ protected Q_SLOTS:
        void on_branchesTW_itemDoubleClicked(QTreeWidgetItem *, int);
        void on_branchesTW_itemSelectionChanged();
        void on_colorPB_clicked();
+       void on_suffixPB_pressed();
        void on_unknownPB_pressed();
        void addUnknown();
        void addAllUnknown();
index dd165ffa7ef1da6bcc1d2b034f648c3e84538e9d..298931e1e55ad175c6b96e2dcf0aa4f730b18b15 100644 (file)
    <property name="spacing" >
     <number>6</number>
    </property>
-   <item row="3" column="3" >
-    <widget class="QPushButton" name="renamePB" >
-     <property name="toolTip" >
-      <string>Change the name of the selected branch</string>
-     </property>
+   <item row="0" column="0" >
+    <widget class="QLabel" name="newBranchLA" >
      <property name="text" >
-      <string>Re&amp;name...</string>
-     </property>
-    </widget>
-   </item>
-   <item row="2" column="3" >
-    <widget class="QPushButton" name="removePB" >
-     <property name="toolTip" >
-      <string>Remove the selected branch</string>
+      <string>&amp;New:</string>
      </property>
-     <property name="text" >
-      <string>&amp;Remove</string>
+     <property name="buddy" >
+      <cstring>newBranchLE</cstring>
      </property>
     </widget>
    </item>
-   <item row="4" column="3" >
-    <widget class="QPushButton" name="colorPB" >
+   <item row="5" column="3" >
+    <widget class="QPushButton" name="suffixPB" >
      <property name="toolTip" >
-      <string>Define or change background color</string>
+      <string>Append the name of this branch to the output filename, given the branch is active.</string>
      </property>
      <property name="text" >
-      <string>Alter Co&amp;lor...</string>
+      <string>Filename &amp;Suffix</string>
      </property>
     </widget>
    </item>
-   <item row="5" column="3" >
+   <item row="6" column="3" >
     <spacer>
      <property name="orientation" >
       <enum>Qt::Vertical</enum>
      <property name="sizeHint" >
       <size>
        <width>83</width>
-       <height>61</height>
+       <height>51</height>
       </size>
      </property>
     </spacer>
    </item>
-   <item row="0" column="1" colspan="2" >
-    <widget class="QLineEdit" name="newBranchLE" />
-   </item>
-   <item row="0" column="3" >
-    <widget class="QPushButton" name="addBranchPB" >
+   <item row="8" column="2" colspan="2" >
+    <widget class="QPushButton" name="unknownPB" >
      <property name="toolTip" >
-      <string>Add a new branch to the list</string>
+      <string>Show undefined branches used in this document.</string>
      </property>
      <property name="text" >
-      <string>&amp;Add</string>
+      <string>&amp;Undefined Branches</string>
      </property>
     </widget>
    </item>
-   <item row="0" column="0" >
-    <widget class="QLabel" name="newBranchLA" >
+   <item row="8" column="0" colspan="2" >
+    <spacer>
+     <property name="orientation" >
+      <enum>Qt::Horizontal</enum>
+     </property>
+     <property name="sizeHint" >
+      <size>
+       <width>251</width>
+       <height>20</height>
+      </size>
+     </property>
+    </spacer>
+   </item>
+   <item row="1" column="0" colspan="3" >
+    <widget class="QLabel" name="availableLB" >
      <property name="text" >
-      <string>&amp;New:</string>
+      <string>A&amp;vailable Branches:</string>
      </property>
      <property name="buddy" >
-      <cstring>newBranchLE</cstring>
+      <cstring>branchesTW</cstring>
      </property>
     </widget>
    </item>
-   <item rowspan="5" row="2" column="0" colspan="3" >
-    <widget class="QTreeWidget" name="branchesTW" />
-   </item>
-   <item row="6" column="3" >
+   <item row="7" column="3" >
     <widget class="QPushButton" name="activatePB" >
      <property name="toolTip" >
       <string>Toggle the selected branch</string>
      </property>
     </widget>
    </item>
-   <item row="1" column="0" colspan="3" >
-    <widget class="QLabel" name="availableLB" >
+   <item rowspan="6" row="2" column="0" colspan="3" >
+    <widget class="QTreeWidget" name="branchesTW" />
+   </item>
+   <item row="0" column="3" >
+    <widget class="QPushButton" name="addBranchPB" >
+     <property name="toolTip" >
+      <string>Add a new branch to the list</string>
+     </property>
      <property name="text" >
-      <string>A&amp;vailable Branches:</string>
+      <string>&amp;Add</string>
      </property>
-     <property name="buddy" >
-      <cstring>branchesTW</cstring>
+    </widget>
+   </item>
+   <item row="0" column="1" colspan="2" >
+    <widget class="QLineEdit" name="newBranchLE" />
+   </item>
+   <item row="4" column="3" >
+    <widget class="QPushButton" name="colorPB" >
+     <property name="toolTip" >
+      <string>Define or change background color</string>
+     </property>
+     <property name="text" >
+      <string>Alter Co&amp;lor...</string>
      </property>
     </widget>
    </item>
-   <item row="7" column="0" colspan="2" >
-    <spacer>
-     <property name="orientation" >
-      <enum>Qt::Horizontal</enum>
+   <item row="2" column="3" >
+    <widget class="QPushButton" name="removePB" >
+     <property name="toolTip" >
+      <string>Remove the selected branch</string>
      </property>
-     <property name="sizeHint" >
-      <size>
-       <width>251</width>
-       <height>20</height>
-      </size>
+     <property name="text" >
+      <string>&amp;Remove</string>
      </property>
-    </spacer>
+    </widget>
    </item>
-   <item row="7" column="2" colspan="2" >
-    <widget class="QPushButton" name="unknownPB" >
+   <item row="3" column="3" >
+    <widget class="QPushButton" name="renamePB" >
      <property name="toolTip" >
-      <string>Show undefined branches used in this document.</string>
+      <string>Change the name of the selected branch</string>
      </property>
      <property name="text" >
-      <string>&amp;Undefined Branches</string>
+      <string>Re&amp;name...</string>
      </property>
     </widget>
    </item>