2009-06-07 13:36:12 +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,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2009-06-07 13:36:12 +00:00
|
|
|
*
|
|
|
|
|
* The Original Code is Copyright (C) 2009 Blender Foundation.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Contributor(s): Blender Foundation
|
|
|
|
|
*
|
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
2009-07-23 20:40:51 +00:00
|
|
|
#include "DNA_screen_types.h"
|
|
|
|
|
#include "DNA_space_types.h"
|
2009-06-07 13:36:12 +00:00
|
|
|
|
|
|
|
|
#include "BKE_context.h"
|
|
|
|
|
|
|
|
|
|
#include "WM_api.h"
|
|
|
|
|
#include "WM_types.h"
|
|
|
|
|
|
2009-07-14 20:27:28 +00:00
|
|
|
#include "RNA_access.h"
|
|
|
|
|
#include "RNA_define.h"
|
|
|
|
|
|
2009-07-23 20:40:51 +00:00
|
|
|
#include "UI_interface.h"
|
2009-07-28 18:51:06 +00:00
|
|
|
#include "UI_resources.h"
|
2009-07-23 20:40:51 +00:00
|
|
|
|
2009-06-07 13:36:12 +00:00
|
|
|
#include "buttons_intern.h" // own include
|
|
|
|
|
|
2009-07-23 20:40:51 +00:00
|
|
|
/********************** toolbox operator *********************/
|
|
|
|
|
|
|
|
|
|
static int toolbox_invoke(bContext *C, wmOperator *op, wmEvent *event)
|
|
|
|
|
{
|
|
|
|
|
bScreen *sc= CTX_wm_screen(C);
|
2009-07-28 16:33:02 +00:00
|
|
|
SpaceButs *sbuts= CTX_wm_space_buts(C);
|
2009-07-23 20:40:51 +00:00
|
|
|
PointerRNA ptr;
|
|
|
|
|
uiPopupMenu *pup;
|
|
|
|
|
uiLayout *layout;
|
|
|
|
|
|
2009-08-18 12:58:51 +00:00
|
|
|
RNA_pointer_create(&sc->id, &RNA_SpaceProperties, sbuts, &ptr);
|
2009-07-23 20:40:51 +00:00
|
|
|
|
|
|
|
|
pup= uiPupMenuBegin(C, "Align", 0);
|
|
|
|
|
layout= uiPupMenuLayout(pup);
|
|
|
|
|
uiItemsEnumR(layout, &ptr, "align");
|
|
|
|
|
uiPupMenuEnd(C, pup);
|
|
|
|
|
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BUTTONS_OT_toolbox(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
|
|
|
|
ot->name= "Toolbox";
|
2009-10-07 12:19:47 +00:00
|
|
|
ot->description="Display button panel toolbox";
|
2009-07-23 20:40:51 +00:00
|
|
|
ot->idname= "BUTTONS_OT_toolbox";
|
|
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
|
ot->invoke= toolbox_invoke;
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-28 18:51:06 +00:00
|
|
|
/********************** filebrowse operator *********************/
|
|
|
|
|
|
|
|
|
|
typedef struct FileBrowseOp {
|
|
|
|
|
PointerRNA ptr;
|
|
|
|
|
PropertyRNA *prop;
|
|
|
|
|
} FileBrowseOp;
|
|
|
|
|
|
|
|
|
|
static int file_browse_exec(bContext *C, wmOperator *op)
|
|
|
|
|
{
|
|
|
|
|
FileBrowseOp *fbo= op->customdata;
|
|
|
|
|
char *str;
|
|
|
|
|
|
2009-09-12 19:54:39 +00:00
|
|
|
if (RNA_property_is_set(op->ptr, "path")==0 || fbo==NULL)
|
2009-09-04 08:49:11 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
|
2009-09-12 19:54:39 +00:00
|
|
|
str= RNA_string_get_alloc(op->ptr, "path", 0, 0);
|
2009-07-28 18:51:06 +00:00
|
|
|
RNA_property_string_set(&fbo->ptr, fbo->prop, str);
|
|
|
|
|
RNA_property_update(C, &fbo->ptr, fbo->prop);
|
|
|
|
|
MEM_freeN(str);
|
|
|
|
|
|
|
|
|
|
MEM_freeN(op->customdata);
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int file_browse_cancel(bContext *C, wmOperator *op)
|
|
|
|
|
{
|
|
|
|
|
MEM_freeN(op->customdata);
|
|
|
|
|
op->customdata= NULL;
|
|
|
|
|
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int file_browse_invoke(bContext *C, wmOperator *op, wmEvent *event)
|
|
|
|
|
{
|
|
|
|
|
PointerRNA ptr;
|
|
|
|
|
PropertyRNA *prop;
|
|
|
|
|
FileBrowseOp *fbo;
|
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
|
|
uiFileBrowseContextProperty(C, &ptr, &prop);
|
|
|
|
|
|
|
|
|
|
if(!prop)
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
|
|
|
|
|
fbo= MEM_callocN(sizeof(FileBrowseOp), "FileBrowseOp");
|
|
|
|
|
fbo->ptr= ptr;
|
|
|
|
|
fbo->prop= prop;
|
|
|
|
|
op->customdata= fbo;
|
|
|
|
|
|
|
|
|
|
str= RNA_property_string_get_alloc(&ptr, prop, 0, 0);
|
2009-09-20 15:30:52 +00:00
|
|
|
RNA_string_set(op->ptr, "path", str);
|
2009-07-28 18:51:06 +00:00
|
|
|
MEM_freeN(str);
|
|
|
|
|
|
|
|
|
|
WM_event_add_fileselect(C, op);
|
|
|
|
|
|
|
|
|
|
return OPERATOR_RUNNING_MODAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BUTTONS_OT_file_browse(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
|
|
|
|
ot->name= "File Browse";
|
2010-02-10 21:15:44 +00:00
|
|
|
ot->description="Open a file browser";
|
2009-10-07 12:19:47 +00:00
|
|
|
ot->idname= "BUTTONS_OT_file_browse";
|
2009-07-28 18:51:06 +00:00
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
|
ot->invoke= file_browse_invoke;
|
|
|
|
|
ot->exec= file_browse_exec;
|
|
|
|
|
ot->cancel= file_browse_cancel;
|
|
|
|
|
|
|
|
|
|
/* properties */
|
2010-01-31 23:07:32 +00:00
|
|
|
WM_operator_properties_filesel(ot, 0, FILE_SPECIAL, FILE_OPENFILE);
|
2009-07-28 18:51:06 +00:00
|
|
|
}
|
|
|
|
|
|