[Goodies-commits] r7458 - in xfce4-notes-plugin/trunk: . panel-plugin
Mike Massonnet
mmassonnet at xfce.org
Thu Jun 4 18:01:58 CEST 2009
Author: mmassonnet
Date: 2009-06-04 16:01:58 +0000 (Thu, 04 Jun 2009)
New Revision: 7458
Modified:
xfce4-notes-plugin/trunk/ChangeLog
xfce4-notes-plugin/trunk/NEWS
xfce4-notes-plugin/trunk/configure.in.in
xfce4-notes-plugin/trunk/panel-plugin/application.vala
xfce4-notes-plugin/trunk/panel-plugin/note.vala
xfce4-notes-plugin/trunk/panel-plugin/window.vala
Log:
Load/save notes contents and windows configuration
Modified: xfce4-notes-plugin/trunk/ChangeLog
===================================================================
--- xfce4-notes-plugin/trunk/ChangeLog 2009-06-04 14:13:28 UTC (rev 7457)
+++ xfce4-notes-plugin/trunk/ChangeLog 2009-06-04 16:01:58 UTC (rev 7458)
@@ -1,3 +1,19 @@
+2009-06-04 Mike Massonnet <mmassonnet at xfce.org>
+
+Load/save notes contents and windows configuration
+ * panel-plugin/application.vala:
+ - Load/save windows configuration from/to config_file.
+ - Add destructor to save notes and windows configuration.
+ * panel-plugin/window.vala:
+ - New public methods get/set_current_page() as needed by the window
+ configuration to restore the "LastPage" on the next run.
+ - New public method save_notes() called by the Xnp.Application
+ destructor to save remaining dirty notes.
+ * panel-plugin/note.vala:
+ - New property dirty, when set to true it initiates a timeout to
+ send the save-data signal and destroys the timeout on false.
+ - On buffer_changed_cb only set dirty to true.
+
2009-05-31 Mike Massonnet <mmassonnet at xfce.org>
Load/Save notes from files
@@ -163,7 +179,7 @@
- Remove existing GLib.Sources on destruction
* panel-plugin/window.vala,
panel-plugin/note.vala:
- Vala vala vala vala vala
+ - Vala vala vala vala vala
2009-03-13 Mike Massonnet <mmassonnet at xfce.org>
Modified: xfce4-notes-plugin/trunk/NEWS
===================================================================
--- xfce4-notes-plugin/trunk/NEWS 2009-06-04 14:13:28 UTC (rev 7457)
+++ xfce4-notes-plugin/trunk/NEWS 2009-06-04 16:01:58 UTC (rev 7458)
@@ -1,8 +1,10 @@
-VERSION 1.6.5
+VERSION 1.7.0
- New window menu layout with navigation for notes
-- Dropped show-tabs option for the window in favor of a navigation bar
+- Dropped show-tabs option from the window in favor of a navigation bar
+- ? Made font option apply per note instead of every notes from the window
- New vala objects Window and Note, based on the existing code inside notes.c
+- New vala object Application to build window with notes and save on-disk
VERSION 1.6.4
Modified: xfce4-notes-plugin/trunk/configure.in.in
===================================================================
--- xfce4-notes-plugin/trunk/configure.in.in 2009-06-04 14:13:28 UTC (rev 7457)
+++ xfce4-notes-plugin/trunk/configure.in.in 2009-06-04 16:01:58 UTC (rev 7458)
@@ -7,8 +7,8 @@
dnl
m4_define([xfce4_notes_plugin_version_major], [1])
-m4_define([xfce4_notes_plugin_version_minor], [6])
-m4_define([xfce4_notes_plugin_version_micro], [5])
+m4_define([xfce4_notes_plugin_version_minor], [7])
+m4_define([xfce4_notes_plugin_version_micro], [0])
m4_define([xfce4_notes_plugin_version_nano], [])
m4_define([xfce4_notes_plugin_version_build], [r at REVISION@])
m4_define([xfce4_notes_plugin_version_tag], [svn]) # Leave empty for releases
@@ -84,7 +84,7 @@
fi
dnl check for valac
-valac_minimum_version=0.5.7
+valac_minimum_version=0.7.1
if test "x$USE_MAINTAINER_MODE" = "xyes" ; then
AC_CHECK_PROG([has_valac], [valac], [yes], [no])
AC_PATH_PROG([VALAC], [valac], [valac])
Modified: xfce4-notes-plugin/trunk/panel-plugin/application.vala
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/application.vala 2009-06-04 14:13:28 UTC (rev 7457)
+++ xfce4-notes-plugin/trunk/panel-plugin/application.vala 2009-06-04 16:01:58 UTC (rev 7458)
@@ -25,29 +25,36 @@
private SList<Xnp.Window> window_list;
private string notes_path;
+ private string config_file;
construct {
- this.notes_path = "%s/notes".printf (GLib.Environment.get_user_data_dir ());
+ notes_path = "%s/notes".printf (GLib.Environment.get_user_data_dir ());
+ config_file = "%s/xfce4/panel/xfce4-notes-plugin.rc".printf (GLib.Environment.get_user_config_dir ());
}
public Application () {
string name;
bool found = false;
try {
- var dir = Dir.open (this.notes_path, 0);
+ var dir = Dir.open (notes_path, 0);
while ((name = dir.read_name ()) != null) {
create_window (name);
found = true;
}
}
catch (Error e) {
- GLib.DirUtils.create_with_parents (this.notes_path, 0700);
+ GLib.DirUtils.create_with_parents (notes_path, 0700);
}
if (found == false) {
create_window (null);
}
}
+ ~Application () {
+ save_windows_configuration ();
+ save_notes ();
+ }
+
/*
* Window management
*/
@@ -86,13 +93,10 @@
}
/* Insert initial notes */
- if (name != null) {
- this.load_window_data (window);
- }
- else {
+ if (name == null) {
var note = window.insert_note ();
- string window_path = "%s/%s".printf (this.notes_path, window.name);
+ string window_path = "%s/%s".printf (notes_path, window.name);
GLib.DirUtils.create_with_parents (window_path, 0700);
try {
string note_path = "%s/%s".printf (window_path, note.name);
@@ -100,7 +104,12 @@
}
catch (FileError e) {
}
+
+ window.show ();
}
+ else {
+ this.load_window_data (window);
+ }
/* Connect signals */
window.action += (win, action) => {
@@ -115,20 +124,10 @@
}
};
window.save_data += (win, note) => {
- string path = "%s/%s/%s".printf (this.notes_path, win.name, note.name);
- try {
- Gtk.TextIter start, end;
- var buffer = note.text_view.get_buffer ();
- buffer.get_bounds (out start, out end);
- string contents = buffer.get_text (start, end, true);
- GLib.FileUtils.set_contents (path, contents, -1);
- }
- catch (FileError e) {
- warning ("%s", e.message);
- }
+ save_note (win, note);
};
window.note_inserted += (win, note) => {
- string path = "%s/%s/%s".printf (this.notes_path, win.name, note.name);
+ string path = "%s/%s/%s".printf (notes_path, win.name, note.name);
try {
GLib.FileUtils.set_contents (path, "", -1);
}
@@ -136,26 +135,25 @@
}
};
window.note_deleted += (win, note) => {
- string path = "%s/%s/%s".printf (this.notes_path, win.name, note.name);
+ string path = "%s/%s/%s".printf (notes_path, win.name, note.name);
GLib.FileUtils.unlink (path);
};
window.note_renamed += (win, note, old_name) => {
- string old_path = "%s/%s/%s".printf (this.notes_path, win.name, old_name);
- string new_path = "%s/%s/%s".printf (this.notes_path, win.name, note.name);
+ string old_path = "%s/%s/%s".printf (notes_path, win.name, old_name);
+ string new_path = "%s/%s/%s".printf (notes_path, win.name, note.name);
GLib.FileUtils.rename (old_path, new_path);
};
-
- window.show ();
}
/**
* load_window_data:
*
- * Loads existing notes inside the window.
+ * Load existing notes and configuration inside the window.
*/
private void load_window_data (Xnp.Window window) {
+ /* Load notes */
string name;
- string path = "%s/%s".printf (this.notes_path, window.name);
+ string path = "%s/%s".printf (notes_path, window.name);
try {
var dir = GLib.Dir.open (path, 0);
while ((name = dir.read_name ()) != null) {
@@ -175,17 +173,112 @@
}
catch (FileError e) {
}
+
+ /* Load configuration */
+ var keyfile = new GLib.KeyFile ();
+ try {
+ keyfile.load_from_file (config_file, GLib.KeyFileFlags.NONE);
+ int winx = keyfile.get_integer (window.name, "PosX");
+ int winy = keyfile.get_integer (window.name, "PosY");
+ int width = keyfile.get_integer (window.name, "Width");
+ int height = keyfile.get_integer (window.name, "Height");
+ int last_page = keyfile.get_integer (window.name, "LastTab");
+ bool above = keyfile.get_boolean (window.name, "Above");
+ bool sticky = keyfile.get_boolean (window.name, "Sticky");
+ double opacity = 1 - keyfile.get_integer (window.name, "Transparency") / 100;
+ bool visible = keyfile.get_boolean (window.name, "Visible");
+
+ window.move (winx, winy);
+ window.resize (width, height);
+ window.set_current_page (last_page);
+ window.above = above;
+ window.sticky = sticky;
+ window.opacity = opacity;
+ if (visible)
+ window.show ();
+ }
+ catch (Error e) {
+ warning ("%s: %s", config_file, e.message);
+ window.show ();
+ }
}
/**
+ * save_windows_configuration:
+ *
+ * Save window configuration inside rc file.
+ * TODO save font descriptions
+ */
+ public void save_windows_configuration () {
+ var keyfile = new GLib.KeyFile ();
+ try {
+ foreach (var win in this.window_list) {
+ int winx, winy;
+ win.get_position (out winx, out winy);
+ int width = win.allocation.width;
+ // TODO if shaded
+ int height = win.allocation.height;
+ int last_page = win.get_current_page ();
+ int transparency = (int)((1 - win.opacity) * 100);
+ bool visible = (bool)(win.get_flags () & Gtk.WidgetFlags.VISIBLE);
+
+ keyfile.set_integer (win.name, "PosX", winx);
+ keyfile.set_integer (win.name, "PosY", winy);
+ // TODO if !visible
+ keyfile.set_integer (win.name, "Width", visible ? width : win.default_width);
+ keyfile.set_integer (win.name, "Height", visible ? height : win.default_height);
+ keyfile.set_integer (win.name, "LastTab", last_page);
+ keyfile.set_boolean (win.name, "Above", win.above);
+ keyfile.set_boolean (win.name, "Sticky", win.sticky);
+ keyfile.set_double (win.name, "Transparency", transparency);
+ keyfile.set_boolean (win.name, "Visible", visible);
+ }
+ string contents = keyfile.to_data (null);
+ GLib.FileUtils.set_contents (config_file, contents);
+ }
+ catch (FileError e) {
+ }
+ }
+
+ /**
+ * save_notes:
+ *
+ * Save the contents of every existing notes.
+ */
+ private void save_notes () {
+ foreach (var win in this.window_list) {
+ win.save_notes ();
+ }
+ }
+
+ /**
+ * save_note:
+ *
+ * Save the contents of the given note.
+ */
+ private void save_note (Xnp.Window window, Xnp.Note note) {
+ string path = "%s/%s/%s".printf (notes_path, window.name, note.name);
+ try {
+ Gtk.TextIter start, end;
+ var buffer = note.text_view.get_buffer ();
+ buffer.get_bounds (out start, out end);
+ string contents = buffer.get_text (start, end, true);
+ GLib.FileUtils.set_contents (path, contents, -1);
+ }
+ catch (FileError e) {
+ warning ("%s", e.message);
+ }
+ }
+
+ /**
* rename_window:
*
* Renames the window name.
*/
private void rename_window (Xnp.Window window) {
var dialog = new Gtk.Dialog.with_buttons ("Rename group", window,
- Gtk.DialogFlags.DESTROY_WITH_PARENT|Gtk.DialogFlags.NO_SEPARATOR,
- Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OK, Gtk.ResponseType.OK);
+ Gtk.DialogFlags.DESTROY_WITH_PARENT|Gtk.DialogFlags.NO_SEPARATOR,
+ Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OK, Gtk.ResponseType.OK);
dialog.set_default_response (Gtk.ResponseType.OK);
dialog.resizable = false;
dialog.icon_name = Gtk.STOCK_EDIT;
@@ -209,8 +302,8 @@
error_dialog.destroy ();
}
else {
- string old_path = "%s/%s".printf (this.notes_path, window.name);
- string new_path = "%s/%s".printf (this.notes_path, name);
+ string old_path = "%s/%s".printf (notes_path, window.name);
+ string new_path = "%s/%s".printf (notes_path, name);
window.name = name;
GLib.FileUtils.rename (old_path, new_path);
}
@@ -232,7 +325,7 @@
return;
string name;
- string path = "%s/%s".printf (this.notes_path, window.name);
+ string path = "%s/%s".printf (notes_path, window.name);
try {
var dir = GLib.Dir.open (path, 0);
while ((name = dir.read_name ()) != null) {
Modified: xfce4-notes-plugin/trunk/panel-plugin/note.vala
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/note.vala 2009-06-04 14:13:28 UTC (rev 7457)
+++ xfce4-notes-plugin/trunk/panel-plugin/note.vala 2009-06-04 16:01:58 UTC (rev 7458)
@@ -24,11 +24,38 @@
public class Note : Gtk.Bin {
- public new string name { get; set; }
- private uint save_timeout;
public Gtk.ScrolledWindow scrolled_window;
public Xnp.HypertextView text_view;
+ public new string name { get; set; }
+ private uint save_timeout;
+ private bool _dirty;
+ public bool dirty {
+ default = false;
+ get {
+ return this._dirty;
+ }
+ set {
+ this._dirty = value;
+ if (value == false) {
+ if (this.save_timeout > 0) {
+ Source.remove (this.save_timeout);
+ this.save_timeout = 0;
+ }
+ }
+ else {
+ if (this.save_timeout > 0)
+ Source.remove (this.save_timeout);
+ this.save_timeout = Timeout.add_seconds (60, () => {
+ save_data ();
+ this.save_timeout = 0;
+ this._dirty = false;
+ return false;
+ });
+ }
+ }
+ }
+
public signal void save_data ();
public Note (string name) {
@@ -53,8 +80,10 @@
}
~Note () {
- if (this.save_timeout != 0)
+ if (this.save_timeout > 0) {
Source.remove (this.save_timeout);
+ this.save_timeout = 0;
+ }
}
public override void size_request (ref Gtk.Requisition requisition) {
@@ -87,14 +116,7 @@
* changes and send the save-data signal.
*/
private void buffer_changed_cb () {
- if (this.save_timeout > 0) {
- Source.remove (this.save_timeout);
- }
- this.save_timeout = Timeout.add_seconds (60, () => {
- save_data ();
- this.save_timeout = 0;
- return false;
- });
+ this.dirty = true;
}
}
Modified: xfce4-notes-plugin/trunk/panel-plugin/window.vala
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/window.vala 2009-06-04 14:13:28 UTC (rev 7457)
+++ xfce4-notes-plugin/trunk/panel-plugin/window.vala 2009-06-04 16:01:58 UTC (rev 7458)
@@ -618,7 +618,6 @@
}
if (x + requisition.width > Gdk.Screen.width ()) {
/* Adjust menu left */
- debug ("%d %d", Gdk.Screen.width (), x);
x = x - menu.requisition.width + content_box.allocation.y;
}
}
@@ -786,6 +785,24 @@
this.window_list = list;
}
+ /**
+ * get_current_page:
+ *
+ * Get the current page in the notebook.
+ */
+ public int get_current_page () {
+ return this.notebook.get_current_page ();
+ }
+
+ /**
+ * set_current_page:
+ *
+ * Set the current page in the notebook.
+ */
+ public void set_current_page (int page) {
+ this.notebook.set_current_page (page);
+ }
+
/*
* Window management
*/
@@ -991,6 +1008,22 @@
return false;
}
+ /**
+ * save_notes:
+ *
+ * Send the save-data signal on every dirty note.
+ */
+ public void save_notes () {
+ int n_pages = this.notebook.get_n_pages ();
+ for (int p = 0; p < n_pages; p++) {
+ var note = (Xnp.Note)this.notebook.get_nth_page (p);
+ if (note.dirty) {
+ note.dirty = false;
+ save_data (note);
+ }
+ }
+ }
+
/*
static int main (string[] args) {
Gtk.init (ref args);
More information about the Goodies-commits
mailing list