Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
necros0 committed Feb 22, 2013
2 parents 0baf206 + a3e37ba commit 29334cf
Show file tree
Hide file tree
Showing 10 changed files with 167 additions and 81 deletions.
17 changes: 17 additions & 0 deletions Mac/TrenchBroom.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1184,6 +1184,7 @@
484763CE15E2BC5000095BC0 /* Frameworks */,
484763CF15E2BC5000095BC0 /* Resources */,
48B64C5716CEC30D00ECA6C5 /* CopyFiles */,
4858930216D78EA30079E897 /* ShellScript */,
);
buildRules = (
);
Expand Down Expand Up @@ -1261,6 +1262,22 @@
};
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
4858930216D78EA30079E897 /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = "#!/bin/bash";
shellScript = "buildPlist=${INFOPLIST_FILE}\nbuildNumber=$(/usr/libexec/PlistBuddy -c \"Print CFBundleVersion\" $buildPlist)\nbuildNumber=$(($buildNumber + 1))\n/usr/libexec/PlistBuddy -c \"Set :CFBundleVersion $buildNumber\" $buildPlist";
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
484763CD15E2BC5000095BC0 /* Sources */ = {
isa = PBXSourcesBuildPhase;
Expand Down
2 changes: 1 addition & 1 deletion Mac/TrenchBroom/TrenchBroom-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<string>5</string>
<key>LSMinimumSystemVersion</key>
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
<key>NSHumanReadableCopyright</key>
Expand Down
14 changes: 14 additions & 0 deletions Source/Model/EntityDefinition.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,20 @@ namespace TrenchBroom {
return m_name;
}

inline const String groupName() const {
size_t uscoreIndex = m_name.find_first_of('_');
if (uscoreIndex == String::npos)
return "Misc";
return Utility::capitalize(m_name.substr(0, uscoreIndex));
}

inline const String shortName() const {
size_t uscoreIndex = m_name.find_first_of('_');
if (uscoreIndex == String::npos)
return m_name;
return m_name.substr(uscoreIndex + 1);
}

inline const Color& color() const {
return m_color;
}
Expand Down
14 changes: 14 additions & 0 deletions Source/Model/EntityDefinitionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,19 @@ namespace TrenchBroom {
std::sort(result.begin(), result.end(), CompareEntityDefinitionsByName());
return result;
}

EntityDefinitionManager::EntityDefinitionGroups EntityDefinitionManager::groups(EntityDefinition::Type type, SortOrder order) {
EntityDefinitionGroups groups;
EntityDefinitionList list = definitions(type, order);

EntityDefinitionList::const_iterator it, end;
for (it = list.begin(), end = list.end(); it != end; ++it) {
EntityDefinition* definition = *it;
const String groupName = definition->groupName();
groups[groupName].push_back(definition);
}

return groups;
}
}
}
3 changes: 3 additions & 0 deletions Source/Model/EntityDefinitionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ namespace TrenchBroom {
Name,
Usage
};

typedef std::map<String, EntityDefinitionList> EntityDefinitionGroups;
protected:
class CompareEntityDefinitionsByName {
public:
Expand Down Expand Up @@ -67,6 +69,7 @@ namespace TrenchBroom {

EntityDefinition* definition(const String& name);
EntityDefinitionList definitions(EntityDefinition::Type type, SortOrder order = Name);
EntityDefinitionGroups groups(EntityDefinition::Type type, SortOrder order = Name);
};
}
}
Expand Down
101 changes: 74 additions & 27 deletions Source/Utility/String.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,66 @@ typedef std::vector<String> StringList;

