Move QLPreviewPanelDataSource to AtomNSWindowDelegate
This commit is contained in:
Родитель
f6a7e5ea23
Коммит
569967ac21
|
@ -17,6 +17,7 @@
|
|||
|
||||
@class AtomNSWindow;
|
||||
@class AtomNSWindowDelegate;
|
||||
@class AtomPreviewItem;
|
||||
@class AtomTouchBar;
|
||||
@class FullSizeContentView;
|
||||
|
||||
|
@ -137,7 +138,8 @@ class NativeWindowMac : public NativeWindow {
|
|||
};
|
||||
TitleBarStyle title_bar_style() const { return title_bar_style_; }
|
||||
|
||||
AtomTouchBar* atom_touch_bar() const { return atom_touch_bar_.get(); }
|
||||
AtomPreviewItem* preview_item() const { return preview_item_.get(); }
|
||||
AtomTouchBar* touch_bar() const { return touch_bar_.get(); }
|
||||
bool zoom_to_page_width() const { return zoom_to_page_width_; }
|
||||
bool fullscreen_window_title() const { return fullscreen_window_title_; }
|
||||
bool simple_fullscreen() const { return always_simple_fullscreen_; }
|
||||
|
@ -150,7 +152,8 @@ class NativeWindowMac : public NativeWindow {
|
|||
|
||||
base::scoped_nsobject<AtomNSWindow> window_;
|
||||
base::scoped_nsobject<AtomNSWindowDelegate> window_delegate_;
|
||||
base::scoped_nsobject<AtomTouchBar> atom_touch_bar_;
|
||||
base::scoped_nsobject<AtomPreviewItem> preview_item_;
|
||||
base::scoped_nsobject<AtomTouchBar> touch_bar_;
|
||||
|
||||
std::unique_ptr<views::Widget> widget_;
|
||||
|
||||
|
|
|
@ -5,11 +5,12 @@
|
|||
#include "atom/browser/native_window_mac.h"
|
||||
|
||||
#include <AvailabilityMacros.h>
|
||||
#include <Quartz/Quartz.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "atom/browser/native_browser_view_mac.h"
|
||||
#include "atom/browser/ui/cocoa/atom_ns_window_delegate.h"
|
||||
#include "atom/browser/ui/cocoa/atom_preview_item.h"
|
||||
#include "atom/browser/ui/cocoa/atom_touch_bar.h"
|
||||
#include "atom/browser/window_list.h"
|
||||
#include "atom/common/options_switches.h"
|
||||
|
@ -165,31 +166,6 @@ bool ScopedDisableResize::disable_resize_ = false;
|
|||
|
||||
@end
|
||||
|
||||
@interface AtomPreviewItem : NSObject <QLPreviewItem>
|
||||
|
||||
@property (nonatomic, retain) NSURL* previewItemURL;
|
||||
@property (nonatomic, retain) NSString* previewItemTitle;
|
||||
|
||||
- (id)initWithURL:(NSURL*)url title:(NSString*)title;
|
||||
|
||||
@end
|
||||
|
||||
@implementation AtomPreviewItem
|
||||
|
||||
@synthesize previewItemURL;
|
||||
@synthesize previewItemTitle;
|
||||
|
||||
- (id)initWithURL:(NSURL*)url title:(NSString*)title {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
self.previewItemURL = url;
|
||||
self.previewItemTitle = title;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
#if !defined(AVAILABLE_MAC_OS_X_VERSION_10_12_AND_LATER)
|
||||
|
||||
enum {
|
||||
|
@ -209,7 +185,7 @@ enum {
|
|||
|
||||
#endif
|
||||
|
||||
@interface AtomNSWindow : EventDispatchingWindow<QLPreviewPanelDataSource, QLPreviewPanelDelegate> {
|
||||
@interface AtomNSWindow : EventDispatchingWindow {
|
||||
@private
|
||||
atom::NativeWindowMac* shell_;
|
||||
bool enable_larger_than_screen_;
|
||||
|
@ -219,7 +195,6 @@ enum {
|
|||
@property BOOL disableAutoHideCursor;
|
||||
@property BOOL disableKeyOrMainWindow;
|
||||
@property NSPoint windowButtonsOffset;
|
||||
@property (nonatomic, retain) AtomPreviewItem* quickLookItem;
|
||||
@property (nonatomic, retain) NSView* vibrantView;
|
||||
|
||||
- (void)setShell:(atom::NativeWindowMac*)shell;
|
||||
|
@ -246,8 +221,8 @@ enum {
|
|||
}
|
||||
|
||||
- (NSTouchBar*)makeTouchBar API_AVAILABLE(macosx(10.12.2)) {
|
||||
if (shell_->atom_touch_bar())
|
||||
return [shell_->atom_touch_bar() makeTouchBar];
|
||||
if (shell_->touch_bar())
|
||||
return [shell_->touch_bar() makeTouchBar];
|
||||
else
|
||||
return nil;
|
||||
}
|
||||
|
@ -400,8 +375,8 @@ enum {
|
|||
}
|
||||
|
||||
- (void)beginPreviewPanelControl:(QLPreviewPanel*)panel {
|
||||
panel.delegate = self;
|
||||
panel.dataSource = self;
|
||||
panel.delegate = [self delegate];
|
||||
panel.dataSource = static_cast<id<QLPreviewPanelDataSource>>([self delegate]);
|
||||
}
|
||||
|
||||
- (void)endPreviewPanelControl:(QLPreviewPanel*)panel {
|
||||
|
@ -409,20 +384,6 @@ enum {
|
|||
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];
|
||||
}
|
||||
|
||||
// Custom window button methods
|
||||
|
||||
- (void)performClose:(id)sender {
|
||||
|
@ -1007,9 +968,10 @@ void NativeWindowMac::SetAspectRatio(double aspect_ratio,
|
|||
|
||||
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];
|
||||
preview_item_.reset([[AtomPreviewItem alloc]
|
||||
initWithURL:[NSURL fileURLWithPath:base::SysUTF8ToNSString(path)]
|
||||
title:base::SysUTF8ToNSString(display_name)]);
|
||||
[[QLPreviewPanel sharedPreviewPanel] makeKeyAndOrderFront:nil];
|
||||
}
|
||||
|
||||
void NativeWindowMac::CloseFilePreview() {
|
||||
|
@ -1507,7 +1469,7 @@ void NativeWindowMac::SetTouchBar(
|
|||
if (![window_ respondsToSelector:@selector(touchBar)])
|
||||
return;
|
||||
|
||||
atom_touch_bar_.reset([[AtomTouchBar alloc]
|
||||
touch_bar_.reset([[AtomTouchBar alloc]
|
||||
initWithDelegate:window_delegate_.get()
|
||||
window:this
|
||||
settings:items]);
|
||||
|
@ -1515,14 +1477,14 @@ void NativeWindowMac::SetTouchBar(
|
|||
}
|
||||
|
||||
void NativeWindowMac::RefreshTouchBarItem(const std::string& item_id) {
|
||||
if (atom_touch_bar_ && [window_ touchBar])
|
||||
[atom_touch_bar_ refreshTouchBarItem:[window_ touchBar] id:item_id];
|
||||
if (touch_bar_ && [window_ touchBar])
|
||||
[touch_bar_ refreshTouchBarItem:[window_ touchBar] id:item_id];
|
||||
}
|
||||
|
||||
void NativeWindowMac::SetEscapeTouchBarItem(
|
||||
const mate::PersistentDictionary& item) {
|
||||
if (atom_touch_bar_ && [window_ touchBar])
|
||||
[atom_touch_bar_ setEscapeTouchBarItem:item forTouchBar:[window_ touchBar]];
|
||||
if (touch_bar_ && [window_ touchBar])
|
||||
[touch_bar_ setEscapeTouchBarItem:item forTouchBar:[window_ touchBar]];
|
||||
}
|
||||
|
||||
gfx::Rect NativeWindowMac::ContentBoundsToWindowBounds(
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
#ifndef ATOM_BROWSER_UI_COCOA_ATOM_NS_WINDOW_DELEGATE_H_
|
||||
#define ATOM_BROWSER_UI_COCOA_ATOM_NS_WINDOW_DELEGATE_H_
|
||||
|
||||
#include <Quartz/Quartz.h>
|
||||
|
||||
#include "ui/views/cocoa/views_nswindow_delegate.h"
|
||||
|
||||
namespace atom {
|
||||
|
@ -12,7 +14,8 @@ class NativeWindowMac;
|
|||
}
|
||||
|
||||
@interface AtomNSWindowDelegate : NSObject<NSWindowDelegate,
|
||||
NSTouchBarDelegate> {
|
||||
NSTouchBarDelegate,
|
||||
QLPreviewPanelDataSource> {
|
||||
@private
|
||||
atom::NativeWindowMac* shell_;
|
||||
bool is_zooming_;
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include "atom/browser/browser.h"
|
||||
#include "atom/browser/native_window_mac.h"
|
||||
#include "atom/browser/ui/cocoa/atom_preview_item.h"
|
||||
#include "atom/browser/ui/cocoa/atom_touch_bar.h"
|
||||
#include "base/mac/mac_util.h"
|
||||
|
||||
|
@ -253,10 +254,21 @@
|
|||
|
||||
- (NSTouchBarItem*)touchBar:(NSTouchBar*)touchBar
|
||||
makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier API_AVAILABLE(macosx(10.12.2)) {
|
||||
if (touchBar && shell_->atom_touch_bar())
|
||||
return [shell_->atom_touch_bar() makeItemForIdentifier:identifier];
|
||||
if (touchBar && shell_->touch_bar())
|
||||
return [shell_->touch_bar() makeItemForIdentifier:identifier];
|
||||
else
|
||||
return nil;
|
||||
}
|
||||
|
||||
#pragma mark - QLPreviewPanelDataSource
|
||||
|
||||
- (NSInteger)numberOfPreviewItemsInPreviewPanel:(QLPreviewPanel*)panel {
|
||||
return 1;
|
||||
}
|
||||
|
||||
- (id <QLPreviewItem>)previewPanel:(QLPreviewPanel*)panel
|
||||
previewItemAtIndex:(NSInteger)index {
|
||||
return shell_->preview_item();
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
// Copyright (c) 2018 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef ATOM_BROWSER_UI_COCOA_ATOM_PREVIEW_ITEM_H_
|
||||
#define ATOM_BROWSER_UI_COCOA_ATOM_PREVIEW_ITEM_H_
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import <Quartz/Quartz.h>
|
||||
|
||||
@interface AtomPreviewItem : NSObject<QLPreviewItem>
|
||||
@property (nonatomic, retain) NSURL* previewItemURL;
|
||||
@property (nonatomic, retain) NSString* previewItemTitle;
|
||||
- (id)initWithURL:(NSURL*)url title:(NSString*)title;
|
||||
@end
|
||||
|
||||
#endif // ATOM_BROWSER_UI_COCOA_ATOM_PREVIEW_ITEM_H_
|
|
@ -0,0 +1,21 @@
|
|||
// Copyright (c) 2018 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "atom/browser/ui/cocoa/atom_preview_item.h"
|
||||
|
||||
@implementation AtomPreviewItem
|
||||
|
||||
@synthesize previewItemURL;
|
||||
@synthesize previewItemTitle;
|
||||
|
||||
- (id)initWithURL:(NSURL*)url title:(NSString*)title {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
self.previewItemURL = url;
|
||||
self.previewItemTitle = title;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
|
@ -320,6 +320,8 @@
|
|||
'atom/browser/ui/cocoa/atom_native_widget_mac.mm',
|
||||
'atom/browser/ui/cocoa/atom_ns_window_delegate.h',
|
||||
'atom/browser/ui/cocoa/atom_ns_window_delegate.mm',
|
||||
'atom/browser/ui/cocoa/atom_preview_item.h',
|
||||
'atom/browser/ui/cocoa/atom_preview_item.mm',
|
||||
'atom/browser/ui/cocoa/atom_touch_bar.h',
|
||||
'atom/browser/ui/cocoa/atom_touch_bar.mm',
|
||||
'atom/browser/ui/cocoa/views_delegate_mac.h',
|
||||
|
|
|
@ -13,6 +13,7 @@ IGNORE_FILES = set(os.path.join(*components) for components in [
|
|||
['atom', 'browser', 'resources', 'win', 'resource.h'],
|
||||
['atom', 'browser', 'ui', 'cocoa', 'atom_menu_controller.h'],
|
||||
['atom', 'browser', 'ui', 'cocoa', 'atom_ns_window_delegate.h'],
|
||||
['atom', 'browser', 'ui', 'cocoa', 'atom_preview_item.h'],
|
||||
['atom', 'browser', 'ui', 'cocoa', 'atom_touch_bar.h'],
|
||||
['atom', 'browser', 'ui', 'cocoa', 'touch_bar_forward_declarations.h'],
|
||||
['atom', 'browser', 'ui', 'cocoa', 'NSColor+Hex.h'],
|
||||
|
|
Загрузка…
Ссылка в новой задаче