Merge pull request #493 from hokein/issue460

mac: Add BrowserWindow.getRepresentedFilename API, fixes #460.
This commit is contained in:
Cheng Zhao 2014-07-24 21:10:43 +08:00
commit 99ef165884
7 changed files with 40 additions and 0 deletions

View file

@ -320,10 +320,18 @@ void Window::SetRepresentedFilename(const std::string& filename) {
window_->SetRepresentedFilename(filename); window_->SetRepresentedFilename(filename);
} }
std::string Window::GetRepresentedFilename() {
return window_->GetRepresentedFilename();
}
void Window::SetDocumentEdited(bool edited) { void Window::SetDocumentEdited(bool edited) {
window_->SetDocumentEdited(edited); window_->SetDocumentEdited(edited);
} }
bool Window::IsDocumentEdited() {
return window_->IsDocumentEdited();
}
mate::Handle<WebContents> Window::GetWebContents(v8::Isolate* isolate) const { mate::Handle<WebContents> Window::GetWebContents(v8::Isolate* isolate) const {
return WebContents::Create(isolate, window_->GetWebContents()); return WebContents::Create(isolate, window_->GetWebContents());
} }
@ -373,7 +381,9 @@ void Window::BuildPrototype(v8::Isolate* isolate,
.SetMethod("setKiosk", &Window::SetKiosk) .SetMethod("setKiosk", &Window::SetKiosk)
.SetMethod("isKiosk", &Window::IsKiosk) .SetMethod("isKiosk", &Window::IsKiosk)
.SetMethod("setRepresentedFilename", &Window::SetRepresentedFilename) .SetMethod("setRepresentedFilename", &Window::SetRepresentedFilename)
.SetMethod("getRepresentedFilename", &Window::GetRepresentedFilename)
.SetMethod("setDocumentEdited", &Window::SetDocumentEdited) .SetMethod("setDocumentEdited", &Window::SetDocumentEdited)
.SetMethod("IsDocumentEdited", &Window::IsDocumentEdited)
.SetMethod("_openDevTools", &Window::OpenDevTools) .SetMethod("_openDevTools", &Window::OpenDevTools)
.SetMethod("closeDevTools", &Window::CloseDevTools) .SetMethod("closeDevTools", &Window::CloseDevTools)
.SetMethod("isDevToolsOpened", &Window::IsDevToolsOpened) .SetMethod("isDevToolsOpened", &Window::IsDevToolsOpened)

View file

@ -98,7 +98,9 @@ class Window : public mate::EventEmitter,
bool IsWebViewFocused(); bool IsWebViewFocused();
void CapturePage(mate::Arguments* args); void CapturePage(mate::Arguments* args);
void SetRepresentedFilename(const std::string& filename); void SetRepresentedFilename(const std::string& filename);
std::string GetRepresentedFilename();
void SetDocumentEdited(bool edited); void SetDocumentEdited(bool edited);
bool IsDocumentEdited();
// APIs for WebContents. // APIs for WebContents.
mate::Handle<WebContents> GetWebContents(v8::Isolate* isolate) const; mate::Handle<WebContents> GetWebContents(v8::Isolate* isolate) const;

View file

@ -192,12 +192,20 @@ void NativeWindow::InitFromOptions(const mate::Dictionary& options) {
void NativeWindow::SetRepresentedFilename(const std::string& filename) { void NativeWindow::SetRepresentedFilename(const std::string& filename) {
} }
std::string NativeWindow::GetRepresentedFilename() {
return "";
}
void NativeWindow::SetDocumentEdited(bool edited) { void NativeWindow::SetDocumentEdited(bool edited) {
} }
void NativeWindow::SetMenu(ui::MenuModel* menu) { void NativeWindow::SetMenu(ui::MenuModel* menu) {
} }
bool NativeWindow::IsDocumentEdited() {
return false;
}
bool NativeWindow::HasModalDialog() { bool NativeWindow::HasModalDialog() {
return has_dialog_attached_; return has_dialog_attached_;
} }

View file

@ -135,8 +135,10 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
virtual void SetKiosk(bool kiosk) = 0; virtual void SetKiosk(bool kiosk) = 0;
virtual bool IsKiosk() = 0; virtual bool IsKiosk() = 0;
virtual void SetRepresentedFilename(const std::string& filename); virtual void SetRepresentedFilename(const std::string& filename);
virtual std::string GetRepresentedFilename();
virtual void SetDocumentEdited(bool edited); virtual void SetDocumentEdited(bool edited);
virtual void SetMenu(ui::MenuModel* menu); virtual void SetMenu(ui::MenuModel* menu);
virtual bool IsDocumentEdited();
virtual bool HasModalDialog(); virtual bool HasModalDialog();
virtual gfx::NativeWindow GetNativeWindow() = 0; virtual gfx::NativeWindow GetNativeWindow() = 0;

View file

@ -59,7 +59,9 @@ class NativeWindowMac : public NativeWindow {
virtual void SetKiosk(bool kiosk) OVERRIDE; virtual void SetKiosk(bool kiosk) OVERRIDE;
virtual bool IsKiosk() OVERRIDE; virtual bool IsKiosk() OVERRIDE;
virtual void SetRepresentedFilename(const std::string& filename) OVERRIDE; virtual void SetRepresentedFilename(const std::string& filename) OVERRIDE;
virtual std::string GetRepresentedFilename() OVERRIDE;
virtual void SetDocumentEdited(bool edited) OVERRIDE; virtual void SetDocumentEdited(bool edited) OVERRIDE;
virtual bool IsDocumentEdited() OVERRIDE;
virtual bool HasModalDialog() OVERRIDE; virtual bool HasModalDialog() OVERRIDE;
virtual gfx::NativeWindow GetNativeWindow() OVERRIDE; virtual gfx::NativeWindow GetNativeWindow() OVERRIDE;

View file

@ -461,10 +461,18 @@ void NativeWindowMac::SetRepresentedFilename(const std::string& filename) {
[window_ setRepresentedFilename:base::SysUTF8ToNSString(filename)]; [window_ setRepresentedFilename:base::SysUTF8ToNSString(filename)];
} }
std::string NativeWindowMac::GetRepresentedFilename() {
return base::SysNSStringToUTF8([window_ representedFilename]);
}
void NativeWindowMac::SetDocumentEdited(bool edited) { void NativeWindowMac::SetDocumentEdited(bool edited) {
[window_ setDocumentEdited:edited]; [window_ setDocumentEdited:edited];
} }
bool NativeWindowMac::IsDocumentEdited() {
return [window_ isDocumentEdited];
}
bool NativeWindowMac::HasModalDialog() { bool NativeWindowMac::HasModalDialog() {
return [window_ attachedSheet] != nil; return [window_ attachedSheet] != nil;
} }

View file

@ -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 __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. 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) ### BrowserWindow.setDocumentEdited(edited)
* `edited` Boolean * `edited` Boolean
@ -390,6 +394,10 @@ of the file will show in window's title bar.
__OS X Only:__ Specifies whether the windows document has been edited, and the __OS X Only:__ Specifies whether the windows document has been edited, and the
icon in titlebar will become grey when set to `true`. 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() ### BrowserWindow.openDevTools()
Opens the developer tools. Opens the developer tools.