Author Topic: Additional Eclipse macros  (Read 1804 times)

CyberZombie

  • Community Member
  • Posts: 23
  • Hero Points: 0
Additional Eclipse macros
« on: October 07, 2011, 02:57:55 am »
Works up through 15.0.1 and verified using the 16.0 trial...

Code: [Select]
#import "box.e";
#import "clipbd.e";
#import "moveline.e";
#import "stdcmds.e";
#import "util.e";

static class Selection {
    private _str m_selectionType = null;
    private int m_startCol = 0;
    private int m_startLine = 0;
    private int m_endCol = 0;
    private int m_endLine = 0;
    private int m_currentCol = 0;
    private int m_currentLine = 0;
    private boolean m_isInclusive = false;
    private boolean m_isPersistent = false;

    private int m_windowTop = 0;
    private int m_windowBottom = 0;

    public void save() {
        m_selectionType = _select_type('', 'T');
        if (m_selectionType == null) {
            m_startCol = m_endCol = m_currentCol = p_col;
            m_startLine = m_endLine = m_currentLine = p_line;
            m_selectionType = null;
        } else {
            m_isInclusive = _select_type('', 'I') == 1;
            m_isPersistent = _select_type('', 'U') == 'P';
            m_currentCol = p_col;
            m_currentLine = p_line;
            _begin_select('', true, true);
            m_startCol = p_col;
            m_startLine = p_line;
            _end_select('', true, true);
            m_endCol = p_col;
            m_endLine = p_line;

            // restore is beginning to end. If we've selected bottom-up, need to swap these.
            if (! m_isPersistent && m_currentCol == m_startCol && m_currentLine == m_startLine) {
                int swap = m_startCol;
                m_startCol = m_endCol;
                m_endCol = swap;
                swap = m_startLine;
                m_startLine = m_endLine;
                m_endLine = swap;
            }
        }

        top_left_of_window();
        m_windowTop = p_line;
        bottom_left_of_window();
        m_windowBottom = p_line;
    }

    public void selectLines(_str style = 'ECLIPSE') {
        _deselect();
        p_line = m_startLine;
        _select_line('', 'P');
        p_line = m_endLine;
        if (style == 'ECLIPSE' && ! m_isInclusive && m_selectionType == 'CHAR' && m_endCol == 1 &&
            m_endLine > m_startLine) {
            p_line--;
        }
        _select_line('', 'P');
    }

    public void restore() {
        _deselect();
        if (m_selectionType != null) {
            p_col = m_endCol;
            p_line = m_endLine;
            _str options = 'C';
            if (m_isPersistent) {
                options = options :+ 'P';
            }
            if (m_selectionType == 'CHAR' && m_isInclusive) {
                options = options :+ 'I';
            }
            select_it(m_selectionType, '', options);
            p_col = m_startCol;
            p_line = m_startLine;
        }

        if (m_isPersistent) {
            p_col = m_currentCol;
            p_line = m_currentLine;
        }
    }

    public void delete() {
        save();
        selectLines();
        _delete_selection();
        m_currentLine = p_line;
        goto_line(m_windowTop);
        line_to_top();
        p_col = m_currentCol;
        p_line = m_currentLine;
    }

    public void moveUp() {
        save();
        selectLines();
        move_lines_up();
        _begin_select('', true, true);

        if (m_startLine > 0) {
            m_startLine--;
            m_endLine--;
            m_currentLine--;

            if (m_startLine >= m_windowTop) {
                goto_line(m_windowTop);
                line_to_top();
            }
        }

        restore();
    }

    public void moveDown() {
        save();
        selectLines();
        move_lines_down();
        _end_select('', true, true);

        if (p_line > m_endLine) {
            m_startLine++;
            m_endLine++;
            m_currentLine++;
        }

        restore();
    }

    public void comment() {
        save();
        selectLines();
        toggle_comment();
        restore();
    }

    public _str toString() {
        _str result = '';
        result = result :+ "selectionType=" :+ m_selectionType;
        result = result :+ ",startCol=" :+ m_startCol;
        result = result :+ ",startLine=" :+ m_startLine;
        result = result :+ ",endCol=" :+ m_endCol;
        result = result :+ ",endLine=" :+ m_endLine;
        result = result :+ ",currentCol=" :+ m_currentCol;
        result = result :+ ",currentLine=" :+ m_currentLine;
        result = result :+ ",isInclusive=" :+ m_isInclusive;
        result = result :+ ",isPersistent=" :+ m_isPersistent;
        return result;
    }
};

_command void eclipse_delete_lines() name_info(','VSARG2_REQUIRES_EDITORCTL|VSARG2_MARK)
{
    Selection selection;
    selection.delete();
}

_command void eclipse_move_lines_up() name_info(','VSARG2_REQUIRES_EDITORCTL|VSARG2_MARK)
{
    Selection selection;
    selection.moveUp();
}

_command void eclipse_move_lines_down() name_info(','VSARG2_REQUIRES_EDITORCTL|VSARG2_MARK)
{
    Selection selection;
    selection.moveDown();
}

_command void eclipse_toggle_comment() name_info(','VSARG2_REQUIRES_EDITORCTL|VSARG2_MARK)
{
    Selection selection;
    selection.comment();
}
« Last Edit: October 07, 2011, 03:00:10 am by CyberZombie »

lclevesy

  • Guest
Re: Additional Eclipse macros
« Reply #1 on: October 07, 2011, 12:46:35 pm »
Thank you for your submission. It is in the running for the iPad!

The winner will be announced via our Facebook page https://www.facebook.com/slickedit, Twitter page http://www.twitter.com/slickedit, and on this forum under the main SlickEdit October Macros Challenge Rules & How to Enter post http://community.slickedit.com/index.php/topic,7327.0.html on November 7, 2011.

CyberZombie

  • Community Member
  • Posts: 23
  • Hero Points: 0
Re: Additional Eclipse macros
« Reply #2 on: October 07, 2011, 11:56:52 pm »
Just to explain the purpose of this macro file. It provides better Eclipse behavior in move/delete/comment commands. I.e., no selection works on the current line. Line/char/block selections work on the lines included in the select area keeping the selection unchanged.

lclevesy

  • Guest
Re: Additional Eclipse macros
« Reply #3 on: November 01, 2011, 03:14:44 pm »
We'll be announcing the winner of the iPad 2 on November 7th. Until then, your submission has earned a SlickEdit t-shirt! Email your size and address to marketing@slickedit.com to receive one.