namespace TrenchBroom {
namespace Utility {
struct CaseSensitiveCharCompare {
public:
int operator()(char lhs, char rhs) const {
return lhs - rhs;
}
};

struct CaseInsensitiveCharCompare {
private:
const std::locale& m_locale;
public:
CaseInsensitiveCharCompare(const std::locale& loc = std::locale::classic()) :
m_locale(loc) {}

int operator()(char lhs, char rhs) const {
return std::tolower(lhs, m_locale) - std::tolower(rhs, m_locale);
}
};

template <typename Cmp>
struct CharEqual {
private:
Cmp m_compare;
public:
bool operator()(char lhs, char rhs) const {
return m_compare(lhs, rhs) == 0;
}
};

template <typename Cmp>
struct CharLess {
private:
Cmp m_compare;
public:
bool operator()(char lhs, char rhs) const {
return m_compare(lhs, rhs) < 0;
}
};

template <typename Cmp>
struct StringEqual {
public:
bool operator()(const String& lhs, const String& rhs) const {
String::const_iterator lhsEnd, rhsEnd;
std::advance(lhsEnd = lhs.begin(), std::min(lhs.size(), rhs.size()));
std::advance(rhsEnd = rhs.begin(), std::min(lhs.size(), rhs.size()));
return std::lexicographical_compare(lhs.begin(), lhsEnd, rhs.begin(), rhsEnd, CharEqual<Cmp>());
}
};

template <typename Cmp>
struct StringLess {
bool operator()(const String& lhs, const String& rhs) const {
String::const_iterator lhsEnd, rhsEnd;
std::advance(lhsEnd = lhs.begin(), std::min(lhs.size(), rhs.size()));
std::advance(rhsEnd = rhs.begin(), std::min(lhs.size(), rhs.size()));
return std::lexicographical_compare(lhs.begin(), lhsEnd, rhs.begin(), rhsEnd, CharLess<Cmp>());
}
};

inline void formatString(const char* format, va_list arguments, String& result) {
static char buffer[4096];

Expand Down Expand Up @@ -71,8 +131,8 @@ namespace TrenchBroom {

inline StringList split(const String& str, char d) {
StringList result;
unsigned int lastIndex = 0;
for (unsigned int i = 0; i < str.length(); i++) {
size_t lastIndex = 0;
for (size_t i = 0; i < str.length(); i++) {
char c = str[i];
if (c == d && lastIndex < i) {
result.push_back(str.substr(lastIndex, i - lastIndex));
Expand All @@ -92,7 +152,7 @@ namespace TrenchBroom {

StringStream result;
result << strs[0];
for (unsigned int i = 1; i < strs.size(); i++)
for (size_t i = 1; i < strs.size(); i++)
result << d << strs[i];
return result.str();
}
Expand All @@ -108,7 +168,7 @@ namespace TrenchBroom {
return str.find_first_not_of(" \n\t\r" + 0) == String::npos;
}

inline String toLower(String str) {
inline String toLower(const String& str) {
String result(str);
std::transform(result.begin(), result.end(), result.begin(), tolower);
return result;
Expand All @@ -133,21 +193,13 @@ namespace TrenchBroom {
}
return buffer.str();
}

inline bool caseInsensitiveCharEqual(char c1, char c2) {
return std::toupper(c1, std::locale::classic()) == std::toupper(c2, std::locale::classic());
}

inline bool caseSensitiveCharEqual(char c1, char c2) {
return c1 == c2;
}


inline bool containsString(const String& haystack, const String& needle, bool caseSensitive = true) {
String::const_iterator it;
if (caseSensitive)
it = std::search(haystack.begin(), haystack.end(), needle.begin(), needle.end(), caseSensitiveCharEqual);
it = std::search(haystack.begin(), haystack.end(), needle.begin(), needle.end(), CharEqual<CaseSensitiveCharCompare>());
else
it = std::search(haystack.begin(), haystack.end(), needle.begin(), needle.end(), caseInsensitiveCharEqual);
it = std::search(haystack.begin(), haystack.end(), needle.begin(), needle.end(), CharEqual<CaseInsensitiveCharCompare>());
return it != haystack.end();
}

Expand All @@ -160,18 +212,13 @@ namespace TrenchBroom {
inline bool startsWith(const String& haystack, const String& needle, bool caseSensitive = true) {
if (needle.size() > haystack.size())
return false;
if (caseSensitive) {
for (size_t i = 0; i < needle.size(); i++) {
if (haystack[i] != needle[i])
return false;
}
} else {
for (size_t i = 0; i < needle.size(); i++) {
if (!caseInsensitiveCharEqual(haystack[i], haystack[i]))
return false;
}
}
return true;

String::const_iterator hEnd = haystack.begin();
std::advance(hEnd, needle.size());

if (caseSensitive)
return std::equal(haystack.begin(), hEnd, needle.begin(), CharEqual<CaseSensitiveCharCompare>());
return std::equal(haystack.begin(), hEnd, needle.begin(), CharEqual<CaseInsensitiveCharCompare>());
}
}
}
Expand Down
54 changes: 31 additions & 23 deletions Source/View/EditorView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ namespace TrenchBroom {
EVT_MENU_RANGE(CommandIds::CreateEntityPopupMenu::LowestBrushEntityItem, CommandIds::CreateEntityPopupMenu::HighestBrushEntityItem, EditorView::OnPopupCreateBrushEntity)
EVT_UPDATE_UI_RANGE(CommandIds::CreateEntityPopupMenu::LowestBrushEntityItem, CommandIds::CreateEntityPopupMenu::HighestBrushEntityItem, EditorView::OnPopupUpdateBrushMenuItem)

EVT_MENU_HIGHLIGHT_ALL(EditorView::OnMenuHighlight)
END_EVENT_TABLE()

IMPLEMENT_DYNAMIC_CLASS(EditorView, wxView)
Expand Down Expand Up @@ -399,28 +398,49 @@ namespace TrenchBroom {
wxMenu* EditorView::createEntityPopupMenu() {
if (m_createEntityPopupMenu == NULL) {
Model::EntityDefinitionManager& definitionManager = mapDocument().definitionManager();
Model::EntityDefinitionList::const_iterator it, end;
Model::EntityDefinitionManager::EntityDefinitionGroups::const_iterator groupIt, groupEnd;
Model::EntityDefinitionList::const_iterator defIt, defEnd;

int id = 0;
wxMenu* pointMenu = new wxMenu();
pointMenu->SetEventHandler(this);

const Model::EntityDefinitionList& pointDefinitions = definitionManager.definitions(Model::EntityDefinition::PointEntity);
for (it = pointDefinitions.begin(), end = pointDefinitions.end(); it != end; ++it) {
Model::EntityDefinition& definition = **it;
pointMenu->Append(CommandIds::CreateEntityPopupMenu::LowestPointEntityItem + id++, definition.name());
Model::EntityDefinitionManager::EntityDefinitionGroups groups = definitionManager.groups(Model::EntityDefinition::PointEntity);
for (groupIt = groups.begin(), groupEnd = groups.end(); groupIt != groupEnd; ++groupIt) {
const String& groupName = groupIt->first;
wxMenu* groupMenu = new wxMenu();
groupMenu->SetEventHandler(this);

const Model::EntityDefinitionList& definitions = groupIt->second;
for (defIt = definitions.begin(), defEnd = definitions.end(); defIt != defEnd; ++defIt) {
Model::EntityDefinition& definition = **defIt;
groupMenu->Append(CommandIds::CreateEntityPopupMenu::LowestPointEntityItem + id++, definition.shortName());
}

pointMenu->AppendSubMenu(groupMenu, groupName);
}


m_createPointEntityMenu = pointMenu;

id = 0;
wxMenu* brushMenu = new wxMenu();
brushMenu->SetEventHandler(this);
const Model::EntityDefinitionList& brushDefinitions = definitionManager.definitions(Model::EntityDefinition::BrushEntity);
for (it = brushDefinitions.begin(), end = brushDefinitions.end(); it != end; ++it) {
Model::EntityDefinition& definition = **it;
if (definition.name() != Model::Entity::WorldspawnClassname)
brushMenu->Append(CommandIds::CreateEntityPopupMenu::LowestBrushEntityItem + id++, definition.name());

groups = definitionManager.groups(Model::EntityDefinition::BrushEntity);
for (groupIt = groups.begin(), groupEnd = groups.end(); groupIt != groupEnd; ++groupIt) {
const String& groupName = groupIt->first;
wxMenu* groupMenu = new wxMenu();
groupMenu->SetEventHandler(this);

const Model::EntityDefinitionList& definitions = groupIt->second;
for (defIt = definitions.begin(), defEnd = definitions.end(); defIt != defEnd; ++defIt) {
Model::EntityDefinition& definition = **defIt;
if (definition.name() != Model::Entity::WorldspawnClassname)
groupMenu->Append(CommandIds::CreateEntityPopupMenu::LowestBrushEntityItem + id++, definition.shortName());
}

brushMenu->AppendSubMenu(groupMenu, groupName);
}

m_createEntityPopupMenu = new wxMenu();
Expand Down Expand Up @@ -1819,17 +1839,5 @@ namespace TrenchBroom {
!inputController().moveVerticesToolActive() &&
editStateManager.selectionMode() == Model::EditStateManager::SMBrushes);
}

void EditorView::OnMenuHighlight(wxMenuEvent& event) {
if (event.GetMenu() != NULL && event.GetMenu() == m_createPointEntityMenu) {
Model::EntityDefinitionManager& definitionManager = mapDocument().definitionManager();
const Model::EntityDefinitionList& pointDefinitions = definitionManager.definitions(Model::EntityDefinition::PointEntity);
size_t index = static_cast<size_t>(event.GetId() - CommandIds::CreateEntityPopupMenu::LowestPointEntityItem);
assert(index < pointDefinitions.size());

Model::PointEntityDefinition* pointDefinition = static_cast<Model::PointEntityDefinition*>(pointDefinitions[index]);
inputController().showPointEntityPreview(*pointDefinition);
}
}
}
}
2 changes: 0 additions & 2 deletions Source/View/EditorView.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,6 @@ namespace TrenchBroom {
void OnPopupCreateBrushEntity(wxCommandEvent& event);
void OnPopupUpdateBrushMenuItem(wxUpdateUIEvent& event);

void OnMenuHighlight(wxMenuEvent& event);

DECLARE_EVENT_TABLE();
};
}
Expand Down
Loading

0 comments on commit 29334cf

Please sign in to comment.