Skip to content
Merged
17 changes: 11 additions & 6 deletions PythonScript/res/PythonScript.rc
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_UK
// TEXTINCLUDE
//

1 TEXTINCLUDE
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END

2 TEXTINCLUDE
2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END

3 TEXTINCLUDE
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
Expand Down Expand Up @@ -68,9 +68,9 @@ STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSM
CAPTION "Python Script"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
EDITTEXT IDC_INPUT,28,156,121,14,ES_AUTOHSCROLL | ES_WANTRETURN
PUSHBUTTON "Run",IDC_RUN,152,156,40,14
LTEXT ">>>",IDC_PROMPT,7,161,17,8
PUSHBUTTON "Run",IDC_RUN,152,156,40,13
LTEXT ">>>",IDC_PROMPT,7,158,17,11
COMBOBOX IDC_COMBO1,25,156,125,50,CBS_DROPDOWN | CBS_HASSTRINGS | CBS_AUTOHSCROLL | WS_VSCROLL | WS_TABSTOP
END

IDD_SCRIPTCONFIG DIALOGEX 0, 0, 377, 404
Expand Down Expand Up @@ -204,6 +204,11 @@ BEGIN
0
END

IDD_CONSOLE AFX_DIALOG_LAYOUT
BEGIN
0
END

#endif // English (United Kingdom) resources
/////////////////////////////////////////////////////////////////////////////

Expand Down
7 changes: 4 additions & 3 deletions PythonScript/res/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#define IDI_ICON1 114
#define IDD_PROMPTDIALOG 116
#define IDB_PYTHONPOWERED 118
#define IDC_INPUT 1001
#define IDC_COMBO1 1001
#define IDC_RUN 1002
#define IDC_PROMPT 1003
#define IDC_FILETREE 1004
Expand All @@ -43,13 +43,14 @@
#define IDC_CHECKCOLORIZEOUTPUT 1023
#define IDC_COLORCHOOSER 1024


// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 121
#define _APS_NEXT_RESOURCE_VALUE 122
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1025
#define _APS_NEXT_CONTROL_VALUE 1028
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
52 changes: 43 additions & 9 deletions PythonScript/src/ConfigFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,31 @@ void ConfigFile::readConfig()

while (startupFile.good())
{
tstring scriptFullPath = _T("");
startupFile.getline(buffer, 500);
char *context;
char *element = strtok_s(buffer, "/", &context);
if (element)
{

// Menu item
if (0 == strcmp(element, "ITEM"))
{
element = strtok_s(NULL, "/", &context);
m_menuItems.push_back(tstring(WcharMbcsConverter::char2tchar(element).get()));
m_menuScripts.push_back(tstring(WcharMbcsConverter::char2tchar(element).get()));
scriptFullPath = expandPathIfNeeded(element);
if (scriptFullPath != L"")
{
m_menuItems.push_back(scriptFullPath);
m_menuScripts.push_back(scriptFullPath);
}
}

// Toolbar item
else if (0 == strcmp(element, "TOOLBAR"))
{
tstring iconFullPath = _T("");
element = strtok_s(NULL, "/", &context);
scriptFullPath = expandPathIfNeeded(element);

char *iconPath = strtok_s(NULL, "/", &context);
if (!iconPath || !(*iconPath))
{
Expand All @@ -88,11 +95,13 @@ void ConfigFile::readConfig()
}
else
{
hIcon = static_cast<HBITMAP>(LoadImage(NULL, WcharMbcsConverter::char2tchar(iconPath).get(), IMAGE_BITMAP, 16, 16, LR_LOADMAP3DCOLORS | LR_LOADFROMFILE));
iconFullPath = expandPathIfNeeded(iconPath);
hIcon = static_cast<HBITMAP>(LoadImage(NULL, iconFullPath.c_str(), IMAGE_BITMAP, 16, 16, LR_LOADMAP3DCOLORS | LR_LOADFROMFILE));
}
if (scriptFullPath != L"")
{
m_toolbarItems.push_back(std::pair<tstring, std::pair<HBITMAP, tstring> >(scriptFullPath, std::pair<HBITMAP, tstring>(hIcon, iconPath ? iconFullPath : tstring())));
}


m_toolbarItems.push_back(std::pair<tstring, std::pair<HBITMAP, tstring> >(tstring(WcharMbcsConverter::char2tchar(element).get()), std::pair<HBITMAP, tstring>(hIcon, iconPath ? tstring(WcharMbcsConverter::char2tchar(iconPath).get()) : tstring())));
}
else if (0 == strcmp(element, "SETTING"))
{
Expand All @@ -113,19 +122,44 @@ void ConfigFile::clearItems()
m_toolbarItems.erase(m_toolbarItems.begin(), m_toolbarItems.end());
}

tstring ConfigFile::expandPathIfNeeded(char *userPath)
{
tstring fullPath = L"";
if (userPath)
{
if ((userPath[1] == ':') || (userPath[1] == '\\'))
{
fullPath = WcharMbcsConverter::char2tchar(userPath).get();
}
else
{
fullPath.append(m_userScriptsDir).append(tstring(WcharMbcsConverter::char2tchar(userPath).get()));
}
}
return fullPath;
}

std::string ConfigFile::shortenPathIfPossible(tstring userPath)
{
std::string userScriptsDir(WcharMbcsConverter::tchar2char((m_userScriptsDir).c_str()).get());
std::string fullPath = WcharMbcsConverter::tchar2char((userPath).c_str()).get();
return (fullPath.find(userScriptsDir, 0) == 0) ? fullPath.replace(0, userScriptsDir.length(), "") : fullPath;
}

void ConfigFile::save()
{
//just char(UTF8) as TCHAR is not working as expected, because stream is converted to char implicitly
//see also https://www.codeproject.com/Articles/38242/Reading-UTF-with-C-streams

std::ofstream startupFile(m_configFilename.c_str(), std::ios_base::out | std::ios_base::trunc);
for(MenuItemsTD::iterator it = m_menuItems.begin(); it != m_menuItems.end(); ++it)
{
startupFile << "ITEM/" << WcharMbcsConverter::tchar2char((*it).c_str()).get() << "\n";
startupFile << "ITEM/" << shortenPathIfPossible(*it) << "\n";
}

for(ToolbarItemsTD::iterator it = m_toolbarItems.begin(); it != m_toolbarItems.end(); ++it)
{
startupFile << "TOOLBAR/" << WcharMbcsConverter::tchar2char((it->first).c_str()).get() << "/" << WcharMbcsConverter::tchar2char((it->second.second).c_str()).get() << "\n";
startupFile << "TOOLBAR/" << shortenPathIfPossible(it->first) << "/" << shortenPathIfPossible(it->second.second) << "\n";
}

for(SettingsTD::iterator it = m_settings.begin(); it != m_settings.end(); ++it)
Expand Down
2 changes: 2 additions & 0 deletions PythonScript/src/ConfigFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class ConfigFile

void refresh() { clearItems(); readConfig(); };

std::string shortenPathIfPossible(tstring userPath);
tstring expandPathIfNeeded(char *userPath);

const tstring& getMachineScriptsDir() { return m_machineScriptsDir; };
const tstring& getUserScriptsDir() { return m_userScriptsDir; };
Expand Down
Loading