Proper '/' on the end of directories in the find-file window.

git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@381 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2005-04-03 16:36:19 +00:00
parent fe11d1936d
commit 874e46fc64
15 changed files with 216 additions and 24 deletions
+36 -6
View File
@@ -26,22 +26,48 @@
#include <rak/algorithm.h>
#include "path_input.h"
#include "utils/file_stat.h"
namespace input {
PathInput::PathInput() {
PathInput::PathInput() :
m_showNext(false) {
}
bool
PathInput::pressed(int key) {
if (key == '\t')
receive_do_complete();
else
if (key != '\t') {
m_showNext = false;
return TextInput::pressed(key);
} else if (m_showNext) {
m_signalShowNext.emit();
} else {
receive_do_complete();
m_showNext = true;
}
return true;
}
struct _transform_filename {
_transform_filename(const std::string& base) : m_base(base) {}
void operator () (std::string& filename) {
utils::FileStat fs;
if (fs.update((m_base + filename).c_str()))
return;
else if (fs.is_directory())
filename += '/';
}
const std::string& m_base;
};
void
PathInput::receive_do_complete() {
size_type dirEnd = find_last_delim();
@@ -49,12 +75,13 @@ PathInput::receive_do_complete() {
utils::Directory dir(dirEnd != 0 ? str().substr(0, dirEnd) : "./");
if (!dir.update() || dir.empty()) {
str() += "!";
mark_dirty();
return;
}
std::for_each(dir.begin(), dir.end(), _transform_filename(str().substr(0, dirEnd)));
Range r = find_incomplete(dir, str().substr(dirEnd, get_pos()));
if (r.first == r.second)
@@ -71,7 +98,10 @@ PathInput::receive_do_complete() {
set_pos(dirEnd + base.size());
mark_dirty();
m_signalShowRange.emit(r.first, r.second);
// Only emit if there are more than one option.
if (++utils::Directory::iterator(r.first) != r.second)
m_signalShowRange.emit(r.first, r.second);
}
PathInput::size_type
+6 -1
View File
@@ -34,12 +34,14 @@ namespace input {
class PathInput : public TextInput {
public:
typedef std::pair<utils::Directory::iterator, utils::Directory::iterator> Range;
typedef sigc::signal0<void> Signal;
typedef sigc::signal2<void, utils::Directory::iterator, utils::Directory::iterator> SignalShowRange;
PathInput();
virtual ~PathInput() {}
SignalShowRange& signal_show_range() { return m_signalShowRange; }
Signal& signal_show_next() { return m_signalShowNext; }
SignalShowRange& signal_show_range() { return m_signalShowRange; }
virtual bool pressed(int key);
@@ -49,6 +51,9 @@ private:
size_type find_last_delim();
Range find_incomplete(utils::Directory& d, const std::string& f);
bool m_showNext;
Signal m_signalShowNext;
SignalShowRange m_signalShowRange;
};