X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;ds=inline;f=src%2Ffrontends%2Fcontrollers%2FControlGraphics.C;h=6c1454fc13d7ed72ec6b2c3f48e9765af7217489;hb=b9a7e874051b4fbc7f3a7ae70fd70b8f4a6766b7;hp=bdca7e622901e4b5a1428a55072ed98532b3c5bd;hpb=5fd04c35323e5ee7e4cf8a8849d3bc74e96108cd;p=lyx.git diff --git a/src/frontends/controllers/ControlGraphics.C b/src/frontends/controllers/ControlGraphics.C index bdca7e6229..6c1454fc13 100644 --- a/src/frontends/controllers/ControlGraphics.C +++ b/src/frontends/controllers/ControlGraphics.C @@ -1,5 +1,5 @@ /* This file is part of - * ====================================================== + * ====================================================== * * LyX, The Document Processor * @@ -12,18 +12,19 @@ * \author Herbert Voss */ -#include +#include #include #ifdef __GNUG__ #pragma implementation -#endif +#endif #include "ViewBase.h" #include "ButtonControllerBase.h" #include "ControlGraphics.h" #include "ControlInset.tmpl" #include "buffer.h" +#include "BufferView.h" #include "Dialogs.h" #include "LyXView.h" #include "gettext.h" @@ -33,11 +34,9 @@ #include "insets/insetgraphicsParams.h" // need operator!=() #include "support/FileInfo.h" // for FileInfo -#include "helper_funcs.h" // for browseFile +#include "helper_funcs.h" #include "support/lstrings.h" #include "support/filetools.h" // for AddName, zippedFile -#include "frontends/Alert.h" -#include "BufferView.h" using std::pair; using std::make_pair; @@ -67,7 +66,7 @@ void ControlGraphics::applyParamsToInset() { // Set the parameters in the inset, it also returns true if the new // parameters are different from what was in the inset already. - bool changed = inset()->setParams(params()); + bool changed = inset()->setParams(params(), lv_.buffer()->filePath()); // Tell LyX we've got a change, and mark the document dirty, // if it changed. lv_.view()->updateInset(inset(), changed); @@ -81,42 +80,46 @@ void ControlGraphics::applyParamsNoInset() // We need these in the file browser. extern string system_lyxdir; extern string user_lyxdir; - + string const ControlGraphics::Browse(string const & in_name) { string const title = N_("Select graphics file"); - // FIXME: currently we need the second '|' to prevent mis-interpretation + // FIXME: currently we need the second '|' to prevent mis-interpretation string const pattern = "*.(ps|eps|png|jpeg|jpg|gif|gz)|"; - // Does user clipart directory exist? - string clipdir = AddName (user_lyxdir, "clipart"); - FileInfo fileInfo(clipdir); - if (!(fileInfo.isOK() && fileInfo.isDir())) - // No - bail out to system clipart directory - clipdir = AddName (system_lyxdir, "clipart"); + // Does user clipart directory exist? + string clipdir = AddName (user_lyxdir, "clipart"); + FileInfo fileInfo(clipdir); + if (!(fileInfo.isOK() && fileInfo.isDir())) + // No - bail out to system clipart directory + clipdir = AddName (system_lyxdir, "clipart"); pair dir1(N_("Clipart|#C#c"), clipdir); pair dir2(N_("Documents|#o#O"), string(lyxrc.document_path)); // Show the file browser dialog - return browseFile(&lv_, in_name, title, pattern, dir1, dir2); + return browseRelFile(&lv_, in_name, lv_.buffer()->filePath(), + title, pattern, dir1, dir2); } - + string const ControlGraphics::readBB(string const & file) { -// in a file it's an entry like %%BoundingBox:23 45 321 345 -// the first number can following without a space, so we have -// to check a bit more. -// on the other hand some plot programs write the bb at the -// end of the file. Than we have in the header a -// %%BoundingBox: (atend) -// In this case we must check until the end. + // in a file it's an entry like %%BoundingBox:23 45 321 345 + // The first number can following without a space, so we have + // to be a little careful. + // On the other hand some plot programs write the bb at the + // end of the file. Than we have in the header: + // %%BoundingBox: (atend) + // In this case we must check the end. string file_ = file; if (zippedFile(file_)) file_ = unzipFile(file_); + + string const format = getExtFromContents(file_); + if (format != "eps" && format != "ps") + return string(); + std::ifstream is(file_.c_str()); - if (!contains(getExtFromContents(file_),"ps")) // bb exists? - return string(); while (is) { string s; is >> s; @@ -124,7 +127,7 @@ string const ControlGraphics::readBB(string const & file) string a, b, c, d; is >> a >> b >> c >> d; if (is && !contains(a,"atend")) { // bb at the end? - if (s != "%%BoundingBox:") + if (s != "%%BoundingBox:") return (s.substr(14)+" "+a+" "+b+" "+c+" "); else return (a+" "+b+" "+c+" "+d+" "); @@ -135,10 +138,9 @@ string const ControlGraphics::readBB(string const & file) } -void ControlGraphics::checkFilename(string const & fname) { - if (!IsFileReadable(fname)) - Alert::alert(_("Warning!"), - _("Filename") + ' ' - + fname + _(" does not exist!")); - +bool ControlGraphics::isFilenameValid(string const & fname) const +{ + // It may be that the filename is relative. + string const name = MakeAbsPath(fname, lv_.buffer()->filePath()); + return IsFileReadable(name); }