Commit 67ae46c5 authored by Daniel Elstner's avatar Daniel Elstner
Browse files

:find_add_file): New method. Move the actual file-adding parts from

* src/filetree.{cc,h} (FileTree::find_add_file): New method.
Move the actual file-adding parts from find_check_file() here.
(FileTree::find_recursively): Move the file testing previously
done in find_check_file() into this method in order to make the
recursion more obvious.  Also handle Glib::Dir exceptions right
here, so that the caller doesn't have to handle them.
(FileTree::find_files): Remove the try/catch block enclosing the
call to find_recursively().  We no longer need to do it twice.
(FileTree::find_check_file): Remove.
parent 54442e33
2004-06-08 Daniel Elstner <daniel.elstner@gmx.net>
* src/filetree.{cc,h} (FileTree::find_add_file): New method.
Move the actual file-adding parts from find_check_file() here.
(FileTree::find_recursively): Move the file testing previously
done in find_check_file() into this method in order to make the
recursion more obvious. Also handle Glib::Dir exceptions right
here, so that the caller doesn't have to handle them.
(FileTree::find_files): Remove the try/catch block enclosing the
call to find_recursively(). We no longer need to do it twice.
(FileTree::find_check_file): Remove.
2004-06-03 Daniel Elstner <daniel.elstner@gmx.net>
* src/filetree.cc (FileTree::calculate_file_index): Simplify.
......
......@@ -146,14 +146,7 @@ void FileTree::find_files(const std::string& dirname, Pcre::Pattern& pattern,
if (modified_count_changed)
signal_modified_count_changed(); // emit
try
{
find_recursively(dirname, find_data);
}
catch (const Glib::FileError& error)
{
find_data.error_list->push_back(error.what()); // collect errors but don't fail
}
find_recursively(dirname, find_data);
// Work around a strange misbehavior: the tree is kept sorted while the
// file search is in progress, which causes the scroll offset to change
......@@ -387,91 +380,85 @@ void FileTree::find_recursively(const std::string& dirname, FindData& find_data)
{
using namespace Glib;
int file_count = 0;
Dir dir (dirname);
for (Dir::iterator pos = dir.begin(); pos != dir.end(); ++pos)
try
{
if (signal_pulse()) // emit
break;
const std::string basename = *pos;
if (!find_data.hidden && *basename.begin() == '.')
continue;
const std::string fullname = build_filename(dirname, basename);
int file_count = 0;
Dir dir (dirname);
try
{
if (find_check_file(basename, fullname, find_data)) // file added?
++file_count;
}
catch (const Glib::FileError& error)
for (Dir::iterator pos = dir.begin(); pos != dir.end(); ++pos)
{
// Collect errors but don't interrupt the search.
find_data.error_list->push_back(error.what());
}
}
if (signal_pulse()) // emit
break;
find_increment_file_count(find_data, file_count);
}
const std::string basename = *pos;
bool FileTree::find_check_file(const std::string& basename, const std::string& fullname,
FindData& find_data)
{
using namespace Glib;
if (file_test(fullname, FILE_TEST_IS_SYMLINK))
return false;
if (find_data.recursive && file_test(fullname, FILE_TEST_IS_DIR))
{
// Put the directory name on the stack instead of creating a new node
// immediately. The corresponding node will be created on demand if
// there's actually a matching file in the directory or one of its
// subdirectories.
//
ScopedPushDir pushdir (find_data.dirstack, basename);
find_recursively(fullname, find_data); // recurse
}
else if (file_test(fullname, FILE_TEST_IS_REGULAR))
{
const ustring basename_utf8 = Util::filename_to_utf8_fallback(basename);
if (!find_data.hidden && *basename.begin() == '.')
continue;
if (find_data.pattern.match(basename_utf8) > 0)
{
// Build the collate key with a leading '1' so that directories always
// come first (they have a leading '0'). This is simpler and faster
// than explicitely checking for directories in the sort function.
std::string collate_key (1, '1');
collate_key += basename_utf8.collate_key();
const std::string fullname = build_filename(dirname, basename);
Gtk::TreeModel::Row row;
if (file_test(fullname, FILE_TEST_IS_SYMLINK))
continue; // ignore symbolic links
if (find_data.dirstack.empty())
if (find_data.recursive && file_test(fullname, FILE_TEST_IS_DIR))
{
row = *treestore_->prepend(); // new toplevel node
// Put the directory name on the stack instead of creating a new node
// immediately. The corresponding node will be created on demand if
// there's actually a matching file in the directory or one of its
// subdirectories.
//
ScopedPushDir pushdir (find_data.dirstack, basename);
find_recursively(fullname, find_data); // recurse
}
else
else if (file_test(fullname, FILE_TEST_IS_REGULAR))
{
if (!find_data.dirstack.back().second)
find_fill_dirstack(find_data); // build all directory nodes in the stack
const ustring basename_utf8 = Util::filename_to_utf8_fallback(basename);
row = *treestore_->prepend(find_data.dirstack.back().second->children());
if (find_data.pattern.match(basename_utf8) > 0)
{
find_add_file(basename_utf8, fullname, find_data);
++file_count;
}
}
}
const FileTreeColumns& columns = FileTreeColumns::instance();
find_increment_file_count(find_data, file_count);
}
catch (const FileError& error)
{
// Collect errors but don't interrupt the search.
find_data.error_list->push_back(error.what());
}
}
row[columns.filename] = basename_utf8;
row[columns.collatekey] = collate_key;
row[columns.fileinfo] = FileInfoBasePtr(new FileInfo(fullname));
void FileTree::find_add_file(const Glib::ustring& basename, const std::string& fullname,
FindData& find_data)
{
// Build the collate key with a leading '1' so that directories always
// come first (they have a leading '0'). This is simpler and faster
// than explicitely checking for directories in the sort function.
std::string collate_key (1, '1');
collate_key += basename.collate_key();
return true; // a file has been added
}
Gtk::TreeModel::Row row;
if (find_data.dirstack.empty())
{
row = *treestore_->prepend(); // new toplevel node
}
else
{
if (!find_data.dirstack.back().second)
find_fill_dirstack(find_data); // build all directory nodes in the stack
return false;
row = *treestore_->prepend(find_data.dirstack.back().second->children());
}
const FileTreeColumns& columns = FileTreeColumns::instance();
row[columns.filename] = basename;
row[columns.collatekey] = collate_key;
row[columns.fileinfo] = FileInfoBasePtr(new FileInfo(fullname));
}
void FileTree::find_fill_dirstack(FindData& find_data)
......
......@@ -122,7 +122,7 @@ private:
bool currently_selected);
void find_recursively(const std::string& dirname, FindData& find_data);
bool find_check_file(const std::string& basename, const std::string& fullname, FindData& find_data);
void find_add_file(const Glib::ustring& basename, const std::string& fullname, FindData& find_data);
void find_fill_dirstack(FindData& find_data);
void find_increment_file_count(FindData& find_data, int file_count);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment