[Goodies-commits] r1787 - xfce4-notes-plugin/trunk/panel-plugin

Mike Massonnet mmassonnet at xfce.org
Mon Jul 24 21:57:13 CEST 2006


Author: mmassonnet
Date: 2006-07-24 19:57:11 +0000 (Mon, 24 Jul 2006)
New Revision: 1787

Modified:
   xfce4-notes-plugin/trunk/panel-plugin/notes.c
   xfce4-notes-plugin/trunk/panel-plugin/notes.h
Log:
 * Save on timeout (use the event "changed" from GtkTextBuffer (from 
   GtkTextView)
 * Modified default configuration:
   * Always on top
   * Not show in the takslist
   * Not show in the pager



Modified: xfce4-notes-plugin/trunk/panel-plugin/notes.c
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/notes.c	2006-07-24 19:54:50 UTC (rev 1786)
+++ xfce4-notes-plugin/trunk/panel-plugin/notes.c	2006-07-24 19:57:11 UTC (rev 1787)
@@ -30,15 +30,11 @@
 #include <libxfce4panel/xfce-panel-plugin.h>
 #include <libxfce4panel/xfce-panel-convenience.h>
 
+#include "note.h"
 #include "notes.h"
 
 #define PLUGIN_NAME "xfce4-notes-plugin"
 
-static void     notes_construct (XfcePanelPlugin *);
-static void     notes_free_data (XfcePanelPlugin *, NotesPlugin *);
-static void     notes_save (XfcePanelPlugin *, NotesPlugin *);
-static void     notes_configure (XfcePanelPlugin *, NotesPlugin *);
-static gboolean notes_set_size (XfcePanelPlugin *, int size, NotesPlugin *);
 
 /* Panel Plugin Interface */
 
@@ -50,6 +46,9 @@
 static void 
 notes_free_data (XfcePanelPlugin *plugin, NotesPlugin *notes)
 {
+    if (notes->timeout_id > 0)
+        g_source_remove (notes->timeout_id);
+
     notes_save (plugin, notes);
 
     DBG ("Free data: %s", PLUGIN_NAME);
@@ -65,7 +64,7 @@
     GtkTextBuffer *buffer;
     GtkTextIter start, end;
     gchar *text;
-    
+
     DBG ("Save: %s", PLUGIN_NAME);
 
     if (!(file = xfce_panel_plugin_save_location (plugin, TRUE)))
@@ -97,6 +96,14 @@
       }
 }
 
+gboolean
+save_on_timeout (NotesPlugin *notes)
+{
+    notes_save (notes->plugin, notes);
+
+    return FALSE;
+}
+
 static void
 notes_configure (XfcePanelPlugin *plugin, NotesPlugin *notes)
 {
@@ -121,6 +128,7 @@
     return TRUE;
 }
 
+
 /* create widgets and connect to signals */ 
 
 static void 
@@ -159,3 +167,92 @@
                       G_CALLBACK (notes_configure), notes);
 }
 
+NotesPlugin *
+notes_new (XfcePanelPlugin *plugin)
+{
+    NotesPlugin *notes;
+    GtkTextBuffer *buffer;
+
+    DBG ("New Notes Plugin");
+
+    notes = g_new0 (NotesPlugin, 1);
+    
+    notes->plugin = plugin;
+    notes->timeout_id = 0;
+    
+    notes->button = xfce_create_panel_toggle_button ();
+    gtk_widget_show (notes->button);
+
+    notes->icon = gtk_image_new ();
+    gtk_widget_show (notes->icon);
+    gtk_container_add (GTK_CONTAINER (notes->button), notes->icon);
+
+    notes->tooltips = gtk_tooltips_new ();
+    gtk_tooltips_set_tip (GTK_TOOLTIPS (notes->tooltips), notes->button, 
+                          _("Notes\nClick this button to show/hide your notes"),
+                          NULL);
+
+    notes->note = note_new (plugin);
+
+    g_signal_connect (notes->note->close_button, "clicked", 
+                      G_CALLBACK (on_note_close), notes->button);
+
+    g_signal_connect (notes->note->text, "key-press-event", 
+                      G_CALLBACK (on_note_key_press), notes);
+
+    buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (notes->note->text));
+    g_signal_connect (buffer, "changed", G_CALLBACK (on_note_changed), notes);
+
+    return notes;
+}
+
+static void
+notes_button_toggled (XfcePanelPlugin *plugin, NotesPlugin *notes)
+{
+    /* Show/hide the note */
+    if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (notes->button)))
+      {
+        gtk_window_move (GTK_WINDOW (notes->note->window), notes->note->x, 
+                                     notes->note->y);
+
+        gtk_widget_show (notes->note->window);
+
+        gtk_window_set_keep_above (GTK_WINDOW (notes->note->window), FALSE);
+        gtk_window_stick (GTK_WINDOW (notes->note->window));
+      }
+    else
+      {
+        gtk_window_get_position (GTK_WINDOW (notes->note->window), 
+                                 &notes->note->x, &notes->note->y);
+
+        gtk_widget_hide (notes->note->window);
+      }
+}
+
+static void
+on_note_close (GtkWidget *widget, GtkToggleButton *panel_button)
+{
+    gtk_toggle_button_set_active (panel_button, FALSE);
+}
+
+static gboolean
+on_note_key_press (GtkWidget *widget, GdkEventKey *event, NotesPlugin *notes)
+{
+    if (event->type == GDK_KEY_PRESS && event->keyval == GDK_Escape)
+        on_note_close (widget, GTK_TOGGLE_BUTTON (notes->button));
+
+    return FALSE;
+}
+
+static void
+on_note_changed (GtkWidget *widget, NotesPlugin *notes)
+{
+    if (notes->timeout_id > 0)
+      {
+        g_source_remove (notes->timeout_id);
+        notes->timeout_id = 0;
+      }
+
+    notes->timeout_id = g_timeout_add (5000, (GSourceFunc) save_on_timeout, 
+                                       notes);
+}

