diff options
author | Ton Roosendaal <ton@blender.org> | 2009-02-16 15:14:04 +0300 |
---|---|---|
committer | Ton Roosendaal <ton@blender.org> | 2009-02-16 15:14:04 +0300 |
commit | 4154e48c053caf947f2668a168ce38aa10b8481b (patch) | |
tree | 294c3173648572d6669a8c85e08a459ba0075ce1 /source/blender/editors | |
parent | f6df8e1860d44d6b4d2c9048b0fb0ebdbfd850d3 (diff) |
2.5
Proper integration of File-selecting in WM. The communication
flow was flawed. :) Main problem was that filewindow can change
the screen context entirely, and should not do this directly on
a call inside an operator. Another problem was that the operator
ownership was handed over to SpaceFile, which is asking for
problems if you want to execute the operator with proper context
later on.
Solution is simple; window handlers already are valid owners of
operators and can manage context, so instead of directly talking
to the 'file space', you give the operator to a new handler this
way:
WM_event_add_fileselect(C, op);
This handler then listens to events (OPEN, EXEC, CANCEL) sent
by the WM or by the filewindow itself. This way local context
operators (like "open new image in imagewindow") will survive
a full-window fileselector fine, and in future also secondary
windows browsing files.
Two bugfixes included in this commit too:
- Add sequence menus in Sequencer used wrong context.
- When handler executes operators, it sets stored context now
by first checking if this is still valid.
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/space_file/file_ops.c | 24 | ||||
-rw-r--r-- | source/blender/editors/space_file/space_file.c | 4 | ||||
-rw-r--r-- | source/blender/editors/space_image/image_ops.c | 16 | ||||
-rw-r--r-- | source/blender/editors/space_sequencer/sequencer_header.c | 8 |
4 files changed, 11 insertions, 41 deletions
diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index 1d1f31c4221..1cedc7b0282 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -457,11 +457,8 @@ int file_cancel_exec(bContext *C, wmOperator *unused) { SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C); - if(sfile->op) { - WM_operator_free(sfile->op); - sfile->op = NULL; - } - ED_screen_full_prevspace(C); + WM_event_fileselect_event(C, sfile->op, EVT_FILESELECT_CANCEL); + sfile->op = NULL; return OPERATOR_FINISHED; } @@ -477,34 +474,21 @@ void FILE_OT_cancel(struct wmOperatorType *ot) ot->poll= ED_operator_file_active; } - +/* sends events now, so things get handled on windowqueue level */ int file_exec(bContext *C, wmOperator *unused) { SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C); char name[FILE_MAX]; - ED_screen_full_prevspace(C); - if(sfile->op) { wmOperator *op= sfile->op; - /* if load .blend, all UI pointers after exec are invalid! */ - /* but, operator can be freed still */ - sfile->op = NULL; BLI_strncpy(name, sfile->params->dir, sizeof(name)); strcat(name, sfile->params->file); RNA_string_set(op->ptr, "filename", name); - /* a bit weak, might become arg for ED_fileselect? */ - if(strncmp(sfile->params->title, "Save", 4)==0) { - /* this gives ownership to pupmenu */ - uiPupMenuSaveOver(C, op, name); - } - else { - op->type->exec(C, op); - WM_operator_free(op); - } + WM_event_fileselect_event(C, op, EVT_FILESELECT_EXEC); } return OPERATOR_FINISHED; diff --git a/source/blender/editors/space_file/space_file.c b/source/blender/editors/space_file/space_file.c index f8557a2b573..6eed864ff47 100644 --- a/source/blender/editors/space_file/space_file.c +++ b/source/blender/editors/space_file/space_file.c @@ -125,10 +125,6 @@ static void file_free(SpaceLink *sl) MEM_freeN(sfile->params); sfile->params= NULL; } - - if (sfile->op) { - WM_operator_free(sfile->op); - } } diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c index 51bca9d4fcc..edbb960785d 100644 --- a/source/blender/editors/space_image/image_ops.c +++ b/source/blender/editors/space_image/image_ops.c @@ -63,7 +63,6 @@ #include "RNA_types.h" #include "ED_image.h" -#include "ED_fileselect.h" #include "ED_screen.h" #include "ED_space_api.h" #include "ED_uvedit.h" @@ -591,18 +590,8 @@ static char *filesel_imagetype_string(Image *ima) static void image_filesel(bContext *C, wmOperator *op, const char *path) { - SpaceFile *sfile; - - // XXX context is not set back ok afterwards - // ED_screen_full_newspace(C, CTX_wm_area(C), SPACE_FILE); - ED_area_newspace(C, CTX_wm_area(C), SPACE_FILE); - - /* settings for filebrowser */ - sfile= (SpaceFile*)CTX_wm_space_data(C); - sfile->op= op; - - /* XXX right params for image save, with pupmenu and image type .. */ - ED_fileselect_set_params(sfile, FILE_SPECIAL, op->type->name, path, 0, 0, 0); + RNA_string_set(op->ptr, "filename", path); + WM_event_add_fileselect(C, op); } /******************** open image operator ********************/ @@ -834,6 +823,7 @@ static int save_as_invoke(bContext *C, wmOperator *op, wmEvent *event) sima->imtypenr= BKE_ftype_to_imtype(ibuf->ftype); // XXX activate_fileselect_menu(FILE_SPECIAL, "Save Image", name, strp, &sima->imtypenr, save_image_doit); + // XXX note: we can give default menu enums to operator for this image_filesel(C, op, ima->name); diff --git a/source/blender/editors/space_sequencer/sequencer_header.c b/source/blender/editors/space_sequencer/sequencer_header.c index 32a60f1fb54..71d7ff728d3 100644 --- a/source/blender/editors/space_sequencer/sequencer_header.c +++ b/source/blender/editors/space_sequencer/sequencer_header.c @@ -146,7 +146,7 @@ static uiBlock *seq_viewmenu(bContext *C, ARegion *ar, void *arg_unused) //static uiBlock *seq_selectmenu(bContext *C, ARegion *ar, void *arg_unused) static void seq_selectmenu(bContext *C, uiMenuItem *head, void *arg_unused) { - uiMenuContext(head, WM_OP_INVOKE_DEFAULT); + uiMenuContext(head, WM_OP_INVOKE_REGION_WIN); uiMenuItemEnumO(head, "Strips to the Left", 0, "SEQUENCER_OT_select_active_side", "side", SEQ_SIDE_LEFT); uiMenuItemEnumO(head, "Strips to the Right", 0, "SEQUENCER_OT_select_active_side", "side", SEQ_SIDE_RIGHT); @@ -212,7 +212,7 @@ static uiBlock *seq_markermenu(bContext *C, ARegion *ar, void *arg_unused) //static uiBlock *seq_addmenu_effectmenu(bContext *C, ARegion *ar, void *arg_unused) static void seq_addmenu_effectmenu(bContext *C, uiMenuItem *head, void *arg_unused) { - uiMenuContext(head, WM_OP_INVOKE_DEFAULT); + uiMenuContext(head, WM_OP_INVOKE_REGION_WIN); uiMenuItemEnumO(head, "", 0, "SEQUENCER_OT_add_effect_strip", "type", SEQ_ADD); uiMenuItemEnumO(head, "", 0, "SEQUENCER_OT_add_effect_strip", "type", SEQ_SUB); @@ -238,7 +238,7 @@ static void seq_addmenu(bContext *C, uiMenuItem *head, void *arg_unused) uiMenuLevel(head, "Effects...", seq_addmenu_effectmenu); uiMenuSeparator(head); - uiMenuContext(head, WM_OP_INVOKE_DEFAULT); + uiMenuContext(head, WM_OP_INVOKE_REGION_WIN); #ifdef WITH_FFMPEG uiMenuItemBooleanO(head, "Audio (RAM)", 0, "SEQUENCER_OT_add_sound_strip", "hd", FALSE); @@ -263,7 +263,7 @@ static void seq_editmenu(bContext *C, uiMenuItem *head, void *arg_unused) Scene *scene= CTX_data_scene(C); Editing *ed= seq_give_editing(scene, FALSE); - uiMenuContext(head, WM_OP_INVOKE_DEFAULT); + uiMenuContext(head, WM_OP_INVOKE_REGION_WIN); uiMenuItemEnumO(head, "", 0, "TFM_OT_transform", "mode", TFM_TRANSLATION); uiMenuItemEnumO(head, "", 0, "TFM_OT_transform", "mode", TFM_TIME_EXTEND); |