From 39bdd66dbb0e67b6519792a1532b8b557543cbf8 Mon Sep 17 00:00:00 2001 From: "royqh1979@gmail.com" Date: Sun, 20 Jun 2021 14:49:38 +0800 Subject: [PATCH] * work save --- RedPandaIDE/colorscheme.cpp | 8 ++++---- RedPandaIDE/colorscheme.h | 2 +- .../settingsdialog/editorcolorschemewidget.cpp | 13 ++++++++----- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/RedPandaIDE/colorscheme.cpp b/RedPandaIDE/colorscheme.cpp index 392c2a9c..3a3babe5 100644 --- a/RedPandaIDE/colorscheme.cpp +++ b/RedPandaIDE/colorscheme.cpp @@ -283,14 +283,14 @@ bool ColorManager::exists(const QString name) return mSchemes.contains(name); } -PColorScheme ColorManager::copy(const QString &sourceName) +QString ColorManager::copy(const QString &sourceName) { if (!mSchemes.contains(sourceName)) - return PColorScheme(); + return QString(); PColorScheme sourceScheme = mSchemes[sourceName]; QString newName = sourceName+" Copy"; if (mSchemes.contains(newName)) - return PColorScheme(); + return QString(); // save source with the new name QString newFilepath = generateFullPathname(newName,false,false); sourceScheme->save(newFilepath); @@ -299,7 +299,7 @@ PColorScheme ColorManager::copy(const QString &sourceName) newScheme->setBundled(false); newScheme->setCustomed(false); mSchemes[newName]=newScheme; - return newScheme; + return newName; } QString ColorManager::generateFilename(const QString &name, bool isCustomed) diff --git a/RedPandaIDE/colorscheme.h b/RedPandaIDE/colorscheme.h index e1ebf355..519e0313 100644 --- a/RedPandaIDE/colorscheme.h +++ b/RedPandaIDE/colorscheme.h @@ -129,7 +129,7 @@ public: QStringList getDefines(); bool exists(const QString name); - PColorScheme copy(const QString& source); + QString copy(const QString& source); bool rename(const QString& oldName, const QString& newName); PColorScheme remove(const QString& name); PColorScheme get(const QString& name); diff --git a/RedPandaIDE/settingsdialog/editorcolorschemewidget.cpp b/RedPandaIDE/settingsdialog/editorcolorschemewidget.cpp index dd95dbaf..4e164ed4 100644 --- a/RedPandaIDE/settingsdialog/editorcolorschemewidget.cpp +++ b/RedPandaIDE/settingsdialog/editorcolorschemewidget.cpp @@ -6,6 +6,7 @@ #include #include +#include EditorColorSchemeWidget::EditorColorSchemeWidget(const QString& name, const QString& group, QWidget *parent) : SettingsWidget(name,group,parent), @@ -292,14 +293,18 @@ void EditorColorSchemeWidget::doSave() void EditorColorSchemeWidget::on_actionCopy_Scheme_triggered() { - + QString newName = pColorManager->copy(ui->cbScheme->currentText()); + if (newName.isEmpty()) + return; + ui->cbScheme->addItem(newName); + ui->cbScheme->setCurrentText(newName); } void EditorColorSchemeWidget::on_btnSchemeMenu_pressed() { QMenu menu; - PColorScheme scheme = pColorManager->get(ui->cbScheme->currentText()); + PColorScheme scheme = getCurrentScheme(); if (scheme) { if (scheme->customed()) { menu.addAction(ui->actionReset_Scheme); @@ -316,7 +321,5 @@ void EditorColorSchemeWidget::on_btnSchemeMenu_pressed() QPoint p; p.setX(0); p.setY(ui->btnSchemeMenu->height()+2); - QAction* action = menu.exec(ui->btnSchemeMenu->mapToGlobal(p)); - if (action) - action->trigger(); + menu.exec(ui->btnSchemeMenu->mapToGlobal(p)); }