Skip to content

Commit f61d834

Browse files
author
Deren Vural
committed
Working view reordering (on deletion only atm)
Updated MainWindow class: - Fixed a strange comment layout Updated GpuPage class: - Removed an unused import Updated ModificationWindow class: - Added the "reorder_data()" function, fixes view ID order. Called after delete/reposition of a view - Updated some panic statements to give more info - Added calls to "reorder_data()" function to "delete_stored_data()" function and "update_stored_data()" function (only cases where id changes, should help when adding the scrollwheel modifier later) - Removed some unecessary psuedocode/todo statements Signed-off-by: Deren Vural <derenv@live.co.uk>
1 parent de3f999 commit f61d834

File tree

4 files changed

+128
-8
lines changed

4 files changed

+128
-8
lines changed

src/gpu_page/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use imp::ModificationWindowContainer;
2424
// Imports
2525
use adwaita::{gio, glib, Application, ViewStack};
2626
use gio::Settings;
27-
use glib::{clone, closure, closure_local, translate::FromGlib, Object, SourceId};
27+
use glib::{clone, closure, translate::FromGlib, Object, SourceId};
2828
use gtk::{prelude::*, subclass::prelude::*, Align, Button, Grid, Label, LayoutChild, Orientation};
2929
use std::{cell::RefMut, sync::Arc, sync::Mutex, sync::MutexGuard};
3030

src/mainwindow/imp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1513,7 +1513,7 @@ impl MainWindow {
15131513
// Construct a row for each GPU
15141514
for uuid in gpu_uuids {
15151515
// println!("UUID: `{}`", uuid); //TEST
1516-
// Grab current provider
1516+
// Grab current provider
15171517
let provider_container: Option<Provider> = self.provider.take();
15181518
self.provider.set(provider_container.clone());
15191519

src/modificationwindow/imp.rs

Lines changed: 125 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,113 @@ impl ObjectSubclass for ModificationWindow {
115115
*
116116
*/
117117
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+
118225
/**
119226
* Name:
120227
* delete_stored_data
@@ -157,7 +264,7 @@ impl ModificationWindow {
157264
// If present in saved settings
158265
if stored_views_data.len() == 0 {
159266
// no views exist
160-
panic!("this shouldn't be happening!"); //programmer error
267+
panic!("no stored views: this shouldn't be happening!"); //programmer error
161268
} else {
162269
// index of the view we are deleting
163270
let mut view_index: i32 = -1;
@@ -178,15 +285,22 @@ impl ModificationWindow {
178285
// If we found the view
179286
if view_index == -1 {
180287
// 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
182289
} else {
183290
// Delete viewconfig
184291
stored_views_data.remove(view_index as usize);
185292

293+
let total_remaining: usize = stored_views_data.len();
294+
186295
// Update stored viewconfigs
187296
self.update_setting::<Vec<String>>("viewconfigs", stored_views_data);
188297
// println!("viewconfig updated.."); //TEST
189298

299+
// Re-order remaining views
300+
if total_remaining != 0 {
301+
self.reorder_data(true);
302+
}
303+
190304
// Delete associated viewcomponentconfigs
191305
// println!("Initial components list: `{:?}`", stored_views_components); //TEST
192306
let mut to_remove: Vec<i32> = vec![];
@@ -396,6 +510,9 @@ impl ModificationWindow {
396510
// Update stored viewconfigs
397511
self.update_setting::<Vec<String>>("viewconfigs", stored_views_data);
398512
// println!("viewconfig updated.."); //TEST
513+
514+
// Re-order remaining views
515+
self.reorder_data(true);
399516
}
400517
// MATCH name is the same, id is different
401518
(true, false) => {
@@ -413,6 +530,9 @@ impl ModificationWindow {
413530
// Update stored viewconfigs
414531
self.update_setting::<Vec<String>>("viewconfigs", stored_views_data);
415532
// println!("viewconfig updated.."); //TEST
533+
534+
// Re-order remaining views
535+
self.reorder_data(true);
416536
}
417537
// MATCH name is the same, id is the same
418538
(true, true) => {
@@ -597,6 +717,9 @@ impl ModificationWindow {
597717
// Update stored viewconfigs
598718
self.update_setting::<Vec<String>>("viewconfigs", stored_views_data);
599719

720+
// Re-order remaining views
721+
self.reorder_data(true);
722+
600723
// Get current components
601724
let mut current_components: Vec<ViewComponent> = self.view_components_list.take();
602725
let dropdowns: Vec<DropDown> = self.dropdowns.take();

src/modificationwindow/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,7 @@ impl ModificationWindow {
213213
let mut dropdowns: Vec<DropDown> = vec![];
214214

215215
// println!("LETS GET LOOPIN"); //TEST
216-
if view_components_list.len() == 0 {
217-
// TODO: View that needs components
218-
//
219-
} else {
216+
if view_components_list.len() != 0 {
220217
for index in 0..view_components_list.len() {
221218
// println!("item: `{}`", view_components_list[index]); //TEST
222219
let sub_items: Vec<&str> = view_components_list[index].split(':').collect();

0 commit comments

Comments
 (0)