- feature: editor title tabbar context menu

This commit is contained in:
royqh1979@gmail.com 2021-09-05 05:01:31 +08:00
parent 097236eb59
commit d232cd85d3
7 changed files with 58 additions and 21 deletions

View File

@ -17,6 +17,7 @@ SOURCES += \
autolinkmanager.cpp \
caretlist.cpp \
codeformatter.cpp \
codetemplate.cpp \
colorscheme.cpp \
compiler/compiler.cpp \
compiler/compilermanager.cpp \
@ -94,6 +95,7 @@ HEADERS += \
autolinkmanager.h \
caretlist.h \
codeformatter.h \
codetemplate.h \
colorscheme.h \
compiler/compiler.h \
compiler/compilermanager.h \

View File

@ -0,0 +1,6 @@
#include "codetemplate.h"
CodeTemplate::CodeTemplate()
{
}

View File

@ -0,0 +1,11 @@
#ifndef CODETEMPLATE_H
#define CODETEMPLATE_H
class CodeTemplate
{
public:
CodeTemplate();
};
#endif // CODETEMPLATE_H

View File

@ -1112,11 +1112,11 @@ void MainWindow::buildContextMenus()
ui->watchView->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->watchView,&QWidget::customContextMenuRequested,
this, &MainWindow::onWatchViewContextMenu);
ui->EditorTabsLeft->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->EditorTabsLeft,&QWidget::customContextMenuRequested,
ui->EditorTabsLeft->tabBar()->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->EditorTabsLeft->tabBar(),&QWidget::customContextMenuRequested,
this, &MainWindow::onEditorTabContextMenu);
ui->EditorTabsRight->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->EditorTabsRight,&QWidget::customContextMenuRequested,
ui->EditorTabsRight->tabBar()->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->EditorTabsRight->tabBar(),&QWidget::customContextMenuRequested,
this, &MainWindow::onEditorTabContextMenu);
}
@ -1208,7 +1208,7 @@ void MainWindow::onEditorContextMenu(const QPoint &pos)
return;
QMenu menu(this);
BufferCoord p;
mContextMenuPos = pos;
mEditorContextMenuPos = pos;
if (editor->GetPositionOfMouse(p)) {
//mouse on editing area
menu.addAction(ui->actionCompile_Run);
@ -1256,7 +1256,21 @@ void MainWindow::onEditorContextMenu(const QPoint &pos)
void MainWindow::onEditorTabContextMenu(const QPoint &pos)
{
int index = ui->EditorTabsLeft->tabBar()->tabAt(pos);
if (index<0)
return;
ui->EditorTabsLeft->setCurrentIndex(index);
QMenu menu(this);
QTabBar* tabBar = ui->EditorTabsLeft->tabBar();
menu.addAction(ui->actionClose);
menu.addAction(ui->actionClose_All);
menu.addSeparator();
menu.addAction(ui->actionOpen_Containing_Folder);
menu.addAction(ui->actionOpen_Terminal);
menu.addSeparator();
menu.addAction(ui->actionFile_Properties);
menu.exec(tabBar->mapToGlobal(pos));
}
void MainWindow::onFileChanged(const QString &path)
@ -2256,7 +2270,7 @@ void MainWindow::on_actionToggle_Breakpoint_triggered()
{
Editor * editor = mEditorList->getEditor();
int line;
if (editor && editor->PointToLine(mContextMenuPos,line))
if (editor && editor->PointToLine(mEditorContextMenuPos,line))
editor->toggleBreakpoint(line);
}
@ -2280,7 +2294,7 @@ void MainWindow::on_actionBreakpoint_property_triggered()
{
Editor * editor = mEditorList->getEditor();
int line;
if (editor && editor->PointToLine(mContextMenuPos,line)) {
if (editor && editor->PointToLine(mEditorContextMenuPos,line)) {
if (editor->hasBreakpoint(line))
editor->modifyBreakpointProperty(line);
}
@ -2292,7 +2306,7 @@ void MainWindow::on_actionGoto_Declaration_triggered()
{
Editor * editor = mEditorList->getEditor();
BufferCoord pos;
if (editor && editor->PointToCharLine(mContextMenuPos,pos)) {
if (editor && editor->PointToCharLine(mEditorContextMenuPos,pos)) {
editor->gotoDeclaration(pos);
}
}
@ -2302,7 +2316,7 @@ void MainWindow::on_actionGoto_Definition_triggered()
{
Editor * editor = mEditorList->getEditor();
BufferCoord pos;
if (editor && editor->PointToCharLine(mContextMenuPos,pos)) {
if (editor && editor->PointToCharLine(mEditorContextMenuPos,pos)) {
editor->gotoDefinition(pos);
}
}
@ -2312,7 +2326,7 @@ void MainWindow::on_actionFind_references_triggered()
{
Editor * editor = mEditorList->getEditor();
BufferCoord pos;
if (editor && editor->PointToCharLine(mContextMenuPos,pos)) {
if (editor && editor->PointToCharLine(mEditorContextMenuPos,pos)) {
CppRefacter refactor;
refactor.findOccurence(editor,pos);
ui->tabMessages->setCurrentWidget(ui->tabSearch);
@ -2348,8 +2362,11 @@ void MainWindow::on_actionOpen_Terminal_triggered()
void MainWindow::on_actionFile_Properties_triggered()
{
FilePropertiesDialog dialog(this);
Editor* editor = mEditorList->getEditor();
if (editor) {
FilePropertiesDialog dialog(editor,this);
dialog.exec();
dialog.setParent(nullptr);
}
}

View File

@ -327,8 +327,7 @@ private:
bool mClosing;
bool mSystemTurnedOff;
QPoint mContextMenuPos;
QPoint mEditorContextMenuPos;
// QWidget interface
protected:

View File

@ -7,8 +7,9 @@
#include <QFileInfo>
FilePropertiesDialog::FilePropertiesDialog(QWidget *parent) :
FilePropertiesDialog::FilePropertiesDialog(Editor* activeEditor,QWidget *parent) :
QDialog(parent),
mActiveEditor(activeEditor),
ui(new Ui::FilePropertiesDialog)
{
ui->setupUi(this);
@ -36,7 +37,7 @@ void FilePropertiesDialog::calcFile(Editor *editor,
for (int i=0;i<editor->lines()->count();i++) {
QString line = editor->lines()->getString(i);
int j=0;
while (j<line.length() && (line[j]=='\t' || line[i]==' '))
while (j<line.length() && (line[j]=='\t' || line[j]==' '))
j++;
QString token;
PSynHighlighterAttribute attr;
@ -67,10 +68,9 @@ void FilePropertiesDialog::calcFile(Editor *editor,
void FilePropertiesDialog::showEvent(QShowEvent *)
{
Editor* activeEditor = pMainWindow->editorList()->getEditor();
for (int i=0;i<pMainWindow->editorList()->pageCount();i++) {
Editor * editor = (*(pMainWindow->editorList()))[i];
if (editor == activeEditor) {
if (editor == mActiveEditor) {
ui->cbFiles->setCurrentIndex(i);
break;
}
@ -120,7 +120,7 @@ void FilePropertiesDialog::on_cbFiles_currentIndexChanged(int index)
} else {
ui->txtFileSize->setText(QString("%1 ").arg(fileSize / 1024.0 / 1024.0 / 1024.0)+tr("GB"));
}
ui->txtFileDate->setText( info.lastModified().toString(Qt::DateFormat::LocaleDate));
ui->txtFileDate->setText( QLocale::system().toString(info.lastModified(), QLocale::LongFormat));
ui->txtProject->setText("-");
ui->txtPath->setText(editor->filename());
ui->txtRelativeToProject->setText("_");

View File

@ -24,8 +24,9 @@ class FilePropertiesDialog : public QDialog
Q_OBJECT
public:
explicit FilePropertiesDialog(QWidget *parent = nullptr);
explicit FilePropertiesDialog(Editor* activeEditor,QWidget *parent = nullptr);
~FilePropertiesDialog();
private:
void calcFile(Editor* editor,
int& totalLines,
@ -35,6 +36,7 @@ private:
int &includeLines);
private:
FilePropertiesModel mModel;
Editor * mActiveEditor;
private:
Ui::FilePropertiesDialog *ui;