[gedit-code-assistance/wip/indent] One extension per view
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit-code-assistance/wip/indent] One extension per view
- Date: Wed, 9 Apr 2014 07:07:06 +0000 (UTC)
commit bc66191492f305881a02d1ab92a6defaf76992ec
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Wed Apr 9 08:32:01 2014 +0200
One extension per view
indentbackends/c/gca-c-backend.vala | 33 ++++++++++++----------------
indentbackends/c/gcaindentbackendc.plugin | 2 +-
src/gca-backend-manager.vala | 33 +++-------------------------
src/gca-indent-backend.vala | 13 +++++------
src/gca-view.vala | 29 ++++++-------------------
5 files changed, 32 insertions(+), 78 deletions(-)
---
diff --git a/indentbackends/c/gca-c-backend.vala b/indentbackends/c/gca-c-backend.vala
index a91cd55..7ccdf9c 100644
--- a/indentbackends/c/gca-c-backend.vala
+++ b/indentbackends/c/gca-c-backend.vala
@@ -22,16 +22,11 @@ namespace Gca.C
class Backend : Object, Gca.IndentBackend
{
- private unowned Gedit.View d_view;
+ private Gedit.View d_view;
- void register_backend(Gedit.View view)
- {
- d_view = view;
- }
-
- void unregister_backend()
- {
- d_view = null;
+ public Gedit.View view {
+ get { return d_view; }
+ construct set { d_view = value; }
}
string[] get_triggers()
@@ -128,7 +123,7 @@ class Backend : Object, Gca.IndentBackend
if (document.iter_has_context_class(iter, "comment"))
{
// FIXME: leave it as it is for now :)
- return get_line_indents(d_view, iter);
+ return get_line_indents(iter);
}
// move to the beginning to get some context from previous lines
@@ -148,7 +143,7 @@ class Backend : Object, Gca.IndentBackend
else
{
// align with the start of the comment
- amount = get_line_indents(d_view, iter);
+ amount = get_line_indents(iter);
}
}
@@ -163,18 +158,18 @@ class Backend : Object, Gca.IndentBackend
{
if (find_open_char(ref copy, '(', ')', false))
{
- amount = get_line_indents(d_view, copy);
+ amount = get_line_indents(copy);
}
else
{
// fallback to try to use the current place
- amount = get_line_indents(d_view, iter);
+ amount = get_line_indents(iter);
}
}
else
{
// hello;
- amount = get_line_indents(d_view, iter);
+ amount = get_line_indents(iter);
}
}
else if (c == ')')
@@ -182,18 +177,18 @@ class Backend : Object, Gca.IndentBackend
var copy = iter;
if (find_open_char(ref copy, '(', ')', false))
{
- amount = get_line_indents(d_view, copy);
+ amount = get_line_indents(copy);
if (get_first_char_in_line(place) != '{')
{
- amount += get_indent_width(d_view);
+ amount += get_indent_width();
}
}
}
else if (c == '{')
{
- amount = get_line_indents(d_view, iter);
- amount += get_indent_width(d_view);
+ amount = get_line_indents(iter);
+ amount += get_indent_width();
}
if (get_first_char_in_line(place) == '}')
@@ -206,7 +201,7 @@ class Backend : Object, Gca.IndentBackend
if (find_open_char(ref copy, '{', '}', true))
{
- amount = get_line_indents(d_view, copy);
+ amount = get_line_indents(copy);
}
}
else if (get_first_char_in_line(place) == '#')
diff --git a/indentbackends/c/gcaindentbackendc.plugin b/indentbackends/c/gcaindentbackendc.plugin
index 21e2829..af65218 100644
--- a/indentbackends/c/gcaindentbackendc.plugin
+++ b/indentbackends/c/gcaindentbackendc.plugin
@@ -8,4 +8,4 @@ Description=Code assistance indent backend for C
Authors=Ignacio Casal Quinteiro <icq gnome org>
Copyright=Copyright © 2014 Ignacio Casal Quinteiro
Website=http://www.gedit.org
-X-Languages=c
+X-Languages=c,cpp,chdr
diff --git a/src/gca-backend-manager.vala b/src/gca-backend-manager.vala
index 3084d92..f00e5e2 100644
--- a/src/gca-backend-manager.vala
+++ b/src/gca-backend-manager.vala
@@ -29,9 +29,8 @@ class BackendManager
private Gee.HashMap<string, IndentBackendInfo> d_indent_backends;
private Peas.Engine d_engine;
- class IndentBackendInfo : Object
+ public class IndentBackendInfo : Object
{
- public IndentBackend ?backend { get; set; }
public Peas.PluginInfo info { get; set; }
public IndentBackendInfo(Peas.PluginInfo info)
@@ -70,23 +69,6 @@ class BackendManager
d_engine.add_search_path(Gca.Config.GCA_INDENT_BACKENDS_DIR,
Gca.Config.GCA_INDENT_BACKENDS_DATA_DIR);
- d_engine.enable_loader("python3");
-
- // require the gca gir
- string tpdir = Path.build_filename(Gca.Config.GCA_LIBS_DIR,
- "girepository-1.0");
-
- var repo = GI.Repository.get_default();
-
- try
- {
- repo.require_private(tpdir, "Gca", "3.0", 0);
- }
- catch (Error error)
- {
- warning("Could not load Gca typelib: %s", error.message);
- }
-
register_backends();
}
@@ -101,6 +83,7 @@ class BackendManager
continue;
}
+ d_engine.load_plugin(info);
IndentBackendInfo binfo = new IndentBackendInfo(info);
foreach (string lang in langs.split(","))
@@ -171,22 +154,14 @@ class BackendManager
return backend;
}
- public async IndentBackend? indent_backend(string language)
+ public IndentBackendInfo? indent_backend_info(string language)
{
if (!d_indent_backends.has_key(language))
{
return null;
}
- IndentBackendInfo info = d_indent_backends[language];
-
- if (info.backend == null)
- {
- d_engine.load_plugin(info.info);
- info.backend = (Gca.IndentBackend)d_engine.create_extension(info.info,
typeof(Gca.IndentBackend));
- }
-
- return info.backend;
+ return d_indent_backends[language];
}
public static BackendManager instance
diff --git a/src/gca-indent-backend.vala b/src/gca-indent-backend.vala
index effcfb9..eba6ee1 100644
--- a/src/gca-indent-backend.vala
+++ b/src/gca-indent-backend.vala
@@ -22,20 +22,19 @@ namespace Gca
public interface IndentBackend : Object
{
- public abstract void register_backend(Gedit.View view);
- public abstract void unregister_backend();
+ public abstract Gedit.View view { get; construct set; }
/* These are the chars that trigger an extra indentation, i.e { */
public abstract string[] get_triggers();
/* It returns the indentation level */
public abstract uint get_indent(Gedit.Document document, Gtk.TextIter place);
- public uint get_indent_width(Gedit.View view)
+ public uint get_indent_width()
{
return view.indent_width < 0 ? view.tab_width : view.indent_width;
}
- public uint get_line_indents(Gedit.View view, Gtk.TextIter place)
+ public uint get_line_indents(Gtk.TextIter place)
{
var start = place;
start.set_line_offset(0);
@@ -52,12 +51,12 @@ public interface IndentBackend : Object
c = start.get_char();
}
- return get_amount_indents_from_position(view, start);
+ return get_amount_indents_from_position(start);
}
- public uint get_amount_indents_from_position(Gedit.View view, Gtk.TextIter place)
+ public uint get_amount_indents_from_position(Gtk.TextIter place)
{
- var indent_width = get_indent_width(view);
+ var indent_width = get_indent_width();
var start = place;
start.set_line_offset(0);
diff --git a/src/gca-view.vala b/src/gca-view.vala
index 34034f2..b8a75d4 100644
--- a/src/gca-view.vala
+++ b/src/gca-view.vala
@@ -190,10 +190,11 @@ class View : Object
register_backend(backend);
});
- manager.indent_backend.begin(d_document.document.language.id, (obj, res) => {
- var backend = manager.indent_backend.end(res);
- register_indent_backend(backend);
- });
+ BackendManager.IndentBackendInfo? info =
manager.indent_backend_info(d_document.document.language.id);
+ if (info != null)
+ {
+ d_indent_backend =
(Gca.IndentBackend)Peas.Engine.get_default().create_extension(info.info, typeof(IndentBackend), "view",
d_view);
+ }
}
}
@@ -210,11 +211,7 @@ class View : Object
d_backend = null;
}
- if (d_indent_backend != null)
- {
- d_indent_backend.unregister_backend();
- d_indent_backend = null;
- }
+ d_indent_backend = null;
}
private void register_backend(Backend? backend)
@@ -230,18 +227,6 @@ class View : Object
on_document_changed();
}
- private void register_indent_backend(IndentBackend? backend)
- {
- d_indent_backend = backend;
-
- if (d_indent_backend == null)
- {
- return;
- }
-
- d_indent_backend.register_backend(d_view);
- }
-
private void on_notify_buffer()
{
disconnect_document();
@@ -313,7 +298,7 @@ class View : Object
}
else
{
- var indent_width = d_indent_backend.get_indent_width(d_view);
+ var indent_width = d_indent_backend.get_indent_width();
uint tabs = level / indent_width;
uint spaces = level % indent_width;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]