Adding launch button to projects settings, dashboard and flyout

This commit is contained in:
donlaci
2024-07-30 13:03:52 +02:00
parent e16f3ab4e5
commit 2af86355ac
10 changed files with 76 additions and 8 deletions

View File

@@ -196,6 +196,10 @@ public
return gcnew String(CommonSharedConstants::FANCY_ZONES_EDITOR_TOGGLE_EVENT);
}
static String ^ ProjectsLaunchEditorEvent() {
return gcnew String(CommonSharedConstants::PROJECTS_LAUNCH_EDITOR_EVENT);
}
static String ^ ColorPickerSendSettingsTelemetryEvent() {
return gcnew String(CommonSharedConstants::COLOR_PICKER_SEND_SETTINGS_TELEMETRY_EVENT);
}

View File

@@ -41,6 +41,8 @@ namespace CommonSharedConstants
const wchar_t FANCY_ZONES_EDITOR_TOGGLE_EVENT[] = L"Local\\FancyZones-ToggleEditorEvent-1e174338-06a3-472b-874d-073b21c62f14";
const wchar_t PROJECTS_LAUNCH_EDITOR_EVENT[] = L"Local\\Projects-LaunchEditorEvent-a55ff427-cf62-4994-a2cd-9f72139296bf";
const wchar_t SHOW_HOSTS_EVENT[] = L"Local\\Hosts-ShowHostsEvent-5a0c0aae-5ff5-40f5-95c2-20e37ed671f0";
const wchar_t SHOW_HOSTS_ADMIN_EVENT[] = L"Local\\Hosts-ShowHostsAdminEvent-60ff44e2-efd3-43bf-928a-f4d269f98bec";

View File

