Implement the getStatus mechanism for the context menu of the toc.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@29200 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Vincent van Ravesteijn 2009-04-11 11:43:13 +00:00
parent 1c738a37fb
commit 86392456e8
5 changed files with 43 additions and 3 deletions

View File

@ -97,6 +97,13 @@ void GuiToc::doDispatch(Cursor & cur, FuncRequest const & cmd)
} }
bool GuiToc::getStatus(Cursor & cur, FuncRequest const & cmd,
FuncStatus & status) const
{
return widget_->getStatus(cur, cmd, status);
}
Dialog * createGuiToc(GuiView & lv) Dialog * createGuiToc(GuiView & lv)
{ {
GuiView & guiview = static_cast<GuiView &>(lv); GuiView & guiview = static_cast<GuiView &>(lv);

View File

@ -59,6 +59,8 @@ public:
bool isBufferDependent() const { return true; } bool isBufferDependent() const { return true; }
/// ///
void doDispatch(Cursor & cur, FuncRequest const & fr); void doDispatch(Cursor & cur, FuncRequest const & fr);
///
bool getStatus(Cursor & cur, FuncRequest const & fr, FuncStatus & fs) const;
private: private:
/// ///

View File

@ -1206,7 +1206,12 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
buf = 0; buf = 0;
if (cmd.origin == FuncRequest::TOC) { if (cmd.origin == FuncRequest::TOC) {
//FIXME: dispatch this to the toc GuiToc * toc = static_cast<GuiToc*>(findOrBuild("toc", false));
FuncStatus fs;
if (toc->getStatus(view()->cursor(), cmd, fs))
flag |= fs;
else
flag.setEnabled(false);
return true; return true;
} }

View File

@ -21,6 +21,7 @@
#include "Buffer.h" #include "Buffer.h"
#include "CutAndPaste.h" #include "CutAndPaste.h"
#include "FuncRequest.h" #include "FuncRequest.h"
#include "FuncStatus.h"
#include "LyXFunc.h" #include "LyXFunc.h"
#include "Menus.h" #include "Menus.h"
#include "TocBackend.h" #include "TocBackend.h"
@ -95,7 +96,7 @@ void TocWidget::showContextMenu(const QPoint & pos)
} }
void TocWidget::doDispatch(Cursor & cur, FuncRequest const & cmd) Inset * TocWidget::itemInset() const
{ {
QModelIndex const & index = tocTV->currentIndex(); QModelIndex const & index = tocTV->currentIndex();
TocItem const & item = TocItem const & item =
@ -116,6 +117,25 @@ void TocWidget::doDispatch(Cursor & cur, FuncRequest const & cmd)
tmp_dit.pop_back(); tmp_dit.pop_back();
inset = &tmp_dit.inset(); inset = &tmp_dit.inset();
} }
return inset;
}
bool TocWidget::getStatus(Cursor & cur, FuncRequest const & cmd,
FuncStatus & status) const
{
Inset * inset = itemInset();
FuncRequest tmpcmd(cmd);
if (inset)
return inset->getStatus(cur, tmpcmd, status);
return false;
}
void TocWidget::doDispatch(Cursor & cur, FuncRequest const & cmd)
{
Inset * inset = itemInset();
FuncRequest tmpcmd(cmd); FuncRequest tmpcmd(cmd);
if (inset) if (inset)

View File

@ -36,8 +36,11 @@ public:
/// Initialise GUI. /// Initialise GUI.
void init(QString const & str); void init(QString const & str);
///
void doDispatch(Cursor & cur, FuncRequest const & fr); void doDispatch(Cursor & cur, FuncRequest const & fr);
///
bool getStatus(Cursor & cur, FuncRequest const & fr, FuncStatus & status)
const;
public Q_SLOTS: public Q_SLOTS:
/// Update the display of the dialog whilst it is still visible. /// Update the display of the dialog whilst it is still visible.
@ -70,6 +73,9 @@ private:
void setTreeDepth(int depth); void setTreeDepth(int depth);
/// ///
void outline(int func_code); void outline(int func_code);
/// finds the inset that is connected to the current item,
/// if any, otherwise return null
Inset * itemInset() const;
/// ///
QString current_type_; QString current_type_;