Fix [#36530] Texture tab refreshing problem
[blender-staging.git] / source / blender / editors / space_buttons / buttons_texture.c
index 51e740e539fb405dcc247fd4951d9bcee34e162f..8508123f9422ea642606af7028f8a61a179570d3 100644 (file)
@@ -150,20 +150,31 @@ static void set_texture_context(const bContext *C, SpaceButs *sbuts)
                bool valid_particles = ED_texture_context_check_particles(C);
                bool valid_others = ED_texture_context_check_others(C);
 
+               /* this is similar to direct user action, no need to keep "better" ctxt in _prev */
                if ((sbuts->mainb == BCONTEXT_WORLD) && valid_world) {
-                       sbuts->texture_context = SB_TEXC_WORLD;
+                       sbuts->texture_context = sbuts->texture_context_prev = SB_TEXC_WORLD;
                }
                else if ((sbuts->mainb == BCONTEXT_MATERIAL) && valid_material) {
-                       sbuts->texture_context = SB_TEXC_MATERIAL;
+                       sbuts->texture_context = sbuts->texture_context_prev = SB_TEXC_MATERIAL;
                }
                else if ((sbuts->mainb == BCONTEXT_DATA) && valid_lamp) {
-                       sbuts->texture_context = SB_TEXC_LAMP;
+                       sbuts->texture_context = sbuts->texture_context_prev = SB_TEXC_LAMP;
                }
                else if ((sbuts->mainb == BCONTEXT_PARTICLE) && valid_particles) {
-                       sbuts->texture_context = SB_TEXC_PARTICLES;
+                       sbuts->texture_context = sbuts->texture_context_prev = SB_TEXC_PARTICLES;
                }
                else if ((ELEM(sbuts->mainb, BCONTEXT_MODIFIER, BCONTEXT_PHYSICS)) && valid_others) {
-                       sbuts->texture_context = SB_TEXC_OTHER;
+                       sbuts->texture_context = sbuts->texture_context_prev = SB_TEXC_OTHER;
+               }
+               /* Else, try to revive a previous "better" ctxt... */
+               else if ((sbuts->texture_context_prev != sbuts->texture_context) &&
+                        (((sbuts->texture_context_prev == SB_TEXC_WORLD) && valid_world) ||
+                         ((sbuts->texture_context_prev == SB_TEXC_MATERIAL) && valid_material) ||
+                         ((sbuts->texture_context_prev == SB_TEXC_LAMP) && valid_lamp) ||
+                         ((sbuts->texture_context_prev == SB_TEXC_PARTICLES) && valid_particles) ||
+                         ((sbuts->texture_context_prev == SB_TEXC_OTHER) && valid_others)))
+               {
+                       sbuts->texture_context = sbuts->texture_context_prev;
                }
                /* Else, just be sure that current context is valid! */
                else if (((sbuts->texture_context == SB_TEXC_WORLD) && !valid_world) ||
@@ -172,13 +183,9 @@ static void set_texture_context(const bContext *C, SpaceButs *sbuts)
                         ((sbuts->texture_context == SB_TEXC_PARTICLES) && !valid_particles) ||
                         ((sbuts->texture_context == SB_TEXC_OTHER) && !valid_others))
                {
-                       if (valid_others) {
-                               sbuts->texture_context = SB_TEXC_OTHER;
-                       }
-                       else if (valid_world) {
-                               sbuts->texture_context = SB_TEXC_WORLD;
-                       }
-                       else if (valid_material) {
+                       /* this is default fallback, do keep "better" ctxt in _prev */
+                       sbuts->texture_context_prev = sbuts->texture_context;
+                       if (valid_material) {
                                sbuts->texture_context = SB_TEXC_MATERIAL;
                        }
                        else if (valid_lamp) {
@@ -187,6 +194,12 @@ static void set_texture_context(const bContext *C, SpaceButs *sbuts)
                        else if (valid_particles) {
                                sbuts->texture_context = SB_TEXC_PARTICLES;
                        }
+                       else if (valid_world) {
+                               sbuts->texture_context = SB_TEXC_WORLD;
+                       }
+                       else if (valid_others) {
+                               sbuts->texture_context = SB_TEXC_OTHER;
+                       }
                }
        }
 }