Move some special code from menu frontend to backend.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1079 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jean-Marc Lasgouttes 2000-10-04 09:54:31 +00:00
parent ebfcf1c0e7
commit df13cd9f7c
6 changed files with 126 additions and 113 deletions

View File

@ -1,3 +1,18 @@
2000-10-04 Jean-Marc Lasgouttes <Jean-Marc.Lasgouttes@inria.fr>
* src/frontends/xforms/Menubar_pimpl.C (create_submenu): use
Menu::expand.
(add_lastfiles): removed.
(add_documents): removed.
(add_formats): removed.
* src/frontends/Menubar.C: remove useless "using" directive.
* src/MenuBackend.h: add a new MenuItem constructor.
* src/MenuBackend.[Ch] (Menu::expand): new method. Used in the
xforms frontend.
2000-10-04 Allan Rae <rae@lyx.org>
* lib/Makefile.am (listerrors):

View File

@ -21,10 +21,18 @@
#include "LyXAction.h"
#include "debug.h"
#include "gettext.h"
#include "lastfiles.h"
#include "bufferlist.h"
#include "exporter.h"
#include "support/filetools.h"
extern LyXAction lyxaction;
extern LastFiles * lastfiles;
extern BufferList bufferlist;
using std::endl;
using std::vector;
using std::pair;
// This is the global menu definition
MenuBackend menubackend;
@ -184,6 +192,83 @@ Menu & Menu::read(LyXLex & lex)
return *this;
}
void Menu::expand(Menu & tomenu, Buffer *buf) const
{
for (const_iterator cit = begin();
cit != end() ; ++cit) {
switch ((*cit).kind()) {
case MenuItem::Lastfiles: {
int ii = 1;
for (LastFiles::const_iterator lfit = lastfiles->begin();
lfit != lastfiles->end() && ii < 10;
++lfit, ++ii) {
string label = tostr(ii) + ". "
+ MakeDisplayPath((*lfit), 30)
+ '|' + tostr(ii);
int action = lyxaction.
getPseudoAction(LFUN_FILE_OPEN,
(*lfit));
tomenu.add(MenuItem(MenuItem::Command,
label, action));
}
}
break;
case MenuItem::Documents: {
vector<string> names = bufferlist.getFileNames();
if (names.empty()) {
tomenu.add(MenuItem(MenuItem::Command,
_("No Documents Open!"),
LFUN_NOACTION));
break;
}
for (vector<string>::const_iterator docit = names.begin();
docit != names.end() ; ++docit) {
int action =
lyxaction.getPseudoAction(LFUN_SWITCHBUFFER, *docit);
string label = MakeDisplayPath(*docit, 30);
tomenu.add(MenuItem(MenuItem::Command,
label, action));
}
}
break;
case MenuItem::ViewFormats:
case MenuItem::UpdateFormats:
case MenuItem::ExportFormats: {
vector<pair<string,string> > names;
kb_action action;
if ((*cit).kind() == MenuItem::ViewFormats) {
names = Exporter::GetViewableFormats(buf);
action = LFUN_PREVIEW;
} else if ((*cit).kind() == MenuItem::UpdateFormats) {
names = Exporter::GetViewableFormats(buf);
action = LFUN_UPDATE;
} else {
names = Exporter::GetExportableFormats(buf);
action = LFUN_EXPORT;
}
for (vector<pair<string,string> >::const_iterator fit = names.begin();
fit != names.end() ; ++fit) {
int action2 =
lyxaction.getPseudoAction(action,
(*fit).first);
string label = (*fit).second;
tomenu.add(MenuItem(MenuItem::Command,
label, action2));
}
}
break;
default:
tomenu.add(*cit);
}
}
}
void MenuBackend::read(LyXLex & lex)
{

View File

@ -23,6 +23,7 @@
#include <vector>
class LyXLex;
class Buffer;
///
class MenuItem {
@ -46,13 +47,13 @@ public:
///
References,
/** This is a list of viewable formats
typically for the Documents menu. */
typically for the File->View menu. */
ViewFormats,
/** This is a list of updatable formats
typically for the Documents menu. */
typically for the File->Update menu. */
UpdateFormats,
/** This is a list of exportable formats
typically for the Documents menu. */
typically for the File->Export menu. */
ExportFormats
};
/// Create a Command type MenuItem
@ -60,6 +61,13 @@ public:
string const & label = string(),
string const & command = string(),
bool optional = false);
MenuItem(Kind kind,
string const & label,
int action,
bool optional = false)
: kind_(kind), label_(label),
action_(action), submenu_(), optional_(optional) {}
/// The label of a given menuitem
string const label() const { return token(label_, '|', 0); }
///
@ -94,12 +102,18 @@ public:
///
typedef ItemList::const_iterator const_iterator;
///
explicit Menu(string const & name, bool mb = false)
explicit Menu(string const & name = string(), bool mb = false)
: menubar_(mb), name_(name) {}
///
Menu & add(MenuItem const &);
///
Menu & read(LyXLex &);
/// Expands some special entries of the menu
/** The entries with the following kind are exanded to a
sequence of Command MenuItems: Lastfiles, Documents,
ViewFormats, ExportFormats, UpdateFormats
*/
void expand(Menu & tomenu, Buffer *) const;
///
bool menubar() const { return menubar_; }
///

View File

