Changed Themes to Layouts

This commit is contained in:
Birunthan Mohanathas
2012-10-02 17:44:47 +03:00
parent 4a15878b9b
commit 3cae4f743c
13 changed files with 196 additions and 176 deletions

View File

@@ -40,7 +40,7 @@ CDialogManage* CDialogManage::c_Dialog = NULL;
*/
CDialogManage::CDialogManage(HWND wnd) : CDialog(wnd),
m_TabSkins(wnd),
m_TabThemes(wnd),
m_TabLayouts(wnd),
m_TabSettings(wnd)
{
}
@@ -63,7 +63,8 @@ void CDialogManage::Open(const WCHAR* name)
if (name)
{
if (_wcsicmp(name, L"Themes") == 0)
if (_wcsicmp(name, L"Layouts") == 0 ||
_wcsicmp(name, L"Themes") == 0) // For backwards compatibility.
{
tab = 1;
}
@@ -146,7 +147,7 @@ CDialog::CTab& CDialogManage::GetActiveTab()
}
else if (sel == 1)
{
return m_TabThemes;
return m_TabLayouts;
}
else // if (sel == 2)
{
@@ -283,7 +284,7 @@ INT_PTR CDialogManage::OnNotify(WPARAM wParam, LPARAM lParam)
{
// Disable all tab windows first
EnableWindow(m_TabSkins.GetWindow(), FALSE);
EnableWindow(m_TabThemes.GetWindow(), FALSE);
EnableWindow(m_TabLayouts.GetWindow(), FALSE);
EnableWindow(m_TabSettings.GetWindow(), FALSE);
GetActiveTab().Activate();
@@ -1321,7 +1322,7 @@ INT_PTR CDialogManage::CTabSkins::OnNotify(WPARAM wParam, LPARAM lParam)
// -----------------------------------------------------------------------------------------------
//
// Themes tab
// Layouts tab
//
// -----------------------------------------------------------------------------------------------
@@ -1329,7 +1330,7 @@ INT_PTR CDialogManage::CTabSkins::OnNotify(WPARAM wParam, LPARAM lParam)
** Constructor.
**
*/
CDialogManage::CTabThemes::CTabThemes(HWND owner) : CTab(Rainmeter->GetResourceInstance(), owner, IDD_MANAGETHEMES_DIALOG, DlgProc)
CDialogManage::CTabLayouts::CTabLayouts(HWND owner) : CTab(Rainmeter->GetResourceInstance(), owner, IDD_MANAGETHEMES_DIALOG, DlgProc)
{
}
@@ -1337,34 +1338,34 @@ CDialogManage::CTabThemes::CTabThemes(HWND owner) : CTab(Rainmeter->GetResourceI
** Called when tab is displayed.
**
*/
void CDialogManage::CTabThemes::Initialize()
void CDialogManage::CTabLayouts::Initialize()
{
m_Initialized = true;
HWND item = GetDlgItem(m_Window, IDC_MANAGETHEMES_LIST);
const std::vector<std::wstring>& themes = Rainmeter->GetAllThemes();
for (int i = 0, isize = themes.size(); i < isize; ++i)
const std::vector<std::wstring>& layouts = Rainmeter->GetAllLayouts();
for (int i = 0, isize = layouts.size(); i < isize; ++i)
{
ListBox_AddString(item, themes[i].c_str());
ListBox_AddString(item, layouts[i].c_str());
}
}
/*
** Dialog procedure for the Themes tab.
** Dialog procedure for the Layouts tab.
**
*/
INT_PTR CALLBACK CDialogManage::CTabThemes::DlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
INT_PTR CALLBACK CDialogManage::CTabLayouts::DlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_COMMAND:
return c_Dialog->m_TabThemes.OnCommand(wParam, lParam);
return c_Dialog->m_TabLayouts.OnCommand(wParam, lParam);
}
return FALSE;
}
INT_PTR CDialogManage::CTabThemes::OnCommand(WPARAM wParam, LPARAM lParam)
INT_PTR CDialogManage::CTabLayouts::OnCommand(WPARAM wParam, LPARAM lParam)
{
switch (LOWORD(wParam))
{
@@ -1407,12 +1408,12 @@ INT_PTR CDialogManage::CTabThemes::OnCommand(WPARAM wParam, LPARAM lParam)
item = GetDlgItem(m_Window, IDC_MANAGETHEMES_EDIT_BUTTON);
EnableWindow(item, TRUE);
const std::vector<std::wstring>& themes = Rainmeter->GetAllThemes();
const std::vector<std::wstring>& layouts = Rainmeter->GetAllLayouts();
item = GetDlgItem(m_Window, IDC_MANAGETHEMES_LIST);
int sel = ListBox_GetCurSel(item);
item = GetDlgItem(m_Window, IDC_MANAGETHEMES_NAME_TEXT);
Edit_SetText(item, themes[sel].c_str());
Edit_SetText(item, layouts[sel].c_str());
}
}
break;
@@ -1423,15 +1424,15 @@ INT_PTR CDialogManage::CTabThemes::OnCommand(WPARAM wParam, LPARAM lParam)
HWND item = GetDlgItem(m_Window, IDC_MANAGETHEMES_NAME_TEXT);
Edit_GetText(item, buffer, MAX_PATH);
std::wstring theme = buffer;
std::wstring path = Rainmeter->GetThemePath();
std::wstring layout = buffer;
std::wstring path = Rainmeter->GetLayoutPath();
CreateDirectory(path.c_str(), 0);
path += theme;
path += layout;
bool alreadyExists = (_waccess(path.c_str(), 0) != -1);
if (alreadyExists)
{
std::wstring text = GetFormattedString(ID_STR_THEMEALREADYEXISTS, theme.c_str());
std::wstring text = GetFormattedString(ID_STR_THEMEALREADYEXISTS, layout.c_str());
if (Rainmeter->ShowMessage(m_Window, text.c_str(), MB_ICONWARNING | MB_YESNO) != IDYES)
{
// Cancel
@@ -1444,7 +1445,7 @@ INT_PTR CDialogManage::CTabThemes::OnCommand(WPARAM wParam, LPARAM lParam)
CreateDirectory(path.c_str(), NULL);
}
path += L"\\Rainmeter.thm";
path += L"\\Rainmeter.ini";
item = GetDlgItem(m_Window, IDC_MANAGETHEMES_EMPTYTHEME_CHECKBOX);
if (Button_GetCheck(item) != BST_CHECKED)
@@ -1482,14 +1483,14 @@ INT_PTR CDialogManage::CTabThemes::OnCommand(WPARAM wParam, LPARAM lParam)
if (SystemParametersInfo(SPI_GETDESKWALLPAPER, MAX_PATH, &buffer, 0))
{
std::wstring::size_type pos = path.find_last_of(L'\\');
path.replace(pos + 1, path.length() - pos - 1, L"RainThemes.bmp");
path.replace(pos + 1, path.length() - pos - 1, L"Wallpaper.bmp");
CSystem::CopyFiles((std::wstring)buffer, path);
}
}
}
else
{
// Create empty theme
// Create empty layout
HANDLE file = CreateFile(path.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (file == INVALID_HANDLE_VALUE)
{
@@ -1504,9 +1505,9 @@ INT_PTR CDialogManage::CTabThemes::OnCommand(WPARAM wParam, LPARAM lParam)
if (!alreadyExists)
{
item = GetDlgItem(m_Window, IDC_MANAGETHEMES_LIST);
ListBox_AddString(item, theme.c_str());
ListBox_AddString(item, layout.c_str());
Rainmeter->ScanForThemes();
Rainmeter->ScanForLayouts();
}
}
break;
@@ -1515,7 +1516,7 @@ INT_PTR CDialogManage::CTabThemes::OnCommand(WPARAM wParam, LPARAM lParam)
{
HWND item = GetDlgItem(m_Window, IDC_MANAGETHEMES_LIST);
int sel = ListBox_GetCurSel(item);
Rainmeter->LoadTheme(Rainmeter->m_Themes[sel]);
Rainmeter->LoadLayout(Rainmeter->m_Layouts[sel]);
}
break;
@@ -1523,11 +1524,11 @@ INT_PTR CDialogManage::CTabThemes::OnCommand(WPARAM wParam, LPARAM lParam)
{
HWND item = GetDlgItem(m_Window, IDC_MANAGETHEMES_LIST);
int sel = ListBox_GetCurSel(item);
const std::vector<std::wstring>& themes = Rainmeter->GetAllThemes();
const std::vector<std::wstring>& layouts = Rainmeter->GetAllLayouts();
std::wstring args = L"\"" + Rainmeter->GetThemePath();
args += themes[sel];
args += L"\\Rainmeter.thm";
std::wstring args = L"\"" + Rainmeter->GetLayoutPath();
args += layouts[sel];
args += L"\\Rainmeter.ini";
args += L'"';
RunFile(Rainmeter->GetSkinEditor().c_str(), args.c_str());
}
@@ -1537,29 +1538,29 @@ INT_PTR CDialogManage::CTabThemes::OnCommand(WPARAM wParam, LPARAM lParam)
{
HWND item = GetDlgItem(m_Window, IDC_MANAGETHEMES_LIST);
int sel = ListBox_GetCurSel(item);
std::vector<std::wstring>& themes = const_cast<std::vector<std::wstring>&>(Rainmeter->GetAllThemes());
std::vector<std::wstring>& layouts = const_cast<std::vector<std::wstring>&>(Rainmeter->GetAllLayouts());
std::wstring text = GetFormattedString(ID_STR_THEMEDELETE, themes[sel].c_str());
std::wstring text = GetFormattedString(ID_STR_THEMEDELETE, layouts[sel].c_str());
if (Rainmeter->ShowMessage(m_Window, text.c_str(), MB_ICONQUESTION | MB_YESNO) != IDYES)
{
// Cancel
break;
}
std::wstring folder = Rainmeter->GetThemePath();
folder += themes[sel];
std::wstring folder = Rainmeter->GetLayoutPath();
folder += layouts[sel];
if (CSystem::RemoveFolder(folder))
{
ListBox_DeleteString(item, sel);
// Remove theme from vector
std::vector<std::wstring>::iterator iter = themes.begin();
for ( ; iter != themes.end(); ++iter)
// Remove layout from vector
std::vector<std::wstring>::iterator iter = layouts.begin();
for ( ; iter != layouts.end(); ++iter)
{
if (wcscmp(themes[sel].c_str(), (*iter).c_str()) == 0)
if (wcscmp(layouts[sel].c_str(), (*iter).c_str()) == 0)
{
themes.erase(iter);
layouts.erase(iter);
break;
}
}

View File

@@ -76,11 +76,11 @@ private:
bool m_IgnoreUpdate;
};
// Themes tab
class CTabThemes : public CTab
// Layouts tab
class CTabLayouts : public CTab
{
public:
CTabThemes(HWND owner);
CTabLayouts(HWND owner);
virtual void Initialize();
@@ -104,7 +104,7 @@ private:
CTab& GetActiveTab();
CTabSkins m_TabSkins;
CTabThemes m_TabThemes;
CTabLayouts m_TabLayouts;
CTabSettings m_TabSettings;
};

View File

@@ -922,7 +922,7 @@ int CRainmeter::Initialize(LPCWSTR iniPath)
m_SkinPath = m_Path + L"Skins\\";
}
// Create user skins, themes, addons, and plugins folders if needed
// Create user skins, layouts, addons, and plugins folders if needed
CreateComponentFolders(bDefaultIniLocation);
delete [] buffer;
@@ -1153,8 +1153,8 @@ void CRainmeter::CreateOptionsFile()
{
CreateDirectory(m_SettingsPath.c_str(), NULL);
std::wstring defaultIni = GetDefaultThemePath();
defaultIni += L"illustro default\\Rainmeter.thm";
std::wstring defaultIni = GetDefaultLayoutPath();
defaultIni += L"illustro default\\Rainmeter.ini";
CSystem::CopyFiles(defaultIni, m_IniFile);
}
@@ -1202,13 +1202,61 @@ void CRainmeter::CreateComponentFolders(bool defaultIniLocation)
}
}
path = GetThemePath();
path = GetLayoutPath();
if (_waccess(path.c_str(), 0) == -1)
{
std::wstring from = GetDefaultThemePath();
if (_waccess(from.c_str(), 0) != -1)
// TODO: If Skin Installer creates Layouts first, old Themes is not migrated.
std::wstring themesPath = m_SettingsPath + L"Themes";
if (_waccess(themesPath.c_str(), 0) != -1)
{
CSystem::CopyFiles(from, m_SettingsPath);
// Migrate Themes into Layouts for backwards compatibility and rename
// Rainmeter.thm to Rainmeter.ini and RainThemes.bmp to Wallpaper.bmp.
MoveFile(themesPath.c_str(), path.c_str());
path += L'*'; // For FindFirstFile.
WIN32_FIND_DATA fd;
HANDLE hFind = FindFirstFile(path.c_str(), &fd);
path.pop_back(); // Remove '*'.
if (hFind != INVALID_HANDLE_VALUE)
{
do
{
if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY &&
wcscmp(L".", fd.cFileName) != 0 &&
wcscmp(L"..", fd.cFileName) != 0)
{
std::wstring layoutFolder = path + fd.cFileName;
layoutFolder += L'\\';
std::wstring file = layoutFolder + L"Rainmeter.thm";
if (_waccess(file.c_str(), 0) != -1)
{
std::wstring newFile = layoutFolder + L"Rainmeter.ini";
MoveFile(file.c_str(), newFile.c_str());
}
file = layoutFolder + L"RainThemes.bmp";
if (_waccess(file.c_str(), 0) != -1)
{
std::wstring newFile = layoutFolder + L"Wallpaper.ini";
MoveFile(file.c_str(), newFile.c_str());
}
}
}
while (FindNextFile(hFind, &fd));
FindClose(hFind);
}
}
else
{
std::wstring from = GetDefaultLayoutPath();
if (_waccess(from.c_str(), 0) != -1)
{
CSystem::CopyFiles(from, m_SettingsPath);
}
}
}
else
@@ -1216,7 +1264,7 @@ void CRainmeter::CreateComponentFolders(bool defaultIniLocation)
path += L"Backup";
if (_waccess(path.c_str(), 0) != -1)
{
std::wstring newPath = GetThemePath();
std::wstring newPath = GetLayoutPath();
newPath += L"@Backup";
MoveFile(path.c_str(), newPath.c_str());
}
@@ -1277,7 +1325,7 @@ void CRainmeter::CreateComponentFolders(bool defaultIniLocation)
void CRainmeter::ReloadSettings()
{
ScanForSkins();
ScanForThemes();
ScanForLayouts();
ReadGeneralSettings(m_IniFile);
}
@@ -1789,17 +1837,17 @@ int CRainmeter::ScanForSkinsRecursive(const std::wstring& path, std::wstring bas
}
/*
** Scans the given folder for themes
** Scans the given folder for layouts
*/
void CRainmeter::ScanForThemes()
void CRainmeter::ScanForLayouts()
{
m_Themes.clear();
m_Layouts.clear();
WIN32_FIND_DATA fileData; // Data structure describes the file found
HANDLE hSearch; // Search handle returned by FindFirstFile
// Scan for folders
std::wstring folders = GetThemePath();
std::wstring folders = GetLayoutPath();
folders += L'*';
hSearch = FindFirstFileEx(
@@ -1818,7 +1866,7 @@ void CRainmeter::ScanForThemes()
wcscmp(L".", fileData.cFileName) != 0 &&
wcscmp(L"..", fileData.cFileName) != 0)
{
m_Themes.push_back(fileData.cFileName);
m_Layouts.push_back(fileData.cFileName);
}
}
while (FindNextFile(hSearch, &fileData));
@@ -2482,15 +2530,15 @@ void CRainmeter::RefreshAll()
CDialogManage::UpdateSkins(NULL);
}
void CRainmeter::LoadTheme(const std::wstring& name)
void CRainmeter::LoadLayout(const std::wstring& name)
{
// Delete all meter windows
DeleteMeterWindow(NULL);
std::wstring backup = GetThemePath();
std::wstring backup = GetLayoutPath();
backup += L"@Backup";
CreateDirectory(backup.c_str(), NULL);
backup += L"\\Rainmeter.thm";
backup += L"\\Rainmeter.ini";
if (_wcsicmp(name.c_str(), L"@Backup") == 0)
{
@@ -2502,12 +2550,12 @@ void CRainmeter::LoadTheme(const std::wstring& name)
// Make a copy of current Rainmeter.ini
CSystem::CopyFiles(m_IniFile, backup);
// Replace Rainmeter.ini with theme
std::wstring theme = GetThemePath();
theme += name;
std::wstring wallpaper = theme + L"\\RainThemes.bmp";
theme += L"\\Rainmeter.thm";
CSystem::CopyFiles(theme, GetIniFile());
// Replace Rainmeter.ini with layout
std::wstring layout = GetLayoutPath();
layout += name;
std::wstring wallpaper = layout + L"\\Wallpaper.bmp";
layout += L"\\Rainmeter.ini";
CSystem::CopyFiles(layout, GetIniFile());
PreserveSetting(backup, L"SkinPath");
PreserveSetting(backup, L"ConfigEditor");
@@ -2797,13 +2845,13 @@ void CRainmeter::ShowContextMenu(POINT pos, CMeterWindow* meterWindow)
}
}
HMENU themeMenu = GetSubMenu(subMenu, 5);
if (themeMenu)
HMENU layoutMenu = GetSubMenu(subMenu, 5);
if (layoutMenu)
{
if (!m_Themes.empty())
if (!m_Layouts.empty())
{
DeleteMenu(themeMenu, 0, MF_BYPOSITION); // "No themes available" menuitem
CreateThemeMenu(themeMenu);
DeleteMenu(layoutMenu, 0, MF_BYPOSITION); // "No layouts available" menuitem
CreateLayoutMenu(layoutMenu);
}
}
@@ -3115,11 +3163,11 @@ HMENU CRainmeter::CreateSkinMenu(CMeterWindow* meterWindow, int index, HMENU men
return skinMenu;
}
void CRainmeter::CreateThemeMenu(HMENU themeMenu)
void CRainmeter::CreateLayoutMenu(HMENU layoutMenu)
{
for (size_t i = 0, isize = m_Themes.size(); i < isize; ++i)
for (size_t i = 0, isize = m_Layouts.size(); i < isize; ++i)
{
InsertMenu(themeMenu, i, MF_BYPOSITION, ID_THEME_FIRST + i, m_Themes[i].c_str());
InsertMenu(layoutMenu, i, MF_BYPOSITION, ID_THEME_FIRST + i, m_Layouts[i].c_str());
}
}

