Skip to content

Commit

Permalink
feat: [editor] Implement a feature of cursor position back or forward
Browse files Browse the repository at this point in the history
as title

Log: new feature
  • Loading branch information
Kakueeen authored and deepin-mozart committed Jan 19, 2024
1 parent ce66c64 commit 94c3edc
Show file tree
Hide file tree
Showing 15 changed files with 221 additions and 85 deletions.
2 changes: 2 additions & 0 deletions src/common/util/eventdefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ OPI_OBJECT(debugger,
OPI_OBJECT(editor,
// in
OPI_INTERFACE(openFile, "filePath")
OPI_INTERFACE(back)
OPI_INTERFACE(forward)
OPI_INTERFACE(jumpToLine, "filePath", "line")
OPI_INTERFACE(openFileWithKey, "workspace", "language", "filePath")
OPI_INTERFACE(jumpToLineWithKey, "workspace", "language", "filePath", "line")
Expand Down
27 changes: 27 additions & 0 deletions src/plugins/codeeditor/codeeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ void CodeEditor::initialize()
bool CodeEditor::start()
{
qInfo() << __FUNCTION__;

initActions();
auto &ctx = dpfInstance.serviceContext();
WindowService *windowService = ctx.service<WindowService>(WindowService::name());

Expand Down Expand Up @@ -139,3 +141,28 @@ dpf::Plugin::ShutdownFlag CodeEditor::stop()
qInfo() << __FUNCTION__;
return Sync;
}

void CodeEditor::initActions()
{
auto &ctx = dpfInstance.serviceContext();
WindowService *windowService = ctx.service<WindowService>(WindowService::name());
if (!windowService)
return;

QAction *backAction = new QAction(this);
QAction *forwardAction = new QAction(this);
ActionManager::getInstance()->registerAction(backAction, "Editor.back",
tr("Back"), QKeySequence(Qt::Modifier::ALT | Qt::Key_Left));
ActionManager::getInstance()->registerAction(forwardAction, "Editor.forward",
tr("Forward"), QKeySequence(Qt::Modifier::ALT | Qt::Key_Right));

windowService->addAction(tr("&Edit"), new AbstractAction(backAction));
windowService->addAction(tr("&Edit"), new AbstractAction(forwardAction));
connect(backAction, &QAction::triggered, [=] {
editor.back();
});

connect(forwardAction, &QAction::triggered, [=] {
editor.forward();
});
}
3 changes: 3 additions & 0 deletions src/plugins/codeeditor/codeeditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ class CodeEditor : public dpf::Plugin
virtual void initialize() override;
virtual bool start() override;
virtual dpf::Plugin::ShutdownFlag stop() override;

private:
void initActions();
};

#endif // COREPLUGIN_H
15 changes: 15 additions & 0 deletions src/plugins/codeeditor/gui/private/tabwidget_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,29 @@ class TabWidgetPrivate : public QObject
{
Q_OBJECT
public:
struct PosRecord
{
int pos = 0;
QString fileName;
};

explicit TabWidgetPrivate(TabWidget *qq);

void initUI();
void initConnection();

TextEditor *currentTextEditor() const;
void changeFocusProxy();
bool processKeyPressEvent(QKeyEvent *event);

void doSave();
void removePositionRecord(const QString &fileName);

public:
void onTabSwitched(const QString &fileName);
void onTabClosed(const QString &fileName);
void onSpliterClicked(Qt::Orientation ori);
void onLinePositionChanged(int line, int index);

public:
TabWidget *q;
Expand All @@ -36,6 +47,10 @@ class TabWidgetPrivate : public QObject
TextEditorManager *editorMng { nullptr };

QHash<QString, int> editorIndexHash;

PosRecord curPosRecord;
QList<PosRecord> prePosRecord;
QList<PosRecord> nextPosRecord;
};

#endif // TABWIDGET_P_H
9 changes: 8 additions & 1 deletion src/plugins/codeeditor/gui/private/texteditor_p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ static constexpr int TAB_DEFAULT_WIDTH = 4;
DGUI_USE_NAMESPACE

TextEditorPrivate::TextEditorPrivate(TextEditor *qq)
: q(qq)
: QObject(qq),
q(qq)
{
init();
initConnection();
}

void TextEditorPrivate::init()
Expand All @@ -34,6 +36,11 @@ void TextEditorPrivate::init()
updateSettings();
}

void TextEditorPrivate::initConnection()
{
connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, &TextEditorPrivate::updateColorTheme);
}

void TextEditorPrivate::initMargins()
{
// Display line number
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/codeeditor/gui/private/texteditor_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

#include "gui/texteditor.h"

class TextEditorPrivate
class TextEditorPrivate : public QObject
{
Q_OBJECT
public:
enum MarkSymbol {
BreakpointSymbol = 0,
Expand Down Expand Up @@ -38,6 +39,7 @@ class TextEditorPrivate
explicit TextEditorPrivate(TextEditor *qq);

void init();
void initConnection();
void initMargins();
void updateColorTheme();
void updateSettings();
Expand Down
8 changes: 5 additions & 3 deletions src/plugins/codeeditor/gui/private/workspacewidget_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ class WorkspaceWidgetPrivate : public QObject
public:
void onSplitRequested(Qt::Orientation ori, const QString &fileName);
void onCloseRequested();
void onOpenFileRequested(const QString &fileName);
void onAddBreakpointRequested(const QString &fileName, int line);
void onRemoveBreakpointRequested(const QString &fileName, int line);
void handleOpenFile(const QString &fileName);
void handleAddBreakpoint(const QString &fileName, int line);
void handleRemoveBreakpoint(const QString &fileName, int line);
void handleBack();
void handleForward();
void onFocusChanged(QWidget *old, QWidget *now);

public:
Expand Down
Loading

0 comments on commit 94c3edc

Please sign in to comment.