show in finder done, open with custom dialog started for mac

This commit is contained in:
John Preston 2014-06-17 10:06:01 +04:00
parent 196b412d1f
commit 2b61046a75
9 changed files with 122 additions and 32 deletions

View File

@ -314,6 +314,7 @@ lng_context_copy_image: "Copy Image";
lng_context_close_image: "Close Image";
lng_context_cancel_download: "Cancel Download";
lng_context_show_in_folder: "Show in Folder";
lng_context_show_in_finder: "Show in Finder";
lng_context_open_video: "Open Video";
lng_context_save_video: "Save Video As...";
lng_context_open_audio: "Open Audio";

View File

@ -1768,7 +1768,8 @@ void HistoryVideo::draw(QPainter &p, const HistoryItem *parent, const QString &t
p.fillRect(0, _height, width, st::msgShadow, shadow->b);
if (_thumbw) {
p.drawPixmap(QPoint(st::mediaPadding.left(), st::mediaPadding.top()), data->thumb->pix(_thumbw), QRect(_thumbx, _thumby, st::mediaThumbSize, st::mediaThumbSize));
int32 rf(cIntRetinaFactor());
p.drawPixmap(QPoint(st::mediaPadding.left(), st::mediaPadding.top()), data->thumb->pix(_thumbw), QRect(_thumbx * rf, _thumby * rf, st::mediaThumbSize * rf, st::mediaThumbSize * rf));
} else {
p.drawPixmap(QPoint(st::mediaPadding.left(), st::mediaPadding.top()), App::sprite(), (out ? st::mediaDocOutImg : st::mediaDocInImg));
}

View File

@ -636,7 +636,7 @@ void HistoryList::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
_menu->addAction(lang(lng_context_cancel_download), this, SLOT(cancelContextDownload()))->setEnabled(true);
} else {
if ((lnkVideo && !lnkVideo->video()->already(true).isEmpty()) || (lnkAudio && !lnkAudio->audio()->already(true).isEmpty()) || (lnkDocument && !lnkDocument->document()->already(true).isEmpty())) {
_menu->addAction(lang(lng_context_show_in_folder), this, SLOT(showContextInFolder()))->setEnabled(true);
_menu->addAction(lang(cPlatform() == dbipMac ? lng_context_show_in_finder : lng_context_show_in_folder), this, SLOT(showContextInFolder()))->setEnabled(true);
}
_menu->addAction(lang(lnkVideo ? lng_context_open_video : (lnkAudio ? lng_context_open_audio : lng_context_open_document)), this, SLOT(openContextFile()))->setEnabled(true);
_menu->addAction(lang(lnkVideo ? lng_context_save_video : (lnkAudio ? lng_context_save_audio : lng_context_save_document)), this, SLOT(saveContextFile()))->setEnabled(true);

View File

@ -71,7 +71,7 @@ void debugLogWrite(const char *file, int32 line, const QString &v) {
OutputDebugString(reinterpret_cast<const wchar_t *>(msg.utf16()));
#endif
#ifdef Q_OS_MAC
_outputDebugString(msg.toUtf8().constData());
objc_outputDebugString(msg.toUtf8().constData());
#endif
}
}

View File

