From baaf477d46e619127b91faf59be2cf2c2c95afff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20L=C3=BCbking?= Date: Sat, 23 Jul 2016 16:39:44 +0200 Subject: [PATCH] add support for dedicated completion data This allows to complete random things, useful along the -print flag but also to limit the commands to those found my menumaker etc. --- doc/asciidoc/fbrun.txt | 4 ++++ util/fbrun/FbRun.cc | 19 ++++++++++++++++++- util/fbrun/FbRun.hh | 1 + util/fbrun/main.cc | 10 ++++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/doc/asciidoc/fbrun.txt b/doc/asciidoc/fbrun.txt index 113f79ea..cc790f9d 100644 --- a/doc/asciidoc/fbrun.txt +++ b/doc/asciidoc/fbrun.txt @@ -69,6 +69,10 @@ OPTIONS *-hf* 'filename':: History file to load. The default is *~/.fluxbox/fbrun_history*. +*-cf* 'filename':: + Completion data to load. The default is empty. If no data can be loaded, + completion defaults to executables in $PATH + *-preselect*:: Select the preset text given by the *-text* parameter diff --git a/util/fbrun/FbRun.cc b/util/fbrun/FbRun.cc index 321959e6..b6971873 100644 --- a/util/fbrun/FbRun.cc +++ b/util/fbrun/FbRun.cc @@ -214,6 +214,23 @@ bool FbRun::loadHistory(const char *filename) { return true; } +bool FbRun::loadCompletion(const char *filename) { + if (!filename) + return false; + ifstream infile(filename); + if (!infile) + return false; + + m_apps.clear(); + string line; + while (getline(infile, line)) { + if (!line.empty()) // don't add empty lines + m_apps.push_back(line); + } + return true; +} + + bool FbRun::loadFont(const string &fontname) { if (!m_font.load(fontname.c_str())) return false; @@ -472,7 +489,7 @@ void FbRun::tabCompleteApps() { tabComplete(m_files, m_current_files_item); } else { static bool first_run = true; - if (first_run) { + if (first_run && m_apps.empty()) { first_run = false; std::string path = getenv("PATH"); FbTk::Directory dir; diff --git a/util/fbrun/FbRun.hh b/util/fbrun/FbRun.hh index f0915b05..e351d28d 100644 --- a/util/fbrun/FbRun.hh +++ b/util/fbrun/FbRun.hh @@ -58,6 +58,7 @@ public: @return true on success, else false */ bool loadHistory(const char *filename); + bool loadCompletion(const char *filename); /** @name events */ diff --git a/util/fbrun/main.cc b/util/fbrun/main.cc index 4022ef69..a8655ab4 100644 --- a/util/fbrun/main.cc +++ b/util/fbrun/main.cc @@ -66,6 +66,7 @@ void showUsage(const char *progname) { " -bg [color name] Background color"<