This repository was archived by the owner on Apr 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathTextEditor.jl
More file actions
executable file
·81 lines (64 loc) · 2.28 KB
/
TextEditor.jl
File metadata and controls
executable file
·81 lines (64 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env julia
using Gtk, Gtk.ShortNames
mutable struct TextModule
name::AbstractString
fileplace::AbstractString
TextModule() = new("", "")
end
text = TextModule()
ui = Builder(filename=(@__DIR__) * "/ui.glade")
showall(ui["win"])
writetext!(textview::GtkTextView, s::AbstractString) = get_gtk_property(textview, :buffer, GtkTextBuffer) |> x -> set_gtk_property!(x, :text, s)
gettext(textview::GtkTextView) = get_gtk_property(textview, :buffer, GtkTextBuffer) |> x -> get_gtk_property(x, :text, AbstractString)
function file_new()
textcontent = gettext(ui["textview"])
if !isempty(textcontent)
info_dialog("中身消しちゃったけど許してね!")
end
writetext!(ui["textview"], "")
set_gtk_property!(ui["win"], :title, "")
text.name, text.fileplace = "", ""
return nothing
end
function file_open()
text.fileplace = open_dialog("Open file", ui["win"], ("*.txt", "*",))
if !isempty(text.fileplace)
textcontent = open(io->read(io, String), text.fileplace)
writetext!(ui["textview"], textcontent)
text.name = split(text.fileplace, "/")[end]
set_gtk_property!(ui["win"], :title, text.name)
end
return nothing
end
function file_save()
if isempty(text.name)
file_save_as()
else
textcontent = gettext(ui["textview"])
write(text.fileplace, textcontent)
end
return nothing
end
function file_save_as()
fileplace = save_dialog("Save file")
if !isempty(fileplace)
text.fileplace = fileplace
textcontent = gettext(ui["textview"])
write(text.fileplace, textcontent)
text.name = split(text.fileplace, "/")[end]
set_gtk_property!(ui["win"], :title, text.name)
end
return nothing
end
signal_connect((x,y)->file_new(), ui["file_new"], :activate, Nothing, (), false)
signal_connect((x,y)->file_open(), ui["file_open"], :activate, Nothing, (), false)
signal_connect((x,y)->file_save(), ui["file_save"], :activate, Nothing, (), false)
signal_connect((x,y)->file_save_as(), ui["file_save_as"], :activate, Nothing, (), false)
signal_connect((x,y)->exit(), ui["file_quit"], :activate, Nothing, (), false)
if !isinteractive()
c = Condition()
signal_connect(ui["win"], :destroy) do widget
notify(c)
end
wait(c)
end