38 m_list =
new wxListCtrl(
this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_SINGLE_SEL );
39 m_list->AppendColumn(
_(
"Title" ) );
40 m_list->AppendColumn(
_(
"Time" ) );
41 m_list->SetColumnWidth( 0, FromDIP( 200 ) );
42 m_list->SetColumnWidth( 1, FromDIP( 150 ) );
44 wxBoxSizer* sizer =
new wxBoxSizer( wxVERTICAL );
45 sizer->Add(
m_list, 1, wxEXPAND );
63 if( !IsShownOnScreen() )
69 wxFileName hist( aProjectPath, wxS(
".history" ) );
71 git_repository* repo =
nullptr;
72 if( git_repository_open( &repo, hist.GetFullPath().mb_str().data() ) != 0 )
75 git_revwalk* walk =
nullptr;
76 if( git_revwalk_new( &walk, repo ) != 0 )
78 git_repository_free( repo );
82 if( git_revwalk_push_head( walk ) != 0 )
84 git_revwalk_free( walk );
85 git_repository_free( repo );
89 wxDateTime now = wxDateTime::Now();
92 while( git_revwalk_next( &oid, walk ) == 0 )
94 git_commit* commit =
nullptr;
95 if( git_commit_lookup( &commit, repo, &oid ) != 0 )
99 info.hash = wxString::FromUTF8( git_oid_tostr_s( &oid ) );
100 info.summary = wxString::FromUTF8( git_commit_summary( commit ) );
101 info.message = wxString::FromUTF8( git_commit_message( commit ) );
102 info.date = wxDateTime(
static_cast<time_t
>( git_commit_time( commit ) ) );
105 wxTimeSpan elapsed = now -
info.date;
108 if( elapsed.GetMinutes() < 1 )
110 timeStr =
_(
"Moments ago" );
112 else if( elapsed.GetMinutes() < 91 )
114 int minutes = elapsed.GetMinutes();
115 timeStr = wxString::Format(
_(
"%d minutes ago" ), minutes );
117 else if( elapsed.GetHours() < 24 )
119 int hours = elapsed.GetHours();
120 timeStr = wxString::Format(
_(
"%d hours ago" ), hours );
124 timeStr =
info.date.Format();
127 wxString title =
info.message.BeforeFirst(
'\n' );
128 long row =
m_list->InsertItem(
m_list->GetItemCount(), title );
129 m_list->SetItem( row, 1, timeStr );
132 if(
info.summary.StartsWith( wxS(
"Autosave" ) ) )
133 m_list->SetItemTextColour( row, wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
134 else if(
info.summary.StartsWith( wxS(
"Backup" ) ) )
135 m_list->SetItemTextColour( row, wxColour( 80, 120, 200 ) );
138 git_commit_free( commit );
141 git_revwalk_free( walk );
142 git_repository_free( repo );
LOCAL_HISTORY_PANE(KICAD_MANAGER_FRAME *aParent)
void OnRefreshTimer(wxTimerEvent &aEvent)
void OnRightClick(wxListEvent &aEvent)
KICAD_MANAGER_FRAME * m_frame
void RefreshHistory(const wxString &aProjectPath)
void OnRefreshEvent(wxCommandEvent &aEvent)
std::vector< LOCAL_COMMIT_INFO > m_commits
void OnMotion(wxMouseEvent &aEvent)
wxDEFINE_EVENT(EVT_LOCAL_HISTORY_REFRESH, wxCommandEvent)