Skip to content

Commit 949205a

Browse files
author
siska
committed
Add master switch
1 parent bfc53a7 commit 949205a

File tree

7 files changed

+35
-10
lines changed

7 files changed

+35
-10
lines changed

foo_np_adv/events.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include "stdafx.h"
22

3-
43
CEvents *IEvents::m_Events = nullptr;
54
static std::map<pfc::string8, instance_state> c_instst;
65

@@ -43,6 +42,10 @@ void CEvents::Clear() {
4342
}
4443

4544
void CEvents::event_update(uint32_t event) {
45+
if (!IConfig::IsEnabled()) {
46+
return;
47+
}
48+
4649
for (const auto &p : m_instancemap[event]) {
4750
event_item &ievent = (event_item&)p.second;
4851
pfc::string8 state = format_title(ievent.m_script);

foo_np_adv/foo_npa.aps

84 Bytes
Binary file not shown.

foo_np_adv/foo_npa.rc

226 Bytes
Binary file not shown.

foo_np_adv/initquit.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include "stdafx.h"
22

3-
43
class npa_initquit : public initquit {
54
public:
65
void on_init() {
@@ -10,10 +9,12 @@ class npa_initquit : public initquit {
109
IEvents::Destroy();
1110
IWriter::Destroy();
1211

13-
for (t_size i = 0; i < IConfig::Count(); i++) {
14-
const instance_item item = IConfig::Get(i);
15-
if (item.on_exit && item.write_to_file) {
16-
CWriter::Write(write_job(item.filename, item.on_exit_str, item.encoding));
12+
if (IConfig::IsEnabled()) {
13+
for (t_size i = 0; i < IConfig::Count(); i++) {
14+
const instance_item &item = IConfig::Get(i);
15+
if (item.on_exit && item.write_to_file) {
16+
CWriter::Write(write_job(item.filename, item.on_exit_str, item.encoding));
17+
}
1718
}
1819
}
1920
}

foo_np_adv/preferences.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@ using namespace std;
77

88
static const GUID cfg_instance_list_guid =
99
{ 0xAAD2BD90,0xAECA,0x42AA,{0x8B, 0x9D, 0x5A, 0x4B, 0xD9, 0x64, 0xB2, 0x82} };
10+
static const GUID guid_cfg_masterswitch =
11+
{ 0x2130D72F,0x8A53,0x41A5,{0xAE, 0x67, 0xE2, 0x83, 0xD9, 0x2A, 0x7D, 0x43} };
1012

11-
static cfg_objList<instance_item> g_cfg_instance_list(cfg_instance_list_guid);
13+
static cfg_bool cfg_masterswitch(guid_cfg_masterswitch, true);
14+
cfg_bool *IConfig::m_cfg_masterswitch = &cfg_masterswitch;
1215

16+
static cfg_objList<instance_item> g_cfg_instance_list(cfg_instance_list_guid);
1317
cfg_objList<instance_item> *IConfig::m_cfg_objlist = &g_cfg_instance_list;
1418

1519
BOOL CNPAPreferences::OnInitDialog(CWindow, LPARAM)
@@ -34,6 +38,9 @@ BOOL CNPAPreferences::OnInitDialog(CWindow, LPARAM)
3438
m_StaticEncoding = GetDlgItem(IDC_STATIC5);
3539
m_CheckBoxChangesOnly = GetDlgItem(IDC_CHECK5);
3640
m_CheckBoxClipboard = GetDlgItem(IDC_CHECK6);
41+
m_CheckEnabled = GetDlgItem(IDC_ENABLED);
42+
43+
m_CheckEnabled.SetCheck(cfg_masterswitch ? 1 : 0);
3744

3845
SendMessage(m_WinDelaySpin, UDM_SETBUDDY, (WPARAM)(HWND)m_EditDelay, 0);
3946
SendMessage(m_WinDelaySpin, UDM_SETRANGE32, 0, CNPAPreferences::idc_delay_hardlimit);
@@ -228,8 +235,7 @@ void CNPAPreferences::OnBnClickedAdd(UINT, int, CWindow)
228235
return;
229236
}
230237

231-
instance_item item((const char *) CT2CA(str));
232-
g_cfg_instance_list.add_item(item);
238+
g_cfg_instance_list.add_item(instance_item((const char *)CT2CA(str)));
233239
m_ComboBoxInstance.InsertString(m_ComboBoxInstance.GetCount(), str);
234240
ComboInstanceSelect(m_ComboBoxInstance.GetCount() - 1);
235241
}
@@ -644,6 +650,8 @@ void CNPAPreferences::apply()
644650
return;
645651
}
646652

653+
cfg_masterswitch = m_CheckEnabled.IsChecked();
654+
647655
instance_item item = g_cfg_instance_list.get_item(m_curIndex);
648656

649657
pfc::string8 str;
@@ -683,6 +691,10 @@ bool CNPAPreferences::HasChanged()
683691
return false;
684692
}
685693

694+
if (m_CheckEnabled.IsChecked() != cfg_masterswitch) {
695+
return true;
696+
}
697+
686698
instance_item item = g_cfg_instance_list.get_item(m_curIndex);
687699

688700
if (m_CheckBoxLogMode.IsChecked() != item.log_mode) {

foo_np_adv/preferences.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
typedef struct fn_filter_s {
1010
pfc::string8 ext, desc;
11-
fn_filter_s(const char *p_ext,const char *p_desc) : ext(p_ext), desc(p_desc) {}
11+
fn_filter_s(const char *p_ext, const char *p_desc) : ext(p_ext), desc(p_desc) {}
1212
}fn_filter;
1313

1414
class CNPAPreferences : public CDialogImpl<CNPAPreferences>,
@@ -50,6 +50,7 @@ class CNPAPreferences : public CDialogImpl<CNPAPreferences>,
5050
COMMAND_HANDLER_EX(IDC_ON_EXIT, EN_CHANGE, OnChangeDefault)
5151
COMMAND_HANDLER_EX(IDC_CHECK5, BN_CLICKED, OnChangeDefault)
5252
COMMAND_HANDLER_EX(IDC_CHECK6, BN_CLICKED, OnCheckBoxClipboardClick)
53+
COMMAND_HANDLER_EX(IDC_ENABLED, BN_CLICKED, OnChangeDefault)
5354
MSG_WM_CONTEXTMENU(OnContextMenu)
5455
END_MSG_MAP()
5556

@@ -116,6 +117,7 @@ class CNPAPreferences : public CDialogImpl<CNPAPreferences>,
116117
CCheckBox m_CheckBoxOnExit;
117118
CCheckBox m_CheckBoxChangesOnly;
118119
CCheckBox m_CheckBoxClipboard;
120+
CCheckBox m_CheckEnabled;
119121
CEdit m_EditFilename;
120122
CEdit m_EditPattern;
121123
CEdit m_EditDelay;
@@ -170,6 +172,11 @@ class IConfig {
170172
{
171173
return m_cfg_objlist->get_item(i);
172174
}
175+
176+
static bool IsEnabled() {
177+
return m_cfg_masterswitch->get_value();
178+
}
173179
private:
174180
static cfg_objList<instance_item> *m_cfg_objlist;
181+
static cfg_bool *m_cfg_masterswitch;
175182
};

foo_np_adv/resource.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#define IDC_STATIC5 1022
3030
#define IDC_CHECK6 1023
3131
#define IDC_BUTTON4 1024
32+
#define IDC_CHECK7 1025
33+
#define IDC_ENABLED 1025
3234
#define IDC_BUTTON6 1026
3335
#define IDC_CONTEXT_CONFIG 1026
3436

0 commit comments

Comments
 (0)