mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 03:07:04 +02:00
* Added localization code to pipeline and created one LocProject json for Settings * Fixed typo * Reordered nuget source * Moved nuget install to restore step * Added FZ.rc file to LocProj * Added FZ resx file and modified rc file * Fixed file names * Changed to check folder for LocProject files * Updated folder * Changed directory * Changed to src directory * Changed language set and name format, removed rc file localization * Added all projects with resx/resw files * Added newline to end of file * Removed nuget source as it is not used * Updated comments * Updated keyboard manager to use resx file * Tweaked resources.resx and added it to project files * Added comments and added in string table to resx script * Remove change from bad merge * Fix syntax error in convert stringtable * Changed file type to None * Migrated color picker's resources * Migrated resources for Microsoft.Launcher * Migrated resources for fancy zones * Revert fancyzones changes * Migrated resources for ImageResizer and modified script to add language specific code * Added try catch and checks for modification to avoid unnecessary file creation * Changed tab insertion to 4 spaces to avoid mixed file types in rc file * Migrated resources for power preview project * Added LocProject.json file for 5 projects * added resgen exception check * Moved non-localizable strings out of resx for powerpreview
201 lines
5.4 KiB
C++
201 lines
5.4 KiB
C++
#include "pch.h"
|
|
#include <settings_objects.h>
|
|
#include <common.h>
|
|
#include "powerpreview.h"
|
|
#include "trace.h"
|
|
#include "settings.h"
|
|
#include "Generated Files/resource.h"
|
|
|
|
// Destroy the powertoy and free memory.
|
|
void PowerPreviewModule::destroy()
|
|
{
|
|
Trace::Destroyed();
|
|
for (auto previewHandler : this->m_previewHandlers)
|
|
{
|
|
if (previewHandler != NULL)
|
|
{
|
|
// Disable all the active preview handlers.
|
|
if (this->m_enabled && previewHandler->GetToggleSettingState())
|
|
{
|
|
previewHandler->DisablePreview();
|
|
}
|
|
|
|
delete previewHandler;
|
|
}
|
|
}
|
|
|
|
for (auto thumbnailProvider : this->m_thumbnailProviders)
|
|
{
|
|
if (thumbnailProvider != NULL)
|
|
{
|
|
// Disable all the active thumbnail providers.
|
|
if (this->m_enabled && thumbnailProvider->GetToggleSettingState())
|
|
{
|
|
thumbnailProvider->DisablePreview();
|
|
}
|
|
|
|
delete thumbnailProvider;
|
|
}
|
|
}
|
|
|
|
delete this;
|
|
}
|
|
|
|
// Return the display name of the powertoy, this will be cached.
|
|
const wchar_t* PowerPreviewModule::get_name()
|
|
{
|
|
return m_moduleName.c_str();
|
|
}
|
|
|
|
// Return JSON with the configuration options.
|
|
bool PowerPreviewModule::get_config(_Out_ wchar_t* buffer, _Out_ int* buffer_size)
|
|
{
|
|
HINSTANCE hinstance = reinterpret_cast<HINSTANCE>(&__ImageBase);
|
|
|
|
// Create a Settings object.
|
|
PowerToysSettings::Settings settings(hinstance, get_name());
|
|
|
|
// General Settings.
|
|
settings.set_description(GET_RESOURCE_STRING(IDS_GENERAL_DESCRIPTION));
|
|
settings.set_icon_key(GET_RESOURCE_STRING(IDS_ICON_KEY_NAME));
|
|
settings.set_overview_link(L"https://aka.ms/PowerToysOverview_FileExplorerAddOns");
|
|
|
|
// Preview Pane: Settings Group Header.
|
|
settings.add_header_szLarge(
|
|
GET_RESOURCE_STRING(IDS_PRVPANE_FILE_PREV_STTNGS_GROUP_HEADER_ID),
|
|
GET_RESOURCE_STRING(IDS_PRVPANE_FILE_PREV_STTNGS_GROUP_DESC),
|
|
GET_RESOURCE_STRING(IDS_PRVPANE_FILE_PREV_STTNGS_GROUP_TEXT));
|
|
|
|
for (auto previewHandler : this->m_previewHandlers)
|
|
{
|
|
settings.add_bool_toggle(
|
|
previewHandler->GetToggleSettingName(),
|
|
previewHandler->GetToggleSettingDescription(),
|
|
previewHandler->GetToggleSettingState());
|
|
}
|
|
|
|
for (auto thumbnailProvider : this->m_thumbnailProviders)
|
|
{
|
|
settings.add_bool_toggle(
|
|
thumbnailProvider->GetToggleSettingName(),
|
|
thumbnailProvider->GetToggleSettingDescription(),
|
|
thumbnailProvider->GetToggleSettingState());
|
|
}
|
|
|
|
return settings.serialize_to_buffer(buffer, buffer_size);
|
|
}
|
|
|
|
// Called by the runner to pass the updated settings values as a serialized JSON.
|
|
void PowerPreviewModule::set_config(const wchar_t* config)
|
|
{
|
|
try
|
|
{
|
|
PowerToysSettings::PowerToyValues settings = PowerToysSettings::PowerToyValues::from_json_string(config);
|
|
|
|
for (auto previewHandler : this->m_previewHandlers)
|
|
{
|
|
previewHandler->UpdateState(settings, this->m_enabled);
|
|
}
|
|
|
|
for (auto thumbnailProvider : this->m_thumbnailProviders)
|
|
{
|
|
thumbnailProvider->UpdateState(settings, this->m_enabled);
|
|
}
|
|
|
|
settings.save_to_settings_file();
|
|
}
|
|
catch (std::exception const& e)
|
|
{
|
|
Trace::SetConfigInvalidJSON(e.what());
|
|
}
|
|
}
|
|
|
|
// Enable preview handlers.
|
|
void PowerPreviewModule::enable()
|
|
{
|
|
for (auto previewHandler : this->m_previewHandlers)
|
|
{
|
|
if (previewHandler->GetToggleSettingState())
|
|
{
|
|
// Enable all the previews with initial state set as true.
|
|
previewHandler->EnablePreview();
|
|
}
|
|
else
|
|
{
|
|
previewHandler->DisablePreview();
|
|
}
|
|
}
|
|
|
|
for (auto thumbnailProvider : this->m_thumbnailProviders)
|
|
{
|
|
if (thumbnailProvider->GetToggleSettingState())
|
|
{
|
|
// Enable all the thumbnail providers with initial state set as true.
|
|
thumbnailProvider->EnableThumbnailProvider();
|
|
}
|
|
else
|
|
{
|
|
thumbnailProvider->DisableThumbnailProvider();
|
|
}
|
|
}
|
|
|
|
if (!this->m_enabled)
|
|
{
|
|
Trace::EnabledPowerPreview(true);
|
|
}
|
|
|
|
this->m_enabled = true;
|
|
}
|
|
|
|
// Disable active preview handlers.
|
|
void PowerPreviewModule::disable()
|
|
{
|
|
for (auto previewHandler : this->m_previewHandlers)
|
|
{
|
|
previewHandler->DisablePreview();
|
|
}
|
|
|
|
for (auto thumbnailProvider : this->m_thumbnailProviders)
|
|
{
|
|
thumbnailProvider->DisableThumbnailProvider();
|
|
}
|
|
|
|
if (this->m_enabled)
|
|
{
|
|
Trace::EnabledPowerPreview(false);
|
|
}
|
|
|
|
this->m_enabled = false;
|
|
}
|
|
|
|
// Returns if the powertoys is enabled
|
|
bool PowerPreviewModule::is_enabled()
|
|
{
|
|
return this->m_enabled;
|
|
}
|
|
|
|
// Load the settings file.
|
|
void PowerPreviewModule::init_settings()
|
|
{
|
|
try
|
|
{
|
|
// Load and parse the settings file for this PowerToy.
|
|
PowerToysSettings::PowerToyValues settings =
|
|
PowerToysSettings::PowerToyValues::load_from_settings_file(PowerPreviewModule::get_name());
|
|
|
|
// Load settings states.
|
|
for (auto previewHandler : this->m_previewHandlers)
|
|
{
|
|
previewHandler->LoadState(settings);
|
|
}
|
|
|
|
for (auto thumbnailProvider : this->m_thumbnailProviders)
|
|
{
|
|
thumbnailProvider->LoadState(settings);
|
|
}
|
|
}
|
|
catch (std::exception const& e)
|
|
{
|
|
Trace::InitSetErrorLoadingFile(e.what());
|
|
}
|
|
} |