]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetinclude.C
The speed patch: redraw only rows that have changed
[lyx.git] / src / insets / insetinclude.C
index c1278f01a841e0507ddb8f6e69421aec30a333bc..5afd3f382273c667b96711b17879f2b54c472540 100644 (file)
@@ -22,6 +22,7 @@
 #include "dispatchresult.h"
 #include "exporter.h"
 #include "funcrequest.h"
+#include "FuncStatus.h"
 #include "gettext.h"
 #include "LaTeXFeatures.h"
 #include "lyx_main.h"
 
 #include "insets/render_preview.h"
 
-#include "support/FileInfo.h"
 #include "support/filename.h"
 #include "support/filetools.h"
 #include "support/lstrings.h" // contains
 #include "support/lyxlib.h"
-#include "support/tostr.h"
+#include "support/convert.h"
 
 #include <boost/bind.hpp>
+#include <boost/filesystem/operations.hpp>
 
 #include "support/std_ostream.h"
 
@@ -58,11 +59,11 @@ using lyx::support::bformat;
 using lyx::support::ChangeExtension;
 using lyx::support::contains;
 using lyx::support::copy;
-using lyx::support::FileInfo;
 using lyx::support::FileName;
 using lyx::support::GetFileContents;
 using lyx::support::IsFileReadable;
 using lyx::support::IsLyXFilename;
+using lyx::support::latex_path;
 using lyx::support::MakeAbsPath;
 using lyx::support::MakeDisplayPath;
 using lyx::support::MakeRelPath;
@@ -78,6 +79,7 @@ using std::istringstream;
 using std::ostream;
 using std::ostringstream;
 
+namespace fs = boost::filesystem;
 
 extern BufferList bufferlist;
 
@@ -87,7 +89,7 @@ namespace {
 string const uniqueID()
 {
        static unsigned int seed = 1000;
-       return "file" + tostr(++seed);
+       return "file" + convert<string>(++seed);
 }
 
 } // namespace anon
@@ -107,7 +109,7 @@ InsetInclude::InsetInclude(InsetInclude const & other)
          params_(other.params_),
          include_label(other.include_label),
          preview_(new RenderMonitoredPreview(this)),
-         set_label_(other.set_label_)
+         set_label_(false)
 {
        preview_->fileChanged(boost::bind(&InsetInclude::fileChanged, this));
 }
@@ -126,10 +128,10 @@ void InsetInclude::doDispatch(LCursor & cur, FuncRequest & cmd)
        case LFUN_INSET_MODIFY: {
                InsetCommandParams p;
                InsetIncludeMailer::string2params(cmd.argument, p);
-               if (!p.getCmdName().empty()) {
+               if (!p.getCmdName().empty())
                        set(p, cur.buffer());
-                       cur.bv().update();
-               }
+               else
+                       cur.noUpdate();
                break;
        }
 
@@ -143,12 +145,29 @@ void InsetInclude::doDispatch(LCursor & cur, FuncRequest & cmd)
                break;
 
        default:
-               InsetOld::doDispatch(cur, cmd);
+               InsetBase::doDispatch(cur, cmd);
                break;
        }
 }
 
 
+bool InsetInclude::getStatus(LCursor & cur, FuncRequest const & cmd,
+               FuncStatus & flag) const
+{
+       switch (cmd.action) {
+
+       case LFUN_INSET_MODIFY:
+       case LFUN_INSET_DIALOG_UPDATE:
+       case LFUN_INSET_DIALOG_SHOW:
+               flag.enabled(true);
+               return true;
+
+       default:
+               return InsetBase::getStatus(cur, cmd, flag);
+       }
+}
+
+
 InsetCommandParams const & InsetInclude::params() const
 {
        return params_;
@@ -241,7 +260,7 @@ void InsetInclude::write(Buffer const &, ostream & os) const
 void InsetInclude::write(ostream & os) const
 {
        os << "Include " << params_.getCommand() << '\n'
-          << "preview " << tostr(params_.preview()) << '\n';
+          << "preview " << convert<string>(params_.preview()) << '\n';
 }
 
 
@@ -294,8 +313,7 @@ bool loadIfNeeded(Buffer const & buffer, InsetCommandParams const & params)
        Buffer * buf = bufferlist.getBuffer(included_file);
        if (!buf) {
                // the readonly flag can/will be wrong, not anymore I think.
-               FileInfo finfo(included_file);
-               if (!finfo.isOK())
+               if (!fs::exists(included_file))
                        return false;
                buf = bufferlist.newBuffer(included_file);
                if (!loadLyXFile(buf, included_file))
@@ -386,6 +404,7 @@ int InsetInclude::latex(Buffer const & buffer, ostream & os,
        }
 
        if (isVerbatim(params_)) {
+               incfile = latex_path(incfile);
                os << '\\' << params_.getCmdName() << '{' << incfile << '}';
        } else if (type(params_) == INPUT) {
                runparams.exportdata->addExternalFile("latex", writefile,
@@ -393,10 +412,13 @@ int InsetInclude::latex(Buffer const & buffer, ostream & os,
 
                // \input wants file with extension (default is .tex)
                if (!IsLyXFilename(included_file)) {
+                       incfile = latex_path(incfile);
                        os << '\\' << params_.getCmdName() << '{' << incfile << '}';
                } else {
+               incfile = ChangeExtension(incfile, ".tex");
+               incfile = latex_path(incfile);
                        os << '\\' << params_.getCmdName() << '{'
-                          << ChangeExtension(incfile, ".tex")
+                          << incfile
                           <<  '}';
                }
        } else {
@@ -405,8 +427,10 @@ int InsetInclude::latex(Buffer const & buffer, ostream & os,
 
                // \include don't want extension and demands that the
                // file really have .tex
+               incfile = ChangeExtension(incfile, string());
+               incfile = latex_path(incfile);
                os << '\\' << params_.getCmdName() << '{'
-                  << ChangeExtension(incfile, string())
+                  << incfile
                   << '}';
        }
 
@@ -737,7 +761,7 @@ void InsetIncludeMailer::string2params(string const & in,
        string id;
        lex >> id;
        if (!lex || id != "Include")
-               return print_mailer_error("InsetBoxMailer", in, 2, "Include");
+               return print_mailer_error("InsetIncludeMailer", in, 2, "Include");
 
        InsetInclude inset(params);
        inset.read(lex);