mirror of
https://github.com/textmate/textmate.git
synced 2026-01-15 01:38:02 -05:00
Store a parent menu reference in bundle items instead of a path
This is simpler to setup and maintain and requires less storage.
This commit is contained in:
@@ -165,14 +165,14 @@ namespace bundles
|
||||
return name() + (bundle() ? " — " + bundle()->name() : "");
|
||||
}
|
||||
|
||||
std::vector<std::string> const& item_t::menu_path () const
|
||||
oak::uuid_t const& item_t::parent_menu () const
|
||||
{
|
||||
return _menu_path;
|
||||
return _parent_menu;
|
||||
}
|
||||
|
||||
void item_t::set_menu_path (std::vector<std::string> const& newMenuPath)
|
||||
void item_t::set_parent_menu (oak::uuid_t const& newParentMenu)
|
||||
{
|
||||
_menu_path = newMenuPath;
|
||||
_parent_menu = newParentMenu;
|
||||
}
|
||||
|
||||
oak::uuid_t const& item_t::uuid () const
|
||||
|
||||
@@ -48,8 +48,8 @@ namespace bundles
|
||||
std::string const& name () const;
|
||||
void set_name (std::string const& newName);
|
||||
std::string full_name () const;
|
||||
std::vector<std::string> const& menu_path () const;
|
||||
void set_menu_path (std::vector<std::string> const& newMenuPath);
|
||||
oak::uuid_t const& parent_menu () const;
|
||||
void set_parent_menu (oak::uuid_t const& uuid);
|
||||
oak::uuid_t const& uuid () const;
|
||||
oak::uuid_t bundle_uuid () const;
|
||||
scope::selector_t const& scope_selector () const;
|
||||
@@ -114,7 +114,7 @@ namespace bundles
|
||||
mutable std::mutex _plist_mutex;
|
||||
std::vector<required_bundle_t> _required_bundles;
|
||||
std::vector<required_executable_t> _required_executables;
|
||||
std::vector<std::string> _menu_path;
|
||||
oak::uuid_t _parent_menu;
|
||||
};
|
||||
|
||||
} /* bundles */
|
||||
|
||||
@@ -129,31 +129,6 @@ namespace bundles
|
||||
}
|
||||
}
|
||||
|
||||
static void setup_full_name (oak::uuid_t const& menuUUID, std::map< oak::uuid_t, std::vector<oak::uuid_t> > const& menus, std::map<oak::uuid_t, item_ptr> const& items, std::vector<std::string>* prefixStack)
|
||||
{
|
||||
std::map< oak::uuid_t, std::vector<oak::uuid_t> >::const_iterator menu = menus.find(menuUUID);
|
||||
if(menu != menus.end())
|
||||
{
|
||||
for(auto const& uuid : menu->second)
|
||||
{
|
||||
std::map<oak::uuid_t, item_ptr>::const_iterator item = items.find(uuid);
|
||||
if(item == items.end())
|
||||
continue;
|
||||
|
||||
if(item->second->kind() == kItemTypeMenu)
|
||||
{
|
||||
prefixStack->push_back(item->second->name());
|
||||
setup_full_name(item->second->uuid(), menus, items, prefixStack);
|
||||
prefixStack->pop_back();
|
||||
}
|
||||
else
|
||||
{
|
||||
item->second->set_menu_path(*prefixStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool set_index (std::vector<item_ptr> const& items, std::map< oak::uuid_t, std::vector<oak::uuid_t> > const& menus)
|
||||
{
|
||||
Callbacks(&callback_t::bundles_will_change);
|
||||
@@ -162,16 +137,22 @@ namespace bundles
|
||||
AllMenus = menus;
|
||||
cache().clear();
|
||||
|
||||
std::map< item_ptr, std::map<oak::uuid_t, item_ptr> > map; // bundle → { item_uuid → bundle_item }
|
||||
std::map<oak::uuid_t, item_ptr> lookupTable;
|
||||
for(auto const& item : items)
|
||||
{
|
||||
if(item->bundle())
|
||||
map[item->bundle()].emplace(item->uuid(), item);
|
||||
if(item_ptr bundle = item->bundle())
|
||||
item->set_parent_menu(bundle->uuid());
|
||||
lookupTable.emplace(item->uuid(), item);
|
||||
}
|
||||
|
||||
std::vector<std::string> stack;
|
||||
for(auto const& bundle : map)
|
||||
setup_full_name(bundle.first->uuid(), menus, bundle.second, &stack);
|
||||
for(auto const& pair : menus)
|
||||
{
|
||||
for(auto const& itemUUID : pair.second)
|
||||
{
|
||||
if(auto item = lookupTable[itemUUID])
|
||||
item->set_parent_menu(pair.first);
|
||||
}
|
||||
}
|
||||
|
||||
Callbacks(&callback_t::bundles_did_change);
|
||||
|
||||
@@ -338,11 +319,11 @@ namespace bundles
|
||||
return format_bundle_item_title(item->name(), hasSelection);
|
||||
}
|
||||
|
||||
std::string menu_path (item_ptr const& item)
|
||||
std::string menu_path (item_ptr item)
|
||||
{
|
||||
std::vector<std::string> path = item->menu_path();
|
||||
if(item->kind() != kItemTypeBundle && item->bundle())
|
||||
path.insert(path.begin(), item->bundle()->name());
|
||||
std::deque<std::string> path;
|
||||
while(item = lookup(item->parent_menu()))
|
||||
path.push_front(item->name());
|
||||
return text::join(path, " ▸ ");
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace bundles
|
||||
PUBLIC std::vector<item_ptr> items_for_proxy (item_ptr proxyItem, scope::context_t const& scope = scope::wildcard, int kind = kItemTypeCommand|kItemTypeDragCommand|kItemTypeGrammar|kItemTypeMacro|kItemTypeSnippet|kItemTypeProxy|kItemTypeTheme, oak::uuid_t const& bundle = oak::uuid_t(), bool filter = true, bool includeDisabledItems = false);
|
||||
PUBLIC item_ptr lookup (oak::uuid_t const& uuid);
|
||||
PUBLIC std::string name_with_selection (item_ptr const& item, bool hasSelection);
|
||||
PUBLIC std::string menu_path (item_ptr const& item);
|
||||
PUBLIC std::string menu_path (item_ptr item);
|
||||
PUBLIC std::string key_equivalent (item_ptr const& item);
|
||||
|
||||
} /* bundles */
|
||||
|
||||
Reference in New Issue
Block a user