- 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.
This commit is contained in:
Roy Qu 2023-03-23 22:33:04 +08:00
parent 0fdac532b2
commit 0730aa6c22
7 changed files with 102 additions and 41 deletions

View File

@ -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

View File

@ -2708,6 +2708,7 @@ bool Editor::handleBraceCompletion()
setSelText(text);
processCommand(QSynedit::EditCommand::InsertLine);
}
processCommand(QSynedit::EditCommand::Char,'}');
if (
( (s.startsWith("struct")

View File

@ -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));
// }
}
}

View File

@ -12,6 +12,7 @@
#include "compiler/executablerunner.h"
#include <QComboBox>
#ifdef Q_OS_WIN
#include <QDesktopServices>
#include <windows.h>
#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));
}
}

View File

@ -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,

View File

@ -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

View File

@ -472,6 +472,7 @@ protected:
protected:
void doSelectLine();
private:
BufferCoord ensureBufferCoordValid(const BufferCoord& coord);
void beginEditingWithoutUndo();
void endEditingWithoutUndo();
void clearAreaList(EditingAreaList areaList);