From acb8b7771e8abee7675feb2f4af501cbbb6cd7b4 Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Fri, 18 Jul 2014 21:42:26 +0800 Subject: [PATCH] mac: Add BrowserWindow.getRepresentedFilename API, fixes #460. --- atom/browser/api/atom_api_window.cc | 5 +++++ atom/browser/api/atom_api_window.h | 1 + atom/browser/native_window.cc | 4 ++++ atom/browser/native_window.h | 1 + atom/browser/native_window_mac.h | 1 + atom/browser/native_window_mac.mm | 4 ++++ docs/api/browser-window.md | 4 ++++ 7 files changed, 20 insertions(+) diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index c6b28af5585c..668aa1a55c2c 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -320,6 +320,10 @@ void Window::SetRepresentedFilename(const std::string& filename) { window_->SetRepresentedFilename(filename); } +std::string Window::GetRepresentedFilename() { + return window_->GetRepresentedFilename(); +} + void Window::SetDocumentEdited(bool edited) { window_->SetDocumentEdited(edited); } @@ -373,6 +377,7 @@ void Window::BuildPrototype(v8::Isolate* isolate, .SetMethod("setKiosk", &Window::SetKiosk) .SetMethod("isKiosk", &Window::IsKiosk) .SetMethod("setRepresentedFilename", &Window::SetRepresentedFilename) + .SetMethod("getRepresentedFilename", &Window::GetRepresentedFilename) .SetMethod("setDocumentEdited", &Window::SetDocumentEdited) .SetMethod("_openDevTools", &Window::OpenDevTools) .SetMethod("closeDevTools", &Window::CloseDevTools) diff --git a/atom/browser/api/atom_api_window.h b/atom/browser/api/atom_api_window.h index 91f9d333adb4..d47a66f1dfae 100644 --- a/atom/browser/api/atom_api_window.h +++ b/atom/browser/api/atom_api_window.h @@ -98,6 +98,7 @@ class Window : public mate::EventEmitter, bool IsWebViewFocused(); void CapturePage(mate::Arguments* args); void SetRepresentedFilename(const std::string& filename); + std::string GetRepresentedFilename(); void SetDocumentEdited(bool edited); // APIs for WebContents. diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index f99f783f1605..5027114915ff 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -192,6 +192,10 @@ void NativeWindow::InitFromOptions(const mate::Dictionary& options) { void NativeWindow::SetRepresentedFilename(const std::string& filename) { } +std::string NativeWindow::GetRepresentedFilename() { + return ""; +} + void NativeWindow::SetDocumentEdited(bool edited) { } diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index fdb7fa676f8a..896e0dbc10e0 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -135,6 +135,7 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate, virtual void SetKiosk(bool kiosk) = 0; virtual bool IsKiosk() = 0; virtual void SetRepresentedFilename(const std::string& filename); + virtual std::string GetRepresentedFilename(); virtual void SetDocumentEdited(bool edited); virtual void SetMenu(ui::MenuModel* menu); virtual bool HasModalDialog(); diff --git a/atom/browser/native_window_mac.h b/atom/browser/native_window_mac.h index 16092065f230..5df01f91a1d2 100644 --- a/atom/browser/native_window_mac.h +++ b/atom/browser/native_window_mac.h @@ -59,6 +59,7 @@ class NativeWindowMac : public NativeWindow { virtual void SetKiosk(bool kiosk) OVERRIDE; virtual bool IsKiosk() OVERRIDE; virtual void SetRepresentedFilename(const std::string& filename) OVERRIDE; + virtual std::string GetRepresentedFilename() OVERRIDE; virtual void SetDocumentEdited(bool edited) OVERRIDE; virtual bool HasModalDialog() OVERRIDE; virtual gfx::NativeWindow GetNativeWindow() OVERRIDE; diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index 794f4a8af13c..b524a8acf46e 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -452,6 +452,10 @@ void NativeWindowMac::SetRepresentedFilename(const std::string& filename) { [window_ setRepresentedFilename:base::SysUTF8ToNSString(filename)]; } +std::string NativeWindowMac::GetRepresentedFilename() { + return base::SysNSStringToUTF8([window_ representedFilename]); +} + void NativeWindowMac::SetDocumentEdited(bool edited) { [window_ setDocumentEdited:edited]; } diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index 57b89202400d..8facd14f0f30 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -383,6 +383,10 @@ Returns whether the window is in kiosk mode. __OS X Only:__ Sets the pathname of the file the window represents, and the icon of the file will show in window's title bar. +### BrowserWindow.getRepresentedFilename() + +__OS X Only:__ Returns the pathname of the file the window represents. + ### BrowserWindow.setDocumentEdited(edited) * `edited` Boolean