Verified Commit 0cb87151 authored by Alexander Lohnau's avatar Alexander Lohnau
Browse files

Port "Move to new lesson" functionality away from kross

Task: https://phabricator.kde.org/T11571
parent 1bb9b02e
......@@ -7,14 +7,6 @@ T = Kross.module("kdetranslation")
#FUNCTIONS
#moves selected entries to a new lesson
def moveSelectedToNewLesson():
selected_entries = Parley.selectedEntries()
if len(selected_entries) > 0:
newlesson = Parley.doc.appendNewLesson(T.i18n("New Lesson"))
for entry in selected_entries:
newlesson.appendEntry(entry)
#marks the selected translations as known (grade 7)
def markAsKnown():
for tr in Parley.selectedTranslations():
......@@ -22,11 +14,6 @@ def markAsKnown():
#SCRIPT MENU
#create a new action for the Scripts menu (action1)
action1 = Parley.newAction("example_action1",T.i18n("Move to new lesson"))
action1.statusTip=T.i18n("Moves the selected vocabulary to a new lesson")
Parley.connect(action1,"triggered()",moveSelectedToNewLesson)
#create a new action for the Scripts menu (action2)
action2 = Parley.newAction("example_action2",T.i18n("Mark as known (highest grade)"))
......
......@@ -174,3 +174,8 @@ KEduVocContainer::EnumContainerType ReadonlyContainerModel::containerType()
{
return m_type;
}
KEduVocDocument *ReadonlyContainerModel::document() const
{
return m_doc.get();
}
......@@ -43,6 +43,8 @@ public:
KEduVocContainer::EnumContainerType containerType();
KEduVocDocument *document() const;
public slots:
/** Set the new source kvtml file
* @param doc the new file */
......
......@@ -101,6 +101,10 @@ public slots:
*/
void addWordWithTranslation(const QStringList &w);
VocabularyView *vocabularyView() const {
return m_vocabularyView;
}
private slots:
/** Make the search bar visible and focus it */
......
......@@ -52,6 +52,7 @@
<Action name="delete_lesson" />
<Separator/>
<Action name="split_lesson" />
<Action name="move_to_new_lesson" />
<Separator/>
<Action name="remove_grades_lesson" />
<Action name="remove_grades_lesson_children" />
......
......@@ -5,6 +5,9 @@
#include "lessonview.h"
#include "vocabularymodel.h"
#include "vocabularyview.h"
#include <QAction>
#include <KActionCollection>
#include <QInputDialog>
......@@ -19,7 +22,7 @@
using namespace Editor;
LessonView::LessonView(EditorWindow * parent) : ContainerView(parent)
LessonView::LessonView(EditorWindow * parent) : ContainerView(parent), m_editorWindow(parent)
{
QAction *actionNewLesson = new QAction(this);
parent->actionCollection()->addAction(QStringLiteral("new_lesson"), actionNewLesson);
......@@ -53,6 +56,14 @@ LessonView::LessonView(EditorWindow * parent) : ContainerView(parent)
actionSplitLesson->setToolTip(actionSplitLesson->whatsThis());
actionSplitLesson->setStatusTip(actionSplitLesson->whatsThis());
QAction *actionMoveToNewLesson = new QAction(this);
parent->actionCollection()->addAction(QStringLiteral("move_to_new_lesson"), actionMoveToNewLesson);
actionMoveToNewLesson->setText(i18n("Move to new lesson"));
actionMoveToNewLesson->setIcon(QIcon::fromTheme(QStringLiteral("edit-move")));
actionMoveToNewLesson->setWhatsThis(i18n("Moves the selected vocabulary to a new lesson"));
actionMoveToNewLesson->setToolTip(actionMoveToNewLesson->whatsThis());
actionMoveToNewLesson->setStatusTip(actionMoveToNewLesson->whatsThis());
QAction *actionRemoveGradesLesson = new QAction(this);
parent->actionCollection()->addAction(QStringLiteral("remove_grades_lesson"), actionRemoveGradesLesson);
actionRemoveGradesLesson->setText(i18n("Remove Confidence Levels"));
......@@ -89,6 +100,7 @@ LessonView::LessonView(EditorWindow * parent) : ContainerView(parent)
connect(actionRenameLesson, &QAction::triggered, this, &LessonView::slotRename);
connect(actionDeleteLesson, &QAction::triggered, this, &LessonView::slotDeleteLesson);
connect(actionSplitLesson, &QAction::triggered, this, &LessonView::slotSplitLesson);
connect(actionMoveToNewLesson, &QAction::triggered, this, &LessonView::moveToNewLesson);
connect(actionRemoveGradesLesson, &QAction::triggered, this, &LessonView::slotRemoveGradesLesson);
connect(actionRemoveGradesLessonChildren, &QAction::triggered, this, &LessonView::slotRemoveGradesLessonChildren);
connect(actionExpandAll, &QAction::triggered, this, &LessonView::expandAllLesson);
......@@ -196,6 +208,7 @@ void LessonView::slotSplitLesson()
* Maybe with radio buttons to ask, if the entries should be in random order or as they come. */
bool ok = false;
int numEntries = QInputDialog::getInt(this, i18n("Entries per Unit"), i18n("The unit will be split into smaller unit. How many entries in each unit do you want?"), Prefs::entriesPerLesson(), 1, 1000, 1, &ok);
if (!ok) {
return;
}
......@@ -204,6 +217,23 @@ void LessonView::slotSplitLesson()
setExpanded(selectionModel()->currentIndex(), true);
}
void LessonView::moveToNewLesson()
{
const QModelIndexList indexes = m_editorWindow->vocabularyView()->getSelectedIndexes();
if (indexes.isEmpty()) {
return;
}
KEduVocDocument *doc = m_model->document();
KEduVocLesson *lesson = new KEduVocLesson(i18n("New Lesson"), doc->lesson());
doc->lesson()->appendChildContainer(lesson);
for (const QModelIndex &index : indexes) {
lesson->appendEntry(qvariant_cast<KEduVocExpression*> (index.data(VocabularyModel::EntryRole)));
}
}
void LessonView::slotRemoveGradesLesson()
{
QModelIndex selectedIndex = selectionModel()->currentIndex();
......
......@@ -50,6 +50,11 @@ public slots:
*/
void slotSplitLesson();
/**
* Moves the selected vocabs to a new lession
*/
void moveToNewLesson();
/** Remove the grades for the selected lesson. */
void slotRemoveGradesLesson();
......@@ -82,6 +87,7 @@ private:
}
LessonModel *m_model;
EditorWindow *m_editorWindow;
};
}
......
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