Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/windowmanager/intern/wm_files.c')
-rw-r--r--source/blender/windowmanager/intern/wm_files.c173
1 files changed, 106 insertions, 67 deletions
diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c
index 561e27f933d..4706287a3a9 100644
--- a/source/blender/windowmanager/intern/wm_files.c
+++ b/source/blender/windowmanager/intern/wm_files.c
@@ -50,6 +50,7 @@
#include "MEM_guardedalloc.h"
#include "BLI_blenlib.h"
+#include "BLI_fileops_types.h"
#include "BLI_linklist.h"
#include "BLI_system.h"
#include "BLI_threads.h"
@@ -69,6 +70,7 @@
#include "DNA_windowmanager_types.h"
#include "DNA_workspace_types.h"
+#include "BKE_addon.h"
#include "BKE_appdir.h"
#include "BKE_autoexec.h"
#include "BKE_blender.h"
@@ -388,13 +390,21 @@ static void wm_window_match_do(bContext *C,
/** \name Preferences Initialization & Versioning
* \{ */
-/* in case UserDef was read, we re-initialize all, and do versioning */
+/**
+ * In case #UserDef was read, re-initialize values that depend on it.
+ */
static void wm_init_userdef(Main *bmain)
{
- /* versioning is here */
- UI_init_userdef(bmain);
+ /* Not versioning, just avoid errors. */
+#ifndef WITH_CYCLES
+ BKE_addon_remove_safe(&U.addons, "cycles");
+#else
+ UNUSED_VARS(BKE_addon_remove_safe);
+#endif
- /* needed so loading a file from the command line respects user-pref [#26156] */
+ UI_init_userdef();
+
+ /* needed so loading a file from the command line respects user-pref T26156. */
SET_FLAG_FROM_TEST(G.fileflags, U.flag & USER_FILENOUI, G_FILE_NO_UI);
/* set the python auto-execute setting from user prefs */
@@ -406,11 +416,13 @@ static void wm_init_userdef(Main *bmain)
MEM_CacheLimiter_set_maximum(((size_t)U.memcachelimit) * 1024 * 1024);
BKE_sound_init(bmain);
- /* update tempdir from user preferences */
+ /* Update the temporary directory from the preferences or fallback to the system default. */
BKE_tempdir_init(U.tempdir);
/* Update tablet API preference. */
WM_init_tablet_api();
+
+ BLO_sanitize_experimental_features_userpref_blend(&U);
}
/* return codes */
@@ -1020,20 +1032,17 @@ void wm_homefile_read(bContext *C,
if (!use_factory_settings || (filepath_startup[0] != '\0')) {
if (BLI_access(filepath_startup, R_OK) == 0) {
- success = BKE_blendfile_read(C,
- filepath_startup,
- &(const struct BlendFileReadParams){
- .is_startup = true,
- .skip_flags = skip_flags | BLO_READ_SKIP_USERDEF,
- },
- NULL);
+ success = BKE_blendfile_read_ex(C,
+ filepath_startup,
+ &(const struct BlendFileReadParams){
+ .is_startup = true,
+ .skip_flags = skip_flags | BLO_READ_SKIP_USERDEF,
+ },
+ NULL,
+ update_defaults && use_data,
+ app_template);
}
if (success) {
- if (update_defaults) {
- if (use_data) {
- BLO_update_defaults_startup_blend(CTX_data_main(C), app_template);
- }
- }
is_factory_startup = filepath_startup_is_factory;
}
}
@@ -1052,15 +1061,16 @@ void wm_homefile_read(bContext *C,
}
if (success == false) {
- success = BKE_blendfile_read_from_memory(C,
- datatoc_startup_blend,
- datatoc_startup_blend_size,
- true,
- &(const struct BlendFileReadParams){
- .is_startup = true,
- .skip_flags = skip_flags,
- },
- NULL);
+ success = BKE_blendfile_read_from_memory_ex(C,
+ datatoc_startup_blend,
+ datatoc_startup_blend_size,
+ &(const struct BlendFileReadParams){
+ .is_startup = true,
+ .skip_flags = skip_flags,
+ },
+ NULL,
+ true,
+ NULL);
if (use_data && BLI_listbase_is_empty(&wmbase)) {
wm_clear_default_size(C);
@@ -2359,10 +2369,47 @@ static int wm_open_mainfile_exec(bContext *C, wmOperator *op)
return wm_open_mainfile__open(C, op);
}
+static char *wm_open_mainfile_description(struct bContext *UNUSED(C),
+ struct wmOperatorType *UNUSED(op),
+ struct PointerRNA *params)
+{
+ if (!RNA_struct_property_is_set(params, "filepath")) {
+ return NULL;
+ }
+
+ /* Filepath. */
+ char path[FILE_MAX];
+ RNA_string_get(params, "filepath", path);
+
+ BLI_stat_t stats;
+ if (BLI_stat(path, &stats) == -1) {
+ return BLI_sprintfN("%s\n\n%s", path, N_("File Not Found"));
+ }
+
+ /* Date. */
+ char date_st[FILELIST_DIRENTRY_DATE_LEN];
+ char time_st[FILELIST_DIRENTRY_TIME_LEN];
+ bool is_today, is_yesterday;
+ BLI_filelist_entry_datetime_to_string(
+ NULL, (int64_t)stats.st_mtime, false, time_st, date_st, &is_today, &is_yesterday);
+ if (is_today || is_yesterday) {
+ BLI_strncpy(date_st, is_today ? N_("Today") : N_("Yesterday"), sizeof(date_st));
+ }
+
+ /* Size. */
+ char size_str[FILELIST_DIRENTRY_SIZE_LEN];
+ BLI_filelist_entry_size_to_string(NULL, (uint64_t)stats.st_size, false, size_str);
+
+ return BLI_sprintfN(
+ "%s\n\n%s: %s %s\n%s: %s", path, N_("Modified"), date_st, time_st, N_("Size"), size_str);
+}
+
/* currently fits in a pointer */
struct FileRuntime {
bool is_untrusted;
};
+BLI_STATIC_ASSERT(sizeof(struct FileRuntime) <= sizeof(void *),
+ "Struct must not exceed pointer size");
static bool wm_open_mainfile_check(bContext *UNUSED(C), wmOperator *op)
{
@@ -2421,6 +2468,7 @@ void WM_OT_open_mainfile(wmOperatorType *ot)
ot->name = "Open";
ot->idname = "WM_OT_open_mainfile";
ot->description = "Open a Blender file";
+ ot->get_description = wm_open_mainfile_description;
ot->invoke = wm_open_mainfile_invoke;
ot->exec = wm_open_mainfile_exec;
@@ -2434,7 +2482,7 @@ void WM_OT_open_mainfile(wmOperatorType *ot)
FILE_OPENFILE,
WM_FILESEL_FILEPATH,
FILE_DEFAULTDISPLAY,
- FILE_SORT_ALPHA);
+ FILE_SORT_DEFAULT);
RNA_def_boolean(
ot->srna, "load_ui", true, "Load UI", "Load user interface setup in the .blend file");
@@ -2756,7 +2804,7 @@ void WM_OT_save_as_mainfile(wmOperatorType *ot)
FILE_SAVE,
WM_FILESEL_FILEPATH,
FILE_DEFAULTDISPLAY,
- FILE_SORT_ALPHA);
+ FILE_SORT_DEFAULT);
RNA_def_boolean(ot->srna, "compress", false, "Compress", "Write compressed .blend file");
RNA_def_boolean(ot->srna,
"relative_remap",
@@ -2826,7 +2874,7 @@ void WM_OT_save_mainfile(wmOperatorType *ot)
FILE_SAVE,
WM_FILESEL_FILEPATH,
FILE_DEFAULTDISPLAY,
- FILE_SORT_ALPHA);
+ FILE_SORT_DEFAULT);
RNA_def_boolean(ot->srna, "compress", false, "Compress", "Write compressed .blend file");
RNA_def_boolean(ot->srna,
"relative_remap",
@@ -2901,6 +2949,9 @@ static uiBlock *block_create_autorun_warning(struct bContext *C,
{
wmWindowManager *wm = CTX_wm_manager(C);
const uiStyle *style = UI_style_get_dpi();
+ const int text_points_max = MAX2(style->widget.points, style->widgetlabel.points);
+ const int dialog_width = text_points_max * 44 * U.dpi_fac;
+
uiBlock *block = UI_block_begin(C, region, "autorun_warning_popup", UI_EMBOSS);
UI_block_flag_enable(
@@ -2908,15 +2959,8 @@ static uiBlock *block_create_autorun_warning(struct bContext *C,
UI_block_theme_style_set(block, UI_BLOCK_THEME_STYLE_POPUP);
UI_block_emboss_set(block, UI_EMBOSS);
- uiLayout *layout = UI_block_layout(block,
- UI_LAYOUT_VERTICAL,
- UI_LAYOUT_PANEL,
- 10,
- 2,
- U.widget_unit * 24,
- U.widget_unit * 6,
- 0,
- style);
+ uiLayout *layout = UI_block_layout(
+ block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 10, 2, dialog_width, 0, 0, style);
/* Text and some vertical space */
uiLayout *col = uiLayoutColumn(layout, true);
@@ -3142,11 +3186,17 @@ static uiBlock *block_create__close_file_dialog(struct bContext *C,
wmGenericCallback *post_action = (wmGenericCallback *)arg1;
Main *bmain = CTX_data_main(C);
const uiStyle *style = UI_style_get_dpi();
- const int dialog_width = U.widget_unit * 22;
const short icon_size = 64 * U.dpi_fac;
+ const int text_points_max = MAX2(style->widget.points, style->widgetlabel.points);
+ const int dialog_width = icon_size + (text_points_max * 34 * U.dpi_fac);
+ /* By default, the space between icon and text/buttons will be equal to the 'columnspace',
+ this extra padding will add some space by increasing the left column width,
+ making the icon placement more symmetrical, between the block edge and the text. */
+ const float icon_padding = 6.0f * U.dpi_fac;
/* Calculate icon column factor. */
- const float split_factor = (float)icon_size / (float)(dialog_width - style->columnspace);
+ const float split_factor = ((float)icon_size + icon_padding) /
+ (float)(dialog_width - style->columnspace);
uiBlock *block = UI_block_begin(C, region, close_file_dialog_name, UI_EMBOSS);
@@ -3162,8 +3212,10 @@ static uiBlock *block_create__close_file_dialog(struct bContext *C,
uiLayout *split_block = uiLayoutSplit(block_layout, split_factor, false);
/* Alert Icon. */
- uiLayout *layout = uiLayoutColumn(split_block, false);
- uiDefButAlert(block, ALERT_ICON_WARNING, 0, 0, 0, icon_size);
+ uiLayout *layout = uiLayoutRow(split_block, false);
+ /* Using 'align_left' with 'row' avoids stretching the icon along the width of column. */
+ uiLayoutSetAlignment(layout, UI_LAYOUT_ALIGN_LEFT);
+ uiDefButAlert(block, ALERT_ICON_QUESTION, 0, 0, icon_size, icon_size);
/* The rest of the content on the right. */
layout = uiLayoutColumn(split_block, false);
@@ -3176,10 +3228,9 @@ static uiBlock *block_create__close_file_dialog(struct bContext *C,
char filename[FILE_MAX];
if (blendfile_pathpath[0] != '\0') {
BLI_split_file_part(blendfile_pathpath, filename, sizeof(filename));
- BLI_path_extension_replace(filename, sizeof(filename), "");
}
else {
- STRNCPY(filename, IFACE_("Untitled"));
+ STRNCPY(filename, IFACE_("untitled.blend"));
}
uiItemL(layout, filename, ICON_NONE);
@@ -3191,7 +3242,7 @@ static uiBlock *block_create__close_file_dialog(struct bContext *C,
LISTBASE_FOREACH (Report *, report, &reports.list) {
uiLayout *row = uiLayoutColumn(layout, false);
uiLayoutSetScaleY(row, 0.6f);
- uiItemS_ex(row, 1.2f);
+ uiItemS(row);
/* Error messages created in ED_image_save_all_modified_info() can be long,
* but are made to separate into two parts at first colon between text and paths.
@@ -3214,12 +3265,8 @@ static uiBlock *block_create__close_file_dialog(struct bContext *C,
/* Modified Images Checkbox. */
if (modified_images_count > 0) {
char message[64];
- BLI_snprintf(message,
- sizeof(message),
- (modified_images_count == 1) ? "Save %u modified image" :
- "Save %u modified images",
- modified_images_count);
- uiItemS_ex(layout, 2.0f);
+ BLI_snprintf(message, sizeof(message), "Save %u modified image(s)", modified_images_count);
+ uiItemS(layout);
uiDefButBitC(block,
UI_BTYPE_CHECKBOX,
1,
@@ -3239,7 +3286,7 @@ static uiBlock *block_create__close_file_dialog(struct bContext *C,
BKE_reports_clear(&reports);
- uiItemS_ex(layout, 1.0f);
+ uiItemS_ex(layout, modified_images_count > 0 ? 2.0f : 4.0f);
/* Buttons. */
#ifdef _WIN32
@@ -3251,13 +3298,10 @@ static uiBlock *block_create__close_file_dialog(struct bContext *C,
if (windows_layout) {
/* Windows standard layout. */
- uiLayout *split = uiLayoutSplit(block_layout, 0.174f, true);
+ uiLayout *split = uiLayoutSplit(layout, 0.0f, true);
uiLayoutSetScaleY(split, 1.2f);
uiLayoutColumn(split, false);
- uiItemS(layout);
-
- uiLayoutColumn(split, false);
wm_block_file_close_save_button(block, post_action);
uiLayoutColumn(split, false);
@@ -3269,21 +3313,16 @@ static uiBlock *block_create__close_file_dialog(struct bContext *C,
else {
/* Non-Windows layout (macOS and Linux). */
- uiLayout *split = uiLayoutSplit(block_layout, 0.167f, true);
+ uiLayout *split = uiLayoutSplit(layout, 0.3f, true);
uiLayoutSetScaleY(split, 1.2f);
- layout = uiLayoutColumn(split, false);
- uiItemS(layout);
-
- /* Split button area into two sections: 40/60. */
- uiLayout *split_left = uiLayoutSplit(split, 0.40f, true);
-
- /* First button uses 75% of left side (30% of original). */
- uiLayoutSplit(split_left, 0.75f, true);
+ uiLayoutColumn(split, false);
wm_block_file_close_discard_button(block, post_action);
- /* The right side is split 50/50 (each 30% of original). */
- uiLayout *split_right = uiLayoutSplit(split_left, 0.50f, true);
+ uiLayout *split_right = uiLayoutSplit(split, 0.1f, true);
+
+ uiLayoutColumn(split_right, false);
+ /* Empty space. */
uiLayoutColumn(split_right, false);
wm_block_file_close_cancel_button(block, post_action);