From 80094754dc9038e91a68eff4241b92295ae475c1 Mon Sep 17 00:00:00 2001 From: Andre Miranda Date: Thu, 4 Aug 2016 16:02:11 +0300 Subject: [PATCH] Delete newline --- mousepad/mousepad-view.c | 30 ++++++++++++++++++++++++++++++ mousepad/mousepad-view.h | 2 ++ mousepad/mousepad-window-ui.xml | 1 + mousepad/mousepad-window.c | 16 +++++++++++++++- 4 files changed, 48 insertions(+), 1 deletion(-) diff --git a/mousepad/mousepad-view.c b/mousepad/mousepad-view.c index 03f4609..e6375a4 100644 --- a/mousepad/mousepad-view.c +++ b/mousepad/mousepad-view.c @@ -2517,6 +2517,36 @@ mousepad_view_move_selection (MousepadView *view, } +void +mousepad_view_delete (MousepadView *view) +{ + GtkTextBuffer *buffer; + GtkTextIter start_iter, end_iter; + + g_return_if_fail (MOUSEPAD_IS_VIEW (view)); + + /* get the buffer */ + buffer = mousepad_view_get_buffer (view); + + /* begin a user action */ + gtk_text_buffer_begin_user_action (buffer); + + /* get iters */ + gtk_text_buffer_get_selection_bounds (buffer, &start_iter, &end_iter); + + /* set to the start of the first line */ + gtk_text_iter_set_line_offset (&start_iter, 0); + + /* move the other iter to the start of the next line */ + gtk_text_iter_forward_line (&end_iter); + + /* delete the line / selection of the text */ + gtk_text_buffer_delete (buffer, &start_iter, &end_iter); + + /* end the action */ + gtk_text_buffer_end_user_action (buffer); +} + void mousepad_view_duplicate (MousepadView *view) diff --git a/mousepad/mousepad-view.h b/mousepad/mousepad-view.h index 14c5fce..0149a5f 100644 --- a/mousepad/mousepad-view.h +++ b/mousepad/mousepad-view.h @@ -86,6 +86,8 @@ void mousepad_view_strip_trailing_spaces (MousepadView *view void mousepad_view_move_selection (MousepadView *view, gint type); +void mousepad_view_delete (MousepadView *view); + void mousepad_view_duplicate (MousepadView *view); void mousepad_view_indent (MousepadView *view, diff --git a/mousepad/mousepad-window-ui.xml b/mousepad/mousepad-window-ui.xml index e03223d..de028b9 100644 --- a/mousepad/mousepad-window-ui.xml +++ b/mousepad/mousepad-window-ui.xml @@ -76,6 +76,7 @@ + diff --git a/mousepad/mousepad-window.c b/mousepad/mousepad-window.c index adae7cd..dd2f06b 100644 --- a/mousepad/mousepad-window.c +++ b/mousepad/mousepad-window.c @@ -297,6 +297,8 @@ static void mousepad_window_action_move_line_up (GtkAction MousepadWindow *window); static void mousepad_window_action_move_line_down (GtkAction *action, MousepadWindow *window); +static void mousepad_window_action_delete_line (GtkAction *action, + MousepadWindow *window); static void mousepad_window_action_duplicate (GtkAction *action, MousepadWindow *window); static void mousepad_window_action_increase_indent (GtkAction *action, @@ -411,7 +413,7 @@ static const GtkActionEntry action_entries[] = { "save-all", NULL, N_("Save A_ll"), NULL, N_("Save all document in this window"), G_CALLBACK (mousepad_window_action_save_all), }, { "revert", GTK_STOCK_REVERT_TO_SAVED, N_("Re_vert"), NULL, N_("Revert to the saved version of the file"), G_CALLBACK (mousepad_window_action_revert), }, { "print", GTK_STOCK_PRINT, N_("_Print..."), "P", N_("Print the current document"), G_CALLBACK (mousepad_window_action_print), }, - { "detach", NULL, N_("_Detach Tab"), "D", N_("Move the current document to a new window"), G_CALLBACK (mousepad_window_action_detach), }, + { "detach", NULL, N_("_Detach Tab"), NULL, N_("Move the current document to a new window"), G_CALLBACK (mousepad_window_action_detach), }, { "close", GTK_STOCK_CLOSE, N_("Close _Tab"), "W", N_("Close the current document"), G_CALLBACK (mousepad_window_action_close), }, { "close-window", GTK_STOCK_QUIT, N_("_Close Window"), "Q", N_("Close this window"), G_CALLBACK (mousepad_window_action_close_window), }, @@ -440,6 +442,7 @@ static const GtkActionEntry action_entries[] = { "line-up", NULL, N_("Line _Up"), NULL, N_("Move the selection one line up"), G_CALLBACK (mousepad_window_action_move_line_up), }, { "line-down", NULL, N_("Line _Down"), NULL, N_("Move the selection one line down"), G_CALLBACK (mousepad_window_action_move_line_down), }, { "duplicate", NULL, N_("Dup_licate Line / Selection"), NULL, N_("Duplicate the current line or selection"), G_CALLBACK (mousepad_window_action_duplicate), }, + { "delete-line", NULL, N_("D_elete Line / Selection"), "d", N_("Delete the current line or selection"), G_CALLBACK (mousepad_window_action_delete_line), }, { "increase-indent", GTK_STOCK_INDENT, N_("_Increase Indent"), NULL, N_("Increase the indentation of the selection or current line"), G_CALLBACK (mousepad_window_action_increase_indent), }, { "decrease-indent", GTK_STOCK_UNINDENT, N_("_Decrease Indent"), NULL, N_("Decrease the indentation of the selection or current line"), G_CALLBACK (mousepad_window_action_decrease_indent), }, { "preferences", GTK_STOCK_PREFERENCES, N_("Preferences"), NULL, N_("Show the preferences dialog"), G_CALLBACK (mousepad_window_action_preferences), }, @@ -4654,6 +4657,17 @@ mousepad_window_action_move_line_down (GtkAction *action, } +static void +mousepad_window_action_delete_line (GtkAction *action, + MousepadWindow *window) +{ + g_return_if_fail (MOUSEPAD_IS_WINDOW (window)); + g_return_if_fail (MOUSEPAD_IS_DOCUMENT (window->active)); + + /* duplicate */ + mousepad_view_delete (window->active->textview); +} + static void mousepad_window_action_duplicate (GtkAction *action, -- 2.7.4