- 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: 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: 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. - 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 Red Panda C++ Version 2.18

View File

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

View File

@ -4546,16 +4546,7 @@ void MainWindow::onFilesViewOpenInExplorer()
{ {
QString path = mFileSystemModel.filePath(ui->treeFiles->currentIndex()); QString path = mFileSystemModel.filePath(ui->treeFiles->currentIndex());
if (!path.isEmpty()) { if (!path.isEmpty()) {
QFileInfo info(path); openFileFolderInExplorer(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));
}
} }
} }
@ -6718,12 +6709,13 @@ void MainWindow::on_actionOpen_Containing_Folder_triggered()
{ {
Editor* editor = mEditorList->getEditor(); Editor* editor = mEditorList->getEditor();
if (editor) { if (editor) {
QFileInfo info(editor->filename()); openFileFolderInExplorer(editor->filename());
if (!info.path().isEmpty()) { // QFileInfo info(editor->filename());
QDesktopServices::openUrl( // if (!info.path().isEmpty()) {
QUrl("file:///"+ // QDesktopServices::openUrl(
includeTrailingPathDelimiter(info.path()),QUrl::TolerantMode)); // QUrl("file:///"+
} // includeTrailingPathDelimiter(info.path()),QUrl::TolerantMode));
// }
} }
} }

View File

@ -12,6 +12,7 @@
#include "compiler/executablerunner.h" #include "compiler/executablerunner.h"
#include <QComboBox> #include <QComboBox>
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
#include <QDesktopServices>
#include <windows.h> #include <windows.h>
#endif #endif
@ -540,3 +541,28 @@ void saveComboHistory(QComboBox* cb,const QString& text) {
cb->insertItem(0,s); cb->insertItem(0,s);
cb->setCurrentText(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, bool inheritEnvironment = false,
const QProcessEnvironment& env = QProcessEnvironment() ); const QProcessEnvironment& env = QProcessEnvironment() );
void openFileFolderInExplorer(const QString& path);
void executeFile(const QString& fileName, void executeFile(const QString& fileName,
const QString& params, const QString& params,
const QString& workingDir, const QString& workingDir,

View File

@ -230,24 +230,7 @@ void QSynEdit::setCaretXY(const BufferCoord &value)
void QSynEdit::setCaretXYEx(bool CallEnsureCursorPosVisible, BufferCoord value) void QSynEdit::setCaretXYEx(bool CallEnsureCursorPosVisible, BufferCoord value)
{ {
int nMaxX; value = ensureBufferCoordValid(value);
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);
// if ((value.Char > nMaxX) && (! (mOptions.testFlag(SynEditorOption::eoScrollPastEol)) ) ) // if ((value.Char > nMaxX) && (! (mOptions.testFlag(SynEditorOption::eoScrollPastEol)) ) )
// value.Char = nMaxX; // value.Char = nMaxX;
// if (value.Char < 1) // if (value.Char < 1)
@ -2119,6 +2102,30 @@ void QSynEdit::doSelectLine()
setCaretAndSelection(ptBegin,ptBegin,ptEnd); 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() void QSynEdit::doDuplicateLine()
{ {
if (!mReadOnly && (mDocument->count() > 0)) { if (!mReadOnly && (mDocument->count() > 0)) {
@ -2126,9 +2133,9 @@ void QSynEdit::doDuplicateLine()
if (foldRange && foldRange->collapsed) if (foldRange && foldRange->collapsed)
return; return;
QString s = lineText(); QString s = lineText();
beginEditing();
mDocument->insertLine(mCaretY, lineText()); mDocument->insertLine(mCaretY, lineText());
doLinesInserted(mCaretY + 1, 1); doLinesInserted(mCaretY + 1, 1);
beginEditing();
addCaretToUndo(); addCaretToUndo();
mUndoList->addChange(ChangeReason::LineBreak, mUndoList->addChange(ChangeReason::LineBreak,
BufferCoord{s.length()+1,mCaretY}, BufferCoord{s.length()+1,mCaretY},
@ -6352,12 +6359,12 @@ void QSynEdit::dropEvent(QDropEvent *event)
mDropped = true; mDropped = true;
return; return;
} }
if (coord.line<=0 || coord.line>=mDocument->count()) { // if (coord.line<=0 || coord.line>=mDocument->count()) {
//do nothing if drag out of range // //do nothing if drag out of range
event->acceptProposedAction(); // event->acceptProposedAction();
mDropped = true; // mDropped = true;
return; // return;
} // }
int topLine = mTopLine; int topLine = mTopLine;
int leftChar = mLeftChar; int leftChar = mLeftChar;
@ -6368,6 +6375,21 @@ void QSynEdit::dropEvent(QDropEvent *event)
addSelectionToUndo(); addSelectionToUndo();
internalSetCaretXY(coord); internalSetCaretXY(coord);
if (event->proposedAction() == Qt::DropAction::CopyAction) { 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 //just copy it
doInsertText(coord,text,mActiveSelectionMode,coord.line,coord.line+text.length()-1); doInsertText(coord,text,mActiveSelectionMode,coord.line,coord.line+text.length()-1);
} else if (event->proposedAction() == Qt::DropAction::MoveAction) { } else if (event->proposedAction() == Qt::DropAction::MoveAction) {
@ -6377,6 +6399,21 @@ void QSynEdit::dropEvent(QDropEvent *event)
//paste to new position //paste to new position
doInsertText(coord,text,mActiveSelectionMode,coord.line,coord.line+text.length()-1); doInsertText(coord,text,mActiveSelectionMode,coord.line,coord.line+text.length()-1);
} else { } 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 //paste to new position
doInsertText(coord,text,mActiveSelectionMode,coord.line,coord.line+text.length()-1); doInsertText(coord,text,mActiveSelectionMode,coord.line,coord.line+text.length()-1);
//delete old //delete old

View File

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