diff options
author | simonb <simonb> | 2006-04-25 02:42:05 (GMT) |
---|---|---|
committer | simonb <simonb> | 2006-04-25 02:42:05 (GMT) |
commit | cb65dae95fb3bd01cb4e43286ba2a56c41838d2e (patch) | |
tree | 8e0aba840aed873956b2c061c1d631b76577bd33 | |
parent | 3707b74c40256c09465171d39e2c4d95aeaefb0e (diff) | |
download | fluxbox_lack-cb65dae95fb3bd01cb4e43286ba2a56c41838d2e.zip fluxbox_lack-cb65dae95fb3bd01cb4e43286ba2a56c41838d2e.tar.bz2 |
fbrun: Move the cursor to the end when tab completing
+ thanks Jonas Koelker, sf.net rfe #1333003, patch #1475578
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | util/fbrun/FbRun.cc | 33 | ||||
-rw-r--r-- | util/fbrun/FbRun.hh | 1 |
3 files changed, 27 insertions, 10 deletions
@@ -1,6 +1,9 @@ | |||
1 | (Format: Year/Month/Day) | 1 | (Format: Year/Month/Day) |
2 | Changes for 0.9.16: | 2 | Changes for 0.9.16: |
3 | *06/04/25: | 3 | *06/04/25: |
4 | * fbrun: Move the cursor to the end when tab completing | ||
5 | (Simon + thanks Jonas Koelker), sf.net rfe #1333003, patch #1475578 | ||
6 | util/fbrun/FbRun.hh/cc | ||
4 | * Fix up comments for doxygen (Thanks Jonas Koelker) | 7 | * Fix up comments for doxygen (Thanks Jonas Koelker) |
5 | Screen.cc CommandParser.cc Container.hh fluxbox.hh Workspace.hh | 8 | Screen.cc CommandParser.cc Container.hh fluxbox.hh Workspace.hh |
6 | ArrowButton.hh FbTk/Texture.cc FbTk/ThemeItems.cc FbTk/Texture.hh | 9 | ArrowButton.hh FbTk/Texture.cc FbTk/ThemeItems.cc FbTk/Texture.hh |
diff --git a/util/fbrun/FbRun.cc b/util/fbrun/FbRun.cc index 41c7474..7392083 100644 --- a/util/fbrun/FbRun.cc +++ b/util/fbrun/FbRun.cc | |||
@@ -64,6 +64,7 @@ FbRun::FbRun(int x, int y, size_t width): | |||
64 | m_gc(*this), | 64 | m_gc(*this), |
65 | m_end(false), | 65 | m_end(false), |
66 | m_current_history_item(0), | 66 | m_current_history_item(0), |
67 | m_last_completion_prefix(""), | ||
67 | m_current_apps_item(0), | 68 | m_current_apps_item(0), |
68 | m_cursor(XCreateFontCursor(FbTk::App::instance()->display(), XC_xterm)) { | 69 | m_cursor(XCreateFontCursor(FbTk::App::instance()->display(), XC_xterm)) { |
69 | 70 | ||
@@ -222,10 +223,11 @@ void FbRun::redrawLabel() { | |||
222 | } | 223 | } |
223 | 224 | ||
224 | void FbRun::keyPressEvent(XKeyEvent &ke) { | 225 | void FbRun::keyPressEvent(XKeyEvent &ke) { |
225 | 226 | // reset last completion prefix if we don't do a tab completion thing | |
227 | bool did_tab_complete = false; | ||
228 | |||
226 | ke.state = FbTk::KeyUtil::instance().cleanMods(ke.state); | 229 | ke.state = FbTk::KeyUtil::instance().cleanMods(ke.state); |
227 | 230 | ||
228 | int cp= cursorPosition(); | ||
229 | FbTk::TextBox::keyPressEvent(ke); | 231 | FbTk::TextBox::keyPressEvent(ke); |
230 | KeySym ks; | 232 | KeySym ks; |
231 | char keychar[1]; | 233 | char keychar[1]; |
@@ -238,22 +240,26 @@ void FbRun::keyPressEvent(XKeyEvent &ke) { | |||
238 | if ((ke.state & ControlMask) == ControlMask) { | 240 | if ((ke.state & ControlMask) == ControlMask) { |
239 | switch (ks) { | 241 | switch (ks) { |
240 | case XK_p: | 242 | case XK_p: |
243 | did_tab_complete = true; | ||
241 | prevHistoryItem(); | 244 | prevHistoryItem(); |
242 | break; | 245 | break; |
243 | case XK_n: | 246 | case XK_n: |
247 | did_tab_complete = true; | ||
244 | nextHistoryItem(); | 248 | nextHistoryItem(); |
245 | break; | 249 | break; |
246 | case XK_Tab: | 250 | case XK_Tab: |
251 | did_tab_complete = true; | ||
247 | tabCompleteHistory(); | 252 | tabCompleteHistory(); |
248 | setCursorPosition(cp); | ||
249 | break; | 253 | break; |
250 | } | 254 | } |
251 | } else if ((ke.state & (Mod1Mask|ShiftMask)) == (Mod1Mask | ShiftMask)) { | 255 | } else if ((ke.state & (Mod1Mask|ShiftMask)) == (Mod1Mask | ShiftMask)) { |
252 | switch (ks) { | 256 | switch (ks) { |
253 | case XK_less: | 257 | case XK_less: |
258 | did_tab_complete = true; | ||
254 | firstHistoryItem(); | 259 | firstHistoryItem(); |
255 | break; | 260 | break; |
256 | case XK_greater: | 261 | case XK_greater: |
262 | did_tab_complete = true; | ||
257 | lastHistoryItem(); | 263 | lastHistoryItem(); |
258 | break; | 264 | break; |
259 | } | 265 | } |
@@ -276,12 +282,14 @@ void FbRun::keyPressEvent(XKeyEvent &ke) { | |||
276 | nextHistoryItem(); | 282 | nextHistoryItem(); |
277 | break; | 283 | break; |
278 | case XK_Tab: | 284 | case XK_Tab: |
285 | did_tab_complete = true; | ||
279 | tabCompleteApps(); | 286 | tabCompleteApps(); |
280 | setCursorPosition(cp); | ||
281 | break; | 287 | break; |
282 | } | 288 | } |
283 | } | 289 | } |
284 | clear(); | 290 | clear(); |
291 | if (!did_tab_complete) | ||
292 | m_last_completion_prefix = ""; | ||
285 | } | 293 | } |
286 | 294 | ||
287 | void FbRun::lockPosition(bool size_too) { | 295 | void FbRun::lockPosition(bool size_too) { |
@@ -347,11 +355,14 @@ void FbRun::tabCompleteHistory() { | |||
347 | } else { | 355 | } else { |
348 | unsigned int nr= 0; | 356 | unsigned int nr= 0; |
349 | unsigned int history_item = m_current_history_item - 1; | 357 | unsigned int history_item = m_current_history_item - 1; |
350 | string prefix = text().substr(0, textStartPos() + cursorPosition()); | 358 | if (m_last_completion_prefix.empty()) |
359 | m_last_completion_prefix = text().substr(0, textStartPos() + cursorPosition()); | ||
360 | |||
351 | while (history_item != m_current_history_item && nr++ < m_history.size()) { | 361 | while (history_item != m_current_history_item && nr++ < m_history.size()) { |
352 | if (m_history[history_item].find(prefix) == 0) { | 362 | if (m_history[history_item].find(m_last_completion_prefix) == 0) { |
353 | m_current_history_item = history_item; | 363 | m_current_history_item = history_item; |
354 | setText(m_history[m_current_history_item]); | 364 | setText(m_history[m_current_history_item]); |
365 | cursorEnd(); | ||
355 | break; | 366 | break; |
356 | } | 367 | } |
357 | if (history_item == 0) // loop | 368 | if (history_item == 0) // loop |
@@ -365,15 +376,16 @@ void FbRun::tabCompleteHistory() { | |||
365 | void FbRun::tabCompleteApps() { | 376 | void FbRun::tabCompleteApps() { |
366 | 377 | ||
367 | static bool first_run= true; | 378 | static bool first_run= true; |
368 | static string saved_prefix= ""; | 379 | if (m_last_completion_prefix.empty()) |
369 | string prefix= text().substr(0, textStartPos() + cursorPosition()); | 380 | m_last_completion_prefix = text().substr(0, textStartPos() + cursorPosition()); |
381 | string prefix = m_last_completion_prefix; | ||
370 | FbTk::Directory dir; | 382 | FbTk::Directory dir; |
371 | 383 | ||
372 | bool add_dirs= false; | 384 | bool add_dirs= false; |
373 | bool changed_prefix= false; | 385 | bool changed_prefix= false; |
374 | 386 | ||
375 | // (re)build m_apps-container | 387 | // (re)build m_apps-container |
376 | if (first_run || saved_prefix != prefix) { | 388 | if (first_run || m_last_completion_prefix != prefix) { |
377 | first_run= false; | 389 | first_run= false; |
378 | 390 | ||
379 | string path; | 391 | string path; |
@@ -430,7 +442,7 @@ void FbRun::tabCompleteApps() { | |||
430 | sort(m_apps.begin(), m_apps.end()); | 442 | sort(m_apps.begin(), m_apps.end()); |
431 | unique(m_apps.begin(), m_apps.end()); | 443 | unique(m_apps.begin(), m_apps.end()); |
432 | 444 | ||
433 | saved_prefix= prefix; | 445 | m_last_completion_prefix = prefix; |
434 | changed_prefix= true; | 446 | changed_prefix= true; |
435 | m_current_apps_item= 0; | 447 | m_current_apps_item= 0; |
436 | } | 448 | } |
@@ -456,6 +468,7 @@ void FbRun::tabCompleteApps() { | |||
456 | setText(m_apps[m_current_apps_item] + "/"); | 468 | setText(m_apps[m_current_apps_item] + "/"); |
457 | else | 469 | else |
458 | setText(m_apps[m_current_apps_item]); | 470 | setText(m_apps[m_current_apps_item]); |
471 | cursorEnd(); | ||
459 | break; | 472 | break; |
460 | } | 473 | } |
461 | apps_item++; | 474 | apps_item++; |
diff --git a/util/fbrun/FbRun.hh b/util/fbrun/FbRun.hh index f34f691..9d2705e 100644 --- a/util/fbrun/FbRun.hh +++ b/util/fbrun/FbRun.hh | |||
@@ -93,6 +93,7 @@ private: | |||
93 | std::vector<std::string> m_history; ///< history list of commands | 93 | std::vector<std::string> m_history; ///< history list of commands |
94 | std::string m_history_file; ///< holds filename for command history file | 94 | std::string m_history_file; ///< holds filename for command history file |
95 | size_t m_current_history_item; ///< holds current position in command history | 95 | size_t m_current_history_item; ///< holds current position in command history |
96 | std::string m_last_completion_prefix; ///< last prefix we completed on | ||
96 | 97 | ||
97 | typedef std::vector<std::string> AppsContainer; | 98 | typedef std::vector<std::string> AppsContainer; |
98 | typedef AppsContainer::iterator AppsContainerIt; | 99 | typedef AppsContainer::iterator AppsContainerIt; |