2003-09-21 Lars Gullik Bjønnes <larsbj@gullik.net>
+ * toc.C (action): return a FuncRequest, simplify
+
+ * lyxfunc.C (processKeySym): adjust
+ (getStatus): delete version that takes an int.
+ (getStatus): adjust
+ (dispatch): delete version that takes action as int
+ (dispatch): adjust
+ (sendDispatchMessage): simplify and adjust
+
+ * funcrequest.C (getArg): take unsigned int as arg
+
+ * ToolbarBackend.C (read): adjust
+ (add): delete version that takes func as a string.
+ (getIton): take a FuncRequest as arg
+
+ * MenuBackend.h (MenuItem): store a FuncRequest instead of an int
+ action.
+
+ * MenuBackend.C (MenuItem): add a new construct that only takes a
+ Kind, simplify the constructor use for submenus.
+ (add): adjust
+ (expandLastfiles): adjust
+ (expandDocuments): adjust
+ (expandFormats): adjust
+ (expandFloatListInsert): adjust
+ (expandFloatInsert): adjust
+ (expandToc2,expandToc,expandPasteRecent,expandBranches): adjust
+
+ * LyXAction.h: remove typdefs pseudo_map, arg_item and arg_map.
+ Remove class variables lyx_pseudo_map and lyx_arg_map
+
+ * LyXAction.C (searchActionArg): delete function
+ (getPseudoAction): delete function
+ (retrieveActionArg): delete function
+ (LookupFunc): make it return kb_action, simplify.
+ (getActionName): simplify
+
* factory.C (createInset): fix new bug
2003-09-19 Angus Leeming <leeming@lyx.org>
}
-int LyXAction::searchActionArg(kb_action action, string const & arg) const
-{
- arg_map::const_iterator pit = lyx_arg_map.find(action);
-
- if (pit == lyx_arg_map.end()) {
- lyxerr[Debug::ACTION] << "Action " << action
- << " does not have any pseudo actions."
- << endl;
- return LFUN_UNKNOWN_ACTION;
- }
-
- arg_item::const_iterator aci = pit->second.find(arg);
-
- if (aci == pit->second.end()) {
- lyxerr[Debug::ACTION]
- << "Action " << action
- << "does not have any pseudoactions with arg "
- << arg << endl;
- return LFUN_UNKNOWN_ACTION;
- }
-
- lyxerr[Debug::ACTION] << "Pseudoaction exists["
- << action << '|'
- << arg << "] = " << aci->second << endl;
-
- return aci->second;
-}
-
-
-int LyXAction::getPseudoAction(kb_action action, string const & arg)
-{
- int const psdaction = searchActionArg(action, arg);
-
- if (isPseudoAction(psdaction)) return psdaction;
-
- static unsigned int pseudo_counter = LFUN_LASTACTION;
-
- // Create new pseudo action.
- lyx_pseudo_map[++pseudo_counter] = FuncRequest(0, action, arg);
-
- // First ensure that the action is in lyx_arg_map;
- lyx_arg_map[action];
- // get the arg_item map
- arg_map::iterator ami = lyx_arg_map.find(action);
- // put the new pseudo function in it
- ami->second[arg] = pseudo_counter;
-
- lyxerr[Debug::ACTION] << "Creating new pseudoaction "
- << pseudo_counter << " for [" << action
- << '|' << arg << "]\n";
-
- return pseudo_counter;
-}
-
-
-FuncRequest LyXAction::retrieveActionArg(int pseudo) const
-{
- if (!isPseudoAction(pseudo))
- return FuncRequest(static_cast<kb_action>(pseudo));
-
- pseudo_map::const_iterator pit = lyx_pseudo_map.find(pseudo);
-
- if (pit != lyx_pseudo_map.end()) {
- lyxerr[Debug::ACTION] << "Found the pseudoaction: ["
- << pit->second.action << '|'
- << pit->second.argument << "]" << endl;
- return pit->second;
- } else {
- lyxerr << "Lyx Error: Unrecognized pseudo-action "
- << pseudo << endl;
- return FuncRequest(LFUN_UNKNOWN_ACTION);
- }
-}
-
-
// Returns an action tag from a string.
-int LyXAction::LookupFunc(string const & func)
+kb_action LyXAction::LookupFunc(string const & func)
{
string const func2 = trim(func);
if (func2.empty()) return LFUN_NOACTION;
func_map::const_iterator fit = lyx_func_map.find(actstr);
- if (!argstr.empty() && fit != lyx_func_map.end()) {
- // might be pseudo (or create one)
- return getPseudoAction(fit->second, argstr);
- }
-
return fit != lyx_func_map.end() ? fit->second : LFUN_UNKNOWN_ACTION;
}
string const LyXAction::getActionName(int action) const
{
- FuncRequest ev = retrieveActionArg(action);
- if (!ev.argument.empty())
- ev.argument.insert(string::size_type(0), 1, ' ');
-
- info_map::const_iterator const it = lyx_info_map.find(ev.action);
-
+ info_map::const_iterator const it = lyx_info_map.find(kb_action(action));
if (it != lyx_info_map.end())
- return it->second.name + ev.argument;
+ return it->second.name;
return string();
}
typedef std::map<string, kb_action> func_map;
/// type for map between an action and its info
typedef std::map<kb_action, func_info> info_map;
- /// type for a map between a pseudo-action and its stored action/arg
- typedef std::map<unsigned int, FuncRequest> pseudo_map;
- /// map from argument to pseudo-action
- typedef std::map<string, unsigned int> arg_item;
- /// map from an action to all its dependent pseudo-actions
- typedef std::map<kb_action, arg_item> arg_map;
/// possible "permissions" for an action
enum func_attrib {
* If you include arguments in func_name, a new pseudoaction
* will be created if needed.
*/
- int LookupFunc(string const & func_name);
-
- /// Returns a pseudo-action given an action and its argument.
- int getPseudoAction(kb_action action, string const & arg);
-
- /**
- * Given a pseudo-action, return the real action and
- * associated argument
- */
- FuncRequest retrieveActionArg(int pseudo) const;
-
- /// Search for an existent pseudoaction, return -1 if it doesn't exist.
- int searchActionArg(kb_action action, string const & arg) const;
+ kb_action LookupFunc(string const & func_name);
/// Return the name (and argument) associated with the given (pseudo) action
string const getActionName(int action) const;
* command attributes (ro)
*/
info_map lyx_info_map;
-
- /**
- * A mapping from the automatically created pseudo action number
- * to the real action and its argument.
- */
- pseudo_map lyx_pseudo_map;
-
- /**
- * A (multi) mapping from the lyx action to all the generated
- * pseudofuncs and the arguments the action should use.
- */
- arg_map lyx_arg_map;
};
/// singleton instance
MenuBackend menubackend;
+MenuItem::MenuItem(Kind kind)
+ : kind_(kind), optional_(false)
+{}
+
+
MenuItem::MenuItem(Kind kind, string const & label,
- string const & command, bool optional)
- : kind_(kind), label_(label), optional_(optional)
+ string const & submenu, bool optional)
+ : kind_(kind), label_(label),
+ submenuname_(submenu), optional_(optional)
{
- switch (kind) {
- case Separator:
- case Documents:
- case Lastfiles:
- case Toc:
- case ViewFormats:
- case UpdateFormats:
- case ExportFormats:
- case ImportFormats:
- case FloatListInsert:
- case FloatInsert:
- case PasteRecent:
- case Branches:
- break;
- case Command:
- action_ = lyxaction.LookupFunc(command);
-
- if (action_ == LFUN_UNKNOWN_ACTION) {
- lyxerr << "MenuItem(): LyX command `"
- << command << "' does not exist." << endl;
- }
- if (optional_)
- lyxerr[Debug::GUI] << "Optional item "
- << command << endl;
- break;
- case Submenu:
- submenuname_ = command;
- break;
- }
+ BOOST_ASSERT(kind == Submenu);
}
-MenuItem::MenuItem(Kind kind, string const & label, int action, bool optional)
- : kind_(kind), label_(label), action_(action), submenuname_(),
- optional_(optional)
+MenuItem::MenuItem(Kind kind, string const & label,
+ FuncRequest const & func, bool optional)
+ : kind_(kind), label_(label), func_(func), optional_(optional)
{}
return token(label_, '|', 1);
}
+
string const MenuItem::binding() const
{
if (kind_ != Command)
// Get the keys bound to this action, but keep only the
// first one later
- string bindings = toplevel_keymap->findbinding(action_);
+ string bindings = toplevel_keymap->findbinding(func_.action);
if (!bindings.empty()) {
return bindings.substr(1, bindings.find(']') - 1);
case MenuItem::Command:
{
FuncStatus status =
- view->getLyXFunc().getStatus(i.action());
+ view->getLyXFunc().getStatus(i.func());
if (status.unknown()
|| (status.disabled() && i.optional()))
break;
string const name = _(lex.getString());
lex.next(true);
string const command = lex.getString();
- add(MenuItem(MenuItem::Command, name,
- command, optional));
+ string::size_type sp = command.find(' ');
+ if (sp != string::npos) {
+ string const cmd = command.substr(0, sp);
+ string const arg =command.substr(sp + 1,
+ string::npos);
+ kb_action act = lyxaction.LookupFunc(cmd);
+ add(MenuItem(MenuItem::Command, name,
+ FuncRequest(act, arg), optional));
+ } else {
+ kb_action act = lyxaction.LookupFunc(command);
+ add(MenuItem(MenuItem::Command, name,
+ FuncRequest(act), optional));
+ }
+
optional = false;
break;
}
string const label = tostr(ii) + ". "
+ MakeDisplayPath((*lfit), 30)
+ '|' + tostr(ii);
- int const action = lyxaction.
- getPseudoAction(LFUN_FILE_OPEN,
- (*lfit));
- tomenu.add(MenuItem(MenuItem::Command, label, action), view);
+ tomenu.add(MenuItem(MenuItem::Command, label, FuncRequest(LFUN_FILE_OPEN, (*lfit))), view);
}
}
if (names.empty()) {
tomenu.add(MenuItem(MenuItem::Command, _("No Documents Open!"),
- LFUN_NOACTION), view);
+ FuncRequest(LFUN_NOACTION)), view);
return;
}
Strings::const_iterator docit = names.begin();
Strings::const_iterator end = names.end();
for (; docit != end; ++docit, ++ii) {
- int const action =
- lyxaction.getPseudoAction(LFUN_SWITCHBUFFER, *docit);
string label = MakeDisplayPath(*docit, 20);
if (ii < 10)
label = tostr(ii) + ". " + label + '|' + tostr(ii);
- tomenu.add(MenuItem(MenuItem::Command, label, action), view);
+ tomenu.add(MenuItem(MenuItem::Command, label, FuncRequest(LFUN_SWITCHBUFFER, *docit)), view);
}
}
{
if (!view->buffer() && kind != MenuItem::ImportFormats) {
tomenu.add(MenuItem(MenuItem::Command,
- _("No Documents Open!"), LFUN_NOACTION),
+ _("No Documents Open!"),
+ FuncRequest(LFUN_NOACTION)),
view);
return;
}
}
if (!(*fit)->shortcut().empty())
label += '|' + (*fit)->shortcut();
- int const action2 = lyxaction.
- getPseudoAction(action, (*fit)->name());
- tomenu.add(MenuItem(MenuItem::Command, label, action2),
+
+ tomenu.add(MenuItem(MenuItem::Command, label,
+ FuncRequest(action, (*fit)->name())),
view);
}
}
{
if (!view->buffer()) {
tomenu.add(MenuItem(MenuItem::Command,
- _("No Documents Open!"), LFUN_NOACTION),
+ _("No Documents Open!"),
+ FuncRequest(LFUN_NOACTION)),
view);
return;
}
FloatList::const_iterator cit = floats.begin();
FloatList::const_iterator end = floats.end();
for (; cit != end; ++cit) {
- int const action = lyxaction
- .getPseudoAction(LFUN_FLOAT_LIST, cit->second.type());
tomenu.add(MenuItem(MenuItem::Command,
- _(cit->second.listName()), action),
+ _(cit->second.listName()),
+ FuncRequest(LFUN_FLOAT_LIST,
+ cit->second.type())),
view);
}
}
{
if (!view->buffer()) {
tomenu.add(MenuItem(MenuItem::Command,
- _("No Documents Open!"), LFUN_NOACTION),
+ _("No Documents Open!"),
+ FuncRequest(LFUN_NOACTION)),
view);
return;
}
FloatList::const_iterator end = floats.end();
for (; cit != end; ++cit) {
// normal float
- int const action =
- lyxaction.getPseudoAction(LFUN_INSET_FLOAT,
- cit->second.type());
string const label = _(cit->second.name());
- tomenu.add(MenuItem(MenuItem::Command, label, action),
+ tomenu.add(MenuItem(MenuItem::Command, label,
+ FuncRequest(LFUN_INSET_FLOAT,
+ cit->second.type())),
view);
}
}
int shortcut_count = 0;
if (to - from <= max_number_of_items) {
for (lyx::toc::Toc::size_type i = from; i < to; ++i) {
- int const action = toc_list[i].action();
string label(4 * max(0, toc_list[i].depth - depth),' ');
label += limit_string_length(toc_list[i].str);
if (toc_list[i].depth == depth
&& ++shortcut_count <= 9) {
label += '|' + tostr(shortcut_count);
}
- tomenu.add(MenuItem(MenuItem::Command, label, action));
+ tomenu.add(MenuItem(MenuItem::Command, label,
+ FuncRequest(toc_list[i].action())));
}
} else {
lyx::toc::Toc::size_type pos = from;
toc_list[new_pos].depth > depth)
++new_pos;
- int const action = toc_list[pos].action();
string label(4 * max(0, toc_list[pos].depth - depth), ' ');
label += limit_string_length(toc_list[pos].str);
if (toc_list[pos].depth == depth &&
if (new_pos == pos + 1) {
tomenu.add(MenuItem(MenuItem::Command,
- label, action));
+ label, FuncRequest(toc_list[pos].action())));
} else {
MenuItem item(MenuItem::Submenu, label);
item.submenu(new Menu);
if (!view->buffer()) {
tomenu.add(MenuItem(MenuItem::Command,
- _("No Documents Open!"), LFUN_NOACTION),
+ _("No Documents Open!"),
+ FuncRequest(LFUN_NOACTION)),
view);
return;
}
for (; ccit != eend; ++ccit) {
string const label = limit_string_length(ccit->str);
menu->add(MenuItem(MenuItem::Command,
- label, ccit->action()));
+ label,
+ FuncRequest(ccit->action())));
}
string const & floatName = cit->first;
// Is the _(...) really needed here? (Lgb)
vector<string>::const_iterator end = selL.end();
for (unsigned int index = 0; cit != end; ++cit, ++index) {
- int const action = lyxaction.getPseudoAction(LFUN_PASTE,
- tostr(index));
- tomenu.add(MenuItem(MenuItem::Command, *cit, action));
+ tomenu.add(MenuItem(MenuItem::Command, *cit,
+ FuncRequest(LFUN_PASTE, tostr(index))));
}
}
for (int ii = 1; cit != end; ++cit, ++ii) {
string label = cit->getBranch();
- int const action = lyxaction.
- getPseudoAction(LFUN_INSERT_BRANCH,
- (cit->getBranch()));
if (ii < 10)
label = tostr(ii) + ". " + label + "|" + tostr(ii);
- tomenu.add(MenuItem(MenuItem::Command, label, action), view);
+ tomenu.add(MenuItem(MenuItem::Command, label,
+ FuncRequest(LFUN_INSERT_BRANCH,
+ cit->getBranch())), view);
}
}
#ifndef MENUBACKEND_H
#define MENUBACKEND_H
+#include "FuncStatus.h"
+#include "funcrequest.h"
+
#include "support/std_string.h"
#include <boost/shared_ptr.hpp>
#include <vector>
-#include "FuncStatus.h"
-
class LyXLex;
class LyXView;
class Menu;
/** Available branches in document */
Branches
};
- /// Create a Command type MenuItem
+
+ explicit MenuItem(Kind kind);
+
MenuItem(Kind kind,
- string const & label = string(),
+ string const & label,
string const & command = string(),
bool optional = false);
+
MenuItem(Kind kind,
string const & label,
- int action,
+ FuncRequest const & func,
bool optional = false);
/// This one is just to please boost::shared_ptr<>
/// The kind of entry
Kind kind() const { return kind_; }
/// the action (if relevant)
- int action() const { return action_; }
+ FuncRequest const & func() const { return func_; }
/// returns true if the entry should be ommited when disabled
bool optional() const { return optional_; }
/// returns the status of the lfun associated with this entry
///
string label_;
///
- int action_;
+ FuncRequest func_;
///
string submenuname_;
///
if (lex.next(true)) {
string const tooltip = _(lex.getString());
lex.next(true);
- string const func = lex.getString();
+ string const func_arg = lex.getString();
lyxerr[Debug::PARSER]
<< "ToolbarBackend::read TO_ADD func: `"
- << func << '\'' << endl;
- add(tb, func, tooltip);
+ << func_arg << '\'' << endl;
+ // Split func_arg in function and arg.
+ string::size_type sp = func_arg.find(' ');
+ if (sp != string::npos) {
+
+ string const func =
+ func_arg.substr(0, sp);
+ string const arg =
+ func_arg.substr(sp + 1,
+ string::npos);
+
+ kb_action const tf =
+ lyxaction.LookupFunc(func);
+
+ add(tb, FuncRequest(tf, arg), tooltip);
+ } else {
+ kb_action const tf = lyxaction.LookupFunc(func_arg);
+ add(tb, FuncRequest(tf), tooltip);
+
+ }
+
}
break;
case TO_MINIBUFFER:
- add(tb, MINIBUFFER);
+ add(tb, FuncRequest(kb_action(MINIBUFFER)));
break;
case TO_SEPARATOR:
- add(tb, SEPARATOR);
+ add(tb, FuncRequest(kb_action(SEPARATOR)));
break;
case TO_LAYOUTS:
- add(tb, LAYOUTS);
+ add(tb, FuncRequest(kb_action(LAYOUTS)));
break;
case TO_ENDTOOLBAR:
}
-void ToolbarBackend::add(Toolbar & tb, int action, string const & tooltip)
-{
- tb.items.push_back(make_pair(action, tooltip));
-}
-
-
-void ToolbarBackend::add(Toolbar & tb, string const & func, string const & tooltip)
+void ToolbarBackend::add(Toolbar & tb,
+ FuncRequest const & func, string const & tooltip)
{
- int const tf = lyxaction.LookupFunc(func);
-
- if (tf == -1) {
- lyxerr << "ToolbarBackend::add: no LyX command called `"
- << func << "' exists!" << endl;
- } else {
- add(tb, tf, tooltip);
- }
+ tb.items.push_back(make_pair(func, tooltip));
}
-string const ToolbarBackend::getIcon(int action)
+string const ToolbarBackend::getIcon(FuncRequest const & f)
{
string fullname;
- FuncRequest f = lyxaction.retrieveActionArg(action);
if (f.action == LFUN_INSERT_MATH) {
if (!f.argument.empty())
lyxerr[Debug::GUI] << "Cannot find icon for command \""
<< lyxaction.getActionName(f.action)
- << ' ' << f.argument << '"' << endl;
+ << '(' << f.argument << ")\"" << endl;
return LibFileSearch("images", "unknown", "xpm");
}
#ifndef TOOLBAR_BACKEND_H
#define TOOLBAR_BACKEND_H
+#include "funcrequest.h"
+
#include <vector>
#include "support/std_string.h"
class LyXLex;
+
///
class ToolbarBackend {
public:
};
/// action, tooltip
- typedef std::pair<int, string> Item;
+ typedef std::pair<FuncRequest, string> Item;
/// the toolbar items
- typedef std::vector<std::pair<int, string> > Items;
+ typedef std::vector<Item> Items;
/// toolbar flags
enum Flags {
void readToolbars(LyXLex &);
/// return a full path of an XPM for the given action
- static string const getIcon(int action);
+ static string const getIcon(FuncRequest const &);
private:
/// add the given lfun with tooltip if relevant
- void add(Toolbar & tb, int, string const & tooltip = string());
-
- /// add the given lfun with tooltip if relevant
- void add(Toolbar & tb, string const &, string const & tooltip);
+ void add(Toolbar & tb, FuncRequest const &,
+ string const & tooltip = string());
/// all the toolbars
Toolbars toolbars;
+2003-09-21 Lars Gullik Bjønnes <larsbj@gullik.net>
+
+ * LyXView.C (updateToolbar): adjust
+
2003-09-18 Angus Leeming <leeming@lyx.org>
-
+
* Painter.C:
* Painter.h:
* lyx_gui.h: rename EnumLColor as LColor_color.
{
bool const math = mathcursor;
bool const table =
- !getLyXFunc().getStatus(LFUN_LAYOUT_TABULAR).disabled();
+ !getLyXFunc().getStatus(FuncRequest(LFUN_LAYOUT_TABULAR)).disabled();
toolbar_->update(math, table);
}
r.setView(view().get());
getLyXFunc().dispatch(r);
}
+10
virtual ~Toolbar();
/// Initialize toolbar from backend
- void init();
+ void init();
/// update the state of the toolbars
void update(bool in_math, bool in_table);
2003-09-21 Lars Gullik Bjønnes <larsbj@gullik.net>
+ * GToolbar.C (add): Make it take a ToobarBackend::Item as arg,
+ adjust.
+ (onButtonClicked): take a FuncRequest
+ (update): adjust
+
+ * GMenubar.C (submenuDisabled): pass FuncRequest to getStatus.
+ (onSubMenuActivate): ditto
+ (onCommandActivate): pass MenuItem::func to dispatch
+
* LyXKeySymFactory.C (create): fix new bug
* GView.C (GView): fix new bug
case MenuItem::Command:
{
FuncStatus const flag =
- view_->getLyXFunc().getStatus(i->action());
+ view_->getLyXFunc().getStatus(i->func());
if (!flag.disabled())
return false;
break;
case MenuItem::Command:
{
FuncStatus const flag =
- view_->getLyXFunc().getStatus(i->action());
+ view_->getLyXFunc().getStatus(i->func());
bool on, off;
on = flag.onoff(true);
off = flag.onoff(false);
void GMenubar::onCommandActivate(MenuItem const * item,
Gtk::MenuItem * /*gitem*/)
{
- view_->getLyXFunc().dispatch(item->action(), true);
+ view_->getLyXFunc().dispatch(item->func(), true);
}
ToolbarBackend::item_iterator it = tb.items.begin();
ToolbarBackend::item_iterator end = tb.items.end();
for (; it != end; ++it)
- add(toolbar, it->first, it->second);
+ add(toolbar, *it);
toolbar->set_toolbar_style(Gtk::TOOLBAR_ICONS);
toolbar->show();
vbox_.children().push_back(
void GToolbar::add(Gtk::Toolbar * toolbar,
- int action,
- string const & tooltip)
+ ToolbarBackend::Item const & item)
{
- switch (action) {
+ FuncRequest const & func = item.first;
+ string const & tooltip = item.second;
+ switch (func.action) {
case ToolbarBackend::SEPARATOR:
toolbar->tools().push_back(Gtk::Toolbar_Helpers::Space());
break;
Gtk::Toolbar_Helpers::Element(combo_));
toolbar->tools().back().get_widget()->set_data(
gToolData,
- reinterpret_cast<void*>(LFUN_LAYOUT));
+ reinterpret_cast<void*>(&const_cast<ToolbarBackend::Item&>(item)));
break;
}
default:
{
Glib::ustring xpmName =
- Glib::locale_to_utf8(toolbarbackend.getIcon(action));
+ Glib::locale_to_utf8(toolbarbackend.getIcon(func));
Glib::ustring tip = Glib::locale_to_utf8(tooltip);
if (xpmName.size() == 0) {
toolbar->tools().push_back(
Gtk::Toolbar_Helpers::ButtonElem(
"",
SigC::bind(SigC::slot(*this, >oolbar::onButtonClicked),
- action),
+ FuncRequest(func)),
tip));
} else {
Gtk::Image * image =
"",
*image,
SigC::bind(SigC::slot(*this, >oolbar::onButtonClicked),
- action),
+ FuncRequest(func)),
tip));
}
toolbar->tools().back().get_content()->set_data(
gToolData,
- reinterpret_cast<void*>(action));
+ reinterpret_cast<void*>(&const_cast<ToolbarBackend::Item&>(item)));
break;
}
}
}
-void GToolbar::onButtonClicked(int action)
+void GToolbar::onButtonClicked(FuncRequest func)
{
- view_->getLyXFunc().dispatch(action, true);
+ view_->getLyXFunc().dispatch(func, true);
}
default:
widget = it->get_content();
}
- int action = reinterpret_cast<int>(
+ ToolbarBackend::Item * item =
+ reinterpret_cast<ToolbarBackend::Item*>(
widget->get_data(gToolData));
FuncStatus const status = view_->
- getLyXFunc().getStatus(action);
+ getLyXFunc().getStatus(item->first);
bool sensitive = !status.disabled();
widget->set_sensitive(sensitive);
if (it->get_type() != Gtk::TOOLBAR_CHILD_BUTTON)
#include "ToolbarBackend.h"
#include "support/std_string.h"
+
class GToolbar : public Toolbar, public SigC::Object
{
public:
/// add a new button to the toolbar.
void add(Gtk::Toolbar * toolbar,
- int action,
- string const & tooltip);
+ ToolbarBackend::Item const & item);
/// display toolbar, not implemented
void displayToolbar(ToolbarBackend::Toolbar const & tb, bool show);
/// Erase the layout list
void clearLayoutList();
private:
- void onButtonClicked(int action);
+ void onButtonClicked(FuncRequest);
void onLayoutSelected();
Gtk::VBox vbox_;
std::vector<Gtk::Toolbar*> toolbars_;
2003-09-21 Lars Gullik Bjønnes <larsbj@gullik.net>
+ * QtView.C (activated): change to take a FuncRequest, not a slot
+ anymore.
+
+ * QLToolbar.C (update): adjust
+ (add): change to take a FuncRequest
+
+ * QLPopupMenu.C (createMenu): constify id
+ (QLPopupMenu): connect to local class func fire instead of to
+ QtView::activated.
+ (fire): new class function
+ (populate): change to store a cache of FuncRequest for the menu
+ items, adjust
+
* QContentPane.C (keyPressEvent): fix new bug
* LyXKeySymFactory.C (create): fix new bug
{
// FIXME: leaks ??
QLPopupMenu * pm = new QLPopupMenu(owner, item->submenuname(), is_toplevel);
- int id = parent->insertItem(toqstr(getLabel(*item)), pm);
+ int const id = parent->insertItem(toqstr(getLabel(*item)), pm);
return make_pair(id, pm);
}
if (toplevel)
connect(this, SIGNAL(aboutToShow()), this, SLOT(showing()));
connect(this, SIGNAL(activated(int)),
- owner_->view(), SLOT(activated(int)));
+ this, SLOT(fire(int)));
+}
+
+
+void QLPopupMenu::fire(int index)
+{
+ owner_->view()->activated(funcs_[index]);
}
void QLPopupMenu::populate(Menu * menu)
{
+ funcs_.clear();
+
Menu::const_iterator m = menu->begin();
Menu::const_iterator end = menu->end();
for (; m != end; ++m) {
} else {
FuncStatus const status = m->status();
- insertItem(toqstr(getLabel(*m)), m->action());
- setItemEnabled(m->action(), !status.disabled());
- setItemChecked(m->action(), status.onoff(true));
+ Funcs::iterator fit =
+ funcs_.insert(funcs_.end(), m->func());
+ int const index = std::distance(funcs_.begin(), fit);
+
+ insertItem(toqstr(getLabel(*m)), index);
+ setItemEnabled(index, !status.disabled());
+ setItemChecked(index, status.onoff(true));
}
}
}
#include <qpopupmenu.h>
+#include "funcrequest.h"
+
#include "support/std_string.h"
+#include <vector>
#include <utility>
class MenuBackend;
public slots:
/// populate the toplevel menu and all children
void showing();
+ ///
+ void fire(int);
private:
/// our owning menubar
QLMenubar * owner_;
/// the name of this menu
string name_;
+
+ ///
+ typedef std::vector<FuncRequest> Funcs;
+ ///
+ Funcs funcs_;
};
#endif // QLPOPUPMENU_H
for (; p != end; ++p) {
QToolButton * button = p->first;
- int action = p->second;
+ FuncRequest const & func = p->second;
FuncStatus const status =
- owner_->getLyXFunc().getStatus(action);
+ owner_->getLyXFunc().getStatus(func);
button->setToggleButton(true);
button->setOn(status.onoff(true));
button->setEnabled(!status.disabled());
}
- bool const enable = !owner_->getLyXFunc().getStatus(LFUN_LAYOUT).disabled();
+ bool const enable = !owner_->getLyXFunc().getStatus(FuncRequest(LFUN_LAYOUT)).disabled();
// Workaround for Qt bug where setEnabled(true) closes
// the popup
}
-void QLToolbar::add(QToolBar * tb, int action, string const & tooltip)
+void QLToolbar::add(QToolBar * tb,
+ FuncRequest const & func, string const & tooltip)
{
- switch (action) {
+ switch (func.action) {
case ToolbarBackend::SEPARATOR:
tb->addSeparator();
break;
tb->setHorizontalStretchable(true);
break;
default: {
- if (owner_->getLyXFunc().getStatus(action).unknown())
+ if (owner_->getLyXFunc().getStatus(func).unknown())
break;
- QPixmap p = QPixmap(toolbarbackend.getIcon(action).c_str());
+ QPixmap p = QPixmap(toolbarbackend.getIcon(func).c_str());
QToolButton * button =
new QToolButton(p, toqstr(tooltip), "",
proxy_.get(), SLOT(button_selected()), tb);
- map_[button] = action;
+ map_[button] = func;
break;
}
}
void add(ToolbarBackend::Toolbar const & tb);
/// add an item to a toolbar
- void add(QToolBar * tb, int action, string const & tooltip);
+ void add(QToolBar * tb, FuncRequest const &, string const & tooltip);
/// show or hide a toolbar
void displayToolbar(ToolbarBackend::Toolbar const & tb, bool show);
QLComboBox * combo_;
- typedef std::map<QToolButton *, int> ButtonMap;
+ typedef std::map<QToolButton *, FuncRequest> ButtonMap;
ButtonMap map_;
};
}
-void QtView::activated(int id)
+void QtView::activated(FuncRequest const & func)
{
- getLyXFunc().dispatch(id, true);
+ getLyXFunc().dispatch(func, true);
}
#include <qtimer.h>
class QCommandBuffer;
+class FuncRequest;
/**
* QtView - Qt implementation of LyXView
/// add the command buffer
void addCommandBuffer(QWidget * parent);
-public slots:
/// menu item has been selected
- void activated(int id);
+ void activated(FuncRequest const &);
+public slots:
/// idle timeout
void update_view_state_qt();
protected:
2003-09-21 Lars Gullik Bjønnes <larsbj@gullik.net>
+ * XFormsToolbar.C: adjust
+
+ * XFormsMenubar.C (create_submenu): change to update a cache of
+ FuncRequest for the MenuItems.
+ (MenuCallback): adjust
+
* lyx_gui.C (parse_init): fix new bug
* XFormsToolbar.C (XFormsToolbar): fix new bug
int XFormsMenubar::create_submenu(Window win, XFormsView * view,
- Menu const & menu, vector<int> & smn)
+ Menu const & menu,
+ vector<int> & smn, Funcs & funcs)
{
- const int menuid = get_new_submenu(smn, win);
+ int const menuid = get_new_submenu(smn, win);
lyxerr[Debug::GUI] << "XFormsMenubar::create_submenu: creating "
<< menu.name() << " as menuid=" << menuid << endl;
++count;
// add a More... submenu if the menu is too long (but
// not just for one extra entry!)
- if (count > max_number_of_items && (i+1) != end) {
+ if (count > max_number_of_items && (i + 1) != end) {
int tmpmenuid = get_new_submenu(smn, win);
lyxerr[Debug::GUI] << "Too many items, creating "
<< "new menu " << tmpmenuid << endl;
}
// Is there a separator after the item?
- if ((i+1) != end
+ if ((i + 1) != end
&& (i + 1)->kind() == MenuItem::Separator)
label += "%l";
// create the submenu
submenuid =
create_submenu(win, view,
- *item.submenu(), smn);
+ *item.submenu(), smn, funcs);
if (submenuid == -1)
return -1;
label += "%x" + tostr(smn.size());
<< "), ";
} else {
// Add the action
- label += "%x" + tostr(item.action()
- + action_offset);
+ Funcs::iterator fit =
+ funcs.insert(funcs.end(), item.func());
+ int const action_count =
+ std::distance(funcs.begin(), fit);
+
+ label += "%x" + tostr(action_count + action_offset);
lyxerr[Debug::GUI] << "Action: \""
- << item.action() << "\", ";
+ << item.func().action
+ << "(" << item.func().argument
+ << ")\", ";
}
// Add everything to the menu
Menu tomenu;
Menu const frommenu = menubackend_->getMenu(item->submenuname());
menubackend_->expand(frommenu, tomenu, view);
+ Funcs funcs;
vector<int> submenus;
int menu = iteminfo->menubar_->create_submenu(FL_ObjWin(ob), view,
- tomenu, submenus);
+ tomenu, submenus, funcs);
if (menu != -1) {
// place popup
fl_setpup_position(view->getForm()->x + ob->x,
// If the action value is too low, then it is not a
// valid action, but something else.
- if (choice >= action_offset + 1) {
- view->getLyXFunc().dispatch(choice - action_offset, true);
+ if (choice >= action_offset) {
+ view->getLyXFunc().dispatch(funcs[choice - action_offset], true);
} else {
lyxerr[Debug::GUI]
<< "MenuCallback: ignoring bogus action "
#ifndef XFORMSMENUBAR_H
#define XFORMSMENUBAR_H
+#include "funcrequest.h"
#include "frontends/Menubar.h"
#include <boost/shared_ptr.hpp>
#include "support/std_string.h"
#include <vector>
+
class LyXView;
class XFormsView;
class Menu;
class XFormsMenubar : public Menubar {
public:
+ ///
+ typedef std::vector<FuncRequest> Funcs;
///
XFormsMenubar(LyXView *, MenuBackend const &);
///
std::vector<int> & smn, Window win);
///
int create_submenu(Window win, XFormsView * view,
- Menu const & menu, std::vector<int> & smn);
+ Menu const & menu,
+ std::vector<int> & smn, Funcs & funcs);
//
void makeMenubar(Menu const & menu);
const int height = 30; // the height of all items in the toolbar
XFormsToolbar::toolbarItem::toolbarItem()
- : action(LFUN_NOACTION), icon(0)
+ : icon(0)
{}
// But we don't copy the icon from ti
kill_icon();
- action = ti.action;
+ func = ti.func;
return *this;
}
ToolbarList::const_iterator p = toollist_.begin();
ToolbarList::const_iterator end = toollist_.end();
for (; p != end; ++p) {
- if (p->action == ToolbarBackend::LAYOUTS && combox_) {
+ if (p->func.action == int(ToolbarBackend::LAYOUTS) && combox_) {
LyXFunc const & lf = owner_->getLyXFunc();
bool const disable =
- lf.getStatus(LFUN_LAYOUT).disabled();
+ lf.getStatus(FuncRequest(LFUN_LAYOUT)).disabled();
setEnabled(combox_, !disable);
continue;
}
if (!p->icon)
continue;
- FuncStatus const status = owner_->getLyXFunc().getStatus(p->action);
+ FuncStatus const status = owner_->getLyXFunc().getStatus(p->func);
if (status.onoff(true)) {
// I'd like to use a different color
// here, but then the problem is to
void ToolbarCB(FL_OBJECT * ob, long ac)
{
- XFormsView * owner = static_cast<XFormsView *>(ob->u_vdata);
+ if (!ob || !ob->u_vdata)
+ return;
- owner->getLyXFunc().dispatch(int(ac), true);
+ XFormsToolbar * ptr = static_cast<XFormsToolbar *>(ob->u_vdata);
+ XFormsView * owner = ptr->owner_;
+ owner->getLyXFunc().dispatch(ptr->funcs[ac], true);
}
if (!toollist_.empty())
return;
+ funcs.clear();
+
ToolbarBackend::item_iterator it = tb.items.begin();
ToolbarBackend::item_iterator end = tb.items.end();
for (; it != end; ++it)
}
-void XFormsToolbar::add(int action, string const & tooltip)
+void XFormsToolbar::add(FuncRequest const & func, string const & tooltip)
{
toolbarItem item;
- item.action = action;
+ item.func = func;
- switch (action) {
+ switch (func.action) {
case ToolbarBackend::SEPARATOR:
xpos += sepspace;
break;
fl_set_object_gravity(obj,
NorthWestGravity,
NorthWestGravity);
- fl_set_object_callback(obj, C_Toolbar_ToolbarCB,
- static_cast<long>(action));
+
+ Funcs::iterator fit = funcs.insert(funcs.end(), func);
+ int const index = std::distance(funcs.begin(), fit);
+ fl_set_object_callback(obj, C_Toolbar_ToolbarCB, index);
// Remove the blue feedback rectangle
fl_set_pixmapbutton_focus_outline(obj, 0);
tooltip_->init(obj, tooltip);
// The view that this object belongs to.
- obj->u_vdata = owner_;
+ obj->u_vdata = this;
- string const xpm = toolbarbackend.getIcon(action);
+ string const xpm = toolbarbackend.getIcon(func);
fl_set_pixmapbutton_file(obj, xpm.c_str());
// we must remember to update the positions
void add(ToolbarBackend::Toolbar const & tb);
/// add an item to a toolbar
- void add(int action, string const & tooltip);
+ void add(FuncRequest const &, string const & tooltip);
/// display toolbar, not implemented
void displayToolbar(ToolbarBackend::Toolbar const & tb, bool show);
/// deallocate icon
void kill_icon();
- /// lyx action number
- int action;
+ /// lyx action
+ FuncRequest func;
/// icon for this item
FL_OBJECT * icon;
};
+ typedef std::vector<FuncRequest> Funcs;
+
+ Funcs funcs;
+
typedef std::vector<toolbarItem> ToolbarList;
/// The list containing all the buttons
}
-string FuncRequest::getArg(int i) const
+string FuncRequest::getArg(unsigned int i) const
{
vector<string> args;
split(args, argument);
void errorMessage(string const & msg) const;
/// argument parsing, extract argument i as string
- string getArg(int i) const;
+ string getArg(unsigned int i) const;
private:
/// the BufferView we are talking to
<< argument << "']" << endl;
}
} else {
- dispatch(action);
+ dispatch(FuncRequest(kb_action(action)));
}
}
-FuncStatus LyXFunc::getStatus(int ac) const
-{
- return getStatus(lyxaction.retrieveActionArg(ac));
-}
-
-
FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
{
FuncStatus flag;
// solution, we consider only the first action of the sequence
if (ev.action == LFUN_SEQUENCE) {
// argument contains ';'-terminated commands
- flag = getStatus(lyxaction.LookupFunc(token(ev.argument, ';', 0)));
+ flag = getStatus(FuncRequest(lyxaction.LookupFunc(token(ev.argument, ';', 0))));
}
return flag;
return;
}
- dispatch(action, verbose);
+ dispatch(FuncRequest(kb_action(action)), verbose);
}
-void LyXFunc::dispatch(int ac, bool verbose)
-{
- dispatch(lyxaction.retrieveActionArg(ac), verbose);
-}
-
namespace {
bool ensureBufferClean(BufferView * bv) {
meta_fake_bit = key_modifier::none;
if (view()->available())
// cancel any selection
- dispatch(LFUN_MARK_OFF);
+ dispatch(FuncRequest(LFUN_MARK_OFF));
setMessage(N_("Cancel"));
break;
string comname = lyxaction.getActionName(ev.action);
- int pseudoaction = ev.action;
bool argsadded = false;
if (!ev.argument.empty()) {
- // the pseudoaction is useful for the bindings
- pseudoaction = lyxaction.searchActionArg(ev.action, ev.argument);
-
- if (pseudoaction == LFUN_UNKNOWN_ACTION) {
- pseudoaction = ev.action;
- } else {
+ if (ev.action != LFUN_UNKNOWN_ACTION) {
comname += ' ' + ev.argument;
argsadded = true;
}
}
- string const shortcuts = toplevel_keymap->findbinding(pseudoaction);
+ string const shortcuts = toplevel_keymap->findbinding(ev.action);
if (!shortcuts.empty()) {
comname += ": " + shortcuts;
/// Dispatch via a string argument
void dispatch(string const & s, bool verbose = false);
- /// Dispatch via a pseudo action, also displaying shortcut/command name
- void dispatch(int ac, bool verbose = false);
-
/// return the status bar state string
string const view_status_message();
///
void processKeySym(LyXKeySymPtr key, key_modifier::state state);
- /// we need one internal which is called from inside LyXAction and
- /// can contain the string argument.
- FuncStatus getStatus(int ac) const;
///
FuncStatus getStatus(FuncRequest const & action) const;
}
-int TocItem::action() const
+FuncRequest TocItem::action() const
{
- return lyxaction.getPseudoAction(LFUN_GOTO_PARAGRAPH,
- tostr(id_));
+ return FuncRequest(LFUN_GOTO_PARAGRAPH, tostr(id_));
}
class Buffer;
class LyXView;
class Paragraph;
+class FuncRequest;
/** Nice functions and objects to handle TOCs
*/
/// set cursor in LyXView to this TocItem
void goTo(LyXView & lv_) const;
/// the action corresponding to the goTo above
- int action() const;
+ FuncRequest action() const;
/// Paragraph ID containing this item
int id_;
/// nesting depth