* What advanced features the users want to do?
Implement them in a non latex dependent way, but a logical way.
LyX should translate it to latex or any other fitting format.
- * Add a way to roll the image file into the file format.
* When loading, if the image is not found in the expected place, try
to find it in the clipart, or in the same directory with the image.
* The image choosing dialog could show thumbnails of the image formats
#include "BufferView.h"
#include "Converter.h"
#include "Cursor.h"
-#include "support/debug.h"
#include "DispatchResult.h"
#include "ErrorList.h"
#include "Exporter.h"
#include "Format.h"
#include "FuncRequest.h"
#include "FuncStatus.h"
-#include "support/gettext.h"
#include "LaTeXFeatures.h"
#include "Length.h"
#include "Lexer.h"
#include "frontends/alert.h"
#include "support/convert.h"
+#include "support/debug.h"
#include "support/docstream.h"
+#include "support/ExceptionMessage.h"
#include "support/filetools.h"
-#include "support/lyxlib.h" // sum
+#include "support/gettext.h"
+#include "support/lyxlib.h"
#include "support/lstrings.h"
#include "support/os.h"
#include "support/Systemcall.h"
#include <algorithm>
#include <sstream>
+using namespace std;
+using namespace lyx::support;
namespace lyx {
-using support::bformat;
-using support::changeExtension;
-using support::compare_timestamps;
-using support::contains;
-using support::DocFileName;
-using support::FileName;
-using support::float_equal;
-using support::getExtension;
-using support::isValidLaTeXFilename;
-using support::latex_path;
-using support::onlyFilename;
-using support::removeExtension;
-using support::rtrim;
-using support::subst;
-using support::suffixIs;
-using support::Systemcall;
-using support::unzipFile;
-using support::unzippedFileName;
-
-using std::endl;
-using std::string;
-using std::istringstream;
-using std::ostream;
-using std::ostringstream;
-
+namespace Alert = frontend::Alert;
namespace {
Buffer const & buffer = cur.buffer();
InsetGraphicsParams p;
InsetGraphicsMailer::string2params(to_utf8(cmd.argument()), buffer, p);
- if (!p.filename.empty())
+ if (!p.filename.empty()) {
+ try {
+ p.filename.enable(buffer.embedded(), &buffer);
+ } catch (ExceptionMessage const & message) {
+ Alert::error(message.title_, message.details_);
+ // do not set parameter if an error happens
+ break;
+ }
setParams(p);
- else
+ } else
cur.noUpdate();
break;
}
}
-void InsetGraphics::registerEmbeddedFiles(Buffer const &,
- EmbeddedFiles & files) const
+void InsetGraphics::registerEmbeddedFiles(Buffer const & buffer,
+ EmbeddedFileList & files) const
{
- files.registerFile(params().filename.absFilename(),
- false, this);
+ files.registerFile(params().filename, this, buffer);
}
void InsetGraphics::updateEmbeddedFile(Buffer const & buf,
EmbeddedFile const & file)
{
- BOOST_ASSERT(buf.embeddedFiles().enabled());
- params_.filename = file;
+ // when embedding is enabled, change of embedding status leads to actions
+ EmbeddedFile temp = file;
+ temp.enable(buf.embedded(), &buf);
+ // this will not be set if an exception is thorwn in enable()
+ params_.filename = temp;
+
LYXERR(Debug::FILES, "Update InsetGraphic with File "
<< params_.filename.toFilesystemEncoding()
- << ", embedding status: " << params_.filename.embedded());
+ << ", embedding status: " << params_.filename.embedded()
+ << ", enabled: " << params_.filename.enabled());
}
-void InsetGraphics::edit(Cursor & cur, bool)
+void InsetGraphics::edit(Cursor & cur, bool, EntryDirection)
{
InsetGraphicsMailer(*this).showDialog(&cur.bv());
}
else
LYXERR(Debug::GRAPHICS, "Not a Graphics inset!");
- // InsetGraphics is read, with filename in params_. We do not know if this file actually
- // exists or is embedded so we need to get the 'availableFile' from buf.embeddedFiles()
- if (buf.embeddedFiles().enabled()) {
- EmbeddedFiles::EmbeddedFileList::const_iterator it =
- buf.embeddedFiles().find(params_.filename.toFilesystemEncoding());
- if (it != buf.embeddedFiles().end())
- // using available file, embedded or external, depending on file availability and
- // embedding status.
- params_.filename = *it;
- }
+ params_.filename.enable(buf.embedded(), &buf);
graphic_->update(params().as_grfxParams());
}
} else {
if (!params_.Read(lex, token, bufpath))
lyxerr << "Unknown token, " << token << ", skipping."
- << std::endl;
+ << endl;
}
}
}
};
-std::pair<GraphicsCopyStatus, FileName> const
+pair<GraphicsCopyStatus, FileName> const
copyFileIfNeeded(FileName const & file_in, FileName const & file_out)
{
- unsigned long const checksum_in = support::sum(file_in);
- unsigned long const checksum_out = support::sum(file_out);
+ LYXERR(Debug::FILES, "Comparing " << file_in << " and " << file_out);
+ unsigned long const checksum_in = file_in.checksum();
+ unsigned long const checksum_out = file_out.checksum();
if (checksum_in == checksum_out)
// Nothing to do...
- return std::make_pair(IDENTICAL_CONTENTS, file_out);
+ return make_pair(IDENTICAL_CONTENTS, file_out);
Mover const & mover = getMover(formats.getFormatFromFile(file_in));
bool const success = mover.copy(file_in, file_out);
if (!success) {
// FIXME UNICODE
LYXERR(Debug::GRAPHICS,
- to_utf8(support::bformat(_("Could not copy the file\n%1$s\n"
+ to_utf8(bformat(_("Could not copy the file\n%1$s\n"
"into the temporary directory."),
from_utf8(file_in.absFilename()))));
}
GraphicsCopyStatus status = success ? SUCCESS : FAILURE;
- return std::make_pair(status, file_out);
+ return make_pair(status, file_out);
}
-std::pair<GraphicsCopyStatus, FileName> const
+pair<GraphicsCopyStatus, FileName> const
copyToDirIfNeeded(DocFileName const & file, string const & dir)
{
- using support::rtrim;
-
string const file_in = file.absFilename();
- string const only_path = support::onlyPath(file_in);
- if (rtrim(support::onlyPath(file_in) , "/") == rtrim(dir, "/"))
- return std::make_pair(IDENTICAL_PATHS, file_in);
+ string const only_path = onlyPath(file_in);
+ if (rtrim(onlyPath(file_in) , "/") == rtrim(dir, "/"))
+ return make_pair(IDENTICAL_PATHS, file_in);
string mangled = file.mangledFilename();
if (file.isZipped()) {
string::size_type const ext_len = file_in.length() - base.length();
mangled[mangled.length() - ext_len] = '.';
}
- FileName const file_out(support::makeAbsPath(mangled, dir));
+ FileName const file_out(makeAbsPath(mangled, dir));
return copyFileIfNeeded(file, file_out);
}
// dots with a macro whose definition is just a dot ;-)
// The automatic format selection does not work if the file
// name is escaped.
- string const latex_name = latex_path(file,
- support::EXCLUDE_EXTENSION);
+ string const latex_name = latex_path(file, EXCLUDE_EXTENSION);
if (!nice || contains(latex_name, '"'))
return latex_name;
- return latex_path(removeExtension(file),
- support::PROTECT_EXTENSION,
- support::ESCAPE_DOTS);
+ return latex_path(removeExtension(file), PROTECT_EXTENSION, ESCAPE_DOTS);
}
(to_format == "eps" && file_format == "ps") ||
(to_format == "ps" && file_format == "eps"))
return stripExtensionIfPossible(file, nice);
- return latex_path(file, support::EXCLUDE_EXTENSION);
+ return latex_path(file, EXCLUDE_EXTENSION);
}
} // namespace anon
if (params().filename.empty())
return string();
- string const orig_file = params().filename.absFilename();
+ string const orig_file = params().filename.availableFile().absFilename();
+ // this is for dryrun and display purposes, do not use latexFilename
string const rel_file = params().filename.relFilename(buf.filePath());
// previewing source code, no file copying or file format conversion
// 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;
+ FileName temp_file = params().filename.availableFile();
// The master buffer. This is useful when there are multiple levels
// of include files
GraphicsCopyStatus status;
boost::tie(status, temp_file) =
- copyToDirIfNeeded(params().filename, temp_path);
+ copyToDirIfNeeded(params().filename.availableFile(), temp_path);
if (status == FAILURE)
return orig_file;
source_file, output_file);
// We can't strip the extension, because we don't know
// the unzipped file format
- return latex_path(output_file,
- support::EXCLUDE_EXTENSION);
+ return latex_path(output_file, EXCLUDE_EXTENSION);
}
FileName const unzipped_temp_file =
// the file format from the extension, so we must
// change it.
FileName const new_file = FileName(changeExtension(temp_file.absFilename(), ext));
- if (support::rename(temp_file, new_file)) {
+ if (temp_file.moveTo(new_file)) {
temp_file = new_file;
output_file = changeExtension(output_file, ext);
source_file = FileName(changeExtension(source_file.absFilename(), ext));
LYXERR(Debug::GRAPHICS, "insetgraphics::latex: Filename = "
<< params().filename.absFilename());
- string const relative_file =
- params().filename.relFilename(buf.filePath());
-
bool const file_exists = !params().filename.empty()
&& params().filename.isReadableFile();
string const message = file_exists ?
LYXERR(Debug::GRAPHICS, "InsetGraphics::latex outputting:\n" << latex_str);
// Return how many newlines we issued.
- return int(std::count(latex_str.begin(), latex_str.end(),'\n'));
+ return int(count(latex_str.begin(), latex_str.end(),'\n'));
}
{
if (runparams.flavor != OutputParams::XML)
os << "<![ %output.print." << format
- << "; [" << std::endl;
+ << "; [" << endl;
os <<"<imageobject><imagedata fileref=\"&"
<< graphic_label
os << "</imageobject>";
if (runparams.flavor != OutputParams::XML)
- os << std::endl << "]]>" ;
+ os << endl << "]]>" ;
return runparams.flavor == OutputParams::XML ? 0 : 2;
}