xed-sort-plugin.c: Clean up code styling
This commit is contained in:
parent
26f8139317
commit
3a6de664e1
|
@ -85,7 +85,8 @@ typedef struct
|
|||
gint starting_column;
|
||||
} SortInfo;
|
||||
|
||||
static void sort_cb (GtkAction *action, XedSortPlugin *plugin);
|
||||
static void sort_cb (GtkAction *action,
|
||||
XedSortPlugin *plugin);
|
||||
static void sort_real (SortDialog *dialog);
|
||||
|
||||
static const GtkActionEntry action_entries[] =
|
||||
|
@ -95,7 +96,8 @@ static const GtkActionEntry action_entries[] =
|
|||
N_("S_ort..."),
|
||||
NULL,
|
||||
N_("Sort the current document or selection"),
|
||||
G_CALLBACK (sort_cb) }
|
||||
G_CALLBACK (sort_cb)
|
||||
}
|
||||
};
|
||||
|
||||
static void
|
||||
|
@ -122,9 +124,7 @@ sort_dialog_response_handler (GtkDialog *widget,
|
|||
break;
|
||||
|
||||
case GTK_RESPONSE_HELP:
|
||||
xed_help_display (GTK_WINDOW (widget),
|
||||
NULL,
|
||||
"xed-sort-plugin");
|
||||
xed_help_display (GTK_WINDOW (widget), NULL, "xed-sort-plugin");
|
||||
break;
|
||||
|
||||
case GTK_RESPONSE_CANCEL:
|
||||
|
@ -137,7 +137,8 @@ sort_dialog_response_handler (GtkDialog *widget,
|
|||
* the text field (like the combo box) looses the documnent selection.
|
||||
* Storing the selection ONLY works because the dialog is modal */
|
||||
static void
|
||||
get_current_selection (XedWindow *window, SortDialog *dialog)
|
||||
get_current_selection (XedWindow *window,
|
||||
SortDialog *dialog)
|
||||
{
|
||||
XedDocument *doc;
|
||||
|
||||
|
@ -145,14 +146,10 @@ get_current_selection (XedWindow *window, SortDialog *dialog)
|
|||
|
||||
doc = xed_window_get_active_document (window);
|
||||
|
||||
if (!gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (doc),
|
||||
&dialog->start,
|
||||
&dialog->end))
|
||||
if (!gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (doc), &dialog->start, &dialog->end))
|
||||
{
|
||||
/* No selection, get the whole document. */
|
||||
gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (doc),
|
||||
&dialog->start,
|
||||
&dialog->end);
|
||||
gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (doc), &dialog->start, &dialog->end);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -191,8 +188,7 @@ get_sort_dialog (XedSortPlugin *plugin)
|
|||
const gchar *err_message;
|
||||
|
||||
err_message = gtk_label_get_label (GTK_LABEL (error_widget));
|
||||
xed_warning (GTK_WINDOW (window),
|
||||
"%s", err_message);
|
||||
xed_warning (GTK_WINDOW (window), "%s", err_message);
|
||||
|
||||
g_slice_free (SortDialog, dialog);
|
||||
gtk_widget_destroy (error_widget);
|
||||
|
@ -200,18 +196,10 @@ get_sort_dialog (XedSortPlugin *plugin)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
gtk_dialog_set_default_response (GTK_DIALOG (dialog->dialog),
|
||||
GTK_RESPONSE_OK);
|
||||
gtk_dialog_set_default_response (GTK_DIALOG (dialog->dialog), GTK_RESPONSE_OK);
|
||||
|
||||
g_signal_connect (dialog->dialog,
|
||||
"destroy",
|
||||
G_CALLBACK (sort_dialog_destroy),
|
||||
dialog);
|
||||
|
||||
g_signal_connect (dialog->dialog,
|
||||
"response",
|
||||
G_CALLBACK (sort_dialog_response_handler),
|
||||
dialog);
|
||||
g_signal_connect (dialog->dialog, "destroy", G_CALLBACK (sort_dialog_destroy), dialog);
|
||||
g_signal_connect (dialog->dialog, "response", G_CALLBACK (sort_dialog_response_handler), dialog);
|
||||
|
||||
get_current_selection (window, dialog);
|
||||
|
||||
|
@ -238,16 +226,12 @@ sort_cb (GtkAction *action,
|
|||
g_return_if_fail (dialog != NULL);
|
||||
|
||||
wg = xed_window_get_group (window);
|
||||
gtk_window_group_add_window (wg,
|
||||
GTK_WINDOW (dialog->dialog));
|
||||
gtk_window_group_add_window (wg, GTK_WINDOW (dialog->dialog));
|
||||
|
||||
dialog->doc = doc;
|
||||
|
||||
gtk_window_set_transient_for (GTK_WINDOW (dialog->dialog),
|
||||
GTK_WINDOW (window));
|
||||
|
||||
gtk_window_set_modal (GTK_WINDOW (dialog->dialog),
|
||||
TRUE);
|
||||
gtk_window_set_transient_for (GTK_WINDOW (dialog->dialog), GTK_WINDOW (window));
|
||||
gtk_window_set_modal (GTK_WINDOW (dialog->dialog), TRUE);
|
||||
|
||||
gtk_widget_show (GTK_WIDGET (dialog->dialog));
|
||||
}
|
||||
|
@ -348,12 +332,11 @@ get_line_slice (GtkTextBuffer *buf,
|
|||
end = start;
|
||||
|
||||
if (!gtk_text_iter_ends_line (&start))
|
||||
{
|
||||
gtk_text_iter_forward_to_line_end (&end);
|
||||
}
|
||||
|
||||
ret= gtk_text_buffer_get_slice (buf,
|
||||
&start,
|
||||
&end,
|
||||
TRUE);
|
||||
ret= gtk_text_buffer_get_slice (buf, &start, &end, TRUE);
|
||||
|
||||
g_assert (ret != NULL);
|
||||
|
||||
|
@ -392,9 +375,13 @@ sort_real (SortDialog *dialog)
|
|||
* Otherwise the last line is the current one but we try to
|
||||
* move the iter after the line terminator */
|
||||
if (gtk_text_iter_get_line_offset (&end) == 0)
|
||||
{
|
||||
end_line = MAX (start_line, end_line - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_text_iter_forward_line (&end);
|
||||
}
|
||||
|
||||
num_lines = end_line - start_line + 1;
|
||||
lines = g_new0 (gchar *, num_lines + 1);
|
||||
|
@ -410,35 +397,23 @@ sort_real (SortDialog *dialog)
|
|||
|
||||
xed_debug_message (DEBUG_PLUGINS, "Sort list...");
|
||||
|
||||
g_qsort_with_data (lines,
|
||||
num_lines,
|
||||
sizeof (gpointer),
|
||||
compare_algorithm,
|
||||
sort_info);
|
||||
g_qsort_with_data (lines, num_lines, sizeof (gpointer), compare_algorithm, sort_info);
|
||||
|
||||
xed_debug_message (DEBUG_PLUGINS, "Rebuilding document...");
|
||||
|
||||
gtk_source_buffer_begin_not_undoable_action (GTK_SOURCE_BUFFER (doc));
|
||||
|
||||
gtk_text_buffer_delete (GTK_TEXT_BUFFER (doc),
|
||||
&start,
|
||||
&end);
|
||||
gtk_text_buffer_delete (GTK_TEXT_BUFFER (doc), &start, &end);
|
||||
|
||||
for (i = 0; i < num_lines; i++)
|
||||
{
|
||||
if (sort_info->remove_duplicates &&
|
||||
last_row != NULL &&
|
||||
(strcmp (last_row, lines[i]) == 0))
|
||||
if (sort_info->remove_duplicates && last_row != NULL && (strcmp (last_row, lines[i]) == 0))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
gtk_text_buffer_insert (GTK_TEXT_BUFFER (doc),
|
||||
&start,
|
||||
lines[i],
|
||||
-1);
|
||||
gtk_text_buffer_insert (GTK_TEXT_BUFFER (doc),
|
||||
&start,
|
||||
"\n",
|
||||
-1);
|
||||
gtk_text_buffer_insert (GTK_TEXT_BUFFER (doc), &start, lines[i], -1);
|
||||
gtk_text_buffer_insert (GTK_TEXT_BUFFER (doc), &start, "\n", -1);
|
||||
|
||||
last_row = lines[i];
|
||||
}
|
||||
|
@ -522,16 +497,13 @@ xed_sort_plugin_activate (PeasActivatable *activatable)
|
|||
manager = xed_window_get_ui_manager (window);
|
||||
|
||||
data->ui_action_group = gtk_action_group_new ("XedSortPluginActions");
|
||||
gtk_action_group_set_translation_domain (data->ui_action_group,
|
||||
GETTEXT_PACKAGE);
|
||||
gtk_action_group_set_translation_domain (data->ui_action_group, GETTEXT_PACKAGE);
|
||||
gtk_action_group_add_actions (data->ui_action_group,
|
||||
action_entries,
|
||||
G_N_ELEMENTS (action_entries),
|
||||
plugin);
|
||||
|
||||
gtk_ui_manager_insert_action_group (manager,
|
||||
data->ui_action_group,
|
||||
-1);
|
||||
gtk_ui_manager_insert_action_group (manager, data->ui_action_group, -1);
|
||||
|
||||
data->ui_id = gtk_ui_manager_new_merge_id (manager);
|
||||
|
||||
|
@ -560,10 +532,8 @@ xed_sort_plugin_deactivate (PeasActivatable *activatable)
|
|||
|
||||
manager = xed_window_get_ui_manager (window);
|
||||
|
||||
gtk_ui_manager_remove_ui (manager,
|
||||
data->ui_id);
|
||||
gtk_ui_manager_remove_action_group (manager,
|
||||
data->ui_action_group);
|
||||
gtk_ui_manager_remove_ui (manager, data->ui_id);
|
||||
gtk_ui_manager_remove_action_group (manager, data->ui_action_group);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
Loading…
Reference in New Issue