1
0
mirror of https://gitlab.gnome.org/GNOME/nautilus synced 2024-06-30 23:46:35 +00:00

window-slot: Introduce :mode property

The slot and its internals are going to be reused by the upcoming
FileChooser window, as part of a FileChooser portal implementation.

However, some behaviors and UI elements are going to be different.
So, the slot needs to know on which mode to operate from the start.

There are 3 FileChooser portal methods[0]:

  - OpenFile
  - SaveFile
  - SaveFiles

But OpenFile has 2 boolean options ("directory" and "multiple) which
mean there are actually 4 modes:

  1. select single file
  2. select single folder
  3. select multiple files
  4. select multiple folders

As such, we have 6 new modes to support, in addition to the "browse"
mode (i.e., business as usual).

[0]
https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.FileChooser.html
This commit is contained in:
António Fernandes 2024-06-16 17:05:22 +01:00
parent 4fd70e94a0
commit 82403ad89a
5 changed files with 75 additions and 4 deletions

View File

@ -17,6 +17,7 @@ libnautilus_sources = [
'gtk/nautilusgtkplacessidebarprivate.h',
'nautilus-enums.h',
'nautilus-location-banner.h',
'nautilus-mode.h',
'nautilus-search-popover.h',
'nautilus-query.h',
'nautilus-search-provider.h'

38
src/nautilus-mode.h Normal file
View File

@ -0,0 +1,38 @@
/*
* Copyright (C) 2024 GNOME Foundation Inc.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
* Original Author: António Fernandes <antoniof@gnome.org>
*/
#pragma once
#include <glib.h>
typedef enum
{
NAUTILUS_MODE_BROWSE = 0,
NAUTILUS_MODE_OPEN_FILE,
NAUTILUS_MODE_OPEN_FILES,
NAUTILUS_MODE_OPEN_FOLDER,
NAUTILUS_MODE_OPEN_FOLDERS,
NAUTILUS_MODE_SAVE_FILE,
NAUTILUS_MODE_SAVE_FILES,
} NautilusMode;
#define nautilus_mode_is_save(mode) \
((mode) == NAUTILUS_MODE_SAVE_FILE || \
(mode) == NAUTILUS_MODE_SAVE_FILES)
#define nautilus_mode_is_open(mode) \
((mode) == NAUTILUS_MODE_OPEN_FILE || \
(mode) == NAUTILUS_MODE_OPEN_FILES || \
(mode) == NAUTILUS_MODE_OPEN_FOLDER || \
(mode) == NAUTILUS_MODE_OPEN_FOLDERS)
#define nautilus_mode_is_single_selection(mode) \
((mode) == NAUTILUS_MODE_OPEN_FILE || \
(mode) == NAUTILUS_MODE_OPEN_FOLDER || \
(mode) == NAUTILUS_MODE_SAVE_FILE || \
(mode) == NAUTILUS_MODE_SAVE_FILES)

View File

@ -27,6 +27,7 @@
#include "nautilus-application.h"
#include "nautilus-bookmark.h"
#include "nautilus-bookmark-list.h"
#include "nautilus-enum-types.h"
#include "nautilus-fd-holder.h"
#include "nautilus-files-view.h"
#include "nautilus-location-banner.h"
@ -50,6 +51,7 @@
enum
{
PROP_ACTIVE = 1,
PROP_MODE,
PROP_ICON_NAME,
PROP_TOOLBAR_MENU_SECTIONS,
PROP_EXTENSIONS_BACKGROUND_MENU,
@ -69,6 +71,8 @@ struct _NautilusWindowSlot
{
AdwBin parent_instance;
NautilusMode mode;
gboolean active : 1;
guint loading : 1;
@ -662,6 +666,12 @@ nautilus_window_slot_set_property (GObject *object,
switch (property_id)
{
case PROP_MODE:
{
self->mode = g_value_get_enum (value);
}
break;
case PROP_LOCATION:
{
nautilus_window_slot_set_location (self, g_value_get_object (value));
@ -747,6 +757,12 @@ nautilus_window_slot_get_property (GObject *object,
}
break;
case PROP_MODE:
{
g_value_set_enum (value, nautilus_window_slot_get_mode (self));
}
break;
case PROP_ICON_NAME:
{
g_value_set_static_string (value, nautilus_window_slot_get_icon_name (self));
@ -2895,6 +2911,11 @@ nautilus_window_slot_class_init (NautilusWindowSlotClass *klass)
FALSE,
G_PARAM_READABLE);
properties[PROP_MODE] =
g_param_spec_enum ("mode", NULL, NULL,
NAUTILUS_TYPE_MODE, NAUTILUS_MODE_BROWSE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
properties[PROP_LOADING] =
g_param_spec_boolean ("loading",
"Whether the slot loading",
@ -3131,9 +3152,10 @@ nautilus_window_slot_get_forward_history (NautilusWindowSlot *self)
}
NautilusWindowSlot *
nautilus_window_slot_new (void)
nautilus_window_slot_new (NautilusMode mode)
{
return g_object_new (NAUTILUS_TYPE_WINDOW_SLOT,
"mode", mode,
NULL);
}
@ -3274,6 +3296,14 @@ nautilus_window_slot_set_loading (NautilusWindowSlot *self,
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_LOADING]);
}
NautilusMode
nautilus_window_slot_get_mode (NautilusWindowSlot *self)
{
g_return_val_if_fail (NAUTILUS_IS_WINDOW_SLOT (self), NAUTILUS_MODE_BROWSE);
return self->mode;
}
gboolean
nautilus_window_slot_get_loading (NautilusWindowSlot *self)
{

View File

@ -26,6 +26,7 @@
#include <gtk/gtk.h>
#include <adwaita.h>
#include "nautilus-mode.h"
#include "nautilus-types.h"
typedef enum {
@ -46,13 +47,14 @@ typedef struct
NautilusQuery *current_search_query;
} NautilusNavigationState;
NautilusWindowSlot * nautilus_window_slot_new (void);
NautilusWindowSlot * nautilus_window_slot_new (NautilusMode mode);
void nautilus_window_slot_open_location_full (NautilusWindowSlot *slot,
GFile *location,
NautilusOpenFlags flags,
GList *new_selection);
NautilusMode nautilus_window_slot_get_mode (NautilusWindowSlot *slot);
GFile * nautilus_window_slot_get_location (NautilusWindowSlot *slot);
GFile * nautilus_window_slot_get_pending_location (NautilusWindowSlot *slot);

View File

@ -494,7 +494,7 @@ nautilus_window_create_and_init_slot (NautilusWindow *window,
{
NautilusWindowSlot *slot;
slot = nautilus_window_slot_new ();
slot = nautilus_window_slot_new (NAUTILUS_MODE_BROWSE);
nautilus_window_initialize_slot (window, slot, flags);
return slot;
@ -1718,7 +1718,7 @@ nautilus_window_back_or_forward_in_new_tab (NautilusWindow *window,
NautilusNavigationState *state;
window_slot = nautilus_window_get_active_slot (window);
new_slot = nautilus_window_slot_new ();
new_slot = nautilus_window_slot_new (NAUTILUS_MODE_BROWSE);
state = nautilus_window_slot_get_navigation_state (window_slot);
/* Manually fix up the back / forward lists and location.