2021-04-06 23:10:57 +08:00
|
|
|
#include "mainwindow.h"
|
|
|
|
#include "ui_mainwindow.h"
|
2021-04-07 21:13:15 +08:00
|
|
|
#include "editorlist.h"
|
2021-04-08 10:29:21 +08:00
|
|
|
#include "editor.h"
|
|
|
|
|
2021-04-09 17:48:25 +08:00
|
|
|
#include <QCloseEvent>
|
2021-04-08 10:29:21 +08:00
|
|
|
#include <QLabel>
|
|
|
|
|
|
|
|
MainWindow* pMainWindow;
|
2021-04-06 23:10:57 +08:00
|
|
|
|
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
|
|
|
: QMainWindow(parent)
|
|
|
|
, ui(new Ui::MainWindow)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2021-04-08 10:29:21 +08:00
|
|
|
// status bar
|
|
|
|
mFileInfoStatus=new QLabel(this);
|
|
|
|
mFileEncodingStatus = new QLabel(this);
|
|
|
|
mFileInfoStatus->setStyleSheet("margin-left:10px; margin-right:10px");
|
|
|
|
mFileEncodingStatus->setStyleSheet("margin-left:10px; margin-right:10px");
|
|
|
|
ui->statusbar->addWidget(mFileInfoStatus);
|
|
|
|
ui->statusbar->addWidget(mFileEncodingStatus);
|
2021-04-07 21:13:15 +08:00
|
|
|
mEditorList = new EditorList(ui->EditorTabsLeft,
|
|
|
|
ui->EditorTabsRight,
|
|
|
|
ui->EditorPanelSplitter,
|
|
|
|
ui->EditorPanel);
|
|
|
|
setupActions();
|
2021-04-07 22:44:08 +08:00
|
|
|
ui->EditorTabsRight->setVisible(false);
|
2021-04-06 23:10:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
MainWindow::~MainWindow()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2021-04-08 10:29:21 +08:00
|
|
|
void MainWindow::updateStatusBarForEncoding() {
|
|
|
|
Editor * editor = mEditorList->getEditor();
|
|
|
|
if (editor!=NULL) {
|
|
|
|
mFileEncodingStatus->setText(editor->fileEncoding());
|
|
|
|
}
|
2021-04-11 13:55:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::updateStatusBarForEditingInfo(int line,int col,int lines,int charCount)
|
|
|
|
{
|
|
|
|
Editor * editor = mEditorList->getEditor();
|
|
|
|
if (editor!=NULL) {
|
|
|
|
mFileInfoStatus->setText(
|
|
|
|
QString(tr("Line: %1 Col: %2 Lines: %3 Chars: %4")).arg(line)
|
|
|
|
.arg(col).arg(lines).arg(charCount));
|
|
|
|
}
|
2021-04-08 10:29:21 +08:00
|
|
|
}
|
|
|
|
|
2021-04-07 21:13:15 +08:00
|
|
|
void MainWindow::setupActions() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::on_actionNew_triggered()
|
|
|
|
{
|
2021-04-08 10:29:21 +08:00
|
|
|
Editor * editor=mEditorList->newEditor("",ENCODING_AUTO_DETECT,false,true);
|
|
|
|
updateStatusBarForEncoding();
|
2021-04-07 21:13:15 +08:00
|
|
|
}
|
2021-04-07 22:44:08 +08:00
|
|
|
|
|
|
|
void MainWindow::on_EditorTabsLeft_tabCloseRequested(int index)
|
|
|
|
{
|
2021-04-08 10:29:21 +08:00
|
|
|
Editor* editor = mEditorList->getEditor(index);
|
|
|
|
mEditorList->closeEditor(editor);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_actionOpen_triggered()
|
|
|
|
{
|
|
|
|
Editor * editor = mEditorList->getEditor();
|
|
|
|
if (editor != NULL) {
|
2021-04-11 12:39:22 +08:00
|
|
|
//editor->save();
|
2021-04-08 10:29:21 +08:00
|
|
|
}
|
2021-04-07 22:44:08 +08:00
|
|
|
}
|
2021-04-09 17:48:25 +08:00
|
|
|
|
|
|
|
void MainWindow::closeEvent(QCloseEvent *event) {
|
|
|
|
if (!mEditorList->closeAll(true)) {
|
|
|
|
event->ignore();
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete mEditorList;
|
|
|
|
event->accept();
|
|
|
|
return;
|
|
|
|
}
|
2021-04-11 12:39:22 +08:00
|
|
|
|
|
|
|
void MainWindow::on_actionSave_triggered()
|
|
|
|
{
|
|
|
|
Editor * editor = mEditorList->getEditor();
|
|
|
|
if (editor != NULL) {
|
|
|
|
editor->save();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_actionSaveAs_triggered()
|
|
|
|
{
|
|
|
|
Editor * editor = mEditorList->getEditor();
|
|
|
|
if (editor != NULL) {
|
|
|
|
editor->saveAs();
|
|
|
|
}
|
|
|
|
}
|