- fix: rename macro doesn't work in project

- fix: can't remove a shortcut
  - enhancement: hide all menu actions in the option dialog's shortcut panel
This commit is contained in:
Roy Qu 2022-06-12 22:54:34 +08:00
parent 2182553fe1
commit 5a31e1dd42
11 changed files with 93 additions and 27 deletions

View File

@ -8,6 +8,8 @@ Red Panda C++ Version 1.1.0
- enhancement: delete in files view's context menu - enhancement: delete in files view's context menu
- change: drag&drop in files view default to move - change: drag&drop in files view default to move
- fix: rename macro doesn't work in project - fix: rename macro doesn't work in project
- fix: can't remove a shortcut
- enhancement: hide all menu actions in the option dialog's shortcut panel
Red Panda C++ Version 1.0.10 Red Panda C++ Version 1.0.10
- fix: modify watch doesn't work - fix: modify watch doesn't work

View File

@ -313,8 +313,18 @@ void CppRefacter::renameSymbolInFile(const QString &filename, const PStatement &
Editor * oldEditor = pMainWindow->editorList()->getOpenedEditorByFilename(filename); Editor * oldEditor = pMainWindow->editorList()->getOpenedEditorByFilename(filename);
if (oldEditor) { if (oldEditor) {
BufferCoord oldXY=oldEditor->caretXY();
int topLine = oldEditor->topLine();
int leftChar = oldEditor->leftChar();
oldEditor->beginUndoBlock();
oldEditor->addLeftTopToUndo();
oldEditor->addCaretToUndo();
oldEditor->selectAll(); oldEditor->selectAll();
oldEditor->setSelText(newContents.join(oldEditor->lineBreak())); oldEditor->setSelText(newContents.join(oldEditor->lineBreak()));
oldEditor->setTopLine(topLine);
oldEditor->setLeftChar(leftChar);
oldEditor->setCaretXY(oldXY);
oldEditor->endUndoBlock();
} else { } else {
QByteArray realEncoding; QByteArray realEncoding;
QFile file(filename); QFile file(filename);

View File

@ -4261,9 +4261,14 @@ void Editor::reformat()
args, args,
content); content);
#endif #endif
if (newContent.isEmpty())
return;
int oldTopLine = topLine(); int oldTopLine = topLine();
BufferCoord mOldCaret = caretXY(); BufferCoord mOldCaret = caretXY();
beginUndoBlock();
addLeftTopToUndo();
addCaretToUndo();
selectAll(); selectAll();
SynEditorOptions oldOptions = getOptions(); SynEditorOptions oldOptions = getOptions();
SynEditorOptions newOptions = oldOptions; SynEditorOptions newOptions = oldOptions;
@ -4273,6 +4278,7 @@ void Editor::reformat()
setCaretXY(mOldCaret); setCaretXY(mOldCaret);
setTopLine(oldTopLine); setTopLine(oldTopLine);
setOptions(oldOptions); setOptions(oldOptions);
endUndoBlock();
reparse(); reparse();
checkSyntaxInBack(); checkSyntaxInBack();
reparseTodo(); reparseTodo();

View File

@ -5334,13 +5334,7 @@ void MainWindow::on_actionReformat_Code_triggered()
{ {
Editor* e = mEditorList->getEditor(); Editor* e = mEditorList->getEditor();
if (e) { if (e) {
BufferCoord oldXY=e->caretXY();
int topLine = e->topLine();
int leftChar = e->leftChar();
e->reformat(); e->reformat();
e->setTopLine(topLine);
e->setLeftChar(leftChar);
e->setCaretXY(oldXY);
e->activate(); e->activate();
} }
} }
@ -6360,13 +6354,8 @@ void MainWindow::on_actionRename_Symbol_triggered()
parser->parseFile(editor->filename(), editor->inProject(), false, false); parser->parseFile(editor->filename(), editor->inProject(), false, false);
} }
CppRefacter refactor; CppRefacter refactor;
BufferCoord oldXY=editor->caretXY();
int topLine = editor->topLine();
int leftChar = editor->leftChar();
refactor.renameSymbol(editor,oldCaretXY,word,newWord); refactor.renameSymbol(editor,oldCaretXY,word,newWord);
editor->setTopLine(topLine);
editor->setLeftChar(leftChar);
editor->setCaretXY(oldXY);
editor->reparse(); editor->reparse();
} }

View File

@ -858,7 +858,7 @@
<enum>QTabWidget::South</enum> <enum>QTabWidget::South</enum>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>3</number> <number>6</number>
</property> </property>
<property name="iconSize"> <property name="iconSize">
<size> <size>

View File

