Merge pull request #7592 from frontapp/master
Preview file with QuickLook
This commit is contained in:
commit
9e266642f9
8 changed files with 92 additions and 1 deletions
|
@ -729,6 +729,13 @@ void Window::SetAspectRatio(double aspect_ratio, mate::Arguments* args) {
|
||||||
window_->SetAspectRatio(aspect_ratio, extra_size);
|
window_->SetAspectRatio(aspect_ratio, extra_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Window::PreviewFile(const std::string& path, mate::Arguments* args) {
|
||||||
|
std::string display_name;
|
||||||
|
if (!args->GetNext(&display_name))
|
||||||
|
display_name = path;
|
||||||
|
window_->PreviewFile(path, display_name);
|
||||||
|
}
|
||||||
|
|
||||||
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()) {
|
||||||
|
@ -825,6 +832,7 @@ void Window::BuildPrototype(v8::Isolate* isolate,
|
||||||
.SetMethod("setFullScreen", &Window::SetFullScreen)
|
.SetMethod("setFullScreen", &Window::SetFullScreen)
|
||||||
.SetMethod("isFullScreen", &Window::IsFullscreen)
|
.SetMethod("isFullScreen", &Window::IsFullscreen)
|
||||||
.SetMethod("setAspectRatio", &Window::SetAspectRatio)
|
.SetMethod("setAspectRatio", &Window::SetAspectRatio)
|
||||||
|
.SetMethod("previewFile", &Window::PreviewFile)
|
||||||
#if !defined(OS_WIN)
|
#if !defined(OS_WIN)
|
||||||
.SetMethod("setParentWindow", &Window::SetParentWindow)
|
.SetMethod("setParentWindow", &Window::SetParentWindow)
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -170,6 +170,7 @@ class Window : public mate::TrackableObject<Window>,
|
||||||
void SetMenuBarVisibility(bool visible);
|
void SetMenuBarVisibility(bool visible);
|
||||||
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 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;
|
||||||
|
|
|
@ -374,6 +374,10 @@ void NativeWindow::SetAspectRatio(double aspect_ratio,
|
||||||
aspect_ratio_extraSize_ = extra_size;
|
aspect_ratio_extraSize_ = extra_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NativeWindow::PreviewFile(const std::string& path,
|
||||||
|
const std::string& display_name) {
|
||||||
|
}
|
||||||
|
|
||||||
void NativeWindow::RequestToClosePage() {
|
void NativeWindow::RequestToClosePage() {
|
||||||
bool prevent_default = false;
|
bool prevent_default = false;
|
||||||
FOR_EACH_OBSERVER(NativeWindowObserver,
|
FOR_EACH_OBSERVER(NativeWindowObserver,
|
||||||
|
|
|
@ -176,6 +176,8 @@ 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);
|
||||||
|
virtual void PreviewFile(const std::string& path,
|
||||||
|
const std::string& display_name);
|
||||||
|
|
||||||
base::WeakPtr<NativeWindow> GetWeakPtr() {
|
base::WeakPtr<NativeWindow> GetWeakPtr() {
|
||||||
return weak_factory_.GetWeakPtr();
|
return weak_factory_.GetWeakPtr();
|
||||||
|
|
|
@ -55,6 +55,8 @@ class NativeWindowMac : public NativeWindow,
|
||||||
void SetMovable(bool movable) override;
|
void SetMovable(bool movable) override;
|
||||||
void SetAspectRatio(double aspect_ratio, const gfx::Size& extra_size)
|
void SetAspectRatio(double aspect_ratio, const gfx::Size& extra_size)
|
||||||
override;
|
override;
|
||||||
|
void PreviewFile(const std::string& path, const std::string& display_name)
|
||||||
|
override;
|
||||||
bool IsMovable() override;
|
bool IsMovable() override;
|
||||||
void SetMinimizable(bool minimizable) override;
|
void SetMinimizable(bool minimizable) override;
|
||||||
bool IsMinimizable() override;
|
bool IsMinimizable() override;
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include "atom/browser/native_window_mac.h"
|
#include "atom/browser/native_window_mac.h"
|
||||||
|
|
||||||
|
#include <Quartz/Quartz.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "atom/browser/window_list.h"
|
#include "atom/browser/window_list.h"
|
||||||
|
@ -277,7 +278,29 @@ bool ScopedDisableResize::disable_resize_ = false;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface AtomNSWindow : EventDispatchingWindow {
|
@interface AtomPreviewItem : NSObject <QLPreviewItem>
|
||||||
|
|
||||||
|
@property (nonatomic, retain) NSURL* previewItemURL;
|
||||||
|
@property (nonatomic, retain) NSString* previewItemTitle;
|
||||||
|
|
||||||
|
- (id)initWithURL:(NSURL*)url title:(NSString*)title;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation AtomPreviewItem
|
||||||
|
|
||||||
|
- (id)initWithURL:(NSURL*)url title:(NSString*)title {
|
||||||
|
self = [super init];
|
||||||
|
if (self) {
|
||||||
|
self.previewItemURL = url;
|
||||||
|
self.previewItemTitle = title;
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface AtomNSWindow : EventDispatchingWindow<QLPreviewPanelDataSource, QLPreviewPanelDelegate> {
|
||||||
@private
|
@private
|
||||||
atom::NativeWindowMac* shell_;
|
atom::NativeWindowMac* shell_;
|
||||||
bool enable_larger_than_screen_;
|
bool enable_larger_than_screen_;
|
||||||
|
@ -287,6 +310,7 @@ bool ScopedDisableResize::disable_resize_ = false;
|
||||||
@property BOOL disableAutoHideCursor;
|
@property BOOL disableAutoHideCursor;
|
||||||
@property BOOL disableKeyOrMainWindow;
|
@property BOOL disableKeyOrMainWindow;
|
||||||
@property NSPoint windowButtonsOffset;
|
@property NSPoint windowButtonsOffset;
|
||||||
|
@property (nonatomic, retain) AtomPreviewItem* quickLookItem;
|
||||||
|
|
||||||
- (void)setShell:(atom::NativeWindowMac*)shell;
|
- (void)setShell:(atom::NativeWindowMac*)shell;
|
||||||
- (void)setEnableLargerThanScreen:(bool)enable;
|
- (void)setEnableLargerThanScreen:(bool)enable;
|
||||||
|
@ -444,6 +468,36 @@ bool ScopedDisableResize::disable_resize_ = false;
|
||||||
return [[self contentView] superview];
|
return [[self contentView] superview];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Quicklook methods
|
||||||
|
|
||||||
|
- (BOOL)acceptsPreviewPanelControl:(QLPreviewPanel*)panel {
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)beginPreviewPanelControl:(QLPreviewPanel*)panel {
|
||||||
|
panel.delegate = self;
|
||||||
|
panel.dataSource = self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)endPreviewPanelControl:(QLPreviewPanel*)panel {
|
||||||
|
panel.delegate = nil;
|
||||||
|
panel.dataSource = nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSInteger)numberOfPreviewItemsInPreviewPanel:(QLPreviewPanel*)panel {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (id <QLPreviewItem>)previewPanel:(QLPreviewPanel*)panel previewItemAtIndex:(NSInteger)index {
|
||||||
|
return [self quickLookItem];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)previewFileAtPath:(NSString*)path withName:(NSString*) fileName {
|
||||||
|
NSURL* url = [[[NSURL alloc] initFileURLWithPath:path] autorelease];
|
||||||
|
[self setQuickLookItem:[[[AtomPreviewItem alloc] initWithURL:url title:fileName] autorelease]];
|
||||||
|
[[QLPreviewPanel sharedPreviewPanel] makeKeyAndOrderFront:nil];
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface ControlRegionView : NSView
|
@interface ControlRegionView : NSView
|
||||||
|
@ -899,6 +953,13 @@ void NativeWindowMac::SetAspectRatio(double aspect_ratio,
|
||||||
[window_ setResizeIncrements:NSMakeSize(1.0, 1.0)];
|
[window_ setResizeIncrements:NSMakeSize(1.0, 1.0)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NativeWindowMac::PreviewFile(const std::string& path,
|
||||||
|
const std::string& display_name) {
|
||||||
|
NSString* path_ns = [NSString stringWithUTF8String:path.c_str()];
|
||||||
|
NSString* name_ns = [NSString stringWithUTF8String:display_name.c_str()];
|
||||||
|
[window_ previewFileAtPath:path_ns withName:name_ns];
|
||||||
|
}
|
||||||
|
|
||||||
void NativeWindowMac::SetMovable(bool movable) {
|
void NativeWindowMac::SetMovable(bool movable) {
|
||||||
[window_ setMovable:movable];
|
[window_ setMovable:movable];
|
||||||
}
|
}
|
||||||
|
|
|
@ -664,6 +664,17 @@ the player itself we would call this function with arguments of 16/9 and
|
||||||
are within the content view--only that they exist. Just sum any extra width and
|
are within the content view--only that they exist. Just sum any extra width and
|
||||||
height areas you have within the overall content view.
|
height areas you have within the overall content view.
|
||||||
|
|
||||||
|
#### `win.previewFile(path[, displayName])` _macOS_
|
||||||
|
|
||||||
|
* `path` String - The absolute path to the file to preview with QuickLook. This
|
||||||
|
is important as Quick Look uses the file name and file extension on the path
|
||||||
|
to determine the content type of the file to open.
|
||||||
|
* `displayName` String (Optional) - The name of the file to display on the
|
||||||
|
Quick Look modal view. This is purely visual and does not affect the content
|
||||||
|
type of the file. Defaults to `path`.
|
||||||
|
|
||||||
|
Uses [Quick Look][quick-look] to preview a file at a given path.
|
||||||
|
|
||||||
#### `win.setBounds(bounds[, animate])`
|
#### `win.setBounds(bounds[, animate])`
|
||||||
|
|
||||||
* `bounds` [Rectangle](structures/rectangle.md)
|
* `bounds` [Rectangle](structures/rectangle.md)
|
||||||
|
@ -1182,3 +1193,4 @@ Returns `BrowserWindow` - The parent window.
|
||||||
Returns `BrowserWindow[]` - All child windows.
|
Returns `BrowserWindow[]` - All child windows.
|
||||||
|
|
||||||
[window-levels]: https://developer.apple.com/reference/appkit/nswindow/1664726-window_levels
|
[window-levels]: https://developer.apple.com/reference/appkit/nswindow/1664726-window_levels
|
||||||
|
[quick-look]: https://en.wikipedia.org/wiki/Quick_Look
|
||||||
|
|
|
@ -509,6 +509,7 @@
|
||||||
'libraries': [
|
'libraries': [
|
||||||
'$(SDKROOT)/System/Library/Frameworks/Carbon.framework',
|
'$(SDKROOT)/System/Library/Frameworks/Carbon.framework',
|
||||||
'$(SDKROOT)/System/Library/Frameworks/QuartzCore.framework',
|
'$(SDKROOT)/System/Library/Frameworks/QuartzCore.framework',
|
||||||
|
'$(SDKROOT)/System/Library/Frameworks/Quartz.framework',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
'mac_bundle': 1,
|
'mac_bundle': 1,
|
||||||
|
|
Loading…
Reference in a new issue