void InsetHyperlink::viewTarget() const { if (getParam("type") == "file:") { FileName url = makeAbsPath(to_utf8(getParam("target")), buffer().filePath()); string const format = formats.getFormatFromFile(url); formats.view(buffer(), url, format); } }
int writeExternal(InsetExternalParams const & params, string const & format, Buffer const & buffer, odocstream & os, ExportData & exportdata, bool external_in_tmpdir, bool dryrun) { Template const * const et_ptr = getTemplatePtr(params); if (!et_ptr) return 0; Template const & et = *et_ptr; Template::Formats::const_iterator cit = et.formats.find(format); if (cit == et.formats.end()) { LYXERR(Debug::EXTERNAL, "External template format '" << format << "' not specified in template " << params.templatename()); return 0; } if (!dryrun || contains(cit->second.product, "$$Contents")) updateExternal(params, format, buffer, exportdata, external_in_tmpdir, dryrun); bool const use_latex_path = format == "LaTeX"; string str = doSubstitution(params, buffer, cit->second.product, use_latex_path, external_in_tmpdir); string const absname = makeAbsPath( params.filename.outputFileName(buffer.filePath()), buffer.filePath()).absFileName(); if (!external_in_tmpdir && !isValidLaTeXFileName(absname)) { lyx::frontend::Alert::warning(_("Invalid filename"), _("The following filename is likely to cause trouble " "when running the exported file through LaTeX: ") + from_utf8(absname)); } str = substituteCommands(params, str, format); str = substituteOptions(params, str, format); // FIXME UNICODE os << from_utf8(str); return int(count(str.begin(), str.end(),'\n')); }
string const doSubstitution(InsetExternalParams const & params, Buffer const & buffer, string const & s, bool use_latex_path, bool external_in_tmpdir, Substitute what) { Buffer const * masterBuffer = buffer.masterBuffer(); string const parentpath = external_in_tmpdir ? masterBuffer->temppath() : buffer.filePath(); string const filename = external_in_tmpdir ? params.filename.mangledFileName() : params.filename.outputFileName(parentpath); string const basename = changeExtension( onlyFileName(filename), string()); string const absname = makeAbsPath(filename, parentpath).absFileName(); string result = s; if (what != ALL_BUT_PATHS) { string const filepath = onlyPath(filename); string const abspath = onlyPath(absname); string const masterpath = external_in_tmpdir ? masterBuffer->temppath() : masterBuffer->filePath(); // FIXME UNICODE string relToMasterPath = onlyPath( to_utf8(makeRelPath(from_utf8(absname), from_utf8(masterpath)))); if (relToMasterPath == "./") relToMasterPath.clear(); // FIXME UNICODE string relToParentPath = onlyPath( to_utf8(makeRelPath(from_utf8(absname), from_utf8(parentpath)))); if (relToParentPath == "./") relToParentPath.clear(); result = subst_path(result, "$$FPath", filepath, use_latex_path, PROTECT_EXTENSION, ESCAPE_DOTS); result = subst_path(result, "$$AbsPath", abspath, use_latex_path, PROTECT_EXTENSION, ESCAPE_DOTS); result = subst_path(result, "$$RelPathMaster", relToMasterPath, use_latex_path, PROTECT_EXTENSION, ESCAPE_DOTS); result = subst_path(result, "$$RelPathParent", relToParentPath, use_latex_path, PROTECT_EXTENSION, ESCAPE_DOTS); if (FileName::isAbsolute(filename)) { result = subst_path(result, "$$AbsOrRelPathMaster", abspath, use_latex_path, PROTECT_EXTENSION, ESCAPE_DOTS); result = subst_path(result, "$$AbsOrRelPathParent", abspath, use_latex_path, PROTECT_EXTENSION, ESCAPE_DOTS); } else { result = subst_path(result, "$$AbsOrRelPathMaster", relToMasterPath, use_latex_path, PROTECT_EXTENSION, ESCAPE_DOTS); result = subst_path(result, "$$AbsOrRelPathParent", relToParentPath, use_latex_path, PROTECT_EXTENSION, ESCAPE_DOTS); } } if (what == PATHS) return result; result = subst_path(result, "$$FName", filename, use_latex_path, EXCLUDE_EXTENSION); result = subst_path(result, "$$Basename", basename, use_latex_path, PROTECT_EXTENSION, ESCAPE_DOTS); result = subst_path(result, "$$Extension", '.' + getExtension(filename), use_latex_path); result = subst_path(result, "$$Tempname", params.tempname().absFileName(), use_latex_path); result = subst_path(result, "$$Sysdir", package().system_support().absFileName(), use_latex_path); // Handle the $$Contents(filename) syntax if (contains(result, "$$Contents(\"")) { // Since use_latex_path may be true we must extract the file // name from s instead of result and do the substitutions // again, this time with use_latex_path false. size_t const spos = s.find("$$Contents(\""); size_t const send = s.find("\")", spos); string const file_template = s.substr(spos + 12, send - (spos + 12)); string const file = doSubstitution(params, buffer, file_template, false, external_in_tmpdir, what); string contents; FileName const absfile( makeAbsPath(file, masterBuffer->temppath())); if (absfile.isReadableFile()) // FIXME UNICODE contents = to_utf8(absfile.fileContents("UTF-8")); size_t const pos = result.find("$$Contents(\""); size_t const end = result.find("\")", pos); result.replace(pos, end + 2, contents); } return result; }