Skip to content

Instantly share code, notes, and snippets.

@robertbrook
Created July 26, 2013 18:50
Show Gist options
  • Save robertbrook/6091303 to your computer and use it in GitHub Desktop.
Save robertbrook/6091303 to your computer and use it in GitHub Desktop.
# Copyright 2013, Small Picture, Inc.
op =
expand: ->
$(getActiveOutliner()).concord().op.expand()
expandAllLevels: ->
$(getActiveOutliner()).concord().op.expandAllLevels()
expandEverything: ->
$(getActiveOutliner()).concord().op.fullExpand()
expandTo: (headline) ->
expandToCursor headline
setCursorActive headline.getCursor()
collapse: ->
$(getActiveOutliner()).concord().op.collapse()
collapseEverything: ->
$(getActiveOutliner()).concord().op.fullCollapse()
go: (dir, ct) ->
op.expand() if dir is right
$(getActiveOutliner()).concord().op.go dir, ct
firstSummit: ->
op.go left, infinity
op.go up, infinity
true
countSubs: ->
$(getActiveOutliner()).concord().op.countSubs()
hasSubs: ->
op.countSubs() > 0
getLineText: ->
$(getActiveOutliner()).concord().op.getLineText()
insert: (s, direction) ->
$(getActiveOutliner()).concord().op.insert s, direction
reorg: (dir, ct) ->
$(getActiveOutliner()).concord().op.reorg dir, count
promote: ->
$(getActiveOutliner()).concord().op.promote()
demote: ->
$(getActiveOutliner()).concord().op.demote()
deleteSubs: ->
$(getActiveOutliner()).concord().op.deleteSubs()
getCursorOpml: ->
$(getActiveOutliner()).concord().op.cursorToXml()
bold: ->
$(getActiveOutliner()).concord().op.bold()
italic: ->
$(getActiveOutliner()).concord().op.italic()
strikethrough: ->
$(getActiveOutliner()).concord().op.strikethrough()
link: ->
$(getActiveOutliner()).concord().op.link()
getCursor: ->
$(getActiveOutliner()).concord().op.getCursorRef()
runSelection: ->
value = eval_(op.getLineText())
op.deleteSubs()
op.insert value, right
op.go left, 1
setModified: ->
$(getActiveOutliner()).concord().op.markChanged()
getModified: ->
$(getActiveOutliner()).concord().op.changed()
setTextMode: (fltextmode) ->
$(getActiveOutliner()).concord().op.setTextMode fltextmode
visitSubs: (lineCallback, indentCallback, outdentCallback) ->
levelnum = 0
visitSub = (sub) ->
lineCallback sub, levelnum
if sub.countSubs() > 0
indentCallback() unless indentCallback is `undefined`
levelnum++
sub.visitLevel visitSub
levelnum--
outdentCallback() unless outdentCallback is `undefined`
true
op.getCursor().visitLevel visitSub
visitAll: (callback) ->
$(getActiveOutliner()).concord().op.visitAll callback
visitToSummit: (callback) ->
$(getActiveOutliner()).concord().op.visitToSummit callback
attributes:
getAll: ->
$(getActiveOutliner()).concord().op.attributes.getAll()
getOne: (name) ->
$(getActiveOutliner()).concord().op.attributes.getOne name
setOne: (name, value) ->
$(getActiveOutliner()).concord().op.attributes.setOne name, value
addGroup: (atts) ->
$(getActiveOutliner()).concord().op.attributes.setGroup atts
deleteOne: (name) ->
atts = op.attributes.getAll()
delete atts[name] unless atts[name] is `undefined`
op.attributes.addGroup atts
makeEmpty: ->
atts = new Object()
op.attributes.addGroup atts
script =
isComment: ->
isComment = op.attributes.getOne("isComment")
if (isComment is `undefined`) or (isComment is "false")
false
else
true
unComment: ->
op.attributes.deleteOne "isComment" if script.isComment()
makeComment: ->
op.attributes.setOne "isComment", "true"
toggleComment: ->
if script.isComment()
script.unComment()
else
script.makeComment()
number = random: (lower, upper) ->
random lower, upper
file =
readWholeFile: (path, callback) ->
vendor.read path, callback
writeWholeFile: (path, data, callback) ->
vendor.write path, data, callback
getCurrentFilePath: ->
tab = smallTabs.getActiveTab()
tab.url
getCurrentFileTitle: ->
tab = smallTabs.getActiveTab()
tab.getTitle()
getPublicUrl: (path, callback) ->
vendor.createSharedUrl path, callback
getDatePath: (theDate, flLastSeparator) ->
theDate = new Date() if theDate is `undefined`
flLastSeparator = true if flLastSeparator is `undefined`
month = padWithZeros(theDate.getMonth() + 1, 2)
day = padWithZeros(theDate.getDate(), 2)
year = theDate.getFullYear()
if flLastSeparator
year + "/" + month + "/" + day + "/"
else
year + "/" + month + "/" + day
string =
innerCaseName: (s) ->
getCanonicalName s
dayOfWeekToString: (theDayNum) ->
dayOfWeekToString theDayNum - 1
monthToString: (theMonthNum) -> #January, February etc.
monthToString theMonthNum - 1
isAlpha: (ch) ->
isAlpha ch
isNumeric: (ch) ->
isNumeric ch
getRandomPassword: (ctchars) ->
getRandomPassword ctchars
filledString: (s, ct) ->
theString = ""
i = 0
while i < ct
theString += s
i++
theString
trimLeading: (s, ch) ->
ch = " " if ch is `undefined`
trimLeading s, ch
trimTrailing: (s, ch) ->
ch = " " if ch is `undefined`
trimTrailing s, ch
padWithZeros: (num, ctplaces) ->
padWithZeros num, ctplaces
mid: (s, ix, len) ->
s.substr ix - 1, len
countFields: (s, chdelim) ->
ct = 1
return (0) if s.length is 0
i = 0
while i < s.length
ct++ if s[i] is chdelim
i++
ct
nthField: (s, chdelim, n) ->
splits = s.split(chdelim)
return splits[n - 1] if splits.length >= n
""
stripMarkup: (s) ->
stripMarkup s
dialog =
alert: (s) ->
alertDialog s
ask: (prompt, defaultValue, placeholder, callback) ->
askDialog prompt, defaultValue, placeholder, callback
viewText: (prompt, s) ->
showViewTextDialog prompt, s
confirm: (prompt, callback) ->
confirmDialog prompt, callback
clock =
now: ->
new Date()
waitSeconds: (ctsecs) ->
ctloops = 0
whenStart = new Date()
while secondsSince(whenStart) < ctsecs
ctloops++
ctloops
ctloops
speaker = beep: ->
speakerBeep()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment