TOC context menu (part 2)

* TocWidget: add context menu to toc.

* Menus: specify origin of cmd.

* GuiView: if cmd coming from toc, dispatch to GuiToc.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@29155 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Vincent van Ravesteijn 2009-04-08 21:06:58 +00:00
parent f7f24a2709
commit a465fcb55e
7 changed files with 62 additions and 4 deletions

View File

@ -34,7 +34,8 @@ public:
MENU, // A menu entry MENU, // A menu entry
TOOLBAR, // A toolbar icon TOOLBAR, // A toolbar icon
KEYBOARD, // a keyboard binding KEYBOARD, // a keyboard binding
COMMANDBUFFER COMMANDBUFFER,
TOC
}; };
/// just for putting these things in std::container /// just for putting these things in std::container

View File

@ -91,6 +91,11 @@ void GuiToc::enableView(bool enable)
widget_->updateView(); widget_->updateView();
} }
void GuiToc::doDispatch(Cursor & cur, FuncRequest const & cmd)
{
widget_->doDispatch(cur, cmd);
}
Dialog * createGuiToc(GuiView & lv) Dialog * createGuiToc(GuiView & lv)
{ {

View File

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

View File

@ -23,6 +23,7 @@
#include "GuiCompleter.h" #include "GuiCompleter.h"
#include "GuiWorkArea.h" #include "GuiWorkArea.h"
#include "GuiKeySymbol.h" #include "GuiKeySymbol.h"
#include "GuiToc.h"
#include "GuiToolbar.h" #include "GuiToolbar.h"
#include "Menus.h" #include "Menus.h"
#include "TocModel.h" #include "TocModel.h"
@ -1204,6 +1205,11 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
if (cmd.origin == FuncRequest::MENU && !hasFocus()) if (cmd.origin == FuncRequest::MENU && !hasFocus())
buf = 0; buf = 0;
if (cmd.origin == FuncRequest::TOC) {
//FIXME: dispatch this to the toc
return true;
}
switch(cmd.action) { switch(cmd.action) {
case LFUN_BUFFER_WRITE: case LFUN_BUFFER_WRITE:
enable = buf && (buf->isUnnamed() || !buf->isClean()); enable = buf && (buf->isUnnamed() || !buf->isClean());
@ -1969,6 +1975,12 @@ bool GuiView::dispatch(FuncRequest const & cmd)
bv->cursor().updateFlags(Update::None); bv->cursor().updateFlags(Update::None);
bool dispatched = true; bool dispatched = true;
if (cmd.origin == FuncRequest::TOC) {
GuiToc * toc = static_cast<GuiToc*>(findOrBuild("toc", false));
toc->doDispatch(bv->cursor(), cmd);
return true;
}
switch(cmd.action) { switch(cmd.action) {
case LFUN_BUFFER_IMPORT: case LFUN_BUFFER_IMPORT:
importDocument(to_utf8(cmd.argument())); importDocument(to_utf8(cmd.argument()));

View File

@ -168,10 +168,11 @@ public:
MenuItem(Kind kind, MenuItem(Kind kind,
QString const & label, QString const & label,
FuncRequest const & func, FuncRequest const & func,
bool optional = false) bool optional = false,
FuncRequest::Origin origin = FuncRequest::MENU)
: kind_(kind), label_(label), func_(func), optional_(optional) : kind_(kind), label_(label), func_(func), optional_(optional)
{ {
func_.origin = FuncRequest::MENU; func_.origin = origin;
} }
// boost::shared_ptr<MenuDefinition> needs this apprently... // boost::shared_ptr<MenuDefinition> needs this apprently...
@ -453,7 +454,10 @@ void MenuDefinition::read(Lexer & lex)
lex.next(true); lex.next(true);
string const command = lex.getString(); string const command = lex.getString();
FuncRequest func = lyxaction.lookupFunc(command); FuncRequest func = lyxaction.lookupFunc(command);
add(MenuItem(MenuItem::Command, toqstr(name), func, optional)); FuncRequest::Origin origin = FuncRequest::MENU;
if (name_.startsWith("context-toc-"))
origin = FuncRequest::TOC;
add(MenuItem(MenuItem::Command, toqstr(name), func, optional, origin));
optional = false; optional = false;
break; break;
} }

View File

@ -21,11 +21,13 @@
#include "Buffer.h" #include "Buffer.h"
#include "FuncRequest.h" #include "FuncRequest.h"
#include "LyXFunc.h" #include "LyXFunc.h"
#include "Menus.h"
#include "support/debug.h" #include "support/debug.h"
#include "support/lassert.h" #include "support/lassert.h"
#include <QHeaderView> #include <QHeaderView>
#include <QMenu>
#include <QTimer> #include <QTimer>
#include <vector> #include <vector>
@ -67,10 +69,36 @@ TocWidget::TocWidget(GuiView & gui_view, QWidget * parent)
// Buffer. // Buffer.
enableControls(false); enableControls(false);
// make us responsible for the context menu of the tabbar
setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, SIGNAL(customContextMenuRequested(const QPoint &)),
this, SLOT(showContextMenu(const QPoint &)));
connect(tocTV, SIGNAL(customContextMenuRequested(const QPoint &)),
this, SLOT(showContextMenu(const QPoint &)));
init(QString()); init(QString());
} }
void TocWidget::showContextMenu(const QPoint & pos)
{
std::string name = "context-toc-" + fromqstr(current_type_);
QMenu * menu = guiApp->menus().menu(toqstr(name), gui_view_);
if (!menu)
return;
menu->exec(mapToGlobal(pos));
}
void TocWidget::doDispatch(Cursor const & cur, FuncRequest const & cmd)
{
switch(cmd.action) {
default:
break;
}
}
void TocWidget::on_tocTV_activated(QModelIndex const & index) void TocWidget::on_tocTV_activated(QModelIndex const & index)
{ {
goTo(index); goTo(index);

View File

@ -15,6 +15,8 @@
#include "ui_TocUi.h" #include "ui_TocUi.h"
#include "Cursor.h"
#include <QWidget> #include <QWidget>
class QModelIndex; class QModelIndex;
@ -35,6 +37,8 @@ public:
/// Initialise GUI. /// Initialise GUI.
void init(QString const & str); void init(QString const & str);
void doDispatch(Cursor const & cur, FuncRequest const & fr);
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.
void updateView(); void updateView();
@ -57,6 +61,8 @@ protected Q_SLOTS:
void on_moveInTB_clicked(); void on_moveInTB_clicked();
void on_moveOutTB_clicked(); void on_moveOutTB_clicked();
void showContextMenu(const QPoint & pos);
private: private:
/// ///
void enableControls(bool enable = true); void enableControls(bool enable = true);