Merged 15170:15635 from trunk (no conflicts or even merges)
[blender.git] / source / blender / src / headerbuttons.c
index a31f17d1638dae66e43ddbfa256bb94bb8e9ea79..1a91ada1562cd4b03bda256d5409ee6c86a99958 100644 (file)
@@ -1,15 +1,12 @@
 /**
  * $Id$
  *
- * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
+ * ***** BEGIN GPL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
  * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version. The Blender
- * Foundation also sells licenses for use in proprietary software under
- * the Blender License.  See http://www.blender.org/BL/ for information
- * about this.
+ * of the License, or (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -27,7 +24,7 @@
  *
  * Contributor(s): none yet.
  *
- * ***** END GPL/BL DUAL LICENSE BLOCK *****
+ * ***** END GPL LICENSE BLOCK *****
  */
 
 #include <stdlib.h>
 #include "BKE_material.h"
 #include "BKE_mball.h"
 #include "BKE_mesh.h"
+#include "BKE_node.h"
 #include "BKE_object.h"
 #include "BKE_packedFile.h"
 #include "BKE_sca.h"
 #include "BIF_writeimage.h"
 #include "BIF_butspace.h"
 
-#include "BPI_script.h"
-
 #include "BSE_edit.h"
 #include "BSE_filesel.h"
 #include "BSE_headerbuttons.h"
 #include "BDR_editobject.h"
 #include "BDR_editcurve.h"
 #include "BDR_editmball.h"
+#include "BDR_sculptmode.h"
 
 #include "BPY_extern.h"
 #include "BPY_menus.h"
