From dd13a30fe46cf60d6f8432dea3cf655824af348e Mon Sep 17 00:00:00 2001 From: Yevgen Muntyan <17531749+muntyan@users.noreply.github.com> Date: Thu, 21 Jan 2016 03:16:33 -0800 Subject: [PATCH] Better string class --- moo/medit-app/main.cpp | 2 +- moo/mooapp/mooapp.cpp | 22 +- moo/moocpp/gobjptr.h | 7 +- moo/moocpp/gobjtypes-gio.h | 4 +- moo/moocpp/gobjtypes-glib.h | 5 +- moo/moocpp/gobjtypes-gtk.h | 4 +- moo/moocpp/grefptr.h | 2 +- moo/moocpp/memutils.h | 6 +- moo/moocpp/strutils.cpp | 294 ++++++++++++- moo/moocpp/strutils.h | 54 ++- moo/mooedit/mooedit-fileops.cpp | 34 +- moo/mooedit/mooedit.cpp | 4 +- moo/mooedit/mooeditdialogs.cpp | 49 +-- moo/mooedit/mooeditfileinfo-impl.h | 12 +- moo/mooedit/mooeditfileinfo.cpp | 684 ++++++++++++++--------------- moo/mooedit/mooeditfileinfo.h | 4 +- moo/mooedit/mooeditor.cpp | 14 +- moo/mooedit/mooeditprogress.cpp | 4 +- moo/mooedit/moolangmgr.cpp | 2 +- moo/mooutils/moofiledialog.cpp | 20 +- moo/mooutils/moofiledialog.h | 14 +- moo/mooutils/mooutils-misc.cpp | 8 +- 22 files changed, 763 insertions(+), 486 deletions(-) diff --git a/moo/medit-app/main.cpp b/moo/medit-app/main.cpp index 5582b079..6fdec95e 100644 --- a/moo/medit-app/main.cpp +++ b/moo/medit-app/main.cpp @@ -763,7 +763,7 @@ medit_main (int argc, char *argv[]) MeditApp::StartupOptions sopts; sopts.run_input = run_input; sopts.use_session = medit_opts.use_session; - sopts.instance_name.borrow(medit_opts.instance_name); + sopts.instance_name.set(medit_opts.instance_name); gref_ptr app = MeditApp::create(sopts); if (!app->init()) diff --git a/moo/mooapp/mooapp.cpp b/moo/mooapp/mooapp.cpp index aaabfcb1..8dffd4cf 100644 --- a/moo/mooapp/mooapp.cpp +++ b/moo/mooapp/mooapp.cpp @@ -76,6 +76,8 @@ struct App::Private static volatile int signal_received; Private(App& app) : app(app) {} + Private(const Private&) = delete; + Private& operator=(const Private&) = delete; App& app; @@ -261,7 +263,7 @@ App::App(gobj_wrapper_data& d, const StartupOptions& opts) p = new Private(*this); p->run_input = opts.run_input; p->use_session = opts.use_session; - p->instance_name.copy (opts.instance_name); + p->instance_name = opts.instance_name; #if defined(HAVE_SIGNAL) && defined(SIGINT) setup_signals (sigint_handler); @@ -436,7 +438,7 @@ void App::Private::editor_after_close_window (App::Private* self) void App::Private::init_editor () { - editor.take (moo_editor_create_instance ()); + editor.set_new (moo_editor_create_instance ()); editor->connect_swapped ("will-close-window", G_CALLBACK(editor_will_close_window), @@ -467,7 +469,7 @@ void App::Private::init_ui () if (file) { - xml.take (moo_ui_xml_new ()); + xml.set_new (moo_ui_xml_new ()); moo_ui_xml_add_ui_from_string (xml.gobj(), g_mapped_file_get_contents (file), g_mapped_file_get_length (file)); @@ -822,7 +824,7 @@ MooUiXml* App::Private::get_ui_xml () ui_xml.ref(moo_editor_get_ui_xml(editor.gobj())); if (!ui_xml) - ui_xml.take(moo_ui_xml_new()); + ui_xml.set_new(moo_ui_xml_new()); } return ui_xml.gobj(); @@ -843,7 +845,7 @@ void App::Private::save_session () if (session_file.empty()) return; - session.take (moo_markup_doc_new ("session")); + session.set_new (moo_markup_doc_new ("session")); root = moo_markup_create_root_element (session.gobj(), "session"); moo_markup_set_prop (root, "version", SESSION_VERSION); @@ -890,10 +892,10 @@ void App::load_session () if (p->session_file.empty()) { if (!p->instance_name.empty()) - p->session_file.take(g_strdup_printf(MOO_NAMED_SESSION_XML_FILE_NAME, - p->instance_name.get())); + p->session_file.set_new(g_strdup_printf(MOO_NAMED_SESSION_XML_FILE_NAME, + p->instance_name.get())); else - p->session_file.literal(MOO_SESSION_XML_FILE_NAME); + p->session_file.set_const(MOO_SESSION_XML_FILE_NAME); } gstr session_file = gstr::wrap_new (moo_get_user_cache_file (p->session_file)); @@ -1161,8 +1163,8 @@ void App::Private::load_prefs () gerrp error; char **sys_files; - rc_files[MOO_PREFS_RC].take(moo_get_user_data_file (MOO_PREFS_XML_FILE_NAME)); - rc_files[MOO_PREFS_STATE].take(moo_get_user_cache_file (MOO_STATE_XML_FILE_NAME)); + rc_files[MOO_PREFS_RC].set_new(moo_get_user_data_file (MOO_PREFS_XML_FILE_NAME)); + rc_files[MOO_PREFS_STATE].set_new(moo_get_user_cache_file (MOO_STATE_XML_FILE_NAME)); sys_files = moo_get_sys_data_files (MOO_PREFS_XML_FILE_NAME); diff --git a/moo/moocpp/gobjptr.h b/moo/moocpp/gobjptr.h index 75ebb0b8..e71b79d9 100644 --- a/moo/moocpp/gobjptr.h +++ b/moo/moocpp/gobjptr.h @@ -66,7 +66,7 @@ public: assign(obj, ref_transfer::make_copy); } - void take(Object* obj) + void set_new(Object* obj) { assign(obj, ref_transfer::take_ownership); } @@ -281,6 +281,11 @@ bool operator!=(const X& p1, const moo::gobj_ptr& p2) return !(p1 == p2); } +template bool operator==(const moo::gobj_ptr& p1, int) = delete; +template bool operator==(int, const moo::gobj_ptr& p2) = delete; +template bool operator!=(const moo::gobj_ptr& p1, int) = delete; +template bool operator!=(int, const moo::gobj_ptr& p2) = delete; + template void g_object_unref(const moo::gobj_ptr&) = delete; template diff --git a/moo/moocpp/gobjtypes-gio.h b/moo/moocpp/gobjtypes-gio.h index 5edaeb5b..3458b13a 100644 --- a/moo/moocpp/gobjtypes-gio.h +++ b/moo/moocpp/gobjtypes-gio.h @@ -15,11 +15,11 @@ #pragma once -#ifdef __cplusplus - #include #include +#ifdef __cplusplus + #include "moocpp/gobjtypes-glib.h" #include "moocpp/strutils.h" diff --git a/moo/moocpp/gobjtypes-glib.h b/moo/moocpp/gobjtypes-glib.h index 5c8426b6..f748d915 100644 --- a/moo/moocpp/gobjtypes-glib.h +++ b/moo/moocpp/gobjtypes-glib.h @@ -15,10 +15,11 @@ #pragma once -#ifdef __cplusplus - #include #include + +#ifdef __cplusplus + #include "moocpp/gobjptr.h" #include "moocpp/gobjectutils.h" diff --git a/moo/moocpp/gobjtypes-gtk.h b/moo/moocpp/gobjtypes-gtk.h index 964b7665..0d79ddcb 100644 --- a/moo/moocpp/gobjtypes-gtk.h +++ b/moo/moocpp/gobjtypes-gtk.h @@ -15,11 +15,11 @@ #pragma once -#ifdef __cplusplus - #include #include +#ifdef __cplusplus + #include "moocpp/gobjtypes-glib.h" #define MOO_DEFINE_GTK_TYPE(Object, Parent, obj_g_type) \ diff --git a/moo/moocpp/grefptr.h b/moo/moocpp/grefptr.h index edd297c3..24c7d364 100644 --- a/moo/moocpp/grefptr.h +++ b/moo/moocpp/grefptr.h @@ -69,7 +69,7 @@ public: assign(obj, ref_transfer::make_copy); } - void take(Object* obj) + void set_new(Object* obj) { assign(obj, ref_transfer::take_ownership); } diff --git a/moo/moocpp/memutils.h b/moo/moocpp/memutils.h index 872ed216..29876a36 100644 --- a/moo/moocpp/memutils.h +++ b/moo/moocpp/memutils.h @@ -261,10 +261,10 @@ public: } template - static Self wrap_literal(Arg&& arg) + static Self wrap_const(Arg&& arg) { Self s; - s.literal(std::forward(arg)); + s.set_const(std::forward(arg)); return std::move(s); } @@ -280,7 +280,7 @@ public: static Self wrap_new(Arg&& arg) { Self s; - s.take(std::forward(arg)); + s.set_new(std::forward(arg)); return std::move(s); } diff --git a/moo/moocpp/strutils.cpp b/moo/moocpp/strutils.cpp index 6346b7a1..e9011a66 100644 --- a/moo/moocpp/strutils.cpp +++ b/moo/moocpp/strutils.cpp @@ -18,27 +18,6 @@ using namespace moo; -MOO_DEFINE_STANDARD_PTR_METHODS(gstr, super) - -const gstr gstr::null; - -//static void compile_errors(const gstr& constref, gstr& ref, gstr val) -//{ -// //ref.borrow(g_strdup("zzz")); -// //gstr::make_borrowed(g_strdup("zzz")); -// gstr::make_borrowed(ref); -// gstr::make_borrowed(constref); -// -// if (constref) -// return; -// -// if (ref) -// return; -// -// if (val) -// return; -//} - static bool str_equal(const char* s1, const char* s2) { if (!s1 || !*s1) @@ -78,3 +57,276 @@ bool moo::operator!=(const char* s1, const gstr& s2) { return !(s1 == s2); } + + +class StringData +{ +public: + StringData(const char* s) + : m_p(g_strdup(s)) + , m_ref(1) + { + } + + ~StringData() + { + g_free(m_p); + } + + StringData(const StringData&) = delete; + StringData& operator=(const StringData&) = delete; + + char* get() const + { + return m_p; + } + + char* release() + { + char* ret = m_p; + m_p = nullptr; + return ret; + } + + void ref() + { + g_atomic_int_inc(&m_ref); + } + + void unref() + { + if (g_atomic_int_dec_and_test(&m_ref)) + delete this; + } + + int ref_count() const + { + return g_atomic_int_get(&m_ref); + } + +private: + char* m_p; + int m_ref; +}; + +gstr::gstr() + : m_p(nullptr) + , m_is_inline(true) + , m_is_const(true) +{ +} + +gstr::gstr(const char* s, mem_transfer mt) + : gstr() +{ + if (s == nullptr) + return; + + if (*s == 0) + { + if (mt == mem_transfer::take_ownership) + g_free(const_cast(s)); + + mt = mem_transfer::borrow; + s = ""; + } + + switch (mt) + { + case mem_transfer::borrow: + m_is_const = true; + m_is_inline = true; + m_p = const_cast(s); + break; + + case mem_transfer::make_copy: + m_is_const = false; + m_is_inline = true; + m_p = g_strdup(s); + break; + + case mem_transfer::take_ownership: + m_is_const = false; + m_is_inline = true; + m_p = const_cast(s); + break; + } +} + +gstr::gstr(const gstr& other) + : gstr() +{ + if (other.m_p == nullptr) + return; + + if (other.m_is_const) + { + moo_assert(other.m_is_inline); + m_p = other.m_p; + m_is_const = true; + m_is_inline = true; + } + else if (other.m_is_inline) + { + moo_assert(other.m_p != nullptr); + moo_assert(!other.m_is_const); + + StringData* d = new StringData(static_cast(other)); + m_p = d; + m_is_inline = false; + m_is_const = false; + } + else + { + moo_assert(other.m_p != nullptr); + moo_assert(!other.m_is_const); + StringData* d = reinterpret_cast(other.m_p); + m_p = d; + d->ref(); + } +} + +gstr& gstr::operator=(const gstr& other) +{ + if (this != &other) + { + gstr tmp(other); + *this = std::move(tmp); + } + + return *this; +} + +gstr::gstr(gstr&& other) + : gstr() +{ + *this = std::move(other); +} + +gstr& gstr::operator=(gstr&& other) +{ + std::swap(m_is_const, other.m_is_const); + std::swap(m_is_inline, other.m_is_inline); + std::swap(m_p, other.m_p); + return *this; +} + +gstr::~gstr() +{ + clear(); +} + +bool gstr::is_null() const +{ + bool ret = (m_p == nullptr); + moo_assert(!ret || m_is_const == true); + moo_assert(!ret || m_is_inline == true); + return ret; +} + +gstr::operator const char*() const +{ + if (m_is_inline) + return reinterpret_cast(m_p); + else + return reinterpret_cast(m_p)->get(); +} + +void gstr::assign(const char* s, mem_transfer mt) +{ + gstr tmp(s, mt); + *this = std::move(tmp); +} + +void gstr::clear() +{ + if (m_p == nullptr) + return; + + if (!m_is_const) + { + moo_assert(m_p != nullptr); + + if (m_is_inline) + g_free(m_p); + else + reinterpret_cast(m_p)->unref(); + + m_is_const = true; + } + + m_is_inline = true; + m_p = nullptr; +} + +char* gstr::get_mutable() +{ + if (!m_p) + { + return nullptr; + } + else if (m_is_const) + { + char* s = reinterpret_cast(m_p); + + if (*s != 0) + { + set(s); + moo_assert(!m_is_const); + moo_assert(m_is_inline); + } + + return reinterpret_cast(m_p); + } + else if (m_is_inline) + { + return reinterpret_cast(m_p); + } + else + { + StringData* d = reinterpret_cast(m_p); + moo_assert(d->get() && *d->get()); + + if (d->ref_count() == 1) + { + return d->get(); + } + else + { + m_p = g_strdup(d->get()); + m_is_inline = true; + return reinterpret_cast(m_p); + } + } +} + +char* gstr::release_owned() +{ + if (m_p == nullptr) + { + return nullptr; + } + else if (m_is_const) + { + return g_strdup(get()); + } + else if (m_is_inline) + { + m_is_const = true; + char* p = reinterpret_cast(m_p); + m_p = nullptr; + return p; + } + + StringData* d = reinterpret_cast(m_p); + moo_assert(d->get() && *d->get()); + + char* p = d->ref_count() == 1 ? d->release() : g_strdup(d->get()); + + d->unref(); + + m_p = nullptr; + m_is_const = true; + m_is_inline = true; + return p; +} diff --git a/moo/moocpp/strutils.h b/moo/moocpp/strutils.h index e826d553..663b2803 100644 --- a/moo/moocpp/strutils.h +++ b/moo/moocpp/strutils.h @@ -54,12 +54,6 @@ private: char* m_p; }; -struct gstr_mem_handler -{ - static char* dup(const char* p) { return p ? g_strdup (p) : nullptr; } - static void free(char* p) { ::g_free(p); } -}; - template struct mg_get_string { @@ -78,24 +72,54 @@ public: operator bool() const = delete; bool operator!() const = delete; - char* operator*() const = delete; - private: Self& self() { return static_cast(*this); } const Self& self() const { return static_cast(*this); } const char* c_str() const { return GetString::get_string(static_cast(*this)); } }; -class gstr - : public mg_mem_holder - , public gstr_methods_mixin +class gstr : public gstr_methods_mixin { - using super = mg_mem_holder; - public: - MOO_DECLARE_STANDARD_PTR_METHODS(gstr, super) + gstr(); + ~gstr(); + gstr(const char* s, mem_transfer mt); - static const gstr null; + gstr(const gstr&); + gstr& operator=(const gstr&); + gstr(gstr&&); + gstr& operator=(gstr&&); + + gstr(nullptr_t) : gstr() {} + gstr& operator=(nullptr_t) { clear(); return *this; } + + void set(const gstr& s) = delete; + static gstr wrap(const gstr& s) = delete; + + void set(const char *s) { assign(s, mem_transfer::make_copy); } + void set_new(char *s) { assign(s, mem_transfer::take_ownership); } + void set_const(const char *s) { assign(s, mem_transfer::borrow); } + static gstr wrap(const char *s) { return gstr(s, mem_transfer::make_copy); } + static gstr wrap_new(char *s) { return gstr(s, mem_transfer::take_ownership); } + static gstr wrap_const(const char *s) { return gstr(s, mem_transfer::borrow); } + + bool is_null() const; + + operator const char*() const; + const char* get() const { return static_cast(*this); } + + char* get_mutable(); + char* release_owned(); + void clear(); + void reset() { clear(); } + +private: + void assign(const char* s, mem_transfer mt); + +private: + void *m_p; // either char* or Data* + bool m_is_inline; + bool m_is_const; }; diff --git a/moo/mooedit/mooedit-fileops.cpp b/moo/mooedit/mooedit-fileops.cpp index 6a38c89b..703700a1 100644 --- a/moo/mooedit/mooedit-fileops.cpp +++ b/moo/mooedit/mooedit-fileops.cpp @@ -116,9 +116,9 @@ normalize_encoding (const gstr& encoding, bool for_save) { if (encoding.empty() || encoding == MOO_ENCODING_AUTO) - return for_save ? gstr::wrap_literal(MOO_ENCODING_UTF8) : gstr(); + return for_save ? gstr::wrap_const(MOO_ENCODING_UTF8) : gstr(); else - return encoding.borrow(); + return encoding; } @@ -194,8 +194,6 @@ convert_file_data_to_utf8_with_prompt (const char* data, cached_encoding = NULL; } - used_encoding.ensure_not_borrowed(); - return text_utf8; } @@ -258,7 +256,7 @@ bool _moo_edit_save_file(Edit edit, MooEditSaveFlags flags, gerrp& error) { - gstr encoding_copy = gstr::make_copy(normalize_encoding(encoding, true)); + gstr encoding_copy = gstr::wrap(normalize_encoding(encoding, true)); return moo_edit_save_local(edit, file, encoding_copy, flags, error); } @@ -269,7 +267,7 @@ bool _moo_edit_save_file_copy(Edit edit, MooEditSaveFlags flags, gerrp& error) { - gstr encoding_copy = gstr::make_copy(normalize_encoding(encoding, true)); + gstr encoding_copy = gstr::wrap(normalize_encoding(encoding, true)); return moo_edit_save_copy_local(edit, file, encoding_copy, flags, error); } @@ -361,13 +359,13 @@ get_encodings (void) } if (!any_of(result, [enc](const char* s) { return g_ascii_strcasecmp(s, enc) == 0; })) - result.emplace_back(gstr::make_copy(enc)); + result.emplace_back(gstr::wrap(enc)); } if (result.empty()) { g_critical ("oops"); - result.emplace_back(gstr::wrap_literal("UTF-8")); + result.emplace_back(gstr::wrap_const("UTF-8")); } g_strfreev (raw); @@ -535,8 +533,8 @@ static bool moo_edit_reload_local(Edit edit, auto& priv = edit.get_priv(); gboolean result = _moo_edit_load_file(edit, *file, - encoding ? gstr::make_borrowed(encoding) : priv.encoding.borrow(), - NULL, + encoding ? gstr::wrap(encoding) : priv.encoding, + nullptr, error); if (result) @@ -660,7 +658,7 @@ do_save_local(Edit edit, gsize bom_len = 0; gstr utf8_contents = get_contents(edit); - moo_release_assert(utf8_contents != nullptr); + moo_release_assert(!utf8_contents.is_null()); if (encoding_needs_bom_save(encoding, &enc_no_bom, &bom, &bom_len)) encoding = enc_no_bom; @@ -994,11 +992,11 @@ void Edit::_set_file(g::FileRawPtr file, priv.norm_name = nullptr; if (n == 1) - priv.display_filename.copy(_("Untitled")); + priv.display_filename.set(_("Untitled")); else - priv.display_filename.take(g_strdup_printf(_("Untitled %d"), n)); + priv.display_filename.set_new(g_strdup_printf(_("Untitled %d"), n)); - priv.display_basename.copy(priv.display_filename); + priv.display_basename = priv.display_filename; } else { @@ -1006,8 +1004,8 @@ void Edit::_set_file(g::FileRawPtr file, priv.file = file->dup(); priv.filename = file->get_path(); priv.norm_name = _get_normalized_name(*file); - priv.display_filename.take(moo_file_get_display_name(*file)); - priv.display_basename.take(moo_file_get_display_basename(*file)); + priv.display_filename = moo_file_get_display_name(*file); + priv.display_basename = moo_file_get_display_basename(*file); } if (!encoding) @@ -1292,7 +1290,7 @@ moo_convert_file_data_to_utf8 (const char *data, std::list encodings = get_encodings (); if (cached_encoding) - encodings.push_front(gstr::make_borrowed(cached_encoding)); + encodings.push_front(gstr::wrap(cached_encoding)); for (auto& enc: encodings) { @@ -1308,7 +1306,7 @@ moo_convert_file_data_to_utf8 (const char *data, else { result = try_convert_to_utf8_from_encoding (data, len, encoding); - used_enc = gstr::make_borrowed(encoding); + used_enc = gstr::wrap(encoding); } return result; diff --git a/moo/mooedit/mooedit.cpp b/moo/mooedit/mooedit.cpp index d9dd20c0..4b077407 100644 --- a/moo/mooedit/mooedit.cpp +++ b/moo/mooedit/mooedit.cpp @@ -277,7 +277,7 @@ moo_edit_class_init (MooEditClass *klass) MooEditPrivate::MooEditPrivate() : line_end_type(MOO_LE_NONE) { - buffer.take(GTK_TEXT_BUFFER(g_object_new(MOO_TYPE_TEXT_BUFFER, NULL))); + buffer.set_new(GTK_TEXT_BUFFER(g_object_new(MOO_TYPE_TEXT_BUFFER, NULL))); actions = wrap_new (moo_action_collection_new ("MooEdit", "MooEdit")); } @@ -836,7 +836,7 @@ moo_edit_set_encoding (MooEdit *edit, if (edit->priv->encoding != encoding) { - edit->priv->encoding.copy(encoding); + edit->priv->encoding.set(encoding); g_object_notify (G_OBJECT (edit), "encoding"); } } diff --git a/moo/mooedit/mooeditdialogs.cpp b/moo/mooedit/mooeditdialogs.cpp index 97c24b28..390d65bb 100644 --- a/moo/mooedit/mooeditdialogs.cpp +++ b/moo/mooedit/mooeditdialogs.cpp @@ -54,7 +54,7 @@ _moo_edit_open_dialog (GtkWidget *widget, } if (!start) - start.take(moo_prefs_get_file(moo_edit_setting(MOO_EDIT_PREFS_LAST_DIR))); + start.set_new(moo_prefs_get_file(moo_edit_setting(MOO_EDIT_PREFS_LAST_DIR))); dialog = moo_file_dialog_new (MOO_FILE_DIALOG_OPEN, widget, TRUE, GTK_STOCK_OPEN, start.gobj(), @@ -79,7 +79,7 @@ _moo_edit_open_dialog (GtkWidget *widget, for (i = 0; i < files->n_elms; ++i) moo_open_info_array_take (info_array, moo_open_info_new_file (files->elms[i], encoding, -1, MOO_OPEN_FLAGS_NONE)); - start.take(g_file_get_parent (files->elms[0])); + start.set_new(g_file_get_parent (files->elms[0])); moo_prefs_set_file (moo_edit_setting (MOO_EDIT_PREFS_LAST_DIR), start.gobj()); } @@ -96,8 +96,8 @@ _moo_edit_save_as_dialog (MooEdit *doc, const char *encoding; MooFileDialog *dialog; MooSaveInfo *info; - GFile *start = NULL; - GFile *file = NULL; + g::FilePtr start; + g::FilePtr file; g_return_val_if_fail (MOO_IS_EDIT (doc), NULL); @@ -106,20 +106,19 @@ _moo_edit_save_as_dialog (MooEdit *doc, if (moo_prefs_get_bool (moo_edit_setting (MOO_EDIT_PREFS_DIALOGS_OPEN_FOLLOWS_DOC))) { - file = moo_edit_get_file (doc); + file = wrap_new (moo_edit_get_file (doc)); if (file) - start = g_file_get_parent (file); - g_object_unref (file); + start = file->get_parent (); file = NULL; } if (!start) - start = moo_prefs_get_file (moo_edit_setting (MOO_EDIT_PREFS_LAST_DIR)); + start = wrap_new (moo_prefs_get_file (moo_edit_setting (MOO_EDIT_PREFS_LAST_DIR))); dialog = moo_file_dialog_new (MOO_FILE_DIALOG_SAVE, GTK_WIDGET (moo_edit_get_view (doc)), FALSE, GTK_STOCK_SAVE_AS, - start, display_basename); + start.gobj(), display_basename); g_object_set (dialog, "enable-encodings", TRUE, NULL); moo_file_dialog_set_encoding (dialog, moo_edit_get_encoding (doc)); moo_file_dialog_set_help_id (dialog, "dialog-save"); @@ -129,21 +128,17 @@ _moo_edit_save_as_dialog (MooEdit *doc, if (!moo_file_dialog_run (dialog)) { g_object_unref (dialog); - g_object_unref (start); return NULL; } encoding = moo_file_dialog_get_encoding (dialog); file = moo_file_dialog_get_file (dialog); - g_return_val_if_fail (file != NULL, NULL); - info = moo_save_info_new_file (file, encoding); + g_return_val_if_fail (file != nullptr, NULL); + info = moo_save_info_new_file (file.gobj(), encoding); - g_object_unref (start); - start = g_file_get_parent (file); - moo_prefs_set_file (moo_edit_setting (MOO_EDIT_PREFS_LAST_DIR), start); + start = file->get_parent (); + moo_prefs_set_file (moo_edit_setting (MOO_EDIT_PREFS_LAST_DIR), start.gobj()); - g_object_unref (start); - g_object_unref (file); g_object_unref (dialog); return info; } @@ -496,20 +491,20 @@ _moo_edit_try_encoding_dialog (g::File file, { /* Could not open file foo.txt */ gstr tmp = gstr::wrap_new(g_strdup_printf(_("Could not open file\n%s"), filename.get())); - msg.take(g_markup_printf_escaped("%s", tmp.get())); + msg.set_new(g_markup_printf_escaped("%s", tmp.get())); } else { const char *tmp = _("Could not open file"); - msg.take(g_markup_printf_escaped("%s", tmp)); + msg.set_new(g_markup_printf_escaped("%s", tmp)); } if (encoding != NULL) - secondary.take(g_strdup_printf (_("Could not open file using character encoding %s. " - "Try to select another encoding below."), encoding)); + secondary.set_new(g_strdup_printf (_("Could not open file using character encoding %s. " + "Try to select another encoding below."), encoding)); else - secondary.take(g_strdup_printf (_("Could not detect file character encoding. " - "Try to select an encoding below."))); + secondary.set_new(g_strdup_printf (_("Could not detect file character encoding. " + "Try to select an encoding below."))); xml = try_encoding_dialog_xml_new (); g_return_val_if_fail (xml && xml->TryEncodingDialog, MOO_EDIT_TRY_ENCODING_RESPONSE_CANCEL); @@ -537,7 +532,7 @@ _moo_edit_try_encoding_dialog (g::File file, dialog_response = gtk_dialog_run (GTK_DIALOG (dialog)); - new_encoding.copy(_moo_encodings_combo_get_enc (GTK_COMBO_BOX (xml->encoding_combo), MOO_ENCODING_COMBO_OPEN)); + new_encoding.set(_moo_encodings_combo_get_enc (GTK_COMBO_BOX (xml->encoding_combo), MOO_ENCODING_COMBO_OPEN)); gtk_widget_destroy (dialog); @@ -560,12 +555,12 @@ _moo_edit_open_error_dialog (GtkWidget* widget, if (!filename.empty()) /* Could not open file foo.txt */ - msg.take (g_strdup_printf (_("Could not open file\n%s"), filename.get())); + msg.set_new (g_strdup_printf (_("Could not open file\n%s"), filename.get())); else - msg.literal (_("Could not open file")); + msg.set_const (_("Could not open file")); if (error) - secondary.borrow (error->message); + secondary.set (error->message); moo_error_dialog (msg, secondary, widget); } diff --git a/moo/mooedit/mooeditfileinfo-impl.h b/moo/mooedit/mooeditfileinfo-impl.h index ea1b54a3..bad2125d 100644 --- a/moo/mooedit/mooeditfileinfo-impl.h +++ b/moo/mooedit/mooeditfileinfo-impl.h @@ -15,7 +15,7 @@ struct MooOpenInfo MooOpenInfo(GFile* file, const char* encoding, int line, MooOpenFlags flags) : file(wrap_new(g_file_dup(file))) - , encoding(gstr::make_copy(encoding)) + , encoding(gstr::wrap(encoding)) , line(line) , flags(flags) { @@ -23,7 +23,7 @@ struct MooOpenInfo MooOpenInfo(const MooOpenInfo& other) : file(other.file->dup()) - , encoding(other.encoding.copy()) + , encoding(other.encoding) , line(other.line) , flags(other.flags) { @@ -37,13 +37,13 @@ struct MooOpenInfo struct MooReloadInfo : public GObject { MooReloadInfo(const char* encoding, int line) - : encoding(gstr::make_copy(encoding)) + : encoding(gstr::wrap(encoding)) , line(line) { } MooReloadInfo(const MooReloadInfo& other) - : encoding(other.encoding.copy()) + : encoding(other.encoding) , line(other.line) { } @@ -61,13 +61,13 @@ struct MooSaveInfo : public GObject MooSaveInfo(GFile* file, const char* encoding) : file(wrap_new(g_file_dup(file))) - , encoding(gstr::make_copy(encoding)) + , encoding(gstr::wrap(encoding)) { } MooSaveInfo(const MooSaveInfo& other) : file(other.file->dup()) - , encoding(other.encoding.copy()) + , encoding(other.encoding) { } diff --git a/moo/mooedit/mooeditfileinfo.cpp b/moo/mooedit/mooeditfileinfo.cpp index bfccba93..5362063a 100644 --- a/moo/mooedit/mooeditfileinfo.cpp +++ b/moo/mooedit/mooeditfileinfo.cpp @@ -1,342 +1,342 @@ -/** -* boxed:MooOpenInfo: information for opening a file - * - * Object which contains filename, character encoding, line - * number, and options to use in moo_editor_open_file(). - **/ - -/** - * boxed:MooSaveInfo: information for saving a file - * - * Object which contains a filename and character encoding to - * use in moo_editor_save() and moo_editor_save_as(). - **/ - -/** - * boxed:MooReloadInfo: information for reloading a file - * - * Object which contains character encoding and line number to - * use in moo_editor_reload(). - **/ - -#include "mooeditfileinfo-impl.h" -#include -#include - -using namespace moo; - -MOO_DEFINE_BOXED_CPP_TYPE(MooOpenInfo, moo_open_info) -MOO_DEFINE_BOXED_CPP_TYPE(MooSaveInfo, moo_save_info) -MOO_DEFINE_BOXED_CPP_TYPE(MooReloadInfo, moo_reload_info) - -MOO_DEFINE_PTR_ARRAY_FULL(MooOpenInfoArray, moo_open_info_array, MooOpenInfo, - gboxed_helper::array_elm_copy, - gboxed_helper::array_elm_free) - -/** - * moo_open_info_new_file: (static-method-of MooOpenInfo) (moo-kwargs) - * - * @file: - * @encoding: (type const-utf8) (allow-none) (default NULL) - * @line: (type index) (default -1) - * @flags: (default 0) - * - * Returns: (transfer full) - **/ -MooOpenInfo * -moo_open_info_new_file (GFile *file, - const char *encoding, - int line, - MooOpenFlags flags) -{ - g_return_val_if_fail (G_IS_FILE (file), nullptr); - return new MooOpenInfo(file, encoding, line, flags); -} - -/** - * moo_open_info_new: (constructor-of MooOpenInfo) (moo-kwargs) - * - * @path: (type const-filename) - * @encoding: (type const-utf8) (allow-none) (default NULL) - * @line: (type index) (default -1) - * @flags: (default 0) - * - * Returns: (transfer full) - **/ -MooOpenInfo * -moo_open_info_new (const char *path, - const char *encoding, - int line, - MooOpenFlags flags) -{ - g::FilePtr file = g::File::new_for_path(path); - return moo_open_info_new_file (file.gobj(), encoding, line, flags); -} - -/** - * moo_open_info_new_uri: (static-method-of MooOpenInfo) (moo-kwargs) - * - * @uri: (type const-utf8) - * @encoding: (type const-utf8) (allow-none) (default NULL) - * @line: (type index) (default -1) - * @flags: (default 0) - * - * Returns: (transfer full) - **/ -MooOpenInfo * -moo_open_info_new_uri (const char *uri, - const char *encoding, - int line, - MooOpenFlags flags) -{ - g::FilePtr file = g::File::new_for_uri(uri); - return moo_open_info_new_file (file.gobj(), encoding, line, flags); -} - -/** - * moo_open_info_dup: - * - * Returns: (transfer full) - **/ -MooOpenInfo * -moo_open_info_dup (MooOpenInfo *info) -{ - g_return_val_if_fail(info != nullptr, nullptr); - return new MooOpenInfo(*info); -} - - -/** - * moo_open_info_get_filename: (moo.private 1) - * - * Returns: (type filename) - **/ -char * -moo_open_info_get_filename (MooOpenInfo *info) -{ - g_return_val_if_fail(info != nullptr, nullptr); - return info->file->get_path().release_owned(); -} - -/** - * moo_open_info_get_uri: (moo.private 1) - * - * Returns: (type utf8) - **/ -char * -moo_open_info_get_uri (MooOpenInfo *info) -{ - g_return_val_if_fail(info != nullptr, nullptr); - return info->file->get_uri().release_owned(); -} - -/** - * moo_open_info_get_file: (moo.private 1) - * - * Returns: (transfer full) - **/ -GFile * -moo_open_info_get_file (MooOpenInfo *info) -{ - g_return_val_if_fail(info != nullptr, nullptr); - return info->file->dup().release(); -} - -/** - * moo_open_info_get_encoding: (moo.private 1) - * - * Returns: (type const-utf8) - **/ -const char * -moo_open_info_get_encoding (MooOpenInfo *info) -{ - g_return_val_if_fail(info != nullptr, nullptr); - return info->encoding; -} - -/** - * moo_open_info_set_encoding: (moo.private 1) - * - * @info: - * @encoding: (type const-utf8) (allow-none) - **/ -void -moo_open_info_set_encoding (MooOpenInfo *info, - const char *encoding) -{ - g_return_if_fail(info != nullptr); - info->encoding.copy(encoding); -} - -/** - * moo_open_info_get_line: - * - * Returns: (type index) - **/ -int -moo_open_info_get_line (MooOpenInfo *info) -{ - g_return_val_if_fail(info != nullptr, -1); - return info->line; -} - -/** - * moo_open_info_set_line: - * - * @info: - * @line: (type index) - **/ -void -moo_open_info_set_line (MooOpenInfo *info, - int line) -{ - g_return_if_fail(info != nullptr); - info->line = line; -} - -/** - * moo_open_info_get_flags: - **/ -MooOpenFlags -moo_open_info_get_flags (MooOpenInfo *info) -{ - g_return_val_if_fail(info != nullptr, MOO_OPEN_FLAGS_NONE); - return info->flags; -} - -/** - * moo_open_info_set_flags: - **/ -void -moo_open_info_set_flags(MooOpenInfo *info, - MooOpenFlags flags) -{ - g_return_if_fail(info != nullptr); - info->flags = flags; -} - -/** - * moo_open_info_add_flags: - **/ -void -moo_open_info_add_flags(MooOpenInfo *info, - MooOpenFlags flags) -{ - g_return_if_fail(info != nullptr); - info->flags |= flags; -} - - -/** - * moo_save_info_new_file: (static-method-of MooSaveInfo) - * - * @file: - * @encoding: (type const-utf8) (allow-none) (default NULL) - * - * Returns: (transfer full) - **/ -MooSaveInfo * -moo_save_info_new_file(GFile *file, - const char *encoding) -{ - g_return_val_if_fail(G_IS_FILE(file), nullptr); - return new MooSaveInfo(file, encoding); -} - -/** - * moo_save_info_new: (constructor-of MooSaveInfo) - * - * @path: (type const-filename) - * @encoding: (type const-utf8) (allow-none) (default NULL) - * - * Returns: (transfer full) - **/ -MooSaveInfo * -moo_save_info_new(const char *path, - const char *encoding) -{ - auto file = g::File::new_for_path(path); - MooSaveInfo *info = moo_save_info_new_file(file.gobj(), encoding); - return info; -} - -/** - * moo_save_info_new_uri: (static-method-of MooSaveInfo) - * - * @uri: (type const-utf8) - * @encoding: (type const-utf8) (allow-none) (default NULL) - * - * Returns: (transfer full) - **/ -MooSaveInfo * -moo_save_info_new_uri (const char *uri, - const char *encoding) -{ - auto file = g::File::new_for_uri(uri); - MooSaveInfo *info = moo_save_info_new_file(file.gobj(), encoding); - return info; -} - -/** - * moo_save_info_dup: - * - * Returns: (transfer full) - **/ -MooSaveInfo * -moo_save_info_dup (MooSaveInfo *info) -{ - g_return_val_if_fail(info != nullptr, nullptr); - return new MooSaveInfo(*info); -} - - -/** - * moo_reload_info_new: (constructor-of MooReloadInfo) - * - * @encoding: (type const-utf8) (allow-none) (default NULL) - * @line: (type index) (default -1) - **/ -MooReloadInfo * -moo_reload_info_new (const char *encoding, - int line) -{ - return new MooReloadInfo(encoding, line); -} - -/** - * moo_reload_info_dup: - * - * Returns: (transfer full) - **/ -MooReloadInfo * -moo_reload_info_dup (MooReloadInfo *info) -{ - g_return_val_if_fail(info != nullptr, nullptr); - return new MooReloadInfo(*info); -} - -/** - * moo_reload_info_get_line: - * - * Returns: (type index) - **/ -int -moo_reload_info_get_line (MooReloadInfo *info) -{ - g_return_val_if_fail (info != nullptr, -1); - return info->line; -} - -/** - * moo_reload_info_set_line: - * - * @info: - * @line: (type index) - **/ -void -moo_reload_info_set_line (MooReloadInfo *info, - int line) -{ - g_return_if_fail (info != nullptr); - info->line = line; -} +/** +* boxed:MooOpenInfo: information for opening a file + * + * Object which contains filename, character encoding, line + * number, and options to use in moo_editor_open_file(). + **/ + +/** + * boxed:MooSaveInfo: information for saving a file + * + * Object which contains a filename and character encoding to + * use in moo_editor_save() and moo_editor_save_as(). + **/ + +/** + * boxed:MooReloadInfo: information for reloading a file + * + * Object which contains character encoding and line number to + * use in moo_editor_reload(). + **/ + +#include "mooeditfileinfo-impl.h" +#include +#include + +using namespace moo; + +MOO_DEFINE_BOXED_CPP_TYPE(MooOpenInfo, moo_open_info) +MOO_DEFINE_BOXED_CPP_TYPE(MooSaveInfo, moo_save_info) +MOO_DEFINE_BOXED_CPP_TYPE(MooReloadInfo, moo_reload_info) + +MOO_DEFINE_PTR_ARRAY_FULL(MooOpenInfoArray, moo_open_info_array, MooOpenInfo, + gboxed_helper::array_elm_copy, + gboxed_helper::array_elm_free) + +/** + * moo_open_info_new_file: (static-method-of MooOpenInfo) (moo-kwargs) + * + * @file: + * @encoding: (type const-utf8) (allow-none) (default NULL) + * @line: (type index) (default -1) + * @flags: (default 0) + * + * Returns: (transfer full) + **/ +MooOpenInfo * +moo_open_info_new_file (GFile *file, + const char *encoding, + int line, + MooOpenFlags flags) +{ + g_return_val_if_fail (G_IS_FILE (file), nullptr); + return new MooOpenInfo(file, encoding, line, flags); +} + +/** + * moo_open_info_new: (constructor-of MooOpenInfo) (moo-kwargs) + * + * @path: (type const-filename) + * @encoding: (type const-utf8) (allow-none) (default NULL) + * @line: (type index) (default -1) + * @flags: (default 0) + * + * Returns: (transfer full) + **/ +MooOpenInfo * +moo_open_info_new (const char *path, + const char *encoding, + int line, + MooOpenFlags flags) +{ + g::FilePtr file = g::File::new_for_path(path); + return moo_open_info_new_file (file.gobj(), encoding, line, flags); +} + +/** + * moo_open_info_new_uri: (static-method-of MooOpenInfo) (moo-kwargs) + * + * @uri: (type const-utf8) + * @encoding: (type const-utf8) (allow-none) (default NULL) + * @line: (type index) (default -1) + * @flags: (default 0) + * + * Returns: (transfer full) + **/ +MooOpenInfo * +moo_open_info_new_uri (const char *uri, + const char *encoding, + int line, + MooOpenFlags flags) +{ + g::FilePtr file = g::File::new_for_uri(uri); + return moo_open_info_new_file (file.gobj(), encoding, line, flags); +} + +/** + * moo_open_info_dup: + * + * Returns: (transfer full) + **/ +MooOpenInfo * +moo_open_info_dup (MooOpenInfo *info) +{ + g_return_val_if_fail(info != nullptr, nullptr); + return new MooOpenInfo(*info); +} + + +/** + * moo_open_info_get_filename: (moo.private 1) + * + * Returns: (type filename) + **/ +char * +moo_open_info_get_filename (MooOpenInfo *info) +{ + g_return_val_if_fail(info != nullptr, nullptr); + return info->file->get_path().release_owned(); +} + +/** + * moo_open_info_get_uri: (moo.private 1) + * + * Returns: (type utf8) + **/ +char * +moo_open_info_get_uri (MooOpenInfo *info) +{ + g_return_val_if_fail(info != nullptr, nullptr); + return info->file->get_uri().release_owned(); +} + +/** + * moo_open_info_get_file: (moo.private 1) + * + * Returns: (transfer full) + **/ +GFile * +moo_open_info_get_file (MooOpenInfo *info) +{ + g_return_val_if_fail(info != nullptr, nullptr); + return info->file->dup().release(); +} + +/** + * moo_open_info_get_encoding: (moo.private 1) + * + * Returns: (type const-utf8) + **/ +const char * +moo_open_info_get_encoding (MooOpenInfo *info) +{ + g_return_val_if_fail(info != nullptr, nullptr); + return info->encoding; +} + +/** + * moo_open_info_set_encoding: (moo.private 1) + * + * @info: + * @encoding: (type const-utf8) (allow-none) + **/ +void +moo_open_info_set_encoding (MooOpenInfo *info, + const char *encoding) +{ + g_return_if_fail(info != nullptr); + info->encoding.set(encoding); +} + +/** + * moo_open_info_get_line: + * + * Returns: (type index) + **/ +int +moo_open_info_get_line (MooOpenInfo *info) +{ + g_return_val_if_fail(info != nullptr, -1); + return info->line; +} + +/** + * moo_open_info_set_line: + * + * @info: + * @line: (type index) + **/ +void +moo_open_info_set_line (MooOpenInfo *info, + int line) +{ + g_return_if_fail(info != nullptr); + info->line = line; +} + +/** + * moo_open_info_get_flags: + **/ +MooOpenFlags +moo_open_info_get_flags (MooOpenInfo *info) +{ + g_return_val_if_fail(info != nullptr, MOO_OPEN_FLAGS_NONE); + return info->flags; +} + +/** + * moo_open_info_set_flags: + **/ +void +moo_open_info_set_flags(MooOpenInfo *info, + MooOpenFlags flags) +{ + g_return_if_fail(info != nullptr); + info->flags = flags; +} + +/** + * moo_open_info_add_flags: + **/ +void +moo_open_info_add_flags(MooOpenInfo *info, + MooOpenFlags flags) +{ + g_return_if_fail(info != nullptr); + info->flags |= flags; +} + + +/** + * moo_save_info_new_file: (static-method-of MooSaveInfo) + * + * @file: + * @encoding: (type const-utf8) (allow-none) (default NULL) + * + * Returns: (transfer full) + **/ +MooSaveInfo * +moo_save_info_new_file(GFile *file, + const char *encoding) +{ + g_return_val_if_fail(G_IS_FILE(file), nullptr); + return new MooSaveInfo(file, encoding); +} + +/** + * moo_save_info_new: (constructor-of MooSaveInfo) + * + * @path: (type const-filename) + * @encoding: (type const-utf8) (allow-none) (default NULL) + * + * Returns: (transfer full) + **/ +MooSaveInfo * +moo_save_info_new(const char *path, + const char *encoding) +{ + auto file = g::File::new_for_path(path); + MooSaveInfo *info = moo_save_info_new_file(file.gobj(), encoding); + return info; +} + +/** + * moo_save_info_new_uri: (static-method-of MooSaveInfo) + * + * @uri: (type const-utf8) + * @encoding: (type const-utf8) (allow-none) (default NULL) + * + * Returns: (transfer full) + **/ +MooSaveInfo * +moo_save_info_new_uri (const char *uri, + const char *encoding) +{ + auto file = g::File::new_for_uri(uri); + MooSaveInfo *info = moo_save_info_new_file(file.gobj(), encoding); + return info; +} + +/** + * moo_save_info_dup: + * + * Returns: (transfer full) + **/ +MooSaveInfo * +moo_save_info_dup (MooSaveInfo *info) +{ + g_return_val_if_fail(info != nullptr, nullptr); + return new MooSaveInfo(*info); +} + + +/** + * moo_reload_info_new: (constructor-of MooReloadInfo) + * + * @encoding: (type const-utf8) (allow-none) (default NULL) + * @line: (type index) (default -1) + **/ +MooReloadInfo * +moo_reload_info_new (const char *encoding, + int line) +{ + return new MooReloadInfo(encoding, line); +} + +/** + * moo_reload_info_dup: + * + * Returns: (transfer full) + **/ +MooReloadInfo * +moo_reload_info_dup (MooReloadInfo *info) +{ + g_return_val_if_fail(info != nullptr, nullptr); + return new MooReloadInfo(*info); +} + +/** + * moo_reload_info_get_line: + * + * Returns: (type index) + **/ +int +moo_reload_info_get_line (MooReloadInfo *info) +{ + g_return_val_if_fail (info != nullptr, -1); + return info->line; +} + +/** + * moo_reload_info_set_line: + * + * @info: + * @line: (type index) + **/ +void +moo_reload_info_set_line (MooReloadInfo *info, + int line) +{ + g_return_if_fail (info != nullptr); + info->line = line; +} diff --git a/moo/mooedit/mooeditfileinfo.h b/moo/mooedit/mooeditfileinfo.h index 14aa9e8e..167e0709 100644 --- a/moo/mooedit/mooeditfileinfo.h +++ b/moo/mooedit/mooeditfileinfo.h @@ -1,7 +1,7 @@ /* * mooeditfileinfo.h * - * Copyright (C) 2004-2010 by Yevgen Muntyan + * Copyright (C) 2004-2016 by Yevgen Muntyan * * This file is part of medit. medit is free software; you can * redistribute it and/or modify it under the terms of the @@ -15,8 +15,8 @@ #pragma once -#include #include +#include G_BEGIN_DECLS diff --git a/moo/mooedit/mooeditor.cpp b/moo/mooedit/mooeditor.cpp index c796dbaf..914cea97 100644 --- a/moo/mooedit/mooeditor.cpp +++ b/moo/mooedit/mooeditor.cpp @@ -375,7 +375,7 @@ moo_editor_constructor (GType type, _moo_stock_init (); - editor->priv->doc_ui_xml.take(moo_ui_xml_new()); + editor->priv->doc_ui_xml.set_new(moo_ui_xml_new()); moo_ui_xml_add_ui_from_string (editor->priv->doc_ui_xml.gobj(), mooedit_ui_xml, -1); @@ -384,7 +384,7 @@ moo_editor_constructor (GType type, G_CALLBACK (_moo_editor_apply_prefs), editor); - editor->priv->history.take(MOO_HISTORY_MGR ( + editor->priv->history.set_new(MOO_HISTORY_MGR ( g_object_new (MOO_TYPE_HISTORY_MGR, "name", "Editor", (const char*) NULL))); @@ -622,7 +622,7 @@ moo_editor_get_ui_xml (MooEditor *editor) if (!editor->priv->ui_xml) { - editor->priv->ui_xml.take(moo_ui_xml_new ()); + editor->priv->ui_xml.set_new(moo_ui_xml_new ()); moo_ui_xml_add_ui_from_string (editor->priv->ui_xml.gobj(), medit_ui_xml, -1); } @@ -1021,8 +1021,8 @@ moo_editor_load_file(MooEditor *editor, { // XXX success = _moo_edit_load_file(*doc, *info->file, - gstr::make_borrowed(info->encoding), - gstr::make_borrowed(recent_encoding), + info->encoding, + gstr::wrap(recent_encoding), error_here); } } @@ -1728,7 +1728,7 @@ load_doc_session (MooEditor *editor, if (file_is_uri) { - uri = gstr::make_copy(moo_markup_get_content(elm)); + uri = gstr::wrap(moo_markup_get_content(elm)); } else { @@ -2528,7 +2528,7 @@ moo_editor_save (MooEditor *editor, return moo_editor_save_as (editor, doc, NULL, error); g::FilePtr file = wrap_new(moo_edit_get_file(doc)); - gstr encoding = gstr::make_copy(moo_edit_get_encoding(doc)); + gstr encoding = gstr::wrap(moo_edit_get_encoding(doc)); if ((moo_edit_get_status (doc) & MOO_EDIT_STATUS_MODIFIED_ON_DISK) && !_moo_edit_overwrite_modified_dialog (doc)) diff --git a/moo/mooedit/mooeditprogress.cpp b/moo/mooedit/mooeditprogress.cpp index 1952f77a..3d542f18 100644 --- a/moo/mooedit/mooeditprogress.cpp +++ b/moo/mooedit/mooeditprogress.cpp @@ -90,7 +90,7 @@ void _moo_edit_progress_set_text (MooEditProgress& progress, const char* text) { - progress.text.copy(text); + progress.text.set(text); progress.update(); } @@ -147,7 +147,7 @@ _moo_edit_progress_start (MooEditProgress& progress, { g_return_if_fail(progress.timeout == 0); - progress.text.take(g_strdup(text)); + progress.text.set_new(g_strdup(text)); _moo_edit_progress_set_cancel_func(progress, cancel_func, cancel_func_data); diff --git a/moo/mooedit/moolangmgr.cpp b/moo/mooedit/moolangmgr.cpp index 8ea0fd51..7e4cba78 100644 --- a/moo/mooedit/moolangmgr.cpp +++ b/moo/mooedit/moolangmgr.cpp @@ -327,7 +327,7 @@ lang_mgr_get_lang_for_bak_filename (MooLangMgr *mgr, } if (base) - lang = get_lang_for_filename (mgr, gstr::make_borrowed(base)); + lang = get_lang_for_filename (mgr, gstr::wrap(base)); g_free (base); return lang; diff --git a/moo/mooutils/moofiledialog.cpp b/moo/mooutils/moofiledialog.cpp index 3761cc39..d933513b 100644 --- a/moo/mooutils/moofiledialog.cpp +++ b/moo/mooutils/moofiledialog.cpp @@ -30,6 +30,7 @@ #include #include +using namespace moo; struct _MooFileDialogPrivate { gboolean multiple; @@ -335,25 +336,22 @@ moo_file_dialog (GtkWidget *parent, const char *title, const char *start_dir) { - static char *filename; + static gstr filename; MooFileDialog *dialog; - GFile *start; - GFile *file; + g::FilePtr start; + g::FilePtr file; - start = start_dir ? g_file_new_for_path (start_dir) : NULL; + start = start_dir ? g::File::new_for_path (start_dir) : NULL; - dialog = moo_file_dialog_new (type, parent, FALSE, title, start, start_name); + dialog = moo_file_dialog_new (type, parent, FALSE, title, start.gobj(), start_name); g_return_val_if_fail (dialog != NULL, NULL); moo_file_dialog_run (dialog); file = moo_file_dialog_get_file (dialog); - g_free (filename); - filename = file ? g_file_get_path (file) : NULL; + filename = file ? file->get_path() : NULL; - g_object_unref (file); - g_object_unref (start); g_object_unref (dialog); return filename; } @@ -741,11 +739,11 @@ moo_file_dialog_set_extra_widget (MooFileDialog *dialog, } -GFile * +g::FilePtr moo_file_dialog_get_file (MooFileDialog *dialog) { g_return_val_if_fail (MOO_IS_FILE_DIALOG (dialog), NULL); - return dialog->priv->uri ? g_file_new_for_uri (dialog->priv->uri) : NULL; + return dialog->priv->uri ? g::File::new_for_uri (dialog->priv->uri) : NULL; } char * diff --git a/moo/mooutils/moofiledialog.h b/moo/mooutils/moofiledialog.h index 9735d609..0a275bca 100644 --- a/moo/mooutils/moofiledialog.h +++ b/moo/mooutils/moofiledialog.h @@ -1,7 +1,7 @@ /* * moofiledialog.h * - * Copyright (C) 2004-2010 by Yevgen Muntyan + * Copyright (C) 2004-2016 by Yevgen Muntyan * * This file is part of medit. medit is free software; you can * redistribute it and/or modify it under the terms of the @@ -13,11 +13,11 @@ * License along with medit. If not, see . */ -#ifndef MOO_FILE_DIALOG_H -#define MOO_FILE_DIALOG_H +#pragma once #include #include +#include G_BEGIN_DECLS @@ -69,7 +69,11 @@ void moo_file_dialog_set_filter_mgr_id (MooFileDialog *dialog, const char *id); gboolean moo_file_dialog_run (MooFileDialog *dialog); -GFile *moo_file_dialog_get_file (MooFileDialog *dialog); +#ifdef __cplusplus +G_END_DECLS +moo::g::FilePtr moo_file_dialog_get_file (MooFileDialog *dialog); +G_BEGIN_DECLS +#endif MooFileArray *moo_file_dialog_get_files (MooFileDialog *dialog); char *moo_file_dialog_get_uri (MooFileDialog *dialog); char **moo_file_dialog_get_uris (MooFileDialog *dialog); @@ -109,5 +113,3 @@ const char *moo_file_dialogp (GtkWidget *parent, G_END_DECLS - -#endif /* MOO_FILE_DIALOG_H */ diff --git a/moo/mooutils/mooutils-misc.cpp b/moo/mooutils/mooutils-misc.cpp index 386f8ca4..743ceff6 100644 --- a/moo/mooutils/mooutils-misc.cpp +++ b/moo/mooutils/mooutils-misc.cpp @@ -983,7 +983,7 @@ private: void moo_set_log_func_file (const char *log_file) { - LogHandler::set_writer(make_unique(gstr::make_copy(log_file))); + LogHandler::set_writer(make_unique(gstr::wrap(log_file))); } @@ -1746,9 +1746,9 @@ save_user_data_file (const char *basename, gstr file; if (cache) - file.take (moo_get_user_cache_file (basename)); + file.set_new (moo_get_user_cache_file (basename)); else - file.take (moo_get_user_data_file (basename)); + file.set_new (moo_get_user_data_file (basename)); return save_config_file (file, content, len, error); } @@ -2247,7 +2247,7 @@ moo_error_message (GError *error) moo::gstr moo_error_message(const moo::gerrp& err) { - return gstr::make_borrowed (moo_error_message (err.get ())); + return gstr::wrap (moo_error_message (err.get ())); }