@@ -51,6 +51,7 @@ def __init__(self, path = "", title = ""):
5151 _scriptuntitledcounter = _scriptuntitledcounter + 1
5252 text = ""
5353 self ._creator = W ._signature
54+ self ._eoln = os .linesep
5455 elif os .path .exists (path ):
5556 path = resolvealiases (path )
5657 dir , name = os .path .split (path )
@@ -67,18 +68,14 @@ def __init__(self, path = "", title = ""):
6768 if '\n ' in text :
6869 import EasyDialogs
6970 if string .find (text , '\r \n ' ) >= 0 :
70- sourceOS = 'DOS'
71- searchString = '\r \n '
71+ self ._eoln = '\r \n '
7272 else :
73- sourceOS = 'UNIX'
74- searchString = '\n '
75- change = EasyDialogs .AskYesNoCancel ('"%s" contains %s-style line feeds. '
76- 'Change them to MacOS carriage returns?' % (self .title , sourceOS ), 1 )
77- # bug: Cancel is treated as No
78- if change > 0 :
79- text = string .replace (text , searchString , '\r ' )
73+ self ._eoln = '\n '
74+ text = string .replace (text , self ._eoln , '\r ' )
75+ change = 0
8076 else :
8177 change = 0
78+ self ._eoln = '\r '
8279
8380 self .settings = {}
8481 if self .path :
@@ -318,10 +315,11 @@ def domenu_fontsettings(self, *args):
318315 self .editgroup .editor .settabsettings (tabsettings )
319316
320317 def domenu_options (self , * args ):
321- rv = SaveOptions (self ._creator )
322- if rv :
318+ rvcreator , rveoln = SaveOptions (self ._creator , self . _eoln )
319+ if rvcreator != self . _creator or rveoln != self . _eoln :
323320 self .editgroup .editor .selectionchanged () # ouch...
324- self ._creator = rv
321+ self ._creator = rvcreator
322+ self ._eoln = rveoln
325323
326324 def clicklinefield (self ):
327325 if self ._currentwidget <> self .linefield :
@@ -383,6 +381,8 @@ def domenu_save(self, *args):
383381 # Will call us recursively
384382 return self .domenu_save_as ()
385383 data = self .editgroup .editor .get ()
384+ if self ._eoln != '\r ' :
385+ data = string .replace (data , '\r ' , self ._eoln )
386386 fp = open (self .path , 'wb' ) # open file in binary mode, data has '\r' line-endings
387387 fp .write (data )
388388 fp .close ()
@@ -744,24 +744,44 @@ def selectline(self, lineno, charoffset = 0):
744744
745745class _saveoptions :
746746
747- def __init__ (self , creator ):
747+ def __init__ (self , creator , eoln ):
748748 self .rv = None
749- self .w = w = W .ModalDialog ((240 , 140 ), 'Save options' )
749+ self .eoln = eoln
750+ self .w = w = W .ModalDialog ((260 , 160 ), 'Save options' )
750751 radiobuttons = []
751752 w .label = W .TextBox ((8 , 8 , 80 , 18 ), "File creator:" )
752753 w .ide_radio = W .RadioButton ((8 , 22 , 160 , 18 ), "This application" , radiobuttons , self .ide_hit )
753- w .interp_radio = W .RadioButton ((8 , 42 , 160 , 18 ), "Python Interpreter" , radiobuttons , self .interp_hit )
754- w .other_radio = W .RadioButton ((8 , 62 , 50 , 18 ), "Other:" , radiobuttons )
755- w .other_creator = W .EditText ((62 , 62 , 40 , 20 ), creator , self .otherselect )
754+ w .interp_radio = W .RadioButton ((8 , 42 , 160 , 18 ), "MacPython Interpreter" , radiobuttons , self .interp_hit )
755+ w .interpx_radio = W .RadioButton ((8 , 62 , 160 , 18 ), "OSX PythonW Interpreter" , radiobuttons , self .interpx_hit )
756+ w .other_radio = W .RadioButton ((8 , 82 , 50 , 18 ), "Other:" , radiobuttons )
757+ w .other_creator = W .EditText ((62 , 82 , 40 , 20 ), creator , self .otherselect )
758+ w .none_radio = W .RadioButton ((8 , 102 , 160 , 18 ), "None" , radiobuttons , self .none_hit )
756759 w .cancelbutton = W .Button ((- 180 , - 30 , 80 , 16 ), "Cancel" , self .cancelbuttonhit )
757760 w .okbutton = W .Button ((- 90 , - 30 , 80 , 16 ), "Done" , self .okbuttonhit )
758761 w .setdefaultbutton (w .okbutton )
759762 if creator == 'Pyth' :
760763 w .interp_radio .set (1 )
761764 elif creator == W ._signature :
762765 w .ide_radio .set (1 )
766+ elif creator == 'PytX' :
767+ w .interpx_radio .set (1 )
768+ elif creator == '\0 \0 \0 \0 ' :
769+ w .none_radio .set (1 )
763770 else :
764771 w .other_radio .set (1 )
772+
773+ w .eolnlabel = W .TextBox ((168 , 8 , 80 , 18 ), "Newline style:" )
774+ radiobuttons = []
775+ w .unix_radio = W .RadioButton ((168 , 22 , 80 , 18 ), "Unix" , radiobuttons , self .unix_hit )
776+ w .mac_radio = W .RadioButton ((168 , 42 , 80 , 18 ), "Macintosh" , radiobuttons , self .mac_hit )
777+ w .win_radio = W .RadioButton ((168 , 62 , 80 , 18 ), "Windows" , radiobuttons , self .win_hit )
778+ if self .eoln == '\n ' :
779+ w .unix_radio .set (1 )
780+ elif self .eoln == '\r \n ' :
781+ w .win_radio .set (1 )
782+ else :
783+ w .mac_radio .set (1 )
784+
765785 w .bind ("cmd." , w .cancelbutton .push )
766786 w .open ()
767787
@@ -771,6 +791,12 @@ def ide_hit(self):
771791 def interp_hit (self ):
772792 self .w .other_creator .set ("Pyth" )
773793
794+ def interpx_hit (self ):
795+ self .w .other_creator .set ("PytX" )
796+
797+ def none_hit (self ):
798+ self .w .other_creator .set ("\0 \0 \0 \0 " )
799+
774800 def otherselect (self , * args ):
775801 sel_from , sel_to = self .w .other_creator .getselection ()
776802 creator = self .w .other_creator .get ()[:4 ]
@@ -779,16 +805,25 @@ def otherselect(self, *args):
779805 self .w .other_creator .setselection (sel_from , sel_to )
780806 self .w .other_radio .set (1 )
781807
808+ def mac_hit (self ):
809+ self .eoln = '\r '
810+
811+ def unix_hit (self ):
812+ self .eoln = '\n '
813+
814+ def win_hit (self ):
815+ self .eoln = '\r \n '
816+
782817 def cancelbuttonhit (self ):
783818 self .w .close ()
784819
785820 def okbuttonhit (self ):
786- self .rv = self .w .other_creator .get ()[:4 ]
821+ self .rv = ( self .w .other_creator .get ()[:4 ], self . eoln )
787822 self .w .close ()
788823
789824
790- def SaveOptions (creator ):
791- s = _saveoptions (creator )
825+ def SaveOptions (creator , eoln ):
826+ s = _saveoptions (creator , eoln )
792827 return s .rv
793828
794829
0 commit comments