Skip to content

Commit 66261bf

Browse files
author
Deren Vural
committed
Bugfix
Updated ModificationWindow class: - Fixed bug that couldn't handle inserting a new view to a non-end position - Added some clearer debug print statements Signed-off-by: Deren Vural <derenv@live.co.uk>
1 parent b6cbbe9 commit 66261bf

File tree

2 files changed

+32
-14
lines changed

2 files changed

+32
-14
lines changed

src/gpu_page/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -593,8 +593,8 @@ impl GpuPage {
593593
// Load list of Properties for current Page
594594
let loaded_properties_data: Vec<String> =
595595
settings_obj.get::<Vec<String>>("viewcomponentconfigs");
596-
// println!("items saved #: `{}`", loaded_properties_data.len()); //TEST
597-
// println!("items saved: `{:?}`", loaded_properties_data); //TEST
596+
println!("items saved #: `{}`", loaded_properties_data.len()); //TEST
597+
println!("items saved: `{:?}`", loaded_properties_data); //TEST
598598

599599
// If present in saved settings, use! otherwise follow below defaults
600600
if let 0 = loaded_properties_data.len() {
@@ -607,7 +607,7 @@ impl GpuPage {
607607
vec![String::from(""); loaded_properties_data.len()];
608608

609609
for index in 0..loaded_properties_data.len() {
610-
// println!("item: `{}`", loaded_properties_data[index]); //TEST
610+
println!("item: `{}`", loaded_properties_data[index]); //TEST
611611

612612
// Split current item into the 4 parts
613613
let parts: Vec<&str> = loaded_properties_data[index]
@@ -621,19 +621,19 @@ impl GpuPage {
621621

622622
// If from valid page
623623
if parts[0] == self.property::<String>("uuid") {
624-
// println!("VALID UUID"); //TEST
624+
println!("VALID UUID"); //TEST
625625

626626
// If from valid view
627627
if parts[1] == view_name {
628-
// println!("VALID VIEW #"); //TEST
628+
println!("VALID VIEW #"); //TEST
629629

630630
// If a valid position
631631
match parts[2].parse::<usize>() {
632632
Ok(position) => {
633-
// println!("POSITION INDEX: `{}`", position); //TEST
633+
println!("POSITION INDEX: `{}`", position); //TEST
634634
if position <= loaded_properties_data.len() {
635-
// println!("VALID POSITION INDEX"); //TEST
636-
// println!("VALID PROPERTY: `{}`", parts[3]); //TEST
635+
println!("VALID POSITION INDEX"); //TEST
636+
println!("VALID PROPERTY: `{}`", parts[3]); //TEST
637637

638638
// Add to final list
639639
loaded_properties[position] = parts[3].to_owned();

src/modificationwindow/imp.rs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,40 +182,57 @@ impl ModificationWindow {
182182
.parse::<i32>()
183183
.expect("Malformed gschema data..");
184184

185+
// println!("old_id: `{}`", old_id); //TEST
186+
// println!("new_id: `{}`", new_id); //TEST
187+
// println!("this_id: `{}`", this_id); //TEST
188+
185189
// If viewconfig was at/above current view position
186190
match (new_id > this_id, new_id == this_id, remove) {
187191
(true, false, true) => {
188192
// println!("edit required"); //TEST
189193
// println!("removing"); //TEST
190194

191195
// If above position & removing
196+
// println!("new_id: `{}` modified by -1", new_id); //TEST
192197
new_id -= 1; // Modify order
198+
// println!("new_id: `{}`", new_id); //TEST
193199

194200
// Update record
195201
stored_views_data[index] =
196202
uuid.clone() + ":" + &new_id.to_string() + ":" + sub_items[2];
197203
}
198204
(true, false, false) => {
199205
// println!("edit required"); //TEST
200-
// println!("reorder"); //TEST
206+
// println!("tff reorder"); //TEST
201207

202208
// If above position & re-order
209+
// println!("new_id: `{}` modified by -1", new_id); //TEST
203210
new_id -= 1; // Modify order
211+
// println!("new_id: `{}`", new_id); //TEST
204212

205213
// Update record
206214
stored_views_data[index] =
207215
uuid.clone() + ":" + &new_id.to_string() + ":" + sub_items[2];
208216
}
209217
(false, true, false) => {
210218
// println!("edit required"); //TEST
211-
// println!("reorder"); //TEST
219+
// println!("ftf reorder"); //TEST
212220

213221
// If same position & re-order, we need to check direction of change
214-
if old_id < new_id {
215-
new_id -= 1; // Modify order
216-
} else if old_id > new_id {
222+
if old_id == -1 {
223+
// if inserting new view
224+
// println!("new_id: `{}` modified by +1", new_id); //TEST
217225
new_id += 1; // Modify order
226+
} else {
227+
if old_id < new_id {
228+
// println!("new_id: `{}` modified by -1", new_id); //TEST
229+
new_id -= 1; // Modify order
230+
} else if old_id > new_id {
231+
// println!("new_id: `{}` modified by +1", new_id); //TEST
232+
new_id += 1; // Modify order
233+
}
218234
}
235+
// println!("new_id: `{}`", new_id); //TEST
219236

220237
// Update record
221238
stored_views_data[index] =
@@ -225,7 +242,8 @@ impl ModificationWindow {
225242
// println!("tuple `{} {} {}`", new_id > this_id, new_id == this_id, remove);
226243

227244
// otherwise ignore
228-
//println!("NO edit required"); //TEST
245+
// println!("new_id: `{}` NOT modified", new_id); //TEST
246+
// println!("NO edit required"); //TEST
229247
}
230248
}
231249
}

0 commit comments

Comments
 (0)