Aptana Studio ヘルプ > はじめに > Aptana Studioの基本 > プラグインの基本 > Adding a source control plugin to Aptana > Quick reference for popular plug-ins > Aptana Snippets

Toggling word wrap

This Help topic describes how to use a short Eclipse Monkey script to toggle the current editor's text wrapping setting.

Introduction

Aptana Studio currently does not support word wrapping due to a limitation in the Eclipse framework. However, it is possible to access the text widget responsible for the display of text in the Aptana editors. Gaining access to this widget allows Eclipse Monkey to toggle the word wrap setting. Please note that there are known issues when word wrap is turned on.

Instructions

  1. Create a new, empty Eclipse Monkey script. See Creating a new Eclipse Monkey script for instructions.

    Name the file something related to the actual script that you want to execute (e.g. toggle_word_wrap.js). Note that Studio may insert an author comment at the top of the new file and you should delete it.

  2. Copy and paste the JavaScript below into your new file:
    /*
     * Menu: Editors > Toggle Word Wrap
     * Kudos: Kevin Lindsey (Aptana, Inc.)
     * License: EPL 1.0
     * DOM: http://download.eclipse.org/technology/dash/update/org.eclipse.eclipsemonkey.lang.javascript
     */
    
    /**
     * main
     */
    function main()
    {
            var textWidget = getTextWidget();
            
            if (textWidget)
            {
                    var setting = textWidget.getWordWrap() == false;
                    
                    textWidget.setWordWrap(setting);
                    
                    if (setting)
                    {
                            out.println("Word wrap is on");
                    }
                    else
                    {
                            out.println("Word wrap is off");
                    }
            }
    }
    
    /**
     * getTextWidget
     */
    function getTextWidget()
    {
            var result = null;
            
            try
            {
                    result = editors.activeEditor.textEditor.getViewer().getTextWidget()
            }
            catch (e)
            {
                    // fail silently
            }
            
            return result;
    }

You should now be able to execute this script using the menu item in the sample script (i.e. Scripts > Editors > Toggle Word Wrap), or any other metadata that you added on your own.

Related Topics