make undo levels user-configuarable
authorPaul Mangan <paul@claws-mail.org>
Sun, 16 Dec 2001 13:34:13 +0000 (13:34 +0000)
committerPaul Mangan <paul@claws-mail.org>
Sun, 16 Dec 2001 13:34:13 +0000 (13:34 +0000)
ChangeLog.claws
src/prefs_common.c
src/prefs_common.h
src/undo.c

index fb9879e..aa1ff43 100644 (file)
        * po/de.po
                updated by Jens Oberender
 
+       * src/prefs_common.[ch]
        * src/undo.c
-               increased undo_levels from 10 to 50
+               number of undo levels is user configurable
+               (squeeze it into the release in the dying
+               moments)        
 
 2001-12-15 [melvin]
 
index 63df944..8602504 100644 (file)
@@ -110,6 +110,9 @@ static struct Compose {
        GtkWidget *checkbtn_forward_account_autosel;
        GtkWidget *checkbtn_reedit_account_autosel;
 
+       GtkWidget *spinbtn_undolevels;
+       GtkObject *spinbtn_undolevels_adj;
+
        GtkWidget *spinbtn_linewrap;
        GtkObject *spinbtn_linewrap_adj;
        GtkWidget *checkbtn_wrapquote;
@@ -320,8 +323,12 @@ static PrefParam param[] = {
         &compose.checkbtn_autoextedit,
         prefs_set_data_from_toggle, prefs_set_toggle},
 
+       {"undolevels", "50", &prefs_common.undolevels, P_INT,
+        &compose.spinbtn_undolevels,
+        prefs_set_data_from_spinbtn, prefs_set_spinbtn},
+
        {"linewrap_length", "74", &prefs_common.linewrap_len, P_INT,
-        &compose.spinbtn_linewrap,
+       &compose.spinbtn_linewrap,
         prefs_set_data_from_spinbtn, prefs_set_spinbtn},
        {"linewrap_quotation", "FALSE", &prefs_common.linewrap_quote, P_BOOL,
         &compose.checkbtn_wrapquote,
@@ -1359,7 +1366,12 @@ static void prefs_compose_create(void)
        GtkWidget *checkbtn_forward_account_autosel;
        GtkWidget *checkbtn_reedit_account_autosel;
 
-        GtkWidget *vbox_linewrap;
+       GtkWidget *hbox_undolevels;
+       GtkWidget *label_undolevels;
+       GtkObject *spinbtn_undolevels_adj;
+       GtkWidget *spinbtn_undolevels;
+
+       GtkWidget *vbox_linewrap;
 
        GtkWidget *hbox3;
        GtkWidget *hbox4;
@@ -1500,6 +1512,24 @@ static void prefs_compose_create(void)
        PACK_CHECK_BUTTON (vbox1, checkbtn_block_cursor,
                          _("Block cursor"));
 
+       PACK_VSPACER (vbox2, vbox3, VSPACING_NARROW_2);
+
+       hbox_undolevels = gtk_hbox_new (FALSE, 8);
+       gtk_widget_show (hbox3);
+       gtk_box_pack_start (GTK_BOX (vbox1), hbox_undolevels, FALSE, FALSE, 0);
+
+       label_undolevels = gtk_label_new (_("Undo levels"));
+       gtk_widget_show (label_undolevels);
+       gtk_box_pack_start (GTK_BOX (hbox_undolevels), label_undolevels, FALSE, FALSE, 0);
+
+       spinbtn_undolevels_adj = gtk_adjustment_new (50, 0, 100, 1, 10, 10);
+       spinbtn_undolevels = gtk_spin_button_new
+               (GTK_ADJUSTMENT (spinbtn_undolevels_adj), 1, 0);
+       gtk_widget_show (spinbtn_undolevels);
+       gtk_box_pack_start (GTK_BOX (hbox_undolevels), spinbtn_undolevels, FALSE, FALSE, 0);
+       gtk_widget_set_usize (spinbtn_undolevels, 64, -1);
+       gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_undolevels), TRUE);
+
 #if USE_PSPELL
        /* spell checker defaults */                       
        PACK_FRAME(vbox1, frame_spell, _("Global spelling checker settings"));
