]> git.lyx.org Git - lyx.git/blobdiff - src/minibuffer.C
I reactivate the code to resize the InsetText on a resize event of the main
[lyx.git] / src / minibuffer.C
index 944af290e338f54cbe143514ec0308d25eb40690..3f1ae5224e5dc511ac6fd60cc2860f337af5c1f4 100644 (file)
@@ -18,6 +18,9 @@
 #pragma implementation
 #endif
 
+// FIXME: temporary 
+#include "frontends/xforms/DropDown.h"
 #include "minibuffer.h"
 
 #include "support/lyxalgo.h"
 #include "gettext.h"
 #include "LyXAction.h"
 #include "BufferView.h"
+#include "frontends/Timeout.h"
 
+#include <cctype>
 
 using SigC::slot;
 using std::vector;
+using std::back_inserter;
+using std::find;
 
 extern LyXAction lyxaction;
 
@@ -55,14 +62,33 @@ MiniBuffer::MiniBuffer(LyXView * o, FL_Coord x, FL_Coord y,
        : stored_(false), owner_(o), state_(spaces)
 {
        add(FL_NORMAL_INPUT, x, y, h, w);
-       timer.setTimeout(6000);
-       timer.timeout.connect(slot(this, &MiniBuffer::init));
-       stored_timer.setTimeout(1500);
-       stored_timer.timeout.connect(slot(this, &MiniBuffer::stored_slot));
+
+       timer = new Timeout(6000);
+       timer->timeout.connect(slot(this, &MiniBuffer::init));
+
+       stored_timer = new Timeout(1500);
+       stored_timer->timeout.connect(slot(this, &MiniBuffer::stored_slot));
        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));
+       dropdown_->keypress.connect(slot(this, &MiniBuffer::append_char));
+}
+
+
+MiniBuffer::~MiniBuffer()
+{
+       delete timer;
+       delete stored_timer;
+       delete dropdown_;
+}
 
 void MiniBuffer::stored_slot() 
 {
        if (stored_) {
@@ -76,19 +102,22 @@ void MiniBuffer::stored_set(string const & str)
 {
        stored_input = str;
        stored_ = true;
-       stored_timer.start();
+       stored_timer->start();
 }
 
 
 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);
                string input = tmp ? tmp : "";
                if (stored_) {
-                       stored_timer.stop();
+                       stored_timer->stop();
                        input = stored_input;
                        set_input(input);
                        stored_ = false;
@@ -125,7 +154,7 @@ int MiniBuffer::peek_event(FL_OBJECT * ob, int event, int key)
                        vector<string> comp;
                        lyx::copy_if(completion_.begin(),
                                     completion_.end(),
-                                    std::back_inserter(comp), prefix(input));
+                                    back_inserter(comp), prefix(input));
 
                        if (comp.empty()) {
                                // No matches
@@ -136,19 +165,20 @@ 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(),
                                                     comp.end(),
-                                                    std::back_inserter(vtmp),
+                                                    back_inserter(vtmp),
                                                     prefix(test));
                                        if (vtmp.size() != comp.size()) {
                                                test.erase(test.length() - 1);
@@ -158,10 +188,16 @@ 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
+                               int const air = the_buffer->x;
+                               x += air;
+                               y += h - (the_buffer->h + air);
+                               w = the_buffer->w;
+                               dropdown_->select(comp, x, y, w);
                        }
                        return 1; 
                }
@@ -182,7 +218,7 @@ int MiniBuffer::peek_event(FL_OBJECT * ob, int event, int key)
                        // of argumetns LFUN's should have first. (Lgb)
                        // First check for match
                        vector<string>::const_iterator cit =
-                               std::find(completion_.begin(),
+                               find(completion_.begin(),
                                          completion_.end(),
                                          input);
                        if (cit == completion_.end()) {
@@ -195,7 +231,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
                        }
@@ -282,7 +320,7 @@ FL_OBJECT * MiniBuffer::add(int type, FL_Coord x, FL_Coord y,
 
 void MiniBuffer::message(string const & str) 
 {
-       timer.restart();
+       timer->restart();
        string const ntext = strip(str);
        if (!the_buffer->focus) {
                set_input(ntext);
@@ -333,7 +371,7 @@ void MiniBuffer::init()
                return;
 
        timeout.emit();
-       timer.stop();
+       timer->stop();
 }
 
 
@@ -359,6 +397,30 @@ 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::append_char(char c)
+{
+       if (!c || !isprint(c))
+               return;
+
+       char const * tmp = fl_get_input(the_buffer);
+       string str = tmp ? tmp : "";
+
+       str += c;
+
+       fl_set_input(the_buffer, str.c_str());
+}
+
 void MiniBuffer::set_input(string const & str)
 {
        fl_set_input(the_buffer, str.c_str());