Commit 094e0091 authored by Victor Yacovlev's avatar Victor Yacovlev

Fixed course manager program handling

parent 70f5cf79
......@@ -423,7 +423,7 @@ Right click to navigate target</source>
<name>CoreGUI::MainWindow</name>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.ui" line="14"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="497"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="498"/>
<source>Kumir</source>
<translation>Кумир</translation>
</message>
......@@ -506,10 +506,10 @@ Right click to navigate target</source>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.ui" line="147"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="778"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1169"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1269"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1411"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="779"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1175"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1275"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1417"/>
<source>Save</source>
<translation>Сохранить программу</translation>
</message>
......@@ -618,12 +618,12 @@ Right click to navigate target</source>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.ui" line="227"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1108"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1114"/>
<source>Restore previous session</source>
<translation>Восстановить предыдущий сеанс</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="119"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="120"/>
<source>No actions for this tab</source>
<translation>Для этой вкладки нет действий</translation>
</message>
......@@ -648,91 +648,91 @@ Right click to navigate target</source>
<translation type="obsolete">Выполнено шагов: %1</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="492"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="493"/>
<source>New Program</source>
<translation>Новая программа</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="495"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="496"/>
<source>New Text</source>
<translation>Новый текст</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="694"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1298"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="695"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1304"/>
<source>%1 programs (*%2)</source>
<translation>Программы %1 (*%2)</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="697"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1301"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="698"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1307"/>
<source>Text files (*.txt)</source>
<translation>Текстовые файлы (*.txt)</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="699"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1303"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="700"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1309"/>
<source>All files (*)</source>
<translation>Все файлы (*)</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="700"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="701"/>
<source>Save file</source>
<translation>Сохранить файл</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="727"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="728"/>
<source>Can&apos;t save file</source>
<translation>Не могу сохранить файл</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="772"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="773"/>
<source>Close editor</source>
<translation>Закрытие текста</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="773"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1264"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1406"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="774"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1270"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1412"/>
<source>Save current text?</source>
<translation>Сохранить текущий текст?</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="780"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1171"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1271"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1413"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="781"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1177"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1277"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1419"/>
<source>Don&apos;t save</source>
<translation>Не сохранять</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="782"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1173"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="783"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1179"/>
<source>Cancel closing</source>
<translation>Отменить закрытие</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="825"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="826"/>
<source>Preferences</source>
<translation>Настройки</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1109"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1115"/>
<source>Are you sure to restore previous session? All unsaved changes will be lost.</source>
<translation>Вы уверены, что хотите восстановить предыдущий сеанс? Все открытые файлы будут закрыты без сохранения.</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1113"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1119"/>
<source>Yes</source>
<translation>Да</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1114"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1120"/>
<source>No</source>
<translation>Нет</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1160"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1166"/>
<source>The following files have changes:
%1
Save them?</source>
......@@ -741,29 +741,29 @@ Save them?</source>
Сохранить их?</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1163"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1169"/>
<source>Close Kumir</source>
<translation>Выход из Кумир</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1263"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1405"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1269"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1411"/>
<source>Open another file</source>
<translation>Открытие другого файла</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1273"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1415"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1279"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1421"/>
<source>Cancel opening another file</source>
<translation>Не открывать другой файл</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1300"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1306"/>
<source>Web pages (*.html *.htm)</source>
<translation>Web-страницы (*.html *.htm)</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1474"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1480"/>
<source>Can&apos;t open file</source>
<translation>Не могу открыть файл</translation>
</message>
......@@ -802,7 +802,7 @@ Using Qt version %2</source>
Использует Qt версии %2</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1307"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1313"/>
<source>Load file...</source>
<translation>Загрузить файл...</translation>
</message>
......@@ -829,7 +829,7 @@ Using Qt version %2</source>
<translation type="obsolete">Область ввода/вывода</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/plugin.cpp" line="324"/>
<location filename="../../../src/plugins/coregui/plugin.cpp" line="325"/>
<source>Variables</source>
<translation>Значения величин</translation>
</message>
......@@ -872,7 +872,7 @@ Using Qt version %2</source>
<translation type="obsolete">Пауза</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/plugin.cpp" line="463"/>
<location filename="../../../src/plugins/coregui/plugin.cpp" line="464"/>
<source>Start</source>
<translation>Начало</translation>
</message>
......@@ -1082,6 +1082,14 @@ p, li { white-space: pre-wrap; }
<translation type="obsolete">Закрыть текущую вкладку</translation>
</message>
</context>
<context>
<name>CoreGUI::TabWidgetElement</name>
<message>
<location filename="../../../src/plugins/coregui/tabwidgetelement.cpp" line="96"/>
<source>%1 (Course)</source>
<translation>%1 (Практикум)</translation>
</message>
</context>
<context>
<name>Terminal::OneSession</name>
<message>
......
......@@ -8,6 +8,7 @@ set(SOURCES
mainwindow.cpp
plugin.cpp
tabwidget.cpp
tabwidgetelement.cpp
kumirprogram.cpp
terminal.cpp
terminal_onesession.cpp
......
......@@ -70,7 +70,7 @@ MainWindow::MainWindow(Plugin * p) :
setStatusBar(statusBar_);
setMinimumHeight(380);
b_notabs = false;
tabsDisabledFlag_ = false;
b_workspaceSwitching = false;
......@@ -283,7 +283,7 @@ bool MainWindow::eventFilter(QObject *o, QEvent *e)
&& url.scheme()=="file"
)
{
static const QStringList validSuffices = b_notabs
static const QStringList validSuffices = tabsDisabledFlag_
? ( QStringList() << "kum" )
: ( QStringList() << "kum" << "txt"
<< "html" << "htm" );
......@@ -299,7 +299,7 @@ bool MainWindow::eventFilter(QObject *o, QEvent *e)
}
}
}
const bool canAccept = b_notabs
const bool canAccept = tabsDisabledFlag_
? validUrls.size() == 1
: validUrls.size() >= 1;
if (canAccept) {
......@@ -345,7 +345,7 @@ void MainWindow::lockActions()
ui->actionPreferences->setEnabled(false);
if (b_notabs) {
if (tabsDisabledFlag_) {
ui->actionNewProgram->setEnabled(false);
ui->actionOpen->setEnabled(false);
ui->actionRecent_files->setEnabled(false);
......@@ -371,7 +371,7 @@ void MainWindow::unlockActions()
ui->actionPreferences->setEnabled(true);
if (b_notabs) {
if (tabsDisabledFlag_) {
ui->actionNewProgram->setEnabled(true);
ui->actionOpen->setEnabled(true);
ui->actionRecent_files->setEnabled(true);
......@@ -856,7 +856,7 @@ void MainWindow::newProgram()
{
using namespace ExtensionSystem;
using namespace Shared;
if (b_notabs && !closeTab(tabWidget_->currentIndex())) {
if (tabsDisabledFlag_ && !closeTab(tabWidget_->currentIndex())) {
return;
}
AnalizerInterface * analizer =
......@@ -872,15 +872,12 @@ void MainWindow::newProgram()
this, SLOT(showAlgorithmHelp(QString)));
QString fileName = suggestNewFileName(suffix, editor->analizer());
vc->setProperty("title",QFileInfo(fileName).fileName());
vc->setProperty("fileName", QDir::current().absoluteFilePath(fileName));
TabWidgetElement * e = addCentralComponent(
fileName,
vc,
editor->toolBarActions(),
editor->menus(),
type,
true);
type);
e->editorInstance = editor;
tabWidget_->setCurrentWidget(e);
e->setFocus();
......@@ -913,8 +910,7 @@ void MainWindow::newText(const QString &fileName, const QString & text)
vc,
editor->toolBarActions(),
editor->menus(),
Text,
true);
Text);
e->editorInstance = editor;
tabWidget_->setCurrentWidget(e);
if (!text.isEmpty()) {
......@@ -957,37 +953,23 @@ TabWidgetElement * MainWindow::addCentralComponent(
, QWidget *c
, const QList<QAction*> & toolbarActions
, const QList<QMenu*> & menus
// , const QList<QWidget*> & statusbarWidgets
, DocumentType type
, bool enableToolBar)
, DocumentType type)
{
class KumirProgram * kumir = 0;
class PascalProgram * pascal = 0;
if (type==Program) {
kumir = m_plugin->kumirProgram_;
}
TabWidgetElement * element = new TabWidgetElement(
c,
enableToolBar,
toolbarActions,
menus,
// statusbarWidgets,
type,
gr_fileActions,
gr_otherActions,
kumir,
pascal
);
TabWidgetElement * element = new TabWidgetElement(c, type != WWW,
toolbarActions, menus, type,
gr_fileActions, gr_otherActions, kumir);
connect(element, SIGNAL(documentCleanChanged(bool)), this, SLOT(handleDocumentCleanChanged(bool)));
createTopLevelMenus(menus, true);
tabWidget_->addTab(element, title);
return element;
}
void MainWindow::createTopLevelMenus(const QList<QMenu*> & c, bool tabDependent)
{
QList<QMenu*> menus;
......@@ -1041,7 +1023,7 @@ void MainWindow::setupContentForTab()
void MainWindow::disableTabs()
{
tabWidget_->disableTabs();
b_notabs = true;
tabsDisabledFlag_ = true;
ui->actionClose->setVisible(false);
ui->actionClose->setEnabled(false);
ui->actionNewText->setVisible(false);
......@@ -1154,7 +1136,7 @@ void MainWindow::closeEvent(QCloseEvent *e)
{
// saveSettings();
// m_plugin->saveSession();
if (m_plugin->sessionsDisableFlag_ && b_notabs) {
if (m_plugin->sessionsDisableFlag_ && tabsDisabledFlag_) {
TabWidgetElement * twe = qobject_cast<TabWidgetElement*>(tabWidget_->currentWidget());
if (twe->editorInstance) {
bool notSaved = twe->editorInstance->isModified();
......@@ -1277,7 +1259,7 @@ void MainWindow::fileOpen()
{
using namespace ExtensionSystem;
using namespace Shared;
if (b_notabs) {
if (tabsDisabledFlag_) {
TabWidgetElement * twe =
qobject_cast<TabWidgetElement*>(tabWidget_->currentWidget());
if (twe->editorInstance && twe->editorInstance->isModified()) {
......@@ -1320,7 +1302,7 @@ void MainWindow::fileOpen()
const QString languageName = analizer->languageName();
const QString fileNameSuffix = analizer->defaultDocumentFileNameSuffix();
filters << tr("%1 programs (*%2)").arg(languageName).arg(fileNameSuffix);
if (!b_notabs) {
if (!tabsDisabledFlag_) {
filters << tr("Web pages (*.html *.htm)");
filters << tr("Text files (*.txt)");
}
......@@ -1419,7 +1401,7 @@ void MainWindow::addToRecent(const QString &fileName)
void MainWindow::loadRecentFile(const QString & fullPath)
{
if (b_notabs) {
if (tabsDisabledFlag_) {
TabWidgetElement * twe =
qobject_cast<TabWidgetElement*>(tabWidget_->currentWidget());
if (twe->editorInstance && twe->editorInstance->isModified()) {
......@@ -1504,10 +1486,7 @@ TabWidgetElement * MainWindow::loadFromUrl(const QUrl & url, bool addToRecentFil
connect(vc, SIGNAL(requestHelpForAlgorithm(QString)),
this, SLOT(showAlgorithmHelp(QString)));
QString fileName = QFileInfo(url.toLocalFile()).fileName();
vc->setProperty("fileName", url.toLocalFile());
vc->setProperty("realFileName", url.toLocalFile());
vc->setProperty("title", fileName);
if (b_notabs) {
if (tabsDisabledFlag_) {
while(tabWidget_->count()) tabWidget_->removeTab(0);
}
result = addCentralComponent(
......@@ -1515,8 +1494,7 @@ TabWidgetElement * MainWindow::loadFromUrl(const QUrl & url, bool addToRecentFil
vc,
editor->toolBarActions(),
editor->menus(),
type,
true);
type);
result->editorInstance = editor;
tabWidget_->setCurrentIndex(tabWidget_->count()-1);
tabWidget_->currentWidget()->setFocus();
......@@ -1527,7 +1505,7 @@ TabWidgetElement * MainWindow::loadFromUrl(const QUrl & url, bool addToRecentFil
Shared::Browser::InstanceInterface * browser =
m_plugin->plugin_browser->createBrowser(url, m_plugin->m_browserObjects);
browser->setTitleChangeHandler(this, SLOT(updateBrowserTitle(QString, const Shared::Browser::InstanceInterface*)));
if (b_notabs) {
if (tabsDisabledFlag_) {
while(tabWidget_->count()) tabWidget_->removeTab(0);
}
result = addCentralComponent(
......@@ -1535,8 +1513,7 @@ TabWidgetElement * MainWindow::loadFromUrl(const QUrl & url, bool addToRecentFil
browser->widget(),
QList<QAction*>(),
QList<QMenu*>(),
WWW,
true);
WWW);
result->browserInstance = browser;
tabWidget_->setCurrentIndex(tabWidget_->count()-1);
tabWidget_->currentWidget()->setFocus();
......@@ -1560,28 +1537,35 @@ TabWidgetElement* MainWindow::loadFromCourseManager(
break;
}
}
if (tabsDisabledFlag_) {
courseManagerTab = qobject_cast<TabWidgetElement*>(tabWidget_->widget(0));
Q_CHECK_PTR(courseManagerTab);
}
if (data.language == ST::Kumir) {
QWidget * vc = nullptr;
Shared::Editor::InstanceInterface * editor =
m_plugin->plugin_editor->loadDocument(data.content);
KumFile::Data src = data.content;
src.canonicalSourceLanguageName = "kum";
if (courseManagerTab) {
// Reuse opened course manager tab
QObject * oldEditor = dynamic_cast<QObject*>(courseManagerTab->editorInstance);
oldEditor->deleteLater();
courseManagerTab->editorInstance = editor;
// Reuse existing tab
Shared::Editor::InstanceInterface * editor =
courseManagerTab->editorInstance;
}
else {
Shared::Editor::InstanceInterface * editor =
m_plugin->plugin_editor->loadDocument(src);
// Create new course manager tab
courseManagerTab = addCentralComponent(
data.title,
editor->widget(),
editor->toolBarActions(),
editor->menus(),
Program,
true
Program
);
courseManagerTab->editorInstance = editor;
courseManagerTab->setCourseManagerTab(true);
courseManagerTab->setCourseTitle(data.title);
}
}
tabWidget_->setCurrentWidget(courseManagerTab);
return courseManagerTab;
......
......@@ -38,9 +38,7 @@ public:
, QWidget *c
, const QList<QAction*> & toolbarActions
, const QList<QMenu*> & menus
// , const QList<QWidget*> & statusbarWidgets
, DocumentType type
, bool enableToolBar);
, DocumentType type);
~MainWindow();
......@@ -131,7 +129,7 @@ private:
QActionGroup * gr_fileActions;
QActionGroup * gr_otherActions;
bool b_notabs;
bool tabsDisabledFlag_;
// static QString StatusbarWidgetCSS;
......
......@@ -465,8 +465,7 @@ void Plugin::restoreSession()
startPage_->widget(),
QList<QAction*>(),
QList<QMenu*>(),
MainWindow::WWW,
false
MainWindow::WWW
);
twe->browserInstance = startPage_;
}
......
#include "tabwidgetelement.h"
namespace CoreGUI {
TabWidgetElement::TabWidgetElement(QWidget * w
, bool enableToolBar
, QList<QAction*> toolbarActions
, QList<QMenu*> ms
// , QList<QWidget*> sws
, MainWindow::DocumentType t
, QActionGroup * gr_fileActions
, QActionGroup * gr_otherActions
, class KumirProgram * kumir
)
: QWidget()
, component(w)
, menus(ms)
// , statusbarWidgets(sws)
, type(t)
, editorInstance(nullptr)
, browserInstance(nullptr)
, kumirProgram_(kumir)
, courseManagerTab_(false)
{
kumirProgram_ = nullptr;
Q_CHECK_PTR(w);
Q_ASSERT(!QString::fromAscii(w->metaObject()->className()).isEmpty());
setProperty("uncloseable", w->property("uncloseable"));
if (type==MainWindow::WWW) {
connect(w, SIGNAL(titleChanged(QString)), this, SIGNAL(changeTitle(QString)));
}
else {
connect(w, SIGNAL(documentCleanChanged(bool)), this, SIGNAL(documentCleanChanged(bool)));
connect(w, SIGNAL(documentCleanChanged(bool)), this, SLOT(setDocumentChangesClean(bool)));
}
QVBoxLayout * l = new QVBoxLayout;
l->setContentsMargins(0,0,0,0);
l->setSpacing(0);
setLayout(l);
if (enableToolBar) {
if (!toolbarActions.isEmpty()) {
QToolBar * tb = new QToolBar(this);
tb->setIconSize(QSize(22, 22));
#ifdef Q_OS_MAC
static const char * css = ""
"QToolBar {"
" border: 0px;"
" background-color: $windowColor;"
" padding: 8px;"
"}"
"QToolButton {"
" border: 0px;"
"}"
"";
#else
static const char * css = ""
"QToolBar { border: 0px }";
#endif
tb->setStyleSheet(QString::fromAscii(css).replace("$windowColor",palette().brush(QPalette::Window).color().name()));
l->addWidget(tb);
if (type!=MainWindow::WWW) {
tb->addActions(gr_fileActions->actions());
}
tb->addSeparator();
foreach (QAction * a, toolbarActions)
tb->addAction(a);
if (type==MainWindow::Program) {
tb->addSeparator();
QList<QAction*> acts = kumir->actions()->actions();