Skip to content

Commit

Permalink
Dynamic Command IDs working (with N++ 5.8) (V0.8)
Browse files Browse the repository at this point in the history
 - 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
  • Loading branch information
bruderstein committed Oct 24, 2010
1 parent 16d55c5 commit 3e3e28e
Show file tree
Hide file tree
Showing 18 changed files with 463 additions and 138 deletions.
7 changes: 4 additions & 3 deletions PythonScript/project/PythonScript2010.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,12 @@
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>python26.lib;NppPlugin.lib;shlwapi.lib;comctl32.lib;htmlhelp.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>python27.lib;NppPlugin.lib;shlwapi.lib;comctl32.lib;htmlhelp.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>C:\Program Files (x86)\HTML Help Workshop\lib</AdditionalLibraryDirectories>
<ShowProgress>LinkVerbose</ShowProgress>
</Link>
<PostBuildEvent>
<Command>copy $(OutDir)$(TargetFileName) "C:\Program Files (x86)\Notepad++\plugins"</Command>
<Command>copy $(OutDir)$(TargetFileName) "C:\Program Files (x86)\Notepad++5.8\plugins"</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='DebugStartup|Win32'">
Expand Down Expand Up @@ -186,7 +187,7 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>python26.lib;NppPlugin.lib;shlwapi.lib;comctl32.lib;htmlhelp.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>python27.lib;NppPlugin.lib;shlwapi.lib;comctl32.lib;htmlhelp.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>C:\Program Files (x86)\HTML Help Workshop\lib</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
Expand Down
2 changes: 1 addition & 1 deletion PythonScript/project/PythonSettings.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="PropertySheets" />
<PropertyGroup Label="UserMacros">
<PythonBase>E:\work\Python-2.6.5</PythonBase>
<PythonBase>E:\work\Python-2.7</PythonBase>
<PythonLibPath>$(PythonBase)\PCbuild</PythonLibPath>
<BoostPythonLibPath>E:\libs\boost\bin.v2\libs\python\build\msvc-10.0\$(Configuration)\link-static\runtime-link-static\threading-multi</BoostPythonLibPath>
</PropertyGroup>
Expand Down
13 changes: 13 additions & 0 deletions PythonScript/src/ConfigFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,16 @@ const tstring& ConfigFile::getSetting(const TCHAR *settingName)
{
return m_settings[tstring(settingName)];
}


const std::string& ConfigFile::getMenuScript(int index) const
{
if (m_menuScripts.size() > static_cast<size_t>(index))
{
return m_menuScripts[index];
}
else
{
return m_emptyString;
}
}
9 changes: 7 additions & 2 deletions PythonScript/src/ConfigFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ConfigFile
// TODO: Need to make these pointers
MenuItemsTD getMenuItems() { return m_menuItems; };
ToolbarItemsTD getToolbarItems() { return m_toolbarItems; };
std::string& getMenuScript(int index) { return m_menuScripts[index]; }
const std::string& getMenuScript(int index) const;

void addMenuItem(const tstring scriptPath);
void addToolbarItem(const tstring scriptPath, const tstring iconPath);
Expand Down Expand Up @@ -55,7 +55,12 @@ class ConfigFile

MenuItemsTD m_menuItems;
std::vector< std::string > m_menuScripts;


// Used in case an invalid script number is requested
// so we can return a reference to this puppy instead.
std::string m_emptyString;


ToolbarItemsTD m_toolbarItems;
std::map< tstring, HICON > m_icons;
SettingsTD m_settings;
Expand Down
54 changes: 52 additions & 2 deletions PythonScript/src/DynamicIDManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,20 @@ using namespace std;

void DynamicIDManager::reserve(int quantity)
{
if (quantity < m_capacity)
if (quantity > m_capacity)
{
reserveAdditional(quantity - m_capacity);
}
}

void DynamicIDManager::addBlock(int start, int quantity)
{
m_idList.push_back(pair<int, int>(start, quantity));

// Assume no overlaps (should really fix this, but we just need to use this carefully)
m_capacity += quantity;
}

void DynamicIDManager::reserveAdditional(int quantity)
{

Expand Down Expand Up @@ -50,8 +58,12 @@ int DynamicIDManager::begin()
m_current = m_idList.begin();
m_nextID = m_current->first;
}
else
{
m_nextID = m_current->first;
}

return m_nextID++;
return m_nextID;
}

int DynamicIDManager::currentID()
Expand Down Expand Up @@ -83,6 +95,24 @@ DynamicIDManager& DynamicIDManager::operator++(int)
{
throw exception("Out of IDs");
}
else
{
// If the current ID is now within the limits of the last block
// then we can just increment m_nextID
if (m_nextID > m_current->first && m_nextID < m_current->first + m_current->second)
{
++m_nextID;
}
else
{
// Otherwise, we can just set the next ID to the first in the last block
m_nextID = m_current->first;
}
}
}
else
{
m_nextID = m_current->first;
}
}
}
Expand All @@ -94,4 +124,24 @@ DynamicIDManager& DynamicIDManager::operator++(int)
bool DynamicIDManager::allocateIDs(int quantity, int *start)
{
return m_allocator->allocate(quantity, start);
}


bool DynamicIDManager::inRange(int id)
{
bool retVal = false;
list< pair<int, int> >::iterator it = m_idList.begin();
for(;it != m_idList.end(); ++it)
{
if (it->first > id)
break;

if (id >= it->first && (id < (it->first + it->second)))
{
retVal = true;
break;
}
}

return retVal;
}
14 changes: 9 additions & 5 deletions PythonScript/src/DynamicIDManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ class DynamicIDManager
public:

DynamicIDManager(IDAllocator *allocator)
: m_allocator (allocator)
: m_allocator (allocator),
m_capacity(0)
{
m_current = m_idList.begin();
};

DynamicIDManager(IDAllocator *allocator, int initialStart, int quantity)
: m_allocator (allocator)
: m_allocator (allocator),
m_capacity(quantity),
m_nextID(initialStart + quantity)
{
m_idList.push_back(std::pair<int, int>(initialStart, quantity));
m_current = m_idList.begin();
m_capacity = quantity;
m_nextID = initialStart + quantity;

};


Expand All @@ -32,12 +32,16 @@ class DynamicIDManager

int currentID();

void addBlock(int start, int quantity);

// Post-increment operator
DynamicIDManager& operator++(int);


int capacity() { return m_capacity; };

bool inRange(int id);

private:
// Methods
bool allocateIDs(int quantity, int *start);
Expand Down
Loading

0 comments on commit 3e3e28e

Please sign in to comment.