Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GREPの「カレントフォルダーが初期値」に対応 #1852

Merged
merged 4 commits into from Jun 12, 2022

Conversation

dep5
Copy link
Contributor

@dep5 dep5 commented Jun 9, 2022

PR の目的

#1851 で報告された問題に対応します

カテゴリ

  • 不具合修正

PR の背景

#1696 により動かなくなっています。

PR のメリット

PR のデメリット (トレードオフとかあれば)

仕様・動作説明

CDlgGrep::SetData()
の中で"カレントフォルダーを初期値"がONの場合

		SetGrepFolder( GetItemHwnd(IDC_COMBO_FOLDER), szWorkFolder );

が動きますが、#1696 での追加で

		::DlgItem_SetText(GetHwnd(), IDC_COMBO_FOLDER, m_szFolder);

別の変数で上書きしています。

https://github.com/sakura-editor/sakura/releases/tag/v2.4.1
で動きを確認してみると、
チェックボックスをONOFFするたびに反映されるタイプのものではなく、
ダイアログ表示時に一度動けばよいようです。

CDlgGrep::SetData() からCDlgGrep::DoModal() へ移動して対応してみました。

PR の影響範囲

テスト内容

テスト1

#1851
「カレントフォルダーを初期値」にチェックを入れた状態で「検索」を押した後
ファイルを開いてからGREPダイアログを表示します。

手順

関連 issue, PR

#1851
#1696

参考資料

@AppVeyorBot
Copy link

Build sakura 1.0.4144 completed (commit 41710c4828 by @dep5)

@dep5
Copy link
Contributor Author

dep5 commented Jun 10, 2022

m_szFolder[0] == L'\0'

を消しましたが、心配になったので元に戻しました。
CDlgGrep::DoModal()に移動する際必要のない

SetGrepFolder( GetItemHwnd(IDC_COMBO_FOLDER), m_szFolder );

まで移動してしまったので削除しました。

@dep5
Copy link
Contributor Author

dep5 commented Jun 10, 2022

1 Security Hotspot
はなぜ出ているのでしょう?/* 除外ファイル */と同じ書き方のつもりなのですが…
どなたか修正方法を教えてください。

@AppVeyorBot
Copy link

Build sakura 1.0.4147 completed (commit 5e2c6f85bd by @dep5)

@dep5 dep5 changed the title 'GREPの「カレントフォルダーを初期値」に対応' GREPの「カレントフォルダーを初期値」に対応 Jun 10, 2022
@dep5 dep5 changed the title GREPの「カレントフォルダーを初期値」に対応 GREPの「カレントフォルダーが初期値」に対応 Jun 10, 2022
@dep5
Copy link
Contributor Author

dep5 commented Jun 10, 2022

元からあるコードの条件を変更しないように書き直しました。

@AppVeyorBot
Copy link

Build sakura 1.0.4148 completed (commit 2aa1cee79d by @dep5)

