ref: a7339fa17654de4bcf5a3e12d8f43279c4e1a834
parent: 3ab5f2ca87e8f035ff0a138258493f81f761ea69
author: phil9 <[email protected]>
date: Wed Mar 23 03:53:30 EDT 2022
add middle-click menu to select search database
--- a/vdict.c
+++ b/vdict.c
@@ -16,6 +16,7 @@
Rectangle searchr;
Rectangle entryr;
Rectangle viewr;
+char *db;
enum
{
@@ -32,9 +33,47 @@
flushimage(display, 1);
}
+char*
+dictmenu(int index)
+{
+ Element *e;
+
+ if(index < 0 || index >= dvlen(dict->db) + 2)
+ return nil;
+ if(index == 0)
+ return "First matching result";
+ else if(index == 1)
+ return "All matching results";
+ e = dvref(dict->db, index - 2);
+ return e->desc;
+}
+
void
emouse(Mouse m)
{
+ Menu menu;
+ Element *e;
+ int n;
+
+ if(ptinrect(m.xy, viewr) && m.buttons == 2){
+ menu.gen = dictmenu;
+ n = menuhit(2, mc, &menu, nil);
+ if(n < 0)
+ return;
+ switch(n){
+ case 0:
+ db = Dfirstmatch;
+ break;
+ case 1:
+ db = Dallmatches;
+ break;
+ default:
+ e = dvref(dict->db, n - 2);
+ db = e->name;
+ break;
+ }
+ return;
+ }
entrymouse(entry, m);
dviewmouse(m);
}
@@ -80,7 +119,9 @@
{
Dvec *v;
- v = dictdefine(dict, Dfirstmatch, s);
+ v = dictdefine(dict, db, s);
+ if(v == nil)
+ sysfatal("dictdefine: %r");
dviewset(v);
dviewredraw();
flushimage(display, 1);
@@ -153,6 +194,7 @@
}ARGEND;
if(host == nil)
usage();
+ db = Dfirstmatch;
dict = dictdial(host, port);
if(dict == nil)
sysfatal("initdict: %r");