Modified: xfce4-notes-plugin/trunk/panel-plugin/notes.h
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/notes.h	2006-07-24 19:54:50 UTC (rev 1786)
+++ xfce4-notes-plugin/trunk/panel-plugin/notes.h	2006-07-24 19:57:11 UTC (rev 1787)
@@ -22,8 +22,6 @@
 
 #include <gdk/gdkkeysyms.h>
 
-#include "note.h"
-
 typedef struct
 {
     XfcePanelPlugin *plugin;
@@ -34,88 +32,27 @@
 
     Note *note;
 
+    /* Stored state */
     gboolean show;
+    gboolean task_switcher;
+    gboolean always_on_top;
+    gboolean stick;
+
+    guint timeout_id;
 }
 NotesPlugin;
 
+static void     notes_construct (XfcePanelPlugin *);
+static void     notes_free_data (XfcePanelPlugin *, NotesPlugin *);
+static void     notes_save (XfcePanelPlugin *, NotesPlugin *);
+gboolean        save_on_timeout (NotesPlugin *);
+static void     notes_configure (XfcePanelPlugin *, NotesPlugin *);
+static gboolean notes_set_size (XfcePanelPlugin *, int size, NotesPlugin *);
 NotesPlugin *   notes_new (XfcePanelPlugin *);
 static void     notes_button_toggled (XfcePanelPlugin *, NotesPlugin *);
 static void     on_note_close (GtkWidget *, GtkToggleButton *);
-static gboolean on_note_key_press (GtkWidget *, GdkEventKey *, 
-                                   GtkToggleButton *);
+static gboolean on_note_key_press (GtkWidget *, GdkEventKey *, NotesPlugin *);
+static void     on_note_changed (GtkWidget *widget, NotesPlugin *notes);
 
-NotesPlugin *
-notes_new (XfcePanelPlugin *plugin)
-{
-    NotesPlugin *notes;
-
-    DBG ("New Notes Plugin");
-
-    notes = g_new0 (NotesPlugin, 1);
-    
-    notes->plugin = plugin;
-    
-    notes->button = xfce_create_panel_toggle_button ();
-    gtk_widget_show (notes->button);
-
-    notes->icon = gtk_image_new ();
-    gtk_widget_show (notes->icon);
-    gtk_container_add (GTK_CONTAINER (notes->button), notes->icon);
-
-    notes->tooltips = gtk_tooltips_new ();
-    gtk_tooltips_set_tip (GTK_TOOLTIPS (notes->tooltips), notes->button, 
-                          _("Notes\nClick this button to show/hide your notes"),
-                          NULL);
-
-    notes->note = note_new (plugin);
-
-    g_signal_connect (notes->note->close_button, "clicked", 
-                      G_CALLBACK (on_note_close), notes->button);
-
-    g_signal_connect (notes->note->text, "key-press-event", 
-                      G_CALLBACK (on_note_key_press), notes->button);
-
-    return notes;
-}
-
-static void
-notes_button_toggled (XfcePanelPlugin *plugin, NotesPlugin *notes)
-{
-    /* Show/hide the note */
-    if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (notes->button)))
-      {
-        gtk_widget_show (notes->note->window);
-
-        gtk_window_set_keep_above (GTK_WINDOW (notes->note->window), TRUE);
-        gtk_window_stick (GTK_WINDOW (notes->note->window));
-        gtk_window_move (GTK_WINDOW (notes->note->window), notes->note->x, 
-                                     notes->note->y);
-      }
-    else
-      {
-        gtk_window_get_position (GTK_WINDOW (notes->note->window), 
-                                 &notes->note->x, &notes->note->y);
-
-        gtk_widget_hide (notes->note->window);
-      }
-}
-
-static void
-on_note_close (GtkWidget *widget, GtkToggleButton *panel_button)
-{
-    gtk_toggle_button_set_active (panel_button, FALSE);
-}
-
-static gboolean
-on_note_key_press (GtkWidget *widget, GdkEventKey *event, 
-                   GtkToggleButton *panel_button)
-{
-    if (event->type == GDK_KEY_PRESS)
-        if (event->keyval == GDK_Escape)
-            on_note_close (widget, panel_button);
-
-    return FALSE;
-}
-
 #endif
 




More information about the Goodies-commits mailing list