home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 53 / IOPROG_53.ISO / soft / sharpdevelop / add-ins / plugins / texttools / texttools.cs < prev    next >
Encoding:
Text File  |  2001-10-26  |  2.9 KB  |  88 lines

  1. // TextTools.cs
  2. // Copyright (C) 2000 Mike Krueger
  3. //
  4. // This program is free software; you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation; either version 2 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program; if not, write to the Free Software
  16. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  17.  
  18. using System;
  19. using System.Diagnostics;
  20. using System.Drawing;
  21. using SharpDevelop.Gui;
  22. using SharpDevelop.Actions;
  23. using SharpDevelop.Actions.Menu;
  24. using SharpDevelop.Internal.Plugin;
  25. using SharpDevelop.Gui.Edit.Text;
  26. using SharpDevelop.Internal.Text;
  27. using SharpDevelop.Internal.Messages;
  28.  
  29. namespace TextTools {
  30.     
  31.     /// <summary>
  32.     /// This is a sample menu plugin.
  33.     /// It Removes all trailing white space characters in the current buffer
  34.     /// </summary>
  35.     public class RemoveTrailingWS : ISdPlugin
  36.     {
  37.         public ISdMessageHandler MessageHandler {
  38.             get {
  39.                 return null;
  40.             }
  41.         }
  42.         
  43.         public void Execute(ISdPluginExecutor executor)
  44.         {
  45.             if (!executor.Main.ActiveContentWindow.HasTextArea)
  46.                 return;
  47.             
  48.             TextAreaControl textarea    = executor.Main.ActiveContentWindow.TextArea;
  49.  
  50.             int           redocounter = 0; // must count how many Delete operations occur
  51.             Point         p1 = new Point();
  52.             Point         p2 = new Point();
  53.             for (int i = 0; i < textarea.Buffer.Length; ++i) {
  54.                 int x = textarea.Buffer[i].Text.Length - 1;
  55.                 p1.Y = p2.Y = i;
  56.                 while (x >= 0 && Char.IsWhiteSpace(textarea.Buffer[i].Text[x])) {
  57.                     p1.X = x;
  58.                     p2.X = x + 1;
  59.                     textarea.Buffer.Delete(p1, p2);
  60.                     ++redocounter;                  // count deletes
  61.                     --x;                            // length changed
  62.                 }
  63.             }
  64.             textarea.Caret.CheckCaretPos();                       // current cursor position may be invalid
  65.             textarea.Buffer.UndoStack.UndoLast(redocounter); // redo the whole operation (not the single deletes)
  66.             textarea.Refresh();
  67.         }
  68.     }
  69.     
  70.     /// <summary>
  71.     /// This is a sample editaction plugin, it indents the selected area.
  72.     /// </summary>
  73.     public class IndentSelection : ISdEditAction
  74.     {
  75.         public void Execute(ISdEditActionExecutor executor)
  76.         {
  77.             if (executor.TextArea.Buffer.ReadOnly) 
  78.                 return;
  79.             if (executor.TextArea.Selection.HasSomethingSelected) {
  80.                 int y1 = executor.TextArea.Selection.RealStart.Y;
  81.                 int y2 = executor.TextArea.Selection.RealEnd.Y;
  82.                 Indent.IndentLines(executor.TextArea.Buffer, y1, y2, executor.TextArea.Options.IndentStyle);
  83.                 executor.TextArea.Refresh();
  84.             }
  85.         }
  86.     }
  87. }
  88.