2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2009-01-06 14:42:54 +00:00
|
|
|
* ***** 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-01-06 14:42:54 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2008 Blender Foundation.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Contributor(s): Andrea Weikert (c) 2008 Blender Foundation
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
2011-02-27 20:29:51 +00:00
|
|
|
/** \file blender/editors/space_file/file_ops.c
|
|
|
|
* \ingroup spfile
|
|
|
|
*/
|
|
|
|
|
2013-01-10 16:37:48 +00:00
|
|
|
#include "BLI_blenlib.h"
|
|
|
|
#include "BLI_utildefines.h"
|
2013-03-05 03:44:47 +00:00
|
|
|
#include "BLI_fileops_types.h"
|
2015-02-11 00:09:45 +01:00
|
|
|
#include "BLI_linklist.h"
|
2011-02-27 20:29:51 +00:00
|
|
|
|
2013-11-22 14:35:34 +01:00
|
|
|
#include "BLO_readfile.h"
|
|
|
|
|
2014-11-23 14:37:13 +01:00
|
|
|
#include "BKE_appdir.h"
|
2009-01-06 14:42:54 +00:00
|
|
|
#include "BKE_context.h"
|
|
|
|
#include "BKE_screen.h"
|
|
|
|
#include "BKE_global.h"
|
2009-12-07 23:47:37 +00:00
|
|
|
#include "BKE_report.h"
|
2010-10-18 06:41:16 +00:00
|
|
|
#include "BKE_main.h"
|
2009-01-06 14:42:54 +00:00
|
|
|
|
|
|
|
#ifdef WIN32
|
2012-04-15 07:54:07 +00:00
|
|
|
# include "BLI_winstuff.h"
|
2009-01-06 14:42:54 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "ED_screen.h"
|
|
|
|
#include "ED_fileselect.h"
|
|
|
|
|
2013-11-22 01:35:38 +01:00
|
|
|
#include "UI_interface.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-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>
|
2011-08-05 06:06:15 +00:00
|
|
|
#include <ctype.h>
|
2016-02-03 16:37:02 +11:00
|
|
|
#include <errno.h>
|
2009-01-06 14:42:54 +00:00
|
|
|
|
2009-01-21 19:28:28 +00:00
|
|
|
/* ---------- FILE SELECTION ------------ */
|
2014-04-21 16:47:16 +10:00
|
|
|
static FileSelection find_file_mouse_rect(SpaceFile *sfile, ARegion *ar, const rcti *rect_region)
|
2009-01-06 14:42:54 +00:00
|
|
|
{
|
2011-03-14 19:56:13 +00:00
|
|
|
FileSelection sel;
|
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
View2D *v2d = &ar->v2d;
|
2011-03-14 19:56:13 +00:00
|
|
|
rcti rect_view;
|
2014-04-21 16:47:16 +10:00
|
|
|
rctf rect_view_fl;
|
|
|
|
rctf rect_region_fl;
|
2009-01-21 19:28:28 +00:00
|
|
|
|
2014-04-21 16:47:16 +10:00
|
|
|
BLI_rctf_rcti_copy(&rect_region_fl, rect_region);
|
2009-01-21 19:28:28 +00:00
|
|
|
|
2014-04-21 16:47:16 +10:00
|
|
|
UI_view2d_region_to_view_rctf(v2d, &rect_region_fl, &rect_view_fl);
|
|
|
|
|
|
|
|
BLI_rcti_init(&rect_view,
|
|
|
|
(int)(v2d->tot.xmin + rect_view_fl.xmin),
|
|
|
|
(int)(v2d->tot.xmin + rect_view_fl.xmax),
|
|
|
|
(int)(v2d->tot.ymax - rect_view_fl.ymin),
|
|
|
|
(int)(v2d->tot.ymax - rect_view_fl.ymax));
|
2011-03-14 19:56:13 +00:00
|
|
|
|
|
|
|
sel = ED_fileselect_layout_offset_rect(sfile->layout, &rect_view);
|
2009-06-09 07:28:15 +00:00
|
|
|
|
2011-03-14 19:56:13 +00:00
|
|
|
return sel;
|
2009-01-06 14:42:54 +00:00
|
|
|
}
|
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
static void file_deselect_all(SpaceFile *sfile, unsigned int flag)
|
2009-01-06 14:42:54 +00:00
|
|
|
{
|
2011-03-20 15:15:05 +00:00
|
|
|
FileSelection sel;
|
|
|
|
sel.first = 0;
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
sel.last = filelist_files_ensure(sfile->files) - 1;
|
2011-03-20 15:15:05 +00:00
|
|
|
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
filelist_entries_select_index_range_set(sfile->files, &sel, FILE_SEL_REMOVE, flag, CHECK_ALL);
|
2009-01-06 14:42:54 +00:00
|
|
|
}
|
|
|
|
|
2011-03-14 19:56:13 +00:00
|
|
|
typedef enum FileSelect {
|
|
|
|
FILE_SELECT_NOTHING = 0,
|
|
|
|
FILE_SELECT_DIR = 1,
|
|
|
|
FILE_SELECT_FILE = 2
|
|
|
|
} FileSelect;
|
2009-07-26 19:23:07 +00:00
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
static void clamp_to_filelist(int numfiles, FileSelection *sel)
|
2009-09-20 15:02:14 +00:00
|
|
|
{
|
|
|
|
/* border select before the first file */
|
2012-06-18 13:01:24 +00:00
|
|
|
if ( (sel->first < 0) && (sel->last >= 0) ) {
|
2011-03-14 19:56:13 +00:00
|
|
|
sel->first = 0;
|
2009-09-20 15:02:14 +00:00
|
|
|
}
|
|
|
|
/* don't select if everything is outside filelist */
|
2011-03-14 19:56:13 +00:00
|
|
|
if ( (sel->first >= numfiles) && ((sel->last < 0) || (sel->last >= numfiles)) ) {
|
|
|
|
sel->first = -1;
|
|
|
|
sel->last = -1;
|
2009-09-20 15:02:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* fix if last file invalid */
|
2011-03-14 19:56:13 +00:00
|
|
|
if ( (sel->first > 0) && (sel->last < 0) )
|
2012-06-18 13:01:24 +00:00
|
|
|
sel->last = numfiles - 1;
|
2009-09-20 15:02:14 +00:00
|
|
|
|
|
|
|
/* clamp */
|
2011-03-14 19:56:13 +00:00
|
|
|
if ( (sel->first >= numfiles) ) {
|
2012-06-18 13:01:24 +00:00
|
|
|
sel->first = numfiles - 1;
|
2009-09-20 15:02:14 +00:00
|
|
|
}
|
2011-03-14 19:56:13 +00:00
|
|
|
if ( (sel->last >= numfiles) ) {
|
2012-06-18 13:01:24 +00:00
|
|
|
sel->last = numfiles - 1;
|
2009-09-20 15:02:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-11 11:25:41 +10:00
|
|
|
static FileSelection file_selection_get(bContext *C, const rcti *rect, bool fill)
|
2009-01-06 14:42:54 +00:00
|
|
|
{
|
2012-06-18 13:01:24 +00:00
|
|
|
ARegion *ar = CTX_wm_region(C);
|
|
|
|
SpaceFile *sfile = CTX_wm_space_file(C);
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
int numfiles = filelist_files_ensure(sfile->files);
|
2011-03-14 19:56:13 +00:00
|
|
|
FileSelection sel;
|
2009-07-26 19:23:07 +00:00
|
|
|
|
2011-03-14 19:56:13 +00:00
|
|
|
sel = find_file_mouse_rect(sfile, ar, rect);
|
2012-06-18 13:01:24 +00:00
|
|
|
if (!((sel.first == -1) && (sel.last == -1)) ) {
|
2011-03-14 19:56:13 +00:00
|
|
|
clamp_to_filelist(numfiles, &sel);
|
|
|
|
}
|
2009-01-21 19:28:28 +00:00
|
|
|
|
2009-09-20 15:02:14 +00:00
|
|
|
|
2011-03-14 19:56:13 +00:00
|
|
|
/* if desired, fill the selection up from the last selected file to the current one */
|
|
|
|
if (fill && (sel.last >= 0) && (sel.last < numfiles) ) {
|
2012-06-18 13:01:24 +00:00
|
|
|
int f = sel.last;
|
2010-04-19 19:29:40 +00:00
|
|
|
while (f >= 0) {
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
if (filelist_entry_select_index_get(sfile->files, f, CHECK_ALL) )
|
2010-04-19 19:29:40 +00:00
|
|
|
break;
|
|
|
|
f--;
|
|
|
|
}
|
|
|
|
if (f >= 0) {
|
2012-06-18 13:01:24 +00:00
|
|
|
sel.first = f + 1;
|
2009-01-21 19:28:28 +00:00
|
|
|
}
|
|
|
|
}
|
2011-03-14 19:56:13 +00:00
|
|
|
return sel;
|
|
|
|
}
|
2009-03-08 13:14:12 +00:00
|
|
|
|
2014-04-11 11:25:41 +10:00
|
|
|
static FileSelect file_select_do(bContext *C, int selected_idx, bool do_diropen)
|
2011-03-14 19:56:13 +00:00
|
|
|
{
|
|
|
|
FileSelect retval = FILE_SELECT_NOTHING;
|
2012-06-18 13:01:24 +00:00
|
|
|
SpaceFile *sfile = CTX_wm_space_file(C);
|
2011-03-14 19:56:13 +00:00
|
|
|
FileSelectParams *params = ED_fileselect_get_params(sfile);
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
int numfiles = filelist_files_ensure(sfile->files);
|
|
|
|
const FileDirEntry *file;
|
2009-09-20 15:02:14 +00:00
|
|
|
|
2011-03-14 19:56:13 +00:00
|
|
|
/* make the selected file active */
|
2012-06-18 13:01:24 +00:00
|
|
|
if ((selected_idx >= 0) &&
|
|
|
|
(selected_idx < numfiles) &&
|
|
|
|
(file = filelist_file(sfile->files, selected_idx)))
|
2011-09-16 06:47:01 +00:00
|
|
|
{
|
File Browser Arrow Keys Navigation
Adds support for selecting/deselecting files in File Browser using the
arrow keys. All directions (up, down, left, right) are possible.
When to Select, When to Deselect?
Standard behaviour is selecting, however if we move into a block of
already selected files (meaning 2+ files are selected) we start
deselecting
Possible Selection Methods
Simple selection (arrow-key): All other files are deselected
Expand selection (Shift+arrow key): Add to/remove from existing
selection
ill-Expand selection (Ctrl+Shift+arrow key): Add to/remove from existing
selection and fill everything in-between
From which file do we start navigating?
From each available selection method (Mouse-, Walk-, All-, Border
Select), we use the last selected file. If there's no selection at all
we use the first (down/right arrow) or last (up/left arrow) file.
(Ideally, the view would automatically be set to the new selection, but
this behaviour overlaps with an other patch I've been working on, so
prefer to do that separately)
(Also tweaks color for highlighted file for better feedback)
D1297, Review done by @campbellbarton, thx a lot :)
2015-06-11 17:20:29 +02:00
|
|
|
params->highlight_file = selected_idx;
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
params->active_file = selected_idx;
|
2009-01-21 19:28:28 +00:00
|
|
|
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
if (file->typeflag & FILE_TYPE_DIR) {
|
|
|
|
const bool is_parent_dir = FILENAME_IS_PARENT(file->relpath);
|
2015-02-15 16:26:41 +01:00
|
|
|
|
2014-04-01 11:34:00 +11:00
|
|
|
if (do_diropen == false) {
|
2012-09-12 10:04:09 +00:00
|
|
|
params->file[0] = '\0';
|
|
|
|
retval = FILE_SELECT_DIR;
|
|
|
|
}
|
2009-07-28 16:46:14 +00:00
|
|
|
/* the path is too long and we are not going up! */
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
else if (!is_parent_dir && strlen(params->dir) + strlen(file->relpath) >= FILE_MAX) {
|
2009-01-21 19:28:28 +00:00
|
|
|
// XXX error("Path too long, cannot enter this directory");
|
2011-09-16 06:47:01 +00:00
|
|
|
}
|
|
|
|
else {
|
2015-02-15 16:26:41 +01:00
|
|
|
if (is_parent_dir) {
|
2011-09-16 06:47:01 +00:00
|
|
|
/* avoids /../../ */
|
|
|
|
BLI_parent_dir(params->dir);
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
|
|
|
|
if (params->recursion_level > 1) {
|
|
|
|
/* Disable 'dirtree' recursion when going up in tree. */
|
|
|
|
params->recursion_level = 0;
|
|
|
|
filelist_setrecursion(sfile->files, params->recursion_level);
|
|
|
|
}
|
2011-09-16 06:47:01 +00:00
|
|
|
}
|
|
|
|
else {
|
2010-10-18 06:41:16 +00:00
|
|
|
BLI_cleanup_dir(G.main->name, params->dir);
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
strcat(params->dir, file->relpath);
|
2009-07-28 16:46:14 +00:00
|
|
|
BLI_add_slash(params->dir);
|
|
|
|
}
|
|
|
|
|
2015-02-11 00:09:45 +01:00
|
|
|
ED_file_change_dir(C, false);
|
2009-07-26 19:23:07 +00:00
|
|
|
retval = FILE_SELECT_DIR;
|
2009-01-21 19:28:28 +00:00
|
|
|
}
|
|
|
|
}
|
2012-04-21 12:51:47 +00:00
|
|
|
else {
|
2011-03-14 19:56:13 +00:00
|
|
|
retval = FILE_SELECT_FILE;
|
|
|
|
}
|
2015-07-09 18:40:34 +02:00
|
|
|
fileselect_file_set(sfile, selected_idx);
|
2010-09-17 09:27:31 +00:00
|
|
|
}
|
2011-03-14 19:56:13 +00:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2015-06-12 04:42:31 +02:00
|
|
|
/**
|
|
|
|
* \warning: loops over all files so better use cautiously
|
|
|
|
*/
|
|
|
|
static bool file_is_any_selected(struct FileList *files)
|
|
|
|
{
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
const int numfiles = filelist_files_ensure(files);
|
2015-06-12 04:42:31 +02:00
|
|
|
int i;
|
|
|
|
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
/* Is any file selected ? */
|
2015-06-12 04:42:31 +02:00
|
|
|
for (i = 0; i < numfiles; ++i) {
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
if (filelist_entry_select_index_get(files, i, CHECK_ALL)) {
|
2015-06-12 04:42:31 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-09-19 03:29:06 +02:00
|
|
|
/**
|
|
|
|
* If \a file is outside viewbounds, this adjusts view to make sure it's inside
|
|
|
|
*/
|
|
|
|
static void file_ensure_inside_viewbounds(ARegion *ar, SpaceFile *sfile, const int file)
|
|
|
|
{
|
|
|
|
FileLayout *layout = ED_fileselect_get_layout(sfile, ar);
|
|
|
|
rctf *cur = &ar->v2d.cur;
|
|
|
|
rcti rect;
|
|
|
|
bool changed = true;
|
|
|
|
|
|
|
|
file_tile_boundbox(ar, layout, file, &rect);
|
|
|
|
|
|
|
|
/* down - also use if tile is higher than viewbounds so view is aligned to file name */
|
|
|
|
if (cur->ymin > rect.ymin || layout->tile_h > ar->winy) {
|
|
|
|
cur->ymin = rect.ymin - (2 * layout->tile_border_y);
|
|
|
|
cur->ymax = cur->ymin + ar->winy;
|
|
|
|
}
|
|
|
|
/* up */
|
|
|
|
else if (cur->ymax < rect.ymax) {
|
|
|
|
cur->ymax = rect.ymax + layout->tile_border_y;
|
|
|
|
cur->ymin = cur->ymax - ar->winy;
|
|
|
|
}
|
|
|
|
/* left - also use if tile is wider than viewbounds so view is aligned to file name */
|
|
|
|
else if (cur->xmin > rect.xmin || layout->tile_w > ar->winx) {
|
|
|
|
cur->xmin = rect.xmin - layout->tile_border_x;
|
|
|
|
cur->xmax = cur->xmin + ar->winx;
|
|
|
|
}
|
|
|
|
/* right */
|
|
|
|
else if (cur->xmax < rect.xmax) {
|
|
|
|
cur->xmax = rect.xmax + (2 * layout->tile_border_x);
|
|
|
|
cur->xmin = cur->xmax - ar->winx;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BLI_assert(cur->xmin <= rect.xmin && cur->xmax >= rect.xmax &&
|
|
|
|
cur->ymin <= rect.ymin && cur->ymax >= rect.ymax);
|
|
|
|
changed = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (changed) {
|
|
|
|
UI_view2d_curRect_validate(&ar->v2d);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-14 19:56:13 +00:00
|
|
|
|
2014-04-11 11:25:41 +10:00
|
|
|
static FileSelect file_select(bContext *C, const rcti *rect, FileSelType select, bool fill, bool do_diropen)
|
2011-03-14 19:56:13 +00:00
|
|
|
{
|
2012-06-18 13:01:24 +00:00
|
|
|
SpaceFile *sfile = CTX_wm_space_file(C);
|
2011-03-14 19:56:13 +00:00
|
|
|
FileSelect retval = FILE_SELECT_NOTHING;
|
2012-06-18 13:01:24 +00:00
|
|
|
FileSelection sel = file_selection_get(C, rect, fill); /* get the selection */
|
|
|
|
const FileCheckType check_type = (sfile->params->flag & FILE_DIRSEL_ONLY) ? CHECK_DIRS : CHECK_ALL;
|
2011-03-14 19:56:13 +00:00
|
|
|
|
|
|
|
/* flag the files as selected in the filelist */
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
filelist_entries_select_index_range_set(sfile->files, &sel, select, FILE_SEL_SELECTED, check_type);
|
2011-03-14 19:56:13 +00:00
|
|
|
|
|
|
|
/* Don't act on multiple selected files */
|
|
|
|
if (sel.first != sel.last) select = 0;
|
|
|
|
|
2011-03-20 11:16:59 +00:00
|
|
|
/* Do we have a valid selection and are we actually selecting */
|
2015-06-12 04:42:31 +02:00
|
|
|
if ((sel.last >= 0) && (select != FILE_SEL_REMOVE)) {
|
2011-03-20 11:16:59 +00:00
|
|
|
/* Check last selection, if selected, act on the file or dir */
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
if (filelist_entry_select_index_get(sfile->files, sel.last, check_type)) {
|
2012-09-12 10:04:09 +00:00
|
|
|
retval = file_select_do(C, sel.last, do_diropen);
|
2011-03-20 11:16:59 +00:00
|
|
|
}
|
2011-03-20 10:22:51 +00:00
|
|
|
}
|
|
|
|
|
2015-06-12 04:42:31 +02:00
|
|
|
if (select != FILE_SEL_ADD && !file_is_any_selected(sfile->files)) {
|
|
|
|
sfile->params->active_file = -1;
|
|
|
|
}
|
2015-09-19 04:24:48 +02:00
|
|
|
else {
|
|
|
|
ARegion *ar = CTX_wm_region(C);
|
|
|
|
const FileLayout *layout = ED_fileselect_get_layout(sfile, ar);
|
|
|
|
|
|
|
|
/* Adjust view to display selection. Doing iterations for first and last
|
|
|
|
* selected item makes view showing as much of the selection possible.
|
|
|
|
* Not really useful if tiles are (almost) bigger than viewbounds though. */
|
|
|
|
if (((layout->flag & FILE_LAYOUT_HOR) && ar->winx > (1.2f * layout->tile_w)) ||
|
|
|
|
((layout->flag & FILE_LAYOUT_VER) && ar->winy > (2.0f * layout->tile_h)))
|
|
|
|
{
|
|
|
|
file_ensure_inside_viewbounds(ar, sfile, sel.last);
|
|
|
|
file_ensure_inside_viewbounds(ar, sfile, sel.first);
|
|
|
|
}
|
|
|
|
}
|
2015-06-12 04:42:31 +02:00
|
|
|
|
2010-09-17 09:27:31 +00:00
|
|
|
/* update operator for name change event */
|
2015-02-17 08:52:19 +11:00
|
|
|
file_draw_check(C);
|
2010-09-17 09:27:31 +00:00
|
|
|
|
2009-07-26 19:23:07 +00:00
|
|
|
return retval;
|
2009-01-21 19:28:28 +00:00
|
|
|
}
|
|
|
|
|
File Browser Arrow Keys Navigation
Adds support for selecting/deselecting files in File Browser using the
arrow keys. All directions (up, down, left, right) are possible.
When to Select, When to Deselect?
Standard behaviour is selecting, however if we move into a block of
already selected files (meaning 2+ files are selected) we start
deselecting
Possible Selection Methods
Simple selection (arrow-key): All other files are deselected
Expand selection (Shift+arrow key): Add to/remove from existing
selection
ill-Expand selection (Ctrl+Shift+arrow key): Add to/remove from existing
selection and fill everything in-between
From which file do we start navigating?
From each available selection method (Mouse-, Walk-, All-, Border
Select), we use the last selected file. If there's no selection at all
we use the first (down/right arrow) or last (up/left arrow) file.
(Ideally, the view would automatically be set to the new selection, but
this behaviour overlaps with an other patch I've been working on, so
prefer to do that separately)
(Also tweaks color for highlighted file for better feedback)
D1297, Review done by @campbellbarton, thx a lot :)
2015-06-11 17:20:29 +02:00
|
|
|
static int file_border_select_find_last_selected(
|
|
|
|
SpaceFile *sfile, ARegion *ar, const FileSelection *sel,
|
|
|
|
const int mouse_xy[2])
|
|
|
|
{
|
|
|
|
FileLayout *layout = ED_fileselect_get_layout(sfile, ar);
|
|
|
|
rcti bounds_first, bounds_last;
|
|
|
|
int dist_first, dist_last;
|
2015-09-19 03:05:08 +02:00
|
|
|
float mouseco_view[2];
|
|
|
|
|
|
|
|
UI_view2d_region_to_view(&ar->v2d, UNPACK2(mouse_xy), &mouseco_view[0], &mouseco_view[1]);
|
File Browser Arrow Keys Navigation
Adds support for selecting/deselecting files in File Browser using the
arrow keys. All directions (up, down, left, right) are possible.
When to Select, When to Deselect?
Standard behaviour is selecting, however if we move into a block of
already selected files (meaning 2+ files are selected) we start
deselecting
Possible Selection Methods
Simple selection (arrow-key): All other files are deselected
Expand selection (Shift+arrow key): Add to/remove from existing
selection
ill-Expand selection (Ctrl+Shift+arrow key): Add to/remove from existing
selection and fill everything in-between
From which file do we start navigating?
From each available selection method (Mouse-, Walk-, All-, Border
Select), we use the last selected file. If there's no selection at all
we use the first (down/right arrow) or last (up/left arrow) file.
(Ideally, the view would automatically be set to the new selection, but
this behaviour overlaps with an other patch I've been working on, so
prefer to do that separately)
(Also tweaks color for highlighted file for better feedback)
D1297, Review done by @campbellbarton, thx a lot :)
2015-06-11 17:20:29 +02:00
|
|
|
|
|
|
|
file_tile_boundbox(ar, layout, sel->first, &bounds_first);
|
|
|
|
file_tile_boundbox(ar, layout, sel->last, &bounds_last);
|
|
|
|
|
|
|
|
/* are first and last in the same column (horizontal layout)/row (vertical layout)? */
|
|
|
|
if ((layout->flag & FILE_LAYOUT_HOR && bounds_first.xmin == bounds_last.xmin) ||
|
|
|
|
(layout->flag & FILE_LAYOUT_VER && bounds_first.ymin != bounds_last.ymin))
|
|
|
|
{
|
|
|
|
/* use vertical distance */
|
2015-09-19 03:05:08 +02:00
|
|
|
const int my_loc = (int)mouseco_view[1];
|
File Browser Arrow Keys Navigation
Adds support for selecting/deselecting files in File Browser using the
arrow keys. All directions (up, down, left, right) are possible.
When to Select, When to Deselect?
Standard behaviour is selecting, however if we move into a block of
already selected files (meaning 2+ files are selected) we start
deselecting
Possible Selection Methods
Simple selection (arrow-key): All other files are deselected
Expand selection (Shift+arrow key): Add to/remove from existing
selection
ill-Expand selection (Ctrl+Shift+arrow key): Add to/remove from existing
selection and fill everything in-between
From which file do we start navigating?
From each available selection method (Mouse-, Walk-, All-, Border
Select), we use the last selected file. If there's no selection at all
we use the first (down/right arrow) or last (up/left arrow) file.
(Ideally, the view would automatically be set to the new selection, but
this behaviour overlaps with an other patch I've been working on, so
prefer to do that separately)
(Also tweaks color for highlighted file for better feedback)
D1297, Review done by @campbellbarton, thx a lot :)
2015-06-11 17:20:29 +02:00
|
|
|
dist_first = BLI_rcti_length_y(&bounds_first, my_loc);
|
|
|
|
dist_last = BLI_rcti_length_y(&bounds_last, my_loc);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* use horizontal distance */
|
2015-09-19 03:05:08 +02:00
|
|
|
const int mx_loc = (int)mouseco_view[0];
|
File Browser Arrow Keys Navigation
Adds support for selecting/deselecting files in File Browser using the
arrow keys. All directions (up, down, left, right) are possible.
When to Select, When to Deselect?
Standard behaviour is selecting, however if we move into a block of
already selected files (meaning 2+ files are selected) we start
deselecting
Possible Selection Methods
Simple selection (arrow-key): All other files are deselected
Expand selection (Shift+arrow key): Add to/remove from existing
selection
ill-Expand selection (Ctrl+Shift+arrow key): Add to/remove from existing
selection and fill everything in-between
From which file do we start navigating?
From each available selection method (Mouse-, Walk-, All-, Border
Select), we use the last selected file. If there's no selection at all
we use the first (down/right arrow) or last (up/left arrow) file.
(Ideally, the view would automatically be set to the new selection, but
this behaviour overlaps with an other patch I've been working on, so
prefer to do that separately)
(Also tweaks color for highlighted file for better feedback)
D1297, Review done by @campbellbarton, thx a lot :)
2015-06-11 17:20:29 +02:00
|
|
|
dist_first = BLI_rcti_length_x(&bounds_first, mx_loc);
|
|
|
|
dist_last = BLI_rcti_length_x(&bounds_last, mx_loc);
|
|
|
|
}
|
|
|
|
|
2015-09-19 03:05:08 +02:00
|
|
|
return (dist_first < dist_last) ? sel->first : sel->last;
|
File Browser Arrow Keys Navigation
Adds support for selecting/deselecting files in File Browser using the
arrow keys. All directions (up, down, left, right) are possible.
When to Select, When to Deselect?
Standard behaviour is selecting, however if we move into a block of
already selected files (meaning 2+ files are selected) we start
deselecting
Possible Selection Methods
Simple selection (arrow-key): All other files are deselected
Expand selection (Shift+arrow key): Add to/remove from existing
selection
ill-Expand selection (Ctrl+Shift+arrow key): Add to/remove from existing
selection and fill everything in-between
From which file do we start navigating?
From each available selection method (Mouse-, Walk-, All-, Border
Select), we use the last selected file. If there's no selection at all
we use the first (down/right arrow) or last (up/left arrow) file.
(Ideally, the view would automatically be set to the new selection, but
this behaviour overlaps with an other patch I've been working on, so
prefer to do that separately)
(Also tweaks color for highlighted file for better feedback)
D1297, Review done by @campbellbarton, thx a lot :)
2015-06-11 17:20:29 +02:00
|
|
|
}
|
|
|
|
|
2013-03-13 09:03:46 +00:00
|
|
|
static int file_border_select_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
2011-03-20 00:34:08 +00:00
|
|
|
{
|
2012-06-18 13:01:24 +00:00
|
|
|
ARegion *ar = CTX_wm_region(C);
|
|
|
|
SpaceFile *sfile = CTX_wm_space_file(C);
|
2011-03-20 00:34:08 +00:00
|
|
|
FileSelectParams *params = ED_fileselect_get_params(sfile);
|
|
|
|
FileSelection sel;
|
|
|
|
rcti rect;
|
|
|
|
|
|
|
|
int result;
|
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
result = WM_border_select_modal(C, op, event);
|
2011-03-20 00:34:08 +00:00
|
|
|
|
2012-05-19 13:55:54 +00:00
|
|
|
if (result == OPERATOR_RUNNING_MODAL) {
|
2012-08-08 20:38:55 +00:00
|
|
|
WM_operator_properties_border_to_rcti(op, &rect);
|
2011-03-20 00:34:08 +00:00
|
|
|
|
2012-07-15 00:29:56 +00:00
|
|
|
BLI_rcti_isect(&(ar->v2d.mask), &rect, &rect);
|
2011-03-20 00:34:08 +00:00
|
|
|
|
|
|
|
sel = file_selection_get(C, &rect, 0);
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
if ((sel.first != params->sel_first) || (sel.last != params->sel_last)) {
|
2015-01-04 02:36:42 +01:00
|
|
|
int idx;
|
|
|
|
|
2015-01-04 12:03:47 +01:00
|
|
|
file_deselect_all(sfile, FILE_SEL_HIGHLIGHTED);
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
filelist_entries_select_index_range_set(sfile->files, &sel, FILE_SEL_ADD, FILE_SEL_HIGHLIGHTED, CHECK_ALL);
|
2012-06-18 13:01:24 +00:00
|
|
|
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_PARAMS, NULL);
|
2015-01-04 02:36:42 +01:00
|
|
|
|
|
|
|
for (idx = sel.last; idx >= 0; idx--) {
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
const FileDirEntry *file = filelist_file(sfile->files, idx);
|
2015-01-04 02:36:42 +01:00
|
|
|
|
2015-07-09 19:48:03 +02:00
|
|
|
/* dont highlight readonly file (".." or ".") on border select */
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
if (FILENAME_IS_CURRPAR(file->relpath)) {
|
|
|
|
filelist_entry_select_set(sfile->files, file, FILE_SEL_REMOVE, FILE_SEL_HIGHLIGHTED, CHECK_ALL);
|
2015-01-04 02:36:42 +01:00
|
|
|
}
|
|
|
|
|
File Browser Arrow Keys Navigation
Adds support for selecting/deselecting files in File Browser using the
arrow keys. All directions (up, down, left, right) are possible.
When to Select, When to Deselect?
Standard behaviour is selecting, however if we move into a block of
already selected files (meaning 2+ files are selected) we start
deselecting
Possible Selection Methods
Simple selection (arrow-key): All other files are deselected
Expand selection (Shift+arrow key): Add to/remove from existing
selection
ill-Expand selection (Ctrl+Shift+arrow key): Add to/remove from existing
selection and fill everything in-between
From which file do we start navigating?
From each available selection method (Mouse-, Walk-, All-, Border
Select), we use the last selected file. If there's no selection at all
we use the first (down/right arrow) or last (up/left arrow) file.
(Ideally, the view would automatically be set to the new selection, but
this behaviour overlaps with an other patch I've been working on, so
prefer to do that separately)
(Also tweaks color for highlighted file for better feedback)
D1297, Review done by @campbellbarton, thx a lot :)
2015-06-11 17:20:29 +02:00
|
|
|
/* make sure highlight_file is no readonly file */
|
2015-01-04 02:36:42 +01:00
|
|
|
if (sel.last == idx) {
|
File Browser Arrow Keys Navigation
Adds support for selecting/deselecting files in File Browser using the
arrow keys. All directions (up, down, left, right) are possible.
When to Select, When to Deselect?
Standard behaviour is selecting, however if we move into a block of
already selected files (meaning 2+ files are selected) we start
deselecting
Possible Selection Methods
Simple selection (arrow-key): All other files are deselected
Expand selection (Shift+arrow key): Add to/remove from existing
selection
ill-Expand selection (Ctrl+Shift+arrow key): Add to/remove from existing
selection and fill everything in-between
From which file do we start navigating?
From each available selection method (Mouse-, Walk-, All-, Border
Select), we use the last selected file. If there's no selection at all
we use the first (down/right arrow) or last (up/left arrow) file.
(Ideally, the view would automatically be set to the new selection, but
this behaviour overlaps with an other patch I've been working on, so
prefer to do that separately)
(Also tweaks color for highlighted file for better feedback)
D1297, Review done by @campbellbarton, thx a lot :)
2015-06-11 17:20:29 +02:00
|
|
|
params->highlight_file = idx;
|
2015-01-04 02:36:42 +01:00
|
|
|
}
|
|
|
|
}
|
2011-03-20 00:34:08 +00:00
|
|
|
}
|
|
|
|
params->sel_first = sel.first; params->sel_last = sel.last;
|
2015-09-19 03:05:08 +02:00
|
|
|
params->active_file = file_border_select_find_last_selected(sfile, ar, &sel, event->mval);
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else {
|
File Browser Arrow Keys Navigation
Adds support for selecting/deselecting files in File Browser using the
arrow keys. All directions (up, down, left, right) are possible.
When to Select, When to Deselect?
Standard behaviour is selecting, however if we move into a block of
already selected files (meaning 2+ files are selected) we start
deselecting
Possible Selection Methods
Simple selection (arrow-key): All other files are deselected
Expand selection (Shift+arrow key): Add to/remove from existing
selection
ill-Expand selection (Ctrl+Shift+arrow key): Add to/remove from existing
selection and fill everything in-between
From which file do we start navigating?
From each available selection method (Mouse-, Walk-, All-, Border
Select), we use the last selected file. If there's no selection at all
we use the first (down/right arrow) or last (up/left arrow) file.
(Ideally, the view would automatically be set to the new selection, but
this behaviour overlaps with an other patch I've been working on, so
prefer to do that separately)
(Also tweaks color for highlighted file for better feedback)
D1297, Review done by @campbellbarton, thx a lot :)
2015-06-11 17:20:29 +02:00
|
|
|
params->highlight_file = -1;
|
2011-03-20 00:34:08 +00:00
|
|
|
params->sel_first = params->sel_last = -1;
|
2015-07-09 18:40:34 +02:00
|
|
|
fileselect_file_set(sfile, params->active_file);
|
2015-01-04 12:03:47 +01:00
|
|
|
file_deselect_all(sfile, FILE_SEL_HIGHLIGHTED);
|
2012-06-18 13:01:24 +00:00
|
|
|
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_PARAMS, NULL);
|
2011-03-20 00:34:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2009-01-21 19:28:28 +00:00
|
|
|
|
|
|
|
static int file_border_select_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
2012-06-18 13:01:24 +00:00
|
|
|
ARegion *ar = CTX_wm_region(C);
|
2015-07-09 19:48:03 +02:00
|
|
|
SpaceFile *sfile = CTX_wm_space_file(C);
|
2009-01-21 19:28:28 +00:00
|
|
|
rcti rect;
|
2011-03-14 19:56:13 +00:00
|
|
|
FileSelect ret;
|
2013-11-26 06:39:14 +11:00
|
|
|
const bool select = (RNA_int_get(op->ptr, "gesture_mode") == GESTURE_MODAL_SELECT);
|
|
|
|
const bool extend = RNA_boolean_get(op->ptr, "extend");
|
2011-11-16 19:22:14 +00:00
|
|
|
|
2012-08-08 20:38:55 +00:00
|
|
|
WM_operator_properties_border_to_rcti(op, &rect);
|
2009-01-21 19:28:28 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!extend) {
|
2015-01-04 12:03:47 +01:00
|
|
|
file_deselect_all(sfile, FILE_SEL_SELECTED);
|
2011-11-16 19:22:14 +00:00
|
|
|
}
|
|
|
|
|
2012-07-15 00:29:56 +00:00
|
|
|
BLI_rcti_isect(&(ar->v2d.mask), &rect, &rect);
|
2011-03-14 19:56:13 +00:00
|
|
|
|
2014-04-01 11:34:00 +11:00
|
|
|
ret = file_select(C, &rect, select ? FILE_SEL_ADD : FILE_SEL_REMOVE, false, false);
|
2015-07-09 19:48:03 +02:00
|
|
|
|
|
|
|
/* unselect '..' parent entry - it's not supposed to be selected if more than one file is selected */
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
filelist_entry_select_index_set(sfile->files, 0, FILE_SEL_REMOVE, FILE_SEL_SELECTED, CHECK_ALL);
|
2015-07-09 19:48:03 +02:00
|
|
|
|
2011-03-14 19:56:13 +00:00
|
|
|
if (FILE_SELECT_DIR == ret) {
|
2012-06-18 13:01:24 +00:00
|
|
|
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL);
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else if (FILE_SELECT_FILE == ret) {
|
2012-06-18 13:01:24 +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 */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Activate/Select File";
|
|
|
|
ot->description = "Activate/select the file(s) contained in the border";
|
|
|
|
ot->idname = "FILE_OT_select_border";
|
2009-01-21 19:28:28 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->invoke = WM_border_select_invoke;
|
|
|
|
ot->exec = file_border_select_exec;
|
|
|
|
ot->modal = file_border_select_modal;
|
|
|
|
ot->poll = ED_operator_file_active;
|
|
|
|
ot->cancel = WM_border_select_cancel;
|
2009-01-21 19:28:28 +00:00
|
|
|
|
2012-10-08 03:33:02 +00:00
|
|
|
/* properties */
|
2011-11-16 19:22:14 +00:00
|
|
|
WM_operator_properties_gesture_border(ot, 1);
|
2009-01-06 14:42:54 +00:00
|
|
|
}
|
|
|
|
|
2013-03-13 09:03:46 +00:00
|
|
|
static int file_select_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
2009-01-06 14:42:54 +00:00
|
|
|
{
|
2012-06-18 13:01:24 +00:00
|
|
|
ARegion *ar = CTX_wm_region(C);
|
|
|
|
SpaceFile *sfile = CTX_wm_space_file(C);
|
2011-03-20 10:22:51 +00:00
|
|
|
FileSelect ret;
|
2009-01-21 19:28:28 +00:00
|
|
|
rcti rect;
|
2013-11-26 06:39:14 +11:00
|
|
|
const bool extend = RNA_boolean_get(op->ptr, "extend");
|
|
|
|
const bool fill = RNA_boolean_get(op->ptr, "fill");
|
|
|
|
const bool do_diropen = RNA_boolean_get(op->ptr, "open");
|
2009-01-21 19:28:28 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (ar->regiontype != RGN_TYPE_WINDOW)
|
2009-07-28 16:46:14 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
2011-05-20 07:40:05 +00:00
|
|
|
rect.xmin = rect.xmax = event->mval[0];
|
|
|
|
rect.ymin = rect.ymax = event->mval[1];
|
2009-01-21 19:28:28 +00:00
|
|
|
|
2012-08-23 18:25:45 +00:00
|
|
|
if (!BLI_rcti_isect_pt(&ar->v2d.mask, rect.xmin, rect.ymin))
|
2009-07-28 16:46:14 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
2014-12-24 19:51:42 +01:00
|
|
|
if (sfile && sfile->params) {
|
File Browser Arrow Keys Navigation
Adds support for selecting/deselecting files in File Browser using the
arrow keys. All directions (up, down, left, right) are possible.
When to Select, When to Deselect?
Standard behaviour is selecting, however if we move into a block of
already selected files (meaning 2+ files are selected) we start
deselecting
Possible Selection Methods
Simple selection (arrow-key): All other files are deselected
Expand selection (Shift+arrow key): Add to/remove from existing
selection
ill-Expand selection (Ctrl+Shift+arrow key): Add to/remove from existing
selection and fill everything in-between
From which file do we start navigating?
From each available selection method (Mouse-, Walk-, All-, Border
Select), we use the last selected file. If there's no selection at all
we use the first (down/right arrow) or last (up/left arrow) file.
(Ideally, the view would automatically be set to the new selection, but
this behaviour overlaps with an other patch I've been working on, so
prefer to do that separately)
(Also tweaks color for highlighted file for better feedback)
D1297, Review done by @campbellbarton, thx a lot :)
2015-06-11 17:20:29 +02:00
|
|
|
int idx = sfile->params->highlight_file;
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
int numfiles = filelist_files_ensure(sfile->files);
|
2014-12-24 19:51:42 +01:00
|
|
|
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
if ((idx >= 0) && (idx < numfiles)) {
|
2015-07-09 19:48:03 +02:00
|
|
|
/* single select, deselect all selected first */
|
|
|
|
if (!extend) {
|
|
|
|
file_deselect_all(sfile, FILE_SEL_SELECTED);
|
2014-12-24 19:51:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-07-28 16:46:14 +00:00
|
|
|
|
2012-09-12 10:04:09 +00:00
|
|
|
ret = file_select(C, &rect, extend ? FILE_SEL_TOGGLE : FILE_SEL_ADD, fill, do_diropen);
|
2015-07-09 19:48:03 +02:00
|
|
|
|
|
|
|
if (extend) {
|
|
|
|
/* unselect '..' parent entry - it's not supposed to be selected if more than one file is selected */
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
filelist_entry_select_index_set(sfile->files, 0, FILE_SEL_REMOVE, FILE_SEL_SELECTED, CHECK_ALL);
|
2015-07-09 19:48:03 +02:00
|
|
|
}
|
|
|
|
|
2011-03-20 10:22:51 +00:00
|
|
|
if (FILE_SELECT_DIR == ret)
|
2012-06-18 13:01:24 +00:00
|
|
|
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL);
|
2011-03-20 10:22:51 +00:00
|
|
|
else if (FILE_SELECT_FILE == ret)
|
2012-06-18 13:01:24 +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 */
|
2012-06-18 13:01:24 +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
|
|
|
{
|
2012-10-08 03:33:02 +00:00
|
|
|
PropertyRNA *prop;
|
|
|
|
|
2009-01-06 14:42:54 +00:00
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Activate/Select File";
|
|
|
|
ot->description = "Activate/select file";
|
|
|
|
ot->idname = "FILE_OT_select";
|
2009-01-06 14:42:54 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->invoke = file_select_invoke;
|
|
|
|
ot->poll = ED_operator_file_active;
|
2009-01-21 19:28:28 +00:00
|
|
|
|
2012-10-08 03:33:02 +00:00
|
|
|
/* properties */
|
2014-04-01 11:34:00 +11:00
|
|
|
prop = RNA_def_boolean(ot->srna, "extend", false, "Extend", "Extend selection instead of deselecting everything first");
|
2012-10-08 03:33:02 +00:00
|
|
|
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
|
2014-04-01 11:34:00 +11:00
|
|
|
prop = RNA_def_boolean(ot->srna, "fill", false, "Fill", "Select everything beginning with the last selection");
|
2012-10-08 03:33:02 +00:00
|
|
|
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
|
2014-04-01 11:34:00 +11:00
|
|
|
prop = RNA_def_boolean(ot->srna, "open", true, "Open", "Open a directory when selecting it");
|
2012-10-08 03:33:02 +00:00
|
|
|
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
|
2009-01-06 14:42:54 +00:00
|
|
|
}
|
|
|
|
|
File Browser Arrow Keys Navigation
Adds support for selecting/deselecting files in File Browser using the
arrow keys. All directions (up, down, left, right) are possible.
When to Select, When to Deselect?
Standard behaviour is selecting, however if we move into a block of
already selected files (meaning 2+ files are selected) we start
deselecting
Possible Selection Methods
Simple selection (arrow-key): All other files are deselected
Expand selection (Shift+arrow key): Add to/remove from existing
selection
ill-Expand selection (Ctrl+Shift+arrow key): Add to/remove from existing
selection and fill everything in-between
From which file do we start navigating?
From each available selection method (Mouse-, Walk-, All-, Border
Select), we use the last selected file. If there's no selection at all
we use the first (down/right arrow) or last (up/left arrow) file.
(Ideally, the view would automatically be set to the new selection, but
this behaviour overlaps with an other patch I've been working on, so
prefer to do that separately)
(Also tweaks color for highlighted file for better feedback)
D1297, Review done by @campbellbarton, thx a lot :)
2015-06-11 17:20:29 +02:00
|
|
|
/**
|
|
|
|
* \returns true if selection has changed
|
|
|
|
*/
|
|
|
|
static bool file_walk_select_selection_set(
|
|
|
|
bContext *C, SpaceFile *sfile,
|
|
|
|
const int direction, const int numfiles,
|
|
|
|
const int active_old, const int active_new, const int other_site,
|
|
|
|
const bool has_selection, const bool extend, const bool fill)
|
|
|
|
{
|
|
|
|
FileSelectParams *params = sfile->params;
|
|
|
|
struct FileList *files = sfile->files;
|
|
|
|
const int last_sel = params->active_file; /* store old value */
|
|
|
|
int active = active_old; /* could use active_old instead, just for readability */
|
|
|
|
bool deselect = false;
|
|
|
|
|
2015-06-12 06:25:43 +02:00
|
|
|
BLI_assert(params);
|
|
|
|
|
File Browser Arrow Keys Navigation
Adds support for selecting/deselecting files in File Browser using the
arrow keys. All directions (up, down, left, right) are possible.
When to Select, When to Deselect?
Standard behaviour is selecting, however if we move into a block of
already selected files (meaning 2+ files are selected) we start
deselecting
Possible Selection Methods
Simple selection (arrow-key): All other files are deselected
Expand selection (Shift+arrow key): Add to/remove from existing
selection
ill-Expand selection (Ctrl+Shift+arrow key): Add to/remove from existing
selection and fill everything in-between
From which file do we start navigating?
From each available selection method (Mouse-, Walk-, All-, Border
Select), we use the last selected file. If there's no selection at all
we use the first (down/right arrow) or last (up/left arrow) file.
(Ideally, the view would automatically be set to the new selection, but
this behaviour overlaps with an other patch I've been working on, so
prefer to do that separately)
(Also tweaks color for highlighted file for better feedback)
D1297, Review done by @campbellbarton, thx a lot :)
2015-06-11 17:20:29 +02:00
|
|
|
if (has_selection) {
|
|
|
|
if (extend &&
|
2015-08-25 19:32:30 +02:00
|
|
|
filelist_entry_select_index_get(files, active_old, CHECK_ALL) &&
|
|
|
|
filelist_entry_select_index_get(files, active_new, CHECK_ALL))
|
File Browser Arrow Keys Navigation
Adds support for selecting/deselecting files in File Browser using the
arrow keys. All directions (up, down, left, right) are possible.
When to Select, When to Deselect?
Standard behaviour is selecting, however if we move into a block of
already selected files (meaning 2+ files are selected) we start
deselecting
Possible Selection Methods
Simple selection (arrow-key): All other files are deselected
Expand selection (Shift+arrow key): Add to/remove from existing
selection
ill-Expand selection (Ctrl+Shift+arrow key): Add to/remove from existing
selection and fill everything in-between
From which file do we start navigating?
From each available selection method (Mouse-, Walk-, All-, Border
Select), we use the last selected file. If there's no selection at all
we use the first (down/right arrow) or last (up/left arrow) file.
(Ideally, the view would automatically be set to the new selection, but
this behaviour overlaps with an other patch I've been working on, so
prefer to do that separately)
(Also tweaks color for highlighted file for better feedback)
D1297, Review done by @campbellbarton, thx a lot :)
2015-06-11 17:20:29 +02:00
|
|
|
{
|
2015-06-16 10:18:45 +10:00
|
|
|
/* conditions for deselecting: initial file is selected, new file is
|
|
|
|
* selected and either other_side isn't selected/found or we use fill */
|
2015-08-20 08:51:35 +10:00
|
|
|
deselect = (fill || other_site == -1 ||
|
2015-08-25 19:32:30 +02:00
|
|
|
!filelist_entry_select_index_get(files, other_site, CHECK_ALL));
|
2015-06-16 10:18:45 +10:00
|
|
|
|
2015-07-09 18:40:34 +02:00
|
|
|
/* don't change highlight_file here since we either want to deselect active or we want to
|
2015-06-16 10:18:45 +10:00
|
|
|
* walk through a block of selected files without selecting/deselecting anything */
|
|
|
|
params->active_file = active_new;
|
|
|
|
/* but we want to change active if we use fill (needed to get correct selection bounds) */
|
|
|
|
if (deselect && fill) {
|
|
|
|
active = active_new;
|
|
|
|
}
|
File Browser Arrow Keys Navigation
Adds support for selecting/deselecting files in File Browser using the
arrow keys. All directions (up, down, left, right) are possible.
When to Select, When to Deselect?
Standard behaviour is selecting, however if we move into a block of
already selected files (meaning 2+ files are selected) we start
deselecting
Possible Selection Methods
Simple selection (arrow-key): All other files are deselected
Expand selection (Shift+arrow key): Add to/remove from existing
selection
ill-Expand selection (Ctrl+Shift+arrow key): Add to/remove from existing
selection and fill everything in-between
From which file do we start navigating?
From each available selection method (Mouse-, Walk-, All-, Border
Select), we use the last selected file. If there's no selection at all
we use the first (down/right arrow) or last (up/left arrow) file.
(Ideally, the view would automatically be set to the new selection, but
this behaviour overlaps with an other patch I've been working on, so
prefer to do that separately)
(Also tweaks color for highlighted file for better feedback)
D1297, Review done by @campbellbarton, thx a lot :)
2015-06-11 17:20:29 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* regular selection change */
|
|
|
|
params->active_file = active = active_new;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* select last file */
|
|
|
|
if (ELEM(direction, FILE_SELECT_WALK_UP, FILE_SELECT_WALK_LEFT)) {
|
|
|
|
params->active_file = active = numfiles - 1;
|
|
|
|
}
|
|
|
|
/* select first file */
|
|
|
|
else if (ELEM(direction, FILE_SELECT_WALK_DOWN, FILE_SELECT_WALK_RIGHT)) {
|
2015-07-09 19:48:03 +02:00
|
|
|
params->active_file = active = extend ? 1 : 0;
|
File Browser Arrow Keys Navigation
Adds support for selecting/deselecting files in File Browser using the
arrow keys. All directions (up, down, left, right) are possible.
When to Select, When to Deselect?
Standard behaviour is selecting, however if we move into a block of
already selected files (meaning 2+ files are selected) we start
deselecting
Possible Selection Methods
Simple selection (arrow-key): All other files are deselected
Expand selection (Shift+arrow key): Add to/remove from existing
selection
ill-Expand selection (Ctrl+Shift+arrow key): Add to/remove from existing
selection and fill everything in-between
From which file do we start navigating?
From each available selection method (Mouse-, Walk-, All-, Border
Select), we use the last selected file. If there's no selection at all
we use the first (down/right arrow) or last (up/left arrow) file.
(Ideally, the view would automatically be set to the new selection, but
this behaviour overlaps with an other patch I've been working on, so
prefer to do that separately)
(Also tweaks color for highlighted file for better feedback)
D1297, Review done by @campbellbarton, thx a lot :)
2015-06-11 17:20:29 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
BLI_assert(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-12 06:25:43 +02:00
|
|
|
if (active < 0) {
|
2015-06-11 20:03:55 +02:00
|
|
|
return false;
|
|
|
|
}
|
File Browser Arrow Keys Navigation
Adds support for selecting/deselecting files in File Browser using the
arrow keys. All directions (up, down, left, right) are possible.
When to Select, When to Deselect?
Standard behaviour is selecting, however if we move into a block of
already selected files (meaning 2+ files are selected) we start
deselecting
Possible Selection Methods
Simple selection (arrow-key): All other files are deselected
Expand selection (Shift+arrow key): Add to/remove from existing
selection
ill-Expand selection (Ctrl+Shift+arrow key): Add to/remove from existing
selection and fill everything in-between
From which file do we start navigating?
From each available selection method (Mouse-, Walk-, All-, Border
Select), we use the last selected file. If there's no selection at all
we use the first (down/right arrow) or last (up/left arrow) file.
(Ideally, the view would automatically be set to the new selection, but
this behaviour overlaps with an other patch I've been working on, so
prefer to do that separately)
(Also tweaks color for highlighted file for better feedback)
D1297, Review done by @campbellbarton, thx a lot :)
2015-06-11 17:20:29 +02:00
|
|
|
|
|
|
|
if (extend) {
|
2015-07-09 19:48:03 +02:00
|
|
|
/* highlight the active walker file for extended selection for better visual feedback */
|
File Browser Arrow Keys Navigation
Adds support for selecting/deselecting files in File Browser using the
arrow keys. All directions (up, down, left, right) are possible.
When to Select, When to Deselect?
Standard behaviour is selecting, however if we move into a block of
already selected files (meaning 2+ files are selected) we start
deselecting
Possible Selection Methods
Simple selection (arrow-key): All other files are deselected
Expand selection (Shift+arrow key): Add to/remove from existing
selection
ill-Expand selection (Ctrl+Shift+arrow key): Add to/remove from existing
selection and fill everything in-between
From which file do we start navigating?
From each available selection method (Mouse-, Walk-, All-, Border
Select), we use the last selected file. If there's no selection at all
we use the first (down/right arrow) or last (up/left arrow) file.
(Ideally, the view would automatically be set to the new selection, but
this behaviour overlaps with an other patch I've been working on, so
prefer to do that separately)
(Also tweaks color for highlighted file for better feedback)
D1297, Review done by @campbellbarton, thx a lot :)
2015-06-11 17:20:29 +02:00
|
|
|
params->highlight_file = params->active_file;
|
2015-07-09 19:48:03 +02:00
|
|
|
|
|
|
|
/* unselect '..' parent entry - it's not supposed to be selected if more than one file is selected */
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
filelist_entry_select_index_set(files, 0, FILE_SEL_REMOVE, FILE_SEL_SELECTED, CHECK_ALL);
|
File Browser Arrow Keys Navigation
Adds support for selecting/deselecting files in File Browser using the
arrow keys. All directions (up, down, left, right) are possible.
When to Select, When to Deselect?
Standard behaviour is selecting, however if we move into a block of
already selected files (meaning 2+ files are selected) we start
deselecting
Possible Selection Methods
Simple selection (arrow-key): All other files are deselected
Expand selection (Shift+arrow key): Add to/remove from existing
selection
ill-Expand selection (Ctrl+Shift+arrow key): Add to/remove from existing
selection and fill everything in-between
From which file do we start navigating?
From each available selection method (Mouse-, Walk-, All-, Border
Select), we use the last selected file. If there's no selection at all
we use the first (down/right arrow) or last (up/left arrow) file.
(Ideally, the view would automatically be set to the new selection, but
this behaviour overlaps with an other patch I've been working on, so
prefer to do that separately)
(Also tweaks color for highlighted file for better feedback)
D1297, Review done by @campbellbarton, thx a lot :)
2015-06-11 17:20:29 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* deselect all first */
|
|
|
|
file_deselect_all(sfile, FILE_SEL_SELECTED);
|
|
|
|
|
|
|
|
/* highlight file under mouse pos */
|
|
|
|
params->highlight_file = -1;
|
|
|
|
WM_event_add_mousemove(C);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* do the actual selection */
|
|
|
|
if (fill) {
|
|
|
|
FileSelection sel = { MIN2(active, last_sel), MAX2(active, last_sel) };
|
|
|
|
|
2015-07-09 19:48:03 +02:00
|
|
|
/* clamping selection to not include '..' parent entry */
|
|
|
|
if (sel.first == 0) {
|
|
|
|
sel.first = 1;
|
|
|
|
}
|
|
|
|
|
File Browser Arrow Keys Navigation
Adds support for selecting/deselecting files in File Browser using the
arrow keys. All directions (up, down, left, right) are possible.
When to Select, When to Deselect?
Standard behaviour is selecting, however if we move into a block of
already selected files (meaning 2+ files are selected) we start
deselecting
Possible Selection Methods
Simple selection (arrow-key): All other files are deselected
Expand selection (Shift+arrow key): Add to/remove from existing
selection
ill-Expand selection (Ctrl+Shift+arrow key): Add to/remove from existing
selection and fill everything in-between
From which file do we start navigating?
From each available selection method (Mouse-, Walk-, All-, Border
Select), we use the last selected file. If there's no selection at all
we use the first (down/right arrow) or last (up/left arrow) file.
(Ideally, the view would automatically be set to the new selection, but
this behaviour overlaps with an other patch I've been working on, so
prefer to do that separately)
(Also tweaks color for highlighted file for better feedback)
D1297, Review done by @campbellbarton, thx a lot :)
2015-06-11 17:20:29 +02:00
|
|
|
/* fill selection between last and first selected file */
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
filelist_entries_select_index_range_set(
|
2015-06-11 20:03:55 +02:00
|
|
|
files, &sel, deselect ? FILE_SEL_REMOVE : FILE_SEL_ADD, FILE_SEL_SELECTED, CHECK_ALL);
|
File Browser Arrow Keys Navigation
Adds support for selecting/deselecting files in File Browser using the
arrow keys. All directions (up, down, left, right) are possible.
When to Select, When to Deselect?
Standard behaviour is selecting, however if we move into a block of
already selected files (meaning 2+ files are selected) we start
deselecting
Possible Selection Methods
Simple selection (arrow-key): All other files are deselected
Expand selection (Shift+arrow key): Add to/remove from existing
selection
ill-Expand selection (Ctrl+Shift+arrow key): Add to/remove from existing
selection and fill everything in-between
From which file do we start navigating?
From each available selection method (Mouse-, Walk-, All-, Border
Select), we use the last selected file. If there's no selection at all
we use the first (down/right arrow) or last (up/left arrow) file.
(Ideally, the view would automatically be set to the new selection, but
this behaviour overlaps with an other patch I've been working on, so
prefer to do that separately)
(Also tweaks color for highlighted file for better feedback)
D1297, Review done by @campbellbarton, thx a lot :)
2015-06-11 17:20:29 +02:00
|
|
|
/* entire sel is cleared here, so select active again */
|
|
|
|
if (deselect) {
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
filelist_entry_select_index_set(files, active, FILE_SEL_ADD, FILE_SEL_SELECTED, CHECK_ALL);
|
File Browser Arrow Keys Navigation
Adds support for selecting/deselecting files in File Browser using the
arrow keys. All directions (up, down, left, right) are possible.
When to Select, When to Deselect?
Standard behaviour is selecting, however if we move into a block of
already selected files (meaning 2+ files are selected) we start
deselecting
Possible Selection Methods
Simple selection (arrow-key): All other files are deselected
Expand selection (Shift+arrow key): Add to/remove from existing
selection
ill-Expand selection (Ctrl+Shift+arrow key): Add to/remove from existing
selection and fill everything in-between
From which file do we start navigating?
From each available selection method (Mouse-, Walk-, All-, Border
Select), we use the last selected file. If there's no selection at all
we use the first (down/right arrow) or last (up/left arrow) file.
(Ideally, the view would automatically be set to the new selection, but
this behaviour overlaps with an other patch I've been working on, so
prefer to do that separately)
(Also tweaks color for highlighted file for better feedback)
D1297, Review done by @campbellbarton, thx a lot :)
2015-06-11 17:20:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
filelist_entry_select_index_set(
|
2015-06-11 20:03:55 +02:00
|
|
|
files, active, deselect ? FILE_SEL_REMOVE : FILE_SEL_ADD, FILE_SEL_SELECTED, CHECK_ALL);
|
File Browser Arrow Keys Navigation
Adds support for selecting/deselecting files in File Browser using the
arrow keys. All directions (up, down, left, right) are possible.
When to Select, When to Deselect?
Standard behaviour is selecting, however if we move into a block of
already selected files (meaning 2+ files are selected) we start
deselecting
Possible Selection Methods
Simple selection (arrow-key): All other files are deselected
Expand selection (Shift+arrow key): Add to/remove from existing
selection
ill-Expand selection (Ctrl+Shift+arrow key): Add to/remove from existing
selection and fill everything in-between
From which file do we start navigating?
From each available selection method (Mouse-, Walk-, All-, Border
Select), we use the last selected file. If there's no selection at all
we use the first (down/right arrow) or last (up/left arrow) file.
(Ideally, the view would automatically be set to the new selection, but
this behaviour overlaps with an other patch I've been working on, so
prefer to do that separately)
(Also tweaks color for highlighted file for better feedback)
D1297, Review done by @campbellbarton, thx a lot :)
2015-06-11 17:20:29 +02:00
|
|
|
}
|
|
|
|
|
2015-07-09 19:48:03 +02:00
|
|
|
BLI_assert(IN_RANGE(active, -1, numfiles));
|
2015-07-09 18:40:34 +02:00
|
|
|
fileselect_file_set(sfile, params->active_file);
|
File Browser Arrow Keys Navigation
Adds support for selecting/deselecting files in File Browser using the
arrow keys. All directions (up, down, left, right) are possible.
When to Select, When to Deselect?
Standard behaviour is selecting, however if we move into a block of
already selected files (meaning 2+ files are selected) we start
deselecting
Possible Selection Methods
Simple selection (arrow-key): All other files are deselected
Expand selection (Shift+arrow key): Add to/remove from existing
selection
ill-Expand selection (Ctrl+Shift+arrow key): Add to/remove from existing
selection and fill everything in-between
From which file do we start navigating?
From each available selection method (Mouse-, Walk-, All-, Border
Select), we use the last selected file. If there's no selection at all
we use the first (down/right arrow) or last (up/left arrow) file.
(Ideally, the view would automatically be set to the new selection, but
this behaviour overlaps with an other patch I've been working on, so
prefer to do that separately)
(Also tweaks color for highlighted file for better feedback)
D1297, Review done by @campbellbarton, thx a lot :)
2015-06-11 17:20:29 +02:00
|
|
|
|
2015-09-19 03:29:06 +02:00
|
|
|
/* ensure newly selected file is inside viewbounds */
|
|
|
|
file_ensure_inside_viewbounds(CTX_wm_region(C), sfile, params->active_file);
|
|
|
|
|
File Browser Arrow Keys Navigation
Adds support for selecting/deselecting files in File Browser using the
arrow keys. All directions (up, down, left, right) are possible.
When to Select, When to Deselect?
Standard behaviour is selecting, however if we move into a block of
already selected files (meaning 2+ files are selected) we start
deselecting
Possible Selection Methods
Simple selection (arrow-key): All other files are deselected
Expand selection (Shift+arrow key): Add to/remove from existing
selection
ill-Expand selection (Ctrl+Shift+arrow key): Add to/remove from existing
selection and fill everything in-between
From which file do we start navigating?
From each available selection method (Mouse-, Walk-, All-, Border
Select), we use the last selected file. If there's no selection at all
we use the first (down/right arrow) or last (up/left arrow) file.
(Ideally, the view would automatically be set to the new selection, but
this behaviour overlaps with an other patch I've been working on, so
prefer to do that separately)
(Also tweaks color for highlighted file for better feedback)
D1297, Review done by @campbellbarton, thx a lot :)
2015-06-11 17:20:29 +02:00
|
|
|
/* selection changed */
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \returns true if selection has changed
|
|
|
|
*/
|
|
|
|
static bool file_walk_select_do(
|
|
|
|
bContext *C, SpaceFile *sfile,
|
|
|
|
FileSelectParams *params, const int direction,
|
|
|
|
const bool extend, const bool fill)
|
|
|
|
{
|
2015-06-11 20:03:55 +02:00
|
|
|
struct FileList *files = sfile->files;
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
const int numfiles = filelist_files_ensure(files);
|
2015-06-11 20:03:55 +02:00
|
|
|
const bool has_selection = file_is_any_selected(files);
|
File Browser Arrow Keys Navigation
Adds support for selecting/deselecting files in File Browser using the
arrow keys. All directions (up, down, left, right) are possible.
When to Select, When to Deselect?
Standard behaviour is selecting, however if we move into a block of
already selected files (meaning 2+ files are selected) we start
deselecting
Possible Selection Methods
Simple selection (arrow-key): All other files are deselected
Expand selection (Shift+arrow key): Add to/remove from existing
selection
ill-Expand selection (Ctrl+Shift+arrow key): Add to/remove from existing
selection and fill everything in-between
From which file do we start navigating?
From each available selection method (Mouse-, Walk-, All-, Border
Select), we use the last selected file. If there's no selection at all
we use the first (down/right arrow) or last (up/left arrow) file.
(Ideally, the view would automatically be set to the new selection, but
this behaviour overlaps with an other patch I've been working on, so
prefer to do that separately)
(Also tweaks color for highlighted file for better feedback)
D1297, Review done by @campbellbarton, thx a lot :)
2015-06-11 17:20:29 +02:00
|
|
|
const int active_old = params->active_file;
|
|
|
|
int active_new = -1;
|
|
|
|
int other_site = -1; /* file on the other site of active_old */
|
|
|
|
|
|
|
|
|
|
|
|
/* *** get all needed files for handling selection *** */
|
|
|
|
|
|
|
|
if (has_selection) {
|
|
|
|
ARegion *ar = CTX_wm_region(C);
|
|
|
|
FileLayout *layout = ED_fileselect_get_layout(sfile, ar);
|
|
|
|
const int idx_shift = (layout->flag & FILE_LAYOUT_HOR) ? layout->rows : layout->columns;
|
|
|
|
|
|
|
|
if ((layout->flag & FILE_LAYOUT_HOR && direction == FILE_SELECT_WALK_UP) ||
|
|
|
|
(layout->flag & FILE_LAYOUT_VER && direction == FILE_SELECT_WALK_LEFT))
|
|
|
|
{
|
|
|
|
active_new = active_old - 1;
|
|
|
|
other_site = active_old + 1;
|
|
|
|
}
|
|
|
|
else if ((layout->flag & FILE_LAYOUT_HOR && direction == FILE_SELECT_WALK_DOWN) ||
|
|
|
|
(layout->flag & FILE_LAYOUT_VER && direction == FILE_SELECT_WALK_RIGHT))
|
|
|
|
{
|
|
|
|
active_new = active_old + 1;
|
|
|
|
other_site = active_old - 1;
|
|
|
|
}
|
|
|
|
else if ((layout->flag & FILE_LAYOUT_HOR && direction == FILE_SELECT_WALK_LEFT) ||
|
|
|
|
(layout->flag & FILE_LAYOUT_VER && direction == FILE_SELECT_WALK_UP))
|
|
|
|
{
|
|
|
|
active_new = active_old - idx_shift;
|
|
|
|
other_site = active_old + idx_shift;
|
|
|
|
}
|
|
|
|
else if ((layout->flag & FILE_LAYOUT_HOR && direction == FILE_SELECT_WALK_RIGHT) ||
|
|
|
|
(layout->flag & FILE_LAYOUT_VER && direction == FILE_SELECT_WALK_DOWN))
|
|
|
|
{
|
|
|
|
|
|
|
|
active_new = active_old + idx_shift;
|
|
|
|
other_site = active_old - idx_shift;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BLI_assert(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!IN_RANGE(active_new, 0, numfiles)) {
|
2015-06-11 20:03:55 +02:00
|
|
|
if (extend) {
|
|
|
|
/* extend to invalid file -> abort */
|
|
|
|
return false;
|
|
|
|
}
|
2015-07-09 19:48:03 +02:00
|
|
|
/* if we don't extend, selecting '..' (index == 0) is allowed so
|
|
|
|
* using key selection to go to parent directory is possible */
|
|
|
|
else if (active_new != 0) {
|
2015-06-11 20:03:55 +02:00
|
|
|
/* select initial file */
|
|
|
|
active_new = active_old;
|
|
|
|
}
|
File Browser Arrow Keys Navigation
Adds support for selecting/deselecting files in File Browser using the
arrow keys. All directions (up, down, left, right) are possible.
When to Select, When to Deselect?
Standard behaviour is selecting, however if we move into a block of
already selected files (meaning 2+ files are selected) we start
deselecting
Possible Selection Methods
Simple selection (arrow-key): All other files are deselected
Expand selection (Shift+arrow key): Add to/remove from existing
selection
ill-Expand selection (Ctrl+Shift+arrow key): Add to/remove from existing
selection and fill everything in-between
From which file do we start navigating?
From each available selection method (Mouse-, Walk-, All-, Border
Select), we use the last selected file. If there's no selection at all
we use the first (down/right arrow) or last (up/left arrow) file.
(Ideally, the view would automatically be set to the new selection, but
this behaviour overlaps with an other patch I've been working on, so
prefer to do that separately)
(Also tweaks color for highlighted file for better feedback)
D1297, Review done by @campbellbarton, thx a lot :)
2015-06-11 17:20:29 +02:00
|
|
|
}
|
|
|
|
if (!IN_RANGE(other_site, 0, numfiles)) {
|
|
|
|
other_site = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-11 20:03:55 +02:00
|
|
|
return file_walk_select_selection_set(
|
|
|
|
C, sfile, direction, numfiles, active_old, active_new, other_site, has_selection, extend, fill);
|
File Browser Arrow Keys Navigation
Adds support for selecting/deselecting files in File Browser using the
arrow keys. All directions (up, down, left, right) are possible.
When to Select, When to Deselect?
Standard behaviour is selecting, however if we move into a block of
already selected files (meaning 2+ files are selected) we start
deselecting
Possible Selection Methods
Simple selection (arrow-key): All other files are deselected
Expand selection (Shift+arrow key): Add to/remove from existing
selection
ill-Expand selection (Ctrl+Shift+arrow key): Add to/remove from existing
selection and fill everything in-between
From which file do we start navigating?
From each available selection method (Mouse-, Walk-, All-, Border
Select), we use the last selected file. If there's no selection at all
we use the first (down/right arrow) or last (up/left arrow) file.
(Ideally, the view would automatically be set to the new selection, but
this behaviour overlaps with an other patch I've been working on, so
prefer to do that separately)
(Also tweaks color for highlighted file for better feedback)
D1297, Review done by @campbellbarton, thx a lot :)
2015-06-11 17:20:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static int file_walk_select_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
|
|
|
|
{
|
|
|
|
SpaceFile *sfile = (SpaceFile *)CTX_wm_space_data(C);
|
|
|
|
FileSelectParams *params = sfile->params;
|
|
|
|
const int direction = RNA_enum_get(op->ptr, "direction");
|
|
|
|
const bool extend = RNA_boolean_get(op->ptr, "extend");
|
|
|
|
const bool fill = RNA_boolean_get(op->ptr, "fill");
|
|
|
|
|
|
|
|
if (file_walk_select_do(C, sfile, params, direction, extend, fill)) {
|
|
|
|
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_PARAMS, NULL);
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FILE_OT_select_walk(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
static EnumPropertyItem direction_items[] = {
|
|
|
|
{FILE_SELECT_WALK_UP, "UP", 0, "Prev", ""},
|
|
|
|
{FILE_SELECT_WALK_DOWN, "DOWN", 0, "Next", ""},
|
|
|
|
{FILE_SELECT_WALK_LEFT, "LEFT", 0, "Left", ""},
|
|
|
|
{FILE_SELECT_WALK_RIGHT, "RIGHT", 0, "Right", ""},
|
|
|
|
{0, NULL, 0, NULL, NULL}
|
|
|
|
};
|
|
|
|
PropertyRNA *prop;
|
|
|
|
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Walk Select/Deselect File";
|
|
|
|
ot->description = "Select/Deselect files by walking through them";
|
|
|
|
ot->idname = "FILE_OT_select_walk";
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
ot->invoke = file_walk_select_invoke;
|
|
|
|
ot->poll = ED_operator_file_active;
|
|
|
|
|
|
|
|
/* properties */
|
|
|
|
prop = RNA_def_enum(ot->srna, "direction", direction_items, 0, "Walk Direction",
|
|
|
|
"Select/Deselect file in this direction");
|
|
|
|
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
|
|
|
|
prop = RNA_def_boolean(ot->srna, "extend", false, "Extend",
|
|
|
|
"Extend selection instead of deselecting everything first");
|
|
|
|
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
|
|
|
|
prop = RNA_def_boolean(ot->srna, "fill", false, "Fill", "Select everything beginning with the last selection");
|
|
|
|
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
|
|
|
|
}
|
|
|
|
|
2010-10-15 01:36:14 +00:00
|
|
|
static int file_select_all_exec(bContext *C, wmOperator *UNUSED(op))
|
2009-01-21 19:28:28 +00:00
|
|
|
{
|
2012-06-18 13:01:24 +00:00
|
|
|
ScrArea *sa = CTX_wm_area(C);
|
|
|
|
SpaceFile *sfile = CTX_wm_space_file(C);
|
2011-03-20 15:15:05 +00:00
|
|
|
FileSelection sel;
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
const int numfiles = filelist_files_ensure(sfile->files);
|
File Browser Arrow Keys Navigation
Adds support for selecting/deselecting files in File Browser using the
arrow keys. All directions (up, down, left, right) are possible.
When to Select, When to Deselect?
Standard behaviour is selecting, however if we move into a block of
already selected files (meaning 2+ files are selected) we start
deselecting
Possible Selection Methods
Simple selection (arrow-key): All other files are deselected
Expand selection (Shift+arrow key): Add to/remove from existing
selection
ill-Expand selection (Ctrl+Shift+arrow key): Add to/remove from existing
selection and fill everything in-between
From which file do we start navigating?
From each available selection method (Mouse-, Walk-, All-, Border
Select), we use the last selected file. If there's no selection at all
we use the first (down/right arrow) or last (up/left arrow) file.
(Ideally, the view would automatically be set to the new selection, but
this behaviour overlaps with an other patch I've been working on, so
prefer to do that separately)
(Also tweaks color for highlighted file for better feedback)
D1297, Review done by @campbellbarton, thx a lot :)
2015-06-11 17:20:29 +02:00
|
|
|
const bool has_selection = file_is_any_selected(sfile->files);
|
2011-04-21 13:11:51 +00:00
|
|
|
|
2011-03-20 15:15:05 +00:00
|
|
|
sel.first = 0;
|
2012-06-18 13:01:24 +00:00
|
|
|
sel.last = numfiles - 1;
|
2009-01-21 19:28:28 +00:00
|
|
|
|
|
|
|
/* select all only if previously no file was selected */
|
File Browser Arrow Keys Navigation
Adds support for selecting/deselecting files in File Browser using the
arrow keys. All directions (up, down, left, right) are possible.
When to Select, When to Deselect?
Standard behaviour is selecting, however if we move into a block of
already selected files (meaning 2+ files are selected) we start
deselecting
Possible Selection Methods
Simple selection (arrow-key): All other files are deselected
Expand selection (Shift+arrow key): Add to/remove from existing
selection
ill-Expand selection (Ctrl+Shift+arrow key): Add to/remove from existing
selection and fill everything in-between
From which file do we start navigating?
From each available selection method (Mouse-, Walk-, All-, Border
Select), we use the last selected file. If there's no selection at all
we use the first (down/right arrow) or last (up/left arrow) file.
(Ideally, the view would automatically be set to the new selection, but
this behaviour overlaps with an other patch I've been working on, so
prefer to do that separately)
(Also tweaks color for highlighted file for better feedback)
D1297, Review done by @campbellbarton, thx a lot :)
2015-06-11 17:20:29 +02:00
|
|
|
if (has_selection) {
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
filelist_entries_select_index_range_set(sfile->files, &sel, FILE_SEL_REMOVE, FILE_SEL_SELECTED, CHECK_ALL);
|
2015-06-12 04:42:31 +02:00
|
|
|
sfile->params->active_file = -1;
|
2011-06-16 15:01:22 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-06-18 13:01:24 +00:00
|
|
|
const FileCheckType check_type = (sfile->params->flag & FILE_DIRSEL_ONLY) ? CHECK_DIRS : CHECK_FILES;
|
File Browser Arrow Keys Navigation
Adds support for selecting/deselecting files in File Browser using the
arrow keys. All directions (up, down, left, right) are possible.
When to Select, When to Deselect?
Standard behaviour is selecting, however if we move into a block of
already selected files (meaning 2+ files are selected) we start
deselecting
Possible Selection Methods
Simple selection (arrow-key): All other files are deselected
Expand selection (Shift+arrow key): Add to/remove from existing
selection
ill-Expand selection (Ctrl+Shift+arrow key): Add to/remove from existing
selection and fill everything in-between
From which file do we start navigating?
From each available selection method (Mouse-, Walk-, All-, Border
Select), we use the last selected file. If there's no selection at all
we use the first (down/right arrow) or last (up/left arrow) file.
(Ideally, the view would automatically be set to the new selection, but
this behaviour overlaps with an other patch I've been working on, so
prefer to do that separately)
(Also tweaks color for highlighted file for better feedback)
D1297, Review done by @campbellbarton, thx a lot :)
2015-06-11 17:20:29 +02:00
|
|
|
int i;
|
|
|
|
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
filelist_entries_select_index_range_set(sfile->files, &sel, FILE_SEL_ADD, FILE_SEL_SELECTED, check_type);
|
File Browser Arrow Keys Navigation
Adds support for selecting/deselecting files in File Browser using the
arrow keys. All directions (up, down, left, right) are possible.
When to Select, When to Deselect?
Standard behaviour is selecting, however if we move into a block of
already selected files (meaning 2+ files are selected) we start
deselecting
Possible Selection Methods
Simple selection (arrow-key): All other files are deselected
Expand selection (Shift+arrow key): Add to/remove from existing
selection
ill-Expand selection (Ctrl+Shift+arrow key): Add to/remove from existing
selection and fill everything in-between
From which file do we start navigating?
From each available selection method (Mouse-, Walk-, All-, Border
Select), we use the last selected file. If there's no selection at all
we use the first (down/right arrow) or last (up/left arrow) file.
(Ideally, the view would automatically be set to the new selection, but
this behaviour overlaps with an other patch I've been working on, so
prefer to do that separately)
(Also tweaks color for highlighted file for better feedback)
D1297, Review done by @campbellbarton, thx a lot :)
2015-06-11 17:20:29 +02:00
|
|
|
|
|
|
|
/* set active_file to first selected */
|
|
|
|
for (i = 0; i < numfiles; i++) {
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
if (filelist_entry_select_index_get(sfile->files, i, check_type)) {
|
File Browser Arrow Keys Navigation
Adds support for selecting/deselecting files in File Browser using the
arrow keys. All directions (up, down, left, right) are possible.
When to Select, When to Deselect?
Standard behaviour is selecting, however if we move into a block of
already selected files (meaning 2+ files are selected) we start
deselecting
Possible Selection Methods
Simple selection (arrow-key): All other files are deselected
Expand selection (Shift+arrow key): Add to/remove from existing
selection
ill-Expand selection (Ctrl+Shift+arrow key): Add to/remove from existing
selection and fill everything in-between
From which file do we start navigating?
From each available selection method (Mouse-, Walk-, All-, Border
Select), we use the last selected file. If there's no selection at all
we use the first (down/right arrow) or last (up/left arrow) file.
(Ideally, the view would automatically be set to the new selection, but
this behaviour overlaps with an other patch I've been working on, so
prefer to do that separately)
(Also tweaks color for highlighted file for better feedback)
D1297, Review done by @campbellbarton, thx a lot :)
2015-06-11 17:20:29 +02:00
|
|
|
sfile->params->active_file = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-01-21 19:28:28 +00:00
|
|
|
}
|
File Browser Arrow Keys Navigation
Adds support for selecting/deselecting files in File Browser using the
arrow keys. All directions (up, down, left, right) are possible.
When to Select, When to Deselect?
Standard behaviour is selecting, however if we move into a block of
already selected files (meaning 2+ files are selected) we start
deselecting
Possible Selection Methods
Simple selection (arrow-key): All other files are deselected
Expand selection (Shift+arrow key): Add to/remove from existing
selection
ill-Expand selection (Ctrl+Shift+arrow key): Add to/remove from existing
selection and fill everything in-between
From which file do we start navigating?
From each available selection method (Mouse-, Walk-, All-, Border
Select), we use the last selected file. If there's no selection at all
we use the first (down/right arrow) or last (up/left arrow) file.
(Ideally, the view would automatically be set to the new selection, but
this behaviour overlaps with an other patch I've been working on, so
prefer to do that separately)
(Also tweaks color for highlighted file for better feedback)
D1297, Review done by @campbellbarton, thx a lot :)
2015-06-11 17:20:29 +02:00
|
|
|
|
2015-02-17 08:52:19 +11:00
|
|
|
file_draw_check(C);
|
File Browser Arrow Keys Navigation
Adds support for selecting/deselecting files in File Browser using the
arrow keys. All directions (up, down, left, right) are possible.
When to Select, When to Deselect?
Standard behaviour is selecting, however if we move into a block of
already selected files (meaning 2+ files are selected) we start
deselecting
Possible Selection Methods
Simple selection (arrow-key): All other files are deselected
Expand selection (Shift+arrow key): Add to/remove from existing
selection
ill-Expand selection (Ctrl+Shift+arrow key): Add to/remove from existing
selection and fill everything in-between
From which file do we start navigating?
From each available selection method (Mouse-, Walk-, All-, Border
Select), we use the last selected file. If there's no selection at all
we use the first (down/right arrow) or last (up/left arrow) file.
(Ideally, the view would automatically be set to the new selection, but
this behaviour overlaps with an other patch I've been working on, so
prefer to do that separately)
(Also tweaks color for highlighted file for better feedback)
D1297, Review done by @campbellbarton, thx a lot :)
2015-06-11 17:20:29 +02:00
|
|
|
WM_event_add_mousemove(C);
|
2011-03-20 15:15:05 +00:00
|
|
|
ED_area_tag_redraw(sa);
|
File Browser Arrow Keys Navigation
Adds support for selecting/deselecting files in File Browser using the
arrow keys. All directions (up, down, left, right) are possible.
When to Select, When to Deselect?
Standard behaviour is selecting, however if we move into a block of
already selected files (meaning 2+ files are selected) we start
deselecting
Possible Selection Methods
Simple selection (arrow-key): All other files are deselected
Expand selection (Shift+arrow key): Add to/remove from existing
selection
ill-Expand selection (Ctrl+Shift+arrow key): Add to/remove from existing
selection and fill everything in-between
From which file do we start navigating?
From each available selection method (Mouse-, Walk-, All-, Border
Select), we use the last selected file. If there's no selection at all
we use the first (down/right arrow) or last (up/left arrow) file.
(Ideally, the view would automatically be set to the new selection, but
this behaviour overlaps with an other patch I've been working on, so
prefer to do that separately)
(Also tweaks color for highlighted file for better feedback)
D1297, Review done by @campbellbarton, thx a lot :)
2015-06-11 17:20:29 +02:00
|
|
|
|
2009-01-21 19:28:28 +00:00
|
|
|
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 */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "(De)select All Files";
|
|
|
|
ot->description = "Select or deselect all files";
|
|
|
|
ot->idname = "FILE_OT_select_all_toggle";
|
2009-01-21 19:28:28 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = file_select_all_exec;
|
|
|
|
ot->poll = ED_operator_file_active;
|
2009-01-21 19:28:28 +00:00
|
|
|
|
2012-10-08 03:33:02 +00:00
|
|
|
/* properties */
|
2009-01-21 19:28:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------- BOOKMARKS ----------- */
|
|
|
|
|
2015-02-11 00:09:45 +01:00
|
|
|
/* Note we could get rid of this one, but it's used by some addon so... Does not hurt keeping it around for now. */
|
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
|
|
|
{
|
2012-06-18 13:01:24 +00:00
|
|
|
SpaceFile *sfile = CTX_wm_space_file(C);
|
2015-02-17 13:09:21 +11:00
|
|
|
PropertyRNA *prop;
|
2009-01-21 19:28:28 +00:00
|
|
|
|
2015-02-17 13:09:21 +11:00
|
|
|
if ((prop = RNA_struct_find_property(op->ptr, "dir"))) {
|
2009-06-29 20:23:40 +00:00
|
|
|
char entry[256];
|
2012-06-18 13:01:24 +00:00
|
|
|
FileSelectParams *params = sfile->params;
|
2009-01-21 19:28:28 +00:00
|
|
|
|
2015-02-17 13:09:21 +11:00
|
|
|
RNA_property_string_get(op->ptr, prop, entry);
|
2009-06-29 20:23:40 +00:00
|
|
|
BLI_strncpy(params->dir, entry, sizeof(params->dir));
|
2010-10-18 06:41:16 +00:00
|
|
|
BLI_cleanup_dir(G.main->name, params->dir);
|
2015-02-11 00:09:45 +01:00
|
|
|
ED_file_change_dir(C, true);
|
2009-01-21 19:28:28 +00:00
|
|
|
|
2012-06-18 13:01:24 +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
|
|
|
{
|
2012-10-08 03:33:02 +00:00
|
|
|
PropertyRNA *prop;
|
|
|
|
|
2009-01-06 14:42:54 +00:00
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Select Directory";
|
|
|
|
ot->description = "Select a bookmarked directory";
|
|
|
|
ot->idname = "FILE_OT_select_bookmark";
|
2009-01-06 14:42:54 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = bookmark_select_exec;
|
|
|
|
ot->poll = ED_operator_file_active;
|
2009-06-29 20:23:40 +00:00
|
|
|
|
2012-10-08 03:33:02 +00:00
|
|
|
/* properties */
|
2014-01-16 21:43:22 +11:00
|
|
|
prop = RNA_def_string(ot->srna, "dir", NULL, FILE_MAXDIR, "Dir", "");
|
2012-10-08 03:33:02 +00:00
|
|
|
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
|
2009-01-18 18:24:11 +00:00
|
|
|
}
|
|
|
|
|
2010-10-15 01:36:14 +00:00
|
|
|
static int bookmark_add_exec(bContext *C, wmOperator *UNUSED(op))
|
2009-06-29 22:16:48 +00:00
|
|
|
{
|
2012-06-18 13:01:24 +00:00
|
|
|
ScrArea *sa = CTX_wm_area(C);
|
|
|
|
SpaceFile *sfile = CTX_wm_space_file(C);
|
2015-02-11 00:09:45 +01:00
|
|
|
struct FSMenu *fsmenu = ED_fsmenu_get();
|
2012-06-18 13:01:24 +00:00
|
|
|
struct FileSelectParams *params = ED_fileselect_get_params(sfile);
|
2009-06-29 22:16:48 +00:00
|
|
|
|
|
|
|
if (params->dir[0] != '\0') {
|
|
|
|
char name[FILE_MAX];
|
|
|
|
|
2015-02-11 00:09:45 +01:00
|
|
|
fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, params->dir, NULL, FS_INSERT_SAVE);
|
2014-11-23 15:54:29 +01:00
|
|
|
BLI_make_file_string("/", name, BKE_appdir_folder_id_create(BLENDER_USER_CONFIG, NULL), BLENDER_BOOKMARK_FILE);
|
2009-06-29 22:16:48 +00:00
|
|
|
fsmenu_write_file(fsmenu, name);
|
|
|
|
}
|
|
|
|
|
2015-02-11 00:09:45 +01:00
|
|
|
ED_area_tag_refresh(sa);
|
2009-06-29 22:16:48 +00:00
|
|
|
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 */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Add Bookmark";
|
|
|
|
ot->description = "Add a bookmark for the selected/active directory";
|
|
|
|
ot->idname = "FILE_OT_bookmark_add";
|
2009-06-29 22:16:48 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = bookmark_add_exec;
|
|
|
|
ot->poll = ED_operator_file_active;
|
2009-06-29 22:16:48 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2012-06-18 13:01:24 +00:00
|
|
|
ScrArea *sa = CTX_wm_area(C);
|
2015-02-11 00:09:45 +01:00
|
|
|
SpaceFile *sfile = CTX_wm_space_file(C);
|
|
|
|
struct FSMenu *fsmenu = ED_fsmenu_get();
|
|
|
|
int nentries = ED_fsmenu_get_nentries(fsmenu, FS_CATEGORY_BOOKMARKS);
|
|
|
|
|
|
|
|
PropertyRNA *prop = RNA_struct_find_property(op->ptr, "index");
|
|
|
|
|
|
|
|
if (prop) {
|
|
|
|
int index;
|
|
|
|
if (RNA_property_is_set(op->ptr, prop)) {
|
|
|
|
index = RNA_property_int_get(op->ptr, prop);
|
|
|
|
}
|
|
|
|
else { /* if index unset, use active bookmark... */
|
|
|
|
index = sfile->bookmarknr;
|
|
|
|
}
|
2014-03-17 21:48:13 +11:00
|
|
|
if ((index > -1) && (index < nentries)) {
|
2009-06-29 22:16:48 +00:00
|
|
|
char name[FILE_MAX];
|
|
|
|
|
|
|
|
fsmenu_remove_entry(fsmenu, FS_CATEGORY_BOOKMARKS, index);
|
2014-11-23 15:54:29 +01:00
|
|
|
BLI_make_file_string("/", name, BKE_appdir_folder_id_create(BLENDER_USER_CONFIG, NULL), BLENDER_BOOKMARK_FILE);
|
2009-06-29 22:16:48 +00:00
|
|
|
fsmenu_write_file(fsmenu, name);
|
2015-02-11 00:09:45 +01:00
|
|
|
ED_area_tag_refresh(sa);
|
2009-06-29 22:16:48 +00:00
|
|
|
ED_area_tag_redraw(sa);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
2013-10-08 13:16:14 +00:00
|
|
|
void FILE_OT_bookmark_delete(wmOperatorType *ot)
|
2009-06-29 22:16:48 +00:00
|
|
|
{
|
2012-10-08 03:33:02 +00:00
|
|
|
PropertyRNA *prop;
|
|
|
|
|
2009-06-29 22:16:48 +00:00
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Delete Bookmark";
|
|
|
|
ot->description = "Delete selected bookmark";
|
2013-10-08 13:16:14 +00:00
|
|
|
ot->idname = "FILE_OT_bookmark_delete";
|
2009-06-29 22:16:48 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = bookmark_delete_exec;
|
|
|
|
ot->poll = ED_operator_file_active;
|
2009-06-29 22:16:48 +00:00
|
|
|
|
2012-10-08 03:33:02 +00:00
|
|
|
/* properties */
|
|
|
|
prop = RNA_def_int(ot->srna, "index", -1, -1, 20000, "Index", "", -1, 20000);
|
|
|
|
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
|
2009-06-29 22:16:48 +00:00
|
|
|
}
|
|
|
|
|
2015-02-11 17:07:52 +01:00
|
|
|
static int bookmark_cleanup_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
|
|
|
ScrArea *sa = CTX_wm_area(C);
|
|
|
|
struct FSMenu *fsmenu = ED_fsmenu_get();
|
|
|
|
struct FSMenuEntry *fsme_next, *fsme = ED_fsmenu_get_category(fsmenu, FS_CATEGORY_BOOKMARKS);
|
|
|
|
int index;
|
|
|
|
bool changed = false;
|
|
|
|
|
|
|
|
for (index = 0; fsme; fsme = fsme_next) {
|
|
|
|
fsme_next = fsme->next;
|
|
|
|
|
|
|
|
if (!BLI_is_dir(fsme->path)) {
|
|
|
|
fsmenu_remove_entry(fsmenu, FS_CATEGORY_BOOKMARKS, index);
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (changed) {
|
|
|
|
char name[FILE_MAX];
|
|
|
|
|
|
|
|
BLI_make_file_string("/", name, BKE_appdir_folder_id_create(BLENDER_USER_CONFIG, NULL), BLENDER_BOOKMARK_FILE);
|
|
|
|
fsmenu_write_file(fsmenu, name);
|
2015-02-16 15:48:37 +01:00
|
|
|
fsmenu_refresh_bookmarks_status(fsmenu);
|
2015-02-11 17:07:52 +01:00
|
|
|
ED_area_tag_refresh(sa);
|
|
|
|
ED_area_tag_redraw(sa);
|
|
|
|
}
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FILE_OT_bookmark_cleanup(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Cleanup Bookmarks";
|
|
|
|
ot->description = "Delete all invalid bookmarks";
|
|
|
|
ot->idname = "FILE_OT_bookmark_cleanup";
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = bookmark_cleanup_exec;
|
|
|
|
ot->poll = ED_operator_file_active;
|
|
|
|
|
|
|
|
/* properties */
|
|
|
|
}
|
|
|
|
|
2015-02-11 00:09:45 +01:00
|
|
|
enum {
|
|
|
|
FILE_BOOKMARK_MOVE_TOP = -2,
|
|
|
|
FILE_BOOKMARK_MOVE_UP = -1,
|
|
|
|
FILE_BOOKMARK_MOVE_DOWN = 1,
|
|
|
|
FILE_BOOKMARK_MOVE_BOTTOM = 2,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int bookmark_move_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
ScrArea *sa = CTX_wm_area(C);
|
|
|
|
SpaceFile *sfile = CTX_wm_space_file(C);
|
|
|
|
struct FSMenu *fsmenu = ED_fsmenu_get();
|
|
|
|
struct FSMenuEntry *fsmentry = ED_fsmenu_get_category(fsmenu, FS_CATEGORY_BOOKMARKS);
|
|
|
|
const struct FSMenuEntry *fsmentry_org = fsmentry;
|
|
|
|
|
|
|
|
char fname[FILE_MAX];
|
|
|
|
|
|
|
|
const int direction = RNA_enum_get(op->ptr, "direction");
|
|
|
|
const int totitems = ED_fsmenu_get_nentries(fsmenu, FS_CATEGORY_BOOKMARKS);
|
|
|
|
const int act_index = sfile->bookmarknr;
|
|
|
|
int new_index;
|
|
|
|
|
2015-02-18 13:17:41 +01:00
|
|
|
if (totitems < 2) {
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
2015-02-11 00:09:45 +01:00
|
|
|
switch (direction) {
|
|
|
|
case FILE_BOOKMARK_MOVE_TOP:
|
|
|
|
new_index = 0;
|
|
|
|
break;
|
|
|
|
case FILE_BOOKMARK_MOVE_BOTTOM:
|
|
|
|
new_index = totitems - 1;
|
|
|
|
break;
|
|
|
|
case FILE_BOOKMARK_MOVE_UP:
|
|
|
|
case FILE_BOOKMARK_MOVE_DOWN:
|
|
|
|
default:
|
|
|
|
new_index = (totitems + act_index + direction) % totitems;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (new_index == act_index) {
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
BLI_linklist_move_item((LinkNode **)&fsmentry, act_index, new_index);
|
|
|
|
if (fsmentry != fsmentry_org) {
|
|
|
|
ED_fsmenu_set_category(fsmenu, FS_CATEGORY_BOOKMARKS, fsmentry);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Need to update active bookmark number. */
|
|
|
|
sfile->bookmarknr = new_index;
|
|
|
|
|
|
|
|
BLI_make_file_string("/", fname, BKE_appdir_folder_id_create(BLENDER_USER_CONFIG, NULL), BLENDER_BOOKMARK_FILE);
|
|
|
|
fsmenu_write_file(fsmenu, fname);
|
|
|
|
|
|
|
|
ED_area_tag_redraw(sa);
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FILE_OT_bookmark_move(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
static EnumPropertyItem slot_move[] = {
|
2016-01-21 09:05:52 +11:00
|
|
|
{FILE_BOOKMARK_MOVE_TOP, "TOP", 0, "Top", "Top of the list"},
|
2015-02-11 00:09:45 +01:00
|
|
|
{FILE_BOOKMARK_MOVE_UP, "UP", 0, "Up", ""},
|
|
|
|
{FILE_BOOKMARK_MOVE_DOWN, "DOWN", 0, "Down", ""},
|
|
|
|
{FILE_BOOKMARK_MOVE_BOTTOM, "BOTTOM", 0, "Bottom", "Bottom of the list"},
|
|
|
|
{ 0, NULL, 0, NULL, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Move Bookmark";
|
|
|
|
ot->idname = "FILE_OT_bookmark_move";
|
|
|
|
ot->description = "Move the active bookmark up/down in the list";
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
ot->poll = ED_operator_file_active;
|
|
|
|
ot->exec = bookmark_move_exec;
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
ot->flag = OPTYPE_REGISTER; /* No undo! */
|
|
|
|
|
|
|
|
RNA_def_enum(ot->srna, "direction", slot_move, 0, "Direction", "Direction to move, UP or DOWN");
|
|
|
|
}
|
|
|
|
|
2012-09-17 22:34:42 +00:00
|
|
|
static int reset_recent_exec(bContext *C, wmOperator *UNUSED(op))
|
2012-09-17 21:38:04 +00:00
|
|
|
{
|
|
|
|
ScrArea *sa = CTX_wm_area(C);
|
|
|
|
char name[FILE_MAX];
|
2015-02-11 00:09:45 +01:00
|
|
|
struct FSMenu *fsmenu = ED_fsmenu_get();
|
2012-09-17 21:38:04 +00:00
|
|
|
|
2015-02-11 00:09:45 +01:00
|
|
|
while (ED_fsmenu_get_entry(fsmenu, FS_CATEGORY_RECENT, 0) != NULL) {
|
2012-09-17 21:38:04 +00:00
|
|
|
fsmenu_remove_entry(fsmenu, FS_CATEGORY_RECENT, 0);
|
|
|
|
}
|
2014-11-23 15:54:29 +01:00
|
|
|
BLI_make_file_string("/", name, BKE_appdir_folder_id_create(BLENDER_USER_CONFIG, NULL), BLENDER_BOOKMARK_FILE);
|
2012-09-17 21:38:04 +00:00
|
|
|
fsmenu_write_file(fsmenu, name);
|
|
|
|
ED_area_tag_redraw(sa);
|
2015-02-11 00:09:45 +01:00
|
|
|
|
2012-09-17 21:38:04 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FILE_OT_reset_recent(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Reset Recent";
|
|
|
|
ot->description = "Reset Recent files";
|
|
|
|
ot->idname = "FILE_OT_reset_recent";
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = reset_recent_exec;
|
|
|
|
ot->poll = ED_operator_file_active;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-07-04 15:04:38 +00:00
|
|
|
int file_highlight_set(SpaceFile *sfile, ARegion *ar, int mx, int my)
|
2009-01-21 19:28:28 +00:00
|
|
|
{
|
2012-06-18 13:01:24 +00:00
|
|
|
View2D *v2d = &ar->v2d;
|
|
|
|
FileSelectParams *params;
|
2012-10-21 05:46:41 +00:00
|
|
|
int numfiles, origfile;
|
2011-03-14 19:56:13 +00:00
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
if (sfile == NULL || sfile->files == NULL) return 0;
|
2009-07-28 16:46:14 +00:00
|
|
|
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
numfiles = filelist_files_ensure(sfile->files);
|
2009-01-21 19:28:28 +00:00
|
|
|
params = ED_fileselect_get_params(sfile);
|
2009-03-14 18:15:28 +00:00
|
|
|
|
File Browser Arrow Keys Navigation
Adds support for selecting/deselecting files in File Browser using the
arrow keys. All directions (up, down, left, right) are possible.
When to Select, When to Deselect?
Standard behaviour is selecting, however if we move into a block of
already selected files (meaning 2+ files are selected) we start
deselecting
Possible Selection Methods
Simple selection (arrow-key): All other files are deselected
Expand selection (Shift+arrow key): Add to/remove from existing
selection
ill-Expand selection (Ctrl+Shift+arrow key): Add to/remove from existing
selection and fill everything in-between
From which file do we start navigating?
From each available selection method (Mouse-, Walk-, All-, Border
Select), we use the last selected file. If there's no selection at all
we use the first (down/right arrow) or last (up/left arrow) file.
(Ideally, the view would automatically be set to the new selection, but
this behaviour overlaps with an other patch I've been working on, so
prefer to do that separately)
(Also tweaks color for highlighted file for better feedback)
D1297, Review done by @campbellbarton, thx a lot :)
2015-06-11 17:20:29 +02:00
|
|
|
origfile = params->highlight_file;
|
2009-07-28 16:46:14 +00:00
|
|
|
|
|
|
|
mx -= ar->winrct.xmin;
|
|
|
|
my -= ar->winrct.ymin;
|
|
|
|
|
2012-08-23 18:25:45 +00:00
|
|
|
if (BLI_rcti_isect_pt(&ar->v2d.mask, mx, my)) {
|
2011-03-14 19:56:13 +00:00
|
|
|
float fx, fy;
|
File Browser Arrow Keys Navigation
Adds support for selecting/deselecting files in File Browser using the
arrow keys. All directions (up, down, left, right) are possible.
When to Select, When to Deselect?
Standard behaviour is selecting, however if we move into a block of
already selected files (meaning 2+ files are selected) we start
deselecting
Possible Selection Methods
Simple selection (arrow-key): All other files are deselected
Expand selection (Shift+arrow key): Add to/remove from existing
selection
ill-Expand selection (Ctrl+Shift+arrow key): Add to/remove from existing
selection and fill everything in-between
From which file do we start navigating?
From each available selection method (Mouse-, Walk-, All-, Border
Select), we use the last selected file. If there's no selection at all
we use the first (down/right arrow) or last (up/left arrow) file.
(Ideally, the view would automatically be set to the new selection, but
this behaviour overlaps with an other patch I've been working on, so
prefer to do that separately)
(Also tweaks color for highlighted file for better feedback)
D1297, Review done by @campbellbarton, thx a lot :)
2015-06-11 17:20:29 +02:00
|
|
|
int highlight_file;
|
2011-03-14 19:56:13 +00:00
|
|
|
|
|
|
|
UI_view2d_region_to_view(v2d, mx, my, &fx, &fy);
|
|
|
|
|
File Browser Arrow Keys Navigation
Adds support for selecting/deselecting files in File Browser using the
arrow keys. All directions (up, down, left, right) are possible.
When to Select, When to Deselect?
Standard behaviour is selecting, however if we move into a block of
already selected files (meaning 2+ files are selected) we start
deselecting
Possible Selection Methods
Simple selection (arrow-key): All other files are deselected
Expand selection (Shift+arrow key): Add to/remove from existing
selection
ill-Expand selection (Ctrl+Shift+arrow key): Add to/remove from existing
selection and fill everything in-between
From which file do we start navigating?
From each available selection method (Mouse-, Walk-, All-, Border
Select), we use the last selected file. If there's no selection at all
we use the first (down/right arrow) or last (up/left arrow) file.
(Ideally, the view would automatically be set to the new selection, but
this behaviour overlaps with an other patch I've been working on, so
prefer to do that separately)
(Also tweaks color for highlighted file for better feedback)
D1297, Review done by @campbellbarton, thx a lot :)
2015-06-11 17:20:29 +02:00
|
|
|
highlight_file = ED_fileselect_layout_offset(sfile->layout, (int)(v2d->tot.xmin + fx), (int)(v2d->tot.ymax - fy));
|
2009-07-28 16:46:14 +00:00
|
|
|
|
File Browser Arrow Keys Navigation
Adds support for selecting/deselecting files in File Browser using the
arrow keys. All directions (up, down, left, right) are possible.
When to Select, When to Deselect?
Standard behaviour is selecting, however if we move into a block of
already selected files (meaning 2+ files are selected) we start
deselecting
Possible Selection Methods
Simple selection (arrow-key): All other files are deselected
Expand selection (Shift+arrow key): Add to/remove from existing
selection
ill-Expand selection (Ctrl+Shift+arrow key): Add to/remove from existing
selection and fill everything in-between
From which file do we start navigating?
From each available selection method (Mouse-, Walk-, All-, Border
Select), we use the last selected file. If there's no selection at all
we use the first (down/right arrow) or last (up/left arrow) file.
(Ideally, the view would automatically be set to the new selection, but
this behaviour overlaps with an other patch I've been working on, so
prefer to do that separately)
(Also tweaks color for highlighted file for better feedback)
D1297, Review done by @campbellbarton, thx a lot :)
2015-06-11 17:20:29 +02:00
|
|
|
if ((highlight_file >= 0) && (highlight_file < numfiles))
|
|
|
|
params->highlight_file = highlight_file;
|
2009-07-28 16:46:14 +00:00
|
|
|
else
|
File Browser Arrow Keys Navigation
Adds support for selecting/deselecting files in File Browser using the
arrow keys. All directions (up, down, left, right) are possible.
When to Select, When to Deselect?
Standard behaviour is selecting, however if we move into a block of
already selected files (meaning 2+ files are selected) we start
deselecting
Possible Selection Methods
Simple selection (arrow-key): All other files are deselected
Expand selection (Shift+arrow key): Add to/remove from existing
selection
ill-Expand selection (Ctrl+Shift+arrow key): Add to/remove from existing
selection and fill everything in-between
From which file do we start navigating?
From each available selection method (Mouse-, Walk-, All-, Border
Select), we use the last selected file. If there's no selection at all
we use the first (down/right arrow) or last (up/left arrow) file.
(Ideally, the view would automatically be set to the new selection, but
this behaviour overlaps with an other patch I've been working on, so
prefer to do that separately)
(Also tweaks color for highlighted file for better feedback)
D1297, Review done by @campbellbarton, thx a lot :)
2015-06-11 17:20:29 +02:00
|
|
|
params->highlight_file = -1;
|
2009-07-28 16:46:14 +00:00
|
|
|
}
|
|
|
|
else
|
File Browser Arrow Keys Navigation
Adds support for selecting/deselecting files in File Browser using the
arrow keys. All directions (up, down, left, right) are possible.
When to Select, When to Deselect?
Standard behaviour is selecting, however if we move into a block of
already selected files (meaning 2+ files are selected) we start
deselecting
Possible Selection Methods
Simple selection (arrow-key): All other files are deselected
Expand selection (Shift+arrow key): Add to/remove from existing
selection
ill-Expand selection (Ctrl+Shift+arrow key): Add to/remove from existing
selection and fill everything in-between
From which file do we start navigating?
From each available selection method (Mouse-, Walk-, All-, Border
Select), we use the last selected file. If there's no selection at all
we use the first (down/right arrow) or last (up/left arrow) file.
(Ideally, the view would automatically be set to the new selection, but
this behaviour overlaps with an other patch I've been working on, so
prefer to do that separately)
(Also tweaks color for highlighted file for better feedback)
D1297, Review done by @campbellbarton, thx a lot :)
2015-06-11 17:20:29 +02:00
|
|
|
params->highlight_file = -1;
|
2009-07-28 16:46:14 +00:00
|
|
|
|
File Browser Arrow Keys Navigation
Adds support for selecting/deselecting files in File Browser using the
arrow keys. All directions (up, down, left, right) are possible.
When to Select, When to Deselect?
Standard behaviour is selecting, however if we move into a block of
already selected files (meaning 2+ files are selected) we start
deselecting
Possible Selection Methods
Simple selection (arrow-key): All other files are deselected
Expand selection (Shift+arrow key): Add to/remove from existing
selection
ill-Expand selection (Ctrl+Shift+arrow key): Add to/remove from existing
selection and fill everything in-between
From which file do we start navigating?
From each available selection method (Mouse-, Walk-, All-, Border
Select), we use the last selected file. If there's no selection at all
we use the first (down/right arrow) or last (up/left arrow) file.
(Ideally, the view would automatically be set to the new selection, but
this behaviour overlaps with an other patch I've been working on, so
prefer to do that separately)
(Also tweaks color for highlighted file for better feedback)
D1297, Review done by @campbellbarton, thx a lot :)
2015-06-11 17:20:29 +02:00
|
|
|
return (params->highlight_file != origfile);
|
2009-01-28 11:27:25 +00:00
|
|
|
}
|
|
|
|
|
2013-03-13 09:03:46 +00:00
|
|
|
static int file_highlight_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *event)
|
2009-01-28 11:27:25 +00:00
|
|
|
{
|
2012-06-18 13:01:24 +00:00
|
|
|
ARegion *ar = CTX_wm_region(C);
|
|
|
|
SpaceFile *sfile = CTX_wm_space_file(C);
|
2009-07-28 16:46:14 +00:00
|
|
|
|
2012-07-04 15:04:38 +00:00
|
|
|
if (!file_highlight_set(sfile, ar, event->x, event->y))
|
2009-07-28 16:46:14 +00:00
|
|
|
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 */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Highlight File";
|
|
|
|
ot->description = "Highlight selected file(s)";
|
|
|
|
ot->idname = "FILE_OT_highlight";
|
2009-01-21 19:28:28 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->invoke = file_highlight_invoke;
|
|
|
|
ot->poll = ED_operator_file_active;
|
2009-01-21 19:28:28 +00:00
|
|
|
}
|
|
|
|
|
2010-10-15 01:36:14 +00:00
|
|
|
int file_cancel_exec(bContext *C, wmOperator *UNUSED(unused))
|
2009-01-28 11:27:25 +00:00
|
|
|
{
|
2013-03-15 19:56:29 +00:00
|
|
|
wmWindowManager *wm = CTX_wm_manager(C);
|
2012-06-18 13:01:24 +00:00
|
|
|
SpaceFile *sfile = CTX_wm_space_file(C);
|
2010-09-17 22:12:23 +00:00
|
|
|
wmOperator *op = sfile->op;
|
2009-01-28 11:27:25 +00:00
|
|
|
|
2010-09-17 22:12:23 +00:00
|
|
|
sfile->op = NULL;
|
|
|
|
|
2013-03-15 19:56:29 +00:00
|
|
|
WM_event_fileselect_event(wm, op, EVT_FILESELECT_CANCEL);
|
2009-09-15 20:47:34 +00:00
|
|
|
|
2009-01-28 11:27:25 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
2011-02-14 17:55:27 +00:00
|
|
|
static int file_operator_poll(bContext *C)
|
2009-09-20 17:23:57 +00:00
|
|
|
{
|
|
|
|
int poll = ED_operator_file_active(C);
|
2012-06-18 13:01:24 +00:00
|
|
|
SpaceFile *sfile = CTX_wm_space_file(C);
|
2009-09-20 17:23:57 +00:00
|
|
|
|
2012-06-18 13:01:24 +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 */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Cancel File Load";
|
|
|
|
ot->description = "Cancel loading of selected file";
|
|
|
|
ot->idname = "FILE_OT_cancel";
|
2009-01-28 11:27:25 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = file_cancel_exec;
|
|
|
|
ot->poll = file_operator_poll;
|
2009-01-28 11:27:25 +00:00
|
|
|
}
|
|
|
|
|
2010-09-17 09:27:31 +00:00
|
|
|
|
2015-11-04 14:24:46 +01:00
|
|
|
void file_sfile_to_operator_ex(wmOperator *op, SpaceFile *sfile, char *filepath)
|
2010-09-17 09:27:31 +00:00
|
|
|
{
|
2015-02-17 13:09:21 +11:00
|
|
|
PropertyRNA *prop;
|
|
|
|
|
2011-02-13 03:21:27 +00:00
|
|
|
BLI_join_dirfile(filepath, FILE_MAX, sfile->params->dir, sfile->params->file); /* XXX, not real length */
|
2015-02-17 13:09:21 +11:00
|
|
|
|
|
|
|
if ((prop = RNA_struct_find_property(op->ptr, "relative_path"))) {
|
|
|
|
if (RNA_property_boolean_get(op->ptr, prop)) {
|
2010-10-18 06:41:16 +00:00
|
|
|
BLI_path_rel(filepath, G.main->name);
|
2010-09-17 09:27:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-17 13:09:21 +11:00
|
|
|
if ((prop = RNA_struct_find_property(op->ptr, "filename"))) {
|
|
|
|
RNA_property_string_set(op->ptr, prop, sfile->params->file);
|
2010-09-17 09:27:31 +00:00
|
|
|
}
|
2015-02-17 13:09:21 +11:00
|
|
|
if ((prop = RNA_struct_find_property(op->ptr, "directory"))) {
|
|
|
|
RNA_property_string_set(op->ptr, prop, sfile->params->dir);
|
2010-09-17 09:27:31 +00:00
|
|
|
}
|
2015-02-17 13:09:21 +11:00
|
|
|
if ((prop = RNA_struct_find_property(op->ptr, "filepath"))) {
|
|
|
|
RNA_property_string_set(op->ptr, prop, filepath);
|
2010-09-17 09:27:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* some ops have multiple files to select */
|
2011-08-24 14:22:41 +00:00
|
|
|
/* this is called on operators check() so clear collections first since
|
|
|
|
* they may be already set. */
|
2010-09-17 09:27:31 +00:00
|
|
|
{
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
int i, numfiles = filelist_files_ensure(sfile->files);
|
2011-03-21 03:22:33 +00:00
|
|
|
|
2015-02-17 13:09:21 +11:00
|
|
|
if ((prop = RNA_struct_find_property(op->ptr, "files"))) {
|
|
|
|
PointerRNA itemptr;
|
2012-06-17 14:16:26 +00:00
|
|
|
int num_files = 0;
|
2015-02-17 13:09:21 +11:00
|
|
|
RNA_property_collection_clear(op->ptr, prop);
|
2012-06-18 13:01:24 +00:00
|
|
|
for (i = 0; i < numfiles; i++) {
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
if (filelist_entry_select_index_get(sfile->files, i, CHECK_FILES)) {
|
|
|
|
FileDirEntry *file = filelist_file(sfile->files, i);
|
2015-02-17 13:09:21 +11:00
|
|
|
RNA_property_collection_add(op->ptr, prop, &itemptr);
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
RNA_string_set(&itemptr, "name", file->relpath);
|
2012-06-17 14:16:26 +00:00
|
|
|
num_files++;
|
2010-09-17 09:27:31 +00:00
|
|
|
}
|
|
|
|
}
|
2012-06-17 14:16:26 +00:00
|
|
|
/* make sure the file specified in the filename button is added even if no files selected */
|
|
|
|
if (0 == num_files) {
|
2015-02-17 13:09:21 +11:00
|
|
|
RNA_property_collection_add(op->ptr, prop, &itemptr);
|
2012-06-17 14:16:26 +00:00
|
|
|
RNA_string_set(&itemptr, "name", sfile->params->file);
|
|
|
|
}
|
2010-09-17 09:27:31 +00:00
|
|
|
}
|
2011-08-24 14:22:41 +00:00
|
|
|
|
2015-02-17 13:09:21 +11:00
|
|
|
if ((prop = RNA_struct_find_property(op->ptr, "dirs"))) {
|
|
|
|
PointerRNA itemptr;
|
2012-06-17 14:16:26 +00:00
|
|
|
int num_dirs = 0;
|
2015-02-17 13:09:21 +11:00
|
|
|
RNA_property_collection_clear(op->ptr, prop);
|
2012-06-18 13:01:24 +00:00
|
|
|
for (i = 0; i < numfiles; i++) {
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
if (filelist_entry_select_index_get(sfile->files, i, CHECK_DIRS)) {
|
|
|
|
FileDirEntry *file = filelist_file(sfile->files, i);
|
2015-02-17 13:09:21 +11:00
|
|
|
RNA_property_collection_add(op->ptr, prop, &itemptr);
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
RNA_string_set(&itemptr, "name", file->relpath);
|
2012-06-17 14:16:26 +00:00
|
|
|
num_dirs++;
|
2010-09-17 09:27:31 +00:00
|
|
|
}
|
|
|
|
}
|
2012-06-17 14:16:26 +00:00
|
|
|
|
|
|
|
/* make sure the directory specified in the button is added even if no directory selected */
|
|
|
|
if (0 == num_dirs) {
|
2015-02-17 13:09:21 +11:00
|
|
|
RNA_property_collection_add(op->ptr, prop, &itemptr);
|
2012-06-17 14:16:26 +00:00
|
|
|
RNA_string_set(&itemptr, "name", sfile->params->dir);
|
|
|
|
}
|
2010-09-17 09:27:31 +00:00
|
|
|
}
|
2011-03-20 15:15:05 +00:00
|
|
|
|
|
|
|
|
2010-09-17 09:27:31 +00:00
|
|
|
}
|
|
|
|
}
|
2015-11-04 14:24:46 +01:00
|
|
|
void file_sfile_to_operator(wmOperator *op, SpaceFile *sfile)
|
|
|
|
{
|
|
|
|
char filepath[FILE_MAX];
|
|
|
|
|
|
|
|
file_sfile_to_operator_ex(op, sfile, filepath);
|
|
|
|
}
|
2010-09-17 09:27:31 +00:00
|
|
|
|
|
|
|
void file_operator_to_sfile(SpaceFile *sfile, wmOperator *op)
|
|
|
|
{
|
2011-08-26 01:32:07 +00:00
|
|
|
PropertyRNA *prop;
|
|
|
|
|
2010-09-17 09:27:31 +00:00
|
|
|
/* If neither of the above are set, split the filepath back */
|
2012-06-18 13:01:24 +00:00
|
|
|
if ((prop = RNA_struct_find_property(op->ptr, "filepath"))) {
|
2011-08-26 01:32:07 +00:00
|
|
|
char filepath[FILE_MAX];
|
|
|
|
RNA_property_string_get(op->ptr, prop, filepath);
|
2011-10-15 03:56:05 +00:00
|
|
|
BLI_split_dirfile(filepath, sfile->params->dir, sfile->params->file, sizeof(sfile->params->dir), sizeof(sfile->params->file));
|
2011-08-26 01:32:07 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-06-18 13:01:24 +00:00
|
|
|
if ((prop = RNA_struct_find_property(op->ptr, "filename"))) {
|
2011-08-26 01:32:07 +00:00
|
|
|
RNA_property_string_get(op->ptr, prop, sfile->params->file);
|
|
|
|
}
|
2012-06-18 13:01:24 +00:00
|
|
|
if ((prop = RNA_struct_find_property(op->ptr, "directory"))) {
|
2011-08-26 01:32:07 +00:00
|
|
|
RNA_property_string_get(op->ptr, prop, sfile->params->dir);
|
2010-09-17 09:27:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-26 01:32:07 +00:00
|
|
|
/* we could check for relative_path property which is used when converting
|
|
|
|
* in the other direction but doesnt hurt to do this every time */
|
|
|
|
BLI_path_abs(sfile->params->dir, G.main->name);
|
|
|
|
|
2010-09-17 09:27:31 +00:00
|
|
|
/* XXX, files and dirs updates missing, not really so important though */
|
|
|
|
}
|
|
|
|
|
2015-11-04 14:24:46 +01:00
|
|
|
/**
|
|
|
|
* Use to set the file selector path from some arbitrary source.
|
|
|
|
*/
|
|
|
|
void file_sfile_filepath_set(SpaceFile *sfile, const char *filepath)
|
|
|
|
{
|
|
|
|
BLI_assert(BLI_exists(filepath));
|
|
|
|
|
|
|
|
if (BLI_is_dir(filepath)) {
|
|
|
|
BLI_strncpy(sfile->params->dir, filepath, sizeof(sfile->params->dir));
|
|
|
|
sfile->params->file[0] = '\0';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if ((sfile->params->flag & FILE_DIRSEL_ONLY) == 0) {
|
|
|
|
BLI_split_dirfile(filepath, sfile->params->dir, sfile->params->file,
|
|
|
|
sizeof(sfile->params->dir), sizeof(sfile->params->file));
|
|
|
|
}
|
2015-11-06 05:09:14 +11:00
|
|
|
else {
|
2015-11-04 14:24:46 +01:00
|
|
|
BLI_split_dir_part(filepath, sfile->params->dir, sizeof(sfile->params->dir));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-17 08:52:19 +11:00
|
|
|
void file_draw_check(bContext *C)
|
2010-09-17 09:27:31 +00:00
|
|
|
{
|
2012-06-18 13:01:24 +00:00
|
|
|
SpaceFile *sfile = CTX_wm_space_file(C);
|
|
|
|
wmOperator *op = sfile->op;
|
2012-03-24 06:38:07 +00:00
|
|
|
if (op) { /* fail on reload */
|
|
|
|
if (op->type->check) {
|
2015-11-04 14:24:46 +01:00
|
|
|
file_sfile_to_operator(op, sfile);
|
2010-09-17 15:11:12 +00:00
|
|
|
|
|
|
|
/* redraw */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (op->type->check(C, op)) {
|
2010-09-17 15:11:12 +00:00
|
|
|
file_operator_to_sfile(sfile, op);
|
|
|
|
|
|
|
|
/* redraw, else the changed settings wont get updated */
|
|
|
|
ED_area_tag_redraw(CTX_wm_area(C));
|
|
|
|
}
|
2010-09-17 09:27:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-17 08:52:19 +11:00
|
|
|
/* for use with; UI_block_func_set */
|
|
|
|
void file_draw_check_cb(bContext *C, void *UNUSED(arg1), void *UNUSED(arg2))
|
|
|
|
{
|
|
|
|
file_draw_check(C);
|
|
|
|
}
|
|
|
|
|
2014-02-03 18:55:59 +11:00
|
|
|
bool file_draw_check_exists(SpaceFile *sfile)
|
2010-09-17 09:27:31 +00:00
|
|
|
{
|
2012-03-24 06:38:07 +00:00
|
|
|
if (sfile->op) { /* fails on reload */
|
2015-02-17 13:09:21 +11:00
|
|
|
PropertyRNA *prop;
|
|
|
|
if ((prop = RNA_struct_find_property(sfile->op->ptr, "check_existing"))) {
|
|
|
|
if (RNA_property_boolean_get(sfile->op->ptr, prop)) {
|
2010-09-17 15:11:12 +00:00
|
|
|
char filepath[FILE_MAX];
|
2011-02-13 03:21:27 +00:00
|
|
|
BLI_join_dirfile(filepath, sizeof(filepath), sfile->params->dir, sfile->params->file);
|
2012-03-24 06:38:07 +00:00
|
|
|
if (BLI_is_file(filepath)) {
|
2014-04-01 11:34:00 +11:00
|
|
|
return true;
|
2010-09-17 15:11:12 +00:00
|
|
|
}
|
2010-09-17 09:27:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-01 11:34:00 +11:00
|
|
|
return false;
|
2010-09-17 09:27:31 +00:00
|
|
|
}
|
|
|
|
|
2010-01-20 08:57:26 +00:00
|
|
|
int file_exec(bContext *C, wmOperator *exec_op)
|
2009-01-28 11:27:25 +00:00
|
|
|
{
|
2013-03-15 19:56:29 +00:00
|
|
|
wmWindowManager *wm = CTX_wm_manager(C);
|
2012-06-18 13:01:24 +00:00
|
|
|
SpaceFile *sfile = CTX_wm_space_file(C);
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
const struct FileDirEntry *file = filelist_file(sfile->files, sfile->params->active_file);
|
2010-06-26 08:53:29 +00:00
|
|
|
char filepath[FILE_MAX];
|
2015-07-09 18:40:34 +02:00
|
|
|
|
|
|
|
/* directory change */
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
if (file && (file->typeflag & FILE_TYPE_DIR)) {
|
2015-08-24 09:59:04 +02:00
|
|
|
if (!file->relpath) {
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
if (FILENAME_IS_PARENT(file->relpath)) {
|
2015-07-09 19:48:03 +02:00
|
|
|
BLI_parent_dir(sfile->params->dir);
|
|
|
|
}
|
2015-08-24 09:59:04 +02:00
|
|
|
else {
|
2015-07-09 19:48:03 +02:00
|
|
|
BLI_cleanup_dir(G.main->name, sfile->params->dir);
|
2016-01-10 09:45:57 +01:00
|
|
|
strncat(sfile->params->dir, file->relpath, sizeof(sfile->params->dir));
|
2015-07-09 19:48:03 +02:00
|
|
|
BLI_add_slash(sfile->params->dir);
|
|
|
|
}
|
2015-07-09 18:40:34 +02:00
|
|
|
|
|
|
|
ED_file_change_dir(C, false);
|
|
|
|
}
|
|
|
|
/* opening file - sends events now, so things get handled on windowqueue level */
|
|
|
|
else if (sfile->op) {
|
2012-06-18 13:01:24 +00:00
|
|
|
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,
|
2012-03-03 16:31:46 +00:00
|
|
|
* to prevent closing when doubleclicking on .. item */
|
2010-01-20 08:57:26 +00:00
|
|
|
if (RNA_boolean_get(exec_op->ptr, "need_active")) {
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
const int numfiles = filelist_files_ensure(sfile->files);
|
2012-06-18 13:01:24 +00:00
|
|
|
int i, active = 0;
|
2010-01-20 08:57:26 +00:00
|
|
|
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
for (i = 0; i < numfiles; i++) {
|
|
|
|
if (filelist_entry_select_index_get(sfile->files, i, CHECK_ALL)) {
|
2012-06-18 13:01:24 +00:00
|
|
|
active = 1;
|
2011-03-20 15:15:05 +00:00
|
|
|
break;
|
2010-01-20 08:57:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (active == 0)
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
2009-01-28 11:27:25 +00:00
|
|
|
sfile->op = NULL;
|
2009-09-13 08:08:50 +00:00
|
|
|
|
2015-11-04 14:24:46 +01:00
|
|
|
file_sfile_to_operator_ex(op, sfile, filepath);
|
2009-09-16 18:07:49 +00:00
|
|
|
|
2012-09-17 02:19:41 +00:00
|
|
|
if (BLI_exists(sfile->params->dir)) {
|
2015-02-11 00:09:45 +01:00
|
|
|
fsmenu_insert_entry(ED_fsmenu_get(), FS_CATEGORY_RECENT, sfile->params->dir, NULL,
|
|
|
|
FS_INSERT_SAVE | FS_INSERT_FIRST);
|
2012-09-17 02:19:41 +00:00
|
|
|
}
|
2011-09-22 15:46:43 +00:00
|
|
|
|
2015-02-11 00:09:45 +01:00
|
|
|
BLI_make_file_string(G.main->name, filepath, BKE_appdir_folder_id_create(BLENDER_USER_CONFIG, NULL),
|
|
|
|
BLENDER_BOOKMARK_FILE);
|
|
|
|
fsmenu_write_file(ED_fsmenu_get(), filepath);
|
2013-03-15 19:56:29 +00:00
|
|
|
WM_event_fileselect_event(wm, op, EVT_FILESELECT_EXEC);
|
2009-09-15 20:47:34 +00:00
|
|
|
|
2009-01-28 11:27:25 +00:00
|
|
|
}
|
2015-07-09 18:40:34 +02: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
|
|
|
{
|
2012-03-23 22:31:14 +00:00
|
|
|
PropertyRNA *prop;
|
|
|
|
|
2009-01-28 11:27:25 +00:00
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Execute File Window";
|
|
|
|
ot->description = "Execute selected file";
|
|
|
|
ot->idname = "FILE_OT_execute";
|
2009-01-28 11:27:25 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = file_exec;
|
|
|
|
ot->poll = file_operator_poll;
|
2012-10-08 03:33:02 +00:00
|
|
|
|
|
|
|
/* properties */
|
2012-03-23 22:31:14 +00:00
|
|
|
prop = RNA_def_boolean(ot->srna, "need_active", 0, "Need Active",
|
|
|
|
"Only execute if there's an active selected file in the file list");
|
|
|
|
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
|
2009-01-28 11:27:25 +00:00
|
|
|
}
|
|
|
|
|
2009-02-14 14:25:48 +00:00
|
|
|
|
2010-10-15 01:36:14 +00:00
|
|
|
int file_parent_exec(bContext *C, wmOperator *UNUSED(unused))
|
2009-02-10 17:53:10 +00:00
|
|
|
{
|
2012-06-18 13:01:24 +00:00
|
|
|
SpaceFile *sfile = CTX_wm_space_file(C);
|
2009-02-10 17:53:10 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (sfile->params) {
|
2014-01-31 03:28:53 +11:00
|
|
|
if (BLI_parent_dir(sfile->params->dir)) {
|
2010-10-18 06:41:16 +00:00
|
|
|
BLI_cleanup_dir(G.main->name, sfile->params->dir);
|
2014-04-21 16:49:35 +02:00
|
|
|
/* if not browsing in .blend file, we still want to check whether the path is a directory */
|
|
|
|
if (sfile->params->type == FILE_LOADLIB) {
|
2015-08-18 13:18:50 +02:00
|
|
|
char tdir[FILE_MAX];
|
|
|
|
if (BLO_library_path_explode(sfile->params->dir, tdir, NULL, NULL)) {
|
2015-02-11 00:09:45 +01:00
|
|
|
ED_file_change_dir(C, false);
|
2014-04-21 16:49:35 +02:00
|
|
|
}
|
|
|
|
else {
|
2015-02-11 00:09:45 +01:00
|
|
|
ED_file_change_dir(C, true);
|
2014-04-21 16:49:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2015-02-11 00:09:45 +01:00
|
|
|
ED_file_change_dir(C, true);
|
2014-04-21 16:49:35 +02:00
|
|
|
}
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
if (sfile->params->recursion_level > 1) {
|
|
|
|
/* Disable 'dirtree' recursion when going up in tree. */
|
|
|
|
sfile->params->recursion_level = 0;
|
|
|
|
filelist_setrecursion(sfile->files, sfile->params->recursion_level);
|
|
|
|
}
|
2012-06-18 13:01:24 +00:00
|
|
|
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL);
|
2009-07-10 19:19:54 +00:00
|
|
|
}
|
2012-10-21 05:46:41 +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 */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Parent File";
|
|
|
|
ot->description = "Move to parent directory";
|
|
|
|
ot->idname = "FILE_OT_parent";
|
2009-02-10 17:53:10 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = file_parent_exec;
|
|
|
|
ot->poll = ED_operator_file_active; /* <- important, handler is on window level */
|
2009-02-10 17:53:10 +00:00
|
|
|
}
|
|
|
|
|
2009-03-12 06:40:03 +00:00
|
|
|
|
2011-02-14 17:55:27 +00:00
|
|
|
static int file_refresh_exec(bContext *C, wmOperator *UNUSED(unused))
|
2009-03-12 06:40:03 +00:00
|
|
|
{
|
2013-03-15 19:56:29 +00:00
|
|
|
wmWindowManager *wm = CTX_wm_manager(C);
|
2012-06-18 13:01:24 +00:00
|
|
|
SpaceFile *sfile = CTX_wm_space_file(C);
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
ScrArea *sa = CTX_wm_area(C);
|
2015-02-11 00:09:45 +01:00
|
|
|
struct FSMenu *fsmenu = ED_fsmenu_get();
|
2010-04-19 19:29:40 +00:00
|
|
|
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
ED_fileselect_clear(wm, sa, sfile);
|
2009-07-07 07:25:44 +00:00
|
|
|
|
2012-05-18 12:49:25 +00:00
|
|
|
/* refresh system directory menu */
|
|
|
|
fsmenu_refresh_system_category(fsmenu);
|
|
|
|
|
2012-06-18 13:01:24 +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 */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Previous Folder";
|
|
|
|
ot->description = "Move to previous folder";
|
|
|
|
ot->idname = "FILE_OT_previous";
|
2009-07-07 07:25:44 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = file_previous_exec;
|
|
|
|
ot->poll = ED_operator_file_active; /* <- important, handler is on window level */
|
2009-07-07 07:25:44 +00:00
|
|
|
}
|
|
|
|
|
2010-10-15 01:36:14 +00:00
|
|
|
int file_previous_exec(bContext *C, wmOperator *UNUSED(unused))
|
2009-07-07 07:25:44 +00:00
|
|
|
{
|
2012-06-18 13:01:24 +00:00
|
|
|
SpaceFile *sfile = CTX_wm_space_file(C);
|
2009-07-07 07:25:44 +00:00
|
|
|
|
2012-03-24 06:38:07 +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);
|
|
|
|
|
2015-02-11 00:09:45 +01:00
|
|
|
ED_file_change_dir(C, true);
|
2009-06-29 20:23:40 +00:00
|
|
|
}
|
2012-06-18 13:01:24 +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 */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Next Folder";
|
|
|
|
ot->description = "Move to next folder";
|
|
|
|
ot->idname = "FILE_OT_next";
|
2009-07-07 07:25:44 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2010-10-15 01:36:14 +00:00
|
|
|
int file_next_exec(bContext *C, wmOperator *UNUSED(unused))
|
2009-07-07 07:25:44 +00:00
|
|
|
{
|
2012-06-18 13:01:24 +00:00
|
|
|
SpaceFile *sfile = CTX_wm_space_file(C);
|
2012-03-24 06:38:07 +00:00
|
|
|
if (sfile->params) {
|
2010-03-27 12:14:51 +00:00
|
|
|
if (!sfile->folders_next)
|
2009-07-07 07:25:44 +00:00
|
|
|
sfile->folders_next = folderlist_new();
|
|
|
|
|
|
|
|
folderlist_pushdir(sfile->folders_prev, sfile->params->dir);
|
|
|
|
folderlist_popdir(sfile->folders_next, sfile->params->dir);
|
|
|
|
|
2011-04-25 09:28:52 +00:00
|
|
|
// update folders_prev so we can check for it in folderlist_clear_next()
|
2009-07-07 07:25:44 +00:00
|
|
|
folderlist_pushdir(sfile->folders_prev, sfile->params->dir);
|
|
|
|
|
2015-02-11 00:09:45 +01:00
|
|
|
ED_file_change_dir(C, true);
|
2012-10-21 05:46:41 +00:00
|
|
|
}
|
2012-06-18 13:01:24 +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
|
|
|
|
2010-05-08 21:02:22 +00:00
|
|
|
|
|
|
|
/* only meant for timer usage */
|
2013-03-13 09:03:46 +00:00
|
|
|
static int file_smoothscroll_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *event)
|
2010-05-08 21:02:22 +00:00
|
|
|
{
|
2010-05-10 08:57:58 +00:00
|
|
|
ScrArea *sa = CTX_wm_area(C);
|
2012-06-18 13:01:24 +00:00
|
|
|
SpaceFile *sfile = CTX_wm_space_file(C);
|
|
|
|
ARegion *ar, *oldar = CTX_wm_region(C);
|
2011-03-14 19:56:13 +00:00
|
|
|
int offset;
|
|
|
|
int numfiles, numfiles_layout;
|
2010-05-08 21:02:22 +00:00
|
|
|
int edit_idx = 0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* escape if not our timer */
|
2012-06-18 13:01:24 +00:00
|
|
|
if (sfile->smoothscroll_timer == NULL || sfile->smoothscroll_timer != event->customdata)
|
2010-05-08 21:02:22 +00:00
|
|
|
return OPERATOR_PASS_THROUGH;
|
|
|
|
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
numfiles = filelist_files_ensure(sfile->files);
|
2010-05-08 21:02:22 +00:00
|
|
|
|
|
|
|
/* check if we are editing a name */
|
2012-06-18 13:01:24 +00:00
|
|
|
for (i = 0; i < numfiles; ++i) {
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
if (filelist_entry_select_index_get(sfile->files, i, CHECK_ALL) ) {
|
2012-06-18 13:01:24 +00:00
|
|
|
edit_idx = i;
|
2010-05-08 21:02:22 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if we are not editing, we are done */
|
2012-06-18 13:01:24 +00:00
|
|
|
if (0 == edit_idx) {
|
2010-05-08 21:02:22 +00:00
|
|
|
WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), sfile->smoothscroll_timer);
|
2012-06-18 13:01:24 +00:00
|
|
|
sfile->smoothscroll_timer = NULL;
|
2010-05-08 21:02:22 +00:00
|
|
|
return OPERATOR_PASS_THROUGH;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we need the correct area for scrolling */
|
2010-05-10 08:57:58 +00:00
|
|
|
ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW);
|
2010-05-08 21:02:22 +00:00
|
|
|
if (!ar || ar->regiontype != RGN_TYPE_WINDOW) {
|
|
|
|
WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), sfile->smoothscroll_timer);
|
2012-06-18 13:01:24 +00:00
|
|
|
sfile->smoothscroll_timer = NULL;
|
2010-05-08 21:02:22 +00:00
|
|
|
return OPERATOR_PASS_THROUGH;
|
|
|
|
}
|
|
|
|
|
2011-04-10 09:37:04 +00:00
|
|
|
offset = ED_fileselect_layout_offset(sfile->layout, (int)ar->v2d.cur.xmin, (int)-ar->v2d.cur.ymax);
|
2012-06-18 13:01:24 +00:00
|
|
|
if (offset < 0) offset = 0;
|
2010-05-08 21:02:22 +00:00
|
|
|
|
|
|
|
/* scroll offset is the first file in the row/column we are editing in */
|
|
|
|
if (sfile->scroll_offset == 0) {
|
|
|
|
if (sfile->layout->flag & FILE_LAYOUT_HOR) {
|
2012-06-18 13:01:24 +00:00
|
|
|
sfile->scroll_offset = (edit_idx / sfile->layout->rows) * sfile->layout->rows;
|
2010-05-08 21:02:22 +00:00
|
|
|
if (sfile->scroll_offset <= offset) sfile->scroll_offset -= sfile->layout->rows;
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-06-18 13:01:24 +00:00
|
|
|
sfile->scroll_offset = (edit_idx / sfile->layout->columns) * sfile->layout->columns;
|
2010-05-08 21:02:22 +00:00
|
|
|
if (sfile->scroll_offset <= offset) sfile->scroll_offset -= sfile->layout->columns;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
numfiles_layout = ED_fileselect_layout_numfiles(sfile->layout, ar);
|
|
|
|
|
|
|
|
/* check if we have reached our final scroll position */
|
|
|
|
if ( (sfile->scroll_offset >= offset) && (sfile->scroll_offset < offset + numfiles_layout) ) {
|
|
|
|
WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), sfile->smoothscroll_timer);
|
2012-06-18 13:01:24 +00:00
|
|
|
sfile->smoothscroll_timer = NULL;
|
2010-05-08 21:02:22 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
2010-05-10 08:57:58 +00:00
|
|
|
/* temporarily set context to the main window region,
|
|
|
|
* so the scroll operators work */
|
|
|
|
CTX_wm_region_set(C, ar);
|
|
|
|
|
2010-05-08 21:02:22 +00:00
|
|
|
/* scroll one step in the desired direction */
|
|
|
|
if (sfile->scroll_offset < offset) {
|
|
|
|
if (sfile->layout->flag & FILE_LAYOUT_HOR) {
|
|
|
|
WM_operator_name_call(C, "VIEW2D_OT_scroll_left", 0, NULL);
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else {
|
2010-05-08 21:02:22 +00:00
|
|
|
WM_operator_name_call(C, "VIEW2D_OT_scroll_up", 0, NULL);
|
|
|
|
}
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else {
|
2010-05-08 21:02:22 +00:00
|
|
|
if (sfile->layout->flag & FILE_LAYOUT_HOR) {
|
|
|
|
WM_operator_name_call(C, "VIEW2D_OT_scroll_right", 0, NULL);
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else {
|
2010-05-08 21:02:22 +00:00
|
|
|
WM_operator_name_call(C, "VIEW2D_OT_scroll_down", 0, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-30 07:48:54 +10:00
|
|
|
ED_region_tag_redraw(ar);
|
2010-05-08 21:02:22 +00:00
|
|
|
|
2010-05-10 08:57:58 +00:00
|
|
|
/* and restore context */
|
|
|
|
CTX_wm_region_set(C, oldar);
|
|
|
|
|
2010-05-08 21:02:22 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FILE_OT_smoothscroll(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Smooth Scroll";
|
|
|
|
ot->idname = "FILE_OT_smoothscroll";
|
|
|
|
ot->description = "Smooth scroll to make editable file visible";
|
2010-05-08 21:02:22 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->invoke = file_smoothscroll_invoke;
|
2010-05-08 21:02:22 +00:00
|
|
|
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->poll = ED_operator_file_active;
|
2010-05-08 21:02:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-11-04 14:24:46 +01:00
|
|
|
static int filepath_drop_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
SpaceFile *sfile = CTX_wm_space_file(C);
|
|
|
|
|
|
|
|
if (sfile) {
|
|
|
|
char filepath[FILE_MAX];
|
|
|
|
|
|
|
|
RNA_string_get(op->ptr, "filepath", filepath);
|
|
|
|
if (!BLI_exists(filepath)) {
|
|
|
|
BKE_report(op->reports, RPT_ERROR, "File does not exist");
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
file_sfile_filepath_set(sfile, filepath);
|
|
|
|
|
|
|
|
if (sfile->op) {
|
|
|
|
file_sfile_to_operator(sfile->op, sfile);
|
|
|
|
file_draw_check(C);
|
|
|
|
}
|
|
|
|
|
|
|
|
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_PARAMS, NULL);
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FILE_OT_filepath_drop(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
ot->name = "File Selector Drop";
|
|
|
|
ot->description = "";
|
|
|
|
ot->idname = "FILE_OT_filepath_drop";
|
|
|
|
|
|
|
|
ot->exec = filepath_drop_exec;
|
|
|
|
ot->poll = WM_operator_winactive;
|
|
|
|
|
|
|
|
RNA_def_string_file_path(ot->srna, "filepath", "Path", FILE_MAX, "", "");
|
|
|
|
}
|
|
|
|
|
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.
|
2012-03-03 16:31:46 +00:00
|
|
|
* The actual name is returned in 'name', 'folder' contains the complete path, including the new folder name.
|
|
|
|
*/
|
2012-06-18 13:01:24 +00:00
|
|
|
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);
|
2011-02-13 03:21:27 +00:00
|
|
|
BLI_join_dirfile(folder, FILE_MAX, parent, name); /* XXX, not real length */
|
2009-12-07 23:47:37 +00:00
|
|
|
/* check whether folder with the name already exists, in this case
|
2012-03-03 16:31:46 +00:00
|
|
|
* add number to the name. Check length of generated name to avoid
|
|
|
|
* crazy case of huge number of folders each named 'New Folder (x)' */
|
2012-06-18 13:01:24 +00:00
|
|
|
while (BLI_exists(folder) && (len < FILE_MAXFILE)) {
|
2009-12-07 23:47:37 +00:00
|
|
|
len = BLI_snprintf(name, FILE_MAXFILE, "New Folder(%d)", i);
|
2011-02-13 03:21:27 +00:00
|
|
|
BLI_join_dirfile(folder, FILE_MAX, parent, name); /* XXX, not real length */
|
2009-12-07 23:47:37 +00:00
|
|
|
i++;
|
|
|
|
}
|
2009-07-10 17:05:04 +00:00
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
return (len < FILE_MAXFILE);
|
2009-12-07 23:47:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int file_directory_new_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
char name[FILE_MAXFILE];
|
|
|
|
char path[FILE_MAX];
|
2015-07-14 18:48:51 +02:00
|
|
|
bool generate_name = true;
|
2015-02-17 13:09:21 +11:00
|
|
|
PropertyRNA *prop;
|
2010-11-06 16:09:12 +00:00
|
|
|
|
2013-03-15 19:56:29 +00:00
|
|
|
wmWindowManager *wm = CTX_wm_manager(C);
|
2012-06-18 13:01:24 +00:00
|
|
|
SpaceFile *sfile = CTX_wm_space_file(C);
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
ScrArea *sa = CTX_wm_area(C);
|
2009-07-10 17:05:04 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!sfile->params) {
|
2012-04-29 15:47:02 +00:00
|
|
|
BKE_report(op->reports, RPT_WARNING, "No parent directory given");
|
2009-12-07 23:47:37 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
2010-11-06 16:09:12 +00:00
|
|
|
path[0] = '\0';
|
|
|
|
|
2015-02-17 13:09:21 +11:00
|
|
|
if ((prop = RNA_struct_find_property(op->ptr, "directory"))) {
|
|
|
|
RNA_property_string_get(op->ptr, prop, path);
|
2015-07-14 18:48:51 +02:00
|
|
|
if (path[0] != '\0') {
|
|
|
|
generate_name = false;
|
|
|
|
}
|
2009-12-07 23:47:37 +00:00
|
|
|
}
|
2010-11-06 16:09:12 +00:00
|
|
|
|
|
|
|
if (generate_name) {
|
|
|
|
/* create a new, non-existing folder name */
|
|
|
|
if (!new_folder_path(sfile->params->dir, path, name)) {
|
2012-10-26 17:32:50 +00:00
|
|
|
BKE_report(op->reports, RPT_ERROR, "Could not create new folder name");
|
2010-11-06 16:09:12 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
}
|
2015-07-14 18:48:51 +02:00
|
|
|
else { /* We assume we are able to generate a valid name! */
|
|
|
|
char org_path[FILE_MAX];
|
|
|
|
|
|
|
|
BLI_strncpy(org_path, path, sizeof(org_path));
|
|
|
|
if (BLI_path_make_safe(path)) {
|
|
|
|
BKE_reportf(op->reports, RPT_WARNING, "'%s' given path is OS-invalid, creating '%s' path instead",
|
|
|
|
org_path, path);
|
|
|
|
}
|
|
|
|
}
|
2010-11-06 16:09:12 +00:00
|
|
|
|
|
|
|
/* create the file */
|
2016-02-03 16:37:02 +11:00
|
|
|
errno = 0;
|
|
|
|
if (!BLI_dir_create_recursive(path) ||
|
|
|
|
/* Should no more be needed,
|
|
|
|
* now that BLI_dir_create_recursive returns a success state - but kept just in case. */
|
|
|
|
!BLI_exists(path))
|
|
|
|
{
|
|
|
|
BKE_reportf(op->reports, RPT_ERROR,
|
|
|
|
"Could not create new folder: %s",
|
|
|
|
errno ? strerror(errno) : "unknown error");
|
2015-07-14 18:48:51 +02:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
2009-12-07 23:47:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* now remember file to jump into editing */
|
|
|
|
BLI_strncpy(sfile->params->renamefile, name, FILE_MAXFILE);
|
2010-05-08 21:02:22 +00:00
|
|
|
|
|
|
|
/* set timer to smoothly view newly generated file */
|
2014-04-30 07:48:54 +10:00
|
|
|
sfile->smoothscroll_timer = WM_event_add_timer(wm, CTX_wm_window(C), TIMER1, 1.0 / 1000.0); /* max 30 frs/sec */
|
2012-06-18 13:01:24 +00:00
|
|
|
sfile->scroll_offset = 0;
|
2010-05-08 21:02:22 +00:00
|
|
|
|
|
|
|
/* reload dir to make sure we're seeing what's in the directory */
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
ED_fileselect_clear(wm, sa, sfile);
|
2013-11-22 01:35:38 +01:00
|
|
|
|
|
|
|
if (RNA_boolean_get(op->ptr, "open")) {
|
|
|
|
BLI_strncpy(sfile->params->dir, path, sizeof(sfile->params->dir));
|
2015-02-11 00:09:45 +01:00
|
|
|
ED_file_change_dir(C, true);
|
2013-11-22 01:35:38 +01:00
|
|
|
}
|
|
|
|
|
2012-06-18 13:01:24 +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)
|
|
|
|
{
|
2012-10-08 03:33:02 +00:00
|
|
|
PropertyRNA *prop;
|
|
|
|
|
2009-07-10 17:05:04 +00:00
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Create New Directory";
|
|
|
|
ot->description = "Create a new directory";
|
|
|
|
ot->idname = "FILE_OT_directory_new";
|
2009-07-10 17:05:04 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->invoke = WM_operator_confirm;
|
|
|
|
ot->exec = file_directory_new_exec;
|
|
|
|
ot->poll = ED_operator_file_active; /* <- important, handler is on window level */
|
2010-11-06 16:09:12 +00:00
|
|
|
|
2014-01-16 21:43:22 +11:00
|
|
|
prop = RNA_def_string_dir_path(ot->srna, "directory", NULL, FILE_MAX, "Directory", "Name of new directory");
|
2012-10-08 03:33:02 +00:00
|
|
|
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
|
2013-11-22 01:35:38 +01:00
|
|
|
prop = RNA_def_boolean(ot->srna, "open", false, "Open", "Open new directory");
|
|
|
|
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
|
2009-07-10 17:05:04 +00:00
|
|
|
}
|
|
|
|
|
2010-11-06 16:09:12 +00:00
|
|
|
|
2015-07-14 18:48:51 +02:00
|
|
|
/* TODO This should go to BLI_path_utils. */
|
2010-11-06 16:09:12 +00:00
|
|
|
static void file_expand_directory(bContext *C)
|
2009-07-10 17:05:04 +00:00
|
|
|
{
|
2012-06-18 13:01:24 +00:00
|
|
|
SpaceFile *sfile = CTX_wm_space_file(C);
|
2009-07-10 17:05:04 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (sfile->params) {
|
2012-05-17 10:07:29 +00:00
|
|
|
/* TODO, what about // when relbase isn't valid? */
|
2012-08-29 10:32:38 +00:00
|
|
|
if (G.relbase_valid && BLI_path_is_rel(sfile->params->dir)) {
|
2012-05-17 10:07:29 +00:00
|
|
|
BLI_path_abs(sfile->params->dir, G.main->name);
|
|
|
|
}
|
|
|
|
else if (sfile->params->dir[0] == '~') {
|
2012-06-18 13:01:24 +00:00
|
|
|
char tmpstr[sizeof(sfile->params->dir) - 1];
|
|
|
|
BLI_strncpy(tmpstr, sfile->params->dir + 1, sizeof(tmpstr));
|
2014-11-23 15:54:29 +01:00
|
|
|
BLI_join_dirfile(sfile->params->dir, sizeof(sfile->params->dir), BKE_appdir_folder_default(), tmpstr);
|
2009-07-10 17:05:04 +00:00
|
|
|
}
|
2010-05-07 23:34:03 +00:00
|
|
|
|
2012-01-30 10:04:27 +00:00
|
|
|
else if (sfile->params->dir[0] == '\0')
|
|
|
|
#ifndef WIN32
|
|
|
|
{
|
|
|
|
sfile->params->dir[0] = '/';
|
|
|
|
sfile->params->dir[1] = '\0';
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
{
|
2009-07-10 19:52:00 +00:00
|
|
|
get_default_root(sfile->params->dir);
|
2011-08-05 06:06:15 +00:00
|
|
|
}
|
|
|
|
/* change "C:" --> "C:\", [#28102] */
|
2013-03-01 14:47:06 +00:00
|
|
|
else if ((isalpha(sfile->params->dir[0]) &&
|
|
|
|
(sfile->params->dir[1] == ':')) &&
|
|
|
|
(sfile->params->dir[2] == '\0'))
|
|
|
|
{
|
2012-06-18 13:01:24 +00:00
|
|
|
sfile->params->dir[2] = '\\';
|
|
|
|
sfile->params->dir[3] = '\0';
|
2011-08-05 06:06:15 +00:00
|
|
|
}
|
2014-04-21 16:49:35 +02:00
|
|
|
else if (BLI_path_is_unc(sfile->params->dir)) {
|
|
|
|
BLI_cleanup_unc(sfile->params->dir, FILE_MAX_LIBEXTRA);
|
|
|
|
}
|
2009-07-10 19:52:00 +00:00
|
|
|
#endif
|
2010-11-06 16:09:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-14 18:48:51 +02:00
|
|
|
/* TODO check we still need this, it's annoying to have OS-specific code here... :/ */
|
2014-04-21 16:49:35 +02:00
|
|
|
#if defined(WIN32)
|
|
|
|
static bool can_create_dir(const char *dir)
|
|
|
|
{
|
|
|
|
/* for UNC paths we need to check whether the parent of the new
|
|
|
|
* directory is a proper directory itself and not a share or the
|
|
|
|
* UNC root (server name) itself. Calling BLI_is_dir does this
|
|
|
|
*/
|
|
|
|
if (BLI_path_is_unc(dir)) {
|
|
|
|
char parent[PATH_MAX];
|
|
|
|
BLI_strncpy(parent, dir, PATH_MAX);
|
|
|
|
BLI_parent_dir(parent);
|
|
|
|
return BLI_is_dir(parent);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-11-22 01:35:38 +01:00
|
|
|
void file_directory_enter_handle(bContext *C, void *UNUSED(arg_unused), void *UNUSED(arg_but))
|
2010-11-06 16:09:12 +00:00
|
|
|
{
|
2012-06-18 13:01:24 +00:00
|
|
|
SpaceFile *sfile = CTX_wm_space_file(C);
|
2010-11-06 16:09:12 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (sfile->params) {
|
2010-11-06 16:09:12 +00:00
|
|
|
file_expand_directory(C);
|
|
|
|
|
2011-12-12 18:06:36 +00:00
|
|
|
/* special case, user may have pasted a filepath into the directory */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (BLI_is_file(sfile->params->dir)) {
|
2011-01-13 07:25:18 +00:00
|
|
|
char path[sizeof(sfile->params->dir)];
|
|
|
|
BLI_strncpy(path, sfile->params->dir, sizeof(path));
|
2011-10-15 03:56:05 +00:00
|
|
|
BLI_split_dirfile(path, sfile->params->dir, sfile->params->file, sizeof(sfile->params->dir), sizeof(sfile->params->file));
|
2011-01-13 07:25:18 +00:00
|
|
|
}
|
2010-11-06 16:09:12 +00:00
|
|
|
|
2010-10-18 06:41:16 +00:00
|
|
|
BLI_cleanup_dir(G.main->name, sfile->params->dir);
|
2009-10-15 11:11:52 +00:00
|
|
|
|
2013-11-22 01:35:38 +01:00
|
|
|
if (BLI_exists(sfile->params->dir)) {
|
|
|
|
/* if directory exists, enter it immediately */
|
2015-02-11 00:09:45 +01:00
|
|
|
ED_file_change_dir(C, true);
|
2009-07-10 17:05:04 +00:00
|
|
|
|
2013-11-22 01:35:38 +01:00
|
|
|
/* don't do for now because it selects entire text instead of
|
|
|
|
* placing cursor at the end */
|
|
|
|
/* UI_textbutton_activate_but(C, but); */
|
|
|
|
}
|
2014-04-21 16:49:35 +02:00
|
|
|
#if defined(WIN32)
|
|
|
|
else if (!can_create_dir(sfile->params->dir)) {
|
|
|
|
const char *lastdir = folderlist_peeklastdir(sfile->folders_prev);
|
|
|
|
if (lastdir)
|
|
|
|
BLI_strncpy(sfile->params->dir, lastdir, sizeof(sfile->params->dir));
|
|
|
|
}
|
|
|
|
#endif
|
2013-11-22 01:35:38 +01:00
|
|
|
else {
|
|
|
|
const char *lastdir = folderlist_peeklastdir(sfile->folders_prev);
|
2009-07-10 17:05:04 +00:00
|
|
|
|
2013-11-22 01:35:38 +01:00
|
|
|
/* if not, ask to create it and enter if confirmed */
|
2014-07-11 15:07:55 +10:00
|
|
|
wmOperatorType *ot = WM_operatortype_find("FILE_OT_directory_new", false);
|
2013-11-22 01:35:38 +01:00
|
|
|
PointerRNA ptr;
|
2014-07-11 15:07:55 +10:00
|
|
|
WM_operator_properties_create_ptr(&ptr, ot);
|
2013-11-22 01:35:38 +01:00
|
|
|
RNA_string_set(&ptr, "directory", sfile->params->dir);
|
|
|
|
RNA_boolean_set(&ptr, "open", true);
|
2013-11-22 14:35:34 +01:00
|
|
|
|
2013-11-22 01:35:38 +01:00
|
|
|
if (lastdir)
|
|
|
|
BLI_strncpy(sfile->params->dir, lastdir, sizeof(sfile->params->dir));
|
2013-11-22 14:35:34 +01:00
|
|
|
|
|
|
|
|
2014-07-11 15:07:55 +10:00
|
|
|
WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &ptr);
|
2013-11-22 01:35:38 +01:00
|
|
|
WM_operator_properties_free(&ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL);
|
|
|
|
}
|
2013-11-22 14:35:34 +01:00
|
|
|
}
|
|
|
|
|
2013-11-22 01:35:38 +01:00
|
|
|
void file_filename_enter_handle(bContext *C, void *UNUSED(arg_unused), void *arg_but)
|
2009-07-10 17:05:04 +00:00
|
|
|
{
|
2012-06-18 13:01:24 +00:00
|
|
|
SpaceFile *sfile = CTX_wm_space_file(C);
|
2013-12-10 13:44:46 +11:00
|
|
|
uiBut *but = arg_but;
|
2012-06-17 14:16:26 +00:00
|
|
|
char matched_file[FILE_MAX];
|
2013-11-22 14:35:34 +01:00
|
|
|
char filepath[sizeof(sfile->params->dir)];
|
|
|
|
|
2012-03-06 18:40:15 +00:00
|
|
|
if (sfile->params) {
|
2013-11-22 01:35:38 +01:00
|
|
|
int matches;
|
2012-06-17 14:16:26 +00:00
|
|
|
matched_file[0] = '\0';
|
2013-11-22 14:35:34 +01:00
|
|
|
filepath[0] = '\0';
|
|
|
|
|
2013-11-22 01:35:38 +01:00
|
|
|
file_expand_directory(C);
|
|
|
|
|
|
|
|
matches = file_select_match(sfile, sfile->params->file, matched_file);
|
|
|
|
|
2015-09-13 08:20:48 +02:00
|
|
|
/* *After* file_select_match! */
|
|
|
|
BLI_filename_make_safe(sfile->params->file);
|
|
|
|
|
2013-11-22 01:35:38 +01:00
|
|
|
if (matches) {
|
2012-06-18 12:39:19 +00:00
|
|
|
/* int i, numfiles = filelist_numfiles(sfile->files); */ /* XXX UNUSED */
|
2009-07-10 17:05:04 +00:00
|
|
|
sfile->params->file[0] = '\0';
|
2012-06-17 14:16:26 +00:00
|
|
|
/* replace the pattern (or filename that the user typed in, with the first selected file of the match */
|
|
|
|
BLI_strncpy(sfile->params->file, matched_file, sizeof(sfile->params->file));
|
|
|
|
|
2012-06-18 13:01:24 +00:00
|
|
|
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_PARAMS, NULL);
|
2009-07-10 17:05:04 +00:00
|
|
|
}
|
2013-11-22 14:35:34 +01:00
|
|
|
|
|
|
|
if (matches == 1) {
|
|
|
|
|
|
|
|
BLI_join_dirfile(filepath, sizeof(sfile->params->dir), sfile->params->dir, sfile->params->file);
|
|
|
|
|
|
|
|
/* if directory, open it and empty filename field */
|
|
|
|
if (BLI_is_dir(filepath)) {
|
|
|
|
BLI_cleanup_dir(G.main->name, filepath);
|
|
|
|
BLI_strncpy(sfile->params->dir, filepath, sizeof(sfile->params->dir));
|
|
|
|
sfile->params->file[0] = '\0';
|
2015-02-11 00:09:45 +01:00
|
|
|
ED_file_change_dir(C, true);
|
2013-11-22 01:35:38 +01:00
|
|
|
UI_textbutton_activate_but(C, but);
|
2013-11-22 14:35:34 +01:00
|
|
|
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_PARAMS, NULL);
|
|
|
|
}
|
2013-11-23 02:06:06 +11:00
|
|
|
else if (sfile->params->type == FILE_LOADLIB) {
|
2015-08-18 13:18:50 +02:00
|
|
|
char tdir[FILE_MAX];
|
2013-11-22 14:35:34 +01:00
|
|
|
BLI_add_slash(filepath);
|
2015-08-18 13:18:50 +02:00
|
|
|
if (BLO_library_path_explode(filepath, tdir, NULL, NULL)) {
|
2013-11-22 14:35:34 +01:00
|
|
|
BLI_cleanup_dir(G.main->name, filepath);
|
|
|
|
BLI_strncpy(sfile->params->dir, filepath, sizeof(sfile->params->dir));
|
|
|
|
sfile->params->file[0] = '\0';
|
2015-02-11 00:09:45 +01:00
|
|
|
ED_file_change_dir(C, false);
|
2013-11-22 01:35:38 +01:00
|
|
|
UI_textbutton_activate_but(C, but);
|
2013-11-22 14:35:34 +01:00
|
|
|
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-02-17 08:52:19 +11:00
|
|
|
else if (matches > 1) {
|
|
|
|
file_draw_check(C);
|
|
|
|
}
|
2012-06-18 12:39:19 +00:00
|
|
|
}
|
2013-11-22 14:35:34 +01:00
|
|
|
}
|
|
|
|
|
2009-03-12 06:40:03 +00:00
|
|
|
void FILE_OT_refresh(struct wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Refresh Filelist";
|
|
|
|
ot->description = "Refresh the file list";
|
|
|
|
ot->idname = "FILE_OT_refresh";
|
2009-03-12 06:40:03 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = file_refresh_exec;
|
|
|
|
ot->poll = ED_operator_file_active; /* <- important, handler is on window level */
|
2009-03-12 06:40:03 +00:00
|
|
|
}
|
|
|
|
|
2011-02-14 17:55:27 +00:00
|
|
|
static int file_hidedot_exec(bContext *C, wmOperator *UNUSED(unused))
|
2009-06-30 18:29:30 +00:00
|
|
|
{
|
2013-03-15 19:56:29 +00:00
|
|
|
wmWindowManager *wm = CTX_wm_manager(C);
|
2012-06-18 13:01:24 +00:00
|
|
|
SpaceFile *sfile = CTX_wm_space_file(C);
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
ScrArea *sa = CTX_wm_area(C);
|
2009-06-30 18:29:30 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (sfile->params) {
|
2009-06-30 18:29:30 +00:00
|
|
|
sfile->params->flag ^= FILE_HIDE_DOT;
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
ED_fileselect_clear(wm, sa, sfile);
|
2012-06-18 13:01:24 +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 */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Toggle Hide Dot Files";
|
|
|
|
ot->description = "Toggle hide hidden dot files";
|
|
|
|
ot->idname = "FILE_OT_hidedot";
|
2009-06-30 18:29:30 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = file_hidedot_exec;
|
|
|
|
ot->poll = ED_operator_file_active; /* <- important, handler is on window level */
|
2009-06-30 18:29:30 +00:00
|
|
|
}
|
|
|
|
|
2015-02-11 00:09:45 +01:00
|
|
|
ARegion *file_tools_region(ScrArea *sa)
|
2012-06-20 16:43:48 +00:00
|
|
|
{
|
2009-06-29 20:23:40 +00:00
|
|
|
ARegion *ar, *arnew;
|
2015-02-11 00:09:45 +01:00
|
|
|
|
|
|
|
if ((ar = BKE_area_find_region_type(sa, RGN_TYPE_TOOLS)) != NULL)
|
|
|
|
return ar;
|
2009-06-29 20:23:40 +00:00
|
|
|
|
|
|
|
/* add subdiv level; after header */
|
2015-02-11 00:09:45 +01:00
|
|
|
ar = BKE_area_find_region_type(sa, RGN_TYPE_HEADER);
|
2009-06-29 20:23:40 +00:00
|
|
|
|
|
|
|
/* is error! */
|
2015-02-11 00:09:45 +01:00
|
|
|
if (ar == NULL)
|
|
|
|
return NULL;
|
2009-06-29 20:23:40 +00:00
|
|
|
|
2015-02-11 00:09:45 +01:00
|
|
|
arnew = MEM_callocN(sizeof(ARegion), "tools for file");
|
2009-06-29 20:23:40 +00:00
|
|
|
BLI_insertlinkafter(&sa->regionbase, ar, arnew);
|
2015-02-11 00:09:45 +01:00
|
|
|
arnew->regiontype = RGN_TYPE_TOOLS;
|
2012-06-18 13:01:24 +00:00
|
|
|
arnew->alignment = RGN_ALIGN_LEFT;
|
2015-02-11 00:09:45 +01:00
|
|
|
|
|
|
|
ar = MEM_callocN(sizeof(ARegion), "tool props for file");
|
|
|
|
BLI_insertlinkafter(&sa->regionbase, arnew, ar);
|
|
|
|
ar->regiontype = RGN_TYPE_TOOL_PROPS;
|
|
|
|
ar->alignment = RGN_ALIGN_BOTTOM | RGN_SPLIT_PREV;
|
|
|
|
|
2009-06-29 20:23:40 +00:00
|
|
|
return arnew;
|
2009-03-08 13:14:12 +00:00
|
|
|
}
|
2009-01-28 11:27:25 +00:00
|
|
|
|
2011-02-14 17:55:27 +00:00
|
|
|
static int file_bookmark_toggle_exec(bContext *C, wmOperator *UNUSED(unused))
|
2009-03-08 13:14:12 +00:00
|
|
|
{
|
2012-06-18 13:01:24 +00:00
|
|
|
ScrArea *sa = CTX_wm_area(C);
|
2015-02-11 00:09:45 +01:00
|
|
|
ARegion *ar = file_tools_region(sa);
|
2009-03-08 13:14:12 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (ar)
|
2009-09-14 19:12:29 +00:00
|
|
|
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 */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Toggle Bookmarks";
|
|
|
|
ot->description = "Toggle bookmarks display";
|
|
|
|
ot->idname = "FILE_OT_bookmark_toggle";
|
2009-03-08 13:14:12 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = file_bookmark_toggle_exec;
|
|
|
|
ot->poll = ED_operator_file_active; /* <- important, handler is on window level */
|
2009-03-08 13:14:12 +00:00
|
|
|
}
|
2009-07-05 22:26:43 +00:00
|
|
|
|
|
|
|
|
2015-10-16 04:57:52 +11:00
|
|
|
/**
|
|
|
|
* Looks for a string of digits within name (using BLI_stringdec) and adjusts it by add.
|
|
|
|
*/
|
|
|
|
static void filenum_newname(char *name, size_t name_size, int add)
|
|
|
|
{
|
|
|
|
char head[FILE_MAXFILE], tail[FILE_MAXFILE];
|
|
|
|
char name_temp[FILE_MAXFILE];
|
|
|
|
int pic;
|
|
|
|
unsigned short digits;
|
|
|
|
|
|
|
|
pic = BLI_stringdec(name, head, tail, &digits);
|
|
|
|
|
|
|
|
/* are we going from 100 -> 99 or from 10 -> 9 */
|
|
|
|
if (add < 0 && digits > 0) {
|
|
|
|
int i, exp;
|
|
|
|
exp = 1;
|
|
|
|
for (i = digits; i > 1; i--) {
|
|
|
|
exp *= 10;
|
|
|
|
}
|
|
|
|
if (pic >= exp && (pic + add) < exp) {
|
|
|
|
digits--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pic += add;
|
|
|
|
if (pic < 0)
|
|
|
|
pic = 0;
|
|
|
|
BLI_stringenc(name_temp, head, tail, digits, pic);
|
|
|
|
BLI_strncpy(name, name_temp, name_size);
|
|
|
|
}
|
|
|
|
|
2011-02-14 17:55:27 +00:00
|
|
|
static int file_filenum_exec(bContext *C, wmOperator *op)
|
2009-07-05 22:26:43 +00:00
|
|
|
{
|
2012-06-18 13:01:24 +00:00
|
|
|
SpaceFile *sfile = CTX_wm_space_file(C);
|
|
|
|
ScrArea *sa = CTX_wm_area(C);
|
2009-07-05 22:26:43 +00:00
|
|
|
|
|
|
|
int inc = RNA_int_get(op->ptr, "increment");
|
2012-03-24 06:38:07 +00:00
|
|
|
if (sfile->params && (inc != 0)) {
|
2015-10-16 04:57:52 +11:00
|
|
|
filenum_newname(sfile->params->file, sizeof(sfile->params->file), inc);
|
2009-09-12 19:54:39 +00:00
|
|
|
ED_area_tag_redraw(sa);
|
2015-02-17 08:52:19 +11:00
|
|
|
file_draw_check(C);
|
2009-09-12 19:54:39 +00:00
|
|
|
// 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 */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Increment Number in Filename";
|
|
|
|
ot->description = "Increment number in filename";
|
|
|
|
ot->idname = "FILE_OT_filenum";
|
2009-07-05 22:26:43 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = file_filenum_exec;
|
|
|
|
ot->poll = ED_operator_file_active; /* <- important, handler is on window level */
|
2009-07-05 22:26:43 +00:00
|
|
|
|
|
|
|
/* props */
|
2012-04-29 15:47:02 +00:00
|
|
|
RNA_def_int(ot->srna, "increment", 1, -100, 100, "Increment", "", -100, 100);
|
2009-07-09 19:49:04 +00:00
|
|
|
}
|
|
|
|
|
2011-02-14 17:55:27 +00:00
|
|
|
static int file_rename_exec(bContext *C, wmOperator *UNUSED(op))
|
2009-07-26 18:52:27 +00:00
|
|
|
{
|
2012-06-18 13:01:24 +00:00
|
|
|
ScrArea *sa = CTX_wm_area(C);
|
|
|
|
SpaceFile *sfile = (SpaceFile *)CTX_wm_space_data(C);
|
2009-07-26 18:52:27 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (sfile->params) {
|
File Browser Arrow Keys Navigation
Adds support for selecting/deselecting files in File Browser using the
arrow keys. All directions (up, down, left, right) are possible.
When to Select, When to Deselect?
Standard behaviour is selecting, however if we move into a block of
already selected files (meaning 2+ files are selected) we start
deselecting
Possible Selection Methods
Simple selection (arrow-key): All other files are deselected
Expand selection (Shift+arrow key): Add to/remove from existing
selection
ill-Expand selection (Ctrl+Shift+arrow key): Add to/remove from existing
selection and fill everything in-between
From which file do we start navigating?
From each available selection method (Mouse-, Walk-, All-, Border
Select), we use the last selected file. If there's no selection at all
we use the first (down/right arrow) or last (up/left arrow) file.
(Ideally, the view would automatically be set to the new selection, but
this behaviour overlaps with an other patch I've been working on, so
prefer to do that separately)
(Also tweaks color for highlighted file for better feedback)
D1297, Review done by @campbellbarton, thx a lot :)
2015-06-11 17:20:29 +02:00
|
|
|
int idx = sfile->params->highlight_file;
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
int numfiles = filelist_files_ensure(sfile->files);
|
2015-07-14 18:48:51 +02:00
|
|
|
if ((0 <= idx) && (idx < numfiles)) {
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
FileDirEntry *file = filelist_file(sfile->files, idx);
|
|
|
|
filelist_entry_select_index_set(sfile->files, idx, FILE_SEL_ADD, FILE_SEL_EDITING, CHECK_ALL);
|
|
|
|
BLI_strncpy(sfile->params->renameedit, file->relpath, FILE_MAXFILE);
|
2012-06-18 13:01:24 +00:00
|
|
|
sfile->params->renamefile[0] = '\0';
|
2009-07-26 18:52:27 +00:00
|
|
|
}
|
|
|
|
ED_area_tag_redraw(sa);
|
|
|
|
}
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-02-14 17:55:27 +00:00
|
|
|
static int file_rename_poll(bContext *C)
|
2009-09-12 19:54:39 +00:00
|
|
|
{
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
bool poll = ED_operator_file_active(C);
|
2012-06-18 13:01:24 +00:00
|
|
|
SpaceFile *sfile = CTX_wm_space_file(C);
|
2009-09-12 19:54:39 +00:00
|
|
|
|
|
|
|
if (sfile && sfile->params) {
|
File Browser Arrow Keys Navigation
Adds support for selecting/deselecting files in File Browser using the
arrow keys. All directions (up, down, left, right) are possible.
When to Select, When to Deselect?
Standard behaviour is selecting, however if we move into a block of
already selected files (meaning 2+ files are selected) we start
deselecting
Possible Selection Methods
Simple selection (arrow-key): All other files are deselected
Expand selection (Shift+arrow key): Add to/remove from existing
selection
ill-Expand selection (Ctrl+Shift+arrow key): Add to/remove from existing
selection and fill everything in-between
From which file do we start navigating?
From each available selection method (Mouse-, Walk-, All-, Border
Select), we use the last selected file. If there's no selection at all
we use the first (down/right arrow) or last (up/left arrow) file.
(Ideally, the view would automatically be set to the new selection, but
this behaviour overlaps with an other patch I've been working on, so
prefer to do that separately)
(Also tweaks color for highlighted file for better feedback)
D1297, Review done by @campbellbarton, thx a lot :)
2015-06-11 17:20:29 +02:00
|
|
|
int idx = sfile->params->highlight_file;
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
int numfiles = filelist_files_ensure(sfile->files);
|
2014-11-10 20:29:44 +01:00
|
|
|
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
if ((0 <= idx) && (idx < numfiles)) {
|
|
|
|
FileDirEntry *file = filelist_file(sfile->files, idx);
|
|
|
|
if (FILENAME_IS_CURRPAR(file->relpath)) {
|
|
|
|
poll = false;
|
2014-11-10 20:29:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
File Browser Arrow Keys Navigation
Adds support for selecting/deselecting files in File Browser using the
arrow keys. All directions (up, down, left, right) are possible.
When to Select, When to Deselect?
Standard behaviour is selecting, however if we move into a block of
already selected files (meaning 2+ files are selected) we start
deselecting
Possible Selection Methods
Simple selection (arrow-key): All other files are deselected
Expand selection (Shift+arrow key): Add to/remove from existing
selection
ill-Expand selection (Ctrl+Shift+arrow key): Add to/remove from existing
selection and fill everything in-between
From which file do we start navigating?
From each available selection method (Mouse-, Walk-, All-, Border
Select), we use the last selected file. If there's no selection at all
we use the first (down/right arrow) or last (up/left arrow) file.
(Ideally, the view would automatically be set to the new selection, but
this behaviour overlaps with an other patch I've been working on, so
prefer to do that separately)
(Also tweaks color for highlighted file for better feedback)
D1297, Review done by @campbellbarton, thx a lot :)
2015-06-11 17:20:29 +02:00
|
|
|
if (sfile->params->highlight_file < 0) {
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
poll = false;
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else {
|
2015-08-18 13:18:50 +02:00
|
|
|
char dir[FILE_MAX];
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
if (filelist_islibrary(sfile->files, dir, NULL)) {
|
|
|
|
poll = false;
|
|
|
|
}
|
2009-09-12 19:54:39 +00:00
|
|
|
}
|
|
|
|
}
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
else {
|
|
|
|
poll = false;
|
|
|
|
}
|
|
|
|
|
2009-09-12 19:54:39 +00:00
|
|
|
return poll;
|
|
|
|
}
|
|
|
|
|
2009-07-26 18:52:27 +00:00
|
|
|
void FILE_OT_rename(struct wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Rename File or Directory";
|
|
|
|
ot->description = "Rename file or file directory";
|
|
|
|
ot->idname = "FILE_OT_rename";
|
2009-07-26 18:52:27 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = file_rename_exec;
|
|
|
|
ot->poll = file_rename_poll;
|
2009-07-26 18:52:27 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-02-14 17:55:27 +00:00
|
|
|
static int file_delete_poll(bContext *C)
|
2009-07-10 17:05:04 +00:00
|
|
|
{
|
|
|
|
int poll = ED_operator_file_active(C);
|
2012-06-18 13:01:24 +00:00
|
|
|
SpaceFile *sfile = CTX_wm_space_file(C);
|
2009-07-10 17:05:04 +00:00
|
|
|
|
2013-03-25 02:41:30 +00:00
|
|
|
if (sfile && sfile->params) {
|
2015-08-18 13:18:50 +02:00
|
|
|
char dir[FILE_MAX];
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
int numfiles = filelist_files_ensure(sfile->files);
|
2013-03-24 19:29:49 +00:00
|
|
|
int i;
|
|
|
|
int num_selected = 0;
|
|
|
|
|
2015-08-18 13:18:50 +02:00
|
|
|
if (filelist_islibrary(sfile->files, dir, NULL)) poll = 0;
|
2013-03-25 02:41:30 +00:00
|
|
|
for (i = 0; i < numfiles; i++) {
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
if (filelist_entry_select_index_get(sfile->files, i, CHECK_FILES)) {
|
2013-03-24 19:29:49 +00:00
|
|
|
num_selected++;
|
|
|
|
}
|
2009-07-20 00:02:03 +00:00
|
|
|
}
|
2013-03-24 19:29:49 +00:00
|
|
|
if (num_selected <= 0) {
|
|
|
|
poll = 0;
|
2013-03-25 02:41:30 +00:00
|
|
|
}
|
2009-07-10 17:05:04 +00:00
|
|
|
}
|
2009-07-20 00:02:03 +00:00
|
|
|
else
|
2012-06-18 13:01:24 +00:00
|
|
|
poll = 0;
|
2009-07-20 00:02:03 +00:00
|
|
|
|
2009-07-10 17:05:04 +00:00
|
|
|
return poll;
|
|
|
|
}
|
|
|
|
|
2016-02-03 16:37:02 +11:00
|
|
|
int file_delete_exec(bContext *C, wmOperator *op)
|
2009-07-10 17:05:04 +00:00
|
|
|
{
|
|
|
|
char str[FILE_MAX];
|
2013-03-15 19:56:29 +00:00
|
|
|
wmWindowManager *wm = CTX_wm_manager(C);
|
2012-06-18 13:01:24 +00:00
|
|
|
SpaceFile *sfile = CTX_wm_space_file(C);
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
ScrArea *sa = CTX_wm_area(C);
|
|
|
|
FileDirEntry *file;
|
|
|
|
int numfiles = filelist_files_ensure(sfile->files);
|
2013-03-24 19:29:49 +00:00
|
|
|
int i;
|
|
|
|
|
2016-02-03 16:37:02 +11:00
|
|
|
bool report_error = false;
|
|
|
|
errno = 0;
|
2013-03-24 19:29:49 +00:00
|
|
|
for (i = 0; i < numfiles; i++) {
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
if (filelist_entry_select_index_get(sfile->files, i, CHECK_FILES)) {
|
2013-03-24 19:29:49 +00:00
|
|
|
file = filelist_file(sfile->files, i);
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
BLI_make_file_string(G.main->name, str, sfile->params->dir, file->relpath);
|
2016-02-03 16:37:02 +11:00
|
|
|
if (BLI_delete(str, false, false) != 0 ||
|
|
|
|
BLI_exists(str))
|
|
|
|
{
|
|
|
|
report_error = true;
|
|
|
|
}
|
2013-03-24 19:29:49 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-10 17:05:04 +00:00
|
|
|
|
2016-02-03 16:37:02 +11:00
|
|
|
if (report_error) {
|
|
|
|
BKE_reportf(op->reports, RPT_ERROR,
|
|
|
|
"Could not delete file: %s",
|
|
|
|
errno ? strerror(errno) : "unknown error");
|
|
|
|
}
|
|
|
|
|
Final 'FileBrowser First Stage' merge.
It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.
From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.
From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).
Revision: https://developer.blender.org/D1316
Thanks to Campbell & Sergey for the reviews. :)
2015-08-19 22:41:39 +02:00
|
|
|
ED_fileselect_clear(wm, sa, sfile);
|
2012-06-18 13:01:24 +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 */
|
2013-03-24 19:29:49 +00:00
|
|
|
ot->name = "Delete Selected Files";
|
|
|
|
ot->description = "Delete selected files";
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->idname = "FILE_OT_delete";
|
2009-07-10 17:05:04 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->invoke = WM_operator_confirm;
|
|
|
|
ot->exec = file_delete_exec;
|
|
|
|
ot->poll = file_delete_poll; /* <- important, handler is on window level */
|
2009-07-10 17:05:04 +00:00
|
|
|
}
|
|
|
|
|
2010-01-19 03:59:05 +00:00
|
|
|
|
|
|
|
void ED_operatormacros_file(void)
|
|
|
|
{
|
2011-03-11 17:01:29 +00:00
|
|
|
// wmOperatorType *ot;
|
|
|
|
// wmOperatorTypeMacro *otmacro;
|
2010-01-19 03:59:05 +00:00
|
|
|
|
2011-03-11 17:01:29 +00:00
|
|
|
/* future macros */
|
2010-01-19 03:59:05 +00:00
|
|
|
}
|