[gnome-latex: 31/205] copy, cut, paste, delete and select all



commit 1e82be4881dd21405e5e4dd312d86ba1d2699e78
Author: Sébastien Wilmet <sebastien wilmet gmail com>
Date:   Tue Aug 25 21:34:13 2009 +0200

    copy, cut, paste, delete and select all

 TODO            |   2 +-
 src/callbacks.c | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++------
 src/callbacks.h |   5 +++
 src/main.c      |  10 +++++
 src/ui.xml      |  12 ++++++
 5 files changed, 130 insertions(+), 12 deletions(-)
---
diff --git a/TODO b/TODO
index e8bc9af..69e1888 100644
--- a/TODO
+++ b/TODO
@@ -8,7 +8,7 @@ Mon Aug 24, 2009 to Mon Aug 31, 2009
        x button replace sensitivity
        x same width for entries
 
-[-] copy/cut/paste
+[x] copy, cut, paste, delete and select all
 
 [-] printing
 
diff --git a/src/callbacks.c b/src/callbacks.c
index bd75096..cb4305e 100644
--- a/src/callbacks.c
+++ b/src/callbacks.c
@@ -195,6 +195,67 @@ cb_redo (void)
        set_undo_redo_sensitivity ();
 }
 
+void
+cb_cut (void)
+{
+       if (latexila.active_doc == NULL)
+               return;
+
+       GtkClipboard *clipboard = gtk_widget_get_clipboard (
+                       latexila.active_doc->source_view, GDK_SELECTION_CLIPBOARD);
+       gtk_text_buffer_cut_clipboard (
+                       GTK_TEXT_BUFFER (latexila.active_doc->source_buffer),
+                       clipboard, TRUE);
+}
+
+void
+cb_copy (void)
+{
+       if (latexila.active_doc == NULL)
+               return;
+
+       GtkClipboard *clipboard = gtk_widget_get_clipboard (
+                       latexila.active_doc->source_view, GDK_SELECTION_CLIPBOARD);
+       gtk_text_buffer_copy_clipboard (
+                       GTK_TEXT_BUFFER (latexila.active_doc->source_buffer), clipboard);
+}
+
+void
+cb_paste (void)
+{
+       if (latexila.active_doc == NULL)
+               return;
+
+       GtkClipboard *clipboard = gtk_widget_get_clipboard (
+                       latexila.active_doc->source_view, GDK_SELECTION_CLIPBOARD);
+       gtk_text_buffer_paste_clipboard (
+                       GTK_TEXT_BUFFER (latexila.active_doc->source_buffer),
+                       clipboard, NULL, TRUE);
+}
+
+void
+cb_delete (void)
+{
+       if (latexila.active_doc == NULL)
+               return;
+
+       GtkTextBuffer *buffer = GTK_TEXT_BUFFER (latexila.active_doc->source_buffer);
+       gtk_text_buffer_delete_selection (buffer, TRUE, TRUE);
+}
+
+void
+cb_select_all (void)
+{
+       if (latexila.active_doc == NULL)
+               return;
+
+       GtkTextBuffer *buffer = GTK_TEXT_BUFFER (latexila.active_doc->source_buffer);
+       GtkTextIter start, end;
+       gtk_text_buffer_get_start_iter (buffer, &start);
+       gtk_text_buffer_get_end_iter (buffer, &end);
+       gtk_text_buffer_select_range (buffer, &start, &end);
+}
+
 void
 cb_find (void)
 {
@@ -228,6 +289,9 @@ cb_find (void)
 
        gtk_widget_show_all (content_area);
 
+       guint context_id = gtk_statusbar_get_context_id (latexila.statusbar,
+                       "searching");
+
        while (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK)
        {
                const gchar *what = gtk_entry_get_text (GTK_ENTRY (entry));
@@ -239,9 +303,17 @@ cb_find (void)
                                GTK_TOGGLE_BUTTON (backward_search));
 
                GtkTextIter match_start, match_end;
-               find_next_match (what, flags, backward, &match_start, &match_end);
+               if (! find_next_match (what, flags, backward, &match_start, &match_end))
+               {
+                       // print a message in the statusbar
+                       gtk_statusbar_pop (latexila.statusbar, context_id);
+                       gtk_statusbar_push (latexila.statusbar, context_id,
+                                       _("Phrase not found"));
+               }
        }
 
+       gtk_statusbar_pop (latexila.statusbar, context_id);
+
        gtk_widget_destroy (dialog);
 }
 
@@ -302,6 +374,9 @@ cb_replace (void)
         */
        gboolean backward = FALSE;
 
+       guint context_id = gtk_statusbar_get_context_id (latexila.statusbar,
+                       "searching");
+
        gboolean stop = FALSE;
        gboolean match_found = FALSE;
        GtkTextIter match_start, match_end, iter;
@@ -329,6 +404,7 @@ cb_replace (void)
 
                                // begin at the start of the buffer
                                gtk_text_buffer_get_start_iter (buffer, &iter);
+                               gint i = 0;
                                while (gtk_source_iter_forward_search (&iter, what, flags,
                                                        &match_start, &match_end, NULL))
                                {
@@ -338,9 +414,25 @@ cb_replace (void)
 
                                        // iter points to the end of the inserted text
                                        iter = match_start;
+
+                                       i++;
                                }
 
                                gtk_text_buffer_end_user_action (buffer);
