Replace Buffer' changed() and closing() signals with a WorkAreaManager before Andre erase everything :-)

The resulting source code is not much bigger actually.



git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20654 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2007-10-02 09:00:08 +00:00
parent 522c624821
commit 4ce0961b5a
9 changed files with 129 additions and 29 deletions

View File

@ -68,6 +68,7 @@
#include "mathed/MathSupport.h" #include "mathed/MathSupport.h"
#include "frontends/alert.h" #include "frontends/alert.h"
#include "frontends/WorkAreaManager.h"
#include "graphics/Previews.h" #include "graphics/Previews.h"
@ -206,13 +207,17 @@ public:
/// modified. (Used to properly enable 'File->Revert to saved', bug 4114). /// modified. (Used to properly enable 'File->Revert to saved', bug 4114).
time_t timestamp_; time_t timestamp_;
unsigned long checksum_; unsigned long checksum_;
///
frontend::WorkAreaManager * wa_;
}; };
Buffer::Impl::Impl(Buffer & parent, FileName const & file, bool readonly_) Buffer::Impl::Impl(Buffer & parent, FileName const & file, bool readonly_)
: lyx_clean(true), bak_clean(true), unnamed(false), read_only(readonly_), : lyx_clean(true), bak_clean(true), unnamed(false), read_only(readonly_),
filename(file), file_fully_loaded(false), inset(params), filename(file), file_fully_loaded(false), inset(params),
toc_backend(&parent), embedded_files(&parent), timestamp_(0), checksum_(0) toc_backend(&parent), embedded_files(&parent), timestamp_(0),
checksum_(0), wa_(0)
{ {
inset.setAutoBreakRows(true); inset.setAutoBreakRows(true);
lyxvc.buffer(&parent); lyxvc.buffer(&parent);
@ -221,6 +226,9 @@ Buffer::Impl::Impl(Buffer & parent, FileName const & file, bool readonly_)
// FIXME: And now do something if temppath == string(), because we // FIXME: And now do something if temppath == string(), because we
// assume from now on that temppath points to a valid temp dir. // assume from now on that temppath points to a valid temp dir.
// See http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg67406.html // See http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg67406.html
if (use_gui)
wa_ = new frontend::WorkAreaManager;
} }
@ -253,10 +261,25 @@ Buffer::~Buffer()
// Remove any previewed LaTeX snippets associated with this buffer. // Remove any previewed LaTeX snippets associated with this buffer.
graphics::Previews::get().removeLoader(*this); graphics::Previews::get().removeLoader(*this);
closing(this); if (pimpl_->wa_) {
pimpl_->wa_->closing();
delete pimpl_->wa_;
}
} }
void Buffer::changed()
{
if (pimpl_->wa_)
pimpl_->wa_->changed();
}
frontend::WorkAreaManager * Buffer::workAreaManager() const
{
return pimpl_->wa_;
}
Text & Buffer::text() const Text & Buffer::text() const
{ {
return const_cast<Text &>(pimpl_->inset.text_); return const_cast<Text &>(pimpl_->inset.text_);

View File

@ -54,6 +54,9 @@ class TexRow;
class TocBackend; class TocBackend;
class Undo; class Undo;
namespace frontend {
class WorkAreaManager;
}
/** The buffer object. /** The buffer object.
* This is the buffer object. It contains all the informations about * This is the buffer object. It contains all the informations about
@ -141,7 +144,11 @@ public:
bool hasParWithID(int id) const; bool hasParWithID(int id) const;
/// This signal is emitted when the buffer is changed. /// This signal is emitted when the buffer is changed.
boost::signal<void()> changed; void changed();
///
frontend::WorkAreaManager * workAreaManager() const;
/// This signal is emitted when the buffer structure is changed. /// This signal is emitted when the buffer structure is changed.
boost::signal<void()> structureChanged; boost::signal<void()> structureChanged;
/// This signal is emitted when an embedded file is changed /// This signal is emitted when an embedded file is changed
@ -158,8 +165,6 @@ public:
boost::signal<void()> updateTitles; boost::signal<void()> updateTitles;
/// Reset autosave timers for all users. /// Reset autosave timers for all users.
boost::signal<void()> resetAutosaveTimers; boost::signal<void()> resetAutosaveTimers;
/// This signal is emitting if the buffer is being closed.
boost::signal<void(Buffer *)> closing;
/** Save file. /** Save file.

View File

@ -626,8 +626,8 @@ void updateLabels(Buffer const & buf, bool childonly)
// FIXME // FIXME
// the embedding signal is emitted with structureChanged signal // the embedding signal is emitted with structureChanged signal
// this is inaccurate so these two will be separated later. // this is inaccurate so these two will be separated later.
cbuf.embeddedFiles().update(); //cbuf.embeddedFiles().update();
cbuf.embeddingChanged(); //cbuf.embeddingChanged();
} }

View File

@ -35,5 +35,7 @@ liblyxfrontends_la_SOURCES = \
Selection.h \ Selection.h \
WorkArea.cpp \ WorkArea.cpp \
WorkArea.h \ WorkArea.h \
WorkAreaManager.cpp \
WorkAreaManager.h \
key_state.h \ key_state.h \
mouse_state.h mouse_state.h

View File

@ -72,23 +72,12 @@ WorkArea::WorkArea(Buffer & buffer, LyXView & lv)
timecon = cursor_timeout_.timeout timecon = cursor_timeout_.timeout
.connect(boost::bind(&WorkArea::toggleCursor, this)); .connect(boost::bind(&WorkArea::toggleCursor, this));
bufferChangedConnection_ =
buffer.changed.connect(
boost::bind(&WorkArea::redraw, this));
bufferClosingConnection_ =
buffer.closing.connect(
boost::bind(&WorkArea::close, this));
cursor_timeout_.start(); cursor_timeout_.start();
} }
WorkArea::~WorkArea() WorkArea::~WorkArea()
{ {
bufferChangedConnection_.disconnect();
bufferClosingConnection_.disconnect();
delete buffer_view_; delete buffer_view_;
} }

View File

@ -19,8 +19,6 @@
#include "support/Timeout.h" #include "support/Timeout.h"
#include "support/docstring.h" #include "support/docstring.h"
#include <boost/signals/trackable.hpp>
#undef CursorShape #undef CursorShape
namespace lyx { namespace lyx {
@ -52,7 +50,8 @@ enum CursorShape {
* It works in concert with the BaseScreen class to update the * It works in concert with the BaseScreen class to update the
* widget view of a document. * widget view of a document.
*/ */
class WorkArea : public boost::signals::trackable { class WorkArea
{
public: public:
/// ///
WorkArea(Buffer & buffer, LyXView & lv); WorkArea(Buffer & buffer, LyXView & lv);
@ -100,6 +99,10 @@ public:
/// This needs to be public because it is accessed externally by GuiView. /// This needs to be public because it is accessed externally by GuiView.
void processKeySym(KeySymbol const & key, key_modifier::state state); void processKeySym(KeySymbol const & key, key_modifier::state state);
/// close this work area.
/// Slot for Buffer::closing signal.
void close();
protected: protected:
/// cause the display of the given area of the work area /// cause the display of the given area of the work area
virtual void expose(int x, int y, int w, int h) = 0; virtual void expose(int x, int y, int w, int h) = 0;
@ -107,9 +110,6 @@ protected:
void dispatch(FuncRequest const & cmd0, void dispatch(FuncRequest const & cmd0,
key_modifier::state = key_modifier::none); key_modifier::state = key_modifier::none);
/// close this work area.
/// Slot for Buffer::closing boost signal.
void close();
/// ///
void resizeBufferView(); void resizeBufferView();
/// hide the visible cursor, if it is visible /// hide the visible cursor, if it is visible
@ -136,11 +136,6 @@ private:
/// ///
Timeout cursor_timeout_; Timeout cursor_timeout_;
/// buffer changed signal connection
boost::signals::connection bufferChangedConnection_;
/// buffer closing signal connection
boost::signals::connection bufferClosingConnection_;
}; };
} // namespace frontend } // namespace frontend

View File

@ -0,0 +1,40 @@
// -*- C++ -*-
/**
* \file WorkAreaManager.cpp
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Abdelrazak Younes
*
* Full author contact details are available in file CREDITS.
*/
#include <config.h>
#include "WorkArea.h"
#include "WorkAreaManager.h"
namespace lyx {
namespace frontend {
void WorkAreaManager::registerWorkArea(WorkArea * wa)
{
work_areas_.push_back(wa);
}
void WorkAreaManager::changed()
{
for (size_t i = 0; i != work_areas_.size(); ++i)
work_areas_[i]->redraw();
}
void WorkAreaManager::closing()
{
for (size_t i = 0; i != work_areas_.size(); ++i)
work_areas_[i]->close();
}
} // namespace frontend
} // namespace lyx

View File

@ -0,0 +1,43 @@
// -*- C++ -*-
/**
* \file WorkAreaManager.h
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Abdelrazak Younes
*
* Full author contact details are available in file CREDITS.
*/
#ifndef WORKAREA_MANAGER_H
#define WORKAREA_MANAGER_H
#include <vector>
namespace lyx {
namespace frontend {
class WorkArea;
class WorkAreaManager
{
public:
WorkAreaManager() {}
///
void registerWorkArea(WorkArea * wa);
///
void changed();
///
void closing();
private:
std::vector<WorkArea *> work_areas_;
};
} // namespace frontend
} // namespace lyx
#endif // BASE_WORKAREA_H

View File

@ -27,6 +27,7 @@
#include "frontends/Dialogs.h" #include "frontends/Dialogs.h"
#include "frontends/Gui.h" #include "frontends/Gui.h"
#include "frontends/WorkArea.h" #include "frontends/WorkArea.h"
#include "frontends/WorkAreaManager.h"
#include "support/filetools.h" #include "support/filetools.h"
#include "support/convert.h" #include "support/convert.h"
@ -858,6 +859,8 @@ WorkArea * GuiViewBase::addWorkArea(Buffer & buffer)
d.stack_widget_->setCurrentWidget(d.tab_widget_); d.stack_widget_->setCurrentWidget(d.tab_widget_);
// Hide tabbar if there's only one tab. // Hide tabbar if there's only one tab.
d.tab_widget_->showBar(d.tab_widget_->count() > 1); d.tab_widget_->showBar(d.tab_widget_->count() > 1);
///
buffer.workAreaManager()->registerWorkArea(wa);
return wa; return wa;
} }