View Full Version : Select a File Screen
DoubleDub
12-30-2008, 01:38 PM
I need a screen that allows the users to select a file, exactly like the "Select Install Folder" screen only showing a file browse. I can't find anything in the stock screens. Any ideas?
DoubleDub
12-30-2008, 01:44 PM
Okay, so I realized I could create a new global function using most of the g_EditFieldFolderBrowse function as such:
--[[
************************************************** ********************************
Function: g_EditFieldFileBrowse
Purpose: Browses for a file and fills an edit field with the path. It uses
the edit field's text as the initial folder in the folder browse dialog.
Arguments: (number) nIDEditField - The ID of the edit field
(string) strPrompt - The prompt for the folder browse dialog
Returns: Nothing.
************************************************** ********************************
--]]
function g_EditFieldFileBrowse(nIDEditField, strPrompt)
-- get the current properties of the edit field
local tbEditProps = DlgEditField.GetProperties(nIDEditField);
if(not tbEditProps) then
-- The edit field is not accessible or does not exist
return;
end
-- display a folder browse dialog, using the current contents of the edit
-- field as the initial folder path (the folder to start browsing from)
local strInitialFolder = tbEditProps.Text;
local strTargetFile = Dialog.FileBrowse(true, strPrompt, strInitialFolder, "All Files (*.*)|*.*|", "", false, true);
if((strTargetFile == "") or (strTargetFile == "CANCEL")) then
return;
end
-- replace the contents of the edit field with the folder path that was selected
tbEditProps.Text = strTargetFile;
DlgEditField.SetProperties(nIDEditField, tbEditProps);
end
DoubleDub
12-30-2008, 02:13 PM
A few corrections due to FileBrowse returning a table instead of a string and a missing parameter:
--[[
************************************************** ********************************
Function: g_EditFieldFileBrowse
Purpose: Browses for a file and fills an edit field with the path. It uses
the edit field's text as the initial folder in the folder browse dialog.
Arguments: (number) nIDEditField - The ID of the edit field
(string) strPrompt - The prompt for the folder browse dialog
Returns: Nothing.
************************************************** ********************************
--]]
function g_EditFieldFileBrowse(nIDEditField, strPrompt, strFileFilters)
-- get the current properties of the edit field
local tbEditProps = DlgEditField.GetProperties(nIDEditField);
if(not tbEditProps) then
-- The edit field is not accessible or does not exist
return;
end
-- display a folder browse dialog, using the current contents of the edit
-- field as the initial folder path (the folder to start browsing from)
local strInitialFolder = tbEditProps.Text;
local strTarget = {};
local strTarget = Dialog.FileBrowse(true, strPrompt, strInitialFolder, strFileFilters, "", "", false, true);
local strTargetFile = strTarget[1];
if((strTargetFile == "") or (strTargetFile == "CANCEL")) then
return;
end
-- replace the contents of the edit field with the folder path that was selected
tbEditProps.Text = strTargetFile;
DlgEditField.SetProperties(nIDEditField, tbEditProps);
end
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.