Hello,
this is a patch for providing "awareness", within LyXView, of the
distinction between:
- the currently selected buffer (i.e., document buf, search buf, replace
buf), retrieved using
LyXView::buffer()
- the buffer containing the actual document, retrieved using:
LyXView::mainBuffer()
The patch includes changes to LyXFunc.cpp, so that, when preview-output
is selected but focus is on the search or replace WorkAreas, the main
document buffer is actually previewed (not the search/replace buffers,
as it happens currently on trunk).
Perhaps this distinction may turn out to be useful in other LFUNs as well.
I'm waiting for Abdel's approval before committing this.
T.
Index: src/LyXFunc.cpp
===================================================================
--- src/LyXFunc.cpp (revisione 31126)
+++ src/LyXFunc.cpp (copia locale)
@@ -900,38 +900,42 @@
}
case LFUN_BUFFER_UPDATE: {
- LASSERT(lyx_view_ && buffer, /**/);
+ LASSERT(lyx_view_ && lyx_view_->mainBuffer(), /**/);
+ Buffer * doc_buffer = lyx_view_->mainBuffer();
string format = argument;
if (argument.empty())
- format = buffer->getDefaultOutputFormat();
- buffer->doExport(format, true);
+ format = doc_buffer->getDefaultOutputFormat();
+ doc_buffer->doExport(format, true);
break;
}
case LFUN_BUFFER_VIEW: {
- LASSERT(lyx_view_ && buffer, /**/);
+ LASSERT(lyx_view_ && lyx_view_->mainBuffer(), /**/);
+ Buffer * doc_buffer = lyx_view_->mainBuffer();
string format = argument;
if (argument.empty())
- format = buffer->getDefaultOutputFormat();
- buffer->preview(format);
+ format = doc_buffer->getDefaultOutputFormat();
+ doc_buffer->preview(format);
break;
}
case LFUN_MASTER_BUFFER_UPDATE: {
- LASSERT(lyx_view_ && buffer && buffer->masterBuffer(), /**/);
+ LASSERT(lyx_view_ && lyx_view_->mainBuffer() && lyx_view_->mainBuffer()->masterBuffer(), /**/);
+ Buffer * doc_buffer = lyx_view_->mainBuffer();
string format = argument;
if (argument.empty())
- format = buffer->masterBuffer()->getDefaultOutputFormat();
- buffer->masterBuffer()->doExport(format, true);
+ format = doc_buffer->masterBuffer()->getDefaultOutputFormat();
+ doc_buffer->masterBuffer()->doExport(format, true);
break;
}
case LFUN_MASTER_BUFFER_VIEW: {
- LASSERT(lyx_view_ && buffer && buffer->masterBuffer(), /**/);
+ LASSERT(lyx_view_ && lyx_view_->mainBuffer() && lyx_view_->mainBuffer()->masterBuffer(), /**/);
+ Buffer * doc_buffer = lyx_view_->mainBuffer();
string format = argument;
if (argument.empty())
- format = buffer->masterBuffer()->getDefaultOutputFormat();
- buffer->masterBuffer()->preview(format);
+ format = doc_buffer->masterBuffer()->getDefaultOutputFormat();
+ doc_buffer->masterBuffer()->preview(format);
break;
}
Index: src/frontends/LyXView.h
===================================================================
--- src/frontends/LyXView.h (revisione 31126)
+++ src/frontends/LyXView.h (copia locale)
@@ -59,9 +59,14 @@
/// \return the current buffer view.
virtual BufferView * view() = 0;
- /// \return the buffer currently shown in this window
+ /// \return the buffer currently selected in this window
virtual Buffer * buffer() = 0;
virtual Buffer const * buffer() const = 0;
+
+ /// \return the document buffer in this window
+ virtual Buffer * mainBuffer() = 0;
+ virtual Buffer const * mainBuffer() const = 0;
+
/// set a buffer to the current workarea.
virtual void setBuffer(Buffer * b) = 0; ///< \c Buffer to set.
///
Index: src/frontends/qt4/GuiView.h
===================================================================
--- src/frontends/qt4/GuiView.h (revisione 31126)
+++ src/frontends/qt4/GuiView.h (copia locale)
@@ -84,9 +84,14 @@
///
LayoutBox * getLayoutDialog() const;
- /// \return the buffer currently shown in this window
- Buffer * buffer();
- Buffer const * buffer() 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 * mainBuffer();
+ virtual Buffer const * mainBuffer() const;
+
/// set a buffer to the current workarea.
void setBuffer(Buffer * b); ///< \c Buffer to set.
///
Index: src/frontends/qt4/GuiView.cpp
===================================================================
--- src/frontends/qt4/GuiView.cpp (revisione 31126)
+++ src/frontends/qt4/GuiView.cpp (copia locale)
@@ -1049,6 +1049,24 @@
}
+Buffer * GuiView::mainBuffer()
+{
+ TabWorkArea * twa = d.currentTabWorkArea();
+ if (twa && twa->currentWorkArea())
+ return &twa->currentWorkArea()->bufferView().buffer();
+ return 0;
+}
+
+
+Buffer const * GuiView::mainBuffer() const
+{
+ TabWorkArea * twa = d.currentTabWorkArea();
+ if (twa && twa->currentWorkArea())
+ return &twa->currentWorkArea()->bufferView().buffer();
+ return 0;
+}
+
+
void GuiView::setBuffer(Buffer * newBuffer)
{
LYXERR(Debug::DEBUG, "Setting buffer: " << newBuffer << std::endl);