@@ -253,7 +250,7 @@ int std_libbuttons(uiBlock *block, short xco, short yco,
        if(browse) {
                char *extrastr= NULL;
                
-               if(ELEM3(id_code, ID_MA, ID_TE, ID_BR)) add_addbutton= 1;
+               if(ELEM4(id_code, ID_MA, ID_TE, ID_BR, ID_PA)) add_addbutton= 1;
                        
                lb= wich_libbase(G.main, id_code);
                
@@ -263,21 +260,23 @@ int std_libbuttons(uiBlock *block, short xco, short yco,
                        uiBlockSetCol(block, TH_BUT_SETTING2);
                }
                
-               if ELEM8( id_code, ID_SCE, ID_SCR, ID_MA, ID_TE, ID_WO, ID_IP, ID_AC, ID_BR) extrastr= "ADD NEW %x 32767";
+               if (ELEM8( id_code, ID_SCE, ID_SCR, ID_MA, ID_TE, ID_WO, ID_IP, ID_AC, ID_BR) || id_code == ID_PA) extrastr= "ADD NEW %x 32767";
                else if (id_code==ID_TXT) extrastr= "OPEN NEW %x 32766 |ADD NEW %x 32767";
                else if (id_code==ID_SO) extrastr= "OPEN NEW %x 32766";
-               
-               uiSetButLock(G.scene->id.lib!=0, "Can't edit library data");
+
+               uiSetButLock(G.scene->id.lib!=0, ERROR_LIBDATA_MESSAGE);
                if( id_code==ID_SCE || id_code==ID_SCR ) uiClearButLock();
                
                if(curarea->spacetype==SPACE_BUTS)
                        uiSetButLock(id_code!=ID_SCR && G.obedit!=0 && G.buts->mainb==CONTEXT_EDITING, "Cannot perform in EditMode");
                
-               if(parid) uiSetButLock(parid->lib!=0, "Can't edit library data");
+               if(parid) uiSetButLock(parid->lib!=0, ERROR_LIBDATA_MESSAGE);
 
                if (lb) {
                        if( id_code==ID_IP)
                                IPOnames_to_pupstring(&str, NULL, extrastr, lb, id, menupoin, G.sipo->blocktype);
+                       else if(browse!=B_SIMABROWSE && id_code==ID_IM )
+                               IMAnames_to_pupstring(&str, NULL, extrastr, lb, id, menupoin);
                        else
                                IDnames_to_pupstring(&str, NULL, extrastr, lb, id, menupoin);
                }
@@ -303,7 +302,7 @@ int std_libbuttons(uiBlock *block, short xco, short yco,
                /* Redalert overrides pin color */
                if(id->us<=0) uiBlockSetCol(block, TH_REDALERT);
 
-               uiSetButLock(id->lib!=0, "Can't edit library data");
+               uiSetButLock(id->lib!=0, ERROR_LIBDATA_MESSAGE);
                
                if(GS(id->name)==ID_SCE) strcpy(str1, "SCE:");
                else if(GS(id->name)==ID_SCE) strcpy(str1, "SCR:");
@@ -321,10 +320,11 @@ int std_libbuttons(uiBlock *block, short xco, short yco,
                }
                
                if( GS(id->name)==ID_IP) len= 110;
+               else if((yco) && (GS(id->name)==ID_AC)) len= 100; // comes from button panel (poselib)
                else if(yco) len= 140;  // comes from button panel
                else len= 120;
                
-               but= uiDefBut(block, TEX, B_IDNAME, str1,xco, yco, (short)len, YIC, id->name+2, 0.0, 19.0, 0, 0, "Displays current Datablock name. Click to change.");
+               but= uiDefBut(block, TEX, B_IDNAME, str1,xco, yco, (short)len, YIC, id->name+2, 0.0, 21.0, 0, 0, "Displays current Datablock name. Click to change.");
                uiButSetFunc(but, test_idbutton_cb, id->name, NULL);
 
                uiClearButLock();
@@ -333,8 +333,10 @@ int std_libbuttons(uiBlock *block, short xco, short yco,
                
                if(id->lib) {
                        
-                       if(parid && parid->lib) uiDefIconBut(block, BUT, 0, ICON_DATALIB,xco,yco,XIC,YIC, 0, 0, 0, 0, 0, "Displays name of the current Indirect Library Datablock. Click to change.");
-                       else uiDefIconBut(block, BUT, lib, ICON_PARLIB, xco,yco,XIC,YIC, 0, 0, 0, 0, 0, "Displays current Library Datablock name. Click to make local.");
+                       if(id->flag & LIB_INDIRECT) uiDefIconBut(block, BUT, 0, ICON_DATALIB,xco,yco,XIC,YIC, 0, 0, 0, 0, 0, "Indirect Library Datablock. Cannot change.");
+                       else uiDefIconBut(block, BUT, lib, ICON_PARLIB, xco,yco,XIC,YIC, 0, 0, 0, 0, 0, 
+                                                         lib?"Direct linked Library Datablock. Click to make local.":"Direct linked Library Datablock, cannot make local."
+                                                         );
                        
                        xco+= XIC;
                }
@@ -359,14 +361,13 @@ int std_libbuttons(uiBlock *block, short xco, short yco,
                }
                
                if(del) {
-
                        uiSetButLock (pin && *pinpoin, "Can't unlink pinned data");
                        if(parid && parid->lib);
                        else {
                                uiDefIconBut(block, BUT, del, ICON_X, xco,yco,XIC,YIC, 0, 0, 0, 0, 0, "Deletes link to this Datablock");
                                xco+= XIC;
                        }
-
+                       
                        uiClearButLock();
                }
 
@@ -380,12 +381,13 @@ int std_libbuttons(uiBlock *block, short xco, short yco,
                        
                }
                if(keepbut) {
-                       uiDefBut(block, BUT, keepbut, "F", xco,yco,XIC,YIC, 0, 0, 0, 0, 0, "Saves this datablock even if it has no users");  
+                       uiDefButBitS(block, TOG, LIB_FAKEUSER, keepbut, "F", xco,yco,XIC,YIC, &id->flag, 0, 0, 0, 0, "Saves this datablock even if it has no users");
                        xco+= XIC;
                }
        }
        else if(add_addbutton) {        /* "add new" button */
                uiBlockSetCol(block, oldcol);
+               if(parid) uiSetButLock(parid->lib!=0, ERROR_LIBDATA_MESSAGE);
                uiDefButS(block, TOG, browse, "Add New" ,xco, yco, 110, YIC, menupoin, (float)*menupoin, 32767.0, 0, 0, "Add new data block");
                xco+= 110;
        }
@@ -410,9 +412,18 @@ static void do_update_for_newframe(int mute, int events)
        /* this function applies the changes too */
        scene_update_for_newframe(G.scene, screen_view3d_layers()); /* BKE_scene.h */
 
-       if ( (CFRA>1) && (!mute) && (G.scene->audio.flag & AUDIO_SCRUB)) audiostream_scrub( CFRA );
+       if ( (CFRA>1) && (!mute) && (G.scene->audio.flag & AUDIO_SCRUB)) 
+               audiostream_scrub( CFRA );
+       
+       /* 3d window, preview */
        BIF_view3d_previewrender_signal(curarea, PR_DBASE|PR_DISPRECT);
 
+       /* all movie/sequence images */
+       BIF_image_update_frame();
+       
+       /* composite */
+       if(G.scene->use_nodes && G.scene->nodetree)
+               ntreeCompositTagAnimated(G.scene->nodetree);
 }
 
 void update_for_newframe(void)
@@ -442,11 +453,12 @@ static void show_splash(void)
        char buffer[1024];
        extern char * build_date;
        extern char * build_time;
+       extern char * build_rev;
        extern char * build_platform;
        extern char * build_type;
 
        string = &buffer[0];
-       sprintf(string,"Built on %s %s     Version %s %s", build_date, build_time, build_platform, build_type);
+       sprintf(string,"Built on %s %s, Rev-%s    Version %s %s", build_date, build_time, build_rev, build_platform, build_type);
 #endif
 
        splash((void *)datatoc_splash_jpg, datatoc_splash_jpg_size, string);
@@ -528,9 +540,14 @@ static void filesel_u_pythondir(char *name)
 
        BLI_cleanup_dir(G.sce, name);
        BLI_split_dirfile(name, dir, file);
-
+       
        strcpy(U.pythondir, dir);
        allqueue(REDRAWALL, 0);
+       
+       /* act on the change */
+       if (BPY_path_update()==0) {
+               error("Invalid scripts dir: check console");
+       }
 }
 
 static void filesel_u_sounddir(char *name)
@@ -552,6 +569,8 @@ static void filesel_u_tempdir(char *name)
        BLI_split_dirfile(name, dir, file);
 
        strcpy(U.tempdir, dir);
+       BLI_where_is_temp( btempdir, 1 );
+       
        allqueue(REDRAWALL, 0);
 }
 
