+44
-6
src/event_handlers.zig
+44
-6
src/event_handlers.zig
···
275
defer app.alloc.free(a.new);
276
defer app.alloc.free(a.old);
277
278
-
// TODO: Will overwrite an item if it has the same name.
279
-
if (app.directories.dir.rename(a.new, a.old)) {
280
app.directories.clearEntries();
281
const fuzzy = inputToSlice(app);
282
app.directories.populateEntries(fuzzy) catch |err| {
···
285
else => try app.notification.writeErr(.UnknownError),
286
}
287
};
288
-
try app.notification.writeInfo(.RestoredDelete);
289
} else |_| {
290
try app.notification.writeErr(.UnableToUndo);
291
}
···
294
defer app.alloc.free(a.new);
295
defer app.alloc.free(a.old);
296
297
-
// TODO: Will overwrite an item if it has the same name.
298
-
if (app.directories.dir.rename(a.new, a.old)) {
299
app.directories.clearEntries();
300
const fuzzy = inputToSlice(app);
301
app.directories.populateEntries(fuzzy) catch |err| {
···
304
else => try app.notification.writeErr(.UnknownError),
305
}
306
};
307
-
try app.notification.writeInfo(.RestoredRename);
308
} else |_| {
309
try app.notification.writeErr(.UnableToUndo);
310
}
···
275
defer app.alloc.free(a.new);
276
defer app.alloc.free(a.old);
277
278
+
var had_duplicate = false;
279
+
280
+
// Handle if item with same name already exists.
281
+
var new_path_buf: [std.fs.max_path_bytes]u8 = undefined;
282
+
const new_path = if (environment.fileExists(app.directories.dir, a.old)) lbl: {
283
+
const extension = std.fs.path.extension(a.old);
284
+
had_duplicate = true;
285
+
break :lbl try std.fmt.bufPrint(
286
+
&new_path_buf,
287
+
"{s}-{s}{s}",
288
+
.{ a.old[0 .. a.old.len - extension.len], zuid.new.v4(), extension },
289
+
);
290
+
} else lbl: {
291
+
break :lbl a.old;
292
+
};
293
+
294
+
if (app.directories.dir.rename(a.new, new_path)) {
295
app.directories.clearEntries();
296
const fuzzy = inputToSlice(app);
297
app.directories.populateEntries(fuzzy) catch |err| {
···
300
else => try app.notification.writeErr(.UnknownError),
301
}
302
};
303
+
if (had_duplicate) {
304
+
try app.notification.writeWarn(.DuplicateFileOnUndo);
305
+
} else {
306
+
try app.notification.writeInfo(.RestoredDelete);
307
+
}
308
} else |_| {
309
try app.notification.writeErr(.UnableToUndo);
310
}
···
313
defer app.alloc.free(a.new);
314
defer app.alloc.free(a.old);
315
316
+
var had_duplicate = false;
317
+
318
+
// Handle if item with same name already exists.
319
+
var new_path_buf: [std.fs.max_path_bytes]u8 = undefined;
320
+
const new_path = if (environment.fileExists(app.directories.dir, a.old)) lbl: {
321
+
const extension = std.fs.path.extension(a.old);
322
+
had_duplicate = true;
323
+
break :lbl try std.fmt.bufPrint(
324
+
&new_path_buf,
325
+
"{s}-{s}{s}",
326
+
.{ a.old[0 .. a.old.len - extension.len], zuid.new.v4(), extension },
327
+
);
328
+
} else lbl: {
329
+
break :lbl a.old;
330
+
};
331
+
332
+
if (app.directories.dir.rename(a.new, new_path)) {
333
app.directories.clearEntries();
334
const fuzzy = inputToSlice(app);
335
app.directories.populateEntries(fuzzy) catch |err| {
···
338
else => try app.notification.writeErr(.UnknownError),
339
}
340
};
341
+
if (had_duplicate) {
342
+
try app.notification.writeWarn(.DuplicateFileOnUndo);
343
+
} else {
344
+
try app.notification.writeInfo(.RestoredRename);
345
+
}
346
} else |_| {
347
try app.notification.writeErr(.UnableToUndo);
348
}
+2
-1
src/notification.zig
+2
-1
src/notification.zig
···
45
ConfigReloaded,
46
};
47
48
-
const Warn = enum { DeprecatedConfigPath };
49
50
buf: [1024]u8 = undefined,
51
style: Style = Style.info,
···
106
pub fn writeWarn(self: *Self, warning: Warn) !void {
107
try switch (warning) {
108
.DeprecatedConfigPath => self.write("You are using a deprecated config path. Please move your config to either `$XDG_CONFIG_HOME/jido` or `$HOME/.jido`", .warn),
109
};
110
}
111
···
45
ConfigReloaded,
46
};
47
48
+
const Warn = enum { DeprecatedConfigPath, DuplicateFileOnUndo };
49
50
buf: [1024]u8 = undefined,
51
style: Style = Style.info,
···
106
pub fn writeWarn(self: *Self, warning: Warn) !void {
107
try switch (warning) {
108
.DeprecatedConfigPath => self.write("You are using a deprecated config path. Please move your config to either `$XDG_CONFIG_HOME/jido` or `$HOME/.jido`", .warn),
109
+
.DuplicateFileOnUndo => self.write("A file with the same name already exists. A unique identifier has been appending to the duplicated item.", .warn),
110
};
111
}
112