def cb_read
    return unless wait_for_loading&&$main_bible.valid?
    req=Request::new(Request::READ,$main_textview)
    return unless req.valid
    $request.push req
    req.show
    $request.shift if $request.length>MAX_REQUEST
    $casual_request=$request.length-1
    update_forrew_buttons
end

class ReadDialog < Gtk::Dialog

    class MiniBook
	attr_reader :name,:chapters,:number
	def initialize(number,name,chapters)
	    @number=number
	    @name=name
	    @chapters=Array::new
	    chapters.each {|ch| @chapters.push MiniChapter::new(self,ch)}
	end
	def <=>(o)
	    return @number<=>o.number
	end
    end

    class MiniChapter
	attr_reader :number
	def initialize(mini_book,number)
	    @book=mini_book
	    @number=number
	end
	def fake_number
	    return 1 if @number==BibleChapter::NONE
	    @number
	end
    end

    def initialize(bible=$main_bible)
	super("Lire un livre ou un chapitre", 
	      $main_window, 
	      Gtk::Dialog::MODAL|Gtk::Dialog::DESTROY_WITH_PARENT, 
	      [Gtk::Stock::CANCEL,Gtk::Dialog::RESPONSE_CANCEL], 
	      [Gtk::Stock::OK,Gtk::Dialog::RESPONSE_OK]
	     )
	hbox=Gtk::HBox::new(false,0)
	vbox.pack_start(hbox)
	img=Gtk::Image::new(Gtk::Stock::DIALOG_QUESTION,Gtk::IconSize::DIALOG)
	hbox.pack_start(img,false,false,0)
	hboxr=Gtk::HBox::new(false,10)
	hbox.pack_start(hboxr,true,true,0)

	#@title_list=title_list
	#@chap_number_list=chap_number_list

	books_window=Gtk::ScrolledWindow::new()
	books_window.set_policy(Gtk::PolicyType::NEVER,Gtk::POLICY_AUTOMATIC)
	@books_store=Gtk::ListStore::new(MiniBook)
	bible.mini_books_list.each do |number,name,noc| 
	    @books_store.append[0]=MiniBook::new(number,name,noc)
	end
	@books_view=Gtk::TreeView::new
	@books_view.model=@books_store
	@books_view.insert_column(0,'Livre',Gtk::CellRendererText::new){|tvc,cell,model,iter| cell.text=iter.get_value(0).name}
	books_window.add(@books_view)
	@books_view.signal_connect("cursor_changed"){|tree| if @books_view.selection.selected then update_chapters(@books_view.selection.selected.get_value(0)) end}
	@books_view.signal_connect("button_press_event"){|widget,event| if event.button==1&&event.event_type==Gdk::Event::BUTTON2_PRESS then response(Gtk::Dialog::RESPONSE_OK) end}
	hboxr.pack_start(books_window,true,true,0)

	chapters_window=Gtk::ScrolledWindow::new()
	chapters_window.set_policy(Gtk::PolicyType::NEVER,Gtk::POLICY_AUTOMATIC)
	@chapters_store=Gtk::ListStore::new(MiniChapter)
	@chapters_view=Gtk::TreeView::new
	@chapters_view.model=@chapters_store
	@chapters_view.insert_column(0,'Chapitre',Gtk::CellRendererText::new){|tvc,cell,model,iter| cell.text=iter.get_value(0).fake_number.to_s}
	chapters_window.add(@chapters_view)
	@chapters_view.signal_connect("button_press_event"){|widget,event| if event.button==1&&event.event_type==Gdk::Event::BUTTON2_PRESS then response(Gtk::Dialog::RESPONSE_OK) end}
	hboxr.pack_start(chapters_window,true,true,0)

	resize(400,400)

	hbox.show_all
    end
    def update_chapters(mini_book)
	@chapters_store.clear
	list=mini_book.chapters
	list.each {|c| @chapters_store.append[0]=c}
    end

    def reference
	book=@books_view.selection.selected.get_value(0)
	iter=@chapters_view.selection.selected
	chapter=if iter then iter.get_value(0) else nil end
	if chapter
	    return Reference::new(book.number,chapter.number,Reference::ALL)
	else
	    return Reference::new(book.number,Reference::ALL,Reference::ALL)
	end
    end
end
