SF.net SVN: geany-plugins:[390] trunk/geanylipsum/src/geanylipsum.c
frlan at users.sourceforge.net
frlan at xxxxx
Tue Jan 20 00:16:25 UTC 2009
Revision: 390
http://geany-plugins.svn.sourceforge.net/geany-plugins/?rev=390&view=rev
Author: frlan
Date: 2009-01-20 00:16:25 +0000 (Tue, 20 Jan 2009)
Log Message:
-----------
GeanyLipsum: Implemented length handling
Modified Paths:
--------------
trunk/geanylipsum/src/geanylipsum.c
Modified: trunk/geanylipsum/src/geanylipsum.c
===================================================================
--- trunk/geanylipsum/src/geanylipsum.c 2009-01-20 00:15:50 UTC (rev 389)
+++ trunk/geanylipsum/src/geanylipsum.c 2009-01-20 00:16:25 UTC (rev 390)
@@ -66,6 +66,7 @@
static gchar *config_file = NULL;
static gchar *lipsum = NULL;
+
/* Doing some basic keybinding stuff */
enum
{
@@ -76,6 +77,7 @@
PLUGIN_KEY_GROUP(geanylipsum, COUNT_KB);
+
void
insert_string(gchar *string)
{
@@ -90,6 +92,7 @@
}
}
+
void
lipsum_activated(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer gdata)
{
@@ -130,19 +133,46 @@
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
{
+ int tmp = 0;
+ int x = 0;
+ int i = 0;
+ int missing = 0;
+
/* Checking for length of string that should be inserted */
length = gtk_spin_button_get_value_as_int(
GTK_SPIN_BUTTON(spin));
gtk_widget_destroy(dialog);
- insert_string(lipsum);
+ /* Checking what we have */
+
+ tmp = strlen(lipsum);
+
+ if (tmp > length)
+ {
+ x = 0;
+ missing = length - (x * tmp);
+ }
+ else if (tmp == length)
+ {
+ x = 1;
+ }
+ else if (tmp > 0)
+ {
+ x = length / tmp;
+ missing = length - (x * tmp);
+ }
+
+ for (i = 0; i < x; i++)
+ insert_string(lipsum);
+
+ if (missing > 0)
+ insert_string(g_strndup(lipsum, missing));
}
- else
- {
- gtk_widget_destroy(dialog);
- }
+ gtk_widget_destroy(dialog);
+
+
}
static void kblipsum_insert(G_GNUC_UNUSED guint key_id)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Plugins-Commits
mailing list