comparison src/myframe.cpp @ 26:5a934c8e1b95 v2.2dev

implement shorcutkeys & file count
author pyon@macmini
date Thu, 03 Nov 2011 15:48:26 +0900
parents 5c99c6fa50df
children d21de4693652
comparison
equal deleted inserted replaced
25:b3b3b8e97b54 26:5a934c8e1b95
1 // Filename : myframe.cpp 1 // Filename : myframe.cpp
2 // Last Change: 02-Nov-2011. 2 // Last Change: 03-Nov-2011.
3 // 3 //
4 4
5 #include "main.h" 5 #include "main.h"
6 #include "myframe.h" 6 #include "myframe.h"
7 #include "param.h" 7 #include "param.h"
153 gSizer->Add( m_buttonUndo, 0, wxALL, 5 ); 153 gSizer->Add( m_buttonUndo, 0, wxALL, 5 );
154 m_buttonUndo->Enable(false); 154 m_buttonUndo->Enable(false);
155 155
156 bSizerButton->Add( gSizer, 0, wxALL, 5 ); 156 bSizerButton->Add( gSizer, 0, wxALL, 5 );
157 157
158 m_listCtrlDir = new wxListCtrl( this, ID_LISTCTRLDIR, wxDefaultPosition, wxDefaultSize, wxLC_REPORT|wxLC_SINGLE_SEL ); 158 m_listCtrlHhsDir = new wxListCtrl( this, ID_LISTCTRLDIR, wxDefaultPosition, wxDefaultSize, wxLC_REPORT|wxLC_SINGLE_SEL );
159 wxListItem itemCol; 159 wxListItem itemCol;
160 itemCol.SetText( wxT("通番") ); 160 itemCol.SetText( wxT("通番") );
161 m_listCtrlDir->InsertColumn( 0, itemCol ); 161 m_listCtrlHhsDir->InsertColumn( 0, itemCol );
162 m_listCtrlDir->SetColumnWidth( 0, 50 ); 162 m_listCtrlHhsDir->SetColumnWidth( 0, 50 );
163 itemCol.SetText( wxT("被保険者番号") ); 163 itemCol.SetText( wxT("被保険者番号") );
164 m_listCtrlDir->InsertColumn( 1, itemCol ); 164 m_listCtrlHhsDir->InsertColumn( 1, itemCol );
165 m_listCtrlDir->SetColumnWidth( 1, 100 ); 165 m_listCtrlHhsDir->SetColumnWidth( 1, 100 );
166 itemCol.SetText( wxT("ファイル数") ); 166 itemCol.SetText( wxT("ファイル数") );
167 m_listCtrlDir->InsertColumn( 2, itemCol ); 167 m_listCtrlHhsDir->InsertColumn( 2, itemCol );
168 m_listCtrlDir->SetColumnWidth( 2, 60 ); 168 m_listCtrlHhsDir->SetColumnWidth( 2, 60 );
169 169
170 bSizerButton->Add( m_listCtrlDir, 1, wxEXPAND|wxALL, 5 ); 170 bSizerButton->Add( m_listCtrlHhsDir, 1, wxEXPAND|wxALL, 5 );
171 171
172 bSizerManip->Add( bSizerButton, 0, wxEXPAND|wxALIGN_CENTER_VERTICAL, 5 ); 172 bSizerManip->Add( bSizerButton, 0, wxEXPAND|wxALIGN_CENTER_VERTICAL, 5 );
173 173
174 bSizerTop->Add( bSizerManip, 1, wxEXPAND, 5 ); 174 bSizerTop->Add( bSizerManip, 1, wxEXPAND, 5 );
175 175
191 { 191 {
192 } 192 }
193 193
194 // Event Table 194 // Event Table
195 BEGIN_EVENT_TABLE( MyFrame, wxFrame ) 195 BEGIN_EVENT_TABLE( MyFrame, wxFrame )
196 EVT_CHAR( MyFrame::OnChar )
196 EVT_IDLE( MyFrame::OnIdle ) 197 EVT_IDLE( MyFrame::OnIdle )
197 EVT_TIMER( ID_TIMER, MyFrame::OnTimer ) 198 EVT_TIMER( ID_TIMER, MyFrame::OnTimer )
198 EVT_SIZE( MyFrame::OnWinSize ) 199 EVT_SIZE( MyFrame::OnWinSize )
199 EVT_MOVE( MyFrame::OnWinMove ) 200 EVT_MOVE( MyFrame::OnWinMove )
200 EVT_MENU( ID_MENUITEMPARAM, MyFrame::OnParam ) 201 EVT_MENU( ID_MENUITEMPARAM, MyFrame::OnParam )
259 wxExecute( cmd ); 260 wxExecute( cmd );
260 } 261 }
261 /* 検知 */ 262 /* 検知 */
262 void MyFrame::OnDetect(wxCommandEvent& WXUNUSED(event)) 263 void MyFrame::OnDetect(wxCommandEvent& WXUNUSED(event))
263 { 264 {
264 UpdateCache(); 265 F5_Shortcut(); // UpdateCache -> UpdateListImage
265 UpdateListImage(); 266 }
267
268 /* 移動 */
269 void MyFrame::OnMove(wxCommandEvent& WXUNUSED(event))
270 {
271 F7_Shortcut(); // MoveImages -> UpdateCache -> UpdateListImage -> ListHhsDir
266 } 272 }
267 273
268 /* 選択したファイルを移動 */ 274 /* 選択したファイルを移動 */
269 void MyFrame::OnMove(wxCommandEvent& WXUNUSED(event)) 275 void MyFrame::MoveImages()
270 { 276 {
271 m_undo.Clear(); 277 m_undo.Clear();
272 wxString workdir = m_dirPickerWork->GetPath(); 278 wxString workdir = m_dirPickerWork->GetPath();
273 wxString distdir = m_textCtrlDist->GetValue(); 279 wxString distdir = m_textCtrlDist->GetValue();
280 wxString hhsno = m_textCtrlGuess->GetValue();
281
282 m_hhsList.Remove(hhsno);
283 m_hhsList.Add(hhsno);
274 long item = -1; 284 long item = -1;
275 for ( ;; ) { 285 for ( ;; ) {
276 item = m_listCtrlView->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); 286 item = m_listCtrlView->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
277 if ( item == -1 ) break; 287 if ( item == -1 ) break;
278 wxString hhsno = m_textCtrlGuess->GetValue();
279 if ( !wxDirExists( distdir + wxFILE_SEP_PATH + hhsno ) ) wxMkdir( distdir + wxFILE_SEP_PATH + hhsno ); 288 if ( !wxDirExists( distdir + wxFILE_SEP_PATH + hhsno ) ) wxMkdir( distdir + wxFILE_SEP_PATH + hhsno );
280 289
281 wxString file = m_listCtrlView->GetItemText( item ); 290 wxString file = m_listCtrlView->GetItemText( item );
282 wxString from = workdir + wxFILE_SEP_PATH + file; 291 wxString from = workdir + wxFILE_SEP_PATH + file;
283 wxString to = distdir + wxFILE_SEP_PATH + hhsno + wxFILE_SEP_PATH + file; 292 wxString to = distdir + wxFILE_SEP_PATH + hhsno + wxFILE_SEP_PATH + file;
284 wxRenameFile( from, to, true ); 293 wxRenameFile( from, to, true );
285 294
286 wxString movecmd = MOVECMD; 295 wxString movecmd = MOVECMD;
287 m_undo.Insert( movecmd + wxT(" ") + to + wxT(" ") + from, 0 ); 296 m_undo.Insert( movecmd + wxT(" ") + to + wxT(" ") + from, 0 );
288 } 297 }
289 UpdateCache();
290 UpdateListImage();
291 m_buttonUndo->Enable(true);
292 } 298 }
293 /* 選択したファイルを削除 */ 299 /* 選択したファイルを削除 */
294 void MyFrame::OnDelete(wxCommandEvent& WXUNUSED(event)) 300 void MyFrame::OnDelete(wxCommandEvent& WXUNUSED(event))
295 { 301 {
296 m_undo.Clear(); 302 m_undo.Clear();
321 wxMessageBox(wxT("戻し完了.")); 327 wxMessageBox(wxT("戻し完了."));
322 m_buttonUndo->Enable(false); 328 m_buttonUndo->Enable(false);
323 m_undo.Clear(); 329 m_undo.Clear();
324 UpdateCache(); 330 UpdateCache();
325 UpdateListImage(); 331 UpdateListImage();
332 ListHhsDir();
326 } 333 }
327 334
328 /* 画像をリストコントロールに表示 */ 335 /* 画像をリストコントロールに表示 */
329 void MyFrame::UpdateListImage() 336 void MyFrame::UpdateListImage()
330 { 337 {
471 wxGetApp().lmin.ToLong( &lmin ); 478 wxGetApp().lmin.ToLong( &lmin );
472 wxGetApp().lmax.ToLong( &lmax ); 479 wxGetApp().lmax.ToLong( &lmax );
473 480
474 m_buttonDetect->Enable(false); 481 m_buttonDetect->Enable(false);
475 wxGetApp().WriteLog( wxT("start updating cache") ); 482 wxGetApp().WriteLog( wxT("start updating cache") );
476 SetStatusText( wxT("rebuiling cache..."), 0 );
477 wxStopWatch sw; 483 wxStopWatch sw;
478 sw.Start(0); 484 sw.Start(0);
479 485
480 /* キャッシュ存在フラグOFF */ 486 /* キャッシュ存在フラグOFF */
481 for ( CacheHash::iterator it=CH.begin(); it != CH.end(); ++it ) { 487 for ( CacheHash::iterator it=CH.begin(); it != CH.end(); ++it ) {
483 ci = it->second; 489 ci = it->second;
484 ci->exists = false; 490 ci->exists = false;
485 } 491 }
486 492
487 wxString workdir = m_dirPickerWork->GetPath(); 493 wxString workdir = m_dirPickerWork->GetPath();
488 wxDir dir( workdir );
489 if ( !dir.IsOpened() ) return;
490
491 wxArrayString filenames; 494 wxArrayString filenames;
492 wxListItem item; 495 wxListItem item;
493 496
494 /* キャッシュ作成 */ 497 /* キャッシュ作成 */
495 unsigned int n = dir.GetAllFiles( workdir, &filenames, wxT("*.jpg"), wxDIR_FILES ); 498 unsigned int n = wxDir::GetAllFiles( workdir, &filenames, wxT("*.jpg"), wxDIR_FILES );
496 for ( int i=0; i<n; i++ ) { 499 for ( int i=0; i<n; i++ ) {
497 wxString fullpath = filenames[i]; 500 wxString fullpath = filenames[i];
498 wxFileName f( fullpath ); 501 wxFileName f( fullpath );
499 wxString file = f.GetFullName(); 502 wxString file = f.GetFullName();
500 503
524 ci->thumbnail = bmp; 527 ci->thumbnail = bmp;
525 ci->selthumbnail = bmp_mask; 528 ci->selthumbnail = bmp_mask;
526 ci->modtime = wxEmptyString; // TODO. 529 ci->modtime = wxEmptyString; // TODO.
527 530
528 CH[ci->filename] = ci; // add hash 531 CH[ci->filename] = ci; // add hash
529 SetStatusText( wxString::Format( wxT("rebuiling cache...(%.1fsec passed)"), (float)sw.Time()/1000 ), 0 ); 532 SetStatusText( wxString::Format( wxT("rebuiling cache...( %d/%d :%.1fsec passed )"), i+1, n, (float)sw.Time()/1000 ), 0 );
530 wxGetApp().WriteLog( file + wxT(" appended.") + wxString::Format(wxT(" ( m=%d z=%f l=%d )"), m ? 1 : 0, z, l ) ); 533 wxGetApp().WriteLog( file + wxT(" appended.") + wxString::Format(wxT(" ( m=%d z=%f l=%d )"), m ? 1 : 0, z, l ) );
531 } 534 }
532 535
533 /* 存在しないファイルはキャッシュから削除 */ 536 /* 存在しないファイルはキャッシュから削除 */
534 wxArrayString removelist; 537 wxArrayString removelist;
545 m_buttonDetect->Enable(true); 548 m_buttonDetect->Enable(true);
546 SetStatusText( wxEmptyString, 0 ); 549 SetStatusText( wxEmptyString, 0 );
547 m_timer.Start( 20*1000, wxTIMER_ONE_SHOT ); // restart 550 m_timer.Start( 20*1000, wxTIMER_ONE_SHOT ); // restart
548 } 551 }
549 552
550 /* 被保険者を開く */ 553 /* 被保険者フォルダを列挙 */
554 void MyFrame::ListHhsDir()
555 {
556 wxString distdir = m_textCtrlDist->GetValue();
557 wxString hhsdir;
558 wxString buf;
559
560 m_listCtrlHhsDir->DeleteAllItems();
561 for ( int i=0; i<m_hhsList.GetCount(); i++ ) {
562 hhsdir = distdir + wxFILE_SEP_PATH + m_hhsList[i];
563 wxArrayString filenames;
564 unsigned int n = wxDir::GetAllFiles( hhsdir, &filenames, wxT("*.jpg"), wxDIR_FILES );
565
566 m_listCtrlHhsDir->InsertItem( i, -1 );
567 buf.Printf(wxT("%d"),i+1);
568 m_listCtrlHhsDir->SetItem( i, 0, buf, -1 );
569 m_listCtrlHhsDir->SetItem( i, 1, m_hhsList[i], -1 );
570 buf.Printf(wxT("%d"),n);
571 m_listCtrlHhsDir->SetItem( i, 2, buf, -1 );
572 if ( i % 2 ) m_listCtrlHhsDir->SetItemBackgroundColour( i, wxColour(wxT("WHEAT")) );
573 }
574 }
575
576 /* 被保険者フォルダを開く */
551 void MyFrame::OnOpenHhsDir(wxListEvent& event) 577 void MyFrame::OnOpenHhsDir(wxListEvent& event)
552 { 578 {
553 wxString hhsdir = m_textCtrlDist->GetValue(); 579 wxString hhsdir;
580 hhsdir.Append( m_textCtrlDist->GetValue() );
554 hhsdir.Append( wxFILE_SEP_PATH ); 581 hhsdir.Append( wxFILE_SEP_PATH );
555 582
556 wxListItem item = event.GetItem(); 583 wxListItem item = event.GetItem();
557 item.SetColumn(1); 584 item.SetColumn(1);
558 item.SetMask(wxLIST_MASK_TEXT); 585 item.SetMask(wxLIST_MASK_TEXT);
559 m_listCtrlDir->GetItem( item ); 586 m_listCtrlHhsDir->GetItem( item );
560 hhsdir.Append( item.GetText() ); 587 hhsdir.Append( item.GetText() );
561 wxString execmd = wxT("explorer ") + hhsdir; 588 wxString execmd = wxT("explorer ") + hhsdir;
562 wxExecute( execmd ); 589 wxExecute( execmd );
590 //wxMessageBox(hhsdir);
563 } 591 }
564 592
565 // 以下,定型もの 593 // 以下,定型もの
566 void MyFrame::OnTimer(wxTimerEvent& event) 594 void MyFrame::OnTimer(wxTimerEvent& event)
567 { 595 {
568 UpdateCache(); 596 UpdateCache();
569 } 597 }
598
599 /* キーハンドリング */
600 void MyFrame::OnChar(wxKeyEvent& event)
601 {
602 if ( event.GetKeyCode() == WXK_F5 ) F5_Shortcut();
603 if ( event.GetKeyCode() == WXK_F7 ) F7_Shortcut();
604 }
605 void MyFrame::F5_Shortcut()
606 {
607 UpdateCache();
608 UpdateListImage();
609 }
610 void MyFrame::F7_Shortcut()
611 {
612 MoveImages();
613 UpdateCache();
614 UpdateListImage();
615 ListHhsDir();
616 m_buttonUndo->Enable(true);
617 }
618
570 /* アイドリング */ 619 /* アイドリング */
571 void MyFrame::OnIdle(wxIdleEvent& event) 620 void MyFrame::OnIdle(wxIdleEvent& event)
572 { 621 {
573 if ( !m_timer.IsRunning() ) { 622 if ( !m_timer.IsRunning() ) {
574 m_timer.Start( 20*1000, wxTIMER_ONE_SHOT ); 623 m_timer.Start( 20*1000, wxTIMER_ONE_SHOT );