Commit 256f4d00 authored by Nikita Sirgienko's avatar Nikita Sirgienko
Browse files

[T12843][GSoC 2020] Add new global entries actions: collapsing all Results,...

[T12843][GSoC 2020] Add new global entries actions: collapsing all Results, uncollapsing all results, remove all results
parent 156d076b
......@@ -308,6 +308,21 @@ CantorPart::CantorPart( QWidget *parentWidget, QObject *parent, const QVariantLi
connect(insertImageEntry, SIGNAL(triggered()), m_worksheet, SLOT(insertImageEntry()));
m_editActions.push_back(insertImageEntry);
QAction* collapseAllEntries = new QAction(QIcon(), i18n("Collapse All Results"), collection);
collection->addAction(QLatin1String("all_entries_collapse_results"), collapseAllEntries);
connect(collapseAllEntries, &QAction::triggered, m_worksheet, &Worksheet::collapseAllResults);
m_editActions.push_back(collapseAllEntries);
QAction* uncollapseAllEntries = new QAction(QIcon(), i18n("Expand All Results"), collection);
collection->addAction(QLatin1String("all_entries_uncollapse_results"), uncollapseAllEntries );
connect(uncollapseAllEntries , &QAction::triggered, m_worksheet, &Worksheet::uncollapseAllResults);
m_editActions.push_back(uncollapseAllEntries);
QAction* removeAllResults = new QAction(QIcon(), i18n("Remove All Results"), collection);
collection->addAction(QLatin1String("all_entries_remove_all_results"), removeAllResults);
connect(removeAllResults, &QAction::triggered, m_worksheet, &Worksheet::removeAllResults);
m_editActions.push_back(removeAllResults);
QAction* removeCurrent = new QAction(QIcon::fromTheme(QLatin1String("edit-delete")), i18n("Remove current Entry"), collection);
collection->addAction(QLatin1String("remove_current"), removeCurrent);
collection->setDefaultShortcut(removeCurrent, Qt::ShiftModifier + Qt::Key_Delete);
......
......@@ -41,6 +41,10 @@
<Action name="insert_image_entry"/>
<Action name="insert_page_break_entry"/>
<Separator/>
<Action name="all_entries_collapse_results"/>
<Action name="all_entries_uncollapse_results"/>
<Action name="all_entries_remove_all_results"/>
<Separator/>
<Action name="remove_current"/>
</Menu>
<Menu name="settings">
......
......@@ -1379,6 +1379,9 @@ WorksheetTextItem* CommandEntry::highlightItem()
void CommandEntry::collapseResults()
{
if (m_resultsCollapsed)
return;
for(auto* item : m_resultItems) {
fadeOutItem(item->graphicsObject(), nullptr);
item->graphicsObject()->hide();
......@@ -1400,6 +1403,9 @@ void CommandEntry::collapseResults()
void CommandEntry::expandResults()
{
if(!m_resultsCollapsed)
return;
for(auto* item : m_resultItems) {
fadeInItem(item->graphicsObject(), nullptr);
item->graphicsObject()->show();
......
......@@ -97,6 +97,8 @@ class CommandEntry : public WorksheetEntry
void addInformation();
void removeResults();
void removeResult(Cantor::Result* result);
void collapseResults();
void expandResults();
void showCompletion() override;
void selectPreviousCompletion();
......@@ -137,8 +139,6 @@ class CommandEntry : public WorksheetEntry
void invalidate();
void resultDeleted();
void clearResultItems();
void collapseResults();
void expandResults();
void removeResultItem(int index);
void replaceResultItem(int index);
void updateCompletions();
......
......@@ -2520,3 +2520,44 @@ void Worksheet::notifyEntryFocus(WorksheetEntry* entry)
else
m_circularFocusBuffer.clear();
}
void Worksheet::collapseAllResults()
{
for (WorksheetEntry *entry = firstEntry(); entry; entry = entry->next())
if (entry->type() == CommandEntry::Type)
static_cast<CommandEntry*>(entry)->collapseResults();
}
void Worksheet::uncollapseAllResults()
{
for (WorksheetEntry *entry = firstEntry(); entry; entry = entry->next())
if (entry->type() == CommandEntry::Type)
static_cast<CommandEntry*>(entry)->expandResults();
}
void Worksheet::removeAllResults()
{
bool remove = false;
if (KMessageBox::shouldBeShownContinue(QLatin1String("WarnAboutAllResultsRemoving")))
{
KMessageBox::ButtonCode btn = KMessageBox::warningContinueCancel(
views().first(),
i18n("This action will remove all results without the possibility of cancellation. Are you sure?"),
i18n("Remove all results"),
KStandardGuiItem::cont(),
KStandardGuiItem::cancel(),
QLatin1String("WarnAboutAllResultsRemoving")
);
remove = (btn == KMessageBox::Continue);
}
else
remove = true;
if (remove)
{
for (WorksheetEntry *entry = firstEntry(); entry; entry = entry->next())
if (entry->type() == CommandEntry::Type)
static_cast<CommandEntry*>(entry)->removeResults();
}
}
......@@ -235,6 +235,10 @@ class Worksheet : public QGraphicsScene
void changeEntryType(WorksheetEntry* target, int newType);
void collapseAllResults();
void uncollapseAllResults();
void removeAllResults();
Q_SIGNALS:
void modified();
void loaded();
......
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