From 48750ce6d8b5be11321954edce118442673b677e Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Fri, 3 Nov 2000 13:26:55 +0000 Subject: [PATCH] Add code to check shortcuts in menu files git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1190 a592a061-630c-0410-9148-cb99ea01b6c8 --- ChangeLog | 13 +++++++++++++ src/MenuBackend.C | 29 +++++++++++++++++++++++++++++ src/MenuBackend.h | 10 ++++++++-- src/insets/insettext.C | 5 ++--- 4 files changed, 52 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6b01b16c53..fe9678e9fa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2000-11-03 Jean-Marc Lasgouttes + + * src/MenuBackend.h (fulllabel): new method. + + * src/MenuBackend.C (checkShortcuts): new method. Checks whether + the menu shortcuts of a menu are unique and whether they + correspond to a letter of the label. + (expand): call checkShortcuts when debugging. + +2000-11-03 Andre Poenitz + + * src/insets/insettext.C (InsetButtonPress): shut off warning. + 2000-11-02 Lior Silberman * lib/examples/*.lyx : '\language default' => '\language english' diff --git a/src/MenuBackend.C b/src/MenuBackend.C index 3e982eb045..0289bf8928 100644 --- a/src/MenuBackend.C +++ b/src/MenuBackend.C @@ -198,6 +198,31 @@ struct compare_formatpair { } }; +void Menu::checkShortcuts() const +{ + // This is a quadratic algorithm, but we do not care because + // it is used for debugging only. + for (const_iterator it1 = begin(); it1 != end(); ++it1) { + string shortcut = it1->shortcut(); + if (shortcut.empty()) + continue; + if (!contains(it1->label(), shortcut)) + lyxerr << "Menu warning: menu entry \"" + << it1->label() + << "\" does not contain shortcut `" + << shortcut << '\'' << endl; + for (const_iterator it2 = begin(); it2 != it1 ; ++it2) { + if (!compare_no_case(it2->shortcut(), shortcut)) { + lyxerr << "Menu warning: menu entries " + << '"' << it1->fulllabel() + << "\" and \"" << it2->fulllabel() + << "\" share the same shortcut." + << endl; + } + } + } +} + void Menu::expand(Menu & tomenu, Buffer * buf) const { for (const_iterator cit = begin(); @@ -291,6 +316,10 @@ void Menu::expand(Menu & tomenu, Buffer * buf) const tomenu.add(*cit); } } + + // Check whether the shortcuts are unique + if (lyxerr.debugging(Debug::GUI)) + checkShortcuts(); } diff --git a/src/MenuBackend.h b/src/MenuBackend.h index f03bf57ec9..2c09e4ee48 100644 --- a/src/MenuBackend.h +++ b/src/MenuBackend.h @@ -70,8 +70,10 @@ public: /// The label of a given menuitem string const label() const { return token(label_, '|', 0); } - /// + /// The keyboard shortcut (usually underlined in the entry) string const shortcut() const { return token(label_, '|', 1); } + /// The complete label, with label and shortcut separated by a '|' + string const fulllabel() const { return label_;} /// The kind of entry Kind kind() const { return kind_; } /// the action (if relevant) @@ -109,7 +111,7 @@ public: /// Menu & read(LyXLex &); /// Expands some special entries of the menu - /** The entries with the following kind are exanded to a + /** The entries with the following kind are expanded to a sequence of Command MenuItems: Lastfiles, Documents, ViewFormats, ExportFormats, UpdateFormats */ @@ -130,6 +132,10 @@ public: const_iterator end() const { return items_.end(); } + + // Check whether the menu shortcuts are unique + void checkShortcuts() const; + private: /// ItemList items_; diff --git a/src/insets/insettext.C b/src/insets/insettext.C index 26039d185f..9122719fe0 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -595,9 +595,8 @@ void InsetText::InsetButtonPress(BufferView * bv, int x, int y, int button) no_selection = false; int tmp_x = x - drawTextXOffset; - int tmp_y = y + insetAscent; - Inset * inset = bv->checkInsetHit(TEXT(bv), tmp_x, tmp_y-TEXT(bv)->first, - button); + int tmp_y = y + insetAscent - TEXT(bv)->first; + Inset * inset = bv->checkInsetHit(TEXT(bv), tmp_x, tmp_y, button); HideInsetCursor(bv); if (the_locking_inset) { -- 2.39.2