]> git.lyx.org Git - lyx.git/blob - src/frontends/MiniBuffer.C
Create a grfx::Loader class and so move large chunks of code out of
[lyx.git] / src / frontends / MiniBuffer.C
1 // -*- C++ -*-
2 /**
3  * \file MiniBuffer.C
4  * Copyright 1995-2002 the LyX Team
5  * Read the file COPYING
6  *
7  * \author Lars
8  * \author Asger and Juergen
9  */
10
11 #include <config.h>
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "MiniBuffer.h"
18
19 #include "support/lyxalgo.h"
20 #include "support/filetools.h"
21 #include "support/lstrings.h"
22 #include "frontends/LyXView.h"
23 #include "gettext.h"
24 #include "LyXAction.h"
25 #include "BufferView.h"
26 #include "frontends/Timeout.h"
27
28 #include <boost/bind.hpp>
29
30 using std::vector;
31 using std::back_inserter;
32 using std::find;
33
34 extern LyXAction lyxaction;
35
36
37 MiniBuffer::MiniBuffer(LyXView * o)
38         : information_displayed_(false), owner_(o)
39 {
40         timer = new Timeout(6000);
41         timer->timeout.connect(boost::bind(&MiniBuffer::message_timeout, this));
42         
43         information_timer_ = new Timeout(1500);
44         information_timer_->timeout.connect(boost::bind(&MiniBuffer::restore_input, this));
45 }
46
47
48 MiniBuffer::~MiniBuffer()
49 {
50         delete timer;
51         delete information_timer_;
52 }
53
54
55 void MiniBuffer::show_information(string const & info, string const & input)
56 {
57         stored_input = input;
58         information_displayed_ = true;
59         information_timer_->start();
60         set_input(info);
61 }
62
63
64 void MiniBuffer::restore_input()
65 {
66         if (information_displayed_) {
67                 information_displayed_ = false;
68                 set_input(stored_input);
69         }
70 }
71
72
73 void MiniBuffer::message(string const & str)
74 {
75         timer->restart();
76         string const ntext = strip(str);
77         if (! isEditingMode()) {
78                 set_input(ntext);
79                 text = ntext;
80         }
81 }
82
83
84 void MiniBuffer::messagePush(string const & str)
85 {
86         text_stored = text;
87         message(str);
88 }
89
90
91 void MiniBuffer::messagePop()
92 {
93         if (!text_stored.empty()) {
94                 message(text_stored);
95                 text_stored.erase();
96         }
97 }
98
99
100 void MiniBuffer::addSet(string const & s1)
101 {
102         string const str = text + ' ' +  s1;
103         message(str);
104 }
105
106
107 void MiniBuffer::prepareForInput(vector<string> const & completion,
108                                  vector<string> & history)
109 {
110         completion_ = completion;
111         history_ = &history;
112         hist_iter = history_->end();
113         text.erase();
114         set_input("");
115         editingMode();
116 }
117
118
119 void MiniBuffer::message_timeout()
120 {
121         // If we have focus, we don't want to change anything.
122         if (isEditingMode())
123                 return;
124         
125         timeout();
126         // we have redraw problems therefor we don't stop the
127         // timer as so we force a redraw every 6 seconds.
128         //      timer->stop();
129 }
130
131
132 void MiniBuffer::set_complete_input(string const & str)
133 {
134         if (!str.empty()) {
135                 // add a space so the user can type
136                 // an argument immediately
137                 set_input(str + " ");
138         }
139 }