六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 71|回复: 0

[UliPad]wxSnip in UliPad

[复制链接]

升级  36%

4

主题

4

主题

4

主题

童生

Rank: 1

积分
18
 楼主| 发表于 2013-1-27 06:03:16 | 显示全部楼层 |阅读模式
Thanks Kibleur C. (http://kib2.webfactional.com/) for his wxSnip package, and I'v ported it into UliPad, you can get the lastest code from svn (http://cvs.woodpecker.org.cn/svn/woodpecker/ulipad/trunk). But wxSnip is not very suit for UliPad, because UliPad has its own InputAssistant functionality, so I changed wxSnip code and made it more suitable for UliPad. The source file in UliPad is named mixins/SnipMixin.py. And I made a SnipMixin class, it receives a `editor` argument, and not like in wxSnipEdit.py it's  SnipEditor. So I can merge this class into my own StyledTextCtrl object. And I also don't need the adding template string process, because InputAssistant functionality can do this, but I indeed fixed the indent bug when adding template string according wxSnipEdit. And I trigger the process of snippet field outside the SnipMixin class, so I bind the key_down event in my own editor class but not in SnipEditor class. So there are two method which I need to call:
start(self, tpl, start, end)
this function will be invoked after adding template string, and it comes from insertSnippet() method of SnipEditor, and it'll auto invoke the nextField() method.
nextField(self, pos)
this function will be invoked after you pressing the trigger keystroke Ctrl+] now.
And the snippet template is defined in a ACP(Auto Completion Pattern) file, you can find in conf folder of UliPad. Each syntax has such a file, such as Python.acp. For now, I made some example in python.acp, you can see:
[autore]
(^\s*)def<space> = \\1def ${1:method_name}(${2:}):\n\t'''${3:}'''\n\t${0}
(^\s*)cdef<space> = \\1def ${1:method_name}(self, ${2:}):\n\t'''${3:}'''\n\t${0}
The acp file is a ini-like file. If the value is quoted by double-quoter("), then it's just like a python string. If there is not, it just like a raw string. Notice, if there is a ',' in the string, you should quote it by double-quoter, just like:
"ab,cd"
If you don't quote it, it'll be treate as a list. So you'll see a popup list when the pattern is matched. And for keys, there are some special character representations just like: <space> (' '), <equal> ('='), <div> ('/'), <square> ('['), etc
<div class="feedflare">
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表