Skip to content
Browse files

Updated commands to work with get_string in dialog.py. You may need t…

…o update your support directory for this to work as designed.

git-svn-id: http://svn.textmate.org/trunk/Bundles/Matlab.tmbundle@10989 dfb7d73b-c2ec-0310-8fea-fb051d288c6d
  • Loading branch information...
1 parent 7607cc1 commit 7f3427d8232dccf70ca88f2be5dadac4cee6a9fc @mattfoster mattfoster committed Dec 9, 2008
Showing with 19 additions and 34 deletions.
  1. +9 −17 Commands/Introduce variable (throughout).tmCommand
  2. +10 −17 Commands/Introduce variable.tmCommand
View
26 Commands/Introduce variable (throughout).tmCommand
@@ -10,20 +10,7 @@
import sys,os
sys.path.append(os.environ['TM_SUPPORT_PATH'] + '/lib')
-import plistlib
-
-def dialog_get_string(title="", prompt=""):
- """docstring for dialog_get_string"""
- dialog = os.environ.get('DIALOG')
- nib = os.path.join(os.environ.get('TM_SUPPORT_PATH'),
- 'nibs/RequestString')
- plist = "title='%s'; prompt='%s';" % (title, prompt)
- st = """'%s' -cmp "%s" '%s' """ % (dialog, plist, nib)
- # run constructed command
- ret = os.popen(st, 'r').read()
- # Extract exit value
- plist = plistlib.readPlistFromString(ret)
- return plist['result']['returnArgument'].rstrip('\n')
+import dialog
def first_occurance(arr, str):
"""find first_occurance of str in an array of strings"""
@@ -36,7 +23,6 @@ def first_occurance(arr, str):
break
except ValueError:
pass
-
return line_no
@@ -50,12 +36,18 @@ except KeyError:
pass
else:
line_no = first_occurance(lines, sel)-1
- var = dialog_get_string('Enter new variable name', 'Variable name:')
+ try:
+ var = dialog.get_string(text='Enter new variable name',
+ prompt='Variable name:')
+ except AttributeError:
+ print '% Please update your support directory'
+ var = 'var'
for line in lines[0:line_no]:
print line.replace(sel, var),
-print '%s = %s;' % (var, sel),
+term = os.environ.get('TM_LINE_TERMINATOR') or ';'
+print '%s = %s%s\n' % (var, sel, term),
for line in lines[line_no:]:
print line.replace(sel, var),
View
27 Commands/Introduce variable.tmCommand
@@ -10,33 +10,26 @@
import sys,os
sys.path.append(os.environ['TM_SUPPORT_PATH'] + '/lib')
-import plistlib
-
-def dialog_get_string(title="", prompt=""):
- """docstring for dialog_get_string"""
- dialog = os.environ.get('DIALOG')
- nib = os.path.join(os.environ.get('TM_SUPPORT_PATH'),
- 'nibs/RequestString')
- plist = "title='%s'; prompt='%s';" % (title, prompt)
- st = """'%s' -cmp "%s" '%s' """ % (dialog, plist, nib)
- # run constructed command
- ret = os.popen(st, 'r').read()
- # Extract exit value
- plist = plistlib.readPlistFromString(ret)
- return plist['result']['returnArgument'].rstrip('\n')
+import dialog
line_no = int(os.environ.get('TM_LINE_NUMBER'))-1
-
lines = sys.stdin.readlines()
try:
sel = os.environ['TM_SELECTED_TEXT']
except KeyError:
pass
else:
- var = dialog_get_string('Enter new variable name', 'Variable name:')
+ try:
+ var = dialog.get_string(text='Enter new variable name',
+ prompt='Variable name:')
+ except AttributeError:
+ print '% Please update your support directory'
+ var = 'var'
+
+ term = os.environ.get('TM_LINE_TERMINATOR') or ';'
lines[line_no] = lines[line_no].replace(sel, var)
- lines.insert(line_no, '%s = %s;\n' % (var, sel))
+ lines.insert(line_no, '%s = %s%s\n' % (var, sel, term))
for line in lines:
print line,</string>

0 comments on commit 7f3427d

Please sign in to comment.
Something went wrong with that request. Please try again.