Commit a56e497f authored by Shubham  .'s avatar Shubham .
Browse files

merge master

parents 829adb5c 4b1ff759
......@@ -130,9 +130,9 @@
<binary>cantor</binary>
</provides>
<releases>
<release version="20.04.3" date="2020-07-09"/>
<release version="20.04.2" date="2020-06-11"/>
<release version="20.04.1" date="2020-05-14"/>
<release version="20.04.0" date="2020-04-23"/>
<release version="19.12.3" date="2020-03-05"/>
</releases>
</component>
......@@ -65,7 +65,7 @@ KConfigSkeleton* KAlgebraBackend::config() const
QUrl KAlgebraBackend::helpUrl() const
{
return QUrl(i18nc("The url to the documentation of KAlgebra, please check if there is a translated version and use the correct url",
"https://docs.kde.org/stable/en/kdeedu/kalgebra/"));
"https://docs.kde.org/?application=kalgebra"));
}
bool KAlgebraBackend::requirementsFullfilled(QString* const reason) const
......
......@@ -19,7 +19,6 @@ if (WITH_EPS)
else (WITH_EPS)
set(DEFAULT_PLOT_FORMAT "png")
endif (WITH_EPS)
message(STATUS ${CMAKE_CURRENT_SOURCE_DIR})
configure_file(octavebackend.kcfg.in ${CMAKE_CURRENT_BINARY_DIR}/octavebackend.kcfg)
configure_file(settings.ui.in ${CMAKE_CURRENT_BINARY_DIR}/settings.ui)
......
......@@ -60,8 +60,12 @@ def __cantor_plotly_show__(figure):
figure.write_image(__cantor_plt_filename__, scale=2)
print('\nINNER PLOT INFO CANTOR: ', __cantor_plt_filename__, sep='')
__cantor_plotly_original_show__ = __cantor_plotly__.basedatatypes.BaseFigure.show
__cantor_plotly__.basedatatypes.BaseFigure.show = __cantor_plotly_show__
if hasattr(__cantor_plotly__, 'basedatatypes'):
__cantor_plotly_original_show__ = __cantor_plotly__.basedatatypes.BaseFigure.show
__cantor_plotly__.basedatatypes.BaseFigure.show = __cantor_plotly_show__
else:
__cantor_plotly_original_show__ = __cantor_plotly__.graph_objects.Figure.show
__cantor_plotly__.graph_objects.Figure.show = __cantor_plotly_show__
</EnableCommand>
<DisableCommand>
__cantor_plotly__.basedatatypes.BaseFigure.show = __cantor_plotly_original_show__;
......
......@@ -21,6 +21,7 @@
#include <KActionCollection>
#include <KConfigDialog>
#include <KConfigGroup>
#include <KConfig>
#include <KMessageBox>
#include <KShortcutsDialog>
#include <KStandardAction>
......@@ -317,9 +318,10 @@ void CantorShell::addWorksheet(const QString& backendName)
KPluginFactory* factory = loader.factory();
if (factory)
{
Cantor::Backend* backend = nullptr;
if (!backendName.isEmpty())
{
Cantor::Backend* backend = Cantor::Backend::getBackend(backendName);
backend = Cantor::Backend::getBackend(backendName);
if (!backend)
{
KMessageBox::error(this, i18n("Backend %1 is not installed", backendName), i18n("Cantor"));
......@@ -341,9 +343,15 @@ void CantorShell::addWorksheet(const QString& backendName)
{
connect(part, SIGNAL(setCaption(QString,QIcon)), this, SLOT(setTabCaption(QString,QIcon)));
connect(part, SIGNAL(worksheetSave(QUrl)), this, SLOT(onWorksheetSave(QUrl)));
connect(part, SIGNAL(requestOpenWorksheet(QUrl)), this, SLOT(load(QUrl)));
m_parts.append(part);
if (backend) // If backend empty (loading worksheet from file), then we connect to signal and wait
m_parts2Backends[part] = backend->id();
else
{
m_parts2Backends[part] = QString();
connect(part, SIGNAL(setBackendName(QString)), this, SLOT(updateBackendForPart(setBackendName)));
}
int tab = m_tabWidget->addTab(part->widget(), i18n("Session %1", sessionCount++));
m_tabWidget->setCurrentIndex(tab);
// Setting focus on worksheet view, because Qt clear focus of added widget inside addTab
......@@ -424,9 +432,20 @@ void CantorShell::updateWindowTitle(const QString& fileName)
void CantorShell::closeTab(int index)
{
if (!reallyClose(false))
if (index != -1)
{
return;
QWidget* widget = m_tabWidget->widget(index);
if (widget)
{
KParts::ReadWritePart* part= findPart(widget);
if (part && !reallyCloseThisPart(part))
return;
}
}
else
{
if (!reallyClose(false))
return;
}
QWidget* widget = nullptr;
......@@ -456,8 +475,11 @@ void CantorShell::closeTab(int index)
KParts::ReadWritePart* part= findPart(widget);
if(part)
{
saveDockPanelsState(part);
m_parts.removeAll(part);
m_pluginsVisibility.remove(part);
m_parts2Backends.remove(part);
delete part;
}
}
......@@ -488,17 +510,23 @@ bool CantorShell::reallyClose(bool checkAllParts) {
return false;
}
}
if (m_part && m_part->isModified() ) {
return reallyCloseThisPart(m_part);
}
bool CantorShell::reallyCloseThisPart(KParts::ReadWritePart* part)
{
if (part && part->isModified() ) {
int want_save = KMessageBox::warningYesNoCancel( this,
i18n("The current project has been modified. Do you want to save it?"),
i18n("Save Project"));
switch (want_save) {
case KMessageBox::Yes:
m_part->save();
if(m_part->waitSaveComplete()) {
part->save();
if(part->waitSaveComplete()) {
return true;
} else {
m_part->setModified(true);
part->setModified(true);
return false;
}
case KMessageBox::Cancel:
......@@ -510,10 +538,14 @@ bool CantorShell::reallyClose(bool checkAllParts) {
return true;
}
void CantorShell::closeEvent(QCloseEvent* event) {
if(!reallyClose()) {
event->ignore();
} else {
for (KParts::ReadWritePart* part : m_parts)
saveDockPanelsState(part);
KParts::MainWindow::closeEvent(event);
}
}
......@@ -625,10 +657,25 @@ void CantorShell::updatePanel()
}
QDockWidget* last=nullptr;
bool isNewWorksheet = !m_pluginsVisibility.contains(m_part);
if (isNewWorksheet)
{
KConfigGroup panelStatusGroup(KSharedConfig::openConfig(), QLatin1String("PanelsStatus"));
if (m_parts2Backends.contains(m_part) && panelStatusGroup.hasKey(m_parts2Backends[m_part]))
{
const QStringList& plugins = panelStatusGroup.readEntry(m_parts2Backends[m_part]).split(QLatin1Char('\n'));
m_pluginsVisibility[m_part] = plugins;
isNewWorksheet = false;
}
}
QList<Cantor::PanelPlugin*> plugins=handler->plugins();
<<<<<<< HEAD
const bool isNewWorksheet = !m_pluginsVisibility.contains(m_part);
=======
>>>>>>> master
foreach(Cantor::PanelPlugin* plugin, plugins)
{
if(plugin==nullptr)
......@@ -728,3 +775,32 @@ void CantorShell::onWorksheetSave(const QUrl& url)
updateWindowTitle(m_part->url().fileName());
}
void CantorShell::saveDockPanelsState(KParts::ReadWritePart* part)
{
if (m_parts2Backends.contains(part))
{
QStringList visiblePanelNames;
if (part == m_part)
{
foreach (QDockWidget* doc, m_panels)
{
if (doc->widget() && doc->widget()->isVisible())
visiblePanelNames << doc->objectName();
}
}
else if (m_pluginsVisibility.contains(part))
visiblePanelNames = m_pluginsVisibility[part];
KConfigGroup panelStatusGroup(KSharedConfig::openConfig(), QLatin1String("PanelsStatus"));
panelStatusGroup.writeEntry(m_parts2Backends[part], visiblePanelNames.join(QLatin1Char('\n')));
}
}
void CantorShell::updateBackendForPart(const QString& backend)
{
KParts::ReadWritePart* part=dynamic_cast<KParts::ReadWritePart*>(sender());
if (part && m_parts2Backends.contains(part) && m_parts2Backends[part].isEmpty())
m_parts2Backends[part] = backend;
}
......@@ -88,6 +88,7 @@ private Q_SLOTS:
void activateWorksheet(int index);
void setTabCaption(const QString& tab, const QIcon& icon);
void updateBackendForPart(const QString& backend);
void closeTab(int index = -1);
void showSettings();
......@@ -104,12 +105,15 @@ private:
void setupActions();
void closeEvent(QCloseEvent*) override;
bool reallyClose(bool checkAllParts = true);
bool reallyCloseThisPart(KParts::ReadWritePart* part);
void updateWindowTitle(const QString& fileName);
void saveDockPanelsState(KParts::ReadWritePart* part);
KParts::ReadWritePart* findPart(QWidget* widget);
private:
QMap<KParts::ReadWritePart*, QStringList> m_pluginsVisibility;
QList<KParts::ReadWritePart *> m_parts;
QMap<KParts::ReadWritePart*, QString> m_parts2Backends;
KParts::ReadWritePart* m_part;
QTabWidget* m_tabWidget;
QList<QDockWidget*> m_panels;
......
......@@ -482,6 +482,8 @@ bool CantorPart::openFile()
if (rc) {
qDebug()<< "Worksheet successfully loaded in " << (float)timer.elapsed()/1000 << " seconds";
updateCaption();
if (m_worksheet && m_worksheet->session() && m_worksheet->session()->backend())
setBackendName(m_worksheet->session()->backend()->id());
// We modified, but it we load file now, so no need in save option
setModified(false);
}
......
......@@ -84,6 +84,8 @@ Q_SIGNALS:
void setCaption(const QString& caption, const QIcon& icon);
void showHelp(const QString& help);
void worksheetSave(const QUrl& url);
void requestOpenWorksheet(const QUrl& url);
void setBackendName(const QString& name);
void requestDocumentation(const QString&);
public Q_SLOTS:
......
......@@ -149,7 +149,7 @@ class CANTOR_EXPORT Backend : public QObject, public KXMLGUIClient
* The method should be overwritten by all Backends(who have an online help)
* You should make the returned Url translatable, e.g. by doing something like:
* return i18nc("the url to the documentation of KAlgebra, please check if there is a translated version and use the correct url",
* "https://docs.kde.org/stable5/en/kdeedu/kalgebra/index.html");
* "https://docs.kde.org/?application=kalgebra");
* @return Url of the help
*/
virtual QUrl helpUrl() const = 0;
......
......@@ -12,4 +12,6 @@ endfunction()
add_subdirectory(helppanel)
add_subdirectory(variablemgr)
add_subdirectory(filebrowserpanel)
add_subdirectory(documentationpanel)
set(FileBrowserPanelPlugin_SRCS
filebrowserpanelplugin.cpp
)
add_panel(filebrowserpanelplugin ${FileBrowserPanelPlugin_SRCS})
target_link_libraries(cantor_filebrowserpanelplugin KF5::Parts)
/*
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
---
Copyright (C) 2020 Sirgienko Nikita <warquark@gmail.com>
*/
#include "filebrowserpanelplugin.h"
#include <QFileSystemModel>
#include <QTreeView>
#include <QHeaderView>
#include <QModelIndex>
#include <QStandardItem>
#include <QDesktopServices>
#include <QUrl>
#include <QDebug>
#include <QFileInfo>
#include <KParts/ReadOnlyPart>
QFileSystemModel* FileBrowserPanelPlugin::model = nullptr;
FileBrowserPanelPlugin::FileBrowserPanelPlugin(QObject* parent, const QList<QVariant>& args): Cantor::PanelPlugin(parent),
m_view(nullptr)
{
Q_UNUSED(args);
KParts::ReadOnlyPart* part = dynamic_cast<KParts::ReadOnlyPart*>(parent->parent());
if (part)
m_dirRoot = QFileInfo(part->url().toLocalFile()).absoluteDir().absolutePath();
else
m_dirRoot = QDir::currentPath();
}
FileBrowserPanelPlugin::~FileBrowserPanelPlugin()
{
if (m_view)
m_view->deleteLater();;
}
QWidget* FileBrowserPanelPlugin::widget()
{
if (!m_view)
{
if (!model)
{
model = new QFileSystemModel();
model->setRootPath(QDir::currentPath());
}
m_view = new QTreeView();
m_view->setModel(model);
m_view->setRootIndex(model->index(m_dirRoot));
// First column is name with the dir tree
for (int i = 1; i < model->columnCount(); i++)
m_view->setColumnHidden(i, true);
m_view->header()->hide();
connect(m_view, &QTreeView::doubleClicked, this, &FileBrowserPanelPlugin::handleDoubleClicked);
connect(this, SIGNAL(requestOpenWorksheet(QUrl)), parent()->parent(), SIGNAL(requestOpenWorksheet(QUrl)));
}
return m_view;
}
bool FileBrowserPanelPlugin::showOnStartup()
{
return false;
}
void FileBrowserPanelPlugin::handleDoubleClicked(const QModelIndex& index)
{
if (model->isDir(index))
return;
QVariant data = model->data(index, QFileSystemModel::FilePathRole);
if (data.isValid() && data.type() == QVariant::String)
{
const QString& filename = data.value<QString>();
const QUrl& url = QUrl::fromLocalFile(filename);
if (filename.endsWith(QLatin1String(".cws")) || filename.endsWith(QLatin1String(".ipynb")))
emit requestOpenWorksheet(url);
else
QDesktopServices::openUrl(url);
}
}
K_PLUGIN_FACTORY_WITH_JSON(filebrowserpanelplugin, "filebrowserpanelplugin.json", registerPlugin<FileBrowserPanelPlugin>();)
#include "filebrowserpanelplugin.moc"
/*
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
---
Copyright (C) 2020 Sirgienko Nikita <warquark@gmail.com>
*/
#ifndef _FILEBROWSERPANELPLUGIN_H
#define _FILEBROWSERPANELPLUGIN_H
#include "panelplugin.h"
class QTreeView;
class QModelIndex;
class QFileSystemModel;
class FileBrowserPanelPlugin : public Cantor::PanelPlugin
{
Q_OBJECT
public:
FileBrowserPanelPlugin (QObject* parent, const QList<QVariant>& args);
~FileBrowserPanelPlugin() override;
QWidget* widget() override;
bool showOnStartup() override;
Q_SIGNALS:
void requestOpenWorksheet(const QUrl&);
private Q_SLOTS:
void handleDoubleClicked(const QModelIndex&);
private:
QPointer<QTreeView> m_view;
QString m_dirRoot;
static QFileSystemModel* model;
};
#endif /* _FILEBROWSERPANELPLUGIN_H */
{
"KPlugin": {
"Dependencies": [],
"Description": "A panel for working with files inside Cantor",
"Icon": "",
"Id": "FileBrowserPanel",
"License": "GPL",
"Name": "File Browser",
"ServiceTypes": [
"Cantor/PanelPlugin"
]
},
"RequiredExtensions": ""
}
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