SF.net SVN: geany-plugins:[537] trunk

andrew_janke at users.sourceforge.net andrew_janke at xxxxx
Mon Mar 9 16:20:10 UTC 2009


Revision: 537
          http://geany-plugins.svn.sourceforge.net/geany-plugins/?rev=537&view=rev
Author:   andrew_janke
Date:     2009-03-09 16:20:10 +0000 (Mon, 09 Mar 2009)

Log Message:
-----------
 * intial entry to SVN

Added Paths:
-----------
    trunk/shiftcolumn/
    trunk/shiftcolumn/AUTHORS
    trunk/shiftcolumn/ChangeLog
    trunk/shiftcolumn/Makefile.am
    trunk/shiftcolumn/NEWS
    trunk/shiftcolumn/README
    trunk/shiftcolumn/autogen.sh
    trunk/shiftcolumn/configure.in
    trunk/shiftcolumn/po/
    trunk/shiftcolumn/po/LINGUAS
    trunk/shiftcolumn/po/POTFILES.in
    trunk/shiftcolumn/po/de.po
    trunk/shiftcolumn/po/ru.po
    trunk/shiftcolumn/po/shiftcolumn.pot
    trunk/shiftcolumn/src/
    trunk/shiftcolumn/src/Makefile.am
    trunk/shiftcolumn/src/shiftcolumn.c

Added: trunk/shiftcolumn/AUTHORS
===================================================================
--- trunk/shiftcolumn/AUTHORS	                        (rev 0)
+++ trunk/shiftcolumn/AUTHORS	2009-03-09 16:20:10 UTC (rev 537)
@@ -0,0 +1 @@
+Andrew L Janke <a.janke at gmail.com>

Added: trunk/shiftcolumn/ChangeLog
===================================================================
--- trunk/shiftcolumn/ChangeLog	                        (rev 0)
+++ trunk/shiftcolumn/ChangeLog	2009-03-09 16:20:10 UTC (rev 537)
@@ -0,0 +1,10 @@
+2009-03-10  Andrew L Janke  <a.janke at gmail.com>
+
+ * Added GPL license and a few patches from Frank
+ * added a few translations in the process of learning pot
+
+2009-03-09  Andrew L Janke  <a.janke at gmail.com>
+
+ * Actually works now
+
+

Added: trunk/shiftcolumn/Makefile.am
===================================================================
--- trunk/shiftcolumn/Makefile.am	                        (rev 0)
+++ trunk/shiftcolumn/Makefile.am	2009-03-09 16:20:10 UTC (rev 537)
@@ -0,0 +1,32 @@
+
+SUBDIRS = src po
+
+DOCDIR = $(DESTDIR)$(docdir)
+
+EXTRA_DIST = \
+	autogen.sh \
+	po/LINGUAS
+
+dist-bzip2: distdir
+	BZIP2=$(BZIP2_ENV) $(AMTAR) --bzip2 -chof $(distdir).tar.bz2 $(distdir)
+	-rm -rf $(distdir)
+
+sign:
+	if test -f $(PACKAGE)-$(VERSION).tar.gz; then \
+		gpg --detach-sign --digest-algo SHA512 $(PACKAGE)-$(VERSION).tar.gz; fi
+	if test -f $(PACKAGE)-$(VERSION).tar.bz2; then \
+		gpg --detach-sign --digest-algo SHA512 $(PACKAGE)-$(VERSION).tar.bz2; fi
+
+html:
+	rst2html README index.html
+
+install-data-local:
+	$(mkinstalldirs) $(DOCDIR)
+	$(INSTALL_DATA) $(top_srcdir)/README $(DOCDIR)
+	$(INSTALL_DATA) $(top_srcdir)/ChangeLog $(DOCDIR)
+	$(INSTALL_DATA) $(top_srcdir)/NEWS $(DOCDIR)
+	$(INSTALL_DATA) $(top_srcdir)/COPYING $(DOCDIR)
+	$(INSTALL_DATA) $(top_srcdir)/AUTHORS $(DOCDIR)
+
+uninstall-local:
+	rm -rf $(DOCDIR)

Added: trunk/shiftcolumn/NEWS
===================================================================
--- trunk/shiftcolumn/NEWS	                        (rev 0)
+++ trunk/shiftcolumn/NEWS	2009-03-09 16:20:10 UTC (rev 537)
@@ -0,0 +1,10 @@
+
+New in Version 0.3
+------------------
+
+* added license and po files
+
+New in Version 0.2
+------------------
+
+* it works

Added: trunk/shiftcolumn/README
===================================================================
--- trunk/shiftcolumn/README	                        (rev 0)
+++ trunk/shiftcolumn/README	2009-03-09 16:20:10 UTC (rev 537)
@@ -0,0 +1,54 @@
+Shift Column Plugin
+===================
+
+.. contents::
+
+About
+-----
+This plugin allows you to move blocks of text horizontally
+
+Requirements
+------------
+For compiling the plugin yourself, you will need the GTK (>= 2.8.0) libraries
+and header files. You will also need its dependency libraries and header
+files, such as Pango, Glib and ATK. All these files are available at
+http://www.gtk.org.
+
+Installation
+------------
+Compiling and installing the code is done by the following three commands:
+$ ./configure
+$ make
+$ make install
+
+For more configuration details run
+$ ./configure --help
+
+If there are any errors during compilation, check your build environment
+and try to find the error, otherwise contact one of the authors.
+
+
+Usage
+-----
+After installed successfully, load the plugin in Geany's plugin manager
+and a new menu item in the Tools menu will appear. Alternatively, you can
+assign a keyboard shortcut in Geany's preferences dialog. By default
+the mappings are to <Ctrl>9 and <Ctrl>0
+
+
+Known issues
+------------
+   * none, my code rocks.. (well I can hope)
+
+License
+-------
+Shift Column is distributed 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.  A copy of this license
+can be found in the file COPYING included with the source code of this
+program.
+
+
+Ideas, questions, patches and bug reports
+-----------------------------------------
+Andrew Janke <a.janke at gmail.com>

Added: trunk/shiftcolumn/autogen.sh
===================================================================
--- trunk/shiftcolumn/autogen.sh	                        (rev 0)
+++ trunk/shiftcolumn/autogen.sh	2009-03-09 16:20:10 UTC (rev 537)
@@ -0,0 +1,159 @@
+#!/bin/sh
+# Run this to generate all the initial makefiles, etc.
+
+srcdir=`dirname $0`
+test -z "$srcdir" && srcdir=.
+
+DIE=0
+
+if [ -n "$GNOME2_DIR" ]; then
+	ACLOCAL_FLAGS="-I $GNOME2_DIR/share/aclocal $ACLOCAL_FLAGS"
+	LD_LIBRARY_PATH="$GNOME2_DIR/lib:$LD_LIBRARY_PATH"
+	PATH="$GNOME2_DIR/bin:$PATH"
+	export PATH
+	export LD_LIBRARY_PATH
+fi
+
+(test -f $srcdir/configure.in) || {
+    echo -n "**Error**: Directory "\`$srcdir\'" does not look like the"
+    echo " top-level package directory"
+    exit 1
+}
+
+(autoconf --version) < /dev/null > /dev/null 2>&1 || {
+  echo
+  echo "**Error**: You must have \`autoconf' installed."
+  echo "Download the appropriate package for your distribution,"
+  echo "or get the source tarball at ftp://ftp.gnu.org/pub/gnu/"
+  DIE=1
+}
+
+(grep "^AC_PROG_INTLTOOL" $srcdir/configure.in >/dev/null) && {
+  (intltoolize --version) < /dev/null > /dev/null 2>&1 || {
+    echo 
+    echo "**Error**: You must have \`intltool' installed."
+    echo "You can get it from:"
+    echo "  ftp://ftp.gnome.org/pub/GNOME/"
+    DIE=1
+  }
+}
+
+(grep "^AM_PROG_XML_I18N_TOOLS" $srcdir/configure.in >/dev/null) && {
+  (xml-i18n-toolize --version) < /dev/null > /dev/null 2>&1 || {
+    echo
+    echo "**Error**: You must have \`xml-i18n-toolize' installed."
+    echo "You can get it from:"
+    echo "  ftp://ftp.gnome.org/pub/GNOME/"
+    DIE=1
+  }
+}
+
+(grep "^AM_PROG_LIBTOOL" $srcdir/configure.in >/dev/null) && {
+  (libtool --version) < /dev/null > /dev/null 2>&1 || {
+    echo
+    echo "**Error**: You must have \`libtool' installed."
+    echo "You can get it from: ftp://ftp.gnu.org/pub/gnu/"
+    DIE=1
+  }
+}
+
+(grep "^AM_GLIB_GNU_GETTEXT" $srcdir/configure.in >/dev/null) && {
+  (grep "sed.*POTFILES" $srcdir/configure.in) > /dev/null || \
+  (glib-gettextize --version) < /dev/null > /dev/null 2>&1 || {
+    echo
+    echo "**Error**: You must have \`glib' installed."
+    echo "You can get it from: ftp://ftp.gtk.org/pub/gtk"
+    DIE=1
+  }
+}
+
+(automake --version) < /dev/null > /dev/null 2>&1 || {
+  echo
+  echo "**Error**: You must have \`automake' installed."
+  echo "You can get it from: ftp://ftp.gnu.org/pub/gnu/"
+  DIE=1
+  NO_AUTOMAKE=yes
+}
+
+
+# if no automake, don't bother testing for aclocal
+test -n "$NO_AUTOMAKE" || (aclocal --version) < /dev/null > /dev/null 2>&1 || {
+  echo
+  echo "**Error**: Missing \`aclocal'.  The version of \`automake'"
+  echo "installed doesn't appear recent enough."
+  echo "You can get automake from ftp://ftp.gnu.org/pub/gnu/"
+  DIE=1
+}
+
+if test "$DIE" -eq 1; then
+  exit 1
+fi
+
+if test -z "$*"; then
+  echo "**Warning**: I am going to run \`configure' with no arguments."
+  echo "If you wish to pass any to it, please specify them on the"
+  echo \`$0\'" command line."
+  echo
+fi
+
+case $CC in
+xlc )
+  am_opt=--include-deps;;
+esac
+
+for coin in `find $srcdir -path $srcdir/CVS -prune -o -name configure.in -print`
+do 
+  dr=`dirname $coin`
+  if test -f $dr/NO-AUTO-GEN; then
+    echo skipping $dr -- flagged as no auto-gen
+  else
+    echo processing $dr
+    ( cd $dr
+
+      aclocalinclude="$ACLOCAL_FLAGS"
+
+      if grep "^AM_GLIB_GNU_GETTEXT" configure.in >/dev/null; then
+	echo "Creating $dr/aclocal.m4 ..."
+	test -r $dr/aclocal.m4 || touch $dr/aclocal.m4
+	echo "Running glib-gettextize...  Ignore non-fatal messages."
+	echo "no" | glib-gettextize --force --copy
+	echo "Making $dr/aclocal.m4 writable ..."
+	test -r $dr/aclocal.m4 && chmod u+w $dr/aclocal.m4
+      fi
+      if grep "^AC_PROG_INTLTOOL" configure.in >/dev/null; then
+        echo "Running intltoolize..."
+	intltoolize --copy --force --automake
+      fi
+      if grep "^AM_PROG_XML_I18N_TOOLS" configure.in >/dev/null; then
+        echo "Running xml-i18n-toolize..."
+	xml-i18n-toolize --copy --force --automake
+      fi
+      if grep "^AM_PROG_LIBTOOL" configure.in >/dev/null; then
+	if test -z "$NO_LIBTOOLIZE" ; then 
+	  echo "Running libtoolize..."
+	  libtoolize --force --copy
+	fi
+      fi
+      echo "Running aclocal $aclocalinclude ..."
+      aclocal $aclocalinclude
+      if grep "^AM_CONFIG_HEADER" configure.in >/dev/null; then
+	echo "Running autoheader..."
+	autoheader
+      fi
+      echo "Running automake --gnu $am_opt ..."
+      automake --add-missing --gnu $am_opt
+      echo "Running autoconf ..."
+      autoconf
+    )
+  fi
+done
+
+conf_flags="--enable-maintainer-mode"
+
+if test x$NOCONFIGURE = x; then
+  echo Running $srcdir/configure $conf_flags "$@" ...
+  $srcdir/configure $conf_flags "$@" \
+  && echo Now type \`make\' to compile. || exit 1
+else
+  echo Skipping configure process.
+fi


Property changes on: trunk/shiftcolumn/autogen.sh
___________________________________________________________________
Added: svn:executable
   + *

Added: trunk/shiftcolumn/configure.in
===================================================================
--- trunk/shiftcolumn/configure.in	                        (rev 0)
+++ trunk/shiftcolumn/configure.in	2009-03-09 16:20:10 UTC (rev 537)
@@ -0,0 +1,65 @@
+# Process this file with autoconf to produce a configure script.
+# $Id: configure.in 2 2008-04-02 14:52:33Z eht16 $
+
+AC_INIT(configure.in)
+AM_INIT_AUTOMAKE(shiftcolumn, 0.3)
+
+AM_CONFIG_HEADER(config.h)
+
+AC_PROG_CC
+
+AC_DISABLE_STATIC
+AM_PROG_LIBTOOL
+LIBTOOL="$LIBTOOL --silent"
+
+AC_PROG_INSTALL
+
+# checking for Geany
+PKG_CHECK_MODULES(GEANY, [geany >= 0.16])
+AC_SUBST(GEANY_CFLAGS)
+AC_SUBST(GEANY_LIBS)
+
+GEANY_VERSION=`$PKG_CONFIG --modversion geany`
+GTK_VERSION=`$PKG_CONFIG --modversion gtk+-2.0`
+
+# i18n
+GETTEXT_PACKAGE=shiftcolumn
+AC_SUBST(GETTEXT_PACKAGE)
+AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE", [Gettext package.])
+
+ALL_LINGUAS="`sed -e '/^#/d' $srcdir/po/LINGUAS`" # take all languages found in file po/LINGUAS
+
+AM_GLIB_GNU_GETTEXT
+# workaround for intltool bug (http://bugzilla.gnome.org/show_bug.cgi?id=490845)
+if test "x$MSGFMT" = "xno"; then
+	AC_MSG_ERROR([msgfmt not found. Please install the gettext package.])
+fi
+
+# intltool hack to define install_sh on Debian/Ubuntu systems
+if test "x$install_sh" = "x"; then
+	install_sh="`pwd`/install-sh"
+	AC_SUBST(install_sh)
+fi
+
+
+
+# get the plugin installed at the correct location for Geany
+# TODO find a way to NOT override --libdir/--docdir command line option if given
+libdir="`$PKG_CONFIG --variable=libdir geany`/geany"
+docdir="${datarootdir}/doc/geany-plugins/${PACKAGE}"
+
+
+AC_OUTPUT([
+Makefile
+src/Makefile
+po/Makefile.in
+])
+
+echo "----------------------------------------"
+echo "Install Shift Column plugin binary in : ${libdir}"
+echo "Install Shift Column files in         : ${prefix}"
+echo "Using Geany version                   : ${GEANY_VERSION}"
+echo "Using GTK version                     : ${GTK_VERSION}"
+echo ""
+echo "Configuration is done OK."
+echo ""

Added: trunk/shiftcolumn/po/LINGUAS
===================================================================
--- trunk/shiftcolumn/po/LINGUAS	                        (rev 0)
+++ trunk/shiftcolumn/po/LINGUAS	2009-03-09 16:20:10 UTC (rev 537)
@@ -0,0 +1,2 @@
+# set of available languages (in alphabetic order)
+de ru

Added: trunk/shiftcolumn/po/POTFILES.in
===================================================================
--- trunk/shiftcolumn/po/POTFILES.in	                        (rev 0)
+++ trunk/shiftcolumn/po/POTFILES.in	2009-03-09 16:20:10 UTC (rev 537)
@@ -0,0 +1,3 @@
+# List of source files containing translatable strings.
+
+src/shiftcolumn.c

Added: trunk/shiftcolumn/po/de.po
===================================================================
--- trunk/shiftcolumn/po/de.po	                        (rev 0)
+++ trunk/shiftcolumn/po/de.po	2009-03-09 16:20:10 UTC (rev 537)
@@ -0,0 +1,33 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL at ADDRESS>, YEAR.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: shiftcolumn 0.3\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2009-03-09 03:32+1100\n"
+"PO-Revision-Date: 2009-03-09 20:50+1000\n"
+"Last-Translator: Andrew Janke <a.janke at gmail.com>\n"
+"Language-Team: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: src/shiftcolumn.c:39
+msgid "Shift Column"
+msgstr "spalte rucken"
+
+#: src/shiftcolumn.c:40
+msgid "Shift a selection left and right"
+msgstr ""
+
+#: src/shiftcolumn.c:342
+msgid "Shift Left"
+msgstr "links rucken"
+
+#: src/shiftcolumn.c:349
+msgid "Shift Right"
+msgstr "rechts rucken"
+

Added: trunk/shiftcolumn/po/ru.po
===================================================================
--- trunk/shiftcolumn/po/ru.po	                        (rev 0)
+++ trunk/shiftcolumn/po/ru.po	2009-03-09 16:20:10 UTC (rev 537)
@@ -0,0 +1,33 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL at ADDRESS>, YEAR.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: shiftcolumn 0.3\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2009-03-09 03:32+1100\n"
+"PO-Revision-Date: 2009-03-09 20:37+1000\n"
+"Last-Translator: Andrew Janke <a.janke at gmail.com>\n"
+"Language-Team: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: src/shiftcolumn.c:39
+msgid "Shift Column"
+msgstr "Сдвинуть Столбец"
+
+#: src/shiftcolumn.c:40
+msgid "Shift a selection left and right"
+msgstr "Сдвинить Выделение влево и вправо"
+
+#: src/shiftcolumn.c:342
+msgid "Shift Left"
+msgstr "Сдвинуть Влево"
+
+#: src/shiftcolumn.c:349
+msgid "Shift Right"
+msgstr "Сдвинуть Вправо"
+

Added: trunk/shiftcolumn/po/shiftcolumn.pot
===================================================================
--- trunk/shiftcolumn/po/shiftcolumn.pot	                        (rev 0)
+++ trunk/shiftcolumn/po/shiftcolumn.pot	2009-03-09 16:20:10 UTC (rev 537)
@@ -0,0 +1,33 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL at ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2009-03-09 03:32+1100\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL at ADDRESS>\n"
+"Language-Team: LANGUAGE <LL at li.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=CHARSET\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: src/shiftcolumn.c:39
+msgid "Shift Column"
+msgstr ""
+
+#: src/shiftcolumn.c:40
+msgid "Shift a selection left and right"
+msgstr ""
+
+#: src/shiftcolumn.c:342
+msgid "Shift Left"
+msgstr ""
+
+#: src/shiftcolumn.c:349
+msgid "Shift Right"
+msgstr ""

Added: trunk/shiftcolumn/src/Makefile.am
===================================================================
--- trunk/shiftcolumn/src/Makefile.am	                        (rev 0)
+++ trunk/shiftcolumn/src/Makefile.am	2009-03-09 16:20:10 UTC (rev 537)
@@ -0,0 +1,7 @@
+
+lib_LTLIBRARIES = shiftcolumn.la
+shiftcolumn_la_SOURCES = shiftcolumn.c
+shiftcolumn_la_LDFLAGS = -module -avoid-version
+shiftcolumn_la_LIBADD  = @GEANY_LIBS@
+
+AM_CFLAGS = @GEANY_CFLAGS@ -DLOCALEDIR=\""$(localedir)"\" -DDOCDIR=\""$(docdir)"\"

Added: trunk/shiftcolumn/src/shiftcolumn.c
===================================================================
--- trunk/shiftcolumn/src/shiftcolumn.c	                        (rev 0)
+++ trunk/shiftcolumn/src/shiftcolumn.c	2009-03-09 16:20:10 UTC (rev 537)
@@ -0,0 +1,377 @@
+/*  shiftcolumn.c - a Geany plugin
+ *
+ *  Copyright 2009 Andrew L Janke <a.janke 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., 51 Franklin Street, Fifth Floor, Boston,
+ *  MA 02110-1301, USA.
+ */
+
+
+#include "geany.h"
+#include "ui_utils.h"
+
+#include "sciwrappers.h"
+#include "document.h"
+#include "keybindings.h"
+#include "plugindata.h"
+#include "geanyfunctions.h"
+
+#include <glib.h>
+#include <glib/gprintf.h>
+#include <gdk/gdkkeysyms.h>
+
+GeanyPlugin     *geany_plugin;
+GeanyData       *geany_data;
+GeanyFunctions  *geany_functions;
+
+PLUGIN_VERSION_CHECK(130);
+PLUGIN_SET_INFO(_("Shift Column"),
+                _("Shift a selection left and right"),
+                "0.1", "Andrew L Janke <a.janke at gmail.com>");
+
+
+static GtkWidget *menu_item_shift_left = NULL;
+static GtkWidget *menu_item_shift_right = NULL;
+
+/* Keybinding(s) */
+enum{
+   KB_SHIFT_LEFT,
+   KB_SHIFT_RIGHT,
+   KB_COUNT
+   };
+PLUGIN_KEY_GROUP(shiftcolumn, KB_COUNT)
+
+
+static void shift_left_cb(G_GNUC_UNUSED GtkMenuItem *menuitem, 
+                          G_GNUC_UNUSED gpointer gdata){
+   gchar *txt;
+   gchar *txt_i;
+   gchar char_before;
+   gint txt_len;
+   
+   gint startpos;
+   gint endpos;
+   
+   gint startline;
+   gint endline;
+   gint line_iter;
+   gint linepos;
+   gint linelen;
+   
+   gint startcol;
+   gint endcol;
+   
+   gint i;
+   
+   gint n_spaces;
+   gchar *spaces;
+   
+   ScintillaObject *sci;
+   
+   /* get a pointer to the scintilla object */
+   sci = document_get_current()->editor->sci;
+      
+   if (sci_has_selection(sci)){
+      
+      startpos = sci_get_selection_start(sci);
+      endpos = sci_get_selection_end(sci);
+      
+      /* sanity check -- we dont care which way the block was selected */
+      if(startpos > endpos){
+         i = endpos;
+         endpos = startpos;
+         startpos = i;
+         }
+      
+      startline = sci_get_line_from_position(sci, startpos);
+      endline = sci_get_line_from_position(sci, endpos);
+      
+      /* normal mode */
+      // if(sci_get_selection_mode(sci) == 1){
+      if(startline == endline){
+         
+         /* get the text in question */
+         txt_len = endpos - startpos;
+         txt_i = g_malloc(txt_len + 1);
+         txt = g_malloc(txt_len + 2);
+         sci_get_selected_text(sci, txt_i);
+         
+         char_before = sci_get_char_at(sci, startpos - 1);
+               
+         /* set up new text buf */
+         (void) g_sprintf(txt, "%s%c", txt_i, char_before);
+         
+         /* start undo */
+         sci_start_undo_action(sci);
+         
+         /* put the new text in */
+         sci_set_selection_start(sci, startpos - 1);
+         sci_replace_sel(sci, txt);
+      
+         /* select the right bit again */
+         sci_set_selection_start(sci, startpos - 1);
+         sci_set_selection_end(sci, endpos - 1);
+         
+         /* end undo */
+         sci_end_undo_action(sci);
+         
+         g_free(txt);
+         g_free(txt_i);
+         }
+      
+      /* rectangle mode (we hope!) */
+      else{
+         startcol = sci_get_col_from_position(sci, startpos);
+         endcol = sci_get_col_from_position(sci, endpos);
+         
+         /* return early for the trivial case */
+         if(startcol == 0 || startcol == endcol){
+            return;
+            }
+         
+         /* start undo */
+         sci_start_undo_action(sci);
+         
+         for(line_iter = startline; line_iter <= endline; line_iter++){
+            linepos = sci_get_position_from_line(sci, line_iter);
+            linelen = sci_get_line_length(sci, line_iter);
+            
+            /* do we need to do something */
+            if(linelen >= startcol - 1 ){
+               
+               /* if between the two columns */
+               /* pad to the end first */     
+               if(linelen <= endcol){         
+                  
+                  /* bung in some spaces -- sorry, I dont like tabs */
+                  n_spaces = endcol - linelen + 1;
+                  spaces = g_malloc(sizeof(gchar) * (n_spaces + 1));
+                  for(i = 0; i < n_spaces; i++){
+                     spaces[i] = ' ';
+                     }
+                  spaces[i] = '\0';
+                  
+                  sci_insert_text(sci, linepos + linelen - 1, spaces);
+                  g_free(spaces);
+                  }
+               
+               /* now move the text itself */
+               sci_set_selection_mode(sci, 0);
+               sci_set_selection_start(sci, linepos + startcol);
+               sci_set_selection_end(sci, linepos + endcol);
+               
+               txt_len = sci_get_selected_text_length(sci);
+               txt_i = g_malloc(txt_len + 1);
+               txt = g_malloc(txt_len + 2);
+               
+               sci_get_selected_text(sci, txt_i);
+               char_before = sci_get_char_at(sci, linepos + startcol - 1);
+               
+               /* set up new text buf */
+               (void) g_sprintf(txt, "%s%c", txt_i, char_before);
+               
+               /* put the new text in */
+               sci_set_selection_start(sci, linepos + startcol - 1);
+               sci_replace_sel(sci, txt);
+               
+               g_free(txt);
+               g_free(txt_i);
+               }
+            }
+         
+         /* put the selection box back */
+         /* here we rely upon the last result of linepos */
+         sci_set_selection_mode(sci, 1);
+         sci_set_selection_start(sci, startpos - 1);
+         sci_set_selection_end(sci, linepos + endcol - 1);
+         
+         /* end undo action */
+         sci_end_undo_action(sci);
+         }
+      
+      }
+   }
+
+static void shift_right_cb(G_GNUC_UNUSED GtkMenuItem *menuitem, 
+                           G_GNUC_UNUSED gpointer gdata){
+   gchar *txt;
+   gchar *txt_i;
+   gchar char_after;
+   gint txt_len;
+   
+   gint startpos;
+   gint endpos;
+   
+   gint startline;
+   gint endline;
+   gint line_iter;
+   gint linepos;
+   gint linelen;
+   
+   gint startcol;
+   gint endcol;
+   
+   gint i;
+   
+   ScintillaObject *sci;
+   
+   /* get a pointer to the scintilla object */
+   sci = document_get_current()->editor->sci;
+      
+   if (sci_has_selection(sci)){
+      
+      startpos = sci_get_selection_start(sci);
+      endpos = sci_get_selection_end(sci);
+      
+      /* sanity check -- we dont care which way the block was selected */
+      if(startpos > endpos){
+         i = endpos;
+         endpos = startpos;
+         startpos = i;
+         }
+      
+      startline = sci_get_line_from_position(sci, startpos);
+      endline = sci_get_line_from_position(sci, endpos);
+      
+      /* normal mode */
+      if(startline == endline){
+         
+         /* get the text in question */
+         txt_len = endpos - startpos;
+         txt_i = g_malloc(txt_len + 1);
+         txt = g_malloc(txt_len + 2);
+         sci_get_selected_text(sci, txt_i);
+         
+         char_after = sci_get_char_at(sci, endpos);
+               
+         /* set up new text buf */
+         (void) g_sprintf(txt, "%c%s", char_after, txt_i);
+         
+         /* start undo */
+         sci_start_undo_action(sci);
+         
+         /* put the new text in */
+         sci_set_selection_end(sci, endpos + 1);
+         sci_replace_sel(sci, txt);
+      
+         /* select the right bit again */
+         sci_set_selection_start(sci, startpos + 1);
+         sci_set_selection_end(sci, endpos + 1);
+         
+         /* end undo */
+         sci_end_undo_action(sci);
+         
+         g_free(txt);
+         g_free(txt_i);
+         }
+      
+      /* rectangle mode (we hope!) */
+      else{
+         startcol = sci_get_col_from_position(sci, startpos);
+         endcol = sci_get_col_from_position(sci, endpos);
+         
+         /* start undo */
+         sci_start_undo_action(sci);
+         
+         for(line_iter = startline; line_iter <= endline; line_iter++){
+            linepos = sci_get_position_from_line(sci, line_iter);
+            linelen = sci_get_line_length(sci, line_iter);
+            
+            /* do we need to do something */
+            if(linelen >= startcol - 1 ){
+               
+               /* if between the two columns or at the end */
+               /* add in a space */
+               if(linelen <= endcol || linelen - 1 == endcol){
+                  txt = g_malloc(sizeof(gchar) * 2);
+                  sprintf(txt, " ");
+                  
+                  sci_insert_text(sci, linepos + startcol, txt);
+                  g_free(txt);
+                  }
+               
+               else{
+                  /* move the text itself */
+                  sci_set_selection_mode(sci, 0);
+                  sci_set_selection_start(sci, linepos + startcol);
+                  sci_set_selection_end(sci, linepos + endcol);
+                 
+                  txt_len = sci_get_selected_text_length(sci);
+                  txt_i = g_malloc(txt_len + 1);
+                  txt = g_malloc(txt_len + 2);
+                  
+                  sci_get_selected_text(sci, txt_i);
+                  char_after = sci_get_char_at(sci, linepos + endcol);
+                  
+                  /* set up new text buf */
+                  (void) g_sprintf(txt, "%c%s", char_after, txt_i);
+               
+                  /* put the new text in */
+                  sci_set_selection_end(sci, linepos + endcol + 1);
+                  sci_replace_sel(sci, txt);
+                  
+                  g_free(txt);
+                  g_free(txt_i);
+                  }
+               }
+            }
+         
+         /* put the selection box back */
+         /* here we rely upon the last result of linepos */
+         sci_set_selection_mode(sci, 1);
+         sci_set_selection_start(sci, startpos + 1);
+         sci_set_selection_end(sci, linepos + endcol + 1);
+         
+         /* end undo action */
+         sci_end_undo_action(sci);
+         }
+      }
+   }
+
+
+static void kb_shift_left(G_GNUC_UNUSED guint key_id){
+   shift_left_cb(NULL, NULL);
+   }
+
+static void kb_shift_right(G_GNUC_UNUSED guint key_id){
+   shift_right_cb(NULL, NULL);
+   }
+
+void plugin_init(G_GNUC_UNUSED GeanyData *data){
+   menu_item_shift_left = gtk_menu_item_new_with_mnemonic(_("Shift Left"));
+   gtk_widget_show(menu_item_shift_left);
+   gtk_container_add(GTK_CONTAINER(geany->main_widgets->tools_menu),
+       menu_item_shift_left);
+   g_signal_connect(menu_item_shift_left, "activate",
+       G_CALLBACK(shift_left_cb), NULL);
+   
+   menu_item_shift_right = gtk_menu_item_new_with_mnemonic(_("Shift Right"));
+   gtk_widget_show(menu_item_shift_right);
+   gtk_container_add(GTK_CONTAINER(geany->main_widgets->tools_menu),
+       menu_item_shift_right);
+   g_signal_connect(menu_item_shift_right, "activate",
+       G_CALLBACK(shift_right_cb), NULL);
+   
+   /* setup keybindings */
+   keybindings_set_item(plugin_key_group, KB_SHIFT_LEFT, kb_shift_left,
+      GDK_9, GDK_CONTROL_MASK, "shift_left", "_(Shift Left)", NULL);
+   keybindings_set_item(plugin_key_group, KB_SHIFT_RIGHT, kb_shift_right,
+      GDK_0, GDK_CONTROL_MASK, "shift_right", "_(Shift Right)", NULL);
+   }
+ 
+void plugin_cleanup(void){
+   gtk_widget_destroy(menu_item_shift_left);
+   gtk_widget_destroy(menu_item_shift_right);
+   }


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