help-gnats
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

another bug fix for the GNATS emacs interface


From: Mel Hatzis
Subject: another bug fix for the GNATS emacs interface
Date: Mon, 13 Oct 2003 18:50:49 -0700
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030624

The emacs client interface for GNATS has an edit-mode
whereby it's possible to right-click on an Enum field
and get a popup menu of all the enum field values.
Unfortunately, if the number of Enum values exceeds
the number that can be displayed in a single popup
menu, only a subset of the values is displayed.

Please review the attached patch which fixes the
edit mode so that the Enum values are displayed
in a a multi-paned (cascading) menu. The number
of values displayed in each sub-menu is based
on the frame-height associated with the emacs
session.

--
Mel Hatzis
--- gnats.el~   6 Dec 2002 10:32:58 -0000       1.1.1.1
+++ gnats.el    11 Oct 2003 01:13:05 -0000
@@ -85,6 +85,11 @@ If the environment variable is unset, \"
   :group 'gnats
   :type 'boolean)
 
+(defcustom gnats-menu-length 70
+  "*Maximum length of a name displayed on a popup menu."
+  :type 'integer
+  :group 'boolean)
+
 
 
 (defvar gnats-server-conn nil
@@ -294,6 +299,43 @@ Use an X menu for the value selection."
   (sit-for 0)
   (gnats-request-enum (get-text-property (point) 'gnats-field-name) e))
 
+(defun gnats-menu-build-paned-menu (name entries)
+  "Build a multi-paned menu named NAME from the strings in ENTRIES.
+That is, ENTRIES is a list of strings which appear as the choices
+in the menu.  The number of panes depends on the number of entries.
+The visible entries are truncated to `gnats-menu-length', but the
+strings returned are not."
+  (let* ((f-height (/ (frame-height) 2))
+         (pane-list
+          (let (temp-pane-list
+                (iter 0))
+            (while entries
+              (let (lst
+                    (count 0))
+                (while (and (< count f-height) entries)
+                  (let ((str (car entries)))
+                    (setq lst (cons
+                               (cons
+                                (if (> (length str) gnats-menu-length)
+                                    (substring str 0 gnats-menu-length)
+                                  str)
+                                str)
+                               lst))
+                    (setq entries (cdr entries))
+                    (setq count (1+ count))))
+                (setq iter (1+ iter))
+                (setq
+                 temp-pane-list
+                 (cons
+                  (cons
+                   (format "-*- %s (%d) -*-" name iter)
+                   (nreverse lst))
+                  temp-pane-list))))
+            (nreverse temp-pane-list))))
+
+    ;; Return the menu:
+    (cons (concat "-*- " name " -*-") pane-list)))
+
 (defun gnats-request-enum (field &optional menup no-default)
   "Ask the user for an enumerated value for FIELD and change the field value.
 If MENUP is non-nil, use an X menu for the selection.
@@ -305,9 +347,9 @@ minibuffer."
          (if menup
              (x-popup-menu
               t
-              (list (concat "New value for " (get field 'field-name) ":")
-                    (cons "" (mapcar (lambda (x) (cons (car x) (cadr x)))
-                                     completions))))
+              (gnats-menu-build-paned-menu
+               (concat "New value for " (get field 'field-name) ":")
+               (mapcar (lambda (x) (car x)) completions)))
            (completing-read
             (concat "New value for " (get field 'field-name) ": ")
             completions nil t

reply via email to

[Prev in Thread] Current Thread [Next in Thread]