Changeset View
Changeset View
Standalone View
Standalone View
source/blender/windowmanager/intern/wm_operators.c
| Context not available. | |||||
| RNA_def_property_flag(prop, PROP_SKIP_SAVE); | RNA_def_property_flag(prop, PROP_SKIP_SAVE); | ||||
| } | } | ||||
| /* *************** revert save **************** */ | |||||
| static int wm_revert_mainfile_exec(bContext *C, wmOperator *op) | |||||
| { | |||||
| char* filename; | |||||
| filename = G.main->name; | |||||
| if(filename[0]) { | |||||
| if (BLI_exists(filename)) { | |||||
| /* XXX wm in context is not set correctly after WM_file_read -> crash */ | |||||
campbellbarton: Checking `filename` isnt NULL makes no sense, its assigned from a fixed length array.
also… | |||||
| /* do it before for now, but is this correct with multiple windows? */ | |||||
| WM_event_add_notifier(C, NC_WINDOW, NULL); | |||||
Not Done Inline Actionsno need to check for reports operators always set. campbellbarton: no need to check for `reports` operators always set. | |||||
Not Done Inline ActionsIf the filename doesnt exist, it should probably report that... or allow open to. campbellbarton: If the `filename` doesnt exist, it should probably report that... or allow open to. | |||||
| /* load file */ | |||||
| WM_file_autoexec_init(filename); | |||||
| WM_file_read(C, filename, op->reports); | |||||
| return OPERATOR_FINISHED; | |||||
| } else { | |||||
| /* display error message because file doesn't exist */ | |||||
| BKE_report(op->reports, RPT_ERROR, "File does not exist"); | |||||
| } | |||||
| } else { | |||||
Not Done Inline Actionseven if this fails it will return finished, think this should return canceled on failure. campbellbarton: even if this fails it will return finished, think this should return canceled on failure. | |||||
| /* display error message because file hasn't been saved */ | |||||
| BKE_report(op->reports, RPT_ERROR, "File has not been saved before"); | |||||
| } | |||||
| return OPERATOR_CANCELLED; | |||||
| } | |||||
| static int wm_revert_mainfile_poll(bContext *UNUSED(C)) | |||||
Not Done Inline Actionsno need to check fixed lenth array for NULL, just check G.main->name[0] is enough campbellbarton: no need to check fixed lenth array for NULL, just check `G.main->name[0]` is enough | |||||
| { | |||||
| /* make sure file has been saved before */ | |||||
| if (G.main->name[0]) { | |||||
| return 1; | |||||
| } | |||||
| return 0; | |||||
| } | |||||
| static void WM_OT_revert_mainfile(wmOperatorType *ot) | |||||
| { | |||||
| ot->name = "Revert"; | |||||
| ot->idname = "WM_OT_revert_mainfile"; | |||||
| ot->description = "Reload the current save"; | |||||
| ot->invoke = WM_operator_confirm; | |||||
| ot->exec = wm_revert_mainfile_exec; | |||||
| ot->poll = wm_revert_mainfile_poll; | |||||
| } | |||||
| /* *************** recover last session **************** */ | /* *************** recover last session **************** */ | ||||
| void WM_recover_last_session(bContext *C, ReportList *reports) | void WM_recover_last_session(bContext *C, ReportList *reports) | ||||
| Context not available. | |||||
| WM_operatortype_append(WM_OT_quit_blender); | WM_operatortype_append(WM_OT_quit_blender); | ||||
| WM_operatortype_append(WM_OT_open_mainfile); | WM_operatortype_append(WM_OT_open_mainfile); | ||||
| WM_operatortype_append(WM_OT_link_append); | WM_operatortype_append(WM_OT_link_append); | ||||
| WM_operatortype_append(WM_OT_revert_mainfile); | |||||
| WM_operatortype_append(WM_OT_recover_last_session); | WM_operatortype_append(WM_OT_recover_last_session); | ||||
| WM_operatortype_append(WM_OT_recover_auto_save); | WM_operatortype_append(WM_OT_recover_auto_save); | ||||
| WM_operatortype_append(WM_OT_save_as_mainfile); | WM_operatortype_append(WM_OT_save_as_mainfile); | ||||
| Context not available. | |||||
Checking filename isnt NULL makes no sense, its assigned from a fixed length array.
also referencing both G.main->name and filename is unnecessarily confusing (use one or the other)
strlen(G.main->name) can be replaced with filename[0]