small code cleanup

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22830 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2008-02-07 09:51:49 +00:00
parent 4bc0fdcacf
commit c3890f1377

View File

@ -1156,12 +1156,9 @@ void GuiView::openDocument(string const & fname)
} }
// FIXME: clean that // FIXME: clean that
static bool import(LyXView * lv, FileName const & filename, static bool import(GuiView * lv, FileName const & filename,
string const & format, ErrorList & errorList) string const & format, ErrorList & errorList)
{ {
docstring const displaypath = makeDisplayPath(filename.absFilename());
lv->message(bformat(_("Importing %1$s..."), displaypath));
FileName const lyxfile(changeExtension(filename.absFilename(), ".lyx")); FileName const lyxfile(changeExtension(filename.absFilename(), ".lyx"));
string loader_format; string loader_format;
@ -1169,7 +1166,9 @@ static bool import(LyXView * lv, FileName const & filename,
if (find(loaders.begin(), loaders.end(), format) == loaders.end()) { if (find(loaders.begin(), loaders.end(), format) == loaders.end()) {
for (vector<string>::const_iterator it = loaders.begin(); for (vector<string>::const_iterator it = loaders.begin();
it != loaders.end(); ++it) { it != loaders.end(); ++it) {
if (theConverters().isReachable(format, *it)) { if (!theConverters().isReachable(format, *it))
continue;
string const tofile = string const tofile =
changeExtension(filename.absFilename(), changeExtension(filename.absFilename(),
formats.extension(*it)); formats.extension(*it));
@ -1179,33 +1178,27 @@ static bool import(LyXView * lv, FileName const & filename,
loader_format = *it; loader_format = *it;
break; break;
} }
}
if (loader_format.empty()) { if (loader_format.empty()) {
frontend::Alert::error(_("Couldn't import file"), frontend::Alert::error(_("Couldn't import file"),
bformat(_("No information for importing the format %1$s."), bformat(_("No information for importing the format %1$s."),
formats.prettyName(format))); formats.prettyName(format)));
return false; return false;
} }
} else { } else
loader_format = format; loader_format = format;
}
if (loader_format == "lyx") { if (loader_format == "lyx") {
Buffer * buf = lv->loadDocument(lyxfile); Buffer * buf = lv->loadDocument(lyxfile);
if (!buf) { if (!buf)
// we are done
lv->message(_("file not imported!"));
return false; return false;
}
updateLabels(*buf); updateLabels(*buf);
lv->setBuffer(buf); lv->setBuffer(buf);
buf->errors("Parse"); buf->errors("Parse");
} else { } else {
Buffer * const b = newFile(lyxfile.absFilename(), string(), true); Buffer * const b = newFile(lyxfile.absFilename(), string(), true);
if (b) if (!b)
lv->setBuffer(b);
else
return false; return false;
lv->setBuffer(b);
bool as_paragraphs = loader_format == "textparagraph"; bool as_paragraphs = loader_format == "textparagraph";
string filename2 = (loader_format == format) ? filename.absFilename() string filename2 = (loader_format == format) ? filename.absFilename()
: changeExtension(filename.absFilename(), : changeExtension(filename.absFilename(),
@ -1215,8 +1208,6 @@ static bool import(LyXView * lv, FileName const & filename,
lyx::dispatch(FuncRequest(LFUN_MARK_OFF)); lyx::dispatch(FuncRequest(LFUN_MARK_OFF));
} }
// we are done
lv->message(_("imported."));
return true; return true;
} }
@ -1287,13 +1278,14 @@ void GuiView::importDocument(string const & argument)
} }
} }
docstring const displaypath = makeDisplayPath(lyxfile.absFilename(), 30);
// if the file exists already, and we didn't do // if the file exists already, and we didn't do
// -i lyx thefile.lyx, warn // -i lyx thefile.lyx, warn
if (lyxfile.exists() && fullname != lyxfile) { if (lyxfile.exists() && fullname != lyxfile) {
docstring const file = makeDisplayPath(lyxfile.absFilename(), 30);
docstring text = bformat(_("The document %1$s already exists.\n\n" docstring text = bformat(_("The document %1$s already exists.\n\n"
"Do you want to overwrite that document?"), file); "Do you want to overwrite that document?"), displaypath);
int const ret = Alert::prompt(_("Overwrite document?"), int const ret = Alert::prompt(_("Overwrite document?"),
text, 0, 1, _("&Overwrite"), _("&Cancel")); text, 0, 1, _("&Overwrite"), _("&Cancel"));
@ -1303,8 +1295,13 @@ void GuiView::importDocument(string const & argument)
} }
} }
message(bformat(_("Importing %1$s..."), displaypath));
ErrorList errorList; ErrorList errorList;
import(this, fullname, format, errorList); if (import(this, fullname, format, errorList))
message(_("imported."));
else
message(_("file not imported!"));
// FIXME (Abdel 12/08/06): Is there a need to display the error list here? // FIXME (Abdel 12/08/06): Is there a need to display the error list here?
} }