+
+                               // print a message in the statusbar
+                               gchar *msg;
+                               if (i == 0)
+                                       msg = g_strdup (_("Phrase not found"));
+                               else if (i == 1)
+                                       msg = g_strdup (_("Found and replaced one occurence"));
+                               else
+                                       msg = g_strdup_printf (_("Found and replaced %d occurences"), i);
+
+                               gtk_statusbar_pop (latexila.statusbar, context_id);
+                               gtk_statusbar_push (latexila.statusbar, context_id, msg);
+                               g_free (msg);
+
                                break;
 
                        /* replace */
@@ -362,6 +454,12 @@ cb_replace (void)
                        case GTK_RESPONSE_OK:
                                match_found = find_next_match (what, flags, backward,
                                                &match_start, &match_end);
+                               if (! match_found)
+                               {
+                                       gtk_statusbar_pop (latexila.statusbar, context_id);
+                                       gtk_statusbar_push (latexila.statusbar, context_id,
+                                                       _("Phrase not found"));
+                               }
                                break;
 
                        default:
@@ -370,6 +468,7 @@ cb_replace (void)
                }
        }
 
+       gtk_statusbar_pop (latexila.statusbar, context_id);
        gtk_widget_destroy (dialog);
 }
 
@@ -891,7 +990,7 @@ run_compilation (gchar *title, gchar *command)
        gtk_statusbar_push (latexila.statusbar, context_id,
                        _("Compilation in progress. Please wait..."));
 
-       // without do that, the message in the statusbar does not appear
+       // without that, the message in the statusbar does not appear
        while (gtk_events_pending ())
                gtk_main_iteration ();
 
@@ -1036,7 +1135,7 @@ convert_document (gchar *title, gchar *doc_extension, gchar *command)
        gtk_statusbar_push (latexila.statusbar, context_id,
                        _("Converting in progress. Please wait..."));
 
-       // without do that, the message in the statusbar does not appear
+       // without that, the message in the statusbar does not appear
        while (gtk_events_pending ())
                gtk_main_iteration ();
 
@@ -1191,12 +1290,8 @@ find_next_match (const gchar *what, GtkSourceSearchFlags flags,
                        }
                        
                        // match not found
-                       // TODO message in the statusbar
                        else
-                       {
-                               print_info ("\"%s\" not found.", what);
                                return FALSE;
-                       }
                }
        }
 
@@ -1226,12 +1321,8 @@ find_next_match (const gchar *what, GtkSourceSearchFlags flags,
                        }
                        
                        // match not found
-                       // TODO message dialog
                        else
-                       {
-                               print_info ("\"%s\" not found.", what);
                                return FALSE;
-                       }
                }
        }
 }
diff --git a/src/callbacks.h b/src/callbacks.h
index b3fe5c8..44f8731 100644
--- a/src/callbacks.h
+++ b/src/callbacks.h
@@ -10,6 +10,11 @@ void cb_close_tab (GtkWidget *widget, GtkWidget *child);
 void cb_quit (void);
 void cb_undo (void);
 void cb_redo (void);
+void cb_cut (void);
+void cb_copy (void);
+void cb_paste (void);
+void cb_delete (void);
+void cb_select_all (void);
 void cb_find (void);
 void cb_replace (void);
 void cb_latex (void);
diff --git a/src/main.c b/src/main.c
index a159be5..39a8898 100644
--- a/src/main.c
+++ b/src/main.c
@@ -116,6 +116,16 @@ main (int argc, char *argv[])
                        _("Undo the last action"), G_CALLBACK (cb_undo)},
                {"EditRedo", GTK_STOCK_REDO, _("Redo"), "<Shift><Control>Z",
                        _("Redo the last undone action"), G_CALLBACK (cb_redo)},
+               {"EditCut", GTK_STOCK_CUT, _("Cut"), "<Control>X",
+                       _("Cut the selection"), G_CALLBACK (cb_cut)},
+               {"EditCopy", GTK_STOCK_COPY, _("Copy"), "<Control>C",
+                       _("Copy the selection"), G_CALLBACK (cb_copy)},
+               {"EditPaste", GTK_STOCK_PASTE, _("Paste"), "<Control>V",
+                       _("Paste the clipboard"), G_CALLBACK (cb_paste)},
+               {"EditDelete", GTK_STOCK_DELETE, _("Delete"), NULL,
+                       _("Delete the selected text"), G_CALLBACK (cb_delete)},
+               {"EditSelectAll", GTK_STOCK_SELECT_ALL, _("Select All"), "<Control>A",
+                       _("Select the entire document"), G_CALLBACK (cb_select_all)},
 
                {"View", NULL, _("View"), NULL, NULL, NULL},
 
diff --git a/src/ui.xml b/src/ui.xml
index f9ce158..0049634 100644
--- a/src/ui.xml
+++ b/src/ui.xml
@@ -20,6 +20,13 @@ In the code, GtkUIManager is used to construct them.
     <menu name="Edit" action="Edit">
       <menuitem name="Undo" action="EditUndo" />
       <menuitem name="Redo" action="EditRedo" />
+      <separator />
+      <menuitem action="EditCut" />
+      <menuitem action="EditCopy" />
+      <menuitem action="EditPaste" />
+      <menuitem action="EditDelete" />
+      <separator />
+      <menuitem action="EditSelectAll" />
     </menu>
 
     <menu action="View">
@@ -52,9 +59,14 @@ In the code, GtkUIManager is used to construct them.
     <toolitem action="FileNew" />
     <toolitem action="FileOpen" />
     <toolitem action="FileSave" />
+    <separator />
     <toolitem action="EditUndo" />
     <toolitem action="EditRedo" />
     <separator />
+    <toolitem action="EditCut" />
+    <toolitem action="EditCopy" />
+    <toolitem action="EditPaste" />
+    <separator />
     <toolitem action="SearchFind" />
     <toolitem action="SearchReplace" />
     <separator />


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]