Skip to content

Commit 3e3e28e

Browse files
committed
Dynamic Command IDs working (with N++ 5.8) (V0.8)
- Several bugs fixed with dynamic IDs - FIX: setStatusBar did not process unicode correctly (at all, actually) - Altered website for donations to Charity - Altered website for release of v0.8.0.0
1 parent 16d55c5 commit 3e3e28e

18 files changed

+463
-138
lines changed

PythonScript/project/PythonScript2010.vcxproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,12 @@
125125
<Link>
126126
<SubSystem>Windows</SubSystem>
127127
<GenerateDebugInformation>true</GenerateDebugInformation>
128-
<AdditionalDependencies>python26.lib;NppPlugin.lib;shlwapi.lib;comctl32.lib;htmlhelp.lib;%(AdditionalDependencies)</AdditionalDependencies>
128+
<AdditionalDependencies>python27.lib;NppPlugin.lib;shlwapi.lib;comctl32.lib;htmlhelp.lib;%(AdditionalDependencies)</AdditionalDependencies>
129129
<AdditionalLibraryDirectories>C:\Program Files (x86)\HTML Help Workshop\lib</AdditionalLibraryDirectories>
130+
<ShowProgress>LinkVerbose</ShowProgress>
130131
</Link>
131132
<PostBuildEvent>
132-
<Command>copy $(OutDir)$(TargetFileName) "C:\Program Files (x86)\Notepad++\plugins"</Command>
133+
<Command>copy $(OutDir)$(TargetFileName) "C:\Program Files (x86)\Notepad++5.8\plugins"</Command>
133134
</PostBuildEvent>
134135
</ItemDefinitionGroup>
135136
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='DebugStartup|Win32'">
@@ -186,7 +187,7 @@
186187
<GenerateDebugInformation>true</GenerateDebugInformation>
187188
<EnableCOMDATFolding>true</EnableCOMDATFolding>
188189
<OptimizeReferences>true</OptimizeReferences>
189-
<AdditionalDependencies>python26.lib;NppPlugin.lib;shlwapi.lib;comctl32.lib;htmlhelp.lib;%(AdditionalDependencies)</AdditionalDependencies>
190+
<AdditionalDependencies>python27.lib;NppPlugin.lib;shlwapi.lib;comctl32.lib;htmlhelp.lib;%(AdditionalDependencies)</AdditionalDependencies>
190191
<AdditionalLibraryDirectories>C:\Program Files (x86)\HTML Help Workshop\lib</AdditionalLibraryDirectories>
191192
</Link>
192193
</ItemDefinitionGroup>

PythonScript/project/PythonSettings.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<ImportGroup Label="PropertySheets" />
44
<PropertyGroup Label="UserMacros">
5-
<PythonBase>E:\work\Python-2.6.5</PythonBase>
5+
<PythonBase>E:\work\Python-2.7</PythonBase>
66
<PythonLibPath>$(PythonBase)\PCbuild</PythonLibPath>
77
<BoostPythonLibPath>E:\libs\boost\bin.v2\libs\python\build\msvc-10.0\$(Configuration)\link-static\runtime-link-static\threading-multi</BoostPythonLibPath>
88
</PropertyGroup>

PythonScript/src/ConfigFile.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,16 @@ const tstring& ConfigFile::getSetting(const TCHAR *settingName)
147147
{
148148
return m_settings[tstring(settingName)];
149149
}
150+
151+
152+
const std::string& ConfigFile::getMenuScript(int index) const
153+
{
154+
if (m_menuScripts.size() > static_cast<size_t>(index))
155+
{
156+
return m_menuScripts[index];
157+
}
158+
else
159+
{
160+
return m_emptyString;
161+
}
162+
}

PythonScript/src/ConfigFile.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class ConfigFile
2121
// TODO: Need to make these pointers
2222
MenuItemsTD getMenuItems() { return m_menuItems; };
2323
ToolbarItemsTD getToolbarItems() { return m_toolbarItems; };
24-
std::string& getMenuScript(int index) { return m_menuScripts[index]; }
24+
const std::string& getMenuScript(int index) const;
2525

2626
void addMenuItem(const tstring scriptPath);
2727
void addToolbarItem(const tstring scriptPath, const tstring iconPath);
@@ -55,7 +55,12 @@ class ConfigFile
5555

