2009-01-06 14:42:54 +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): Andrea Weikert (c) 2008 Blender Foundation
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "BKE_context.h"
|
|
|
|
#include "BKE_screen.h"
|
|
|
|
#include "BKE_global.h"
|
2009-12-07 23:47:37 +00:00
|
|
|
#include "BKE_report.h"
|
2009-01-06 14:42:54 +00:00
|
|
|
|
|
|
|
#include "BLI_blenlib.h"
|
|
|
|
#include "BLI_storage_types.h"
|
|
|
|
#ifdef WIN32
|
|
|
|
#include "BLI_winstuff.h"
|
|
|
|
#endif
|
|
|
|
#include "DNA_space_types.h"
|
|
|
|
#include "DNA_userdef_types.h"
|
|
|
|
|
|
|
|
#include "ED_space_api.h"
|
|
|
|
#include "ED_screen.h"
|
|
|
|
#include "ED_fileselect.h"
|
|
|
|
|
2009-06-29 20:23:40 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
2009-01-21 19:28:28 +00:00
|
|
|
#include "RNA_access.h"
|
|
|
|
#include "RNA_define.h"
|
2009-01-06 14:42:54 +00:00
|
|
|
|
2009-02-14 10:03:24 +00:00
|
|
|
#include "UI_interface.h"
|
2009-01-06 16:15:43 +00:00
|
|
|
#include "UI_view2d.h"
|
|
|
|
|
2009-01-21 19:28:28 +00:00
|
|
|
#include "WM_api.h"
|
|
|
|
#include "WM_types.h"
|
|
|
|
|
2009-01-06 14:42:54 +00:00
|
|
|
#include "file_intern.h"
|
|
|
|
#include "filelist.h"
|
|
|
|
#include "fsmenu.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
/* for events */
|
|
|
|
#define NOTACTIVE 0
|
|
|
|
#define ACTIVATE 1
|
|
|
|
#define INACTIVATE 2
|
|
|
|
|
2009-01-21 19:28:28 +00:00
|
|
|
/* ---------- FILE SELECTION ------------ */
|
2009-01-06 14:42:54 +00:00
|
|
|
|
2009-09-28 12:10:23 +00:00
|
|
|
static int find_file_mouse(SpaceFile *sfile, struct ARegion* ar, int x, int y)
|
2009-01-06 14:42:54 +00:00
|
|
|
{
|
2009-01-21 19:28:28 +00:00
|
|
|
float fx,fy;
|
|
|
|
int active_file = -1;
|
2009-01-06 14:42:54 +00:00
|
|
|
View2D* v2d = &ar->v2d;
|
2009-01-21 19:28:28 +00:00
|
|
|
|
|
|
|
UI_view2d_region_to_view(v2d, x, y, &fx, &fy);
|
|
|
|
|
2009-03-08 13:14:12 +00:00
|
|
|
active_file = ED_fileselect_layout_offset(sfile->layout, v2d->tot.xmin + fx, v2d->tot.ymax - fy);
|
2009-06-09 07:28:15 +00:00
|
|
|
|
2009-01-21 19:28:28 +00:00
|
|
|
return active_file;
|
2009-01-06 14:42:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-21 19:28:28 +00:00
|
|
|
static void file_deselect_all(SpaceFile* sfile)
|
2009-01-06 14:42:54 +00:00
|
|
|
{
|
2009-01-21 19:28:28 +00:00
|
|
|
int numfiles = filelist_numfiles(sfile->files);
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for ( i=0; i < numfiles; ++i) {
|
|
|
|
struct direntry* file = filelist_file(sfile->files, i);
|
|
|
|
if (file && (file->flags & ACTIVE)) {
|
|
|
|
file->flags &= ~ACTIVE;
|
|
|
|
}
|
2009-01-06 14:42:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-26 19:23:07 +00:00
|
|
|
typedef enum FileSelect { FILE_SELECT_DIR = 1,
|
|
|
|
FILE_SELECT_FILE = 2 } FileSelect;
|
|
|
|
|
|
|
|
|
2009-09-20 15:02:14 +00:00
|
|
|
static void clamp_to_filelist(int numfiles, int *first_file, int *last_file)
|
|
|
|
{
|
|
|
|
/* border select before the first file */
|
|
|
|
if ( (*first_file < 0) && (*last_file >=0 ) ) {
|
|
|
|
*first_file = 0;
|
|
|
|
}
|
|
|
|
/* don't select if everything is outside filelist */
|
|
|
|
if ( (*first_file >= numfiles) && ((*last_file < 0) || (*last_file >= numfiles)) ) {
|
|
|
|
*first_file = -1;
|
|
|
|
*last_file = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fix if last file invalid */
|
|
|
|
if ( (*first_file > 0) && (*last_file < 0) )
|
|
|
|
*last_file = numfiles-1;
|
|
|
|
|
|
|
|
/* clamp */
|
|
|
|
if ( (*first_file >= numfiles) ) {
|
|
|
|
*first_file = numfiles-1;
|
|
|
|
}
|
|
|
|
if ( (*last_file >= numfiles) ) {
|
|
|
|
*last_file = numfiles-1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-22 22:23:58 +00:00
|
|
|
static FileSelect file_select(SpaceFile* sfile, ARegion* ar, const rcti* rect, short selecting, short toggle_one)
|
2009-01-06 14:42:54 +00:00
|
|
|
{
|
2009-01-21 19:28:28 +00:00
|
|
|
int first_file = -1;
|
|
|
|
int last_file = -1;
|
|
|
|
int act_file;
|
2009-07-26 19:23:07 +00:00
|
|
|
FileSelect retval = FILE_SELECT_FILE;
|
|
|
|
|
2009-03-14 18:15:28 +00:00
|
|
|
FileSelectParams *params = ED_fileselect_get_params(sfile);
|
2009-06-08 20:08:19 +00:00
|
|
|
// FileLayout *layout = ED_fileselect_get_layout(sfile, ar);
|
2009-01-21 19:28:28 +00:00
|
|
|
|
2009-01-06 19:22:29 +00:00
|
|
|
int numfiles = filelist_numfiles(sfile->files);
|
2009-01-21 19:28:28 +00:00
|
|
|
|
|
|
|
params->selstate = NOTACTIVE;
|
2009-09-20 15:02:14 +00:00
|
|
|
first_file = find_file_mouse(sfile, ar, rect->xmin, rect->ymax);
|
|
|
|
last_file = find_file_mouse(sfile, ar, rect->xmax, rect->ymin);
|
2009-01-21 19:28:28 +00:00
|
|
|
|
2009-09-20 15:02:14 +00:00
|
|
|
clamp_to_filelist(numfiles, &first_file, &last_file);
|
|
|
|
|
2009-01-21 19:28:28 +00:00
|
|
|
/* select all valid files between first and last indicated */
|
|
|
|
if ( (first_file >= 0) && (first_file < numfiles) && (last_file >= 0) && (last_file < numfiles) ) {
|
|
|
|
for (act_file = first_file; act_file <= last_file; act_file++) {
|
|
|
|
struct direntry* file = filelist_file(sfile->files, act_file);
|
2009-11-22 22:23:58 +00:00
|
|
|
|
|
|
|
if (toggle_one) {
|
|
|
|
if (file->flags & ACTIVE) {
|
|
|
|
file->flags &= ~ACTIVE;
|
|
|
|
selecting=0;
|
|
|
|
} else
|
|
|
|
file->flags |= ACTIVE;
|
|
|
|
} else if (selecting)
|
2009-01-21 19:28:28 +00:00
|
|
|
file->flags |= ACTIVE;
|
|
|
|
else
|
|
|
|
file->flags &= ~ACTIVE;
|
|
|
|
}
|
|
|
|
}
|
2009-03-08 13:14:12 +00:00
|
|
|
|
2009-09-20 15:02:14 +00:00
|
|
|
/* Don't act on multiple selected files */
|
|
|
|
if (first_file != last_file) selecting= 0;
|
|
|
|
|
2009-01-21 19:28:28 +00:00
|
|
|
/* make the last file active */
|
2009-06-09 07:28:15 +00:00
|
|
|
if (selecting && (last_file >= 0 && last_file < numfiles)) {
|
2009-01-21 19:28:28 +00:00
|
|
|
struct direntry* file = filelist_file(sfile->files, last_file);
|
|
|
|
params->active_file = last_file;
|
|
|
|
|
|
|
|
if(file && S_ISDIR(file->type)) {
|
2009-07-28 16:46:14 +00:00
|
|
|
/* the path is too long and we are not going up! */
|
|
|
|
if (strcmp(file->relname, "..") && strlen(params->dir) + strlen(file->relname) >= FILE_MAX )
|
2009-01-21 19:28:28 +00:00
|
|
|
{
|
|
|
|
// XXX error("Path too long, cannot enter this directory");
|
2009-01-06 14:42:54 +00:00
|
|
|
} else {
|
2009-07-28 16:46:14 +00:00
|
|
|
if (strcmp(file->relname, "..")==0) {
|
|
|
|
/* avoids /../../ */
|
|
|
|
BLI_parent_dir(params->dir);
|
|
|
|
} else {
|
|
|
|
BLI_cleanup_dir(G.sce, params->dir);
|
|
|
|
strcat(params->dir, file->relname);
|
|
|
|
BLI_add_slash(params->dir);
|
|
|
|
}
|
|
|
|
|
2009-10-15 11:11:52 +00:00
|
|
|
file_change_dir(sfile, 0);
|
2009-07-26 19:23:07 +00:00
|
|
|
retval = FILE_SELECT_DIR;
|
2009-01-21 19:28:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (file)
|
|
|
|
{
|
|
|
|
if (file->relname) {
|
|
|
|
BLI_strncpy(params->file, file->relname, FILE_MAXFILE);
|
2009-01-06 14:42:54 +00:00
|
|
|
}
|
2009-01-21 19:28:28 +00:00
|
|
|
|
|
|
|
}
|
2009-09-20 15:02:14 +00:00
|
|
|
}
|
2009-07-26 19:23:07 +00:00
|
|
|
return retval;
|
2009-01-21 19:28:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int file_border_select_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
ARegion *ar= CTX_wm_region(C);
|
2009-07-28 16:46:14 +00:00
|
|
|
SpaceFile *sfile= CTX_wm_space_file(C);
|
2009-11-06 22:51:08 +00:00
|
|
|
short selecting;
|
2009-01-21 19:28:28 +00:00
|
|
|
rcti rect;
|
|
|
|
|
2009-11-06 22:51:08 +00:00
|
|
|
selecting= (RNA_int_get(op->ptr, "gesture_mode")==GESTURE_MODAL_SELECT);
|
2009-01-21 19:28:28 +00:00
|
|
|
rect.xmin= RNA_int_get(op->ptr, "xmin");
|
|
|
|
rect.ymin= RNA_int_get(op->ptr, "ymin");
|
|
|
|
rect.xmax= RNA_int_get(op->ptr, "xmax");
|
|
|
|
rect.ymax= RNA_int_get(op->ptr, "ymax");
|
|
|
|
|
2009-06-24 17:22:22 +00:00
|
|
|
BLI_isect_rcti(&(ar->v2d.mask), &rect, &rect);
|
2009-06-09 07:28:15 +00:00
|
|
|
|
2009-11-22 22:23:58 +00:00
|
|
|
if (FILE_SELECT_DIR == file_select(sfile, ar, &rect, selecting, 0)) {
|
2.5
Notifiers
---------
Various fixes for wrong use of notifiers, and some new notifiers
to make things a bit more clear and consistent, with two notable
changes:
* Geometry changes are now done with NC_GEOM, rather than
NC_OBJECT|ND_GEOM_, so an object does need to be available.
* Space data now use NC_SPACE|ND_SPACE_*, instead of data
notifiers or even NC_WINDOW in some cases. Note that NC_SPACE
should only be used for notifying about changes in space data,
we don't want to go back to allqueue(REDRAW..).
Depsgraph
---------
The dependency graph now has a different flush call:
DAG_object_flush_update(scene, ob, flag)
is replaced by:
DAG_id_flush_update(id, flag)
It still works basically the same, one difference is that it now
also accepts object data (e.g. Mesh), again to avoid requiring an
Object to be available. Other ID types will simply do nothing at
the moment.
Docs
----
I made some guidelines for how/when to do which kinds of updates
and notifiers. I can't specify totally exact how to make these
decisions, but these are basically the guidelines I use. So, new
and updated docs are here:
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/NotifiersUpdates
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/DataNotifiers
2009-09-04 20:51:09 +00:00
|
|
|
WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_LIST, NULL);
|
2009-07-26 19:23:07 +00:00
|
|
|
} else {
|
2.5
Notifiers
---------
Various fixes for wrong use of notifiers, and some new notifiers
to make things a bit more clear and consistent, with two notable
changes:
* Geometry changes are now done with NC_GEOM, rather than
NC_OBJECT|ND_GEOM_, so an object does need to be available.
* Space data now use NC_SPACE|ND_SPACE_*, instead of data
notifiers or even NC_WINDOW in some cases. Note that NC_SPACE
should only be used for notifying about changes in space data,
we don't want to go back to allqueue(REDRAW..).
Depsgraph
---------
The dependency graph now has a different flush call:
DAG_object_flush_update(scene, ob, flag)
is replaced by:
DAG_id_flush_update(id, flag)
It still works basically the same, one difference is that it now
also accepts object data (e.g. Mesh), again to avoid requiring an
Object to be available. Other ID types will simply do nothing at
the moment.
Docs
----
I made some guidelines for how/when to do which kinds of updates
and notifiers. I can't specify totally exact how to make these
decisions, but these are basically the guidelines I use. So, new
and updated docs are here:
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/NotifiersUpdates
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/DataNotifiers
2009-09-04 20:51:09 +00:00
|
|
|
WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_PARAMS, NULL);
|
2009-07-26 19:23:07 +00:00
|
|
|
}
|
2009-01-21 19:28:28 +00:00
|
|
|
return OPERATOR_FINISHED;
|
2009-01-06 14:42:54 +00:00
|
|
|
}
|
|
|
|
|
2009-03-29 02:15:13 +00:00
|
|
|
void FILE_OT_select_border(wmOperatorType *ot)
|
2009-01-06 14:42:54 +00:00
|
|
|
{
|
2009-01-21 19:28:28 +00:00
|
|
|
/* identifiers */
|
|
|
|
ot->name= "Activate/Select File";
|
2010-02-10 21:15:44 +00:00
|
|
|
ot->description= "Activate/select the file(s) contained in the border";
|
2009-03-29 02:15:13 +00:00
|
|
|
ot->idname= "FILE_OT_select_border";
|
2009-01-21 19:28:28 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
ot->invoke= WM_border_select_invoke;
|
|
|
|
ot->exec= file_border_select_exec;
|
|
|
|
ot->modal= WM_border_select_modal;
|
2009-11-06 22:51:08 +00:00
|
|
|
ot->poll= ED_operator_file_active;
|
2009-01-21 19:28:28 +00:00
|
|
|
|
|
|
|
/* rna */
|
2009-11-06 22:51:08 +00:00
|
|
|
WM_operator_properties_gesture_border(ot, 0);
|
2009-01-06 14:42:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int file_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
|
|
|
|
{
|
|
|
|
ARegion *ar= CTX_wm_region(C);
|
2009-07-28 16:46:14 +00:00
|
|
|
SpaceFile *sfile= CTX_wm_space_file(C);
|
2009-01-21 19:28:28 +00:00
|
|
|
short val;
|
|
|
|
rcti rect;
|
2009-11-22 22:23:58 +00:00
|
|
|
int extend = RNA_boolean_get(op->ptr, "extend");
|
2009-01-21 19:28:28 +00:00
|
|
|
|
2009-07-28 16:46:14 +00:00
|
|
|
if(ar->regiontype != RGN_TYPE_WINDOW)
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
2009-01-21 19:28:28 +00:00
|
|
|
rect.xmin = rect.xmax = event->x - ar->winrct.xmin;
|
|
|
|
rect.ymin = rect.ymax = event->y - ar->winrct.ymin;
|
|
|
|
val = event->val;
|
|
|
|
|
2009-07-28 16:46:14 +00:00
|
|
|
if(!BLI_in_rcti(&ar->v2d.mask, rect.xmin, rect.ymin))
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
|
|
|
/* single select, deselect all selected first */
|
2009-11-22 22:23:58 +00:00
|
|
|
if (!extend) file_deselect_all(sfile);
|
2009-07-28 16:46:14 +00:00
|
|
|
|
2009-11-22 22:23:58 +00:00
|
|
|
if (FILE_SELECT_DIR == file_select(sfile, ar, &rect, 1, extend ))
|
2.5
Notifiers
---------
Various fixes for wrong use of notifiers, and some new notifiers
to make things a bit more clear and consistent, with two notable
changes:
* Geometry changes are now done with NC_GEOM, rather than
NC_OBJECT|ND_GEOM_, so an object does need to be available.
* Space data now use NC_SPACE|ND_SPACE_*, instead of data
notifiers or even NC_WINDOW in some cases. Note that NC_SPACE
should only be used for notifying about changes in space data,
we don't want to go back to allqueue(REDRAW..).
Depsgraph
---------
The dependency graph now has a different flush call:
DAG_object_flush_update(scene, ob, flag)
is replaced by:
DAG_id_flush_update(id, flag)
It still works basically the same, one difference is that it now
also accepts object data (e.g. Mesh), again to avoid requiring an
Object to be available. Other ID types will simply do nothing at
the moment.
Docs
----
I made some guidelines for how/when to do which kinds of updates
and notifiers. I can't specify totally exact how to make these
decisions, but these are basically the guidelines I use. So, new
and updated docs are here:
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/NotifiersUpdates
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/DataNotifiers
2009-09-04 20:51:09 +00:00
|
|
|
WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_LIST, NULL);
|
2009-07-28 16:46:14 +00:00
|
|
|
else
|
2.5
Notifiers
---------
Various fixes for wrong use of notifiers, and some new notifiers
to make things a bit more clear and consistent, with two notable
changes:
* Geometry changes are now done with NC_GEOM, rather than
NC_OBJECT|ND_GEOM_, so an object does need to be available.
* Space data now use NC_SPACE|ND_SPACE_*, instead of data
notifiers or even NC_WINDOW in some cases. Note that NC_SPACE
should only be used for notifying about changes in space data,
we don't want to go back to allqueue(REDRAW..).
Depsgraph
---------
The dependency graph now has a different flush call:
DAG_object_flush_update(scene, ob, flag)
is replaced by:
DAG_id_flush_update(id, flag)
It still works basically the same, one difference is that it now
also accepts object data (e.g. Mesh), again to avoid requiring an
Object to be available. Other ID types will simply do nothing at
the moment.
Docs
----
I made some guidelines for how/when to do which kinds of updates
and notifiers. I can't specify totally exact how to make these
decisions, but these are basically the guidelines I use. So, new
and updated docs are here:
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/NotifiersUpdates
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/DataNotifiers
2009-09-04 20:51:09 +00:00
|
|
|
WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_PARAMS, NULL);
|
2009-07-28 16:46:14 +00:00
|
|
|
|
|
|
|
WM_event_add_mousemove(C); /* for directory changes */
|
2.5
Notifiers
---------
Various fixes for wrong use of notifiers, and some new notifiers
to make things a bit more clear and consistent, with two notable
changes:
* Geometry changes are now done with NC_GEOM, rather than
NC_OBJECT|ND_GEOM_, so an object does need to be available.
* Space data now use NC_SPACE|ND_SPACE_*, instead of data
notifiers or even NC_WINDOW in some cases. Note that NC_SPACE
should only be used for notifying about changes in space data,
we don't want to go back to allqueue(REDRAW..).
Depsgraph
---------
The dependency graph now has a different flush call:
DAG_object_flush_update(scene, ob, flag)
is replaced by:
DAG_id_flush_update(id, flag)
It still works basically the same, one difference is that it now
also accepts object data (e.g. Mesh), again to avoid requiring an
Object to be available. Other ID types will simply do nothing at
the moment.
Docs
----
I made some guidelines for how/when to do which kinds of updates
and notifiers. I can't specify totally exact how to make these
decisions, but these are basically the guidelines I use. So, new
and updated docs are here:
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/NotifiersUpdates
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/DataNotifiers
2009-09-04 20:51:09 +00:00
|
|
|
WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_PARAMS, NULL);
|
2009-03-10 23:14:41 +00:00
|
|
|
|
2009-01-06 14:42:54 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
2009-02-14 14:25:48 +00:00
|
|
|
void FILE_OT_select(wmOperatorType *ot)
|
2009-01-06 14:42:54 +00:00
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name= "Activate/Select File";
|
2010-02-10 21:15:44 +00:00
|
|
|
ot->description= "Activate/select file";
|
2009-02-14 14:25:48 +00:00
|
|
|
ot->idname= "FILE_OT_select";
|
2009-01-06 14:42:54 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
ot->invoke= file_select_invoke;
|
2009-11-22 22:23:58 +00:00
|
|
|
ot->poll= ED_operator_file_active;
|
2009-01-21 19:28:28 +00:00
|
|
|
|
|
|
|
/* rna */
|
2009-11-22 22:23:58 +00:00
|
|
|
RNA_def_boolean(ot->srna, "extend", 0, "Extend", "Extend selection instead of deselecting everything first.");
|
2009-01-06 14:42:54 +00:00
|
|
|
}
|
|
|
|
|
2009-11-22 22:23:58 +00:00
|
|
|
static int file_select_all_exec(bContext *C, wmOperator *op)
|
2009-01-21 19:28:28 +00:00
|
|
|
{
|
|
|
|
ScrArea *sa= CTX_wm_area(C);
|
2009-07-28 16:46:14 +00:00
|
|
|
SpaceFile *sfile= CTX_wm_space_file(C);
|
2009-01-21 19:28:28 +00:00
|
|
|
int numfiles = filelist_numfiles(sfile->files);
|
|
|
|
int i;
|
|
|
|
int select = 1;
|
|
|
|
|
|
|
|
/* if any file is selected, deselect all first */
|
|
|
|
for ( i=0; i < numfiles; ++i) {
|
|
|
|
struct direntry* file = filelist_file(sfile->files, i);
|
|
|
|
if (file && (file->flags & ACTIVE)) {
|
|
|
|
file->flags &= ~ACTIVE;
|
|
|
|
select = 0;
|
|
|
|
ED_area_tag_redraw(sa);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* select all only if previously no file was selected */
|
|
|
|
if (select) {
|
|
|
|
for ( i=0; i < numfiles; ++i) {
|
|
|
|
struct direntry* file = filelist_file(sfile->files, i);
|
|
|
|
if(file && !S_ISDIR(file->type)) {
|
|
|
|
file->flags |= ACTIVE;
|
|
|
|
ED_area_tag_redraw(sa);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
2009-03-29 02:15:13 +00:00
|
|
|
void FILE_OT_select_all_toggle(wmOperatorType *ot)
|
2009-01-21 19:28:28 +00:00
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name= "Select/Deselect all files";
|
2010-02-10 21:15:44 +00:00
|
|
|
ot->description= "Select/deselect all files";
|
2009-03-29 02:15:13 +00:00
|
|
|
ot->idname= "FILE_OT_select_all_toggle";
|
2009-01-21 19:28:28 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2009-11-22 22:23:58 +00:00
|
|
|
ot->exec= file_select_all_exec;
|
2009-01-21 19:28:28 +00:00
|
|
|
|
|
|
|
/* rna */
|
|
|
|
|
|
|
|
ot->poll= ED_operator_file_active;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------- BOOKMARKS ----------- */
|
|
|
|
|
2009-11-22 22:23:58 +00:00
|
|
|
static int bookmark_select_exec(bContext *C, wmOperator *op)
|
2009-01-06 14:42:54 +00:00
|
|
|
{
|
2009-07-28 16:46:14 +00:00
|
|
|
SpaceFile *sfile= CTX_wm_space_file(C);
|
2009-01-21 19:28:28 +00:00
|
|
|
|
2009-06-29 20:23:40 +00:00
|
|
|
if(RNA_struct_find_property(op->ptr, "dir")) {
|
|
|
|
char entry[256];
|
|
|
|
FileSelectParams* params = sfile->params;
|
2009-01-21 19:28:28 +00:00
|
|
|
|
2009-06-29 20:23:40 +00:00
|
|
|
RNA_string_get(op->ptr, "dir", entry);
|
|
|
|
BLI_strncpy(params->dir, entry, sizeof(params->dir));
|
|
|
|
BLI_cleanup_dir(G.sce, params->dir);
|
2009-10-15 11:11:52 +00:00
|
|
|
file_change_dir(sfile, 1);
|
2009-01-21 19:28:28 +00:00
|
|
|
|
2.5
Notifiers
---------
Various fixes for wrong use of notifiers, and some new notifiers
to make things a bit more clear and consistent, with two notable
changes:
* Geometry changes are now done with NC_GEOM, rather than
NC_OBJECT|ND_GEOM_, so an object does need to be available.
* Space data now use NC_SPACE|ND_SPACE_*, instead of data
notifiers or even NC_WINDOW in some cases. Note that NC_SPACE
should only be used for notifying about changes in space data,
we don't want to go back to allqueue(REDRAW..).
Depsgraph
---------
The dependency graph now has a different flush call:
DAG_object_flush_update(scene, ob, flag)
is replaced by:
DAG_id_flush_update(id, flag)
It still works basically the same, one difference is that it now
also accepts object data (e.g. Mesh), again to avoid requiring an
Object to be available. Other ID types will simply do nothing at
the moment.
Docs
----
I made some guidelines for how/when to do which kinds of updates
and notifiers. I can't specify totally exact how to make these
decisions, but these are basically the guidelines I use. So, new
and updated docs are here:
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/NotifiersUpdates
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/DataNotifiers
2009-09-04 20:51:09 +00:00
|
|
|
WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_LIST, NULL);
|
2009-06-29 20:23:40 +00:00
|
|
|
}
|
|
|
|
|
2009-01-06 14:42:54 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
2009-02-14 14:25:48 +00:00
|
|
|
void FILE_OT_select_bookmark(wmOperatorType *ot)
|
2009-01-06 14:42:54 +00:00
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name= "Select Directory";
|
2010-02-10 21:15:44 +00:00
|
|
|
ot->description= "Select a bookmarked directory";
|
2009-02-14 14:25:48 +00:00
|
|
|
ot->idname= "FILE_OT_select_bookmark";
|
2009-01-06 14:42:54 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2009-11-22 22:23:58 +00:00
|
|
|
ot->exec= bookmark_select_exec;
|
2009-01-18 18:24:11 +00:00
|
|
|
ot->poll= ED_operator_file_active;
|
2009-06-29 20:23:40 +00:00
|
|
|
|
|
|
|
RNA_def_string(ot->srna, "dir", "", 256, "Dir", "");
|
2009-01-18 18:24:11 +00:00
|
|
|
}
|
|
|
|
|
2009-11-22 22:23:58 +00:00
|
|
|
static int bookmark_add_exec(bContext *C, wmOperator *op)
|
2009-06-29 22:16:48 +00:00
|
|
|
{
|
|
|
|
ScrArea *sa= CTX_wm_area(C);
|
2009-07-28 16:46:14 +00:00
|
|
|
SpaceFile *sfile= CTX_wm_space_file(C);
|
2009-06-29 22:16:48 +00:00
|
|
|
struct FSMenu* fsmenu = fsmenu_get();
|
|
|
|
struct FileSelectParams* params= ED_fileselect_get_params(sfile);
|
|
|
|
|
|
|
|
if (params->dir[0] != '\0') {
|
|
|
|
char name[FILE_MAX];
|
|
|
|
|
|
|
|
fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, params->dir, 0, 1);
|
|
|
|
BLI_make_file_string("/", name, BLI_gethome(), ".Bfs");
|
|
|
|
fsmenu_write_file(fsmenu, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
ED_area_tag_redraw(sa);
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
2009-11-28 14:37:21 +00:00
|
|
|
void FILE_OT_bookmark_add(wmOperatorType *ot)
|
2009-06-29 22:16:48 +00:00
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name= "Add Bookmark";
|
2010-02-10 21:15:44 +00:00
|
|
|
ot->description= "Add a bookmark for the selected/active directory";
|
2009-11-28 14:37:21 +00:00
|
|
|
ot->idname= "FILE_OT_bookmark_add";
|
2009-06-29 22:16:48 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2009-11-22 22:23:58 +00:00
|
|
|
ot->exec= bookmark_add_exec;
|
2009-06-29 22:16:48 +00:00
|
|
|
ot->poll= ED_operator_file_active;
|
|
|
|
}
|
|
|
|
|
2009-11-22 22:23:58 +00:00
|
|
|
static int bookmark_delete_exec(bContext *C, wmOperator *op)
|
2009-06-29 22:16:48 +00:00
|
|
|
{
|
|
|
|
ScrArea *sa= CTX_wm_area(C);
|
|
|
|
struct FSMenu* fsmenu = fsmenu_get();
|
|
|
|
int nentries = fsmenu_get_nentries(fsmenu, FS_CATEGORY_BOOKMARKS);
|
2009-07-09 15:40:04 +00:00
|
|
|
|
2009-06-29 22:16:48 +00:00
|
|
|
if(RNA_struct_find_property(op->ptr, "index")) {
|
|
|
|
int index = RNA_int_get(op->ptr, "index");
|
|
|
|
if ( (index >-1) && (index < nentries)) {
|
|
|
|
char name[FILE_MAX];
|
|
|
|
|
|
|
|
fsmenu_remove_entry(fsmenu, FS_CATEGORY_BOOKMARKS, index);
|
|
|
|
BLI_make_file_string("/", name, BLI_gethome(), ".Bfs");
|
|
|
|
fsmenu_write_file(fsmenu, name);
|
|
|
|
ED_area_tag_redraw(sa);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FILE_OT_delete_bookmark(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name= "Delete Bookmark";
|
2010-02-10 21:15:44 +00:00
|
|
|
ot->description= "Delete selected bookmark";
|
2009-06-29 22:16:48 +00:00
|
|
|
ot->idname= "FILE_OT_delete_bookmark";
|
|
|
|
|
|
|
|
/* api callbacks */
|
2009-11-22 22:23:58 +00:00
|
|
|
ot->exec= bookmark_delete_exec;
|
2009-06-29 22:16:48 +00:00
|
|
|
ot->poll= ED_operator_file_active;
|
|
|
|
|
|
|
|
RNA_def_int(ot->srna, "index", -1, -1, 20000, "Index", "", -1, 20000);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-22 22:23:58 +00:00
|
|
|
static int loadimages_exec(bContext *C, wmOperator *op)
|
2009-01-18 18:24:11 +00:00
|
|
|
{
|
|
|
|
ScrArea *sa= CTX_wm_area(C);
|
2009-07-28 16:46:14 +00:00
|
|
|
SpaceFile *sfile= CTX_wm_space_file(C);
|
2009-01-18 18:24:11 +00:00
|
|
|
if (sfile->files) {
|
|
|
|
filelist_loadimage_timer(sfile->files);
|
|
|
|
if (filelist_changed(sfile->files)) {
|
|
|
|
ED_area_tag_redraw(sa);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
2009-02-14 14:25:48 +00:00
|
|
|
void FILE_OT_loadimages(wmOperatorType *ot)
|
2009-01-18 18:24:11 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
/* identifiers */
|
|
|
|
ot->name= "Load Images";
|
2010-02-10 21:15:44 +00:00
|
|
|
ot->description= "Load selected image(s)";
|
2009-02-14 14:25:48 +00:00
|
|
|
ot->idname= "FILE_OT_loadimages";
|
2009-01-18 18:24:11 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2009-11-22 22:23:58 +00:00
|
|
|
ot->exec= loadimages_exec;
|
2009-01-18 18:24:11 +00:00
|
|
|
|
2009-01-28 11:27:25 +00:00
|
|
|
ot->poll= ED_operator_file_active;
|
2009-01-21 19:28:28 +00:00
|
|
|
}
|
|
|
|
|
2009-01-28 11:27:25 +00:00
|
|
|
int file_hilight_set(SpaceFile *sfile, ARegion *ar, int mx, int my)
|
2009-01-21 19:28:28 +00:00
|
|
|
{
|
|
|
|
FileSelectParams* params;
|
2009-07-28 16:46:14 +00:00
|
|
|
int numfiles, actfile, origfile;
|
2009-01-28 11:27:25 +00:00
|
|
|
|
|
|
|
if(sfile==NULL || sfile->files==NULL) return 0;
|
2009-07-28 16:46:14 +00:00
|
|
|
|
2009-01-21 19:28:28 +00:00
|
|
|
numfiles = filelist_numfiles(sfile->files);
|
|
|
|
params = ED_fileselect_get_params(sfile);
|
2009-03-14 18:15:28 +00:00
|
|
|
|
2009-07-28 16:46:14 +00:00
|
|
|
origfile= params->active_file;
|
|
|
|
|
|
|
|
mx -= ar->winrct.xmin;
|
|
|
|
my -= ar->winrct.ymin;
|
|
|
|
|
|
|
|
if(BLI_in_rcti(&ar->v2d.mask, mx, my)) {
|
2009-09-20 15:02:14 +00:00
|
|
|
actfile = find_file_mouse(sfile, ar, mx , my);
|
2009-07-28 16:46:14 +00:00
|
|
|
|
|
|
|
if((actfile >= 0) && (actfile < numfiles))
|
|
|
|
params->active_file=actfile;
|
|
|
|
else
|
|
|
|
params->active_file= -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
params->active_file= -1;
|
|
|
|
|
|
|
|
return (params->active_file != origfile);
|
2009-01-28 11:27:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int file_highlight_invoke(bContext *C, wmOperator *op, wmEvent *event)
|
|
|
|
{
|
|
|
|
ARegion *ar= CTX_wm_region(C);
|
2009-07-28 16:46:14 +00:00
|
|
|
SpaceFile *sfile= CTX_wm_space_file(C);
|
|
|
|
|
|
|
|
if(!file_hilight_set(sfile, ar, event->x, event->y))
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
|
|
|
ED_area_tag_redraw(CTX_wm_area(C));
|
2009-01-21 19:28:28 +00:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
2009-02-14 14:25:48 +00:00
|
|
|
void FILE_OT_highlight(struct wmOperatorType *ot)
|
2009-01-21 19:28:28 +00:00
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name= "Highlight File";
|
2010-02-10 21:15:44 +00:00
|
|
|
ot->description= "Highlight selected file(s)";
|
2009-02-14 14:25:48 +00:00
|
|
|
ot->idname= "FILE_OT_highlight";
|
2009-01-21 19:28:28 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
ot->invoke= file_highlight_invoke;
|
2009-01-28 11:27:25 +00:00
|
|
|
ot->poll= ED_operator_file_active;
|
2009-01-21 19:28:28 +00:00
|
|
|
}
|
|
|
|
|
2009-01-28 11:27:25 +00:00
|
|
|
int file_cancel_exec(bContext *C, wmOperator *unused)
|
|
|
|
{
|
2009-07-28 16:46:14 +00:00
|
|
|
SpaceFile *sfile= CTX_wm_space_file(C);
|
2009-07-07 07:25:44 +00:00
|
|
|
|
|
|
|
folderlist_free(sfile->folders_prev);
|
|
|
|
folderlist_free(sfile->folders_next);
|
|
|
|
|
2009-02-16 12:14:04 +00:00
|
|
|
WM_event_fileselect_event(C, sfile->op, EVT_FILESELECT_CANCEL);
|
|
|
|
sfile->op = NULL;
|
2009-01-28 11:27:25 +00:00
|
|
|
|
2009-09-15 20:47:34 +00:00
|
|
|
if (sfile->files) {
|
2009-09-20 18:26:02 +00:00
|
|
|
filelist_freelib(sfile->files);
|
2009-09-15 20:47:34 +00:00
|
|
|
filelist_free(sfile->files);
|
|
|
|
MEM_freeN(sfile->files);
|
|
|
|
sfile->files= NULL;
|
|
|
|
}
|
|
|
|
|
2009-01-28 11:27:25 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
2009-09-20 17:23:57 +00:00
|
|
|
int file_operator_poll(bContext *C)
|
|
|
|
{
|
|
|
|
int poll = ED_operator_file_active(C);
|
|
|
|
SpaceFile *sfile= CTX_wm_space_file(C);
|
|
|
|
|
2009-09-21 09:17:14 +00:00
|
|
|
if (!sfile || !sfile->op) poll= 0;
|
2009-09-20 17:23:57 +00:00
|
|
|
|
|
|
|
return poll;
|
|
|
|
}
|
|
|
|
|
2009-02-14 14:25:48 +00:00
|
|
|
void FILE_OT_cancel(struct wmOperatorType *ot)
|
2009-01-28 11:27:25 +00:00
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name= "Cancel File Load";
|
2010-02-10 21:15:44 +00:00
|
|
|
ot->description= "Cancel loading of selected file";
|
2009-02-14 14:25:48 +00:00
|
|
|
ot->idname= "FILE_OT_cancel";
|
2009-01-28 11:27:25 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
ot->exec= file_cancel_exec;
|
2009-09-20 17:23:57 +00:00
|
|
|
ot->poll= file_operator_poll;
|
2009-01-28 11:27:25 +00:00
|
|
|
}
|
|
|
|
|
2009-02-16 12:14:04 +00:00
|
|
|
/* sends events now, so things get handled on windowqueue level */
|
2010-01-20 08:57:26 +00:00
|
|
|
int file_exec(bContext *C, wmOperator *exec_op)
|
2009-01-28 11:27:25 +00:00
|
|
|
{
|
2009-07-28 16:46:14 +00:00
|
|
|
SpaceFile *sfile= CTX_wm_space_file(C);
|
2009-01-28 11:27:25 +00:00
|
|
|
char name[FILE_MAX];
|
|
|
|
|
|
|
|
if(sfile->op) {
|
|
|
|
wmOperator *op= sfile->op;
|
2010-01-19 03:59:05 +00:00
|
|
|
|
2010-01-20 08:57:26 +00:00
|
|
|
/* when used as a macro, for doubleclick,
|
|
|
|
to prevent closing when doubleclicking on .. item */
|
|
|
|
if (RNA_boolean_get(exec_op->ptr, "need_active")) {
|
|
|
|
int i, active=0;
|
|
|
|
struct direntry *file;
|
|
|
|
|
|
|
|
for (i=0; i<filelist_numfiles(sfile->files); i++) {
|
|
|
|
file = filelist_file(sfile->files, i);
|
|
|
|
if(file->flags & ACTIVE) {
|
|
|
|
active=1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (active == 0)
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
2009-01-28 11:27:25 +00:00
|
|
|
sfile->op = NULL;
|
2009-09-12 19:54:39 +00:00
|
|
|
RNA_string_set(op->ptr, "filename", sfile->params->file);
|
2009-01-28 11:27:25 +00:00
|
|
|
BLI_strncpy(name, sfile->params->dir, sizeof(name));
|
2009-09-12 19:54:39 +00:00
|
|
|
RNA_string_set(op->ptr, "directory", name);
|
Drag and drop 2.5 integration! Finally, slashdot regulars can use
Blender too now! :)
** Drag works as follows:
- drag-able items are defined by the standard interface ui toolkit
- each button can get this feature, via uiButSetDragXXX(but, ...).
There are calls to define drag-able images, ID blocks, RNA paths,
file paths, and so on. By default you drag an icon, exceptionally
an ImBuf
- Drag items are registered centrally in the WM, it allows more drag
items simultaneous too, but not implemented
** Drop works as follows:
- On mouse release, and if drag items exist in the WM, it converts
the mouse event to an EVT_DROP type. This event then gets the full
drag info as customdata
- drop regions are defined with WM_dropbox_add(), similar to keymaps
you can make a "drop map" this way, which become 'drop map handlers'
in the queues.
- next to that the UI kit handles some common button types (like
accepting ID or names) to be catching a drop event too.
- Every "drop box" has two callbacks:
- poll() = check if the event drag data is relevant for this box
- copy() = fill in custom properties in the dropbox to initialize
an operator
- The dropbox handler then calls its standard Operator with its
dropbox properties.
** Currently implemented
Drag items:
- ID icons in browse buttons
- ID icons in context menu of properties region
- ID icons in outliner and rna viewer
- FileBrowser icons
- FileBrowser preview images
Drag-able icons are subtly visualized by making them brighter a bit
on mouse-over. In case the icon is a button or UI element too (most
cases), the drag-able feature will make the item react to
mouse-release instead of mouse-press.
Drop options:
- UI buttons: ID and text buttons (paste name)
- View3d: Object ID drop copies object
- View3d: Material ID drop assigns to object under cursor
- View3d: Image ID drop assigns to object UV texture under cursor
- Sequencer: Path drop will add either Image or Movie strip
- Image window: Path drop will open image
** Drag and drop Notes:
- Dropping into another Blender window (from same application) works
too. I've added code that passes on mousemoves and clicks to other
windows, without activating them though. This does make using multi-window
Blender a bit friendler.
- Dropping a file path to an image, is not the same as dropping an
Image ID... keep this in mind. Sequencer for example wants paths to
be dropped, textures in 3d window wants an Image ID.
- Although drop boxes could be defined via Python, I suggest they're
part of the UI and editor design (= how we want an editor to work), and
not default offered configurable like keymaps.
- At the moment only one item can be dragged at a time. This is for
several reasons.... For one, Blender doesn't have a well defined
uniform way to define "what is selected" (files, outliner items, etc).
Secondly there's potential conflicts on what todo when you drop mixed
drag sets on spots. All undefined stuff... nice for later.
- Example to bypass the above: a collection of images that form a strip,
should be represented in filewindow as a single sequence anyway.
This then will fit well and gets handled neatly by design.
- Another option to check is to allow multiple options per drop... it
could show the operator as a sort of menu, allowing arrow or scrollwheel
to choose. For time being I'd prefer to try to design a singular drop
though, just offer only one drop action per data type on given spots.
- What does work already, but a tad slow, is to use a function that
detects an object (type) under cursor, so a drag item's option can be
further refined (like drop object on object = parent). (disabled)
** More notes
- Added saving for Region layouts (like split points for toolbar)
- Label buttons now handle mouse over
- File list: added full path entry for drop feature.
- Filesel bugfix: wm_operator_exec() got called there and fully handled,
while WM event code tried same. Added new OPERATOR_HANDLED flag for this.
Maybe python needs it too?
- Cocoa: added window move event, so multi-win setups work OK (didnt save).
- Interface_handlers.c: removed win->active
- Severe area copy bug: area handlers were not set to NULL
- Filesel bugfix: next/prev folder list was not copied on area copies
** Leftover todos
- Cocoa windows seem to hang on cases still... needs check
- Cocoa 'draw overlap' swap doesn't work
- Cocoa window loses focus permanently on using Spotlight
(for these reasons, makefile building has Carbon as default atm)
- ListView templates in UI cannot become dragged yet, needs review...
it consists of two overlapping UI elements, preventing handling icon clicks.
- There's already Ghost library code to handle dropping from OS
into Blender window. I've noticed this code is unfinished for Macs, but
seems to be complete for Windows. Needs test... currently, an external
drop event will print in console when succesfully delivered to Blender's WM.
2010-01-26 18:18:21 +00:00
|
|
|
strcat(name, sfile->params->file); // XXX unsafe
|
2009-09-13 08:08:50 +00:00
|
|
|
|
2009-09-16 18:07:49 +00:00
|
|
|
if(RNA_struct_find_property(op->ptr, "relative_paths"))
|
|
|
|
if(RNA_boolean_get(op->ptr, "relative_paths"))
|
|
|
|
BLI_makestringcode(G.sce, name);
|
|
|
|
|
2009-09-12 19:54:39 +00:00
|
|
|
RNA_string_set(op->ptr, "path", name);
|
2009-01-28 11:27:25 +00:00
|
|
|
|
2009-06-05 16:11:35 +00:00
|
|
|
/* some ops have multiple files to select */
|
|
|
|
{
|
|
|
|
PointerRNA itemptr;
|
|
|
|
int i, numfiles = filelist_numfiles(sfile->files);
|
|
|
|
struct direntry *file;
|
|
|
|
if(RNA_struct_find_property(op->ptr, "files")) {
|
|
|
|
for (i=0; i<numfiles; i++) {
|
|
|
|
file = filelist_file(sfile->files, i);
|
|
|
|
if(file->flags & ACTIVE) {
|
|
|
|
if ((file->type & S_IFDIR)==0) {
|
|
|
|
RNA_collection_add(op->ptr, "files", &itemptr);
|
|
|
|
RNA_string_set(&itemptr, "name", file->relname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(RNA_struct_find_property(op->ptr, "dirs")) {
|
|
|
|
for (i=0; i<numfiles; i++) {
|
|
|
|
file = filelist_file(sfile->files, i);
|
|
|
|
if(file->flags & ACTIVE) {
|
|
|
|
if ((file->type & S_IFDIR)) {
|
|
|
|
RNA_collection_add(op->ptr, "dirs", &itemptr);
|
|
|
|
RNA_string_set(&itemptr, "name", file->relname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-07 07:25:44 +00:00
|
|
|
folderlist_free(sfile->folders_prev);
|
|
|
|
folderlist_free(sfile->folders_next);
|
|
|
|
|
2009-03-12 19:36:59 +00:00
|
|
|
fsmenu_insert_entry(fsmenu_get(), FS_CATEGORY_RECENT, sfile->params->dir,0, 1);
|
|
|
|
BLI_make_file_string(G.sce, name, BLI_gethome(), ".Bfs");
|
|
|
|
fsmenu_write_file(fsmenu_get(), name);
|
2009-02-16 12:14:04 +00:00
|
|
|
WM_event_fileselect_event(C, op, EVT_FILESELECT_EXEC);
|
2009-09-15 20:47:34 +00:00
|
|
|
|
2009-09-20 18:26:02 +00:00
|
|
|
filelist_freelib(sfile->files);
|
2009-09-15 20:47:34 +00:00
|
|
|
filelist_free(sfile->files);
|
|
|
|
MEM_freeN(sfile->files);
|
|
|
|
sfile->files= NULL;
|
2009-01-28 11:27:25 +00:00
|
|
|
}
|
2009-02-14 14:25:48 +00:00
|
|
|
|
2009-01-28 11:27:25 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
2009-09-04 04:29:54 +00:00
|
|
|
void FILE_OT_execute(struct wmOperatorType *ot)
|
2009-01-28 11:27:25 +00:00
|
|
|
{
|
|
|
|
/* identifiers */
|
2009-02-14 14:25:48 +00:00
|
|
|
ot->name= "Execute File Window";
|
2010-02-10 21:15:44 +00:00
|
|
|
ot->description= "Execute selected file";
|
2009-09-04 04:29:54 +00:00
|
|
|
ot->idname= "FILE_OT_execute";
|
2009-01-28 11:27:25 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2009-02-14 14:25:48 +00:00
|
|
|
ot->exec= file_exec;
|
2009-09-20 17:23:57 +00:00
|
|
|
ot->poll= file_operator_poll;
|
2010-01-20 08:57:26 +00:00
|
|
|
|
|
|
|
RNA_def_boolean(ot->srna, "need_active", 0, "Need Active", "Only execute if there's an active selected file in the file list.");
|
2009-01-28 11:27:25 +00:00
|
|
|
}
|
|
|
|
|
2009-02-14 14:25:48 +00:00
|
|
|
|
2009-02-10 17:53:10 +00:00
|
|
|
int file_parent_exec(bContext *C, wmOperator *unused)
|
|
|
|
{
|
2009-07-28 16:46:14 +00:00
|
|
|
SpaceFile *sfile= CTX_wm_space_file(C);
|
2009-02-10 17:53:10 +00:00
|
|
|
|
|
|
|
if(sfile->params) {
|
2009-07-10 19:19:54 +00:00
|
|
|
if (BLI_has_parent(sfile->params->dir)) {
|
|
|
|
BLI_parent_dir(sfile->params->dir);
|
2009-07-12 13:06:52 +00:00
|
|
|
BLI_cleanup_dir(G.sce, sfile->params->dir);
|
2009-10-15 11:11:52 +00:00
|
|
|
file_change_dir(sfile, 0);
|
2.5
Notifiers
---------
Various fixes for wrong use of notifiers, and some new notifiers
to make things a bit more clear and consistent, with two notable
changes:
* Geometry changes are now done with NC_GEOM, rather than
NC_OBJECT|ND_GEOM_, so an object does need to be available.
* Space data now use NC_SPACE|ND_SPACE_*, instead of data
notifiers or even NC_WINDOW in some cases. Note that NC_SPACE
should only be used for notifying about changes in space data,
we don't want to go back to allqueue(REDRAW..).
Depsgraph
---------
The dependency graph now has a different flush call:
DAG_object_flush_update(scene, ob, flag)
is replaced by:
DAG_id_flush_update(id, flag)
It still works basically the same, one difference is that it now
also accepts object data (e.g. Mesh), again to avoid requiring an
Object to be available. Other ID types will simply do nothing at
the moment.
Docs
----
I made some guidelines for how/when to do which kinds of updates
and notifiers. I can't specify totally exact how to make these
decisions, but these are basically the guidelines I use. So, new
and updated docs are here:
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/NotifiersUpdates
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/DataNotifiers
2009-09-04 20:51:09 +00:00
|
|
|
WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_LIST, NULL);
|
2009-07-10 19:19:54 +00:00
|
|
|
}
|
2009-02-10 17:53:10 +00:00
|
|
|
}
|
2009-07-10 19:19:54 +00:00
|
|
|
|
2009-02-10 17:53:10 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-03-08 13:14:12 +00:00
|
|
|
|
2009-02-14 14:25:48 +00:00
|
|
|
void FILE_OT_parent(struct wmOperatorType *ot)
|
2009-02-10 17:53:10 +00:00
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name= "Parent File";
|
2010-02-10 21:15:44 +00:00
|
|
|
ot->description= "Move to parent directory";
|
2009-02-14 14:25:48 +00:00
|
|
|
ot->idname= "FILE_OT_parent";
|
2009-02-10 17:53:10 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
ot->exec= file_parent_exec;
|
|
|
|
ot->poll= ED_operator_file_active; /* <- important, handler is on window level */
|
|
|
|
}
|
|
|
|
|
2009-03-12 06:40:03 +00:00
|
|
|
|
|
|
|
int file_refresh_exec(bContext *C, wmOperator *unused)
|
|
|
|
{
|
2009-07-28 16:46:14 +00:00
|
|
|
SpaceFile *sfile= CTX_wm_space_file(C);
|
2009-03-12 06:40:03 +00:00
|
|
|
|
2009-10-15 11:11:52 +00:00
|
|
|
file_change_dir(sfile, 1);
|
2009-07-07 07:25:44 +00:00
|
|
|
|
2.5
Notifiers
---------
Various fixes for wrong use of notifiers, and some new notifiers
to make things a bit more clear and consistent, with two notable
changes:
* Geometry changes are now done with NC_GEOM, rather than
NC_OBJECT|ND_GEOM_, so an object does need to be available.
* Space data now use NC_SPACE|ND_SPACE_*, instead of data
notifiers or even NC_WINDOW in some cases. Note that NC_SPACE
should only be used for notifying about changes in space data,
we don't want to go back to allqueue(REDRAW..).
Depsgraph
---------
The dependency graph now has a different flush call:
DAG_object_flush_update(scene, ob, flag)
is replaced by:
DAG_id_flush_update(id, flag)
It still works basically the same, one difference is that it now
also accepts object data (e.g. Mesh), again to avoid requiring an
Object to be available. Other ID types will simply do nothing at
the moment.
Docs
----
I made some guidelines for how/when to do which kinds of updates
and notifiers. I can't specify totally exact how to make these
decisions, but these are basically the guidelines I use. So, new
and updated docs are here:
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/NotifiersUpdates
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/DataNotifiers
2009-09-04 20:51:09 +00:00
|
|
|
WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_LIST, NULL);
|
2009-07-07 07:25:44 +00:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void FILE_OT_previous(struct wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name= "Previous Folder";
|
2010-02-10 21:15:44 +00:00
|
|
|
ot->description= "Move to previous folder";
|
2009-07-07 07:25:44 +00:00
|
|
|
ot->idname= "FILE_OT_previous";
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
ot->exec= file_previous_exec;
|
|
|
|
ot->poll= ED_operator_file_active; /* <- important, handler is on window level */
|
|
|
|
}
|
|
|
|
|
|
|
|
int file_previous_exec(bContext *C, wmOperator *unused)
|
|
|
|
{
|
2009-07-28 16:46:14 +00:00
|
|
|
SpaceFile *sfile= CTX_wm_space_file(C);
|
2009-07-07 07:25:44 +00:00
|
|
|
|
2009-03-12 06:40:03 +00:00
|
|
|
if(sfile->params) {
|
2009-07-07 07:25:44 +00:00
|
|
|
if (!sfile->folders_next)
|
|
|
|
sfile->folders_next = folderlist_new();
|
|
|
|
|
|
|
|
folderlist_pushdir(sfile->folders_next, sfile->params->dir);
|
|
|
|
folderlist_popdir(sfile->folders_prev, sfile->params->dir);
|
|
|
|
folderlist_pushdir(sfile->folders_next, sfile->params->dir);
|
|
|
|
|
2009-10-15 11:11:52 +00:00
|
|
|
file_change_dir(sfile, 1);
|
2009-06-29 20:23:40 +00:00
|
|
|
}
|
2.5
Notifiers
---------
Various fixes for wrong use of notifiers, and some new notifiers
to make things a bit more clear and consistent, with two notable
changes:
* Geometry changes are now done with NC_GEOM, rather than
NC_OBJECT|ND_GEOM_, so an object does need to be available.
* Space data now use NC_SPACE|ND_SPACE_*, instead of data
notifiers or even NC_WINDOW in some cases. Note that NC_SPACE
should only be used for notifying about changes in space data,
we don't want to go back to allqueue(REDRAW..).
Depsgraph
---------
The dependency graph now has a different flush call:
DAG_object_flush_update(scene, ob, flag)
is replaced by:
DAG_id_flush_update(id, flag)
It still works basically the same, one difference is that it now
also accepts object data (e.g. Mesh), again to avoid requiring an
Object to be available. Other ID types will simply do nothing at
the moment.
Docs
----
I made some guidelines for how/when to do which kinds of updates
and notifiers. I can't specify totally exact how to make these
decisions, but these are basically the guidelines I use. So, new
and updated docs are here:
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/NotifiersUpdates
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/DataNotifiers
2009-09-04 20:51:09 +00:00
|
|
|
WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_LIST, NULL);
|
2009-03-12 06:40:03 +00:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
2009-07-07 07:25:44 +00:00
|
|
|
}
|
2009-03-12 06:40:03 +00:00
|
|
|
|
2009-07-07 07:25:44 +00:00
|
|
|
void FILE_OT_next(struct wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name= "Next Folder";
|
2010-02-10 21:15:44 +00:00
|
|
|
ot->description= "Move to next folder";
|
2009-07-07 07:25:44 +00:00
|
|
|
ot->idname= "FILE_OT_next";
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
ot->exec= file_next_exec;
|
|
|
|
ot->poll= ED_operator_file_active; /* <- important, handler is on window level */
|
2009-03-12 06:40:03 +00:00
|
|
|
}
|
|
|
|
|
2009-07-07 07:25:44 +00:00
|
|
|
int file_next_exec(bContext *C, wmOperator *unused)
|
|
|
|
{
|
2009-07-28 16:46:14 +00:00
|
|
|
SpaceFile *sfile= CTX_wm_space_file(C);
|
2009-07-07 07:25:44 +00:00
|
|
|
if(sfile->params) {
|
|
|
|
if (!sfile->folders_next)
|
|
|
|
sfile->folders_next = folderlist_new();
|
|
|
|
|
|
|
|
folderlist_pushdir(sfile->folders_prev, sfile->params->dir);
|
|
|
|
folderlist_popdir(sfile->folders_next, sfile->params->dir);
|
|
|
|
|
|
|
|
// update folder_prev so we can check for it in folderlist_clear_next()
|
|
|
|
folderlist_pushdir(sfile->folders_prev, sfile->params->dir);
|
|
|
|
|
2009-10-15 11:11:52 +00:00
|
|
|
file_change_dir(sfile, 1);
|
2009-07-07 07:25:44 +00:00
|
|
|
}
|
2.5
Notifiers
---------
Various fixes for wrong use of notifiers, and some new notifiers
to make things a bit more clear and consistent, with two notable
changes:
* Geometry changes are now done with NC_GEOM, rather than
NC_OBJECT|ND_GEOM_, so an object does need to be available.
* Space data now use NC_SPACE|ND_SPACE_*, instead of data
notifiers or even NC_WINDOW in some cases. Note that NC_SPACE
should only be used for notifying about changes in space data,
we don't want to go back to allqueue(REDRAW..).
Depsgraph
---------
The dependency graph now has a different flush call:
DAG_object_flush_update(scene, ob, flag)
is replaced by:
DAG_id_flush_update(id, flag)
It still works basically the same, one difference is that it now
also accepts object data (e.g. Mesh), again to avoid requiring an
Object to be available. Other ID types will simply do nothing at
the moment.
Docs
----
I made some guidelines for how/when to do which kinds of updates
and notifiers. I can't specify totally exact how to make these
decisions, but these are basically the guidelines I use. So, new
and updated docs are here:
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/NotifiersUpdates
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/DataNotifiers
2009-09-04 20:51:09 +00:00
|
|
|
WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_LIST, NULL);
|
2009-07-07 07:25:44 +00:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
2009-03-12 06:40:03 +00:00
|
|
|
|
2009-12-07 23:47:37 +00:00
|
|
|
/* create a new, non-existing folder name, returns 1 if successful, 0 if name couldn't be created.
|
|
|
|
The actual name is returned in 'name', 'folder' contains the complete path, including the new folder name.
|
|
|
|
*/
|
|
|
|
static int new_folder_path(const char* parent, char *folder, char *name)
|
2009-07-10 17:05:04 +00:00
|
|
|
{
|
|
|
|
int i = 1;
|
2009-12-07 23:47:37 +00:00
|
|
|
int len = 0;
|
|
|
|
|
|
|
|
BLI_strncpy(name, "New Folder", FILE_MAXFILE);
|
|
|
|
BLI_join_dirfile(folder, parent, name);
|
|
|
|
/* check whether folder with the name already exists, in this case
|
|
|
|
add number to the name. Check length of generated name to avoid
|
|
|
|
crazy case of huge number of folders each named 'New Folder (x)' */
|
|
|
|
while (BLI_exists(folder) && (len<FILE_MAXFILE)) {
|
|
|
|
len = BLI_snprintf(name, FILE_MAXFILE, "New Folder(%d)", i);
|
|
|
|
BLI_join_dirfile(folder, parent, name);
|
|
|
|
i++;
|
|
|
|
}
|
2009-07-10 17:05:04 +00:00
|
|
|
|
2009-12-07 23:47:37 +00:00
|
|
|
return (len<FILE_MAXFILE);
|
|
|
|
}
|
|
|
|
|
|
|
|
int file_directory_new_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
char name[FILE_MAXFILE];
|
|
|
|
char path[FILE_MAX];
|
2009-07-28 16:46:14 +00:00
|
|
|
SpaceFile *sfile= CTX_wm_space_file(C);
|
2009-07-10 17:05:04 +00:00
|
|
|
|
2009-12-07 23:47:37 +00:00
|
|
|
if(!sfile->params) {
|
|
|
|
BKE_report(op->reports,RPT_WARNING, "No parent directory given.");
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create a new, non-existing folder name */
|
|
|
|
if (!new_folder_path(sfile->params->dir, path, name)) {
|
|
|
|
BKE_report(op->reports,RPT_ERROR, "Couldn't create new folder name.");
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* rename the file */
|
|
|
|
BLI_recurdir_fileops(path);
|
|
|
|
|
|
|
|
if (!BLI_exists(path)) {
|
|
|
|
BKE_report(op->reports,RPT_ERROR, "Couldn't create new folder.");
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* now remember file to jump into editing */
|
|
|
|
BLI_strncpy(sfile->params->renamefile, name, FILE_MAXFILE);
|
2.5
Notifiers
---------
Various fixes for wrong use of notifiers, and some new notifiers
to make things a bit more clear and consistent, with two notable
changes:
* Geometry changes are now done with NC_GEOM, rather than
NC_OBJECT|ND_GEOM_, so an object does need to be available.
* Space data now use NC_SPACE|ND_SPACE_*, instead of data
notifiers or even NC_WINDOW in some cases. Note that NC_SPACE
should only be used for notifying about changes in space data,
we don't want to go back to allqueue(REDRAW..).
Depsgraph
---------
The dependency graph now has a different flush call:
DAG_object_flush_update(scene, ob, flag)
is replaced by:
DAG_id_flush_update(id, flag)
It still works basically the same, one difference is that it now
also accepts object data (e.g. Mesh), again to avoid requiring an
Object to be available. Other ID types will simply do nothing at
the moment.
Docs
----
I made some guidelines for how/when to do which kinds of updates
and notifiers. I can't specify totally exact how to make these
decisions, but these are basically the guidelines I use. So, new
and updated docs are here:
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/NotifiersUpdates
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/DataNotifiers
2009-09-04 20:51:09 +00:00
|
|
|
WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_LIST, NULL);
|
2009-07-10 17:05:04 +00:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FILE_OT_directory_new(struct wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name= "Create New Directory";
|
2009-07-29 23:12:30 +00:00
|
|
|
ot->description= "Create a new directory";
|
2009-10-07 12:19:47 +00:00
|
|
|
ot->idname= "FILE_OT_directory_new";
|
2009-07-10 17:05:04 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
ot->invoke= WM_operator_confirm;
|
|
|
|
ot->exec= file_directory_new_exec;
|
|
|
|
ot->poll= ED_operator_file_active; /* <- important, handler is on window level */
|
|
|
|
}
|
|
|
|
|
|
|
|
int file_directory_exec(bContext *C, wmOperator *unused)
|
|
|
|
{
|
|
|
|
char tmpstr[FILE_MAX];
|
|
|
|
|
2009-07-28 16:46:14 +00:00
|
|
|
SpaceFile *sfile= CTX_wm_space_file(C);
|
2009-07-10 17:05:04 +00:00
|
|
|
|
|
|
|
if(sfile->params) {
|
|
|
|
if ( sfile->params->dir[0] == '~' ) {
|
|
|
|
if (sfile->params->dir[1] == '\0') {
|
|
|
|
BLI_strncpy(sfile->params->dir, BLI_gethome(), sizeof(sfile->params->dir) );
|
|
|
|
} else {
|
|
|
|
/* replace ~ with home */
|
|
|
|
char homestr[FILE_MAX];
|
|
|
|
char *d = &sfile->params->dir[1];
|
|
|
|
|
|
|
|
while ( (*d == '\\') || (*d == '/') )
|
|
|
|
d++;
|
|
|
|
BLI_strncpy(homestr, BLI_gethome(), FILE_MAX);
|
|
|
|
BLI_join_dirfile(tmpstr, homestr, d);
|
|
|
|
BLI_strncpy(sfile->params->dir, tmpstr, sizeof(sfile->params->dir));
|
|
|
|
}
|
|
|
|
}
|
2009-07-10 19:52:00 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
if (sfile->params->dir[0] == '\0')
|
|
|
|
get_default_root(sfile->params->dir);
|
|
|
|
#endif
|
2009-07-12 13:06:52 +00:00
|
|
|
BLI_cleanup_dir(G.sce, sfile->params->dir);
|
2009-07-10 19:19:54 +00:00
|
|
|
BLI_add_slash(sfile->params->dir);
|
2009-10-15 11:11:52 +00:00
|
|
|
file_change_dir(sfile, 1);
|
|
|
|
|
2.5
Notifiers
---------
Various fixes for wrong use of notifiers, and some new notifiers
to make things a bit more clear and consistent, with two notable
changes:
* Geometry changes are now done with NC_GEOM, rather than
NC_OBJECT|ND_GEOM_, so an object does need to be available.
* Space data now use NC_SPACE|ND_SPACE_*, instead of data
notifiers or even NC_WINDOW in some cases. Note that NC_SPACE
should only be used for notifying about changes in space data,
we don't want to go back to allqueue(REDRAW..).
Depsgraph
---------
The dependency graph now has a different flush call:
DAG_object_flush_update(scene, ob, flag)
is replaced by:
DAG_id_flush_update(id, flag)
It still works basically the same, one difference is that it now
also accepts object data (e.g. Mesh), again to avoid requiring an
Object to be available. Other ID types will simply do nothing at
the moment.
Docs
----
I made some guidelines for how/when to do which kinds of updates
and notifiers. I can't specify totally exact how to make these
decisions, but these are basically the guidelines I use. So, new
and updated docs are here:
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/NotifiersUpdates
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/DataNotifiers
2009-09-04 20:51:09 +00:00
|
|
|
WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_LIST, NULL);
|
2009-07-10 17:05:04 +00:00
|
|
|
}
|
2009-07-10 19:19:54 +00:00
|
|
|
|
2009-07-10 17:05:04 +00:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
int file_filename_exec(bContext *C, wmOperator *unused)
|
|
|
|
{
|
2009-07-28 16:46:14 +00:00
|
|
|
SpaceFile *sfile= CTX_wm_space_file(C);
|
2009-07-10 17:05:04 +00:00
|
|
|
|
|
|
|
if(sfile->params) {
|
|
|
|
if (file_select_match(sfile, sfile->params->file))
|
|
|
|
{
|
|
|
|
sfile->params->file[0] = '\0';
|
2.5
Notifiers
---------
Various fixes for wrong use of notifiers, and some new notifiers
to make things a bit more clear and consistent, with two notable
changes:
* Geometry changes are now done with NC_GEOM, rather than
NC_OBJECT|ND_GEOM_, so an object does need to be available.
* Space data now use NC_SPACE|ND_SPACE_*, instead of data
notifiers or even NC_WINDOW in some cases. Note that NC_SPACE
should only be used for notifying about changes in space data,
we don't want to go back to allqueue(REDRAW..).
Depsgraph
---------
The dependency graph now has a different flush call:
DAG_object_flush_update(scene, ob, flag)
is replaced by:
DAG_id_flush_update(id, flag)
It still works basically the same, one difference is that it now
also accepts object data (e.g. Mesh), again to avoid requiring an
Object to be available. Other ID types will simply do nothing at
the moment.
Docs
----
I made some guidelines for how/when to do which kinds of updates
and notifiers. I can't specify totally exact how to make these
decisions, but these are basically the guidelines I use. So, new
and updated docs are here:
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/NotifiersUpdates
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/DataNotifiers
2009-09-04 20:51:09 +00:00
|
|
|
WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_PARAMS, NULL);
|
2009-07-10 17:05:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-12 06:40:03 +00:00
|
|
|
void FILE_OT_refresh(struct wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name= "Refresh Filelist";
|
2010-02-10 21:15:44 +00:00
|
|
|
ot->description= "Refresh the file list";
|
2009-03-12 06:40:03 +00:00
|
|
|
ot->idname= "FILE_OT_refresh";
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
ot->exec= file_refresh_exec;
|
|
|
|
ot->poll= ED_operator_file_active; /* <- important, handler is on window level */
|
|
|
|
}
|
|
|
|
|
2009-06-30 18:29:30 +00:00
|
|
|
int file_hidedot_exec(bContext *C, wmOperator *unused)
|
|
|
|
{
|
2009-07-28 16:46:14 +00:00
|
|
|
SpaceFile *sfile= CTX_wm_space_file(C);
|
2009-06-30 18:29:30 +00:00
|
|
|
|
|
|
|
if(sfile->params) {
|
|
|
|
sfile->params->flag ^= FILE_HIDE_DOT;
|
|
|
|
filelist_free(sfile->files);
|
|
|
|
sfile->params->active_file = -1;
|
2.5
Notifiers
---------
Various fixes for wrong use of notifiers, and some new notifiers
to make things a bit more clear and consistent, with two notable
changes:
* Geometry changes are now done with NC_GEOM, rather than
NC_OBJECT|ND_GEOM_, so an object does need to be available.
* Space data now use NC_SPACE|ND_SPACE_*, instead of data
notifiers or even NC_WINDOW in some cases. Note that NC_SPACE
should only be used for notifying about changes in space data,
we don't want to go back to allqueue(REDRAW..).
Depsgraph
---------
The dependency graph now has a different flush call:
DAG_object_flush_update(scene, ob, flag)
is replaced by:
DAG_id_flush_update(id, flag)
It still works basically the same, one difference is that it now
also accepts object data (e.g. Mesh), again to avoid requiring an
Object to be available. Other ID types will simply do nothing at
the moment.
Docs
----
I made some guidelines for how/when to do which kinds of updates
and notifiers. I can't specify totally exact how to make these
decisions, but these are basically the guidelines I use. So, new
and updated docs are here:
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/NotifiersUpdates
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/DataNotifiers
2009-09-04 20:51:09 +00:00
|
|
|
WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_LIST, NULL);
|
2009-06-30 18:29:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FILE_OT_hidedot(struct wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name= "Toggle Hide Dot Files";
|
2010-02-10 21:15:44 +00:00
|
|
|
ot->description= "Toggle hide hidden dot files";
|
2009-06-30 18:29:30 +00:00
|
|
|
ot->idname= "FILE_OT_hidedot";
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
ot->exec= file_hidedot_exec;
|
|
|
|
ot->poll= ED_operator_file_active; /* <- important, handler is on window level */
|
|
|
|
}
|
|
|
|
|
2009-03-08 13:14:12 +00:00
|
|
|
struct ARegion *file_buttons_region(struct ScrArea *sa)
|
|
|
|
{
|
2009-06-29 20:23:40 +00:00
|
|
|
ARegion *ar, *arnew;
|
2009-03-08 13:14:12 +00:00
|
|
|
|
|
|
|
for(ar= sa->regionbase.first; ar; ar= ar->next)
|
|
|
|
if(ar->regiontype==RGN_TYPE_CHANNELS)
|
|
|
|
return ar;
|
2009-06-29 20:23:40 +00:00
|
|
|
|
|
|
|
/* add subdiv level; after header */
|
|
|
|
for(ar= sa->regionbase.first; ar; ar= ar->next)
|
|
|
|
if(ar->regiontype==RGN_TYPE_HEADER)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* is error! */
|
|
|
|
if(ar==NULL) return NULL;
|
|
|
|
|
|
|
|
arnew= MEM_callocN(sizeof(ARegion), "buttons for file panels");
|
|
|
|
|
|
|
|
BLI_insertlinkafter(&sa->regionbase, ar, arnew);
|
|
|
|
arnew->regiontype= RGN_TYPE_CHANNELS;
|
|
|
|
arnew->alignment= RGN_ALIGN_LEFT;
|
|
|
|
|
|
|
|
arnew->flag = RGN_FLAG_HIDDEN;
|
|
|
|
|
|
|
|
return arnew;
|
2009-03-08 13:14:12 +00:00
|
|
|
}
|
2009-01-28 11:27:25 +00:00
|
|
|
|
2009-03-08 13:14:12 +00:00
|
|
|
int file_bookmark_toggle_exec(bContext *C, wmOperator *unused)
|
|
|
|
{
|
|
|
|
ScrArea *sa= CTX_wm_area(C);
|
|
|
|
ARegion *ar= file_buttons_region(sa);
|
|
|
|
|
2009-09-14 19:12:29 +00:00
|
|
|
if(ar)
|
|
|
|
ED_region_toggle_hidden(C, ar);
|
|
|
|
|
2009-03-08 13:14:12 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
2009-01-28 11:27:25 +00:00
|
|
|
|
2009-03-08 13:14:12 +00:00
|
|
|
void FILE_OT_bookmark_toggle(struct wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name= "Toggle Bookmarks";
|
2010-02-10 21:15:44 +00:00
|
|
|
ot->description= "Toggle bookmarks display";
|
2009-03-08 13:14:12 +00:00
|
|
|
ot->idname= "FILE_OT_bookmark_toggle";
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
ot->exec= file_bookmark_toggle_exec;
|
|
|
|
ot->poll= ED_operator_file_active; /* <- important, handler is on window level */
|
|
|
|
}
|
2009-07-05 22:26:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
int file_filenum_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
2009-07-28 16:46:14 +00:00
|
|
|
SpaceFile *sfile= CTX_wm_space_file(C);
|
2009-09-12 19:54:39 +00:00
|
|
|
ScrArea *sa= CTX_wm_area(C);
|
2009-07-05 22:26:43 +00:00
|
|
|
|
|
|
|
int inc = RNA_int_get(op->ptr, "increment");
|
|
|
|
if(sfile->params && (inc != 0)) {
|
|
|
|
BLI_newname(sfile->params->file, inc);
|
2009-09-12 19:54:39 +00:00
|
|
|
ED_area_tag_redraw(sa);
|
|
|
|
// WM_event_add_notifier(C, NC_WINDOW, NULL);
|
2009-07-05 22:26:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void FILE_OT_filenum(struct wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name= "Increment Number in Filename";
|
2010-02-10 21:15:44 +00:00
|
|
|
ot->description= "Increment number in filename";
|
2009-07-05 22:26:43 +00:00
|
|
|
ot->idname= "FILE_OT_filenum";
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
ot->exec= file_filenum_exec;
|
|
|
|
ot->poll= ED_operator_file_active; /* <- important, handler is on window level */
|
|
|
|
|
|
|
|
/* props */
|
|
|
|
RNA_def_int(ot->srna, "increment", 1, 0, 100, "Increment", "", 0,100);
|
2009-07-09 19:49:04 +00:00
|
|
|
}
|
|
|
|
|
2009-07-26 18:52:27 +00:00
|
|
|
int file_rename_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
ScrArea *sa= CTX_wm_area(C);
|
|
|
|
SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
|
|
|
|
|
|
|
|
if(sfile->params) {
|
|
|
|
int idx = sfile->params->active_file;
|
|
|
|
int numfiles = filelist_numfiles(sfile->files);
|
|
|
|
if ( (0<=idx) && (idx<numfiles) ) {
|
|
|
|
struct direntry *file= filelist_file(sfile->files, idx);
|
|
|
|
file->flags |= EDITING;
|
|
|
|
}
|
|
|
|
ED_area_tag_redraw(sa);
|
|
|
|
}
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-09-12 19:54:39 +00:00
|
|
|
int file_rename_poll(bContext *C)
|
|
|
|
{
|
|
|
|
int poll = ED_operator_file_active(C);
|
|
|
|
SpaceFile *sfile= CTX_wm_space_file(C);
|
|
|
|
|
|
|
|
if (sfile && sfile->params) {
|
|
|
|
if (sfile->params->active_file < 0) {
|
|
|
|
poll= 0;
|
|
|
|
} else {
|
|
|
|
char dir[FILE_MAX], group[FILE_MAX];
|
|
|
|
if (filelist_islibrary(sfile->files, dir, group)) poll= 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
poll= 0;
|
|
|
|
return poll;
|
|
|
|
}
|
|
|
|
|
2009-07-26 18:52:27 +00:00
|
|
|
void FILE_OT_rename(struct wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name= "Rename File or Directory";
|
2010-02-10 21:15:44 +00:00
|
|
|
ot->description= "Rename file or file directory";
|
2009-07-26 18:52:27 +00:00
|
|
|
ot->idname= "FILE_OT_rename";
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
ot->exec= file_rename_exec;
|
2009-09-12 19:54:39 +00:00
|
|
|
ot->poll= file_rename_poll;
|
2009-07-26 18:52:27 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-07-10 17:05:04 +00:00
|
|
|
int file_delete_poll(bContext *C)
|
|
|
|
{
|
|
|
|
int poll = ED_operator_file_active(C);
|
2009-07-28 16:46:14 +00:00
|
|
|
SpaceFile *sfile= CTX_wm_space_file(C);
|
2009-07-10 17:05:04 +00:00
|
|
|
struct direntry* file;
|
|
|
|
|
2009-07-29 18:15:46 +00:00
|
|
|
if (sfile && sfile->params) {
|
2009-07-20 00:02:03 +00:00
|
|
|
if (sfile->params->active_file < 0) {
|
|
|
|
poll= 0;
|
|
|
|
} else {
|
2009-09-12 19:54:39 +00:00
|
|
|
char dir[FILE_MAX], group[FILE_MAX];
|
|
|
|
if (filelist_islibrary(sfile->files, dir, group)) poll= 0;
|
2009-07-20 00:02:03 +00:00
|
|
|
file = filelist_file(sfile->files, sfile->params->active_file);
|
|
|
|
if (file && S_ISDIR(file->type)) poll= 0;
|
|
|
|
}
|
2009-07-10 17:05:04 +00:00
|
|
|
}
|
2009-07-20 00:02:03 +00:00
|
|
|
else
|
|
|
|
poll= 0;
|
|
|
|
|
2009-07-10 17:05:04 +00:00
|
|
|
return poll;
|
|
|
|
}
|
|
|
|
|
|
|
|
int file_delete_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
char str[FILE_MAX];
|
2009-07-28 16:46:14 +00:00
|
|
|
SpaceFile *sfile= CTX_wm_space_file(C);
|
2009-07-10 17:05:04 +00:00
|
|
|
struct direntry* file;
|
|
|
|
|
|
|
|
|
|
|
|
file = filelist_file(sfile->files, sfile->params->active_file);
|
|
|
|
BLI_make_file_string(G.sce, str, sfile->params->dir, file->relname);
|
|
|
|
BLI_delete(str, 0, 0);
|
2.5
Notifiers
---------
Various fixes for wrong use of notifiers, and some new notifiers
to make things a bit more clear and consistent, with two notable
changes:
* Geometry changes are now done with NC_GEOM, rather than
NC_OBJECT|ND_GEOM_, so an object does need to be available.
* Space data now use NC_SPACE|ND_SPACE_*, instead of data
notifiers or even NC_WINDOW in some cases. Note that NC_SPACE
should only be used for notifying about changes in space data,
we don't want to go back to allqueue(REDRAW..).
Depsgraph
---------
The dependency graph now has a different flush call:
DAG_object_flush_update(scene, ob, flag)
is replaced by:
DAG_id_flush_update(id, flag)
It still works basically the same, one difference is that it now
also accepts object data (e.g. Mesh), again to avoid requiring an
Object to be available. Other ID types will simply do nothing at
the moment.
Docs
----
I made some guidelines for how/when to do which kinds of updates
and notifiers. I can't specify totally exact how to make these
decisions, but these are basically the guidelines I use. So, new
and updated docs are here:
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/NotifiersUpdates
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/DataNotifiers
2009-09-04 20:51:09 +00:00
|
|
|
WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_LIST, NULL);
|
2009-07-10 17:05:04 +00:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void FILE_OT_delete(struct wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name= "Delete File";
|
2010-02-10 21:15:44 +00:00
|
|
|
ot->description= "Delete selected file";
|
2009-07-10 17:05:04 +00:00
|
|
|
ot->idname= "FILE_OT_delete";
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
ot->invoke= WM_operator_confirm;
|
|
|
|
ot->exec= file_delete_exec;
|
|
|
|
ot->poll= file_delete_poll; /* <- important, handler is on window level */
|
|
|
|
}
|
|
|
|
|
2010-01-19 03:59:05 +00:00
|
|
|
|
|
|
|
void ED_operatormacros_file(void)
|
|
|
|
{
|
|
|
|
wmOperatorType *ot;
|
2010-01-20 08:57:26 +00:00
|
|
|
wmOperatorTypeMacro *otmacro;
|
2010-01-19 03:59:05 +00:00
|
|
|
|
|
|
|
ot= WM_operatortype_append_macro("FILE_OT_select_execute", "Select and Execute", OPTYPE_UNDO|OPTYPE_REGISTER);
|
|
|
|
WM_operatortype_macro_define(ot, "FILE_OT_select");
|
2010-01-20 08:57:26 +00:00
|
|
|
otmacro= WM_operatortype_macro_define(ot, "FILE_OT_execute");
|
|
|
|
RNA_boolean_set(otmacro->ptr, "need_active", 1);
|
2010-01-19 03:59:05 +00:00
|
|
|
|
|
|
|
}
|