diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index d5f196451785..dccf6a77ce26 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -729,6 +729,10 @@ void Window::SetAspectRatio(double aspect_ratio, mate::Arguments* args) { window_->SetAspectRatio(aspect_ratio, extra_size); } +void Window::PreviewFile(const base::string16& filepath) { + window_->PreviewFile(filepath); +} + void Window::SetParentWindow(v8::Local value, mate::Arguments* args) { if (IsModal()) { @@ -825,6 +829,7 @@ void Window::BuildPrototype(v8::Isolate* isolate, .SetMethod("setFullScreen", &Window::SetFullScreen) .SetMethod("isFullScreen", &Window::IsFullscreen) .SetMethod("setAspectRatio", &Window::SetAspectRatio) + .SetMethod("previewFile", &Window::PreviewFile) #if !defined(OS_WIN) .SetMethod("setParentWindow", &Window::SetParentWindow) #endif diff --git a/atom/browser/api/atom_api_window.h b/atom/browser/api/atom_api_window.h index 317f5b51ece6..abd19f9d5bed 100644 --- a/atom/browser/api/atom_api_window.h +++ b/atom/browser/api/atom_api_window.h @@ -170,6 +170,7 @@ class Window : public mate::TrackableObject, void SetMenuBarVisibility(bool visible); bool IsMenuBarVisible(); void SetAspectRatio(double aspect_ratio, mate::Arguments* args); + void PreviewFile(const base::string16& filepath); void SetParentWindow(v8::Local value, mate::Arguments* args); v8::Local GetParentWindow() const; std::vector> GetChildWindows() const; diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index 1cf5a23b6efe..b6ea285159a0 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -374,6 +374,9 @@ void NativeWindow::SetAspectRatio(double aspect_ratio, aspect_ratio_extraSize_ = extra_size; } +void NativeWindow::PreviewFile(const base::string16& filepath) { +} + void NativeWindow::RequestToClosePage() { bool prevent_default = false; FOR_EACH_OBSERVER(NativeWindowObserver, diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index d8c022d606c2..c15868c5f407 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -176,6 +176,7 @@ class NativeWindow : public base::SupportsUserData, double GetAspectRatio(); gfx::Size GetAspectRatioExtraSize(); virtual void SetAspectRatio(double aspect_ratio, const gfx::Size& extra_size); + virtual void PreviewFile(const base::string16& filepath); base::WeakPtr GetWeakPtr() { return weak_factory_.GetWeakPtr(); diff --git a/atom/browser/native_window_mac.h b/atom/browser/native_window_mac.h index 4fd7bcc3c2ad..35649ae7d332 100644 --- a/atom/browser/native_window_mac.h +++ b/atom/browser/native_window_mac.h @@ -55,6 +55,7 @@ class NativeWindowMac : public NativeWindow, void SetMovable(bool movable) override; void SetAspectRatio(double aspect_ratio, const gfx::Size& extra_size) override; + void PreviewFile(const base::string16& filepath) override; bool IsMovable() override; void SetMinimizable(bool minimizable) override; bool IsMinimizable() override; diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index 98e8d4b65659..1e18efcc713a 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -10,6 +10,8 @@ #include "atom/common/color_util.h" #include "atom/common/draggable_region.h" #include "atom/common/options_switches.h" +#include "atom/common/native_mate_converters/string16_converter.h" +#include "base/strings/utf_string_conversions.h" #include "base/mac/mac_util.h" #include "base/mac/scoped_cftyperef.h" #include "base/strings/sys_string_conversions.h" @@ -25,6 +27,7 @@ #include "third_party/skia/include/core/SkRegion.h" #include "ui/gfx/skia_util.h" + namespace { // Prevents window from resizing during the scope. @@ -899,6 +902,15 @@ void NativeWindowMac::SetAspectRatio(double aspect_ratio, [window_ setResizeIncrements:NSMakeSize(1.0, 1.0)]; } +void NativeWindowMac::PreviewFile(const base::string16& filepath) { + std::string rtf = base::UTF16ToUTF8(filepath); + + NSString *path = [NSString stringWithCString:rtf.c_str() + encoding:[NSString defaultCStringEncoding]]; + NSAlert *alert = [NSAlert alertWithMessageText:path defaultButton:@"Close anyway" alternateButton:@"Cancel" otherButton:nil informativeTextWithFormat:@""]; + [alert runModal]; +} + void NativeWindowMac::SetMovable(bool movable) { [window_ setMovable:movable]; }