View unanswered posts | View active topics


Reply to topic  [ 3 posts ] 
Macros scripting: getting started, edition and example 
Author Message
Admin

Joined: Wed Aug 31, 2005 7:27 am
Posts: 10740
Location: Paris, France
Post Macros scripting: getting started, edition and example
Advanced macros can be developed for FlashDevelop - the sky is the limit as long as you can stay keep it in one class :)

Here is a very simple macro which "flattens" single line XML code in the current document.
Code:
using System;
using PluginCore;

public class FlattenXML
{
   public static void Execute()
   {
      ScintillaNet.ScintillaControl sci = PluginBase.MainForm.CurrentDocument.SciControl;
      if (sci == null) return; // document not editable

      string src = sci.Text; // WARNING: reading/writing sci.Text property is slow
      sci.Text = src.Replace("><", ">\n<");
   }
}

Save this code as "FlattenXML.cs" in your user FD directory (locate it from FD main menu: Tools > Application Files...).

Now you can <Add> a new macro in the Macros dialog (Macros > Edit Macros...):
Image
The macro properties are pretty straightforward:
* AutoRun - optionally execute macro on FD startup
* Entries - list of basic macro commands (click <...> to edit)
* Image - you can build a nice icon for the menu item using "icomp", a tool included in FD program files (Tools\icomp)
* Label - text of the menu item
* Shortcut - obviously a shortcut to execute your macro

The macro command to run a script during development is the following (the script will be loaded and compiled each time it is executed)
Code:
ExecuteScript|Development;$(BaseDir)\FlattenXML.cs

When your script is completed, change the command for better performance (the script will be compiled only once):
Code:
ExecuteScript|Internal;$(BaseDir)\FlattenXML.cs


Thu Dec 17, 2009 7:49 pm
Profile WWW
Admin

Joined: Wed Aug 31, 2005 7:27 am
Posts: 10740
Location: Paris, France
Post Editing tips
Code completion?

Writing C# code without an appropriate editor can be a pain. You could probably use Visual Studio (or the great and free C# Express) but there is a better solution...

The Snippet Compiler Live 2008 Ultimate Edition for Developers (yeah)!

It's not a joke, this is free, lightweight C# editor offering actually good code completion and compilation - precisely designed to quickly code and compile one class (typically to create a little command line application).

So download Snippet Compiler (SC) and run it. You'll be presented with a default C# class for a command line application.

The template class has 2 methods: RunSnippet and Main. This is a nice way to let you write your code in RunSnippet and to not worry about the usual try/catch and ReadKey when you test a command-line application.

For FD macro scripts:
- you'll want to compile your script using SC to trap compile errors (that's one thing you won't have to worry when testing),
- this means a public static void Main() method is required (SC compiles command line application only),
- you can keep the default class as-is (use RunSnippet() for your tests outside FD).

1. For most code completion needs you'll have to add a "reference" to FlashDevelop's PluginCore:
- in SC, select: Tools > References > File System
- click <...> to browse to FD program files and choose PluginCore.dll (double-click once to add it in the DLL list at the bottom of the dialog) then click <Ok>
(you may have to re-add the reference when you restart SC)

2. You will then simply add a public static void Execute() method with your FD script.

3. Code, compile with Ctrl+Shift+B to control your code is ok, then test in FlashDevelop.


Thu Dec 17, 2009 9:47 pm
Profile WWW
Admin

Joined: Wed Aug 31, 2005 7:27 am
Posts: 10740
Location: Paris, France
Post Basic scripts debugging
Basic scripts debugging (ie. tracing):

You won't have breakpoints and step debugging but you can trace to FD output panel from your plugin:
Code:
using PluginCore.Managers;
...
TraceManager.Add("show this in output");
TraceManager.Add("show this in RED", 3);

Color levels:
- 0: info (gray)
- 1: debug (black)
- 2: warning (orange)
- 3: error (red)
- 4: fatal (purple)


Fri Dec 18, 2009 11:45 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.