Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions src/gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,14 @@ void MainWindow::showEvent(QShowEvent *event)

void MainWindow::openProject()
{
auto path = QFileDialog::getExistingDirectory(this, tr("Open project"), QDir::currentPath());
if (!path.isEmpty()) {
Core::Project::instance()->setRoot(path);
initProject(path);
if (m_scriptPanel->hasFocus())
m_scriptPanel->openScript();
else {
auto path = QFileDialog::getExistingDirectory(this, tr("Open project"), QDir::currentPath());
if (!path.isEmpty()) {
Core::Project::instance()->setRoot(path);
initProject(path);
}
}
}

Expand Down Expand Up @@ -510,9 +514,13 @@ void MainWindow::reloadDocuments()

void MainWindow::saveDocument()
{
auto document = Core::Project::instance()->currentDocument();
if (document)
document->save();
if (m_scriptPanel->hasFocus())
m_scriptPanel->saveScript();
else {
auto document = Core::Project::instance()->currentDocument();
if (document)
document->save();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to not change the mainwindow.cpp - after all, those actions are specific to the script panel.

We could do that with a QShortcut in ScriptPanel:

    auto shortcut = new QShortcut(QKeySequence::Open, this);
    shortcut->setContext(Qt::WidgetWithChildrenShortcut);
    connect(shortcut, &QShortcut::activatedAmbiguously, this, &ScriptPanel::openScript);

Or, maybe better, create actions on the tool buttons and assign non-ambiguous shortcuts (Shift+Ctrl+...).

}

void MainWindow::closeDocument(int closeIndex)
Expand Down
9 changes: 9 additions & 0 deletions src/gui/scriptpanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ bool ScriptPanel::hasScript() const

void ScriptPanel::openScript()
{
if (!checkNeedToSaveScript())
return;

const QString fileName = QFileDialog::getOpenFileName(this, tr("Open Script"), "", "Script files (*.qml *.js)");
if (fileName.isEmpty())
return;
Expand Down Expand Up @@ -429,6 +432,12 @@ void ScriptPanel::keyPressEvent(QKeyEvent *event)
}
return;
}
case Qt::Key_N:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be done in one line in the constrtuctor with:

    newScriptAction->setShortcut(QKeySequence::New);

If you are afraid of ambiguous shortcuts, see for the others

if (event->modifiers() & Qt::ControlModifier) {
newScript();
return;
}
break;
case Qt::Key_F1:
interfaceSettings = new InterfaceSettings();
QString documentationUrl;
Expand Down
6 changes: 3 additions & 3 deletions src/gui/scriptpanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class ScriptPanel : public QPlainTextEdit

bool hasScript() const;
void runScript();
void openScript();
void newScriptDialog();
void saveScript();

signals:
void newScriptCreated();
Expand All @@ -42,11 +45,8 @@ class ScriptPanel : public QPlainTextEdit
void mouseReleaseEvent(QMouseEvent *mouseEvent) override;

private:
void openScript();
void newScript();
void newScriptDialog();
bool checkNeedToSaveScript();
void saveScript();
void editDialog();
void checkEditDialogButton();
QString createDialogFile();
Expand Down