2 Copyright 2007-2008 Vincent Carmona
4 This file is part of ZiK.
6 ZiK is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 ZiK is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with ZiK; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #**********************************
21 #-----Tree explorer----------------
22 #**********************************
24 ####################Voir /usr/share/doc/libgtk2-ruby/examples/gtk-demo/main.rb
26 class Tree < Gtk::TreeStore
28 def refresh(directory,ext)
29 printf 'Refreshing treeview...'
33 extension+=ext+',' if show
37 unless directory[0].nil? or extension.empty?
41 lr=rpath.split('/').length
42 songa=Dir.glob(File.join(rpath,"**","*.{"+extension+"}"),File::FNM_CASEFOLD).sort
46 dirl=rpath#last directory scanned
47 child_rec=[]#keep record of children
49 ext=File.extname(song)
50 name=File.basename(song,ext)
51 dir=File.dirname(song)
53 #Songs in root directory
54 child= self.append(root)
60 dira=dir.split('/');la=dira.length
62 unless dira[lr]==dirla[lr]
63 #sub-directories of root directory
64 child=self.append(root)
70 unless dira[j]==dirla[j]
71 #all sub-directories of first children directories
72 child=self.append(child_rec[j-lr-1])
78 #Songs in other directories
79 child=self.append(child_rec[la-1-lr])