/*
   SaveForbid - принудительно запретить запись добавляемой строки.
                Используется на панели плагина
*/
void History::AddToHistory(const string& Str, history_record_type Type, const GUID* Guid, const wchar_t *File, const wchar_t *Data, bool SaveForbid)
{
	_ASSERTE(this!=NULL);
	if (!m_EnableAdd || SaveForbid)
		return;

	if (Global->CtrlObject->Macro.IsExecuting() && Global->CtrlObject->Macro.IsHistoryDisable((int)m_TypeHistory))
		return;

	if (m_TypeHistory!=HISTORYTYPE_DIALOG && (m_TypeHistory!=HISTORYTYPE_FOLDER || !Guid || *Guid == FarGuid) && Str.empty())
		return;

	bool Lock = false;
	string strName(Str),strGuid,strFile(NullToEmpty(File)),strData(NullToEmpty(Data));
	if(Guid) strGuid=GuidToStr(*Guid);

	unsigned __int64 DeleteId = 0;

	const bool ignore_data = m_TypeHistory == HISTORYTYPE_CMD;

	if (m_RemoveDups) // удалять дубликаты?
	{
		DWORD index=0;
		string strHName,strHGuid,strHFile,strHData;
		history_record_type HType;
		bool HLock;
		unsigned __int64 id;
		unsigned __int64 Time;
		while (HistoryCfgRef()->Enum(index++,m_TypeHistory,m_HistoryName,&id,strHName,&HType,&HLock,&Time,strHGuid,strHFile,strHData))
		{
			if (EqualType(Type,HType))
			{
				typedef int (*CompareFunction)(const string&, const string&);
				CompareFunction CaseSensitive = StrCmp, CaseInsensitive = StrCmpI;
				CompareFunction CmpFunction = (m_RemoveDups == 2 ? CaseInsensitive : CaseSensitive);

				if (!CmpFunction(strName, strHName) &&
					!CmpFunction(strGuid, strHGuid) &&
					!CmpFunction(strFile, strHFile) &&
					(ignore_data || !CmpFunction(strData, strHData)))
				{
					Lock = Lock || HLock;
					DeleteId = id;
					break;
				}
			}
		}
	}

	HistoryCfgRef()->DeleteAndAddAsync(DeleteId, m_TypeHistory, m_HistoryName, strName, Type, Lock, strGuid, strFile, strData);  //Async - should never be used in a transaction

	ResetPosition();
}
Example #2
0
void History::AddToHistoryLocal(const wchar_t *Str, const wchar_t *Prefix, int Type)
{
	if (!Str || !*Str)
		return;

	// xeno.by: I'd love to learn an idiomatic way to exclude stuff from command history
	string WrappedStr(Str);
	if (WrappedStr.Equal(0, "last")) return;
	if (WrappedStr.Equal(0, "edit:")) return;
	if (WrappedStr.Equal(0, "clip:")) return;
	if (WrappedStr.Equal(0, "tmp:")) return;
	if (WrappedStr.Equal(0, "myke clean")) return;
	if (WrappedStr.Equal(0, "myke smart-")) return;
	if (WrappedStr.Equal(0, "myke menu")) return;
	if (WrappedStr.Equal(0, "myke make-test-suite")) return;
	if (WrappedStr.Equal(0, "myke add-files-to-test-suite")) return;
	if (WrappedStr.Equal(0, "myke remove-files-from-test-suite")) return;

	HistoryRecord AddRecord;

	if (TypeHistory == HISTORYTYPE_FOLDER && Prefix && *Prefix)
	{
		AddRecord.strName = Prefix;
		AddRecord.strName += L":";
	}

	AddRecord.strName += Str;
	AddRecord.Type=Type;

	if (RemoveDups) // удалять дубликаты?
	{
		for (HistoryRecord *HistoryItem=HistoryList.First(); HistoryItem ; HistoryItem=HistoryList.Next(HistoryItem))
		{
			if (EqualType(AddRecord.Type,HistoryItem->Type))
			{
				if ((RemoveDups==1 && !StrCmp(AddRecord.strName,HistoryItem->strName)) ||
				        (RemoveDups==2 && !StrCmpI(AddRecord.strName,HistoryItem->strName)))
				{
					AddRecord.Lock=HistoryItem->Lock;
					HistoryItem=HistoryList.Delete(HistoryItem);
					break;
				}
			}
		}
	}

	if (HistoryList.Count()>=HistoryCount)
	{
		for (HistoryRecord *HistoryItem=HistoryList.First(); HistoryItem && HistoryList.Count()>=HistoryCount; )
		{
			if (!HistoryItem->Lock)
			{
				HistoryRecord *tmp = HistoryItem;
				HistoryItem=HistoryList.Next(HistoryItem);
				HistoryList.Delete(tmp);
			}
			else
			{
				HistoryItem=HistoryList.Next(HistoryItem);
		    }
		}
	}

	GetSystemTimeAsFileTime(&AddRecord.Timestamp); // in UTC
	HistoryList.Push(&AddRecord);
	ResetPosition();
}