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

📄 gtk-file-selection.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) = "/usr/local/bin"	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//[c]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-defines"import "user/box"//[c]import "glib/glib"import "glib/glib-object"import "gtk/gtk"//[cf]//[of]:constants//[c]def open title := "Open"def save title := "Save"//[cf]//[of]:structures//[c]public struct pair of strings	string1 : string	string2 : stringend//[c]public struct file selector	private filename: string	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: intend//[cf]//[c]//[of]:initialize - release//[of]:initialize (m)//[c]public func initialize (s: file selector)	initialize (filenames (s), 8)	filename (s) = empty string	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) = 1end//[cf]//[of]:release (m)//[c]public func release (s: file selector)	each (filenames (s)) ? f		delete (f)	end	release (filenames (s))	delete (filename (s))end//[cf]//[cf]//[of]:operations//[of]:open (m)//[c]Open the dialog box//[c]private [name="c"] import func g_strfreev ([][] gchar)private func get title (s: file selector)	def title = title (s)	if is nil (title)		if save (s)			title = save title		else			title = open title		end	end	return titleendpublic func open (s: file selector)	def fs = gtk_file_selection_new (title (s)) : GtkFileSelection	def multi = bool to gboolean (multiselection (s))	gtk_file_selection_set_select_multiple (fs, multi)	gtk_window_set_title (fs, get title (s))	def t := temp string buffer	if not empty (initial path (s))		t << initial path (s) << path separator	end	if not empty (initial name (s))		t << initial name (s)	end	gtk_file_selection_set_filename (fs, as string (t))	release (t)	gtk_window_set_modal (fs, TRUE)	gtk_window_set_transient_for (fs, widget (parent (s)) : GtkWindow)		def ok = (gtk_dialog_run (fs) == GTK_RESPONSE_OK:gint)	if ok		delete (filename (s))		filename (s) = new string (gtk_file_selection_get_filename (fs))	end	if ok & multiselection (s)		def a = gtk_file_selection_get_selections (fs)		def p = a		while not nil (p [])			add (filenames (s), new string (p[]))			++p		end		g_strfreev (a)	end		gtk_widget_destroy (fs)		// Must restore the focus immediately	if not nil (parent (s))		set focus (parent (s))	end	return okend//[cf]//[cf]//[of]:enumerating//[of]:each (m)//[c]Enumerates all files (use when multi-selection enabled)//[c]public equ each (s: file selector)	each (filenames (s)) ? f		yield (f)	endend//[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 + -