#include "LyXRC.h"
#include "lyxfind.h"
#include "Paragraph.h"
+#include "ParagraphParameters.h"
#include "ParIterator.h"
#include "Session.h"
#include "SpellChecker.h"
#include "TextClass.h"
+#include "Text.h"
#include "TocBackend.h"
#include "Toolbars.h"
#include "WordLangTuple.h"
Captions,
/** This is the list of captions available
in the InsetCaption context menu. */
- SwitchCaptions
+ SwitchCaptions,
+ /** Commands to separate environments. */
+ EnvironmentSeparators
};
explicit MenuItem(Kind kind) : kind_(kind), optional_(false) {}
void expandLanguageSelector(Buffer const * buf);
void expandArguments(BufferView const *, bool switcharg = false);
void expandCaptions(Buffer const * buf, bool switchcap = false);
+ void expandEnvironmentSeparators(BufferView const *);
///
ItemList items_;
///
md_arguments,
md_switcharguments,
md_captions,
- md_switchcaptions
+ md_switchcaptions,
+ md_env_separators
};
LexerKeyword menutags[] = {
{ "documents", md_documents },
{ "elements", md_elements },
{ "end", md_endmenu },
+ { "environmentseparators", md_env_separators },
{ "exportformats", md_exportformats },
{ "floatinsert", md_floatinsert },
{ "floatlistinsert", md_floatlistinsert },
add(MenuItem(MenuItem::SwitchCaptions));
break;
+ case md_env_separators:
+ add(MenuItem(MenuItem::EnvironmentSeparators));
+ break;
+
case md_optsubmenu:
case md_submenu: {
lex.next(true);
vector<docstring> const keys = getVectorFromString(key);
vector<CitationStyle> const citeStyleList = buf->params().citeStyles();
+ static const size_t max_length = 40;
vector<docstring> citeStrings =
buf->masterBibInfo().getCiteStrings(keys, citeStyleList, bv->buffer(),
- false, before, after, from_utf8("dialog"));
+ before, after, from_utf8("dialog"), max_length);
vector<docstring>::const_iterator cit = citeStrings.begin();
vector<docstring>::const_iterator end = citeStrings.end();
}
}
+
+void MenuDefinition::expandEnvironmentSeparators(BufferView const * bv)
+{
+ if (!bv)
+ return;
+ Text const * text = bv->cursor().text();
+ // no paragraphs and no separators exist in math
+ if (!text)
+ return;
+
+ pit_type pit = bv->cursor().selBegin().pit();
+ Paragraph const & par = text->getPar(pit);
+ docstring const curlayout = par.layout().name();
+ docstring outerlayout;
+ depth_type current_depth = par.params().depth();
+ // check if we have an environment in our nesting hierarchy
+ Paragraph cpar = par;
+ while (true) {
+ if (pit == 0 || cpar.params().depth() == 0)
+ break;
+ --pit;
+ cpar = text->getPar(pit);
+ if (cpar.params().depth() < current_depth
+ && cpar.layout().isEnvironment()) {
+ outerlayout = cpar.layout().name();
+ current_depth = cpar.params().depth();
+ }
+ }
+ if (par.layout().isEnvironment()) {
+ docstring const label =
+ bformat(_("Start New Environment (%1$s)"),
+ translateIfPossible(curlayout));
+ add(MenuItem(MenuItem::Command, toqstr(label),
+ FuncRequest(LFUN_ENVIRONMENT_SPLIT)));
+ }
+ if (!outerlayout.empty()) {
+ docstring const label =
+ bformat(_("Start New Parent Environment (%1$s)"),
+ translateIfPossible(outerlayout));
+ add(MenuItem(MenuItem::Command, toqstr(label),
+ FuncRequest(LFUN_ENVIRONMENT_SPLIT,
+ from_ascii("outer"))));
+ }
+}
+
} // namespace anon
/** The entries with the following kind are expanded to a
sequence of Command MenuItems: Lastfiles, Documents,
ViewFormats, ExportFormats, UpdateFormats, Branches,
- Indices, Arguments, SwitchArguments, Captions, SwitchCaptions
+ Indices, Arguments, SwitchArguments, Captions, SwitchCaptions,
+ EnvironmentSeparators
*/
void expand(MenuDefinition const & frommenu, MenuDefinition & tomenu,
BufferView const *) const;
QAction::AboutRole},
{LFUN_DIALOG_SHOW, "prefs", "Preferences",
QAction::PreferencesRole},
- /* {LFUN_RECONFIGURE, "", "Reconfigure",
- QAction::ApplicationSpecificRole}, */
+#if !(defined(QT_MAC_USE_COCOA) || (QT_VERSION >= 0x050000))
+ /* This doesn't work with Cocoa. */
+ {LFUN_RECONFIGURE, "", "Reconfigure",
+ QAction::ApplicationSpecificRole},
+#endif
{LFUN_LYX_QUIT, "", "Quit LyX", QAction::QuitRole}
};
const size_t num_entries = sizeof(entries) / sizeof(entries[0]);
MenuDefinition::const_iterator cit = mac_special_menu_.begin();
MenuDefinition::const_iterator end = mac_special_menu_.end();
for (size_t i = 0 ; cit != end ; ++cit, ++i) {
-#if defined(QT_MAC_USE_COCOA) && (QT_MAC_USE_COCOA > 0)
- if (first_call || entries[i].role != QAction::ApplicationSpecificRole) {
- Action * action = new Action(QIcon(), cit->label(),
- cit->func(), QString(), qMenu);
- action->setMenuRole(entries[i].role);
- qMenu->addAction(action);
- }
-#else
Action * action = new Action(QIcon(), cit->label(),
cit->func(), QString(), qMenu);
action->setMenuRole(entries[i].role);
qMenu->addAction(action);
-#endif
}
}
tomenu.expandCaptions(buf, true);
break;
+ case MenuItem::EnvironmentSeparators:
+ tomenu.expandEnvironmentSeparators(bv);
+ break;
+
case MenuItem::Submenu: {
MenuItem item(*cit);
item.setSubmenu(MenuDefinition(cit->submenuname()));
Menu * menu = new Menu(view, m->submenuname(), true);
menu->setTitle(label(*m));
+
+#if defined(Q_WS_MACX) && (defined(QT_MAC_USE_COCOA) || (QT_VERSION >= 0x050000))
+ // On Mac OS with QT/cocoa, the menu is not displayed if there is no action
+ // so we create a temporary one here
+ QAction * action = new QAction(menu);
+ menu->addAction(action);
+#endif
+
qmb->addMenu(menu);
d->name_map_[view][name] = menu;