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