Transfer LyXView::loadLyXFile() to lyxFunc::loadAndViewFile(). This enables to get rid of the flashing tabbar bug and is more correct anyway.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21677 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2007-11-19 12:03:38 +00:00
parent 7e9cf3cec1
commit 37a5647be1
7 changed files with 52 additions and 60 deletions

View File

@ -638,7 +638,7 @@ void LyX::restoreGuiSession()
if (!pimpl_->files_to_load_.empty()) {
for_each(pimpl_->files_to_load_.begin(),
pimpl_->files_to_load_.end(),
bind(&LyXView::loadLyXFile, view, _1, true));
bind(&LyXFunc::loadAndViewFile, pimpl_->lyxfunc_, _1, true));
// clear this list to save a few bytes of RAM
pimpl_->files_to_load_.clear();
pimpl_->session_->lastOpened().clear();
@ -649,7 +649,7 @@ void LyX::restoreGuiSession()
// last session, and should be already there (regular files), or should
// not be added at all (help files).
for_each(lastopened.begin(), lastopened.end(),
bind(&LyXView::loadLyXFile, view, _1, false));
bind(&LyXFunc::loadAndViewFile, pimpl_->lyxfunc_, _1, false));
// clear this list to save a few bytes of RAM
pimpl_->session_->lastOpened().clear();

View File