@@ -16,6 +16,7 @@
#include <shellapi.h>
#include "resource.h"
#include <common/utils/EventWaiter.h>
// Non-localizable
const std::wstring projectsLauncherPath = L"PowerToys.ProjectsLauncher.exe";
@@ -53,6 +54,8 @@ BOOL APIENTRY DllMain(HMODULE /*hModule*/, DWORD ul_reason_for_call, LPVOID /*lp
class ProjectsModuleInterface : public PowertoyModuleIface
{
public:
EventWaiter m_toggleEditorEventWaiter;
// Return the localized display name of the powertoy
virtual PCWSTR get_name() override
{
@@ -219,6 +222,24 @@ public:
app_key = L"Projects";
LoggerHelpers::init_logger(app_key, L"ModuleInterface", "Projects");
init_settings();
m_toggleEditorEvent = CreateDefaultEvent(CommonSharedConstants::PROJECTS_LAUNCH_EDITOR_EVENT);
if (!m_toggleEditorEvent)
{
Logger::error(L"Failed to create launch editor event");
auto message = get_last_error_message(GetLastError());
if (message.has_value())
{
Logger::error(message.value());
}
}
m_toggleEditorEventWaiter = EventWaiter(CommonSharedConstants::PROJECTS_LAUNCH_EDITOR_EVENT, [&](int err) {
if (err == ERROR_SUCCESS)
{
Logger::trace(L"{} event was signaled", CommonSharedConstants::PROJECTS_LAUNCH_EDITOR_EVENT);
launch_editor();
}
});
}
private:

View File

@@ -190,7 +190,7 @@ namespace Microsoft.PowerToys.Run.Plugin.PowerToys
generalSettings.Enabled.Projects,
(_) =>
{
using var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.ShowEnvironmentVariablesSharedEvent());
using var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.ProjectsLaunchEditorEvent());
eventHandle.Set();
return true;
}));

View File

@@ -116,6 +116,14 @@ namespace Microsoft.PowerToys.Settings.UI.Flyout
break;
case ModuleType.Projects: // Launch Projects Editor
using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.ProjectsLaunchEditorEvent()))
{
eventHandle.Set();
}
break;
case ModuleType.ShortcutGuide: // Launch Shortcut Guide
using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.ShortcutGuideTriggerEvent()))
{

View File

@@ -29,12 +29,18 @@
Severity="Informational" />
<controls:SettingsGroup x:Uid="Projects_Activation_GroupSettings" IsEnabled="{x:Bind ViewModel.IsEnabled, Mode=OneWay}">
<tkcontrols:SettingsExpander
<tkcontrols:SettingsCard
x:Uid="Projects_ActivationShortcut"
HeaderIcon="{ui:FontIcon Glyph=&#xEDA7;}"
IsExpanded="True">
HeaderIcon="{ui:FontIcon Glyph=&#xEDA7;}">
<controls:ShortcutControl MinWidth="{StaticResource SettingActionControlMinWidth}" HotkeySettings="{x:Bind Path=ViewModel.Hotkey, Mode=TwoWay}" />
</tkcontrols:SettingsExpander>
</tkcontrols:SettingsCard>
<tkcontrols:SettingsCard
x:Uid="Projects_LaunchEditorButtonControl"
ActionIcon="{ui:FontIcon Glyph=&#xE8A7;}"
Command="{x:Bind ViewModel.LaunchEditorEventHandler}"
HeaderIcon="{ui:FontIcon Glyph=&#xEB3C;}"
IsClickEnabled="True" />
</controls:SettingsGroup>
</StackPanel>
</controls:SettingsPageControl.ModuleContent>

View File

@@ -3143,6 +3143,12 @@ Right-click to remove the key combination, thereby deactivating the shortcut.</v
<data name="Projects_ActivationShortcut.Header" xml:space="preserve">
<value>Activation shortcut</value>
</data>
<data name="Projects_LaunchEditorButtonControl.Description" xml:space="preserve">
<value>Create and manage projects</value>
</data>
<data name="Projects_LaunchEditorButtonControl.Header" xml:space="preserve">
<value>Launch editor</value>
</data>
<data name="LearnMore_Projects.Text" xml:space="preserve">
<value>Learn more about the Projects utility</value>
<comment> Projects is the name of the module. </comment>

View File

@@ -433,9 +433,13 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
private ObservableCollection<DashboardModuleItem> GetModuleItemsProjects()
{
ISettingsRepository<ProjectsSettings> moduleSettingsRepository = SettingsRepository<ProjectsSettings>.GetInstance(new SettingsUtils());
var settings = moduleSettingsRepository.SettingsConfig;
var list = new List<DashboardModuleItem>
{
new DashboardModuleTextItem() { Label = resourceLoader.GetString("Projects_ShortDescription") },
new DashboardModuleShortcutItem() { Label = resourceLoader.GetString("Projects_ShortDescription"), Shortcut = settings.Properties.Hotkey.Value.GetKeysList() },
new DashboardModuleButtonItem() { ButtonTitle = resourceLoader.GetString("Projects_LaunchEditorButtonControl/Header"), IsButtonDescriptionVisible = true, ButtonDescription = resourceLoader.GetString("FancyZones_LaunchEditorButtonControl/Description"), ButtonGlyph = "\uEB3C", ButtonClickHandler = ProjectsLaunchClicked },
};
return new ObservableCollection<DashboardModuleItem>(list);
}
@@ -509,6 +513,12 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
SendConfigMSG("{\"action\":{\"FancyZones\":{\"action_name\":\"ToggledFZEditor\", \"value\":\"\"}}}");
}
private void ProjectsLaunchClicked(object sender, RoutedEventArgs e)
{
// send message to launch the projects editor;
SendConfigMSG("{\"action\":{\"Projects\":{\"action_name\":\"LaunchEditor\", \"value\":\"\"}}}");
}
private void KbmKeyLaunchClicked(object sender, RoutedEventArgs e)
{
var settingsUtils = new SettingsUtils();

View File

@@ -44,6 +44,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
AddFlyoutMenuItem(ModuleType.Hosts);
AddFlyoutMenuItem(ModuleType.PowerLauncher);
AddFlyoutMenuItem(ModuleType.PowerOCR);
AddFlyoutMenuItem(ModuleType.Projects);
AddFlyoutMenuItem(ModuleType.RegistryPreview);
AddFlyoutMenuItem(ModuleType.MeasureTool);
AddFlyoutMenuItem(ModuleType.ShortcutGuide);
@@ -89,6 +90,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
ModuleType.FancyZones => SettingsRepository<FancyZonesSettings>.GetInstance(new SettingsUtils()).SettingsConfig.Properties.FancyzonesEditorHotkey.Value.ToString(),
ModuleType.PowerLauncher => SettingsRepository<PowerLauncherSettings>.GetInstance(new SettingsUtils()).SettingsConfig.Properties.OpenPowerLauncher.ToString(),
ModuleType.PowerOCR => SettingsRepository<PowerOcrSettings>.GetInstance(new SettingsUtils()).SettingsConfig.Properties.ActivationShortcut.ToString(),
ModuleType.Projects => SettingsRepository<ProjectsSettings>.GetInstance(new SettingsUtils()).SettingsConfig.Properties.Hotkey.Value.ToString(),
ModuleType.MeasureTool => SettingsRepository<MeasureToolSettings>.GetInstance(new SettingsUtils()).SettingsConfig.Properties.ActivationShortcut.ToString(),
ModuleType.ShortcutGuide => GetShortcutGuideToolTip(),
_ => string.Empty,

View File

@@ -6,12 +6,11 @@ using System;
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Text.Json;
using Common.UI;
using global::PowerToys.GPOWrapper;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
using Microsoft.PowerToys.Settings.UI.Library.ViewModels.Commands;
namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
@@ -25,6 +24,8 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
private Func<string, int> SendConfigMSG { get; }
public ButtonClickCommand LaunchEditorEventHandler { get; set; }
public ProjectsViewModel(ISettingsUtils settingsUtils, ISettingsRepository<GeneralSettings> settingsRepository, ISettingsRepository<ProjectsSettings> moduleSettingsRepository, Func<string, int> ipcMSGCallBackFunc)
{
ArgumentNullException.ThrowIfNull(settingsUtils);
@@ -47,6 +48,14 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
// set the callback functions value to handle outgoing IPC message.
SendConfigMSG = ipcMSGCallBackFunc;
LaunchEditorEventHandler = new ButtonClickCommand(LaunchEditor);
}
private void LaunchEditor()
{
// send message to launch the zones editor;
SendConfigMSG("{\"action\":{\"Projects\":{\"action_name\":\"LaunchEditor\", \"value\":\"\"}}}");
}
private void InitializeEnabledValue()