[Goodies-commits] r5690 - in xfce4-notes-plugin/trunk: . panel-plugin

Mike Massonnet mmassonnet at xfce.org
Sat Oct 18 21:10:23 CEST 2008


Author: mmassonnet
Date: 2008-10-18 19:10:23 +0000 (Sat, 18 Oct 2008)
New Revision: 5690

Added:
   xfce4-notes-plugin/trunk/panel-plugin/settings-dialog.c
   xfce4-notes-plugin/trunk/panel-plugin/settings-dialog.h
Removed:
   xfce4-notes-plugin/trunk/panel-plugin/notes-options.c
   xfce4-notes-plugin/trunk/panel-plugin/notes-options.h
   xfce4-notes-plugin/trunk/panel-plugin/notes-properties-dialog.c
   xfce4-notes-plugin/trunk/panel-plugin/notes-properties-dialog.h
Modified:
   xfce4-notes-plugin/trunk/ChangeLog
   xfce4-notes-plugin/trunk/panel-plugin/Makefile.am
   xfce4-notes-plugin/trunk/panel-plugin/notes.c
   xfce4-notes-plugin/trunk/panel-plugin/notes.h
   xfce4-notes-plugin/trunk/panel-plugin/panel-plugin.c
Log:
Simple undo/redo feature

Modified: xfce4-notes-plugin/trunk/ChangeLog
===================================================================
--- xfce4-notes-plugin/trunk/ChangeLog	2008-10-18 18:54:38 UTC (rev 5689)
+++ xfce4-notes-plugin/trunk/ChangeLog	2008-10-18 19:10:23 UTC (rev 5690)
@@ -1,5 +1,19 @@
-2008-05-11  Mike Massonnet <mmassonnet at xfce.org>
+2008-10-18  Mike Massonnet <mmassonnet at xfce.org>
 
+Simple undo/redo feature
+	* panel-plugin/notes-options.[ch]:
+	  - Deleted obsolete options dialog.
+	* panel-plugin/notes-properties.[ch],
+	  panel-plugin/settings-dialog.[ch],
+	  panel-plugin/panel-plugin.c,
+	  panel-plugin/Makefile.am:
+	  - Renamed notes-properties to settings-dialog.
+	* panel-plugin/notes.[ch]:
+	  - Added simple undo/redo feature.  Ctrl+Z cycles through one level
+	  of history from undo to redo.
+
+2008-10-11  Mike Massonnet <mmassonnet at xfce.org>
+
 Clean up \o/
 	* Use only one xfconf channel.
 	* By default hide notes windows from taskbar.

Modified: xfce4-notes-plugin/trunk/panel-plugin/Makefile.am
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/Makefile.am	2008-10-18 18:54:38 UTC (rev 5689)
+++ xfce4-notes-plugin/trunk/panel-plugin/Makefile.am	2008-10-18 19:10:23 UTC (rev 5690)
@@ -19,8 +19,8 @@
 xfce4_notes_plugin_SOURCES =						\
 	defines.h							\
 	panel-plugin.c							\
-	notes-properties-dialog.c					\
-	notes-properties-dialog.h					\
+	settings-dialog.c						\
+	settings-dialog.h						\
 	notes.c								\
 	notes.h
 

Deleted: xfce4-notes-plugin/trunk/panel-plugin/notes-options.c

Deleted: xfce4-notes-plugin/trunk/panel-plugin/notes-options.h

Deleted: xfce4-notes-plugin/trunk/panel-plugin/notes-properties-dialog.c

Deleted: xfce4-notes-plugin/trunk/panel-plugin/notes-properties-dialog.h

Modified: xfce4-notes-plugin/trunk/panel-plugin/notes.c
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/notes.c	2008-10-18 18:54:38 UTC (rev 5689)
+++ xfce4-notes-plugin/trunk/panel-plugin/notes.c	2008-10-18 19:10:23 UTC (rev 5690)
@@ -100,6 +100,10 @@
 
 static void             notes_window_delete_note        (NotesWindow *notes_window);
 
+static void             notes_window_undo               (NotesWindow *notes_window);
+
+
+
 static void             notes_note_set_font             (NotesNote *notes_note,
                                                          const gchar *name);
 static inline void      notes_note_sort_names           (NotesNote *notes_note);
