Compare commits
No commits in common. "de0acda8acf0f55160e29fd7f0556b11bc493c7a" and "0acc2d8857fa8ab5e51d5b5a00394a5da9e9bf92" have entirely different histories.
de0acda8ac
...
0acc2d8857
8 changed files with 1 additions and 76 deletions
|
@ -72,19 +72,6 @@ void CSignalConnection::Call(std::vector<Data::Variant> args) {
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
SignalConnectionHolder::SignalConnectionHolder() : heldConnection() {}
|
|
||||||
SignalConnectionHolder::SignalConnectionHolder(std::shared_ptr<SignalConnection> connection) : heldConnection(connection) {}
|
|
||||||
SignalConnectionHolder::SignalConnectionHolder(Data::SignalConnectionRef other) : heldConnection(other) {}
|
|
||||||
|
|
||||||
SignalConnectionHolder::~SignalConnectionHolder() {
|
|
||||||
// printf("Prediscon!\n");
|
|
||||||
// if (!heldConnection.expired()) printf("Disconnected!\n");
|
|
||||||
if (!heldConnection.expired())
|
|
||||||
heldConnection.lock()->Disconnect();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
|
|
||||||
SignalConnectionRef Signal::Connect(std::function<void(std::vector<Data::Variant>)> callback) {
|
SignalConnectionRef Signal::Connect(std::function<void(std::vector<Data::Variant>)> callback) {
|
||||||
auto conn = std::dynamic_pointer_cast<SignalConnection>(std::make_shared<CSignalConnection>(callback, weak_from_this()));
|
auto conn = std::dynamic_pointer_cast<SignalConnection>(std::make_shared<CSignalConnection>(callback, weak_from_this()));
|
||||||
connections.push_back(conn);
|
connections.push_back(conn);
|
||||||
|
@ -109,8 +96,6 @@ SignalConnectionRef Signal::Once(lua_State* state) {
|
||||||
return SignalConnectionRef(conn);
|
return SignalConnectionRef(conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
|
|
||||||
int __waitingThreads = 0;
|
int __waitingThreads = 0;
|
||||||
int Signal::Wait(lua_State* thread) {
|
int Signal::Wait(lua_State* thread) {
|
||||||
// If the table hasn't been constructed yet, make it
|
// If the table hasn't been constructed yet, make it
|
||||||
|
|
|
@ -56,27 +56,6 @@ public:
|
||||||
~LuaSignalConnection();
|
~LuaSignalConnection();
|
||||||
};
|
};
|
||||||
|
|
||||||
// Holds a signal connection such that when the holder is deleted (either via its parent object being deleted, or being overwritten),
|
|
||||||
// the connection is disconnected. Useful to prevent lingering connections that no longer contain valid objects
|
|
||||||
class SignalConnectionHolder {
|
|
||||||
std::weak_ptr<SignalConnection> heldConnection;
|
|
||||||
public:
|
|
||||||
SignalConnectionHolder();
|
|
||||||
SignalConnectionHolder(std::shared_ptr<SignalConnection>);
|
|
||||||
SignalConnectionHolder(Data::SignalConnectionRef other);
|
|
||||||
~SignalConnectionHolder();
|
|
||||||
|
|
||||||
// Prevent SignalConnectionHolder being accidentally copied, making it useless
|
|
||||||
// https://stackoverflow.com/a/10473009/16255372
|
|
||||||
SignalConnectionHolder(const SignalConnectionHolder&) = delete;
|
|
||||||
SignalConnectionHolder& operator=(const SignalConnectionHolder&) = delete;
|
|
||||||
SignalConnectionHolder(SignalConnectionHolder&&) = default;
|
|
||||||
SignalConnectionHolder& operator=(SignalConnectionHolder&&) = default;
|
|
||||||
|
|
||||||
inline bool Connected() { return !heldConnection.expired() && heldConnection.lock()->Connected(); }
|
|
||||||
inline void Disconnect() { if (!heldConnection.expired()) heldConnection.lock()->Disconnect(); }
|
|
||||||
};
|
|
||||||
|
|
||||||
class Signal : public std::enable_shared_from_this<Signal> {
|
class Signal : public std::enable_shared_from_this<Signal> {
|
||||||
std::vector<std::shared_ptr<SignalConnection>> connections;
|
std::vector<std::shared_ptr<SignalConnection>> connections;
|
||||||
std::vector<std::shared_ptr<SignalConnection>> onceConnections;
|
std::vector<std::shared_ptr<SignalConnection>> onceConnections;
|
||||||
|
|
|
@ -96,7 +96,6 @@ void Instance::updateAncestry(std::optional<std::shared_ptr<Instance>> updatedCh
|
||||||
}
|
}
|
||||||
|
|
||||||
OnAncestryChanged(updatedChild, newParent);
|
OnAncestryChanged(updatedChild, newParent);
|
||||||
AncestryChanged->Fire({updatedChild.has_value() ? Data::InstanceRef(updatedChild.value()) : Data::InstanceRef(), newParent.has_value() ? Data::InstanceRef(newParent.value()) : Data::InstanceRef()});
|
|
||||||
|
|
||||||
// Old workspace used to exist, and workspaces differ
|
// Old workspace used to exist, and workspaces differ
|
||||||
if (!oldWorkspace.expired() && oldWorkspace != _workspace) {
|
if (!oldWorkspace.expired() && oldWorkspace != _workspace) {
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "datatypes/signal.h"
|
|
||||||
#include "error/instance.h"
|
#include "error/instance.h"
|
||||||
#include "error/result.h"
|
#include "error/result.h"
|
||||||
#include "member.h"
|
#include "member.h"
|
||||||
|
@ -94,9 +93,6 @@ public:
|
||||||
const static InstanceType TYPE;
|
const static InstanceType TYPE;
|
||||||
std::string name;
|
std::string name;
|
||||||
|
|
||||||
// Signals
|
|
||||||
SignalSource AncestryChanged;
|
|
||||||
|
|
||||||
// Instance is abstract, so it should not implement GetClass directly
|
// Instance is abstract, so it should not implement GetClass directly
|
||||||
virtual const InstanceType* GetClass() = 0;
|
virtual const InstanceType* GetClass() = 0;
|
||||||
bool SetParent(std::optional<std::shared_ptr<Instance>> newParent);
|
bool SetParent(std::optional<std::shared_ptr<Instance>> newParent);
|
||||||
|
|
|
@ -484,30 +484,13 @@ std::optional<std::string> MainWindow::openFileDialog(QString filter, QString de
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::openScriptDocument(std::shared_ptr<Script> script) {
|
void MainWindow::openScriptDocument(std::shared_ptr<Script> script) {
|
||||||
// Document already exists, don't open it
|
|
||||||
if (scriptDocuments.count(script) > 0) {
|
|
||||||
ui->mdiArea->setActiveSubWindow(scriptDocuments[script]);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ScriptDocument* doc = new ScriptDocument(script);
|
ScriptDocument* doc = new ScriptDocument(script);
|
||||||
scriptDocuments[script] = doc;
|
|
||||||
doc->setAttribute(Qt::WA_DeleteOnClose, true);
|
doc->setAttribute(Qt::WA_DeleteOnClose, true);
|
||||||
ui->mdiArea->addSubWindow(doc);
|
ui->mdiArea->addSubWindow(doc);
|
||||||
ui->mdiArea->setActiveSubWindow(doc);
|
ui->mdiArea->setActiveSubWindow(doc);
|
||||||
doc->showMaximized();
|
doc->showMaximized();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::closeScriptDocument(std::shared_ptr<Script> script) {
|
|
||||||
if (scriptDocuments.count(script) == 0) return;
|
|
||||||
|
|
||||||
ScriptDocument* doc = scriptDocuments[script];
|
|
||||||
ui->mdiArea->removeSubWindow(doc);
|
|
||||||
ui->mdiArea->activeSubWindow()->showMaximized();
|
|
||||||
scriptDocuments.erase(script);
|
|
||||||
doc->deleteLater();
|
|
||||||
}
|
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
{
|
{
|
||||||
delete ui;
|
delete ui;
|
||||||
|
|
|
@ -5,10 +5,8 @@
|
||||||
#include "placedocument.h"
|
#include "placedocument.h"
|
||||||
#include "qbasictimer.h"
|
#include "qbasictimer.h"
|
||||||
#include "qcoreevent.h"
|
#include "qcoreevent.h"
|
||||||
#include "script/scriptdocument.h"
|
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <map>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <qfiledialog.h>
|
#include <qfiledialog.h>
|
||||||
|
|
||||||
|
@ -55,12 +53,10 @@ public:
|
||||||
bool editSoundEffects = true;
|
bool editSoundEffects = true;
|
||||||
|
|
||||||
void openScriptDocument(std::shared_ptr<Script>);
|
void openScriptDocument(std::shared_ptr<Script>);
|
||||||
void closeScriptDocument(std::shared_ptr<Script>);
|
|
||||||
|
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
private:
|
private:
|
||||||
PlaceDocument* placeDocument;
|
PlaceDocument* placeDocument;
|
||||||
std::map<std::shared_ptr<Script>, ScriptDocument*> scriptDocuments;
|
|
||||||
|
|
||||||
void updateToolbars();
|
void updateToolbars();
|
||||||
void closeEvent(QCloseEvent* evt) override;
|
void closeEvent(QCloseEvent* evt) override;
|
||||||
|
|
|
@ -5,16 +5,13 @@
|
||||||
#include <Qsci/qsciscintillabase.h>
|
#include <Qsci/qsciscintillabase.h>
|
||||||
#include <Qsci/qscistyle.h>
|
#include <Qsci/qscistyle.h>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
|
||||||
#include <qboxlayout.h>
|
#include <qboxlayout.h>
|
||||||
#include <qcolor.h>
|
#include <qcolor.h>
|
||||||
#include <qfont.h>
|
#include <qfont.h>
|
||||||
#include <qdebug.h>
|
#include <qdebug.h>
|
||||||
#include <qglobal.h>
|
#include <qglobal.h>
|
||||||
#include <qlayout.h>
|
#include <qlayout.h>
|
||||||
#include "mainwindow.h"
|
|
||||||
#include "objects/script.h"
|
#include "objects/script.h"
|
||||||
#include "datatypes/meta.h"
|
|
||||||
|
|
||||||
std::map<int, const QColor> DARK_MODE_COLOR_SCHEME = {{
|
std::map<int, const QColor> DARK_MODE_COLOR_SCHEME = {{
|
||||||
{QsciLexerLua::Comment, QColor("#808080")},
|
{QsciLexerLua::Comment, QColor("#808080")},
|
||||||
|
@ -40,15 +37,6 @@ ScriptDocument::ScriptDocument(std::shared_ptr<Script> script, QWidget* parent):
|
||||||
|
|
||||||
setWindowTitle(QString::fromStdString(script->name));
|
setWindowTitle(QString::fromStdString(script->name));
|
||||||
|
|
||||||
// Add detector for script deletion to automatically close this document
|
|
||||||
scriptDeletionHandler = script->AncestryChanged->Connect([this, script](std::vector<Data::Variant> args) {
|
|
||||||
std::weak_ptr<Instance> child = args[0].get<Data::InstanceRef>();
|
|
||||||
std::weak_ptr<Instance> newParent = args[1].get<Data::InstanceRef>();
|
|
||||||
if (child.expired() || child.lock() != script || !newParent.expired()) return;
|
|
||||||
|
|
||||||
dynamic_cast<MainWindow*>(window())->closeScriptDocument(script);
|
|
||||||
});
|
|
||||||
|
|
||||||
// QFrame* frame = new QFrame;
|
// QFrame* frame = new QFrame;
|
||||||
// QVBoxLayout* frameLayout = new QVBoxLayout;
|
// QVBoxLayout* frameLayout = new QVBoxLayout;
|
||||||
// frame->setLayout(frameLayout);
|
// frame->setLayout(frameLayout);
|
||||||
|
@ -86,6 +74,7 @@ ScriptDocument::ScriptDocument(std::shared_ptr<Script> script, QWidget* parent):
|
||||||
|
|
||||||
// lexer->setAutoIndentStyle(QsciScintilla::AiOpening | QsciScintilla::AiMaintain | QsciScintilla::AiClosing);
|
// lexer->setAutoIndentStyle(QsciScintilla::AiOpening | QsciScintilla::AiMaintain | QsciScintilla::AiClosing);
|
||||||
// scintilla->setAutoIndent(true);
|
// scintilla->setAutoIndent(true);
|
||||||
|
|
||||||
|
|
||||||
connect(scintilla, &QsciScintilla::textChanged, [this]() {
|
connect(scintilla, &QsciScintilla::textChanged, [this]() {
|
||||||
// this-> is important here, as otherwise it will refer to the
|
// this-> is important here, as otherwise it will refer to the
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "datatypes/signal.h"
|
|
||||||
#include <Qsci/qsciscintilla.h>
|
#include <Qsci/qsciscintilla.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <qmdisubwindow.h>
|
#include <qmdisubwindow.h>
|
||||||
|
@ -9,7 +8,6 @@ class Script;
|
||||||
|
|
||||||
class ScriptDocument : public QMdiSubWindow {
|
class ScriptDocument : public QMdiSubWindow {
|
||||||
std::shared_ptr<Script> script;
|
std::shared_ptr<Script> script;
|
||||||
SignalConnectionHolder scriptDeletionHandler;
|
|
||||||
|
|
||||||
QsciScintilla* scintilla;
|
QsciScintilla* scintilla;
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Add table
Reference in a new issue