Port to GtkSource* API
There are still bugs but this gets it started
This commit is contained in:
@@ -302,7 +302,8 @@ set_root_from_doc (XedFileBrowserPlugin *plugin,
|
||||
XedDocument *doc)
|
||||
{
|
||||
XedFileBrowserPluginPrivate *priv = plugin->priv;
|
||||
GFile *file;
|
||||
GtkSourceFile *file;
|
||||
GFile *location;
|
||||
GFile *parent;
|
||||
|
||||
if (doc == NULL)
|
||||
@@ -310,13 +311,14 @@ set_root_from_doc (XedFileBrowserPlugin *plugin,
|
||||
return;
|
||||
}
|
||||
|
||||
file = xed_document_get_location (doc);
|
||||
if (file == NULL)
|
||||
file = xed_document_get_file (doc);
|
||||
location = gtk_source_file_get_location (file);
|
||||
if (location == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
parent = g_file_get_parent (file);
|
||||
parent = g_file_get_parent (location);
|
||||
|
||||
if (parent != NULL)
|
||||
{
|
||||
@@ -326,8 +328,6 @@ set_root_from_doc (XedFileBrowserPlugin *plugin,
|
||||
|
||||
g_object_unref (parent);
|
||||
}
|
||||
|
||||
g_object_unref (file);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -764,8 +764,6 @@ on_rename_cb (XedFileBrowserStore *store,
|
||||
XedApp *app;
|
||||
GList *documents;
|
||||
GList *item;
|
||||
XedDocument *doc;
|
||||
GFile *docfile;
|
||||
|
||||
/* Find all documents and set its uri to newuri where it matches olduri */
|
||||
app = xed_app_get_default ();
|
||||
@@ -773,17 +771,22 @@ on_rename_cb (XedFileBrowserStore *store,
|
||||
|
||||
for (item = documents; item; item = item->next)
|
||||
{
|
||||
doc = XED_DOCUMENT (item->data);
|
||||
docfile = xed_document_get_location (doc);
|
||||
XedDocument *doc;
|
||||
GtkSourceFile *source_file;
|
||||
GFile *docfile;
|
||||
|
||||
if (!docfile)
|
||||
doc = XED_DOCUMENT (item->data);
|
||||
source_file = xed_document_get_file (doc);
|
||||
docfile = gtk_source_file_get_location (source_file);
|
||||
|
||||
if (docfile == NULL)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (g_file_equal (docfile, oldfile))
|
||||
{
|
||||
xed_document_set_location (doc, newfile);
|
||||
gtk_source_file_set_location (source_file, newfile);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -791,22 +794,20 @@ on_rename_cb (XedFileBrowserStore *store,
|
||||
|
||||
relative = g_file_get_relative_path (oldfile, docfile);
|
||||
|
||||
if (relative)
|
||||
if (relative != NULL)
|
||||
{
|
||||
/* relative now contains the part in docfile without
|
||||
the prefix oldfile */
|
||||
|
||||
g_object_unref (docfile);
|
||||
|
||||
docfile = g_file_get_child (newfile, relative);
|
||||
|
||||
xed_document_set_location (doc, docfile);
|
||||
gtk_source_file_set_location (source_file, docfile);
|
||||
|
||||
g_object_unref (docfile);
|
||||
}
|
||||
|
||||
g_free (relative);
|
||||
}
|
||||
|
||||
g_object_unref (docfile);
|
||||
}
|
||||
|
||||
g_list_free (documents);
|
||||
@@ -895,10 +896,12 @@ on_tab_added_cb (XedWindow *window,
|
||||
if (open)
|
||||
{
|
||||
XedDocument *doc;
|
||||
GtkSourceFile *file;
|
||||
GFile *location;
|
||||
|
||||
doc = xed_tab_get_document (tab);
|
||||
location = xed_document_get_location (doc);
|
||||
file = xed_document_get_file (doc);
|
||||
location = gtk_source_file_get_location (file);
|
||||
|
||||
if (location != NULL)
|
||||
{
|
||||
@@ -908,7 +911,6 @@ on_tab_added_cb (XedWindow *window,
|
||||
set_root_from_doc (plugin, doc);
|
||||
load_default = FALSE;
|
||||
}
|
||||
g_object_unref (location);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -141,7 +141,6 @@ xed_modeline_plugin_get_property (GObject *object,
|
||||
|
||||
static void
|
||||
on_document_loaded_or_saved (XedDocument *document,
|
||||
const GError *error,
|
||||
GtkSourceView *view)
|
||||
{
|
||||
modeline_parser_apply_modeline (view);
|
||||
|
@@ -45,6 +45,8 @@
|
||||
#define XED_METADATA_ATTRIBUTE_SPELL_LANGUAGE "metadata::xed-spell-language"
|
||||
#define XED_METADATA_ATTRIBUTE_SPELL_ENABLED "metadata::xed-spell-enabled"
|
||||
|
||||
#define XED_AUTOMATIC_SPELL_VIEW "XedAutomaticSpellView"
|
||||
|
||||
#define MENU_PATH "/MenuBar/ToolsMenu/ToolsOps_1"
|
||||
|
||||
#define XED_SPELL_PLUGIN_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), \
|
||||
@@ -1009,12 +1011,15 @@ spell_cb (GtkAction *action,
|
||||
}
|
||||
|
||||
static void
|
||||
set_auto_spell (XedWindow *window,
|
||||
XedDocument *doc,
|
||||
gboolean active)
|
||||
set_auto_spell (XedWindow *window,
|
||||
XedView *view,
|
||||
gboolean active)
|
||||
{
|
||||
XedAutomaticSpellChecker *autospell;
|
||||
XedSpellChecker *spell;
|
||||
XedDocument *doc;
|
||||
|
||||
doc = XED_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
|
||||
|
||||
spell = get_spell_checker_from_document (doc);
|
||||
g_return_if_fail (spell != NULL);
|
||||
@@ -1025,13 +1030,8 @@ set_auto_spell (XedWindow *window,
|
||||
{
|
||||
if (autospell == NULL)
|
||||
{
|
||||
XedView *active_view;
|
||||
|
||||
active_view = xed_window_get_active_view (window);
|
||||
g_return_if_fail (active_view != NULL);
|
||||
|
||||
autospell = xed_automatic_spell_checker_new (doc, spell);
|
||||
xed_automatic_spell_checker_attach_view (autospell, active_view);
|
||||
xed_automatic_spell_checker_attach_view (autospell, view);
|
||||
xed_automatic_spell_checker_recheck_all (autospell);
|
||||
}
|
||||
}
|
||||
@@ -1050,6 +1050,7 @@ auto_spell_cb (GtkAction *action,
|
||||
{
|
||||
XedSpellPluginPrivate *priv;
|
||||
XedDocument *doc;
|
||||
XedView *view;
|
||||
gboolean active;
|
||||
|
||||
xed_debug (DEBUG_PLUGINS);
|
||||
@@ -1059,12 +1060,14 @@ auto_spell_cb (GtkAction *action,
|
||||
|
||||
xed_debug_message (DEBUG_PLUGINS, active ? "Auto Spell activated" : "Auto Spell deactivated");
|
||||
|
||||
doc = xed_window_get_active_document (priv->window);
|
||||
if (doc == NULL)
|
||||
view = xed_window_get_active_view (priv->window);
|
||||
if (view == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
doc = XED_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
|
||||
|
||||
if (get_autocheck_type (plugin) == AUTOCHECK_DOCUMENT)
|
||||
{
|
||||
xed_document_set_metadata (doc,
|
||||
@@ -1072,33 +1075,32 @@ auto_spell_cb (GtkAction *action,
|
||||
active ? "1" : NULL, NULL);
|
||||
}
|
||||
|
||||
set_auto_spell (priv->window, doc, active);
|
||||
set_auto_spell (priv->window, view, active);
|
||||
}
|
||||
|
||||
static void
|
||||
update_ui (XedSpellPlugin *plugin)
|
||||
{
|
||||
XedSpellPluginPrivate *priv;
|
||||
XedDocument *doc;
|
||||
XedView *view;
|
||||
gboolean autospell;
|
||||
GtkAction *action;
|
||||
|
||||
xed_debug (DEBUG_PLUGINS);
|
||||
|
||||
priv = plugin->priv;
|
||||
doc = xed_window_get_active_document (priv->window);
|
||||
view = xed_window_get_active_view (priv->window);
|
||||
|
||||
autospell = (doc != NULL && xed_automatic_spell_checker_get_from_document (doc) != NULL);
|
||||
|
||||
if (doc != NULL)
|
||||
if (view != NULL)
|
||||
{
|
||||
XedDocument *doc;
|
||||
XedTab *tab;
|
||||
XedTabState state;
|
||||
gboolean autospell;
|
||||
|
||||
doc = XED_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
|
||||
tab = xed_window_get_active_tab (priv->window);
|
||||
state = xed_tab_get_state (tab);
|
||||
autospell = (doc != NULL && xed_automatic_spell_checker_get_from_document (doc) != NULL);
|
||||
|
||||
/* If the document is loading we can't get the metadata so we
|
||||
endup with an useless speller */
|
||||
@@ -1107,7 +1109,7 @@ update_ui (XedSpellPlugin *plugin)
|
||||
action = gtk_action_group_get_action (priv->action_group, "AutoSpell");
|
||||
|
||||
g_signal_handlers_block_by_func (action, auto_spell_cb, plugin);
|
||||
set_auto_spell (priv->window, doc, autospell);
|
||||
set_auto_spell (priv->window, view, autospell);
|
||||
gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), autospell);
|
||||
g_signal_handlers_unblock_by_func (action, auto_spell_cb, plugin);
|
||||
}
|
||||
@@ -1120,15 +1122,18 @@ update_ui (XedSpellPlugin *plugin)
|
||||
|
||||
static void
|
||||
set_auto_spell_from_metadata (XedSpellPlugin *plugin,
|
||||
XedDocument *doc,
|
||||
XedView *view,
|
||||
GtkActionGroup *action_group)
|
||||
{
|
||||
gboolean active = FALSE;
|
||||
gchar *active_str = NULL;
|
||||
XedWindow *window;
|
||||
XedDocument *doc;
|
||||
XedDocument *active_doc;
|
||||
XedSpellPluginAutocheckType autocheck_type;
|
||||
|
||||
doc = XED_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
|
||||
|
||||
autocheck_type = get_autocheck_type (plugin);
|
||||
|
||||
switch (autocheck_type)
|
||||
@@ -1158,7 +1163,7 @@ set_auto_spell_from_metadata (XedSpellPlugin *plugin,
|
||||
|
||||
window = XED_WINDOW (plugin->priv->window);
|
||||
|
||||
set_auto_spell (window, doc, active);
|
||||
set_auto_spell (window, view, active);
|
||||
|
||||
/* In case that the doc is the active one we mark the spell action */
|
||||
active_doc = xed_window_get_active_document (window);
|
||||
@@ -1177,37 +1182,31 @@ set_auto_spell_from_metadata (XedSpellPlugin *plugin,
|
||||
|
||||
static void
|
||||
on_document_loaded (XedDocument *doc,
|
||||
const GError *error,
|
||||
XedSpellPlugin *plugin)
|
||||
{
|
||||
if (error == NULL)
|
||||
|
||||
XedSpellChecker *spell;
|
||||
XedView *view;
|
||||
|
||||
spell = XED_SPELL_CHECKER (g_object_get_qdata (G_OBJECT (doc), spell_checker_id));
|
||||
if (spell != NULL)
|
||||
{
|
||||
XedSpellChecker *spell;
|
||||
|
||||
spell = XED_SPELL_CHECKER (g_object_get_qdata (G_OBJECT (doc), spell_checker_id));
|
||||
if (spell != NULL)
|
||||
{
|
||||
set_language_from_metadata (spell, doc);
|
||||
}
|
||||
|
||||
set_auto_spell_from_metadata (plugin, doc, plugin->priv->action_group);
|
||||
set_language_from_metadata (spell, doc);
|
||||
}
|
||||
|
||||
view = XED_VIEW (g_object_get_data (G_OBJECT (doc), XED_AUTOMATIC_SPELL_VIEW));
|
||||
|
||||
set_auto_spell_from_metadata (plugin, view, plugin->priv->action_group);
|
||||
}
|
||||
|
||||
static void
|
||||
on_document_saved (XedDocument *doc,
|
||||
const GError *error,
|
||||
XedSpellPlugin *plugin)
|
||||
{
|
||||
XedAutomaticSpellChecker *autospell;
|
||||
XedSpellChecker *spell;
|
||||
const gchar *key;
|
||||
|
||||
if (error != NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/* Make sure to save the metadata here too */
|
||||
autospell = xed_automatic_spell_checker_get_from_document (doc);
|
||||
spell = XED_SPELL_CHECKER (g_object_get_qdata (G_OBJECT (doc), spell_checker_id));
|
||||
@@ -1242,9 +1241,13 @@ tab_added_cb (XedWindow *window,
|
||||
XedTab *tab,
|
||||
XedSpellPlugin *plugin)
|
||||
{
|
||||
XedView *view;
|
||||
XedDocument *doc;
|
||||
|
||||
doc = xed_tab_get_document (tab);
|
||||
view = xed_tab_get_view (tab);
|
||||
doc = XED_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
|
||||
|
||||
g_object_set_data (G_OBJECT (doc), XED_AUTOMATIC_SPELL_VIEW, view);
|
||||
|
||||
g_signal_connect (doc, "loaded",
|
||||
G_CALLBACK (on_document_loaded), plugin);
|
||||
@@ -1261,6 +1264,7 @@ tab_removed_cb (XedWindow *window,
|
||||
XedDocument *doc;
|
||||
|
||||
doc = xed_tab_get_document (tab);
|
||||
g_object_set_data (G_OBJECT (doc), XED_AUTOMATIC_SPELL_VIEW, NULL);
|
||||
|
||||
g_signal_handlers_disconnect_by_func (doc, on_document_loaded, plugin);
|
||||
g_signal_handlers_disconnect_by_func (doc, on_document_saved, plugin);
|
||||
@@ -1271,7 +1275,7 @@ xed_spell_plugin_activate (XedWindowActivatable *activatable)
|
||||
{
|
||||
XedSpellPluginPrivate *priv;
|
||||
GtkUIManager *manager;
|
||||
GList *docs, *l;
|
||||
GList *views, *l;
|
||||
|
||||
xed_debug (DEBUG_PLUGINS);
|
||||
|
||||
@@ -1323,15 +1327,12 @@ xed_spell_plugin_activate (XedWindowActivatable *activatable)
|
||||
|
||||
update_ui (XED_SPELL_PLUGIN (activatable));
|
||||
|
||||
docs = xed_window_get_documents (priv->window);
|
||||
for (l = docs; l != NULL; l = g_list_next (l))
|
||||
views = xed_window_get_views (priv->window);
|
||||
for (l = views; l != NULL; l = g_list_next (l))
|
||||
{
|
||||
XedDocument *doc = XED_DOCUMENT (l->data);
|
||||
XedView *view = XED_VIEW (l->data);
|
||||
|
||||
set_auto_spell_from_metadata (XED_SPELL_PLUGIN (activatable), doc, priv->action_group);
|
||||
|
||||
g_signal_handlers_disconnect_by_func (doc, on_document_loaded, activatable);
|
||||
g_signal_handlers_disconnect_by_func (doc, on_document_saved, activatable);
|
||||
set_auto_spell_from_metadata (XED_SPELL_PLUGIN (activatable), view, priv->action_group);
|
||||
}
|
||||
|
||||
priv->tab_added_id = g_signal_connect (priv->window, "tab-added",
|
||||
|
@@ -128,9 +128,6 @@ strip_trailing_spaces (GtkTextBuffer *text_buffer)
|
||||
|
||||
static void
|
||||
on_save (XedDocument *document,
|
||||
const gchar *uri,
|
||||
XedEncoding *encoding,
|
||||
XedDocumentSaveFlags save_flags,
|
||||
XedTrailSavePlugin *plugin)
|
||||
{
|
||||
GtkTextBuffer *text_buffer = GTK_TEXT_BUFFER (document);
|
||||
|
Reference in New Issue
Block a user