@ -130,7 +130,7 @@ posInited(false), trayIcon(0), trayIconMenu(0), icon256(qsl(":/gui/art/iconround
}
void PsMainWindow::psIdleTimeout() {
int64 idleTime = _idleTime();
int64 idleTime = objc_idleTime();
if (idleTime >= 0) {
if (idleTime <= IdleMsecs) {
psIdle = false;
@ -147,7 +147,7 @@ bool PsMainWindow::psIsOnline(int state) const {
} else if (!isVisible()) {
return false;
}
int64 idleTime = _idleTime();
int64 idleTime = objc_idleTime();
LOG(("App Info: idle time %1").arg(idleTime));
if (idleTime >= 0) {
if (idleTime > IdleMsecs) {
@ -1624,26 +1624,11 @@ void psPostprocessFile(const QString &name) {
}
void psOpenFile(const QString &name, bool openWith) {
/*std::wstring wname = QDir::toNativeSeparators(name).toStdWString();
if (openWith && useOpenAs) {
if (shOpenWithDialog) {
OPENASINFO info;
info.oaifInFlags = OAIF_ALLOW_REGISTRATION | OAIF_REGISTER_EXT | OAIF_EXEC;
info.pcszClass = NULL;
info.pcszFile = wname.c_str();
shOpenWithDialog(0, &info);
} else {
openAs_RunDLL(0, 0, wname.c_str(), SW_SHOWNORMAL);
}
} else {
ShellExecute(0, L"open", wname.c_str(), 0, 0, SW_SHOWNORMAL);
}*/
objc_openFile(name.toUtf8().constData(), openWith);
}
void psShowInFolder(const QString &name) {
//QString nameEscaped = QDir::toNativeSeparators(name).replace('"', qsl("\"\""));
//ShellExecute(0, 0, qsl("explorer").toStdWString().c_str(), (qsl("/select,") + nameEscaped).toStdWString().c_str(), 0, SW_SHOWNORMAL);
objc_showInFinder(name.toUtf8().constData(), QFileInfo(name).absolutePath().toUtf8().constData());
}
void psExecUpdater() {

View File

@ -48,6 +48,9 @@ public:
};
void _debugShowAlert(const char *utf8str);
void _outputDebugString(const char *utf8str);
int64 _idleTime();
void objc_debugShowAlert(const char *utf8str);
void objc_outputDebugString(const char *utf8str);
int64 objc_idleTime();
void objc_showInFinder(const char *utf8file, const char *utf8path);
void objc_openFile(const char *utf8file, bool openwith);

View File

@ -18,9 +18,9 @@ Copyright (c) 2014 John Preston, https://tdesktop.com
#include "stdafx.h"
#include "pspecific_mac_p.h"
#include <AppKit/AppKit.h>
#include <Cocoa/Cocoa.h>
#include <IOKit/IOKitLib.h>
#include <CoreFoundation/CFURL.h>
@interface ObserverHelper : NSObject {
}
@ -201,7 +201,7 @@ void PsMacWindowPrivate::clearNotifies(unsigned long long peer) {
}
}
void _debugShowAlert(const char *utf8str) {
void objc_debugShowAlert(const char *utf8str) {
NSString *text = [[NSString alloc] initWithUTF8String: utf8str];
NSAlert *alert = [NSAlert alertWithMessageText:@"Debug Message" defaultButton:@"OK" alternateButton:nil otherButton:nil informativeTextWithFormat:@"%@", text];
[alert runModal];
@ -209,7 +209,7 @@ void _debugShowAlert(const char *utf8str) {
[text release];
}
void _outputDebugString(const char *utf8str) {
void objc_outputDebugString(const char *utf8str) {
NSString *text = [[NSString alloc] initWithUTF8String:utf8str];
NSLog(@"%@", text);
[text release];
@ -219,7 +219,7 @@ PsMacWindowPrivate::~PsMacWindowPrivate() {
delete data;
}
int64 _idleTime() { // taken from https://github.com/trueinteractions/tint/issues/53
int64 objc_idleTime() { // taken from https://github.com/trueinteractions/tint/issues/53
CFMutableDictionaryRef properties = 0;
CFTypeRef obj;
mach_port_t masterPort;
@ -268,3 +268,106 @@ int64 _idleTime() { // taken from https://github.com/trueinteractions/tint/issue
IOObjectRelease(iter);
return (result == err) ? -1 : int64(result);
}
void objc_showInFinder(const char *utf8file, const char *utf8path) {
NSString *file = [[NSString alloc] initWithUTF8String:utf8file], *path = [[NSString alloc] initWithUTF8String:utf8path];
[[NSWorkspace sharedWorkspace] selectFile:file inFileViewerRootedAtPath:path];
[file release];
[path release];
}
@interface NSURL(CompareUrls)
- (BOOL) isEquivalent:(NSURL *)aURL;
@end
@implementation NSURL(CompareUrls)
- (BOOL) isEquivalent:(NSURL *)aURL {
if ([self isEqual:aURL]) return YES;
if ([[self scheme] caseInsensitiveCompare:[aURL scheme]] != NSOrderedSame) return NO;
if ([[self host] caseInsensitiveCompare:[aURL host]] != NSOrderedSame) return NO;
if ([[self path] compare:[aURL path]] != NSOrderedSame) return NO;
if ([[self port] compare:[aURL port]] != NSOrderedSame) return NO;
if ([[self query] compare:[aURL query]] != NSOrderedSame) return NO;
return YES;
}
@end
@interface ChooseApplicationDelegate : NSObject<NSOpenSavePanelDelegate> {
}
- (id) init:(NSArray *)recommendedApps;
- (BOOL) panel:(id)sender shouldEnableURL:(NSURL *)url;
- (void) dealloc;
@end
@implementation ChooseApplicationDelegate {
BOOL onlyRecommended;
NSArray *apps;
}
- (id) init:(NSArray *)recommendedApps {
if (self = [super init]) {
onlyRecommended = YES;
apps = recommendedApps;
}
return self;
}
- (BOOL) panel:(id)sender shouldEnableURL:(NSURL *)url {
NSNumber *isDirectory;
if ([url getResourceValue:&isDirectory forKey:NSURLIsDirectoryKey error:nil] && isDirectory != nil && [isDirectory boolValue]) {
if (onlyRecommended) {
CFStringRef ext = CFURLCopyPathExtension((CFURLRef)url);
NSNumber *isPackage;
if ([url getResourceValue:&isPackage forKey:NSURLIsPackageKey error:nil] && isPackage != nil && [isPackage boolValue]) {
if (apps) {
for (id app in apps) {
if ([(NSURL*)app isEquivalent:url]) {
return YES;
}
}
}
return NO;
}
}
return YES;
}
return NO;
}
- (void) dealloc {
if (apps) {
[apps release];
}
[super dealloc];
}
@end
void objc_openFile(const char *utf8file, bool openwith) {
NSString *file = [[NSString alloc] initWithUTF8String:utf8file];
if (openwith || [[NSWorkspace sharedWorkspace] openFile:file] == NO) {
NSURL *url = [NSURL fileURLWithPath:file];
NSArray *apps = (NSArray*)LSCopyApplicationURLsForURL(CFURLRef(url), kLSRolesAll);
ChooseApplicationDelegate *delegate = [[ChooseApplicationDelegate alloc] init:apps];
NSOpenPanel *openPanel = [NSOpenPanel openPanel];
[openPanel setCanChooseDirectories:NO];
[openPanel setCanChooseFiles:YES];
[openPanel setAllowsMultipleSelection:NO];
[openPanel setDelegate:delegate];
[openPanel setTitle:@"Choose Application"];
[openPanel setMessage:@"Choose an application to open the document \"blabla.png\"."];
if ([openPanel runModal] == NSOKButton) {
NSArray *result = [openPanel URLs];
}
[delegate release];
}
[file release];
}

View File

@ -59,7 +59,6 @@ TitleWidget::TitleWidget(Window *window)
, _maximize(this, window)
, _restore(this, window)
, _close(this, window)
, availWidth(460)
, lastMaximized(!(window->windowState() & Qt::WindowMaximized))
{

View File

@ -84,8 +84,6 @@ private:
RestoreBtn _restore;
CloseBtn _close;
int32 availWidth;
bool lastMaximized;
};