From 523056c092f52a52b6106b37297107211d6ee9de Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Wed, 28 Jul 2010 21:03:27 +0000 Subject: [PATCH] Move the error message out of LayoutFileList::load() and have it be reported by the caller. Otherwise, you could get the error message the first time, and then it would succeed the second!! git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35019 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView.cpp | 25 +++++++++++++++++++------ src/LayoutFile.cpp | 8 +------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/BufferView.cpp b/src/BufferView.cpp index 076bff7af8..2c53809d21 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -1239,9 +1239,15 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr) } case LFUN_TEXTCLASS_APPLY: { - if (!LayoutFileList::get().load(argument, buffer_.temppath()) && - !LayoutFileList::get().load(argument, buffer_.filePath())) + bool success = LayoutFileList::get().load(argument, buffer_.temppath()); + if (!success) + success = LayoutFileList::get().load(argument, buffer_.filePath()); + if (!success) { + docstring s = bformat(_("The document class `%1$s' " + "could not be loaded."), from_utf8(argument)); + frontend::Alert::error(_("Could not load class"), s); break; + } LayoutFile const * old_layout = buffer_.params().baseClass(); LayoutFile const * new_layout = &(LayoutFileList::get()[argument]); @@ -1250,7 +1256,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr) // nothing to do break; - //Save the old, possibly modular, layout for use in conversion. + // Save the old, possibly modular, layout for use in conversion. DocumentClass const * const oldDocClass = buffer_.params().documentClassPtr(); cur.recordUndoFullDocument(); @@ -1262,10 +1268,17 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr) break; } - case LFUN_TEXTCLASS_LOAD: - LayoutFileList::get().load(argument, buffer_.temppath()) || - LayoutFileList::get().load(argument, buffer_.filePath()); + case LFUN_TEXTCLASS_LOAD: { + bool success = LayoutFileList::get().load(argument, buffer_.temppath()); + if (!success) + success = LayoutFileList::get().load(argument, buffer_.filePath()); + if (!success) { + docstring s = bformat(_("The document class `%1$s' " + "could not be loaded."), from_utf8(argument)); + frontend::Alert::error(_("Could not load class"), s); + } break; + } case LFUN_LAYOUT_RELOAD: { DocumentClass const * const oldClass = buffer_.params().documentClassPtr(); diff --git a/src/LayoutFile.cpp b/src/LayoutFile.cpp index 1aa5dbfeb3..541f2dae84 100644 --- a/src/LayoutFile.cpp +++ b/src/LayoutFile.cpp @@ -314,13 +314,7 @@ bool LayoutFileList::load(string const & name, string const & buf_path) } LayoutFile * tc = classmap_[name]; - if (!tc->load(buf_path)) { - docstring s = bformat(_("The document class %1$s " - "could not be loaded."), from_utf8(name)); - frontend::Alert::error(_("Could not load class"), s); - return false; - } - return true; + return tc->load(buf_path); } -- 2.39.5