Skip to content
This repository has been archived by the owner on Aug 15, 2024. It is now read-only.

Commit

Permalink
Fixed sub-window positioning.
Browse files Browse the repository at this point in the history
Windows should no longer get stuck under other windows.
  • Loading branch information
Cruor authored and Vexatos committed Feb 18, 2020
1 parent b353155 commit 2a52813
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 19 deletions.
15 changes: 8 additions & 7 deletions src/helpers/form_helper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -534,23 +534,24 @@ 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)

if data !== nothing
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

Expand Down
39 changes: 38 additions & 1 deletion src/helpers/gtk_helpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/property_menu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/windows/room_window.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions src/windows/styleground_window.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2a52813

Please sign in to comment.