Exemple #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);
		}
	}
}
bool TagNode::isLinkedToFile(File* file) {

    bool isLinked = false;

    FileTagNodeAssoc* fileTagNodeAssoc = getAssocToFile(file);
    if (fileTagNodeAssoc != 0) {
        // a file is considered to be linked with this tag if there is an association between
        // but if the tag is of type boolean, the assoc must have the value 'true'
        if (typeid(*fileTagNodeAssoc) == typeid(FileTagNodeAssocBoolean)) {
            FileTagNodeAssocBoolean* fileTagNodeAssocBoolean = dynamic_cast<FileTagNodeAssocBoolean*>(fileTagNodeAssoc);
            isLinked = fileTagNodeAssocBoolean->value();
        } else {
            isLinked = true;
        }
    }

    if (!isLinked && m_children) {
        // loop over all children
        TagNode* child;
        for (child = m_children->first(); child && !isLinked; child = m_children->next()) {
            isLinked = child->isLinkedToFile(file);
        }
    }

    return isLinked;
}
bool Engine::isTagTextValid(TagNode* parent, QString& text, bool ignoreExifTag) const
{
    // a maintag must not be named 'EXIF' (if ignoreExifTag is false)
    if (!ignoreExifTag && parent == 0 && text.upper() == "EXIF") {
        return false;
    }

    QPtrList<TagNode>* siblings = m_tagForest;

    if (parent) {
        siblings = parent->children();
    }

    if (siblings) {
        TagNode* sibling;
        for ( sibling = siblings->first(); sibling; sibling = siblings->next() ) {
            if (*sibling->text() == text) {
                // sibling with the same name already exists!
                return false;
            }
        }
    }

    // no sibling with the same name found
    return true;
}
Exemple #4
0
void SymbolTree::BuildTree(const wxFileName &fileName)
{
	// Clear the tree
	DeleteAllItems();
	m_items.clear();
	m_globalsNode = wxTreeItemId();
	m_prototypesNode = wxTreeItemId();
	m_macrosNode = wxTreeItemId();
	m_sortItems.clear();

	m_fileName = fileName;
	// Get the current tree
	m_tree = TagsManagerST::Get()->Load(m_fileName);
	if ( !m_tree ) {
		return;
	}

	// Add invisible root node
	wxTreeItemId root;
	root = AddRoot(fileName.GetFullName(), 15, 15);

	TreeWalker<wxString, TagEntry> walker(m_tree->GetRoot());

	// add three items here:
	// the globals node, the mcros and the prototype node
	m_globalsNode    = AppendItem(root, wxT("Global Functions and Variables"), 2, 2, new MyTreeItemData(wxT("Global Functions and Variables"), wxEmptyString));
	m_prototypesNode = AppendItem(root, wxT("Functions Prototypes"), 2, 2, new MyTreeItemData(wxT("Functions Prototypes"), wxEmptyString));
	m_macrosNode     = AppendItem(root, wxT("Macros"), 2, 2, new MyTreeItemData(wxT("Macros"), wxEmptyString));

	// Iterate over the tree and add items
	m_sortItems.clear();

	Freeze();
	for (; !walker.End(); walker++) {
		// Add the item to the tree
		TagNode* node = walker.GetNode();

		// Skip root node
		if (node->IsRoot())
			continue;

		// Add the node
		AddItem(node);
	}

	SortTree(m_sortItems);
	Thaw();

	//select the root node by default
	if (!(GetWindowStyleFlag() & wxTR_HIDE_ROOT)) {
		//root is visible, select it
		SelectItem(GetRootItem());
	}
}
TagNode* TagNode::child(QString text) const
{
    if (m_children) {
        TagNode* child = 0;
        for (child = m_children->first(); child; child = m_children->next() ) {
            if ((*(child->text())) == text) {
                return child;
            }
        }
    }

    return 0;
}
/// 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);
}
TagNode* Engine::createTag(TagNode* parent, TagNode::Type type, const QString& text, const QString& comment, const QString& iconName)
{
    tracer->sinvoked(__func__) << "with type: " << type  << ", text: " << text << ", comment: " << comment << ", icon: " << iconName << endl;

    TagNode* tagNode = TagNode::createInstance(type, m_nextTagNodeId++, text, comment, iconName, parent);
    tagNode->setSecret(false);

    // put the tagNode into the tree
    if (!parent) {
        m_tagForest->append(tagNode);
    }

    // put the new tagnode into the tagnode dictionary
    m_tagNodeDict->insert(tagNode->id(), tagNode);

    m_dirty = true;

    emit(newTagNode(tagNode));

    return tagNode;
}
void FileSystemScanner::readEXIF(File* file)
{
    static QString EXIFIFD_NAME_EXIF = exif_ifd_get_name(EXIF_IFD_EXIF);

    int maxDataLength = 255;
    char* charData = new char[maxDataLength];

    ExifData* exifData = exif_data_new_from_file(file->fileInfo()->absFilePath().ascii());
//    exif_data_dump(exifData);

    for (int i = 0; i < EXIF_IFD_COUNT; i++) {
        ExifContent* content = exifData->ifd[i];

        QString group = QString(exif_ifd_get_name((ExifIfd) i));
        if (group == EXIFIFD_NAME_EXIF) {

            for (unsigned int e = 0; e < content->count; e++) {
                ExifEntry* entry = content->entries[e];

                ExifTag exifTagType = entry->tag;
                QString title = QString(exif_tag_get_title(entry->tag));
                QString name = QString(exif_tag_get_name(entry->tag));

                exif_entry_get_value(entry, charData, maxDataLength);
                QString data = QString(charData);

                QString description = QString(exif_tag_get_description(entry->tag));
//                tracer->sdebug(__func__) << "    - " << title << " / " << name << " = " << data << " (" << description << ")" << endl;

                // get the exif tagnode title and the tagnode representing this tag from the engine
                TagNode* exifTagNodeTitle = m_engine->exifTagNodeTitle();
                TagNode* exifTagNodeEntry = exifTagNodeTitle->child(title);

                switch (exifTagType) {
                    case EXIF_TAG_DATE_TIME_ORIGINAL:
                    case EXIF_TAG_DATE_TIME_DIGITIZED: {
                        QDateTime dateTime = readExifDateTime(data);
                        TagNodeDateTime* exifTagNodeEntryDateTime = dynamic_cast<TagNodeDateTime*>(exifTagNodeEntry);
                        if (exifTagNodeEntryDateTime == 0) {
                            // tagnode for this EXIF entry does not exist --> create it
                            exifTagNodeEntryDateTime = dynamic_cast<TagNodeDateTime*>(m_engine->createTag(exifTagNodeTitle, TagNode::TYPE_DATETIME, title, description, QString::null));
                            exifTagNodeEntryDateTime->setReadonly(true);
                        }
                        if (dateTime.isValid()) {
                            // create new assoc
                            new FileTagNodeAssocDateTime(file, exifTagNodeEntryDateTime, dateTime);
                        }

                        break;
                    }
                    default: {
                        TagNodeString* exifTagNodeEntryString = dynamic_cast<TagNodeString*>(exifTagNodeEntry);
                        if (exifTagNodeEntryString == 0) {
                            // tagnode for this EXIF entry does not exist --> create it
                            exifTagNodeEntryString = dynamic_cast<TagNodeString*>(m_engine->createTag(exifTagNodeTitle, TagNode::TYPE_STRING, title, description, QString::null));
                            exifTagNodeEntryString->setReadonly(true);
                        }
                        // create new assoc
                        new FileTagNodeAssocString(file, exifTagNodeEntryString, data);
                    }
                }
            }
        }
    }

    exif_data_free(exifData);
    delete charData;
}
Exemple #9
0
// FIXME: Most of the assertions below should be turn into parse errors and be
// reported in a cleaner way to the client side.
TemplateNode* Parser::parse()
{
    TemplateNode* root = new TemplateNode();
    Node* current = root;

    m_insideClause = false;

    Tokenizer::Token token;
    do {
        assert(m_lastTokenType != Tokenizer::Token::EndOfInput);
        m_tokenizer->nextToken(token);
        assert(token.type != Tokenizer::Token::None);

        switch (token.type) {
            case Tokenizer::Token::Text:
                assert(m_lastTokenType != Tokenizer::Token::Text);
                switch (m_lastTokenType) {
                    case Tokenizer::Token::OpenComment: {
                        assert(m_insideClause);
                        
                        CommentNode* commentNode = new CommentNode(current);
                        commentNode->setText(token.contents);
                        break;
                    }
                    case Tokenizer::Token::OpenVariable: {
                        assert(m_insideClause);
                        std::string variable;
                        assert(splitVariableExpression(token.contents, variable));

                        VariableNode* variableNode = new VariableNode(current);
                        variableNode->setExpression(VariableExpression::parse(variable));
                        break;
                    }
                    case Tokenizer::Token::OpenTag: {
                        assert(m_insideClause);
                        std::string tagName;
                        std::vector<std::string> parameters;
                        assert(splitTagExpression(token.contents, tagName, parameters));
                        
                        if (tagName.size() > 3 && tagName.substr(0, 3) == "end") {
                            std::string tagBaseName = tagName.substr(3);
                            if (TagNodeFactory::self()->isTagRegistered(tagBaseName.c_str())) {
                                assert(current->type() == Node::Tag);
                                TagNode* tagNode = static_cast<TagNode*>(current);
                                assert(tagNode->name() == tagBaseName);
                                assert(!tagNode->isSelfClosing());
                                current = current->parent();
                            } else {
                                TagNode* tagNode = new NullTagNode(current);
                                assert(tagNode->isSelfClosing());
                            }
                        } else {
                            if (TagNodeFactory::self()->isTagRegistered(tagName.c_str())) {
                                TagNode* tagNode = TagNodeFactory::self()->create(tagName.c_str(), current);
                                assert(tagNode);
                                tagNode->setName(tagName);
                                tagNode->setParameters(parameters);
                                if (!tagNode->isSelfClosing())
                                    current = tagNode;
                            } else {
                                TagNode* tagNode = new NullTagNode(current);
                                assert(tagNode->isSelfClosing());
                            }
                        }

                        break;
                    }
                    default: {
                        TextNode* textNode = new TextNode(current);
                        textNode->setText(token.contents);
                        break;
                    }
                }
                break;
            case Tokenizer::Token::OpenComment:
            case Tokenizer::Token::OpenVariable:
            case Tokenizer::Token::OpenTag:
                assert(!m_insideClause);
                m_insideClause = true;
                break;
            case Tokenizer::Token::CloseComment:
            case Tokenizer::Token::CloseVariable:
            case Tokenizer::Token::CloseTag:
                assert(m_insideClause);
                m_insideClause = false;
                break;
            case Tokenizer::Token::EndOfInput:
                // Make sure all opening tags have their corresponding closing tags.
                assert(current == root);
                break;
        }

        m_lastTokenType = token.type;
        assert(current);
    } while (token.type != Tokenizer::Token::EndOfInput);

    return root;
}
Exemple #10
0
void SymbolTree::BuildTree(const wxFileName &fileName, TagEntryPtrVector_t* tags /*NULL*/)
{
    TagEntryPtrVector_t newTags;
    if ( !tags ) {
        
        // Get the current database
        ITagsStoragePtr db = TagsManagerST::Get()->GetDatabase();
        if ( ! db ) {
            Clear();
            return;
        }
        // Load the new tags from the database
        db->SelectTagsByFile(fileName.GetFullPath(), newTags);
        // Compare the new tags with the old ones
        if ( TagsManagerST::Get()->AreTheSame(newTags, m_currentTags) )
            return;
            
        m_currentTags.clear();
        m_currentTags.insert(m_currentTags.end(), newTags.begin(), newTags.end());
        
    } else {
        
        m_currentTags.clear();
        m_currentTags.insert(m_currentTags.end(), tags->begin(), tags->end());
        
    }
    
    wxWindowUpdateLocker locker(this);
    Clear();
    m_fileName = fileName;
    
    // Convert them into tree
    m_tree = TagsManagerST::Get()->Load(m_fileName, &m_currentTags);
    if ( !m_tree ) {
        return;
    }

    // Add invisible root node
    wxTreeItemId root;
    root = AddRoot(fileName.GetFullName(), 15, 15);

    TreeWalker<wxString, TagEntry> walker(m_tree->GetRoot());

    // add three items here:
    // the globals node, the mcros and the prototype node
    m_globalsNode    = AppendItem(root, wxT("Global Functions and Variables"), 2, 2, new MyTreeItemData(wxT("Global Functions and Variables"), wxEmptyString));
    m_prototypesNode = AppendItem(root, wxT("Functions Prototypes"), 2, 2, new MyTreeItemData(wxT("Functions Prototypes"), wxEmptyString));
    m_macrosNode     = AppendItem(root, wxT("Macros"), 2, 2, new MyTreeItemData(wxT("Macros"), wxEmptyString));

    // Iterate over the tree and add items
    m_sortItems.clear();

    Freeze();
    for (; !walker.End(); walker++) {
        // Add the item to the tree
        TagNode* node = walker.GetNode();

        // Skip root node
        if (node->IsRoot())
            continue;

        // Add the node
        AddItem(node);
    }
    
    SortTree(m_sortItems);
    if ( ItemHasChildren(m_globalsNode) == false ) {
        Delete(m_globalsNode);
    }
    if ( ItemHasChildren(m_prototypesNode) == false ) {
        Delete(m_prototypesNode);
    }
    if ( ItemHasChildren(m_macrosNode) == false ) {
        Delete(m_macrosNode);
    }
    Thaw();

    //select the root node by default
    if (!(GetWindowStyleFlag() & wxTR_HIDE_ROOT)) {
        //root is visible, select it
        SelectItem(GetRootItem());
    }
}