void LoadPaletteCommand::onExecute(Context* context) { std::string filename; if (!m_preset.empty()) { filename = get_preset_palette_filename(m_preset); } else { std::string exts = get_readable_palette_extensions(); filename = app::show_file_selector("Load Palette", "", exts, FileSelectorType::Open); } if (!filename.empty()) { base::UniquePtr<doc::Palette> palette(load_palette(filename.c_str())); if (!palette) { Alert::show("Error<<Loading palette file||&Close"); } else { SetPaletteCommand* cmd = static_cast<SetPaletteCommand*>( CommandsModule::instance()->getCommandByName(CommandId::SetPalette)); cmd->setPalette(palette); context->executeCommand(cmd); } } }
void PalettePopup::onLoadPal() { doc::Palette* palette = m_paletteListBox.selectedPalette(); if (!palette) return; SetPaletteCommand* cmd = static_cast<SetPaletteCommand*>( CommandsModule::instance()->getCommandByName(CommandId::SetPalette)); cmd->setPalette(palette); UIContext::instance()->executeCommand(cmd); }
void PalettePopup::onLoadPal() { doc::Palette* palette = m_paletteListBox.selectedPalette(); if (!palette) return; SetPaletteCommand* cmd = static_cast<SetPaletteCommand*>( Commands::instance()->byId(CommandId::SetPalette())); cmd->setPalette(palette); UIContext::instance()->executeCommand(cmd); m_paletteListBox.requestFocus(); }
void PalettePopup::onLoadPal(bool asDefault) { doc::Palette* palette = m_paletteListBox.selectedPalette(); if (!palette) return; SetPaletteCommand* cmd = static_cast<SetPaletteCommand*>( CommandsModule::instance()->getCommandByName(CommandId::SetPalette)); cmd->setPalette(palette); if (asDefault) cmd->setTarget(SetPaletteCommand::Target::App); else cmd->setTarget(SetPaletteCommand::Target::Document); UIContext::instance()->executeCommand(cmd); }
void LoadPaletteCommand::onExecute(Context* context) { std::string filename; if (!m_preset.empty()) { filename = get_preset_palette_filename(m_preset, ".ase"); if (!base::is_file(filename)) filename = get_preset_palette_filename(m_preset, ".gpl"); } else if (!m_filename.empty()) { filename = m_filename; } else { std::string exts = get_readable_palette_extensions(); FileSelectorFiles filenames; if (app::show_file_selector("Load Palette", "", exts, FileSelectorType::Open, filenames)) { filename = filenames.front(); } } // Do nothing if (filename.empty()) return; base::UniquePtr<doc::Palette> palette(load_palette(filename.c_str())); if (!palette) { if (context->isUIAvailable()) Alert::show("Error<<Loading palette file||&Close"); return; } SetPaletteCommand* cmd = static_cast<SetPaletteCommand*>( CommandsModule::instance()->getCommandByName(CommandId::SetPalette)); cmd->setPalette(palette); context->executeCommand(cmd); }