Merge pull request #8038 from electron/danhp/close-file-preview
Add 'win.closeFilePreview()'
This commit is contained in:
commit
774b2f99f2
8 changed files with 34 additions and 0 deletions
|
@ -757,6 +757,10 @@ void Window::PreviewFile(const std::string& path, mate::Arguments* args) {
|
||||||
window_->PreviewFile(path, display_name);
|
window_->PreviewFile(path, display_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Window::CloseFilePreview() {
|
||||||
|
window_->CloseFilePreview();
|
||||||
|
}
|
||||||
|
|
||||||
void Window::SetParentWindow(v8::Local<v8::Value> value,
|
void Window::SetParentWindow(v8::Local<v8::Value> value,
|
||||||
mate::Arguments* args) {
|
mate::Arguments* args) {
|
||||||
if (IsModal()) {
|
if (IsModal()) {
|
||||||
|
@ -861,6 +865,7 @@ void Window::BuildPrototype(v8::Isolate* isolate,
|
||||||
.SetMethod("isFullScreen", &Window::IsFullscreen)
|
.SetMethod("isFullScreen", &Window::IsFullscreen)
|
||||||
.SetMethod("setAspectRatio", &Window::SetAspectRatio)
|
.SetMethod("setAspectRatio", &Window::SetAspectRatio)
|
||||||
.SetMethod("previewFile", &Window::PreviewFile)
|
.SetMethod("previewFile", &Window::PreviewFile)
|
||||||
|
.SetMethod("closeFilePreview", &Window::CloseFilePreview)
|
||||||
#if !defined(OS_WIN)
|
#if !defined(OS_WIN)
|
||||||
.SetMethod("setParentWindow", &Window::SetParentWindow)
|
.SetMethod("setParentWindow", &Window::SetParentWindow)
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -171,6 +171,7 @@ class Window : public mate::TrackableObject<Window>,
|
||||||
bool IsMenuBarVisible();
|
bool IsMenuBarVisible();
|
||||||
void SetAspectRatio(double aspect_ratio, mate::Arguments* args);
|
void SetAspectRatio(double aspect_ratio, mate::Arguments* args);
|
||||||
void PreviewFile(const std::string& path, mate::Arguments* args);
|
void PreviewFile(const std::string& path, mate::Arguments* args);
|
||||||
|
void CloseFilePreview();
|
||||||
void SetParentWindow(v8::Local<v8::Value> value, mate::Arguments* args);
|
void SetParentWindow(v8::Local<v8::Value> value, mate::Arguments* args);
|
||||||
v8::Local<v8::Value> GetParentWindow() const;
|
v8::Local<v8::Value> GetParentWindow() const;
|
||||||
std::vector<v8::Local<v8::Object>> GetChildWindows() const;
|
std::vector<v8::Local<v8::Object>> GetChildWindows() const;
|
||||||
|
|
|
@ -381,6 +381,9 @@ void NativeWindow::PreviewFile(const std::string& path,
|
||||||
const std::string& display_name) {
|
const std::string& display_name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NativeWindow::CloseFilePreview() {
|
||||||
|
}
|
||||||
|
|
||||||
void NativeWindow::RequestToClosePage() {
|
void NativeWindow::RequestToClosePage() {
|
||||||
bool prevent_default = false;
|
bool prevent_default = false;
|
||||||
FOR_EACH_OBSERVER(NativeWindowObserver,
|
FOR_EACH_OBSERVER(NativeWindowObserver,
|
||||||
|
|
|
@ -179,8 +179,11 @@ class NativeWindow : public base::SupportsUserData,
|
||||||
double GetAspectRatio();
|
double GetAspectRatio();
|
||||||
gfx::Size GetAspectRatioExtraSize();
|
gfx::Size GetAspectRatioExtraSize();
|
||||||
virtual void SetAspectRatio(double aspect_ratio, const gfx::Size& extra_size);
|
virtual void SetAspectRatio(double aspect_ratio, const gfx::Size& extra_size);
|
||||||
|
|
||||||
|
// File preview APIs.
|
||||||
virtual void PreviewFile(const std::string& path,
|
virtual void PreviewFile(const std::string& path,
|
||||||
const std::string& display_name);
|
const std::string& display_name);
|
||||||
|
virtual void CloseFilePreview();
|
||||||
|
|
||||||
base::WeakPtr<NativeWindow> GetWeakPtr() {
|
base::WeakPtr<NativeWindow> GetWeakPtr() {
|
||||||
return weak_factory_.GetWeakPtr();
|
return weak_factory_.GetWeakPtr();
|
||||||
|
|
|
@ -57,6 +57,7 @@ class NativeWindowMac : public NativeWindow,
|
||||||
override;
|
override;
|
||||||
void PreviewFile(const std::string& path, const std::string& display_name)
|
void PreviewFile(const std::string& path, const std::string& display_name)
|
||||||
override;
|
override;
|
||||||
|
void CloseFilePreview() override;
|
||||||
bool IsMovable() override;
|
bool IsMovable() override;
|
||||||
void SetMinimizable(bool minimizable) override;
|
void SetMinimizable(bool minimizable) override;
|
||||||
bool IsMinimizable() override;
|
bool IsMinimizable() override;
|
||||||
|
|
|
@ -1004,6 +1004,12 @@ void NativeWindowMac::PreviewFile(const std::string& path,
|
||||||
[window_ previewFileAtPath:path_ns withName:name_ns];
|
[window_ previewFileAtPath:path_ns withName:name_ns];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NativeWindowMac::CloseFilePreview() {
|
||||||
|
if ([QLPreviewPanel sharedPreviewPanelExists]) {
|
||||||
|
[[QLPreviewPanel sharedPreviewPanel] close];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void NativeWindowMac::SetMovable(bool movable) {
|
void NativeWindowMac::SetMovable(bool movable) {
|
||||||
[window_ setMovable:movable];
|
[window_ setMovable:movable];
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.
|
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])`
|
#### `win.setBounds(bounds[, animate])`
|
||||||
|
|
||||||
* `bounds` [Rectangle](structures/rectangle.md)
|
* `bounds` [Rectangle](structures/rectangle.md)
|
||||||
|
|
|
@ -1718,6 +1718,17 @@ describe('browser-window module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('previewFile', function () {
|
||||||
|
it('opens the path in Quick Look on macOS', function () {
|
||||||
|
if (process.platform !== 'darwin') return this.skip()
|
||||||
|
|
||||||
|
assert.doesNotThrow(function () {
|
||||||
|
w.previewFile(__filename)
|
||||||
|
w.closeFilePreview()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe('offscreen rendering', function () {
|
describe('offscreen rendering', function () {
|
||||||
this.timeout(10000)
|
this.timeout(10000)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue