pub unsafe fn paste(&self, app_ui: &Rc<AppUI>, pack_file_contents_ui: &Rc<PackFileContentsUI>) {

        // Get the current selection. We treat it like a TSV, for compatibility with table editors.
        // Also, if the text ends in \n, remove it. Excel things.
        let mut text = QGuiApplication::clipboard().text().to_std_string();
        if text.ends_with('\n') { text.pop(); }
        let rows = text.split('\n').collect::<Vec<&str>>();
        let rows = rows.iter().map(|x| x.split('\t').collect::<Vec<&str>>()).collect::<Vec<Vec<&str>>>();

        // Get the current selection and his, visually speaking, first item (top-left).
        let indexes = self.table_view_primary.selection_model().selection().indexes();
        let mut indexes_sorted = (0..indexes.count_0a()).map(|x| indexes.at(x)).collect::<Vec<Ref<QModelIndex>>>();
        sort_indexes_visually(&mut indexes_sorted, &self.get_mut_ptr_table_view_primary());

        // If nothing is selected, got back to where you came from.
        if indexes_sorted.is_empty() { return }

        // At this point we should have the strings to paste and the selection. Now, clever pasting ahead:
        // - If the entire selection are rows of the same amount of cells and we have only one row of text with the exact same amount
        //   of items as the rows, we paste the same row in each selected row.
        // - If we only have one TSV value in the text and a ton of cells selected, paste the same value everywhere.
        // - In any other case, pick the first selected cell, and paste the TSV using that as cell 0,0.
        let same_amount_of_cells_selected_per_row = if rows.len() == 1 {
            let mut row = -1;
            let mut items = 0;
            let mut is_valid = true;
            for index in &indexes_sorted {
                if row == -1 {
                    row = index.row();
                }

                if index.row() == row {
                    items += 1;
                } else {
                    if items < rows[0].len() {
                        is_valid = false;
                        break;
                    }
                    row = index.row();
                    items = 1
                }

                if items > rows[0].len() {
                    is_valid = false;
                    break;
                }
            }
            is_valid
        } else { false };

        // Amount of rows selected, to ensure certain behavior only triggers when we got the correct number of rows selected.
        let mut rows_selected = indexes_sorted.iter().map(|x| x.row()).collect::<Vec<i32>>();
        rows_selected.sort_unstable();
        rows_selected.dedup();

        if rows.len() == 1 && rows[0].len() == 1 {
            self.paste_one_for_all(rows[0][0], &indexes_sorted, app_ui, pack_file_contents_ui);
        }

        else if rows.len() == 1 && same_amount_of_cells_selected_per_row && rows_selected.len() > 1 {
            self.paste_same_row_for_all(&rows[0], &indexes_sorted, app_ui, pack_file_contents_ui);
        }

        else {
            self.paste_as_it_fits(&rows, &indexes_sorted, app_ui, pack_file_contents_ui);
        }
    }
/// This function allow us to paste the contents of the clipboard into the selected cells, if the content is compatible with them.
///
/// This function has some... tricky stuff:
/// - There are several special behaviors when pasting, in order to provide an Excel-Like pasting experience.
This function allow us to paste the contents of the clipboard into the selected cells, if the content is compatible with them.
This function has some... tricky stuff:
There are several special behaviors when pasting, in order to provide an Excel-Like pasting experience.
This function allow us to paste the contents of the clipboard into the selected cells if the content is compatible with them . This function has some ... tricky stuff : There are several special behaviors when pasting in order to provide an Excel - Like pasting experience .
pub unsafe fn paste(&self, app_ui: &Rc<AppUI>, pack_file_contents_ui: &Rc<PackFileContentsUI>) {
        // Get the current selection. We treat it like a TSV, for compatibility with table editors.
        // Also, if the text ends in \n, remove it. Excel things.
        let mut text = QGuiApplication::clipboard().text().to_std_string();
        if text.ends_with('\n') { text.pop(); }
        let rows = text.split('\n').collect::<Vec<&str>>();
        let rows = rows.iter().map(|x| x.split('\t').collect::<Vec<&str>>()).collect::<Vec<Vec<&str>>>();
        // Get the current selection and his, visually speaking, first item (top-left).
        let indexes = self.table_view_primary.selection_model().selection().indexes();
        let mut indexes_sorted = (0..indexes.count_0a()).map(|x| indexes.at(x)).collect::<Vec<Ref<QModelIndex>>>();
        sort_indexes_visually(&mut indexes_sorted, &self.get_mut_ptr_table_view_primary());
        // If nothing is selected, got back to where you came from.
        if indexes_sorted.is_empty() { return }
        // At this point we should have the strings to paste and the selection. Now, clever pasting ahead:
        // - If the entire selection are rows of the same amount of cells and we have only one row of text with the exact same amount
        //   of items as the rows, we paste the same row in each selected row.
        // - If we only have one TSV value in the text and a ton of cells selected, paste the same value everywhere.
        // - In any other case, pick the first selected cell, and paste the TSV using that as cell 0,0.
        let same_amount_of_cells_selected_per_row = if rows.len() == 1 {
            let mut row = -1;
            let mut items = 0;
            let mut is_valid = true;
            for index in &indexes_sorted {
                if row == -1 {
                    row = index.row();
                }
                if index.row() == row {
                    items += 1;
                } else {
                    if items < rows[0].len() {
                        is_valid = false;
                        break;
                    }
                    row = index.row();
                    items = 1
                }
                if items > rows[0].len() {
                    is_valid = false;
                    break;
                }
            }
            is_valid
        } else { false };
        // Amount of rows selected, to ensure certain behavior only triggers when we got the correct number of rows selected.
        let mut rows_selected = indexes_sorted.iter().map(|x| x.row()).collect::<Vec<i32>>();
        rows_selected.sort_unstable();
        rows_selected.dedup();
        if rows.len() == 1 && rows[0].len() == 1 {
            self.paste_one_for_all(rows[0][0], &indexes_sorted, app_ui, pack_file_contents_ui);
        }
        else if rows.len() == 1 && same_amount_of_cells_selected_per_row && rows_selected.len() > 1 {
            self.paste_same_row_for_all(&rows[0], &indexes_sorted, app_ui, pack_file_contents_ui);
        }
        else {
            self.paste_as_it_fits(&rows, &indexes_sorted, app_ui, pack_file_contents_ui);
        }
    }
pub unsafe fn paste ( & self , app_ui : & Rc < AppUI > , pack_file_contents_ui : & Rc < PackFileContentsUI > ) { // Get the current selection. We treat it like a TSV, for compatibility with table editors. // Also, if the text ends in \n, remove it. Excel things. let mut text = QGuiApplication :: clipboard ( ) . text ( ) . to_std_string ( ) ; if text . ends_with ( '\n' ) { text . pop ( ) ; } let rows = text . split ( '\n' ) . collect :: < Vec < & str > > ( ) ; let rows = rows . iter ( ) . map ( | x | x . split ( '\t' ) . collect :: < Vec < & str > > ( ) ) . collect :: < Vec < Vec < & str > > > ( ) ; // Get the current selection and his, visually speaking, first item (top-left). let indexes = self . table_view_primary . selection_model ( ) . selection ( ) . indexes ( ) ; let mut indexes_sorted = ( 0 .. indexes . count_0a ( ) ) . map ( | x | indexes . at ( x ) ) . collect :: < Vec < Ref < QModelIndex > > > ( ) ; sort_indexes_visually ( & mut indexes_sorted , & self . get_mut_ptr_table_view_primary ( ) ) ; // If nothing is selected, got back to where you came from. if indexes_sorted . is_empty ( ) { return } // At this point we should have the strings to paste and the selection. Now, clever pasting ahead: // - If the entire selection are rows of the same amount of cells and we have only one row of text with the exact same amount //   of items as the rows, we paste the same row in each selected row. // - If we only have one TSV value in the text and a ton of cells selected, paste the same value everywhere. // - In any other case, pick the first selected cell, and paste the TSV using that as cell 0,0. let same_amount_of_cells_selected_per_row = if rows . len ( ) == 1 { let mut row = - 1 ; let mut items = 0 ; let mut is_valid = true ; for index in & indexes_sorted { if row == - 1 { row = index . row ( ) ; } if index . row ( ) == row { items += 1 ; } else { if items < rows [ 0 ] . len ( ) { is_valid = false ; break ; } row = index . row ( ) ; items = 1 } if items > rows [ 0 ] . len ( ) { is_valid = false ; break ; } } is_valid } else { false } ; // Amount of rows selected, to ensure certain behavior only triggers when we got the correct number of rows selected. let mut rows_selected = indexes_sorted . iter ( ) . map ( | x | x . row ( ) ) . collect :: < Vec < i32 > > ( ) ; rows_selected . sort_unstable ( ) ; rows_selected . dedup ( ) ; if rows . len ( ) == 1 && rows [ 0 ] . len ( ) == 1 { self . paste_one_for_all ( rows [ 0 ] [ 0 ] , & indexes_sorted , app_ui , pack_file_contents_ui ) ; } else if rows . len ( ) == 1 && same_amount_of_cells_selected_per_row && rows_selected . len ( ) > 1 { self . paste_same_row_for_all ( & rows [ 0 ] , & indexes_sorted , app_ui , pack_file_contents_ui ) ; } else { self . paste_as_it_fits ( & rows , & indexes_sorted , app_ui , pack_file_contents_ui ) ; } }
This function allow us to paste the contents of the clipboard into the selected cells, if the content is compatible with them.
This function allow us to paste the contents of the clipboard into the selected cells if the content is compatible with them .
&self
app_ui
&Rc<AppUI>
pack_file_contents_ui
&Rc<PackFileContentsUI>
&self
app_ui
&Rc<AppUI>
pack_file_contents_ui
&Rc<PackFileContentsUI>