- 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
- change: drag&drop in files view default to move
- 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
- 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);
if (oldEditor) {
BufferCoord oldXY=oldEditor->caretXY();
int topLine = oldEditor->topLine();
int leftChar = oldEditor->leftChar();
oldEditor->beginUndoBlock();
oldEditor->addLeftTopToUndo();
oldEditor->addCaretToUndo();
oldEditor->selectAll();
oldEditor->setSelText(newContents.join(oldEditor->lineBreak()));
oldEditor->setTopLine(topLine);
oldEditor->setLeftChar(leftChar);
oldEditor->setCaretXY(oldXY);
oldEditor->endUndoBlock();
} else {
QByteArray realEncoding;
QFile file(filename);

View File

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

View File

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

View File

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

View File

@ -454,6 +454,20 @@ void SynEdit::endUndoBlock()
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()
{
incPaintLock();
@ -4334,6 +4348,18 @@ void SynEdit::doUndoItem()
Item->changeSelMode());
internalSetCaretXY(Item->changeStartPos());
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:
mRedoList->AddChange(
Item->changeReason(),
@ -4609,6 +4635,18 @@ void SynEdit::doRedoItem()
mActiveSelectionMode);
internalSetCaretXY(Item->changeStartPos());
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:
mUndoList->AddChange(
Item->changeReason(),

View File

@ -268,6 +268,8 @@ public:
void beginUndoBlock();
void endUndoBlock();
void addCaretToUndo();
void addLeftTopToUndo();
//Commands
virtual void cutToClipboard() { commandProcessor(SynEditorCommand::ecCut);}
@ -277,7 +279,10 @@ public:
virtual void redo() { commandProcessor(SynEditorCommand::ecRedo);}
virtual void zoomIn() { commandProcessor(SynEditorCommand::ecZoomIn);}
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 shifttab() { commandProcessor(SynEditorCommand::ecShiftTab);}
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
crSpecial1Begin, crSpecial1End,
crSpecial2Begin, crSpecial2End,
crLeftTop,
crCaret, //just restore the Caret, allowing better Undo behavior
crSelection, //restore Selection
crNothing,

View File

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

View File

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

View File

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