IAssistProposal *KeywordsCompletionAssistProcessor::perform(const IAssistInterface *interface)
{
    m_interface.reset(interface);

    if (isInComment())
        return 0;

    if (interface->reason() == IdleEditor && !acceptsIdleEditor())
        return 0;

    if (m_startPosition == -1)
        m_startPosition = findStartOfName();

    int nextCharPos = m_startPosition + m_word.length();
    if (m_keywords.isFunction(m_word)
        && m_interface->characterAt(nextCharPos) == QLatin1Char('(')) {
        QStringList functionSymbols = m_keywords.argsForFunction(m_word);
        IFunctionHintProposalModel *model =
                new KeywordsFunctionHintModel(functionSymbols);
        IAssistProposal *proposal = new FunctionHintProposal(m_startPosition, model);
        return proposal;
    } else {
        QList<TextEditor::BasicProposalItem *> items;
        addWordsToProposalList(&items, m_keywords.variables(), m_variableIcon);
        addWordsToProposalList(&items, m_keywords.functions(), m_functionIcon);
        return new GenericProposal(m_startPosition, new BasicProposalItemListModel(items));
    }
}
bool KeywordsCompletionAssistProcessor::acceptsIdleEditor()
{
    const int pos = m_interface->position();
    QChar characterUnderCursor = m_interface->characterAt(pos);
    if (!characterUnderCursor.isLetterOrNumber()) {
        m_startPosition = findStartOfName();
        if (pos - m_startPosition >= 3 && !isInComment())
            return true;
    }
    return false;
}
Beispiel #3
0
bool Entity::isInOuput(qint64 pos){
    static bool remove=false;
    const Comment* p = isInComment(pos);
    if (p!=nullptr){
        if (p->typeComment==REMOVE_START){
            remove=true;
        } else  if (p->typeComment==REMOVE_END){
            remove=false;
        }

        return false;
    } else {
        return !remove;

    }
}
bool GlslCompleter::contextAllowsAutoParentheses(const QTextCursor &cursor,
                                                 const QString &textToInsert) const
{
    QChar ch;

    if (! textToInsert.isEmpty())
        ch = textToInsert.at(0);

    if (! (MatchingText::shouldInsertMatchingText(cursor)
           || ch == QLatin1Char('\'')
           || ch == QLatin1Char('"')))
        return false;
    else if (isInComment(cursor))
        return false;

    return true;
}
bool AutoCompleter::contextAllowsAutoQuotes(const QTextCursor &cursor, const QString &textToInsert) const
{
    if (isInComment(cursor))
        return false;

    QChar ch;

    if (!textToInsert.isEmpty())
        ch = textToInsert.at(0);

    switch (ch.unicode()) {
    case '"':
    case '\'':
        return true;

    default:
        return false;
    }
}
Beispiel #6
0
const Comment* Entity::isSpecial(qint64 pos){
    const Comment* p1 = isInComment(pos);
    const Comment* p2 = isInComment(pos+1);

    return (p1!=nullptr && p2!=p1)?p1:nullptr;
}
Beispiel #7
0
void IniFile::createMap()
{
	std::string section;
	std::string key;
	std::string value;

	int pos = 0;
	int sec_start, sec_end, key_start, key_end, value_start, value_end;

	while (pos < _FileContainer.size())
	{
		sec_start = _FileContainer.find('[', pos) + 1;
		if (isInComment(sec_start))
		{
			pos = _FileContainer.find('\n',sec_start) + 1;
			if (pos == std::string::npos + 1)
				pos = _FileContainer.size();
			continue;
		}
		while (_FileContainer[sec_start] == ' ')
			sec_start++;
		sec_end = _FileContainer.find(']', sec_start) - 1;
		while (_FileContainer[sec_end] == ' ')
			sec_end--;
		section = _FileContainer.substr(sec_start, sec_end - sec_start + 1);

		pos = sec_end;
		int end = _FileContainer.find('[', pos);
		if (end == std::string::npos)
			end = _FileContainer.size();

		while (pos < end)
		{
			key_end = _FileContainer.find('=', pos) - 1;
			if (isInComment(key_end))
			{
				pos = _FileContainer.find('\n', key_end) + 1;
				if (pos == std::string::npos + 1)
					pos = _FileContainer.size();
				continue;
			}
			while (_FileContainer[key_end] == ' ')
				key_end--;
			key_start = _FileContainer.rfind('\n', key_end) + 1;
			while (_FileContainer[key_start] == ' ')
				key_start++;
			key = _FileContainer.substr(key_start, key_end - key_start + 1);

			value_start = _FileContainer.find('=', key_end) + 1;
			while (_FileContainer[value_start] == ' ')
				value_start++;
			value_end = _FileContainer.find('\n', value_start) - 1;
			if (value_end == std::string::npos)
				value_end = _FileContainer.size() - 1;
			while (_FileContainer[value_end] == ' ')
				value_end--;
			value = _FileContainer.substr(value_start, value_end - value_start + 1);

			_FileMap.insert(std::map<std::string, std::string>::value_type(section + "|" + key, value));

			pos = _FileContainer.find('=', value_end);
			if (pos == std::string::npos)
				pos = _FileContainer.size();
		}
		if (pos == _FileContainer.size())
			break;
		pos = end;
	}
}
Beispiel #8
0
void IniFile::setStringValue(const char * section, const char * key, const char * value)
{
	int sec_start, sec_end, key_start, key_end, value_start, value_end;
	std::string sec(section);
	std::string k(key);
	std::string val(value);

	loadIniFile();

	sec_start = 0;
	int leftbrace, rightbrace, lastnewline, nextnewline;
	do {
		sec_start = _FileContainer.find(section, sec_start + 1);
		while (isInComment(sec_start))
		{
			sec_start = _FileContainer.find(section, sec_start + 1);
		}
		if (sec_start == std::string::npos)
			break;
		leftbrace = _FileContainer.rfind('[', sec_start);
		rightbrace = _FileContainer.find(']', sec_start);
		lastnewline = _FileContainer.rfind('\n', sec_start);
		nextnewline = _FileContainer.find('\n', sec_start);
		if (rightbrace == std::string::npos)
		{
			sec_start = std::string::npos;
			break;
		}
		if (nextnewline == std::string::npos)
			nextnewline = _FileContainer.size();
	} while (leftbrace < lastnewline || rightbrace > nextnewline);
	
	/* not find the section */
	if (sec_start == std::string::npos)
	{
		_FileContainer += "\n[" + sec + "]\n" + k + "=" + val + "\n";

		_FileMap.insert(std::map<std::string, std::string>::value_type(sec + "|" + k, val));
	}
	else{
		sec_end = sec_start + strlen(section);

		int bound = _FileContainer.find('[', sec_start);
		key_start = _FileContainer.find(key, sec_end);
		while (isInComment(key_start))
		{
			key_start = _FileContainer.find(key, key_start + 1);
		}

		/* not find the key */
		if (key_start == std::string::npos || (bound > std::string::npos && key_start > bound))
		{
			int pos = _FileContainer.find('\n', sec_end) + 1;
			_FileContainer.insert(pos, key);
			pos += strlen(key);
			_FileContainer.insert(pos, "=");
			pos++;
			_FileContainer.insert(pos, value);
			pos += strlen(value);
			_FileContainer.insert(pos, "\n");

			_FileMap.insert(std::map<std::string, std::string>::value_type(sec + "|" + k, val));
		}

		else {
			key_end = key_start + strlen(key);
			value_start = _FileContainer.find('=', key_end) + 1;
			while (_FileContainer[value_start] == ' ')
				value_start++;
			value_end = _FileContainer.find('\n', value_start) - 1;
			if (value_end == std::string::npos)
				value_end = _FileContainer.size() - 1;
			while (_FileContainer[value_end] == ' ')
				value_end--;

			_FileContainer.replace(value_start, value_end - value_start + 1, value);

			auto iter = _FileMap.find(sec + "|" + k);
			iter->second = val;
		}
	}

	std::fstream file(_FileName.c_str(), std::ios::out);
	file << _FileContainer;
}