@@ -1568,6 +1598,9 @@ static void prefs_compose_create(void)
        compose.checkbtn_forward_account_autosel = checkbtn_forward_account_autosel;
        compose.checkbtn_reedit_account_autosel  = checkbtn_reedit_account_autosel;
 
+       compose.spinbtn_undolevels     = spinbtn_undolevels;
+       compose.spinbtn_undolevels_adj = spinbtn_undolevels_adj;
+
        compose.spinbtn_linewrap     = spinbtn_linewrap;
        compose.spinbtn_linewrap_adj = spinbtn_linewrap_adj;
        compose.checkbtn_wrapquote   = checkbtn_wrapquote;
index 0787c69..19aac4a 100644 (file)
@@ -71,6 +71,7 @@ struct _PrefsCommon
        /* Compose */
        gboolean auto_sig;
        gchar *sig_sep;
+       gint undolevels;
        gint linewrap_len;
        gboolean linewrap_quote;
        gboolean linewrap_at_send;
index 0269b2d..d236628 100644 (file)
@@ -26,6 +26,7 @@
 #include "undo.h"
 #include "utils.h"
 #include "gtkstext.h"
+#include "prefs_common.h"
 
 typedef struct _UndoInfo UndoInfo;
 
@@ -154,14 +155,13 @@ static void undo_check_size(UndoMain *undostruct)
 {
         gint n;
         UndoInfo *nth_undo;
-       gint undo_levels = 50;
 
-        if (undo_levels < 1)
+        if (prefs_common.undolevels < 1)
                 return;
 
         /* No need to check for the redo list size since the undo
            list gets freed on any call to compose_undo_add */
-        if (g_list_length(undostruct->undo) >= undo_levels && undo_levels > 0) {
+        if (g_list_length(undostruct->undo) >= prefs_common.undolevels && prefs_common.undolevels > 0) {
                nth_undo = g_list_nth_data(undostruct->undo, g_list_length(undostruct->undo) - 1);
                undostruct->undo = g_list_remove(undostruct->undo, nth_undo);
                g_free (nth_undo->text);
@@ -502,10 +502,13 @@ void undo_insert_text_cb(GtkEditable *editable, gchar *new_text,
 {
        guchar *text_to_insert;
 
-       text_to_insert = g_strndup(new_text, new_text_length);
-       undo_add(text_to_insert, *position, (*position + new_text_length), 
-                UNDO_ACTION_INSERT, undostruct);
-       g_free (text_to_insert);
+        if (prefs_common.undolevels > 0){
+               text_to_insert = g_strndup(new_text, new_text_length);
+
+               undo_add(text_to_insert, *position, (*position + new_text_length),
+                        UNDO_ACTION_INSERT, undostruct);
+               g_free (text_to_insert);
+       }
 }
 
 void undo_delete_text_cb(GtkEditable *editable, gint start_pos,
@@ -513,20 +516,23 @@ void undo_delete_text_cb(GtkEditable *editable, gint start_pos,
 {
         guchar *text_to_delete;
 
-        if (start_pos == end_pos )
-               return;
-               
-        text_to_delete = gtk_editable_get_chars(GTK_EDITABLE(editable), 
+        if (prefs_common.undolevels > 0){
+               if (start_pos == end_pos )
+                       return;
+
+               text_to_delete = gtk_editable_get_chars(GTK_EDITABLE(editable),
                                                start_pos, end_pos);
-       undo_add(text_to_delete, start_pos, end_pos, UNDO_ACTION_DELETE, undostruct);
-       g_free (text_to_delete);
+               undo_add(text_to_delete, start_pos, end_pos, UNDO_ACTION_DELETE, undostruct);
+               g_free (text_to_delete);
+       }
 }
 
 void undo_paste_clipboard_cb (GtkEditable *editable, UndoMain *undostruct) 
 {
        debug_print("befor Paste: %d\n", undostruct->paste);
-       if (undo_get_selection(editable, NULL, NULL)) 
-               undostruct->paste = TRUE;
+        if (prefs_common.undolevels > 0)
+               if (undo_get_selection(editable, NULL, NULL))
+                       undostruct->paste = TRUE;
        debug_print("after Paste: %d\n", undostruct->paste);
 }