Re: [Gambas-user] Question on preserving Windows EOL

2015-05-17 Thread Benoît Minisini
Le 17/05/2015 19:21, T Lee Davidson a écrit :
 On 05/17/2015 10:18 AM, Willy@develop wrote:
 Hi All,

 I've been struggling with something I would like to implement.

 A user asked me if it would be possible to preserve Windows EOL (CRLF)
 for files originating from Windows, but opened and modified in gbEdit
 (Gambas written texteditor).

 What happens now is that, if I add a few new lines to a windows
 originated text file, the new lines will be saved with a linux EOL (LF).
 The lines already having the Windows EOL (CRLF) are preserved.

 gbEdit makes use of a Editor control. Saving the contents is now done
 with a simple:

 File.Save($sPathFileLoaded, editMain.Text)

 Where $sPathFileLoaded is the full path and name of the file
 AND
 editMain.Text is the name of the Editor control holding the content.

 Upon opening a file gbEdit determines the EOL and returns either:
 CRLF for Windows EOL
 LF for Unix EOL
 CR for Classic Apple Mac EOL

 So I have all in place to determine when Windows EOL needs to be used
 upon saving.

 What I need is that new lines added, to a file already using Windows
 EOL, have to be saved with Windows EOL as well.

 I imagine I could save the file as a stream, making sure the proper EOL
 is added, but was wondering if there might be any easier way in Gambas
 that can do the job (as somehow that often turns out to be the case).

 Any suggestions?




Something quick and dirty like that?

' EolText = \n ' Unix
EolText = \r\n ' Windows
' EolText = \r ' Mac

Text = Replace(Text, \r\n, \n)
Text = Replace(Text, \r, \n)
if EolText  \n Then Text = Replace(Text, \n, EolText)

-- 
Benoît Minisini

--
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] Question on preserving Windows EOL

2015-05-17 Thread T Lee Davidson
On 05/17/2015 10:18 AM, Willy@develop wrote:
 Hi All,

 I've been struggling with something I would like to implement.

 A user asked me if it would be possible to preserve Windows EOL (CRLF)
 for files originating from Windows, but opened and modified in gbEdit
 (Gambas written texteditor).

 What happens now is that, if I add a few new lines to a windows
 originated text file, the new lines will be saved with a linux EOL (LF).
 The lines already having the Windows EOL (CRLF) are preserved.

 gbEdit makes use of a Editor control. Saving the contents is now done
 with a simple:

 File.Save($sPathFileLoaded, editMain.Text)

 Where $sPathFileLoaded is the full path and name of the file
 AND
 editMain.Text is the name of the Editor control holding the content.

 Upon opening a file gbEdit determines the EOL and returns either:
 CRLF for Windows EOL
 LF for Unix EOL
 CR for Classic Apple Mac EOL

 So I have all in place to determine when Windows EOL needs to be used
 upon saving.

 What I need is that new lines added, to a file already using Windows
 EOL, have to be saved with Windows EOL as well.

 I imagine I could save the file as a stream, making sure the proper EOL
 is added, but was wondering if there might be any easier way in Gambas
 that can do the job (as somehow that often turns out to be the case).

 Any suggestions?



Effect the necessary EOL-type upon data entry by either:

#1) A new property for the Editor control that is set to the EOL-type of the 
text and ensures that RETURN and ENTER effect the appropriate characters, or

#2) Trapping the RETURN and ENTER key events to effect the appropriate 
characters.

I haven't looked further into either idea. They are just off the top of my head.


Lee
__

Artificial Intelligence is no match for natural stupidity.

--
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


[Gambas-user] Question on preserving Windows EOL

2015-05-17 Thread Willy@develop
Hi All,

I've been struggling with something I would like to implement.

A user asked me if it would be possible to preserve Windows EOL (CRLF)
for files originating from Windows, but opened and modified in gbEdit
(Gambas written texteditor).

What happens now is that, if I add a few new lines to a windows
originated text file, the new lines will be saved with a linux EOL (LF).
The lines already having the Windows EOL (CRLF) are preserved.

gbEdit makes use of a Editor control. Saving the contents is now done
with a simple:

File.Save($sPathFileLoaded, editMain.Text)

Where $sPathFileLoaded is the full path and name of the file
AND
editMain.Text is the name of the Editor control holding the content.

Upon opening a file gbEdit determines the EOL and returns either:
CRLF for Windows EOL
LF for Unix EOL
CR for Classic Apple Mac EOL

So I have all in place to determine when Windows EOL needs to be used
upon saving.

What I need is that new lines added, to a file already using Windows
EOL, have to be saved with Windows EOL as well.

I imagine I could save the file as a stream, making sure the proper EOL
is added, but was wondering if there might be any easier way in Gambas
that can do the job (as somehow that often turns out to be the case).

Any suggestions?


-- 
Kind regards,

Willy (aka gbWilly)

http://gambasshowcase.org/
http://howtogambas.org
http://gambos.org





--
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] Question on preserving Windows EOL

2015-05-17 Thread Willy@develop
On zo, 2015-05-17 at 19:39 +0200, Benoît Minisini wrote:
 
  Any suggestions?
 
 
 
 
 Something quick and dirty like that?
 
 ' EolText = \n ' Unix
 EolText = \r\n ' Windows
 ' EolText = \r ' Mac
 
 Text = Replace(Text, \r\n, \n)
 Text = Replace(Text, \r, \n)
 if EolText  \n Then Text = Replace(Text, \n, EolText)
 


Okay, your suggestion worked well.
I wrote a little routine that gets executed before saving and checks a
setting to see if users want the EOL to be preserved in original format.

Private Sub PreserveEOL()
   
  Dim sTemp As String
  If Settings[Preferred/PreserveEOL] = -1 Then
 sTemp = editMain.Text
 Select $sEOL
Case CR '\r  Old Apple Mac
   sTemp = Replace(sTemp, \r\n, \r)
   sTemp = Replace(sTemp, \n, \r)
Case CRLF   '\r\nWindows
   sTemp = Replace(sTemp, \r\n, \n)
   sTemp = Replace(sTemp, \r, \n)
   sTemp = Replace(sTemp, \n, \r\n)
Case LF '\n  Unix/Linux
   sTemp = Replace(sTemp, \r\n, \n)
   sTemp = Replace(sTemp, \r, \n)
 End Select
 editMain.Text = sTemp
  Endif
   
End

It works very well and so simple I could have thought about it.

Thanks

-- 
Kind regards,

Willy (aka gbWilly)

http://gambasshowcase.org/
http://howtogambas.org
http://gambos.org





--
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user