Skip to content

Commit

Permalink
Fix selection updates (akiraux#712)
Browse files Browse the repository at this point in the history
Now all changes are blocked when the signalblocker is active
  • Loading branch information
mbfraga authored Feb 25, 2022
1 parent 8304002 commit 5e6cd58
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/Lib/Managers/NobManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class Akira.Lib.Managers.NobManager : Object {
construct {
nobs = new Utils.Nobs.NobSet ();

view_canvas.window.event_bus.geometry_modified.connect (on_update_select_effect);
view_canvas.window.event_bus.selection_geometry_modified.connect (on_update_select_effect);
view_canvas.mode_manager.mode_changed.connect (on_update_select_effect);
nob_layer = new ViewLayers.ViewLayerNobs ();
nob_layer.add_to_canvas (ViewLayers.ViewLayer.NOBS_LAYER_ID, view_canvas);
Expand Down
42 changes: 29 additions & 13 deletions src/Lib/Managers/SelectionManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ public class Akira.Lib.Managers.SelectionManager : Object {

public unowned ViewCanvas view_canvas { get; construct; }

protected enum ChangeType {
NONE = 0,
TOPOLOGY = 1,
GEOMETRY = 2,
ALL = TOPOLOGY | GEOMETRY;
}

/*
* Blocks notifications until class is destructed.
*/
Expand All @@ -41,12 +48,13 @@ public class Akira.Lib.Managers.SelectionManager : Object {

~ChangeSignalBlocker () {
manager.block_change_notifications -= 1;
manager.on_selection_changed (-1);
manager.inner_selection_changed (-1, manager.change_blocked);
}
}

public Lib.Items.NodeSelection selection;
protected int block_change_notifications = 0;
protected ChangeType change_blocked = ChangeType.NONE;

public SelectionManager (ViewCanvas canvas) {
Object (view_canvas : canvas);
Expand Down Expand Up @@ -74,9 +82,7 @@ public class Akira.Lib.Managers.SelectionManager : Object {
}

selection = new Lib.Items.NodeSelection (null);

on_selection_changed (-1);
view_canvas.window.event_bus.selection_modified ();
inner_selection_changed (-1, ChangeType.TOPOLOGY);
}

public void add_to_selection (int id) {
Expand All @@ -85,8 +91,7 @@ public class Akira.Lib.Managers.SelectionManager : Object {
return;
}
selection.add_node (node);
on_selection_changed (-1);
view_canvas.window.event_bus.selection_modified ();
inner_selection_changed (-1, ChangeType.TOPOLOGY);
}

/*
Expand All @@ -98,8 +103,7 @@ public class Akira.Lib.Managers.SelectionManager : Object {
}

selection.remove_node (id);
on_selection_changed (-1);
view_canvas.window.event_bus.selection_modified ();
inner_selection_changed (-1, ChangeType.TOPOLOGY);
}

public bool item_selected (int id) {
Expand All @@ -111,11 +115,7 @@ public class Akira.Lib.Managers.SelectionManager : Object {
* items, and modifying the selection's geometry.
*/
public void on_selection_changed (int id) {
if (block_change_notifications == 0) {
if (id < 0 || selection.has_id (id, false)) {
view_canvas.window.event_bus.geometry_modified ();
}
}
inner_selection_changed (id, ChangeType.GEOMETRY);
}

public void delete_selected () {
Expand Down Expand Up @@ -158,4 +158,20 @@ public class Akira.Lib.Managers.SelectionManager : Object {
view_canvas.items_manager.flip_items (to_flip, vertical);
}
}

protected void inner_selection_changed (int id, ChangeType change_type) {
if (block_change_notifications == 0) {
if (id < 0 || selection.has_id (id, false)) {
view_canvas.window.event_bus.selection_geometry_modified ();
if (ChangeType.TOPOLOGY in change_type) {
view_canvas.window.event_bus.selection_modified ();
}
}

change_blocked = ChangeType.NONE;
return;
}
change_blocked |= change_type;
}

}
2 changes: 1 addition & 1 deletion src/Services/EventBus.vala
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public class Akira.Services.EventBus : Object {
// the Nob Manager to properly update the select effect.
// INFO!!! DO NOT USE THIS to listen for simple selection changes as it's
// triggered at every geometry change. Use the simple selection_modified ();
public signal void geometry_modified ();
public signal void selection_geometry_modified ();
public signal void request_copy ();
public signal void request_paste ();
public signal void delete_selected_items ();
Expand Down

0 comments on commit 5e6cd58

Please sign in to comment.