Reformated code to conform to Mint coding style

As discussed within the team.
This commit is contained in:
Clement Lefebvre 2016-09-21 13:44:19 +01:00
parent f4236351ae
commit 26d0ac85a0
4 changed files with 1874 additions and 1351 deletions

View File

@ -14,26 +14,30 @@
#include "xed-searchbar.h"
void
_xed_cmd_search_find (GtkAction *action, XedWindow *window)
_xed_cmd_search_find (GtkAction *action,
XedWindow *window)
{
xed_searchbar_show (xed_window_get_searchbar (window), FALSE);
}
void
_xed_cmd_search_replace (GtkAction *action, XedWindow *window)
_xed_cmd_search_replace (GtkAction *action,
XedWindow *window)
{
xed_searchbar_show (xed_window_get_searchbar (window), TRUE);
}
void
_xed_cmd_search_find_next (GtkAction *action, XedWindow *window)
_xed_cmd_search_find_next (GtkAction *action,
XedWindow *window)
{
xed_debug (DEBUG_COMMANDS);
xed_searchbar_find_again (xed_window_get_searchbar (window), FALSE);
}
void
_xed_cmd_search_find_prev (GtkAction *action, XedWindow *window)
_xed_cmd_search_find_prev (GtkAction *action,
XedWindow *window)
{
xed_debug (DEBUG_COMMANDS);
xed_searchbar_find_again (xed_window_get_searchbar (window), TRUE);
@ -45,19 +49,22 @@ _xed_cmd_search_clear_highlight (XedWindow *window)
XedDocument *doc;
xed_debug (DEBUG_COMMANDS);
doc = xed_window_get_active_document (window);
if (doc != NULL) {
if (doc != NULL)
{
xed_document_set_search_text (XED_DOCUMENT(doc), "", XED_SEARCH_DONT_SET_FLAGS);
}
}
void
_xed_cmd_search_goto_line (GtkAction *action, XedWindow *window)
_xed_cmd_search_goto_line (GtkAction *action,
XedWindow *window)
{
XedView *active_view;
xed_debug (DEBUG_COMMANDS);
active_view = xed_window_get_active_view (window);
if (active_view == NULL) {
if (active_view == NULL)
{
return;
}
@ -65,7 +72,6 @@ _xed_cmd_search_goto_line (GtkAction *action, XedWindow *window)
activating the binding for goto line has no effect */
gtk_widget_grab_focus (GTK_WIDGET(active_view));
/* Goto line is builtin in XedView, just activate the corresponding binding. */
gtk_bindings_activate (G_OBJECT(active_view), GDK_KEY_i, GDK_CONTROL_MASK);
}

View File

@ -1,4 +1,3 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@ -22,8 +21,7 @@
/* Signals */
enum
{
SHOW_REPLACE,
LAST_SIGNAL
SHOW_REPLACE, LAST_SIGNAL
};
struct _XedSearchbarPrivate
@ -62,45 +60,46 @@ xed_searchbar_class_init (XedSearchbarClass *klass)
/* Use occurrences only for Replace All */
static void
text_found (XedWindow *window, gint occurrences)
text_found (XedWindow *window,
gint occurrences)
{
if (occurrences > 1) {
xed_statusbar_flash_message (XED_STATUSBAR (window->priv->statusbar),
window->priv->generic_message_cid,
ngettext("Found and replaced %d occurrence",
"Found and replaced %d occurrences",
occurrences),
if (occurrences > 1)
{
xed_statusbar_flash_message (XED_STATUSBAR(window->priv->statusbar), window->priv->generic_message_cid,
ngettext ("Found and replaced %d occurrence", "Found and replaced %d occurrences", occurrences),
occurrences);
}
else
{
if (occurrences == 1) {
xed_statusbar_flash_message (XED_STATUSBAR (window->priv->statusbar),
window->priv->generic_message_cid,
if (occurrences == 1)
{
xed_statusbar_flash_message (XED_STATUSBAR(window->priv->statusbar), window->priv->generic_message_cid,
_("Found and replaced one occurrence"));
}
else {
xed_statusbar_flash_message (XED_STATUSBAR (window->priv->statusbar),
window->priv->generic_message_cid,
else
{
xed_statusbar_flash_message (XED_STATUSBAR(window->priv->statusbar), window->priv->generic_message_cid,
" ");
}
}
}
static void
text_not_found (XedWindow *window, const gchar *text)
text_not_found (XedWindow *window,
const gchar *text)
{
gchar *searched;
searched = xed_utils_str_end_truncate (text, MAX_MSG_LENGTH);
xed_statusbar_flash_message (XED_STATUSBAR (window->priv->statusbar),
window->priv->generic_message_cid,
xed_statusbar_flash_message (XED_STATUSBAR(window->priv->statusbar), window->priv->generic_message_cid,
_("\"%s\" not found"), searched);
g_free (searched);
}
static gboolean
run_search (XedView *view, gboolean wrap_around, gboolean search_backwards)
run_search (XedView *view,
gboolean wrap_around,
gboolean search_backwards)
{
XedDocument *doc;
GtkTextIter start_iter;
@ -110,32 +109,39 @@ run_search (XedView *view, gboolean wrap_around, gboolean search_backwards)
doc = XED_DOCUMENT(gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
if (!search_backwards) {
if (!search_backwards)
{
gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER(doc), NULL, &start_iter);
found = xed_document_search_forward (doc, &start_iter, NULL, &match_start, &match_end);
}
else {
else
{
gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER(doc), &start_iter, NULL);
found = xed_document_search_backward (doc, NULL, &start_iter, &match_start, &match_end);
}
if (!found && wrap_around) {
if (!search_backwards) {
found = xed_document_search_forward (doc, NULL, NULL, /* FIXME: set the end_inter */
&match_start, &match_end);
if (!found && wrap_around)
{
if (!search_backwards)
{
/* FIXME: set the end_inter */
found = xed_document_search_forward (doc, NULL, NULL, &match_start, &match_end);
}
else {
found = xed_document_search_backward (doc, NULL, /* FIXME: set the start_inter */ NULL,
&match_start, &match_end);
else
{
/* FIXME: set the start_inter */
found = xed_document_search_backward (doc, NULL, NULL, &match_start, &match_end);
}
}
if (found) {
if (found)
{
gtk_text_buffer_place_cursor (GTK_TEXT_BUFFER(doc), &match_start);
gtk_text_buffer_move_mark_by_name (GTK_TEXT_BUFFER(doc), "selection_bound", &match_end);
xed_view_scroll_to_cursor (view);
}
else {
else
{
gtk_text_buffer_place_cursor (GTK_TEXT_BUFFER(doc), &start_iter);
}
@ -143,7 +149,8 @@ run_search (XedView *view, gboolean wrap_around, gboolean search_backwards)
}
static void
do_find (XedSearchbar *searchbar, gboolean search_backwards)
do_find (XedSearchbar *searchbar,
gboolean search_backwards)
{
XedView *active_view;
XedDocument *doc;
@ -159,7 +166,8 @@ do_find (XedSearchbar *searchbar, gboolean search_backwards)
/* TODO: make the searchbar insensitive when all the tabs are closed
* and assert here that the view is not NULL */
active_view = xed_window_get_active_view (searchbar->window);
if (active_view == NULL) {
if (active_view == NULL)
{
return;
}
@ -175,7 +183,8 @@ do_find (XedSearchbar *searchbar, gboolean search_backwards)
search_text = xed_document_get_search_text (doc, &old_flags);
if ((search_text == NULL) || (strcmp (search_text, entry_text) != 0) || (flags != old_flags)) {
if ((search_text == NULL) || (strcmp (search_text, entry_text) != 0) || (flags != old_flags))
{
xed_document_set_search_text (doc, entry_text, flags);
}
@ -183,16 +192,19 @@ do_find (XedSearchbar *searchbar, gboolean search_backwards)
found = run_search (active_view, wrap_around, search_backwards);
if (found) {
if (found)
{
text_found (searchbar->window, 0);
}
else {
else
{
text_not_found (searchbar->window, entry_text);
}
}
void
xed_searchbar_find_again (XedSearchbar *searchbar, gboolean backward)
xed_searchbar_find_again (XedSearchbar *searchbar,
gboolean backward)
{
XedView *active_view;
gboolean wrap_around = TRUE;
@ -203,7 +215,8 @@ xed_searchbar_find_again (XedSearchbar *searchbar, gboolean backward)
data = g_object_get_data (G_OBJECT(searchbar->window), XED_SEARCHBAR_KEY);
if (data != NULL) {
if (data != NULL)
{
wrap_around = xed_searchbar_get_wrap_around (XED_SEARCHBAR(data));
}
@ -211,7 +224,8 @@ xed_searchbar_find_again (XedSearchbar *searchbar, gboolean backward)
}
static void
search_buttons_set_sensitive (XedSearchbar *searchbar, gboolean sensitive)
search_buttons_set_sensitive (XedSearchbar *searchbar,
gboolean sensitive)
{
gtk_widget_set_sensitive (searchbar->priv->find_button, sensitive);
gtk_widget_set_sensitive (searchbar->priv->find_prev_button, sensitive);
@ -221,15 +235,19 @@ search_buttons_set_sensitive (XedSearchbar *searchbar, gboolean sensitive)
/* FIXME: move in xed-document.c and share it with xed-view */
static gboolean
get_selected_text (GtkTextBuffer *doc, gchar **selected_text, gint *len)
get_selected_text (GtkTextBuffer *doc,
gchar **selected_text,
gint *len)
{
GtkTextIter start, end;
g_return_val_if_fail(selected_text != NULL, FALSE);
g_return_val_if_fail(*selected_text == NULL, FALSE);
if (!gtk_text_buffer_get_selection_bounds (doc, &start, &end)) {
if (len != NULL) {
if (!gtk_text_buffer_get_selection_bounds (doc, &start, &end))
{
if (len != NULL)
{
len = 0;
}
return FALSE;
@ -237,7 +255,8 @@ get_selected_text (GtkTextBuffer *doc, gchar **selected_text, gint *len)
*selected_text = gtk_text_buffer_get_slice (doc, &start, &end, TRUE);
if (len != NULL) {
if (len != NULL)
{
*len = g_utf8_strlen (*selected_text, -1);
}
@ -245,7 +264,8 @@ get_selected_text (GtkTextBuffer *doc, gchar **selected_text, gint *len)
}
static void
replace_selected_text (GtkTextBuffer *buffer, const gchar *replace)
replace_selected_text (GtkTextBuffer *buffer,
const gchar *replace)
{
g_return_if_fail(gtk_text_buffer_get_selection_bounds (buffer, NULL, NULL));
g_return_if_fail(replace != NULL);
@ -268,7 +288,8 @@ do_replace (XedSearchbar *searchbar)
gboolean match_case;
doc = xed_window_get_active_document (searchbar->window);
if (doc == NULL) {
if (doc == NULL)
{
return;
}
@ -286,12 +307,13 @@ do_replace (XedSearchbar *searchbar)
match_case = xed_searchbar_get_match_case (searchbar);
if ((selected_text == NULL) ||
(match_case && (strcmp (selected_text, unescaped_search_text) != 0)) ||
(!match_case && !g_utf8_caselessnmatch (selected_text,
if ((selected_text == NULL)
|| (match_case && (strcmp (selected_text, unescaped_search_text) != 0))
|| (!match_case && !g_utf8_caselessnmatch (selected_text,
unescaped_search_text,
strlen (selected_text),
strlen (unescaped_search_text)) != 0)) {
strlen (unescaped_search_text)) != 0))
{
do_find (searchbar, FALSE);
g_free (unescaped_search_text);
g_free (selected_text);
@ -322,7 +344,8 @@ do_replace_all (XedSearchbar *searchbar)
gint count;
active_view = xed_window_get_active_view (searchbar->window);
if (active_view == NULL) {
if (active_view == NULL)
{
return;
}
@ -344,24 +367,31 @@ do_replace_all (XedSearchbar *searchbar)
count = xed_document_replace_all (doc, search_entry_text, replace_entry_text, flags);
if (count > 0) {
if (count > 0)
{
text_found (searchbar->window, count);
}
else {
else
{
text_not_found (searchbar->window, search_entry_text);
}
}
static void
insert_text_handler (GtkEditable *editable, const gchar *text, gint length, gint *position, gpointer data)
insert_text_handler (GtkEditable *editable,
const gchar *text,
gint length,
gint *position,
gpointer data)
{
static gboolean insert_text = FALSE;
gchar *escaped_text;
gint new_len;
/* To avoid recursive behavior */
if (insert_text) {
if (insert_text)
{
return;
}
@ -369,7 +399,8 @@ insert_text_handler (GtkEditable *editable, const gchar *text, gint length, gint
new_len = strlen (escaped_text);
if (new_len == length) {
if (new_len == length)
{
g_free (escaped_text);
return;
}
@ -386,18 +417,21 @@ insert_text_handler (GtkEditable *editable, const gchar *text, gint length, gint
}
static void
search_text_entry_changed (GtkEditable *editable, XedSearchbar *searchbar)
search_text_entry_changed (GtkEditable *editable,
XedSearchbar *searchbar)
{
const gchar *search_string;
search_string = gtk_entry_get_text (GTK_ENTRY(editable));
g_return_if_fail(search_string != NULL);
if (*search_string != '\0') {
if (*search_string != '\0')
{
search_buttons_set_sensitive (searchbar, TRUE);
do_find (searchbar, FALSE);
}
else {
else
{
search_buttons_set_sensitive (searchbar, FALSE);
}
}
@ -407,7 +441,8 @@ remember_search_entry (XedSearchbar *searchbar)
{
const gchar *str;
str = gtk_entry_get_text (GTK_ENTRY(searchbar->priv->search_text_entry));
if (*str != '\0') {
if (*str != '\0')
{
gchar *text;
text = xed_utils_unescape_search_text (str);
xed_history_entry_prepend_text (XED_HISTORY_ENTRY(searchbar->priv->search_entry), text);
@ -420,7 +455,8 @@ remember_replace_entry (XedSearchbar *searchbar)
{
const gchar *str;
str = gtk_entry_get_text (GTK_ENTRY(searchbar->priv->replace_text_entry));
if (*str != '\0') {
if (*str != '\0')
{
gchar *text;
text = xed_utils_unescape_search_text (str);
xed_history_entry_prepend_text (XED_HISTORY_ENTRY(searchbar->priv->replace_entry), text);
@ -429,21 +465,24 @@ remember_replace_entry (XedSearchbar *searchbar)
}
static void
find_button_clicked_callback (GtkWidget *button, XedSearchbar *searchbar)
find_button_clicked_callback (GtkWidget *button,
XedSearchbar *searchbar)
{
remember_search_entry (searchbar);
do_find (searchbar, FALSE);
}
static void
find_prev_button_clicked_callback (GtkWidget *button, XedSearchbar *searchbar)
find_prev_button_clicked_callback (GtkWidget *button,
XedSearchbar *searchbar)
{
remember_search_entry (searchbar);
do_find (searchbar, TRUE);
}
static void
replace_button_clicked_callback (GtkWidget *button, XedSearchbar *searchbar)
replace_button_clicked_callback (GtkWidget *button,
XedSearchbar *searchbar)
{
remember_search_entry (searchbar);
remember_replace_entry (searchbar);
@ -451,7 +490,8 @@ replace_button_clicked_callback (GtkWidget *button, XedSearchbar *searchbar)
}
static void
replace_all_button_clicked_callback (GtkWidget *button, XedSearchbar *searchbar)
replace_all_button_clicked_callback (GtkWidget *button,
XedSearchbar *searchbar)
{
remember_search_entry (searchbar);
remember_replace_entry (searchbar);
@ -459,7 +499,8 @@ replace_all_button_clicked_callback (GtkWidget *button, XedSearchbar *searchbar)
}
static void
on_search_text_entry_activated (GtkEntry *widget, XedSearchbar *searchbar)
on_search_text_entry_activated (GtkEntry *widget,
XedSearchbar *searchbar)
{
remember_search_entry (searchbar);
do_find (searchbar, FALSE);
@ -497,20 +538,17 @@ xed_searchbar_init (XedSearchbar *searchbar)
searchbar->priv->search_entry = xed_history_entry_new ("history-search-for", TRUE);
gtk_widget_set_hexpand (searchbar->priv->search_entry, TRUE);
xed_history_entry_set_escape_func (
XED_HISTORY_ENTRY (searchbar->priv->search_entry),
xed_history_entry_set_escape_func (XED_HISTORY_ENTRY(searchbar->priv->search_entry),
(XedHistoryEntryEscapeFunc) xed_utils_escape_search_text);
searchbar->priv->search_text_entry = xed_history_entry_get_entry (
XED_HISTORY_ENTRY (searchbar->priv->search_entry));
searchbar->priv->search_text_entry = xed_history_entry_get_entry (XED_HISTORY_ENTRY(searchbar->priv->search_entry));
gtk_entry_set_activates_default (GTK_ENTRY(searchbar->priv->search_text_entry), TRUE);
gtk_widget_show (searchbar->priv->search_entry);
gtk_grid_attach (GTK_GRID(searchbar->priv->grid), searchbar->priv->search_entry, 2, 0, 1, 1);
searchbar->priv->replace_entry = xed_history_entry_new ("history-replace-with", TRUE);
xed_history_entry_set_escape_func (
XED_HISTORY_ENTRY (searchbar->priv->replace_entry),
xed_history_entry_set_escape_func (XED_HISTORY_ENTRY(searchbar->priv->replace_entry),
(XedHistoryEntryEscapeFunc) xed_utils_escape_search_text);
searchbar->priv->replace_text_entry = xed_history_entry_get_entry (
@ -565,7 +603,8 @@ xed_searchbar_init (XedSearchbar *searchbar)
}
GtkWidget *
xed_searchbar_new (GtkWindow *parent, gboolean show_replace)
xed_searchbar_new (GtkWindow *parent,
gboolean show_replace)
{
XedSearchbar *searchbar;
searchbar = g_object_new (XED_TYPE_SEARCHBAR, NULL);
@ -573,7 +612,9 @@ xed_searchbar_new (GtkWindow *parent, gboolean show_replace)
return GTK_WIDGET(searchbar);
}
void xed_searchbar_show (XedSearchbar *searchbar, gboolean show_replace)
void
xed_searchbar_show (XedSearchbar *searchbar,
gboolean show_replace)
{
XedDocument *doc;
gboolean selection_exists;
@ -586,7 +627,8 @@ void xed_searchbar_show (XedSearchbar *searchbar, gboolean show_replace)
selection_exists = get_selected_text (GTK_TEXT_BUFFER(doc), &find_text, &sel_len);
if (selection_exists && find_text != NULL && sel_len < 80) {
if (selection_exists && find_text != NULL && sel_len < 80)
{
/*
* Special case: if the currently selected text
* is the same as the unescaped search text, use the
@ -595,25 +637,29 @@ void xed_searchbar_show (XedSearchbar *searchbar, gboolean show_replace)
* you'll get an unprintable single-character literal '\n' in the "search for" box).
*/
search_text = xed_searchbar_get_search_text (XED_SEARCHBAR(searchbar));
if (!(search_text != NULL && !strcmp(xed_utils_unescape_search_text(search_text), find_text))) {
if (!(search_text != NULL && !strcmp (xed_utils_unescape_search_text (search_text), find_text)))
{
/* General case */
xed_searchbar_set_search_text (XED_SEARCHBAR(searchbar), find_text);
}
g_free (find_text);
}
else {
else
{
g_free (find_text);
}
gtk_revealer_set_transition_type (GTK_REVEALER(searchbar->priv->revealer), GTK_REVEALER_TRANSITION_TYPE_SLIDE_UP);
gtk_revealer_set_reveal_child (GTK_REVEALER(searchbar->priv->revealer), TRUE);
if (show_replace) {
if (show_replace)
{
gtk_widget_show (searchbar->priv->replace_label);
gtk_widget_show (searchbar->priv->replace_entry);
gtk_widget_show (searchbar->priv->replace_all_button);
gtk_widget_show (searchbar->priv->replace_button);
gtk_grid_set_row_spacing (GTK_GRID(searchbar->priv->grid), 10);
}
else {
else
{
gtk_widget_hide (searchbar->priv->replace_label);
gtk_widget_hide (searchbar->priv->replace_entry);
gtk_widget_hide (searchbar->priv->replace_all_button);
@ -625,15 +671,16 @@ void xed_searchbar_show (XedSearchbar *searchbar, gboolean show_replace)
gtk_widget_grab_focus (searchbar->priv->search_text_entry);
}
void xed_searchbar_hide (XedSearchbar *searchbar)
void
xed_searchbar_hide (XedSearchbar *searchbar)
{
gtk_revealer_set_transition_type (GTK_REVEALER (searchbar->priv->revealer),
GTK_REVEALER_TRANSITION_TYPE_SLIDE_DOWN);
gtk_revealer_set_transition_type (GTK_REVEALER(searchbar->priv->revealer), GTK_REVEALER_TRANSITION_TYPE_SLIDE_DOWN);
gtk_revealer_set_reveal_child (GTK_REVEALER(searchbar->priv->revealer), FALSE);
// focus document
XedView *active_view = xed_window_get_active_view (searchbar->window);
if (active_view != NULL) {
if (active_view != NULL)
{
gtk_widget_grab_focus (GTK_WIDGET(active_view));
}
@ -642,7 +689,8 @@ void xed_searchbar_hide (XedSearchbar *searchbar)
}
void
xed_searchbar_set_search_text (XedSearchbar *searchbar, const gchar *text)
xed_searchbar_set_search_text (XedSearchbar *searchbar,
const gchar *text)
{
g_return_if_fail(XED_IS_SEARCHBAR (searchbar));
g_return_if_fail(text != NULL);
@ -661,7 +709,8 @@ xed_searchbar_get_search_text (XedSearchbar *searchbar)
}
void
xed_searchbar_set_replace_text (XedSearchbar *searchbar, const gchar *text)
xed_searchbar_set_replace_text (XedSearchbar *searchbar,
const gchar *text)
{
g_return_if_fail(XED_IS_SEARCHBAR (searchbar));
g_return_if_fail(text != NULL);
@ -677,7 +726,8 @@ xed_searchbar_get_replace_text (XedSearchbar *searchbar)
}
void
xed_searchbar_set_match_case (XedSearchbar *searchbar, gboolean match_case)
xed_searchbar_set_match_case (XedSearchbar *searchbar,
gboolean match_case)
{
g_return_if_fail(XED_IS_SEARCHBAR (searchbar));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(searchbar->priv->match_case_checkbutton), match_case);
@ -691,7 +741,8 @@ xed_searchbar_get_match_case (XedSearchbar *searchbar)
}
void
xed_searchbar_set_entire_word (XedSearchbar *searchbar, gboolean entire_word)
xed_searchbar_set_entire_word (XedSearchbar *searchbar,
gboolean entire_word)
{
g_return_if_fail(XED_IS_SEARCHBAR (searchbar));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(searchbar->priv->entire_word_checkbutton), entire_word);
@ -705,7 +756,8 @@ xed_searchbar_get_entire_word (XedSearchbar *searchbar)
}
void
xed_searchbar_set_wrap_around (XedSearchbar *searchbar, gboolean wrap_around)
xed_searchbar_set_wrap_around (XedSearchbar *searchbar,
gboolean wrap_around)
{
g_return_if_fail(XED_IS_SEARCHBAR (searchbar));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(searchbar->priv->wrap_around_checkbutton), wrap_around);

View File

@ -55,21 +55,20 @@ G_DEFINE_TYPE(XedView, xed_view, GTK_SOURCE_TYPE_VIEW)
/* Signals */
enum
{
START_INTERACTIVE_GOTO_LINE,
DROP_URIS,
LAST_SIGNAL
START_INTERACTIVE_GOTO_LINE, DROP_URIS, LAST_SIGNAL
};
static guint view_signals[LAST_SIGNAL] = { 0 };
typedef enum
{
XED_SEARCH_ENTRY_NORMAL,
XED_SEARCH_ENTRY_NOT_FOUND
XED_SEARCH_ENTRY_NORMAL, XED_SEARCH_ENTRY_NOT_FOUND
} XedSearchEntryState;
static void
document_read_only_notify_handler (XedDocument *document, GParamSpec *pspec, XedView *view)
document_read_only_notify_handler (XedDocument *document,
GParamSpec *pspec,
XedView *view)
{
xed_debug (DEBUG_VIEW);
gtk_text_view_set_editable (GTK_TEXT_VIEW(view), !xed_document_get_readonly (document));
@ -114,8 +113,8 @@ xed_view_class_init (XedViewClass *klass)
view_signals[START_INTERACTIVE_GOTO_LINE] = g_signal_new ("start_interactive_goto_line",
G_TYPE_FROM_CLASS(object_class), G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (XedViewClass, start_interactive_goto_line), NULL, NULL, xed_marshal_BOOLEAN__NONE,
G_TYPE_BOOLEAN, 0);
G_STRUCT_OFFSET(XedViewClass, start_interactive_goto_line),
NULL, NULL, xed_marshal_BOOLEAN__NONE, G_TYPE_BOOLEAN, 0);
/* A new signal DROP_URIS has been added to allow plugins to intercept
* the default dnd behaviour of 'text/uri-list'. XedView now handles
@ -127,8 +126,9 @@ xed_view_class_init (XedViewClass *klass)
* will not prevent xed from loading the uri
*/
view_signals[DROP_URIS] = g_signal_new ("drop_uris", G_TYPE_FROM_CLASS(object_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (XedViewClass, drop_uris),NULL, NULL,
g_cclosure_marshal_VOID__BOXED, G_TYPE_NONE, 1, G_TYPE_STRV);
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET(XedViewClass, drop_uris),
NULL, NULL, g_cclosure_marshal_VOID__BOXED, G_TYPE_NONE, 1, G_TYPE_STRV);
g_type_class_add_private (klass, sizeof(XedViewPrivate));
@ -143,7 +143,8 @@ xed_view_class_init (XedViewClass *klass)
static void
current_buffer_removed (XedView *view)
{
if (view->priv->current_buffer) {
if (view->priv->current_buffer)
{
g_signal_handlers_disconnect_by_func(view->priv->current_buffer, document_read_only_notify_handler, view);
g_signal_handlers_disconnect_by_func(view->priv->current_buffer, search_highlight_updated_cb, view);
g_object_unref (view->priv->current_buffer);
@ -152,14 +153,17 @@ current_buffer_removed (XedView *view)
}
static void
on_notify_buffer_cb (XedView *view, GParamSpec *arg1, gpointer userdata)
on_notify_buffer_cb (XedView *view,
GParamSpec *arg1,
gpointer userdata)
{
GtkTextBuffer *buffer;
current_buffer_removed (view);
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW(view));
if (buffer == NULL || !XED_IS_DOCUMENT (buffer)) {
if (buffer == NULL || !XED_IS_DOCUMENT(buffer))
{
return;
}
@ -184,13 +188,15 @@ xed_view_init (XedView *view)
* Set tab, fonts, wrap mode, colors, etc. according
* to preferences
*/
if (!xed_prefs_manager_get_use_default_font ()) {
if (!xed_prefs_manager_get_use_default_font ())
{
gchar *editor_font;
editor_font = xed_prefs_manager_get_editor_font ();
xed_view_set_font (view, FALSE, editor_font);
g_free (editor_font);
}
else {
else
{
xed_view_set_font (view, TRUE, NULL);
}
@ -212,7 +218,8 @@ xed_view_init (XedView *view)
/* Drag and drop support */
tl = gtk_drag_dest_get_target_list (GTK_WIDGET(view));
if (tl != NULL) {
if (tl != NULL)
{
gtk_target_list_add_uri_targets (tl, TARGET_URI_LIST);
}
@ -227,11 +234,13 @@ xed_view_dispose (GObject *object)
view = XED_VIEW(object);
if (view->priv->search_window != NULL) {
if (view->priv->search_window != NULL)
{
gtk_widget_destroy (view->priv->search_window);
view->priv->search_window = NULL;
view->priv->search_entry = NULL;
if (view->priv->typeselect_flush_timeout != 0) {
if (view->priv->typeselect_flush_timeout != 0)
{
g_source_remove (view->priv->typeselect_flush_timeout);
view->priv->typeselect_flush_timeout = 0;
}
@ -256,14 +265,16 @@ xed_view_finalize (GObject *object)
}
static gint
xed_view_focus_out (GtkWidget *widget, GdkEventFocus *event)
xed_view_focus_out (GtkWidget *widget,
GdkEventFocus *event)
{
XedView *view = XED_VIEW(widget);
gtk_widget_queue_draw (widget);
/* hide interactive search dialog */
if (view->priv->search_window != NULL) {
if (view->priv->search_window != NULL)
{
hide_search_window (view, FALSE);
}
@ -434,7 +445,9 @@ xed_view_scroll_to_cursor (XedView *view)
* otherwise sets it to @font_name.
**/
void
xed_view_set_font (XedView *view, gboolean def, const gchar *font_name)
xed_view_set_font (XedView *view,
gboolean def,
const gchar *font_name)
{
PangoFontDescription *font_desc = NULL;
@ -442,13 +455,15 @@ xed_view_set_font (XedView *view, gboolean def, const gchar *font_name)
g_return_if_fail(XED_IS_VIEW (view));
if (def) {
if (def)
{
gchar *font;
font = xed_prefs_manager_get_system_font ();
font_desc = pango_font_description_from_string (font);
g_free (font);
}
else {
else
{
g_return_if_fail(font_name != NULL);
font_desc = pango_font_description_from_string (font_name);
}
@ -459,21 +474,25 @@ xed_view_set_font (XedView *view, gboolean def, const gchar *font_name)
}
static void
set_entry_state (GtkWidget *entry, XedSearchEntryState state)
set_entry_state (GtkWidget *entry,
XedSearchEntryState state)
{
GtkStyleContext *context = gtk_widget_get_style_context (GTK_WIDGET(entry));
if (state == XED_SEARCH_ENTRY_NOT_FOUND) {
if (state == XED_SEARCH_ENTRY_NOT_FOUND)
{
gtk_style_context_add_class (context, GTK_STYLE_CLASS_ERROR);
}
else {
else
{
gtk_style_context_remove_class (context, GTK_STYLE_CLASS_ERROR);
}
}
/* Cut and paste from gtkwindow.c */
static void
send_focus_change (GtkWidget *widget, gboolean in)
send_focus_change (GtkWidget *widget,
gboolean in)
{
GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
@ -492,18 +511,22 @@ send_focus_change (GtkWidget *widget, gboolean in)
}
static void
hide_search_window (XedView *view, gboolean cancel)
hide_search_window (XedView *view,
gboolean cancel)
{
if (view->priv->disable_popdown)
{
if (view->priv->disable_popdown) {
return;
}
if (view->priv->search_entry_changed_id != 0) {
if (view->priv->search_entry_changed_id != 0)
{
g_signal_handler_disconnect (view->priv->search_entry, view->priv->search_entry_changed_id);
view->priv->search_entry_changed_id = 0;
}
if (view->priv->typeselect_flush_timeout != 0) {
if (view->priv->typeselect_flush_timeout != 0)
{
g_source_remove (view->priv->typeselect_flush_timeout);
view->priv->typeselect_flush_timeout = 0;
}
@ -513,7 +536,8 @@ hide_search_window (XedView *view, gboolean cancel)
gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW(view), TRUE);
gtk_widget_hide (view->priv->search_window);
if (cancel) {
if (cancel)
{
GtkTextBuffer *buffer;
buffer = GTK_TEXT_BUFFER(gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
gtk_text_buffer_place_cursor (buffer, &view->priv->start_search_iter);
@ -550,14 +574,18 @@ update_search_window_position (XedView *view)
}
static gboolean
search_window_deleted (GtkWidget *widget, GdkEventAny *event, XedView *view)
search_window_deleted (GtkWidget *widget,
GdkEventAny *event,
XedView *view)
{
hide_search_window (view, FALSE);
return TRUE;
}
static gboolean
search_window_button_pressed (GtkWidget *widget, GdkEventButton *event, XedView *view)
search_window_button_pressed (GtkWidget *widget,
GdkEventButton *event,
XedView *view)
{
hide_search_window (view, FALSE);
gtk_propagate_event (GTK_WIDGET(view), (GdkEvent *) event);
@ -565,7 +593,9 @@ search_window_button_pressed (GtkWidget *widget, GdkEventButton *event, XedView
}
static gboolean
search_window_key_pressed (GtkWidget *widget, GdkEventKey *event, XedView *view)
search_window_key_pressed (GtkWidget *widget,
GdkEventKey *event,
XedView *view)
{
gboolean retval = FALSE;
guint modifiers;
@ -573,13 +603,15 @@ search_window_key_pressed (GtkWidget *widget, GdkEventKey *event, XedView *view)
modifiers = gtk_accelerator_get_default_mod_mask ();
/* Close window */
if (event->keyval == GDK_KEY_Tab) {
if (event->keyval == GDK_KEY_Tab)
{
hide_search_window (view, FALSE);
retval = TRUE;
}
/* Close window and cancel the search */
if (event->keyval == GDK_KEY_Escape) {
if (event->keyval == GDK_KEY_Escape)
{
hide_search_window (view, TRUE);
retval = TRUE;
}
@ -588,7 +620,8 @@ search_window_key_pressed (GtkWidget *widget, GdkEventKey *event, XedView *view)
}
static void
search_entry_activate (GtkEntry *entry, XedView *view)
search_entry_activate (GtkEntry *entry,
XedView *view)
{
hide_search_window (view, FALSE);
}
@ -602,21 +635,25 @@ real_search_enable_popdown (gpointer data)
}
static void
search_enable_popdown (GtkWidget *widget, XedView *view)
search_enable_popdown (GtkWidget *widget,
XedView *view)
{
g_timeout_add (200, real_search_enable_popdown, view);
/* renew the flush timeout */
if (view->priv->typeselect_flush_timeout != 0) {
if (view->priv->typeselect_flush_timeout != 0)
{
g_source_remove (view->priv->typeselect_flush_timeout);
}
view->priv->typeselect_flush_timeout =
g_timeout_add (XED_VIEW_SEARCH_DIALOG_TIMEOUT, (GSourceFunc)search_entry_flush_timeout, view);
view->priv->typeselect_flush_timeout = g_timeout_add (XED_VIEW_SEARCH_DIALOG_TIMEOUT,
(GSourceFunc) search_entry_flush_timeout, view);
}
static void
search_entry_populate_popup (GtkEntry *entry, GtkMenu *menu, XedView *view)
search_entry_populate_popup (GtkEntry *entry,
GtkMenu *menu,
XedView *view)
{
GtkWidget *menu_item;
view->priv->disable_popdown = TRUE;
@ -624,7 +661,11 @@ search_entry_populate_popup (GtkEntry *entry, GtkMenu *menu, XedView *view)
}
static void
search_entry_insert_text (GtkEditable *editable, const gchar *text, gint length, gint *position, XedView *view)
search_entry_insert_text (GtkEditable *editable,
const gchar *text,
gint length,
gint *position,
XedView *view)
{
gunichar c;
const gchar *p;
@ -634,29 +675,35 @@ search_entry_insert_text (GtkEditable *editable, const gchar *text, gint length,
p = text;
end = text + length;
if (p == end) {
if (p == end)
{
return;
}
c = g_utf8_get_char (p);
if (((c == '-' || c == '+') && *position == 0) || (c == ':' && *position != 0)) {
if (((c == '-' || c == '+') && *position == 0) || (c == ':' && *position != 0))
{
gchar *s = NULL;
if (c == ':') {
if (c == ':')
{
s = gtk_editable_get_chars (editable, 0, -1);
s = g_utf8_strchr (s, -1, ':');
}
if (s == NULL || s == p) {
if (s == NULL || s == p)
{
next = g_utf8_next_char(p);
p = next;
}
g_free (s);
}
while (p != end) {
while (p != end)
{
next = g_utf8_next_char(p);
c = g_utf8_get_char (p);
if (!g_unichar_isdigit (c)) {
if (!g_unichar_isdigit (c))
{
g_signal_stop_emission_by_name (editable, "insert_text");
gtk_widget_error_bell (view->priv->search_entry);
break;
@ -683,15 +730,19 @@ ensure_search_window (XedView *view)
toplevel = gtk_widget_get_toplevel (GTK_WIDGET(view));
group = gtk_window_get_group (GTK_WINDOW(toplevel));
if (view->priv->search_window != NULL) {
if (view->priv->search_window != NULL)
{
search_group = gtk_window_get_group (GTK_WINDOW(view->priv->search_window));
}
if (view->priv->search_window != NULL) {
if (group) {
if (view->priv->search_window != NULL)
{
if (group)
{
gtk_window_group_add_window (group, GTK_WINDOW(view->priv->search_window));
}
else if (search_group) {
else if (search_group)
{
gtk_window_group_remove_window (search_group, GTK_WINDOW(view->priv->search_window));
}
customize_for_search_mode (view);
@ -700,7 +751,8 @@ ensure_search_window (XedView *view)
view->priv->search_window = gtk_window_new (GTK_WINDOW_POPUP);
if (group) {
if (group)
{
gtk_window_group_add_window (group, GTK_WINDOW(view->priv->search_window));
}
@ -735,15 +787,19 @@ ensure_search_window (XedView *view)
}
static gboolean
get_selected_text (GtkTextBuffer *doc, gchar **selected_text, gint *len)
get_selected_text (GtkTextBuffer *doc,
gchar **selected_text,
gint *len)
{
GtkTextIter start, end;
g_return_val_if_fail(selected_text != NULL, FALSE);
g_return_val_if_fail(*selected_text == NULL, FALSE);
if (!gtk_text_buffer_get_selection_bounds (doc, &start, &end)) {
if (len != NULL) {
if (!gtk_text_buffer_get_selection_bounds (doc, &start, &end))
{
if (len != NULL)
{
len = 0;
}
return FALSE;
@ -751,7 +807,8 @@ get_selected_text (GtkTextBuffer *doc, gchar **selected_text, gint *len)
*selected_text = gtk_text_buffer_get_slice (doc, &start, &end, TRUE);
if (len != NULL) {
if (len != NULL)
{
*len = g_utf8_strlen (*selected_text, -1);
}
@ -773,22 +830,25 @@ init_search_entry (XedView *view)
}
static void
search_init (GtkWidget *entry, XedView *view)
search_init (GtkWidget *entry,
XedView *view)
{
XedDocument *doc;
const gchar *entry_text;
/* renew the flush timeout */
if (view->priv->typeselect_flush_timeout != 0) {
if (view->priv->typeselect_flush_timeout != 0)
{
g_source_remove (view->priv->typeselect_flush_timeout);
view->priv->typeselect_flush_timeout =
g_timeout_add (XED_VIEW_SEARCH_DIALOG_TIMEOUT, (GSourceFunc)search_entry_flush_timeout, view);
view->priv->typeselect_flush_timeout = g_timeout_add (XED_VIEW_SEARCH_DIALOG_TIMEOUT,
(GSourceFunc) search_entry_flush_timeout, view);
}
doc = XED_DOCUMENT(gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
entry_text = gtk_entry_get_text (GTK_ENTRY(entry));
if (*entry_text != '\0') {
if (*entry_text != '\0')
{
gboolean moved, moved_offset;
gint line;
gint offset_line = 0;
@ -798,32 +858,39 @@ search_init (GtkWidget *entry, XedView *view)
split_text = g_strsplit (entry_text, ":", -1);
if (g_strv_length (split_text) > 1) {
if (g_strv_length (split_text) > 1)
{
text = split_text[0];
}
else {
else
{
text = entry_text;
}
if (*text == '-') {
if (*text == '-')
{
gint cur_line = gtk_text_iter_get_line (&view->priv->start_search_iter);
if (*(text + 1) != '\0') {
if (*(text + 1) != '\0')
{
offset_line = MAX(atoi (text + 1), 0);
}
line = MAX(cur_line - offset_line, 0);
}
else if (*entry_text == '+') {
else if (*entry_text == '+')
{
gint cur_line = gtk_text_iter_get_line (&view->priv->start_search_iter);
if (*(text + 1) != '\0') {
if (*(text + 1) != '\0')
{
offset_line = MAX(atoi (text + 1), 0);
}
line = cur_line + offset_line;
}
else {
else
{
line = MAX(atoi (text) - 1, 0);
}
@ -839,10 +906,12 @@ search_init (GtkWidget *entry, XedView *view)
xed_view_scroll_to_cursor (view);
if (!moved || !moved_offset) {
if (!moved || !moved_offset)
{
set_entry_state (view->priv->search_entry, XED_SEARCH_ENTRY_NOT_FOUND);
}
else {
else
{
set_entry_state (view->priv->search_entry, XED_SEARCH_ENTRY_NORMAL);
}
}
@ -853,11 +922,13 @@ start_interactive_goto_line (XedView *view)
{
GtkTextBuffer *buffer;
if ((view->priv->search_window != NULL) && gtk_widget_get_visible (view->priv->search_window)) {
if ((view->priv->search_window != NULL) && gtk_widget_get_visible (view->priv->search_window))
{
return TRUE;
}
if (!gtk_widget_has_focus (GTK_WIDGET (view))) {
if (!gtk_widget_has_focus (GTK_WIDGET(view)))
{
return FALSE;
}
@ -871,15 +942,16 @@ start_interactive_goto_line (XedView *view)
update_search_window_position (view);
gtk_widget_show (view->priv->search_window);
if (view->priv->search_entry_changed_id == 0) {
view->priv->search_entry_changed_id =
g_signal_connect (view->priv->search_entry, "changed", G_CALLBACK (search_init), view);
if (view->priv->search_entry_changed_id == 0)
{
view->priv->search_entry_changed_id = g_signal_connect(view->priv->search_entry, "changed",
G_CALLBACK (search_init), view);
}
init_search_entry (view);
view->priv->typeselect_flush_timeout =
g_timeout_add (XED_VIEW_SEARCH_DIALOG_TIMEOUT, (GSourceFunc) search_entry_flush_timeout, view);
view->priv->typeselect_flush_timeout = g_timeout_add (XED_VIEW_SEARCH_DIALOG_TIMEOUT,
(GSourceFunc) search_entry_flush_timeout, view);
gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW(view), FALSE);
gtk_widget_grab_focus (view->priv->search_entry);
@ -890,7 +962,8 @@ start_interactive_goto_line (XedView *view)
}
static gboolean
xed_view_draw (GtkWidget *widget, cairo_t *cr)
xed_view_draw (GtkWidget *widget,
cairo_t *cr)
{
GtkTextView *text_view;
XedDocument *doc;
@ -900,7 +973,8 @@ xed_view_draw (GtkWidget *widget, cairo_t *cr)
doc = XED_DOCUMENT(gtk_text_view_get_buffer (text_view));
window = gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_TEXT);
if (gtk_cairo_should_draw_window (cr, window) && xed_document_get_enable_search_highlighting (doc)) {
if (gtk_cairo_should_draw_window (cr, window) && xed_document_get_enable_search_highlighting (doc))
{
GdkRectangle visible_rect;
GtkTextIter iter1, iter2;
@ -916,7 +990,8 @@ xed_view_draw (GtkWidget *widget, cairo_t *cr)
}
static GdkAtom
drag_get_uri_target (GtkWidget *widget, GdkDragContext *context)
drag_get_uri_target (GtkWidget *widget,
GdkDragContext *context)
{
GdkAtom target;
GtkTargetList *tl;
@ -930,7 +1005,11 @@ drag_get_uri_target (GtkWidget *widget, GdkDragContext *context)
}
static gboolean
xed_view_drag_motion (GtkWidget *widget, GdkDragContext *context, gint x, gint y, guint timestamp)
xed_view_drag_motion (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
guint timestamp)
{
gboolean result;
@ -940,7 +1019,8 @@ xed_view_drag_motion (GtkWidget *widget, GdkDragContext *context, gint x, gint y
result = GTK_WIDGET_CLASS (xed_view_parent_class)->drag_motion (widget, context, x, y, timestamp);
/* If this is a URL, deal with it here */
if (drag_get_uri_target (widget, context) != GDK_NONE) {
if (drag_get_uri_target (widget, context) != GDK_NONE)
{
gdk_drag_status (context, gdk_drag_context_get_suggested_action (context), timestamp);
result = TRUE;
}
@ -949,29 +1029,41 @@ xed_view_drag_motion (GtkWidget *widget, GdkDragContext *context, gint x, gint y
}
static void
xed_view_drag_data_received (GtkWidget *widget, GdkDragContext *context, gint x, gint y,
GtkSelectionData *selection_data, guint info, guint timestamp)
xed_view_drag_data_received (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
GtkSelectionData *selection_data,
guint info,
guint timestamp)
{
gchar **uri_list;
/* If this is an URL emit DROP_URIS, otherwise chain up the signal */
if (info == TARGET_URI_LIST) {
if (info == TARGET_URI_LIST)
{
uri_list = xed_utils_drop_get_uris (selection_data);
if (uri_list != NULL) {
if (uri_list != NULL)
{
g_signal_emit (widget, view_signals[DROP_URIS], 0, uri_list);
g_strfreev (uri_list);
gtk_drag_finish (context, TRUE, FALSE, timestamp);
}
}
else {
else
{
GTK_WIDGET_CLASS (xed_view_parent_class)->drag_data_received (widget, context, x, y, selection_data, info,
timestamp);
}
}
static gboolean
xed_view_drag_drop (GtkWidget *widget, GdkDragContext *context, gint x, gint y, guint timestamp)
xed_view_drag_drop (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
guint timestamp)
{
gboolean result;
GdkAtom target;
@ -979,11 +1071,13 @@ xed_view_drag_drop (GtkWidget *widget, GdkDragContext *context, gint x, gint y,
/* If this is a URL, just get the drag data */
target = drag_get_uri_target (widget, context);
if (target != GDK_NONE) {
if (target != GDK_NONE)
{
gtk_drag_get_data (widget, context, target, timestamp);
result = TRUE;
}
else {
else
{
/* Chain up */
result = GTK_WIDGET_CLASS (xed_view_parent_class)->drag_drop (widget, context, x, y, timestamp);
}
@ -992,7 +1086,8 @@ xed_view_drag_drop (GtkWidget *widget, GdkDragContext *context, gint x, gint y,
}
static void
show_line_numbers_toggled (GtkMenu *menu, XedView *view)
show_line_numbers_toggled (GtkMenu *menu,
XedView *view)
{
gboolean show;
@ -1009,8 +1104,8 @@ create_line_numbers_menu (GtkWidget *view)
menu = gtk_menu_new ();
item = gtk_check_menu_item_new_with_mnemonic (_("_Display line numbers"));
gtk_check_menu_item_set_active (
GTK_CHECK_MENU_ITEM (item), gtk_source_view_get_show_line_numbers (GTK_SOURCE_VIEW (view)));
gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM(item),
gtk_source_view_get_show_line_numbers (GTK_SOURCE_VIEW(view)));
g_signal_connect(item, "toggled", G_CALLBACK (show_line_numbers_toggled), view);
gtk_menu_shell_append (GTK_MENU_SHELL(menu), item);
@ -1020,7 +1115,8 @@ create_line_numbers_menu (GtkWidget *view)
}
static void
show_line_numbers_menu (GtkWidget *view, GdkEventButton *event)
show_line_numbers_menu (GtkWidget *view,
GdkEventButton *event)
{
GtkWidget *menu;
@ -1029,10 +1125,13 @@ show_line_numbers_menu (GtkWidget *view, GdkEventButton *event)
}
static gboolean
xed_view_button_press_event (GtkWidget *widget, GdkEventButton *event)
xed_view_button_press_event (GtkWidget *widget,
GdkEventButton *event)
{
if ((event->type == GDK_BUTTON_PRESS)
&& (event->button == 3)
&& (event->window == gtk_text_view_get_window (GTK_TEXT_VIEW(widget), GTK_TEXT_WINDOW_LEFT)))
{
if ((event->type == GDK_BUTTON_PRESS) && (event->button == 3) &&
(event->window == gtk_text_view_get_window (GTK_TEXT_VIEW (widget), GTK_TEXT_WINDOW_LEFT))) {
show_line_numbers_menu (widget, event);
@ -1043,7 +1142,10 @@ xed_view_button_press_event (GtkWidget *widget, GdkEventButton *event)
}
static void
search_highlight_updated_cb (XedDocument *doc, GtkTextIter *start, GtkTextIter *end, XedView *view)
search_highlight_updated_cb (XedDocument *doc,
GtkTextIter *start,
GtkTextIter *end,
XedView *view)
{
GdkRectangle visible_rect;
GdkRectangle updated_rect;
@ -1054,8 +1156,7 @@ search_highlight_updated_cb (XedDocument *doc, GtkTextIter *start, GtkTextIter *
text_view = GTK_TEXT_VIEW(view);
g_return_if_fail (
xed_document_get_enable_search_highlighting (XED_DOCUMENT (gtk_text_view_get_buffer (text_view))));
g_return_if_fail(xed_document_get_enable_search_highlighting (XED_DOCUMENT (gtk_text_view_get_buffer (text_view))));
/* get visible area */
gtk_text_view_get_visible_rect (text_view, &visible_rect);
@ -1069,7 +1170,8 @@ search_highlight_updated_cb (XedDocument *doc, GtkTextIter *start, GtkTextIter *
updated_rect.width = visible_rect.width;
/* intersect both rectangles to see whether we need to queue a redraw */
if (gdk_rectangle_intersect (&updated_rect, &visible_rect, &redraw_rect)) {
if (gdk_rectangle_intersect (&updated_rect, &visible_rect, &redraw_rect))
{
GdkRectangle widget_rect;
gtk_text_view_buffer_to_window_coords (text_view, GTK_TEXT_WINDOW_WIDGET, redraw_rect.x, redraw_rect.y,
&widget_rect.x, &widget_rect.y);
@ -1096,51 +1198,65 @@ delete_line (GtkTextView *text_view,
/* If there is a selection delete the selected lines and
* ignore count */
if (gtk_text_buffer_get_selection_bounds (buffer, &start, &end)) {
if (gtk_text_buffer_get_selection_bounds (buffer, &start, &end))
{
gtk_text_iter_order (&start, &end);
if (gtk_text_iter_starts_line (&end)) {
if (gtk_text_iter_starts_line (&end))
{
/* Do no delete the line with the cursor if the cursor
* is at the beginning of the line */
count = 0;
}
else {
else
{
count = 1;
}
}
gtk_text_iter_set_line_offset (&start, 0);
if (count > 0) {
if (count > 0)
{
gtk_text_iter_forward_lines (&end, count);
if (gtk_text_iter_is_end (&end)) {
if (gtk_text_iter_backward_line (&start) && !gtk_text_iter_ends_line (&start)) {
if (gtk_text_iter_is_end (&end))
{
if (gtk_text_iter_backward_line (&start) && !gtk_text_iter_ends_line (&start))
{
gtk_text_iter_forward_to_line_end (&start);
}
}
}
else if (count < 0) {
if (!gtk_text_iter_ends_line (&end)) {
else if (count < 0)
{
if (!gtk_text_iter_ends_line (&end))
{
gtk_text_iter_forward_to_line_end (&end);
}
while (count < 0) {
if (!gtk_text_iter_backward_line (&start)) {
while (count < 0)
{
if (!gtk_text_iter_backward_line (&start))
{
break;
}
++count;
}
if (count == 0) {
if (!gtk_text_iter_ends_line (&start)) {
if (count == 0)
{
if (!gtk_text_iter_ends_line (&start))
{
gtk_text_iter_forward_to_line_end (&start);
}
}
else {
else
{
gtk_text_iter_forward_line (&end);
}
}
if (!gtk_text_iter_equal (&start, &end)) {
if (!gtk_text_iter_equal (&start, &end))
{
GtkTextIter cur = start;
gtk_text_iter_set_line_offset (&cur, 0);
gtk_text_buffer_begin_user_action (buffer);
@ -1149,19 +1265,23 @@ delete_line (GtkTextView *text_view,
gtk_text_buffer_end_user_action (buffer);
gtk_text_view_scroll_mark_onscreen (text_view, gtk_text_buffer_get_insert (buffer));
}
else {
else
{
gtk_widget_error_bell (GTK_WIDGET(text_view));
}
}
static void
xed_view_delete_from_cursor (GtkTextView *text_view, GtkDeleteType type, gint count)
xed_view_delete_from_cursor (GtkTextView *text_view,
GtkDeleteType type,
gint count)
{
/* We override the standard handler for delete_from_cursor since
the GTK_DELETE_PARAGRAPHS case is not implemented as we like (i.e. it
does not remove the carriage return in the previous line)
*/
switch (type) {
switch (type)
{
case GTK_DELETE_PARAGRAPHS:
delete_line (text_view, count);
break;

File diff suppressed because it is too large Load Diff