-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckbox Helper.py
More file actions
42 lines (36 loc) · 1.04 KB
/
Checkbox Helper.py
File metadata and controls
42 lines (36 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from Npp import *
import string
import sys
# A simple helper script for using ASCII todo lists
# The basic implementation knows 3 different states
# [ ] To Do
# [x] Done
# [o] Currently not possible to do
#
# The script is able to toggle between this states. If
# you want only two states or if you want more states
# just edit the checkboxes string list.
#
# If a line doesn't contain a checkbox the script
# just inserts one at the current position.
def nextElem(arr, curPos):
if (curPos + 1 < len(arr)):
return arr[curPos + 1]
else:
return arr[0]
checkboxes = ['[ ]', '[x]', '[o]']
curLine = editor.getCurLine()
curPos = editor.getCurrentPos()
curLineNr = editor.lineFromPosition(curPos)
strippedLine = curLine.lstrip()
insertChkBx = True
for i in range(len(checkboxes)):
elem = checkboxes[i]
if strippedLine.startswith(elem):
curLine = curLine.replace(elem, nextElem(checkboxes, i), 1).rstrip('\n')
editor.replaceWholeLine(curLineNr, curLine)
editor.gotoPos(curPos)
insertChkBx = False
break
if(insertChkBx):
editor.addText('[ ] ')