Skip to content

Commit

Permalink
Refactor skin scanning and skin folder indexing into SkinRegistry.cpp
Browse files Browse the repository at this point in the history
This also adds tests.
  • Loading branch information
poiru committed Jun 16, 2013
1 parent 6332702 commit 5c91ab3
Show file tree
Hide file tree
Showing 20 changed files with 565 additions and 310 deletions.
19 changes: 2 additions & 17 deletions Library/CommandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,26 +577,11 @@ void CommandHandler::DoActivateSkinBang(std::vector<std::wstring>& args, MeterWi
{
if (args.size() == 1)
{
int index = GetRainmeter().FindSkinFolderIndex(args[0]);
if (index != -1)
{
const Rainmeter::SkinFolder& skinFolder = GetRainmeter().m_SkinFolders[index];
if (!(skinFolder.active == 1 && skinFolder.files.size() == 1))
{
// Activate the next index.
GetRainmeter().ActivateSkin(index, (skinFolder.active < skinFolder.files.size()) ? skinFolder.active : 0);
}
return;
}
if (GetRainmeter().ActivateSkin(args[0])) return;
}
else if (args.size() > 1)
{
std::pair<int, int> indexes = GetRainmeter().GetMeterWindowIndex(args[0], args[1]);
if (indexes.first != -1 && indexes.second != -1)
{
GetRainmeter().ActivateSkin(indexes.first, indexes.second);
return;
}
if (GetRainmeter().ActivateSkin(args[0], args[1])) return;
}

LogError(L"!ActivateConfig: Invalid parameters");
Expand Down
24 changes: 13 additions & 11 deletions Library/DialogManage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ void DialogManage::TabSkins::Update(MeterWindow* meterWindow, bool deleted)
tvi.item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
tvi.item.iImage = tvi.item.iSelectedImage = 0;

if (!GetRainmeter().m_SkinFolders.empty())
if (!GetRainmeter().m_SkinRegistry.IsEmpty())
{
PopulateTree(item, tvi);
}
Expand Down Expand Up @@ -881,12 +881,12 @@ std::wstring DialogManage::TabSkins::GetTreeSelectionPath(HWND tree)
*/
int DialogManage::TabSkins::PopulateTree(HWND tree, TVINSERTSTRUCT& tvi, int index)
{
int initialLevel = GetRainmeter().m_SkinFolders[index].level;
int initialLevel = GetRainmeter().m_SkinRegistry.GetFolder(index).level;

const size_t max = GetRainmeter().m_SkinFolders.size();
const size_t max = GetRainmeter().m_SkinRegistry.GetFolderCount();
while (index < max)
{
const Rainmeter::SkinFolder& skinFolder = GetRainmeter().m_SkinFolders[index];
const auto& skinFolder = GetRainmeter().m_SkinRegistry.GetFolder(index);
if (skinFolder.level != initialLevel)
{
return index - 1;
Expand All @@ -901,7 +901,7 @@ int DialogManage::TabSkins::PopulateTree(HWND tree, TVINSERTSTRUCT& tvi, int ind

// Add subfolders
if ((index + 1) < max &&
GetRainmeter().m_SkinFolders[index + 1].level == initialLevel + 1)
GetRainmeter().m_SkinRegistry.GetFolder(index + 1).level == initialLevel + 1)
{
index = PopulateTree(tree, tvi, index + 1);
}
Expand Down Expand Up @@ -1048,11 +1048,12 @@ INT_PTR DialogManage::TabSkins::OnCommand(WPARAM wParam, LPARAM lParam)
if (!m_SkinWindow)
{
// Skin not active, load
std::pair<int, int> indexes = GetRainmeter().GetMeterWindowIndex(m_SkinFolderPath, m_SkinFileName);
if (indexes.first != -1 && indexes.second != -1)
const SkinRegistry::Indexes indexes =
GetRainmeter().m_SkinRegistry.FindIndexes(m_SkinFolderPath, m_SkinFileName);
if (indexes.IsValid())
{
m_HandleCommands = false;
GetRainmeter().ActivateSkin(indexes.first, indexes.second);
GetRainmeter().ActivateSkin(indexes.folder, indexes.file);
m_HandleCommands = true;

// Fake selection change to update controls
Expand Down Expand Up @@ -1147,10 +1148,11 @@ INT_PTR DialogManage::TabSkins::OnCommand(WPARAM wParam, LPARAM lParam)
Edit_SetSel((HWND)lParam, LOWORD(sel), HIWORD(sel));

WritePrivateProfileString(m_SkinFolderPath.c_str(), L"LoadOrder", buffer, GetRainmeter().GetIniFile().c_str());
std::pair<int, int> indexes = GetRainmeter().GetMeterWindowIndex(m_SkinWindow);
if (indexes.first != -1)
const SkinRegistry::Indexes indexes = GetRainmeter().m_SkinRegistry.FindIndexes(
m_SkinWindow->GetFolderPath(), m_SkinWindow->GetFileName());
if (indexes.IsValid())
{
GetRainmeter().SetLoadOrder(indexes.first, value);
GetRainmeter().SetLoadOrder(indexes.folder, value);

std::multimap<int, MeterWindow*> windows;
GetRainmeter().GetMeterWindowsByLoadOrder(windows);
Expand Down
7 changes: 7 additions & 0 deletions Library/Library.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,12 @@
<ClCompile Include="Section.cpp">
<PrecompiledHeader>Use</PrecompiledHeader>
</ClCompile>
<ClCompile Include="SkinRegistry.cpp">
<PrecompiledHeader>Use</PrecompiledHeader>
</ClCompile>
<ClCompile Include="SkinRegistry_Test.cpp">
<ExcludedFromBuild>$(ExcludeTests)</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="StdAfx.cpp">
<PrecompiledHeader>Create</PrecompiledHeader>
</ClCompile>
Expand Down Expand Up @@ -352,6 +358,7 @@
<ClInclude Include="RainmeterQuery.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="Section.h" />
<ClInclude Include="SkinRegistry.h" />
<ClInclude Include="StdAfx.h" />
<ClInclude Include="System.h" />
<ClInclude Include="TintedImage.h" />
Expand Down
9 changes: 9 additions & 0 deletions Library/Library.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,12 @@
<ClCompile Include="CommandHandler.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="SkinRegistry.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="SkinRegistry_Test.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="ConfigParser.h">
Expand Down Expand Up @@ -653,6 +659,9 @@
<ClInclude Include="CommandHandler.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="SkinRegistry.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Library.rc">
Expand Down
Loading

0 comments on commit 5c91ab3

Please sign in to comment.