Welcome, Guest. Please Login or Register.
eccoMAGIC Forums
05/25/18 at 09:54:53
Home Help Search Login Register


Pages: 1
Send Topic Print
  Rating
Rate:
Rating:
Rating: 10.00
Votes: 1

5
4
3
2
1










1

5
4
3
2
1


1


2


3


4


5


6


7


8


9


10

Auto 'sort' sub-items to different parent items (Popularity: 3788 )
Admin
Administrator
*****


I love Ecco!

Posts: 113
Show the link to this post Auto 'sort' sub-items to different parent items
10/16/12 at 08:50:24
 

This fantastic script was posted by phkiefer at http://tech.groups.yahoo.com/group/ecco_pro/message/12252 :
 
The idea for this came from my experimenting with the BrainStormSW outliner.
I've decided against adopting it as Ecco can so much more, but since this
particular BSSW feature was missing from Ecco and since Slang's
set_item_parent() function has made it so easy to implement, I came up with this
script. I'm just an amateur programmer, so don't expect perfection and feel free
to suggest any improvements. I'm sure some bugs will need to be weeded out, some
more precautions put in etc.
 
Be sure to backup your file(s) before you try it - or preferably try it out on a
dummy file first.
 
 
How to get started:
Naturally, EccoExt is required for it to work. To set it up
  • copy the function of this post into the luacmd.lua file in your Ecco folder.  
    For first experimentation, bring up EccoExt's expression evaluator (right-click on EE tray icon and select from the context menu).  
     
  • Make sure "Lua" is selected in the dropdown list.  
     
  • Clear the edit box or comment out all existing entries by preceding each line with "-- ".  
     
  • At the top, type in "SortToParent()" without the quotes.  
     
  • Drag the dialog window out of the way. Now read on below about what the script does. When you're ready to try it out,  
     
  • select an item in the Ecco file and change it according to what you want to do.  
     
  • Make sure the cursor is still placed on the item, then go back to the dialog and click the "Eval" button.

 
What the function does:
 
1. To make an item a parent item that other items can be sorted under, add an
equals symbol plus a single digit at the beginning of the item's text. Say you
have an item called "First parent". Change the item text to "=1First parent".
Then execute the function (see above). The "=1" will disappear and the "First
parent" item is now marked to be sorting parent destination number "1". The
function will remember this between sessions by writing the item's ID to a file
in the same folder and with the same name as your currently open .eco file, but
with the extension ".srt". You can use all digits from 0 to 9, so you can sort
under up to 10 different parent items.
 
2. To sort items under any parents marked in the way described above, add a
single digit at the start of the item's text, this time without the preceding
"=". E.g., change "First child" to "1First child", execute the function and -
ZOOM - the digit will be removed and the item moved to just under the item
marked as sort parent number "1". The cursor now sits at the beginning of the
next item. To move this to the same location, just type 1 and execute the
function. Or use any other digit to send it under a different parent.
 
This can be extremely useful when sorting collections of ideas into an outline,
after either a keyboard brainstorming session in Ecco or importing notes from
other applications / a mobile device (Let's all hope CompanionLink will really
offer an Ecco product soon!) or when sorting stuff that was lazily dumped
somewhere to be sorted some other time.
 

Setting up a hotkey:

 
If you want to use the function regularly, I suggest you call it via a hotkey:
Click "Tools|Launch|Manage Launch Menu..." in Ecco's menu bar. Create a new
launch item. Make sure "Launch as:" is set to "Document", not "Program". In the
"Command:" edit box, enter: "LUAScript: SortToParent()". Now count the items in
the "Manage Tools Menu" dialog and remember which position the new entry you
just created is in. Then right-click EE's tray icon and select EccoExt
Options... Go to the "ShortCut" tab and select "Tool" from the dropdown list.
Scroll down and click on "Launch Menu Item X", X being the position of your
newly created launch item in the dialog above. Enter the desired shortcut in the
"New shortcut" edit box and click the "Assign" button.
 
Okay, here comes the code:
 
Code:
function SortToParent()

-- Get selected item's properties:
itemID = get_current_item()
itemText = get_item_text(itemID)

-- Determine name for .srt file based on currently loaded .eco file:
local ecoPath = get_cur_filename()
local ecoName
ecoName = string.sub(ecoPath, 1, -5)
ecoName = string.match(ecoName, ".+\\(.+)") .. ".srt"

-- If exists, open .srt file for reading and read item IDs for parents into
table:
local srtHnd = io.open(ecoName)
local parentID = {}
if srtHnd then
local i = 0
for line in io.lines(ecoName) do
parentID[i] = line
i = i + 1
if i > 9 then
break
end
end
else
for i = 0, 9, 1 do
parentID[i] = 0
end
end

-- Set new parent item ID for sorting if item text starts with '=' + single
digit:
if string.match(itemText, "=%d") then
local sortNumber = tonumber(string.sub(itemText, 2, 2))
parentID[sortNumber] = itemID

-- Upate .srt file with new parent ID
local srtHnd = io.open(ecoName, "w")
local i
for i = 0, 9, 1 do
srtHnd:write(parentID[i] .. "\n")
end
io.close(srtHnd)

set_item_text(itemID, string.sub(itemText, 3)) -- remove added prefix

-- Set item to be child of parent indicated by single digit at start of item
text:
elseif string.match(itemText, "%d") then
local sortNumber = tonumber(string.sub(itemText, 1, 1))
if get_item_type(parentID[sortNumber]) == 1 then
set_item_text(itemID, string.sub(itemText, 2)) -- remove added prefix
set_item_parent(itemID, parentID[sortNumber])
else
msgbox("Intended parent number has not been assigned.")
error()
end

else
msgbox("Selected item's text doesn't have the required syntax.")
error()
end
end 

Back to top
 
 

The Administrator.
WWW   IP Logged
Pages: 1
Send Topic Print