Wednesday, March 30, 2011

One-click editor splitting in Eclipse

[Note: Does not work in Eclipse 4.x]
UPDATE: Eclipse Luna 4.4 M4 now supports editor splitting... NEW and NOTEWORTHY.

You may know that one can split layout the editors in Eclipse by dragging the editor tab to any edge of the editor area. This works only if you have more than one editor. However there are times when I want to work on two parts of the same file. To do that I first do Window > New Editor to duplicate the editor and then drag it to split the editor in a side-by-side or top-bottom layout. But that is too many clicks and drags. I developed a simple Eclipse Plugin which will help you split the active editor either horizontally or vertically with a single click. It is based on some code I found here that was written by Dimitri Missoh (thanks Dimitri - I have given you credit in the source code of the plug-in). I adapted his code to suite our purpose.

Here is the screenshot:


Split Editor Plug-in is available on Eclipse Marketplace!

You can install it from the plug-in's update site:

http://sandipchitaleseclipseplugins.googlecode.com/svn/trunk/SplitEditorFeatureUpdateSite

Source code is here.

Works in Eclipse 3.4, 3.5, 3.6, 3.7 and 3.8.

Also available on Eclipse Marketplace.

Enjoy!

Tuesday, March 15, 2011

XCode: Corrected user scripts - Delete Line, Copy/Move line Up/Down

[Note: It is a shame that XCode 4 does not have the Scripts menu]

XCode has the following scripts:
  • Delete Line
  • Move Line Up
  • Move Line Down
I added two more (as described in this post):
  • Copy Line Up
  • Copy Line Down
However there was a problem. The script always worked on the first text document. That meant that when you had multiple documents open, the commands sometimes modified the document which did not have focus (baaad!).

It turns out the window 1 is always the window which has the focus. I corrected the scripts to make use of this fact. Here is the general strategy behind the modifications I made to the scripts:
:
:
using terms from application "Xcode"
 set selectedDocument to missing value
 repeat with index from 1 to (count of text documents)
  if (associated file name of window 1 as string) is equal to (path of text document index) then
   -- found the document
   set selectedDocument to (text document index)
   exit repeat
  end if
 end repeat
 if (selectedDocument is not missing value) then
  tell selectedDocument
   -- do the modifications to document
  end tell
 else
  beep 1
 end if
end using terms from

Download the scripts here. Just unzip and drop the scripts in /Developer/Library/Xcode/User Scripts/ .

I have filed a bug at http://radar.apple.com for this. The problem Id is 9138643. I have attached the fixed scripts to the problem.

Wednesday, March 09, 2011

XCode: Copy/Move Up/Down line


[Note: Please see this post for corrected scripts]

XCode already has the following scripts under Script Menu > Text
  • Delete Line
  • Move Line Up
  • Move Line Down
I added the following two scripts:
  • Copy Line Up
  • Copy Line Down
Basically I started by creating the following Applescript files:

/Developer/Library/Xcode/User Scripts/Copy Line Up.scpt with content:

--
(*
To edit this script, choose Save As... and save it in your home directory, then re-add it to the User Scripts list.
*)
using terms from application "Xcode"
tell first text document
set {startLine, endLine} to selected paragraph range
if startLine > 1 then
set theText to (paragraphs startLine through endLine)
set theText to (theText as string)
make new paragraph at beginning of paragraph (startLine) with data theText
set selected paragraph range to {startLine, endLine}
else
beep 1
end if
end tell
end using terms from
--

/Developer/Library/Xcode/User Scripts/Copy Line Down.scpt with content:

--
(*
To edit this script, choose Save As... and save it in your home directory, then re-add it to the User Scripts list.
*)
using terms from application "Xcode"
tell first text document
set {startLine, endLine} to selected paragraph range
if endLine < (count paragraphs) then
set theText to (paragraphs startLine through endLine)
set theText to (theText as string)
make new paragraph at beginning of paragraph (startLine + 1) with data theText
set selected paragraph range to {endLine + 1, endLine + 1}
else
beep 1
end if
end tell
end using terms from
--

and then added those scripts using the Script Menu > Edit User Scripts... dialog.


While I was at it I added the following keybindings:

Delete Line Command+D
Move Line Up Alt+UP
Copy Line Up Control+Alt+UP
Move Line Down Alt+Down
Copy Line Down Control+Alt+Down

Note: The Command+D keybinding for Delete Line conflicts with the default Add Bookmark keybinding. I changed that keybinding to something else in Preference > Key Bindings > Menu Key Bindings > Edit section.

Here is the screenshot:


Now I have my LineTools NetBeans plugin like functionality in XCode. Yay!