// for more details.
//
// You should have received a copy of the GNU General public License along
-// with this program. if (not, see <http://www.gnu.org/licenses/>, or write to
+// with this program. If not, see <http://www.gnu.org/licenses/>, or write to
// the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
// Boston, MA 02110-1301, USA.
using System.ComponentModel;
using System.Data;
using System.Drawing;
+using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows.Forms;
{
public partial class HashtagManage : OTBaseForm
{
+ /// <summary>
+ /// エラー時にダイアログを表示させない (ユニットテストなどで使用)
+ /// </summary>
+ public bool RunSilent { get; set; }
+
//入力補助画面
private AtIdSupplement _hashSupl;
//I/F用
private void DeleteButton_Click(object sender, EventArgs e)
{
if (this.HistoryHashList.SelectedIndices.Count == 0) return;
- if (MessageBox.Show(Properties.Resources.DeleteHashtagsMessage1,
+ if (!this.RunSilent &&
+ MessageBox.Show(Properties.Resources.DeleteHashtagsMessage1,
"Delete Hashtags",
MessageBoxButtons.OKCancel,
MessageBoxIcon.Question) == DialogResult.Cancel)
{
return;
}
- for (int i = 0; i < HistoryHashList.SelectedIndices.Count; i++)
+
+ // 削除によってインデックス番号が変わらないように逆順に処理する
+ var selectedIndices = this.HistoryHashList.SelectedIndices.Cast<int>()
+ .OrderByDescending(x => x).ToArray();
+
+ foreach (var idx in selectedIndices)
{
- if (UseHashText.Text == HistoryHashList.SelectedItems[0].ToString()) UseHashText.Text = "";
- HistoryHashList.Items.RemoveAt(HistoryHashList.SelectedIndices[0]);
+ if (UseHashText.Text == HistoryHashList.Items[idx].ToString()) UseHashText.Text = "";
+ HistoryHashList.Items.RemoveAt(idx);
}
if (HistoryHashList.Items.Count > 0)
{
idx += 1;
continue;
}
- if (string.Compare(src, value, true) == 0)
+ if (string.Compare(src, value, StringComparison.OrdinalIgnoreCase) == 0)
{
return idx;
}
{
//ハッシュタグの整形
string hashStr = UseHashText.Text;
- if (!this.AdjustHashtags(ref hashStr, true)) return;
+ if (!this.AdjustHashtags(ref hashStr, !this.RunSilent)) return;
UseHashText.Text = hashStr;
int idx = 0;
{
if (hash.Length > 0)
{
- if (!hash.StartsWith("#"))
+ if (!hash.StartsWith("#", StringComparison.Ordinal))
{
if (isShowWarn) MessageBox.Show("Invalid hashtag. -> " + hash, "Hashtag warning", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
return false;