Browse Source

default template for PreviewFile

Pierre Laurac 8 years ago
parent
commit
fb444f646b

+ 5 - 0
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<v8::Value> 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

+ 1 - 0
atom/browser/api/atom_api_window.h

@@ -170,6 +170,7 @@ class Window : public mate::TrackableObject<Window>,
   void SetMenuBarVisibility(bool visible);
   bool IsMenuBarVisible();
   void SetAspectRatio(double aspect_ratio, mate::Arguments* args);
+  void PreviewFile(const base::string16& filepath);
   void SetParentWindow(v8::Local<v8::Value> value, mate::Arguments* args);
   v8::Local<v8::Value> GetParentWindow() const;
   std::vector<v8::Local<v8::Object>> GetChildWindows() const;

+ 3 - 0
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,

+ 1 - 0
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<NativeWindow> GetWeakPtr() {
     return weak_factory_.GetWeakPtr();

+ 1 - 0
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;

+ 12 - 0
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];
 }