@ -20,9 +20,6 @@
#include "Menubar.h"
#include "Menubar_pimpl.h"
using std::endl;
Menubar::Menubar(LyXView * o, MenuBackend const & md)
{
pimpl_ = new Pimpl(o, md);

View File

@ -14,22 +14,18 @@
#include <config.h>
#include <algorithm>
#include <cctype>
//#include <cctype>
#include "support/lstrings.h"
#include "support/filetools.h"
#include "support/LAssert.h"
#include "debug.h"
#include "LyXAction.h"
#include "lyxfunc.h"
#include "kbmap.h"
#include "bufferlist.h"
#include "lastfiles.h"
#include "buffer.h"
#include "LyXView.h"
#include "MenuBackend.h"
#include "Menubar_pimpl.h"
#include "exporter.h"
using std::pair;
using std::endl;
using std::vector;
using std::max;
@ -39,8 +35,6 @@ typedef vector<int>::size_type size_type;
extern kb_keymap * toplevel_keymap;
extern LyXAction lyxaction;
extern BufferList bufferlist;
extern LastFiles * lastfiles;
// Some constants
const int MENU_LABEL_SIZE = FL_NORMAL_SIZE;
@ -187,52 +181,6 @@ void Menubar::Pimpl::openByName(string const & name)
}
void Menubar::Pimpl::add_lastfiles(int menu, string const & extra_label)
{
int ii = 1;
for (LastFiles::const_iterator cit = lastfiles->begin();
cit != lastfiles->end() && ii < 10; ++cit, ++ii) {
int action =
lyxaction.getPseudoAction(LFUN_FILE_OPEN, (*cit));
string label = tostr(ii) + ". "
+ MakeDisplayPath((*cit),30)
+ "%x" + tostr(action) + "%h";
if ((cit + 1) == lastfiles->end())
label += extra_label;
string shortcut = tostr(ii) + "#" + tostr(ii);
lyxerr[Debug::GUI] << "shortcut is " << shortcut <<
endl;
fl_addtopup(menu, label.c_str(), shortcut.c_str());
}
}
void Menubar::Pimpl::add_documents(int menu, string const & extra_label)
{
vector<string> names = bufferlist.getFileNames();
if (names.empty()) {
fl_addtopup(menu,_("No Documents Open!%i"));
return;
}
for (vector<string>::const_iterator cit = names.begin();
cit != names.end() ; ++cit) {
int action =
lyxaction.getPseudoAction(LFUN_SWITCHBUFFER, *cit);
string label = MakeDisplayPath(*cit, 30)
+ "%x" + tostr(action);
if ((cit + 1) == names.end())
label += extra_label;
fl_addtopup(menu, label.c_str());
}
}
string limit_string_length(string const & str)
{
string::size_type const max_item_length = 45;
@ -497,28 +445,6 @@ void Menubar::Pimpl::add_references(int menu, string const & extra_label,
}
void Menubar::Pimpl::add_formats(int menu, string const & extra_label,
kb_action action, bool viewable)
{
vector<pair<string,string> > names =
viewable
? Exporter::GetViewableFormats(owner_->buffer())
: Exporter::GetExportableFormats(owner_->buffer());
for (vector<pair<string,string> >::const_iterator cit = names.begin();
cit != names.end() ; ++cit) {
int action2 =
lyxaction.getPseudoAction(action, (*cit).first);
string label = (*cit).second
+ "%x" + tostr(action2);
if ((cit + 1) == names.end())
label += extra_label;
fl_addtopup(menu, label.c_str());
}
}
int Menubar::Pimpl::create_submenu(Window win, LyXView * view,
string const & menu_name,
vector<int> & smn)
@ -528,7 +454,8 @@ int Menubar::Pimpl::create_submenu(Window win, LyXView * view,
<< menu_name << "'" << endl;
return -1;
}
Menu md = menubackend_->getMenu(menu_name);
Menu md = Menu();
menubackend_->getMenu(menu_name).expand(md, owner_->buffer());
int menu = fl_newpup(win);
fl_setpup_softedge(menu, true);
@ -657,14 +584,6 @@ int Menubar::Pimpl::create_submenu(Window win, LyXView * view,
// we just ignore it.
break;
case MenuItem::Documents:
add_documents(menu, extra_label);
break;
case MenuItem::Lastfiles:
add_lastfiles(menu, extra_label);
break;
case MenuItem::Toc:
add_toc(menu, extra_label, smn, win);
break;
@ -673,16 +592,13 @@ int Menubar::Pimpl::create_submenu(Window win, LyXView * view,
add_references(menu, extra_label, smn, win);
break;
case MenuItem::Documents:
case MenuItem::Lastfiles:
case MenuItem::ViewFormats:
add_formats(menu, extra_label, LFUN_PREVIEW, true);
break;
case MenuItem::UpdateFormats:
add_formats(menu, extra_label, LFUN_UPDATE, true);
break;
case MenuItem::ExportFormats:
add_formats(menu, extra_label, LFUN_EXPORT, false);
lyxerr << "Menubar::Pimpl::create_submenu: "
"this should not happen" << endl;
break;
}

View File

@ -29,8 +29,6 @@ class MenuBackend;
class MenuItem;
class Menu;
#include "debug.h"
/** The LyX GUI independent menubar class
The GUI interface is implemented in the corresponding Menubar_pimpl class.
*/
@ -48,18 +46,6 @@ public:
///
static void MenuCallback(FL_OBJECT *, long);
/** Add to "menu" the list of last opened files
(add "extra_label" to the last entry)
*/
void add_lastfiles(int menu, string const & extra_label);
/** Add to "menu" the list of opened documents
(add "extra_label" to the last entry)
*/
void add_documents(int menu, string const & extra_label);
/// Add to "menu" the list of exportable/viewable formats
/// (add "extra_label" to the last entry)
void add_formats(int menu, string const & extra_label,
kb_action action, bool viewable);
///
void add_toc(int menu, string const & extra_label,
std::vector<int> & smn, Window win);