Merged 15170:15635 from trunk (no conflicts or even merges)
[blender.git] / source / blender / src / headerbuttons.c
index 510619e0a8a44cdf36c6d5759d1409d3924cd9f6..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 <config.h>
 #endif
 
-#ifdef WIN32
-#include "BLI_winstuff.h"
-#endif
-
 #include "MEM_guardedalloc.h"
 
 #include "BMF_Api.h"
@@ -62,6 +55,7 @@
 #include "DNA_ID.h"
 #include "DNA_action_types.h"
 #include "DNA_armature_types.h"
+#include "DNA_brush_types.h"
 #include "DNA_camera_types.h"
 #include "DNA_curve_types.h"
 #include "DNA_group_types.h"
 
 #include "BKE_utildefines.h"
 
-#include "BKE_constraint.h"
 #include "BKE_action.h"
 #include "BKE_armature.h"
 #include "BKE_blender.h"
+#include "BKE_brush.h"
+#include "BKE_constraint.h"
 #include "BKE_curve.h"
-#include "BKE_displist.h"
+#include "BKE_depsgraph.h"
 #include "BKE_exotic.h"
 #include "BKE_global.h"
 #include "BKE_image.h"
-#include "BKE_ika.h"
 #include "BKE_ipo.h"
 #include "BKE_key.h"
 #include "BKE_lattice.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_drawoops.h"
 #include "BIF_drawscene.h"
 #include "BIF_drawtext.h"
+#include "BIF_editaction.h"
 #include "BIF_editarmature.h"
 #include "BIF_editfont.h"
 #include "BIF_editlattice.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 "BSE_node.h"
 #include "BSE_view.h"
 #include "BSE_sequence.h"
-#include "BSE_editaction.h"
-#include "BSE_editaction_types.h"
 #include "BSE_editipo.h"
 #include "BSE_drawipo.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"
 #include "nla.h"       /* __NLA : To be removed later */
 #include "butspace.h"  // test_idbutton
 