@@ -572,7 +591,10 @@ void do_global_buttons(unsigned short event)
        ScrArea *sa;
        Brush *br;
        int nr= 1;
-       char buf[FILE_MAXDIR+FILE_MAXFILE];
+       
+#ifdef INTERNATIONAL
+       char buf[FILE_MAX];
+#endif
 
        ob= OBACT;
 
@@ -694,7 +716,12 @@ void do_global_buttons(unsigned short event)
                else return;
                
                if(*menunr== -2) {
-                       activate_databrowse((ID *)lockpoin, ID_MA, 0, B_MATBROWSE, menunr, do_global_buttons);
+                       if(G.qual & LR_CTRLKEY) {
+                               activate_databrowse_imasel((ID *)lockpoin, ID_MA, 0, B_MATBROWSE, menunr, do_global_buttons);
+                       }
+                       else {
+                               activate_databrowse((ID *)lockpoin, ID_MA, 0, B_MATBROWSE, menunr, do_global_buttons);
+                       }
                        return;
                }
                
@@ -750,6 +777,7 @@ void do_global_buttons(unsigned short event)
                                allqueue(REDRAWBUTSSHADING, 0);
                                allqueue(REDRAWIPO, 0);
                                allqueue(REDRAWOOPS, 0);
+                               allqueue(REDRAWVIEW3D, 0);
                                BIF_preview_changed(ID_MA);
                        }
                }