m_szCurrentFilePath[0] != L'\0' ){
WCHAR szWorkFile[MAX_PATH];
SplitPath_FolderAndFile( m_szCurrentFilePath, m_szFolder, szWorkFile );
}else
if( m_szFolder[0] == L'\0' && m_pShareData->m_sSearchKeywords.m_aGrepFolders.size() ){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else と if の行は分けずに else if と書いた方がコードが読み易いと思います。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

force-pushしたのですが、wcscpyの部分でSecurity Hotspotsがでてしまいました。
以前、修正で苦労したのでそれよりはもとのコードを変更しないように書き換えたら
Security Hotspotsが消えるかも、と変な改行が入っています。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Security HotspotsってSonarCloudのでしたっけ?

静的解析のfalse positiveな警告を潰す為にコードを読みにくくするのは、本来はコード品質を良くするためにツールを使っているのに、そのツールの都合に合わせる為にコードの可読性を悪くしている事になります。それだと人間がツールに振り回されてしまっているようで、トータルとしてツールを使う事でプラスになったんだろうか?と疑問を感じてしまいます。。

@@ -250,11 +250,20 @@ int CDlgGrep::DoModal( HINSTANCE hInstance, HWND hwndParent, const WCHAR* pszCur
m_bGrepOutputBaseFolder = m_pShareData->m_Common.m_sSearch.m_bGrepOutputBaseFolder;
m_bGrepSeparateFolder = m_pShareData->m_Common.m_sSearch.m_bGrepSeparateFolder;

if( pszCurrentFilePath ){ // 2010.01.10 ryoji
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ryojiさんは今のプロジェクトに参加してないので解放してあげたい気がします。
ソースコードに名前が入っていると、なんか問題あったら「そいつのせい」に見えます。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m_szCurrentFilePathを使いたかったので移動しましたが、必要なくなりました。

if( m_szFolder[0] == L'\0' && m_pShareData->m_Common.m_sSearch.m_bGrepDefaultFolder &&
m_szCurrentFilePath[0] != L'\0' ){
WCHAR szWorkFile[MAX_PATH];
SplitPath_FolderAndFile( m_szCurrentFilePath, m_szFolder, szWorkFile );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

「カレントフォルダを初期値」は
Grepダイアログの次回表示時のフォルダの初期値をカレントフォルダにするだと思うので、
「初期化専用プロパティ」と考えてよいと思います。

チェックOFF/ONで制御するのは、あくまで「初期表示」の挙動なので、
Grepダイアログ表示後のチェックOFF/ONで反応しなくても問題はないです。

挿入位置はOnInitDialogにしたほうが良いと思います。

関数名 タイミング
CDlgGrep::DoModal Grepダイアログ「表示前」
CDlgGrep::OnInitDialog Grepダイアログの「初期表示時」

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DoModalの時は移動のほかに少し変更がいりましたが、
OnInitDialogにすると、移動するだけで済んで、すっきりしたコードになりました。

sakura_core/dlg/CDlgGrep.cpp Show resolved Hide resolved
Copy link
Contributor

@berryzplus berryzplus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

指摘の意味が通じるか微妙なんですけど、
コードの移動先をOnInitDialogにしたほうがよいと思う
の件で request change にしておきます。

@dep5
Copy link
Contributor Author

dep5 commented Jun 11, 2022

#1852 (comment)
berryzplusさんのアドバイスに従ってCDlgGrep::DoModalからCDlgGrep::OnInitDialogに再移動しました。

@AppVeyorBot
Copy link

Build sakura 1.0.4150 completed (commit d634590c7e by @dep5)

@dep5 dep5 marked this pull request as ready for review June 11, 2022 13:13
berryzplus
berryzplus previously approved these changes Jun 11, 2022
m_szCurrentFilePath[0] != L'\0'
){
WCHAR szWorkFile[MAX_PATH];
SplitPath_FolderAndFile( m_szCurrentFilePath, m_szFolder, szWorkFile );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SonarCloudはCスタイル配列を使っても警告出さなくなったんですね。

SplitPath_FolderAndFileの第3引数は nullptr を受け入れるので szWorkFile のメモリ確保は無駄です。
500バイトくらい許容だと思いますが、文句言う人がいそうです。(既知のGuys...)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

別観点ですが、
OnBnClicked(IDC_BUTTON_CURRENTFOLDER);
とかにしなくて良いのかな?(無題の場合どうなる?)ということを思いました。
これ、指摘じゃないです。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

削除部分のコメントしてるのは間違いだと思いましたが、意味があったんですね。
よく読めばよかったです。

@sonarcloud
Copy link

sonarcloud bot commented Jun 11, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@AppVeyorBot
Copy link

Build sakura 1.0.4152 completed (commit 0a8716dfd9 by @dep5)

@sanomari sanomari merged commit c71e76f into sakura-editor:master Jun 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants