UI: Preference for file browser as fullscreen area
authorJulian Eisel <eiseljulian@gmail.com>
Wed, 18 Sep 2019 12:37:11 +0000 (14:37 +0200)
committerJulian Eisel <eiseljulian@gmail.com>
Wed, 18 Sep 2019 12:37:11 +0000 (14:37 +0200)
Addes a Preference setting to choose between opening new file browsers
in a maximized area (like with the old file browser) or in a new window
(like the new one).

release/scripts/startup/bl_ui/space_userpref.py
source/blender/blenloader/intern/versioning_userdef.c
source/blender/makesdna/DNA_userdef_types.h
source/blender/makesrna/intern/rna_userdef.c
source/blender/windowmanager/intern/wm_event_system.c

index 89b4819eac76eb2f4ac008b65b0b9c35d02ca52a..2384cd0fe38f9fabe0d2f37738caf10953983ae8 100644 (file)
@@ -282,6 +282,7 @@ class USERPREF_PT_interface_temporary_windows(PreferencePanel, Panel):
         flow = layout.grid_flow(row_major=False, columns=0, even_columns=True, even_rows=False, align=False)
 
         flow.prop(view, "render_display_type", text="Render in")
+        flow.prop(view, "filebrowser_display_type", text="File Browser")
 
 
 class USERPREF_PT_interface_menus(Panel):
