From 6f231d58608f12aea749400b719f761c1df02116 Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Thu, 24 Jul 2014 15:48:33 +0800 Subject: [PATCH] mac: Add BrowserWindow.isDoucumentEdited API, fixes #459. --- 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 668aa1a55c2..0fabdd1a5bf 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -328,6 +328,10 @@ void Window::SetDocumentEdited(bool edited) { window_->SetDocumentEdited(edited); } +bool Window::IsDocumentEdited() { + return window_->IsDocumentEdited(); +} + mate::Handle Window::GetWebContents(v8::Isolate* isolate) const { return WebContents::Create(isolate, window_->GetWebContents()); } @@ -379,6 +383,7 @@ void Window::BuildPrototype(v8::Isolate* isolate, .SetMethod("setRepresentedFilename", &Window::SetRepresentedFilename) .SetMethod("getRepresentedFilename", &Window::GetRepresentedFilename) .SetMethod("setDocumentEdited", &Window::SetDocumentEdited) + .SetMethod("IsDocumentEdited", &Window::IsDocumentEdited) .SetMethod("_openDevTools", &Window::OpenDevTools) .SetMethod("closeDevTools", &Window::CloseDevTools) .SetMethod("isDevToolsOpened", &Window::IsDevToolsOpened) diff --git a/atom/browser/api/atom_api_window.h b/atom/browser/api/atom_api_window.h index d47a66f1dfa..62e7d7f0874 100644 --- a/atom/browser/api/atom_api_window.h +++ b/atom/browser/api/atom_api_window.h @@ -100,6 +100,7 @@ class Window : public mate::EventEmitter, void SetRepresentedFilename(const std::string& filename); std::string GetRepresentedFilename(); void SetDocumentEdited(bool edited); + bool IsDocumentEdited(); // APIs for WebContents. mate::Handle GetWebContents(v8::Isolate* isolate) const; diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index 5027114915f..bf055570bdb 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -202,6 +202,10 @@ void NativeWindow::SetDocumentEdited(bool edited) { void NativeWindow::SetMenu(ui::MenuModel* menu) { } +bool NativeWindow::IsDocumentEdited() { + return false; +} + bool NativeWindow::HasModalDialog() { return has_dialog_attached_; } diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index 896e0dbc10e..537f485ef5a 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -138,6 +138,7 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate, virtual std::string GetRepresentedFilename(); virtual void SetDocumentEdited(bool edited); virtual void SetMenu(ui::MenuModel* menu); + virtual bool IsDocumentEdited(); virtual bool HasModalDialog(); virtual gfx::NativeWindow GetNativeWindow() = 0; diff --git a/atom/browser/native_window_mac.h b/atom/browser/native_window_mac.h index 5df01f91a1d..4b29c5d6a68 100644 --- a/atom/browser/native_window_mac.h +++ b/atom/browser/native_window_mac.h @@ -61,6 +61,7 @@ class NativeWindowMac : public NativeWindow { virtual void SetRepresentedFilename(const std::string& filename) OVERRIDE; virtual std::string GetRepresentedFilename() OVERRIDE; virtual void SetDocumentEdited(bool edited) OVERRIDE; + virtual bool IsDocumentEdited() 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 b524a8acf46..07047a3b9e8 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -460,6 +460,10 @@ void NativeWindowMac::SetDocumentEdited(bool edited) { [window_ setDocumentEdited:edited]; } +bool NativeWindowMac::IsDocumentEdited() { + return [window_ isDocumentEdited]; +} + bool NativeWindowMac::HasModalDialog() { return [window_ attachedSheet] != nil; } diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index 8facd14f0f3..cb90af40349 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -394,6 +394,10 @@ __OS X Only:__ Returns the pathname of the file the window represents. __OS X Only:__ Specifies whether the window’s document has been edited, and the icon in titlebar will become grey when set to `true`. +### BrowserWindow.IsDocumentEdited() + +__OS X Only:__ Whether the window's document has been edited. + ### BrowserWindow.openDevTools() Opens the developer tools.