5656
MenuItemsTD m_menuItems;
5757
std::vector< std::string > m_menuScripts;
58-
58+
59+
// Used in case an invalid script number is requested
60+
// so we can return a reference to this puppy instead.
61+
std::string m_emptyString;
62+
63+
5964
ToolbarItemsTD m_toolbarItems;
6065
std::map< tstring, HICON > m_icons;
6166
SettingsTD m_settings;

PythonScript/src/DynamicIDManager.cpp

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,20 @@ using namespace std;
88

99
void DynamicIDManager::reserve(int quantity)
1010
{
11-
if (quantity < m_capacity)
11+
if (quantity > m_capacity)
1212
{
1313
reserveAdditional(quantity - m_capacity);
1414
}
1515
}
1616

17+
void DynamicIDManager::addBlock(int start, int quantity)
18+
{
19+
m_idList.push_back(pair<int, int>(start, quantity));
20+
21+
// Assume no overlaps (should really fix this, but we just need to use this carefully)
22+
m_capacity += quantity;
23+
}
24+
1725
void DynamicIDManager::reserveAdditional(int quantity)
1826
{
1927

@@ -50,8 +58,12 @@ int DynamicIDManager::begin()
5058
m_current = m_idList.begin();
5159
m_nextID = m_current->first;
5260
}
61+
else
62+
{
63+
m_nextID = m_current->first;
64+
}
5365

54-
return m_nextID++;
66+
return m_nextID;
5567
}
5668

5769
int DynamicIDManager::currentID()
@@ -83,6 +95,24 @@ DynamicIDManager& DynamicIDManager::operator++(int)
8395
{
8496
throw exception("Out of IDs");
8597
}
98+
else
99+
{
100+
// If the current ID is now within the limits of the last block
101+
// then we can just increment m_nextID
102+
if (m_nextID > m_current->first && m_nextID < m_current->first + m_current->second)
103+
{
104+
++m_nextID;
105+
}
106+
else
107+
{
108+
// Otherwise, we can just set the next ID to the first in the last block
109+
m_nextID = m_current->first;
110+
}
111+
}
112+
}
113+
else
114+
{
115+
m_nextID = m_current->first;
86116
}
87117
}
88118
}
@@ -94,4 +124,24 @@ DynamicIDManager& DynamicIDManager::operator++(int)
94124
bool DynamicIDManager::allocateIDs(int quantity, int *start)
95125
{
96126
return m_allocator->allocate(quantity, start);
127+
}
128+
129+
130+
bool DynamicIDManager::inRange(int id)
131+
{
132+
bool retVal = false;
133+
list< pair<int, int> >::iterator it = m_idList.begin();
134+
for(;it != m_idList.end(); ++it)
135+
{
136+
if (it->first > id)
137+
break;
138+
139+
if (id >= it->first && (id < (it->first + it->second)))
140+
{
141+
retVal = true;
142+
break;
143+
}
144+
}
145+
146+
return retVal;
97147
}

PythonScript/src/DynamicIDManager.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ class DynamicIDManager
88
public:
99

1010
DynamicIDManager(IDAllocator *allocator)
11-
: m_allocator (allocator)
11+
: m_allocator (allocator),
12+
m_capacity(0)
1213
{
1314
m_current = m_idList.begin();
1415
};
1516

1617
DynamicIDManager(IDAllocator *allocator, int initialStart, int quantity)
17-
: m_allocator (allocator)
18+
: m_allocator (allocator),
19+
m_capacity(quantity),
20+
m_nextID(initialStart + quantity)
1821
{
1922
m_idList.push_back(std::pair<int, int>(initialStart, quantity));
2023
m_current = m_idList.begin();
21-
m_capacity = quantity;
22-
m_nextID = initialStart + quantity;
23-
2424
};
2525

2626

@@ -32,12 +32,16 @@ class DynamicIDManager
3232

3333
int currentID();
3434

35+
void addBlock(int start, int quantity);
36+
3537
// Post-increment operator
3638
DynamicIDManager& operator++(int);
3739

3840

3941
int capacity() { return m_capacity; };
4042

43+
bool inRange(int id);
44+
4145
private:
4246
// Methods
4347
bool allocateIDs(int quantity, int *start);

0 commit comments

Comments
 (0)