index c1c398c32d030f9d614074649e7262e3a3c8788a..75b87c4f1f00beefdae7d4669750f9ff6af9a210 100644 (file)
@@ -621,6 +621,7 @@ void BLO_version_defaults_userpref_blend(Main *bmain, UserDef *userdef)
   {
     /* pass */
     userdef->render_display_type = USER_RENDER_DISPLAY_WINDOW;
+    userdef->filebrowser_display_type = USER_TEMP_SPACE_DISPLAY_WINDOW;
   }
 
   if (userdef->pixelsize == 0.0f) {
index 22da2a860548ebc7379c2f175b4988a94b661098..1110b0fb8b50ca958fa6536c0dd83bf06a4bbe4a 100644 (file)
@@ -815,7 +815,8 @@ typedef struct UserDef {
   char viewport_aa;
 
   char render_display_type;      /* eUserpref_RenderDisplayType */
-  char _pad5[5];
+  char filebrowser_display_type; /* eUserpref_TempSpaceDisplayType */
+  char _pad5[4];
 
   struct WalkNavigation walk_navigation;
 
index 5b75bca89f34e052510f37ccc46ebdb201d220ee..d61c2399592190a8c5bd19f51bf79a1c31306667 100644 (file)
@@ -4310,6 +4310,12 @@ static void rna_def_userdef_view(BlenderRNA *brna)
   RNA_def_property_ui_text(
       prop, "Render Display Type", "Default location where rendered images will be displayed in");
 
+  prop = RNA_def_property(srna, "filebrowser_display_type", PROP_ENUM, PROP_NONE);
+  RNA_def_property_enum_items(prop, temp_space_display_types);
+  RNA_def_property_ui_text(prop,
+                           "File Browser Display Type",
+                           "Default location where the File Editor will be displayed in");
+
   static const EnumPropertyItem text_hinting_items[] = {
       {0, "AUTO", 0, "Auto", ""},
       {USER_TEXT_HINTING_NONE, "NONE", 0, "None", ""},
index 347e26e0ba51da56b4e34e65e8482dfef3f060bd..47b77cf435bf796a0d3c76c44f045a00baf8f83a 100644 (file)
@@ -2346,15 +2346,16 @@ static int wm_handler_fileselect_do(bContext *C,
       wmWindow *win = CTX_wm_window(C);
       const int sizex = 1020 * UI_DPI_FAC;
       const int sizey = 600 * UI_DPI_FAC;
-
-      if (WM_window_open_temp(C,
-                              IFACE_("Blender File View"),
-                              WM_window_pixels_x(win) / 2,
-                              WM_window_pixels_y(win) / 2,
-                              sizex,
-                              sizey,
-                              SPACE_FILE) != NULL) {
-        ScrArea *area = CTX_wm_area(C);
+      ScrArea *area;
+
+      if ((area = ED_screen_temp_space_open(C,
+                                            IFACE_("Blender File View"),
+                                            WM_window_pixels_x(win) / 2,
+                                            WM_window_pixels_y(win) / 2,
+                                            sizex,
+                                            sizey,
+                                            SPACE_FILE,
+                                            U.filebrowser_display_type))) {
         ARegion *region_header = BKE_area_find_region_type(area, RGN_TYPE_HEADER);
 
         BLI_assert(area->spacetype == SPACE_FILE);
@@ -2393,17 +2394,18 @@ static int wm_handler_fileselect_do(bContext *C,
         }
       }
       else {
-        for (wmWindow *win = wm->windows.first; win; win = win->next) {
-          if (WM_window_is_temp_screen(win)) {
-            bScreen *screen = WM_window_get_active_screen(win);
-            ScrArea *file_sa = screen->areabase.first;
+        wmWindow *temp_win;
+        ScrArea *ctx_sa = CTX_wm_area(C);
 
-            BLI_assert(file_sa->spacetype == SPACE_FILE);
+        for (temp_win = wm->windows.first; temp_win; temp_win = temp_win->next) {
+          bScreen *screen = WM_window_get_active_screen(temp_win);
+          ScrArea *file_sa = screen->areabase.first;
 
+          if (screen->temp && (file_sa->spacetype == SPACE_FILE)) {
             if (BLI_listbase_is_single(&file_sa->spacedata)) {
-              BLI_assert(ctx_win != win);
+              BLI_assert(ctx_win != temp_win);
 
-              wm_window_close(C, wm, win);
+              wm_window_close(C, wm, temp_win);
 
               CTX_wm_window_set(C, ctx_win);  // wm_window_close() NULLs.
               /* Some operators expect a drawable context (for EVT_FILESELECT_EXEC) */
@@ -2412,7 +2414,7 @@ static int wm_handler_fileselect_do(bContext *C,
                * opening (UI_BLOCK_MOVEMOUSE_QUIT) */
               wm_get_cursor_position(ctx_win, &ctx_win->eventstate->x, &ctx_win->eventstate->y);
               wm->winactive = ctx_win; /* Reports use this... */
-              if (handler->context.win == win) {
+              if (handler->context.win == temp_win) {
                 handler->context.win = NULL;
               }
             }
@@ -2426,6 +2428,10 @@ static int wm_handler_fileselect_do(bContext *C,
             break;
           }
         }
+
+        if (!temp_win && ctx_sa->full) {
+          ED_screen_full_prevspace(C, ctx_sa);
+        }
       }
 
       wm_handler_op_context(C, handler, ctx_win->eventstate);
@@ -3539,15 +3545,50 @@ void WM_event_add_fileselect(bContext *C, wmOperator *op)
 {
   wmWindowManager *wm = CTX_wm_manager(C);
   wmWindow *win = CTX_wm_window(C);
+  const bool is_temp_screen = WM_window_is_temp_screen(win);
   /* Don't add the file handler to the temporary window, or else it owns the handlers for itself,
    * causing dangling pointers once it's destructed through a handler. It has a parent which should
    * hold the handlers itself. */
-  ListBase *modalhandlers = WM_window_is_temp_screen(win) ? &win->parent->modalhandlers :
-                                                            &win->modalhandlers;
+  ListBase *modalhandlers = is_temp_screen ? &win->parent->modalhandlers : &win->modalhandlers;
 
   /* Close any popups, like when opening a file browser from the splash. */
   UI_popup_handlers_remove_all(C, modalhandlers);
 
+  if (!is_temp_screen) {
+    /* only allow 1 file selector open per window */
+    LISTBASE_FOREACH_MUTABLE (wmEventHandler *, handler_base, modalhandlers) {
+      if (handler_base->type == WM_HANDLER_TYPE_OP) {
+        wmEventHandler_Op *handler = (wmEventHandler_Op *)handler_base;
+        if (handler->is_fileselect == false) {
+          continue;
+        }
+        bScreen *screen = CTX_wm_screen(C);
+        bool cancel_handler = true;
+
+        /* find the area with the file selector for this handler */
+        ED_screen_areas_iter(win, screen, sa)
+        {
+          if (sa->spacetype == SPACE_FILE) {
+            SpaceFile *sfile = sa->spacedata.first;
+
+            if (sfile->op == handler->op) {
+              CTX_wm_area_set(C, sa);
+              wm_handler_fileselect_do(C, &win->modalhandlers, handler, EVT_FILESELECT_CANCEL);
+              cancel_handler = false;
+              break;
+            }
+          }
+        }
+
+        /* if not found we stop the handler without changing the screen */
+        if (cancel_handler) {
+          wm_handler_fileselect_do(
+              C, &win->modalhandlers, handler, EVT_FILESELECT_EXTERNAL_CANCEL);
+        }
+      }
+    }
+  }
+
   wmEventHandler_Op *handler = MEM_callocN(sizeof(*handler), __func__);
   handler->head.type = WM_HANDLER_TYPE_OP;