Return boolean from shell.openItem

This commit is contained in:
Kevin Sawicki 2016-09-12 14:29:06 -07:00
parent 72558654ef
commit 55eab8e385
5 changed files with 18 additions and 16 deletions

View file

@ -25,7 +25,7 @@ bool ShowItemInFolder(const base::FilePath& full_path);
// Open the given file in the desktop's default manner.
// Must be called from the UI thread.
void OpenItem(const base::FilePath& full_path);
bool OpenItem(const base::FilePath& full_path);
// Open the given external protocol URL in the desktop's default manner.
// (For example, mailto: URLs in the default mail user agent.)

View file

@ -67,8 +67,8 @@ bool ShowItemInFolder(const base::FilePath& full_path) {
return XDGOpen(dir.value(), true);
}
void OpenItem(const base::FilePath& full_path) {
XDGOpen(full_path.value(), true);
bool OpenItem(const base::FilePath& full_path) {
return XDGOpen(full_path.value(), true);
}
bool OpenExternal(const GURL& url, bool activate) {

View file

@ -40,11 +40,11 @@ bool ShowItemInFolder(const base::FilePath& path) {
// 2. Silent no-op for unassociated file types: http://crbug.com/50263
// Instead, an AppleEvent is constructed to tell the Finder to open the
// document.
void OpenItem(const base::FilePath& full_path) {
bool OpenItem(const base::FilePath& full_path) {
DCHECK([NSThread isMainThread]);
NSString* path_string = base::SysUTF8ToNSString(full_path.value());
if (!path_string)
return;
return false;
// Create the target of this AppleEvent, the Finder.
base::mac::ScopedAEDesc<AEAddressDesc> address;
@ -55,7 +55,7 @@ void OpenItem(const base::FilePath& full_path) {
address.OutPointer()); // result
if (status != noErr) {
OSSTATUS_LOG(WARNING, status) << "Could not create OpenItem() AE target";
return;
return false;
}
// Build the AppleEvent data structure that instructs Finder to open files.
@ -68,7 +68,7 @@ void OpenItem(const base::FilePath& full_path) {
theEvent.OutPointer()); // result
if (status != noErr) {
OSSTATUS_LOG(WARNING, status) << "Could not create OpenItem() AE event";
return;
return false;
}
// Create the list of files (only ever one) to open.
@ -79,7 +79,7 @@ void OpenItem(const base::FilePath& full_path) {
fileList.OutPointer()); // resultList
if (status != noErr) {
OSSTATUS_LOG(WARNING, status) << "Could not create OpenItem() AE file list";
return;
return false;
}
// Add the single path to the file list. C-style cast to avoid both a
@ -95,11 +95,11 @@ void OpenItem(const base::FilePath& full_path) {
if (status != noErr) {
OSSTATUS_LOG(WARNING, status)
<< "Could not add file path to AE list in OpenItem()";
return;
return false;
}
} else {
LOG(WARNING) << "Could not get FSRef for path URL in OpenItem()";
return;
return false;
}
// Attach the file list to the AppleEvent.
@ -109,7 +109,7 @@ void OpenItem(const base::FilePath& full_path) {
if (status != noErr) {
OSSTATUS_LOG(WARNING, status)
<< "Could not put the AE file list the path in OpenItem()";
return;
return false;
}
// Send the actual event. Do not care about the reply.
@ -125,6 +125,7 @@ void OpenItem(const base::FilePath& full_path) {
OSSTATUS_LOG(WARNING, status)
<< "Could not send AE to Finder in OpenItem()";
}
return status == noErr;
}
bool OpenExternal(const GURL& url, bool activate) {

View file

@ -292,11 +292,11 @@ bool ShowItemInFolder(const base::FilePath& full_path) {
}
}
void OpenItem(const base::FilePath& full_path) {
bool OpenItem(const base::FilePath& full_path) {
if (base::DirectoryExists(full_path))
ui::win::OpenFolderViaShell(full_path);
return ui::win::OpenFolderViaShell(full_path);
else
ui::win::OpenFileViaShell(full_path);
return ui::win::OpenFileViaShell(full_path);
}
bool OpenExternal(const base::string16& url, bool activate) {

View file

@ -21,13 +21,14 @@ The `shell` module has the following methods:
* `fullPath` String
Show the given file in a file manager. If possible, select the file. Returns
true if the item was successfully shown, false otherwse.
true if the item was successfully shown, false otherwise.
### `shell.openItem(fullPath)`
* `fullPath` String
Open the given file in the desktop's default manner.
Open the given file in the desktop's default manner. Returns true if the item
was successfully opened, false otherwise.
### `shell.openExternal(url[, options])`