tomm...@lyx.org schreef:
Author: tommaso
Date: Sat Aug 22 18:16:56 2009
New Revision: 31203
URL: http://www.lyx.org/trac/changeset/31203

Log:
Added at the LyXView level distinction among currently selected WorkArea (and 
BufferView) and document WorkArea (and BufferView).
Fixes crash when opening both Toc Panel and Advanced Find and Replace Panel.
Fixes preview of document (as opposed of previewing the search/replace text) 
while search/replace WorkArea selected.

Modified:
   lyx-devel/trunk/src/LyXFunc.cpp
   lyx-devel/trunk/src/frontends/LyXView.h
   lyx-devel/trunk/src/frontends/qt4/GuiView.cpp
   lyx-devel/trunk/src/frontends/qt4/GuiView.h

Modified: lyx-devel/trunk/src/LyXFunc.cpp
==============================================================================
--- lyx-devel/trunk/src/LyXFunc.cpp     Sat Aug 22 18:09:44 2009        (r31202)
+++ lyx-devel/trunk/src/LyXFunc.cpp     Sat Aug 22 18:16:56 2009        (r31203)
@@ -900,38 +900,42 @@
                }
case LFUN_BUFFER_UPDATE: {
-                       LASSERT(lyx_view_ && buffer, /**/);
+                       LASSERT(lyx_view_ && lyx_view_->documentBuffer(), /**/);
+                       Buffer * doc_buffer = lyx_view_->documentBuffer();
                        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_->documentBuffer(), /**/);
+                       Buffer * doc_buffer = lyx_view_->documentBuffer();
                        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_->documentBuffer() && 
lyx_view_->documentBuffer()->masterBuffer(), /**/);
+                       Buffer * doc_buffer = lyx_view_->documentBuffer();
                        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_->documentBuffer() && 
lyx_view_->documentBuffer()->masterBuffer(), /**/);
+                       Buffer * doc_buffer = lyx_view_->documentBuffer();
                        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;
                }
Modified: lyx-devel/trunk/src/frontends/LyXView.h
==============================================================================
--- lyx-devel/trunk/src/frontends/LyXView.h     Sat Aug 22 18:09:44 2009        
(r31202)
+++ lyx-devel/trunk/src/frontends/LyXView.h     Sat Aug 22 18:16:56 2009        
(r31203)
@@ -56,12 +56,19 @@
//@{ generic accessor functions - /// \return the current buffer view.
+       /// \return the currently selected buffer view.
        virtual BufferView * view() = 0;
+       /// \return the current document buffer view.
+       virtual BufferView * documentBufferView() = 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 * documentBuffer() = 0;
+       virtual Buffer const * documentBuffer() const = 0;
+
        /// set a buffer to the current workarea.
        virtual void setBuffer(Buffer * b) = 0; ///< \c Buffer to set.
        ///

Modified: lyx-devel/trunk/src/frontends/qt4/GuiView.cpp
==============================================================================
--- lyx-devel/trunk/src/frontends/qt4/GuiView.cpp       Sat Aug 22 18:09:44 
2009        (r31202)
+++ lyx-devel/trunk/src/frontends/qt4/GuiView.cpp       Sat Aug 22 18:16:56 
2009        (r31203)
@@ -1051,6 +1051,24 @@
 }
+Buffer * GuiView::documentBuffer()
+{
+       TabWorkArea * twa = d.currentTabWorkArea();
+       if (twa && twa->currentWorkArea())
+               return &twa->currentWorkArea()->bufferView().buffer();
+       return 0;
+}
+
+
+Buffer const * GuiView::documentBuffer() 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);
@@ -1120,7 +1138,7 @@
void GuiView::structureChanged()
 {
-       d.toc_models_.reset(view());
+       d.toc_models_.reset(documentBufferView());
        // Navigator needs more than a simple update in this case. It needs to 
be
        // rebuilt.
        updateDialog("toc", "");
@@ -1142,6 +1160,14 @@
 }
+BufferView * GuiView::documentBufferView()
+{
+       return currentMainWorkArea()
+               ? &currentMainWorkArea()->bufferView()
+               : 0;
+}
+
+
 BufferView * GuiView::view()
 {
        return d.current_work_area_ ? &d.current_work_area_->bufferView() : 0;

Modified: lyx-devel/trunk/src/frontends/qt4/GuiView.h
==============================================================================
--- lyx-devel/trunk/src/frontends/qt4/GuiView.h Sat Aug 22 18:09:44 2009        
(r31202)
+++ lyx-devel/trunk/src/frontends/qt4/GuiView.h Sat Aug 22 18:16:56 2009        
(r31203)
@@ -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 * 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
@@ -119,8 +124,10 @@
        /// called on timeout
        void autoSave();
- /// \return the current buffer view.
+       /// \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.
@@ -137,7 +144,7 @@
        /// \return the \c Workarea associated to \p  Buffer
        /// \retval 0 if no \c WorkArea is found.
        GuiWorkArea * addWorkArea(Buffer & buffer);
-       ///
+       /// \param work_area The current \c WorkArea, or \c NULL
        void setCurrentWorkArea(GuiWorkArea * work_area);
        ///
        void removeWorkArea(GuiWorkArea * work_area);

Didn't we discuss this ? I can't remember we were all very happy to see this to get in.

Vincent

Reply via email to