-#include "TPT_DependKludge.h"
-
 #include "BIF_poseobject.h"
 
 #include "SYS_System.h"
 
 char *windowtype_pup(void)
 {
-       static char string[1024];
-
-       strcpy(string, "Window type:%t"); //14
-       strcat(string, "|3D View %x1"); //30
-
-       strcat(string, "|%l"); // 33
-
-       strcat(string, "|Ipo Curve Editor %x2"); //54
-       strcat(string, "|Action Editor %x12"); //73
-       strcat(string, "|NLA Editor %x13"); //94
+       return(
+       "Window type:%t" //14
+       "|3D View %x1" //30
 
-       strcat(string, "|%l"); //97
+       "|%l" // 33
 
-       strcat(string, "|UV/Image Editor %x6"); //117
+       "|Ipo Curve Editor %x2" //54
+       "|Action Editor %x12" //73
+       "|NLA Editor %x13" //94
 
-       strcat(string, "|Video Sequence Editor %x8"); //143
-       strcat(string, "|Audio Timeline %x11"); //163
-       strcat(string, "|Text Editor %x9"); //179
+       "|%l" //97
 
-       strcat(string, "|%l"); //192
+       "|UV/Image Editor %x6" //117
 
+       "|Video Sequence Editor %x8" //143
+       "|Timeline %x15" //163
+       "|Audio Window %x11" //163
+       "|Text Editor %x9" //179
 
-       strcat(string, "|User Preferences %x7"); //213
-       strcat(string, "|Outliner %x3"); //232
-       strcat(string, "|Buttons Window %x4"); //251
+       "|%l" //192
 
-       strcat(string, "|%l"); //254
 
-       strcat(string, "|Image Browser %x10"); //273
-       strcat(string, "|File Browser %x5"); //290
+       "|User Preferences %x7" //213
+       "|Outliner %x3" //232
+       "|Buttons Window %x4" //251
+       "|Node Editor %x16"
+       "|%l" //254
 
-       strcat(string, "|%l"); //293
+       "|Image Browser %x10" //273
+       "|File Browser %x5" //290
 
-       strcat(string, "|Scripts Window %x14"); //313
+       "|%l" //293
 
-       return (string);
+       "|Scripts Window %x14"//313
+       );
 }
 
 int GetButStringLength(char *str) {
@@ -239,15 +230,13 @@ int GetButStringLength(char *str) {
 /* ********************** GLOBAL ****************************** */
 
 int std_libbuttons(uiBlock *block, short xco, short yco,
-                                                       int pin, short *pinpoin, int browse, ID *id,
+                                                       int pin, short *pinpoin, int browse, short id_code, short special, ID *id,
                                                        ID *parid, short *menupoin, int users, int lib,
                                                        int del, int autobut, int keepbut)
 {
        ListBase *lb;
-       Object *ob;
-       Ipo *ipo;
        uiBut *but;
-       int len, idwasnul=0, idtype, oldcol, add_addbutton=0;
+       int len, oldcol, add_addbutton=0;
        char *str=NULL, str1[10];
 
        uiBlockBeginAlign(block);
@@ -257,141 +246,49 @@ int std_libbuttons(uiBlock *block, short xco, short yco,
                uiDefIconButS(block, ICONTOG, pin, ICON_PIN_DEHLT, xco,yco,XIC,YIC, pinpoin, 0, 0, 0, 0, "Keeps this view displaying the current data regardless of what object is selected");
                xco+= XIC;
        }
+       /* browse menu */
        if(browse) {
-               if(id==0) {
-                       idwasnul= 1;
-                       /* only the browse button */
-                       ob= OBACT;
-                       if(curarea->spacetype==SPACE_IMAGE) {
-                               id= G.main->image.first;
-                       }
-                       else if(curarea->spacetype==SPACE_SOUND) {
-                               id= G.main->sound.first;
-                       }
-                       else if(curarea->spacetype==SPACE_ACTION) {
-                               if(ob) id= G.main->action.first;
-                       }
-                       else if(curarea->spacetype==SPACE_NLA) {
-                               id= NULL;
-                       }
-                       else if(curarea->spacetype==SPACE_IPO) {
-                               id= G.main->ipo.first;
-                               
-                               /* test for ipotype */
-                               while(id) {
-                                       ipo= (Ipo *)id;
-                                       if(G.sipo->blocktype==ipo->blocktype) break;
-                                       id= id->next;
-                               }
-                               if(ob==NULL) {
-                                       if(G.sipo->blocktype!=ID_SEQ && G.sipo->blocktype!=ID_WO) {
-                                               id= NULL; 
-                                               idwasnul= 0;
-                                       }
-                               }
-                       }
-                       else if(curarea->spacetype==SPACE_BUTS) {
-                               if(browse==B_WORLDBROWSE) {
-                                       id= G.main->world.first;
-                               }
-                               else if(ob && ob->type && (ob->type<=OB_LAMP)) {
-                                       if(G.buts->mainb==CONTEXT_SHADING) {
-                                               int tab= G.buts->tab[CONTEXT_SHADING];
-                                               
-                                               if(tab==TAB_SHADING_MAT) id= G.main->mat.first;
-                                               else if(tab==TAB_SHADING_TEX) id= G.main->tex.first;
-                                               
-                                               add_addbutton= 1;
-                                       }
-                               }
-                       }
-                       else if(curarea->spacetype==SPACE_TEXT) {
-                               id= G.main->text.first;
-                       }
-                       else if(curarea->spacetype==SPACE_SCRIPT) {
-                               id= G.main->script.first;
-                       }
-               }
-               if(id) {
-                       char *extrastr= NULL;
-                       
-                       idtype= GS(id->name);
-                       lb= wich_libbase(G.main, GS(id->name));
+               char *extrastr= NULL;
+               
+               if(ELEM4(id_code, ID_MA, ID_TE, ID_BR, ID_PA)) add_addbutton= 1;
                        
-                       if(idwasnul) id= NULL;
-                       else if(id->us>1) uiBlockSetCol(block, TH_BUT_SETTING1);
+               lb= wich_libbase(G.main, id_code);
+               
+               if(id && id->us>1) uiBlockSetCol(block, TH_BUT_SETTING1);
 
-                       if (pin && *pinpoin) {
-                               uiBlockSetCol(block, TH_BUT_SETTING2);
-                       }
-                       
-                       if ELEM7( idtype, ID_SCE, ID_SCR, ID_MA, ID_TE, ID_WO, ID_IP, ID_AC) extrastr= "ADD NEW %x 32767";
-                       else if (idtype==ID_TXT) extrastr= "OPEN NEW %x 32766 |ADD NEW %x 32767";
-                       else if (idtype==ID_SO) extrastr= "OPEN NEW %x 32766";
-                       
-                       uiSetButLock(G.scene->id.lib!=0, "Can't edit library data");
-                       if( idtype==ID_SCE || idtype==ID_SCR ) uiClearButLock();
-                       
-                       if(curarea->spacetype==SPACE_BUTS)
-                               uiSetButLock(idtype!=ID_SCR && G.obedit!=0 && G.buts->mainb==CONTEXT_EDITING, NULL);
-                       
-                       if(parid) uiSetButLock(parid->lib!=0, "Can't edit library data");
+               if (pin && *pinpoin) {
+                       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) || 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";
 
-                       if (lb) {
-                               if( idtype==ID_IP)
-                                       IPOnames_to_pupstring(&str, NULL, extrastr, lb, id, menupoin, G.sipo->blocktype);
-                               else
-                                       IDnames_to_pupstring(&str, NULL, extrastr, lb, id, menupoin);
-                       }
-                       
-                       uiDefButS(block, MENU, browse, str, xco,yco,XIC,YIC, menupoin, 0, 0, 0, 0, "Browses existing choices or adds NEW");
-                       
-                       uiClearButLock();
+               uiSetButLock(G.scene->id.lib!=0, ERROR_LIBDATA_MESSAGE);
+               if( id_code==ID_SCE || id_code==ID_SCR ) uiClearButLock();
                
-                       MEM_freeN(str);
-               }
-               else if(curarea->spacetype==SPACE_BUTS) {
-                       if(G.buts->mainb==CONTEXT_SHADING) {
-                               uiSetButLock(G.scene->id.lib!=0, "Can't edit library data");
-                               if(parid) uiSetButLock(parid->lib!=0, "Can't edit library data");
-                               uiDefButS(block, MENU, browse, "ADD NEW %x 32767",xco,yco,XIC,YIC, menupoin, 0, 0, 0, 0, "Browses Datablock");
-                               uiClearButLock();
-                       } else if (G.buts->mainb == CONTEXT_SCENE) {
-                               if(G.buts->tab[CONTEXT_SCENE]== TAB_SCENE_SOUND) {
-                                       uiDefButS(block, MENU, browse, "OPEN NEW %x 32766",xco,yco,XIC,YIC, menupoin, 0, 0, 0, 0, "Browses Datablock");
-                               }
-                       }
-               }
-               else if(curarea->spacetype==SPACE_TEXT) {
-                       uiDefButS(block, MENU, browse, "OPEN NEW %x 32766 | ADD NEW %x 32767", xco,yco,XIC,YIC, menupoin, 0, 0, 0, 0, "Browses Datablock");
-               }
-               else if(curarea->spacetype==SPACE_SCRIPT) {
-                       uiDefButS(block, MENU, browse, "No running scripts", xco, yco, XIC, YIC, menupoin, 0, 0, 0, 0, "Browses Datablock");
-               }
-               else if(curarea->spacetype==SPACE_SOUND) {
-                       uiDefButS(block, MENU, browse, "OPEN NEW %x 32766",xco,yco,XIC,YIC, menupoin, 0, 0, 0, 0, "Browses Datablock");
-               }
-               else if(curarea->spacetype==SPACE_ACTION) {
-                       uiSetButLock(G.scene->id.lib!=0, "Can't edit library data");
-                       if(parid) uiSetButLock(parid->lib!=0, "Can't edit library data");
+               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, ERROR_LIBDATA_MESSAGE);
 
-                       uiDefButS(block, MENU, browse, "ADD NEW %x 32767", xco,yco,XIC,YIC, menupoin, 0, 0, 0, 0, "Browses Datablock");
-                       uiClearButLock();
-               }
-               else if(curarea->spacetype==SPACE_IPO) {
-                       if(idwasnul) {
-                               uiSetButLock(G.scene->id.lib!=0, "Can't edit library data");
-                               if(parid) uiSetButLock(parid->lib!=0, "Can't edit library data");
-       
-                               uiDefButS(block, MENU, browse, "ADD NEW %x 32767", xco,yco,XIC,YIC, menupoin, 0, 0, 0, 0, "Browses Datablock");
-                               uiClearButLock();
-                       }
+               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);
                }
                
+               uiDefButS(block, MENU, browse, str, xco,yco,XIC,YIC, menupoin, 0, 0, 0, 0, "Browses existing choices or adds NEW");
                xco+= XIC;
+               
+               uiClearButLock();
+       
+               MEM_freeN(str);
        }
 
-
        uiBlockSetCol(block, oldcol);
 
        if(id) {        /* text button with name */
@@ -405,20 +302,29 @@ 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);
                
-               str1[0]= id->name[0];
-               str1[1]= id->name[1];
-               str1[2]= ':';
-               str1[3]= 0;
-               if(strcmp(str1, "SC:")==0) strcpy(str1, "SCE:");
-               else if(strcmp(str1, "SR:")==0) strcpy(str1, "SCR:");
+               if(GS(id->name)==ID_SCE) strcpy(str1, "SCE:");
+               else if(GS(id->name)==ID_SCE) strcpy(str1, "SCR:");
+               else if(GS(id->name)==ID_MA) {
+                       if( ((Material *)id)->use_nodes )
+                               strcpy(str1, "NT:");
+                       else
+                               strcpy(str1, "MA:");
+               }
+               else {
+                       str1[0]= id->name[0];
+                       str1[1]= id->name[1];
+                       str1[2]= ':';
+                       str1[3]= 0;
+               }
                
                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();
@@ -427,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;
                }
