Get rid of MooEditList

This commit is contained in:
Yevgen Muntyan 2016-01-04 11:14:37 -08:00
parent 834c77b5e7
commit 7e6ac89ef3
7 changed files with 42 additions and 38 deletions

View File

@ -62,15 +62,14 @@ public:
gobj_raw_ptr& operator=(const gobj_raw_ptr& other) = default;
gobj_raw_ptr(gobj_raw_ptr&& other)
: m_ref(other.gobj())
: m_ref(std::move(other.m_ref))
{
other = nullptr;
}
gobj_raw_ptr& operator=(gobj_raw_ptr&& other)
{
m_ref._set_gobj(other.gobj());
other.m_ref._set_gobj(nullptr);
m_ref = std::move(other.m_ref);
return *this;
}
@ -160,26 +159,38 @@ inline bool operator==(const nullptr_t&, const moo::gobj_raw_ptr<X>& p)
return p.gobj() == nullptr;
}
template<typename X, typename Y>
inline bool operator==(const moo::gobj_raw_ptr<X>& p1, const moo::gobj_raw_ptr<Y>& p2)
template<typename X>
inline bool operator==(const moo::gobj_raw_ptr<X>& p1, const moo::gobj_raw_ptr<X>& p2)
{
return p1.gobj() == p2.gobj();
}
template<typename X, typename Y>
inline bool operator==(const moo::gobj_raw_ptr<X>& p1, const Y* p2)
template<typename X>
inline bool operator==(const moo::gobj_raw_ptr<X>& p1, const X* p2)
{
return p1.gobj() == p2;
}
template<typename X, typename Y>
inline bool operator==(const X* p1, const moo::gobj_raw_ptr<Y>& p2)
template<typename X>
inline bool operator==(const moo::gobj_raw_ptr<X>& p1, X* p2)
{
return p1.gobj() == p2;
}
template<typename X>
inline bool operator==(const X* p1, const moo::gobj_raw_ptr<X>& p2)
{
return p1 == p2.gobj();
}
template<typename X, typename Y>
bool operator!=(const moo::gobj_raw_ptr<X>& p1, const moo::gobj_raw_ptr<Y>& p2)
template<typename X>
inline bool operator==(X* p1, const moo::gobj_raw_ptr<X>& p2)
{
return p1 == p2.gobj();
}
template<typename X>
bool operator!=(const moo::gobj_raw_ptr<X>& p1, const moo::gobj_raw_ptr<X>& p2)
{
return !(p1 == p2);
}

View File

@ -65,7 +65,7 @@ template<typename Container, typename U>
void remove(Container& vec, const U& elm)
{
auto itr = find(vec, elm);
g_assert (itr != vec.end());
g_return_if_fail(itr != vec.end());
vec.erase(itr);
}

View File

