Sign in to follow this  
Followers 0
poisonkiller

Poisonkiller's text editor

7 posts in this topic

#1 ·  Posted (edited)

So... I maked text editor, but i cant to some things. First, searching.Second, Word wrap.How can i do them?

Code:

#include <GUIConstants.au3>
#include <GUIEdit.au3>
#include <String.au3>
GUICreate("Poisonkiller's text editor", 680, 500)
$text = GUICtrlCreateEdit("", 0, 0, 680, 480)
$file = GUICtrlCreateMenu("File")
$new = GUICtrlCreateMenuItem("New", $file)
$open = GUICtrlCreateMenuItem("Open...", $file)
$save = GUICtrlCreateMenuItem("Save", $file)
$saveas = GUICtrlCreateMenuItem("Save as...", $file)
GUICtrlCreateMenuItem("", $file)
$exit = GUICtrlCreateMenuItem("Exit", $file)
$edit = GUICtrlCreateMenu("Edit")
$undo = GUICtrlCreateMenuItem("Undo", $edit)
GUICtrlCreateMenuItem("", $edit)
$timedate = GUICtrlCreateMenuItem("Time/Date", $edit)
$search = GUICtrlCreateMenu("Search")
$find = GUICtrlCreateMenuItem("Find", $search)
$m_help = GUICtrlCreateMenu("Help")
$help = GUICtrlCreateMenuItem("Help", $m_help)
GUICtrlCreateMenuItem("", $m_help)
$about = GUICtrlCreateMenuItem("About", $m_help)
GUISetState()
While 1
    $msg = GUIGetMsg()
Select
Case $msg = $new
    GUICtrlSetData($text, "")
    $get_title = WinGetTitle("")
    WinSetTitle($get_title, "", "Untitled - Poisonkiller's text editor")
Case $msg = $open
    $open_diag = FileOpenDialog("Open text file...", @DesktopDir, "Text files (*.txt)|All files (*.*)")
    If @error Then ContinueLoop
    $string_right = StringRight($open_diag, 4)
    $string_trim = StringTrimRight($string_right, 3)
    If $string_trim = "." Then
        $save_for_later = $open_diag
        Else
    Dim $save_for_later
    $save_for_later = $open_diag &".txt"
    EndIf 
    $file_read_all = FileReadAll($open_diag)
    GUICtrlSetData($text, $file_read_all)
$get_title = WinGetTitle("")
WinSetTitle($get_title, "", $open_diag &" - Poisonkiller's text editor")


Case $msg = $save
    $read_text = GUICtrlRead($text)
    If WinGetTitle("") = "Poisonkiller's text editor" or WinGetTitle("") = "Untitled - Poisonkiller's text editor" Then
        $save_diag = FileSaveDialog("Save text file...", @DesktopDir, "Text files (*.txt)|All files (*.*)")
    If @error Then ContinueLoop
    $save_text = GUICtrlRead($text)
    Global $save_num = 1
    $string_right = StringRight($save_diag, 4)
    $string_trim = StringTrimRight($string_right, 3)
    If $string_trim = "." Then
        $save_for_later = $save_diag
        Else
    $save_for_later = $save_diag &".txt"
    EndIf
        
    $string_right = StringRight($save_diag, 4)
    $string_trim = StringTrimRight($string_right, 3)
    If $string_trim = "." Then
        $file_open = FileOpen($save_diag, 1)
        Else
    $file_open = FileOpen($save_diag &".txt", 1)
    $save_diag = $save_diag &".txt"
    EndIf
    FileWrite($file_open, $read_text)
    FileClose($file_open)
$get_title = WinGetTitle("")
WinSetTitle($get_title, "", $save_diag &" - Poisonkiller's text editor")
Else
    $get_title = WinGetTitle("")
    $title_trimmed = StringTrimRight($get_title, 29)
    If FileExists($title_trimmed) Then
    FileDelete($title_trimmed)
    $file_open = FileOpen($title_trimmed, 1)
    FileWrite($file_open, $read_text)
    FileClose($file_open)
    $get_title = WinGetTitle("")
WinSetTitle($get_title, "", $title_trimmed &" - Poisonkiller's text editor")
    EndIf
    EndIf
    
    

Case $msg = $saveas
    $read_text = GUICtrlRead($text)
    $save_diag = FileSaveDialog("Save as...", @DesktopDir, "Text files (*.txt)|All files (*.*)")
    If @error Then ContinueLoop
    $string_right = StringRight($save_diag, 4)
    $string_trim = StringTrimRight($string_right, 3)
    If $string_trim = "." Then
        $file_open = FileOpen($save_diag, 1)
        Else
    $file_open = FileOpen($save_diag &".txt", 1)
    $save_diag = $save_diag &".txt"
    EndIf
    FileWrite($file_open, $read_text)
    FileClose($file_open)
$get_title = WinGetTitle("")
WinSetTitle($get_title, "", $save_diag &" - Poisonkiller's text editor")

Case $msg = $find
    $read_text = GUICtrlRead($text)
    $str = InputBox("Find...", "Write here string what you want to find:")
$find_str = StringInStr(GUICtrlRead($text), $str)
;@Autoit Forum   I should use _GUICtrlEditSetSel($text, $find_str, $find_str) but $find_str must be number
Case $msg = $undo
    If _GUICtrlEditCanUndo($text) = 0 Then
        Else
        _GUICtrlEditUndo($text)
    EndIf
Case $msg = $timedate
    $get_title = WinGetState("")
    Send(@HOUR &":" &@MIN &" "& @MDAY &"." & @MON &"." & @YEAR)
Case $msg = $about
    MsgBox(4096, "About", "Poisonkiller's text editor" &@CRLF &@CRLF &"Made by Poisonkiller" &@CRLF &"You can download this from Autoit v3 forum" &@CRLF &"          Year 2005")
Case $msg = $help
    MsgBox(4096, "Help", "This is like Notepad" &@CRLF &"so learn Notepad. :D")
EndSelect

If $msg = $exit Then Exit
    
    
    
    If $msg = $GUI_EVENT_CLOSE Then
        If GUICtrlRead($text) = "" AND WinGetTitle("") = "Poisonkiller's text editor" Then Exit
        If GUICtrlRead($text) = "" AND WinGetTitle("") = "Untitled - Poisonkiller's text editor" Then Exit
        $message = MsgBox(4, "Save work", "Do you want to save your work?")
        If $message = 7 Then
            Exit
            Else
        $read_text = GUICtrlRead($text)
    If WinGetTitle("") = "Poisonkiller's text editor" Then
        $save_diag = FileSaveDialog("Save text file...", @DesktopDir, "Text files (*.txt)|All files (*.*)")
    If @error Then ContinueLoop
    $string_right = StringRight($save_diag, 4)
    $string_trim = StringTrimRight($string_right, 3)
    If $string_trim = "." Then
        $save_for_later = $save_diag
        Else
    $save_for_later = $save_diag &".txt"
    EndIf
        
    $string_right = StringRight($save_diag, 4)
    $string_trim = StringTrimRight($string_right, 3)
    If $string_trim = "." Then
        $file_open = FileOpen($save_diag, 1)
        Else
    $file_open = FileOpen($save_diag &".txt", 1)
    $save_diag = $save_diag &".txt"
    EndIf
    FileWrite($file_open, $read_text)
    FileClose($file_open)
$get_title = WinGetTitle("")
WinSetTitle($get_title, "", $save_diag &" - Poisonkiller's text editor")
Exit
Else
    $get_title = WinGetTitle("")
    $right_trimmed = StringTrimRight($get_title, 29)
    If FileExists($right_trimmed) Then
    FileDelete($right_trimmed)
    $file_open = FileOpen($right_trimmed, 1)
    FileWrite($file_open, $read_text)
    FileClose($file_open)
    $get_title = WinGetTitle("")
WinSetTitle($get_title, "", $right_trimmed &" - Poisonkiller's text editor")
    Exit
    EndIf
    EndIf
EndIf
EndIf
Wend

Func FileReadAll($File)
   $OpenFile = FileOpen($File, 0)
   If $OpenFile = -1 Then Return -1
   $ReadAll = FileRead($OpenFile, FileGetSize($File))
   FileClose($OpenFile)
   Return $ReadAll
EndFunc ;==>FileReadAll

EDIT: deleted: "#include <File.au3>"included: Func FileReadAll()

Edited by poisonkiller

Share this post


Link to post
Share on other sites



I think adding the search function won't be that hard but...

I get this error when i try to compile your script:

C:\Programme\AutoIt3\Projects\Poisonkillerstexteditor.au3(43,44) : ERROR: FileReadAll(): undefined function.
    $file_read_all = FileReadAll($open_diag)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Programme\AutoIt3\Projects\Poisonkillerstexteditor.au3 - 1 error(s), 0 warning(s)

YES, im using the newest beta (3.1.1.84)!

Whats that about, is there a function.au3 you didn't post?

Felix N. (tdlrali)

Share this post


Link to post
Share on other sites

Sry, add this end of your script:

Func FileReadAll($File)
   $OpenFile = FileOpen($File, 0)
   If $OpenFile = -1 Then Return -1
   $ReadAll = FileRead($OpenFile, FileGetSize($File))
   FileClose($OpenFile)
   Return $ReadAll
EndFunc  ;==>FileReadAll

And delete #include <File.au3>

Share this post


Link to post
Share on other sites

hey poisonkiller!

is w0uter right? I'm pretty sure, but still i don't understand why it worked for you? (I guess you try your scripts before you upload them?)

FN (tdlrali)

Share this post


Link to post
Share on other sites

I have lot of UDF-s...If you want i can post user calltips B)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0