]> git.decadent.org.uk Git - ion3.git/blobdiff - mod_query/mod_query.lua
[svn-upgrade] Integrating new upstream version, ion3 (20070318)
[ion3.git] / mod_query / mod_query.lua
index 243f98785fafc317097fc52506531214f55c29f3..1bd3e231534896d69b8c857c1ba13a6a4de07e4f 100644 (file)
@@ -31,6 +31,20 @@ local DIE_TIMEOUT_NO_ERRORCODE=2 -- 2 seconds
 -- Generic helper functions {{{
 
 
+--DOC
+-- Display an error message box in the multiplexer \var{mplex}.
+function mod_query.warn(mplex, str)
+    ioncore.unsqueeze(mod_query.do_warn(mplex, str))
+end
+
+
+--DOC
+-- Display a message in \var{mplex}.
+function mod_query.message(mplex, str)
+    ioncore.unsqueeze(mod_query.do_message(mplex, str))
+end
+
+
 --DOC
 -- Low-level query routine. \var{mplex} is the \type{WMPlex} to display
 -- the query in, \var{prompt} the prompt string, and \var{initvalue}
@@ -50,6 +64,9 @@ function mod_query.query(mplex, prompt, initvalue, handler, completor,
     local function cycle(wedln)
         wedln:complete('next', 'normal')
     end
+    local function bcycle(wedln)
+        wedln:complete('prev', 'normal')
+    end
 
     -- Check that no other queries are open in the mplex.
     local ok=mplex:managed_i(function(r) 
@@ -60,9 +77,14 @@ function mod_query.query(mplex, prompt, initvalue, handler, completor,
     end
     
     local wedln=mod_query.do_query(mplex, prompt, initvalue, 
-                                   handle_it, completor, cycle)
-    if context then
-        wedln:set_context(context)
+                                   handle_it, completor, cycle, bcycle)
+                                   
+    if wedln then
+        ioncore.unsqueeze(wedln)
+        
+        if context then
+            wedln:set_context(context)
+        end
     end
     
     return wedln
@@ -437,24 +459,12 @@ function mod_query.attachclient_handler(frame, str)
         return
     end
     
-    local reg=cwin:manager()
-    local attach
+    local reg=cwin:groupleader_of()
     
-    if not obj_is(reg, "WGroupCW") then
-        reg = cwin
-        attach = function()
-                     frame:attach_new {
-                         type = "WGroupCW", 
-                         switchto = true,
-                         managed = {{ reg = cwin, bottom = true }}
-                     }
-                 end
-    else
-        attach = function()
-                     frame:attach(reg, { switchto = true })
-                 end
+    local function attach()
+        frame:attach(reg, { switchto = true })
     end
-        
+    
     if frame:rootwin_of()~=reg:rootwin_of() then
         mod_query.warn(frame, TR("Cannot attach: different root windows."))
     elseif reg:manager()==frame then
@@ -961,8 +971,10 @@ end
 
 function mod_query.man_completor(wedln, str)
     local mc=ioncore.lookup_script("ion-completeman")
+    local icase=(mod_query.get().caseicompl and " -icase" or "")
+    local mid=""
     if mc then
-        mod_query.popen_completions(wedln, (mc.." -complete "
+        mod_query.popen_completions(wedln, (mc..icase..mid.." -complete "
                                             ..string.shell_safe(str)))
     end
 end
@@ -1132,9 +1144,15 @@ end
 
 --DOC
 -- This query can be used to create a query of a defined menu.
-function mod_query.query_menu(mplex, themenu, prompt)
-    local _sub=mplex:current()
-    local menu=ioncore.evalmenu(themenu, {mplex, _sub})
+function mod_query.query_menu(mplex, sub, themenu, prompt)
+    if type(sub)=="string" then
+        -- Backwards compat. shift
+        prompt=themenu
+        themenu=sub
+        sub=nil
+    end
+    
+    local menu=ioncore.evalmenu(themenu, mplex, sub)
     local menuname=(type(themenu)=="string" and themenu or "?")
     
     if not menu then
@@ -1149,19 +1167,25 @@ function mod_query.query_menu(mplex, themenu, prompt)
     end
 
     local function xform_name(n, is_submenu)
-        return (string.lower(string.gsub(n, "[-/%s]+", "-"))
-                ..(is_submenu and "/" or ""))
+        return string.lower(string.gsub(n, "[-/%s]+", "-"))
     end
 
     local function xform_menu(t, m, p)
         for _, v in ipairs(m) do
             if v.name then
                 local is_submenu=v.submenu_fn
-                local n=p..xform_name(v.name, is_submenu)
-                while t[n] do
+                local n=p..xform_name(v.name)
+                
+                while t[n] or t[n..'/'] do
                     n=n.."'"
                 end
+                
+                if is_submenu then
+                    n=n..'/'
+                end
+                
                 t[n]=v
+                
                 if is_submenu and not v.noautoexpand then
                     local sm=v.submenu_fn()
                     if sm then