@@ -804,7 +832,10 @@ void do_global_buttons(unsigned short event)
                        }
                        else {  /* from brush */
                                br= G.scene->toolsettings->imapaint.brush;
-                               if(br) {
+                               if(G.f & G_SCULPTMODE) {
+                                       sculptmode_rem_tex(NULL, NULL);
+                                       allqueue(REDRAWBUTSSHADING, 0);
+                               } else if(br) {
                                        mtex= br->mtex[ br->texact ];
                                        if(mtex) {
                                                if(mtex->tex) mtex->tex->id.us--;
@@ -835,8 +866,12 @@ void do_global_buttons(unsigned short event)
                                        if(mtex) id= (ID *)mtex->tex;
                                }
                        }
-                       
-                       activate_databrowse(id, ID_TE, 0, B_TEXBROWSE, &G.buts->texnr, do_global_buttons);
+                       if(G.qual & LR_CTRLKEY) {
+                               activate_databrowse_imasel(id, ID_TE, 0, B_TEXBROWSE, &G.buts->texnr, do_global_buttons);
+                       }
+                       else {
+                               activate_databrowse(id, ID_TE, 0, B_TEXBROWSE, &G.buts->texnr, do_global_buttons);
+                       }
                        return;
                }
                if(G.buts->texnr < 0) break;
@@ -884,76 +919,152 @@ void do_global_buttons(unsigned short event)
                }
                break;
        case B_ACTIONDELETE:
-               act=ob->action;
-               
-               if (act)
-                       act->id.us--;
-               ob->action=NULL;
-               if(ob->pose) {          // clear flag, also used for draw colors
-                       bPoseChannel *pchan;
-                       for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next)
-                               pchan->flag= 0;
-               }
-               BIF_undo_push("Unlink Action");
-               
-               allqueue(REDRAWVIEW3D, 0);
-               allqueue(REDRAWACTION, 0);
-               allqueue(REDRAWNLA, 0);
-               allqueue(REDRAWIPO, 0);
+               /* only available when not pinned */
+               if (G.saction->pin == 0) {
+                       act= ob->action;
+                       
+                       /* decrement user-count of action (as ob no longer uses it) */
+                       if (act)
+                               act->id.us--;
+                       
+                       /* make sure object doesn't hold reference to it anymore */     
+                       ob->action=NULL;
+                       if (ob->pose) {         /* clear flag (POSE_LOC/ROT/SIZE), also used for draw colors */
+                               bPoseChannel *pchan;
+                               for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next)
+                                       pchan->flag= 0;
+                       }
+                       
+                       BIF_undo_push("Unlink Action");
+                       
+                       allqueue(REDRAWVIEW3D, 0);
+                       allqueue(REDRAWACTION, 0);
+                       allqueue(REDRAWNLA, 0);
+                       allqueue(REDRAWIPO, 0);
+                       allqueue(REDRAWBUTSEDIT, 0);
+               }
                break;
        case B_ACTIONBROWSE:
                if (!ob)
                        break;
                act=ob->action;
                id= (ID *)act;
-
+               
                if (G.saction->actnr== -2){
                                activate_databrowse((ID *)G.saction->action, ID_AC,  0, B_ACTIONBROWSE, &G.saction->actnr, do_global_buttons);
                        return;
                }
-
-               if(G.saction->actnr < 0) break;
-
+               
+               if (G.saction->actnr < 0) break;
+               
                /*      See if we have selected a valid action */
                for (idtest= G.main->action.first; idtest; idtest= idtest->next) {
-                               if(nr==G.saction->actnr) {
-                                       break;
-                               }
-                               nr++;
-                       
+                       if (nr==G.saction->actnr)
+                               break;
+                       nr++;
                }
 