View File

@@ -124,7 +124,7 @@ public:
int FindSkinFolderIndex(const std::wstring& folderPath);
const std::vector<SkinFolder>& GetFolders() { return m_SkinFolders; }
const std::vector<std::wstring>& GetAllThemes() { return m_Themes; }
const std::vector<std::wstring>& GetAllLayouts() { return m_Layouts; }
void DeleteMeterWindow(CMeterWindow* meterWindow, bool force = false);
@@ -138,7 +138,7 @@ public:
const std::wstring& GetLogFile() { return m_LogFile; }
const std::wstring& GetSettingsPath() { return m_SettingsPath; }
const std::wstring& GetSkinPath() { return m_SkinPath; }
std::wstring GetThemePath() { return m_SettingsPath + L"Themes\\"; }
std::wstring GetLayoutPath() { return m_SettingsPath + L"Layouts\\"; }
std::wstring GetPluginPath() { return m_Path + L"Plugins\\"; }
std::wstring GetUserPluginPath() { return m_SettingsPath + L"Plugins\\"; }
std::wstring GetAddonPath() { return m_SettingsPath + L"Addons\\"; }
@@ -146,7 +146,7 @@ public:
bool HasUserPluginPath() { return (_wcsicmp(m_Path.c_str(), m_SettingsPath.c_str()) != 0); }
std::wstring GetDefaultSkinPath() { return m_Path + L"Defaults\\Skins\\"; }
std::wstring GetDefaultThemePath() { return m_Path + L"Defaults\\Themes\\"; }
std::wstring GetDefaultLayoutPath() { return m_Path + L"Defaults\\Layouts\\"; }
std::wstring GetDefaultPluginPath() { return m_Path + L"Defaults\\Plugins\\"; }
std::wstring GetDefaultAddonPath() { return m_Path + L"Defaults\\Addons\\"; }
@@ -215,7 +215,7 @@ public:
void RefreshAll();
void LoadTheme(const std::wstring& name);
void LoadLayout(const std::wstring& name);
void PreserveSetting(const std::wstring& from, LPCTSTR key, bool replace = true);
static std::vector<std::wstring> ParseString(LPCTSTR str, CConfigParser* parser = NULL);
@@ -244,7 +244,7 @@ private:
void CreateMeterWindow(const std::wstring& folderPath, const std::wstring& file);
void WriteActive(const std::wstring& folderPath, int fileIndex);
void ScanForSkins();
void ScanForThemes();
void ScanForLayouts();
void ReadGeneralSettings(const std::wstring& iniFile);
void SetLoadOrder(int folderIndex, int order);
int GetLoadOrder(const std::wstring& folderPath);
@@ -256,7 +256,7 @@ private:
void CreateAllSkinsMenu(HMENU skinMenu) { CreateAllSkinsMenuRecursive(skinMenu, 0); }
int CreateAllSkinsMenuRecursive(HMENU skinMenu, int index);
void CreateThemeMenu(HMENU themeMenu);
void CreateLayoutMenu(HMENU layoutMenu);
void CreateMonitorMenu(HMENU monitorMenu, CMeterWindow* meterWindow);
void CreateOptionsFile();
void CreateDataFile();
@@ -269,7 +269,7 @@ private:
std::vector<SkinFolder> m_SkinFolders;
std::multimap<int, int> m_SkinOrders;
std::map<std::wstring, CMeterWindow*> m_MeterWindows;
std::vector<std::wstring> m_Themes;
std::vector<std::wstring> m_Layouts;
std::wstring m_Path;
std::wstring m_IniFile;

View File

@@ -513,10 +513,10 @@ LRESULT CALLBACK CTrayWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
{
int pos = (wParam & 0x0ffff) - ID_THEME_FIRST;
const std::vector<std::wstring>& themes = Rainmeter->GetAllThemes();
if (pos >= 0 && pos < (int)themes.size())
const std::vector<std::wstring>& layouts = Rainmeter->GetAllLayouts();
if (pos >= 0 && pos < (int)layouts.size())
{
Rainmeter->LoadTheme(themes[pos]);
Rainmeter->LoadLayout(layouts[pos]);
}
}
else if ((wParam & 0x0ffff) >= ID_CONFIG_FIRST && (wParam & 0x0ffff) <= ID_CONFIG_LAST)