mirror of https://github.com/procxx/kepka.git
Add context menu to filters side bar.
This commit is contained in:
parent
ae7529004d
commit
12b18829f0
|
@ -2282,6 +2282,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
"lng_filters_type_no_read" = "Read";
|
||||
"lng_filters_icon_header" = "Choose icon";
|
||||
"lng_filters_error_pinned_max" = "Sorry, you can't pin any more chats to the top.";
|
||||
"lng_filters_context_edit" = "Edit Folder";
|
||||
"lng_filters_context_remove" = "Remove";
|
||||
"lng_filters_remove_sure" = "This will remove the folder, your chats will not be deleted.";
|
||||
"lng_filters_remove_yes" = "Remove";
|
||||
|
||||
// Wnd specific
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "main/main_session.h"
|
||||
#include "window/window_session_controller.h"
|
||||
#include "window/window_controller.h"
|
||||
#include "apiwrap.h"
|
||||
#include "styles/style_settings.h"
|
||||
#include "styles/style_boxes.h"
|
||||
#include "styles/style_layers.h"
|
||||
|
@ -639,4 +640,34 @@ void EditFilterBox(
|
|||
creating ? tr::lng_filters_create_button() : tr::lng_settings_save(),
|
||||
save);
|
||||
box->addButton(tr::lng_cancel(), [=] { box->closeBox(); });
|
||||
}
|
||||
}
|
||||
|
||||
void EditExistingFilter(
|
||||
not_null<Window::SessionController*> window,
|
||||
FilterId id) {
|
||||
const auto session = &window->session();
|
||||
const auto &list = session->data().chatsFilters().list();
|
||||
const auto i = ranges::find(list, id, &Data::ChatFilter::id);
|
||||
if (i == end(list)) {
|
||||
return;
|
||||
}
|
||||
const auto doneCallback = [=](const Data::ChatFilter &result) {
|
||||
Expects(id == result.id());
|
||||
|
||||
const auto tl = result.tl();
|
||||
session->data().chatsFilters().apply(MTP_updateDialogFilter(
|
||||
MTP_flags(MTPDupdateDialogFilter::Flag::f_filter),
|
||||
MTP_int(id),
|
||||
tl));
|
||||
session->api().request(MTPmessages_UpdateDialogFilter(
|
||||
MTP_flags(MTPmessages_UpdateDialogFilter::Flag::f_filter),
|
||||
MTP_int(id),
|
||||
tl
|
||||
)).send();
|
||||
};
|
||||
window->window().show(Box(
|
||||
EditFilterBox,
|
||||
window,
|
||||
*i,
|
||||
crl::guard(session, doneCallback)));
|
||||
}
|
||||
|
|
|
@ -7,9 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
*/
|
||||
#pragma once
|
||||
|
||||
namespace Ui {
|
||||
class GenericBox;
|
||||
} // namespace Ui
|
||||
#include "ui/layers/generic_box.h"
|
||||
|
||||
namespace Window {
|
||||
class SessionController;
|
||||
|
@ -24,3 +22,7 @@ void EditFilterBox(
|
|||
not_null<Window::SessionController*> window,
|
||||
const Data::ChatFilter &filter,
|
||||
Fn<void(const Data::ChatFilter &)> doneCallback);
|
||||
|
||||
void EditExistingFilter(
|
||||
not_null<Window::SessionController*> window,
|
||||
FilterId id);
|
||||
|
|
|
@ -16,8 +16,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "lang/lang_keys.h"
|
||||
#include "ui/filter_icons.h"
|
||||
#include "ui/wrap/vertical_layout_reorder.h"
|
||||
#include "ui/widgets/popup_menu.h"
|
||||
#include "boxes/confirm_box.h"
|
||||
#include "boxes/filters/edit_filter_box.h"
|
||||
#include "settings/settings_common.h"
|
||||
#include "api/api_chat_filters.h"
|
||||
#include "apiwrap.h"
|
||||
#include "styles/style_widgets.h"
|
||||
#include "styles/style_window.h"
|
||||
|
||||
|
@ -203,9 +207,60 @@ base::unique_qptr<Ui::SideBarButton> FiltersMenu::prepareButton(
|
|||
}
|
||||
}
|
||||
});
|
||||
if (id > 0) {
|
||||
raw->events(
|
||||
) | rpl::filter([=](not_null<QEvent*> e) {
|
||||
return e->type() == QEvent::ContextMenu;
|
||||
}) | rpl::start_with_next([=] {
|
||||
showMenu(QCursor::pos(), id);
|
||||
}, raw->lifetime());
|
||||
}
|
||||
return button;
|
||||
}
|
||||
|
||||
void FiltersMenu::showMenu(QPoint position, FilterId id) {
|
||||
if (_popupMenu) {
|
||||
_popupMenu = nullptr;
|
||||
return;
|
||||
}
|
||||
const auto i = _filters.find(id);
|
||||
if (i == end(_filters)) {
|
||||
return;
|
||||
}
|
||||
_popupMenu = base::make_unique_q<Ui::PopupMenu>(i->second.get());
|
||||
_popupMenu->addAction(
|
||||
tr::lng_filters_context_edit(tr::now),
|
||||
crl::guard(&_outer, [=] { showEditBox(id); }));
|
||||
_popupMenu->addAction(
|
||||
tr::lng_filters_context_remove(tr::now),
|
||||
crl::guard(&_outer, [=] { showRemoveBox(id); }));
|
||||
_popupMenu->popup(position);
|
||||
}
|
||||
|
||||
void FiltersMenu::showEditBox(FilterId id) {
|
||||
EditExistingFilter(_session, id);
|
||||
}
|
||||
|
||||
void FiltersMenu::showRemoveBox(FilterId id) {
|
||||
const auto box = std::make_shared<QPointer<Ui::BoxContent>>();
|
||||
*box = _session->window().show(Box<ConfirmBox>(
|
||||
tr::lng_filters_remove_sure(tr::now),
|
||||
tr::lng_filters_remove_yes(tr::now),
|
||||
[=] { (*box)->closeBox(); remove(id); }));
|
||||
}
|
||||
|
||||
void FiltersMenu::remove(FilterId id) {
|
||||
_session->session().data().chatsFilters().apply(MTP_updateDialogFilter(
|
||||
MTP_flags(MTPDupdateDialogFilter::Flag(0)),
|
||||
MTP_int(id),
|
||||
MTPDialogFilter()));
|
||||
_session->session().api().request(MTPmessages_UpdateDialogFilter(
|
||||
MTP_flags(MTPmessages_UpdateDialogFilter::Flag(0)),
|
||||
MTP_int(id),
|
||||
MTPDialogFilter()
|
||||
)).send();
|
||||
}
|
||||
|
||||
void FiltersMenu::applyReorder(
|
||||
not_null<Ui::RpWidget*> widget,
|
||||
int oldPosition,
|
||||
|
|
|
@ -14,8 +14,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
namespace Ui {
|
||||
class VerticalLayoutReorder;
|
||||
enum class FilterIcon : uchar;
|
||||
class PopupMenu;
|
||||
} // namespace Ui
|
||||
|
||||
namespace Data {
|
||||
class ChatFilter;
|
||||
} // namespace Data
|
||||
|
||||
namespace Window {
|
||||
|
||||
class SessionController;
|
||||
|
@ -40,6 +45,10 @@ private:
|
|||
FilterId id,
|
||||
const QString &title,
|
||||
Ui::FilterIcon icon);
|
||||
void showMenu(QPoint position, FilterId id);
|
||||
void showEditBox(FilterId id);
|
||||
void showRemoveBox(FilterId id);
|
||||
void remove(FilterId id);
|
||||
|
||||
const not_null<SessionController*> _session;
|
||||
const not_null<Ui::RpWidget*> _parent;
|
||||
|
@ -57,6 +66,8 @@ private:
|
|||
bool _ignoreRefresh = false;
|
||||
bool _waitingSuggested = false;
|
||||
|
||||
base::unique_qptr<Ui::PopupMenu> _popupMenu;
|
||||
|
||||
};
|
||||
|
||||
} // namespace Window
|
||||
|
|
Loading…
Reference in New Issue