pub fn add_chapter(&mut self, position: u64, duration: u64) -> Option<gtk::TreeIter> {
        let (new_iter, end, end_str) = match self.selected_iter.take() {
            Some(selected_iter) => {
                // a chapter is currently selected
                let (current_start, current_end, current_end_str) = {
                    let selected_chapter = ChapterEntry::new(&self.store, &selected_iter);
                    (
                        selected_chapter.start(),
                        selected_chapter.end(),
                        selected_chapter.end_str(),
                    )
                };

                if current_start != position {
                    // update currently selected chapter end
                    // to match the start of the newly added chapter
                    self.store.set(
                        &selected_iter,
                        &[END_COL, END_STR_COL],
                        &[&position, &Timestamp::format(position, false)],
                    );
                    let new_iter = self.store.insert_after(None, &selected_iter);
                    (new_iter, current_end, current_end_str)
                } else {
                    // attempting to add the new chapter at current position
                    // => restore current state
                    self.selected_iter = Some(selected_iter);
                    return None;
                }
            }
            None => {
                match self.iter.take() {
                    Some(iter) => {
                        // chapters are available, but none is selected:
                        // either position is before the first chapter
                        // or in a gap between two chapters
                        let iter_chapter = ChapterEntry::new(&self.store, &iter);
                        let new_chapter_end = iter_chapter.start();
                        if position > new_chapter_end {
                            panic!(
                                concat!(
                                    "ChapterTreeManager::add_chapter inconsistent position",
                                    " {} with regard to current iter [{}, {}]",
                                ),
                                position,
                                iter_chapter.start(),
                                iter_chapter.end(),
                            );
                        }

                        let new_iter = self.store.insert_before(None, &iter);
                        (new_iter, new_chapter_end, iter_chapter.start_str())
                    }
                    None => {
                        // No chapter in iter:
                        // either position is passed the end of last chapter
                        // or there is no chapter
                        let insert_position = match self.store.get_iter_first() {
                                    None => // No chapter yet => inset at the beginning
                                        0i32,
                                    Some(_) => // store contains chapters => insert at the end
                                        -1i32,
                                };

                        let new_iter = self.store.insert(None, insert_position);
                        (new_iter, duration, Timestamp::format(duration, false))
                    }
                }
            }
        };

        let default_title = get_default_chapter_title();
        self.store.set(
            &new_iter,
            &[TITLE_COL, START_COL, START_STR_COL, END_COL, END_STR_COL],
            &[
                &default_title,
                &position,
                &Timestamp::format(position, false),
                &end,
                &end_str,
            ],
        );

        self.boundaries
            .borrow_mut()
            .add_chapter(position, end, &default_title, &new_iter);

        self.selected_iter = Some(new_iter.clone());
        self.iter = Some(new_iter.clone());

        Some(new_iter)
    }
// Returns an iter on the new chapter
Returns an iter on the new chapter
Returns an iter on the new chapter
pub fn add_chapter(&mut self, position: u64, duration: u64) -> Option<gtk::TreeIter> {
        let (new_iter, end, end_str) = match self.selected_iter.take() {
            Some(selected_iter) => {
                // a chapter is currently selected
                let (current_start, current_end, current_end_str) = {
                    let selected_chapter = ChapterEntry::new(&self.store, &selected_iter);
                    (
                        selected_chapter.start(),
                        selected_chapter.end(),
                        selected_chapter.end_str(),
                    )
                };
                if current_start != position {
                    // update currently selected chapter end
                    // to match the start of the newly added chapter
                    self.store.set(
                        &selected_iter,
                        &[END_COL, END_STR_COL],
                        &[&position, &Timestamp::format(position, false)],
                    );
                    let new_iter = self.store.insert_after(None, &selected_iter);
                    (new_iter, current_end, current_end_str)
                } else {
                    // attempting to add the new chapter at current position
                    // => restore current state
                    self.selected_iter = Some(selected_iter);
                    return None;
                }
            }
            None => {
                match self.iter.take() {
                    Some(iter) => {
                        // chapters are available, but none is selected:
                        // either position is before the first chapter
                        // or in a gap between two chapters
                        let iter_chapter = ChapterEntry::new(&self.store, &iter);
                        let new_chapter_end = iter_chapter.start();
                        if position > new_chapter_end {
                            panic!(
                                concat!(
                                    "ChapterTreeManager::add_chapter inconsistent position",
                                    " {} with regard to current iter [{}, {}]",
                                ),
                                position,
                                iter_chapter.start(),
                                iter_chapter.end(),
                            );
                        }
                        let new_iter = self.store.insert_before(None, &iter);
                        (new_iter, new_chapter_end, iter_chapter.start_str())
                    }
                    None => {
                        // No chapter in iter:
                        // either position is passed the end of last chapter
                        // or there is no chapter
                        let insert_position = match self.store.get_iter_first() {
                                    None => // No chapter yet => inset at the beginning
                                        0i32,
                                    Some(_) => // store contains chapters => insert at the end
                                        -1i32,
                                };
                        let new_iter = self.store.insert(None, insert_position);
                        (new_iter, duration, Timestamp::format(duration, false))
                    }
                }
            }
        };
        let default_title = get_default_chapter_title();
        self.store.set(
            &new_iter,
            &[TITLE_COL, START_COL, START_STR_COL, END_COL, END_STR_COL],
            &[
                &default_title,
                &position,
                &Timestamp::format(position, false),
                &end,
                &end_str,
            ],
        );
        self.boundaries
            .borrow_mut()
            .add_chapter(position, end, &default_title, &new_iter);
        self.selected_iter = Some(new_iter.clone());
        self.iter = Some(new_iter.clone());
        Some(new_iter)
    }
pub fn add_chapter ( & mut self , position : u64 , duration : u64 ) -> Option < gtk :: TreeIter > { let ( new_iter , end , end_str ) = match self . selected_iter . take ( ) { Some ( selected_iter ) => { // a chapter is currently selected let ( current_start , current_end , current_end_str ) = { let selected_chapter = ChapterEntry :: new ( & self . store , & selected_iter ) ; ( selected_chapter . start ( ) , selected_chapter . end ( ) , selected_chapter . end_str ( ) , ) } ; if current_start != position { // update currently selected chapter end // to match the start of the newly added chapter self . store . set ( & selected_iter , & [ END_COL , END_STR_COL ] , & [ & position , & Timestamp :: format ( position , false ) ] , ) ; let new_iter = self . store . insert_after ( None , & selected_iter ) ; ( new_iter , current_end , current_end_str ) } else { // attempting to add the new chapter at current position // => restore current state self . selected_iter = Some ( selected_iter ) ; return None ; } } None => { match self . iter . take ( ) { Some ( iter ) => { // chapters are available, but none is selected: // either position is before the first chapter // or in a gap between two chapters let iter_chapter = ChapterEntry :: new ( & self . store , & iter ) ; let new_chapter_end = iter_chapter . start ( ) ; if position > new_chapter_end { panic ! ( concat ( " " " " ) position iter_chapter start ( ) iter_chapter end ( ) ) ; } let new_iter = self . store . insert_before ( None , & iter ) ; ( new_iter , new_chapter_end , iter_chapter . start_str ( ) ) } None => { // No chapter in iter: // either position is passed the end of last chapter // or there is no chapter let insert_position = match self . store . get_iter_first ( ) { None => // No chapter yet => inset at the beginning 0i32 , Some ( _ ) => // store contains chapters => insert at the end - 1i32 , } ; let new_iter = self . store . insert ( None , insert_position ) ; ( new_iter , duration , Timestamp :: format ( duration , false ) ) } } } } ; let default_title = get_default_chapter_title ( ) ; self . store . set ( & new_iter , & [ TITLE_COL , START_COL , START_STR_COL , END_COL , END_STR_COL ] , & [ & default_title , & position , & Timestamp :: format ( position , false ) , & end , & end_str , ] , ) ; self . boundaries . borrow_mut ( ) . add_chapter ( position , end , & default_title , & new_iter ) ; self . selected_iter = Some ( new_iter . clone ( ) ) ; self . iter = Some ( new_iter . clone ( ) ) ; Some ( new_iter ) }
Returns an iter on the new chapter
Returns an iter on the new chapter
&mut self
position
u64
duration
u64
&mut self
position
u64
duration
u64