⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 file-selector-box.zc

📁 实现树形结构
💻 ZC
字号:
//[c]The file selector dialog box
//[c]
//[of]:license
//[c]    Code Browser - a folding text editor for programmers
//[c]    Copyright (C) 2003-07 Marc Kerbiquet
//[c]
//[c]    This program is free software; you can redistribute it and/or modify
//[c]    it under the terms of the GNU General Public License as published by
//[c]    the Free Software Foundation; either version 2 of the License, or
//[c]    (at your option) any later version.
//[c]
//[c]    This program is distributed in the hope that it will be useful,
//[c]    but WITHOUT ANY WARRANTY; without even the implied warranty of
//[c]    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//[c]    GNU General Public License for more details.
//[c]
//[c]    You should have received a copy of the GNU General Public License
//[c]    along with this program; if not, write to the Free Software
//[c]    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//[cf]
//[of]:example of use
//[c]
/*

Example of use:

	def s: local file selector
	initialize (s)
	parent (s) = m
	title (s) = "Open file"
	initial name (s) = "choose file"
	initial path (s) = "e:\\devel\\applications\\decompiler"
	multiselection (s) = true
	filters (s) = 
		const [] local pair of strings (
			"All (*.*)", "*.*",
			"C++ (*.cpp;*.h)", "*.cpp;*.h",
			nil, nil)
	filter index (s) = 2

	if open (s)
		def fn := temp string buffer
		
		each (s) {f}
			fn << f << "\r\n"
		end
		
		set text (e3[], as string (fn))
		release (fn)
	end

*/
//[cf]
//[of]:imports
import "base/types"
import "base/memory-allocator"
import "collection/vector"
import "text/string"
import "text/string-buffer"
import "text/vector-of-strings"
import "file/file"
import "user/box"
//[c]
import "win32/windows"
import "win32/commdlg"
//[cf]
//[of]:constants
//[c]
equ buffer size = 4096
//[cf]
//[of]:structures
//[c]
public struct pair of strings
	string1 : string
	string2 : string
end
//[c]
public struct file selector

	private p : local OPENFILENAMEA
	private filename: [buffer size] char
	private filenames: local vector of strings

	save: bool	
	multiselection: bool
	parent: box
	title: string
	initial path: string
	initial name: string
	filters: [] local pair of strings
	filter index: dword

end
//[cf]
//[c]
//[of]:initialize - release
//[of]:initialize (m)
//[c]
public func initialize (s: file selector)

	initialize (filenames (s), 8)
	save (s) = false
	multiselection (s) = false
	parent (s) = nil
	title (s) = nil // "Open" by default
	initial path (s) = empty string
	initial name (s) = empty string
	filters (s) = nil
	filter index (s) = 1

end
//[cf]
//[of]:release (m)
//[c]
public func release (s: file selector)

	each (filenames (s)) ? f
		delete (f)
	end
	release (filenames (s))

end
//[cf]
//[cf]
//[of]:operations
//[of]:open (m)
//[c]Open the dialog box
//[c]
public func open (s: file selector)

	def filters = temp string buffer
	def pair = filters (s)
	repeat
		def s1 = string1 (pair[])
		def s2 = string2 (pair[])
		if is nil (s1)
			break
		end
		filters << s1 << \0
		filters << s2 << \0
		++pair
	end
	filters << \0 << \0
	
	def flags = OFN_HIDEREADONLY
	if multiselection (s)
		flags |= OFN_ALLOWMULTISELECT | OFN_EXPLORER
	end
	if save (s)
		flags |= OFN_OVERWRITEPROMPT
	end

	copy (filename (s), initial name (s))

	def p = p (s)
	p.lStructSize = sizeof local OPENFILENAMEA
	p.hwndOwner = hwnd (parent (s))
	p.hInstance = nil
	p.lpstrFilter = base (filters)
	p.lpstrCustomFilter = nil
	p.nMaxCustFilter = 0
	p.nFilterIndex = filter index (s)
	p.lpstrFile = filename (s)
	p.nMaxFile = buffer size
	p.lpstrFileTitle = nil
	p.nMaxFileTitle = 0
	p.lpstrInitialDir = initial path (s)
	p.lpstrTitle = title (s)
	p.Flags = flags
	p.nFileOffset = 0:w
	p.nFileExtension = 0:w
	p.lpstrDefExt = nil
	p.lCustData = 0
	p.lpfnHook = nil
	p.lpTemplateName = nil

	def ok : bool
	if save (s)
		ok = GetSaveFileNameA (p) <> 0
	else
		ok = GetOpenFileNameA (p) <> 0
	end

	release (filters)

	if ok & multiselection (s)
		def f = filename (s)
		def l = size (f) + 1
		def e = f + l
		if is nul (e[])
			add (filenames (s), new string (f))
		else
			def stream := temp string buffer
			while not nul (e[])
				remove all (stream)
				stream << f << path separator << e
				add (filenames (s), new string (stream))
				e += size (e) + 1
			end
			release (stream)
		end
	end
	
	filter index (s) = nFilterIndex (p)

	return ok
end
//[cf]
//[cf]
//[of]:enumerating
//[of]:each (file selector)
//[c]Enumerates all files (use when multi-selection enabled)
//[c]
public equ each (s: file selector)
	each (filenames (s)) ? f
		yield (f)
	end
end
//[cf]
//[cf]
//[of]:accessing
//[of]:get filename (m, string buffer)
//[c]Appends the selected filename to the string buffer
//[c]
public func get filename (s: file selector, stream: string buffer)
	stream << filename (s)
end
//[cf]
//[cf]

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -