pub unsafe fn rewrite_selection(&self, app_ui: &Rc<AppUI>, pack_file_contents_ui: &Rc<PackFileContentsUI>) {
        if let Some((is_math_operation, value)) = self.create_rewrite_selection_dialog() {
            let horizontal_header = self.table_view_primary.horizontal_header();

            // Get the current selection. As we need his visual order, we get it directly from the table/filter, NOT FROM THE MODEL.
            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());

            let mut real_cells = vec![];
            let mut values = vec![];

            let mut row = 0;
            let mut prev_row = None;
            for index in &indexes_sorted {
                if index.is_valid() {

                    // Row depends on the selection. If none, it's the first row.
                    if prev_row.is_none() {
                        prev_row = Some(index.row());
                    }

                    // If row changed, + 1.
                    if let Some(ref mut prev_row) = prev_row {
                        if *prev_row != index.row() {
                            *prev_row = index.row();
                            row += 1;
                        }
                    }

                    // Get the column of that cell, the row, the current value, and the new value.
                    let item = self.table_model.item_from_index(&self.table_filter.map_to_source(*index));
                    let column = horizontal_header.visual_index(index.column());
                    let current_value = item.text().to_std_string();
                    let new_value = value.replace("{x}", &current_value).replace("{X}", &current_value)
                        .replace("{y}", &column.to_string()).replace("{Y}", &column.to_string())
                        .replace("{z}", &row.to_string()).replace("{Z}", &row.to_string());

                    let text = if is_math_operation {
                         if let Ok(result) = meval::eval_str(&new_value) {

                            // If we got a current value and it's different, it's a valid cell.
                            match current_value.parse::<f64>() {
                                Ok(value) => {
                                    if (result - value).abs() >= std::f64::EPSILON {
                                        result.to_string()
                                    } else {
                                        current_value.to_owned()
                                    }
                                },
                                Err(_) => result.to_string(),
                            }
                        }

                        // If meval fails, it's not a valid operation for this cell
                        else { continue; }
                    } else { new_value.to_owned() };

                    real_cells.push(self.table_filter.map_to_source(*index));
                    values.push(text);
                }
            }

            let mut realer_cells = vec![];
            for index in (0..real_cells.len()).rev() {
                realer_cells.push((real_cells.pop().unwrap(), &*values[index]));
            }
            realer_cells.reverse();

            self.set_data_on_cells(&realer_cells, 0, &[], app_ui, pack_file_contents_ui);
        }
    }
/// This function rewrite the currently selected cells using the provided formula.
This function rewrite the currently selected cells using the provided formula.
This function rewrite the currently selected cells using the provided formula .
pub unsafe fn rewrite_selection(&self, app_ui: &Rc<AppUI>, pack_file_contents_ui: &Rc<PackFileContentsUI>) {
        if let Some((is_math_operation, value)) = self.create_rewrite_selection_dialog() {
            let horizontal_header = self.table_view_primary.horizontal_header();
            // Get the current selection. As we need his visual order, we get it directly from the table/filter, NOT FROM THE MODEL.
            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());
            let mut real_cells = vec![];
            let mut values = vec![];
            let mut row = 0;
            let mut prev_row = None;
            for index in &indexes_sorted {
                if index.is_valid() {
                    // Row depends on the selection. If none, it's the first row.
                    if prev_row.is_none() {
                        prev_row = Some(index.row());
                    }
                    // If row changed, + 1.
                    if let Some(ref mut prev_row) = prev_row {
                        if *prev_row != index.row() {
                            *prev_row = index.row();
                            row += 1;
                        }
                    }
                    // Get the column of that cell, the row, the current value, and the new value.
                    let item = self.table_model.item_from_index(&self.table_filter.map_to_source(*index));
                    let column = horizontal_header.visual_index(index.column());
                    let current_value = item.text().to_std_string();
                    let new_value = value.replace("{x}", &current_value).replace("{X}", &current_value)
                        .replace("{y}", &column.to_string()).replace("{Y}", &column.to_string())
                        .replace("{z}", &row.to_string()).replace("{Z}", &row.to_string());
                    let text = if is_math_operation {
                         if let Ok(result) = meval::eval_str(&new_value) {
                            // If we got a current value and it's different, it's a valid cell.
                            match current_value.parse::<f64>() {
                                Ok(value) => {
                                    if (result - value).abs() >= std::f64::EPSILON {
                                        result.to_string()
                                    } else {
                                        current_value.to_owned()
                                    }
                                },
                                Err(_) => result.to_string(),
                            }
                        }
                        // If meval fails, it's not a valid operation for this cell
                        else { continue; }
                    } else { new_value.to_owned() };
                    real_cells.push(self.table_filter.map_to_source(*index));
                    values.push(text);
                }
            }
            let mut realer_cells = vec![];
            for index in (0..real_cells.len()).rev() {
                realer_cells.push((real_cells.pop().unwrap(), &*values[index]));
            }
            realer_cells.reverse();
            self.set_data_on_cells(&realer_cells, 0, &[], app_ui, pack_file_contents_ui);
        }
    }
pub unsafe fn rewrite_selection ( & self , app_ui : & Rc < AppUI > , pack_file_contents_ui : & Rc < PackFileContentsUI > ) { if let Some ( ( is_math_operation , value ) ) = self . create_rewrite_selection_dialog ( ) { let horizontal_header = self . table_view_primary . horizontal_header ( ) ; // Get the current selection. As we need his visual order, we get it directly from the table/filter, NOT FROM THE MODEL. 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 ( ) ) ; let mut real_cells = vec ! [ ] ; let mut values = vec ! [ ] ; let mut row = 0 ; let mut prev_row = None ; for index in & indexes_sorted { if index . is_valid ( ) { // Row depends on the selection. If none, it's the first row. if prev_row . is_none ( ) { prev_row = Some ( index . row ( ) ) ; } // If row changed, + 1. if let Some ( ref mut prev_row ) = prev_row { if * prev_row != index . row ( ) { * prev_row = index . row ( ) ; row += 1 ; } } // Get the column of that cell, the row, the current value, and the new value. let item = self . table_model . item_from_index ( & self . table_filter . map_to_source ( * index ) ) ; let column = horizontal_header . visual_index ( index . column ( ) ) ; let current_value = item . text ( ) . to_std_string ( ) ; let new_value = value . replace ( " " , & current_value ) . replace ( " " , & current_value ) . replace ( " " , & column . to_string ( ) ) . replace ( " " , & column . to_string ( ) ) . replace ( " " , & row . to_string ( ) ) . replace ( " " , & row . to_string ( ) ) ; let text = if is_math_operation { if let Ok ( result ) = meval :: eval_str ( & new_value ) { // If we got a current value and it's different, it's a valid cell. match current_value . parse :: < f64 > ( ) { Ok ( value ) => { if ( result - value ) . abs ( ) >= std :: f64 :: EPSILON { result . to_string ( ) } else { current_value . to_owned ( ) } } , Err ( _ ) => result . to_string ( ) , } } // If meval fails, it's not a valid operation for this cell else { continue ; } } else { new_value . to_owned ( ) } ; real_cells . push ( self . table_filter . map_to_source ( * index ) ) ; values . push ( text ) ; } } let mut realer_cells = vec ! [ ] ; for index in ( 0 .. real_cells . len ( ) ) . rev ( ) { realer_cells . push ( ( real_cells . pop ( ) . unwrap ( ) , & * values [ index ] ) ) ; } realer_cells . reverse ( ) ; self . set_data_on_cells ( & realer_cells , 0 , & [ ] , app_ui , pack_file_contents_ui ) ; } }
This function rewrite the currently selected cells using the provided formula.
This function rewrite the currently selected cells using the provided formula .
&self
app_ui
&Rc<AppUI>
pack_file_contents_ui
&Rc<PackFileContentsUI>
&self
app_ui
&Rc<AppUI>
pack_file_contents_ui
&Rc<PackFileContentsUI>