*curselection
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:
I created a searchbar with a button which allows to find a specific entry:
searchedproject s.insert(search edprojects.leng th(), i) if i.downcase.incl ude? $spec_ent.to_s. downcase}
searchedproject s.each {|f| $list.insert 'end', f}
end
end
And with the following code I chose the selected project (which shall be filtered before):
My Problem: After I filtered the Listbox with my searchbar, and I chose a project in the Listbox, I get the wrong drectory(name), because of the index. For instance, when i filter the Listbox, it contains only 3 entries, and I chose the third, it will give me the third entry of the unfiltered Listbox.
Thanks for helping.
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:
Code:
$projects = Dir.entries("#{Dir.pwd}/projects")[2..-1]
$projects.each {|f| $list.insert 'end', f}
Code:
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
searchedproject s.each {|f| $list.insert 'end', f}
end
end
And with the following code I chose the selected project (which shall be filtered before):
Code:
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.
Comment