-               if(G.saction->pin) {
-                       G.saction->action= (bAction *)idtest;
+               if (G.saction->pin) {
+                       if (idtest == NULL) {
+                               /* assign new/copy of pinned action only - messy as it doesn't assign to any obj's */
+                               if (G.saction->action)
+                                       G.saction->action= (bAction *)copy_action(G.saction->action);
+                               else
+                                       G.saction->action= (bAction *)add_empty_action("PinnedAction");
+                       }
+                       else {
+                               G.saction->action= (bAction *)idtest;
+                       }
                        allqueue(REDRAWACTION, 0);
                }
                else {
-
                        /* Store current action */
-                       if (!idtest){
-                               if (act)
+                       if (idtest == NULL) {
+                               /* 'Add New' option: 
+                                *      - make a copy of an exisiting action
+                                *      - or make a new empty action if no existing action
+                                */
+                               if (act) {
                                        idtest= (ID *)copy_action(act);
-                               else 
-                                       idtest=(ID *)add_empty_action(ob->type==OB_ARMATURE?ID_PO:ID_OB);
+                               } 
+                               else { 
+                                       if ((ob->ipo) && (ob->ipoflag & OB_ACTION_OB)==0) {
+                                               /* object ipo - like if B_IPO_ACTION_OB is triggered */
+                                               bActionChannel *achan;
+                                               
+                                               if (has_ipo_code(ob->ipo, OB_LAY))
+                                                       notice("Note: Layer Ipo doesn't work in Actions");
+                                               
+                                               ob->ipoflag |= OB_ACTION_OB;
+                                               
+                                               act = add_empty_action("ObAction");
+                                               idtest=(ID *)act;
+                                               
+                                               
+                                               achan= verify_action_channel(act, "Object");
+                                               achan->flag = (ACHAN_HILIGHTED|ACHAN_SELECTED|ACHAN_EXPANDED|ACHAN_SHOWIPO);
+                                               
+                                               if (achan->ipo==NULL) {
+                                                       achan->ipo= ob->ipo;
+                                                       ob->ipo= NULL;
+                                                       
+                                                       allqueue(REDRAWIPO, 0);
+                                                       allqueue(REDRAWOOPS, 0);
+                                               }
+                                               
+                                               /* object constraints */
+                                               if (ob->constraintChannels.first) {
+                                                       free_constraint_channels(&achan->constraintChannels);
+                                                       achan->constraintChannels= ob->constraintChannels;
+                                                       ob->constraintChannels.first= ob->constraintChannels.last= NULL;
+                                               }
+                                       }
+                                       else if (ELEM(ob->type, OB_MESH, OB_LATTICE) && ob_get_key(ob)) {
+                                               /* shapekey - like if B_IPO_ACTION_KEY is triggered */
+                                               bActionChannel *achan;
+                                               Key *key= ob_get_key(ob);
+                                               
+                                               ob->ipoflag |= OB_ACTION_KEY;
+                                               
+                                               act = add_empty_action("ShapeAction");
+                                               idtest=(ID *)act;
+                                               
+                                               achan= verify_action_channel(act, "Shape");
+                                               achan->flag = (ACHAN_HILIGHTED|ACHAN_SELECTED|ACHAN_EXPANDED|ACHAN_SHOWIPO);
+                                               
+                                               if ((achan->ipo==NULL) && (key->ipo)) {
+                                                       achan->ipo= key->ipo;
+                                                       key->ipo= NULL;
+                                                       
+                                                       allqueue(REDRAWIPO, 0);
+                                                       allqueue(REDRAWOOPS, 0);
+                                               }
+                                       }
+                                       else {
+                                               /* a plain action */
+                                               idtest=(ID *)add_empty_action("Action");
+                                       }
+                               }
                                idtest->us--;
                        }
                        
                        
-                       if(idtest!=id && ob) {
+                       if ((idtest!=id) && (ob)) {
                                act= (bAction *)idtest;
                                
                                ob->action= act;
                                id_us_plus(idtest);
                                
-                               if(id) id->us--;
+                               if (id) id->us--;
                                
-                               // Update everything
+                               /* Update everything */
                                BIF_undo_push("Browse Action");
                                do_global_buttons (B_NEWFRAME);
                                allqueue(REDRAWVIEW3D, 0);
                                allqueue(REDRAWNLA, 0);
                                allqueue(REDRAWACTION, 0);
                                allqueue(REDRAWHEADERS, 0); 
+                               allqueue(REDRAWBUTSEDIT, 0);
                        }
                }
                
@@ -966,7 +1077,7 @@ void do_global_buttons(unsigned short event)
                if(from==NULL) return;
 
                if(G.sipo->menunr== -2) {
-                       activate_databrowse((ID *)G.sipo->ipo, ID_IP, GS(from->name), B_IPOBROWSE, &G.sipo->menunr, do_global_buttons);
+                       activate_databrowse((ID *)G.sipo->ipo, ID_IP, G.sipo->blocktype, B_IPOBROWSE, &G.sipo->menunr, do_global_buttons);
                        return;
                }
 
@@ -1008,13 +1119,15 @@ void do_global_buttons(unsigned short event)
                                        else if(nr==ID_LA) idtest= (ID *)add_ipo("LaIpo", nr);
                                        else if(nr==ID_CA) idtest= (ID *)add_ipo("CaIpo", nr);
                                        else if(nr==ID_SO) idtest= (ID *)add_ipo("SndIpo", nr);
+                                       else if(nr==ID_FLUIDSIM) idtest= (ID *)add_ipo("FluidsimIpo", nr);
+                                       else if(nr==ID_PA) idtest= (ID *)add_ipo("PaIpo", nr);
                                        else error("Warn bugtracker!");
                                }
                                idtest->us--;
                        }
                        if(idtest!=id && from) {
                                spaceipo_assign_ipo(G.sipo, (Ipo *)idtest);
-                                                                       
+                               
                                BIF_undo_push("Browse Ipo");
                        }
                }
