[gnome-builder: 59/139] beautifier: port to libide-editor
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder: 59/139] beautifier: port to libide-editor
- Date: Thu, 10 Jan 2019 04:22:16 +0000 (UTC)
commit 335c4e2565d16361c144e405e8778bee7b29e00a
Author: Christian Hergert <chergert redhat com>
Date: Wed Jan 9 17:02:31 2019 -0800
beautifier: port to libide-editor
This ports the beautifier code to use the new libide-editor design and
renamed layout components.
...{gb-beautifier-plugin.c => beautifier-plugin.c} | 10 ++--
...fier.gresource.xml => beautifier.gresource.xml} | 16 +++----
src/plugins/beautifier/beautifier.plugin | 12 ++---
src/plugins/beautifier/gb-beautifier-config.c | 55 ++++++++++------------
.../beautifier/gb-beautifier-editor-addin.c | 42 ++++++++---------
src/plugins/beautifier/gb-beautifier-helper.c | 2 +-
src/plugins/beautifier/gb-beautifier-helper.h | 2 +-
src/plugins/beautifier/gb-beautifier-private.h | 19 ++++----
src/plugins/beautifier/gb-beautifier-process.c | 2 +-
src/plugins/beautifier/meson.build | 28 +++++------
10 files changed, 87 insertions(+), 101 deletions(-)
---
diff --git a/src/plugins/beautifier/gb-beautifier-plugin.c b/src/plugins/beautifier/beautifier-plugin.c
similarity index 87%
rename from src/plugins/beautifier/gb-beautifier-plugin.c
rename to src/plugins/beautifier/beautifier-plugin.c
index 6668b8754..ec065e5ef 100644
--- a/src/plugins/beautifier/gb-beautifier-plugin.c
+++ b/src/plugins/beautifier/beautifier-plugin.c
@@ -1,4 +1,4 @@
-/* gb-beautifier-plugin.c
+/* beautifier-plugin.c
*
* Copyright 2016 sebastien lafargue <slafargue gnome org>
*
@@ -18,13 +18,15 @@
* SPDX-License-Identifier: GPL-3.0-or-later
*/
-#include <ide.h>
+#include "config.h"
+
+#include <libide-editor.h>
#include <libpeas/peas.h>
#include "gb-beautifier-editor-addin.h"
-void
-gb_beautifier_register_types (PeasObjectModule *module)
+_IDE_EXTERN void
+_gb_beautifier_register_types (PeasObjectModule *module)
{
peas_object_module_register_extension_type (module,
IDE_TYPE_EDITOR_ADDIN,
diff --git a/src/plugins/beautifier/gb-beautifier.gresource.xml
b/src/plugins/beautifier/beautifier.gresource.xml
similarity index 70%
rename from src/plugins/beautifier/gb-beautifier.gresource.xml
rename to src/plugins/beautifier/beautifier.gresource.xml
index c52028579..6e40f6899 100644
--- a/src/plugins/beautifier/gb-beautifier.gresource.xml
+++ b/src/plugins/beautifier/beautifier.gresource.xml
@@ -1,12 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
- <gresource prefix="/org/gnome/builder/plugins">
+ <gresource prefix="/plugins/beautifier">
<file>beautifier.plugin</file>
- </gresource>
- <gresource prefix="/org/gnome/builder/plugins/beautifier_plugin">
- <file>gtk/menus.ui</file>
- </gresource>
- <gresource prefix="/org/gnome/builder/plugins/beautifier_plugin">
+
+ <file preprocess="xml-stripblanks">gtk/menus.ui</file>
+
<file>config/global.ini</file>
<file>config/automake/config.ini</file>
<file>config/c/config.ini</file>
@@ -24,14 +22,12 @@
<file>config/objc/objc.cfg</file>
<file>config/python/config.ini</file>
<file>config/xml/config.ini</file>
- </gresource>
- <gresource prefix="/org/gnome/builder/plugins/beautifier_plugin">
+
<file>self/global.ini</file>
<file>self/c/config.ini</file>
<file>self/c/gb-clang-format.cfg</file>
<file>self/c/gb-uncrustify.cfg</file>
- </gresource>
- <gresource prefix="/org/gnome/builder/plugins/beautifier_plugin">
+
<file>internal/align_makefile.py</file>
</gresource>
</gresources>
diff --git a/src/plugins/beautifier/beautifier.plugin b/src/plugins/beautifier/beautifier.plugin
index d30494dcb..063e23a16 100644
--- a/src/plugins/beautifier/beautifier.plugin
+++ b/src/plugins/beautifier/beautifier.plugin
@@ -1,9 +1,9 @@
[Plugin]
-Module=beautifier_plugin
-Name=Code Beautifier
-Description=Beautify code according to profiles
Authors=Sébastien Lafargue <slafargue gnome org>
-Copyright=Copyright © 2016 Sébastien Lafargue
-Depends=editor
Builtin=true
-Embedded=gb_beautifier_register_types
+Copyright=Copyright © 2016 Sébastien Lafargue
+Depends=editor;
+Description=Beautify code according to profiles
+Embedded=_gb_beautifier_register_types
+Module=beautifier
+Name=Code Beautifier
diff --git a/src/plugins/beautifier/gb-beautifier-config.c b/src/plugins/beautifier/gb-beautifier-config.c
index 6c089b9b3..81321ce7d 100644
--- a/src/plugins/beautifier/gb-beautifier-config.c
+++ b/src/plugins/beautifier/gb-beautifier-config.c
@@ -24,7 +24,7 @@
#include <glib/gi18n.h>
#include <glib/gstdio.h>
-#include <ide.h>
+#include <libide-editor.h>
#include <libpeas/peas.h>
#include "gb-beautifier-helper.h"
@@ -77,8 +77,8 @@ gb_beautifier_config_check_duplicates (GbBeautifierEditorAddin *self,
{
g_assert (GB_IS_BEAUTIFIER_EDITOR_ADDIN (self));
g_assert (entries != NULL);
- g_assert (!dzl_str_empty0 (lang_id));
- g_assert (!dzl_str_empty0 (display_name));
+ g_assert (!ide_str_empty0 (lang_id));
+ g_assert (!ide_str_empty0 (display_name));
for (guint i = 0; i < entries->len; ++i)
{
@@ -103,7 +103,7 @@ gb_beautifier_map_check_duplicates (GbBeautifierEditorAddin *self,
{
g_assert (GB_IS_BEAUTIFIER_EDITOR_ADDIN (self));
g_assert (map != NULL);
- g_assert (!dzl_str_empty0 (lang_id));
+ g_assert (!ide_str_empty0 (lang_id));
for (guint i = 0; i < map->len; ++i)
{
@@ -132,8 +132,8 @@ copy_to_tmp_file (GbBeautifierEditorAddin *self,
g_autofree gchar *tmp_path = NULL;
gint fd;
- g_assert (!dzl_str_empty0 (tmp_dir));
- g_assert (!dzl_str_empty0 (source_path));
+ g_assert (!ide_str_empty0 (tmp_dir));
+ g_assert (!ide_str_empty0 (source_path));
tmp_path = g_build_filename (tmp_dir, "XXXXXX.txt", NULL);
if (-1 != (fd = g_mkstemp (tmp_path)))
@@ -190,9 +190,9 @@ add_entries_from_config_ini_file (GbBeautifierEditorAddin *self,
gsize nb_profiles;
g_assert (GB_IS_BEAUTIFIER_EDITOR_ADDIN (self));
- g_assert (!dzl_str_empty0 (base_path));
- g_assert (!dzl_str_empty0 (lang_id));
- g_assert (!dzl_str_empty0 (real_lang_id));
+ g_assert (!ide_str_empty0 (base_path));
+ g_assert (!ide_str_empty0 (lang_id));
+ g_assert (!ide_str_empty0 (real_lang_id));
g_assert (entries != NULL);
*has_default = FALSE;
@@ -319,7 +319,7 @@ add_entries_from_config_ini_file (GbBeautifierEditorAddin *self,
command = g_key_file_get_string (key_file, profile, "command-pattern", NULL);
if (g_str_has_prefix (command, "[internal]"))
{
- command_pattern = g_build_filename
("resource:///org/gnome/builder/plugins/beautifier_plugin/internal/",
+ command_pattern = g_build_filename ("resource:///plugins/beautifier/internal/",
command + 10,
NULL);
}
@@ -437,7 +437,7 @@ add_entries_from_base_path (GbBeautifierEditorAddin *self,
gboolean ret_has_default = FALSE;
g_assert (GB_IS_BEAUTIFIER_EDITOR_ADDIN (self));
- g_assert (!dzl_str_empty0 (base_path));
+ g_assert (!ide_str_empty0 (base_path));
g_assert (entries != NULL);
g_assert (map != NULL);
@@ -526,7 +526,7 @@ gb_beautifier_config_get_map (GbBeautifierEditorAddin *self,
gsize data_len;
g_assert (GB_IS_BEAUTIFIER_EDITOR_ADDIN (self));
- g_assert (!dzl_str_empty0 (path));
+ g_assert (!ide_str_empty0 (path));
map = g_array_new (TRUE, TRUE, sizeof (GbBeautifierMapEntry));
g_array_set_clear_func (map, map_entry_clear_func);
@@ -597,15 +597,14 @@ get_entries_worker (IdeTask *task,
GCancellable *cancellable)
{
GbBeautifierEditorAddin *self = (GbBeautifierEditorAddin *)source_object;
- IdeProject *project;
- IdeVcs *vcs;
- GArray *entries;
- GArray *map = NULL;
- const gchar *project_name;
+ GbBeautifierEntriesResult *result;
g_autofree gchar *project_config_path = NULL;
g_autofree gchar *user_config_path = NULL;
+ g_autofree gchar *project_id = NULL;
+ g_autoptr(GFile) workdir = NULL;
+ GArray *entries;
+ GArray *map = NULL;
gchar *configdir;
- GbBeautifierEntriesResult *result;
gboolean has_default = FALSE;
gboolean ret_has_default = FALSE;
@@ -636,13 +635,14 @@ get_entries_worker (IdeTask *task,
g_clear_pointer (&map, g_array_unref);
+ project_id = ide_context_dup_project_id (self->context);
+
/* Project wide config */
- if (NULL != (project = ide_context_get_project (self->context)))
+ if (project_id != NULL)
{
- project_name = ide_project_get_name (project);
- if (dzl_str_equal0 (project_name, "Builder"))
+ if (ide_str_equal0 (project_id, "Builder"))
{
- configdir = g_strdup ("resource:///org/gnome/builder/plugins/beautifier_plugin/self/");
+ configdir = g_strdup ("resource:///plugins/beautifier/self/");
map = gb_beautifier_config_get_map (self, configdir);
add_entries_from_base_path (self, configdir, entries, map, &ret_has_default);
has_default |= ret_has_default;
@@ -650,14 +650,9 @@ get_entries_worker (IdeTask *task,
g_clear_pointer (&map, g_array_unref);
}
- else if (NULL != (vcs = ide_context_get_vcs (self->context)))
+ else if ((workdir = ide_context_ref_workdir (self->context)))
{
- GFile *workdir;
- g_autofree gchar *workdir_path = NULL;
-
- workdir = ide_vcs_get_working_directory (vcs);
- workdir_path = g_file_get_path (workdir);
- project_config_path = g_build_filename (workdir_path,
+ project_config_path = g_build_filename (g_file_peek_path (workdir),
".beautifier",
NULL);
map = gb_beautifier_config_get_map (self, project_config_path);
@@ -669,7 +664,7 @@ get_entries_worker (IdeTask *task,
}
/* System wide config */
- configdir = g_strdup ("resource:///org/gnome/builder/plugins/beautifier_plugin/config/");
+ configdir = g_strdup ("resource:///plugins/beautifier/config/");
map = gb_beautifier_config_get_map (self, configdir);
add_entries_from_base_path (self, configdir, entries, map, &ret_has_default);
diff --git a/src/plugins/beautifier/gb-beautifier-editor-addin.c
b/src/plugins/beautifier/gb-beautifier-editor-addin.c
index bda60617b..72b86d33c 100644
--- a/src/plugins/beautifier/gb-beautifier-editor-addin.c
+++ b/src/plugins/beautifier/gb-beautifier-editor-addin.c
@@ -26,7 +26,7 @@
#include <glib.h>
#include <glib/gi18n.h>
#include <gtksourceview/gtksource.h>
-#include <ide.h>
+#include <libide-editor.h>
#include "gb-beautifier-editor-addin.h"
#include "gb-beautifier-helper.h"
@@ -64,7 +64,7 @@ view_activate_beautify_action_cb (GSimpleAction *action,
gpointer user_data)
{
GbBeautifierEditorAddin *self = (GbBeautifierEditorAddin *)user_data;
- IdeEditorView *view;
+ IdeEditorPage *view;
IdeSourceView *source_view;
GtkTextBuffer *buffer;
GCancellable *cancellable;
@@ -79,10 +79,10 @@ view_activate_beautify_action_cb (GSimpleAction *action,
g_assert (G_IS_SIMPLE_ACTION (action));
view = g_object_get_data (G_OBJECT (action), "gb-beautifier-editor-addin");
- if (view == NULL || !IDE_IS_EDITOR_VIEW (view))
+ if (view == NULL || !IDE_IS_EDITOR_PAGE (view))
return;
- source_view = ide_editor_view_get_view (view);
+ source_view = ide_editor_page_get_view (view);
if (!GTK_SOURCE_IS_VIEW (source_view))
{
ide_object_warning (self, _("Beautifier Plugin: the view is not a GtkSourceView"));
@@ -277,14 +277,14 @@ static void
setup_view_cb (GtkWidget *widget,
GbBeautifierEditorAddin *self)
{
- IdeEditorView *view = (IdeEditorView *)widget;
+ IdeEditorPage *view = (IdeEditorPage *)widget;
IdeSourceView *source_view;
GActionGroup *actions;
GAction *action;
g_assert (GB_IS_BEAUTIFIER_EDITOR_ADDIN (self));
- if (!IDE_IS_EDITOR_VIEW (view))
+ if (!IDE_IS_EDITOR_PAGE (view))
return;
actions = gtk_widget_get_action_group (GTK_WIDGET (view), "view");
@@ -300,7 +300,7 @@ setup_view_cb (GtkWidget *widget,
g_object_set_data (G_OBJECT (view), "gb-beautifier-editor-addin", self);
- source_view = ide_editor_view_get_view (view);
+ source_view = ide_editor_page_get_view (view);
g_signal_connect_object (source_view,
"populate-popup",
G_CALLBACK (view_populate_popup),
@@ -317,12 +317,12 @@ static void
cleanup_view_cb (GtkWidget *widget,
GbBeautifierEditorAddin *self)
{
- IdeEditorView *view = (IdeEditorView *)widget;
+ IdeEditorPage *view = (IdeEditorPage *)widget;
GActionGroup *actions;
g_assert (GB_IS_BEAUTIFIER_EDITOR_ADDIN (self));
- if (!IDE_IS_EDITOR_VIEW (view))
+ if (!IDE_IS_EDITOR_PAGE (view))
return;
if (NULL != (actions = gtk_widget_get_action_group (GTK_WIDGET (view), "view")))
@@ -385,7 +385,7 @@ gb_beautifier_editor_addin_async_cb (GObject *object,
if (!self->has_default)
set_default_keybinding (self, "view.beautify-default::none");
- ide_perspective_views_foreach (IDE_PERSPECTIVE (self->editor), (GtkCallback)setup_view_cb, self);
+ ide_surface_foreach_page (IDE_SURFACE (self->editor), (GtkCallback)setup_view_cb, self);
add_shortcut_window_entry (self);
}
@@ -421,7 +421,7 @@ gb_beautifier_editor_addin_reap_cb (GObject *object,
static void
gb_beautifier_editor_addin_load (IdeEditorAddin *addin,
- IdeEditorPerspective *editor)
+ IdeEditorSurface *editor)
{
GbBeautifierEditorAddin *self = (GbBeautifierEditorAddin *)addin;
IdeWorkbench *workbench;
@@ -429,7 +429,7 @@ gb_beautifier_editor_addin_load (IdeEditorAddin *addin,
g_autoptr (GFile) tmp_file = NULL;
g_assert (GB_IS_BEAUTIFIER_EDITOR_ADDIN (self));
- g_assert (IDE_IS_EDITOR_PERSPECTIVE (editor));
+ g_assert (IDE_IS_EDITOR_SURFACE (editor));
g_set_weak_pointer (&self->editor, editor);
workbench = ide_widget_get_workbench (GTK_WIDGET (editor));
@@ -451,17 +451,17 @@ gb_beautifier_editor_addin_load (IdeEditorAddin *addin,
}
static void
-gb_beautifier_editor_addin_unload (IdeEditorAddin *addin,
- IdeEditorPerspective *editor)
+gb_beautifier_editor_addin_unload (IdeEditorAddin *addin,
+ IdeEditorSurface *editor)
{
GbBeautifierEditorAddin *self = (GbBeautifierEditorAddin *)addin;
GbBeautifierConfigEntry *entry;
g_autoptr (GFile) tmp_file = NULL;
g_assert (GB_IS_BEAUTIFIER_EDITOR_ADDIN (self));
- g_assert (IDE_IS_EDITOR_PERSPECTIVE (editor));
+ g_assert (IDE_IS_EDITOR_SURFACE (editor));
- ide_perspective_views_foreach (IDE_PERSPECTIVE (self->editor), (GtkCallback)cleanup_view_cb, self);
+ ide_surface_foreach_page (IDE_SURFACE (self->editor), (GtkCallback)cleanup_view_cb, self);
if (self->entries != NULL)
{
for (guint i = 0; i < self->entries->len; i++)
@@ -485,19 +485,19 @@ gb_beautifier_editor_addin_unload (IdeEditorAddin *addin,
}
static void
-gb_beautifier_editor_addin_view_set (IdeEditorAddin *addin,
- IdeLayoutView *view)
+gb_beautifier_editor_addin_page_set (IdeEditorAddin *addin,
+ IdePage *view)
{
GbBeautifierEditorAddin *self = (GbBeautifierEditorAddin *)addin;
g_assert (GB_IS_BEAUTIFIER_EDITOR_ADDIN (self));
- g_assert (!view || IDE_IS_LAYOUT_VIEW (view));
+ g_assert (!view || IDE_IS_PAGE (view));
/* If there is currently a view set, and this is
* a new view, then we want to clean it up.
*/
- if (!IDE_IS_EDITOR_VIEW (view))
+ if (!IDE_IS_EDITOR_PAGE (view))
return;
if (self->current_view != NULL)
@@ -532,5 +532,5 @@ editor_addin_iface_init (IdeEditorAddinInterface *iface)
{
iface->load = gb_beautifier_editor_addin_load;
iface->unload = gb_beautifier_editor_addin_unload;
- iface->view_set = gb_beautifier_editor_addin_view_set;
+ iface->page_set = gb_beautifier_editor_addin_page_set;
}
diff --git a/src/plugins/beautifier/gb-beautifier-helper.c b/src/plugins/beautifier/gb-beautifier-helper.c
index 9f5ea63b5..70cf74870 100644
--- a/src/plugins/beautifier/gb-beautifier-helper.c
+++ b/src/plugins/beautifier/gb-beautifier-helper.c
@@ -24,7 +24,7 @@
#include <glib/gi18n.h>
#include <glib/gstdio.h>
#include <gtksourceview/gtksource.h>
-#include <ide.h>
+#include <libide-editor.h>
#include <string.h>
#include "gb-beautifier-helper.h"
diff --git a/src/plugins/beautifier/gb-beautifier-helper.h b/src/plugins/beautifier/gb-beautifier-helper.h
index 7e1fbec3d..080e76124 100644
--- a/src/plugins/beautifier/gb-beautifier-helper.h
+++ b/src/plugins/beautifier/gb-beautifier-helper.h
@@ -22,7 +22,7 @@
#include <glib-object.h>
-#include "ide.h"
+#include "libide-editor.h"
#include "gb-beautifier-config.h"
#include "gb-beautifier-editor-addin.h"
diff --git a/src/plugins/beautifier/gb-beautifier-private.h b/src/plugins/beautifier/gb-beautifier-private.h
index ef74c90f7..5bab0b5b9 100644
--- a/src/plugins/beautifier/gb-beautifier-private.h
+++ b/src/plugins/beautifier/gb-beautifier-private.h
@@ -20,27 +20,26 @@
#pragma once
-#include <glib-object.h>
+#include <libide-editor.h>
-#include "ide.h"
#include "gb-beautifier-editor-addin.h"
G_BEGIN_DECLS
struct _GbBeautifierEditorAddin
{
- GObject parent_instance;
+ GObject parent_instance;
- IdeContext *context;
- IdeEditorPerspective *editor;
- IdeLayoutView *current_view;
- GArray *entries;
+ IdeContext *context;
+ IdeEditorSurface *editor;
+ IdePage *current_view;
+ GArray *entries;
- gchar *tmp_dir;
+ gchar *tmp_dir;
- gboolean has_default;
+ gboolean has_default;
};
-GbBeautifierEditorAddin *gb_beautifier_editor_addin_get_editor_perspective (GbBeautifierEditorAddin
*self);
+GbBeautifierEditorAddin *gb_beautifier_editor_addin_get_editor_surface (GbBeautifierEditorAddin *self);
G_END_DECLS
diff --git a/src/plugins/beautifier/gb-beautifier-process.c b/src/plugins/beautifier/gb-beautifier-process.c
index 7d9f65b2d..8a319553a 100644
--- a/src/plugins/beautifier/gb-beautifier-process.c
+++ b/src/plugins/beautifier/gb-beautifier-process.c
@@ -21,7 +21,7 @@
#include <glib.h>
#include <glib/gi18n.h>
#include <gtksourceview/gtksource.h>
-#include <ide.h>
+#include <libide-editor.h>
#include <string.h>
#include "gb-beautifier-private.h"
diff --git a/src/plugins/beautifier/meson.build b/src/plugins/beautifier/meson.build
index 8e67241a7..268957d2d 100644
--- a/src/plugins/beautifier/meson.build
+++ b/src/plugins/beautifier/meson.build
@@ -1,25 +1,19 @@
-if get_option('with_beautifier')
+if get_option('plugin_beautifier')
-beautifier_resources = gnome.compile_resources(
- 'gb-beautifier-resources',
- 'gb-beautifier.gresource.xml',
- c_name: 'gb_beautifier'
-)
-
-beautifier_sources = [
+plugins_sources += files([
+ 'beautifier-plugin.c',
'gb-beautifier-config.c',
- 'gb-beautifier-config.h',
'gb-beautifier-helper.c',
- 'gb-beautifier-helper.h',
- 'gb-beautifier-plugin.c',
- 'gb-beautifier-private.h',
'gb-beautifier-process.c',
- 'gb-beautifier-process.h',
'gb-beautifier-editor-addin.c',
- 'gb-beautifier-editor-addin.h',
-]
+])
+
+plugin_beautifier_resources = gnome.compile_resources(
+ 'beautifier-resources',
+ 'beautifier.gresource.xml',
+ c_name: 'gbp_beautifier',
+)
-gnome_builder_plugins_sources += files(beautifier_sources)
-gnome_builder_plugins_sources += beautifier_resources[0]
+plugins_sources += plugin_beautifier_resources[0]
endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]