#include "Converter.h"
#include "Cursor.h"
#include "DispatchResult.h"
-#include "EmbeddedFiles.h"
#include "ErrorList.h"
#include "Exporter.h"
#include "Format.h"
#include "FuncRequest.h"
#include "FuncStatus.h"
+#include "InsetIterator.h"
#include "LaTeXFeatures.h"
#include "Length.h"
#include "Lexer.h"
#include "TocBackend.h"
#include "frontends/alert.h"
+#include "frontends/Application.h"
#include "support/convert.h"
#include "support/debug.h"
return format;
}
+
+void readInsetGraphics(Lexer & lex, string const & bufpath,
+ InsetGraphicsParams & params)
+{
+ bool finished = false;
+
+ while (lex.isOK() && !finished) {
+ lex.next();
+
+ string const token = lex.getString();
+ LYXERR(Debug::GRAPHICS, "Token: '" << token << '\'');
+
+ if (token.empty())
+ continue;
+
+ if (token == "\\end_inset") {
+ finished = true;
+ } else {
+ if (!params.Read(lex, token, bufpath))
+ lyxerr << "Unknown token, "
+ << token
+ << ", skipping."
+ << endl;
+ }
+ }
+}
+
} // namespace anon
-InsetGraphics::InsetGraphics()
+InsetGraphics::InsetGraphics(Buffer & buf)
: graphic_label(sgml::uniqueID(from_ascii("graph"))),
graphic_(new RenderGraphic(this))
-{}
+{
+ Inset::setBuffer(buf);
+}
InsetGraphics::InsetGraphics(InsetGraphics const & ig)
InsetGraphics::~InsetGraphics()
{
- InsetGraphicsMailer(*this).hideDialog();
-}
-
-
-void InsetGraphics::setBuffer(Buffer & buffer)
-{
- if (buffer_) {
- try {
- // a file may not be copied successfully when, e.g. buffer_
- // has already been closed.
- params_.filename = params_.filename.copyTo(&buffer);
- } catch (ExceptionMessage const & message) {
- Alert::error(message.title_, message.details_);
- // failed to embed
- params_.filename.setEmbed(false);
- }
- }
- Inset::setBuffer(buffer);
+ hideDialogs("graphics", this);
}
void InsetGraphics::doDispatch(Cursor & cur, FuncRequest & cmd)
{
switch (cmd.action) {
- case LFUN_GRAPHICS_EDIT: {
+ case LFUN_INSET_EDIT: {
InsetGraphicsParams p = params();
if (!cmd.argument().empty())
- InsetGraphicsMailer::string2params(to_utf8(cmd.argument()), buffer(), p);
+ string2params(to_utf8(cmd.argument()), buffer(), p);
editGraphics(p, buffer());
break;
}
case LFUN_INSET_MODIFY: {
InsetGraphicsParams p;
- InsetGraphicsMailer::string2params(to_utf8(cmd.argument()), buffer(), p);
+ string2params(to_utf8(cmd.argument()), buffer(), p);
if (!p.filename.empty())
setParams(p);
else
}
case LFUN_INSET_DIALOG_UPDATE:
- InsetGraphicsMailer(*this).updateDialog(&cur.bv());
+ cur.bv().updateDialog("graphics", params2string(params(),
+ cur.bv().buffer()));
break;
case LFUN_MOUSE_RELEASE:
- if (!cur.selection())
- InsetGraphicsMailer(*this).showDialog(&cur.bv());
+ if (!cur.selection() && cmd.button() == mouse_button::button1)
+ cur.bv().showDialog("graphics", params2string(params(),
+ cur.bv().buffer()), this);
break;
default:
FuncStatus & flag) const
{
switch (cmd.action) {
- case LFUN_GRAPHICS_EDIT:
+ case LFUN_INSET_EDIT:
case LFUN_INSET_MODIFY:
case LFUN_INSET_DIALOG_UPDATE:
- flag.enabled(true);
+ flag.setEnabled(true);
return true;
default:
}
-void InsetGraphics::registerEmbeddedFiles(EmbeddedFileList & files) const
-{
- files.registerFile(params().filename, this, buffer());
-}
-
-
-void InsetGraphics::updateEmbeddedFile(EmbeddedFile const & file)
-{
- // only properties of an embedded file can be changed here.
- params_.filename = file;
-}
-
-
void InsetGraphics::edit(Cursor & cur, bool, EntryDirection)
{
- InsetGraphicsMailer(*this).showDialog(&cur.bv());
+ cur.bv().showDialog("graphics", params2string(params(),
+ cur.bv().buffer()), this);
}
void InsetGraphics::read(Lexer & lex)
{
- string const token = lex.getString();
-
- if (token == "Graphics")
- readInsetGraphics(lex, buffer().filePath());
- else
- LYXERR(Debug::GRAPHICS, "Not a Graphics inset!");
-
- params_.filename.enable(buffer().embedded(), &buffer(), false);
+ lex.setContext("InsetGraphics::read");
+ //lex >> "Graphics";
+ readInsetGraphics(lex, buffer().filePath(), params_);
graphic_->update(params().as_grfxParams());
}
-void InsetGraphics::readInsetGraphics(Lexer & lex, string const & bufpath)
-{
- bool finished = false;
-
- while (lex.isOK() && !finished) {
- lex.next();
-
- string const token = lex.getString();
- LYXERR(Debug::GRAPHICS, "Token: '" << token << '\'');
-
- if (token.empty())
- continue;
-
- if (token == "\\end_inset") {
- finished = true;
- } else {
- if (!params_.Read(lex, token, bufpath))
- lyxerr << "Unknown token, " << token << ", skipping."
- << endl;
- }
- }
-}
-
-
-string const InsetGraphics::createLatexOptions() const
+string InsetGraphics::createLatexOptions() const
{
// Calculate the options part of the command, we must do it to a string
// stream since we might have a trailing comma that we would like to remove
}
-docstring const InsetGraphics::toDocbookLength(Length const & len) const
+docstring InsetGraphics::toDocbookLength(Length const & len) const
{
odocstringstream result;
switch (len.unit()) {
return result.str();
}
-docstring const InsetGraphics::createDocBookAttributes() const
+
+docstring InsetGraphics::createDocBookAttributes() const
{
// Calculate the options part of the command, we must do it to a string
// stream since we copied the code from createLatexParams() ;-)
if (params().filename.empty())
return string();
- string const orig_file = params().filename.availableFile().absFilename();
+ string const orig_file = params().filename.absFilename();
// this is for dryrun and display purposes, do not use latexFilename
string const rel_file = params().filename.relFilename(buffer().filePath());
// temp_file will contain the file for LaTeX to act on if, for example,
// we move it to a temp dir or uncompress it.
- FileName temp_file = params().filename.availableFile();
+ FileName temp_file = params().filename;
// The master buffer. This is useful when there are multiple levels
// of include files
GraphicsCopyStatus status;
boost::tie(status, temp_file) =
- copyToDirIfNeeded(params().filename.availableFile(), temp_path);
+ copyToDirIfNeeded(params().filename, temp_path);
if (status == FAILURE)
return orig_file;
// noUnzip parameter meaningless.
LYXERR(Debug::GRAPHICS, "\tpass zipped file to LaTeX.");
- FileName const bb_orig_file = FileName(changeExtension(orig_file, "bb"));
+ FileName const bb_orig_file =
+ FileName(changeExtension(orig_file, "bb"));
if (runparams.nice) {
runparams.exportdata->addExternalFile(tex_format,
bb_orig_file,
} else {
// LaTeX needs the bounding box file in the
// tmp dir
- FileName bb_file = FileName(changeExtension(temp_file.absFilename(), "bb"));
+ FileName bb_file =
+ FileName(changeExtension(temp_file.absFilename(), "bb"));
boost::tie(status, bb_file) =
copyFileIfNeeded(bb_orig_file, bb_file);
if (status == FAILURE)
// The LaTeX compiler will not be able to determine
// the file format from the extension, so we must
// change it.
- FileName const new_file = FileName(changeExtension(temp_file.absFilename(), ext));
+ FileName const new_file =
+ FileName(changeExtension(temp_file.absFilename(), ext));
if (temp_file.moveTo(new_file)) {
temp_file = new_file;
output_file = changeExtension(output_file, ext);
- source_file = FileName(changeExtension(source_file.absFilename(), ext));
+ source_file =
+ FileName(changeExtension(source_file.absFilename(), ext));
} else {
LYXERR(Debug::GRAPHICS, "Could not rename file `"
<< temp_file << "' to `" << new_file << "'.");
if (features.runparams().nice) {
Buffer const * masterBuffer = features.buffer().masterBuffer();
- string const rel_file = removeExtension(params().filename.relFilename(masterBuffer->filePath()));
+ string const rel_file = removeExtension(
+ params().filename.relFilename(masterBuffer->filePath()));
if (contains(rel_file, "."))
features.require("lyxdot");
}
}
-void InsetGraphics::addToToc(ParConstIterator const & cpit) const
+void InsetGraphics::addToToc(DocIterator const & cpit)
{
TocBackend & backend = buffer().tocBackend();
- docstring str = params_.filename.displayName();
- if (params_.filename.embedded()) {
- backend.toc("embedded").push_back(TocItem(cpit, 0, str));
- str += _(" (embedded)");
- }
+ //FIXME UNICODE
+ docstring const str = from_utf8(params_.filename.onlyFileName());
backend.toc("graphics").push_back(TocItem(cpit, 0, str));
}
}
-string const InsetGraphicsMailer::name_("graphics");
+void InsetGraphics::string2params(string const & in, Buffer const & buffer,
+ InsetGraphicsParams & params)
+{
+ if (in.empty())
+ return;
-InsetGraphicsMailer::InsetGraphicsMailer(InsetGraphics & inset)
- : inset_(inset)
-{}
+ istringstream data(in);
+ Lexer lex;
+ lex.setStream(data);
+ lex.setContext("InsetGraphics::string2params");
+ lex >> "graphics";
+ params = InsetGraphicsParams();
+ readInsetGraphics(lex, buffer.filePath(), params);
+}
-string const InsetGraphicsMailer::inset2string(Buffer const & buffer) const
+string InsetGraphics::params2string(InsetGraphicsParams const & params,
+ Buffer const & buffer)
{
- return params2string(inset_.params(), buffer);
+ ostringstream data;
+ data << "graphics" << ' ';
+ params.Write(data, buffer);
+ data << "\\end_inset\n";
+ return data.str();
}
+namespace graphics {
-void InsetGraphicsMailer::string2params(string const & in,
- Buffer const & buffer,
- InsetGraphicsParams & params)
+void getGraphicsGroups(Buffer const & b, set<string> & ids)
{
- params = InsetGraphicsParams();
- if (in.empty())
- return;
+ 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);
+ InsetGraphicsParams inspar = ins.getParams();
+ if (!inspar.groupId.empty())
+ ids.insert(inspar.groupId);
+ }
+}
- istringstream data(in);
- Lexer lex(0,0);
- lex.setStream(data);
- string name;
- lex >> name;
- if (!lex || name != name_)
- return print_mailer_error("InsetGraphicsMailer", in, 1, name_);
+string getGroupParams(Buffer const & b, string const & groupId)
+{
+ if (groupId.empty())
+ return string();
+ 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);
+ InsetGraphicsParams inspar = ins.getParams();
+ if (inspar.groupId == groupId) {
+ InsetGraphicsParams tmp = inspar;
+ tmp.filename.erase();
+ return InsetGraphics::params2string(tmp, b);
+ }
+ }
+ return string();
+}
+
+
+void unifyGraphicsGroups(Buffer const & b, string const & argument)
+{
+ InsetGraphicsParams params;
+ InsetGraphics::string2params(argument, b, params);
+
+ 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);
+ InsetGraphicsParams inspar = ins.getParams();
+ if (params.groupId == inspar.groupId) {
+ params.filename = inspar.filename;
+ ins.setParams(params);
+ }
+ }
+ }
- InsetGraphics inset;
- inset.readInsetGraphics(lex, buffer.filePath());
- params = inset.params();
}
-string const
-InsetGraphicsMailer::params2string(InsetGraphicsParams const & params,
- Buffer const & buffer)
+InsetGraphics * getCurrentGraphicsInset(Cursor const & cur)
{
- ostringstream data;
- data << name_ << ' ';
- params.Write(data, buffer);
- data << "\\end_inset\n";
- return data.str();
+ Inset * instmp = &cur.inset();
+ if (instmp->lyxCode() != GRAPHICS_CODE)
+ instmp = cur.nextInset();
+ if (!instmp || instmp->lyxCode() != GRAPHICS_CODE)
+ return 0;
+
+ return static_cast<InsetGraphics *>(instmp);
}
+} // namespace graphics
} // namespace lyx