@@ -453,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();
                }
 
@@ -474,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;
        }
@@ -491,50 +399,50 @@ int std_libbuttons(uiBlock *block, short xco, short yco,
        return xco;
 }
 
-static void do_update_for_newframe(int mute)
+
+/* results in fully updated anim system */
+static void do_update_for_newframe(int mute, int events)
 {
        extern void audiostream_scrub(unsigned int frame);      /* seqaudio.c */
        
-       allqueue(REDRAWVIEW3D, 0);
-       allqueue(REDRAWACTION,0);
-       allqueue(REDRAWNLA,0);
-       allqueue(REDRAWIPO, 0);
-       allqueue(REDRAWINFO, 1);
-       allqueue(REDRAWSEQ, 1);
-       allqueue(REDRAWSOUND, 1);
-       allqueue(REDRAWBUTSHEAD, 0);
-       allqueue(REDRAWBUTSSHADING, 0);
-       allqueue(REDRAWBUTSOBJECT, 0);
-
-       /* layers/materials, object ipos are calculted in where_is_object (too) */
-       do_all_ipos();
-       BPY_do_all_scripts(SCRIPT_FRAMECHANGED);
-       clear_all_constraints();
-       do_all_keys();
-
-       do_all_actions();
-       rebuild_all_armature_displists();
-       /* so nice, better do it twice */
-       do_all_actions();
-       rebuild_all_armature_displists();
-
-       do_all_ikas();
-
-       test_all_displists();
+       if(events) {
+               allqueue(REDRAWALL, 0);
+       }
        
-       if ( (CFRA>1) && (!mute) && (G.scene->audio.flag & AUDIO_SCRUB)) audiostream_scrub( CFRA );
+       /* 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 );
+       
+       /* 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)
 {
-       do_update_for_newframe(0);
+       do_update_for_newframe(0, 1);
 }
 
 void update_for_newframe_muted(void)
 {
-       do_update_for_newframe(1);
+       do_update_for_newframe(1, 1);
+}
+
+/* used by new animated UI playback */
+void update_for_newframe_nodraw(int nosound)
+{
+       do_update_for_newframe(nosound, 0);
 }
 
+
 static void show_splash(void)
 {
        extern char datatoc_splash_jpg[];
@@ -545,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);
@@ -562,6 +471,8 @@ static void show_splash(void)
 static void filesel_u_yfexportdir(char *name)
 {
        char dir[FILE_MAXDIR], file[FILE_MAXFILE];
+
+       BLI_cleanup_dir(G.sce, name);
        BLI_split_dirfile(name, dir, file);
 
        strcpy(U.yfexportdir, dir);
@@ -571,6 +482,8 @@ static void filesel_u_yfexportdir(char *name)
 static void filesel_u_fontdir(char *name)
 {
        char dir[FILE_MAXDIR], file[FILE_MAXFILE];
+       
+       BLI_cleanup_dir(G.sce, name);
        BLI_split_dirfile(name, dir, file);
 
        strcpy(U.fontdir, dir);
@@ -580,6 +493,8 @@ static void filesel_u_fontdir(char *name)
 static void filesel_u_textudir(char *name)
 {
        char dir[FILE_MAXDIR], file[FILE_MAXFILE];
+
+       BLI_cleanup_dir(G.sce, name);
        BLI_split_dirfile(name, dir, file);
 
        strcpy(U.textudir, dir);
@@ -589,6 +504,8 @@ static void filesel_u_textudir(char *name)
 static void filesel_u_plugtexdir(char *name)
 {
        char dir[FILE_MAXDIR], file[FILE_MAXFILE];
+
+       BLI_cleanup_dir(G.sce, name);
        BLI_split_dirfile(name, dir, file);
 
        strcpy(U.plugtexdir, dir);
@@ -598,6 +515,8 @@ static void filesel_u_plugtexdir(char *name)
 static void filesel_u_plugseqdir(char *name)
 {
        char dir[FILE_MAXDIR], file[FILE_MAXFILE];
+
+       BLI_cleanup_dir(G.sce, name);
        BLI_split_dirfile(name, dir, file);
 
        strcpy(U.plugseqdir, dir);
@@ -607,6 +526,8 @@ static void filesel_u_plugseqdir(char *name)
 static void filesel_u_renderdir(char *name)
 {
        char dir[FILE_MAXDIR], file[FILE_MAXFILE];
+
+       BLI_cleanup_dir(G.sce, name);
        BLI_split_dirfile(name, dir, file);
 
        strcpy(U.renderdir, dir);
@@ -616,15 +537,24 @@ static void filesel_u_renderdir(char *name)
 static void filesel_u_pythondir(char *name)
 {
        char dir[FILE_MAXDIR], file[FILE_MAXFILE];
-       BLI_split_dirfile(name, dir, file);
 
+       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)
 {
        char dir[FILE_MAXDIR], file[FILE_MAXFILE];
+
+       BLI_cleanup_dir(G.sce, name);
        BLI_split_dirfile(name, dir, file);
 
        strcpy(U.sounddir, dir);
@@ -634,9 +564,13 @@ static void filesel_u_sounddir(char *name)
 static void filesel_u_tempdir(char *name)
 {
        char dir[FILE_MAXDIR], file[FILE_MAXFILE];
+
+       BLI_cleanup_dir(G.sce, name);
        BLI_split_dirfile(name, dir, file);
 
        strcpy(U.tempdir, dir);
+       BLI_where_is_temp( btempdir, 1 );
+       
        allqueue(REDRAWALL, 0);
 }
 
@@ -652,17 +586,19 @@ void do_global_buttons(unsigned short event)
        Ipo *ipo;
        Lamp *la;
        World *wrld;
-       Sequence *seq;
        bAction *act;
-       ID *id, *idtest, *from;
+       ID *id, *idtest, *from=NULL;
        ScrArea *sa;
+       Brush *br;
        int nr= 1;
-       char buf[FILE_MAXDIR+FILE_MAXFILE];
-
+       
+#ifdef INTERNATIONAL
+       char buf[FILE_MAX];
+#endif
 
        ob= OBACT;
 
-       id= 0;  /* id at null for texbrowse */
+       id= NULL;       /* id at null for texbrowse */
 
 
        switch(event) {
@@ -683,10 +619,10 @@ void do_global_buttons(unsigned short event)
                scrarea_queue_headredraw(curarea);
                break;
        case B_EDITBROWSE:
-               if(ob==0) return;
+               if(ob==NULL) return;
                if(ob->id.lib) return;
                id= ob->data;
-               if(id==0) return;
+               if(id==NULL) return;
 
                if(G.buts->menunr== -2) {
                        activate_databrowse((ID *)G.buts->lockpoin, GS(id->name), 0, B_EDITBROWSE, &G.buts->menunr, do_global_buttons);
@@ -708,12 +644,11 @@ void do_global_buttons(unsigned short event)
                                        
                                        if( GS(idtest->name)==ID_CU ) {
                                                test_curve_type(ob);
-                                               allqueue(REDRAWBUTSEDIT, 0);
-                                               makeDispList(ob);
                                        }
-                                       else if( ob->type==OB_MESH ) {
-                                               makeDispList(ob);
+                                       else if( ob->type==OB_ARMATURE) {
+                                               armature_rebuild_pose(ob, ob->data);
                                        }
+                                       DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
                                        
                                        allqueue(REDRAWBUTSEDIT, 0);
                                        allqueue(REDRAWVIEW3D, 0);
@@ -746,9 +681,10 @@ void do_global_buttons(unsigned short event)
                idtest= G.main->mesh.first;
                while(idtest) {
                        if(nr==G.buts->menunr) {
-                                       
                                set_mesh(ob, (Mesh *)idtest);
                                
+                               DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
+                                       
                                BIF_undo_push("Browse Mesh");
                                allqueue(REDRAWBUTSEDIT, 0);
                                allqueue(REDRAWVIEW3D, 0);
@@ -763,14 +699,35 @@ void do_global_buttons(unsigned short event)
 
                break;
        case B_MATBROWSE:
-               if(G.buts->menunr== -2) {
-                       activate_databrowse((ID *)G.buts->lockpoin, ID_MA, 0, B_MATBROWSE, &G.buts->menunr, do_global_buttons);
+       {
+               void *lockpoin= NULL;
+               short *menunr= 0;
+               
+               /* this is called now from Node editor too, buttons might not exist */
+               if(curarea->spacetype==SPACE_NODE) {
+                       SpaceNode *snode= curarea->spacedata.first;
+                       menunr= &snode->menunr;
+                       lockpoin= snode->id;
+               }
+               else if(G.buts) {
+                       menunr= &G.buts->menunr;
+                       lockpoin= G.buts->lockpoin;
+               }
+               else return;
+               
+               if(*menunr== -2) {
+                       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;
                }
                
-               if(G.buts->menunr < 0) return;
+               if(*menunr < 0) return;
                
-               if(G.buts->pin) {
+               if(0) { /* future pin */
                        
                }
                else {
@@ -782,7 +739,7 @@ void do_global_buttons(unsigned short event)
                        
                        idtest= G.main->mat.first;
                        while(idtest) {
-                               if(nr==G.buts->menunr) {
+                               if(nr== *menunr) {
                                        break;
                                }
                                nr++;
@@ -801,13 +758,15 @@ void do_global_buttons(unsigned short event)
                                BIF_undo_push("Browse Material");
                                allqueue(REDRAWBUTSSHADING, 0);
                                allqueue(REDRAWIPO, 0);
-                               BIF_preview_changed(G.buts);
+                               allqueue(REDRAWNODE, 0);
+                               BIF_preview_changed(ID_MA);
                        }
                        
                }
+       }
                break;
        case B_MATDELETE:
-               if(G.buts->pin) {
+               if(0) { /* future pin */
                        
                }
                else {
@@ -818,7 +777,8 @@ void do_global_buttons(unsigned short event)
                                allqueue(REDRAWBUTSSHADING, 0);
                                allqueue(REDRAWIPO, 0);
                                allqueue(REDRAWOOPS, 0);
-                               BIF_preview_changed(G.buts);
+                               allqueue(REDRAWVIEW3D, 0);
+                               BIF_preview_changed(ID_MA);
                        }
                }
                break;
@@ -829,15 +789,16 @@ void do_global_buttons(unsigned short event)
                else {
                        if(G.buts->texfrom==0) {        /* from mat */
                                ma= give_current_material(ob, ob->actcol);
+                               ma= editnode_get_active_material(ma);
                                if(ma) {
                                        mtex= ma->mtex[ ma->texact ];
                                        if(mtex) {
                                                if(mtex->tex) mtex->tex->id.us--;
                                                MEM_freeN(mtex);
-                                               ma->mtex[ ma->texact ]= 0;
+                                               ma->mtex[ ma->texact ]= NULL;
                                                allqueue(REDRAWBUTSSHADING, 0);
                                                allqueue(REDRAWIPO, 0);
-                                               BIF_preview_changed(G.buts);
+                                               BIF_preview_changed(ID_MA);
                                        }
                                }
                        }
@@ -848,24 +809,42 @@ void do_global_buttons(unsigned short event)
                                        if(mtex) {
                                                if(mtex->tex) mtex->tex->id.us--;
                                                MEM_freeN(mtex);
-                                               wrld->mtex[ wrld->texact ]= 0;
+                                               wrld->mtex[ wrld->texact ]= NULL;
                                                allqueue(REDRAWBUTSSHADING, 0);
                                                allqueue(REDRAWIPO, 0);
-                                               BIF_preview_changed(G.buts);
+                                               BIF_preview_changed(ID_WO);
                                        }
                                }
                        }
-                       else {  /* from lamp */
+                       else if(G.buts->texfrom==2) {   /* from lamp */
                                la= ob->data;
                                if(la && ob->type==OB_LAMP) { /* to be sure */
                                        mtex= la->mtex[ la->texact ];
                                        if(mtex) {
                                                if(mtex->tex) mtex->tex->id.us--;
                                                MEM_freeN(mtex);
-                                               la->mtex[ la->texact ]= 0;
+                                               la->mtex[ la->texact ]= NULL;
+                                               allqueue(REDRAWBUTSSHADING, 0);
+                                               allqueue(REDRAWIPO, 0);
+                                               BIF_preview_changed(ID_LA);
+                                       }
+                               }
+                       }
+                       else {  /* from brush */
+                               br= G.scene->toolsettings->imapaint.brush;
+                               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--;
+                                               MEM_freeN(mtex);
+                                               br->mtex[ br->texact ]= NULL;
                                                allqueue(REDRAWBUTSSHADING, 0);
+                                               allqueue(REDRAWIMAGE, 0);
                                                allqueue(REDRAWIPO, 0);
-                                               BIF_preview_changed(G.buts);
+                                               /*BIF_preview_changed(ID_BR);*/
                                        }
                                }
                        }
@@ -879,15 +858,20 @@ void do_global_buttons(unsigned short event)
                        
                        id= G.buts->lockpoin;
                        if(event==B_EXTEXBROWSE) {
-                               id= 0;
+                               id= NULL;
                                ma= give_current_material(ob, ob->actcol);
+                               ma= editnode_get_active_material(ma);
                                if(ma) {
                                        mtex= ma->mtex[ ma->texact ];
                                        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;
@@ -896,9 +880,10 @@ void do_global_buttons(unsigned short event)
                        
                }
                else {
-                       id= 0;
+                       id= NULL;
                        
                        ma= give_current_material(ob, ob->actcol);
+                       ma= editnode_get_active_material(ma);
                        if(ma) {
                                mtex= ma->mtex[ ma->texact ];
                                if(mtex) id= (ID *)mtex->tex;
@@ -929,88 +914,170 @@ void do_global_buttons(unsigned short event)
                                allqueue(REDRAWBUTSSHADING, 0);
                                allqueue(REDRAWIPO, 0);
                                allqueue(REDRAWOOPS, 0);
-                               BIF_preview_changed(G.buts);
+                               BIF_preview_changed(ID_MA);
                        }
                }
                break;
        case B_ACTIONDELETE:
-               act=ob->action;
-               
-               if (act)
-                       act->id.us--;
-               ob->action=NULL;
-               
-               BIF_undo_push("Unlink Action");
-               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();
+                               } 
+                               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;
-                               ob->activecon=NULL;
                                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);
                        }
                }
                
                break;
        case B_IPOBROWSE:
 
-               ipo= get_ipo_to_edit(&from);
+               ipo= G.sipo->ipo;
+               from= G.sipo->from;
                id= (ID *)ipo;
-               if(from==0) return;
+               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;
                }
 
@@ -1039,13 +1106,10 @@ void do_global_buttons(unsigned short event)
                        if(idtest==0) {
                                if(ipo) idtest= (ID *)copy_ipo(ipo);
                                else {
-                                       nr= GS(from->name);
-                                       if(nr==ID_OB){
-                                               if (G.sipo->blocktype==IPO_CO)
-                                                       idtest= (ID *)add_ipo("CoIpo", IPO_CO); /* BLEARGH! */
-                                               else
-                                                       idtest= (ID *)add_ipo("ObIpo", nr);
-                                       }
+                                       nr= G.sipo->blocktype;
+                                       if(nr==ID_OB) idtest= (ID *)add_ipo("ObIpo", ID_OB);
+                                       else if(nr==ID_CO) idtest= (ID *)add_ipo("CoIpo", ID_CO);
+                                       else if(nr==ID_PO) idtest= (ID *)add_ipo("ActIpo", nr);
                                        else if(nr==ID_MA) idtest= (ID *)add_ipo("MatIpo", nr);
                                        else if(nr==ID_TE) idtest= (ID *)add_ipo("TexIpo", nr);
                                        else if(nr==ID_SEQ) idtest= (ID *)add_ipo("MatSeq", nr);
@@ -1055,131 +1119,28 @@ 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_AC) idtest= (ID *)add_ipo("ActIpo", nr);
-                                       else error("Warn bugs@blender.nl!");
+                                       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) {
-                               ipo= (Ipo *)idtest;
-               
-                               if (ipo->blocktype==IPO_CO){
-                                       ((Object*)from)->activecon->ipo = ipo;
-                                       id_us_plus(idtest);
-                                       allqueue(REDRAWVIEW3D, 0);
-                                       allqueue(REDRAWACTION, 0);
-                                       allqueue(REDRAWNLA, 0);
-                               }
-                               else if(ipo->blocktype==ID_OB) {
-                                       ( (Object *)from)->ipo= ipo;
-                                       id_us_plus(idtest);
-                                       allqueue(REDRAWVIEW3D, 0);
-                               }
-                               else if(ipo->blocktype==ID_AC) {
-                                       bActionChannel *chan;
-                                       chan = get_hilighted_action_channel ((bAction*)from);
-                                       if (!chan){
-                                               error ("Create an action channel first");
-                                               return;
-                                       }
-                                       chan->ipo=ipo;
-                                       id_us_plus(idtest);
-                                       allqueue(REDRAWNLA, 0);
-                                       allqueue(REDRAWACTION, 0);
-                               }
-                               else if(ipo->blocktype==ID_MA) {
-                                       ( (Material *)from)->ipo= ipo;
-                                       id_us_plus(idtest);
-                                       allqueue(REDRAWBUTSSHADING, 0);
-                               }
-                               else if(ipo->blocktype==ID_TE) {
-                                       ( (Tex *)from)->ipo= ipo;
-                                       id_us_plus(idtest);
-                                       allqueue(REDRAWBUTSSHADING, 0);
-                               }
-                               else if(ipo->blocktype==ID_SEQ) {
-                                       seq= (Sequence *)from;
-                                       if((seq->type & SEQ_EFFECT)||(seq->type == SEQ_SOUND)) {
-                                               id_us_plus(idtest);
-                                               seq->ipo= ipo;
-                                       }
-                               }
-                               else if(ipo->blocktype==ID_CU) {
-                                       ( (Curve *)from)->ipo= ipo;
-                                       id_us_plus(idtest);
-                                       allqueue(REDRAWVIEW3D, 0);
-                               }
-                               else if(ipo->blocktype==ID_KE) {
-                                       ( (Key *)from)->ipo= ipo;
-                                       
-                                       id_us_plus(idtest);
-                                       allqueue(REDRAWVIEW3D, 0);
-                                       
-                               }
-                               else if(ipo->blocktype==ID_WO) {
-                                       ( (World *)from)->ipo= ipo;
-                                       id_us_plus(idtest);
-                                       allqueue(REDRAWBUTSSHADING, 0);
-                               }
-                               else if(ipo->blocktype==ID_LA) {
-                                       ( (Lamp *)from)->ipo= ipo;
-                                       id_us_plus(idtest);
-                                       allqueue(REDRAWBUTSSHADING, 0);
-                               }
-                               else if(ipo->blocktype==ID_CA) {
-                                       ( (Camera *)from)->ipo= ipo;
-                                       id_us_plus(idtest);
-                                       allqueue(REDRAWBUTSEDIT, 0);
-                               }
-                               else if(ipo->blocktype==ID_SO) {
-                                       ( (bSound *)from)->ipo= ipo;
-                                       id_us_plus(idtest);
-                                       allqueue(REDRAWBUTSEDIT, 0);
-                               }
-                               else
-                                       printf("error in browse ipo \n");
-                               
-                               if(id) id->us--;
+                               spaceipo_assign_ipo(G.sipo, (Ipo *)idtest);
                                
                                BIF_undo_push("Browse Ipo");
-                               scrarea_queue_winredraw(curarea);
-                               scrarea_queue_headredraw(curarea);
-                               allqueue(REDRAWIPO, 0);
                        }
                }
                break;
        case B_IPODELETE:
-               ipo= get_ipo_to_edit(&from);
-               if(from==0) return;
-               
-               ipo->id.us--;
+               ipo= G.sipo->ipo;
+               from= G.sipo->from;
                
-               if(ipo->blocktype==ID_OB) ( (Object *)from)->ipo= 0;
-               else if(ipo->blocktype==ID_MA) ( (Material *)from)->ipo= 0;
-               else if(ipo->blocktype==ID_TE) ( (Tex *)from)->ipo= 0;
-               else if(ipo->blocktype==ID_SEQ) ( (Sequence *)from)->ipo= 0;
-               else if(ipo->blocktype==ID_CU) ( (Curve *)from)->ipo= 0;
-               else if(ipo->blocktype==ID_KE) ( (Key *)from)->ipo= 0;
-               else if(ipo->blocktype==ID_WO) ( (World *)from)->ipo= 0;
-               else if(ipo->blocktype==ID_LA) ( (Lamp *)from)->ipo= 0;
-               else if(ipo->blocktype==ID_WO) ( (World *)from)->ipo= 0;
-               else if(ipo->blocktype==ID_CA) ( (Camera *)from)->ipo= 0;
-               else if(ipo->blocktype==ID_SO) ( (bSound *)from)->ipo= 0;
-               else if(ipo->blocktype==ID_AC) {
-                       bAction *act = (bAction*) from;
-                       bActionChannel *chan = 
-                               get_hilighted_action_channel((bAction*)from);
-                       BLI_freelinkN (&act->chanbase, chan);
-               }
-               else if(ipo->blocktype==IPO_CO) ((Object *)from)->activecon->ipo= 0;
-
-               else error("Warn bugtracker!");
+               spaceipo_assign_ipo(G.sipo, NULL);
                
                editipo_changed(G.sipo, 1); /* doredraw */
+               
                BIF_undo_push("Unlink Ipo");
-               allqueue(REDRAWIPO, 0);
-               allqueue(REDRAWNLA, 0);
-               allqueue (REDRAWACTION, 0);
                
                break;
        case B_WORLDBROWSE:
@@ -1219,13 +1180,13 @@ void do_global_buttons(unsigned short event)
                        allqueue(REDRAWBUTSSHADING, 0);
                        allqueue(REDRAWIPO, 0);
                        allqueue(REDRAWOOPS, 0);
-                       BIF_preview_changed(G.buts);
+                       BIF_preview_changed(ID_WO);
                }
                break;
        case B_WORLDDELETE:
                if(G.scene->world) {
                        G.scene->world->id.us--;
-                       G.scene->world= 0;
+                       G.scene->world= NULL;
 
                        BIF_undo_push("Unlink World");
                        allqueue(REDRAWBUTSSHADING, 0);
@@ -1236,7 +1197,7 @@ void do_global_buttons(unsigned short event)
        case B_WTEXBROWSE:
 
                if(G.buts->texnr== -2) {
-                       id= 0;
+                       id= NULL;
                        wrld= G.scene->world;
                        if(wrld) {
                                mtex= wrld->mtex[ wrld->texact ];
@@ -1252,7 +1213,7 @@ void do_global_buttons(unsigned short event)
                        
                }
                else {
-                       id= 0;
+                       id= NULL;
                        
                        wrld= G.scene->world;
                        if(wrld) {
@@ -1287,7 +1248,7 @@ void do_global_buttons(unsigned short event)
                                allqueue(REDRAWBUTSSHADING, 0);
                                allqueue(REDRAWIPO, 0);
                                allqueue(REDRAWOOPS, 0);
-                               BIF_preview_changed(G.buts);
+                               BIF_preview_changed(ID_WO);
                        }
                }
                break;
@@ -1327,7 +1288,7 @@ void do_global_buttons(unsigned short event)
                        allqueue(REDRAWVIEW3D, 0);
                        allqueue(REDRAWIPO, 0);
                        allqueue(REDRAWOOPS, 0);
-                       BIF_preview_changed(G.buts);
+                       BIF_preview_changed(ID_LA);
                }
                break;
        
@@ -1337,7 +1298,7 @@ void do_global_buttons(unsigned short event)
                if(ob->type!=OB_LAMP) return;
 
                if(G.buts->texnr== -2) {
-                       id= 0;
+                       id= NULL;
                        la= ob->data;
                        mtex= la->mtex[ la->texact ];
                        if(mtex) id= (ID *)mtex->tex;
@@ -1351,7 +1312,7 @@ void do_global_buttons(unsigned short event)
                        
                }
                else {
-                       id= 0;
+                       id= NULL;
                        
                        la= ob->data;
                        mtex= la->mtex[ la->texact ];
@@ -1384,23 +1345,39 @@ void do_global_buttons(unsigned short event)
                                allqueue(REDRAWBUTSSHADING, 0);
                                allqueue(REDRAWIPO, 0);
                                allqueue(REDRAWOOPS, 0);
-                               BIF_preview_changed(G.buts);
+                               BIF_preview_changed(ID_LA);
                        }
                }
                break;
-       
+
        case B_IMAGEDELETE:
-               G.sima->image= 0;
-               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:
-               automatname(G.buts->lockpoin);
+               /* this is called now from Node editor too, buttons might not exist */
+               if(curarea->spacetype==SPACE_NODE) {
+                       SpaceNode *snode= curarea->spacedata.first;
+                       automatname((Material *)snode->id);
+               }
+               else if(G.buts) {
+                       automatname(G.buts->lockpoin);
+               }
+               else return;
 
                BIF_undo_push("Auto name");
                allqueue(REDRAWBUTSSHADING, 0);
+               allqueue(REDRAWNODE, 0);
                allqueue(REDRAWOOPS, 0);
                break;          
        case B_AUTOTEXNAME:
@@ -1423,6 +1400,17 @@ void do_global_buttons(unsigned short event)
                        BIF_undo_push("Auto name");
                        allqueue(REDRAWBUTSSHADING, 0);
                        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;
 
@@ -1440,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();
@@ -1455,11 +1449,16 @@ void do_global_buttons(unsigned short event)
                allqueue(REDRAWVIEW3D, 0);
                break;
 
+       case B_PLAINMENUS:     /* is button from space.c  *info* */
+               reset_toolbox();
+               break;
+
        case B_FLIPINFOMENU:    /* is button from space.c  *info* */
                scrarea_queue_headredraw(curarea);
                break;
 
-#ifdef _WIN32 // FULLSCREEN
+#if 0
+//#ifdef _WIN32 // FULLSCREEN
        case B_FLIPFULLSCREEN:
                if(U.uiflag & USER_FLIPFULLSCREEN)
                        U.uiflag &= ~USER_FLIPFULLSCREEN;
@@ -1527,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) {
@@ -1592,11 +1594,6 @@ void do_global_buttons(unsigned short event)
                break;
                
        case B_USETEXTUREFONT:          /* is button from space.c  *info* */
-               if(U.transopts & USER_USETEXTUREFONT)
-                       FTF_SetMode(FTF_TEXTUREFONT);
-               else
-                       FTF_SetMode(FTF_PIXMAPFONT);
-
                refresh_interface_font();
                allqueue(REDRAWALL, 0);
                break;
@@ -1621,17 +1618,21 @@ void do_global_buttons(unsigned short event)
                         * can require it to be updated because its
                         * basis might have changed... -zr
                         */
-               if (OBACT && OBACT->type==OB_MBALL)
-                       makeDispList(OBACT);
-                       
+               if (ob && ob->type==OB_MBALL) {
+                       DAG_scene_sort(G.scene);
+                       DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
+               }
                /* redraw because name has changed: new pup */
                scrarea_queue_headredraw(curarea);
                allqueue(REDRAWINFO, 1);
                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:
@@ -1642,15 +1643,17 @@ void do_global_buttons(unsigned short event)
                        id= (ID *)G.buts->lockpoin;
                } else if(curarea->spacetype==SPACE_IPO) {
                        id = (ID *)G.sipo->ipo;
-               } /* similar for other spacetypes ? */
+               } else if(curarea->spacetype==SPACE_NODE) {
+                       id = ((SpaceNode *)curarea->spacedata.first)->id;
+               } 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);
 
@@ -1675,6 +1678,7 @@ void do_global_buttons2(short event)
        World *wrld;
        ID *idfrom; 
        bAction *act;
+       Brush *br;
 
        /* general:  Single User is allowed when from==LOCAL 
         *                       Make Local is allowed when (from==LOCAL && id==LIB)
@@ -1724,6 +1728,7 @@ void do_global_buttons2(short event)
                        if(arm->id.us>1) {
                                if(okee("Single user")) {
                                        ob->data= copy_armature(arm);
+                                       armature_rebuild_pose(ob, ob->data);
                                        arm->id.us--;
                                }
                        }
@@ -1735,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);
                                }
                        }
                }
@@ -1743,13 +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);
-                                       ob->activecon=NULL;
                                        act->id.us--;
                                        allqueue(REDRAWACTION, 0);
+                                       allqueue(REDRAWBUTSEDIT, 0);
                                }
                        }
                }
@@ -1850,6 +1856,8 @@ void do_global_buttons2(short event)
                                if(okee("Make local")) {
                                        make_local_mesh(me);
                                        make_local_key( me->key );
+
+                                       DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);                           
                                }
                        }
                }
@@ -1885,7 +1893,7 @@ void do_global_buttons2(short event)
                                if(okee("Single user")) {
                                        ob->data= copy_curve(cu);
                                        cu->id.us--;
-                                       makeDispList(ob);
+                                       DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
                                        if(ob==G.obedit) allqueue(REDRAWVIEW3D, 0);
                                }
                        }
@@ -1898,7 +1906,7 @@ void do_global_buttons2(short event)
                                if(okee("Make local")) {
                                        make_local_curve(cu);
                                        make_local_key( cu->key );
-                                       makeDispList(ob);
+                                       DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
                                }
                        }
                }
@@ -1908,6 +1916,7 @@ void do_global_buttons2(short event)
                if(G.buts->texfrom==0) {        /* from mat */
                        if(ob==0) return;
                        ma= give_current_material(ob, ob->actcol);
+                       ma= editnode_get_active_material(ma);
                        if(ma && ma->id.lib==0) {
                                mtex= ma->mtex[ ma->texact ];
                                if(mtex->tex && mtex->tex->id.us>1) {
@@ -1943,11 +1952,26 @@ void do_global_buttons2(short event)
                                }
                        }
                }
+               else if(G.buts->texfrom==3) { /* from brush */
+                       br= G.scene->toolsettings->imapaint.brush;
+                       if(br==0) return;
+                       if(br->id.lib==0) {
+                               mtex= br->mtex[ br->texact ];
+                               if(mtex->tex && mtex->tex->id.us>1) {
+                                       if(okee("Single user")) {
+                                               mtex->tex->id.us--;
+                                               mtex->tex= copy_texture(mtex->tex);
+                                               allqueue(REDRAWIMAGE, 0);
+                                       }
+                               }
+                       }
+               }
                break;
        case B_TEXLOCAL:
                if(G.buts->texfrom==0) {        /* from mat */
                        if(ob==0) return;
                        ma= give_current_material(ob, ob->actcol);
+                       ma= editnode_get_active_material(ma);
                        if(ma && ma->id.lib==0) {
                                mtex= ma->mtex[ ma->texact ];
                                if(mtex->tex && mtex->tex->id.lib) {
@@ -1980,36 +2004,39 @@ void do_global_buttons2(short event)
                                }
                        }
                }
+               else if(G.buts->texfrom==3) { /* from brush */
+                       br= G.scene->toolsettings->imapaint.brush;
+                       if(br==0) return;
+                       if(br->id.lib==0) {
+                               mtex= br->mtex[ br->texact ];
+                               if(mtex->tex && mtex->tex->id.lib) {
+                                       if(okee("Make local")) {
+                                               make_local_texture(mtex->tex);
+                                               allqueue(REDRAWIMAGE, 0);
+                                       }
+                               }
+                       }
+               }
                break;
        
        case B_IPOALONE:
-               ipo= get_ipo_to_edit(&idfrom);
+               ipo= G.sipo->ipo;
+               idfrom= G.sipo->from;
                
-               if(idfrom && idfrom->lib==0) {
+               if(idfrom && idfrom->lib==NULL) {
                        if(ipo->id.us>1) {
                                if(okee("Single user")) {
-                                       if(ipo->blocktype==ID_OB) ((Object *)idfrom)->ipo= copy_ipo(ipo);
-                                       else if(ipo->blocktype==ID_MA) ((Material *)idfrom)->ipo= copy_ipo(ipo);
-                                       else if(ipo->blocktype==ID_TE) ((Tex *)idfrom)->ipo= copy_ipo(ipo);
-                                       else if(ipo->blocktype==ID_SEQ) ((Sequence *)idfrom)->ipo= copy_ipo(ipo);
-                                       else if(ipo->blocktype==ID_CU) ((Curve *)idfrom)->ipo= copy_ipo(ipo);
-                                       else if(ipo->blocktype==ID_KE) ((Key *)idfrom)->ipo= copy_ipo(ipo);
-                                       else if(ipo->blocktype==ID_LA) ((Lamp *)idfrom)->ipo= copy_ipo(ipo);
-                                       else if(ipo->blocktype==ID_WO) ((World *)idfrom)->ipo= copy_ipo(ipo);
-                                       else if(ipo->blocktype==ID_CA) ((Camera *)idfrom)->ipo= copy_ipo(ipo);
-                                       else if(ipo->blocktype==ID_SO) ((bSound *)idfrom)->ipo= copy_ipo(ipo);
-                                       else if(ipo->blocktype==ID_AC) get_hilighted_action_channel((bAction *)idfrom)->ipo= copy_ipo(ipo);
-                                       else if(ipo->blocktype==IPO_CO) ((Object *)idfrom)->activecon->ipo= copy_ipo(ipo);
-                                       else error("Warn ton!");
-                                       
-                                       ipo->id.us--;
+                                       ipo= copy_ipo(ipo);
+                                       ipo->id.us= 0;  /* assign_ipo adds users, copy_ipo sets to 1 */
+                                       spaceipo_assign_ipo(G.sipo, ipo);
                                        allqueue(REDRAWIPO, 0);
                                }
                        }
                }
                break;
        case B_IPOLOCAL:
-               ipo= get_ipo_to_edit(&idfrom);
+               ipo= G.sipo->ipo;
+               idfrom= G.sipo->from;
                
                if(idfrom && idfrom->lib==0) {
                        if(ipo->id.lib) {
@@ -2061,6 +2088,8 @@ void do_global_buttons2(short event)
                                        
                                        set_mesh(ob, men);
                                        
+                                       DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
+                                       
                                        if(ob==G.obedit) allqueue(REDRAWVIEW3D, 0);
                                }
                        }
@@ -2092,7 +2121,10 @@ void do_headerbuttons(short event)
        else if(event<600) do_file_buttons(event);
        else if(event<650) do_seq_buttons(event);
        else if(event<700) do_sound_buttons(event);
-       else if(event<800) do_action_buttons(event);
-       else if(event<900) do_nla_buttons(event);
+       else if(event<750) do_action_buttons(event);
+       else if(event<800) do_time_buttons(curarea, event);
+       else if(event<850) do_nla_buttons(event);
+       else if(event<900) do_node_buttons(curarea, event);
+       else if(event>=REDRAWVIEW3D) allqueue(event, 0);
 }