mirror of
https://gitlab.gnome.org/GNOME/nautilus
synced 2024-11-04 19:08:23 +00:00
internal-place-file: Introduce new file subclass
Instead of special casing the NautilusFile for the starred:/// URI, give it a proper display name as part of a new specialized subclass. This is prepared to handle more cases, like the upcoming Network view.
This commit is contained in:
parent
61032380f3
commit
7776f13c69
8 changed files with 148 additions and 15 deletions
|
@ -36,6 +36,7 @@ src/nautilus-file-undo-operations.c
|
|||
src/nautilus-file-utilities.c
|
||||
src/nautilus-filename-utilities.c
|
||||
src/nautilus-global-preferences.c
|
||||
src/nautilus-internal-place-file.c
|
||||
src/nautilus-list-view.c
|
||||
src/nautilus-location-banner.c
|
||||
src/nautilus-location-entry.c
|
||||
|
|
|
@ -195,6 +195,8 @@ libnautilus_sources = [
|
|||
'nautilus-icon-info.c',
|
||||
'nautilus-icon-info.h',
|
||||
'nautilus-icon-names.h',
|
||||
'nautilus-internal-place-file.c',
|
||||
'nautilus-internal-place-file.h',
|
||||
'nautilus-keyfile-metadata.c',
|
||||
'nautilus-keyfile-metadata.h',
|
||||
'nautilus-metadata.h',
|
||||
|
|
|
@ -74,10 +74,6 @@ nautilus_compute_title_for_location (GFile *location)
|
|||
{
|
||||
title = g_strdup (_("Other Locations"));
|
||||
}
|
||||
else if (nautilus_file_is_starred_location (file))
|
||||
{
|
||||
title = g_strdup (_("Starred"));
|
||||
}
|
||||
else
|
||||
{
|
||||
title = g_strdup (nautilus_file_get_display_name (file));
|
||||
|
|
|
@ -4232,10 +4232,6 @@ nautilus_file_get_display_name (NautilusFile *file)
|
|||
{
|
||||
return _("Other Locations");
|
||||
}
|
||||
else if (nautilus_file_is_starred_location (file))
|
||||
{
|
||||
return _("Starred");
|
||||
}
|
||||
else
|
||||
{
|
||||
return nautilus_file_peek_display_name (file);
|
||||
|
|
107
src/nautilus-internal-place-file.c
Normal file
107
src/nautilus-internal-place-file.c
Normal file
|
@ -0,0 +1,107 @@
|
|||
/*
|
||||
* Copyright (C) 2024 GNOME Foundation Inc.
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*
|
||||
* Original Author: António Fernandes <antoniof@gnome.org>
|
||||
*/
|
||||
|
||||
#include "nautilus-internal-place-file.h"
|
||||
|
||||
#include <glib/gi18n.h>
|
||||
|
||||
#include "nautilus-file-private.h"
|
||||
#include "nautilus-scheme.h"
|
||||
#include "nautilus-starred-directory.h"
|
||||
|
||||
struct _NautilusInternalPlaceFile
|
||||
{
|
||||
NautilusFile parent_instance;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (NautilusInternalPlaceFile, nautilus_internal_place_file, NAUTILUS_TYPE_FILE);
|
||||
|
||||
static void
|
||||
real_monitor_add (NautilusFile *file,
|
||||
gconstpointer client,
|
||||
NautilusFileAttributes attributes)
|
||||
{
|
||||
/* Internal place attributes are static, so there is nothing to monitor. */
|
||||
}
|
||||
|
||||
static void
|
||||
real_monitor_remove (NautilusFile *file,
|
||||
gconstpointer client)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
real_call_when_ready (NautilusFile *file,
|
||||
NautilusFileAttributes file_attributes,
|
||||
NautilusFileCallback callback,
|
||||
gpointer callback_data)
|
||||
{
|
||||
if (callback != NULL)
|
||||
{
|
||||
/* Internal place attributes are static, so its always ready. */
|
||||
(*callback)(file, callback_data);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
real_cancel_call_when_ready (NautilusFile *file,
|
||||
NautilusFileCallback callback,
|
||||
gpointer callback_data)
|
||||
{
|
||||
}
|
||||
|
||||
static gboolean
|
||||
real_check_if_ready (NautilusFile *file,
|
||||
NautilusFileAttributes attributes)
|
||||
{
|
||||
/* Internal place attributes are static, so its always ready. */
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
nautilus_internal_place_file_init (NautilusInternalPlaceFile *self)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
nautilus_internal_place_file_constructed (GObject *object)
|
||||
{
|
||||
G_OBJECT_CLASS (nautilus_internal_place_file_parent_class)->constructed (object);
|
||||
|
||||
NautilusInternalPlaceFile *self = NAUTILUS_INTERNAL_PLACE_FILE (object);
|
||||
NautilusFile *file = NAUTILUS_FILE (self);
|
||||
|
||||
file->details->mime_type = g_ref_string_new_intern ("inode/directory");
|
||||
file->details->size = 0;
|
||||
|
||||
if (NAUTILUS_IS_STARRED_DIRECTORY (file->details->directory))
|
||||
{
|
||||
nautilus_file_set_display_name (file, _("Starred"), NULL, TRUE);
|
||||
}
|
||||
|
||||
file->details->got_file_info = TRUE;
|
||||
file->details->file_info_is_up_to_date = TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
nautilus_internal_place_file_class_init (NautilusInternalPlaceFileClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
NautilusFileClass *file_class = NAUTILUS_FILE_CLASS (klass);
|
||||
|
||||
/* We need to know the parent directory, which is a construction property.*/
|
||||
object_class->constructed = nautilus_internal_place_file_constructed;
|
||||
|
||||
file_class->default_file_type = G_FILE_TYPE_DIRECTORY;
|
||||
|
||||
file_class->monitor_add = real_monitor_add;
|
||||
file_class->monitor_remove = real_monitor_remove;
|
||||
file_class->call_when_ready = real_call_when_ready;
|
||||
file_class->cancel_call_when_ready = real_cancel_call_when_ready;
|
||||
file_class->check_if_ready = real_check_if_ready;
|
||||
}
|
16
src/nautilus-internal-place-file.h
Normal file
16
src/nautilus-internal-place-file.h
Normal file
|
@ -0,0 +1,16 @@
|
|||
/*
|
||||
* 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 "nautilus-file.h"
|
||||
|
||||
#define NAUTILUS_TYPE_INTERNAL_PLACE_FILE nautilus_internal_place_file_get_type ()
|
||||
G_DECLARE_FINAL_TYPE (NautilusInternalPlaceFile, nautilus_internal_place_file,
|
||||
NAUTILUS, INTERNAL_PLACE_FILE,
|
||||
NautilusFile)
|
|
@ -386,11 +386,6 @@ get_dir_name (ButtonData *button_data)
|
|||
return _("Other Locations");
|
||||
}
|
||||
|
||||
case STARRED_BUTTON:
|
||||
{
|
||||
return _("Starred");
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
return button_data->dir_name;
|
||||
|
|
|
@ -17,9 +17,12 @@
|
|||
*/
|
||||
|
||||
#include "nautilus-starred-directory.h"
|
||||
#include "nautilus-tag-manager.h"
|
||||
#include "nautilus-file-utilities.h"
|
||||
|
||||
#include "nautilus-directory-private.h"
|
||||
#include "nautilus-file-private.h"
|
||||
#include "nautilus-file-utilities.h"
|
||||
#include "nautilus-internal-place-file.h"
|
||||
#include "nautilus-tag-manager.h"
|
||||
#include "nautilus-scheme.h"
|
||||
#include <glib/gi18n.h>
|
||||
|
||||
|
@ -176,6 +179,22 @@ on_starred_files_changed (NautilusTagManager *tag_manager,
|
|||
nautilus_starred_directory_update_files (self, changed_files);
|
||||
}
|
||||
|
||||
static NautilusFile *
|
||||
real_new_file_from_filename (NautilusDirectory *directory,
|
||||
const char *filename,
|
||||
gboolean self_owned)
|
||||
{
|
||||
if (!self_owned)
|
||||
{
|
||||
g_warning ("Creating a file within starred://. This shouldn't happen.");
|
||||
return NAUTILUS_DIRECTORY_CLASS (nautilus_starred_directory_parent_class)->new_file_from_filename (directory, filename, self_owned);
|
||||
}
|
||||
|
||||
return NAUTILUS_FILE (g_object_new (NAUTILUS_TYPE_INTERNAL_PLACE_FILE,
|
||||
"directory", directory,
|
||||
NULL));
|
||||
}
|
||||
|
||||
static gboolean
|
||||
real_contains_file (NautilusDirectory *directory,
|
||||
NautilusFile *file)
|
||||
|
@ -499,6 +518,7 @@ nautilus_starred_directory_class_init (NautilusFavoriteDirectoryClass *klass)
|
|||
oclass->finalize = nautilus_starred_directory_finalize;
|
||||
oclass->dispose = nautilus_starred_directory_dispose;
|
||||
|
||||
directory_class->new_file_from_filename = real_new_file_from_filename;
|
||||
directory_class->handles_location = real_handles_location;
|
||||
directory_class->contains_file = real_contains_file;
|
||||
directory_class->is_editable = real_is_editable;
|
||||
|
|
Loading…
Reference in a new issue