From 2a528137cb11d9a8457e51a4736bc9b73ce6e3d8 Mon Sep 17 00:00:00 2001 From: Cruor Date: Tue, 18 Feb 2020 20:08:41 +0100 Subject: [PATCH] Fixed sub-window positioning. Windows should no longer get stuck under other windows. --- src/helpers/form_helper.jl | 15 ++++++------ src/helpers/gtk_helpers.jl | 39 ++++++++++++++++++++++++++++++- src/property_menu.jl | 2 +- src/windows/room_window.jl | 10 ++++---- src/windows/styleground_window.jl | 10 ++++---- 5 files changed, 57 insertions(+), 19 deletions(-) diff --git a/src/helpers/form_helper.jl b/src/helpers/form_helper.jl index f0a555b..d654f6d 100644 --- a/src/helpers/form_helper.jl +++ b/src/helpers/form_helper.jl @@ -534,6 +534,13 @@ function createFormWindow(title::String, sections::Union{Array{Section, 1}, Sect sections = isa(sections, Section) ? Section[sections] : sections updateButton = Button(buttonText) + content = generateSectionsNotebook(sections, columns=columns, separateGroups=separateGroups, gridIfSingleSection=gridIfSingleSection) + + window = Window(title, -1, -1, canResize, icon=icon) |> (Frame() |> (box = Box(:v))) + + push!(box, content) + push!(box, updateButton) + @guarded signal_connect(updateButton, "clicked") do args... data, incorrectOptions = getSectionsData(sections) @@ -541,16 +548,10 @@ function createFormWindow(title::String, sections::Union{Array{Section, 1}, Sect callback(data) else - info_dialog(getIncorrectOptionsMessage(incorrectOptions), parent) + Ahorn.topMostInfoDialog(getIncorrectOptionsMessage(incorrectOptions), window) end end - content = generateSectionsNotebook(sections, columns=columns, separateGroups=separateGroups, gridIfSingleSection=gridIfSingleSection) - - window = Window(title, -1, -1, canResize, icon=icon) |> (Frame() |> (box = Box(:v))) - push!(box, content) - push!(box, updateButton) - return window end diff --git a/src/helpers/gtk_helpers.jl b/src/helpers/gtk_helpers.jl index c42e60b..c57e862 100644 --- a/src/helpers/gtk_helpers.jl +++ b/src/helpers/gtk_helpers.jl @@ -264,6 +264,43 @@ end useNativeFileDialogs = isdefined(Gtk, :save_dialog_native) && Gtk.libgtk_version >= v"3.20.0" +# Copy of Gtk.jl definition, but calls a function before running the widget +function infoDialog(func::Function, message::String, parent::Gtk.GtkWindow=Ahorn.window) + w = GtkMessageDialogLeaf(ccall((:gtk_message_dialog_new, Gtk.libgtk), Ptr{Gtk.GObject}, + (Ptr{Gtk.GObject}, Cint, Cint, Cint, Ptr{UInt8}), + parent, Gtk.GtkDialogFlags.DESTROY_WITH_PARENT, + Gtk.GtkMessageType.INFO, Gtk.GtkButtonsType.CLOSE, C_NULL)) + + set_gtk_property!(w, :text, message) + + func(w) + + run(w) + Gtk.destroy(w) +end + +infoDialog(message::String, parent::Gtk.GtkWindow=Ahorn.window) = infoDialog(w -> (), message, parent) +topMostInfoDialog(message::String, parent::Gtk.GtkWindow=Ahorn.window) = infoDialog(w -> GAccessor.keep_above(w, true), message, parent) + +# Copy of Gtk.jl definition, but calls a function before running the widget +askDialog(message::String, parent::Gtk.GtkWindow=Ahorn.window) = askDialog(message, "No", "Yes", parent) +askDialog(func::Function, message::String, parent::Gtk.GtkWindow=Ahorn.window) = askDialog(func, message, "No", "Yes", parent) + +function askDialog(func::Function, message::String, noText::String, yesText::String, parent::Gtk.GtkWindow=Ahorn.window) + dlg = GtkMessageDialog(message, ((noText, 0), (yesText, 1)), + Gtk.GtkDialogFlags.DESTROY_WITH_PARENT, Gtk.GtkMessageType.QUESTION, parent) + + func(dlg) + + response = run(dlg) + Gtk.destroy(dlg) + + return response == 1 +end + +askDialog(message::String, noText::String, yesText::String, parent::Gtk.GtkWindow=Ahorn.window) = askDialog(dlg -> (), message, noText, yesText, parent) +topMostAskDialog(message::String, parent::Gtk.GtkWindow=Ahorn.window) = askDialog(dlg -> GAccessor.keep_above(dlg, true), message, parent) + # Modified version of standard open dialog function openDialog(title::AbstractString, parent=GtkNullContainer(), filters::Union{AbstractVector, Tuple}=String[]; folder::String="", native::Bool=useNativeFileDialogs, kwargs...) local dlg @@ -294,7 +331,7 @@ function openDialog(title::AbstractString, parent=GtkNullContainer(), filters::U if response == GConstants.GtkResponseType.ACCEPT if multiple - filename_list = ccall((:gtk_file_chooser_get_filenames, libgtk), Ptr{Gtk._GSList{String}}, (Ptr{GObject},), dlgp) + filename_list = ccall((:gtk_file_chooser_get_filenames, Gtk.libgtk), Ptr{Gtk._GSList{String}}, (Ptr{GObject},), dlgp) selection = String[f for f in Gtk.GList(filename_list, true)] else diff --git a/src/property_menu.jl b/src/property_menu.jl index 96e5a75..f5d3df4 100644 --- a/src/property_menu.jl +++ b/src/property_menu.jl @@ -92,7 +92,7 @@ function displayProperties(x::Number, y::Number, room::Maple.Room, targetLayer:: width, height = Int(get(data, "width", minWidth)), Int(get(data, "height", minHeight)) if hasWidth && width < minWidth || hasHeight && height < minHeight - updateTarget = ask_dialog("The size specified is smaller than the recommended minimum size ($minWidth, $minHeight)\nDo you want to keep this size regardless?", lastPropertyWindow) + updateTarget = Ahorn.topMostAskDialog("The size specified is smaller than the recommended minimum size ($minWidth, $minHeight)\nDo you want to keep this size regardless?", lastPropertyWindow) end if updateTarget diff --git a/src/windows/room_window.jl b/src/windows/room_window.jl index 3668abe..7a20aaa 100644 --- a/src/windows/room_window.jl +++ b/src/windows/room_window.jl @@ -150,7 +150,7 @@ end function handleMusicTrack(data::Dict{String, Any}, parent::Gtk.GtkWindow=Ahorn.window) if data["music"] != "" && !(data["music"] in dropdownOptions["music"]) && !startswith(data["music"], "event:/") - info_dialog("You have entered an invalid song name.\nIf you're using a custom song, make sure to copy the event path from FMOD Studio, which starts with 'event:/'", parent) + Ahorn.topMostInfoDialog("You have entered an invalid song name.\nIf you're using a custom song, make sure to copy the event path from FMOD Studio, which starts with 'event:/'", parent) return true end @@ -161,7 +161,7 @@ end function handleRoomSize(data::Dict{String, Any}, simple::Bool=get(Ahorn.config, "use_simple_room_values", true), parent::Gtk.GtkWindow=Ahorn.window) minimumRecommendedDisplay = (floor(Int, 320 / (simple ? 8 : 1)), floor(Int, 184 / (simple ? 8 : 1))) if any(data["size"] .< minimumRecommended) - if !ask_dialog("The size you have chosen is smaller than the recommended minimum size $minimumRecommended.\nAre you sure you want this size?", parent) + if !Ahorn.topMostAskDialog("The size you have chosen is smaller than the recommended minimum size $minimumRecommended.\nAre you sure you want this size?", parent) return true end end @@ -177,7 +177,7 @@ function handleRoomName(data::Dict{String, Any}, currentRoom::Maple.Room, map::M return false end - info_dialog("The selected room name is already in use.", parent) + Ahorn.topMostInfoDialog("The selected room name is already in use.", parent) return true end @@ -216,10 +216,10 @@ end function createRoomWindow(creating::Bool=true, simple::Bool=get(Ahorn.config, "use_simple_room_values", true)) if Ahorn.loadedState.map === nothing - info_dialog("No map is currently loaded.", Ahorn.window) + Ahorn.topMostInfoDialog("No map is currently loaded.", Ahorn.window) elseif !creating && Ahorn.loadedState.room === nothing - info_dialog("Cannot edit non existing room.", Ahorn.window) + Ahorn.topMostInfoDialog("Cannot edit non existing room.", Ahorn.window) else updateTemplateRoom(creating) diff --git a/src/windows/styleground_window.jl b/src/windows/styleground_window.jl index 82fba54..b1c17d7 100644 --- a/src/windows/styleground_window.jl +++ b/src/windows/styleground_window.jl @@ -446,7 +446,7 @@ function getParallaxGrid(map::Maple.Map) Ahorn.updateTreeView!(parallaxList, getParallaxListRows(map.style), Ahorn.currentRow(parallaxList) + 1, updateByReplacement=true) else - info_dialog(Ahorn.Form.getIncorrectOptionsMessage(incorrectOptions), stylegroundWindow) + Ahorn.topMostInfoDialog(Ahorn.Form.getIncorrectOptionsMessage(incorrectOptions), stylegroundWindow) end end @@ -491,7 +491,7 @@ function getParallaxGrid(map::Maple.Map) Ahorn.updateTreeView!(parallaxList, getParallaxListRows(map.style), Ahorn.currentRow(parallaxList), updateByReplacement=true) else - info_dialog(Ahorn.Form.getIncorrectOptionsMessage(incorrectOptions), stylegroundWindow) + Ahorn.topMostInfoDialog(Ahorn.Form.getIncorrectOptionsMessage(incorrectOptions), stylegroundWindow) end end end @@ -615,7 +615,7 @@ function getEffectGrid(map::Maple.Map) end else - info_dialog(Ahorn.Form.getIncorrectOptionsMessage(incorrectOptions), stylegroundWindow) + Ahorn.topMostInfoDialog(Ahorn.Form.getIncorrectOptionsMessage(incorrectOptions), stylegroundWindow) end else @@ -675,7 +675,7 @@ function getEffectGrid(map::Maple.Map) Ahorn.updateTreeView!(effectList, getEffectListRows(map.style), select, updateByReplacement=true) else - info_dialog(Ahorn.Form.getIncorrectOptionsMessage(incorrectOptions), stylegroundWindow) + Ahorn.topMostInfoDialog(Ahorn.Form.getIncorrectOptionsMessage(incorrectOptions), stylegroundWindow) end end end @@ -728,7 +728,7 @@ end function createStylegroundWindow(widget::Ahorn.MenuItemsTypes) if Ahorn.loadedState.map === nothing - info_dialog("No map is currently loaded.", Ahorn.window) + Ahorn.topMostInfoDialog("No map is currently loaded.", Ahorn.window) else @Ahorn.catchall begin