Get rid of MooEditList
This commit is contained in:
parent
834c77b5e7
commit
7e6ac89ef3
@ -62,15 +62,14 @@ public:
|
|||||||
gobj_raw_ptr& operator=(const gobj_raw_ptr& other) = default;
|
gobj_raw_ptr& operator=(const gobj_raw_ptr& other) = default;
|
||||||
|
|
||||||
gobj_raw_ptr(gobj_raw_ptr&& other)
|
gobj_raw_ptr(gobj_raw_ptr&& other)
|
||||||
: m_ref(other.gobj())
|
: m_ref(std::move(other.m_ref))
|
||||||
{
|
{
|
||||||
other = nullptr;
|
other = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
gobj_raw_ptr& operator=(gobj_raw_ptr&& other)
|
gobj_raw_ptr& operator=(gobj_raw_ptr&& other)
|
||||||
{
|
{
|
||||||
m_ref._set_gobj(other.gobj());
|
m_ref = std::move(other.m_ref);
|
||||||
other.m_ref._set_gobj(nullptr);
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,26 +159,38 @@ inline bool operator==(const nullptr_t&, const moo::gobj_raw_ptr<X>& p)
|
|||||||
return p.gobj() == nullptr;
|
return p.gobj() == nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename X, typename Y>
|
template<typename X>
|
||||||
inline bool operator==(const moo::gobj_raw_ptr<X>& p1, const moo::gobj_raw_ptr<Y>& p2)
|
inline bool operator==(const moo::gobj_raw_ptr<X>& p1, const moo::gobj_raw_ptr<X>& p2)
|
||||||
{
|
{
|
||||||
return p1.gobj() == p2.gobj();
|
return p1.gobj() == p2.gobj();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename X, typename Y>
|
template<typename X>
|
||||||
inline bool operator==(const moo::gobj_raw_ptr<X>& p1, const Y* p2)
|
inline bool operator==(const moo::gobj_raw_ptr<X>& p1, const X* p2)
|
||||||
{
|
{
|
||||||
return p1.gobj() == p2;
|
return p1.gobj() == p2;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename X, typename Y>
|
template<typename X>
|
||||||
inline bool operator==(const X* p1, const moo::gobj_raw_ptr<Y>& p2)
|
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();
|
return p1 == p2.gobj();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename X, typename Y>
|
template<typename X>
|
||||||
bool operator!=(const moo::gobj_raw_ptr<X>& p1, const moo::gobj_raw_ptr<Y>& p2)
|
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);
|
return !(p1 == p2);
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ template<typename Container, typename U>
|
|||||||
void remove(Container& vec, const U& elm)
|
void remove(Container& vec, const U& elm)
|
||||||
{
|
{
|
||||||
auto itr = find(vec, elm);
|
auto itr = find(vec, elm);
|
||||||
g_assert (itr != vec.end());
|
g_return_if_fail(itr != vec.end());
|
||||||
vec.erase(itr);
|
vec.erase(itr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,11 +24,7 @@
|
|||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
#include <moocpp/strutils.h>
|
#include <moocpp/strutils.h>
|
||||||
#include <moocpp/gobjptrtypes-gio.h>
|
#include <moocpp/gobjptrtypes-gio.h>
|
||||||
#endif
|
#include <vector>
|
||||||
|
|
||||||
extern MooEditList *_moo_edit_instances;
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
|
|
||||||
namespace moo {
|
namespace moo {
|
||||||
|
|
||||||
@ -38,6 +34,8 @@ class gobj_ref<MooEdit> : public gobj_ref_parent<MooEdit>
|
|||||||
public:
|
public:
|
||||||
MOO_DEFINE_GOBJREF_METHODS(MooEdit)
|
MOO_DEFINE_GOBJREF_METHODS(MooEdit)
|
||||||
|
|
||||||
|
static std::vector<gobj_raw_ptr<MooEdit>> _moo_edit_instances;
|
||||||
|
|
||||||
void _add_view (EditView view);
|
void _add_view (EditView view);
|
||||||
void _remove_view (EditView view);
|
void _remove_view (EditView view);
|
||||||
void _set_active_view (EditView view);
|
void _set_active_view (EditView view);
|
||||||
|
@ -23,8 +23,6 @@
|
|||||||
#include "moocpp/utils.h"
|
#include "moocpp/utils.h"
|
||||||
#include "moocpp/gobjptrtypes.h"
|
#include "moocpp/gobjptrtypes.h"
|
||||||
|
|
||||||
#define MOO_EDIT_IS_UNTITLED(edit) (!(edit)->priv->file)
|
|
||||||
|
|
||||||
struct MooEditPrivate {
|
struct MooEditPrivate {
|
||||||
MooEditPrivate();
|
MooEditPrivate();
|
||||||
~MooEditPrivate();
|
~MooEditPrivate();
|
||||||
|
@ -66,7 +66,7 @@ using namespace moo;
|
|||||||
|
|
||||||
MOO_DEFINE_OBJECT_ARRAY (MooEdit, moo_edit)
|
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 guint moo_edit_apply_config_all_idle;
|
||||||
|
|
||||||
static GObject *moo_edit_constructor (GType type,
|
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);
|
g_assert(priv.views.size() == 1 && priv.views[0] == view);
|
||||||
|
|
||||||
doc._add_class_actions();
|
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.changed_handler_id =
|
||||||
priv.buffer->signal_connect("changed",
|
priv.buffer->signal_connect("changed",
|
||||||
@ -353,7 +353,7 @@ void Edit::_closed()
|
|||||||
moo_assert(priv.state == MOO_EDIT_STATE_NORMAL);
|
moo_assert(priv.state == MOO_EDIT_STATE_NORMAL);
|
||||||
|
|
||||||
_remove_untitled(*this);
|
_remove_untitled(*this);
|
||||||
_moo_edit_instances = moo_edit_list_remove (_moo_edit_instances, gobj());
|
remove(_moo_edit_instances, gobj());
|
||||||
|
|
||||||
while (!priv.views.empty())
|
while (!priv.views.empty())
|
||||||
gtk_widget_destroy (priv.views[0].gobj<GtkWidget>());
|
gtk_widget_destroy (priv.views[0].gobj<GtkWidget>());
|
||||||
@ -627,7 +627,7 @@ moo_edit_is_empty (MooEdit *edit)
|
|||||||
|
|
||||||
Edit r = *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;
|
return FALSE;
|
||||||
|
|
||||||
gtk_text_buffer_get_bounds (moo_edit_get_buffer (edit), &start, &end);
|
gtk_text_buffer_get_bounds (moo_edit_get_buffer (edit), &start, &end);
|
||||||
@ -642,7 +642,7 @@ gboolean
|
|||||||
moo_edit_is_untitled (MooEdit *edit)
|
moo_edit_is_untitled (MooEdit *edit)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (MOO_IS_EDIT (edit), FALSE);
|
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
|
static gboolean
|
||||||
moo_edit_apply_config_all_in_idle (void)
|
moo_edit_apply_config_all_in_idle (void)
|
||||||
{
|
{
|
||||||
MooEditList *l;
|
|
||||||
|
|
||||||
moo_edit_apply_config_all_idle = 0;
|
moo_edit_apply_config_all_idle = 0;
|
||||||
|
|
||||||
for (l = _moo_edit_instances; l != NULL; l = l->next)
|
for (const auto& doc: Edit::_moo_edit_instances)
|
||||||
moo_edit_recheck_config (l->data);
|
moo_edit_recheck_config (doc);
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
@ -206,7 +206,6 @@ moo_edit_class_install_action (MooEditClass *klass,
|
|||||||
GHashTable *actions;
|
GHashTable *actions;
|
||||||
ActionInfo *info;
|
ActionInfo *info;
|
||||||
GType type;
|
GType type;
|
||||||
MooEditList *l;
|
|
||||||
|
|
||||||
g_return_if_fail (MOO_IS_EDIT_CLASS (klass));
|
g_return_if_fail (MOO_IS_EDIT_CLASS (klass));
|
||||||
g_return_if_fail (MOO_IS_ACTION_FACTORY (factory));
|
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);
|
info = action_info_new (factory, doc_conditions, view_conditions);
|
||||||
g_hash_table_insert (actions, g_strdup (action_id), info);
|
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)
|
if (action)
|
||||||
{
|
{
|
||||||
moo_edit_add_action (l->data, action);
|
moo_edit_add_action (doc, action);
|
||||||
g_object_unref (action);
|
g_object_unref (action);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -521,7 +520,6 @@ moo_edit_class_remove_action (MooEditClass *klass,
|
|||||||
{
|
{
|
||||||
GHashTable *actions;
|
GHashTable *actions;
|
||||||
GType type;
|
GType type;
|
||||||
MooEditList *l;
|
|
||||||
|
|
||||||
g_return_if_fail (MOO_IS_EDIT_CLASS (klass));
|
g_return_if_fail (MOO_IS_EDIT_CLASS (klass));
|
||||||
|
|
||||||
@ -531,9 +529,11 @@ moo_edit_class_remove_action (MooEditClass *klass,
|
|||||||
if (actions)
|
if (actions)
|
||||||
g_hash_table_remove (actions, action_id);
|
g_hash_table_remove (actions, action_id);
|
||||||
|
|
||||||
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))
|
{
|
||||||
moo_edit_remove_action (l->data, action_id);
|
if (g_type_is_a(G_OBJECT_TYPE(doc), type))
|
||||||
|
moo_edit_remove_action(doc, action_id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,7 +27,6 @@ MOO_DECLARE_OBJECT_ARRAY (MooEdit, moo_edit)
|
|||||||
MOO_DECLARE_OBJECT_ARRAY (MooEditView, moo_edit_view)
|
MOO_DECLARE_OBJECT_ARRAY (MooEditView, moo_edit_view)
|
||||||
MOO_DECLARE_OBJECT_ARRAY (MooEditTab, moo_edit_tab)
|
MOO_DECLARE_OBJECT_ARRAY (MooEditTab, moo_edit_tab)
|
||||||
MOO_DECLARE_OBJECT_ARRAY (MooEditWindow, moo_edit_window)
|
MOO_DECLARE_OBJECT_ARRAY (MooEditWindow, moo_edit_window)
|
||||||
MOO_DEFINE_SLIST (MooEditList, moo_edit_list, MooEdit)
|
|
||||||
|
|
||||||
MOO_DECLARE_OBJECT_ARRAY (MooOpenInfo, moo_open_info)
|
MOO_DECLARE_OBJECT_ARRAY (MooOpenInfo, moo_open_info)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user