diff --git a/docs/src/manual/dialogs.md b/docs/src/manual/dialogs.md index 225710d5..0fe1cfc0 100644 --- a/docs/src/manual/dialogs.md +++ b/docs/src/manual/dialogs.md @@ -10,14 +10,14 @@ Dialogs are transient windows that show messages or ask the user for information ## Message dialogs -Gtk4.jl supports `GtkAlertDialog` and wraps it in convenience functions `info_dialog` and `ask_dialog`. -Each takes a string for a message to show and an optional parent container. +Gtk4.jl wraps `GtkAlertDialog` in convenience functions `info_dialog` and `ask_dialog`. +Each takes a string for a message to show and an optional parent window. For all dialog convenience functions, there are two ways of using them. For use in the REPL or an interactive script, the following forms can be used: ```julia info_dialog("Julia rocks!") -ask_dialog("Do you like chocolate ice cream?", "Not at all", "I like it") && println("That's my favorite too.") +ask_dialog("Do you like chocolate ice cream?"; no_text = "Not at all", yes_text = "I like it") && println("That's my favorite too.") ``` Note that `ask_dialog` returns `true` if the user clicks the button corresponding to yes. These functions take an optional argument `timeout` (in seconds) that can be used to make the dialog disappear after a certain time. diff --git a/examples/dialogs.jl b/examples/dialogs.jl index 76f267f8..1fcdc163 100644 --- a/examples/dialogs.jl +++ b/examples/dialogs.jl @@ -21,7 +21,7 @@ question_dialog_button = GtkButton("Question dialog") push!(box,question_dialog_button) function open_question_dialog(b) - ask_dialog("May I ask you a question?","No","Yes",main_window) do ans + ask_dialog("May I ask you a question?",main_window) do ans @async println("You answered $ans") end end @@ -34,7 +34,7 @@ input_dialog_button = GtkButton("Input dialog") push!(box, input_dialog_button) function open_input_dialog(b) - input_dialog("Enter your information", "", (("Cancel", 0), ("Accept", 1)), main_window) do t + input_dialog("Enter your information", "", main_window) do t @async println("response was ",t) end end diff --git a/src/windows.jl b/src/windows.jl index 615562c9..891ea4a8 100644 --- a/src/windows.jl +++ b/src/windows.jl @@ -341,7 +341,7 @@ function input_dialog(callback::Function, message::AbstractString, entry_default cancel = GtkButton("Cancel"; hexpand = true) push!(boxb, cancel) push!(boxb, accept) - isnothing(parent) && (G_.set_transient_for(dlg, parent); G_.set_modal(dlg, true)) + isnothing(parent) || (G_.set_transient_for(dlg, parent); G_.set_modal(dlg, true)) dlg[] = box signal_connect(cancel, "clicked") do b @@ -456,7 +456,7 @@ Keyword arguments: - `start_folder = ""`: if set to a path, the dialog will start out browsing a particular folder. Otherwise GTK will decide. """ function open_dialog(title::AbstractString, parent = nothing, filters::Union{AbstractVector, Tuple} = String[]; timeout = -1, multiple = false, select_folder = false, start_folder = "") - res = Ref{String}("") + res = Ref{Union{Vector{String},String}}("") c = Condition() open_dialog(title, parent, filters; timeout, multiple, select_folder, start_folder) do filename diff --git a/test/gui/dialogs.jl b/test/gui/dialogs.jl index df57abb6..0488158c 100644 --- a/test/gui/dialogs.jl +++ b/test/gui/dialogs.jl @@ -31,11 +31,13 @@ main_window = GtkWindow("Dialog example") open_dialog("Pick a file to open", main_window; timeout = 0.25) sleep(1.0) -open_dialog("Pick a file to open", main_window, ["*.png"]; timeout = 0.25) +open_dialog("Pick files to open", main_window, ["*.png"]; timeout = 0.25, multiple = true, start_folder = ".") sleep(1.0) save_dialog("Pick a filename", main_window; timeout = 0.25) +sleep(1.0) +save_dialog("Pick a filename", main_window, ["*.png"]; timeout = 0.25, start_folder = ".") sleep(1.0) color_dialog("What is your favorite color?", main_window; timeout = 0.25) @@ -77,6 +79,9 @@ csvfilter3 = GtkFileFilter("", "text/csv") csvfilter4 = GtkFileFilter("*.csv", "text/csv") # Pattern takes precedence over mime-type, causing mime-type to be ignored @test csvfilter4.name == "*.csv" + +imfilter = GtkFileFilter("") +@test GtkFileFilter(imfilter) == imfilter end @testset "New dialogs" begin diff --git a/test/gui/window.jl b/test/gui/window.jl index 54d0c489..39ba5d91 100644 --- a/test/gui/window.jl +++ b/test/gui/window.jl @@ -23,6 +23,10 @@ visible(w,false) visible(w,true) @test isvisible(w) == true +@test Gtk4.issuspended(w) == false +@test Gtk4.isfullscreen(w) == false +@test Gtk4.isactive(w) == true + m = Gtk4.monitor(w) if m!==nothing r = Gtk4.G_.get_geometry(m)