SF.net SVN: geany: [2067] trunk

eht16 at users.sourceforge.net eht16 at xxxxx
Thu Nov 22 17:03:53 UTC 2007


Revision: 2067
          http://geany.svn.sourceforge.net/geany/?rev=2067&view=rev
Author:   eht16
Date:     2007-11-22 09:03:53 -0800 (Thu, 22 Nov 2007)

Log Message:
-----------
New plugin: Auto Save.

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/plugins/Makefile.am
    trunk/plugins/makefile.win32
    trunk/po/POTFILES.in

Added Paths:
-----------
    trunk/plugins/autosave.c

Property Changed:
----------------
    trunk/plugins/svndiff.c

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2007-11-21 18:54:31 UTC (rev 2066)
+++ trunk/ChangeLog	2007-11-22 17:03:53 UTC (rev 2067)
@@ -1,3 +1,9 @@
+2007-11-22  Enrico Tröger  <enrico(dot)troeger(at)uvena(dot)de>
+
+ * po/POTFILES.in, plugins/autosave.c, plugins/Makefile.am,
+   plugins/makefile.win32: New plugin: Auto Save.
+
+
 2007-11-21  Enrico Tröger  <enrico(dot)troeger(at)uvena(dot)de>
 
  * src/editor.c: Fix crash when trying to add a multiline comment in

Modified: trunk/plugins/Makefile.am
===================================================================
--- trunk/plugins/Makefile.am	2007-11-21 18:54:31 UTC (rev 2066)
+++ trunk/plugins/Makefile.am	2007-11-22 17:03:53 UTC (rev 2067)
@@ -12,6 +12,7 @@
 export_la_LDFLAGS        = -module -avoid-version
 svndiff_la_LDFLAGS       = -module -avoid-version
 vcdiff_la_LDFLAGS        = -module -avoid-version
+autosave_la_LDFLAGS      = -module -avoid-version
 filebrowser_la_LDFLAGS   = -module -avoid-version
 
 if PLUGINS
@@ -23,6 +24,7 @@
 	export.la \
 	svndiff.la \
 	vcdiff.la \
+	autosave.la \
 	filebrowser.la
 
 # Plugins not to be installed
@@ -35,6 +37,7 @@
 export_la_SOURCES        = export.c
 svndiff_la_SOURCES       = svndiff.c
 vcdiff_la_SOURCES        = vcdiff.c
+autosave_la_SOURCES      = autosave.c
 filebrowser_la_SOURCES   = filebrowser.c
 
 demoplugin_la_LIBADD    = $(GTK_LIBS)
@@ -42,7 +45,8 @@
 htmlchars_la_LIBADD     = $(GTK_LIBS)
 export_la_LIBADD        = $(GTK_LIBS)
 svndiff_la_LIBADD       = $(GTK_LIBS)
-vcdiff_la_LIBADD       = $(GTK_LIBS)
+vcdiff_la_LIBADD        = $(GTK_LIBS)
+autosave_la_LIBAD       = $(GTK_LIBS)
 filebrowser_la_LIBADD   = $(GTK_LIBS)
 
 endif # PLUGINS

