Update of /cvsroot/pywin32/pywin32/Pythonwin/pywin/scintilla
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6911/scintilla
Modified Files:
Tag: py3k
document.py view.py
Log Message:
Fix some problems with line endings
Index: view.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/Pythonwin/pywin/scintilla/view.py,v
retrieving revision 1.28.2.3
retrieving revision 1.28.2.4
diff -C2 -d -r1.28.2.3 -r1.28.2.4
*** view.py 3 Sep 2008 03:05:57 -0000 1.28.2.3
--- view.py 8 Sep 2008 04:08:27 -0000 1.28.2.4
***************
*** 387,394 ****
doc = self.GetDocument()
s = self.GetTextRange()
! ## if is_platform_unicode:
! ## s = str(s,"utf-8").encode("mbcs")
! f = open(filename, 'w')
! f.write(s)
f.close()
doc.SetModifiedFlag(0)
--- 387,394 ----
doc = self.GetDocument()
s = self.GetTextRange()
! # Save in binary mode so line endings are not translated.
! # Edit control uses '\r\n', and universal newlines mode replaces ALL '\r' with '\r\n'.
! f = open(filename, 'wb')
! f.write(s.encode('mbcs'))
f.close()
doc.SetModifiedFlag(0)
Index: document.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/Pythonwin/pywin/scintilla/document.py,v
retrieving revision 1.6.4.3
retrieving revision 1.6.4.4
diff -C2 -d -r1.6.4.3 -r1.6.4.4
*** document.py 3 Sep 2008 03:05:57 -0000 1.6.4.3
--- document.py 8 Sep 2008 04:08:27 -0000 1.6.4.4
***************
*** 5,9 ****
import win32con
import string
! import array
ParentScintillaDocument=docview.Document
--- 5,9 ----
import win32con
import string
! import os
ParentScintillaDocument=docview.Document
***************
*** 15,33 ****
def OnOpenDocument(self, filename):
# init data members
! #print "Opening", filename
self.SetPathName(filename) # Must set this early!
try:
! if is_platform_unicode:
! # Scintilla in UTF-8 mode - translate accordingly.
! import codecs
! f = codecs.open(filename, 'rb', default_platform_encoding)
! else:
! f = open(filename, 'r')
try:
text = f.read()
finally:
f.close()
- # Translate from locale-specific (MCBS) encoding to UTF-8 for Scintilla
- text = text.encode(default_scintilla_encoding)
except IOError:
win32ui.MessageBox("Could not load the file from %s" % filename)
--- 15,26 ----
def OnOpenDocument(self, filename):
# init data members
! # print ("CScintillaDocument.OnOpenDocument", filename)
self.SetPathName(filename) # Must set this early!
try:
! f = open(filename, 'r')
try:
text = f.read()
finally:
f.close()
except IOError:
win32ui.MessageBox("Could not load the file from %s" % filename)
***************
*** 35,41 ****
self._SetLoadedText(text)
- ## if self.GetFirstView():
- ## self.GetFirstView()._SetLoadedText(text)
- ## self.SetModifiedFlag(0) # No longer dirty
return 1
--- 28,31 ----
***************
*** 54,57 ****
--- 44,58 ----
# Helper to transfer text from the MFC document to the control.
def _SetLoadedText(self, text):
+ # In universal newlines mode, line endings read from file are translated to '\n',
+ # but edit control expects CR/LF ('\r\n').
+ # Might be simpler to just tell scintilla to use '\n'
+ # SendScintilla(scintillacon.SCI_SETEOLMODE, scintillacon.SC_EOL_LF)
+ # and have eols automatically translated back when written to file
+ if os.linesep != '\n':
+ text=text.replace('\n', os.linesep)
+
+ # Translate from unicode to UTF-8 bytes for Scintilla
+ char_text = text.encode(default_scintilla_encoding)
+
view = self.GetFirstView()
if view.IsWindow():
***************
*** 60,67 ****
# Make sure the control isnt read-only
view.SetReadOnly(0)
-
- doc = self
view.SendScintilla(scintillacon.SCI_CLEARALL)
! view.SendMessage(scintillacon.SCI_ADDTEXT, text)
view.SendScintilla(scintillacon.SCI_SETUNDOCOLLECTION, 1, 0)
view.SendScintilla(win32con.EM_EMPTYUNDOBUFFER, 0, 0)
--- 61,66 ----
# Make sure the control isnt read-only
view.SetReadOnly(0)
view.SendScintilla(scintillacon.SCI_CLEARALL)
! view.SendMessage(scintillacon.SCI_ADDTEXT, char_text)
view.SendScintilla(scintillacon.SCI_SETUNDOCOLLECTION, 1, 0)
view.SendScintilla(win32con.EM_EMPTYUNDOBUFFER, 0, 0)
|