CommonCtrl.OpenFileDialog

Open File Dialog

Title Open File Dialog
Author(s) LiXizhi
Date 2007/5/15
File script/ide/OpenFileDialog.lua

Description

TIP Sample Code

NPL.load("(gl)script/ide/OpenFileDialog.lua");
local ctl = CommonCtrl.OpenFileDialog:new{
   name = "OpenFileDialog1",
   alignment = "_ct",
   left=-256, top=-150,
   width = 512,
   height = 380,
   parent = nil,
   fileextensions = {"all files(*.*)", "images(*.jpg; *.png; *.dds)", "animations(*.swf; *.wmv; *.avi)", "web pages(*.htm; *.html)", },
   folderlinks = {
      {path = "model/", text = "model"},
      {path = "Texture/", text = "Texture"},
      {path = "character/", text = "character"},
      {path = "script/", text = "script"},
   },
};
ctl:Show(true);

-- external open using win32 dialog
NPL.load("(gl)script/ide/OpenFileDialog.lua");
local filename = CommonCtrl.OpenFileDialog.ShowDialog_Win32();
if(filename) then
   commonlib.log(filename);
end

Member Functions

OpenFileDialog:new

 common control library
NPL.load("(gl)script/ide/common_control.lua");
local L = CommonCtrl.Locale("IDE");

 define a new control in the common control libary

 default member attributes
local OpenFileDialog = {
   -- the top level control name
   name = "OpenFileDialog1",
   -- the title to be displayed. 
   title = nil,
   -- normal window size
   alignment = "_lt",
   left = 0,
   top = 0,
   width = 512,
   height = 290, 
   -- TODO: how a dialog is poped up. if nil, it is just displayed as a top level window. 
   -- If 1, it will gradually grey out the background and pops up with an animation. 
   -- If 2, it will grey out the background and pops up WITHOUT animations. 
   PopupStyle = 1,
   parent = nil,
   -- what kind of file extensions to load, the first one is always the default one.
   fileextensions = {"all files(*.*)", "images(*.jpg; *.png; *.dds)", "animations(*.swf; *.wmv; *.avi)", "web pages(*.htm; *.html)", },
   -- at most four items
   folderlinks = {
      {folder = "model/", text = "model"},
      {folder = "Texture/", text = "Texture"},
      {folder = "character/", text = "character"},
      {folder = "script/", text = "script"},
   },
   -- [used only internally] current folder, if nil, it will be the folder specifeid by the currentFolderlinkIndex
   currentFolder = nil, 
   -- how many sub directory levels to show for the current folder.
   showSubDirLevels = 0,
   -- whether check the file existance
   CheckFileExists = true,
   -- event if CheckFileExists is true, we can specify a filename pass filter like "http://.*", so that the open file dialog will 
   -- return when the user has specified a filename that contains could pass the specified filter. 
   FileNamePassFilter = nil,
   -- initial file name to be displayed, usually "" 
   FileName = "",
   -- appearance
   openInExplorerBtn_bg = "Texture/3DMapSystem/common/folder_go.png",
   deleteFileBtn_bg = "Texture/3DMapSystem/common/folder_delete.png",
   renameFileBtn_bg = "Texture/3DMapSystem/common/folder_edit.png",
   openAddFolderBtn_bg = "Texture/3DMapSystem/common/folder_add.png",
   main_bg = nil, -- use default container bg
   -- oncheck event, it can be nil, a string to be executed or a function of type void ()(sCtrlName, filename)
   onopen = nil,
}
OpenFileDialog = OpenFileDialog;

constructor

syntax

function OpenFileDialog:new (o)

parameters

o  

OpenFileDialog:Destroy

Destroy the UI control

syntax

function OpenFileDialog:Destroy ()

OpenFileDialog.ShowDialog_Win32

use the external dialog

  • param filter : "All Files (.)\0*.*\0"
  • return the : filename selected or nil if nothing is selected or user clicked cancel.

syntax

function OpenFileDialog.ShowDialog_Win32(filter)

parameters

filter "All Files (.)\0*.*\0"

OpenFileDialog:Show

  • param bShow : boolean to show or hide. if nil, it will toggle current setting.

syntax

function OpenFileDialog:Show(bShow)

parameters

bShow boolean to show or hide. if nil, it will toggle current setting.

OpenFileDialog:Update

update the UI according to the current selected folder and text

syntax

function OpenFileDialog:Update()

OpenFileDialog:GetFileName

get the file name

syntax

function OpenFileDialog:GetFileName()

CommonCtrl.OpenFileDialog.OnClickFolder

when a folder is clicked.

syntax

function CommonCtrl.OpenFileDialog.OnClickFolder(self, filepath)

parameters

self  
filepath  

CommonCtrl.OpenFileDialog.OnFileSelected

select the file to file name box

syntax

function CommonCtrl.OpenFileDialog.OnFileSelected(sCtrlName)   

parameters

sCtrlName  

CommonCtrl.OpenFileDialog.OnFileSelectedAndOpen

select and open file. called when double click on file.

syntax

function CommonCtrl.OpenFileDialog.OnFileSelectedAndOpen(sCtrlName)

parameters

sCtrlName  

CommonCtrl.OpenFileDialog.OnClickOpenInExplorer

open in external browser

syntax

function CommonCtrl.OpenFileDialog.OnClickOpenInExplorer(sCtrlName)

parameters

sCtrlName  

CommonCtrl.OpenFileDialog.OnClickAddFolder

TODO: add folder to current directory

syntax

function CommonCtrl.OpenFileDialog.OnClickAddFolder(sCtrlName)

parameters

sCtrlName  

OpenFileDialog.OnClose

close the given control

syntax

function OpenFileDialog.OnClose(sCtrlName)

parameters

sCtrlName  
Topic revision: r1 - 2008-02-29 - LiXizhi
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback