[latexila] Use the GtkSourceView:smart-backspace property
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [latexila] Use the GtkSourceView:smart-backspace property
- Date: Tue, 18 Aug 2015 09:08:17 +0000 (UTC)
commit 15f7894d0a7ed7e50337e3a842bee09fde906c7f
Author: Sébastien Wilmet <swilmet gnome org>
Date: Fri Aug 14 14:32:33 2015 +0200
Use the GtkSourceView:smart-backspace property
configure.ac | 2 +-
src/document_view.vala | 71 ++---------------------------------------------
2 files changed, 4 insertions(+), 69 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 4d9046b..ecd5e2d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -27,7 +27,7 @@ LT_INIT
# Update also the --target-glib option in src/Makefile.am.
GLIB_REQUIRED_VERSION="2.40"
GTK_REQUIRED_VERSION="3.14"
-GTKSOURCEVIEW_REQUIRED_VERSION="3.16"
+GTKSOURCEVIEW_REQUIRED_VERSION="3.17.5"
GTKSPELL_REQUIRED_VERSION="3.0.4"
VALA_REQUIRED_VERSION="0.26"
GEE_REQUIRED_VERSION="0.10"
diff --git a/src/document_view.vala b/src/document_view.vala
index 392cb2c..d198f59 100644
--- a/src/document_view.vala
+++ b/src/document_view.vala
@@ -43,6 +43,9 @@ public class DocumentView : Gtk.SourceView
/* settings */
_editor_settings = new GLib.Settings ("org.gnome.latexila.preferences.editor");
+ _editor_settings.bind ("forget-no-tabs", this, "smart-backspace",
+ SettingsBindFlags.GET);
+
set_font_from_settings ();
// tab width
@@ -75,9 +78,6 @@ public class DocumentView : Gtk.SourceView
warning ("Completion: %s", e.message);
}
- // smart backspace (if indent with spaces)
- key_press_event.connect (on_backspace);
-
// spell checking
if (_editor_settings.get_boolean ("spell-checking"))
activate_spell_checking ();
@@ -278,69 +278,4 @@ public class DocumentView : Gtk.SourceView
provider.hide_calltip_window ();
});
}
-
- private bool on_backspace (Gdk.EventKey event)
- {
- // See GDK_KEY_BackSpace in gdk/gdkkeysyms.h (not available in Vala)
-
- // TODO~ connect/disconnect the signal when settings in gsettings change
- if (! _editor_settings.get_boolean ("insert-spaces")
- || ! _editor_settings.get_boolean ("forget-no-tabs")
- || event.keyval != 0xff08
- || buffer.has_selection
- || tab_width == 1)
-
- // propagate the event further
- return false;
-
- /* forget that we are not using tabulations */
- TextIter iter_start, iter_insert;
- buffer.get_iter_at_mark (out iter_insert, buffer.get_insert ());
- buffer.get_iter_at_line (out iter_start, iter_insert.get_line ());
-
- string text = buffer.get_text (iter_start, iter_insert, false);
-
- if (text == "")
- return false;
-
- int nb_chars_to_delete = 0;
- bool between = true; // between two indent
-
- for (long i = 0 ; i < text.length ; i++)
- {
- if (text[i] == '\t')
- {
- nb_chars_to_delete = 1;
- between = true;
- continue;
- }
-
- // smart backspace only at the beginnig of a line, not inside it
- if (text[i] != ' ')
- return false;
-
- // it's a space
-
- if (between)
- {
- nb_chars_to_delete = 1;
- between = false;
- continue;
- }
-
- nb_chars_to_delete++;
- if (nb_chars_to_delete == tab_width)
- between = true;
- }
-
- iter_start = iter_insert;
- if (! iter_start.backward_chars (nb_chars_to_delete))
- return false;
-
- buffer.begin_user_action ();
- buffer.delete_range (iter_start, iter_insert);
- buffer.end_user_action ();
-
- return true;
- }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]