2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2016-03-18 07:55:01 +01:00
|
|
|
#pragma once
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
#include "texteditor_global.h"
|
|
|
|
|
|
2020-06-26 13:59:38 +02:00
|
|
|
#include <utils/id.h>
|
2020-06-17 09:14:47 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QObject>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2017-05-08 13:52:34 +02:00
|
|
|
#include <functional>
|
|
|
|
|
|
2015-02-26 13:22:35 +01:00
|
|
|
namespace Core {
|
|
|
|
|
class IEditor;
|
|
|
|
|
}
|
2011-08-18 14:23:06 +02:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
namespace TextEditor {
|
2014-09-26 11:37:54 +02:00
|
|
|
class TextEditorWidget;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2014-07-01 14:26:55 +02:00
|
|
|
namespace Internal { class TextEditorActionHandlerPrivate; }
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
// Redirects slots from global actions to the respective editor.
|
|
|
|
|
|
2020-02-05 17:51:41 +01:00
|
|
|
class TEXTEDITOR_EXPORT TextEditorActionHandler final
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2020-02-05 17:51:41 +01:00
|
|
|
TextEditorActionHandler(const TextEditorActionHandler &) = delete;
|
|
|
|
|
TextEditorActionHandler &operator=(const TextEditorActionHandler &) = delete;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
enum OptionalActionsMask {
|
|
|
|
|
None = 0,
|
|
|
|
|
Format = 1,
|
|
|
|
|
UnCommentSelection = 2,
|
2012-03-27 23:18:46 +04:00
|
|
|
UnCollapseAll = 4,
|
|
|
|
|
FollowSymbolUnderCursor = 8,
|
2023-09-05 11:14:10 +02:00
|
|
|
FollowTypeUnderCursor = 16,
|
|
|
|
|
JumpToFileUnderCursor = 32,
|
|
|
|
|
RenameSymbol = 64,
|
|
|
|
|
FindUsage = 128,
|
|
|
|
|
CallHierarchy = 256
|
2008-12-02 12:01:29 +01:00
|
|
|
};
|
2017-05-08 13:52:34 +02:00
|
|
|
using TextEditorWidgetResolver = std::function<TextEditorWidget *(Core::IEditor *)>;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2020-06-26 13:59:38 +02:00
|
|
|
TextEditorActionHandler(Utils::Id editorId,
|
|
|
|
|
Utils::Id contextId,
|
2020-02-05 17:51:41 +01:00
|
|
|
uint optionalActions = None,
|
|
|
|
|
const TextEditorWidgetResolver &resolver = {});
|
2011-08-18 14:23:06 +02:00
|
|
|
|
2020-06-17 10:28:27 +02:00
|
|
|
uint optionalActions() const;
|
2020-02-05 17:51:41 +01:00
|
|
|
~TextEditorActionHandler();
|
2013-05-17 16:32:57 +02:00
|
|
|
|
2023-08-29 14:10:21 +02:00
|
|
|
void updateCurrentEditor();
|
2023-08-31 08:50:11 +02:00
|
|
|
void updateActions();
|
|
|
|
|
|
|
|
|
|
using Predicate = std::function<bool(Core::IEditor *editor)>;
|
|
|
|
|
|
|
|
|
|
void setCanUndoCallback(const Predicate &callback);
|
|
|
|
|
void setCanRedoCallback(const Predicate &callback);
|
2023-08-29 14:10:21 +02:00
|
|
|
|
2023-09-26 10:43:33 +02:00
|
|
|
using UnhandledCallback = std::function<void(Utils::Id commandId, Core::IEditor *editor)>;
|
|
|
|
|
void setUnhandledCallback(const UnhandledCallback &callback);
|
|
|
|
|
|
2013-12-10 15:54:20 +01:00
|
|
|
private:
|
2014-07-01 14:26:55 +02:00
|
|
|
Internal::TextEditorActionHandlerPrivate *d;
|
2008-12-02 12:01:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace TextEditor
|