Пример #1
0
bool ShadowTree::tryCommit(ShadowTreeCommitTransaction transaction) const {
  SystraceSection s("ShadowTree::tryCommit");

  auto telemetry = MountingTelemetry{};
  telemetry.willCommit();

  SharedRootShadowNode oldRootShadowNode;

  {
    // Reading `rootShadowNode_` in shared manner.
    std::shared_lock<better::shared_mutex> lock(commitMutex_);
    oldRootShadowNode = rootShadowNode_;
  }

  UnsharedRootShadowNode newRootShadowNode = transaction(oldRootShadowNode);

  if (!newRootShadowNode) {
    return false;
  }

  std::vector<LayoutableShadowNode const *> affectedLayoutableNodes{};
  affectedLayoutableNodes.reserve(1024);

  telemetry.willLayout();
  newRootShadowNode->layout(&affectedLayoutableNodes);
  telemetry.didLayout();

  newRootShadowNode->sealRecursive();

  auto revisionNumber = ShadowTreeRevision::Number{};

  {
    // Updating `rootShadowNode_` in unique manner if it hasn't changed.
    std::unique_lock<better::shared_mutex> lock(commitMutex_);

    if (rootShadowNode_ != oldRootShadowNode) {
      return false;
    }

    rootShadowNode_ = newRootShadowNode;

    {
      std::lock_guard<std::mutex> dispatchLock(EventEmitter::DispatchMutex());

      updateMountedFlag(
          oldRootShadowNode->getChildren(), newRootShadowNode->getChildren());
    }

    revisionNumber_++;
    revisionNumber = revisionNumber_;
  }

  emitLayoutEvents(affectedLayoutableNodes);

  telemetry.didCommit();

  mountingCoordinator_->push(
      ShadowTreeRevision{newRootShadowNode, revisionNumber, telemetry});

  if (delegate_) {
    delegate_->shadowTreeDidCommit(*this, mountingCoordinator_);
  }

  return true;
}
Пример #2
0
void toMain::commandCallback ( int cmd )
{
    QWidget * focus = qApp->focusWidget();

    if ( focus ) {
        toEditWidget * edit = findEdit ( focus );
        if ( edit && edit != Edit )
            setEditWidget ( edit );
        else if ( focus->inherits ( "QLineEdit" ) ||
                  focus->isA ( "QSpinBox" ) )
            editDisable ( Edit );
    }

    if ( Tools[cmd] )
        Tools[cmd]->createWindow();
    else if ( cmd >= TO_TOOL_ABOUT_ID && cmd <= TO_TOOL_ABOUT_ID_END ) {
        if ( Tools[cmd-TO_ABOUT_ID_OFFSET] )
            Tools[cmd-TO_ABOUT_ID_OFFSET]->about ( this );
    } else if ( cmd >= TO_WINDOWS_WINDOWS && cmd <= TO_WINDOWS_END ) {
        if ( cmd - TO_WINDOWS_WINDOWS < int ( workspace() ->windowList().count() ) )
            workspace() ->windowList().at ( cmd - TO_WINDOWS_WINDOWS ) ->setFocus();
    } else if ( cmd >= TO_STATUS_ID && cmd <= TO_STATUS_ID_END ) {
        QString str = StatusMenu->text ( cmd );
        new toMemoEditor ( this, str );
    } else {
        QWidget *currWidget = qApp->focusWidget();
        toEditWidget *edit = NULL;
        while ( currWidget && !edit ) {
            edit = dynamic_cast<toEditWidget *> ( currWidget );
            currWidget = currWidget->parentWidget();
        }
        if ( edit ) {
            switch ( cmd ) {
            case TO_EDIT_REDO:
                edit->editRedo();
                break;
            case TO_EDIT_UNDO:
                edit->editUndo();
                break;
            case TO_EDIT_COPY:
                edit->editCopy();
                break;
            case TO_EDIT_PASTE:
                edit->editPaste();
                break;
            case TO_EDIT_CUT:
                edit->editCut();
                break;
            case TO_EDIT_SELECT_ALL:
                edit->editSelectAll();;
                break;
            case TO_EDIT_READ_ALL:
                edit->editReadAll();
                break;
            case TO_EDIT_SEARCH:
                if ( !Search )
                    Search = new toSearchReplace ( this );
                edit->editSearch ( Search );
                break;
            case TO_FILE_OPEN:
                edit->editOpen();
                break;
            case TO_FILE_SAVE_AS:
                edit->editSave ( true );
                break;
            case TO_FILE_SAVE:
                edit->editSave ( false );
                break;
            case TO_FILE_PRINT:
                edit->editPrint();
                break;
            }
        }
        switch ( cmd ) {
        case TO_FILE_COMMIT:
            try {
                toConnection & conn = currentConnection();
                emit willCommit ( conn, true );
                conn.commit();
                setNeedCommit ( conn, false );
            }
            TOCATCH
            break;
        case TO_FILE_CLEARCACHE:
            try {
                currentConnection().rereadCache();
            }
            TOCATCH
            toMainWidget() ->checkCaching();
            break;
        case TO_FILE_ROLLBACK:
            try {
                toConnection &conn = currentConnection();
                emit willCommit ( conn, false );
                conn.rollback();
                setNeedCommit ( conn, false );
            }
            TOCATCH
            break;
        case TO_FILE_CURRENT:
            ConnectionSelection->setFocus();
            break;
        case TO_FILE_QUIT:
            close ( true );
            break;
        case TO_EDIT_SEARCH_NEXT:
            if ( Search )
                Search->searchNext();
            break;
        case TO_WINDOWS_CASCADE:
            workspace() ->cascade();
            break;
        case TO_WINDOWS_TILE:
            workspace() ->tile();
            break;
        case TO_NEW_CONNECTION:
            addConnection();
            break;
        case TO_HELP_CONTEXT:
            contextHelp();
            break;
        case TO_HELP_CONTENTS:
            toHelp::displayHelp ( "toc.htm" );
            break;
        case TO_HELP_ABOUT:
        case TO_HELP_LICENSE:
        case TO_HELP_QUOTES: {
            toAbout *about = new toAbout ( cmd - TO_HELP_ABOUT, this, "About TOra", true );
            about->exec();
            delete about;
        }
        break;
        case TO_HELP_REGISTER:
            toCheckLicense ( true );
            break;
        case TO_EDIT_OPTIONS:
            toPreferences::displayPreferences ( this );
            break;
        case TO_WINDOWS_CLOSE_ALL:
            while ( workspace() ->windowList().count() > 0 && workspace() ->windowList().at ( 0 ) )
                if ( workspace() ->windowList().at ( 0 ) &&
                        !workspace() ->windowList().at ( 0 ) ->close ( true ) )
                    return;
            break;
        case TO_WINDOWS_CLOSE:
            QWidget *widget = workspace() ->activeWindow();
            if ( widget )
                widget->close ( true );
            break;
        }
    }
}