diff --git a/NEWS.md b/NEWS.md index fd30a1c5..e34885a9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -26,6 +26,7 @@ Version 0.6.0 - implement: config shortcuts - implement: handle windows logout message - fix: editor's inproject property not correctly setted (and may cause devcpp to crash when close project) + - implement: print Version 0.5.0 - enhancement: support C++ using type alias; diff --git a/RedPandaIDE/RedPandaIDE.pro b/RedPandaIDE/RedPandaIDE.pro index 92714521..d176f670 100644 --- a/RedPandaIDE/RedPandaIDE.pro +++ b/RedPandaIDE/RedPandaIDE.pro @@ -1,4 +1,4 @@ -QT += core gui +QT += core gui printsupport greaterThan(QT_MAJOR_VERSION, 4): QT += widgets diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index fb24ad56..e3eaae54 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -24,6 +24,9 @@ #include #include #include +#include +#include +#include #include "iconsmanager.h" #include "debugger.h" #include "editorlist.h" @@ -1997,6 +2000,44 @@ void Editor::insertCodeSnippet(const QString &code) } } +void Editor::print() +{ + QPrinter printer; + + QPrintDialog dialog(&printer, this); + dialog.setWindowTitle(tr("Print Document")); +// if (editor->selAvail()) +// dialog.addEnabledOption(QAbstractPrintDialog::PrintSelection); + if (dialog.exec() != QDialog::Accepted) { + return; + } + QTextDocument doc; +// if (editor->selAvail()) { +// doc.setPlainText(editor->selText()); +// } else { + QStringList lst = contents(); + for (int i=0;icodeCompletion().enabled()) @@ -3136,7 +3177,7 @@ void Editor::reformat() return; //we must remove all breakpoints and syntax issues onLinesDeleted(1,lines()->count()); - QByteArray content = lines()->text().toUtf8(); + QByteArray content = text().toUtf8(); QStringList args = pSettings->codeFormatter().getArguments(); QByteArray newContent = runAndGetOutput("astyle.exe", pSettings->dirs().app(), diff --git a/RedPandaIDE/editor.h b/RedPandaIDE/editor.h index 8cf1812f..132dc475 100644 --- a/RedPandaIDE/editor.h +++ b/RedPandaIDE/editor.h @@ -158,6 +158,7 @@ public: void reparseTodo(); void insertString(const QString& value, bool moveCursor); void insertCodeSnippet(const QString& code); + void print(); const PCppParser &parser(); diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 44e49d36..47256628 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -234,6 +234,7 @@ void MainWindow::updateEditorActions() ui->actionRedo->setEnabled(false); ui->actionSave->setEnabled(false); ui->actionSaveAs->setEnabled(false); + ui->actionPrint->setEnabled(false); ui->actionSelectAll->setEnabled(false); ui->actionToggleComment->setEnabled(false); ui->actionUnIndent->setEnabled(false); @@ -266,6 +267,7 @@ void MainWindow::updateEditorActions() ui->actionUndo->setEnabled(e->canUndo()); ui->actionSave->setEnabled(e->modified()); ui->actionSaveAs->setEnabled(true); + ui->actionPrint->setEnabled(true); ui->actionSelectAll->setEnabled(e->lines()->count()>0); ui->actionToggleComment->setEnabled(!e->readOnly() && e->lines()->count()>0); ui->actionUnIndent->setEnabled(!e->readOnly() && e->lines()->count()>0); @@ -891,10 +893,10 @@ void MainWindow::checkSyntaxInBack(Editor *e) ui->tableIssues->clearIssues(); CompileTarget target =getCompileTarget(); if (target ==CompileTarget::Project) { - mCompilerManager->checkSyntax(e->filename(),e->lines()->text(), + mCompilerManager->checkSyntax(e->filename(),e->text(), e->fileEncoding() == ENCODING_ASCII, mProject); } else { - mCompilerManager->checkSyntax(e->filename(),e->lines()->text(), + mCompilerManager->checkSyntax(e->filename(),e->text(), e->fileEncoding() == ENCODING_ASCII, nullptr); } // if not PrepareForCompile(cttStdin,True) then begin @@ -4108,3 +4110,12 @@ void MainWindow::on_btnCancelReplace_clicked() { showSearchReplacePanel(false); } + +void MainWindow::on_actionPrint_triggered() +{ + Editor * editor = mEditorList->getEditor(); + if (!editor) + return; + editor->print(); +} + diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h index c75ff16b..064e6e6d 100644 --- a/RedPandaIDE/mainwindow.h +++ b/RedPandaIDE/mainwindow.h @@ -383,6 +383,8 @@ private slots: void on_btnCancelReplace_clicked(); + void on_actionPrint_triggered(); + private: Ui::MainWindow *ui; EditorList *mEditorList; diff --git a/RedPandaIDE/mainwindow.ui b/RedPandaIDE/mainwindow.ui index 4a32306e..4303e27a 100644 --- a/RedPandaIDE/mainwindow.ui +++ b/RedPandaIDE/mainwindow.ui @@ -854,6 +854,8 @@ + + @@ -1808,6 +1810,18 @@ Shift+F6 + + + + :/icons/images/newlook24/055-package.png:/icons/images/newlook24/055-package.png + + + Print... + + + Ctrl+P + + diff --git a/RedPandaIDE/qsynedit/SynEdit.cpp b/RedPandaIDE/qsynedit/SynEdit.cpp index 3ee520d1..e24f8cef 100644 --- a/RedPandaIDE/qsynedit/SynEdit.cpp +++ b/RedPandaIDE/qsynedit/SynEdit.cpp @@ -538,6 +538,12 @@ QStringList SynEdit::contents() return lines()->contents(); } +QString SynEdit::text() +{ + QMutexLocker locker(&mMutex); + return lines()->text(); +} + bool SynEdit::getPositionOfMouse(BufferCoord &aPos) { QPoint point = QCursor::pos(); @@ -4147,7 +4153,7 @@ void SynEdit::setHighlighter(const PSynHighlighter &highlighter) invalidate(); } -PSynEditStringList SynEdit::lines() const +const PSynEditStringList& SynEdit::lines() const { return mLines; } diff --git a/RedPandaIDE/qsynedit/SynEdit.h b/RedPandaIDE/qsynedit/SynEdit.h index f6ede3b6..94be52bb 100644 --- a/RedPandaIDE/qsynedit/SynEdit.h +++ b/RedPandaIDE/qsynedit/SynEdit.h @@ -258,6 +258,7 @@ public: virtual BufferCoord getMatchingBracketEx(BufferCoord APoint); QStringList contents(); + QString text(); bool getPositionOfMouse(BufferCoord& aPos); bool getLineOfMouse(int& line); @@ -309,7 +310,7 @@ public: QString lineText() const; void setLineText(const QString s); - PSynEditStringList lines() const; + const PSynEditStringList& lines() const; bool empty(); SynSelectionMode selectionMode() const; diff --git a/RedPandaIDE/qsynedit/TextBuffer.cpp b/RedPandaIDE/qsynedit/TextBuffer.cpp index 14e4dd14..c69d96a2 100644 --- a/RedPandaIDE/qsynedit/TextBuffer.cpp +++ b/RedPandaIDE/qsynedit/TextBuffer.cpp @@ -25,7 +25,7 @@ static void ListIndexOutOfBounds(int index) { -int SynEditStringList::parenthesisLevels(int Index) +int SynEditStringList::parenthesisLevels(int Index) const { if (Index>=0 && Index < mList.size()) { return mList[Index]->fRange.parenthesisLevel; @@ -33,7 +33,7 @@ int SynEditStringList::parenthesisLevels(int Index) return 0; } -int SynEditStringList::bracketLevels(int Index) +int SynEditStringList::bracketLevels(int Index) const { if (Index>=0 && Index < mList.size()) { return mList[Index]->fRange.bracketLevel; @@ -41,7 +41,7 @@ int SynEditStringList::bracketLevels(int Index) return 0; } -int SynEditStringList::braceLevels(int Index) +int SynEditStringList::braceLevels(int Index) const { if (Index>=0 && Index < mList.size()) { return mList[Index]->fRange.braceLevel; @@ -71,7 +71,7 @@ int SynEditStringList::lineColumns(int Index) return 0; } -int SynEditStringList::leftBraces(int Index) +int SynEditStringList::leftBraces(int Index) const { if (Index>=0 && Index < mList.size()) { return mList[Index]->fLeftBraces; @@ -79,7 +79,7 @@ int SynEditStringList::leftBraces(int Index) return 0; } -int SynEditStringList::rightBraces(int Index) +int SynEditStringList::rightBraces(int Index) const { if (Index>=0 && Index < mList.size()) { return mList[Index]->fRightBraces; @@ -87,8 +87,7 @@ int SynEditStringList::rightBraces(int Index) return 0; } -int SynEditStringList::lengthOfLongestLine() -{ +int SynEditStringList::lengthOfLongestLine() { if (mIndexOfLongestLine < 0) { int MaxLen = -1; mIndexOfLongestLine = -1; @@ -108,7 +107,7 @@ int SynEditStringList::lengthOfLongestLine() return 0; } -QString SynEditStringList::lineBreak() +QString SynEditStringList::lineBreak() const { switch(mFileEndingType) { case FileEndingType::Linux: @@ -121,7 +120,7 @@ QString SynEditStringList::lineBreak() return "\n"; } -const SynRangeState& SynEditStringList::ranges(int Index) +const SynRangeState& SynEditStringList::ranges(int Index) const { if (Index>=0 && Index < mList.size()) { return mList[Index]->fRange; @@ -178,7 +177,7 @@ void SynEditStringList::setRange(int Index, const SynRangeState& ARange, int ALe endUpdate(); } -QString SynEditStringList::getString(int Index) +QString SynEditStringList::getString(int Index) const { if (Index<0 || Index>=mList.count()) { return QString(); @@ -186,12 +185,12 @@ QString SynEditStringList::getString(int Index) return mList[Index]->fString; } -int SynEditStringList::count() +int SynEditStringList::count() const { return mList.count(); } -void *SynEditStringList::getObject(int Index) +void *SynEditStringList::getObject(int Index) const { if (Index<0 || Index>=mList.count()) { return nullptr; @@ -199,7 +198,7 @@ void *SynEditStringList::getObject(int Index) return mList[Index]->fObject; } -QString SynEditStringList::text() +QString SynEditStringList::text() const { return getTextStr(); } @@ -227,7 +226,7 @@ void SynEditStringList::setContents(const QStringList &text) } } -QStringList SynEditStringList::contents() +QStringList SynEditStringList::contents() const { QStringList Result; SynEditStringRecList list = mList; @@ -371,7 +370,7 @@ void SynEditStringList::deleteAt(int Index) endUpdate(); } -QString SynEditStringList::getTextStr() +QString SynEditStringList::getTextStr() const { QString result; for (int i=0;icode = ui->editCode->lines()->text(); + snippet->code = ui->editCode->text(); setSettingsChanged(); }); connect(ui->tblSnippets->selectionModel(), &QItemSelectionModel::currentChanged,