:gift: Add 'win.closeFilePreview()'
authorDaniel Pham <pham.dany@gmail.com>
Mon, 21 Nov 2016 18:30:13 +0000 (13:30 -0500)
committerKevin Sawicki <kevinsawicki@gmail.com>
Mon, 28 Nov 2016 22:25:11 +0000 (14:25 -0800)
atom/browser/api/atom_api_window.cc
atom/browser/api/atom_api_window.h
atom/browser/native_window.cc
atom/browser/native_window.h
atom/browser/native_window_mac.h
atom/browser/native_window_mac.mm
docs/api/browser-window.md

index 75be280..358c884 100644 (file)
@@ -736,6 +736,10 @@ void Window::PreviewFile(const std::string& path, mate::Arguments* args) {
   window_->PreviewFile(path, display_name);
 }
 
+void Window::CloseFilePreview() {
+  window_->CloseFilePreview();
+}
+
 void Window::SetParentWindow(v8::Local<v8::Value> value,
                              mate::Arguments* args) {
   if (IsModal()) {
@@ -840,6 +844,7 @@ void Window::BuildPrototype(v8::Isolate* isolate,
       .SetMethod("isFullScreen", &Window::IsFullscreen)
       .SetMethod("setAspectRatio", &Window::SetAspectRatio)
       .SetMethod("previewFile", &Window::PreviewFile)
+      .SetMethod("closeFilePreview", &Window::CloseFilePreview)
 #if !defined(OS_WIN)
       .SetMethod("setParentWindow", &Window::SetParentWindow)
 #endif
index 8a5b95b..c06d9ec 100644 (file)
@@ -171,6 +171,7 @@ class Window : public mate::TrackableObject<Window>,
   bool IsMenuBarVisible();
   void SetAspectRatio(double aspect_ratio, mate::Arguments* args);
   void PreviewFile(const std::string& path, mate::Arguments* args);
+  void CloseFilePreview();
   void SetParentWindow(v8::Local<v8::Value> value, mate::Arguments* args);
   v8::Local<v8::Value> GetParentWindow() const;
   std::vector<v8::Local<v8::Object>> GetChildWindows() const;
index 92419d3..6493476 100644 (file)
@@ -381,6 +381,9 @@ void NativeWindow::PreviewFile(const std::string& path,
                                const std::string& display_name) {
 }
 
+void NativeWindow::CloseFilePreview() {
+}
+
 void NativeWindow::RequestToClosePage() {
   bool prevent_default = false;
   FOR_EACH_OBSERVER(NativeWindowObserver,
index b5e2cf3..4c1d0a9 100644 (file)
@@ -179,8 +179,11 @@ class NativeWindow : public base::SupportsUserData,
   double GetAspectRatio();
   gfx::Size GetAspectRatioExtraSize();
   virtual void SetAspectRatio(double aspect_ratio, const gfx::Size& extra_size);
+
+  // File preview APIs.
   virtual void PreviewFile(const std::string& path,
                            const std::string& display_name);
+  virtual void CloseFilePreview();
 
   base::WeakPtr<NativeWindow> GetWeakPtr() {
     return weak_factory_.GetWeakPtr();
index 7c4d2b4..3f781a7 100644 (file)
@@ -57,6 +57,7 @@ class NativeWindowMac : public NativeWindow,
     override;
   void PreviewFile(const std::string& path, const std::string& display_name)
     override;
+  void CloseFilePreview() override;
   bool IsMovable() override;
   void SetMinimizable(bool minimizable) override;
   bool IsMinimizable() override;
index 5ba0700..0e7aadb 100644 (file)
@@ -1004,6 +1004,12 @@ void NativeWindowMac::PreviewFile(const std::string& path,
   [window_ previewFileAtPath:path_ns withName:name_ns];
 }
 
+void NativeWindowMac::CloseFilePreview() {
+  if ([QLPreviewPanel sharedPreviewPanelExists]) {
+    [[QLPreviewPanel sharedPreviewPanel] close];
+  }
+}
+
 void NativeWindowMac::SetMovable(bool movable) {
   [window_ setMovable:movable];
 }
index 40a2cca..aa70743 100644 (file)
@@ -682,6 +682,10 @@ height areas you have within the overall content view.
 
 Uses [Quick Look][quick-look] to preview a file at a given path.
 
+#### `win.closeFilePreview()` _macOS_
+
+Closes the currently open [Quick Look][quick-look] panel.
+
 #### `win.setBounds(bounds[, animate])`
 
 * `bounds` [Rectangle](structures/rectangle.md)