[Bf-blender-cvs] [499c47a974b] soc-2019-outliner: Outliner: Improve click and drag for openclose

Nathan Craddock noreply at git.blender.org
Fri Jul 26 20:17:51 CEST 2019


Commit: 499c47a974bd2214382f6b56a14bee7246340ada
Author: Nathan Craddock
Date:   Fri Jul 26 12:15:01 2019 -0600
Branches: soc-2019-outliner
https://developer.blender.org/rB499c47a974bd2214382f6b56a14bee7246340ada

Outliner: Improve click and drag for openclose

This adds the ability to click and drag over a disclosure triangle
and immediately drag back over it to close it. Previously it
required opening the next element before closing the first opened
element because of the way the operator stored the previously
toggled disclosure. This makes the operator more easy to use and
understand.

===================================================================

M	source/blender/editors/space_outliner/outliner_edit.c

===================================================================

diff --git a/source/blender/editors/space_outliner/outliner_edit.c b/source/blender/editors/space_outliner/outliner_edit.c
index 7f16539054b..53b8014eb5c 100644
--- a/source/blender/editors/space_outliner/outliner_edit.c
+++ b/source/blender/editors/space_outliner/outliner_edit.c
@@ -175,6 +175,11 @@ bool outliner_item_openclose(TreeElement *te, bool toggle_all)
   return false;
 }
 
+typedef struct OpenCloseData {
+  TreeStoreElem *prev_tselem;
+  int x_location;
+} OpenCloseData;
+
 static int outliner_item_openclose_modal(bContext *C, wmOperator *op, const wmEvent *event)
 {
   ARegion *ar = CTX_wm_region(C);
@@ -185,22 +190,30 @@ static int outliner_item_openclose_modal(bContext *C, wmOperator *op, const wmEv
 
   if (event->type == MOUSEMOVE) {
     TreeElement *te = outliner_find_item_at_y(soops, &soops->tree, view_mval[1]);
-    TreeStoreElem *prev_tselem = (TreeStoreElem *)op->customdata;
-    TreeElement *prev_elem = outliner_find_tree_element(&soops->tree, prev_tselem);
+
+    OpenCloseData *data = (OpenCloseData *)op->customdata;
 
     /* Only openclose if mouse is not over the previously toggled element */
-    if (te && TREESTORE(te) != prev_tselem) {
+    if (te && TREESTORE(te) != data->prev_tselem) {
 
       /* Only toggle openclose on the same level as the first clicked element */
-      if (te->xs == prev_elem->xs) {
+      if (te->xs == data->x_location) {
         if (outliner_item_openclose(te, false)) {
           ED_region_tag_redraw(ar);
         }
-        op->customdata = TREESTORE(te);
       }
     }
+
+    if (te) {
+      data->prev_tselem = TREESTORE(te);
+    }
+    else {
+      data->prev_tselem = NULL;
+    }
   }
   else if (event->val == KM_RELEASE) {
+    MEM_freeN(op->customdata);
+
     return OPERATOR_FINISHED;
   }
 
@@ -223,14 +236,19 @@ static int outliner_item_openclose_invoke(bContext *C, wmOperator *op, const wmE
     outliner_item_openclose(te, toggle_all);
     ED_region_tag_redraw(ar);
 
-    /* Store the first clicked on element */
-    op->customdata = TREESTORE(te);
-
     /* Only toggle once for single click toggling */
     if (event->type == LEFTMOUSE) {
       return OPERATOR_FINISHED;
     }
 
+    /* Store last expanded tselem and x coordinate of disclosure triangle */
+    OpenCloseData *toggle_data = MEM_callocN(sizeof(OpenCloseData), "open_close_data");
+    toggle_data->prev_tselem = TREESTORE(te);
+    toggle_data->x_location = te->xs;
+
+    /* Store the first clicked on element */
+    op->customdata = toggle_data;
+
     WM_event_add_modal_handler(C, op);
     return OPERATOR_RUNNING_MODAL;
   }



More information about the Bf-blender-cvs mailing list