@ -454,6 +454,20 @@ void SynEdit::endUndoBlock()
mUndoList->EndBlock(); mUndoList->EndBlock();
} }
void SynEdit::addCaretToUndo()
{
BufferCoord p=caretXY();
mUndoList->AddChange(SynChangeReason::crCaret,p,p,"", activeSelectionMode());
}
void SynEdit::addLeftTopToUndo()
{
BufferCoord p;
p.Char = leftChar();
p.Line = topLine();
mUndoList->AddChange(SynChangeReason::crLeftTop,p,p,"", activeSelectionMode());
}
void SynEdit::beginUpdate() void SynEdit::beginUpdate()
{ {
incPaintLock(); incPaintLock();
@ -4334,6 +4348,18 @@ void SynEdit::doUndoItem()
Item->changeSelMode()); Item->changeSelMode());
internalSetCaretXY(Item->changeStartPos()); internalSetCaretXY(Item->changeStartPos());
break; break;
case SynChangeReason::crLeftTop:
BufferCoord p;
p.Char = leftChar();
p.Line = topLine();
mRedoList->AddChange(
Item->changeReason(),
p,
p, "",
Item->changeSelMode());
setLeftChar(Item->changeStartPos().Char);
setTopLine(Item->changeStartPos().Line);
break;
case SynChangeReason::crSelection: case SynChangeReason::crSelection:
mRedoList->AddChange( mRedoList->AddChange(
Item->changeReason(), Item->changeReason(),
@ -4609,6 +4635,18 @@ void SynEdit::doRedoItem()
mActiveSelectionMode); mActiveSelectionMode);
internalSetCaretXY(Item->changeStartPos()); internalSetCaretXY(Item->changeStartPos());
break; break;
case SynChangeReason::crLeftTop:
BufferCoord p;
p.Char = leftChar();
p.Line = topLine();
mUndoList->AddChange(
Item->changeReason(),
p,
p, "",
Item->changeSelMode());
setLeftChar(Item->changeStartPos().Char);
setTopLine(Item->changeStartPos().Line);
break;
case SynChangeReason::crSelection: case SynChangeReason::crSelection:
mUndoList->AddChange( mUndoList->AddChange(
Item->changeReason(), Item->changeReason(),

View File

@ -268,6 +268,8 @@ public:
void beginUndoBlock(); void beginUndoBlock();
void endUndoBlock(); void endUndoBlock();
void addCaretToUndo();
void addLeftTopToUndo();
//Commands //Commands
virtual void cutToClipboard() { commandProcessor(SynEditorCommand::ecCut);} virtual void cutToClipboard() { commandProcessor(SynEditorCommand::ecCut);}
@ -277,7 +279,10 @@ public:
virtual void redo() { commandProcessor(SynEditorCommand::ecRedo);} virtual void redo() { commandProcessor(SynEditorCommand::ecRedo);}
virtual void zoomIn() { commandProcessor(SynEditorCommand::ecZoomIn);} virtual void zoomIn() { commandProcessor(SynEditorCommand::ecZoomIn);}
virtual void zoomOut() { commandProcessor(SynEditorCommand::ecZoomOut);} virtual void zoomOut() { commandProcessor(SynEditorCommand::ecZoomOut);}
virtual void selectAll() { commandProcessor(SynEditorCommand::ecSelectAll);} virtual void selectAll() {
mUndoList->AddChange(SynChangeReason::crSelection,mBlockBegin,mBlockEnd,"", activeSelectionMode());
commandProcessor(SynEditorCommand::ecSelectAll);
}
virtual void tab() { commandProcessor(SynEditorCommand::ecTab);} virtual void tab() { commandProcessor(SynEditorCommand::ecTab);}
virtual void shifttab() { commandProcessor(SynEditorCommand::ecShiftTab);} virtual void shifttab() { commandProcessor(SynEditorCommand::ecShiftTab);}
virtual void toggleComment() { commandProcessor(SynEditorCommand::ecToggleComment);} virtual void toggleComment() { commandProcessor(SynEditorCommand::ecToggleComment);}

View File

@ -171,6 +171,7 @@ enum class SynChangeReason {crInsert, crPaste, crDragDropInsert,
crPasteBegin, crPasteEnd, //for pasting, since it might do a lot of operations crPasteBegin, crPasteEnd, //for pasting, since it might do a lot of operations
crSpecial1Begin, crSpecial1End, crSpecial1Begin, crSpecial1End,
crSpecial2Begin, crSpecial2End, crSpecial2Begin, crSpecial2End,
crLeftTop,
crCaret, //just restore the Caret, allowing better Undo behavior crCaret, //just restore the Caret, allowing better Undo behavior
crSelection, //restore Selection crSelection, //restore Selection
crNothing, crNothing,

View File

@ -19,6 +19,7 @@
#include "../mainwindow.h" #include "../mainwindow.h"
#include "../widgets/shortcutinputedit.h" #include "../widgets/shortcutinputedit.h"
#include <QMenuBar> #include <QMenuBar>
#include <QMenu>
#include <QMessageBox> #include <QMessageBox>
EnvironmentShortcutWidget::EnvironmentShortcutWidget(const QString& name, const QString& group, QWidget *parent) : EnvironmentShortcutWidget::EnvironmentShortcutWidget(const QString& name, const QString& group, QWidget *parent) :
@ -62,8 +63,8 @@ void EnvironmentShortcutModel::reload()
{ {
beginResetModel(); beginResetModel();
mShortcuts.clear(); mShortcuts.clear();
QList<QAction*> actions = pMainWindow->findChildren<QAction*>(QString(), Qt::FindDirectChildrenOnly);
QList<QMenu*> menus = pMainWindow->menuBar()->findChildren<QMenu*>(); QList<QMenu*> menus = pMainWindow->menuBar()->findChildren<QMenu*>();
QList<QAction*> actions = pMainWindow->findChildren<QAction*>(QString(), Qt::FindDirectChildrenOnly);
foreach( const QMenu* menu, menus) { foreach( const QMenu* menu, menus) {
if (menu->title().isEmpty()) if (menu->title().isEmpty())
continue; continue;
@ -76,6 +77,7 @@ void EnvironmentShortcutModel::reload()
item->fullPath = QString("%1 : %2").arg(tr("action"),action->text()); item->fullPath = QString("%1 : %2").arg(tr("action"),action->text());
item->action = action; item->action = action;
item->shortcut = action->shortcut().toString().trimmed(); item->shortcut = action->shortcut().toString().trimmed();
item->isAction = true;
mShortcuts.append(item); mShortcuts.append(item);
} }
} }
@ -120,6 +122,9 @@ bool EnvironmentShortcutModel::setData(const QModelIndex &index, const QVariant
PEnvironmentShortcut item = mShortcuts[index.row()]; PEnvironmentShortcut item = mShortcuts[index.row()];
QString s = value.toString().trimmed(); QString s = value.toString().trimmed();
if (s!=item->shortcut) { if (s!=item->shortcut) {
if (s.isEmpty()) {
item->shortcut="";
} else {
for (int i=0;i<mShortcuts.length();i++) { for (int i=0;i<mShortcuts.length();i++) {
if (i==index.row()) if (i==index.row())
continue; continue;
@ -132,6 +137,7 @@ bool EnvironmentShortcutModel::setData(const QModelIndex &index, const QVariant
} }
} }
item->shortcut = value.toString(); item->shortcut = value.toString();
}
emit shortcutChanged(); emit shortcutChanged();
} }
return true; return true;
@ -178,12 +184,13 @@ void EnvironmentShortcutModel::loadShortCutsOfMenu(const QMenu *menu, QList<QAct
{ {
QList<QAction*> actions = menu->actions(); QList<QAction*> actions = menu->actions();
foreach (QAction* action,actions) { foreach (QAction* action,actions) {
if (!action->text().isEmpty()) { if (!action->text().isEmpty() && action->menu()==nullptr) {
PEnvironmentShortcut item = std::make_shared<EnvironmentShortcut>(); PEnvironmentShortcut item = std::make_shared<EnvironmentShortcut>();
item->name = action->objectName(); item->name = action->objectName();
item->fullPath = QString("%1 > %2").arg(menu->title(),action->text()); item->fullPath = QString("%1 > %2").arg(menu->title(),action->text());
item->action = action; item->action = action;
item->shortcut = action->shortcut().toString().trimmed(); item->shortcut = action->shortcut().toString().trimmed();
item->isAction = true;
mShortcuts.append(item); mShortcuts.append(item);
} }
globalActions.removeAll(action); globalActions.removeAll(action);

View File

@ -66,6 +66,10 @@ void ShortcutManager::load()
if (shortcut->name.isEmpty()) if (shortcut->name.isEmpty())
continue; continue;
shortcut->shortcut = object["shortcut"].toString(); shortcut->shortcut = object["shortcut"].toString();
if (object["isAction"].isNull())
shortcut->isAction = true;
else
shortcut->isAction = object["isAction"].toBool();
mShortcuts.insert(shortcut->name,shortcut); mShortcuts.insert(shortcut->name,shortcut);
} }
} }
@ -86,6 +90,7 @@ void ShortcutManager::save()
QJsonObject object; QJsonObject object;
object["name"]=shortcut->name; object["name"]=shortcut->name;
object["shortcut"]=shortcut->shortcut; object["shortcut"]=shortcut->shortcut;
object["isAction"]=shortcut->isAction;
array.append(object); array.append(object);
} }
QJsonDocument doc; QJsonDocument doc;
@ -119,7 +124,7 @@ void ShortcutManager::applyTo(QList<QAction *> actions)
void ShortcutManager::applyTo(QAction *action) void ShortcutManager::applyTo(QAction *action)
{ {
PEnvironmentShortcut item = mShortcuts.value(action->objectName(), PEnvironmentShortcut()); PEnvironmentShortcut item = mShortcuts.value(action->objectName(), PEnvironmentShortcut());
if (item) { if (item && item->isAction) {
action->setShortcut(QKeySequence::fromString(item->shortcut)); action->setShortcut(QKeySequence::fromString(item->shortcut));
} }
} }

View File

@ -22,12 +22,15 @@
#include <memory> #include <memory>
class QAction; class QAction;
class QToolButton;
struct EnvironmentShortcut { struct EnvironmentShortcut {
QString name; QString name;
QString fullPath; QString fullPath;
QString shortcut; QString shortcut;
QAction* action; QAction* action;
QToolButton* button;
bool isAction;
}; };
using PEnvironmentShortcut = std::shared_ptr<EnvironmentShortcut>; using PEnvironmentShortcut = std::shared_ptr<EnvironmentShortcut>;