Skip to content

Commit

Permalink
improve preview handler intergration (microsoft#1319)
Browse files Browse the repository at this point in the history
* improve preview handler intergration

* Fixed typo

* updated typo

* updated enable() function

* updated is enabled()

* re-updated is enabled()

* added this-> key word
  • Loading branch information
Lavius Motileng authored and udit3333 committed Mar 10, 2020
1 parent d54dafd commit ab14460
Show file tree
Hide file tree
Showing 14 changed files with 301 additions and 544 deletions.
Binary file modified src/modules/previewpane/common/PowerToys - Shortcut.lnk
Binary file not shown.
47 changes: 24 additions & 23 deletions src/modules/previewpane/powerpreview/powerpreview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,13 @@ bool PowerPreviewModule::get_config(_Out_ wchar_t* buffer, _Out_ int* buffer_siz
GET_RESOURCE_STRING(IDS_PRVPANE_FILE_PREV_STTNGS_GROUP_DESC),
GET_RESOURCE_STRING(IDS_PRVPANE_FILE_PREV_STTNGS_GROUP_TEXT));

// Preview Pane: SVG Settings.
settings.add_bool_toogle(
m_prevPaneSVGSettings.GetName(),
m_prevPaneSVGSettings.GetDescription(),
m_prevPaneSVGSettings.GetState());

// Preview Pane: Mark Down Settings.
settings.add_bool_toogle(
m_prevPaneMDSettings.GetName(),
m_prevPaneMDSettings.GetDescription(),
m_prevPaneMDSettings.GetState());
for (FileExplorerPreviewSettings& previewHandler : this->m_previewHandlers)
{
settings.add_bool_toogle(
previewHandler.GetName(),
previewHandler.GetDescription(),
previewHandler.GetState());
}

return settings.serialize_to_buffer(buffer, buffer_size);
}
Expand All @@ -65,8 +61,12 @@ void PowerPreviewModule::set_config(const wchar_t* config)
try
{
PowerToysSettings::PowerToyValues values = PowerToysSettings::PowerToyValues::from_json_string(config);
m_prevPaneSVGSettings.UpdateState(values);
m_prevPaneMDSettings.UpdateState(values);

for (FileExplorerPreviewSettings& previewHandler : this->m_previewHandlers)
{
previewHandler.UpdateState(values);
}

values.save_to_settings_file();
}
catch (std::exception const& e)
Expand All @@ -75,21 +75,20 @@ void PowerPreviewModule::set_config(const wchar_t* config)
}
}

// Enable the powertoy
// Enable preview handlers.
void PowerPreviewModule::enable()
{
m_prevPaneSVGSettings.EnablePreview();
m_prevPaneMDSettings.EnablePreview();
Trace::FilePreviewerIsEnabled();
init_settings();
this->m_enabled = true;
}

// Disable the powertoy
// Disable all preview handlers.
void PowerPreviewModule::disable()
{
m_prevPaneSVGSettings.DisablePreview();
m_prevPaneMDSettings.DisablePreview();
Trace::FilePreviewerIsDisabled();
for (FileExplorerPreviewSettings& previewHandler : this->m_previewHandlers)
{
previewHandler.DisablePreview();
}
this->m_enabled = false;
}

Expand All @@ -115,8 +114,10 @@ void PowerPreviewModule::init_settings()
PowerToysSettings::PowerToyValues::load_from_settings_file(PowerPreviewModule::get_name());

// Load settings states.
m_prevPaneSVGSettings.LoadState(settings);
m_prevPaneMDSettings.LoadState(settings);
for (FileExplorerPreviewSettings& previewHandler : this->m_previewHandlers)
{
previewHandler.LoadState(settings);
}
}
catch (std::exception const& e)
{
Expand Down
24 changes: 18 additions & 6 deletions src/modules/previewpane/powerpreview/powerpreview.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,28 @@ class PowerPreviewModule : public PowertoyModuleIface
private:
// The PowerToy state.
bool m_enabled = false;
PrevPaneSVGRendrSettings m_prevPaneSVGSettings;
PrevPaneMDRendrSettings m_prevPaneMDSettings;
std::wstring m_moduleName;
std::vector<FileExplorerPreviewSettings> m_previewHandlers;

public:
PowerPreviewModule()
:
PowerPreviewModule() :
m_moduleName(GET_RESOURCE_STRING(IDS_MODULE_NAME)),
m_prevPaneSVGSettings(PrevPaneSVGRendrSettings()),
m_prevPaneMDSettings(PrevPaneMDRendrSettings())
m_previewHandlers(
{ // SVG Preview Hanlder settings object.
FileExplorerPreviewSettings(
false,
GET_RESOURCE_STRING(IDS_PREVPANE_SVG_BOOL_TOGGLE_CONTROLL),
GET_RESOURCE_STRING(IDS_PREVPANE_SVG_SETTINGS_DESCRIPTION),
L"{ddee2b8a-6807-48a6-bb20-2338174ff779}",
GET_RESOURCE_STRING(IDS_PREVPANE_SVG_SETTINGS_DISPLAYNAME)),

// MarkDown Preview Handler Settings Object.
FileExplorerPreviewSettings(
false,
GET_RESOURCE_STRING(IDS_PREVPANE_MD_BOOL_TOGGLE_CONTROLL),
GET_RESOURCE_STRING(IDS_PREVPANE_MD_SETTINGS_DESCRIPTION),
L"{45769bcc-e8fd-42d0-947e-02beef77a1f5}",
GET_RESOURCE_STRING(IDS_PREVPANE_MD_SETTINGS_DISPLAYNAME)) })
{
init_settings();
};
Expand Down
Loading

0 comments on commit ab14460

Please sign in to comment.