]> git.lyx.org Git - features.git/commitdiff
Embedding: add a check box to InsetGraphic and show/change embedding status
authorBo Peng <bpeng@lyx.org>
Sat, 15 Sep 2007 18:31:32 +0000 (18:31 +0000)
committerBo Peng <bpeng@lyx.org>
Sat, 15 Sep 2007 18:31:32 +0000 (18:31 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20297 a592a061-630c-0410-9148-cb99ea01b6c8

lib/lyx2lyx/lyx_1_6.py
src/EmbeddedFiles.cpp
src/EmbeddedFiles.h
src/frontends/controllers/ControlEmbeddedFiles.cpp
src/frontends/qt4/GuiGraphics.cpp
src/frontends/qt4/ui/GraphicsUi.ui
src/insets/InsetGraphics.cpp
src/insets/InsetGraphicsParams.cpp
src/insets/InsetGraphicsParams.h

index 30c3421942f30d16e5d42ab181b6a5da68a918cc..84f8ba663385150fb1efda66a7a555e568b38acc 100644 (file)
@@ -179,6 +179,26 @@ def remove_manifest(document):
     document.manifest = None
 
 
+def remove_inzip_options(document):
+    "Remove inzipName and embed options from the Graphics inset"
+    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 + 1)
+        if j == -1:
+            # should not happen
+            document.warning("Malformed LyX document: Could not find end of graphics inset.")
+        # If there's a inzip param, just remove that
+        k = find_token(document.body, "\tinzipName", i + 1, j)
+        if k != -1:
+            del document.body[k]
+            # embed option must follow the inzipName option
+            del document.body[k+1]
+        i = i + 1
+
+
 ##
 # Conversion hub
 #
