feat: add shell.trashItem() to replace shell.moveItemToTrash() (#25114)
This commit is contained in:
parent
e9e7eee25e
commit
1b6534b326
11 changed files with 212 additions and 21 deletions
|
@ -117,10 +117,13 @@ void OpenExternal(const GURL& url,
|
|||
});
|
||||
}
|
||||
|
||||
bool MoveItemToTrash(const base::FilePath& full_path, bool delete_on_fail) {
|
||||
bool MoveItemToTrashWithError(const base::FilePath& full_path,
|
||||
bool delete_on_fail,
|
||||
std::string* error) {
|
||||
NSString* path_string = base::SysUTF8ToNSString(full_path.value());
|
||||
if (!path_string) {
|
||||
LOG(WARNING) << "Invalid file path " << full_path.value();
|
||||
*error = "Invalid file path: " + full_path.value();
|
||||
LOG(WARNING) << *error;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -142,14 +145,27 @@ bool MoveItemToTrash(const base::FilePath& full_path, bool delete_on_fail) {
|
|||
}
|
||||
|
||||
if (!did_trash) {
|
||||
*error = base::SysNSStringToUTF8([err localizedDescription]);
|
||||
LOG(WARNING) << "NSWorkspace failed to move file " << full_path.value()
|
||||
<< " to trash: "
|
||||
<< base::SysNSStringToUTF8([err localizedDescription]);
|
||||
<< " to trash: " << *error;
|
||||
}
|
||||
|
||||
return did_trash;
|
||||
}
|
||||
|
||||
bool MoveItemToTrash(const base::FilePath& path, bool delete_on_fail) {
|
||||
std::string error; // ignored
|
||||
return MoveItemToTrashWithError(path, delete_on_fail, &error);
|
||||
}
|
||||
|
||||
namespace internal {
|
||||
|
||||
bool PlatformTrashItem(const base::FilePath& full_path, std::string* error) {
|
||||
return MoveItemToTrashWithError(full_path, false, error);
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
|
||||
void Beep() {
|
||||
NSBeep();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue