Exemplo n.º 1
0
/* the python exec operator uses this */
static int console_scrollback_append_exec(bContext *C, wmOperator *op)
{
	SpaceConsole *sc = CTX_wm_space_console(C);
	ARegion *ar = CTX_wm_region(C);
	ConsoleLine *ci;
	
	char *str = RNA_string_get_alloc(op->ptr, "text", NULL, 0); /* own this text in the new line, don't free */
	int type = RNA_enum_get(op->ptr, "type");

	console_history_verify(C);
	
	ci = console_scrollback_add_str(sc, str, 1); /* own the string */
	ci->type = type;
	
	console_scrollback_limit(sc);

	/* 'ar' can be null depending on the operator that runs
	 * rendering with invoke default for eg causes this */
	if (ar) {
		console_textview_update_rect(sc, ar);
	}

	ED_area_tag_redraw(CTX_wm_area(C));
	
	return OPERATOR_FINISHED;
}
Exemplo n.º 2
0
static int console_insert_exec(bContext *C, wmOperator *op)
{
	SpaceConsole *sc = CTX_wm_space_console(C);
	ARegion *ar = CTX_wm_region(C);
	ConsoleLine *ci = console_history_verify(C);
	char *str = RNA_string_get_alloc(op->ptr, "text", NULL, 0);
	int len;

	if (str[0] == '\t' && str[1] == '\0') {
		len = TAB_LENGTH;
		MEM_freeN(str);
		str = MEM_mallocN(len + 1, "insert_exec");
		memset(str, ' ', len);
		str[len] = '\0';
	}

	len = console_line_insert(ci, str);
	
	MEM_freeN(str);
	
	if (len == 0) {
		return OPERATOR_CANCELLED;
	}
	else {
		console_select_offset(sc, len);
	}

	console_textview_update_rect(sc, ar);
	ED_area_tag_redraw(CTX_wm_area(C));

	console_scroll_bottom(ar);

	return OPERATOR_FINISHED;
}
Exemplo n.º 3
0
/* the python exec operator uses this */
static int history_append_exec(bContext *C, wmOperator *op)
{
	SpaceConsole *sc= CTX_wm_space_console(C);
	ScrArea *sa= CTX_wm_area(C);
	ConsoleLine *ci= console_history_verify(C);
	char *str= RNA_string_get_alloc(op->ptr, "text", NULL, 0); /* own this text in the new line, dont free */
	int cursor= RNA_int_get(op->ptr, "current_character");
	short rem_dupes= RNA_boolean_get(op->ptr, "remove_duplicates");
	int prev_len= ci->len;

	if(rem_dupes) {
		ConsoleLine *cl;

		while((cl= console_history_find(sc, ci->line, ci)))
			console_history_free(sc, cl);

		if(strcmp(str, ci->line)==0) {
			MEM_freeN(str);
			return OPERATOR_FINISHED;
		}
	}

	ci= console_history_add_str(sc, str, 1); /* own the string */
	console_select_offset(sc, ci->len - prev_len);
	console_line_cursor_set(ci, cursor);

	ED_area_tag_redraw(sa);

	return OPERATOR_FINISHED;
}
Exemplo n.º 4
0
static int file_browse_exec(bContext *C, wmOperator *op)
{
	FileBrowseOp *fbo = op->customdata;
	ID *id;
	char *str, path[FILE_MAX];
	const char *path_prop = RNA_struct_find_property(op->ptr, "directory") ? "directory" : "filepath";
	
	if (RNA_struct_property_is_set(op->ptr, path_prop) == 0 || fbo == NULL)
		return OPERATOR_CANCELLED;
	
	str = RNA_string_get_alloc(op->ptr, path_prop, NULL, 0);

	/* add slash for directories, important for some properties */
	if (RNA_property_subtype(fbo->prop) == PROP_DIRPATH) {
		int is_relative = RNA_boolean_get(op->ptr, "relative_path");
		id = fbo->ptr.id.data;

		BLI_strncpy(path, str, FILE_MAX);
		BLI_path_abs(path, id ? ID_BLEND_PATH(G.main, id) : G.main->name);
		
		if (BLI_is_dir(path)) {
			/* do this first so '//' isnt converted to '//\' on windows */
			BLI_add_slash(path);
			if (is_relative) {
				BLI_strncpy(path, str, FILE_MAX);
				BLI_path_rel(path, G.main->name);
				str = MEM_reallocN(str, strlen(path) + 2);
				BLI_strncpy(str, path, FILE_MAX);
			}
			else {
				str = MEM_reallocN(str, strlen(str) + 2);
			}
		}
		else {
			char * const lslash = (char *)BLI_last_slash(str);
			if (lslash) lslash[1] = '\0';
		}
	}

	RNA_property_string_set(&fbo->ptr, fbo->prop, str);
	RNA_property_update(C, &fbo->ptr, fbo->prop);
	MEM_freeN(str);


	/* special, annoying exception, filesel on redo panel [#26618] */
	{
		wmOperator *redo_op = WM_operator_last_redo(C);
		if (redo_op) {
			if (fbo->ptr.data == redo_op->ptr->data) {
				ED_undo_operator_repeat(C, redo_op);
			}
		}
	}

	MEM_freeN(op->customdata);

	return OPERATOR_FINISHED;
}
Exemplo n.º 5
0
static int find_missing_files_exec(bContext *C, wmOperator *op)
{
	Main *bmain= CTX_data_main(C);
	const char *searchpath= RNA_string_get_alloc(op->ptr, "filepath", NULL, 0);
	findMissingFiles(bmain, searchpath, op->reports);
	MEM_freeN((void *)searchpath);

	return OPERATOR_FINISHED;
}
Exemplo n.º 6
0
static int find_missing_files_exec(bContext *UNUSED(C), wmOperator *op)
{
	char *path;
	
	path= RNA_string_get_alloc(op->ptr, "filepath", NULL, 0);
	findMissingFiles(G.main, path);
	MEM_freeN(path);

	return OPERATOR_FINISHED;
}
Exemplo n.º 7
0
static int find_missing_files_exec(bContext *C, wmOperator *op)
{
	Main *bmain = CTX_data_main(C);
	const char *searchpath = RNA_string_get_alloc(op->ptr, "directory", NULL, 0);
	const bool find_all = RNA_boolean_get(op->ptr, "find_all");

	BKE_bpath_missing_files_find(bmain, searchpath, op->reports, find_all);
	MEM_freeN((void *)searchpath);

	return OPERATOR_FINISHED;
}
Exemplo n.º 8
0
static int file_browse_exec(bContext *C, wmOperator *op)
{
	FileBrowseOp *fbo= op->customdata;
	ID *id;
	char *base, *str, path[FILE_MAX];
	const char *path_prop= RNA_struct_find_property(op->ptr, "directory") ? "directory" : "filepath";
	
	if (RNA_property_is_set(op->ptr, path_prop)==0 || fbo==NULL)
		return OPERATOR_CANCELLED;
	
	str= RNA_string_get_alloc(op->ptr, path_prop, NULL, 0);

	/* add slash for directories, important for some properties */
	if(RNA_property_subtype(fbo->prop) == PROP_DIRPATH) {
		char name[FILE_MAX];
		
		id = fbo->ptr.id.data;
		base = (id && id->lib)? id->lib->filepath: G.main->name;

		BLI_strncpy(path, str, FILE_MAX);
		BLI_path_abs(path, base);
		
		if(BLI_is_dir(path)) {
			str = MEM_reallocN(str, strlen(str)+2);
			BLI_add_slash(str);
		}
		else
			BLI_splitdirstring(str, name);
	}

	RNA_property_string_set(&fbo->ptr, fbo->prop, str);
	RNA_property_update(C, &fbo->ptr, fbo->prop);
	MEM_freeN(str);


	/* special, annoying exception, filesel on redo panel [#26618] */
	{
		wmOperator *redo_op= WM_operator_last_redo(C);
		if(redo_op) {
			if(fbo->ptr.data == redo_op->ptr->data) {
				ED_undo_operator_repeat(C, redo_op);
			}
		}
	}

	MEM_freeN(op->customdata);

	return OPERATOR_FINISHED;
}
Exemplo n.º 9
0
/* the python exec operator uses this */
static int scrollback_append_exec(bContext *C, wmOperator *op)
{
	SpaceConsole *sc= CTX_wm_space_console(C);
	ARegion *ar= CTX_wm_region(C);
	ConsoleLine *ci;
	
	char *str= RNA_string_get_alloc(op->ptr, "text", NULL, 0); /* own this text in the new line, dont free */
	int type= RNA_enum_get(op->ptr, "type");

	console_history_verify(C);
	
	ci= console_scrollback_add_str(sc, str, 1); /* own the string */
	ci->type= type;
	
	console_scrollback_limit(sc);

	console_textview_update_rect(sc, ar);
	ED_area_tag_redraw(CTX_wm_area(C));
	
	return OPERATOR_FINISHED;
}
Exemplo n.º 10
0
/* the python exec operator uses this */
static int console_history_append_exec(bContext *C, wmOperator *op)
{
	SpaceConsole *sc = CTX_wm_space_console(C);
	ARegion *ar = CTX_wm_region(C);
	ScrArea *sa = CTX_wm_area(C);
	ConsoleLine *ci = console_history_verify(C);
	char *str = RNA_string_get_alloc(op->ptr, "text", NULL, 0); /* own this text in the new line, don't free */
	int cursor = RNA_int_get(op->ptr, "current_character");
	const bool rem_dupes = RNA_boolean_get(op->ptr, "remove_duplicates");
	int prev_len = ci->len;

	if (rem_dupes) {
		ConsoleLine *cl;

		while ((cl = console_history_find(sc, ci->line, ci)))
			console_history_free(sc, cl);

		if (STREQ(str, ci->line)) {
			MEM_freeN(str);
			return OPERATOR_FINISHED;
		}
	}

	ci = console_history_add_str(sc, str, 1); /* own the string */
	console_select_offset(sc, ci->len - prev_len);
	console_line_cursor_set(ci, cursor);

	ED_area_tag_redraw(sa);

	/* when calling render modally this can be NULL when calling:
	 * bpy.ops.render.render('INVOKE_DEFAULT') */
	if (ar) {
		console_scroll_bottom(ar);
	}

	return OPERATOR_FINISHED;
}