// the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
// Boston, MA 02110-1301, USA.
+#nullable enable
+
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text.RegularExpressions;
using System.IO;
using System.Globalization;
+using OpenTween.Setting;
+using System.Threading.Tasks;
namespace OpenTween
{
public partial class EventViewerDialog : OTBaseForm
{
- public List<Twitter.FormattedEvent> EventSource { get; set; }
+ public List<Twitter.FormattedEvent> EventSource { get; set; } = new List<Twitter.FormattedEvent>();
- private Twitter.FormattedEvent[] _filterdEventSource;
+ private Twitter.FormattedEvent[] _filterdEventSource = Array.Empty<Twitter.FormattedEvent>();
- private ListViewItem[] _ItemCache = null;
+ private ListViewItem[]? _ItemCache = null;
private int _itemCacheIndex;
- private TabPage _curTab = null;
+ private TabPage _curTab = null!;
public EventViewerDialog()
{
private ListViewItem CreateListViewItem(Twitter.FormattedEvent source)
{
- string[] s = { source.CreatedAt.ToString(), source.Event.ToUpper(CultureInfo.CurrentCulture), source.Username, source.Target };
+ string[] s = { source.CreatedAt.ToLocalTimeString(), source.Event.ToUpper(CultureInfo.CurrentCulture), source.Username, source.Target };
return new ListViewItem(s);
}
_curTab = TabEventType.SelectedTab;
CreateFilterdEventSource();
EventList.EndUpdate();
- this.TopMost = SettingCommon.Instance.AlwaysTop;
+ this.TopMost = SettingManager.Common.AlwaysTop;
}
private async void EventList_DoubleClick(object sender, EventArgs e)
+ => await this.OpenEventStatusOrUser();
+
+ private async void EventList_KeyDown(object sender, KeyEventArgs e)
+ {
+ if (e.KeyData == Keys.Enter)
+ await this.OpenEventStatusOrUser();
+ }
+
+ private async Task OpenEventStatusOrUser()
{
- if (EventList.SelectedIndices.Count != 0 && _filterdEventSource[EventList.SelectedIndices[0]] != null)
+ if (this.EventList.SelectedIndices.Count == 0)
+ return;
+
+ var tweenMain = (TweenMain)this.Owner;
+ var selectedEvent = this._filterdEventSource[this.EventList.SelectedIndices[0]];
+ if (selectedEvent != null)
{
- await ((TweenMain)this.Owner).OpenUriInBrowserAsync("https://twitter.com/" + _filterdEventSource[EventList.SelectedIndices[0]].Username);
+ if (selectedEvent.Id != 0)
+ await tweenMain.OpenRelatedTab(selectedEvent.Id);
+ else
+ await tweenMain.OpenUriAsync(new Uri("https://twitter.com/" + selectedEvent.Username));
}
}
private MyCommon.EVENTTYPE ParseEventTypeFromTag()
- {
- return (MyCommon.EVENTTYPE)Enum.Parse(typeof(MyCommon.EVENTTYPE), _curTab.Tag.ToString());
- }
+ => (MyCommon.EVENTTYPE)Enum.Parse(typeof(MyCommon.EVENTTYPE), _curTab.Tag.ToString());
private bool IsFilterMatch(Twitter.FormattedEvent x)
{
{
try
{
- Regex rx = new Regex(TextBoxKeyword.Text);
+ var rx = new Regex(TextBoxKeyword.Text);
return rx.Match(x.Username).Success || rx.Match(x.Target).Success;
}
catch (Exception ex)
{
if (EventSource != null && EventSource.Count > 0)
{
- _filterdEventSource = EventSource.FindAll((x) => (CheckExcludeMyEvent.Checked ? !x.IsMe : true) &&
+ _filterdEventSource = EventSource.FindAll((x) => !(CheckExcludeMyEvent.Checked && x.IsMe) &&
(x.Eventtype & ParseEventTypeFromTag()) != 0 &&
IsFilterMatch(x)).ToArray();
_ItemCache = null;
}
private void CheckExcludeMyEvent_CheckedChanged(object sender, EventArgs e)
- {
- CreateFilterdEventSource();
- }
+ => this.CreateFilterdEventSource();
private void ButtonRefresh_Click(object sender, EventArgs e)
- {
- CreateFilterdEventSource();
- }
+ => this.CreateFilterdEventSource();
private void TabEventType_SelectedIndexChanged(object sender, EventArgs e)
- {
- CreateFilterdEventSource();
- }
+ => this.CreateFilterdEventSource();
private void TabEventType_Selecting(object sender, TabControlCancelEventArgs e)
{
}
private void EventList_CacheVirtualItems(object sender, CacheVirtualItemsEventArgs e)
- {
- CreateCache(e.StartIndex, e.EndIndex);
- }
+ => this.CreateCache(e.StartIndex, e.EndIndex);
private void CreateCache(int StartIndex, int EndIndex)
{
_ItemCache = new ListViewItem[] { };
Array.Resize(ref _ItemCache, EndIndex - StartIndex + 1);
_itemCacheIndex = StartIndex;
- for (int i = 0; i < _ItemCache.Length; i++)
+ for (var i = 0; i < _ItemCache.Length; i++)
{
_ItemCache[i] = CreateListViewItem(_filterdEventSource[StartIndex + i]);
}
private void SaveLogButton_Click(object sender, EventArgs e)
{
- DialogResult rslt = MessageBox.Show(string.Format(Properties.Resources.SaveLogMenuItem_ClickText5, Environment.NewLine),
+ var rslt = MessageBox.Show(string.Format(Properties.Resources.SaveLogMenuItem_ClickText5, Environment.NewLine),
Properties.Resources.SaveLogMenuItem_ClickText2,
MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
switch (rslt)
{
case DialogResult.Yes:
- SaveFileDialog1.FileName = MyCommon.GetAssemblyName() + "Events" + _curTab.Tag.ToString() + DateTime.Now.ToString("yyMMdd-HHmmss") + ".tsv";
+ SaveFileDialog1.FileName = $"{ApplicationSettings.AssemblyName}Events{_curTab.Tag}{DateTimeUtc.Now.ToLocalTime():yyMMdd-HHmmss}.tsv";
break;
case DialogResult.No:
- SaveFileDialog1.FileName = MyCommon.GetAssemblyName() + "Events" + DateTime.Now.ToString("yyMMdd-HHmmss") + ".tsv";
+ SaveFileDialog1.FileName = $"{ApplicationSettings.AssemblyName}Events{DateTimeUtc.Now.ToLocalTime():yyMMdd-HHmmss}.tsv";
break;
default:
return;
if (SaveFileDialog1.ShowDialog() == DialogResult.OK)
{
if (!SaveFileDialog1.ValidateNames) return;
- using (StreamWriter sw = new StreamWriter(SaveFileDialog1.FileName, false, Encoding.UTF8))
+ using var sw = new StreamWriter(SaveFileDialog1.FileName, false, Encoding.UTF8);
+
+ switch (rslt)
{
- switch (rslt)
- {
- case DialogResult.Yes:
- SaveEventLog(_filterdEventSource.ToList(), sw);
- break;
- case DialogResult.No:
- SaveEventLog(EventSource, sw);
- break;
- default:
- //
- break;
- }
+ case DialogResult.Yes:
+ SaveEventLog(_filterdEventSource.ToList(), sw);
+ break;
+ case DialogResult.No:
+ SaveEventLog(EventSource, sw);
+ break;
+ default:
+ break;
}
}
- this.TopMost = SettingCommon.Instance.AlwaysTop;
+ this.TopMost = SettingManager.Common.AlwaysTop;
}
private void SaveEventLog(List<Twitter.FormattedEvent> source, StreamWriter sw)
{
- foreach (Twitter.FormattedEvent _event in source)
+ foreach (var _event in source)
{
- sw.WriteLine(_event.Eventtype.ToString() + "\t" +
- "\"" + _event.CreatedAt.ToString() + "\"\t" +
+ sw.WriteLine(_event.Eventtype + "\t" +
+ "\"" + _event.CreatedAt.ToLocalTimeString() + "\"\t" +
_event.Event + "\t" +
_event.Username + "\t" +
_event.Target + "\t" +
- _event.Id.ToString());
+ _event.Id);
}
}
.Where(e => e != "None" && e != "All")
.Select(e => new TabPage(e)
{
- // Name = "TabPage" + e,
Tag = e,
UseVisualStyleBackColor = true,
AccessibleRole = AccessibleRole.PageTab,