back to krasimirtsonev.com
to blog's home page

FlashDevelop scripting: open file by text selection

FlashDevelop is one of the most preferred editors for the flash development. I've been also using it last few years. I found it helpful for writing JavaScript, HTML, CSS and PHP code as well. I just took a big project with over 1000 php files and it is a little bit difficult to open the right file, even by using the Project panel. That's why I decided to invest time in solving this task and found that I can write my own C# script and run it.

The site that I have to work on has a lot of files, but they are distributed in well named folders and basically the name of every class is a combination of folder's path plus the name of the php file. So when I see something like:
I have to open the file /basic/wrapper/component/manager.php. Firstly I was thinking that I will be able to solve the problem by using snippets. My idea was to select the name of the class and call a snippet which will open the file based on the text's selection. Then I realized that I'll need something more, because I have to parse the string. I checked the FlashDevelop's site and found that I can write my own macros. They are powerful tool, but as far as I know it is not possible to manipulate the selected text as I wanted. At the end I managed to solve my problem by writing a script in C# that is called by macros. Here are all the steps that I went through:

Step 1 - creating the macros


Open the macros panel by pressing Ctrl + F10. The panel looks like on the picture below.

FlashDevelop scripting: open file by text selection

Click Add button and enter the name of your macros in the Label field. Also set a Shortcut so you can call it fast while you are coding. The real part of the macros has to be written in Entries filed. Because you have to run an external script you have to use the following command:
My command looks like that:


Step 2 - creating a basic script code


The script file has to contain C# code and it has a basic structure like this:
Don't worry if you are not familiar with C#. You can still code with a little help from Google.
Every script has to contain Execute method which is actually the starting point. I strongly recommend to check this thread in the FlashDevelop's community forum. I followed the instructions there and downloaded Snippet Compiler which is actually pretty good simple C# editor. It also offers code completion and if you add PluginCore.dll you will have completion of the FlashDevelop's things.

Step 3 - creating the actual script


Firstly we should get the current selected text and the current project's directory:

When we have this data we can parse the file variable, find the path, the name of the file and open it:
The main purpose of this script was to use it in this project, but actually I found that I can use it in any other project. I decided to extend it and add additional features. Here is the full code of the script and you can download it from here.


When you run the script it checks if there is any text selection. If not then open a simple input where you can write in.

FlashDevelop scripting: open file by text selection

After that the data is processed and split by using '_' and '/' (searchForDelimeters method). I.e. the script is trying to guess the file's path. Of course you can skip this by clicking the No button.

FlashDevelop scripting: open file by text selection

findFile method is used to parse all the project's directories and search for the files based on the file's name.

If you want to create your own script I recommend to download the FlashDevelop's code and explore PluginCore's classes, properties and methods.
Sharing ...
Commenting ...
blog comments powered by Disqus