mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-07 23:53:58 +02:00
Added new touchbar to MainWindow.
This commit is contained in:
parent
7cc55e24c0
commit
b95f5071a4
2 changed files with 43 additions and 26 deletions
|
@ -92,11 +92,9 @@ protected:
|
||||||
private:
|
private:
|
||||||
friend class Private;
|
friend class Private;
|
||||||
|
|
||||||
void initTouchBar();
|
|
||||||
void hideAndDeactivate();
|
void hideAndDeactivate();
|
||||||
void updateTitleCounter();
|
void updateTitleCounter();
|
||||||
void updateIconCounters();
|
void updateIconCounters();
|
||||||
void destroyCurrentTouchBar();
|
|
||||||
|
|
||||||
std::unique_ptr<Private> _private;
|
std::unique_ptr<Private> _private;
|
||||||
|
|
||||||
|
@ -105,6 +103,8 @@ private:
|
||||||
|
|
||||||
base::Timer _hideAfterFullScreenTimer;
|
base::Timer _hideAfterFullScreenTimer;
|
||||||
|
|
||||||
|
rpl::variable<bool> _canApplyMarkdown;
|
||||||
|
|
||||||
QMenuBar psMainMenu;
|
QMenuBar psMainMenu;
|
||||||
QAction *psLogout = nullptr;
|
QAction *psLogout = nullptr;
|
||||||
QAction *psUndo = nullptr;
|
QAction *psUndo = nullptr;
|
||||||
|
|
|
@ -26,6 +26,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "window/window_session_controller.h"
|
#include "window/window_session_controller.h"
|
||||||
#include "window/window_controller.h"
|
#include "window/window_controller.h"
|
||||||
#include "window/themes/window_theme.h"
|
#include "window/themes/window_theme.h"
|
||||||
|
#include "platform/mac/touchbar/mac_touchbar_manager.h"
|
||||||
#include "platform/platform_notifications_manager.h"
|
#include "platform/platform_notifications_manager.h"
|
||||||
#include "base/platform/base_platform_info.h"
|
#include "base/platform/base_platform_info.h"
|
||||||
#include "boxes/peer_list_controllers.h"
|
#include "boxes/peer_list_controllers.h"
|
||||||
|
@ -130,6 +131,10 @@ public:
|
||||||
explicit Private(not_null<MainWindow*> window);
|
explicit Private(not_null<MainWindow*> window);
|
||||||
|
|
||||||
void setNativeWindow(NSWindow *window, NSView *view);
|
void setNativeWindow(NSWindow *window, NSView *view);
|
||||||
|
void initTouchBar(
|
||||||
|
NSWindow *window,
|
||||||
|
not_null<Window::Controller*> controller,
|
||||||
|
rpl::producer<bool> canApplyMarkdown);
|
||||||
void setWindowBadge(const QString &str);
|
void setWindowBadge(const QString &str);
|
||||||
void setWindowTitle(const QString &str);
|
void setWindowTitle(const QString &str);
|
||||||
void updateNativeTitle();
|
void updateNativeTitle();
|
||||||
|
@ -281,6 +286,27 @@ void MainWindow::Private::setNativeWindow(NSWindow *window, NSView *view) {
|
||||||
initCustomTitle();
|
initCustomTitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::Private::initTouchBar(
|
||||||
|
NSWindow *window,
|
||||||
|
not_null<Window::Controller*> controller,
|
||||||
|
rpl::producer<bool> canApplyMarkdown) {
|
||||||
|
#ifndef OS_OSX
|
||||||
|
if (!IsMac10_13OrGreater()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
[NSApplication sharedApplication]
|
||||||
|
.automaticCustomizeTouchBarMenuItemEnabled = true;
|
||||||
|
|
||||||
|
[window
|
||||||
|
performSelectorOnMainThread:@selector(setTouchBar:)
|
||||||
|
withObject:[[[RootTouchBar alloc]
|
||||||
|
init:std::move(canApplyMarkdown)
|
||||||
|
controller:controller
|
||||||
|
domain:(&Core::App().domain())] autorelease]
|
||||||
|
waitUntilDone:true];
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::Private::initCustomTitle() {
|
void MainWindow::Private::initCustomTitle() {
|
||||||
#ifndef OS_MAC_OLD
|
#ifndef OS_MAC_OLD
|
||||||
if (![_nativeWindow respondsToSelector:@selector(contentLayoutRect)]
|
if (![_nativeWindow respondsToSelector:@selector(contentLayoutRect)]
|
||||||
|
@ -468,18 +494,6 @@ MainWindow::MainWindow(not_null<Window::Controller*> controller)
|
||||||
_private->updateNativeTitle();
|
_private->updateNativeTitle();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
initTouchBar();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::initTouchBar() {
|
|
||||||
#ifndef OS_OSX
|
|
||||||
#endif // OS_OSX
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::destroyCurrentTouchBar() {
|
|
||||||
#ifndef OS_OSX
|
|
||||||
#endif // OS_OSX
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::closeWithoutDestroy() {
|
void MainWindow::closeWithoutDestroy() {
|
||||||
|
@ -509,6 +523,10 @@ void MainWindow::initHook() {
|
||||||
if (auto view = reinterpret_cast<NSView*>(winId())) {
|
if (auto view = reinterpret_cast<NSView*>(winId())) {
|
||||||
if (auto window = [view window]) {
|
if (auto window = [view window]) {
|
||||||
_private->setNativeWindow(window, view);
|
_private->setNativeWindow(window, view);
|
||||||
|
_private->initTouchBar(
|
||||||
|
window,
|
||||||
|
&controller(),
|
||||||
|
_canApplyMarkdown.changes());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -779,7 +797,7 @@ void MainWindow::updateGlobalMenuHook() {
|
||||||
auto focused = QApplication::focusWidget();
|
auto focused = QApplication::focusWidget();
|
||||||
bool canUndo = false, canRedo = false, canCut = false, canCopy = false, canPaste = false, canDelete = false, canSelectAll = false;
|
bool canUndo = false, canRedo = false, canCut = false, canCopy = false, canPaste = false, canDelete = false, canSelectAll = false;
|
||||||
auto clipboardHasText = _private->clipboardHasText();
|
auto clipboardHasText = _private->clipboardHasText();
|
||||||
auto showTouchBarItem = false;
|
auto canApplyMarkdown = false;
|
||||||
if (auto edit = qobject_cast<QLineEdit*>(focused)) {
|
if (auto edit = qobject_cast<QLineEdit*>(focused)) {
|
||||||
canCut = canCopy = canDelete = edit->hasSelectedText();
|
canCut = canCopy = canDelete = edit->hasSelectedText();
|
||||||
canSelectAll = !edit->text().isEmpty();
|
canSelectAll = !edit->text().isEmpty();
|
||||||
|
@ -793,8 +811,9 @@ void MainWindow::updateGlobalMenuHook() {
|
||||||
canRedo = edit->document()->isRedoAvailable();
|
canRedo = edit->document()->isRedoAvailable();
|
||||||
canPaste = clipboardHasText;
|
canPaste = clipboardHasText;
|
||||||
if (canCopy) {
|
if (canCopy) {
|
||||||
if (const auto inputField = qobject_cast<Ui::InputField*>(focused->parentWidget())) {
|
if (const auto inputField = qobject_cast<Ui::InputField*>(
|
||||||
showTouchBarItem = inputField->isMarkdownEnabled();
|
focused->parentWidget())) {
|
||||||
|
canApplyMarkdown = inputField->isMarkdownEnabled();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (auto list = qobject_cast<HistoryInner*>(focused)) {
|
} else if (auto list = qobject_cast<HistoryInner*>(focused)) {
|
||||||
|
@ -802,8 +821,7 @@ void MainWindow::updateGlobalMenuHook() {
|
||||||
canDelete = list->canDeleteSelected();
|
canDelete = list->canDeleteSelected();
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef OS_OSX
|
_canApplyMarkdown = canApplyMarkdown;
|
||||||
#endif // OS_OSX
|
|
||||||
|
|
||||||
App::wnd()->updateIsActive();
|
App::wnd()->updateIsActive();
|
||||||
const auto logged = (sessionController() != nullptr);
|
const auto logged = (sessionController() != nullptr);
|
||||||
|
@ -823,12 +841,12 @@ void MainWindow::updateGlobalMenuHook() {
|
||||||
ForceDisabled(psNewChannel, inactive || support);
|
ForceDisabled(psNewChannel, inactive || support);
|
||||||
ForceDisabled(psShowTelegram, App::wnd()->isActive());
|
ForceDisabled(psShowTelegram, App::wnd()->isActive());
|
||||||
|
|
||||||
ForceDisabled(psBold, !showTouchBarItem);
|
ForceDisabled(psBold, !canApplyMarkdown);
|
||||||
ForceDisabled(psItalic, !showTouchBarItem);
|
ForceDisabled(psItalic, !canApplyMarkdown);
|
||||||
ForceDisabled(psUnderline, !showTouchBarItem);
|
ForceDisabled(psUnderline, !canApplyMarkdown);
|
||||||
ForceDisabled(psStrikeOut, !showTouchBarItem);
|
ForceDisabled(psStrikeOut, !canApplyMarkdown);
|
||||||
ForceDisabled(psMonospace, !showTouchBarItem);
|
ForceDisabled(psMonospace, !canApplyMarkdown);
|
||||||
ForceDisabled(psClearFormat, !showTouchBarItem);
|
ForceDisabled(psClearFormat, !canApplyMarkdown);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MainWindow::psFilterNativeEvent(void *event) {
|
bool MainWindow::psFilterNativeEvent(void *event) {
|
||||||
|
@ -846,7 +864,6 @@ bool MainWindow::eventFilter(QObject *obj, QEvent *evt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow() {
|
MainWindow::~MainWindow() {
|
||||||
destroyCurrentTouchBar();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
Loading…
Add table
Reference in a new issue