Commit 28d68a4f authored by Daniel Elstner's avatar Daniel Elstner
Browse files

:find_recursively): Replace uses of Glib::filename_display_name() by

* src/filetree.cc (FileTree::find_recursively): Replace uses of
Glib::filename_display_name() by Glib::filename_display_basename()
to enable translation of well-known locations in future.  Store
the full path in the directory stack.
(FileTree::find_fill_dirstack): Convert the full path from the
stack to a displayable name with Glib::filename_display_basename().
(FileTree::save_file_at_iter): Determine the basename for
use in the error message with Glib::filename_display_basename().

* src/mainwindow.cc (MainWindow::set_title_filename): Call
Glib::filename_display_basename() to get the filename to be
displayed in the window title.

* src/filetreeprivate.{cc,h}: Some early spring cleaning.

svn path=/trunk/; revision=630
parent e9615347
2007-01-13 Daniel Elstner <daniel.kitta@gmail.com>
* src/filetree.cc (FileTree::find_recursively): Replace uses of
Glib::filename_display_name() by Glib::filename_display_basename()
to enable translation of well-known locations in future. Store
the full path in the directory stack.
(FileTree::find_fill_dirstack): Convert the full path from the
stack to a displayable name with Glib::filename_display_basename().
(FileTree::save_file_at_iter): Determine the basename for
use in the error message with Glib::filename_display_basename().
* src/mainwindow.cc (MainWindow::set_title_filename): Call
Glib::filename_display_basename() to get the filename to be
displayed in the window title.
* src/filetreeprivate.{cc,h}: Some early spring cleaning.
2007-01-12 Daniel Elstner <daniel.kitta@gmail.com>
* src/fileio.cc: Prefix function and data definitions within
......
......@@ -33,7 +33,6 @@
using namespace Regexxer::FileTreePrivate;
namespace
{
......@@ -54,7 +53,6 @@ GtkWidget* regexxer_create_file_tree(char*, char*, char*, int, int)
} // anonymous namespace
namespace Regexxer
{
......@@ -389,12 +387,12 @@ void FileTree::find_recursively(const std::string& dirname, FindData& find_data)
if (signal_pulse()) // emit
break;
const std::string basename = *pos;
const std::string filename = *pos;
if (!find_data.hidden && *basename.begin() == '.')
if (!find_data.hidden && *filename.begin() == '.')
continue;
const std::string fullname = build_filename(dirname, basename);
const std::string fullname = build_filename(dirname, filename);
if (file_test(fullname, FILE_TEST_IS_SYMLINK))
continue; // ignore symbolic links
......@@ -405,17 +403,16 @@ void FileTree::find_recursively(const std::string& dirname, FindData& find_data)
// 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);
ScopedPushDir pushdir (find_data.dirstack, fullname);
find_recursively(fullname, find_data); // recurse
}
else if (file_test(fullname, FILE_TEST_IS_REGULAR))
{
const ustring displayname = Glib::filename_display_name(basename);
const ustring basename = Glib::filename_display_basename(fullname);
if (find_data.pattern.match(displayname) > 0)
if (find_data.pattern.match(basename) > 0)
{
find_add_file(displayname, fullname, find_data);
find_add_file(basename, fullname, find_data);
++file_count;
}
}
......@@ -474,7 +471,7 @@ void FileTree::find_fill_dirstack(FindData& find_data)
if (pdir->second) // node already created
continue;
const Glib::ustring dirname = Glib::filename_display_name(pdir->first);
const Glib::ustring dirname = Glib::filename_display_basename(pdir->first);
// Build the collate key with a leading '0' so that directories always
// come first. This is simpler and faster than explicitely checking for
......@@ -531,7 +528,7 @@ bool FileTree::save_file_at_iter(const Gtk::TreeModel::iterator& iter,
catch (const Glib::Error& error)
{
error_list->push_back(Util::compose(_("Failed to save file \342\200\234%1\342\200\235: %2"),
Glib::filename_display_name(fileinfo->fullname),
Glib::filename_display_basename(fileinfo->fullname),
error.what()));
}
......
......@@ -37,29 +37,29 @@ const FileTreeColumns& FileTreeColumns::instance()
return column_record;
}
int default_sort_func(const Gtk::TreeModel::iterator& lhs, const Gtk::TreeModel::iterator& rhs)
int default_sort_func(const Gtk::TreeModel::iterator& a, const Gtk::TreeModel::iterator& b)
{
const FileTreeColumns& columns = FileTreeColumns::instance();
const std::string lhs_key = (*lhs)[columns.collatekey];
const std::string rhs_key = (*rhs)[columns.collatekey];
const std::string a_key = (*a)[columns.collatekey];
const std::string b_key = (*b)[columns.collatekey];
return lhs_key.compare(rhs_key);
return a_key.compare(b_key);
}
int collatekey_sort_func(const Gtk::TreeModel::iterator& lhs, const Gtk::TreeModel::iterator& rhs)
int collatekey_sort_func(const Gtk::TreeModel::iterator& a, const Gtk::TreeModel::iterator& b)
{
typedef std::string::difference_type diff_type;
const FileTreeColumns& columns = FileTreeColumns::instance();
const std::string lhs_key = (*lhs)[columns.collatekey];
const std::string rhs_key = (*rhs)[columns.collatekey];
const std::string a_key = (*a)[columns.collatekey];
const std::string b_key = (*b)[columns.collatekey];
if (lhs_key.size() > 1 && rhs_key.size() > 1)
return lhs_key.compare(1, std::string::npos, rhs_key, 1, std::string::npos);
if (a_key.size() > 1 && b_key.size() > 1)
return a_key.compare(1, std::string::npos, b_key, 1, std::string::npos);
else
return diff_type(lhs_key.size()) - diff_type(rhs_key.size());
return diff_type(a_key.size()) - diff_type(b_key.size());
}
bool next_match_file(Gtk::TreeModel::iterator& iter, Gtk::TreeModel::Path* collapse)
......@@ -145,10 +145,10 @@ bool prev_match_file(Gtk::TreeModel::iterator& iter, Gtk::TreeModel::Path* colla
} // namespace FileTreePrivate
/**** Regexxer::FileTree::TreeRowRef ***************************************/
FileTree::TreeRowRef::TreeRowRef(const Glib::RefPtr<Gtk::TreeModel>& model, const Gtk::TreePath& path)
FileTree::TreeRowRef::TreeRowRef(const Glib::RefPtr<Gtk::TreeModel>& model,
const Gtk::TreeModel::Path& path)
:
Gtk::TreeRowReference(model, path)
{}
......@@ -156,7 +156,6 @@ FileTree::TreeRowRef::TreeRowRef(const Glib::RefPtr<Gtk::TreeModel>& model, cons
FileTree::TreeRowRef::~TreeRowRef()
{}
/**** Regexxer::FileTree::MessageList **************************************/
FileTree::MessageList::MessageList()
......@@ -165,7 +164,6 @@ FileTree::MessageList::MessageList()
FileTree::MessageList::~MessageList()
{}
/**** Regexxer::FileTree::Error ********************************************/
FileTree::Error::Error(const Util::SharedPtr<FileTree::MessageList>& error_list)
......@@ -192,7 +190,6 @@ const std::list<Glib::ustring>& FileTree::Error::get_error_list() const
return *error_list_;
}
/**** Regexxer::FileTree::FindData *****************************************/
FileTree::FindData::FindData(Pcre::Pattern& pattern_, bool recursive_, bool hidden_)
......@@ -206,7 +203,6 @@ FileTree::FindData::FindData(Pcre::Pattern& pattern_, bool recursive_, bool hidd
FileTree::FindData::~FindData()
{}
/**** Regexxer::FileTree::FindMatchesData **********************************/
FileTree::FindMatchesData::FindMatchesData(Pcre::Pattern& pattern_, bool multiple_)
......@@ -216,7 +212,6 @@ FileTree::FindMatchesData::FindMatchesData(Pcre::Pattern& pattern_, bool multipl
path_match_first_set (false)
{}
/**** Regexxer::FileTree::ReplaceMatchesData *******************************/
FileTree::ReplaceMatchesData::ReplaceMatchesData(FileTree& filetree_,
......@@ -238,7 +233,6 @@ void FileTree::ReplaceMatchesData::undo_stack_push(UndoActionPtr undo_action)
undo_stack->push(UndoActionPtr(new BufferActionShell(filetree, row_reference, undo_action)));
}
/**** Regexxer::FileTree::ScopedBlockSorting *******************************/
FileTree::ScopedBlockSorting::ScopedBlockSorting(FileTree& filetree)
......@@ -265,7 +259,6 @@ FileTree::ScopedBlockSorting::~ScopedBlockSorting()
filetree_.set_headers_clickable(true);
}
/**** Regexxer::FileTree::BufferActionShell ********************************/
FileTree::BufferActionShell::BufferActionShell(FileTree& filetree,
......
......@@ -27,7 +27,6 @@
#include <gtkmm/treestore.h>
#include <utility>
namespace Regexxer
{
......@@ -43,7 +42,6 @@ namespace FileTreePrivate
using Util::shared_dynamic_cast;
using Util::shared_polymorphic_cast;
struct FileTreeColumns : public Gtk::TreeModel::ColumnRecord
{
Gtk::TreeModelColumn<Glib::ustring> filename;
......@@ -57,7 +55,6 @@ private:
FileTreeColumns() { add(filename); add(collatekey); add(matchcount); add(fileinfo); }
};
inline
FileInfoPtr get_fileinfo_from_iter(const Gtk::TreeModel::iterator& iter)
{
......@@ -71,7 +68,6 @@ int collatekey_sort_func(const Gtk::TreeModel::iterator& lhs, const Gtk::TreeMod
bool next_match_file(Gtk::TreeModel::iterator& iter, Gtk::TreeModel::Path* collapse = 0);
bool prev_match_file(Gtk::TreeModel::iterator& iter, Gtk::TreeModel::Path* collapse = 0);
typedef std::pair<std::string,Gtk::TreeModel::iterator> DirNodePair;
typedef std::list<DirNodePair> DirStack;
......@@ -92,7 +88,6 @@ public:
} // namespace FileTreePrivate
/* This is just a Gtk::TreeRowReference wrapper that can be used with Util::SharedPtr<>.
*/
class FileTree::TreeRowRef : public Util::SharedObject, public Gtk::TreeRowReference
......@@ -106,7 +101,6 @@ private:
FileTree::TreeRowRef& operator=(const FileTree::TreeRowRef&);
};
/* This is just a std::list<> wrapper that can be used with Util::SharedPtr<>.
*/
class FileTree::MessageList : public Util::SharedObject, public std::list<Glib::ustring>
......@@ -120,7 +114,6 @@ private:
FileTree::MessageList& operator=(const FileTree::MessageList&);
};
struct FileTree::FindData
{
FindData(Pcre::Pattern& pattern_, bool recursive_, bool hidden_);
......@@ -137,7 +130,6 @@ private:
FileTree::FindData& operator=(const FileTree::FindData&);
};
struct FileTree::FindMatchesData
{
FindMatchesData(Pcre::Pattern& pattern_, bool multiple_);
......@@ -151,7 +143,6 @@ private:
FileTree::FindMatchesData& operator=(const FileTree::FindMatchesData&);
};
struct FileTree::ReplaceMatchesData
{
ReplaceMatchesData(FileTree& filetree_, const Glib::ustring& substitution_);
......@@ -170,7 +161,6 @@ private:
FileTree::ReplaceMatchesData& operator=(const FileTree::ReplaceMatchesData&);
};
class FileTree::ScopedBlockSorting
{
public:
......@@ -186,7 +176,6 @@ private:
FileTree::ScopedBlockSorting& operator=(const FileTree::ScopedBlockSorting&);
};
class FileTree::BufferActionShell : public UndoAction
{
public:
......
......@@ -353,7 +353,6 @@ void MainWindow::on_hide()
// necessary since they'd be deleted in the destructor anyway. But if we
// have to do a lot of cleanup the dialogs would stay open for that time,
// which doesn't look neat.
{
// Play safe and transfer ownership, and let the dtor do the delete.
const std::auto_ptr<Gtk::Dialog> temp (about_dialog_);
......@@ -743,8 +742,8 @@ void MainWindow::update_preview()
{
Glib::ustring preview;
const int pos = buffer->get_line_preview(entry_substitution_->get_text(), preview);
entry_preview_->set_text(preview);
entry_preview_->set_text(preview);
controller_.replace.set_enabled(pos >= 0);
// Beware, strange code ahead!
......@@ -779,7 +778,7 @@ void MainWindow::update_preview()
void MainWindow::set_title_filename(const std::string& filename)
{
Glib::ustring title = Glib::filename_display_name(Glib::path_get_basename(filename));
Glib::ustring title = Glib::filename_display_basename(filename);
title += " (";
title += Glib::filename_display_name(Util::shorten_pathname(Glib::path_get_dirname(filename)));
......@@ -880,7 +879,8 @@ void MainWindow::on_preferences()
{
std::auto_ptr<PrefDialog> dialog (new PrefDialog(*window_));
dialog->get_dialog()->signal_hide().connect(sigc::mem_fun(*this, &MainWindow::on_pref_dialog_hide));
dialog->get_dialog()->signal_hide()
.connect(sigc::mem_fun(*this, &MainWindow::on_pref_dialog_hide));
dialog->get_dialog()->show();
pref_dialog_ = dialog;
......
......@@ -46,7 +46,6 @@ class Window;
namespace Gnome { namespace Conf { class Value; } }
namespace Regexxer
{
......
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