Commit cecd6e87 authored by Victor Yacovlev's avatar Victor Yacovlev

Fixed '*' title on file changed

parent 1d3a3e8c
......@@ -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="500"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="523"/>
<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="781"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1183"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1283"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1425"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="805"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1205"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1305"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1447"/>
<source>Save</source>
<translation>Сохранить программу</translation>
</message>
......@@ -618,12 +618,14 @@ 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="1122"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1144"/>
<source>Restore previous session</source>
<translation>Восстановить предыдущий сеанс</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="120"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="122"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="129"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="136"/>
<source>No actions for this tab</source>
<translation>Для этой вкладки нет действий</translation>
</message>
......@@ -648,122 +650,120 @@ Right click to navigate target</source>
<translation type="obsolete">Выполнено шагов: %1</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="495"/>
<source>New Program</source>
<translation>Новая программа</translation>
<translation type="obsolete">Новая программа</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="498"/>
<source>New Text</source>
<translation>Новый текст</translation>
<translation type="obsolete">Новый текст</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="697"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1312"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="721"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1334"/>
<source>%1 programs (*%2)</source>
<translation>Программы %1 (*%2)</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="700"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1315"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="724"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1337"/>
<source>Text files (*.txt)</source>
<translation>Текстовые файлы (*.txt)</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="702"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1317"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="726"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1339"/>
<source>All files (*)</source>
<translation>Все файлы (*)</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="703"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="727"/>
<source>Save file</source>
<translation>Сохранить файл</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="730"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="754"/>
<source>Can&apos;t save file</source>
<translation>Не могу сохранить файл</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="775"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="799"/>
<source>Close editor</source>
<translation>Закрытие текста</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="776"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1278"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1420"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="800"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1300"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1442"/>
<source>Save current text?</source>
<translation>Сохранить текущий текст?</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="783"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1185"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1285"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1427"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="807"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1207"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1307"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1449"/>
<source>Don&apos;t save</source>
<translation>Не сохранять</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="785"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1187"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="809"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1209"/>
<source>Cancel closing</source>
<translation>Отменить закрытие</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="828"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="852"/>
<source>Preferences</source>
<translation>Настройки</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1123"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1145"/>
<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="1127"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1149"/>
<source>Yes</source>
<translation>Да</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1128"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1150"/>
<source>No</source>
<translation>Нет</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1174"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1196"/>
<source>The following files have changes:
%1
Save them?</source>
<translation type="unfinished">Эти файлы были изменены:
<translation>Эти файлы были изменены:
%1
Сохранить их?</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1177"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1199"/>
<source>Close Kumir</source>
<translation>Выход из Кумир</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1277"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1419"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1299"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1441"/>
<source>Open another file</source>
<translation>Открытие другого файла</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1287"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1429"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1309"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1451"/>
<source>Cancel opening another file</source>
<translation>Не открывать другой файл</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1314"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1336"/>
<source>Web pages (*.html *.htm)</source>
<translation>Web-страницы (*.html *.htm)</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1488"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1510"/>
<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="1321"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1343"/>
<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="361"/>
<location filename="../../../src/plugins/coregui/plugin.cpp" line="367"/>
<source>Variables</source>
<translation>Значения величин</translation>
</message>
......@@ -865,6 +865,12 @@ Using Qt version %2</source>
<source>Courses</source>
<translation>Практикум</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/plugin.cpp" line="339"/>
<location filename="../../../src/plugins/coregui/plugin.cpp" line="340"/>
<source>No actions for this tab</source>
<translation>Для этой вкладки нет действий</translation>
</message>
<message>
<source>Editing</source>
<translation type="obsolete">Редактирование</translation>
......@@ -882,7 +888,7 @@ Using Qt version %2</source>
<translation type="obsolete">Пауза</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/plugin.cpp" line="338"/>
<location filename="../../../src/plugins/coregui/plugin.cpp" line="344"/>
<source>Start</source>
<translation>Начало</translation>
</message>
......@@ -1095,10 +1101,20 @@ p, li { white-space: pre-wrap; }
<context>
<name>CoreGUI::TabWidgetElement</name>
<message>
<location filename="../../../src/plugins/coregui/tabwidgetelement.cpp" line="96"/>
<location filename="../../../src/plugins/coregui/tabwidgetelement.cpp" line="117"/>
<source>%1 (Course)</source>
<translation>%1 (Практикум)</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/tabwidgetelement.cpp" line="122"/>
<source>New Program</source>
<translation>Новая программа</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/tabwidgetelement.cpp" line="125"/>
<source>New Text</source>
<translation>Новый текст</translation>
</message>
</context>
<context>
<name>Terminal::OneSession</name>
......
......@@ -499,6 +499,15 @@ bool MainWindow::saveCurrentFile()
return result;
}
void MainWindow::handleTabTitleChanged()
{
TabWidgetElement * twe = qobject_cast<TabWidgetElement*>(sender());
Q_ASSERT(twe);
int index = tabWidget_->indexOf(twe);
Q_ASSERT(index >= 0 && index < tabWidget_->count());
setTitleForTab(index);
}
void MainWindow::setTitleForTab(int index)
{
if (index<0 || index>=tabWidget_->count())
......@@ -510,12 +519,7 @@ void MainWindow::setTitleForTab(int index)
TabWidgetElement * twe = currentTab();
QString title = twe->title();
if (title.isEmpty() && twe->type==Program) {
title = tr("New Program");
}
else if (title.isEmpty() && twe->type==Text) {
title = tr("New Text");
}
QString appName = tr("Kumir");
using namespace Shared;
using namespace ExtensionSystem;
......@@ -755,15 +759,15 @@ bool MainWindow::saveCurrentFileTo(const QString &fileName)
void MainWindow::handleDocumentCleanChanged(bool v)
{
TabWidgetElement * twe = qobject_cast<TabWidgetElement*>(sender());
int index = tabWidget_->indexOf(twe);
QString text = tabWidget_->tabText(index);
if (text.endsWith("*"))
text = text.left(text.length()-1);
if (!v)
text += "*";
twe->setProperty("title", text);
setTitleForTab(index);
// TabWidgetElement * twe = qobject_cast<TabWidgetElement*>(sender());
// int index = tabWidget_->indexOf(twe);
// QString text = tabWidget_->tabText(index);
// if (text.endsWith("*"))
// text = text.left(text.length()-1);
// if (!v)
// text += "*";
// twe->setProperty("title", text);
// setTitleForTab(index);
}
......@@ -902,6 +906,7 @@ void MainWindow::newProgram()
type);
e->editorInstance = editor;
tabWidget_->setCurrentWidget(e);
setTitleForTab(tabWidget_->indexOf(e));
e->setFocus();
}
......@@ -940,12 +945,8 @@ void MainWindow::newText(const QString &fileName, const QString & text)
editor->menus(),
Text);
e->editorInstance = editor;
tabWidget_->setCurrentWidget(e);
if (!text.isEmpty()) {
tabWidget_->setTabText(tabWidget_->currentIndex(),
tabWidget_->tabText(tabWidget_->currentIndex())
+"*");
}
tabWidget_->setCurrentWidget(e);
setTitleForTab(tabWidget_->indexOf(e));
e->setFocus();
}
......@@ -992,6 +993,7 @@ TabWidgetElement * MainWindow::addCentralComponent(
gr_fileActions, gr_otherActions, kumir);
connect(element, SIGNAL(documentCleanChanged(bool)), this, SLOT(handleDocumentCleanChanged(bool)));
connect(element, SIGNAL(titleChanged(QString)), this, SLOT(handleTabTitleChanged()));
createTopLevelMenus(menus, true);
tabWidget_->addTab(element, title);
return element;
......
......@@ -93,6 +93,7 @@ private slots:
void setupContentForTab();
void setupStatusbarForTab();
void setTitleForTab(int index);
void handleTabTitleChanged();
void checkCounterValue();
void showAlgorithmHelp(const QString & name);
......
......@@ -21,6 +21,7 @@ TabWidgetElement::TabWidgetElement(QWidget * w
, browserInstance(nullptr)
, kumirProgram_(kumir)
, courseManagerTab_(false)
, documentHasChanges_(false)
{
kumirProgram_ = nullptr;
Q_CHECK_PTR(w);
......@@ -82,6 +83,19 @@ TabWidgetElement::TabWidgetElement(QWidget * w
l->addWidget(w);
}
void TabWidgetElement::setDocumentChangesClean(bool clean)
{
bool oldDocumentHasChanges = documentHasChanges_;
documentHasChanges_ = ! clean;
if (editorInstance &&
!isCourseManagerTab() &&
documentHasChanges_ != oldDocumentHasChanges)
{
emit titleChanged(title());
}
}
QString TabWidgetElement::title() const
{
if (editorInstance) {
......@@ -90,13 +104,30 @@ QString TabWidgetElement::title() const
if (url.isValid()) {
const QString fullPath = editorInstance->documentContents().sourceUrl.toLocalFile();
const QString shortPath = QFileInfo(fullPath).fileName();
return shortPath;
QString title;
if (documentHasChanges_ && !isCourseManagerTab()) {
title = shortPath + "*";
}
else {
title = shortPath;
}
return title;
}
else if (isCourseManagerTab()) {
return tr("%1 (Course)").arg(courseTitle_).trimmed();
}
else {
return "";
QString title;
if (MainWindow::Program == type) {
title = tr("New Program");
}
else if (MainWindow::Text == type) {
title = tr("New Text");
}
if (title.length() > 0 && documentHasChanges_) {
title += "*";
}
return title;
}
}
else if (browserInstance) {
......
......@@ -37,7 +37,7 @@ public:
inline void setCourseTitle(const QString & title) { courseTitle_ = title; }
signals:
void changeTitle(const QString & txt);
void titleChanged(const QString &);
void documentCleanChanged(bool v);
protected:
inline void focusInEvent(QFocusEvent *e) {
......@@ -45,19 +45,13 @@ protected:
component->setFocus();
}
protected slots:
inline void setDocumentChangesClean(bool clean) {
if (clean) {
}
else {
}
}
void setDocumentChangesClean(bool clean);
private:
class KumirProgram * kumirProgram_;
bool courseManagerTab_;
QString courseTitle_;
bool documentHasChanges_;
};
}
......
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