mirror of
https://github.com/python/cpython.git
synced 2025-11-11 14:44:57 +00:00
Completely revamped newline handling. PyEdit is now newline-preserving
(if a single newline convention is used in the sourcefile), and the "save options" has a newline style radio button. The creator radio button also has the new choices PythonW and None. Just: just shout (and revert) if you don't agree.
This commit is contained in:
parent
e0ba087d44
commit
9a38947fba
1 changed files with 55 additions and 20 deletions
|
|
@ -51,6 +51,7 @@ class Editor(W.Window):
|
||||||
_scriptuntitledcounter = _scriptuntitledcounter + 1
|
_scriptuntitledcounter = _scriptuntitledcounter + 1
|
||||||
text = ""
|
text = ""
|
||||||
self._creator = W._signature
|
self._creator = W._signature
|
||||||
|
self._eoln = os.linesep
|
||||||
elif os.path.exists(path):
|
elif os.path.exists(path):
|
||||||
path = resolvealiases(path)
|
path = resolvealiases(path)
|
||||||
dir, name = os.path.split(path)
|
dir, name = os.path.split(path)
|
||||||
|
|
@ -67,18 +68,14 @@ class Editor(W.Window):
|
||||||
if '\n' in text:
|
if '\n' in text:
|
||||||
import EasyDialogs
|
import EasyDialogs
|
||||||
if string.find(text, '\r\n') >= 0:
|
if string.find(text, '\r\n') >= 0:
|
||||||
sourceOS = 'DOS'
|
self._eoln = '\r\n'
|
||||||
searchString = '\r\n'
|
|
||||||
else:
|
else:
|
||||||
sourceOS = 'UNIX'
|
self._eoln = '\n'
|
||||||
searchString = '\n'
|
text = string.replace(text, self._eoln, '\r')
|
||||||
change = EasyDialogs.AskYesNoCancel('"%s" contains %s-style line feeds. '
|
change = 0
|
||||||
'Change them to MacOS carriage returns?' % (self.title, sourceOS), 1)
|
|
||||||
# bug: Cancel is treated as No
|
|
||||||
if change > 0:
|
|
||||||
text = string.replace(text, searchString, '\r')
|
|
||||||
else:
|
else:
|
||||||
change = 0
|
change = 0
|
||||||
|
self._eoln = '\r'
|
||||||
|
|
||||||
self.settings = {}
|
self.settings = {}
|
||||||
if self.path:
|
if self.path:
|
||||||
|
|
@ -318,10 +315,11 @@ class Editor(W.Window):
|
||||||
self.editgroup.editor.settabsettings(tabsettings)
|
self.editgroup.editor.settabsettings(tabsettings)
|
||||||
|
|
||||||
def domenu_options(self, *args):
|
def domenu_options(self, *args):
|
||||||
rv = SaveOptions(self._creator)
|
rvcreator, rveoln = SaveOptions(self._creator, self._eoln)
|
||||||
if rv:
|
if rvcreator != self._creator or rveoln != self._eoln:
|
||||||
self.editgroup.editor.selectionchanged() # ouch...
|
self.editgroup.editor.selectionchanged() # ouch...
|
||||||
self._creator = rv
|
self._creator = rvcreator
|
||||||
|
self._eoln = rveoln
|
||||||
|
|
||||||
def clicklinefield(self):
|
def clicklinefield(self):
|
||||||
if self._currentwidget <> self.linefield:
|
if self._currentwidget <> self.linefield:
|
||||||
|
|
@ -383,6 +381,8 @@ class Editor(W.Window):
|
||||||
# Will call us recursively
|
# Will call us recursively
|
||||||
return self.domenu_save_as()
|
return self.domenu_save_as()
|
||||||
data = self.editgroup.editor.get()
|
data = self.editgroup.editor.get()
|
||||||
|
if self._eoln != '\r':
|
||||||
|
data = string.replace(data, '\r', self._eoln)
|
||||||
fp = open(self.path, 'wb') # open file in binary mode, data has '\r' line-endings
|
fp = open(self.path, 'wb') # open file in binary mode, data has '\r' line-endings
|
||||||
fp.write(data)
|
fp.write(data)
|
||||||
fp.close()
|
fp.close()
|
||||||
|
|
@ -744,15 +744,18 @@ class Editor(W.Window):
|
||||||
|
|
||||||
class _saveoptions:
|
class _saveoptions:
|
||||||
|
|
||||||
def __init__(self, creator):
|
def __init__(self, creator, eoln):
|
||||||
self.rv = None
|
self.rv = None
|
||||||
self.w = w = W.ModalDialog((240, 140), 'Save options')
|
self.eoln = eoln
|
||||||
|
self.w = w = W.ModalDialog((260, 160), 'Save options')
|
||||||
radiobuttons = []
|
radiobuttons = []
|
||||||
w.label = W.TextBox((8, 8, 80, 18), "File creator:")
|
w.label = W.TextBox((8, 8, 80, 18), "File creator:")
|
||||||
w.ide_radio = W.RadioButton((8, 22, 160, 18), "This application", radiobuttons, self.ide_hit)
|
w.ide_radio = W.RadioButton((8, 22, 160, 18), "This application", radiobuttons, self.ide_hit)
|
||||||
w.interp_radio = W.RadioButton((8, 42, 160, 18), "Python Interpreter", radiobuttons, self.interp_hit)
|
w.interp_radio = W.RadioButton((8, 42, 160, 18), "MacPython Interpreter", radiobuttons, self.interp_hit)
|
||||||
w.other_radio = W.RadioButton((8, 62, 50, 18), "Other:", radiobuttons)
|
w.interpx_radio = W.RadioButton((8, 62, 160, 18), "OSX PythonW Interpreter", radiobuttons, self.interpx_hit)
|
||||||
w.other_creator = W.EditText((62, 62, 40, 20), creator, self.otherselect)
|
w.other_radio = W.RadioButton((8, 82, 50, 18), "Other:", radiobuttons)
|
||||||
|
w.other_creator = W.EditText((62, 82, 40, 20), creator, self.otherselect)
|
||||||
|
w.none_radio = W.RadioButton((8, 102, 160, 18), "None", radiobuttons, self.none_hit)
|
||||||
w.cancelbutton = W.Button((-180, -30, 80, 16), "Cancel", self.cancelbuttonhit)
|
w.cancelbutton = W.Button((-180, -30, 80, 16), "Cancel", self.cancelbuttonhit)
|
||||||
w.okbutton = W.Button((-90, -30, 80, 16), "Done", self.okbuttonhit)
|
w.okbutton = W.Button((-90, -30, 80, 16), "Done", self.okbuttonhit)
|
||||||
w.setdefaultbutton(w.okbutton)
|
w.setdefaultbutton(w.okbutton)
|
||||||
|
|
@ -760,8 +763,25 @@ class _saveoptions:
|
||||||
w.interp_radio.set(1)
|
w.interp_radio.set(1)
|
||||||
elif creator == W._signature:
|
elif creator == W._signature:
|
||||||
w.ide_radio.set(1)
|
w.ide_radio.set(1)
|
||||||
|
elif creator == 'PytX':
|
||||||
|
w.interpx_radio.set(1)
|
||||||
|
elif creator == '\0\0\0\0':
|
||||||
|
w.none_radio.set(1)
|
||||||
else:
|
else:
|
||||||
w.other_radio.set(1)
|
w.other_radio.set(1)
|
||||||
|
|
||||||
|
w.eolnlabel = W.TextBox((168, 8, 80, 18), "Newline style:")
|
||||||
|
radiobuttons = []
|
||||||
|
w.unix_radio = W.RadioButton((168, 22, 80, 18), "Unix", radiobuttons, self.unix_hit)
|
||||||
|
w.mac_radio = W.RadioButton((168, 42, 80, 18), "Macintosh", radiobuttons, self.mac_hit)
|
||||||
|
w.win_radio = W.RadioButton((168, 62, 80, 18), "Windows", radiobuttons, self.win_hit)
|
||||||
|
if self.eoln == '\n':
|
||||||
|
w.unix_radio.set(1)
|
||||||
|
elif self.eoln == '\r\n':
|
||||||
|
w.win_radio.set(1)
|
||||||
|
else:
|
||||||
|
w.mac_radio.set(1)
|
||||||
|
|
||||||
w.bind("cmd.", w.cancelbutton.push)
|
w.bind("cmd.", w.cancelbutton.push)
|
||||||
w.open()
|
w.open()
|
||||||
|
|
||||||
|
|
@ -771,6 +791,12 @@ class _saveoptions:
|
||||||
def interp_hit(self):
|
def interp_hit(self):
|
||||||
self.w.other_creator.set("Pyth")
|
self.w.other_creator.set("Pyth")
|
||||||
|
|
||||||
|
def interpx_hit(self):
|
||||||
|
self.w.other_creator.set("PytX")
|
||||||
|
|
||||||
|
def none_hit(self):
|
||||||
|
self.w.other_creator.set("\0\0\0\0")
|
||||||
|
|
||||||
def otherselect(self, *args):
|
def otherselect(self, *args):
|
||||||
sel_from, sel_to = self.w.other_creator.getselection()
|
sel_from, sel_to = self.w.other_creator.getselection()
|
||||||
creator = self.w.other_creator.get()[:4]
|
creator = self.w.other_creator.get()[:4]
|
||||||
|
|
@ -779,16 +805,25 @@ class _saveoptions:
|
||||||
self.w.other_creator.setselection(sel_from, sel_to)
|
self.w.other_creator.setselection(sel_from, sel_to)
|
||||||
self.w.other_radio.set(1)
|
self.w.other_radio.set(1)
|
||||||
|
|
||||||
|
def mac_hit(self):
|
||||||
|
self.eoln = '\r'
|
||||||
|
|
||||||
|
def unix_hit(self):
|
||||||
|
self.eoln = '\n'
|
||||||
|
|
||||||
|
def win_hit(self):
|
||||||
|
self.eoln = '\r\n'
|
||||||
|
|
||||||
def cancelbuttonhit(self):
|
def cancelbuttonhit(self):
|
||||||
self.w.close()
|
self.w.close()
|
||||||
|
|
||||||
def okbuttonhit(self):
|
def okbuttonhit(self):
|
||||||
self.rv = self.w.other_creator.get()[:4]
|
self.rv = (self.w.other_creator.get()[:4], self.eoln)
|
||||||
self.w.close()
|
self.w.close()
|
||||||
|
|
||||||
|
|
||||||
def SaveOptions(creator):
|
def SaveOptions(creator, eoln):
|
||||||
s = _saveoptions(creator)
|
s = _saveoptions(creator, eoln)
|
||||||
return s.rv
|
return s.rv
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue