Commit 4fa17b0f authored by Daniel Elstner's avatar Daniel Elstner
Browse files

Clean up the code a bit. In particular, change occurrences of

* src/filetree.{cc,h}: Clean up the code a bit.  In particular,
change occurrences of Gtk::TreePath to Gtk::TreeModel::Path.
* src/filetreeprivate.{cc,h}: Likewise.

* src/sharedptr.h (Util::SharedPtr::SharedPtr): Inline.
(Util::SharedPtr::~SharedPtr): Remove assertion and inline.
* src/sharedptr.cc: Remove now empty file.

* Makefile.am (src_regexxer_SOURCES): Remove src/sharedptr.cc.

svn path=/trunk/; revision=634
parent 1aecc9f9
2007-01-14 Daniel Elstner <daniel.kitta@gmail.com>
* src/filetree.{cc,h}: Clean up the code a bit. In particular,
change occurrences of Gtk::TreePath to Gtk::TreeModel::Path.
* src/filetreeprivate.{cc,h}: Likewise.
* src/sharedptr.h (Util::SharedPtr::SharedPtr): Inline.
(Util::SharedPtr::~SharedPtr): Remove assertion and inline.
* src/sharedptr.cc: Remove now empty file.
* Makefile.am (src_regexxer_SOURCES): Remove src/sharedptr.cc.
2007-01-14 Daniel Elstner <daniel.kitta@gmail.com>
* src/filetree.cc (regexxer_create_file_tree): Move function to
......
......@@ -53,7 +53,6 @@ src_regexxer_SOURCES = \
src/pcreshell.h \
src/prefdialog.cc \
src/prefdialog.h \
src/sharedptr.cc \
src/sharedptr.h \
src/signalutils.cc \
src/signalutils.h \
......
......@@ -63,6 +63,7 @@ FileTree::FileTree()
sum_matches_ (0)
{
using namespace Gtk;
using sigc::mem_fun;
set_model(treestore_);
const FileTreeColumns& model_columns = FileTreeColumns::instance();
......@@ -71,8 +72,8 @@ FileTree::FileTree()
treestore_->set_sort_func(model_columns.collatekey, &collatekey_sort_func);
treestore_->set_sort_column(TreeStore::DEFAULT_SORT_COLUMN_ID, SORT_ASCENDING);
treestore_->signal_rows_reordered().connect(
sigc::mem_fun(*this, &FileTree::on_treestore_rows_reordered));
treestore_->signal_rows_reordered()
.connect(mem_fun(*this, &FileTree::on_treestore_rows_reordered));
{
Column *const column = new Column(_("File"));
......@@ -85,15 +86,14 @@ FileTree::FileTree()
column->pack_start(*manage(cell_filename));
column->add_attribute(cell_filename->property_text(), model_columns.filename);
column->set_cell_data_func(*cell_icon, sigc::mem_fun(*this, &FileTree::icon_cell_data_func));
column->set_cell_data_func(*cell_filename, sigc::mem_fun(*this, &FileTree::text_cell_data_func));
column->set_cell_data_func(*cell_icon, mem_fun(*this, &FileTree::icon_cell_data_func));
column->set_cell_data_func(*cell_filename, mem_fun(*this, &FileTree::text_cell_data_func));
column->set_resizable(true);
column->set_expand(true);
column->set_sort_column(model_columns.collatekey);
}
{
Column *const column = new Column(_("#"));
append_column(*manage(column));
......@@ -102,7 +102,7 @@ FileTree::FileTree()
column->pack_start(*manage(cell_matchcount));
column->add_attribute(cell_matchcount->property_text(), model_columns.matchcount);
column->set_cell_data_func(*cell_matchcount, sigc::mem_fun(*this, &FileTree::text_cell_data_func));
column->set_cell_data_func(*cell_matchcount, mem_fun(*this, &FileTree::text_cell_data_func));
column->set_alignment(1.0);
cell_matchcount->property_xalign() = 1.0;
......@@ -115,10 +115,10 @@ FileTree::FileTree()
const Glib::RefPtr<TreeSelection> selection = get_selection();
selection->set_select_function(&FileTree::select_func);
selection->signal_changed().connect(sigc::mem_fun(*this, &FileTree::on_selection_changed));
selection->signal_changed().connect(mem_fun(*this, &FileTree::on_selection_changed));
Gnome::Conf::Client::get_default_client()
->signal_value_changed().connect(sigc::mem_fun(*this, &FileTree::on_conf_value_changed));
->signal_value_changed().connect(mem_fun(*this, &FileTree::on_conf_value_changed));
}
FileTree::~FileTree()
......@@ -150,7 +150,7 @@ void FileTree::find_files(const std::string& dirname, Pcre::Pattern& pattern,
// slightly. This in turn confuses TreeView::set_cursor() -- the first
// call after the tree was completely filled just doesn't scroll.
if (toplevel_.file_count > 0)
scroll_to_row(Gtk::TreePath(1U, 0));
scroll_to_row(Gtk::TreeModel::Path(1u, 0));
signal_bound_state_changed(); // emit
......@@ -229,7 +229,7 @@ BoundState FileTree::get_bound_state()
{
if (const Gtk::TreeModel::iterator iter = get_selection()->get_selected())
{
Gtk::TreePath path (iter);
Gtk::TreeModel::Path path (iter);
if (path > path_match_first_)
bound &= ~BOUND_FIRST;
......@@ -365,10 +365,11 @@ void FileTree::text_cell_data_func(Gtk::CellRenderer* cell, const Gtk::TreeModel
}
// static
bool FileTree::select_func(const Glib::RefPtr<Gtk::TreeModel>& model, const Gtk::TreePath& path, bool)
bool FileTree::select_func(const Glib::RefPtr<Gtk::TreeModel>& model,
const Gtk::TreeModel::Path& path, bool)
{
// Don't allow selection of directory nodes.
return get_fileinfo_from_iter(model->get_iter(path));
return (get_fileinfo_from_iter(model->get_iter(path)) != 0);
}
void FileTree::find_recursively(const std::string& dirname, FindData& find_data)
......@@ -566,10 +567,10 @@ bool FileTree::find_matches_at_path_iter(const Gtk::TreeModel::Path& path,
// are actually any handlers connected to the signal. find_matches() can
// then check whether the slot is empty to avoid providing arguments that
// are never going to be used.
const int new_match_count = buffer->find_matches(
find_data.pattern, find_data.multiple,
(signal_feedback.empty()) ? sigc::slot<void,int,const Glib::ustring&>()
: sigc::bind(signal_feedback.make_slot(), fileinfo));
const int new_match_count =
buffer->find_matches(find_data.pattern, find_data.multiple, (signal_feedback.empty())
? sigc::slot<void, int, const Glib::ustring&>()
: sigc::bind(signal_feedback.make_slot(), fileinfo));
if (new_match_count > 0)
{
......@@ -623,9 +624,8 @@ bool FileTree::replace_matches_at_path_iter(const Gtk::TreeModel::Path& path,
// a single user action object for all replacements in all buffers.
// Note that the caller must block conn_undo_stack_push_ to avoid
// double notification.
Util::ScopedConnection conn1 (buffer->signal_undo_stack_push.
connect(replace_data.slot_undo_stack_push));
Util::ScopedConnection conn1 (buffer->signal_undo_stack_push
.connect(replace_data.slot_undo_stack_push));
Util::ScopedConnection conn2 (buffer->signal_pulse.connect(signal_pulse.make_slot()));
buffer->replace_all_matches(replace_data.substitution);
......@@ -643,7 +643,7 @@ bool FileTree::replace_matches_at_path_iter(const Gtk::TreeModel::Path& path,
return false;
}
void FileTree::expand_and_select(const Gtk::TreePath& path)
void FileTree::expand_and_select(const Gtk::TreeModel::Path& path)
{
expand_to_path(path);
set_cursor(path);
......@@ -729,7 +729,7 @@ void FileTree::on_selection_changed()
connect(sigc::mem_fun(*this, &FileTree::on_buffer_undo_stack_push));
}
last_selected_rowref_.reset(new TreeRowRef(treestore_, Gtk::TreePath(iter)));
last_selected_rowref_.reset(new TreeRowRef(treestore_, Gtk::TreeModel::Path(iter)));
}
if (last_selected_ && last_selected_ != fileinfo &&
......@@ -792,7 +792,7 @@ void FileTree::on_buffer_match_count_changed()
// The range should've been set up already since old_sum_matches > 0.
g_return_if_fail(path_match_first_ <= path_match_last_);
Gtk::TreePath path (iter);
Gtk::TreeModel::Path path (iter);
if (old_match_count == 0)
{
......@@ -900,7 +900,7 @@ void FileTree::propagate_modified_change(const Gtk::TreeModel::iterator& pos, bo
const int difference = (modified) ? 1 : -1;
const FileTreeColumns& columns = FileTreeColumns::instance();
Gtk::TreePath path (pos);
Gtk::TreeModel::Path path (pos);
treestore_->row_changed(path, pos);
for (Gtk::TreeModel::iterator iter = pos->parent(); iter && path.up(); iter = iter->parent())
......@@ -949,7 +949,7 @@ void FileTree::load_file_with_fallback(const Gtk::TreeModel::iterator& iter,
{
// Trigger signal_row_changed() because the value of fileinfo->load_failed
// changed, which means we have to change icon and color of the row.
treestore_->row_changed(Gtk::TreePath(iter), iter);
treestore_->row_changed(Gtk::TreeModel::Path(iter), iter);
}
}
......
......@@ -28,15 +28,14 @@
#include <gdkmm/color.h>
#include <gdkmm/pixbuf.h>
#include <gtkmm/treepath.h>
#include <gtkmm/treemodel.h>
#include <gtkmm/treeview.h>
#include <list>
namespace Gtk { class TreeStore; }
namespace Pcre { class Pattern; }
namespace Pcre { class Pattern; }
namespace Gnome { namespace Conf { class Value; } }
namespace Regexxer
{
......@@ -76,7 +75,7 @@ public:
sigc::signal<void,UndoActionPtr> signal_undo_stack_push;
// Provide line number, subject and file info for match location output.
sigc::signal<void,int,const Glib::ustring&,FileInfoPtr> signal_feedback;
sigc::signal<void, int, const Glib::ustring&, FileInfoPtr> signal_feedback;
protected:
virtual void on_style_changed(const Glib::RefPtr<Gtk::Style>& previous_style);
......@@ -112,19 +111,20 @@ private:
Util::AutoConnection conn_modified_changed_;
Util::AutoConnection conn_undo_stack_push_;
Gtk::TreePath path_match_first_;
Gtk::TreePath path_match_last_;
Gtk::TreeModel::Path path_match_first_;
Gtk::TreeModel::Path path_match_last_;
std::string fallback_encoding_;
void icon_cell_data_func(Gtk::CellRenderer* cell, const Gtk::TreeModel::iterator& iter);
void text_cell_data_func(Gtk::CellRenderer* cell, const Gtk::TreeModel::iterator& iter);
static bool select_func(const Glib::RefPtr<Gtk::TreeModel>& model, const Gtk::TreePath& path,
bool currently_selected);
static bool select_func(const Glib::RefPtr<Gtk::TreeModel>& model,
const Gtk::TreeModel::Path& path, bool currently_selected);
void find_recursively(const std::string& dirname, FindData& find_data);
void find_add_file(const Glib::ustring& 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);
......@@ -139,7 +139,7 @@ private:
const Gtk::TreeModel::iterator& iter,
ReplaceMatchesData& replace_data);
void expand_and_select(const Gtk::TreePath& path);
void expand_and_select(const Gtk::TreeModel::Path& path);
void on_treestore_rows_reordered(const Gtk::TreeModel::Path& path,
const Gtk::TreeModel::iterator& iter, int* order);
......@@ -158,7 +158,6 @@ private:
void on_conf_value_changed(const Glib::ustring& key, const Gnome::Conf::Value& value);
};
class FileTree::Error
{
public:
......
......@@ -62,8 +62,8 @@ FileInfoPtr get_fileinfo_from_iter(const Gtk::TreeModel::iterator& iter)
return shared_dynamic_cast<FileInfo>(base);
}
int default_sort_func (const Gtk::TreeModel::iterator& lhs, const Gtk::TreeModel::iterator& rhs);
int collatekey_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);
int collatekey_sort_func(const Gtk::TreeModel::iterator& a, const Gtk::TreeModel::iterator& b);
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);
......@@ -81,7 +81,8 @@ private:
public:
ScopedPushDir(DirStack& dirstack, const std::string& dirname)
: dirstack_ (dirstack) { dirstack_.push_back(DirNodePair(dirname, Gtk::TreeIter())); }
: dirstack_ (dirstack)
{ dirstack_.push_back(DirNodePair(dirname, Gtk::TreeModel::iterator())); }
~ScopedPushDir() { dirstack_.pop_back(); }
};
......@@ -93,7 +94,7 @@ public:
class FileTree::TreeRowRef : public Util::SharedObject, public Gtk::TreeRowReference
{
public:
TreeRowRef(const Glib::RefPtr<Gtk::TreeModel>& model, const Gtk::TreePath& path);
TreeRowRef(const Glib::RefPtr<Gtk::TreeModel>& model, const Gtk::TreeModel::Path& path);
~TreeRowRef();
private:
......
/*
* Copyright (c) 2002-2007 Daniel Elstner <daniel.kitta@gmail.com>
*
* This file is part of regexxer.
*
* regexxer is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* regexxer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with regexxer; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "sharedptr.h"
#include <glib.h>
namespace Util
{
SharedObject::SharedObject()
:
refcount_ (0)
{}
SharedObject::~SharedObject()
{
g_return_if_fail(refcount_ == 0);
}
} // namespace Util
......@@ -23,7 +23,6 @@
#include <algorithm>
namespace Util
{
......@@ -35,12 +34,13 @@ template <class> class SharedPtr;
class SharedObject
{
protected:
SharedObject(); // initial reference count is 0
~SharedObject();
inline SharedObject(); // initial reference count is 0
inline ~SharedObject();
private:
mutable long refcount_;
// noncopyable
SharedObject(const SharedObject&);
SharedObject& operator=(const SharedObject&);
......@@ -111,11 +111,22 @@ private:
T* ptr_;
};
// Explicitely forbid the usage of a generic SharedPtr<SharedObject>
// because class SharedObject doesn't have a virtual destructor.
/*
* Explicitely forbid the usage of a generic SharedPtr<SharedObject>
* because class SharedObject doesn't have a virtual destructor.
*/
template <> class SharedPtr<SharedObject> {};
template <> class SharedPtr<const SharedObject> {};
inline
SharedObject::SharedObject()
:
refcount_ (0)
{}
inline
SharedObject::~SharedObject()
{}
template <class T> inline
SharedPtr<T>::SharedPtr()
......@@ -139,10 +150,11 @@ SharedPtr<T>::SharedPtr(T* ptr)
++ptr_->refcount_;
}
// Note that reset() and get() are defined here and not in declaration order
// on purpose -- defining them before they're first used allows for maximum
// inlining.
/*
* Note that reset() and get() are defined here and not in declaration order
* on purpose -- defining them before their first use is required with some
* compilers for for maximum inlining.
*/
template <class T> inline
void SharedPtr<T>::swap(SharedPtr<T>& other)
{
......@@ -217,11 +229,10 @@ SharedPtr<T>::operator const void*() const
return ptr_;
}
template <class T> inline
void swap(SharedPtr<T>& lhs, SharedPtr<T>& rhs)
void swap(SharedPtr<T>& a, SharedPtr<T>& b)
{
lhs.swap(rhs);
a.swap(b);
}
template <class T, class U> inline
......
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