/* * Copyright 2004 Perforce Software. All rights reserved. * * Developed by Data Shades Ltd. */ #include "FullSubmitDialog.h" #include "debug.h" #define SUBMIT_DESC _T("<enter description here>") FullSubmitDialog::FullSubmitDialog( PluginOperations *ops, PerforceConnection *con, PerforceResults *results, StrPtr *curr, BOOL showOther ) : Dialog( ops, IDD_FULL_SUBMIT_DIALOG, DialogWndProc ) { desc = NULL; submitFiles = NULL; submitJobs = NULL; jobStatus = FALSE; this->con = con; this->results = results; this->curr = curr; this->showOther = showOther; } FullSubmitDialog::~FullSubmitDialog() { if ( desc != NULL ) { delete []desc; } if ( submitFiles != NULL ) { delete submitFiles; } if ( submitJobs != NULL ) { delete submitJobs; } } BOOL CALLBACK FullSubmitDialog::DialogWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { HWND changeDesc = GetDlgItem( hWnd, IDC_CHANGE_DESC_EDIT ); HWND documentsLabel = GetDlgItem( hWnd, IDC_DOCUMENTS_LABEL ); HWND openFile = GetDlgItem( hWnd, IDC_OPEN_FILE_LIST ); HWND jobsLabel = GetDlgItem( hWnd, IDC_JOBS_LABEL ); HWND openJob = GetDlgItem( hWnd, IDC_OPEN_JOB_LIST ); HWND statusLabel = GetDlgItem( hWnd, IDC_STATUS_LABEL ); HWND statusCombo = GetDlgItem( hWnd, IDC_JOB_STATUS_COMBO ); HWND keepOut = GetDlgItem( hWnd, IDC_KEEP_OUT_CHECK ); HWND okButton = GetDlgItem( hWnd, IDOK ); HWND cancelButton = GetDlgItem( hWnd, IDCANCEL ); switch(uMsg) { case WM_INITDIALOG: { FullSubmitDialog *dialog = ( FullSubmitDialog * )lParam; SaveDialogObject( hWnd, dialog ); SendMessage( changeDesc, WM_SETTEXT, 0, (LPARAM) SUBMIT_DESC ); SendMessage( changeDesc, EM_SETSEL, 0, -1 ); SetFocus( changeDesc ); int numMainWin = 1; HWND lastControl = changeDesc; DWORD style = ListView_GetExtendedListViewStyle( openFile ); style |= LVS_EX_CHECKBOXES; ListView_SetExtendedListViewStyle( openFile, style ); style = ListView_GetExtendedListViewStyle( openJob ); style |= LVS_EX_CHECKBOXES; ListView_SetExtendedListViewStyle( openJob, style ); // Can't use images with checks as it creates alignment problems //SetListViewImageLists( fileList ); LV_COLUMN col; col.mask = LVCF_SUBITEM | LVCF_FMT | LVCF_TEXT | LVCF_WIDTH; col.fmt = LVCFMT_LEFT; col.cx = 200; col.pszText = _T("Documents:"); col.iSubItem = 0; ListView_InsertColumn( openFile, 0, &col ); col.cx = 400; ListView_InsertColumn( openJob, 0, &col ); LV_ITEM item; item.mask = LVIF_TEXT; item.iSubItem = 0; StrBuf fileText; RECT rect; PerforceResults *results = dialog->Results(); StrPtr *curr = dialog->CurrFile(); if ( results->Count() > 0 ) { UniStrDict *dict = ( UniStrDict * )dialog->Results()->Get( 0 ); StrBuf key; for ( int i=0;;i++ ) { key.Clear(); key << "Files" << i; StrPtr *filename = dict->GetVar ( key ); if ( filename == NULL ) { break; } item.pszText = (TCHAR *)filename->Text(); item.iItem = i; //item.iImage = FileIcon( filename ); ListView_InsertItem( openFile, &item ); if ( *filename == *curr ) { ListView_SetCheckState( openFile, i, TRUE ); } } if ( dict->GetVar( "Jobs0" ) ) { dialog->FillJobStatus( statusCombo ); StrPtr *data = dict->GetVar( "data" ); TCHAR *start = _tcsstr( (TCHAR *)data->Text(), _T("\nJobs:\n") ); UniStrBuf fullDesc; TCHAR jobDesc[80]; for ( int i=0;;i++ ) { key.Clear(); key << "Jobs" << i; StrPtr *jobname = dict->GetVar ( key ); if ( jobname == NULL ) { break; } // Get the job description TCHAR *begin = _tcschr( start, '#' ) + 2; for ( start = begin; *start != '\n'; start++ ) { } _tcsncpy_s( jobDesc, begin, start - begin ); jobDesc[start - begin] = '\0'; fullDesc.Set( jobname ); fullDesc.Append( _T(" - ") ); fullDesc.Append( jobDesc ); item.pszText = fullDesc.Text(); item.iItem = i; ListView_InsertItem( openJob, &item ); } lastControl = openJob; numMainWin++; } else { ShowWindow( openJob, SW_HIDE ); EnableWindow( openJob, FALSE ); ShowWindow( statusCombo, SW_HIDE ); EnableWindow( statusCombo, FALSE ); ShowWindow( jobsLabel, SW_HIDE ); EnableWindow( jobsLabel, FALSE ); ShowWindow( statusLabel, SW_HIDE ); EnableWindow( statusLabel, FALSE ); } } if ( dialog->ShowOther() ) { GetControlPos( hWnd, lastControl, &rect ); MoveControlY( hWnd, documentsLabel, rect.bottom + 20 ); GetControlPos( hWnd, documentsLabel, &rect); MoveControlY( hWnd, openFile, rect.bottom + 4 ); lastControl = openFile; numMainWin++; } else { ShowWindow( documentsLabel, SW_HIDE ); EnableWindow( documentsLabel, FALSE ); ShowWindow( openFile, SW_HIDE ); EnableWindow( openFile, FALSE ); } GetControlPos( hWnd, lastControl, &rect ); int lastBottom = rect.bottom; MoveControlY( hWnd, keepOut, lastBottom + 5 ); MoveControlY( hWnd, okButton, lastBottom + 40 ); MoveControlY( hWnd, cancelButton, lastBottom + 40 ); // Set height of dialog GetWindowRect( hWnd, &rect ); MoveWindow( hWnd, rect.left, rect.top, rect.right - rect.left, lastBottom + 110, FALSE ); ListView_SetColumnWidth( openFile, 0, LVSCW_AUTOSIZE ); Centre( hWnd ); SaveInitialSizes( hWnd ); if ( numMainWin == 3 ) { SetResizeFlags( changeDesc, RESIZE_WIDTH | RESIZE_HEIGHT_THIRD ); } else if ( numMainWin == 2 ) { SetResizeFlags( changeDesc, RESIZE_WIDTH | RESIZE_HEIGHT_HALF ); } else { SetResizeFlags( changeDesc, RESIZE_WIDTH | RESIZE_HEIGHT ); } if ( numMainWin == 3 ) { SetResizeFlags( jobsLabel, RESIZE_TOP_THIRD ); SetResizeFlags( openJob, RESIZE_TOP_THIRD | RESIZE_WIDTH | RESIZE_HEIGHT_THIRD ); SetResizeFlags( statusLabel, RESIZE_TOP_THIRD ); SetResizeFlags( statusCombo, RESIZE_TOP_THIRD | RESIZE_WIDTH ); } else { SetResizeFlags( jobsLabel, RESIZE_TOP_HALF ); SetResizeFlags( openJob, RESIZE_TOP_HALF | RESIZE_WIDTH | RESIZE_HEIGHT_HALF ); SetResizeFlags( statusLabel, RESIZE_TOP_HALF ); SetResizeFlags( statusCombo, RESIZE_TOP_HALF | RESIZE_WIDTH ); } if ( numMainWin == 3 ) { SetResizeFlags( documentsLabel, RESIZE_TOP_TWOTHIRD ); SetResizeFlags( openFile, RESIZE_TOP_TWOTHIRD | RESIZE_WIDTH | RESIZE_HEIGHT_THIRD ); SetResizeFlags( keepOut, RESIZE_TOP ); SetResizeFlags( okButton, RESIZE_TOP | RESIZE_LEFT_HALF ); SetResizeFlags( cancelButton, RESIZE_TOP | RESIZE_LEFT_HALF ); } else { SetResizeFlags( documentsLabel, RESIZE_TOP_HALF ); SetResizeFlags( openFile, RESIZE_TOP_HALF | RESIZE_WIDTH | RESIZE_HEIGHT_HALF ); SetResizeFlags( keepOut, RESIZE_TOP ); SetResizeFlags( okButton, RESIZE_TOP | RESIZE_LEFT_HALF ); SetResizeFlags( cancelButton, RESIZE_TOP | RESIZE_LEFT_HALF ); } return true; break; } case WM_GETMINMAXINFO: SetMinimumSize( hWnd, (LPMINMAXINFO) lParam ); return true; break; case WM_SIZE: Resize( hWnd, lParam ); return true; break; case WM_PAINT: { FullSubmitDialog *dialog = ( FullSubmitDialog * )DialogObject( hWnd ); dialog->PaintSizeGrip( hWnd ); break; } case WM_NCHITTEST: { return HitTestSizeGrip( hWnd, lParam ); } case WM_COMMAND: switch ( LOWORD( wParam ) ) { case IDOK: { FullSubmitDialog *dialog = ( FullSubmitDialog * )DialogObject( hWnd ); int len = SendMessage( changeDesc, WM_GETTEXTLENGTH, 0, 0 ) + 1; TCHAR *text = new TCHAR[ len ]; GetWindowText( changeDesc, text, len ); bool valid = true; // Check user a has enter a description if ( _tcslen( text ) == 0 || _tcscmp ( text, SUBMIT_DESC ) == 0 ) { MessageBox( hWnd, _T("Please enter a description."), _T("Check In to Perforce"), MB_ICONEXCLAMATION | MB_OK ); SetFocus( changeDesc ); valid = false; } // Check user has selected at least one file if ( valid ) { HWND fileList = GetDlgItem( hWnd, IDC_OPEN_FILE_LIST ); int count = ListView_GetItemCount( fileList ); bool gotOne = false; for ( int i=0; i<count; i++ ) { if ( ListView_GetCheckState( fileList, i ) == TRUE ) { gotOne = true; break; } } if ( !gotOne ) { MessageBox( hWnd, _T("Please select at least one file."), _T("Check In to Perforce"), MB_ICONEXCLAMATION | MB_OK ); SetFocus( fileList ); valid = false; } } if ( valid ) { // Remove carriage returns and add tabs for ( int i=0; text[i] != '\0'; i++ ) { if ( text[i] == '\r' && text[i + 1] == '\n' ) { text[i] = '\n'; text[i + 1] = '\t'; } } dialog->SetDescription( text ); PerforceResults *results = dialog->Results(); UniStrDict *dict = ( UniStrDict * )dialog->Results()->Get( 0 ); StrBuf key; StrPtr *value; // Get checked files UniStrBuf *files = new UniStrBuf(); int count = ListView_GetItemCount( openFile ); for ( int i=0; i<count; i++ ) { if ( ListView_GetCheckState( openFile, i ) == TRUE ) { key.Clear(); key << "Files" << i; value = dict->GetVar ( key ); files->Append( _T("\n\t") ); files->Append( value ); } } dialog->SetSubmitFiles( files ); TCHAR selectedStatus[128] = {'\0'}; // Get the job status int idx = SendMessage( statusCombo, CB_GETCURSEL, (WPARAM) 0, (LPARAM) 0 ); // Ignore first "(default)" entry if ( idx > 0 ) { dialog->SetJobStatus(); SendMessage( statusCombo, CB_GETLBTEXT, (WPARAM) idx, (LPARAM) selectedStatus ); } // Get checked jobs UniStrBuf *jobs = new UniStrBuf(); count = ListView_GetItemCount( openJob ); for ( int i=0; i<count; i++ ) { if ( ListView_GetCheckState( openJob, i ) == TRUE ) { key.Clear(); key << "Jobs" << i; value = dict->GetVar ( key ); jobs->Append( _T("\n\t") ); jobs->Append( value ); if ( _tcslen( selectedStatus ) > 0 ) { jobs->Append( _T(" ") ); jobs->Append( selectedStatus ); } } } dialog->SetSubmitJobs( jobs ); HWND check = GetDlgItem( hWnd, IDC_KEEP_OUT_CHECK ); dialog->SetKeepOut( ( int )SendMessage( check, BM_GETCHECK, 0, 0 ) ); FinishDialog( hWnd, TRUE ); } else { delete []text; } return true; } case IDCANCEL: FinishDialog( hWnd, FALSE ); return true; } } return false; } void FullSubmitDialog::FillJobStatus( HWND combo ) { PerforceResults results; PerforceCommand cmd( _T("jobspec"), _T("-o") ); con->Exec( &cmd, &results ); if ( results.Count() > 0 ) { UniStrDict *dict = ( UniStrDict * )results.Get( 0 ); StrBuf key; TCHAR statusName[80] = { '\0' }; for ( int i=0;;i++ ) { key.Clear(); key << "Fields" << i; StrPtr *fieldname = dict->GetVar ( key ); if ( fieldname == NULL ) { break; } TCHAR *text = (TCHAR *)fieldname->Text(); // Look for status field if ( _tcsncmp( text, _T("102"), 3 ) == 0 ) { TCHAR *end = _tcschr( text + 4, ' '); _tcsncpy_s( statusName, text + 4, end - ( text + 4 ) ); statusName[end - ( text + 4 ) ] = '\0'; break; } } if ( _tcslen( statusName ) > 0 ) { for ( int i=0;;i++ ) { key.Clear(); key << "Values" << i; StrPtr *valuename = dict->GetVar ( key ); if ( valuename == NULL ) { break; } TCHAR *text = (TCHAR *)valuename->Text(); // Look for status field if ( _tcsncmp( text, statusName, _tcslen( statusName ) ) == 0 ) { SendMessage( combo, CB_ADDSTRING, (WPARAM) 0, (LPARAM) _T("(default)") ); TCHAR *start = _tcschr( text, ' ') + 1; TCHAR *end; TCHAR buff[80]; while ( end = _tcschr( start, '/' ), end != NULL ) { _tcsncpy_s( buff, start, end - start ); buff[end - start] = '\0'; start = end + 1; SendMessage( combo, CB_ADDSTRING, (WPARAM) 0, (LPARAM) buff ); } SendMessage( combo, CB_ADDSTRING, (WPARAM) 0, (LPARAM) start ); break; } } } } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 11314 | Robert Cowham | Initial population of perforce_software version of P4OFC | ||
//guest/robert_cowham/perforce/P4OFC/main/libp4gt/FullSubmitDialog.cpp | |||||
#1 | 10843 | Robert Cowham |
Initial version of P4OFC source code. See README.txt (and LICENSE.txt and doc\P4OFC-Design.docx) |