void StudioPaletteCmd::replaceWithCurrentPalette(
    TPaletteHandle *paletteHandle, TPaletteHandle *stdPaletteHandle,
    const TFilePath &fp) {
  StudioPalette *sp = StudioPalette::instance();
  TPalette *palette = sp->getPalette(fp);

  if (!palette || palette->isLocked()) return;

  assert(paletteHandle);
  TPalette *current = paletteHandle->getPalette();

  if (!current) return;
  // keep the studio palette's global name unchanged
  std::wstring oldGlobalName = palette->getGlobalName();

  TPalette *old = palette->clone();
  palette->assign(current);

  // put back the global name
  palette->setGlobalName(oldGlobalName);

  sp->setPalette(fp, current, true);
  TUndoManager::manager()->add(
      new StudioPaletteAssignUndo(fp, old, current->clone(), paletteHandle));

  // Cambio la studioPalette correntette(palette);
  stdPaletteHandle->setPalette(palette);

  stdPaletteHandle->notifyPaletteSwitched();
}
Esempio n. 2
0
/*! Convert level palette to studio palette.
*/
void StudioPaletteTreeViewer::convertToStudioPalette() {
  TFilePath path               = getItemPath(currentItem());
  StudioPalette *studioPalette = StudioPalette::instance();
  if (studioPalette->isPalette(path)) {
    TPalette *palette = studioPalette->getPalette(path);

    if (!palette) {
      error("Can't touch palette");
      return;
    }

    if (m_currentPalette->getPaletteName() != palette->getPaletteName()) {
      error("Can't touch palette");
      return;
    }

    QString question;
    question = QString::fromStdWString(
        L"Convert " + path.getWideString() +
        L" to Studio Palette and Overwrite. \nAre you sure ?");
    int ret = DVGui::MsgBox(question, QObject::tr("Yes"), QObject::tr("No"));
    if (ret == 0 || ret == 2) return;

    // apply global name
    time_t ltime;
    time(&ltime);
    wstring gname = std::to_wstring(ltime) + L"_" + std::to_wstring(rand());
    m_currentPalette->setGlobalName(gname);
    studioPalette->setStylesGlobalNames(m_currentPalette.getPointer());
    studioPalette->save(path, m_currentPalette.getPointer());

    m_currentPalette->setDirtyFlag(false);
    currentItem()->setIcon(0, m_studioPaletteIcon);

  } else
    error("Can't find palette");
}