diff --git a/NEWS.md b/NEWS.md index 1c2a2241..0da98cef 100644 --- a/NEWS.md +++ b/NEWS.md @@ -5,6 +5,8 @@ Red Panda C++ Version 2.19 - fix: Crash when a project is removed from the disk while it is openned in RedPanda-C++. - fix: The option "Open CPU info dialog when signal received" can't be correctly set in the options dialog's debugger page. - fix: Crash when drag the selection beyond the end of the document. + - enhancement: Drag the selection beyond the end of the document, and move/copy it beyond the last line. + - enhancement: Open Containing folder will auto select the file in windows file explore. Red Panda C++ Version 2.18 diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 0a8ee216..8b91c7ea 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -2708,6 +2708,7 @@ bool Editor::handleBraceCompletion() setSelText(text); processCommand(QSynedit::EditCommand::InsertLine); } + processCommand(QSynedit::EditCommand::Char,'}'); if ( ( (s.startsWith("struct") diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 2aa65a29..39c36cf6 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -4546,16 +4546,7 @@ void MainWindow::onFilesViewOpenInExplorer() { QString path = mFileSystemModel.filePath(ui->treeFiles->currentIndex()); if (!path.isEmpty()) { - QFileInfo info(path); - if (info.isFile()){ - QDesktopServices::openUrl( - QUrl("file:///"+ - includeTrailingPathDelimiter(info.path()),QUrl::TolerantMode)); - } else if (info.isDir()){ - QDesktopServices::openUrl( - QUrl("file:///"+ - includeTrailingPathDelimiter(path),QUrl::TolerantMode)); - } + openFileFolderInExplorer(path); } } @@ -6718,12 +6709,13 @@ void MainWindow::on_actionOpen_Containing_Folder_triggered() { Editor* editor = mEditorList->getEditor(); if (editor) { - QFileInfo info(editor->filename()); - if (!info.path().isEmpty()) { - QDesktopServices::openUrl( - QUrl("file:///"+ - includeTrailingPathDelimiter(info.path()),QUrl::TolerantMode)); - } + openFileFolderInExplorer(editor->filename()); +// QFileInfo info(editor->filename()); +// if (!info.path().isEmpty()) { +// QDesktopServices::openUrl( +// QUrl("file:///"+ +// includeTrailingPathDelimiter(info.path()),QUrl::TolerantMode)); +// } } } diff --git a/RedPandaIDE/utils.cpp b/RedPandaIDE/utils.cpp index 55e5a3b6..fcb28539 100644 --- a/RedPandaIDE/utils.cpp +++ b/RedPandaIDE/utils.cpp @@ -12,6 +12,7 @@ #include "compiler/executablerunner.h" #include #ifdef Q_OS_WIN +#include #include #endif @@ -540,3 +541,28 @@ void saveComboHistory(QComboBox* cb,const QString& text) { cb->insertItem(0,s); cb->setCurrentText(s); } + +void openFileFolderInExplorer(const QString &path) +{ + QFileInfo info(path); + if (info.isFile()){ +#ifdef Q_OS_WIN + QProcess process; + QStringList args; + QString filepath=info.absoluteFilePath().replace("/","\\"); + args.append("/n,"); + args.append("/select,"); + args.append(QString("%1").arg(filepath)); + process.startDetached("explorer.exe",args); +#else + QDesktopServices::openUrl( + QUrl("file:///"+ + includeTrailingPathDelimiter(info.path()),QUrl::TolerantMode)); +#endif + } else if (info.isDir()){ + QDesktopServices::openUrl( + QUrl("file:///"+ + includeTrailingPathDelimiter(path),QUrl::TolerantMode)); + } + +} diff --git a/RedPandaIDE/utils.h b/RedPandaIDE/utils.h index 6986349b..926fcb01 100644 --- a/RedPandaIDE/utils.h +++ b/RedPandaIDE/utils.h @@ -124,6 +124,8 @@ QByteArray runAndGetOutput(const QString& cmd, const QString& workingDir, const bool inheritEnvironment = false, const QProcessEnvironment& env = QProcessEnvironment() ); +void openFileFolderInExplorer(const QString& path); + void executeFile(const QString& fileName, const QString& params, const QString& workingDir, diff --git a/libs/qsynedit/qsynedit/qsynedit.cpp b/libs/qsynedit/qsynedit/qsynedit.cpp index 4beed12c..dca3cee3 100644 --- a/libs/qsynedit/qsynedit/qsynedit.cpp +++ b/libs/qsynedit/qsynedit/qsynedit.cpp @@ -230,24 +230,7 @@ void QSynEdit::setCaretXY(const BufferCoord &value) void QSynEdit::setCaretXYEx(bool CallEnsureCursorPosVisible, BufferCoord value) { - int nMaxX; - if (value.line > mDocument->count()) - value.line = mDocument->count(); - if (mActiveSelectionMode!=SelectionMode::Column) { - if (value.line < 1) { - // this is just to make sure if Lines stringlist should be empty - value.line = 1; - if (!mOptions.testFlag(EditorOption::eoScrollPastEol)) { - nMaxX = 1; - } else { - nMaxX = getDisplayStringAtLine(value.line).length()+1; - } - } else { - nMaxX = getDisplayStringAtLine(value.line).length()+1; - } - value.ch = std::min(value.ch,nMaxX); - } - value.ch = std::max(value.ch,1); + value = ensureBufferCoordValid(value); // if ((value.Char > nMaxX) && (! (mOptions.testFlag(SynEditorOption::eoScrollPastEol)) ) ) // value.Char = nMaxX; // if (value.Char < 1) @@ -2119,6 +2102,30 @@ void QSynEdit::doSelectLine() setCaretAndSelection(ptBegin,ptBegin,ptEnd); } +BufferCoord QSynEdit::ensureBufferCoordValid(const BufferCoord &coord) +{ + int nMaxX; + BufferCoord value = coord; + if (value.line > mDocument->count()) + value.line = mDocument->count(); + if (mActiveSelectionMode!=SelectionMode::Column) { + if (value.line < 1) { + // this is just to make sure if Lines stringlist should be empty + value.line = 1; + if (!mOptions.testFlag(EditorOption::eoScrollPastEol)) { + nMaxX = 1; + } else { + nMaxX = getDisplayStringAtLine(value.line).length()+1; + } + } else { + nMaxX = getDisplayStringAtLine(value.line).length()+1; + } + value.ch = std::min(value.ch,nMaxX); + } + value.ch = std::max(value.ch,1); + return value; +} + void QSynEdit::doDuplicateLine() { if (!mReadOnly && (mDocument->count() > 0)) { @@ -2126,9 +2133,9 @@ void QSynEdit::doDuplicateLine() if (foldRange && foldRange->collapsed) return; QString s = lineText(); + beginEditing(); mDocument->insertLine(mCaretY, lineText()); doLinesInserted(mCaretY + 1, 1); - beginEditing(); addCaretToUndo(); mUndoList->addChange(ChangeReason::LineBreak, BufferCoord{s.length()+1,mCaretY}, @@ -6352,12 +6359,12 @@ void QSynEdit::dropEvent(QDropEvent *event) mDropped = true; return; } - if (coord.line<=0 || coord.line>=mDocument->count()) { - //do nothing if drag out of range - event->acceptProposedAction(); - mDropped = true; - return; - } +// if (coord.line<=0 || coord.line>=mDocument->count()) { +// //do nothing if drag out of range +// event->acceptProposedAction(); +// mDropped = true; +// return; +// } int topLine = mTopLine; int leftChar = mLeftChar; @@ -6368,6 +6375,21 @@ void QSynEdit::dropEvent(QDropEvent *event) addSelectionToUndo(); internalSetCaretXY(coord); if (event->proposedAction() == Qt::DropAction::CopyAction) { + if (coord.line>mDocument->count()) { + int line=mDocument->count(); + QString s=mDocument->getLine(line-1); + beginEditing(); + mDocument->addLine(""); + + mUndoList->addChange(ChangeReason::LineBreak, + BufferCoord{s.length()+1,line}, + BufferCoord{s.length()+1,line}, QStringList(), SelectionMode::Normal); + endEditing(); + coord.line = line+1; + coord.ch=1; + } else { + coord = ensureBufferCoordValid(coord); + } //just copy it doInsertText(coord,text,mActiveSelectionMode,coord.line,coord.line+text.length()-1); } else if (event->proposedAction() == Qt::DropAction::MoveAction) { @@ -6377,6 +6399,21 @@ void QSynEdit::dropEvent(QDropEvent *event) //paste to new position doInsertText(coord,text,mActiveSelectionMode,coord.line,coord.line+text.length()-1); } else { + if (coord.line>mDocument->count()) { + int line=mDocument->count(); + QString s=mDocument->getLine(line-1); + beginEditing(); + mDocument->addLine(""); + + mUndoList->addChange(ChangeReason::LineBreak, + BufferCoord{s.length()+1,line}, + BufferCoord{s.length()+1,line}, QStringList(), SelectionMode::Normal); + endEditing(); + coord.line = line+1; + coord.ch=1; + } else { + coord = ensureBufferCoordValid(coord); + } //paste to new position doInsertText(coord,text,mActiveSelectionMode,coord.line,coord.line+text.length()-1); //delete old diff --git a/libs/qsynedit/qsynedit/qsynedit.h b/libs/qsynedit/qsynedit/qsynedit.h index 2817040c..a1627080 100644 --- a/libs/qsynedit/qsynedit/qsynedit.h +++ b/libs/qsynedit/qsynedit/qsynedit.h @@ -472,6 +472,7 @@ protected: protected: void doSelectLine(); private: + BufferCoord ensureBufferCoordValid(const BufferCoord& coord); void beginEditingWithoutUndo(); void endEditingWithoutUndo(); void clearAreaList(EditingAreaList areaList);