static v8::Handle<v8::Value> V8TestNamedConstructorConstructorCallback(const v8::Arguments& args) { if (!args.IsConstructCall()) return throwTypeError("DOM object constructor cannot be called as a function.", args.GetIsolate()); if (ConstructorMode::current() == ConstructorMode::WrapExistingObject) return args.Holder(); Document* document = currentDocument(); // Make sure the document is added to the DOM Node map. Otherwise, the TestNamedConstructor instance // may end up being the only node in the map and get garbage-collected prematurely. toV8(document, args.Holder(), args.GetIsolate()); if (args.Length() < 1) return throwNotEnoughArgumentsError(args.GetIsolate()); ExceptionCode ec = 0; V8TRYCATCH_FOR_V8STRINGRESOURCE(V8StringResource<>, str1, args[0]); V8TRYCATCH_FOR_V8STRINGRESOURCE(V8StringResource<>, str2, args[1]); V8TRYCATCH_FOR_V8STRINGRESOURCE(V8StringResource<>, str3, argumentOrNull(args, 2)); RefPtr<TestNamedConstructor> impl = TestNamedConstructor::createForJSConstructor(document, str1, str2, str3, ec); v8::Handle<v8::Object> wrapper = args.Holder(); if (ec) return setDOMException(ec, args.GetIsolate()); V8DOMWrapper::associateObjectWithWrapper(impl.release(), &V8TestNamedConstructorConstructor::info, wrapper, args.GetIsolate(), WrapperConfiguration::Dependent); return wrapper; }
ExecutionContext* getExecutionContext() { if (WorkerScriptController* controller = WorkerScriptController::controllerForContext()) return &controller->workerGlobalScope(); return currentDocument(); }
score::GUIElements ApplicationPlugin::makeGUIElements() { score::GUIElements e; auto& actions = e.actions; auto& base_menus = context.menus.get(); auto putInLoop = new QAction{this}; connect(putInLoop, &QAction::triggered, this, [this] { auto& ctx = currentDocument()->context(); auto sm = Scenario::focusedScenarioModel(ctx); SCORE_ASSERT(sm); Loop::EncapsulateInLoop(*sm, ctx.commandStack); }); actions.add<Actions::PutInLoop>(putInLoop); auto& scenariomodel_cond = context.actions.condition<Scenario::EnableWhenScenarioModelObject>(); scenariomodel_cond.add<Actions::PutInLoop>(); auto& object = base_menus.at(score::Menus::Object()); object.menu()->addAction(putInLoop); return e; }
void MainWindow::setShapeColor() { Document *doc = currentDocument(); if (doc == 0) return; QString shapeName = doc->currentShapeName(); if (shapeName.isEmpty()) return; QColor color; if (sender() == actionRed) color = Qt::red; else if (sender() == actionGreen) color = Qt::green; else if (sender() == actionBlue) color = Qt::blue; else return; if (color == doc->shape(shapeName).color()) return; doc->undoStack()->push(new SetShapeColorCommand(doc, shapeName, color)); }
v8::Handle<v8::Value> V8AudioContext::constructorCustom(const v8::Arguments& args) { Document* document = currentDocument(); RefPtr<AudioContext> audioContext; if (!args.Length()) { // Constructor for default AudioContext which talks to audio hardware. audioContext = AudioContext::create(document); if (!audioContext.get()) return throwError(v8SyntaxError, "audio resources unavailable for AudioContext construction", args.GetIsolate()); } else { // Constructor for offline (render-target) AudioContext which renders into an AudioBuffer. // new AudioContext(in unsigned long numberOfChannels, in unsigned long numberOfFrames, in float sampleRate); document->addConsoleMessage(JSMessageSource, WarningMessageLevel, "Deprecated AudioContext constructor: use OfflineAudioContext instead"); return V8OfflineAudioContext::constructorCallback(args); } if (!audioContext.get()) return throwError(v8SyntaxError, "Error creating AudioContext", args.GetIsolate()); // Transform the holder into a wrapper object for the audio context. v8::Handle<v8::Object> wrapper = args.Holder(); V8DOMWrapper::associateObjectWithWrapper(audioContext.release(), &info, wrapper, args.GetIsolate(), WrapperConfiguration::Dependent); return wrapper; }
void OSAppBase::updateSelectedMeasureState() { // DLM: this slot seems out of place here, seems like the connection from the measure list to enabling duplicate buttons, etc // should be tighter std::shared_ptr<OSDocument> document = currentDocument(); if (document) { std::shared_ptr<MainRightColumnController> mainRightColumnController = document->mainRightColumnController(); if (mainRightColumnController) { if (measureManager().isMeasureSelected()){ // DLM: this logic is why we cannot remove m_applyMeasureNowDialog as member of OSDocument if( document->m_applyMeasureNowDialog && document->m_applyMeasureNowDialog->isVisible()) { document->m_applyMeasureNowDialog->displayMeasure(); document->m_applyMeasureNowDialog->m_localLibraryController->localLibraryView->duplicateMeasureButton->setEnabled(true); } else { mainRightColumnController->measuresLibraryController()->localLibraryView->duplicateMeasureButton->setEnabled(true); } }else{ if( document->m_applyMeasureNowDialog && document->m_applyMeasureNowDialog->isVisible()) { document->m_applyMeasureNowDialog->m_localLibraryController->localLibraryView->duplicateMeasureButton->setEnabled(false); } else { mainRightColumnController->measuresLibraryController()->localLibraryView->duplicateMeasureButton->setEnabled(false); } } } } }
static v8::Handle<v8::Value> V8TestNamedConstructorConstructorCallback(const v8::Arguments& args) { INC_STATS("DOM.TestNamedConstructor.Constructor"); if (!args.IsConstructCall()) return throwTypeError("DOM object constructor cannot be called as a function."); if (ConstructorMode::current() == ConstructorMode::WrapExistingObject) return args.Holder(); Document* document = currentDocument(BindingState::instance()); // Make sure the document is added to the DOM Node map. Otherwise, the TestNamedConstructor instance // may end up being the only node in the map and get garbage-collected prematurely. toV8(document, args.Holder(), args.GetIsolate()); if (args.Length() < 1) return throwNotEnoughArgumentsError(args.GetIsolate()); ExceptionCode ec = 0; STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, str1, MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined)); STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, str2, MAYBE_MISSING_PARAMETER(args, 1, DefaultIsUndefined)); STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, str3, MAYBE_MISSING_PARAMETER(args, 2, DefaultIsNullString)); RefPtr<TestNamedConstructor> impl = TestNamedConstructor::createForJSConstructor(document, str1, str2, str3, ec); v8::Handle<v8::Object> wrapper = args.Holder(); if (ec) goto fail; V8DOMWrapper::setDOMWrapper(wrapper, &V8TestNamedConstructorConstructor::info, impl.get()); V8DOMWrapper::setJSWrapperForActiveDOMObject(impl.release(), wrapper, args.GetIsolate()); return wrapper; fail: return setDOMException(ec, args.GetIsolate()); }
void MainWindow::saveDocument() { Document *doc = currentDocument(); if (doc == 0) return; for (;;) { QString fileName = doc->fileName(); if (fileName.isEmpty()) fileName = QFileDialog::getSaveFileName(this); if (fileName.isEmpty()) break; QFile file(fileName); if (!file.open(QIODevice::WriteOnly)) { QMessageBox::warning(this, tr("File error"), tr("Failed to open\n%1").arg(fileName)); doc->setFileName(QString()); } else { QTextStream stream(&file); doc->save(stream); doc->setFileName(fileName); int index = documentTabs->indexOf(doc); Q_ASSERT(index != -1); documentTabs->setTabText(index, fixedWindowTitle(doc)); break; } } }
Document * exec( const QPoint & pos ) { move(pos); if (QDialog::exec()) return currentDocument(); else return 0; }
ScriptExecutionContext* getScriptExecutionContext() { #if ENABLE(WORKERS) if (WorkerScriptController* controller = WorkerScriptController::controllerForContext()) return controller->workerContext(); #endif return currentDocument(BindingState::instance()); }
void OSAppBase::chooseHorizontalEditTab() { std::shared_ptr<OSDocument> document = currentDocument(); if (document) { document->mainRightColumnController()->chooseEditTab(); } }
void OSAppBase::openBclDlg() { std::shared_ptr<OSDocument> document = currentDocument(); if (document) { document->openMeasuresBclDlg(); } }
v8::Handle<v8::Value> V8AudioContext::constructorCallback(const v8::Arguments& args) { INC_STATS("DOM.AudioContext.Contructor"); if (!args.IsConstructCall()) return throwTypeError("AudioContext constructor cannot be called as a function.", args.GetIsolate()); if (ConstructorMode::current() == ConstructorMode::WrapExistingObject) return args.Holder(); Document* document = currentDocument(BindingState::instance()); RefPtr<AudioContext> audioContext; if (!args.Length()) { // Constructor for default AudioContext which talks to audio hardware. ExceptionCode ec = 0; audioContext = AudioContext::create(document, ec); if (ec) return setDOMException(ec, args.GetIsolate()); if (!audioContext.get()) return throwError(SyntaxError, "audio resources unavailable for AudioContext construction", args.GetIsolate()); } else { // Constructor for offline (render-target) AudioContext which renders into an AudioBuffer. // new AudioContext(in unsigned long numberOfChannels, in unsigned long numberOfFrames, in float sampleRate); if (args.Length() < 3) return throwNotEnoughArgumentsError(args.GetIsolate()); bool ok = false; int32_t numberOfChannels = toInt32(args[0], ok); if (!ok || numberOfChannels <= 0 || numberOfChannels > 10) return throwError(SyntaxError, "Invalid number of channels", args.GetIsolate()); int32_t numberOfFrames = toInt32(args[1], ok); if (!ok || numberOfFrames <= 0) return throwError(SyntaxError, "Invalid number of frames", args.GetIsolate()); float sampleRate = toFloat(args[2]); if (sampleRate <= 0) return throwError(SyntaxError, "Invalid sample rate", args.GetIsolate()); ExceptionCode ec = 0; audioContext = AudioContext::createOfflineContext(document, numberOfChannels, numberOfFrames, sampleRate, ec); if (ec) return setDOMException(ec, args.GetIsolate()); } if (!audioContext.get()) return throwError(SyntaxError, "Error creating AudioContext", args.GetIsolate()); // Transform the holder into a wrapper object for the audio context. V8DOMWrapper::setDOMWrapper(args.Holder(), &info, audioContext.get()); audioContext->ref(); return args.Holder(); }
boost::optional<openstudio::path> OSAppBase::tempDir() { std::shared_ptr<OSDocument> document = currentDocument(); if (document) { return toPath(document->modelTempDir()); } return boost::none; }
boost::optional<openstudio::Workspace> OSAppBase::currentWorkspace() { std::shared_ptr<OSDocument> document = currentDocument(); if (document) { return document->workspace(); } else { return boost::none; } }
boost::optional<openstudio::model::Model> OSAppBase::currentModel() { std::shared_ptr<OSDocument> document = currentDocument(); if (document) { return document->model(); } else { return boost::optional<openstudio::model::Model>(); } }
QSharedPointer<EditController> OSAppBase::editController() { std::shared_ptr<OSDocument> document = currentDocument(); if (document) { return document->mainRightColumnController()->measuresEditController(); } else { return QSharedPointer<EditController>(); } }
QWidget *OSAppBase::mainWidget() { std::shared_ptr<OSDocument> document = currentDocument(); if (document) { return document->mainWindow(); } else { return nullptr; } }
boost::optional<openstudio::analysisdriver::SimpleProject> OSAppBase::project() { std::shared_ptr<OSDocument> document = currentDocument(); if (document) { return document->project(); } else { return boost::optional<openstudio::analysisdriver::SimpleProject>(); } }
void MainWindow::removeShape() { Document *doc = currentDocument(); if (doc == 0) return; QString shapeName = doc->currentShapeName(); if (shapeName.isEmpty()) return; doc->undoStack()->push(new RemoveShapeCommand(doc, shapeName)); }
ScriptsTabController::ScriptsTabController() : MainTabController(new ScriptsTabView(nullptr)), scriptsTabView(dynamic_cast<ScriptsTabView *>(mainContentWidget())) { auto app = OSAppBase::instance(); boost::optional<path> tempDir = app->tempDir(); OS_ASSERT(tempDir); // save the current osm to a temp location app->measureManager().saveTempModel(*tempDir); // update measures app->currentDocument()->disable(); app->measureManager().updateMeasuresLists(); app->currentDocument()->enable(); m_workflowController = QSharedPointer<openstudio::measuretab::WorkflowController>(new openstudio::measuretab::WorkflowController(OSAppBase::instance())); m_workflowSectionItemDelegate = QSharedPointer<openstudio::measuretab::WorkflowSectionItemDelegate>(new openstudio::measuretab::WorkflowSectionItemDelegate()); scriptsTabView->workflowView->setListController(m_workflowController); scriptsTabView->workflowView->setDelegate(m_workflowSectionItemDelegate); }
void OSAppBase::updateMyMeasures() { std::shared_ptr<OSDocument> document = currentDocument(); if (document) { boost::optional<analysisdriver::SimpleProject> project = document->project(); if (project) { mainWidget()->setEnabled(false); measureManager().updateMyMeasures(*project); mainWidget()->setEnabled(true); } else { LOG(Error, "Unable to update measures, there is no project set..."); } } }
void MainWindow::addSnowman() { Document *doc = currentDocument(); if (doc == 0) return; // Create a macro command using beginMacro() and endMacro() doc->undoStack()->beginMacro(tr("Add snowman")); doc->undoStack()->push(new AddShapeCommand(doc, Shape(Shape::Circle, Qt::blue, QRect(51, 30, 97, 95)))); doc->undoStack()->push(new AddShapeCommand(doc, Shape(Shape::Circle, Qt::blue, QRect(27, 123, 150, 133)))); doc->undoStack()->push(new AddShapeCommand(doc, Shape(Shape::Circle, Qt::blue, QRect(11, 253, 188, 146)))); doc->undoStack()->endMacro(); }
void MainWindow::addShape() { Document *doc = currentDocument(); if (doc == 0) return; Shape::Type type; if (sender() == actionAddCircle) type = Shape::Circle; else if (sender() == actionAddRectangle) type = Shape::Rectangle; else if (sender() == actionAddTriangle) type = Shape::Triangle; else return; Shape newShape(type, randomColor(), randomRect(doc->size())); doc->undoStack()->push(new AddShapeCommand(doc, newShape)); }
void MainWindow::closeDocument() { Document *doc = currentDocument(); if (doc == 0) return; if (!doc->undoStack()->isClean()) { int button = QMessageBox::warning(this, tr("Unsaved changes"), tr("Would you like to save this document?"), QMessageBox::Yes, QMessageBox::No); if (button == QMessageBox::Yes) saveDocument(); } removeDocument(doc); delete doc; }
void MainWindow::addRobot() { Document *doc = currentDocument(); if (doc == 0) return; // Compose a macro command by explicitly adding children to a parent command QUndoCommand *parent = new QUndoCommand(tr("Add robot")); new AddShapeCommand(doc, Shape(Shape::Rectangle, Qt::green, QRect(115, 15, 81, 70)), parent); new AddShapeCommand(doc, Shape(Shape::Rectangle, Qt::green, QRect(82, 89, 148, 188)), parent); new AddShapeCommand(doc, Shape(Shape::Rectangle, Qt::green, QRect(76, 280, 80, 165)), parent); new AddShapeCommand(doc, Shape(Shape::Rectangle, Qt::green, QRect(163, 280, 80, 164)), parent); new AddShapeCommand(doc, Shape(Shape::Circle, Qt::blue, QRect(116, 25, 80, 50)), parent); new AddShapeCommand(doc, Shape(Shape::Rectangle, Qt::green, QRect(232, 92, 80, 127)), parent); new AddShapeCommand(doc, Shape(Shape::Rectangle, Qt::green, QRect(2, 92, 80, 125)), parent); doc->undoStack()->push(parent); }
bool pTabbedWorkspace::eventFilter( QObject* o, QEvent* e ) { // get event type QEvent::Type t = e->type(); // get document QWidget* td = qobject_cast<QWidget*>( o ); // child modified state if ( t == QEvent::ModifiedChange ) mTabBar->setTabText( indexOf( td ), td->windowTitle().append( td->isWindowModified() ? QString( "*" ) : QString::null ) ); // if mode is toplevel and event is activate, activate correct window if needed else if ( mTabMode == tmTopLevel && t == QEvent::WindowActivate ) { if ( td && td != currentDocument() ) setCurrentDocument( td ); } // remove document from workspace else if ( t == QEvent::Close && td ) { // get closeevent QCloseEvent* ce = static_cast<QCloseEvent*>( e ); // emit that document will be close, giving event so user can cancel it emit aboutToCloseTab( indexOf( td ), ce ); emit aboutToCloseDocument( td, ce ); // close document if accepted if ( !ce->isAccepted() && td->property( "ForceClose" ).toBool() && !td->testAttribute( Qt::WA_DeleteOnClose ) ) td->deleteLater(); else if ( ce->isAccepted() && !td->testAttribute( Qt::WA_DeleteOnClose ) ) removeDocument( td ); else return true; } // return default event filter return QWidget::eventFilter( o, e ); }
static void v8HTMLImageElementConstructorMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& args) { if (!args.IsConstructCall()) { throwTypeError("DOM object constructor cannot be called as a function.", args.GetIsolate()); return; } if (ConstructorMode::current() == ConstructorMode::WrapExistingObject) { v8SetReturnValue(args, args.Holder()); return; } Document* document = currentDocument(); ASSERT(document); // Make sure the document is added to the DOM Node map. Otherwise, the HTMLImageElement instance // may end up being the only node in the map and get garbage-collected prematurely. // FIXME: The correct way to do this would be to make HTMLImageElement derive from // ActiveDOMObject and use its interface to keep its wrapper alive. Then we would // remove this code and the special case in isObservableThroughDOM. toV8(document, args.Holder(), args.GetIsolate()); int width; int height; int* optionalWidth = 0; int* optionalHeight = 0; if (args.Length() > 0) { width = toInt32(args[0]); optionalWidth = &width; } if (args.Length() > 1) { height = toInt32(args[1]); optionalHeight = &height; } RefPtr<HTMLImageElement> image = HTMLImageElement::createForJSConstructor(*document, optionalWidth, optionalHeight); v8::Handle<v8::Object> wrapper = args.Holder(); V8DOMWrapper::associateObjectWithWrapper<V8HTMLImageElement>(image.release(), &V8HTMLImageElementConstructor::info, wrapper, args.GetIsolate(), WrapperConfiguration::Dependent); v8SetReturnValue(args, wrapper); }
void MainWindow::updateActions() { Document *doc = currentDocument(); m_undoGroup->setActiveStack(doc == 0 ? 0 : doc->undoStack()); QString shapeName = doc == 0 ? QString() : doc->currentShapeName(); actionAddRobot->setEnabled(doc != 0); actionAddSnowman->setEnabled(doc != 0); actionAddCircle->setEnabled(doc != 0); actionAddRectangle->setEnabled(doc != 0); actionAddTriangle->setEnabled(doc != 0); actionClose->setEnabled(doc != 0); actionSave->setEnabled(doc != 0 && !doc->undoStack()->isClean()); undoLimit->setEnabled(doc != 0 && doc->undoStack()->count() == 0); if (shapeName.isEmpty()) { actionRed->setEnabled(false); actionGreen->setEnabled(false); actionBlue->setEnabled(false); actionRemoveShape->setEnabled(false); } else { Shape shape = doc->shape(shapeName); actionRed->setEnabled(shape.color() != Qt::red); actionGreen->setEnabled(shape.color() != Qt::green); actionBlue->setEnabled(shape.color() != Qt::blue); actionRemoveShape->setEnabled(true); } if (doc != 0) { int index = documentTabs->indexOf(doc); Q_ASSERT(index != -1); static const QIcon unsavedIcon(":/icons/filesave.png"); documentTabs->setTabIcon(index, doc->undoStack()->isClean() ? QIcon() : unsavedIcon); if (doc->undoStack()->count() == 0) doc->undoStack()->setUndoLimit(undoLimit->value()); } }
static void V8TestNamedConstructorConstructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { if (!info.IsConstructCall()) { throwTypeError(ExceptionMessages::failedToConstruct("Audio", "Please use the 'new' operator, this DOM object constructor cannot be called as a function."), info.GetIsolate()); return; } if (ConstructorMode::current() == ConstructorMode::WrapExistingObject) { v8SetReturnValue(info, info.Holder()); return; } Document* document = currentDocument(); ASSERT(document); // Make sure the document is added to the DOM Node map. Otherwise, the TestNamedConstructor instance // may end up being the only node in the map and get garbage-collected prematurely. toV8(document, info.Holder(), info.GetIsolate()); ExceptionState exceptionState(ExceptionState::ConstructionContext, "TestNamedConstructor", info.Holder(), info.GetIsolate()); if (UNLIKELY(info.Length() < 1)) { exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(1, info.Length())); exceptionState.throwIfNeeded(); return; } V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, str1, info[0]); V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, str2, info[1]); V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, str3, argumentOrNull(info, 2)); RefPtr<TestNamedConstructor> impl = TestNamedConstructor::createForJSConstructor(*document, str1, str2, str3, exceptionState); v8::Handle<v8::Object> wrapper = info.Holder(); if (exceptionState.throwIfNeeded()) return; V8DOMWrapper::associateObjectWithWrapper<V8TestNamedConstructor>(impl.release(), &V8TestNamedConstructorConstructor::wrapperTypeInfo, wrapper, info.GetIsolate(), WrapperConfiguration::Dependent); v8SetReturnValue(info, wrapper); }