Commit 82574ffb authored by Alexander Semke's avatar Alexander Semke
Browse files

Squach commit of multiple fixes that were done recently in

release/21.08 branch.

Don't crash when calling the context menu of a rendered markdown entry.

Don't crash when all worksheets were closed and a new one is created
again.

BUG: 443177
FIXED-IN: 21.08.2

Don't create a new worksheet via the double click in the "Select the backend" dialog if the backend is not enabled.

Don't shown the "move up" and "move down" actions in the context menu of a worksheet entry if the entry is already at the very top or very bottom, respectively.

Since we don't have the undo/redo functionality yet, removing an entry by an error can result in a lost of a lot of work.
To at least remedy this problem, pop up a Yes/No-message box and ask the user to confirm.

Re-activated the action toolbar again for worksheet entries (seems to be a regression) and added short cuts for remove, move up and move down actions.

Mark the project as modified also when the entries are move or deleted and properly notify the user about the changes in the window title bar and in the tab names.

Remove the wait cursor prior to showing the message box on LaTeX errors in Jupytor notebooks.
parent ce968c37
Pipeline #85350 passed with stage
in 18 minutes and 10 seconds
......@@ -29,7 +29,10 @@ BackendChooseDialog::BackendChooseDialog(QWidget* parent) : QDialog(parent)
m_ui.backendList->setIconSize(QSize(KIconLoader::SizeMedium, KIconLoader::SizeMedium));
m_ui.backendList->setSortingEnabled(true);
connect(m_ui.backendList, &QListWidget::currentItemChanged, this, &BackendChooseDialog::updateContent);
connect(m_ui.backendList, &QListWidget::itemDoubleClicked, this, &BackendChooseDialog::accept);
connect(m_ui.backendList, &QListWidget::itemDoubleClicked, this, [=]() {
if (m_ui.buttonBox->button(QDialogButtonBox::Ok)->isEnabled())
accept();
});
m_ui.buttonBox->button(QDialogButtonBox::Ok);
m_ui.buttonBox->button(QDialogButtonBox::Ok)->setIcon(QApplication::style()->standardIcon(QStyle::SP_DialogOkButton));
......
/*
SPDX-License-Identifier: GPL-2.0-or-later
SPDX-FileCopyrightText: 2009 Alexander Rieder <alexanderrieder@gmail.com>
SPDX-FileCopyrightText: 2018-2021 Alexander Semke <alexander.semke@web.de>
*/
#include "cantor.h"
#include "lib/session.h"
......@@ -445,7 +446,8 @@ void CantorShell::activateWorksheet(int index)
}
}
updateWindowTitle(m_part->url().fileName());
updateWindowTitle(m_part->url().fileName(), m_part->isModified());
updatePanel();
}
else
......@@ -460,16 +462,29 @@ void CantorShell::setTabCaption(const QString& caption, const QIcon& icon)
auto* part = dynamic_cast<KParts::ReadWritePart*>(sender());
if (part)
{
const int index = m_tabWidget->indexOf(part->widget());
if (!caption.isEmpty())
m_tabWidget->setTabText(m_tabWidget->indexOf(part->widget()), caption);
m_tabWidget->setTabIcon(m_tabWidget->indexOf(part->widget()), icon);
{
if (part->isModified())
m_tabWidget->setTabText(index, caption + QLatin1String(" *"));
else
m_tabWidget->setTabText(index, caption);
if (part == m_part)
updateWindowTitle(m_part->url().fileName(), m_part->isModified());
}
m_tabWidget->setTabIcon(index, icon);
}
}
void CantorShell::updateWindowTitle(const QString& fileName)
void CantorShell::updateWindowTitle(const QString& fileName, bool modified)
{
QFileInfo info(fileName);
setWindowTitle(info.baseName());
QString title = info.baseName();
if (modified)
title += QLatin1String(" [") + i18n("Changed") + QLatin1Char(']');
setWindowTitle(title);
}
void CantorShell::closeTab(int index)
......@@ -524,6 +539,10 @@ void CantorShell::closeTab(int index)
m_pluginsVisibility.remove(part);
m_parts2Backends.remove(part);
m_pluginsStates.remove(part);
if (m_part == part)
m_part = nullptr; //the current worksheet/part is being closed, set to null
delete part;
}
}
......
......@@ -106,7 +106,7 @@ private:
void closeEvent(QCloseEvent*) override;
bool reallyClose(bool checkAllParts = true);
bool reallyCloseThisPart(KParts::ReadWritePart*);
void updateWindowTitle(const QString&);
void updateWindowTitle(const QString&, bool modified = false);
void saveDockPanelsState(KParts::ReadWritePart*);
KParts::ReadWritePart* findPart(QWidget*);
......
......@@ -128,6 +128,7 @@ CantorPart::CantorPart( QWidget *parentWidget, QObject *parent, const QVariantLi
m_worksheetview = new WorksheetView(m_worksheet, widget);
m_worksheetview->setEnabled(false); //disable input until the session has successfully logged in and emits the ready signal
connect(m_worksheet, &Worksheet::modified, this, static_cast<void (KParts::ReadWritePart::*)()>(&KParts::ReadWritePart::setModified));
connect(m_worksheet, &Worksheet::modified, this, &CantorPart::updateCaption);
connect(m_worksheet, &Worksheet::showHelp, this, &CantorPart::showHelp);
connect(m_worksheet, &Worksheet::loaded, this, &CantorPart::initialized);
connect(m_worksheet, &Worksheet::hierarchyChanged, this, &CantorPart::hierarchyChanged);
......@@ -472,6 +473,7 @@ bool CantorPart::saveFile()
else
m_worksheet->save( localFilePath() );
setModified(false);
updateCaption();
emit worksheetSave(QUrl::fromLocalFile(localFilePath()));
return true;
......
......@@ -581,7 +581,10 @@ void MarkdownEntry::handleMathRender(QSharedPointer<MathRenderResult> result)
if (!result->successful)
{
if (Settings::self()->showMathRenderError())
{
QApplication::restoreOverrideCursor();
KMessageBox::error(worksheetView(), result->errorMessage, i18n("Cantor Math Error"));
}
else
qDebug() << "MarkdownEntry: math render failed with message" << result->errorMessage;
return;
......
......@@ -427,10 +427,7 @@ WorksheetView* Worksheet::worksheetView()
void Worksheet::setModified()
{
if (m_isClosing)
return;
if (!m_isLoadingFromFile)
if (!m_isClosing && !m_isLoadingFromFile)
emit modified();
}
......
......@@ -33,6 +33,7 @@
#include <KColorScheme>
#include <KLocalizedString>
#include <KMessageBox>
#include <QDebug>
struct AnimationData
......@@ -76,7 +77,7 @@ QString WorksheetEntry::colorNames[] = {i18n("White"), i18n("Black"),
WorksheetEntry::WorksheetEntry(Worksheet* worksheet) : QGraphicsObject(), m_controlElement(worksheet, this)
{
worksheet->addItem(this);
setAcceptHoverEvents(true);
connect(&m_controlElement, &WorksheetControlItem::drag, this, &WorksheetEntry::startDrag);
}
......@@ -370,11 +371,15 @@ void WorksheetEntry::keyPressEvent(QKeyEvent* event)
case Qt::Key_Up:
if (event->modifiers() == Qt::NoModifier)
moveToPreviousEntry(WorksheetTextItem::BottomRight, 0);
else if (event->modifiers() == Qt::CTRL)
moveToPrevious();
break;
case Qt::Key_Right:
case Qt::Key_Down:
if (event->modifiers() == Qt::NoModifier)
moveToNextEntry(WorksheetTextItem::TopLeft, 0);
else if (event->modifiers() == Qt::CTRL)
moveToNext();
break;
/*case Qt::Key_Enter:
case Qt::Key_Return:
......@@ -382,10 +387,6 @@ void WorksheetEntry::keyPressEvent(QKeyEvent* event)
evaluate();
else if (event->modifiers() == Qt::ControlModifier)
worksheet()->insertCommandEntry();
break;
case Qt::Key_Delete:
if (event->modifiers() == Qt::ShiftModifier)
startRemoving();
break;*/
default:
event->ignore();
......@@ -402,7 +403,10 @@ void WorksheetEntry::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
void WorksheetEntry::populateMenu(QMenu* menu, QPointF pos)
{
auto* firstAction = menu->actions().first();
QAction* firstAction = nullptr;
if (!menu->actions().isEmpty()) //action() can be empty, s.a. WorksheetTextItem::populateMenu() where this function is called
firstAction = menu->actions().first();
QAction* action;
if (!worksheet()->isRunning() && wantToEvaluate())
{
......@@ -412,19 +416,26 @@ void WorksheetEntry::populateMenu(QMenu* menu, QPointF pos)
menu->insertSeparator(firstAction);
}
action = new QAction(QIcon::fromTheme(QLatin1String("go-up")), i18n("Move Up"));
// connect(action, &QAction::triggered, this, &WorksheetEntry::moveToPrevious); //TODO: doesn't work
connect(action, SIGNAL(triggered()), this, SLOT(moveToPrevious()));
menu->insertAction(firstAction, action);
if (m_prev) {
action = new QAction(QIcon::fromTheme(QLatin1String("go-up")), i18n("Move Up"));
// connect(action, &QAction::triggered, this, &WorksheetEntry::moveToPrevious); //TODO: doesn't work
connect(action, SIGNAL(triggered()), this, SLOT(moveToPrevious()));
action->setShortcut(Qt::CTRL + Qt::Key_Up);
menu->insertAction(firstAction, action);
}
action = new QAction(QIcon::fromTheme(QLatin1String("go-down")), i18n("Move Down"));
// connect(action, &QAction::triggered, this, &WorksheetEntry::moveToNext); //TODO: doesn't work
connect(action, SIGNAL(triggered()), this, SLOT(moveToNext()));
menu->insertAction(firstAction, action);
menu->insertSeparator(firstAction);
if (m_next) {
action = new QAction(QIcon::fromTheme(QLatin1String("go-down")), i18n("Move Down"));
// connect(action, &QAction::triggered, this, &WorksheetEntry::moveToNext); //TODO: doesn't work
connect(action, SIGNAL(triggered()), this, SLOT(moveToNext()));
action->setShortcut(Qt::CTRL + Qt::Key_Down);
menu->insertAction(firstAction, action);
menu->insertSeparator(firstAction);
}
action = new QAction(QIcon::fromTheme(QLatin1String("edit-delete")), i18n("Remove"));
connect(action, &QAction::triggered, this, &WorksheetEntry::startRemoving);
action->setShortcut(Qt::ShiftModifier + Qt::Key_Delete);
menu->insertAction(firstAction, action);
menu->insertSeparator(firstAction);
......@@ -699,6 +710,10 @@ bool WorksheetEntry::aboutToBeRemoved()
void WorksheetEntry::startRemoving()
{
int rc = KMessageBox::warningYesNo(nullptr, i18n("Do you really want to remove this entry?"), i18n("Remove Entry"));
if (rc == KMessageBox::No)
return;
if (!worksheet()->animationsEnabled()) {
m_aboutToBeRemoved = true;
remove();
......@@ -785,6 +800,8 @@ void WorksheetEntry::remove()
// make the entry invisible to QGraphicsScene's itemAt() function
forceRemove();
worksheet()->setModified();
}
void WorksheetEntry::setSize(QSizeF size)
......@@ -980,6 +997,8 @@ void WorksheetEntry::moveToNext(bool updateLayout)
if (updateLayout)
worksheet()->updateLayout();
worksheet()->setModified();
}
}
......@@ -1010,6 +1029,8 @@ void WorksheetEntry::moveToPrevious(bool updateLayout)
if (updateLayout)
worksheet()->updateLayout();
worksheet()->setModified();
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment