Skip to content

Commit ddba817

Browse files
committed
use regards more consistently in dialogs (breaking), and other minor tweaks
1 parent cea93ee commit ddba817

File tree

3 files changed

+43
-35
lines changed

3 files changed

+43
-35
lines changed

src/selectors.jl

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,22 @@
1414
#GtkFontSelectionDialog — A dialog box for selecting fonts
1515
#GtkInputDialog — Configure devices for the XInput extension
1616

17-
push!(widget::GtkDialog, text::String, response::Integer) =
17+
function push!(widget::GtkDialog, text::String, response::Integer)
1818
ccall((:gtk_dialog_add_button,libgtk), Ptr{GObject},
1919
(Ptr{GObject},Ptr{Uint8},Cint), widget, text, response)
20+
widget
21+
end
2022

21-
function GtkFileChooserDialogLeaf(title::String, parent::GtkContainer, action::Integer, button_text_response...)
22-
n = length(button_text_response)
23-
if !iseven(n)
24-
error("button_text_response must consist of text/response pairs")
25-
end
23+
#if VERSION >= v"0.4-"
24+
#GtkFileChooserDialogLeaf(title::String, parent::GtkContainer, action::Integer, button_text_response::=>...; kwargs...) =
25+
# GtkFileChooserDialogLeaf(title::String, parent, action, button_text_response; kwargs...)
26+
#end
27+
function GtkFileChooserDialogLeaf(title::String, parent::GtkContainer, action::Integer, button_text_response; kwargs...)
2628
w = GtkFileChooserDialogLeaf(ccall((:gtk_file_chooser_dialog_new,libgtk), Ptr{GObject},
2729
(Ptr{Uint8},Ptr{GObject},Cint,Ptr{Void}),
28-
title, parent, action, C_NULL))
29-
for i = 1:2:n
30-
push!(w, button_text_response[i], button_text_response[i+1])
30+
title, parent, action, C_NULL); kwargs...)
31+
for (k,v) in button_text_response
32+
push!(w, k, v)
3133
end
3234
w
3335
end
@@ -36,7 +38,7 @@ run(widget::GtkDialog) = ccall((:gtk_dialog_run,libgtk), Cint, (Ptr{GObject},),
3638

3739
const SingleComma = r"(?<!,),(?!,)"
3840
function GtkFileFilterLeaf(; name::Union(ByteString,Nothing) = nothing, pattern::ByteString = "", mimetype::ByteString = "")
39-
filt = ccall((:gtk_file_filter_new,libgtk), Ptr{GObject}, ())
41+
filt = GtkFileFilterLeaf(ccall((:gtk_file_filter_new,libgtk), Ptr{GObject}, ()))
4042
if !isempty(pattern)
4143
name == nothing && (name = pattern)
4244
for p in split(pattern, SingleComma)
@@ -57,24 +59,24 @@ function GtkFileFilterLeaf(; name::Union(ByteString,Nothing) = nothing, pattern:
5759
end
5860
GtkFileFilterLeaf(pattern::ByteString; name::Union(ByteString,Nothing) = nothing) = GtkFileFilterLeaf(; name=name, pattern=pattern)
5961

60-
GtkFileFilterLeaf(filter::GtkFileFilterLeaf) = filter
62+
GtkFileFilterLeaf(filter::GtkFileFilter) = filter
6163

62-
function makefilters(dlgp::GtkFileChooser, filters::Union(AbstractVector,Tuple))
64+
function makefilters!(dlgp::GtkFileChooser, filters::Union(AbstractVector,Tuple))
6365
for f in filters
6466
ccall((:gtk_file_chooser_add_filter,libgtk), Void, (Ptr{GObject}, Ptr{GObject}), dlgp, @GtkFileFilter(f))
6567
end
6668
end
6769

68-
function open_dialog(title::String, parent = GtkNullContainer(); filters::Union(AbstractVector,Tuple) = ASCIIString[], multiple::Bool = false)
70+
function open_dialog(title::String, parent = GtkNullContainer(), filters::Union(AbstractVector,Tuple) = ASCIIString[]; kwargs...)
6971
dlg = @GtkFileChooserDialog(title, parent, GConstants.GtkFileChooserAction.OPEN,
70-
"_Cancel", GConstants.GtkResponseType.CANCEL,
71-
"_Open", GConstants.GtkResponseType.ACCEPT)
72-
setproperty!(dlg, :select_multiple, multiple)
72+
(("_Cancel", GConstants.GtkResponseType.CANCEL),
73+
("_Open", GConstants.GtkResponseType.ACCEPT)); kwargs...)
7374
dlgp = GtkFileChooser(dlg)
7475
if !isempty(filters)
75-
makefilters(dlgp, filters)
76+
makefilters!(dlgp, filters)
7677
end
7778
response = run(dlg)
79+
multiple = getproperty(dlg, :select_multiple, Bool)
7880
local selection
7981
if response == GConstants.GtkResponseType.ACCEPT
8082
if multiple
@@ -96,13 +98,13 @@ function open_dialog(title::String, parent = GtkNullContainer(); filters::Union(
9698
selection
9799
end
98100

99-
function save_dialog(title::String, parent = GtkNullContainer(); filters::Union(AbstractVector,Tuple) = ASCIIString[])
101+
function save_dialog(title::String, parent = GtkNullContainer(), filters::Union(AbstractVector,Tuple) = ASCIIString[]; kwargs...)
100102
dlg = @GtkFileChooserDialog(title, parent, GConstants.GtkFileChooserAction.SAVE,
101-
"_Cancel", GConstants.GtkResponseType.CANCEL,
102-
"_Save", GConstants.GtkResponseType.ACCEPT)
103+
(("_Cancel", GConstants.GtkResponseType.CANCEL),
104+
("_Save", GConstants.GtkResponseType.ACCEPT)), kwargs...)
103105
dlgp = GtkFileChooser(dlg)
104106
if !isempty(filters)
105-
makefilters(dlgp, filters)
107+
makefilters!(dlgp, filters)
106108
end
107109
ccall((:gtk_file_chooser_set_do_overwrite_confirmation,libgtk), Void, (Ptr{GObject}, Cint), dlg, true)
108110
response = run(dlg)

src/windows.jl

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,14 @@ GtkScrolledWindowLeaf() = GtkScrolledWindowLeaf(
3333
ccall((:gtk_scrolled_window_new,libgtk),Ptr{GObject},(Ptr{GObject},Ptr{GObject}),
3434
C_NULL,C_NULL))
3535

36-
function GtkDialogLeaf(title::StringLike, parent::GtkContainer, flags::Integer, buttons)
36+
#if VERSION >= v"0.4-"
37+
#GtkDialogLeaf(title::StringLike, parent::GtkContainer, flags::Integer, buttons::=>...; kwargs...) =
38+
# GtkDialogLeaf(title, parent, flags, buttons; kwargs...)
39+
#end
40+
function GtkDialogLeaf(title::StringLike, parent::GtkContainer, flags::Integer, buttons; kwargs...)
3741
w = GtkDialogLeaf(ccall((:gtk_dialog_new_with_buttons,libgtk), Ptr{GObject},
3842
(Ptr{Uint8},Ptr{GObject},Cint,Ptr{Void}),
39-
title, parent, flags, C_NULL))
43+
title, parent, flags, C_NULL); kwargs...)
4044
for (k,v) in buttons
4145
push!(w, k, v)
4246
end
@@ -46,39 +50,41 @@ end
4650
GtkAboutDialogLeaf() = GtkAboutDialogLeaf(
4751
ccall((:gtk_about_dialog_new,libgtk),Ptr{GObject},()))
4852