@@ -110,13 +114,18 @@
 
 static gint             notes_note_rename               (NotesNote *notes_note,
                                                          const gchar *name);
-static void             notes_note_buffer_changed       (NotesNote *notes_note);
-
 static gboolean         notes_note_key_pressed          (NotesNote *notes_note,
                                                          GdkEventKey *event);
+static void             notes_note_buffer_changed       (NotesNote *notes_note);
 
+static void             notes_note_destroy_undo_timeout (NotesNote *notes_note);
 
+static gboolean         notes_note_undo_snapshot        (NotesNote *notes_note);
 
+static void             notes_note_undo                 (NotesNote *notes_note);
+
+
+
 /**
  * NotesWindow
  */
@@ -742,6 +751,7 @@
   GtkWidget *mi_delete_note    = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
   GtkWidget *mi_rename_note    = gtk_menu_item_new_with_mnemonic (_("R_ename..."));
   /*GtkWidget *mi_lock_note      = gtk_menu_item_new_with_mnemonic (_("_Lock note"));*/
+  GtkWidget *mi_undo           = gtk_image_menu_item_new_from_stock (GTK_STOCK_UNDO, NULL);
 
   gtk_widget_set_sensitive (mi_window, FALSE);
   gtk_menu_shell_append (GTK_MENU_SHELL (notes_window->menu), mi_window);
@@ -760,6 +770,7 @@
   gtk_menu_shell_append (GTK_MENU_SHELL (notes_window->menu), mi_delete_note);
   gtk_menu_shell_append (GTK_MENU_SHELL (notes_window->menu), mi_rename_note);
   /*gtk_menu_shell_append (GTK_MENU_SHELL (notes_window->menu), mi_lock_note);*/
+  gtk_menu_shell_append (GTK_MENU_SHELL (notes_window->menu), mi_undo);
 
   /* Accel group */
   gtk_menu_set_accel_group (GTK_MENU (notes_window->menu),
@@ -800,6 +811,12 @@
                               GDK_F2,
                               0,
                               GTK_ACCEL_MASK);
+  gtk_widget_add_accelerator (mi_undo,
+                              "activate",
+                              notes_window->accel_group,
+                              GDK_z,
+                              GDK_CONTROL_MASK,
+                              GTK_ACCEL_MASK);
 
   /* Signals */
   g_signal_connect_swapped (notes_window->menu,
@@ -834,6 +851,10 @@
                             "activate",
                             G_CALLBACK (notes_window_rename_note_dialog),
                             notes_window);
+  g_signal_connect_swapped (mi_undo,
+                            "activate",
+                            G_CALLBACK (notes_window_undo),
+                            notes_window);
 
   /* Show the stuff */
   gtk_widget_show_all (notes_window->menu);
@@ -1473,8 +1494,15 @@
     notes_note_new (notes_window, NULL);
 }
 
+static void
+notes_window_undo (NotesWindow *notes_window)
+{
+  NotesNote *current_note = notes_window_get_current_note (notes_window);
+  notes_note_undo (current_note);
+}
 
 
+
 /**
  * NotesNote
  */
@@ -1666,6 +1694,10 @@
       TRACE ("Load data for notes `%s':\n%s", notes_note->name, contents);
       gtk_text_buffer_set_text (buffer, contents, -1);
       gtk_text_view_set_buffer (GTK_TEXT_VIEW (notes_note->text_view), buffer);
+
+      /* Set initial undo/redo text */
+      notes_note->undo_text = g_strdup (contents);
+      notes_note->redo_text = g_strdup (contents);
     }
 
   g_free (contents);
@@ -1898,11 +1930,67 @@
 static void
 notes_note_buffer_changed (NotesNote *notes_note)
 {
+  /* Save timeout */
   if (notes_note->timeout > 0)
     {
       g_source_remove (notes_note->timeout);
       notes_note->timeout = 0;
     }
   notes_note->timeout = g_timeout_add (60000, (GSourceFunc)notes_note_save_data, notes_note);
+
+  /* Undo timeout */
+  if (notes_note->undo_timeout > 0)
+    g_source_remove (notes_note->undo_timeout);
+  notes_note->undo_timeout = g_timeout_add_full (G_PRIORITY_DEFAULT, 1230,
+                                                 (GSourceFunc)notes_note_undo_snapshot, notes_note,
+                                                 (GDestroyNotify)notes_note_destroy_undo_timeout);
 }
 
