Add an experimental option for "AI Tools" button.

This commit is contained in:
John Preston
2026-04-06 17:00:06 +07:00
parent a17199c7a9
commit 3bbef51448
5 changed files with 23 additions and 29 deletions
@@ -54,6 +54,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/painter.h"
#include "ui/rect.h"
#include "ui/power_saving.h"
#include "ui/controls/compose_ai_button_factory.h"
#include "ui/controls/emoji_button.h"
#include "ui/controls/send_button.h"
#include "ui/controls/send_as_button.h"
@@ -6246,20 +6247,9 @@ bool HistoryWidget::fieldOrDisabledShown() const {
}
bool HistoryWidget::hasEnoughLinesForAi() const {
if (!_history
|| _voiceRecordBar->isActive()
|| session().appConfig().aiComposeStyles().empty()) {
return false;
}
const auto &style = _field->st().style;
const auto lineHeight = style.lineHeight
? style.lineHeight
: style.font->height;
const auto margins = _field->fullTextMargins();
const auto contentHeight = _field->height()
- margins.top()
- margins.bottom();
return contentHeight >= (3 * lineHeight);
return _history
&& !_voiceRecordBar->isActive()
&& Ui::HasEnoughLinesForAi(&session(), _field);
}
void HistoryWidget::updateAiButtonVisibility() {
@@ -92,6 +92,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/widgets/dropdown_menu.h"
#include "ui/widgets/popup_menu.h"
#include "ui/text/format_values.h"
#include "ui/controls/compose_ai_button_factory.h"
#include "ui/controls/emoji_button.h"
#include "ui/controls/send_button.h"
#include "ui/controls/send_as_button.h"
@@ -3640,20 +3641,9 @@ bool ComposeControls::canSendAiComposeDirect() const {
}
bool ComposeControls::hasEnoughLinesForAi() const {
if (!_history
|| _recording.current()
|| session().appConfig().aiComposeStyles().empty()) {
return false;
}
const auto &style = _field->st().style;
const auto lineHeight = style.lineHeight
? style.lineHeight
: style.font->height;
const auto margins = _field->fullTextMargins();
const auto contentHeight = _field->height()
- margins.top()
- margins.bottom();
return contentHeight >= (3 * lineHeight);
return _history
&& !_recording.current()
&& Ui::HasEnoughLinesForAi(&session(), _field);
}
bool ComposeControls::updateBotCommandShown() {
@@ -19,6 +19,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/vertical_list.h"
#include "ui/gl/gl_detection.h"
#include "ui/chat/chat_style_radius.h"
#include "ui/controls/compose_ai_button_factory.h"
#include "base/options.h"
#include "boxes/moderate_messages_box.h"
#include "core/application.h"
@@ -233,6 +234,7 @@ void SetupExperimental(
addToggle(kModerateCommonGroups);
addToggle(kForceComposeSearchOneColumn);
addToggle(ChatHelpers::kOptionUnlimitedRecentStickers);
addToggle(Ui::kOptionHideAiButton);
}
} // namespace
@@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "ui/controls/compose_ai_button_factory.h"
#include "base/options.h"
#include "boxes/compose_ai_box.h"
#include "history/view/controls/history_view_compose_ai_button.h"
#include "lang/lang_keys.h"
@@ -19,10 +20,19 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace Ui {
const char kOptionHideAiButton[] = "hide-ai-button";
base::options::toggle HideAiButtonOption({
.id = kOptionHideAiButton,
.name = "Hide AI button",
.description = "Hide the AI Tools button in message compose fields.",
});
bool HasEnoughLinesForAi(
not_null<Main::Session*> session,
not_null<Ui::InputField*> field) {
if (session->appConfig().aiComposeStyles().empty()) {
if (HideAiButtonOption.value()
|| session->appConfig().aiComposeStyles().empty()) {
return false;
}
const auto &style = field->st().style;
@@ -23,6 +23,8 @@ class ComposeAiButton;
namespace Ui {
extern const char kOptionHideAiButton[];
[[nodiscard]] bool HasEnoughLinesForAi(
not_null<Main::Session*> session,
not_null<Ui::InputField*> field);