示例#1
0
void SymbolTree::UpdateGuiItem(TagEntry& data, const wxString& key)
{
	if (!m_tree)
		return;

	TagNode* node = m_tree->Find(key);
	if ( node ) {
		// Update the new data with the gui tree item id
		data.SetTreeItemId( node->GetData().GetTreeItemId() );
		node->SetData(data);

		// Update Icon if needed
		int iconIndex = GetItemIconIndex(data.GetKind(), data.GetAccess());
		int curIconIndex = -1;
		wxTreeItemId itemId = node->GetData().GetTreeItemId();
		if (itemId.IsOk()) {
			curIconIndex = GetItemImage(itemId);
			if (curIconIndex != iconIndex ) {
				// Need to update the image as well
				SetItemImage(node->GetData().GetTreeItemId(), iconIndex);
				SetItemImage(node->GetData().GetTreeItemId(), iconIndex, wxTreeItemIcon_Selected);

			} // if(curIconIndex != iconIndex )
			//update the linenumber and file
			MyTreeItemData *item_data = new MyTreeItemData(data.GetFile(), data.GetPattern());
			wxTreeItemData *old_data = GetItemData(itemId);
			if (old_data)
				delete old_data;
			SetItemData(itemId, item_data);
		}
	}
}
示例#2
0
bool TagEntry::operator ==(const TagEntry& rhs)
{
    //Note: tree item id is not used in this function!
    bool res =
        m_scope == rhs.m_scope &&
        m_file == rhs.m_file &&
        m_kind == rhs.m_kind &&
        m_parent == rhs.m_parent &&
        m_pattern == rhs.m_pattern &&
        m_name == rhs.m_name &&
        m_path == rhs.m_path &&
        m_lineNumber == rhs.m_lineNumber &&
        GetInherits() == rhs.GetInherits() &&
        GetAccess() == rhs.GetAccess() &&
        GetSignature() == rhs.GetSignature() &&
        GetTyperef() == rhs.GetTyperef();

    bool res2 = m_scope == rhs.m_scope &&
                m_file == rhs.m_file &&
                m_kind == rhs.m_kind &&
                m_parent == rhs.m_parent &&
                m_pattern == rhs.m_pattern &&
                m_name == rhs.m_name &&
                m_path == rhs.m_path &&
                GetInherits() == rhs.GetInherits() &&
                GetAccess() == rhs.GetAccess() &&
                GetSignature() == rhs.GetSignature() &&
                GetTyperef() == rhs.GetTyperef();

    if (res2 && !res) {
        // the entries are differs only in the line numbers
        m_differOnByLineNumber = true;
    }
    return res;
}
/// Util function to help us to build a tree from tags
TagNode* TagTree::AddEntry(TagEntry& tag)
{
	// If a node with thig tag already exist, we simply updating the 
	// data 
	wxString key(tag.Key());

	TagNode* newNode = Find(key);
	if( newNode )
	{
		if( tag.IsOk() )
			newNode->SetData(tag);
		return newNode;

	}

	// To add an entry to the tree, we first must make sure
	// that all path to it exist
	wxString name = tag.GetPath();
	StringTokenizer tok(name, wxT("::"));

	wxString parentPath;
	TagNode* node = GetRoot();
	TagNode* lastFoundNode = GetRoot();
	for(int i=0; i<tok.Count()-1; i++)
	{
		parentPath += tok[i];

		// Try to find this node in the tree
		node = Find(parentPath);
		if( !node )
		{
			// Node does not exist add it, we copy key values
			// from 'tag'
			TagEntry ee;
			ee.SetPath(parentPath);
			ee.SetName(tok[i]);
			node = AddChild(parentPath, ee, lastFoundNode);
		}

		lastFoundNode = node;
		if(i < tok.Count()-2)
			parentPath += _T("::");
	}

	return AddChild(key, tag, node);
}
示例#4
0
bool TagEntry::operator ==(const TagEntry& rhs)
{
    //Note: tree item id is not used in this function!
    return
        m_parentId == rhs.m_parentId &&
        m_scope == rhs.m_scope &&
        m_file == rhs.m_file &&
        m_kind == rhs.m_kind &&
        m_parent == rhs.m_parent &&
        m_pattern == rhs.m_pattern &&
        m_lineNumber == rhs.m_lineNumber &&
        m_name == rhs.m_name &&
        m_path == rhs.m_path &&
        GetInherits() == rhs.GetInherits() &&
        GetAccess() == rhs.GetAccess() &&
        GetSignature() == rhs.GetSignature() &&
        GetPosition() == rhs.GetPosition() &&
        GetTyperef() == rhs.GetTyperef();
}
void TagsDatabase::Store(TagTreePtr tree, const wxFileName& path, bool autoCommit)
{
	if(!path.IsOk() && !m_fileName.IsOk())
	{
		// An attempt is made to save the tree into db but no database
		// is provided and none is currently opened to use
		return;
	}
	
	if( !tree )
		return;

	OpenDatabase(path);
	TreeWalker<wxString, TagEntry> walker( tree->GetRoot() );

	try
	{
		// Create the statements before the execution
		TagEntry dummy;
		wxSQLite3Statement insertStmt = m_db->PrepareStatement( dummy.GetInsertOneStatement() );
		
		std::vector<TagEntry> updateList;

		// AddChild entries to database
		if( autoCommit )
			m_db->Begin();

		for(; !walker.End(); walker++)
		{
			// Skip root node
			if(walker.GetNode() == tree->GetRoot())
				continue;

			walker.GetNode()->GetData().SetParentId(walker.GetNode()->GetParent()->GetData().GetId());
			if(walker.GetNode()->GetData().Store(insertStmt) == TagExist)
			{
				// Update the record
				updateList.push_back(walker.GetNode()->GetData());
			}
		}
		insertStmt.Finalize();

		if( autoCommit )
			m_db->Commit();

		// Do we need to update?
		if(!updateList.empty())
		{
			wxSQLite3Statement updateStmt = m_db->PrepareStatement( updateList[0].GetUpdateOneStatement() );
			if( autoCommit )
				m_db->Begin();
			for(size_t i=0; i<updateList.size(); i++)
				updateList[i].Update(updateStmt);
			updateStmt.Finalize();
			if( autoCommit )
				m_db->Commit();
		}
	}
	catch (wxSQLite3Exception& e)
	{
		wxUnusedVar(e);
		if( autoCommit )
			m_db->Rollback();
	}
}
示例#6
0
void SymbolTree::AddItem(TagNode* node)
{
	// Get node icon index
	TagEntry nodeData = node->GetData();

	int iconIndex = GetItemIconIndex(nodeData.GetKind(), nodeData.GetAccess());
	wxString displayName(nodeData.GetDisplayName());

	wxTreeItemId parentHti;
	if (nodeData.GetName().IsEmpty())
		return;

        wxFont font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
        if (nodeData.GetKind() == wxT("prototype")) {
            font.SetStyle(wxFONTSTYLE_ITALIC);
        }
        if (nodeData.GetAccess() == wxT("public")) {
            font.SetWeight(wxFONTWEIGHT_BOLD);
        }
        
	//-------------------------------------------------------------------------------
	// We gather globals together under special node
	//-------------------------------------------------------------------------------
	if ( (nodeData.GetParent() == wxT("<global>")) &&					// parent is global scope
	        m_globalsKind.find(nodeData.GetKind()) != m_globalsKind.end() ) { //the node kind is one of function, prototype or variable
		if (nodeData.GetKind() == wxT("prototype"))
			parentHti = m_prototypesNode;
		else
			parentHti = m_globalsNode;
	} else
		parentHti = node->GetParent()->GetData().GetTreeItemId();

	//---------------------------------------------------------------------------------
	// Macros are gathered under the 'Macros' node
	//---------------------------------------------------------------------------------
	if (nodeData.GetKind() == wxT("macro")) {
		parentHti = m_macrosNode;
	}

	//only if parent is valid, we add item to the tree
	wxTreeItemId hti;

	if (parentHti.IsOk() == false) {
		parentHti = GetRootItem();
	}

	if (parentHti.IsOk()) {
		hti = AppendItem(parentHti,				// parent
		                 displayName,			// display name
		                 iconIndex,				// item image index
		                 iconIndex,				// selected item image
                         new MyTreeItemData(node->GetData().GetFile(), node->GetData().GetPattern(), node->GetData().GetLine()));
                SetItemFont(hti, font);
		node->GetData().SetTreeItemId( hti );
		m_sortItems[parentHti.m_pItem] = true;
		m_items[nodeData.Key()] = hti.m_pItem;
	}
}