+static void
+notes_note_destroy_undo_timeout (NotesNote *notes_note)
+{
+  notes_note->undo_timeout = 0;
+}
+
+static gboolean
+notes_note_undo_snapshot (NotesNote *notes_note)
+{
+  GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (notes_note->text_view));
+  GtkTextIter start, end;
+
+  gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (buffer), &start, 0);
+  gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (buffer), &end, -1);
+
+  g_free (notes_note->undo_text);
+  notes_note->undo_text = notes_note->redo_text;
+  notes_note->redo_text = gtk_text_buffer_get_text (GTK_TEXT_BUFFER (buffer),
+                                                    &start, &end, FALSE);
+
+  return FALSE;
+}
+
+static void
+notes_note_undo (NotesNote *notes_note)
+{
+  GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (notes_note->text_view));
+  gchar *tmp;
+
+  if (notes_note->undo_timeout > 0)
+    {
+      /* Take the snapshot by hand */
+      g_source_remove (notes_note->undo_timeout);
+      notes_note_undo_snapshot (notes_note);
+    }
+
+  if (notes_note->undo_text == NULL)
+    notes_note->undo_text = g_strdup ("");
+
+  gtk_text_buffer_set_text (GTK_TEXT_BUFFER (buffer), notes_note->undo_text, -1);
+
+  tmp = notes_note->undo_text;
+  notes_note->undo_text = notes_note->redo_text;
+  notes_note->redo_text = tmp;
+
+  g_source_remove (notes_note->undo_timeout);
+}
+

Modified: xfce4-notes-plugin/trunk/panel-plugin/notes.h
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/notes.h	2008-10-18 18:54:38 UTC (rev 5689)
+++ xfce4-notes-plugin/trunk/panel-plugin/notes.h	2008-10-18 19:10:23 UTC (rev 5690)
@@ -122,6 +122,10 @@
   GtkWidget            *scrolled_window;
   GtkWidget            *text_view;
 
+  guint                 undo_timeout;
+  gchar                *undo_text;
+  gchar                *redo_text;
+
 #ifdef HAVE_THUNAR_VFS
   gboolean				delete;
 #endif

Modified: xfce4-notes-plugin/trunk/panel-plugin/panel-plugin.c
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/panel-plugin.c	2008-10-18 18:54:38 UTC (rev 5689)
+++ xfce4-notes-plugin/trunk/panel-plugin/panel-plugin.c	2008-10-18 19:10:23 UTC (rev 5690)
@@ -26,7 +26,7 @@
 #include "defines.h"
 #include "notes.h"
 #ifdef HAVE_XFCONF
-#include "notes-properties-dialog.h"
+#include "settings-dialog.h"
 #endif
 #include "xfce4-popup-notes.h"
 

