mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-27 06:19:36 +00:00
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:
parent
f7f24a2709
commit
a465fcb55e
@ -34,7 +34,8 @@ public:
|
||||
MENU, // A menu entry
|
||||
TOOLBAR, // A toolbar icon
|
||||
KEYBOARD, // a keyboard binding
|
||||
COMMANDBUFFER
|
||||
COMMANDBUFFER,
|
||||
TOC
|
||||
};
|
||||
|
||||
/// just for putting these things in std::container
|
||||
|
@ -91,6 +91,11 @@ void GuiToc::enableView(bool enable)
|
||||
widget_->updateView();
|
||||
}
|
||||
|
||||
void GuiToc::doDispatch(Cursor & cur, FuncRequest const & cmd)
|
||||
{
|
||||
widget_->doDispatch(cur, cmd);
|
||||
}
|
||||
|
||||
|
||||
Dialog * createGuiToc(GuiView & lv)
|
||||
{
|
||||
|
@ -57,6 +57,8 @@ public:
|
||||
void dispatchParams();
|
||||
///
|
||||
bool isBufferDependent() const { return true; }
|
||||
///
|
||||
void doDispatch(Cursor & cur, FuncRequest const & fr);
|
||||
|
||||
private:
|
||||
///
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "GuiCompleter.h"
|
||||
#include "GuiWorkArea.h"
|
||||
#include "GuiKeySymbol.h"
|
||||
#include "GuiToc.h"
|
||||
#include "GuiToolbar.h"
|
||||
#include "Menus.h"
|
||||
#include "TocModel.h"
|
||||
@ -1204,6 +1205,11 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
|
||||
if (cmd.origin == FuncRequest::MENU && !hasFocus())
|
||||
buf = 0;
|
||||
|
||||
if (cmd.origin == FuncRequest::TOC) {
|
||||
//FIXME: dispatch this to the toc
|
||||
return true;
|
||||
}
|
||||
|
||||
switch(cmd.action) {
|
||||
case LFUN_BUFFER_WRITE:
|
||||
enable = buf && (buf->isUnnamed() || !buf->isClean());
|
||||
@ -1969,6 +1975,12 @@ bool GuiView::dispatch(FuncRequest const & cmd)
|
||||
bv->cursor().updateFlags(Update::None);
|
||||
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) {
|
||||
case LFUN_BUFFER_IMPORT:
|
||||
importDocument(to_utf8(cmd.argument()));
|
||||
|
@ -168,10 +168,11 @@ public:
|
||||
MenuItem(Kind kind,
|
||||
QString const & label,
|
||||
FuncRequest const & func,
|
||||
bool optional = false)
|
||||
bool optional = false,
|
||||
FuncRequest::Origin origin = FuncRequest::MENU)
|
||||
: kind_(kind), label_(label), func_(func), optional_(optional)
|
||||
{
|
||||
func_.origin = FuncRequest::MENU;
|
||||
func_.origin = origin;
|
||||
}
|
||||
|
||||
// boost::shared_ptr<MenuDefinition> needs this apprently...
|
||||
@ -453,7 +454,10 @@ void MenuDefinition::read(Lexer & lex)
|
||||
lex.next(true);
|
||||
string const command = lex.getString();
|
||||
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;
|
||||
break;
|
||||
}
|
||||
|
@ -21,11 +21,13 @@
|
||||
#include "Buffer.h"
|
||||
#include "FuncRequest.h"
|
||||
#include "LyXFunc.h"
|
||||
#include "Menus.h"
|
||||
|
||||
#include "support/debug.h"
|
||||
#include "support/lassert.h"
|
||||
|
||||
#include <QHeaderView>
|
||||
#include <QMenu>
|
||||
#include <QTimer>
|
||||
|
||||
#include <vector>
|
||||
@ -67,10 +69,36 @@ TocWidget::TocWidget(GuiView & gui_view, QWidget * parent)
|
||||
// Buffer.
|
||||
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());
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
goTo(index);
|
||||
|
@ -15,6 +15,8 @@
|
||||
|
||||
#include "ui_TocUi.h"
|
||||
|
||||
#include "Cursor.h"
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class QModelIndex;
|
||||
@ -35,6 +37,8 @@ public:
|
||||
/// Initialise GUI.
|
||||
void init(QString const & str);
|
||||
|
||||
void doDispatch(Cursor const & cur, FuncRequest const & fr);
|
||||
|
||||
public Q_SLOTS:
|
||||
/// Update the display of the dialog whilst it is still visible.
|
||||
void updateView();
|
||||
@ -57,6 +61,8 @@ protected Q_SLOTS:
|
||||
void on_moveInTB_clicked();
|
||||
void on_moveOutTB_clicked();
|
||||
|
||||
void showContextMenu(const QPoint & pos);
|
||||
|
||||
private:
|
||||
///
|
||||
void enableControls(bool enable = true);
|
||||
|
Loading…
Reference in New Issue
Block a user