📄 cdlgtagjumplist.cpp
字号:
//標準
::ShowWindow( ::GetDlgItem( m_hWnd, IDC_STATIC_KEYWORD ), FALSE );
::ShowWindow( hwndKey, FALSE );
::ShowWindow( ::GetDlgItem( m_hWnd, IDC_CHECK_ICASE ), FALSE );
::ShowWindow( ::GetDlgItem( m_hWnd, IDC_CHECK_ANYWHERE ), FALSE );
bRet = TRUE;
}else{
//キーワード指定
::ShowWindow( ::GetDlgItem( m_hWnd, IDC_STATIC_KEYWORD ), TRUE );
::ShowWindow( hwndKey, TRUE );
::ShowWindow( ::GetDlgItem( m_hWnd, IDC_CHECK_ICASE ), TRUE );
::ShowWindow( ::GetDlgItem( m_hWnd, IDC_CHECK_ANYWHERE ), TRUE );
::SetFocus( hwndKey );
bRet = FALSE; //for set focus
}
/* 基底クラスメンバ */
CDialog::OnInitDialog( m_hWnd, wParam, lParam );
return bRet;
}
BOOL CDlgTagJumpList::OnBnClicked( int wID )
{
switch( wID )
{
case IDC_BUTTON_HELP:
/* ヘルプ */
::WinHelp( m_hWnd, m_szHelpFile, HELP_CONTEXT, ::FuncID_To_HelpContextID( F_TAGJUMP_LIST ) );
return TRUE;
case IDOK: /* 左右に表示 */
StopTimer();
/* ダイアログデータの取得 */
::EndDialog( m_hWnd, (BOOL)GetData() );
return TRUE;
case IDCANCEL:
StopTimer();
::EndDialog( m_hWnd, FALSE );
return TRUE;
// From Here 2005.04.03 MIK 検索条件設定
case IDC_CHECK_ICASE:
StartTimer();
m_bTagJumpICase = ::IsDlgButtonChecked( m_hWnd, IDC_CHECK_ICASE ) == BST_CHECKED ? TRUE : FALSE;
return TRUE;
case IDC_CHECK_ANYWHERE:
StartTimer();
m_bTagJumpAnyWhere = ::IsDlgButtonChecked( m_hWnd, IDC_CHECK_ANYWHERE ) == BST_CHECKED ? TRUE : FALSE;
return TRUE;
// To Here 2005.04.03 MIK 検索条件設定
}
/* 基底クラスメンバ */
return CDialog::OnBnClicked( wID );
}
BOOL CDlgTagJumpList::OnNotify( WPARAM wParam, LPARAM lParam )
{
NMHDR* pNMHDR;
HWND hwndList;
pNMHDR = (NMHDR*)lParam;
hwndList = GetDlgItem( m_hWnd, IDC_LIST_TAGJUMP );
// 候補一覧リストボックス
if( hwndList == pNMHDR->hwndFrom )
{
switch( pNMHDR->code )
{
case NM_DBLCLK:
m_nIndex = ListView_GetNextItem( hwndList, -1, LVIS_SELECTED );
if( m_nIndex == -1 || m_nIndex >= m_cList.GetCount() ) return TRUE;
StopTimer();
::EndDialog( m_hWnd, GetData() );
return TRUE;
}
}
/* 基底クラスメンバ */
return CDialog::OnNotify( wParam, lParam );
}
/*!
タイマー経過
タイマーを停止し,候補リストを更新する
*/
BOOL CDlgTagJumpList::OnTimer( WPARAM wParam )
{
StopTimer();
char szKey[ MAX_TAG_STRING_LENGTH ];
strcpy( szKey, "" );
::GetDlgItemText( m_hWnd, IDC_KEYWORD, szKey, sizeof( szKey ) );
find_key( szKey );
UpdateData();
return TRUE;
}
/*!
タイマー経過
タイマーを停止し,候補リストを更新する
*/
BOOL CDlgTagJumpList::OnCbnEditChange( HWND hwndCtl, int wID )
{
StartTimer();
/* 基底クラスメンバ */
return CDialog::OnCbnEditChange( hwndCtl, wID );
}
BOOL CDlgTagJumpList::OnCbnSelChange( HWND hwndCtl, int wID )
{
StartTimer();
/* 基底クラスメンバ */
return CDialog::OnCbnSelChange( hwndCtl, wID );
}
#if 0
BOOL CDlgTagJumpList::OnEditChange( HWND hwndCtl, int wID )
{
StartTimer();
/* 基底クラスメンバ */
return CDialog::OnEditChange( hwndCtl, wID );
}
#endif
LPVOID CDlgTagJumpList::GetHelpIdTable( void )
{
return (LPVOID)p_helpids;
}
bool CDlgTagJumpList::AddParam( char *s0, char *s1, int n2, char *s3, char *s4, int depth )
{
if( -1 == m_nIndex ) m_nIndex = 0; //規定値
m_cList.AddParam( s0, s1, n2, s3[0], s4, depth );
return true;
}
bool CDlgTagJumpList::GetSelectedParam( char *s0, char *s1, int *n2, char *s3, char *s4, int *depth )
{
if( -1 == m_nIndex || m_nIndex >= m_cList.GetCount() ) return false;
m_cList.GetParam( m_nIndex, s0, s1, n2, &s3[0], s4, depth );
return true;
}
char *CDlgTagJumpList::GetNameByType( const char type, const char *name )
{
const char *p;
char *token;
int i;
// 2005.03.31 MIK
char tmp[MAX_TAG_STRING_LENGTH];
p = strrchr( name, '.' );
if( ! p ) p = ".c"; //見つからないときは ".c" と想定する。
p++;
for( i = 0; p_extentions[i]; i += 2 )
{
strcpy( tmp, p_extentions[i] );
token = strtok( tmp, "," );
while( token )
{
if( stricmp( p, token ) == 0 )
{
strcpy( tmp, p_extentions[i+1] );
token = strtok( tmp, "," );
while( token )
{
if( token[0] == type )
{
return strdup( &token[2] );
}
token = strtok( NULL, "," );
}
return strdup( "" );
}
token = strtok( NULL, "," );
}
}
return strdup( "" );
}
/*!
与えられたファイル名と,そこに含まれるディレクトリの深さを設定する.
*/
void CDlgTagJumpList::SetFileName( const char *pszFileName )
{
if( NULL == pszFileName ) return;
if( m_pszFileName ) free( m_pszFileName );
m_pszFileName = strdup( pszFileName );
m_nLoop = CalcDirectoryDepth( m_pszFileName );
if( m_nLoop < 0 ) m_nLoop = 0;
if( m_nLoop > (_MAX_PATH/2) ) m_nLoop = (_MAX_PATH/2); //\A\B\C...のようなとき1フォルダで2文字消費するので...
return;
}
/*!
検索キーワードの設定
*/
void CDlgTagJumpList::SetKeyword( const char *pszKeyword )
{
if( NULL == pszKeyword ) return;
if( m_pszKeyword ) free( m_pszKeyword );
m_pszKeyword = strdup( pszKeyword );
return;
}
/*!
得られた候補から最も期待に近いと思われるものを
選び出す.(初期選択位置決定のため)
@return 選択されたアイテムのindex
*/
int CDlgTagJumpList::SearchBestTag( void )
{
if( m_cList.GetCount() <= 0 ) return -1; //選べません。
if( NULL == m_pszFileName ) return 0;
char szFileSrc[1024];
char szFileDst[1024];
char szExtSrc[1024];
char szExtDst[1024];
int nMatch = -1;
int i;
int count;
strcpy( szFileSrc, "" );
strcpy( szExtSrc, "" );
_splitpath( m_pszFileName, NULL, NULL, szFileSrc, szExtSrc );
count = m_cList.GetCount();
for( i = 0; i < count; i++ )
{
CSortedTagJumpList::TagJumpInfo* item;
item = m_cList.GetPtr( i );
strcpy( szFileDst, "" );
strcpy( szExtDst, "" );
_splitpath( item->filename, NULL, NULL, szFileDst, szExtDst );
if( stricmp( szFileSrc, szFileDst ) == 0 )
{
if( stricmp( szExtSrc, szExtDst ) == 0 ) return i;
if( nMatch == -1 ) nMatch = i;
}
}
if( nMatch != -1 ) return nMatch;
return 0;
}
/*!
タグファイルからキーワードにマッチするデータを抽出し,
m_cListに設定する
*/
void CDlgTagJumpList::find_key( const char* keyword )
{
char szCurrentPath[1024]; //カレントフォルダ
char szTagFile[1024]; //タグファイル
char szLineData[MAX_TAG_STRING_LENGTH*4]; //行バッファ
char s[5][MAX_TAG_STRING_LENGTH];
int n2;
int length = strlen( keyword );
int nMatch;
int i;
FILE* fp;
int nRet;
int cmp;
Empty();
if( length == 0 ) return;
strcpy( szCurrentPath, GetFilePath() );
szCurrentPath[ strlen( szCurrentPath ) - strlen( GetFileName() ) ] = '\0';
for( i = 0; i <= m_nLoop; i++ )
{
//タグファイル名を作成する。
wsprintf( szTagFile, "%s%s", szCurrentPath, TAG_FILENAME );
//タグファイルを開く。
fp = fopen( szTagFile, "r" );
if( fp )
{
nMatch = 0;
while( fgets( szLineData, sizeof( szLineData ), fp ) )
{
if( szLineData[0] <= '!' ) goto next_line; //コメントならスキップ
//chop( szLineData );
s[0][0] = s[1][0] = s[2][0] = s[3][0] = s[4][0] = '\0';
n2 = 0;
nRet = sscanf( szLineData,
TAG_FORMAT, //tagsフォーマット
s[0], s[1], &n2, s[3], s[4]
);
if( nRet < 4 ) goto next_line;
if( n2 <= 0 ) goto next_line; //行番号不正(-excmd=nが指定されてないかも)
if( m_bTagJumpAnyWhere ){
if( m_bTagJumpICase )
cmp = strstri( s[0], keyword ) != NULL ? 0 : -1;
else
cmp = strstr( s[0], keyword ) != NULL ? 0 : -1;
}else{
if( m_bTagJumpICase )
cmp = strnicmp( s[0], keyword, length );
else
cmp = strncmp( s[0], keyword, length );
}
if( 0 == cmp )
{
m_cList.AddParam( s[0], s[1], n2, s[3][0], s[4], i );
nMatch++;
}else if( 0 < cmp ){
// tagsはソートされているので,先頭からのcase sensitiveな
// 比較結果によって検索の時は処理の打ち切りが可能
// 2005.04.05 MIK バグ修正
if( (!m_bTagJumpICase) && (!m_bTagJumpAnyWhere) ) break;
}
next_line:
//if( nMatch >= 10 ) break;
;
}
//ファイルを閉じる。
fclose( fp );
}
strcat( szCurrentPath, "..\\" );
}
}
/*!
パスからファイル名部分のみを取り出す.(2バイト対応)
*/
const char * CDlgTagJumpList::GetFileName( void )
{
const char *p, *pszName;
pszName = p = GetFilePath();
while( *p != '\0' ){
if( _IS_SJIS_1( (unsigned char)*p ) && _IS_SJIS_2( (unsigned char)p[1] ) ){
p+=2;
}else if( *p == '\\' ){
pszName = p + 1;
p++;
}else{
p++;
}
}
return pszName;
}
/*[EOF]*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -