]> git.lyx.org Git - lyx.git/blobdiff - src/minibuffer.C
bug 183
[lyx.git] / src / minibuffer.C
index 944af290e338f54cbe143514ec0308d25eb40690..7df08768eb12a69c3e495282c5bdf19e6bf79c9d 100644 (file)
@@ -18,6 +18,9 @@
 #pragma implementation
 #endif
 
+// FIXME: temporary 
+#include "frontends/xforms/DropDown.h"
 #include "minibuffer.h"
 
 #include "support/lyxalgo.h"
@@ -62,7 +65,21 @@ MiniBuffer::MiniBuffer(LyXView * o, FL_Coord x, FL_Coord y,
        deactivate();
 }
 
+// thanks for nothing, xforms (recursive creation not allowed) 
+void MiniBuffer::dd_init()
+{
+       dropdown_ = new DropDown(owner_, the_buffer);
+       dropdown_->result.connect(slot(this, &MiniBuffer::set_complete_input));
+}
 
+
+MiniBuffer::~MiniBuffer()
+{
+       delete dropdown_;
+}
+
 void MiniBuffer::stored_slot() 
 {
        if (stored_) {
@@ -83,6 +100,9 @@ void MiniBuffer::stored_set(string const & str)
 int MiniBuffer::peek_event(FL_OBJECT * ob, int event, int key)
 {
        switch (event) {
+       case FL_UNFOCUS:
+               deactivate();
+               break;
        case FL_KEYBOARD:
        {
                char const * tmp = fl_get_input(ob);
@@ -136,14 +156,15 @@ int MiniBuffer::peek_event(FL_OBJECT * ob, int event, int key)
                                // Perfect match
                                string const tmp =
                                        comp[0] + _(" [sole completion]");
-                               stored_set(comp[0]);
+                               stored_set(comp[0] + " ");
                                set_input(tmp);
                        } else {
                                // More that one match
                                // Find maximal avaliable prefix
                                string const tmp = comp[0];
                                string test(input);
-                               test += tmp[test.length()];
+                               if (tmp.length() > test.length())
+                                       test += tmp[test.length()];
                                while (test.length() < tmp.length()) {
                                        vector<string> vtmp;
                                        lyx::copy_if(comp.begin(),
@@ -158,10 +179,12 @@ int MiniBuffer::peek_event(FL_OBJECT * ob, int event, int key)
                                }
                                set_input(test);
                                
-                               // How should the possible matches
-                               // be visualized?
-                               std::copy(comp.begin(), comp.end(),
-                                         std::ostream_iterator<string>(std::cerr, "\n"));
+                               int x,y,w,h;
+                               fl_get_wingeometry(fl_get_real_object_window(the_buffer),
+                                       &x, &y, &w, &h);
+                               // asynchronous completion 
+                               dropdown_->select(comp, x, y + h, w);
                        }
                        return 1; 
                }
@@ -195,7 +218,9 @@ int MiniBuffer::peek_event(FL_OBJECT * ob, int event, int key)
                                // Return the inputted string
                                deactivate();
                                owner_->view()->focus(true);
-                               history_->push_back(input);
+                               if (!input.empty()) {
+                                       history_->push_back(input);
+                               }
                                stringReady.emit(input);
 # if 0
                        }
@@ -359,6 +384,16 @@ void MiniBuffer::redraw()
 }
 
 
+void MiniBuffer::set_complete_input(string const & str)
+{
+       if (!str.empty()) {
+               // add a space so the user can type
+               // an argument immediately
+               set_input(str + " ");
+       }
+}
+
 void MiniBuffer::set_input(string const & str)
 {
        fl_set_input(the_buffer, str.c_str());