@ -24,11 +24,7 @@
#ifdef __cplusplus
#include <moocpp/strutils.h>
#include <moocpp/gobjptrtypes-gio.h>
#endif
extern MooEditList *_moo_edit_instances;
#ifdef __cplusplus
#include <vector>
namespace moo {
@ -38,6 +34,8 @@ class gobj_ref<MooEdit> : public gobj_ref_parent<MooEdit>
public:
MOO_DEFINE_GOBJREF_METHODS(MooEdit)
static std::vector<gobj_raw_ptr<MooEdit>> _moo_edit_instances;
void _add_view (EditView view);
void _remove_view (EditView view);
void _set_active_view (EditView view);

View File

@ -23,8 +23,6 @@
#include "moocpp/utils.h"
#include "moocpp/gobjptrtypes.h"
#define MOO_EDIT_IS_UNTITLED(edit) (!(edit)->priv->file)
struct MooEditPrivate {
MooEditPrivate();
~MooEditPrivate();

View File

@ -66,7 +66,7 @@ using namespace moo;
MOO_DEFINE_OBJECT_ARRAY (MooEdit, moo_edit)
MooEditList *_moo_edit_instances = NULL;
std::vector<EditRawPtr> Edit::_moo_edit_instances;
static guint moo_edit_apply_config_all_idle;
static GObject *moo_edit_constructor (GType type,
@ -313,7 +313,7 @@ moo_edit_constructor (GType type,
g_assert(priv.views.size() == 1 && priv.views[0] == view);
doc._add_class_actions();
_moo_edit_instances = moo_edit_list_prepend(_moo_edit_instances, &doc);
Edit::_moo_edit_instances.push_back(&doc);
priv.changed_handler_id =
priv.buffer->signal_connect("changed",
@ -353,7 +353,7 @@ void Edit::_closed()
moo_assert(priv.state == MOO_EDIT_STATE_NORMAL);
_remove_untitled(*this);
_moo_edit_instances = moo_edit_list_remove (_moo_edit_instances, gobj());
remove(_moo_edit_instances, gobj());
while (!priv.views.empty())
gtk_widget_destroy (priv.views[0].gobj<GtkWidget>());
@ -627,7 +627,7 @@ moo_edit_is_empty (MooEdit *edit)
Edit r = *edit;
if (r._is_busy () || moo_edit_is_modified (edit) || !MOO_EDIT_IS_UNTITLED (edit))
if (r._is_busy () || moo_edit_is_modified (edit) || !moo_edit_is_untitled (edit))
return FALSE;
gtk_text_buffer_get_bounds (moo_edit_get_buffer (edit), &start, &end);
@ -642,7 +642,7 @@ gboolean
moo_edit_is_untitled (MooEdit *edit)
{
g_return_val_if_fail (MOO_IS_EDIT (edit), FALSE);
return MOO_EDIT_IS_UNTITLED (edit);
return !edit->priv->file;
}
/**
@ -1206,12 +1206,10 @@ moo_edit_get_lang_id (MooEdit *doc)
static gboolean
moo_edit_apply_config_all_in_idle (void)
{
MooEditList *l;
moo_edit_apply_config_all_idle = 0;
for (l = _moo_edit_instances; l != NULL; l = l->next)
moo_edit_recheck_config (l->data);
for (const auto& doc: Edit::_moo_edit_instances)
moo_edit_recheck_config (doc);
return FALSE;
}

View File

@ -206,7 +206,6 @@ moo_edit_class_install_action (MooEditClass *klass,
GHashTable *actions;
ActionInfo *info;
GType type;
MooEditList *l;
g_return_if_fail (MOO_IS_EDIT_CLASS (klass));
g_return_if_fail (MOO_IS_ACTION_FACTORY (factory));
@ -228,15 +227,15 @@ moo_edit_class_install_action (MooEditClass *klass,
info = action_info_new (factory, doc_conditions, view_conditions);
g_hash_table_insert (actions, g_strdup (action_id), info);
for (l = _moo_edit_instances; l != NULL; l = l->next)
for (const auto& doc: Edit::_moo_edit_instances)
{
if (g_type_is_a (G_OBJECT_TYPE (l->data), type))
if (g_type_is_a (G_OBJECT_TYPE (doc), type))
{
GtkAction *action = create_action (action_id, info, l->data);
GtkAction *action = create_action (action_id, info, doc);
if (action)
{
moo_edit_add_action (l->data, action);
moo_edit_add_action (doc, action);
g_object_unref (action);
}
}
@ -521,7 +520,6 @@ moo_edit_class_remove_action (MooEditClass *klass,
{
GHashTable *actions;
GType type;
MooEditList *l;
g_return_if_fail (MOO_IS_EDIT_CLASS (klass));
@ -531,9 +529,11 @@ moo_edit_class_remove_action (MooEditClass *klass,
if (actions)
g_hash_table_remove (actions, action_id);
for (l = _moo_edit_instances; l != NULL; l = l->next)
if (g_type_is_a (G_OBJECT_TYPE (l->data), type))
moo_edit_remove_action (l->data, action_id);
for (const auto& doc: Edit::_moo_edit_instances)
{
if (g_type_is_a(G_OBJECT_TYPE(doc), type))
moo_edit_remove_action(doc, action_id);
}
}

View File

@ -27,7 +27,6 @@ MOO_DECLARE_OBJECT_ARRAY (MooEdit, moo_edit)
MOO_DECLARE_OBJECT_ARRAY (MooEditView, moo_edit_view)
MOO_DECLARE_OBJECT_ARRAY (MooEditTab, moo_edit_tab)
MOO_DECLARE_OBJECT_ARRAY (MooEditWindow, moo_edit_window)
MOO_DEFINE_SLIST (MooEditList, moo_edit_list, MooEdit)
MOO_DECLARE_OBJECT_ARRAY (MooOpenInfo, moo_open_info)