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

📄 gtk-file-chooser.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]:importsimport "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"//[c]import "user/box"import "private/sys-graphics"//[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]public func open (s: file selector)	def w = 		gtk_file_chooser_dialog_new_1 (			to UTF8 (get title (s)), 			widget (parent (s)): GtkWindow,			save (s) -> GTK_FILE_CHOOSER_ACTION_SAVE, GTK_FILE_CHOOSER_ACTION_OPEN,			GTK_STOCK_CANCEL:[]gchar, GTK_RESPONSE_CANCEL:[]gchar,			save (s) -> GTK_STOCK_SAVE, GTK_STOCK_OPEN:[]gchar, 			GTK_RESPONSE_ACCEPT:[]gchar) : GtkFileChooserDialog	def fs = g_type_check_instance_cast (w, gtk_file_chooser_get_type): GtkFileChooser	def multi = bool to gboolean (multiselection (s))	gtk_file_chooser_set_select_multiple (fs, multi)		def initial path = initial path (s)	if not empty (initial path)		gtk_file_chooser_set_current_folder (fs, initial path)	end	gtk_dialog_set_default_response(w, GTK_RESPONSE_ACCEPT)	if save (s) && not empty (initial name (s))		gtk_file_chooser_set_current_name (fs, initial name (s))	end	def ok = (gtk_dialog_run (w) == GTK_RESPONSE_ACCEPT:gint)	if ok		delete (filename (s))		filename (s) = new string (gtk_file_chooser_get_filename (fs))	end	if ok & multiselection (s)		def list = gtk_file_chooser_get_filenames (fs)		while not nil (list)			def fn = data (list)			add (filenames (s), new string (fn: string))			g_free (fn)			list = g_slist_next (list)		end		g_slist_free (list)	end		gtk_widget_destroy (w)		// Must restore the focus immediately	if not nil (parent (s))		set focus (parent (s))	end	return okend//[c]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 titleend//[c]//[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 + -