Monday, July 25, 2011

F4를 누르면 현재 명령라인의 파일을 옆 group에서 보여주기

다음은 한번 따라해보세요 의 연결된 포스트입니다.
현재의 라인이

>edit c:\test\test.txt

일 때, F4를 누르면 그 파일을 열어서 보여주는 코드를 썼습니다만,
여기에 덧붙여, group이 복수개 일때, 현재의 group에서 열지 않고, 그 다음 group에서 열어서 보여주는 코드로 작성해 봅니다.
※group이 하나일 때, 점점 증분해서 보여주는 디자인도 생각할 수 있습니다만, 노트북에서는 group을 두개 열어놓고 쓰기도 좁더라구요.




class CrowdyF4Command(sublime_plugin.TextCommand):
def run(self, edit):
for region in self.view.sel():
if region.empty():
curPoint = self.view.line(region)
strLine = self.view.substr(curPoint)
self.__parseCommand(strLine)
else:
lines = self.view.substr(region)

def __parseCommand(self, strLine):
p = re.compile(r"^'?#?>(.+)\s+([^\n]+)?$")
m = p.match(strLine)
if (m):
strCmd = m.group(1)
if strCmd == 'edit':
strParam = getPathChanged(m.group(2))
window = self.view.window()
if window.num_groups() > 1 :
print "window.num_groups() is " + str(window.num_groups())
print "window.active_group() is " + str(window.active_group())
current_group = window.active_group()
print "current_group is " + str(current_group)

next_group = current_group + 1
if next_group > window.num_groups() : next_group = 0
window.focus_group(next_group)

print strParam
window.open_file(strParam)
window.focus_group(current_group)
else:
window.open_file(strParam)

elif strCmd == 'close':
self.view.window().close_file()
else:
print "not defined command : " + strCmd
else:
print "no command : " + strLine


기동시키는데 부족한 나머지 코드들은 한번 따라해보세요 의 포스트에 있습니다.

왼쪽에는 큰 줄거리, 오른쪽에는 세부 줄거리.. 와 같은 구성으로 사용하시면, 소설을 쓰시는 분들에게도 꽤 쓸만한 기능이지 않을까 합니다.

No comments:

Post a Comment