49-
function GtkMessageDialogLeaf(message::StringLike, buttons, flags::Integer, typ::Integer, parent = GtkNullContainer())
53+
function GtkMessageDialogLeaf(message::StringLike, buttons, flags::Integer, typ::Integer, parent = GtkNullContainer(); kwargs...)
5054
w = GtkMessageDialogLeaf(ccall((:gtk_message_dialog_new,libgtk), Ptr{GObject},
5155
(Ptr{GObject},Cint,Cint,Cint,Ptr{Uint8}),
52-
parent, flags, typ, GtkButtonsType.NONE, C_NULL))
53-
setproperty!(w, :text, bytestring(message))
56+
parent, flags, typ, GtkButtonsType.NONE, C_NULL); kwargs...)
57+
setproperty!(w, :text, message)
5458
for (k,v) in buttons
5559
push!(w, k, v)
5660
end
5761
w
5862
end
5963

6064
ask_dialog(message::String, parent = GtkNullContainer()) =
61-
ask_dialog(message, "Yes", "No", parent)
65+
ask_dialog(message, "No", "Yes", parent)
6266

63-
function ask_dialog(message::String, yes_text, no_text, parent = GtkNullContainer())
64-
dlg = @GtkMessageDialog(message, ((yes_text,1), (no_text,2)),
67+
function ask_dialog(message::String, no_text, yes_text, parent = GtkNullContainer())
68+
dlg = @GtkMessageDialog(message, ((no_text,0), (yes_text,1)),
6569
GtkDialogFlags.DESTROY_WITH_PARENT, GtkMessageType.QUESTION, parent)
6670
response = run(dlg)
6771
destroy(dlg)
6872
response == 1
6973
end
7074

7175
for (func, flag) in (
72-
(:info_dialog, GtkMessageType.INFO),
73-
(:warn_dialog, GtkMessageType.WARNING),
74-
(:error_dialog, GtkMessageType.ERROR))
76+
(:info_dialog, :(GtkMessageType.INFO)),
77+
(:warn_dialog, :(GtkMessageType.WARNING)),
78+
(:error_dialog, :(GtkMessageType.ERROR)))
7579
@eval function $func(message::String, parent = GtkNullContainer())
7680
w = GtkMessageDialogLeaf(ccall((:gtk_message_dialog_new,libgtk), Ptr{GObject},
7781
(Ptr{GObject},Cint,Cint,Cint,Ptr{Uint8}),
7882
parent, GtkDialogFlags.DESTROY_WITH_PARENT,
7983
$flag, GtkButtonsType.CLOSE, C_NULL))
80-
setproperty!(w, :text, bytestring(message))
84+
setproperty!(w, :text, message)
8185
run(w)
8286
destroy(w)
8387
end
8488
end
89+
90+
#TODO: GtkSeparator — A separator widget

test/gui.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,8 +443,8 @@ destroy(win)
443443
## Selectors
444444
import Gtk.GtkFileChooserAction, Gtk.GtkResponseType
445445
dlg = @FileChooserDialog("Select file", @Null(), GtkFileChooserAction.OPEN,
446-
"_Cancel", GtkResponseType.CANCEL,
447-
"_Open", GtkResponseType.ACCEPT)
446+
(("_Cancel", GtkResponseType.CANCEL),
447+
("_Open", GtkResponseType.ACCEPT)))
448448
destroy(dlg)
449449

450450
## List view

0 commit comments

Comments
 (0)