So I am very new to Ruby and Tk and I have a Problem, which solution I didn't find after hours of research:
I have a directory which contains many projects.
With the following code I insert the names of the existing projects into a Listbox:
Expand|Select|Wrap|Line Numbers
- $projects = Dir.entries("#{Dir.pwd}/projects")[2..-1]
- $projects.each {|f| $list.insert 'end', f}
Expand|Select|Wrap|Line Numbers
- def searchprojects
- searchedprojects = []
- $list.clear()
- if $spec_ent.to_s.empty?
- $projects.each {|f| $list.insert 'end', f}
- else
- $projects.each {|i|
- i = i.to_s
searchedprojects.each {|f| $list.insert 'end', f}
end
end
And with the following code I chose the selected project (which shall be filtered before):
Expand|Select|Wrap|Line Numbers
- def show_project
- # updates the status of the chosen project
- idx = $list.curselection[0]
- $proj_name = $projects[idx]
- $status.value = "Project chosen: #{$proj_name}"
- end
Thanks for helping.