Skip to content

Instantly share code, notes, and snippets.

@legendmohe
Created October 21, 2014 02:24
Show Gist options
  • Save legendmohe/d5d3b4608f163ec8025f to your computer and use it in GitHub Desktop.
Save legendmohe/d5d3b4608f163ec8025f to your computer and use it in GitHub Desktop.
#SingleInstance Force
#Persistent
src_objects := []
src_indexs =
Gui, Add, Edit, r25 w350 vMyEdit -Wrap HScroll VScroll
return
#v::
Send ^c
cur_src := Clipboard
last_src := src_objects.MaxIndex()
msg = [last]`n%last_src%
InputBox, content, src tree, %msg%,,,140
if(content && !ErrorLevel && cur_src) {
StringGetPos, plus_pos, content, +
StringGetPos, minus_pos, content, -
if(minus_pos = 0) {
StringTrimLeft, content, content, % minus_pos + 1
if(src_objects[content] = "") {
return
}
src_objects[content] := ""
remove_src_indexs(content)
}
else if(plus_pos = 0) {
StringTrimLeft, content, content, % plus_pos + 1
if(src_objects[content] = "") {
return
}
last_content := src_objects[content]["content"]
src_objects[content]["content"] := last_content . "`n" . insert_node_header(cur_src)
}else {
if(src_objects[content] = "") {
src_indexs := src_indexs . content . "`n"
}
WinGetTitle, title, A
title := parse_src_title(title)
src_objects[content] := {"title":title, "content":cur_src}
}
refresh_list()
}
return
#b::
Gui +LastFound +AlwaysOnTop +ToolWindow
WinSet, Transparent, 200,
Gui, Show
return
remove_src_indexs(target) {
global src_indexs
content := ""
Loop, parse, src_indexs, `n
{
if (A_LoopField != target) {
content := content . A_LoopField . "`n"
}
}
src_indexs := content
}
insert_node_header(cur_src) {
space := ""
pos := RegExMatch(cur_src, "[^\s]")
if (pos != 0){
Loop, %pos% {
space := space . " "
}
space := space . "...`n"
}
return space . cur_src
}
parse_src_title(title) {
StringGetPos, pos, title, -
pos := StrLen(title) - pos + 1
if pos >= 0
StringTrimRight, title, title, pos
return title
}
refresh_list() {
global src_objects
global src_indexs
Sort, src_indexs
content := ""
Loop, parse, src_indexs, `n
{
val := A_LoopField
if (val != "") {
title := src_objects[val]["title"]
src_content := left_aline(src_objects[val]["content"])
intented_content := "[#" . val . " " . title . " ]" . "`n `n" . src_content . "`n `n"
intented_content := insert_intent(val, intented_content)
content := content . intented_content
}
}
GuiControl,, MyEdit, %content%
}
left_aline(src) {
content := ""
pos := 0
min := 10000
Loop, parse, src, `n
{
if (A_LoopField != "")
{
pos := RegExMatch(A_LoopField, "[^\s]")
if (pos != 0 && pos < min){
min := pos
}
}
}
min -= 1
content := ""
Loop, parse, src, `n
{
if (Trim(A_LoopField) != "")
{
line := A_LoopField
StringTrimLeft, line, line, min
content := content . line . "`n"
}
}
return content
}
insert_intent(head, src) {
content := ""
StringReplace, head, head, -, -, UseErrorLevel
intent := ""
Loop % ErrorLevel
{
intent := intent . "| "
}
Loop, parse, src, `n
{
if (A_LoopField != "")
if (A_Index == 1){
content := content . intent . A_LoopField . "`n"
}
else {
content := content . intent . "| " . A_LoopField . "`n"
}
}
return content
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment