]> git.lyx.org Git - features.git/commitdiff
Add code to check shortcuts in menu files
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Fri, 3 Nov 2000 13:26:55 +0000 (13:26 +0000)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Fri, 3 Nov 2000 13:26:55 +0000 (13:26 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1190 a592a061-630c-0410-9148-cb99ea01b6c8

ChangeLog
src/MenuBackend.C
src/MenuBackend.h
src/insets/insettext.C

index 6b01b16c5378e6b8843b4cea0ffdaaf1fedc18a5..fe9678e9fae49935ccc324059eeb54f790712197 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2000-11-03  Jean-Marc Lasgouttes  <Jean-Marc.Lasgouttes@inria.fr>
+
+       * 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  <poenitz@HTWM.De>
+
+       * src/insets/insettext.C (InsetButtonPress): shut off warning. 
+
 2000-11-02  Lior Silberman  <lior@Princeton.EDU>
 
        * lib/examples/*.lyx : '\language default' => '\language english'
index 3e982eb045efe8b1fc6fc41bb2017fac8e7434ea..0289bf8928732951f51c5c18dcc30cd69b18901e 100644 (file)
@@ -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();
 }
 
 
index f03bf57ec9bd7e1c5f89a23dd589acac7a85f0b3..2c09e4ee48b4f265643419fb88124c581ba832b1 100644 (file)
@@ -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_;
index 26039d185f21ca8448dd18e8594f090002d928b8..9122719fe0f8caee5def4ae4fc84dd8a18ca5fe8 100644 (file)
@@ -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) {