@@ -197,7 +217,7 @@ convert = [
           ]
 
 revert =  [
-           [284, [remove_manifest]],
+           [284, [remove_manifest, remove_inzip_options]],
            [283, []],
            [282, [revert_flex]],
            [281, []],
index a28864b4b221d2c2e230283e10303414a41f9a63..a985ea646cea538572c62209ae2cf0e92c1d3bc8 100644 (file)
@@ -468,7 +468,9 @@ void EmbeddedFiles::writeManifest(ostream & os) const
        EmbeddedFiles::EmbeddedFileList::const_iterator it = begin();
        EmbeddedFiles::EmbeddedFileList::const_iterator it_end = end();
        for (; it != it_end; ++it) {
-               if (!it->valid())
+               // only saved 'extra' files. Other embedded files are saved
+               // with insets.
+               if (!it->valid() || it->refCount() > 0)
                        continue;
                // save the relative path
                os << "\\filename "
index 0191c3b3661065dcb6325d57a34cf99c39cb8257..1d526973d3cbafd6abc1179aea28e4fc71fa48e6 100644 (file)
@@ -113,11 +113,14 @@ class ErrorList;
 class EmbeddedFile : public support::DocFileName
 {
 public:
+       EmbeddedFile() {};
+
        EmbeddedFile(std::string const & file, std::string const & inzip_name,
                bool embedded, Inset const * inset);
 
        /// filename in the zip file, usually the relative path
        std::string inzipName() const { return inzip_name_; }
+       void setInzipName(std::string name) { inzip_name_ = name; }
        /// embedded file, equals to temppath()/inzipName()
        std::string embeddedFile(Buffer const * buf) const;
        /// embeddedFile() or absFilename() depending on embedding status
index ac61878bdbc09e5d075fdbeed5b7bea067709907..fddf866b4307e2d37a725744b24ec3613d77dcb5 100644 (file)
@@ -111,6 +111,9 @@ void ControlEmbeddedFiles::setEmbed(EmbeddedFile & item, bool embed, bool update
                else
                        item.extract(&buffer());
                item.updateInsets(&buffer());
+               // FIXME: unless we record the type of file item, we will
+               // need to update all possible dialogs (bibtex etc).
+               updateDialog("graphics");
        }
        if (embed)
                dispatchMessage("Embed file " + item.outputFilename(buffer().filePath()));
index 2c47a0aca9b636ad5f5c005eab8debbabe643843..a1741ba4a91c3d14a09bf1e196d4e86a86018333 100644 (file)
@@ -285,6 +285,7 @@ void GuiGraphicsDialog::on_browsePB_clicked()
                controller().browse(qstring_to_ucs4(filename->text()));
        if(!str.empty()){
                filename->setText(toqstr(str));
+               embedCB->setCheckState(Qt::Unchecked);
                changed();
        }
 }
@@ -454,6 +455,7 @@ void GuiGraphicsDialog::updateContents()
        string const name =
                igp.filename.outputFilename(controller().bufferFilepath());
        filename->setText(toqstr(name));
+    embedCB->setCheckState(igp.filename.embedded() ? Qt::Checked : Qt::Unchecked);
 
        // set the bounding box values
        if (igp.bb.empty()) {
@@ -600,6 +602,7 @@ void GuiGraphicsDialog::applyView()
 
        igp.filename.set(internal_path(fromqstr(filename->text())),
                         controller().bufferFilepath());
+       igp.filename.setEmbed(embedCB->checkState() == Qt::Checked);
 
        // the bb section
        igp.bb.erase();
index ff70d6d77a545c775414756eeb700d32684464fe..e4799ad4b527e3d592514cffe82024b7b6fa3c85 100644 (file)
@@ -49,7 +49,7 @@
        <property name="spacing" >
         <number>6</number>
        </property>
-       <item row="0" column="3" >
+       <item row="0" column="4" >
         <widget class="QPushButton" name="editPB" >
          <property name="text" >
           <string>&amp;Edit</string>
@@ -62,7 +62,7 @@
          </property>
         </widget>
        </item>
-       <item row="0" column="2" >
+       <item row="0" column="3" >
         <widget class="QPushButton" name="browsePB" >
          <property name="toolTip" >
           <string>Select an image file</string>
           <string>&amp;Browse...</string>
          </property>
         </widget>
+       </item>
+           <item row="0" column="2">
+           <widget class="QCheckBox" name="embedCB" >
+            <property name="text" >
+             <string></string>
+            </property>
+           </widget>
        </item>
        <item row="0" column="1" >
         <widget class="QLineEdit" name="filename" >
@@ -92,7 +99,7 @@
          </property>
         </widget>
        </item>
-       <item row="1" column="0" colspan="4" >
+       <item row="1" column="0" colspan="5" >
         <widget class="QGroupBox" name="sizeGB" >
          <property name="title" >
           <string>Output Size</string>
          </layout>
         </widget>
        </item>
-       <item row="2" column="0" colspan="4" >
+       <item row="2" column="0" colspan="5" >
         <widget class="QGroupBox" name="rotationGB" >
          <property name="title" >
           <string>Rotate Graphics</string>
index e979e24e2f8303ff9409e231324dc966c1c6e2dd..b75fc82def1a429b6eb50ca04797f0b6694c981b 100644 (file)
@@ -243,13 +243,11 @@ void InsetGraphics::updateEmbeddedFile(Buffer const & buf,
        EmbeddedFile const & file)
 {
        BOOST_ASSERT(buf.embeddedFiles().enabled());
-       LYXERR(Debug::FILES) << "Update InsetGraphics file from " 
-               << params_.filename.toFilesystemEncoding() << std::endl;
-       params_.filename.set(file.availableFile(&buf), buf.filePath());
-       LYXERR(Debug::FILES) << " to " 
-               << params_.filename.toFilesystemEncoding() << std::endl;
-       // FIXME: graphics dialog is not updated even if the underlying
-       // filename is updated. What should I do?
+       params_.filename = file;
+       LYXERR(Debug::FILES) << "Update InsetGraphic with File " 
+               << params_.filename.toFilesystemEncoding() 
+               << ", embedding status: "
+               << params_.filename.embedded() << std::endl;
 }
 
 
@@ -305,7 +303,7 @@ void InsetGraphics::read(Buffer const & buf, Lexer & lex)
                if (it != buf.embeddedFiles().end())
                        // using available file, embedded or external, depending on file availability and
                        // embedding status.
-                       params_.filename = DocFileName(it->availableFile(&buf));
+                       params_.filename = *it;
        }
        graphic_->update(params().as_grfxParams());
 }
index 6b1bc4cfd4d1e779548b688d6787aaf3efa90649..73060d027c213835e51e00707694066c040383c7 100644 (file)
@@ -18,7 +18,6 @@
 #include "Lexer.h"
 #include "LyXRC.h"
 #include "Buffer.h"
-#include "EmbeddedFiles.h"
 
 #include "graphics/GraphicsParams.h"
 
@@ -154,15 +153,10 @@ bool operator!=(InsetGraphicsParams const & left,
 void InsetGraphicsParams::Write(ostream & os, Buffer const & buffer) const
 {
        // Do not write the default values
-
        if (!filename.empty()) {
-               // when we save, we still use the original filename
-               EmbeddedFiles::EmbeddedFileList::const_iterator it = 
-                       buffer.embeddedFiles().find(filename.toFilesystemEncoding());
-               if (it != buffer.embeddedFiles().end())
-                       os << "\tfilename " << DocFileName(it->absFilename()).outputFilename(buffer.filePath()) << '\n';
-               else
-                       os << "\tfilename " << filename.outputFilename(buffer.filePath()) << '\n';
+               os << "\tfilename " << filename.outputFilename(buffer.filePath()) << '\n';
+               os << "\tinzipName " << filename.inzipName() << '\n';
+               os << "\tembed " << (filename.embedded() ? "true" : "false") << '\n';
        }
        if (lyxscale != 100)
                os << "\tlyxscale " << lyxscale << '\n';
@@ -211,6 +205,12 @@ bool InsetGraphicsParams::Read(Lexer & lex, string const & token, string const &
        if (token == "filename") {
                lex.eatLine();
                filename.set(lex.getString(), bufpath);
+       } else if (token == "inzipName") {
+               lex.eatLine();
+               filename.setInzipName(lex.getString());
+       } else if (token == "embed") {
+               lex.next();
+               filename.setEmbed(lex.getBool());               
        } else if (token == "lyxscale") {
                lex.next();
                lyxscale = lex.getInteger();
index 172215dd2263cc3293f35c52e00607b78ea5a0dc..77423c02b85a730374c85b8ffa189e48397986cd 100644 (file)
@@ -17,6 +17,7 @@
 #include "graphics/GraphicsTypes.h"
 #include "Length.h"
 #include "support/FileName.h"
+#include "EmbeddedFiles.h"
 
 namespace lyx {
 
@@ -31,7 +32,7 @@ class InsetGraphicsParams
 {
 public:
        /// Image filename.
-       support::DocFileName filename;
+       EmbeddedFile filename;
        /// Scaling the Screen inside Lyx
        unsigned int lyxscale;
        /// How to display the image inside LyX