Add new system executable completion mode to kurlcompletion

git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdelibs@1258882 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
v3.5.13-sru
tpearson 13 years ago
parent 80f78d20c3
commit 715433c853

@ -620,6 +620,18 @@ TQString KURLCompletion::makeCompletion(const TQString &text)
if ( urlCompletion( url, &match ) )
return match;
}
else if ( d->mode == SystemExeCompletion ) {
// Executables
//
if ( systemexeCompletion( url, &match ) )
return match;
// KRun can run "man:" and "info:" etc. so why not treat them
// as executables...
if ( urlCompletion( url, &match ) )
return match;
}
else {
// Local files, directories
//
@ -874,6 +886,66 @@ bool KURLCompletion::exeCompletion(const MyURL &url, TQString *match)
return true;
}
//////////////////////////////////////////////////
//////////////////////////////////////////////////
// System Executables
//
bool KURLCompletion::systemexeCompletion(const MyURL &url, TQString *match)
{
if ( url.protocol() != "file" )
return false;
TQString dir = url.dir();
dir = unescape( dir ); // remove escapes
// Find directories to search for completions, either
//
// 1. complete path given in url
// 2. current directory (d->cwd)
// 3. $PATH
// 4. no directory at all
TQStringList dirList;
if ( !url.file().isEmpty() ) {
// $PATH
dirList = TQStringList::split(KPATH_SEPARATOR,
TQString::fromLocal8Bit(::getenv("PATH")));
TQStringList::Iterator it = dirList.begin();
for ( ; it != dirList.end(); it++ )
(*it).append('/');
}
// No hidden files unless the user types "."
bool no_hidden_files = url.file().tqat(0) != '.';
// List files if needed
//
if ( !isListedURL( CTExe, dir, url.file(), no_hidden_files ) )
{
stop();
clear();
setListedURL( CTExe, dir, url.file(), no_hidden_files );
*match = listDirectories( dirList, url.file(), true, false, no_hidden_files );
}
else if ( !isRunning() ) {
*match = finished();
}
else {
if ( d->dirListThread )
setListedURL( CTExe, dir, url.file(), no_hidden_files );
*match = TQString::null;
}
return true;
}
//////////////////////////////////////////////////
//////////////////////////////////////////////////
// Local files

@ -50,7 +50,7 @@ public:
* are listed using KIO.
* @li DirCompletion - Same as FileCompletion but only returns directories.
*/
enum Mode { ExeCompletion=1, FileCompletion, DirCompletion };
enum Mode { ExeCompletion=1, FileCompletion, DirCompletion, SystemExeCompletion };
/**
* Constructs a KURLCompletion object in FileCompletion mode.
@ -186,6 +186,7 @@ private:
bool userCompletion(const MyURL &url, TQString *match);
bool envCompletion(const MyURL &url, TQString *match);
bool exeCompletion(const MyURL &url, TQString *match);
bool systemexeCompletion(const MyURL &url, TQString *match);
bool fileCompletion(const MyURL &url, TQString *match);
bool urlCompletion(const MyURL &url, TQString *match);

Loading…
Cancel
Save