Skip to content

Commit 74affad

Browse files
GurliGebisdonho
authored andcommitted
Always initialize variables
and adds more logging, to help debug issues with the context menu. Close #51
1 parent 58ecdae commit 74affad

4 files changed

+18
-13
lines changed

ClassicEditWithNppExplorerCommandHandler.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ const EXPCMDSTATE ClassicEditWithNppExplorerCommandHandler::State(IShellItemArra
2424
UNREFERENCED_PARAMETER(psiItemArray);
2525

2626
// First we get the current state, before we clear it.
27-
CounterState currentState = state->GetState();
28-
state->SetState(NotSet);
27+
CounterState currentState = state->GetState(L"ClassicEditWithNppExplorerCommandHandler");
28+
state->SetState(L"ClassicEditWithNppExplorerCommandHandler", NotSet);
2929

3030
g_loggingHelper.LogMessage(L"ClassicEditWithNppExplorerCommandHandler::State", L"Current state: " + std::to_wstring(currentState));
3131

ModernEditWithNppExplorerCommandHandler.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ const EXPCMDSTATE ModernEditWithNppExplorerCommandHandler::State(IShellItemArray
2323
{
2424
UNREFERENCED_PARAMETER(psiItemArray);
2525

26-
state->SetState(Set);
26+
state->SetState(L"ModernEditWithNppExplorerCommandHandler", Set);
2727

28-
g_loggingHelper.LogMessage(L"ModernEditWithNppExplorerCommandHandler::State", L"Current state: " + std::to_wstring(state->GetState()));
28+
g_loggingHelper.LogMessage(L"ModernEditWithNppExplorerCommandHandler::State", L"Current state: " + std::to_wstring(state->GetState(L"ModernEditWithNppExplorerCommandHandler")));
2929

3030
return ECS_ENABLED;
3131
}

SharedState.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,20 @@ SharedState::~SharedState()
4646
CloseHandle(hFileMapping);
4747
}
4848

49-
CounterState SharedState::GetState() const
49+
CounterState SharedState::GetState(const wstring caller) const
5050
{
51-
return *pState;
51+
WaitForSingleObject(hMutex, INFINITE);
52+
CounterState value = *pState;
53+
g_loggingHelper.LogMessage(L"SharedState::GetState", L"Get shared state by caller: " + caller);
54+
ReleaseMutex(hMutex);
55+
56+
return value;
5257
}
5358

54-
void SharedState::SetState(CounterState state)
59+
void SharedState::SetState(const wstring caller, const CounterState state)
5560
{
5661
WaitForSingleObject(hMutex, INFINITE);
5762
*pState = state;
58-
g_loggingHelper.LogMessage(L"SharedState::SetState", L"Set shared state to: " + to_wstring(state));
63+
g_loggingHelper.LogMessage(L"SharedState::SetState", L"Set shared state to: " + to_wstring(state) + L" by caller: " + caller);
5964
ReleaseMutex(hMutex);
6065
}

SharedState.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ namespace NppShell::Helpers
1414
SharedState();
1515
~SharedState();
1616

17-
CounterState GetState() const;
18-
void SetState(CounterState state);
17+
CounterState GetState(const wstring caller) const;
18+
void SetState(const wstring caller, const CounterState state);
1919

2020
private:
21-
HANDLE hFileMapping;
22-
HANDLE hMutex;
23-
CounterState* pState;
21+
HANDLE hFileMapping = 0;
22+
HANDLE hMutex = 0;
23+
CounterState* pState = 0;
2424
};
2525
}

0 commit comments

Comments
 (0)