From ffaffb0dc0a9975d28702a877b92c79b4943f9b2 Mon Sep 17 00:00:00 2001 From: Andre Miranda Date: Tue, 16 Sep 2014 22:45:51 -0300 Subject: [PATCH] Add option delete line --- mousepad/mousepad-view.c | 36 ++++++++++++++++++++++++++++++++++-- mousepad/mousepad-view.h | 2 ++ mousepad/mousepad-window-ui.xml | 1 + mousepad/mousepad-window.c | 36 ++++++++++++++++++++++++++---------- 4 files changed, 63 insertions(+), 12 deletions(-) diff --git a/mousepad/mousepad-view.c b/mousepad/mousepad-view.c index 8c3eba6..77b9933 100644 --- a/mousepad/mousepad-view.c +++ b/mousepad/mousepad-view.c @@ -1090,7 +1090,7 @@ mousepad_view_selection_draw (MousepadView *view, /* calculate line coordinates */ gtk_text_view_buffer_to_window_coords(textview,GTK_TEXT_WINDOW_TEXT, rect.x,rect.y, &line_x,&line_y); - + /* draw a line in front of the iter */ gdk_draw_line (GDK_DRAWABLE (window), gtk_widget_get_style(GTK_WIDGET (view))->base_gc[GTK_STATE_SELECTED], @@ -2541,7 +2541,7 @@ mousepad_view_duplicate (MousepadView *view) insert_eol = !gtk_text_iter_forward_line (&end_iter); } - /* insert a dupplicate of the text before the iter */ + /* insert a duplicate of the text before the iter */ gtk_text_buffer_insert_range (buffer, &start_iter, &start_iter, &end_iter); /* insert a new line if needed */ @@ -2555,6 +2555,38 @@ mousepad_view_duplicate (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_indent (MousepadView *view, gint type) { diff --git a/mousepad/mousepad-view.h b/mousepad/mousepad-view.h index 14c5fce..b65fc28 100644 --- a/mousepad/mousepad-view.h +++ b/mousepad/mousepad-view.h @@ -88,6 +88,8 @@ void mousepad_view_move_selection (MousepadView *view void mousepad_view_duplicate (MousepadView *view); +void mousepad_view_delete (MousepadView *view); + void mousepad_view_indent (MousepadView *view, gint type); 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 ae55465..e73cccb 100644 --- a/mousepad/mousepad-window.c +++ b/mousepad/mousepad-window.c @@ -299,6 +299,8 @@ static void mousepad_window_action_move_line_down (GtkAction MousepadWindow *window); static void mousepad_window_action_duplicate (GtkAction *action, MousepadWindow *window); +static void mousepad_window_action_delete_line (GtkAction *action, + MousepadWindow *window); static void mousepad_window_action_increase_indent (GtkAction *action, MousepadWindow *window); static void mousepad_window_action_decrease_indent (GtkAction *action, @@ -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"), NULL, 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), }, @@ -574,7 +577,7 @@ mousepad_window_update_tabs (MousepadWindow *window, { gint n_pages; gboolean always_show; - + always_show = MOUSEPAD_SETTING_GET_BOOLEAN (ALWAYS_SHOW_TABS); n_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (window->notebook)); @@ -743,7 +746,7 @@ mousepad_window_create_style_schemes_menu (MousepadWindow *window) GtkWidget *menu, *item; MousepadActionGroup *group; static const gchar *menu_path = "/main-menu/view-menu/color-scheme-menu"; - + /* create the color schemes menu and add it to the placeholder */ group = MOUSEPAD_ACTION_GROUP (window->action_group); menu = mousepad_action_group_create_style_scheme_menu (group); @@ -751,7 +754,7 @@ mousepad_window_create_style_schemes_menu (MousepadWindow *window) gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), menu); gtk_widget_show_all (menu); gtk_widget_show (item); - + /* watch for activations of the style schemes actions */ g_signal_connect_object (window->action_group, "notify::active-style-scheme", @@ -1350,7 +1353,7 @@ mousepad_window_save_geometry_timer (gpointer user_data) if (remember_size) { gint width, height; - + /* determine the current width/height of the window... */ gtk_window_get_size (GTK_WINDOW (window), &width, &height); @@ -1362,7 +1365,7 @@ mousepad_window_save_geometry_timer (gpointer user_data) if (remember_position) { gint left, top; - + /* determine the current left/top position of the window */ gtk_window_get_position (GTK_WINDOW (window), &left, &top); @@ -1762,7 +1765,7 @@ mousepad_window_provide_languages_menu (MousepadWindow *window, MousepadStatusbar *statusbar) { MousepadActionGroup *group; - + group = MOUSEPAD_ACTION_GROUP (window->action_group); return mousepad_action_group_create_language_menu (group); } @@ -2067,7 +2070,7 @@ mousepad_window_notebook_button_press_event (GtkNotebook *notebook, gtk_notebook_get_current_page (notebook)); if (ev_widget == NULL || ev_widget == nb_child || gtk_widget_is_ancestor (ev_widget, nb_child)) return FALSE; - + /* check if the event window is the notebook event window (not a tab) */ if (mousepad_window_is_position_on_tab_bar (notebook, event)) { @@ -2404,11 +2407,11 @@ mousepad_window_menu_templates_fill (MousepadWindow *window, if (! files_added) { gchar *msg; - + msg = g_strdup_printf (_("No template files found in\n'%s'"), path); item = gtk_menu_item_new_with_label (msg); g_free (msg); - + gtk_widget_set_sensitive (item, FALSE); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); gtk_widget_show (item); @@ -4661,13 +4664,26 @@ mousepad_window_action_duplicate (GtkAction *action, g_return_if_fail (MOUSEPAD_IS_WINDOW (window)); g_return_if_fail (MOUSEPAD_IS_DOCUMENT (window->active)); - /* dupplicate */ + /* duplicate */ mousepad_view_duplicate (window->active->textview); } 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)); + + /* dupplicate */ + mousepad_view_delete (window->active->textview); +} + + + +static void mousepad_window_action_increase_indent (GtkAction *action, MousepadWindow *window) { -- 2.1.0