@@ -115,6 +115,113 @@ impl ObjectSubclass for ModificationWindow {
115
115
*
116
116
*/
117
117
impl ModificationWindow {
118
+ /**
119
+ * Name:
120
+ * reorder_data
121
+ *
122
+ * Description:
123
+ * Update view ID's given ???
124
+ *
125
+ * Made:
126
+ * 08/01/2022
127
+ *
128
+ * Made by:
129
+ * Deren Vural
130
+ *
131
+ * Notes:
132
+ *
133
+ */
134
+ pub fn reorder_data ( & self , remove : bool ) {
135
+ // Get stored & const view data
136
+ let mut stored_views_data: Vec < String > = self . get_setting :: < Vec < String > > ( "viewconfigs" ) ;
137
+ let uuid: String = self
138
+ . uuid
139
+ . clone ( )
140
+ . get ( )
141
+ . expect ( "missing `uuid`.." )
142
+ . to_owned ( ) ;
143
+ // println!("stored views: `{:?}`", stored_views_data); //TEST
144
+
145
+ // Get old + new view title
146
+ let new_view_title: String = self . new_view_title . take ( ) ;
147
+ self . new_view_title . set ( new_view_title. clone ( ) ) ;
148
+
149
+ // If present in saved settings
150
+ if stored_views_data. len ( ) == 0 {
151
+ // no views exist
152
+ panic ! ( "no stored views: this shouldn't be happening!" ) ; //programmer error
153
+ } else {
154
+ // Get list of stored viewconfigs
155
+ for index in 0 ..stored_views_data. len ( ) {
156
+ // Split current viewconfig
157
+ let sub_items: Vec < & str > = stored_views_data[ index] . split ( ':' ) . collect ( ) ;
158
+ // println!("current title: `{}`", sub_items[2]); //TEST
159
+ // println!("searching for old title: `{}`", old_view_title); //TEST
160
+ // println!("searching for new title: `{}`", new_view_title); //TEST
161
+
162
+ // If viewconfig is for this GPU (i.e. has valid UUID) and IS NOT the current view
163
+ if ( sub_items[ 0 ] == uuid, sub_items[ 2 ] != new_view_title) == ( true , true ) {
164
+ // println!("This view needs updated: `{}`", stored_views_data[index]); //TEST
165
+
166
+ // Get ID of current view
167
+ let this_id: i32 = self . new_view_id . clone ( ) . get ( ) ;
168
+
169
+ // Split current viewconfig
170
+ let sub_items: Vec < & str > = stored_views_data[ index] . split ( ':' ) . collect ( ) ;
171
+
172
+ // Get ID of this config
173
+ let mut new_id: i32 = sub_items[ 1 ]
174
+ . parse :: < i32 > ( )
175
+ . expect ( "Malformed gschema data.." ) ;
176
+
177
+ // If viewconfig was at/above current view position
178
+ match ( new_id > this_id, new_id == this_id, remove) {
179
+ ( true , false , true ) => {
180
+ // println!("edit required"); //TEST
181
+ // println!("removing"); //TEST
182
+
183
+ // If above position & removing
184
+ new_id -= 1 ; // Modify order
185
+
186
+ // Update record
187
+ stored_views_data[ index] =
188
+ uuid. clone ( ) + ":" + & new_id. to_string ( ) + ":" + sub_items[ 2 ] ;
189
+ }
190
+ ( true , false , false ) => {
191
+ // println!("edit required"); //TEST
192
+ // println!("reorder"); //TEST
193
+
194
+ // If above position & re-order
195
+ new_id -= 1 ; // Modify order
196
+
197
+ // Update record
198
+ stored_views_data[ index] =
199
+ uuid. clone ( ) + ":" + & new_id. to_string ( ) + ":" + sub_items[ 2 ] ;
200
+ }
201
+ ( false , true , false ) => {
202
+ // println!("edit required"); //TEST
203
+ // println!("reorder"); //TEST
204
+
205
+ // If same position & re-order
206
+ new_id += 1 ; // Modify order
207
+
208
+ // Update record
209
+ stored_views_data[ index] =
210
+ uuid. clone ( ) + ":" + & new_id. to_string ( ) + ":" + sub_items[ 2 ] ;
211
+ }
212
+ _ => {
213
+ // otherwise ignore
214
+ // println!("NO edit required"); //TEST
215
+ }
216
+ }
217
+ }
218
+ }
219
+
220
+ // Update stored viewconfigs
221
+ self . update_setting :: < Vec < String > > ( "viewconfigs" , stored_views_data) ;
222
+ }
223
+ }
224
+
118
225
/**
119
226
* Name:
120
227
* delete_stored_data
@@ -157,7 +264,7 @@ impl ModificationWindow {
157
264
// If present in saved settings
158
265
if stored_views_data. len ( ) == 0 {
159
266
// no views exist
160
- panic ! ( "this shouldn't be happening!" ) ; //programmer error
267
+ panic ! ( "no stored views: this shouldn't be happening!" ) ; //programmer error
161
268
} else {
162
269
// index of the view we are deleting
163
270
let mut view_index: i32 = -1 ;
@@ -178,15 +285,22 @@ impl ModificationWindow {
178
285
// If we found the view
179
286
if view_index == -1 {
180
287
// Not found?
181
- panic ! ( "viwe not found: this shouldn't be happening!" ) ; //programmer error
288
+ panic ! ( "view not found: this shouldn't be happening!" ) ; //programmer error
182
289
} else {
183
290
// Delete viewconfig
184
291
stored_views_data. remove ( view_index as usize ) ;
185
292
293
+ let total_remaining: usize = stored_views_data. len ( ) ;
294
+
186
295
// Update stored viewconfigs
187
296
self . update_setting :: < Vec < String > > ( "viewconfigs" , stored_views_data) ;
188
297
// println!("viewconfig updated.."); //TEST
189
298
299
+ // Re-order remaining views
300
+ if total_remaining != 0 {
301
+ self . reorder_data ( true ) ;
302
+ }
303
+
190
304
// Delete associated viewcomponentconfigs
191
305
// println!("Initial components list: `{:?}`", stored_views_components); //TEST
192
306
let mut to_remove: Vec < i32 > = vec ! [ ] ;
@@ -396,6 +510,9 @@ impl ModificationWindow {
396
510
// Update stored viewconfigs
397
511
self . update_setting :: < Vec < String > > ( "viewconfigs" , stored_views_data) ;
398
512
// println!("viewconfig updated.."); //TEST
513
+
514
+ // Re-order remaining views
515
+ self . reorder_data ( true ) ;
399
516
}
400
517
// MATCH name is the same, id is different
401
518
( true , false ) => {
@@ -413,6 +530,9 @@ impl ModificationWindow {
413
530
// Update stored viewconfigs
414
531
self . update_setting :: < Vec < String > > ( "viewconfigs" , stored_views_data) ;
415
532
// println!("viewconfig updated.."); //TEST
533
+
534
+ // Re-order remaining views
535
+ self . reorder_data ( true ) ;
416
536
}
417
537
// MATCH name is the same, id is the same
418
538
( true , true ) => {
@@ -597,6 +717,9 @@ impl ModificationWindow {
597
717
// Update stored viewconfigs
598
718
self . update_setting :: < Vec < String > > ( "viewconfigs" , stored_views_data) ;
599
719
720
+ // Re-order remaining views
721
+ self . reorder_data ( true ) ;
722
+
600
723
// Get current components
601
724
let mut current_components: Vec < ViewComponent > = self . view_components_list . take ( ) ;
602
725
let dropdowns: Vec < DropDown > = self . dropdowns . take ( ) ;
0 commit comments