Added: trunk/plugins/autosave.c
===================================================================
--- trunk/plugins/autosave.c	                        (rev 0)
+++ trunk/plugins/autosave.c	2007-11-22 17:03:53 UTC (rev 2067)
@@ -0,0 +1,202 @@
+/*
+ *      autosave.c - this file is part of Geany, a fast and lightweight IDE
+ *
+ *      Copyright 2007 Enrico Tröger <enrico.troeger at uvena.de>
+ *      Copyright 2007 Nick Treleaven <nick.treleaven at btinternet.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., 51 Franklin Street, Fifth Floor, Boston,
+ *      MA 02110-1301, USA.
+ *
+ * $Id$
+ */
+
+
+#include "geany.h"
+#include "support.h"
+#include "document.h"
+
+#include "plugindata.h"
+#include "pluginmacros.h"
+
+
+PluginFields	*plugin_fields;
+GeanyData		*geany_data;
+
+
+VERSION_CHECK(32)
+
+PLUGIN_INFO(_("Auto Save"), _("Save automatically all open files in a given time interval."),
+	VERSION, _("The Geany developer team"))
+
+
+static gint interval;
+static gboolean print_msg;
+static gboolean save_all;
+static guint src_id = G_MAXUINT;
+static gchar *config_file;
+
+
+gboolean auto_save(gpointer data)
+{
+	gint cur_idx = documents->get_cur_idx();
+	gint i, idx, max = gtk_notebook_get_n_pages(GTK_NOTEBOOK(app->notebook));
+	gint saved_files = 0;
+
+	if (save_all)
+	{
+		for (i = 0; i < max; i++)
+		{
+			idx = documents->get_n_idx(i);
+
+			// skip current file to save it lastly, skip files without name
+			if (idx != cur_idx && doc_list[idx].file_name != NULL)
+				if (documents->save_file(idx, FALSE))
+					saved_files++;
+		}
+	}
+	// finally save current file, do it after all other files to get correct window title and
+	// symbol list
+	if (doc_list[cur_idx].file_name != NULL)
+		if (documents->save_file(cur_idx, FALSE))
+			saved_files++;
+
+	if (saved_files > 0 && print_msg)
+		ui->set_statusbar(FALSE, _("Autosave: Saved %d files automatically."), saved_files);
+
+	return TRUE;
+}
+
+
+void set_timeout()
+{
+	if (src_id != G_MAXUINT)
+		g_source_remove(src_id);
+	src_id = g_timeout_add(interval * 1000, (GSourceFunc)auto_save, NULL);
+
+}
+
+
+void init(GeanyData *data)
+{
+	GKeyFile *config = g_key_file_new();
+	GError *error = NULL;
+	config_file = g_strconcat(app->configdir, G_DIR_SEPARATOR_S, "plugins", G_DIR_SEPARATOR_S,
+		"autosave", G_DIR_SEPARATOR_S, "autosave.conf", NULL);
+
+	g_key_file_load_from_file(config, config_file, G_KEY_FILE_NONE, NULL);
+	interval = g_key_file_get_integer(config, "autosave", "interval", &error);
+	if (error != NULL)
+	{
+		g_error_free(error);
+		interval = 300;
+	}
+	print_msg = g_key_file_get_boolean(config, "autosave", "print_messages", NULL);
+	save_all = g_key_file_get_boolean(config, "autosave", "save_all", NULL);
+
+	set_timeout();
+
+	g_key_file_free(config);
+}
+
+
+void configure(GtkWidget *parent)
+{
+	GtkWidget *dialog, *label, *spin, *vbox, *hbox, *checkbox, *radio1, *radio2;
+
+	dialog = gtk_dialog_new_with_buttons(_("Auto Save"),
+		GTK_WINDOW(parent), GTK_DIALOG_DESTROY_WITH_PARENT,
+		GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, NULL);
+	vbox = ui->dialog_vbox_new(GTK_DIALOG(dialog));
+	gtk_widget_set_name(dialog, "GeanyDialog");
+	gtk_box_set_spacing(GTK_BOX(vbox), 6);
+
+	label = gtk_label_new("Auto save interval:");
+	gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
+	gtk_container_add(GTK_CONTAINER(vbox), label);
+
+	spin = gtk_spin_button_new_with_range(1, 1800, 1);
+	gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin), interval);
+
+	label = gtk_label_new("seconds");
+
+	hbox = gtk_hbox_new(FALSE, 5);
+	gtk_box_pack_start(GTK_BOX(hbox), spin, TRUE, TRUE, 0);
+	gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
+
+	gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5);
+
+	checkbox = gtk_check_button_new_with_label(
+		_("Print status message if files have been automatcally saved"));
+	gtk_button_set_focus_on_click(GTK_BUTTON(checkbox), FALSE);
+	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox), print_msg);
+	gtk_box_pack_start(GTK_BOX(vbox), checkbox, FALSE, FALSE, 5);
+
+	radio1 = gtk_radio_button_new_with_label(NULL,
+		_("Save only current open file"));
+	gtk_button_set_focus_on_click(GTK_BUTTON(radio1), FALSE);
+	gtk_container_add(GTK_CONTAINER(vbox), radio1);
+
+	radio2 = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(radio1),
+		_("Save all open files"));
+	gtk_button_set_focus_on_click(GTK_BUTTON(radio2), FALSE);
+	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio2), save_all);
+	gtk_container_add(GTK_CONTAINER(vbox), radio2);
+
+	gtk_widget_show_all(vbox);
+
+	// run the dialog and check for the response code
+	if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
+	{
+		GKeyFile *config = g_key_file_new();
+		gchar *data;
+		gchar *config_dir = g_path_get_dirname(config_file);
+
+		interval = gtk_spin_button_get_value_as_int((GTK_SPIN_BUTTON(spin)));
+		print_msg = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbox));
+		save_all = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radio2));
+
+		g_key_file_load_from_file(config, config_file, G_KEY_FILE_NONE, NULL);
+
+		g_key_file_set_integer(config, "autosave", "interval", interval);
+		g_key_file_set_boolean(config, "autosave", "print_messages", print_msg);
+		g_key_file_set_boolean(config, "autosave", "save_all", save_all);
+
+		if (! g_file_test(config_dir, G_FILE_TEST_IS_DIR) && utils->mkdir(config_dir, TRUE) != 0)
+		{
+			dialogs->show_msgbox(GTK_MESSAGE_ERROR,
+				_("Plugin configuration directory could not be created."));
+		}
+		else
+		{
+			// write config to file
+			data = g_key_file_to_data(config, NULL, NULL);
+			utils->write_file(config_file, data);
+			g_free(data);
+		}
+
+		set_timeout(); // apply the changes
+
+		g_free(config_dir);
+		g_key_file_free(config);
+	}
+	gtk_widget_destroy(dialog);
+}
+
+
+void cleanup()
+{
+	g_source_remove(src_id);
+	g_free(config_file);
+}


Property changes on: trunk/plugins/autosave.c
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Modified: trunk/plugins/makefile.win32
===================================================================
--- trunk/plugins/makefile.win32	2007-11-21 18:54:31 UTC (rev 2066)
+++ trunk/plugins/makefile.win32	2007-11-22 17:03:53 UTC (rev 2067)
@@ -46,6 +46,8 @@
 		classbuilder.dll \
 		export.dll \
 		svndiff.dll \
+		vcdiff.dll \
+		autosave.dll \
 		filebrowser.dll
 
 clean:


Property changes on: trunk/plugins/svndiff.c
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Modified: trunk/po/POTFILES.in
===================================================================
--- trunk/po/POTFILES.in	2007-11-21 18:54:31 UTC (rev 2066)
+++ trunk/po/POTFILES.in	2007-11-22 17:03:53 UTC (rev 2067)
@@ -21,6 +21,7 @@
 src/notebook.c
 src/plugins.c
 src/prefs.c
+src/printing.c
 src/project.c
 src/sciwrappers.c
 src/search.c
@@ -39,3 +40,4 @@
 plugins/export.c
 plugins/vcdiff.c
 plugins/filebrowser.c
+plugins/autosave.c


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the Commits mailing list