forked from microsoft/PowerToys
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
User/lamotile/add_powerpreviewsettings (microsoft#1075)
* Added powersettings to PowerToys Settings UI * added settings library * updated settings-web * updated project oncfiguration * updated project onfiguration * updated project .sln file * removed .etl file and added it to git-ignore * separated the PowerPreviewModule into split classes .cpp and .h * moved PowerPreviewModule implemnetations to .cpp file * fixed StringTable formatter * fixed spacing in resource.h * added m_ to member varibales * initiliaze m_isPreviewEnabled in the base class * removed duplication of objects by using pass by refference and std::move * made the getters const * updated naming convention * Split test calsses * Add const string * Replaced move with const string * Made attributes private * Made attributes private * removed unused constructor * Update resource.h formatted resource.h
- Loading branch information
Showing
45 changed files
with
3,362 additions
and
1,832 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include "pch.h" | ||
#include <interface/powertoy_module_interface.h> | ||
#include "trace.h" | ||
#include "powerpreview.h" | ||
|
||
|
||
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) | ||
{ | ||
switch (ul_reason_for_call) | ||
{ | ||
case DLL_PROCESS_ATTACH: | ||
Trace::RegisterProvider(); | ||
break; | ||
case DLL_THREAD_ATTACH: | ||
case DLL_THREAD_DETACH: | ||
break; | ||
case DLL_PROCESS_DETACH: | ||
Trace::UnregisterProvider(); | ||
break; | ||
} | ||
return TRUE; | ||
} | ||
|
||
|
||
extern "C" __declspec(dllexport) PowertoyModuleIface* __cdecl powertoy_create() | ||
{ | ||
return new PowerPreviewModule(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#include "pch.h" | ||
#pragma comment(lib, "windowsapp") | ||
#pragma comment(lib, "shlwapi.lib") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#pragma once | ||
#define WIN32_LEAN_AND_MEAN | ||
#include <windows.h> | ||
#include <Shlwapi.h> | ||
#include <ProjectTelemetry.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
#include "pch.h" | ||
#include <interface/lowlevel_keyboard_event_data.h> | ||
#include <interface/win_hook_event_data.h> | ||
#include <settings_objects.h> | ||
#include <common.h> | ||
#include "powerpreview.h" | ||
#include "trace.h" | ||
#include "settings.h" | ||
#include "resource.h" | ||
|
||
// Destroy the powertoy and free memory. | ||
void PowerPreviewModule::destroy() | ||
{ | ||
Trace::Destroyed(); | ||
delete this; | ||
} | ||
|
||
// Return the display name of the powertoy, this will be cached. | ||
const wchar_t* PowerPreviewModule::get_name() | ||
{ | ||
return m_moduleName.c_str(); | ||
} | ||
|
||
const wchar_t** PowerPreviewModule::get_events() | ||
{ | ||
return nullptr; | ||
} | ||
|
||
// 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)); | ||
|
||
// Explorer: Settings Group Header. | ||
settings.add_header_szLarge( | ||
GET_RESOURCE_STRING(IDS_EXPLR_ICONS_PREV_STTNGS_GROUP_HEADER_ID), | ||
GET_RESOURCE_STRING(IDS_EXPLR_ICONS_PREV_STTNGS_GROUP_DESC), | ||
GET_RESOURCE_STRING(IDS_PRVPANE_FILE_PREV_STTNGS_GROUP_TEXT)); | ||
|
||
// Explorer: SVG Icon Settings. | ||
settings.add_bool_toogle( | ||
m_explrSVGSettings.GetName(), | ||
m_explrSVGSettings.GetDescription(), | ||
m_explrSVGSettings.GetState()); | ||
|
||
// Preview Pane: Settings Group Header. | ||
settings.add_header_szLarge( | ||
GET_RESOURCE_STRING(IDS_PRVPANE_FILE_PREV_STTNGS_GROUP_HEADER_ID), | ||
GET_RESOURCE_STRING(IDS_EXPLR_ICONS_PREV_STTNGS_GROUP_DESC), | ||
GET_RESOURCE_STRING(IDS_EXPLR_ICONS_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()); | ||
|
||
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 values = PowerToysSettings::PowerToyValues::from_json_string(config); | ||
m_explrSVGSettings.UpdateState(values); | ||
m_prevPaneSVGSettings.UpdateState(values); | ||
m_prevPaneMDSettings.UpdateState(values); | ||
values.save_to_settings_file(); | ||
} | ||
catch (std::exception const& e) | ||
{ | ||
Trace::SetConfigInvalidJSON(e.what()); | ||
} | ||
} | ||
|
||
// Enable the powertoy | ||
void PowerPreviewModule::enable() | ||
{ | ||
this->m_enabled = true; | ||
Trace::FilePreviewerIsEnabled(); | ||
} | ||
|
||
// Disable the powertoy | ||
void PowerPreviewModule::disable() | ||
{ | ||
this->m_enabled = false; | ||
Trace::FilePreviewerIsDisabled(); | ||
} | ||
|
||
// Returns if the powertoys is enabled | ||
bool PowerPreviewModule::is_enabled() | ||
{ | ||
return this->m_enabled; | ||
} | ||
|
||
// Handle incoming event, data is event-specific | ||
intptr_t PowerPreviewModule::signal_event(const wchar_t* name, intptr_t data) | ||
{ | ||
return 0; | ||
} | ||
|
||
// 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. | ||
m_explrSVGSettings.LoadState(settings); | ||
m_prevPaneSVGSettings.LoadState(settings); | ||
m_prevPaneMDSettings.LoadState(settings); | ||
} | ||
catch (std::exception const& e) | ||
{ | ||
Trace::InitSetErrorLoadingFile(e.what()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include "pch.h" | ||
#include <interface/powertoy_module_interface.h> | ||
#include <common.h> | ||
#include "trace.h" | ||
#include "settings.h" | ||
|
||
using namespace PowerPreviewSettings; | ||
|
||
extern "C" IMAGE_DOS_HEADER __ImageBase; | ||
|
||
// Implement the PowerToy Module Interface and all the required methods. | ||
class PowerPreviewModule : public PowertoyModuleIface | ||
{ | ||
private: | ||
// The PowerToy state. | ||
bool m_enabled = false; | ||
ExplrSVGSttngs m_explrSVGSettings; | ||
PrevPaneSVGRendrSettings m_prevPaneSVGSettings; | ||
PrevPaneMDRendrSettings m_prevPaneMDSettings; | ||
std::wstring m_moduleName; | ||
|
||
public: | ||
PowerPreviewModule() | ||
: | ||
m_moduleName(GET_RESOURCE_STRING(IDS_MODULE_NAME)), | ||
m_explrSVGSettings(ExplrSVGSttngs()), | ||
m_prevPaneSVGSettings(PrevPaneSVGRendrSettings()), | ||
m_prevPaneMDSettings(PrevPaneMDRendrSettings()) | ||
{ | ||
init_settings(); | ||
}; | ||
|
||
virtual void destroy(); | ||
virtual const wchar_t* get_name(); | ||
virtual const wchar_t** get_events(); | ||
virtual bool get_config(_Out_ wchar_t* buffer, _Out_ int* buffer_size); | ||
virtual void set_config(const wchar_t* config); | ||
virtual void enable(); | ||
virtual void disable(); | ||
virtual bool is_enabled(); | ||
virtual void init_settings(); | ||
virtual intptr_t signal_event(const wchar_t* name, intptr_t data); | ||
virtual void register_system_menu_helper(PowertoySystemMenuIface* helper) override {} | ||
virtual void signal_system_menu_action(const wchar_t* name) override {} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Microsoft Visual C++ generated resource script. | ||
// | ||
#include "resource.h" | ||
|
||
#define APSTUDIO_READONLY_SYMBOLS | ||
///////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Generated from the TEXTINCLUDE 2 resource. | ||
// | ||
#include "winres.h" | ||
|
||
///////////////////////////////////////////////////////////////////////////// | ||
#undef APSTUDIO_READONLY_SYMBOLS | ||
|
||
///////////////////////////////////////////////////////////////////////////// | ||
// English (United States) resources | ||
|
||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) | ||
LANGUAGE 9, 1 | ||
|
||
#ifdef APSTUDIO_INVOKED | ||
///////////////////////////////////////////////////////////////////////////// | ||
// | ||
// TEXTINCLUDE | ||
// | ||
|
||
1 TEXTINCLUDE | ||
BEGIN | ||
"resource.h\0" | ||
END | ||
|
||
2 TEXTINCLUDE | ||
BEGIN | ||
"#include ""winres.h""\r\n" | ||
"\0" | ||
END | ||
|
||
3 TEXTINCLUDE | ||
BEGIN | ||
"\r\n" | ||
"\0" | ||
END | ||
|
||
#endif // APSTUDIO_INVOKED | ||
|
||
#endif // English (United States) resources | ||
///////////////////////////////////////////////////////////////////////////// | ||
STRINGTABLE | ||
BEGIN | ||
IDS_GENERAL_DESCRIPTION L"These settings allow you to manage your Windows File Explorer Addons."; | ||
IDS_MODULE_NAME L"File Explorer Preview"; | ||
IDS_ICON_KEY_NAME L"pt-power-preview"; | ||
IDS_EXPLR_ICONS_PREV_STTNGS_GROUP_HEADER_ID L"EXPLR_ICONS_PREV_STTNGS_GROUP_HEADER_ID"; | ||
IDS_EXPLR_ICONS_PREV_STTNGS_GROUP_DESC L"Settings Group Header Text"; | ||
IDS_EXPLR_ICONS_PREV_STTNGS_GROUP_TEXT L"Explorer Icons"; | ||
IDS_PRVPANE_FILE_PREV_STTNGS_GROUP_HEADER_ID L"PRVPANE_FILE_PREV_STTNGS_GROUP_HEADER_ID"; | ||
IDS_PRVPANE_FILE_PREV_STTNGS_GROUP_DESC L"Settings Group Header Text"; | ||
IDS_PRVPANE_FILE_PREV_STTNGS_GROUP_TEXT L"Preview Pane"; | ||
IDS_PREVPANE_MD_BOOL_TOGGLE_CONTROLL L"PREVPANE_MD_BOOL_TOGGLE_CONTROLL_ID" | ||
IDS_PREVPANE_MD_SETTINGS_DESCRIPTION L"Show Markdown" | ||
IDS_PREVPANE_SVG_BOOL_TOGGLE_CONTROLL L"IDS_PREVPANE_SVG_BOOL_TOGGLE_CONTROLL" | ||
IDS_PREVPANE_SVG_SETTINGS_DESCRIPTION L"Show SVG" | ||
IDS_EXPLR_SVG_BOOL_TOGGLE_CONTROLL L"EXPLR_SVG_BOOL_TOGGLE_CONTROLL" | ||
IDS_EXPLR_SVG_SETTINGS_DESCRIPTION L"Render SVG images" | ||
END | ||
|
||
|
||
#ifndef APSTUDIO_INVOKED | ||
///////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Generated from the TEXTINCLUDE 3 resource. | ||
// | ||
|
||
|
||
///////////////////////////////////////////////////////////////////////////// | ||
#endif // not APSTUDIO_INVOKED |
Oops, something went wrong.