Merge with 2.5 -r 21003:21788.
[blender.git] / source / blender / windowmanager / intern / wm_operators.c
index 5e60207f62d2a3a81b05951c72ca745a05632469..755ba87d080133b01a431707657b733b46704274 100644 (file)
@@ -387,6 +387,7 @@ int WM_operator_redo_popup(bContext *C, wmOperator *op)
        return OPERATOR_CANCELLED;
 }
 
+
 /* ***************** Debug menu ************************* */
 
 static uiBlock *wm_block_create_menu(bContext *C, ARegion *ar, void *arg_op)
@@ -532,6 +533,7 @@ static void WM_OT_search_menu(wmOperatorType *ot)
 }
 
 
+
 /* ************ window / screen operator definitions ************** */
 
 static void WM_OT_window_duplicate(wmOperatorType *ot)
@@ -757,6 +759,108 @@ static void WM_OT_save_mainfile(wmOperatorType *ot)
 }
 
 
+
+
+
+/* XXX: move these to a more appropriate place */
+#include "../../collada/collada.h"
+
+static int wm_collada_export_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+       //char name[FILE_MAX];
+       //BLI_strncpy(name, G.sce, FILE_MAX);
+       //untitled(name);
+
+       // XXX: temporary
+       RNA_string_set(op->ptr, "filename", "/tmp/test.dae");
+       
+       WM_event_add_fileselect(C, op);
+
+       return OPERATOR_RUNNING_MODAL;
+}
+
+/* function used for WM_OT_save_mainfile too */
+static int wm_collada_export_exec(bContext *C, wmOperator *op)
+{
+       char filename[FILE_MAX];
+       
+       if(RNA_property_is_set(op->ptr, "filename"))
+               RNA_string_get(op->ptr, "filename", filename);
+       else {
+               BLI_strncpy(filename, G.sce, FILE_MAX);
+               untitled(filename);
+       }
+       
+       //WM_write_file(C, filename, op->reports);
+       collada_export(CTX_data_scene(C), filename);
+       
+       /* WM_event_add_notifier(C, NC_WM|ND_FILESAVE, NULL); */
+
+       return OPERATOR_FINISHED;
+}
+
+static void WM_OT_collada_export(wmOperatorType *ot)
+{
+       ot->name= "Collada Export";
+       ot->idname= "WM_OT_collada_export";
+       
+       ot->invoke= wm_collada_export_invoke;
+       ot->exec= wm_collada_export_exec;
+       ot->poll= WM_operator_winactive;
+       
+       ot->flag= 0;
+       
+       RNA_def_property(ot->srna, "filename", PROP_STRING, PROP_FILEPATH);
+}
+
+static int wm_collada_import_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+       // XXX: temporary
+       RNA_string_set(op->ptr, "filename", "/tmp/test.dae");
+       
+       WM_event_add_fileselect(C, op);
+
+       return OPERATOR_RUNNING_MODAL;
+}
+
+/* function used for WM_OT_save_mainfile too */
+static int wm_collada_import_exec(bContext *C, wmOperator *op)
+{
+       char filename[FILE_MAX];
+       
+       if(RNA_property_is_set(op->ptr, "filename"))
+               RNA_string_get(op->ptr, "filename", filename);
+       else {
+               BLI_strncpy(filename, G.sce, FILE_MAX);
+               untitled(filename);
+       }
+       
+       //WM_write_file(C, filename, op->reports);
+       collada_import(C, filename);
+       
+       /* WM_event_add_notifier(C, NC_WM|ND_FILESAVE, NULL); */
+
+       return OPERATOR_FINISHED;
+}
+
+static void WM_OT_collada_import(wmOperatorType *ot)
+{
+       ot->name= "Collada Import";
+       ot->idname= "WM_OT_collada_import";
+       
+       ot->invoke= wm_collada_import_invoke;
+       ot->exec= wm_collada_import_exec;
+       ot->poll= WM_operator_winactive;
+       
+       ot->flag= 0;
+       
+       RNA_def_property(ot->srna, "filename", PROP_STRING, PROP_FILEPATH);
+}
+
+
+
+
+
 /* *********************** */
 
 static void WM_OT_window_fullscreen_toggle(wmOperatorType *ot)
@@ -1485,6 +1589,7 @@ void WM_OT_radial_control_partial(wmOperatorType *ot)
        RNA_def_int_vector(ot->srna, "initial_mouse", 2, NULL, INT_MIN, INT_MAX, "initial_mouse", "", INT_MIN, INT_MAX);
 }
 
+
 /* ************************** timer for testing ***************** */
 
 /* uses no type defines, fully local testing function anyway... ;) */
@@ -1596,6 +1701,10 @@ void wm_operatortype_init(void)
        WM_operatortype_append(WM_OT_ten_timer);
        WM_operatortype_append(WM_OT_debug_menu);
        WM_operatortype_append(WM_OT_search_menu);
+
+       /* XXX: move these */
+       WM_operatortype_append(WM_OT_collada_export);
+       WM_operatortype_append(WM_OT_collada_import);
 }
 
 /* default keymap for windows and screens, only call once per WM */