@ -84,6 +84,7 @@
#include "support/environment.h"
#include "support/FileFilterList.h"
#include "support/FileName.h"
#include "support/filetools.h"
#include "support/lstrings.h"
#include "support/Path.h"
@ -176,7 +177,7 @@ bool import(LyXView * lv, FileName const & filename,
if (loader_format == "lyx") {
Buffer * buf = lv->loadLyXFile(lyxfile);
Buffer * buf = theLyXFunc().loadAndViewFile(lyxfile);
if (!buf) {
// we are done
lv->message(_("file not imported!"));
@ -1273,7 +1274,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
}
lyx_view_->message(bformat(_("Opening help file %1$s..."),
makeDisplayPath(fname.absFilename())));
Buffer * buf = lyx_view_->loadLyXFile(fname, false);
Buffer * buf = loadAndViewFile(fname, false);
if (buf) {
updateLabels(*buf);
lyx_view_->setBuffer(buf);
@ -1398,7 +1399,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
if (theBufferList().exists(s.absFilename()))
buf = theBufferList().getBuffer(s.absFilename());
else {
buf = lyx_view_->loadLyXFile(s);
buf = loadAndViewFile(s);
loaded = true;
}
}
@ -1620,7 +1621,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
} else {
setMessage(bformat(_("Opening child document %1$s..."),
makeDisplayPath(filename.absFilename())));
child = lyx_view_->loadLyXFile(filename, true);
child = loadAndViewFile(filename, true);
parsed = true;
}
if (child) {
@ -2164,6 +2165,36 @@ void LyXFunc::menuNew(string const & name, bool fromTemplate)
}
Buffer * LyXFunc::loadAndViewFile(FileName const & filename, bool tolastfiles)
{
lyx_view_->setBusy(true);
Buffer * newBuffer = checkAndLoadLyXFile(filename);
if (!newBuffer) {
lyx_view_->message(_("Document not loaded."));
lyx_view_->updateStatusBar();
lyx_view_->setBusy(false);
return 0;
}
lyx_view_->setBuffer(newBuffer);
// scroll to the position when the file was last closed
if (lyxrc.use_lastfilepos) {
LastFilePosSection::FilePos filepos =
LyX::ref().session().lastFilePos().load(filename);
lyx_view_->view()->moveToPosition(filepos.pit, filepos.pos, 0, 0);
}
if (tolastfiles)
LyX::ref().session().lastFiles().add(filename);
lyx_view_->setBusy(false);
return newBuffer;
}
void LyXFunc::open(string const & fname)
{
string initpath = lyxrc.document_path;
@ -2220,7 +2251,7 @@ void LyXFunc::open(string const & fname)
lyx_view_->message(bformat(_("Opening document %1$s..."), disp_fn));
docstring str2;
Buffer * buf = lyx_view_->loadLyXFile(fullname);
Buffer * buf = loadAndViewFile(fullname);
if (buf) {
updateLabels(*buf);
lyx_view_->setBuffer(buf);
@ -2335,7 +2366,7 @@ void LyXFunc::reloadBuffer()
docstring const disp_fn = makeDisplayPath(filename.absFilename());
docstring str;
closeBuffer();
Buffer * buf = lyx_view_->loadLyXFile(filename);
Buffer * buf = loadAndViewFile(filename);
if (buf) {
updateLabels(*buf);
lyx_view_->setBuffer(buf);

View File

@ -30,6 +30,10 @@ class FuncStatus;
class KeySymbol;
class Text;
namespace support {
class FileName;
}
namespace frontend {
class LyXView;
}
@ -83,6 +87,10 @@ public:
/// not the current buffer
void gotoBookmark(unsigned int idx, bool openFile, bool switchToBuffer);
/// load a buffer into the current workarea.
Buffer * loadAndViewFile(support::FileName const & name, ///< File to load.
bool tolastfiles = true); ///< append to the "Open recent" menu?
private:
///
BufferView * view() const;

View File

@ -72,10 +72,6 @@ public:
//@}
/// load a buffer into the current workarea.
virtual Buffer * loadLyXFile(support::FileName const & name, ///< File to load.
bool tolastfiles = true) = 0; ///< append to the "Open recent" menu?
/// updates the possible layouts selectable
virtual void updateLayoutChoice(bool force) = 0;
/// update the toolbar

View File

@ -31,11 +31,6 @@ using std::string;
#include "qt_helpers.h"
#include "support/filetools.h"
#include "support/convert.h"
#include "support/lstrings.h"
#include "support/os.h"
#include "buffer_funcs.h"
#include "Buffer.h"
#include "BufferList.h"
@ -58,8 +53,9 @@ using std::string;
#include "ToolbarBackend.h"
#include "version.h"
#include "support/convert.h"
#include "support/lstrings.h"
#include "support/filetools.h" // OnlyFilename()
#include "support/os.h"
#include "support/Timeout.h"
#include <QAction>
@ -104,9 +100,6 @@ extern bool quitting;
namespace frontend {
using support::bformat;
using support::FileName;
using support::makeDisplayPath;
using support::onlyFilename;
namespace {
@ -874,40 +867,6 @@ void GuiView::setBuffer(Buffer * newBuffer)
}
Buffer * GuiView::loadLyXFile(FileName const & filename, bool tolastfiles)
{
setBusy(true);
Buffer * newBuffer = checkAndLoadLyXFile(filename);
if (!newBuffer) {
message(_("Document not loaded."));
updateStatusBar();
setBusy(false);
return 0;
}
GuiWorkArea * wa = workArea(*newBuffer);
if (wa == 0)
wa = addWorkArea(*newBuffer);
// scroll to the position when the file was last closed
if (lyxrc.use_lastfilepos) {
LastFilePosSection::FilePos filepos =
LyX::ref().session().lastFilePos().load(filename);
// if successfully move to pit (returned par_id is not zero),
// update metrics and reset font
wa->bufferView().moveToPosition(filepos.pit, filepos.pos, 0, 0);
}
if (tolastfiles)
LyX::ref().session().lastFiles().add(filename);
setBusy(false);
return newBuffer;
}
void GuiView::connectBuffer(Buffer & buf)
{
buf.setGuiDelegate(this);

View File

@ -99,10 +99,6 @@ public:
/// \return the current buffer view.
BufferView * view();
/// load a buffer into the current workarea.
Buffer * loadLyXFile(support::FileName const & name, ///< File to load.
bool tolastfiles = true); ///< append to the "Open recent" menu?
/** redraw \c inset in all the BufferViews in which it is currently
* visible. If successful return a pointer to the owning Buffer.
*/

View File

@ -1060,12 +1060,14 @@ GuiWorkArea * TabWorkArea::addWorkArea(Buffer & buffer, GuiView & view)
{
GuiWorkArea * wa = new GuiWorkArea(buffer, view);
wa->setUpdatesEnabled(false);
// Hide tabbar if there's no tab (avoid a resize and a flashing tabbar
// when hiding it again below).
showBar(count() > 0);
addTab(wa, wa->windowTitle());
QObject::connect(wa, SIGNAL(titleChanged(GuiWorkArea *)),
this, SLOT(updateTabText(GuiWorkArea *)));
// Hide tabbar if there's only one tab.
showBar(count() > 1);
wa->resizeBufferView();
return wa;
}