private void MakeReplyOrDirectStatus(bool isAuto = true, bool isReply = true, bool isAll = false)
{
//isAuto:true=先頭に挿入、false=カーソル位置に挿入
//isReply:true=@,false=DM
if (!StatusText.Enabled) return;
if (_curList == null) return;
if (_curTab == null) return;
if (!this.ExistCurrentPost) return;
// 複数あてリプライはReplyではなく通常ポスト
//↑仕様変更で全部リプライ扱いでOK(先頭ドット付加しない)
//090403暫定でドットを付加しないようにだけ修正。単独と複数の処理は統合できると思われる。
//090513 all @ replies 廃止の仕様変更によりドット付加に戻し(syo68k)
if (_curList.SelectedIndices.Count > 0)
{
// アイテムが1件以上選択されている
if (_curList.SelectedIndices.Count == 1 && !isAll && this.ExistCurrentPost)
{
// 単独ユーザー宛リプライまたはDM
if ((_statuses.Tabs[ListTab.SelectedTab.Text].TabType == MyCommon.TabUsageType.DirectMessage && isAuto) || (!isAuto && !isReply))
{
// ダイレクトメッセージ
StatusText.Text = "D " + _curPost.ScreenName + " " + StatusText.Text;
StatusText.SelectionStart = StatusText.Text.Length;
StatusText.Focus();
this.inReplyTo = null;
return;
}
if (string.IsNullOrEmpty(StatusText.Text))
{
//空の場合
// ステータステキストが入力されていない場合先頭に@ユーザー名を追加する
StatusText.Text = "@" + _curPost.ScreenName + " ";
var inReplyToStatusId = this._curPost.RetweetedId ?? this._curPost.StatusId;
var inReplyToScreenName = this._curPost.ScreenName;
this.inReplyTo = Tuple.Create(inReplyToStatusId, inReplyToScreenName);
}
else
{
//何か入力済の場合
if (isAuto)
{
//1件選んでEnter or DoubleClick
if (StatusText.Text.Contains("@" + _curPost.ScreenName + " "))
{
if (this.inReplyTo?.Item2 == _curPost.ScreenName)
{
//返信先書き換え
var inReplyToStatusId = this._curPost.RetweetedId ?? this._curPost.StatusId;
var inReplyToScreenName = this._curPost.ScreenName;
this.inReplyTo = Tuple.Create(inReplyToStatusId, inReplyToScreenName);
}
return;
}
if (!StatusText.Text.StartsWith("@", StringComparison.Ordinal))
{
//文頭@以外
if (StatusText.Text.StartsWith(". ", StringComparison.Ordinal))
{
// 複数リプライ
StatusText.Text = StatusText.Text.Insert(2, "@" + _curPost.ScreenName + " ");
this.inReplyTo = null;
}
else
{
// 単独リプライ
StatusText.Text = "@" + _curPost.ScreenName + " " + StatusText.Text;
var inReplyToStatusId = this._curPost.RetweetedId ?? this._curPost.StatusId;
var inReplyToScreenName = this._curPost.ScreenName;
this.inReplyTo = Tuple.Create(inReplyToStatusId, inReplyToScreenName);
}
}
else
{
//文頭@
// 複数リプライ
StatusText.Text = ". @" + _curPost.ScreenName + " " + StatusText.Text;
//StatusText.Text = "@" + _curPost.ScreenName + " " + StatusText.Text;
this.inReplyTo = null;
}
}
else
{
//1件選んでCtrl-Rの場合(返信先操作せず)
int sidx = StatusText.SelectionStart;
string id = "@" + _curPost.ScreenName + " ";
if (sidx > 0)
{
if (StatusText.Text.Substring(sidx - 1, 1) != " ")
{
id = " " + id;
}
}
StatusText.Text = StatusText.Text.Insert(sidx, id);
sidx += id.Length;
//if (StatusText.Text.StartsWith("@"))
//{
// //複数リプライ
// StatusText.Text = ". " + StatusText.Text.Insert(sidx, " @" + _curPost.ScreenName + " ");
// sidx += 5 + _curPost.ScreenName.Length;
//}
//else
//{
// // 複数リプライ
// StatusText.Text = StatusText.Text.Insert(sidx, " @" + _curPost.ScreenName + " ");
// sidx += 3 + _curPost.ScreenName.Length;
//}
StatusText.SelectionStart = sidx;
StatusText.Focus();
//_reply_to_id = 0;
//_reply_to_name = null;
return;
}
}
}
else
{
// 複数リプライ
if (!isAuto && !isReply) return;
//C-S-rか、複数の宛先を選択中にEnter/DoubleClick/C-r/C-S-r
if (isAuto)
{
//Enter or DoubleClick
string sTxt = StatusText.Text;
if (!sTxt.StartsWith(". ", StringComparison.Ordinal))
{
sTxt = ". " + sTxt;
this.inReplyTo = null;
}
for (int cnt = 0; cnt < _curList.SelectedIndices.Count; cnt++)
{
PostClass post = _statuses.Tabs[_curTab.Text][_curList.SelectedIndices[cnt]];
if (!sTxt.Contains("@" + post.ScreenName + " "))
{
sTxt = sTxt.Insert(2, "@" + post.ScreenName + " ");
//sTxt = "@" + post.ScreenName + " " + sTxt;
}
}
StatusText.Text = sTxt;
}
else
{
//C-S-r or C-r
if (_curList.SelectedIndices.Count > 1)
{
//複数ポスト選択
string ids = "";
int sidx = StatusText.SelectionStart;
for (int cnt = 0; cnt < _curList.SelectedIndices.Count; cnt++)
{
PostClass post = _statuses.Tabs[_curTab.Text][_curList.SelectedIndices[cnt]];
if (!ids.Contains("@" + post.ScreenName + " ") &&
!post.ScreenName.Equals(tw.Username, StringComparison.CurrentCultureIgnoreCase))
{
ids += "@" + post.ScreenName + " ";
}
if (isAll)
{
foreach (string nm in post.ReplyToList)
{
if (!ids.Contains("@" + nm + " ") &&
!nm.Equals(tw.Username, StringComparison.CurrentCultureIgnoreCase))
{
Match m = Regex.Match(post.TextFromApi, "[@@](?<id>" + nm + ")([^a-zA-Z0-9]|$)", RegexOptions.IgnoreCase);
if (m.Success)
ids += "@" + m.Result("${id}") + " ";
else
ids += "@" + nm + " ";
}
}
}
}
if (ids.Length == 0) return;
if (!StatusText.Text.StartsWith(". ", StringComparison.Ordinal))
{
StatusText.Text = ". " + StatusText.Text;
sidx += 2;
this.inReplyTo = null;
}
if (sidx > 0)
{
if (StatusText.Text.Substring(sidx - 1, 1) != " ")
{
ids = " " + ids;
}
}
StatusText.Text = StatusText.Text.Insert(sidx, ids);
sidx += ids.Length;
//if (StatusText.Text.StartsWith("@"))
//{
// StatusText.Text = ". " + StatusText.Text.Insert(sidx, ids);
// sidx += 2 + ids.Length;
//}
//else
//{
// StatusText.Text = StatusText.Text.Insert(sidx, ids);
// sidx += 1 + ids.Length;
//}
StatusText.SelectionStart = sidx;
StatusText.Focus();
return;
}
else
{
//1件のみ選択のC-S-r(返信元付加する可能性あり)
string ids = "";
int sidx = StatusText.SelectionStart;
PostClass post = _curPost;
if (!ids.Contains("@" + post.ScreenName + " ") &&
!post.ScreenName.Equals(tw.Username, StringComparison.CurrentCultureIgnoreCase))
{
ids += "@" + post.ScreenName + " ";
}
foreach (string nm in post.ReplyToList)
{
if (!ids.Contains("@" + nm + " ") &&
!nm.Equals(tw.Username, StringComparison.CurrentCultureIgnoreCase))
{
Match m = Regex.Match(post.TextFromApi, "[@@](?<id>" + nm + ")([^a-zA-Z0-9]|$)", RegexOptions.IgnoreCase);
if (m.Success)
ids += "@" + m.Result("${id}") + " ";
else
ids += "@" + nm + " ";
}
}
if (!string.IsNullOrEmpty(post.RetweetedBy))
{
if (!ids.Contains("@" + post.RetweetedBy + " ") &&
!post.RetweetedBy.Equals(tw.Username, StringComparison.CurrentCultureIgnoreCase))
{
ids += "@" + post.RetweetedBy + " ";
}
}
if (ids.Length == 0) return;
if (string.IsNullOrEmpty(StatusText.Text))
{
//未入力の場合のみ返信先付加
StatusText.Text = ids;
StatusText.SelectionStart = ids.Length;
StatusText.Focus();
var inReplyToStatusId = this._curPost.RetweetedId ?? this._curPost.StatusId;
var inReplyToScreenName = this._curPost.ScreenName;
this.inReplyTo = Tuple.Create(inReplyToStatusId, inReplyToScreenName);
return;
}
if (sidx > 0)
{
if (StatusText.Text.Substring(sidx - 1, 1) != " ")
{
ids = " " + ids;
}
}
StatusText.Text = StatusText.Text.Insert(sidx, ids);
sidx += ids.Length;
StatusText.SelectionStart = sidx;
StatusText.Focus();
return;
}
}
}
StatusText.SelectionStart = StatusText.Text.Length;
StatusText.Focus();
}
}