@@ -1238,10 +1351,17 @@ void do_global_buttons(unsigned short event)
                break;
 
        case B_IMAGEDELETE:
-               G.sima->image= NULL;
-               image_changed(G.sima, 0);
-               BIF_undo_push("Unlink Image");
-               allqueue(REDRAWIMAGE, 0);
+               if(G.sima->image && (G.sima->image->type == IMA_TYPE_R_RESULT || G.sima->image->type == IMA_TYPE_COMPOSITE)) {
+                       /* Run if G.sima is render, remove the render and display the meshes image if it exists */
+                       G.sima->image= NULL;
+                       what_image(G.sima);
+                       allqueue(REDRAWIMAGE, 0);
+               } else {
+                       /* Run on non render images, unlink normally */
+                       image_changed(G.sima, NULL);
+                       BIF_undo_push("Unlink Image");
+                       allqueue(REDRAWIMAGE, 0);
+               }
                break;
        
        case B_AUTOMATNAME:
@@ -1282,6 +1402,16 @@ void do_global_buttons(unsigned short event)
                        allqueue(REDRAWOOPS, 0);
                        allqueue(REDRAWIMAGE, 0);
                }
+               else if(G.buts->mainb==CONTEXT_EDITING) {
+                       SculptData *sd= &G.scene->sculptdata;
+                       if(sd && sd->texact != -1) {
+                               if(sd->mtex[sd->texact]) autotexname(sd->mtex[sd->texact]->tex);
+
+                               BIF_undo_push("Auto name");
+                               allqueue(REDRAWBUTSEDIT, 0);
+                               allqueue(REDRAWOOPS, 0);
+                       }
+               }
                break;
 
        case B_RESETAUTOSAVE:
