* LyXView:

- view() -> currentBufferView()
  - add const access to bufferViews.
* GuiView.h: cleanups


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@31286 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2009-09-05 14:29:11 +00:00
parent ed4c30930a
commit 722d8c757b
9 changed files with 102 additions and 91 deletions

View File

@ -211,10 +211,10 @@ void LyXFunc::initKeySequences(KeyMap * kb)
void LyXFunc::setLyXView(LyXView * lv)
{
if (lyx_view_ && lyx_view_->view() && lyx_view_ != lv)
if (lyx_view_ && lyx_view_->currentBufferView() && lyx_view_ != lv)
// save current selection to the selection buffer to allow
// middle-button paste in another window
cap::saveSelection(lyx_view_->view()->cursor());
cap::saveSelection(lyx_view_->currentBufferView()->cursor());
lyx_view_ = lv;
}
@ -226,9 +226,10 @@ void LyXFunc::handleKeyFunc(FuncCode action)
if (keyseq.length())
c = 0;
LASSERT(lyx_view_ && lyx_view_->view(), /**/);
lyx_view_->view()->getIntl().getTransManager().deadkey(
c, get_accent(action).accent, view()->cursor().innerText(), view()->cursor());
LASSERT(lyx_view_ && lyx_view_->currentBufferView(), /**/);
lyx_view_->currentBufferView()->getIntl().getTransManager().deadkey(
c, get_accent(action).accent, view()->cursor().innerText(),
currentBufferView()->cursor());
// Need to clear, in case the minibuffer calls these
// actions
keyseq.clear();
@ -823,7 +824,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
case LFUN_WORD_FIND_FORWARD:
case LFUN_WORD_FIND_BACKWARD: {
LASSERT(lyx_view_ && lyx_view_->view(), /**/);
LASSERT(lyx_view_ && lyx_view_->currentBufferView(), /**/);
static docstring last_search;
docstring searched_string;
@ -850,7 +851,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
break;
case LFUN_CANCEL:
LASSERT(lyx_view_ && lyx_view_->view(), /**/);
LASSERT(lyx_view_ && lyx_view_->currentBufferView(), /**/);
keyseq.reset();
meta_fake_bit = NoModifier;
if (buffer)
@ -865,7 +866,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
break;
case LFUN_BUFFER_TOGGLE_READ_ONLY: {
LASSERT(lyx_view_ && lyx_view_->view() && buffer, /**/);
LASSERT(lyx_view_ && lyx_view_->currentBufferView() && buffer, /**/);
if (buffer->lyxvc().inUse())
buffer->lyxvc().toggleReadOnly();
else
@ -1341,22 +1342,22 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
case LFUN_KEYMAP_OFF:
LASSERT(lyx_view_ && lyx_view_->view(), /**/);
lyx_view_->view()->getIntl().keyMapOn(false);
lyx_view_->currentBufferView()->getIntl().keyMapOn(false);
break;
case LFUN_KEYMAP_PRIMARY:
LASSERT(lyx_view_ && lyx_view_->view(), /**/);
lyx_view_->view()->getIntl().keyMapPrim();
LASSERT(lyx_view_ && lyx_view_->currentBufferView(), /**/);
lyx_view_->currentBufferView()->getIntl().keyMapPrim();
break;
case LFUN_KEYMAP_SECONDARY:
LASSERT(lyx_view_ && lyx_view_->view(), /**/);
lyx_view_->view()->getIntl().keyMapSec();
LASSERT(lyx_view_ && lyx_view_->currentBufferView(), /**/);
lyx_view_->currentBufferView()->getIntl().keyMapSec();
break;
case LFUN_KEYMAP_TOGGLE:
LASSERT(lyx_view_ && lyx_view_->view(), /**/);
lyx_view_->view()->getIntl().toggleKeyMap();
LASSERT(lyx_view_ && lyx_view_->currentBufferView(), /**/);
lyx_view_->currentBufferView()->getIntl().toggleKeyMap();
break;
case LFUN_REPEAT: {
@ -1678,15 +1679,15 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
// Let the current LyXView dispatch its own actions.
if (lyx_view_->dispatch(cmd)) {
if (lyx_view_->view()) {
updateFlags = lyx_view_->view()->cursor().result().update();
if (lyx_view_->currentBufferView()) {
updateFlags = lyx_view_->currentBufferView()->cursor().result().update();
if (theBufferList().isLoaded(buffer))
buffer->undo().endUndoGroup();
}
break;
}
LASSERT(lyx_view_->view(), /**/);
LASSERT(lyx_view_->currentBufferView(), /**/);
// Let the current BufferView dispatch its own actions.
if (view()->dispatch(cmd)) {
@ -1889,7 +1890,7 @@ docstring LyXFunc::viewStatusMessage()
BufferView * LyXFunc::view() const
{
LASSERT(lyx_view_, /**/);
return lyx_view_->view();
return lyx_view_->currentBufferView();
}

View File

@ -57,9 +57,11 @@ public:
//@{ generic accessor functions
/// \return the currently selected buffer view.
virtual BufferView * view() = 0;
virtual BufferView * currentBufferView() = 0;
virtual BufferView const * currentBufferView() const = 0;
/// \return the current document buffer view.
virtual BufferView * documentBufferView() = 0;
virtual BufferView const * documentBufferView() const = 0;
/// \return the buffer currently selected in this window
virtual Buffer * buffer() = 0;

View File

@ -108,7 +108,7 @@ KernelDocType Dialog::docType() const
BufferView const * Dialog::bufferview() const
{
return lyxview_->view();
return lyxview_->currentBufferView();
}

View File

@ -297,7 +297,7 @@ string const GuiCommandBuffer::historyDown()
docstring const GuiCommandBuffer::getCurrentState() const
{
return view_->view()->cursor().currentState();
return view_->currentBufferView()->cursor().currentState();
}

View File

@ -929,8 +929,8 @@ void GuiView::setCurrentWorkArea(GuiWorkArea * wa)
if (old_gwa == wa)
return;
if (view())
cap::saveSelection(view()->cursor());
if (currentBufferView())
cap::saveSelection(currentBufferView()->cursor());
theGuiApp()->setCurrentView(this);
d.current_work_area_ = wa;
@ -1168,7 +1168,21 @@ BufferView * GuiView::documentBufferView()
}
BufferView * GuiView::view()
BufferView const * GuiView::documentBufferView() const
{
return currentMainWorkArea()
? &currentMainWorkArea()->bufferView()
: 0;
}
BufferView * GuiView::currentBufferView()
{
return d.current_work_area_ ? &d.current_work_area_->bufferView() : 0;
}
BufferView const * GuiView::currentBufferView() const
{
return d.current_work_area_ ? &d.current_work_area_->bufferView() : 0;
}
@ -1178,8 +1192,8 @@ void GuiView::autoSave()
{
LYXERR(Debug::INFO, "Running autoSave()");
if (buffer())
view()->buffer().autoSave();
if (documentBufferView())
documentBufferView()->buffer().autoSave();
}
@ -1198,7 +1212,7 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
if (cmd.origin == FuncRequest::TOC) {
GuiToc * toc = static_cast<GuiToc*>(findOrBuild("toc", false));
FuncStatus fs;
if (toc->getStatus(view()->cursor(), cmd, fs))
if (toc->getStatus(documentBufferView()->cursor(), cmd, fs))
flag |= fs;
else
flag.setEnabled(false);
@ -1254,12 +1268,13 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
enable = buf->isExportable("dvi")
&& lyxrc.print_command != "none";
else if (name == "character" || name == "symbols") {
if (buf->isReadonly() || !view() || !view()->cursor().inTexted())
if (buf->isReadonly() || !currentBufferView()
|| !currentBufferView()->cursor().inTexted())
enable = false;
else {
// FIXME we should consider passthru
// paragraphs too.
Inset const & in = view()->cursor().inset();
Inset const & in = currentBufferView()->cursor().inset();
enable = !in.getLayout().isPassThru();
}
}
@ -1285,7 +1300,7 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
if (inset) {
FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument());
FuncStatus fs;
if (!inset->getStatus(view()->cursor(), fr, fs)) {
if (!inset->getStatus(currentBufferView()->cursor(), fr, fs)) {
// Every inset is supposed to handle this
LASSERT(false, break);
}
@ -1300,19 +1315,22 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
case LFUN_COMPLETION_INLINE:
if (!d.current_work_area_
|| !d.current_work_area_->completer().inlinePossible(view()->cursor()))
|| !d.current_work_area_->completer().inlinePossible(
currentBufferView()->cursor()))
enable = false;
break;
case LFUN_COMPLETION_POPUP:
if (!d.current_work_area_
|| !d.current_work_area_->completer().popupPossible(view()->cursor()))
|| !d.current_work_area_->completer().popupPossible(
currentBufferView()->cursor()))
enable = false;
break;
case LFUN_COMPLETION_COMPLETE:
if (!d.current_work_area_
|| !d.current_work_area_->completer().inlinePossible(view()->cursor()))
|| !d.current_work_area_->completer().inlinePossible(
currentBufferView()->cursor()))
enable = false;
break;
@ -1385,7 +1403,7 @@ Buffer * GuiView::loadDocument(FileName const & filename, bool tolastfiles)
if (lyxrc.use_lastfilepos) {
LastFilePosSection::FilePos filepos =
theSession().lastFilePos().load(filename);
view()->moveToPosition(filepos.pit, filepos.pos, 0, 0);
documentBufferView()->moveToPosition(filepos.pit, filepos.pos, 0, 0);
}
if (tolastfiles)
@ -1525,7 +1543,8 @@ static bool import(GuiView * lv, FileName const & filename,
string filename2 = (loader_format == format) ? filename.absFilename()
: support::changeExtension(filename.absFilename(),
formats.extension(loader_format));
lv->view()->insertPlaintextFile(FileName(filename2), as_paragraphs);
lv->currentBufferView()->insertPlaintextFile(FileName(filename2),
as_paragraphs);
theLyXFunc().setLyXView(lv);
lyx::dispatch(FuncRequest(LFUN_MARK_OFF));
}
@ -1655,15 +1674,15 @@ void GuiView::newDocument(string const & filename, bool from_template)
// If no new document could be created, it is unsure
// whether there is a valid BufferView.
if (view())
if (currentBufferView())
// Ensure the cursor is correctly positioned on screen.
view()->showCursor();
currentBufferView()->showCursor();
}
void GuiView::insertLyXFile(docstring const & fname)
{
BufferView * bv = view();
BufferView * bv = documentBufferView();
if (!bv)
return;
@ -1713,7 +1732,7 @@ void GuiView::insertLyXFile(docstring const & fname)
void GuiView::insertPlaintextFile(docstring const & fname,
bool asParagraph)
{
BufferView * bv = view();
BufferView * bv = documentBufferView();
if (!bv)
return;
@ -2131,7 +2150,7 @@ void GuiView::gotoNextOrPreviousBuffer(NextOrPrevious np)
bool GuiView::dispatch(FuncRequest const & cmd)
{
BufferView * bv = view();
BufferView * bv = currentBufferView();
// By default we won't need any update.
if (bv)
bv->cursor().updateFlags(Update::None);
@ -2239,7 +2258,7 @@ bool GuiView::dispatch(FuncRequest const & cmd)
Inset * inset = getOpenInset(name);
if (inset) {
FuncRequest fr(LFUN_INSET_DIALOG_UPDATE, cmd.argument());
inset->dispatch(view()->cursor(), fr);
inset->dispatch(currentBufferView()->cursor(), fr);
} else if (name == "paragraph") {
lyx::dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
} else if (name == "prefs" || name == "document") {
@ -2309,16 +2328,16 @@ bool GuiView::dispatch(FuncRequest const & cmd)
Inset * inset = getOpenInset(name);
if (inset) {
// put cursor in front of inset.
if (!view()->setCursorFromInset(inset)) {
if (!currentBufferView()->setCursorFromInset(inset)) {
LASSERT(false, break);
}
BufferView * bv = currentBufferView();
// useful if we are called from a dialog.
view()->cursor().beginUndoGroup();
view()->cursor().recordUndo();
bv->cursor().beginUndoGroup();
bv->cursor().recordUndo();
FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument());
inset->dispatch(view()->cursor(), fr);
view()->cursor().endUndoGroup();
inset->dispatch(bv->cursor(), fr);
bv->cursor().endUndoGroup();
} else {
FuncRequest fr(LFUN_INSET_INSERT, cmd.argument());
lyx::dispatch(fr);

View File

@ -62,53 +62,54 @@ public:
~GuiView();
///
int id() const { return id_; }
void setFocus();
/// LyXView inherited methods.
///@{
int id() const;
void setBusy(bool);
/// returns true if this view has the focus.
BufferView * currentBufferView();
BufferView const * currentBufferView() const;
BufferView * documentBufferView();
BufferView const * documentBufferView() const;
Buffer * buffer();
Buffer const * buffer() const;
Buffer * documentBuffer();
Buffer const * documentBuffer() const;
void setBuffer(Buffer * b);
bool closeBuffer();
bool closeBufferAll();
bool hasFocus() const;
Buffer * loadDocument(support::FileName const & name,
bool tolastfiles = true);
void newDocument(std::string const & filename,
bool fromTemplate);
void message(docstring const &);
bool getStatus(FuncRequest const & cmd, FuncStatus & flag);
bool dispatch(FuncRequest const & cmd);
void restartCursor();
void updateCompletion(Cursor & cur, bool start, bool keep);
void setFocus();
///@}
/// add toolbar, if newline==true, add a toolbar break before the toolbar
GuiToolbar * makeToolbar(ToolbarInfo const & tbinfo, bool newline);
virtual void updateStatusBar();
virtual void message(docstring const & str);
void updateStatusBar();
/// updates the possible layouts selectable
void updateLayoutList();
void updateToolbars();
QMenu * createPopupMenu();
bool getStatus(FuncRequest const & cmd, FuncStatus & flag);
bool dispatch(FuncRequest const & cmd);
///
LayoutBox * getLayoutDialog() const;
/// \return the buffer currently selected in this window
virtual Buffer * buffer();
virtual Buffer const * buffer() const;
/// \return the document buffer in this window
virtual Buffer * documentBuffer();
virtual Buffer const * documentBuffer() const;
/// set a buffer to the current workarea.
void setBuffer(Buffer * b); ///< \c Buffer to set.
/// closes the current active buffer
bool closeBuffer();
/// hides the workarea and makes sure it is clean
bool hideWorkArea(GuiWorkArea * wa);
/// closes the workarea
bool closeWorkArea(GuiWorkArea * wa);
/// load a document into the current workarea.
Buffer * loadDocument(support::FileName const & name, ///< File to load.
bool tolastfiles = true); ///< append to the "Open recent" menu?
///
void openDocument(std::string const & filename);
///
void importDocument(std::string const &);
///
void newDocument(std::string const & filename, bool fromTemplate);
/// GuiBufferDelegate.
///@{
@ -124,17 +125,10 @@ public:
/// called on timeout
void autoSave();
/// \return the currently selected buffer view.
BufferView * view();
/// \return the current document buffer view.
BufferView * documentBufferView();
/** redraw \c inset in all the BufferViews in which it is currently
* visible. If successful return a pointer to the owning Buffer.
*/
Buffer const * updateInset(Inset const *);
///
void restartCursor();
/// \return the \c Workarea associated to \p Buffer
/// \retval 0 if no \c WorkArea is found.
@ -262,9 +256,6 @@ public:
///
void disconnectDialog(std::string const & name);
///
void updateCompletion(Cursor & cur, bool start, bool keep);
private:
///
void saveLayout() const;
@ -314,8 +305,6 @@ private:
/// or to discard the changes. If hiding is true, the
/// document will be reloaded.
bool saveBufferIfNeeded(Buffer & buf, bool hiding);
/// closes all workareas and all hidden buffers
bool closeBufferAll();
/// closes all workareas
bool closeWorkAreaAll();
/// write all open workareas into the session file

View File

@ -630,9 +630,9 @@ void LayoutBox::updateContents(bool reset)
// or we've moved from one inset to another
DocumentClass const * text_class = &buffer->params().documentClass();
Inset const * inset =
&(d->owner_.view()->cursor().innerText()->inset());
&(d->owner_.currentBufferView()->cursor().innerText()->inset());
if (!reset && d->text_class_ == text_class && d->inset_ == inset) {
set(d->owner_.view()->cursor().innerParagraph().layout().name());
set(d->owner_.currentBufferView()->cursor().innerParagraph().layout().name());
return;
}
@ -660,7 +660,7 @@ void LayoutBox::updateContents(bool reset)
lyxrc.group_layouts, lit->isUnknown());
}
set(d->owner_.view()->cursor().innerParagraph().layout().name());
set(d->owner_.currentBufferView()->cursor().innerParagraph().layout().name());
d->countCategories();
// needed to recalculate size hint

View File

@ -1781,7 +1781,7 @@ void Menus::fillMenuBar(QMenuBar * qmb, GuiView * view, bool initial)
MenuDefinition menu;
BufferView * bv = 0;
if (view)
bv = view->view();
bv = view->currentBufferView();
d->expand(d->menubar_, menu, bv);
MenuDefinition::const_iterator m = menu.begin();
@ -1834,7 +1834,7 @@ void Menus::updateMenu(Menu * qmenu)
MenuDefinition const & fromLyxMenu = d->getMenu(qmenu->d->name);
BufferView * bv = 0;
if (qmenu->d->view)
bv = qmenu->d->view->view();
bv = qmenu->d->view->currentBufferView();
d->expand(fromLyxMenu, *qmenu->d->top_level_menu, bv);
qmenu->d->populate(*qmenu, *qmenu->d->top_level_menu);
}

View File

@ -404,7 +404,7 @@ static bool isSortable(QString const & type)
void TocWidget::updateView()
{
if (!gui_view_.view()) {
if (!gui_view_.currentBufferView()) {
enableControls(false);
typeCO->setEnabled(false);
tocTV->setModel(0);