#Include <Misc.au3>
if _Singleton("test",1) = 0 Then
TrayTip ("AutoIt", "TreyGREP уже запущен", 1)
sleep(1000)
TrayTip("clears any tray tip","",0)
Exit
EndIf
TraySetState ( 1 )
Opt("TrayMenuMode", 1)
HotKeySet("^x", "_Replace")
HotKeySet("^ч", "_Replace")
HotKeySet("^+x", "_Exit")
HotKeySet("^+ч", "_Exit")
Global $i, $a, $Text
Dim $Search[1000][2]
Dim $Matches, $Splited
$IniFile = @ScriptDir & "\" & "TrayGREP.ini"
$Edit = TrayCreateItem("Редактировать список замен")
$Exit = TrayCreateItem("Выход")
if not FileExists($IniFile) Then
TrayTip ("AutoIt", "Не могу найти файл ""TrayGREP.ini""", 1)
sleep(2000)
TrayTip("clears any tray tip","",0)
Exit
Else
$in = FileOpen("TrayGREP.ini", 0)
$line = FileReadLine($in, 1)
if $line <> "TrayGREP v.1.0. Автор идеи и разработчик - Suppir." Then
TrayTip ("AutoIt", "Информация о разработчике была повреждена", 1)
sleep(3000)
TrayTip("clears any tray tip","",0)
TrayTip ("AutoIt", "Восстановите информацию или скачайте утилиту заново", 1)
sleep(3000)
TrayTip("clears any tray tip","",0)
Exit
EndIf
EndIf
TrayTip ("AutoIt", "TrayGREP запущен", 1)
sleep(2000)
TrayTip("clears any tray tip","",0)
While 1
Switch TrayGetMsg()
Case $Edit
ShellExecute ($IniFile)
TrayItemSetState ( $Edit, 4 )
Case $Exit
TrayItemSetState ( $Edit, 4 )
_Exit()
EndSwitch
WEnd
Func _Exit()
TrayTip ("AutoIt", "Завершение работы TrayGREP", 1)
Sleep(1000)
Exit
EndFunc
Func _Replace()
if ClipGet() = "" Then
TrayTip ("AutoIt", "Буфер пустой!", 1)
sleep(1000)
TrayTip("clears any tray tip","",0)
Else
$in = FileOpen("TrayGREP.ini", 0)
while 1
local $i
$line = FileReadLine($in)
If @error = -1 Then ExitLoop
$Matches = StringRegExp($line, "^Найти:(.+)", 1)
If @error = 0 Then
$Search[$i][0] = $Matches[0]
ContinueLoop
EndIf
$Matches = StringRegExp($line, "^Заменить на:$", 1)
If @error = 0 Then
$Search[$i][1] = ""
$i += 1
ContinueLoop
EndIf
$Matches = StringRegExp($line, "^Заменить на:(.+)", 1)
If @error = 0 Then
$Search[$i][1] = $Matches[0]
$i += 1
ContinueLoop
EndIf
wend
TrayTip ("AutoIt", "Произвожу замену...", 1)
$Text = ClipGet()
$Splited = StringSplit($Text, @CRLF, 1)
$Text = ""
For $x = 1 to UBound($Splited)-1
for $i = 0 to UBound($Search) - 1
$Splited[$x] = StringRegExpReplace($Splited[$x], $Search[$i][0], $Search[$i][1])
Next
if $Text = "" Then
$Text = $Splited[$x]
Else
$Text = $Text & @CRLF & $Splited[$x]
EndIf
Next
ClipPut($Text)
TrayTip ("AutoIt", "Замена произведена", 1)
sleep(1000)
TrayTip("clears any tray tip","",0)
EndIf
EndFunc