2008-12-14 11:25:00 +00:00
/**
* $ Id $
*
* * * * * * 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 .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software Foundation ,
* Inc . , 59 Temple Place - Suite 330 , Boston , MA 02111 - 1307 , USA .
*
* The Original Code is Copyright ( C ) 2008 Blender Foundation .
* All rights reserved .
*
*
* Contributor ( s ) : Blender Foundation
*
* * * * * * END GPL LICENSE BLOCK * * * * *
*/
# include <string.h>
# include <stdio.h>
# include "DNA_space_types.h"
# include "DNA_scene_types.h"
# include "DNA_screen_types.h"
# include "DNA_windowmanager_types.h"
# include "MEM_guardedalloc.h"
# include "BLI_blenlib.h"
2008-12-18 02:56:48 +00:00
# include "BKE_context.h"
2008-12-14 11:25:00 +00:00
# include "BKE_screen.h"
2009-01-06 14:42:54 +00:00
# include "BKE_global.h"
2008-12-14 11:25:00 +00:00
# include "ED_screen.h"
2008-12-19 12:48:30 +00:00
# include "ED_types.h"
2008-12-14 11:25:00 +00:00
# include "ED_util.h"
2009-01-06 14:42:54 +00:00
# include "ED_fileselect.h"
2008-12-14 11:25:00 +00:00
# include "WM_api.h"
# include "WM_types.h"
# include "BIF_gl.h"
# include "BIF_glutil.h"
# include "UI_interface.h"
# include "UI_resources.h"
# include "UI_view2d.h"
2009-01-06 16:47:01 +00:00
# include "UI_text.h"
2008-12-14 11:25:00 +00:00
2008-12-14 12:16:55 +00:00
# include "file_intern.h"
2009-01-06 14:42:54 +00:00
# include "filelist.h"
# define B_SORTIMASELLIST 1
# define B_RELOADIMASELDIR 2
2008-12-14 12:16:55 +00:00
2008-12-14 11:25:00 +00:00
/* ************************ header area region *********************** */
static void do_viewmenu ( bContext * C , void * arg , int event )
{
}
2.5: UI & Menus
* Cleaned up UI_interface.h a bit, and added some comments to
organize things a bit and indicate what should be used when.
* uiMenu* functions can now be used to create menus for headers
too, this is done with a uiDefMenuBut, which takes a pointer
to a uiMenuCreateFunc, that will then call uiMenu* functions.
* Renamed uiMenuBegin/End to uiPupMenuBegin/End, as these are
specific to making popup menus. Will convert the other
conformation popup menu functions to use this too so we can
remove some code.
* Extended uiMenu functions, now there is is also:
BooleanO, FloatO, BooleanR, EnumR, LevelEnumR, Separator.
* Converted image window headers to use uiMenu functions, simplifies
menu code further here. Did not remove the uiDefMenu functions as
they are used in sequencer/view3d in some places now (will fix).
* Also tried to simplify and fix bounds computation a bit better
for popup menus. It tried to find out in advance what the size
of the menu was but this is difficult with keymap strings in
there, now uiPopupBoundsBlock can figure this out afterwards and
ensure the popup is within the window bounds. Will convert some
other functions to use this too.
2009-01-30 12:18:08 +00:00
static uiBlock * dummy_viewmenu ( bContext * C , ARegion * ar , void * arg_unused )
2008-12-14 11:25:00 +00:00
{
2008-12-18 02:56:48 +00:00
ScrArea * curarea = CTX_wm_area ( C ) ;
2008-12-14 11:25:00 +00:00
uiBlock * block ;
short yco = 0 , menuwidth = 120 ;
2.5: UI & Menus
* Cleaned up UI_interface.h a bit, and added some comments to
organize things a bit and indicate what should be used when.
* uiMenu* functions can now be used to create menus for headers
too, this is done with a uiDefMenuBut, which takes a pointer
to a uiMenuCreateFunc, that will then call uiMenu* functions.
* Renamed uiMenuBegin/End to uiPupMenuBegin/End, as these are
specific to making popup menus. Will convert the other
conformation popup menu functions to use this too so we can
remove some code.
* Extended uiMenu functions, now there is is also:
BooleanO, FloatO, BooleanR, EnumR, LevelEnumR, Separator.
* Converted image window headers to use uiMenu functions, simplifies
menu code further here. Did not remove the uiDefMenu functions as
they are used in sequencer/view3d in some places now (will fix).
* Also tried to simplify and fix bounds computation a bit better
for popup menus. It tried to find out in advance what the size
of the menu was but this is difficult with keymap strings in
there, now uiPopupBoundsBlock can figure this out afterwards and
ensure the popup is within the window bounds. Will convert some
other functions to use this too.
2009-01-30 12:18:08 +00:00
block = uiBeginBlock ( C , ar , " dummy_viewmenu " , UI_EMBOSSP , UI_HELV ) ;
2008-12-14 11:25:00 +00:00
uiBlockSetButmFunc ( block , do_viewmenu , NULL ) ;
uiDefIconTextBut ( block , BUTM , 1 , ICON_BLANK1 , " Nothing yet " , 0 , yco - = 20 ,
menuwidth , 19 , NULL , 0.0 , 0.0 , 1 , 3 , " " ) ;
if ( curarea - > headertype = = HEADERTOP ) {
uiBlockSetDirection ( block , UI_DOWN ) ;
}
else {
uiBlockSetDirection ( block , UI_TOP ) ;
uiBlockFlipOrder ( block ) ;
}
uiTextBoundsBlock ( block , 50 ) ;
uiEndBlock ( C , block ) ;
return block ;
}
2009-01-06 14:42:54 +00:00
static void do_file_header_buttons ( bContext * C , void * arg , int event )
2008-12-14 11:25:00 +00:00
{
2009-01-06 14:42:54 +00:00
SpaceFile * sfile = ( SpaceFile * ) CTX_wm_space_data ( C ) ;
2008-12-14 11:25:00 +00:00
switch ( event ) {
2009-01-06 14:42:54 +00:00
case B_SORTIMASELLIST :
2009-01-06 19:22:29 +00:00
filelist_sort ( sfile - > files , sfile - > params - > sort ) ;
2009-01-06 14:42:54 +00:00
WM_event_add_notifier ( C , NC_WINDOW , NULL ) ;
break ;
case B_RELOADIMASELDIR :
WM_event_add_notifier ( C , NC_WINDOW , NULL ) ;
break ;
2008-12-14 12:16:55 +00:00
}
2008-12-14 11:25:00 +00:00
}
void file_header_buttons ( const bContext * C , ARegion * ar )
{
2009-01-06 14:42:54 +00:00
SpaceFile * sfile = ( SpaceFile * ) CTX_wm_space_data ( C ) ;
2009-01-08 18:47:16 +00:00
FileSelectParams * params = ED_fileselect_get_params ( sfile ) ;
2009-01-06 14:42:54 +00:00
2008-12-14 11:25:00 +00:00
uiBlock * block ;
2008-12-14 12:16:55 +00:00
int xco , yco = 3 ;
2009-01-06 14:42:54 +00:00
int xcotitle ;
2008-12-14 11:25:00 +00:00
block = uiBeginBlock ( C , ar , " header buttons " , UI_EMBOSS , UI_HELV ) ;
2009-01-06 14:42:54 +00:00
uiBlockSetHandleFunc ( block , do_file_header_buttons , NULL ) ;
2008-12-14 11:25:00 +00:00
2008-12-14 12:16:55 +00:00
xco = ED_area_header_standardbuttons ( C , block , yco ) ;
2008-12-14 11:25:00 +00:00
2009-03-09 08:31:45 +00:00
/*
2008-12-14 11:25:00 +00:00
if ( ( sa - > flag & HEADER_NO_PULLDOWN ) = = 0 ) {
int xmax ;
uiBlockSetEmboss ( block , UI_EMBOSSP ) ;
xmax = GetButStringLength ( " View " ) ;
2008-12-18 02:56:48 +00:00
uiDefPulldownBut ( block , dummy_viewmenu , CTX_wm_area ( C ) ,
2008-12-14 11:25:00 +00:00
" View " , xco , yco - 2 , xmax - 3 , 24 , " " ) ;
xco + = XIC + xmax ;
}
2009-03-09 08:31:45 +00:00
*/
2008-12-14 11:25:00 +00:00
2009-01-06 14:42:54 +00:00
/* SORT TYPE */
2009-03-03 13:15:40 +00:00
uiBlockSetEmboss ( block , UI_EMBOSSX ) ;
2009-03-09 08:31:45 +00:00
xco + = 5 ;
2009-03-12 06:40:03 +00:00
uiBlockBeginAlign ( block ) ;
uiDefIconButO ( block , BUT , " FILE_OT_parent " , WM_OP_INVOKE_DEFAULT , ICON_FILE_PARENT , xco + = XIC , yco , 20 , 20 , " Navigate to Parent Folder " ) ;
uiDefIconButO ( block , BUT , " FILE_OT_refresh " , WM_OP_INVOKE_DEFAULT , ICON_FILE_REFRESH , xco + = XIC , yco , 20 , 20 , " Refresh List of Files " ) ;
uiBlockEndAlign ( block ) ;
xco + = 5 ;
2009-03-09 08:31:45 +00:00
if ( sfile - > params - > type ! = FILE_MAIN ) {
uiBlockBeginAlign ( block ) ;
2009-03-09 09:15:23 +00:00
uiDefIconButS ( block , ROW , B_RELOADIMASELDIR , ICON_SHORTDISPLAY , xco + = XIC , yco , XIC , YIC , & params - > display , 1.0 , FILE_SHORTDISPLAY , 0 , 0 , " Displays short file description " ) ;
uiDefIconButS ( block , ROW , B_RELOADIMASELDIR , ICON_LONGDISPLAY , xco + = XIC , yco , XIC , YIC , & params - > display , 1.0 , FILE_LONGDISPLAY , 0 , 0 , " Displays long file description " ) ;
uiDefIconButS ( block , ROW , B_RELOADIMASELDIR , ICON_IMGDISPLAY , xco + = XIC , yco , XIC , YIC , & params - > display , 1.0 , FILE_IMGDISPLAY , 0 , 0 , " Displays files as thumbnails " ) ;
2009-03-09 08:31:45 +00:00
uiBlockEndAlign ( block ) ;
xco + = XIC ;
}
2009-01-06 14:42:54 +00:00
uiBlockBeginAlign ( block ) ;
2009-03-09 08:31:45 +00:00
uiDefIconButS ( block , ROW , B_SORTIMASELLIST , ICON_SORTALPHA , xco + = XIC , yco , XIC , YIC , & params - > sort , 1.0 , 0.0 , 0 , 0 , " Sorts files alphabetically " ) ;
uiDefIconButS ( block , ROW , B_SORTIMASELLIST , ICON_SORTBYEXT , xco + = XIC , yco , XIC , YIC , & params - > sort , 1.0 , 3.0 , 0 , 0 , " Sorts files by extension " ) ;
uiDefIconButS ( block , ROW , B_SORTIMASELLIST , ICON_SORTTIME , xco + = XIC , yco , XIC , YIC , & params - > sort , 1.0 , 1.0 , 0 , 0 , " Sorts files by time " ) ;
uiDefIconButS ( block , ROW , B_SORTIMASELLIST , ICON_SORTSIZE , xco + = XIC , yco , XIC , YIC , & params - > sort , 1.0 , 2.0 , 0 , 0 , " Sorts files by size " ) ;
2009-01-06 14:42:54 +00:00
uiBlockEndAlign ( block ) ;
2009-03-09 08:31:45 +00:00
xco + = XIC ;
2009-01-06 14:42:54 +00:00
2009-03-09 08:31:45 +00:00
/* replace with consistent sub-region collapsing
2009-01-06 14:42:54 +00:00
if ( sfile - > params - > type ! = FILE_MAIN ) {
2009-03-08 13:14:12 +00:00
uiBlockBeginAlign ( block ) ;
// uiDefIconButBitS(block, TOG, FILE_BOOKMARKS, B_RELOADIMASELDIR, ICON_BOOKMARKS,xco+=XIC,0,XIC,YIC, ¶ms->flag, 0, 0, 0, 0, "Toggles Bookmarks on/off");
2009-03-09 08:31:45 +00:00
uiDefIconButO ( block , TOG , " FILE_OT_bookmark_toggle " , WM_OP_INVOKE_DEFAULT , ICON_BOOKMARKS , xco + XIC , yco , 20 , 20 , " Toggle Bookmarks " ) ;
2009-03-08 13:14:12 +00:00
uiBlockEndAlign ( block ) ;
2009-03-09 08:31:45 +00:00
xco + = XIC ;
}
*/
2009-03-03 13:15:40 +00:00
2009-01-06 14:42:54 +00:00
xcotitle = xco ;
2009-01-06 16:47:01 +00:00
xco + = UI_GetStringWidth ( G . font , params - > title , 0 ) ;
2009-01-06 14:42:54 +00:00
2008-12-14 11:25:00 +00:00
uiBlockSetEmboss ( block , UI_EMBOSS ) ;
/* always as last */
2008-12-15 13:23:55 +00:00
UI_view2d_totRect_set ( & ar - > v2d , xco + XIC + 80 , ar - > v2d . tot . ymax - ar - > v2d . tot . ymin ) ;
2008-12-14 11:25:00 +00:00
uiEndBlock ( C , block ) ;
2008-12-26 13:11:04 +00:00
uiDrawBlock ( C , block ) ;
2008-12-14 11:25:00 +00:00
}
2009-01-06 14:42:54 +00:00