Commit d57f3d38 authored by Joachim Eibl's avatar Joachim Eibl

Always stay up to date with history from registry

git-svn-id: https://kdiff3.svn.sourceforge.net/svnroot/kdiff3/trunk@149 c8aa9fed-2811-0410-8543-893ada326672
parent 1de3cc79
......@@ -12,7 +12,7 @@ else
CXXFLAGS ?= -Os
LDFLAGS += -s
endif
CXXFLAGS += -ansi -pedantic -Wall -W -D_UNICODE -DUNICODE
CXXFLAGS += -pedantic -Wall -W -D_UNICODE -DUNICODE
LIBS := -luuid -lole32
DEFFILE = $(PROJ).def
......
......@@ -330,6 +330,9 @@ STDMETHODIMP
DIFF_EXT::QueryContextMenu(HMENU menu, UINT position, UINT first_cmd, UINT /*last_cmd not used*/, UINT flags)
{
LOG();
SERVER::instance()->recent_files(); // updates recent files list (reads from registry)
m_id_Diff = UINT(-1);
m_id_DiffWith = UINT(-1);
m_id_DiffLater = UINT(-1);
......@@ -473,12 +476,14 @@ DIFF_EXT::InvokeCommand(LPCMINVOKECOMMANDINFO ici)
{
LOG();
m_recentFiles.clear();
SERVER::instance()->save_history();
}
else if(id == m_id_DiffLater)
{
MESSAGELOG(TEXT("Diff Later: ")+_file_name1);
m_recentFiles.remove( _file_name1 );
m_recentFiles.push_front( _file_name1 );
SERVER::instance()->save_history();
}
else if(id >= m_id_DiffWith_Base && id < m_id_DiffWith_Base+m_recentFiles.size())
{
......
......@@ -243,16 +243,20 @@ SERVER::recent_files()
LOG();
if ( m_pRecentFiles==0 )
{
MESSAGELOG(TEXT("Reading history from registry..."));
m_pRecentFiles = new std::list<tstring>;
for( int i=0; i<32; ++i ) // Max history size
{
TCHAR numAsString[10];
_sntprintf( numAsString, 10, TEXT("%d"), i );
tstring historyItem = getRegistryKeyString( TEXT("history"), numAsString );
if ( ! historyItem.empty() )
m_pRecentFiles->push_back( historyItem );
}
}
else
{
m_pRecentFiles->clear();
}
MESSAGELOG(TEXT("Reading history from registry..."));
for( int i=0; i<32; ++i ) // Max history size
{
TCHAR numAsString[10];
_sntprintf( numAsString, 10, TEXT("%d"), i );
tstring historyItem = getRegistryKeyString( TEXT("history"), numAsString );
if ( ! historyItem.empty() )
m_pRecentFiles->push_back( historyItem );
}
return *m_pRecentFiles;
}
......@@ -260,7 +264,7 @@ SERVER::recent_files()
void
SERVER::save_history() const
{
if( m_pRecentFiles && !m_pRecentFiles->empty() )
if( m_pRecentFiles )
{
HKEY key;
if( RegCreateKeyEx(HKEY_CURRENT_USER, (m_registryBaseName + TEXT("\\history")).c_str(), 0, 0,
......@@ -283,10 +287,16 @@ SERVER::save_history() const
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, 0,
GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &message, 0, 0);
MessageBox(0, message, TEXT("Save history failed"), MB_OK | MB_ICONINFORMATION);
MessageBox(0, message, TEXT("KDiff3-diff-ext: Save history failed"), MB_OK | MB_ICONINFORMATION);
LocalFree(message);
}
}
for(; n<32; ++n )
{
TCHAR numAsString[10];
_sntprintf( numAsString, 10, TEXT("%d"), n );
RegDeleteValue(key, numAsString );
}
RegCloseKey(key);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment