Commit d4124f27 authored by Victor Yacovlev's avatar Victor Yacovlev

Small fixes on refactoring Editor/Analizer

parent 81e07857
......@@ -249,7 +249,11 @@ void Term::clear()
void Term::start(const QString & fileName)
{
int fixedWidth = -1;
OneSession * session = new OneSession(fixedWidth, QFileInfo(fileName).fileName(), m_plane);
OneSession * session = new OneSession(
fixedWidth,
fileName.isEmpty() ? tr("New Program") : QFileInfo(fileName).fileName(),
m_plane
);
session->relayout(m_plane->width());
connect(session, SIGNAL(updateRequest()), m_plane, SLOT(update()));
sessions_ << session;
......
......@@ -194,7 +194,7 @@ void Editor::loadMacros()
}
using namespace Shared;
using namespace ExtensionSystem;
const QString analizerName = analizerPlugin_->defaultDocumentFileNameSuffix().mid(1);
const QString analizerName = analizerPlugin_->defaultDocumentFileNameSuffix();
// System macros
const QString sharePath = QCoreApplication::instance()->property("sharePath").toString();
......
......@@ -54,12 +54,14 @@ Editor::InstanceInterface * EditorPlugin::newDocument(
connectGlobalSignalsToEditor(editor);
if (analizerPlugin) {
const QString initialTextFileName =
QString initialTextFileName =
mySettings()->value(SettingsPage::KeyProgramTemplateFile
+ "." + analizerPlugin->defaultDocumentFileNameSuffix(),
SettingsPage::DefaultProgramTemplateFile
+ "." + analizerPlugin->defaultDocumentFileNameSuffix()
).toString();
static const QString resourcesRoot = QDir(qApp->applicationDirPath()+"/../share/kumir2/").canonicalPath();
initialTextFileName.replace("${RESOURCES}", resourcesRoot);
QFile f(initialTextFileName);
if (f.open(QIODevice::ReadOnly|QIODevice::Text)) {
const QByteArray bytes = f.readAll();
......
#include "settingspage.h"
#include "ui_settingspage.h"
#include "extensionsystem/pluginmanager.h"
#include "interfaces/analizerinterface.h"
namespace Editor {
QString SettingsPage::KeyInvertColorsIfDarkSystemTheme = "Highlight/InvertColorsIfDarkTheme";
......@@ -256,6 +259,18 @@ void SettingsPage::init()
ui->freeCursorPositioning->setCurrentIndex(freeCursorMovement);
QString initialFileName = DefaultProgramTemplateFile;
Shared::AnalizerInterface * analizer =
ExtensionSystem::PluginManager::instance()
->findPlugin<Shared::AnalizerInterface>();
if (analizer) {
initialFileName += "." + analizer->defaultDocumentFileNameSuffix();
}
else {
initialFileName += ".txt";
}
static const QString resourcesRoot = QDir(qApp->applicationDirPath()+"/../share/kumir2/").canonicalPath();
initialFileName.replace("${RESOURCES}", resourcesRoot);
ui->templateFileName->setText(QDir::toNativeSeparators(
......
......@@ -33,20 +33,21 @@ ContentView::ContentView(QWidget *parent)
this, SLOT(clearLastAnchorUrl()));
ignoreClearAnchorUrl_ = false;
// if (!ExtraFontsLoaded_) {
// const QString resourcesRoot = QCoreApplication::instance()->property("sharePath").toString();
// const QDir fontsDir = QDir(resourcesRoot + "/docbookviewer");
// const QStringList ttfFiles = fontsDir.entryList(QStringList() << "*.ttf" << "*.otf");
// foreach (const QString & fileName, ttfFiles) {
// const QString filePath = fontsDir.absoluteFilePath(fileName);
// int id = QFontDatabase::addApplicationFont(filePath);
// if (id == -1) {
// qWarning() << "Can't load font " << filePath;
// }
// }
// ExtraFontsLoaded_ = true;
// }
#ifdef Q_OS_WIN32
if (!ExtraFontsLoaded_) {
const QString resourcesRoot = QCoreApplication::instance()->property("sharePath").toString();
const QDir fontsDir = QDir(resourcesRoot + "/docbookviewer");
const QStringList ttfFiles = fontsDir.entryList(QStringList() << "*.ttf" << "*.otf");
foreach (const QString & fileName, ttfFiles) {
const QString filePath = fontsDir.absoluteFilePath(fileName);
int id = QFontDatabase::addApplicationFont(filePath);
if (id == -1) {
qWarning() << "Can't load font " << filePath;
}
}
ExtraFontsLoaded_ = true;
}
#endif
}
QSize ContentView::minimumSizeHint() const
......
......@@ -5,7 +5,8 @@
#include <QMetaObject>
#include <QMetaMethod>
#include <QListWidgetItem>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QPushButton>
namespace Widgets {
......@@ -17,14 +18,30 @@ MultiPageDialogImpl::MultiPageDialogImpl(class MultiPageDialog * parent)
void MultiPageDialogImpl::setupUi()
{
QGridLayout * grid = new QGridLayout;
pClass_->setMinimumSize(400, 300);
pClass_->setLayout(new QHBoxLayout);
pClass_->setLayout(grid);
list_ = new QListWidget(pClass_);
pClass_->layout()->addWidget(list_);
grid->addWidget(list_, 0, 0);
stack_ = new QStackedWidget(pClass_);
pClass_->layout()->addWidget(stack_);
grid->addWidget(stack_, 0, 1);
connect(list_, SIGNAL(currentRowChanged(int)),
this, SLOT(handleGroupSelected(int)));
buttonBox_ = new QDialogButtonBox(pClass_);
grid->addWidget(buttonBox_, 1, 0, 1, 2);
QPushButton * btnAccept =
buttonBox_->addButton(tr("OK"), QDialogButtonBox::AcceptRole);
connect(btnAccept, SIGNAL(clicked()), pClass_, SLOT(accept()));
QPushButton * btnCancel =
buttonBox_->addButton(tr("Cancel"), QDialogButtonBox::RejectRole);
connect(btnCancel, SIGNAL(clicked()), pClass_, SLOT(reject()));
QPushButton * btnReset =
buttonBox_->addButton(tr("Reset to Defaults"), QDialogButtonBox::ResetRole);
connect(btnReset, SIGNAL(clicked()), this, SLOT(resetAllPages()));
}
void MultiPageDialogImpl::acceptAllPages()
......@@ -47,6 +64,27 @@ void MultiPageDialogImpl::acceptAllPages()
}
}
void MultiPageDialogImpl::resetAllPages()
{
for (int i=0; i<pages_.size(); i++) {
const QMetaObject * mo = pages_[i]->metaObject();
QMetaMethod m;
bool found = false;
for (int j=0; j<mo->methodCount(); j++) {
const QString signature = mo->method(j).signature();
if (signature=="resetToDefaults()") {
m = mo->method(j);
found = true;
break;
}
}
if (found) {
m.invoke(pages_[i]);
}
}
init();
}
void MultiPageDialogImpl::init()
{
for (int i=0; i<pages_.size(); i++) {
......
......@@ -5,6 +5,7 @@
#include <QStackedWidget>
#include <QListWidget>
#include <QScrollArea>
#include <QDialogButtonBox>
namespace Widgets {
......@@ -21,6 +22,7 @@ private /*methods*/:
private slots:
void handleGroupSelected(int index);
void acceptAllPages();
void resetAllPages();
void init();
private /*fields*/:
......@@ -28,6 +30,7 @@ private /*fields*/:
QList<QWidget*> pages_;
QStackedWidget * stack_;
QListWidget * list_;
QDialogButtonBox * buttonBox_;
};
......
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