@@ -1298,8 +1428,14 @@ void do_global_buttons(unsigned short event)
                set_mipmap(!(U.gameflags & USER_DISABLE_MIPMAP));
                allqueue(REDRAWVIEW3D, 0);
                break;
+       case B_GLRESLIMITCHANGED:
+               free_all_realtime_images(); /* force reloading with new res limit */
+               allqueue(REDRAWVIEW3D, 0);
+               break;
        case B_NEWSPACE:
                newspace(curarea, curarea->butspacetype);
+               reset_filespace(curarea);
+               reset_imaselspace(curarea);
                break;
        case B_LOADTEMP:        /* is button from space.c */
                BIF_read_autosavefile();
@@ -1390,9 +1526,12 @@ void do_global_buttons(unsigned short event)
                break;
 
        case B_PYMENUEVAL: /* is button from space.c *info* */
-               BPyMenu_RemoveAllEntries(); /* free old data */
-               if (BPyMenu_Init(1) == -1) /* re-eval scripts registration in menus */
+               waitcursor( 1 ); /* can take some time */
+               if (BPY_path_update() == 0) { /* re-eval scripts registration in menus */
+                       waitcursor( 0 );
                        error("Invalid scripts dir: check console");
+               }
+               waitcursor( 0 );
                break;
        case B_PYTHONDIRFILESEL:        /* is button from space.c  *info* */
                if(curarea->spacetype==SPACE_INFO) {
@@ -1489,10 +1628,11 @@ void do_global_buttons(unsigned short event)
                allqueue(REDRAWOOPS, 1);
                allqueue(REDRAWACTION, 1);
                allqueue(REDRAWNLA, 1);
+               allqueue(REDRAWVIEW3D, 1);
                /* name scene also in set PUPmenu */
                allqueue(REDRAWBUTSALL, 0);
+               allqueue(REDRAWIMAGE, 0);
                allqueue(REDRAWHEADERS, 0);
-
                break;
        
        case B_KEEPDATA:
@@ -1505,15 +1645,15 @@ void do_global_buttons(unsigned short event)
                        id = (ID *)G.sipo->ipo;
                } else if(curarea->spacetype==SPACE_NODE) {
                        id = ((SpaceNode *)curarea->spacedata.first)->id;
-               } /* similar for other spacetypes ? */
+               } else if(curarea->spacetype==SPACE_ACTION) {
+                       id= (ID *)G.saction->action;
+               }/* similar for other spacetypes ? */
                if (id) {
-                       if( id->flag & LIB_FAKEUSER) {
-                               id->flag -= LIB_FAKEUSER;
-                               id->us--;
-                       } else {
-                               id->flag |= LIB_FAKEUSER;
+                       /* flag was already toggled, just need to update user count */
+                       if(id->flag & LIB_FAKEUSER)
                                id->us++;
-                       }
+                       else
+                               id->us--;
                }
                allqueue(REDRAWHEADERS, 0);
 
@@ -1600,7 +1740,8 @@ void do_global_buttons2(short event)
                        if(act->id.lib) {
                                if(okee("Make local")) {
                                        make_local_action(act);
-                                       allqueue(REDRAWACTION,0);
+                                       allqueue(REDRAWACTION, 0);
+                                       allqueue(REDRAWBUTSEDIT, 0);
                                }
                        }
                }
@@ -1608,12 +1749,13 @@ void do_global_buttons2(short event)
        case B_ACTALONE:
                if(ob && ob->id.lib==0) {
                        act= ob->action;
-               
+                       
                        if(act->id.us>1) {
                                if(okee("Single user")) {
                                        ob->action=copy_action(act);
                                        act->id.us--;
                                        allqueue(REDRAWACTION, 0);
+                                       allqueue(REDRAWBUTSEDIT, 0);
                                }
                        }
                }