Copied: xfce4-notes-plugin/trunk/panel-plugin/settings-dialog.c (from rev 5568, xfce4-notes-plugin/trunk/panel-plugin/notes-properties-dialog.c)
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/settings-dialog.c	                        (rev 0)
+++ xfce4-notes-plugin/trunk/panel-plugin/settings-dialog.c	2008-10-18 19:10:23 UTC (rev 5690)
@@ -0,0 +1,183 @@
+/*
+ *  Notes - panel plugin for Xfce Desktop Environment
+ *  Copyright (C) 2008  Mike Massonnet <mmassonnet at gmail.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef HAVE_XFCONF
+#include <xfconf/xfconf.h>
+
+#include "defines.h"
+#include "settings-dialog.h"
+#include "notes.h"
+
+
+
+static XfconfChannel *xfconf_channel = NULL;
+
+static void
+cb_channel_panel_plugin_toggled (GtkToggleButton *button,
+                                 const gchar *property)
+{
+  xfconf_channel_set_bool (xfconf_channel, property, gtk_toggle_button_get_active (button));
+}
+
+static void
+cb_channel_new_window_toggled (GtkToggleButton *button,
+                               const gchar *property)
+{
+  xfconf_channel_set_bool (xfconf_channel, property, gtk_toggle_button_get_active (button));
+}
+
+static void
+cb_channel_new_window_fontset (GtkFontButton *fontbutton,
+                               const gchar *property)
+{
+  xfconf_channel_set_string (xfconf_channel, property, gtk_font_button_get_font_name (fontbutton));
+}
+
+static void
+cb_channel_new_window_scale (GtkRange *range,
+                             const gchar *property)
+{
+  xfconf_channel_set_int (xfconf_channel, property, (gint32)gtk_range_get_value (range));
+}
+
+GtkWidget *
+prop_dialog_new (NotesPlugin *notes_plugin)
+{
+  GtkWidget *dialog, *frame, *box, *hbox, *button, *scale, *label;
+  GtkWidget *fontbutton, *size_box;
+
+  /* Configuration channel */
+  if (NULL == xfconf_channel)
+    xfconf_channel = notes_plugin->xfconf_channel;
+
+  /* Dialog */
+  dialog =
+    xfce_titled_dialog_new_with_buttons (_("Xfce 4 Notes Plugin"),
+                                         GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (notes_plugin->panel_plugin))),
+                                         GTK_DIALOG_DESTROY_WITH_PARENT|GTK_DIALOG_NO_SEPARATOR,
+                                         GTK_STOCK_HELP, GTK_RESPONSE_HELP,
+                                         GTK_STOCK_CLOSE, GTK_RESPONSE_OK,
+                                         NULL);
+  gtk_window_set_icon_name (GTK_WINDOW (dialog), "xfce4-notes-plugin");
+  gtk_window_set_keep_above (GTK_WINDOW (dialog), TRUE);
+  gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
+  gtk_window_set_default_size (GTK_WINDOW (dialog), 375, -1);
+  gtk_window_stick (GTK_WINDOW (dialog));
+
+  /* === Default settings === */
+  box = gtk_vbox_new (TRUE, BORDER);
+  frame = xfce_create_framebox_with_content (_("Default settings"), box);
+  gtk_container_set_border_width (GTK_CONTAINER (frame), BORDER);
+  gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), frame);
+
+  /* Hide from taskbar */
+  button = gtk_check_button_new_with_label (_("Hide windows from taskbar"));
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
+                                xfconf_channel_get_bool (xfconf_channel, "/general/hide_windows_from_taskbar", FALSE));
+  gtk_container_add (GTK_CONTAINER (box), button);
+  g_signal_connect (button, "toggled", G_CALLBACK (cb_channel_panel_plugin_toggled), "/general/hide_windows_from_taskbar");
+
+  /* Hide arrow button */
+  button = gtk_check_button_new_with_label (_("Hide arrow button"));
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
+                                xfconf_channel_get_bool (xfconf_channel, "/general/hide_arrow_button", FALSE));
+  gtk_container_add (GTK_CONTAINER (box), button);
+  g_signal_connect (button, "toggled", G_CALLBACK (cb_channel_panel_plugin_toggled), "/general/hide_arrow_button");
+
+  /* === New window settings === */
+  box = gtk_vbox_new (TRUE, BORDER);
+  frame = xfce_create_framebox_with_content (_("New window settings"), box);
+  gtk_container_set_border_width (GTK_CONTAINER (frame), BORDER);
+  gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), frame);
+
+  /* Always on top */
+  button = gtk_check_button_new_with_label (_("Always on top"));
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
+                                xfconf_channel_get_bool (xfconf_channel, "/new_window/always_on_top", FALSE));
+  gtk_box_pack_start (GTK_BOX (box), button, TRUE, FALSE, 0);
+  g_signal_connect (button, "toggled", G_CALLBACK (cb_channel_new_window_toggled), "/new_window/always_on_top");
+
+  /* Sticky window */
+  button = gtk_check_button_new_with_label (_("Sticky window"));
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
+                                xfconf_channel_get_bool (xfconf_channel, "/new_window/sticky", TRUE));
+  gtk_box_pack_start (GTK_BOX (box), button, TRUE, FALSE, 0);
+  g_signal_connect (button, "toggled", G_CALLBACK (cb_channel_new_window_toggled), "/new_window/sticky");
+
+  /* Resize grip */
+  button = gtk_check_button_new_with_label (_("Resize grip"));
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
+                                xfconf_channel_get_bool (xfconf_channel, "/new_window/resize_grip", FALSE));
+  gtk_box_pack_start (GTK_BOX (box), button, TRUE, FALSE, 0);
+  g_signal_connect (button, "toggled", G_CALLBACK (cb_channel_new_window_toggled), "/new_window/resize_grip");
+
+  /* Font */
+  hbox = gtk_hbox_new (FALSE, BORDER);
+  gtk_box_pack_start (GTK_BOX (box), hbox, TRUE, FALSE, 0);
+
+  button = gtk_check_button_new_with_label (_("Font"));
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
+                                xfconf_channel_get_bool (xfconf_channel, "/new_window/use_font", FALSE));
+  gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
+  g_signal_connect (button, "toggled", G_CALLBACK (cb_channel_new_window_toggled), "/new_window/use_font");
+
+  gchar *description = xfconf_channel_get_string (xfconf_channel, "/new_window/font_description", "Sans 10");
+  fontbutton = gtk_font_button_new_with_font (description);
+  g_free (description);
+  gtk_box_pack_start (GTK_BOX (hbox), fontbutton, TRUE, TRUE, 0);
+  g_signal_connect (fontbutton, "font-set", G_CALLBACK (cb_channel_new_window_fontset), "/new_window/font_description");
+
+  /* Size */
+  hbox = gtk_hbox_new (FALSE, BORDER);
+  gtk_box_pack_start (GTK_BOX (box), hbox, TRUE, FALSE, 0);
+
+  label = gtk_label_new (_("Size"));
+  gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+
+  size_box = gtk_hbox_new (FALSE, 0);
+  gtk_box_pack_start (GTK_BOX (hbox), size_box, TRUE, TRUE, 0);
+
+  scale = gtk_hscale_new_with_range (20, 600, 10);
+  gtk_range_set_value (GTK_RANGE (scale),
+                       (gdouble)xfconf_channel_get_int (xfconf_channel, "/new_window/width", 375));
+  gtk_scale_set_value_pos (GTK_SCALE (scale), GTK_POS_RIGHT);
+  gtk_box_pack_start (GTK_BOX (size_box), scale, TRUE, TRUE, 0);
+  g_signal_connect (scale, "value-changed", G_CALLBACK (cb_channel_new_window_scale), "/new_window/width");
+
+  label = gtk_label_new ("×");
+  gtk_box_pack_start (GTK_BOX (size_box), label, FALSE, FALSE, 0);
+
+  scale = gtk_hscale_new_with_range (20, 600, 10);
+  gtk_range_set_value (GTK_RANGE (scale),
+                       (gdouble)xfconf_channel_get_int (xfconf_channel, "/new_window/height", 430));
+  gtk_scale_set_value_pos (GTK_SCALE (scale), GTK_POS_LEFT);
+  gtk_box_pack_start (GTK_BOX (size_box), scale, TRUE, TRUE, 0);
+  g_signal_connect (scale, "value-changed", G_CALLBACK (cb_channel_new_window_scale), "/new_window/height");
+
+  /* === Ending === */
+  gtk_widget_show_all (GTK_DIALOG (dialog)->vbox);
+
+  return dialog;
+}
+#endif
+


Property changes on: xfce4-notes-plugin/trunk/panel-plugin/settings-dialog.c
___________________________________________________________________
Name: svn:mergeinfo
   + 

Copied: xfce4-notes-plugin/trunk/panel-plugin/settings-dialog.h (from rev 5565, xfce4-notes-plugin/trunk/panel-plugin/notes-properties-dialog.h)
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/settings-dialog.h	                        (rev 0)
+++ xfce4-notes-plugin/trunk/panel-plugin/settings-dialog.h	2008-10-18 19:10:23 UTC (rev 5690)
@@ -0,0 +1,27 @@
+/*  $Id$
+ *
+ *  Copyright (c) 2006 Mike Massonnet <mmassonnet at gmail.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef NOTES_PROPERTIES_DIALOG_H
+#define NOTES_PROPERTIES_DIALOG_H
+
+#include <gtk/gtk.h>
+
+GtkWidget *             prop_dialog_new           ();
+
+#endif


Property changes on: xfce4-notes-plugin/trunk/panel-plugin/settings-dialog.h
___________________________________________________________________
Name: svn:mergeinfo
   + 




More information about the Goodies-commits mailing list