Commit 76c92a74 authored by Alexander Semke's avatar Alexander Semke
Browse files

Re-designed the handling of actions in the worksheet used for richt-text formatting:

* delay the initialization of actions to the point where they are really required, namely when a text entry is activated. This also fixes the bug when these actions are enabled when a new worksheet is created which is wrong.
* hide richt text related actions if no text entry is selected instead of disabling it - this actions are not used most of the time.
parent 352fa19d
Pipeline #68674 canceled with stage
......@@ -147,7 +147,7 @@ CantorPart::CantorPart( QWidget *parentWidget, QObject *parent, const QVariantLi
//initialize actions
auto* collection = actionCollection();
connect(collection, &KActionCollection::inserted, m_worksheet, &Worksheet::registerShortcut);
m_worksheet->createActions(collection);
m_worksheet->setActionCollection(collection);
KStandardAction::saveAs(this, SLOT(fileSaveAs()), collection);
m_save = KStandardAction::save(this, SLOT(save()), collection);
......@@ -833,7 +833,6 @@ void CantorPart::runAssistant()
{
Cantor::Assistant* a = qobject_cast<Cantor::Assistant*>(sender());
QStringList cmds = a->run(widget());
qDebug()<<cmds;
if(!cmds.isEmpty())
runCommand(cmds.join(QLatin1String("\n")));
}
......@@ -961,15 +960,12 @@ void CantorPart::showScriptEditor(bool show)
if(show)
{
if (m_scriptEditor)
{
return;
}
auto* scriptE = dynamic_cast<Cantor::ScriptExtension*>(m_worksheet->session()->backend()->extension(QLatin1String("ScriptExtension")));
if (!scriptE)
{
return;
}
m_scriptEditor = new ScriptEditorWidget(scriptE->scriptFileFilter(), scriptE->highlightingMode(), widget()->window());
connect(m_scriptEditor, &ScriptEditorWidget::runScript, this, &CantorPart::runScript);
connect(m_scriptEditor, &ScriptEditorWidget::destroyed, this, &CantorPart::scriptEditorClosed);
......@@ -1034,7 +1030,6 @@ void CantorPart::showImportantStatusMessage(const QString& message)
void CantorPart::zoomValueEdited(const QString& text)
{
static const QRegularExpression zoomRegexp(QLatin1String("(?:(\\d+)%|(\\d+))"));
QRegularExpressionMatch match = zoomRegexp.match(text);
if (match.hasMatch())
{
......@@ -1059,6 +1054,5 @@ void CantorPart::updateZoomWidgetValue(double zoom)
}
}
K_PLUGIN_FACTORY_WITH_JSON(CantorPartFactory, "cantor_part.json", registerPlugin<CantorPart>();)
#include "cantor_part.moc"
......@@ -49,7 +49,7 @@ Worksheet* WorksheetTest::loadWorksheet(const QString& name)
new WorksheetView(w, nullptr);
w->load(dataPath + name);
KActionCollection* collection = new KActionCollection(nullptr, QString());
w->createActions(collection);
w->setActionCollection(collection);
return w;
}
......
This diff is collapsed.
......@@ -77,7 +77,7 @@ class Worksheet : public QGraphicsScene
void startDrag(WorksheetEntry*, QDrag*);
void startDragWithHierarchy(HierarchyEntry*, QDrag*, QSizeF responsibleZoneSize);
void createActions(KActionCollection*);
void setActionCollection(KActionCollection*);
QMenu* createContextMenu();
void populateMenu(QMenu*, QPointF);
Cantor::Renderer* renderer();
......@@ -148,7 +148,6 @@ class Worksheet : public QGraphicsScene
WorksheetEntry* appendHierarchyEntry();
WorksheetEntry* insertCommandEntry(WorksheetEntry* current = nullptr);
void insertCommandEntry(const QString&);
WorksheetEntry* insertTextEntry(WorksheetEntry* current = nullptr);
WorksheetEntry* insertMarkdownEntry(WorksheetEntry* current = nullptr);
WorksheetEntry* insertImageEntry(WorksheetEntry* current = nullptr);
......@@ -311,9 +310,9 @@ class Worksheet : public QGraphicsScene
bool loadJupyterNotebook(const QJsonDocument& doc);
void showInvalidNotebookSchemeError(QString additionalInfo = QString());
void initSession(Cantor::Backend*);
std::vector<WorksheetEntry*> hierarchySubelements(HierarchyEntry* hierarchyEntry) const;
void initActions();
std::vector<WorksheetEntry*> hierarchySubelements(HierarchyEntry*) const;
private:
static const double LeftMargin;
static const double RightMargin;
static const double TopMargin;
......@@ -344,17 +343,18 @@ class Worksheet : public QGraphicsScene
QMap<QKeySequence, QAction*> m_shortcuts;
KActionCollection* m_collection{nullptr};
QList<QAction *> m_richTextActionList;
KToggleAction* m_boldAction;
KToggleAction* m_italicAction;
KToggleAction* m_underlineAction;
KToggleAction* m_strikeOutAction;
KFontAction* m_fontAction;
KFontSizeAction* m_fontSizeAction;
KToggleAction* m_alignLeftAction;
KToggleAction* m_alignCenterAction;
KToggleAction* m_alignRightAction;
KToggleAction* m_alignJustifyAction;
KToggleAction* m_boldAction{nullptr};
KToggleAction* m_italicAction{nullptr};
KToggleAction* m_underlineAction{nullptr};
KToggleAction* m_strikeOutAction{nullptr};
KFontAction* m_fontAction{nullptr};
KFontSizeAction* m_fontSizeAction{nullptr};
KToggleAction* m_alignLeftAction{nullptr};
KToggleAction* m_alignCenterAction{nullptr};
KToggleAction* m_alignRightAction{nullptr};
KToggleAction* m_alignJustifyAction{nullptr};
bool m_useDefaultWorksheetParameters{true};
......
Markdown is supported
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