diff options
author | fluxgen <fluxgen> | 2004-04-22 21:01:58 (GMT) |
---|---|---|
committer | fluxgen <fluxgen> | 2004-04-22 21:01:58 (GMT) |
commit | 9fce121737324aaec75c5adfa3ccbd602a543551 (patch) | |
tree | f5999768bdcff069fce3597cf9ea6bd84087bf55 /util/fbrun | |
parent | 217af49664365c485b7d610808ba2a83e74f4972 (diff) | |
download | fluxbox-9fce121737324aaec75c5adfa3ccbd602a543551.zip fluxbox-9fce121737324aaec75c5adfa3ccbd602a543551.tar.bz2 |
path completion, and load apps on first tab press, patch from Mathias Gumz
Diffstat (limited to 'util/fbrun')
-rw-r--r-- | util/fbrun/FbRun.cc | 133 |
1 files changed, 91 insertions, 42 deletions
diff --git a/util/fbrun/FbRun.cc b/util/fbrun/FbRun.cc index 8e8e1c0..025440a 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.29 2004/04/21 14:58:44 rathnor Exp $ | 22 | // $Id: FbRun.cc,v 1.30 2004/04/22 21:01:58 fluxgen Exp $ |
23 | 23 | ||
24 | #include "FbRun.hh" | 24 | #include "FbRun.hh" |
25 | 25 | ||
@@ -99,38 +99,6 @@ FbRun::FbRun(int x, int y, size_t width): | |||
99 | XSetWMHints(m_display, window(), &wmhints); | 99 | XSetWMHints(m_display, window(), &wmhints); |
100 | } | 100 | } |
101 | 101 | ||
102 | string path= getenv("PATH"); | ||
103 | unsigned int l; | ||
104 | unsigned int r; | ||
105 | FbTk::Directory dir; | ||
106 | |||
107 | for(l= 0, r= 0; r < path.size(); r++) { | ||
108 | if ((path[r]==':' || r == path.size() - 1) && r - l > 0) { | ||
109 | |||
110 | string filename; | ||
111 | string fncomplete; | ||
112 | dir.open(path.substr(l, r - l).c_str()); | ||
113 | int n= dir.entries(); | ||
114 | if (n >= 0) { | ||
115 | while(n--) { | ||
116 | filename= dir.readFilename(); | ||
117 | fncomplete= dir.name() + "/" + filename; | ||
118 | if (dir.isRegularFile(fncomplete) && | ||
119 | dir.isExecutable(fncomplete)) { | ||
120 | m_apps.push_back(filename); | ||
121 | } | ||
122 | } | ||
123 | } | ||
124 | l= r + 1; | ||
125 | dir.close(); | ||
126 | } | ||
127 | } | ||
128 | |||
129 | sort(m_apps.begin(), m_apps.end()); | ||
130 | unique(m_apps.begin(), m_apps.end()); | ||
131 | |||
132 | if (!m_apps.empty()) | ||
133 | m_current_apps_item= 1; | ||
134 | } | 102 | } |
135 | 103 | ||
136 | 104 | ||
@@ -374,22 +342,103 @@ void FbRun::tabCompleteHistory() { | |||
374 | } | 342 | } |
375 | 343 | ||
376 | void FbRun::tabCompleteApps() { | 344 | void FbRun::tabCompleteApps() { |
377 | if ( m_current_apps_item == 0 || m_apps.empty() ) { | 345 | |
346 | static bool first_run= true; | ||
347 | static string saved_prefix= ""; | ||
348 | string prefix= text().substr(0, cursorPosition()); | ||
349 | FbTk::Directory dir; | ||
350 | |||
351 | bool add_dirs= false; | ||
352 | bool changed_prefix= false; | ||
353 | |||
354 | // (re)build m_apps-container | ||
355 | if (first_run || saved_prefix != prefix) { | ||
356 | first_run= false; | ||
357 | |||
358 | string path; | ||
359 | |||
360 | if(!prefix.empty() && prefix[0] =='/') { | ||
361 | size_t rseparator= prefix.find_last_of("/"); | ||
362 | path= prefix.substr(0, rseparator + 1) + ":"; | ||
363 | add_dirs= true; | ||
364 | } else | ||
365 | path= getenv("PATH"); | ||
366 | |||
367 | m_apps.clear(); | ||
368 | |||
369 | unsigned int l; | ||
370 | unsigned int r; | ||
371 | |||
372 | for(l= 0, r= 0; r < path.size(); r++) { | ||
373 | if ((path[r]==':' || r == path.size() - 1) && r - l > 0) { | ||
374 | string filename; | ||
375 | string fncomplete; | ||
376 | dir.open(path.substr(l, r - l).c_str()); | ||
377 | int n= dir.entries(); | ||
378 | if (n >= 0) { | ||
379 | while(n--) { | ||
380 | filename= dir.readFilename(); | ||
381 | fncomplete= dir.name() + | ||
382 | (*dir.name().rbegin() != '/' ? "/" : "") + | ||
383 | filename; | ||
384 | |||
385 | // directories in dirmode ? | ||
386 | if (add_dirs && dir.isDirectory(fncomplete) && | ||
387 | filename != ".." && filename != ".") { | ||
388 | m_apps.push_back(fncomplete); | ||
389 | // executables in dirmode ? | ||
390 | } else if (add_dirs && dir.isRegularFile(fncomplete) && | ||
391 | dir.isExecutable(fncomplete) && | ||
392 | (prefix == "" || | ||
393 | fncomplete.substr(0, prefix.size()) == prefix)) { | ||
394 | m_apps.push_back(fncomplete); | ||
395 | // executables in $PATH ? | ||
396 | } else if (dir.isRegularFile(fncomplete) && | ||
397 | dir.isExecutable(fncomplete) && | ||
398 | (prefix == "" || | ||
399 | filename.substr(0, prefix.size()) == prefix)) { | ||
400 | m_apps.push_back(filename); | ||
401 | } | ||
402 | } | ||
403 | } | ||
404 | l= r + 1; | ||
405 | dir.close(); | ||
406 | } | ||
407 | } | ||
408 | sort(m_apps.begin(), m_apps.end()); | ||
409 | unique(m_apps.begin(), m_apps.end()); | ||
410 | |||
411 | saved_prefix= prefix; | ||
412 | changed_prefix= true; | ||
413 | m_current_apps_item= 0; | ||
414 | } | ||
415 | |||
416 | if (m_apps.empty() ) { | ||
378 | XBell(m_display, 0); | 417 | XBell(m_display, 0); |
379 | } else { | 418 | } else { |
380 | size_t apps_item = m_current_apps_item + 1; | 419 | size_t apps_item = m_current_apps_item + (changed_prefix ? 0 : 1); |
381 | string prefix = text().substr(0, cursorPosition()); | 420 | bool loop= false; |
382 | while (apps_item != m_current_apps_item) { | 421 | |
383 | if (apps_item > m_apps.size() ) | 422 | while (true) { |
384 | apps_item = 1; | 423 | if (apps_item >= m_apps.size() ) { |
385 | if (m_apps[apps_item - 1].find(prefix) == 0) { | 424 | loop = true; |
425 | apps_item = 0; | ||
426 | } | ||
427 | |||
428 | if ((!changed_prefix || loop) && apps_item == m_current_apps_item) { | ||
429 | break; | ||
430 | } | ||
431 | if (m_apps[apps_item].find(prefix) == 0) { | ||
386 | m_current_apps_item = apps_item; | 432 | m_current_apps_item = apps_item; |
387 | setText(m_apps[m_current_apps_item - 1]); | 433 | if (FbTk::Directory::isDirectory(m_apps[m_current_apps_item])) |
434 | setText(m_apps[m_current_apps_item] + "/"); | ||
435 | else | ||
436 | setText(m_apps[m_current_apps_item]); | ||
388 | break; | 437 | break; |
389 | } | 438 | } |
390 | apps_item++; | 439 | apps_item++; |
391 | } | 440 | } |
392 | if (apps_item == m_current_apps_item) | 441 | if (!changed_prefix && apps_item == m_current_apps_item) |
393 | XBell(m_display, 0); | 442 | XBell(m_display, 0); |
394 | } | 443 | } |
395 | } | 444 | } |