diff options
author | Gaia Clary <gaia.clary@machinimatrix.org> | 2015-11-04 16:24:46 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2015-11-04 17:33:50 +0300 |
commit | b566adec5255a0d463dd7d16bc7acbb5d6fdbbaf (patch) | |
tree | 047ea0a4e6d8acf69624e900ccb9983083dfd9ec /source/blender/editors/space_file/file_ops.c | |
parent | e43b6e2f9725edd8cbe1ca8538c8a2bbdf1b45cd (diff) |
File Selector, support filepath dropping
This adds support for dropping a filepath on an open file-selector to set that path.
Diffstat (limited to 'source/blender/editors/space_file/file_ops.c')
-rw-r--r-- | source/blender/editors/space_file/file_ops.c | 74 |
1 files changed, 70 insertions, 4 deletions
diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index 36572d6469d..feea40443fa 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -1188,7 +1188,7 @@ void FILE_OT_cancel(struct wmOperatorType *ot) } -void file_sfile_to_operator(wmOperator *op, SpaceFile *sfile, char *filepath) +void file_sfile_to_operator_ex(wmOperator *op, SpaceFile *sfile, char *filepath) { PropertyRNA *prop; @@ -1258,6 +1258,12 @@ void file_sfile_to_operator(wmOperator *op, SpaceFile *sfile, char *filepath) } } +void file_sfile_to_operator(wmOperator *op, SpaceFile *sfile) +{ + char filepath[FILE_MAX]; + + file_sfile_to_operator_ex(op, sfile, filepath); +} void file_operator_to_sfile(SpaceFile *sfile, wmOperator *op) { @@ -1285,14 +1291,35 @@ void file_operator_to_sfile(SpaceFile *sfile, wmOperator *op) /* XXX, files and dirs updates missing, not really so important though */ } +/** + * 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)); + } + else{ + BLI_split_dir_part(filepath, sfile->params->dir, sizeof(sfile->params->dir)); + } + } +} + void file_draw_check(bContext *C) { SpaceFile *sfile = CTX_wm_space_file(C); wmOperator *op = sfile->op; if (op) { /* fail on reload */ if (op->type->check) { - char filepath[FILE_MAX]; - file_sfile_to_operator(op, sfile, filepath); + file_sfile_to_operator(op, sfile); /* redraw */ if (op->type->check(C, op)) { @@ -1375,7 +1402,7 @@ int file_exec(bContext *C, wmOperator *exec_op) sfile->op = NULL; - file_sfile_to_operator(op, sfile, filepath); + file_sfile_to_operator_ex(op, sfile, filepath); if (BLI_exists(sfile->params->dir)) { fsmenu_insert_entry(ED_fsmenu_get(), FS_CATEGORY_RECENT, sfile->params->dir, NULL, @@ -1652,6 +1679,45 @@ void FILE_OT_smoothscroll(wmOperatorType *ot) } +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, "", ""); +} + /* create a new, non-existing folder name, returns 1 if successful, 0 if name couldn't be created. * The actual name is returned in 'name', 'folder' contains the complete path, including the new folder name. */ |