mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-25 22:06:15 +00:00
dynamic context menu for InsetCitation.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@24538 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
eb60240b73
commit
99f2abf59f
@ -94,6 +94,16 @@ Menuset
|
|||||||
End
|
End
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# InsetCitation context menu
|
||||||
|
#
|
||||||
|
Menu "context-citation"
|
||||||
|
CiteStyles
|
||||||
|
Separator
|
||||||
|
Item "Settings...|S" "next-inset-toggle"
|
||||||
|
End
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# InsetBibtex context menu
|
# InsetBibtex context menu
|
||||||
#
|
#
|
||||||
|
@ -23,10 +23,12 @@
|
|||||||
#include "GuiView.h"
|
#include "GuiView.h"
|
||||||
#include "qt_helpers.h"
|
#include "qt_helpers.h"
|
||||||
|
|
||||||
|
#include "BiblioInfo.h"
|
||||||
#include "BranchList.h"
|
#include "BranchList.h"
|
||||||
#include "Buffer.h"
|
#include "Buffer.h"
|
||||||
#include "BufferList.h"
|
#include "BufferList.h"
|
||||||
#include "BufferParams.h"
|
#include "BufferParams.h"
|
||||||
|
#include "BufferView.h"
|
||||||
#include "Converter.h"
|
#include "Converter.h"
|
||||||
#include "CutAndPaste.h"
|
#include "CutAndPaste.h"
|
||||||
#include "Floating.h"
|
#include "Floating.h"
|
||||||
@ -45,6 +47,9 @@
|
|||||||
#include "TocBackend.h"
|
#include "TocBackend.h"
|
||||||
#include "ToolbarBackend.h"
|
#include "ToolbarBackend.h"
|
||||||
|
|
||||||
|
#include "insets/Inset.h"
|
||||||
|
#include "insets/InsetCitation.h"
|
||||||
|
|
||||||
#include "support/assert.h"
|
#include "support/assert.h"
|
||||||
#include "support/convert.h"
|
#include "support/convert.h"
|
||||||
#include "support/debug.h"
|
#include "support/debug.h"
|
||||||
@ -131,7 +136,9 @@ public:
|
|||||||
/** toolbars */
|
/** toolbars */
|
||||||
Toolbars,
|
Toolbars,
|
||||||
/** Available branches in document */
|
/** Available branches in document */
|
||||||
Branches
|
Branches,
|
||||||
|
/** Available citation styles for a given citation */
|
||||||
|
CiteStyles
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit MenuItem(Kind kind) : kind_(kind), optional_(false) {}
|
explicit MenuItem(Kind kind) : kind_(kind), optional_(false) {}
|
||||||
@ -283,6 +290,7 @@ public:
|
|||||||
void expandPasteRecent();
|
void expandPasteRecent();
|
||||||
void expandToolbars();
|
void expandToolbars();
|
||||||
void expandBranches(Buffer const * buf);
|
void expandBranches(Buffer const * buf);
|
||||||
|
void expandCiteStyles(BufferView const *);
|
||||||
///
|
///
|
||||||
ItemList items_;
|
ItemList items_;
|
||||||
///
|
///
|
||||||
@ -363,6 +371,7 @@ void MenuDefinition::read(Lexer & lex)
|
|||||||
enum {
|
enum {
|
||||||
md_item = 1,
|
md_item = 1,
|
||||||
md_branches,
|
md_branches,
|
||||||
|
md_citestyles,
|
||||||
md_documents,
|
md_documents,
|
||||||
md_bookmarks,
|
md_bookmarks,
|
||||||
md_charstyles,
|
md_charstyles,
|
||||||
@ -389,6 +398,7 @@ void MenuDefinition::read(Lexer & lex)
|
|||||||
{ "bookmarks", md_bookmarks },
|
{ "bookmarks", md_bookmarks },
|
||||||
{ "branches", md_branches },
|
{ "branches", md_branches },
|
||||||
{ "charstyles", md_charstyles },
|
{ "charstyles", md_charstyles },
|
||||||
|
{ "citestyles", md_citestyles },
|
||||||
{ "custom", md_custom },
|
{ "custom", md_custom },
|
||||||
{ "documents", md_documents },
|
{ "documents", md_documents },
|
||||||
{ "elements", md_elements },
|
{ "elements", md_elements },
|
||||||
@ -500,6 +510,10 @@ void MenuDefinition::read(Lexer & lex)
|
|||||||
add(MenuItem(MenuItem::Branches));
|
add(MenuItem(MenuItem::Branches));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case md_citestyles:
|
||||||
|
add(MenuItem(MenuItem::CiteStyles));
|
||||||
|
break;
|
||||||
|
|
||||||
case md_optsubmenu:
|
case md_optsubmenu:
|
||||||
optional = true;
|
optional = true;
|
||||||
// fallback to md_submenu
|
// fallback to md_submenu
|
||||||
@ -1055,6 +1069,47 @@ void MenuDefinition::expandBranches(Buffer const * buf)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MenuDefinition::expandCiteStyles(BufferView const * bv)
|
||||||
|
{
|
||||||
|
if (!bv) {
|
||||||
|
add(MenuItem(MenuItem::Command,
|
||||||
|
qt_("No Document Open!"),
|
||||||
|
FuncRequest(LFUN_NOACTION)));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Inset const * inset = bv->cursor().nextInset();
|
||||||
|
if (!inset || inset->lyxCode() != CITE_CODE) {
|
||||||
|
add(MenuItem(MenuItem::Command,
|
||||||
|
qt_("No Citation in Scope!"),
|
||||||
|
FuncRequest(LFUN_NOACTION)));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
InsetCommand const * citinset =
|
||||||
|
static_cast<InsetCommand const *>(inset);
|
||||||
|
|
||||||
|
Buffer const * buf = &bv->buffer();
|
||||||
|
docstring key = citinset->getParam("key");
|
||||||
|
|
||||||
|
vector<CiteStyle> citeStyleList = citeStyles(buf->params().citeEngine());
|
||||||
|
vector<docstring> citeStrings =
|
||||||
|
buf->masterBibInfo().getCiteStrings(key, bv->buffer());
|
||||||
|
|
||||||
|
vector<docstring>::const_iterator cit = citeStrings.begin();
|
||||||
|
vector<docstring>::const_iterator end = citeStrings.end();
|
||||||
|
|
||||||
|
for (int ii = 1; cit != end; ++cit, ++ii) {
|
||||||
|
docstring label = *cit;
|
||||||
|
CitationStyle cs;
|
||||||
|
CiteStyle cst = citeStyleList[ii - 1];
|
||||||
|
cs.style = cst;
|
||||||
|
addWithStatusCheck(MenuItem(MenuItem::Command, toqstr(label),
|
||||||
|
FuncRequest(LFUN_NEXT_INSET_MODIFY,
|
||||||
|
"changetype " + from_utf8(citationStyleToString(cs)))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace anon
|
} // namespace anon
|
||||||
|
|
||||||
|
|
||||||
@ -1170,7 +1225,7 @@ struct Menus::Impl {
|
|||||||
ViewFormats, ExportFormats, UpdateFormats, Branches
|
ViewFormats, ExportFormats, UpdateFormats, Branches
|
||||||
*/
|
*/
|
||||||
void expand(MenuDefinition const & frommenu, MenuDefinition & tomenu,
|
void expand(MenuDefinition const & frommenu, MenuDefinition & tomenu,
|
||||||
Buffer const *) const;
|
BufferView const *) const;
|
||||||
|
|
||||||
/// Initialize specific MACOS X menubar
|
/// Initialize specific MACOS X menubar
|
||||||
void macxMenuBarInit(GuiView * view, QMenuBar * qmb);
|
void macxMenuBarInit(GuiView * view, QMenuBar * qmb);
|
||||||
@ -1273,13 +1328,14 @@ void Menus::Impl::macxMenuBarInit(GuiView * view, QMenuBar * qmb)
|
|||||||
|
|
||||||
|
|
||||||
void Menus::Impl::expand(MenuDefinition const & frommenu,
|
void Menus::Impl::expand(MenuDefinition const & frommenu,
|
||||||
MenuDefinition & tomenu, Buffer const * buf) const
|
MenuDefinition & tomenu, BufferView const * bv) const
|
||||||
{
|
{
|
||||||
if (!tomenu.empty())
|
if (!tomenu.empty())
|
||||||
tomenu.clear();
|
tomenu.clear();
|
||||||
|
|
||||||
for (MenuDefinition::const_iterator cit = frommenu.begin();
|
for (MenuDefinition::const_iterator cit = frommenu.begin();
|
||||||
cit != frommenu.end() ; ++cit) {
|
cit != frommenu.end() ; ++cit) {
|
||||||
|
Buffer const * buf = bv ? &bv->buffer() : 0;
|
||||||
switch (cit->kind()) {
|
switch (cit->kind()) {
|
||||||
case MenuItem::Lastfiles:
|
case MenuItem::Lastfiles:
|
||||||
tomenu.expandLastfiles();
|
tomenu.expandLastfiles();
|
||||||
@ -1332,6 +1388,10 @@ void Menus::Impl::expand(MenuDefinition const & frommenu,
|
|||||||
tomenu.expandBranches(buf);
|
tomenu.expandBranches(buf);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case MenuItem::CiteStyles:
|
||||||
|
tomenu.expandCiteStyles(bv);
|
||||||
|
break;
|
||||||
|
|
||||||
case MenuItem::Toc:
|
case MenuItem::Toc:
|
||||||
tomenu.expandToc(buf);
|
tomenu.expandToc(buf);
|
||||||
break;
|
break;
|
||||||
@ -1339,7 +1399,7 @@ void Menus::Impl::expand(MenuDefinition const & frommenu,
|
|||||||
case MenuItem::Submenu: {
|
case MenuItem::Submenu: {
|
||||||
MenuItem item(*cit);
|
MenuItem item(*cit);
|
||||||
item.setSubmenu(MenuDefinition(cit->submenuname()));
|
item.setSubmenu(MenuDefinition(cit->submenuname()));
|
||||||
expand(getMenu(cit->submenuname()), item.submenu(), buf);
|
expand(getMenu(cit->submenuname()), item.submenu(), bv);
|
||||||
tomenu.addWithStatusCheck(item);
|
tomenu.addWithStatusCheck(item);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -1488,10 +1548,10 @@ void Menus::fillMenuBar(QMenuBar * qmb, GuiView * view, bool initial)
|
|||||||
LYXERR(Debug::GUI, "menu bar entries " << d->menubar_.size());
|
LYXERR(Debug::GUI, "menu bar entries " << d->menubar_.size());
|
||||||
|
|
||||||
MenuDefinition menu;
|
MenuDefinition menu;
|
||||||
Buffer * buf = 0;
|
BufferView * bv = 0;
|
||||||
if (view)
|
if (view)
|
||||||
buf = view->buffer();
|
bv = view->view();
|
||||||
d->expand(d->menubar_, menu, buf);
|
d->expand(d->menubar_, menu, bv);
|
||||||
|
|
||||||
MenuDefinition::const_iterator m = menu.begin();
|
MenuDefinition::const_iterator m = menu.begin();
|
||||||
MenuDefinition::const_iterator end = menu.end();
|
MenuDefinition::const_iterator end = menu.end();
|
||||||
@ -1541,10 +1601,10 @@ void Menus::updateMenu(Menu * qmenu)
|
|||||||
}
|
}
|
||||||
|
|
||||||
MenuDefinition const & fromLyxMenu = d->getMenu(qmenu->d->name);
|
MenuDefinition const & fromLyxMenu = d->getMenu(qmenu->d->name);
|
||||||
Buffer * buf = 0;
|
BufferView * bv = 0;
|
||||||
if (qmenu->d->view)
|
if (qmenu->d->view)
|
||||||
buf = qmenu->d->view->buffer();
|
bv = qmenu->d->view->view();
|
||||||
d->expand(fromLyxMenu, *qmenu->d->top_level_menu, buf);
|
d->expand(fromLyxMenu, *qmenu->d->top_level_menu, bv);
|
||||||
qmenu->d->populate(*qmenu, *qmenu->d->top_level_menu);
|
qmenu->d->populate(*qmenu, *qmenu->d->top_level_menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -516,4 +516,10 @@ void InsetCitation::validate(LaTeXFeatures & features) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
docstring InsetCitation::contextMenu(BufferView const &, int, int) const
|
||||||
|
{
|
||||||
|
return from_ascii("context-citation");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace lyx
|
} // namespace lyx
|
||||||
|
@ -65,6 +65,8 @@ public:
|
|||||||
static std::string defaultCommand() { return "cite"; }
|
static std::string defaultCommand() { return "cite"; }
|
||||||
///
|
///
|
||||||
static bool isCompatibleCommand(std::string const & cmd);
|
static bool isCompatibleCommand(std::string const & cmd);
|
||||||
|
///
|
||||||
|
virtual docstring contextMenu(BufferView const & bv, int x, int y) const;
|
||||||
private:
|
private:
|
||||||
///
|
///
|
||||||
Inset * clone() const { return new InsetCitation(*this); }
|
Inset * clone() const { return new InsetCitation(*this); }
|
||||||
|
Loading…
Reference in New Issue
Block a user