Commit 318b5a31 authored by Alexander Larsson's avatar Alexander Larsson Committed by Alexander Larsson

Don't avoid adding existing files that are not is_added. Fixes a problem

2007-12-06  Alexander Larsson  <alexl@redhat.com>

        * libnautilus-private/nautilus-directory.c:
	Don't avoid adding existing files that are not is_added.
	Fixes a problem where new folder didn't display the new folder.
	
        * libnautilus-private/nautilus-file-operations.[ch]:
        * src/file-manager/fm-directory-view.c:
        * src/file-manager/fm-tree-view.c:
	Implement new folder.


svn path=/trunk/; revision=13499
parent e55bf2bf
2007-12-06 Alexander Larsson <alexl@redhat.com>
* libnautilus-private/nautilus-directory.c:
Don't avoid adding existing files that are not is_added.
Fixes a problem where new folder didn't display the new folder.
* libnautilus-private/nautilus-file-operations.[ch]:
* src/file-manager/fm-directory-view.c:
* src/file-manager/fm-tree-view.c:
Implement new folder.
2007-12-06 Alexander Larsson <alexl@redhat.com>
* libnautilus-private/nautilus-file-operations.c:
......
......@@ -1003,7 +1003,11 @@ nautilus_directory_notify_files_added (GList *files)
}
file = nautilus_file_get_existing (location);
if (file) {
/* We check is_added here, because the file could have been added
* to the directory by a nautilus_file_get() but not gotten
* files_added emitted
*/
if (file && file->details->is_added) {
/* A file already exists, it was probably renamed.
* If it was renamed this could be ignored, but
* queue a change just in case */
......
......@@ -119,6 +119,21 @@ typedef struct {
gpointer done_callback_data;
} DeleteJob;
typedef struct {
CommonJob common;
GFile *dest_dir;
char *filename;
gboolean make_dir;
GFile *src;
char *src_data;
GdkPoint position;
gboolean has_position;
GFile *created_file;
NautilusCreateCallback done_callback;
gpointer done_callback_data;
} CreateJob;
typedef struct {
CommonJob common;
} EmptyTrashJob;
......@@ -3820,6 +3835,8 @@ link_file (CopyMoveJob *job,
} else {
nautilus_file_changes_queue_schedule_position_remove (dest);
}
g_object_unref (dest);
return;
}
......@@ -4129,15 +4146,207 @@ nautilus_file_operations_copy_move (const GList *item_uris,
}
}
static void
create_job_done (gpointer user_data)
{
CreateJob *job;
job = user_data;
if (job->done_callback) {
job->done_callback (job->created_file, job->done_callback_data);
}
g_object_unref (job->dest_dir);
if (job->src) {
g_object_unref (job->src);
}
g_free (job->src_data);
g_free (job->filename);
if (job->created_file) {
g_object_unref (job->created_file);
}
finalize_common ((CommonJob *)job);
nautilus_file_changes_consume_changes (TRUE);
}
static void
create_job (GIOJob *io_job,
GCancellable *cancellable,
gpointer user_data)
{
CreateJob *job;
CommonJob *common;
int count;
GFile *dest;
char *filename, *filename2;
GError *error;
gboolean res;
gboolean filename_is_utf8;
char *primary, *secondary, *details;
int response;
job = user_data;
common = &job->common;
common->io_job = io_job;
nautilus_progress_info_start (job->common.progress);
filename = NULL;
dest = NULL;
verify_destination (common,
job->dest_dir,
NULL, -1);
if (job_aborted (common)) {
goto aborted;
}
filename = g_strdup (job->filename);
filename_is_utf8 = FALSE;
if (filename) {
filename_is_utf8 = g_utf8_validate (filename, -1, NULL);
}
if (filename == NULL) {
if (job->make_dir) {
/* localizers: the initial name of a new folder */
filename = g_strdup (_("untitled folder"));
filename_is_utf8 = TRUE; /* Pass in utf8 */
} else {
if (job->src != NULL) {
filename = g_file_get_basename (job->src);
}
if (filename == NULL) {
/* localizers: the initial name of a new empty file */
filename = g_strdup (_("new file"));
filename_is_utf8 = TRUE; /* Pass in utf8 */
}
}
}
if (filename_is_utf8) {
dest = g_file_get_child_for_display_name (job->dest_dir, filename, NULL);
}
if (dest == NULL) {
dest = g_file_get_child (job->dest_dir, filename);
}
count = 1;
retry:
error = NULL;
if (job->make_dir) {
res = g_file_make_directory (dest,
common->cancellable,
&error);
} else {
if (job->src) {
} else {
if (job->src_data) {
}
}
}
if (res) {
job->created_file = g_object_ref (dest);
nautilus_file_changes_queue_file_added (dest);
if (job->has_position) {
nautilus_file_changes_queue_schedule_position_set (dest, job->position, common->screen_num);
} else {
nautilus_file_changes_queue_schedule_position_remove (dest);
}
} else {
if (error != NULL && IS_IO_ERROR (error, EXISTS)) {
g_object_unref (dest);
dest = NULL;
filename2 = g_strdup_printf ("%s %d", filename, ++count);
if (filename_is_utf8) {
dest = g_file_get_child_for_display_name (job->dest_dir, filename2, NULL);
}
if (dest == NULL) {
dest = g_file_get_child (job->dest_dir, filename2);
}
g_free (filename2);
g_error_free (error);
goto retry;
}
else if (error != NULL && IS_IO_ERROR (error, CANCELLED)) {
g_error_free (error);
}
/* Other error */
else {
if (job->make_dir) {
primary = f (_("Error while creating directory %B."), dest);
} else {
primary = f (_("Error while creating file %B."), dest);
}
secondary = f (_("There was an error creating the directory in %F."), job->dest_dir);
details = error->message;
response = run_warning (common,
primary,
secondary,
details,
GTK_STOCK_CANCEL, SKIP,
NULL);
g_error_free (error);
if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT) {
abort_job (common);
} else if (response == 1) { /* skip */
/* do nothing */
} else {
g_assert_not_reached ();
}
}
}
aborted:
if (dest) {
g_object_unref (dest);
}
g_free (filename);
g_io_job_send_to_mainloop (io_job,
create_job_done,
job,
NULL,
FALSE);
}
void
nautilus_file_operations_new_folder (GtkWidget *parent_view,
GdkPoint *target_point,
const char *parent_dir,
NautilusNewFolderCallback done_callback,
gpointer data)
NautilusCreateCallback done_callback,
gpointer done_callback_data)
{
/* TODO-gio: Implement */
not_supported_yet ();
CreateJob *job;
GtkWindow *parent_window;
parent_window = NULL;
if (parent_view) {
parent_window = (GtkWindow *)gtk_widget_get_ancestor (parent_view, GTK_TYPE_WINDOW);
}
job = op_job_new (CreateJob, parent_window);
job->done_callback = done_callback;
job->done_callback_data = done_callback_data;
job->dest_dir = g_file_new_for_uri (parent_dir);
job->make_dir = TRUE;
if (target_point != NULL) {
job->position = *target_point;
job->has_position = TRUE;
}
g_schedule_io_job (create_job,
job,
NULL, /* destroy notify */
0,
job->common.cancellable);
}
void
......@@ -4146,8 +4355,8 @@ nautilus_file_operations_new_file_from_template (GtkWidget *parent_view,
const char *parent_dir,
const char *target_filename,
const char *template_uri,
NautilusNewFileCallback done_callback,
gpointer data)
NautilusCreateCallback done_callback,
gpointer done_callback_data)
{
/* TODO-gio: Implement */
not_supported_yet ();
......@@ -4158,8 +4367,8 @@ nautilus_file_operations_new_file (GtkWidget *parent_view,
GdkPoint *target_point,
const char *parent_dir,
const char *initial_contents,
NautilusNewFileCallback done_callback,
gpointer data)
NautilusCreateCallback done_callback,
gpointer done_callback_data)
{
/* TODO-gio: Implement */
not_supported_yet ();
......
......@@ -33,9 +33,7 @@
typedef void (* NautilusCopyCallback) (GHashTable *debuting_uris,
gpointer callback_data);
typedef void (* NautilusNewFolderCallback) (const char *new_folder_uri,
gpointer callback_data);
typedef void (* NautilusNewFileCallback) (const char *new_file_uri,
typedef void (* NautilusCreateCallback) (GFile *new_file,
gpointer callback_data);
typedef void (* NautilusSetPermissionsCallback) (gpointer callback_data);
typedef void (* NautilusDeleteCallback) (GHashTable *debuting_uris,
......@@ -56,20 +54,20 @@ void nautilus_file_operations_empty_trash (GtkWidget *parent_vie
void nautilus_file_operations_new_folder (GtkWidget *parent_view,
GdkPoint *target_point,
const char *parent_dir_uri,
NautilusNewFolderCallback done_callback,
NautilusCreateCallback done_callback,
gpointer done_callback_data);
void nautilus_file_operations_new_file (GtkWidget *parent_view,
GdkPoint *target_point,
const char *parent_dir,
const char *initial_contents,
NautilusNewFileCallback done_callback,
NautilusCreateCallback done_callback,
gpointer data);
void nautilus_file_operations_new_file_from_template (GtkWidget *parent_view,
GdkPoint *target_point,
const char *parent_dir,
const char *target_filename,
const char *template_uri,
NautilusNewFileCallback done_callback,
NautilusCreateCallback done_callback,
gpointer data);
void nautilus_file_operations_delete (GList *files,
......
......@@ -3683,7 +3683,7 @@ rename_file (FMDirectoryView *view, NautilusFile *new_file)
return;
}
/* no need to select because start_renaming_file selects
* fm_directory_view_select_file (view, new_file);
*/
......@@ -3692,35 +3692,40 @@ rename_file (FMDirectoryView *view, NautilusFile *new_file)
}
static void
reveal_newly_added_folder (FMDirectoryView *view, NautilusFile *new_file, NautilusDirectory *directory, const char *target_uri)
reveal_newly_added_folder (FMDirectoryView *view, NautilusFile *new_file,
NautilusDirectory *directory, GFile *target_location)
{
if (nautilus_file_matches_uri (new_file, target_uri)) {
GFile *location;
location = nautilus_file_get_location (new_file);
if (g_file_equal (location, target_location)) {
g_signal_handlers_disconnect_by_func (view,
G_CALLBACK (reveal_newly_added_folder),
(void *) target_uri);
(void *) target_location);
rename_file (view, new_file);
}
g_object_unref (location);
}
typedef struct {
FMDirectoryView *directory_view;
GHashTable *added_uris;
GHashTable *added_locations;
} NewFolderData;
static void
track_newly_added_uris (FMDirectoryView *view, NautilusFile *new_file,
NautilusDirectory *directory, gpointer user_data)
track_newly_added_locations (FMDirectoryView *view, NautilusFile *new_file,
NautilusDirectory *directory, gpointer user_data)
{
NewFolderData *data;
data = user_data;
g_hash_table_insert (data->added_uris, nautilus_file_get_uri (new_file), NULL);
g_hash_table_insert (data->added_locations, nautilus_file_get_location (new_file), NULL);
}
static void
new_folder_done (const char *new_folder_uri, gpointer user_data)
new_folder_done (GFile *new_folder, gpointer user_data)
{
FMDirectoryView *directory_view;
NautilusFile *file;
......@@ -3737,23 +3742,24 @@ new_folder_done (const char *new_folder_uri, gpointer user_data)
}
g_signal_handlers_disconnect_by_func (directory_view,
G_CALLBACK (track_newly_added_uris),
G_CALLBACK (track_newly_added_locations),
(void *) data);
if (new_folder_uri == NULL) {
if (new_folder == NULL) {
goto fail;
}
screen = gtk_widget_get_screen (GTK_WIDGET (directory_view));
g_snprintf (screen_string, sizeof (screen_string), "%d", gdk_screen_get_number (screen));
file = nautilus_file_get_by_uri (new_folder_uri);
file = nautilus_file_get (new_folder);
nautilus_file_set_metadata
(file, NAUTILUS_METADATA_KEY_SCREEN,
NULL,
screen_string);
if (g_hash_table_lookup_extended (data->added_uris, new_folder_uri, NULL, NULL)) {
if (g_hash_table_lookup_extended (data->added_locations, new_folder, NULL, NULL)) {
/* The file was already added */
rename_file (directory_view, file);
} else {
......@@ -3764,14 +3770,14 @@ new_folder_done (const char *new_folder_uri, gpointer user_data)
g_signal_connect_data (directory_view,
"add_file",
G_CALLBACK (reveal_newly_added_folder),
g_strdup (new_folder_uri),
(GClosureNotify)g_free,
g_object_ref (new_folder),
(GClosureNotify)g_object_unref,
G_CONNECT_AFTER);
}
nautilus_file_unref (file);
fail:
g_hash_table_destroy (data->added_uris);
g_hash_table_destroy (data->added_locations);
eel_remove_weak_pointer (&data->directory_view);
g_free (data);
}
......@@ -3784,8 +3790,8 @@ new_folder_data_new (FMDirectoryView *directory_view)
data = g_new (NewFolderData, 1);
data->directory_view = directory_view;
data->added_uris = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, NULL);
data->added_locations = g_hash_table_new_full (g_file_hash, (GEqualFunc)g_file_equal,
g_object_unref, NULL);
eel_add_weak_pointer (&data->directory_view);
return data;
......@@ -3831,7 +3837,7 @@ fm_directory_view_new_folder (FMDirectoryView *directory_view)
g_signal_connect_data (directory_view,
"add_file",
G_CALLBACK (track_newly_added_uris),
G_CALLBACK (track_newly_added_locations),
data,
(GClosureNotify)NULL,
G_CONNECT_AFTER);
......@@ -3855,7 +3861,7 @@ setup_new_folder_data (FMDirectoryView *directory_view)
g_signal_connect_data (directory_view,
"add_file",
G_CALLBACK (track_newly_added_uris),
G_CALLBACK (track_newly_added_locations),
data,
(GClosureNotify)NULL,
G_CONNECT_AFTER);
......
......@@ -813,14 +813,14 @@ fm_tree_view_open_in_new_window_cb (GtkWidget *menu_item,
}
static void
new_folder_done (const char *new_folder_uri, gpointer data)
new_folder_done (GFile *new_folder, gpointer data)
{
GList *list;
/* show the properties window for the newly created
* folder so the user can change its name
*/
list = g_list_prepend (NULL, nautilus_file_get_by_uri (new_folder_uri));
list = g_list_prepend (NULL, nautilus_file_get (new_folder));
fm_properties_window_present (list, GTK_WIDGET (data));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment