#include <boost/bind.hpp>
+#include "debug.h" // temporary
namespace grfx {
}
+void PreviewedInset::removePreview()
+{
+ if (!view() || !view()->buffer() || snippet_.empty())
+ return;
+
+ grfx::Previews & previews = grfx::Previews::get();
+ grfx::PreviewLoader & loader = previews.loader(view()->buffer());
+ loader.remove(snippet_);
+ snippet_.erase();
+ pimage_ = 0;
+}
+
+
bool PreviewedInset::previewReady() const
{
if (!Previews::activated() || !previewWanted() ||
#include "support/filetools.h"
#include "support/FileInfo.h"
+#include "support/FileMonitor.h"
#include "support/lstrings.h"
#include "graphics/PreviewedInset.h"
#include "graphics/PreviewImage.h"
+#include <boost/bind.hpp>
+
#include <cstdlib>
InsetInclude & parent() const {
return *static_cast<InsetInclude*>(inset());
}
+
+ ///
+ bool monitoring() const { return monitor_.get(); }
+ ///
+ void startMonitoring();
+ ///
+ void stopMonitoring() { monitor_.reset(); }
+
+private:
+ /// Invoked by monitor_ should the parent file change.
+ void restartLoading();
+ ///
+ boost::scoped_ptr<FileMonitor> monitor_;
};
params_.cparams.setCmdName(command);
+ if (preview_->monitoring())
+ preview_->stopMonitoring();
+
if (grfx::PreviewedInset::activated() && params_.flag == INPUT)
preview_->generatePreview();
}
return;
}
+ if (!preview_->monitoring())
+ preview_->startMonitoring();
+
int const x = int(xx);
int const w = width(bv, font);
int const d = descent(bv, font);
bool InsetInclude::PreviewImpl::previewWanted() const
{
return parent().params_.flag == InsetInclude::INPUT &&
- parent().params_.cparams.preview();
+ parent().params_.cparams.preview() &&
+ IsFileReadable(parent().getFileName());
}
// This fails if the file has a relative path.
// return os.str().c_str();
- // I would /really/ like not to do this...
+ // I would /really/ like not to do this, but don't know how to tell
+ // LaTeX where to find a \input-ed file...
// HELP!
string command;
string file = rtrim(split(os.str().c_str(), command, '{'), "}");
return out.str().c_str();
}
+
+
+void InsetInclude::PreviewImpl::startMonitoring()
+{
+ monitor_.reset(new FileMonitor(parent().getFileName(), 2000));
+ monitor_->connect(boost::bind(&PreviewImpl::restartLoading, this));
+ monitor_->start();
+}
+
+
+void InsetInclude::PreviewImpl::restartLoading()
+{
+ lyxerr << "restartLoading()" << std::endl;
+ removePreview();
+ if (view())
+ view()->updateInset(&parent(), false);
+ generatePreview();
+}