2003-08-23 00:17:00 +00:00
|
|
|
|
// -*- C++ -*-
|
|
|
|
|
/**
|
|
|
|
|
* \file MenuBackend.h
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
* \author Jean-Marc Lasgouttes
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
2000-07-24 13:53:19 +00:00
|
|
|
|
|
|
|
|
|
#ifndef MENUBACKEND_H
|
|
|
|
|
#define MENUBACKEND_H
|
|
|
|
|
|
2003-09-21 18:57:15 +00:00
|
|
|
|
#include "FuncStatus.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "FuncRequest.h"
|
2003-09-21 18:57:15 +00:00
|
|
|
|
|
2002-07-23 22:42:12 +00:00
|
|
|
|
#include <boost/shared_ptr.hpp>
|
2000-07-24 13:53:19 +00:00
|
|
|
|
|
2003-02-13 16:53:15 +00:00
|
|
|
|
#include <vector>
|
2007-10-11 15:14:11 +00:00
|
|
|
|
#include <stack>
|
2003-02-13 16:53:15 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
|
2007-04-26 11:30:54 +00:00
|
|
|
|
class Lexer;
|
2006-09-29 21:40:56 +00:00
|
|
|
|
class Buffer;
|
2002-07-23 22:42:12 +00:00
|
|
|
|
class Menu;
|
2000-07-24 13:53:19 +00:00
|
|
|
|
|
2000-07-24 21:49:58 +00:00
|
|
|
|
///
|
2000-07-24 13:53:19 +00:00
|
|
|
|
class MenuItem {
|
|
|
|
|
public:
|
2000-07-24 21:49:58 +00:00
|
|
|
|
/// The type of elements that can be in a menu
|
|
|
|
|
enum Kind {
|
|
|
|
|
///
|
|
|
|
|
Command,
|
|
|
|
|
///
|
|
|
|
|
Submenu,
|
|
|
|
|
///
|
|
|
|
|
Separator,
|
|
|
|
|
/** This is the list of last opened file,
|
|
|
|
|
typically for the File menu. */
|
|
|
|
|
Lastfiles,
|
|
|
|
|
/** This is the list of opened Documents,
|
|
|
|
|
typically for the Documents menu. */
|
2000-08-30 03:40:51 +00:00
|
|
|
|
Documents,
|
2006-11-01 15:55:17 +00:00
|
|
|
|
/** This is the bookmarks */
|
|
|
|
|
Bookmarks,
|
2000-08-31 11:51:59 +00:00
|
|
|
|
///
|
|
|
|
|
Toc,
|
2000-08-30 03:40:51 +00:00
|
|
|
|
/** This is a list of viewable formats
|
2000-10-04 09:54:31 +00:00
|
|
|
|
typically for the File->View menu. */
|
2000-08-30 03:40:51 +00:00
|
|
|
|
ViewFormats,
|
|
|
|
|
/** This is a list of updatable formats
|
2000-10-04 09:54:31 +00:00
|
|
|
|
typically for the File->Update menu. */
|
2000-08-30 03:40:51 +00:00
|
|
|
|
UpdateFormats,
|
|
|
|
|
/** This is a list of exportable formats
|
2000-10-04 09:54:31 +00:00
|
|
|
|
typically for the File->Export menu. */
|
2000-11-06 11:20:22 +00:00
|
|
|
|
ExportFormats,
|
|
|
|
|
/** This is a list of importable formats
|
|
|
|
|
typically for the File->Export menu. */
|
2001-05-04 10:36:36 +00:00
|
|
|
|
ImportFormats,
|
2004-01-31 15:30:24 +00:00
|
|
|
|
/** This is the list of elements available
|
2003-11-12 14:38:26 +00:00
|
|
|
|
* for insertion into document. */
|
|
|
|
|
CharStyles,
|
2007-08-24 12:45:40 +00:00
|
|
|
|
/** This is the list of user-configurable
|
|
|
|
|
insets to insert into document */
|
|
|
|
|
Custom,
|
2007-09-06 15:37:34 +00:00
|
|
|
|
/** This is the list of XML elements to
|
|
|
|
|
insert into the document */
|
|
|
|
|
Elements,
|
2001-05-04 10:36:36 +00:00
|
|
|
|
/** This is the list of floats that we can
|
|
|
|
|
insert a list for. */
|
|
|
|
|
FloatListInsert,
|
|
|
|
|
/** This is the list of floats that we can
|
|
|
|
|
insert. */
|
2003-06-17 15:33:49 +00:00
|
|
|
|
FloatInsert,
|
|
|
|
|
/** This is the list of selections that can
|
|
|
|
|
be pasted. */
|
2003-08-17 11:28:23 +00:00
|
|
|
|
PasteRecent,
|
2006-11-02 16:01:36 +00:00
|
|
|
|
/** toolbars */
|
|
|
|
|
Toolbars,
|
2003-08-17 11:28:23 +00:00
|
|
|
|
/** Available branches in document */
|
|
|
|
|
Branches
|
2000-07-24 13:53:19 +00:00
|
|
|
|
};
|
2003-09-21 18:57:15 +00:00
|
|
|
|
|
|
|
|
|
explicit MenuItem(Kind kind);
|
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
|
MenuItem(Kind kind,
|
2006-10-21 00:16:43 +00:00
|
|
|
|
docstring const & label,
|
|
|
|
|
docstring const & submenu = docstring(),
|
2000-07-25 10:46:18 +00:00
|
|
|
|
bool optional = false);
|
2003-09-21 18:57:15 +00:00
|
|
|
|
|
2000-10-04 09:54:31 +00:00
|
|
|
|
MenuItem(Kind kind,
|
2006-10-21 00:16:43 +00:00
|
|
|
|
docstring const & label,
|
2003-09-21 18:57:15 +00:00
|
|
|
|
FuncRequest const & func,
|
2002-08-21 06:32:10 +00:00
|
|
|
|
bool optional = false);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-07-23 22:42:12 +00:00
|
|
|
|
/// This one is just to please boost::shared_ptr<>
|
|
|
|
|
~MenuItem();
|
2000-07-24 21:49:58 +00:00
|
|
|
|
/// The label of a given menuitem
|
2006-10-21 00:16:43 +00:00
|
|
|
|
docstring const label() const;
|
2000-11-03 13:26:55 +00:00
|
|
|
|
/// The keyboard shortcut (usually underlined in the entry)
|
2006-10-21 00:16:43 +00:00
|
|
|
|
docstring const shortcut() const;
|
2000-11-03 13:26:55 +00:00
|
|
|
|
/// The complete label, with label and shortcut separated by a '|'
|
2006-10-21 00:16:43 +00:00
|
|
|
|
docstring const fulllabel() const { return label_;}
|
2000-07-24 21:49:58 +00:00
|
|
|
|
/// The kind of entry
|
2002-03-21 17:27:08 +00:00
|
|
|
|
Kind kind() const { return kind_; }
|
2000-07-24 21:49:58 +00:00
|
|
|
|
/// the action (if relevant)
|
2003-09-21 18:57:15 +00:00
|
|
|
|
FuncRequest const & func() const { return func_; }
|
2000-07-25 10:46:18 +00:00
|
|
|
|
/// returns true if the entry should be ommited when disabled
|
|
|
|
|
bool optional() const { return optional_; }
|
2003-02-15 21:03:40 +00:00
|
|
|
|
/// returns the status of the lfun associated with this entry
|
2003-03-04 09:27:27 +00:00
|
|
|
|
FuncStatus const & status() const { return status_; }
|
2003-02-15 21:03:40 +00:00
|
|
|
|
/// returns the status of the lfun associated with this entry
|
2003-03-04 09:27:27 +00:00
|
|
|
|
FuncStatus & status() { return status_; }
|
2003-02-15 21:03:40 +00:00
|
|
|
|
/// returns the status of the lfun associated with this entry
|
2003-03-04 09:27:27 +00:00
|
|
|
|
void status(FuncStatus const & status) { status_ = status; }
|
2007-01-04 17:10:24 +00:00
|
|
|
|
/**
|
2007-05-28 22:27:45 +00:00
|
|
|
|
* returns the binding associated to this action.
|
2007-01-04 17:10:24 +00:00
|
|
|
|
* Use the native UI format when \c forgui is true.
|
|
|
|
|
*/
|
|
|
|
|
docstring const binding(bool forgui) const;
|
2002-07-24 22:32:03 +00:00
|
|
|
|
/// the description of the submenu (if relevant)
|
2006-10-21 00:16:43 +00:00
|
|
|
|
docstring const & submenuname() const { return submenuname_; }
|
2003-02-15 21:03:40 +00:00
|
|
|
|
/// set the description of the submenu
|
2006-10-21 00:16:43 +00:00
|
|
|
|
void submenuname(docstring const & name) { submenuname_ = name; }
|
2002-07-24 22:32:03 +00:00
|
|
|
|
///
|
|
|
|
|
Menu * submenu() const { return submenu_.get(); }
|
2002-07-23 22:42:12 +00:00
|
|
|
|
///
|
2002-08-21 06:32:10 +00:00
|
|
|
|
void submenu(Menu * menu);
|
2002-07-24 22:32:03 +00:00
|
|
|
|
|
2000-07-24 13:53:19 +00:00
|
|
|
|
private:
|
2002-07-24 22:32:03 +00:00
|
|
|
|
//friend class MenuBackend;
|
2000-07-24 21:49:58 +00:00
|
|
|
|
///
|
2000-07-24 13:53:19 +00:00
|
|
|
|
Kind kind_;
|
2000-07-24 21:49:58 +00:00
|
|
|
|
///
|
2006-10-21 00:16:43 +00:00
|
|
|
|
docstring label_;
|
2000-07-24 21:49:58 +00:00
|
|
|
|
///
|
2003-09-21 18:57:15 +00:00
|
|
|
|
FuncRequest func_;
|
2000-07-24 21:49:58 +00:00
|
|
|
|
///
|
2006-10-21 00:16:43 +00:00
|
|
|
|
docstring submenuname_;
|
2000-07-25 10:46:18 +00:00
|
|
|
|
///
|
|
|
|
|
bool optional_;
|
2002-07-23 22:42:12 +00:00
|
|
|
|
///
|
2003-02-15 21:03:40 +00:00
|
|
|
|
FuncStatus status_;
|
|
|
|
|
///
|
2002-07-23 22:42:12 +00:00
|
|
|
|
boost::shared_ptr<Menu> submenu_;
|
2000-07-24 13:53:19 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2000-07-24 21:49:58 +00:00
|
|
|
|
///
|
2000-07-24 13:53:19 +00:00
|
|
|
|
class Menu {
|
|
|
|
|
public:
|
2000-07-24 21:49:58 +00:00
|
|
|
|
///
|
2000-07-24 13:53:19 +00:00
|
|
|
|
typedef std::vector<MenuItem> ItemList;
|
2000-07-24 21:49:58 +00:00
|
|
|
|
///
|
2000-07-24 13:53:19 +00:00
|
|
|
|
typedef ItemList::const_iterator const_iterator;
|
2000-07-24 21:49:58 +00:00
|
|
|
|
///
|
2002-07-24 22:32:03 +00:00
|
|
|
|
typedef ItemList::size_type size_type;
|
|
|
|
|
///
|
2006-10-21 00:16:43 +00:00
|
|
|
|
explicit Menu(docstring const & name = docstring())
|
2002-07-20 21:50:05 +00:00
|
|
|
|
: name_(name) {}
|
2006-09-29 21:40:56 +00:00
|
|
|
|
/// Add the menu item unconditionally
|
|
|
|
|
Menu & add(MenuItem const &);
|
|
|
|
|
/// Checks the associated FuncRequest status before adding the
|
|
|
|
|
/// menu item.
|
|
|
|
|
Menu & addWithStatusCheck(MenuItem const &);
|
2000-07-24 21:49:58 +00:00
|
|
|
|
///
|
2007-04-26 11:30:54 +00:00
|
|
|
|
Menu & read(Lexer &);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
///
|
2006-10-21 00:16:43 +00:00
|
|
|
|
docstring const & name() const { return name_; }
|
2000-07-24 21:49:58 +00:00
|
|
|
|
///
|
2000-07-24 13:53:19 +00:00
|
|
|
|
bool empty() const { return items_.empty(); }
|
2006-03-15 15:07:20 +00:00
|
|
|
|
/// Clear the menu content.
|
|
|
|
|
void clear() { items_.clear(); }
|
2000-08-31 11:51:59 +00:00
|
|
|
|
///
|
|
|
|
|
ItemList::size_type size() const { return items_.size(); }
|
2000-12-06 13:41:44 +00:00
|
|
|
|
///
|
2004-08-14 18:06:10 +00:00
|
|
|
|
MenuItem const & operator[](size_type) const;
|
|
|
|
|
///
|
|
|
|
|
bool hasFunc(FuncRequest const &) const;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
///
|
|
|
|
|
const_iterator begin() const {
|
|
|
|
|
return items_.begin();
|
|
|
|
|
}
|
|
|
|
|
///
|
|
|
|
|
const_iterator end() const {
|
|
|
|
|
return items_.end();
|
|
|
|
|
}
|
2000-11-03 13:26:55 +00:00
|
|
|
|
|
|
|
|
|
// Check whether the menu shortcuts are unique
|
|
|
|
|
void checkShortcuts() const;
|
2007-10-11 15:14:11 +00:00
|
|
|
|
|
|
|
|
|
// search for func in this menu iteratively, and put menu
|
|
|
|
|
// names in a stack.
|
|
|
|
|
bool searchFunc(FuncRequest & func, std::stack<docstring> & names);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-07-24 13:53:19 +00:00
|
|
|
|
private:
|
2003-02-15 21:03:40 +00:00
|
|
|
|
friend class MenuBackend;
|
2000-07-24 13:53:19 +00:00
|
|
|
|
///
|
|
|
|
|
ItemList items_;
|
|
|
|
|
///
|
2006-10-21 00:16:43 +00:00
|
|
|
|
docstring name_;
|
2000-07-24 13:53:19 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2000-07-24 21:49:58 +00:00
|
|
|
|
///
|
2000-07-24 13:53:19 +00:00
|
|
|
|
class MenuBackend {
|
|
|
|
|
public:
|
|
|
|
|
///
|
|
|
|
|
typedef std::vector<Menu> MenuList;
|
|
|
|
|
///
|
|
|
|
|
typedef MenuList::const_iterator const_iterator;
|
|
|
|
|
///
|
2004-01-31 15:30:24 +00:00
|
|
|
|
typedef MenuList::iterator iterator;
|
|
|
|
|
///
|
2007-01-03 11:59:10 +00:00
|
|
|
|
MenuBackend() {}
|
2004-08-14 18:06:10 +00:00
|
|
|
|
///
|
2007-04-26 11:30:54 +00:00
|
|
|
|
void read(Lexer &);
|
2000-07-24 13:53:19 +00:00
|
|
|
|
///
|
|
|
|
|
void add(Menu const &);
|
|
|
|
|
///
|
2006-10-21 00:16:43 +00:00
|
|
|
|
bool hasMenu(docstring const &) const;
|
2000-07-24 13:53:19 +00:00
|
|
|
|
///
|
2006-10-21 00:16:43 +00:00
|
|
|
|
Menu & getMenu(docstring const &);
|
2000-07-26 14:08:09 +00:00
|
|
|
|
///
|
2006-10-21 00:16:43 +00:00
|
|
|
|
Menu const & getMenu(docstring const &) const;
|
2002-07-20 21:50:05 +00:00
|
|
|
|
///
|
|
|
|
|
Menu const & getMenubar() const;
|
|
|
|
|
///
|
2000-07-24 13:53:19 +00:00
|
|
|
|
bool empty() const { return menulist_.empty(); }
|
2004-08-14 18:06:10 +00:00
|
|
|
|
/** This defines a menu whose entries list the FuncRequests
|
2007-01-03 11:59:10 +00:00
|
|
|
|
that will be removed by expand() in other menus. This is
|
|
|
|
|
used by the Qt/Mac code
|
2004-08-14 18:06:10 +00:00
|
|
|
|
*/
|
2007-01-03 11:59:10 +00:00
|
|
|
|
void specialMenu(Menu const &);
|
|
|
|
|
///
|
|
|
|
|
Menu const & specialMenu() { return specialmenu_; }
|
|
|
|
|
|
2002-07-23 22:42:12 +00:00
|
|
|
|
/// Expands some special entries of the menu
|
|
|
|
|
/** The entries with the following kind are expanded to a
|
|
|
|
|
sequence of Command MenuItems: Lastfiles, Documents,
|
2003-08-17 11:28:23 +00:00
|
|
|
|
ViewFormats, ExportFormats, UpdateFormats, Branches
|
2002-07-23 22:42:12 +00:00
|
|
|
|
*/
|
|
|
|
|
void expand(Menu const & frommenu, Menu & tomenu,
|
2006-09-29 21:40:56 +00:00
|
|
|
|
Buffer const *) const;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
///
|
|
|
|
|
const_iterator begin() const {
|
|
|
|
|
return menulist_.begin();
|
|
|
|
|
}
|
|
|
|
|
///
|
2004-01-31 15:30:24 +00:00
|
|
|
|
iterator begin() {
|
|
|
|
|
return menulist_.begin();
|
|
|
|
|
}
|
|
|
|
|
///
|
2002-03-21 17:27:08 +00:00
|
|
|
|
const_iterator end() const {
|
|
|
|
|
return menulist_.end();
|
|
|
|
|
}
|
2004-01-31 15:30:24 +00:00
|
|
|
|
///
|
|
|
|
|
iterator end() {
|
|
|
|
|
return menulist_.end();
|
|
|
|
|
}
|
2000-07-24 13:53:19 +00:00
|
|
|
|
private:
|
|
|
|
|
///
|
|
|
|
|
MenuList menulist_;
|
2002-07-20 21:50:05 +00:00
|
|
|
|
///
|
|
|
|
|
Menu menubar_;
|
2004-08-14 18:06:10 +00:00
|
|
|
|
///
|
2007-01-03 11:59:10 +00:00
|
|
|
|
Menu specialmenu_;
|
2000-07-24 13:53:19 +00:00
|
|
|
|
};
|
|
|
|
|
|
2000-07-24 21:49:58 +00:00
|
|
|
|
///
|
2000-07-24 13:53:19 +00:00
|
|
|
|
extern MenuBackend menubackend;
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
} // namespace lyx
|
|
|
|
|
|
2000-07-24 13:53:19 +00:00
|
|
|
|
#endif /* MENUBACKEND_H */
|