add autocompletion support to fbrun
This commit is contained in:
parent
d741b6fe6e
commit
e85dc01d28
4 changed files with 20 additions and 1 deletions
|
@ -69,6 +69,9 @@ OPTIONS
|
||||||
*-preselect*::
|
*-preselect*::
|
||||||
Select the preset text given by the *-text* parameter
|
Select the preset text given by the *-text* parameter
|
||||||
|
|
||||||
|
*-autocomplete*::
|
||||||
|
Complete on typing. You can also set the FBRUN_AUTOCOMPLETE environment (to any value)
|
||||||
|
|
||||||
*-help*::
|
*-help*::
|
||||||
Show this help
|
Show this help
|
||||||
|
|
||||||
|
|
|
@ -244,7 +244,16 @@ void FbRun::keyPressEvent(XKeyEvent &ke) {
|
||||||
if (IsModifierKey(ks))
|
if (IsModifierKey(ks))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (FbTk::KeyUtil::instance().isolateModifierMask(ke.state)) { // a modifier key is down
|
if (m_autocomplete && isprint(keychar[0])) {
|
||||||
|
did_tab_complete = true;
|
||||||
|
if (m_completion_pos == std::string::npos) {
|
||||||
|
m_completion_pos = cursorPosition();
|
||||||
|
} else {
|
||||||
|
++m_completion_pos;
|
||||||
|
}
|
||||||
|
tabCompleteApps();
|
||||||
|
} else if (FbTk::KeyUtil::instance().isolateModifierMask(ke.state)) {
|
||||||
|
// a modifier key is down
|
||||||
if ((ke.state & ControlMask) == ControlMask) {
|
if ((ke.state & ControlMask) == ControlMask) {
|
||||||
switch (ks) {
|
switch (ks) {
|
||||||
case XK_p:
|
case XK_p:
|
||||||
|
|
|
@ -42,6 +42,7 @@ public:
|
||||||
void setTitle(const std::string &title);
|
void setTitle(const std::string &title);
|
||||||
void resize(unsigned int width, unsigned int height);
|
void resize(unsigned int width, unsigned int height);
|
||||||
void setPrint(bool print) { m_print = print; }
|
void setPrint(bool print) { m_print = print; }
|
||||||
|
void setAutocomplete(bool complete) { m_autocomplete = complete; }
|
||||||
|
|
||||||
/// load and reconfigure for new font
|
/// load and reconfigure for new font
|
||||||
bool loadFont(const std::string &fontname);
|
bool loadFont(const std::string &fontname);
|
||||||
|
@ -102,6 +103,7 @@ private:
|
||||||
int m_current_apps_item; ///< holds current position in apps-history
|
int m_current_apps_item; ///< holds current position in apps-history
|
||||||
|
|
||||||
size_t m_completion_pos;
|
size_t m_completion_pos;
|
||||||
|
bool m_autocomplete;
|
||||||
|
|
||||||
Cursor m_cursor;
|
Cursor m_cursor;
|
||||||
|
|
||||||
|
|
|
@ -65,6 +65,7 @@ void showUsage(const char *progname) {
|
||||||
" -bg [color name] Background color"<<endl<<
|
" -bg [color name] Background color"<<endl<<
|
||||||
" -na Disable antialias"<<endl<<
|
" -na Disable antialias"<<endl<<
|
||||||
" -hf [history file] History file to load (default ~/.fluxbox/fbrun_history)"<<endl<<
|
" -hf [history file] History file to load (default ~/.fluxbox/fbrun_history)"<<endl<<
|
||||||
|
" -autocomplete Complete on typing"<<endl<<
|
||||||
" -preselect Select preset text"<<endl<<
|
" -preselect Select preset text"<<endl<<
|
||||||
" -help Show this help"<<endl<<endl<<
|
" -help Show this help"<<endl<<endl<<
|
||||||
"Example: fbrun -fg black -bg white -text xterm -title \"run xterm\""<<endl;
|
"Example: fbrun -fg black -bg white -text xterm -title \"run xterm\""<<endl;
|
||||||
|
@ -78,6 +79,7 @@ int main(int argc, char **argv) {
|
||||||
bool near_mouse = false; // popup near mouse
|
bool near_mouse = false; // popup near mouse
|
||||||
bool print = false;
|
bool print = false;
|
||||||
bool preselect = false;
|
bool preselect = false;
|
||||||
|
bool autocomplete = getenv("FBRUN_AUTOCOMPLETE");
|
||||||
string fontname; // font name
|
string fontname; // font name
|
||||||
string title("Run program"); // default title
|
string title("Run program"); // default title
|
||||||
string text; // default input text
|
string text; // default input text
|
||||||
|
@ -119,6 +121,8 @@ int main(int argc, char **argv) {
|
||||||
history_file = argv[++i];
|
history_file = argv[++i];
|
||||||
} else if (strcmp(argv[i], "-preselect") == 0) {
|
} else if (strcmp(argv[i], "-preselect") == 0) {
|
||||||
preselect = true;
|
preselect = true;
|
||||||
|
} else if (strcmp(argv[i], "-autocomplete") == 0) {
|
||||||
|
autocomplete = true;
|
||||||
} else if (arg == "-h" || arg == "-help" || arg == "--help") {
|
} else if (arg == "-h" || arg == "-help" || arg == "--help") {
|
||||||
showUsage(argv[0]);
|
showUsage(argv[0]);
|
||||||
exit(0);
|
exit(0);
|
||||||
|
@ -136,6 +140,7 @@ int main(int argc, char **argv) {
|
||||||
FbRun fbrun;
|
FbRun fbrun;
|
||||||
|
|
||||||
fbrun.setPrint(print);
|
fbrun.setPrint(print);
|
||||||
|
fbrun.setAutocomplete(autocomplete);
|
||||||
|
|
||||||
if (fontname.size() != 0) {
|
if (fontname.size() != 0) {
|
||||||
if (!fbrun.loadFont(fontname.c_str())) {
|
if (!fbrun.loadFont(fontname.c_str())) {
|
||||||
|
|
Loading…
Reference in a new issue