aboutsummaryrefslogtreecommitdiff
path: root/util/fbrun/FbRun.cc
diff options
context:
space:
mode:
authorfluxgen <fluxgen>2002-11-12 19:20:31 (GMT)
committerfluxgen <fluxgen>2002-11-12 19:20:31 (GMT)
commit4897fc22888c52ba28af48e9bc57465a86ea3d2e (patch)
treea20ea83cc7768ac187299bddb729d6d9a873fdbd /util/fbrun/FbRun.cc
parentd1292fc5999ec46c2bab9645675bdda11b2d9b04 (diff)
downloadfluxbox_pavel-4897fc22888c52ba28af48e9bc57465a86ea3d2e.zip
fluxbox_pavel-4897fc22888c52ba28af48e9bc57465a86ea3d2e.tar.bz2
added history
Diffstat (limited to 'util/fbrun/FbRun.cc')
-rw-r--r--util/fbrun/FbRun.cc72
1 files changed, 69 insertions, 3 deletions
diff --git a/util/fbrun/FbRun.cc b/util/fbrun/FbRun.cc
index 2042c17..6a0e6d8 100644
--- a/util/fbrun/FbRun.cc
+++ b/util/fbrun/FbRun.cc
@@ -19,7 +19,7 @@
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE. 20// DEALINGS IN THE SOFTWARE.
21 21
22// $Id: FbRun.cc,v 1.3 2002/11/12 17:10:13 fluxgen Exp $ 22// $Id: FbRun.cc,v 1.4 2002/11/12 19:20:31 fluxgen Exp $
23 23
24#include "FbRun.hh" 24#include "FbRun.hh"
25 25
@@ -32,6 +32,7 @@
32#include <unistd.h> 32#include <unistd.h>
33 33
34#include <iostream> 34#include <iostream>
35#include <fstream>
35 36
36using namespace std; 37using namespace std;
37FbRun::FbRun(int x, int y, size_t width): 38FbRun::FbRun(int x, int y, size_t width):
@@ -40,7 +41,8 @@ m_win(None),
40m_display(BaseDisplay::getXDisplay()), 41m_display(BaseDisplay::getXDisplay()),
41m_bevel(4), 42m_bevel(4),
42m_gc(DefaultGC(m_display, DefaultScreen(m_display))), 43m_gc(DefaultGC(m_display, DefaultScreen(m_display))),
43m_end(false) { 44m_end(false),
45m_current_history_item(0) {
44 createWindow(x, y, width + m_bevel, m_font.height()); 46 createWindow(x, y, width + m_bevel, m_font.height());
45} 47}
46 48
@@ -57,11 +59,46 @@ void FbRun::run(const std::string &command) {
57 exit(0); //exit fork 59 exit(0); //exit fork
58 } 60 }
59 61
60 hide(); 62 hide(); // hide gui
63
64 // save command history to file
65 if (m_runtext.size() != 0) { // no need to save empty command
66 // open file in append mode
67 ofstream outfile(m_history_file.c_str(), ios::app);
68 if (outfile)
69 outfile<<m_runtext<<endl;
70 else
71 cerr<<"FbRun Warning: Can't write command history to file: "<<m_history_file<<endl;
72 }
61 73
62 m_end = true; // mark end of processing 74 m_end = true; // mark end of processing
63} 75}
64 76
77bool FbRun::loadHistory(const char *filename) {
78 if (filename == 0)
79 return false;
80 ifstream infile(filename);
81 if (!infile) {
82 //even though we fail to load file, we should try save to it
83 m_history_file = filename;
84 return false;
85 }
86 // clear old history and load new one from file
87 m_history.clear();
88 // each line is a command
89 string line;
90 while (!infile.eof()) {
91 getline(infile, line);
92 if (line.size()) // don't add empty lines
93 m_history.push_back(line);
94 }
95 // set no current histor to display
96 m_current_history_item = m_history.size();
97 // set history file
98 m_history_file = filename;
99 return true;
100}
101
65bool FbRun::loadFont(const string &fontname) { 102bool FbRun::loadFont(const string &fontname) {
66 if (!m_font.load(fontname.c_str())) 103 if (!m_font.load(fontname.c_str()))
67 return false; 104 return false;
@@ -171,6 +208,16 @@ void FbRun::handleEvent(XEvent * const xev) {
171 } else if (! IsModifierKey(ks) && !IsCursorKey(ks)) { 208 } else if (! IsModifierKey(ks) && !IsCursorKey(ks)) {
172 m_runtext+=keychar[0]; // append character 209 m_runtext+=keychar[0]; // append character
173 redrawLabel(); 210 redrawLabel();
211 } else if (IsCursorKey(ks)) {
212 switch (ks) {
213 case XK_Up:
214 prevHistoryItem();
215 break;
216 case XK_Down:
217 nextHistoryItem();
218 break;
219 }
220 redrawLabel();
174 } 221 }
175 } break; 222 } break;
176 case Expose: 223 case Expose:
@@ -203,3 +250,22 @@ void FbRun::setNoMaximize() {
203 sh.min_height = height; 250 sh.min_height = height;
204 XSetWMNormalHints(m_display, m_win, &sh); 251 XSetWMNormalHints(m_display, m_win, &sh);
205} 252}
253
254void FbRun::prevHistoryItem() {
255
256 if (m_current_history_item > 0 && m_history.size() > 0)
257 m_current_history_item--;
258 if (m_current_history_item < m_history.size())
259 m_runtext = m_history[m_current_history_item];
260}
261
262void FbRun::nextHistoryItem() {
263 m_current_history_item++;
264 if (m_current_history_item >= m_history.size()) {
265 m_current_history_item = m_history.size();
266 m_runtext = "";
267 return;
268 } else
269 m_runtext = m_history[m_current_history_item];
270
271}