Hi, Milind Gupta.
It make sense only for non-multiple filters.
For single filter you can perform custom check for file existence, and,
if file exist - mimic warning dialog.
Example in attach.
But I can't setup properly PARENTDIALOG.
11/12/2014 2:14, Milind Gupta пишет:
When using the filedlg i noticed that if we have a filter and we type in
the name of the file it does not append the filter extension to the name of
the file. We can check for that and add it ourselves but the problem is
that the filedlg gives the overwriting confirmation based on the file name
it has and does not append the filter extension before checking for
overwrite condition.
Milind
local iup = require("iuplua")
local function file_exists(path)
local f = io.open(path, "rb")
if f then f:close() end
return f ~= nil
end
local function save_file(info, suffix)
local result
local exfilter = ("%s|*%s"):format(info, suffix:lower())
local filedlg = iup.filedlg {
DIALOGTYPE = "SAVE",
EXTFILTER = exfilter,
MULTIPLEFILES = "NO",
SHOWPREVIEW = "NO",
file_cb = function(this, file_name, status)
if status == "OK" then
if not file_name:lower():match("%.[^\\.]*$") then
local fixed_fname = file_name .. suffix
if file_exists(fixed_fname) then
local warndlg = iup.messagedlg{
--PARENTDIALOG = this,
DIALOGTYPE = "WARNING",
BUTTONS = "YESNO",
BUTTONDEFAULT = 2,
TITLE = "Save As",
VALUE = ("%s already exists.\nDo you want to
replace it?"):format(fixed_fname),
}
warndlg:popup()
if warndlg.BUTTONRESPONSE == "2" then
return iup.CONTINUE
end
iup.Destroy(warndlg)
result = fixed_fname
end
end
end
end,
}
filedlg:popup()
return result or filedlg.VALUE
end
local dlg = iup.dialog{
RASTERSIZE = "200x100",
iup.vbox{
iup.button {
TITLE = "Save to Text File",
action = function (this)
local fname = save_file("Text file", ".txt")
print("RESULT:", fname)
end,
}
},
}
dlg:showxy(iup.CENTER, iup.CENTER)
iup.MainLoop()
------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://pubads.g.doubleclick.net/gampad/clk?id=154624111&iu=/4140/ostg.clktrk
_______________________________________________
Iup-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/iup-users