From bea9062a6c280a7b9deb7273a1d720af6e54fd88 Mon Sep 17 00:00:00 2001 From: Kimura Youichi Date: Sun, 1 Jan 2012 01:58:11 +0900 Subject: [PATCH] Port MyLists.vb to C# --- Tween/MyLists.Designer.vb | 112 -------------- Tween/MyLists.vb | 206 -------------------------- Tween/Tween.vbproj | 15 -- TweenCS/MyLists.Designer.cs | 135 +++++++++++++++++ TweenCS/MyLists.cs | 261 +++++++++++++++++++++++++++++++++ {Tween => TweenCS}/MyLists.en.resx | 0 {Tween => TweenCS}/MyLists.resx | 0 {Tween => TweenCS}/MyLists.zh-CHS.resx | 0 TweenCS/TweenCS.csproj | 15 ++ 9 files changed, 411 insertions(+), 333 deletions(-) delete mode 100644 Tween/MyLists.Designer.vb delete mode 100644 Tween/MyLists.vb create mode 100644 TweenCS/MyLists.Designer.cs create mode 100644 TweenCS/MyLists.cs rename {Tween => TweenCS}/MyLists.en.resx (100%) rename {Tween => TweenCS}/MyLists.resx (100%) rename {Tween => TweenCS}/MyLists.zh-CHS.resx (100%) diff --git a/Tween/MyLists.Designer.vb b/Tween/MyLists.Designer.vb deleted file mode 100644 index 44a4818d..00000000 --- a/Tween/MyLists.Designer.vb +++ /dev/null @@ -1,112 +0,0 @@ - _ -Partial Class MyLists - Inherits System.Windows.Forms.Form - - 'フォームがコンポーネントの一覧をクリーンアップするために dispose をオーバーライドします。 - _ - Protected Overrides Sub Dispose(ByVal disposing As Boolean) - Try - If disposing AndAlso components IsNot Nothing Then - components.Dispose() - End If - Finally - MyBase.Dispose(disposing) - End Try - End Sub - - 'Windows フォーム デザイナーで必要です。 - Private components As System.ComponentModel.IContainer - - 'メモ: 以下のプロシージャは Windows フォーム デザイナーで必要です。 - 'Windows フォーム デザイナーを使用して変更できます。 - 'コード エディターを使って変更しないでください。 - _ - Private Sub InitializeComponent() - Me.components = New System.ComponentModel.Container() - Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(MyLists)) - Me.ListsCheckedListBox = New System.Windows.Forms.CheckedListBox() - Me.ContextMenuStrip1 = New System.Windows.Forms.ContextMenuStrip(Me.components) - Me.追加AToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem() - Me.削除DToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem() - Me.ToolStripMenuItem1 = New System.Windows.Forms.ToolStripSeparator() - Me.更新RToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem() - Me.ListRefreshButton = New System.Windows.Forms.Button() - Me.CloseButton = New System.Windows.Forms.Button() - Me.ContextMenuStrip1.SuspendLayout() - Me.SuspendLayout() - ' - 'ListsCheckedListBox - ' - resources.ApplyResources(Me.ListsCheckedListBox, "ListsCheckedListBox") - Me.ListsCheckedListBox.CheckOnClick = True - Me.ListsCheckedListBox.ContextMenuStrip = Me.ContextMenuStrip1 - Me.ListsCheckedListBox.FormattingEnabled = True - Me.ListsCheckedListBox.Name = "ListsCheckedListBox" - ' - 'ContextMenuStrip1 - ' - Me.ContextMenuStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.追加AToolStripMenuItem, Me.削除DToolStripMenuItem, Me.ToolStripMenuItem1, Me.更新RToolStripMenuItem}) - Me.ContextMenuStrip1.Name = "ContextMenuStrip1" - resources.ApplyResources(Me.ContextMenuStrip1, "ContextMenuStrip1") - ' - '追加AToolStripMenuItem - ' - Me.追加AToolStripMenuItem.Name = "追加AToolStripMenuItem" - resources.ApplyResources(Me.追加AToolStripMenuItem, "追加AToolStripMenuItem") - ' - '削除DToolStripMenuItem - ' - Me.削除DToolStripMenuItem.Name = "削除DToolStripMenuItem" - resources.ApplyResources(Me.削除DToolStripMenuItem, "削除DToolStripMenuItem") - ' - 'ToolStripMenuItem1 - ' - Me.ToolStripMenuItem1.Name = "ToolStripMenuItem1" - resources.ApplyResources(Me.ToolStripMenuItem1, "ToolStripMenuItem1") - ' - '更新RToolStripMenuItem - ' - Me.更新RToolStripMenuItem.Name = "更新RToolStripMenuItem" - resources.ApplyResources(Me.更新RToolStripMenuItem, "更新RToolStripMenuItem") - ' - 'ListRefreshButton - ' - resources.ApplyResources(Me.ListRefreshButton, "ListRefreshButton") - Me.ListRefreshButton.Name = "ListRefreshButton" - Me.ListRefreshButton.UseVisualStyleBackColor = True - ' - 'CloseButton - ' - resources.ApplyResources(Me.CloseButton, "CloseButton") - Me.CloseButton.DialogResult = System.Windows.Forms.DialogResult.Cancel - Me.CloseButton.Name = "CloseButton" - Me.CloseButton.UseVisualStyleBackColor = True - ' - 'MyLists - ' - Me.AcceptButton = Me.CloseButton - resources.ApplyResources(Me, "$this") - Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font - Me.CancelButton = Me.CloseButton - Me.Controls.Add(Me.CloseButton) - Me.Controls.Add(Me.ListRefreshButton) - Me.Controls.Add(Me.ListsCheckedListBox) - Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow - Me.MaximizeBox = False - Me.MinimizeBox = False - Me.Name = "MyLists" - Me.ShowInTaskbar = False - Me.ContextMenuStrip1.ResumeLayout(False) - Me.ResumeLayout(False) - Me.PerformLayout() - - End Sub - Friend WithEvents ListsCheckedListBox As System.Windows.Forms.CheckedListBox - Friend WithEvents ListRefreshButton As System.Windows.Forms.Button - Friend WithEvents ContextMenuStrip1 As System.Windows.Forms.ContextMenuStrip - Friend WithEvents 追加AToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem - Friend WithEvents 削除DToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem - Friend WithEvents ToolStripMenuItem1 As System.Windows.Forms.ToolStripSeparator - Friend WithEvents 更新RToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem - Friend WithEvents CloseButton As System.Windows.Forms.Button -End Class diff --git a/Tween/MyLists.vb b/Tween/MyLists.vb deleted file mode 100644 index 2dff03c6..00000000 --- a/Tween/MyLists.vb +++ /dev/null @@ -1,206 +0,0 @@ -' Tween - Client of Twitter -' Copyright (c) 2007-2011 kiri_feather (@kiri_feather) -' (c) 2008-2011 Moz (@syo68k) -' (c) 2008-2011 takeshik (@takeshik) -' (c) 2010-2011 anis774 (@anis774) -' (c) 2010-2011 fantasticswallow (@f_swallow) -' All rights reserved. -' -' This file is part of Tween. -' -' This program is free software; you can redistribute it and/or modify it -' under the terms of the GNU General Public License as published by the Free -' Software Foundation; either version 3 of the License, or (at your option) -' any later version. -' -' This program is distributed in the hope that it will be useful, but -' WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -' or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -' for more details. -' -' You should have received a copy of the GNU General Public License along -' with this program. If not, see , or write to -' the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, -' Boston, MA 02110-1301, USA. - -Public Class MyLists - Private contextUserName As String - Private _tw As Twitter - - Public Sub New(ByVal userName As String, ByVal tw As Twitter) - Me.InitializeComponent() - - Me.contextUserName = userName - Me._tw = tw - - Me.Text = Me.contextUserName + My.Resources.MyLists1 - End Sub - - Private Sub MyLists_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load - RemoveHandler Me.ListsCheckedListBox.ItemCheck, AddressOf Me.ListsCheckedListBox_ItemCheck - - Me.ListsCheckedListBox.Items.AddRange(TabInformations.GetInstance.SubscribableLists.FindAll(Function(item) item.Username = Me._tw.Username).ToArray()) - - For i As Integer = 0 To Me.ListsCheckedListBox.Items.Count - 1 - Dim listItem As ListElement = CType(Me.ListsCheckedListBox.Items(i), ListElement) - - Dim listPost As New List(Of PostClass)() - Dim otherPost As New List(Of PostClass)() - - For Each tab As TabClass In TabInformations.GetInstance().Tabs.Values - If tab.TabType = TabUsageType.Lists Then - If listItem.Id = tab.ListInfo.Id Then - listPost.AddRange(tab.Posts.Values) - Else - otherPost.AddRange(tab.Posts.Values) - End If - End If - Next - - 'リストが空の場合は推定不能 - If listPost.Count = 0 Then - Me.ListsCheckedListBox.SetItemCheckState(i, CheckState.Indeterminate) - Continue For - End If - - 'リストに該当ユーザーのポストが含まれていれば、リストにユーザーが含まれているとする。 - If listPost.Exists(Function(item) item.ScreenName = contextUserName) Then - Me.ListsCheckedListBox.SetItemChecked(i, True) - Continue For - End If - - Dim listPostUserIDs As New List(Of Long)() - Dim listPostUserNames As New List(Of String)() - Dim listOlderPostCreatedAt As DateTime = DateTime.MaxValue - Dim listNewistPostCreatedAt As DateTime = DateTime.MinValue - - For Each post As PostClass In listPost - If post.UserId > 0 AndAlso Not listPostUserIDs.Contains(post.UserId) Then - listPostUserIDs.Add(post.UserId) - End If - If post.ScreenName IsNot Nothing AndAlso Not listPostUserNames.Contains(post.ScreenName) Then - listPostUserNames.Add(post.ScreenName) - End If - If post.CreatedAt < listOlderPostCreatedAt Then - listOlderPostCreatedAt = post.CreatedAt - End If - If post.CreatedAt > listNewistPostCreatedAt Then - listNewistPostCreatedAt = post.CreatedAt - End If - Next - - 'リスト中のユーザーの人数がlistItem.MemberCount以上で、かつ該当のユーザーが含まれていなければ、リストにユーザーは含まれていないとする。 - If listItem.MemberCount > 0 AndAlso listItem.MemberCount <= listPostUserIDs.Count AndAlso (Not listPostUserNames.Contains(contextUserName)) Then - Me.ListsCheckedListBox.SetItemChecked(i, False) - Continue For - End If - - otherPost.AddRange(TabInformations.GetInstance().Posts().Values) - - 'リストに該当ユーザーのポストが含まれていないのにリスト以外で取得したポストの中にリストに含まれるべきポストがある場合は、リストにユーザーは含まれていないとする。 - If otherPost.Exists(Function(item) (item.ScreenName = Me.contextUserName) AndAlso (item.CreatedAt > listOlderPostCreatedAt) AndAlso (item.CreatedAt < listNewistPostCreatedAt) AndAlso ((Not item.IsReply) OrElse listPostUserNames.Contains(item.InReplyToUser))) Then - Me.ListsCheckedListBox.SetItemChecked(i, False) - Continue For - End If - - Me.ListsCheckedListBox.SetItemCheckState(i, CheckState.Indeterminate) - Next - - AddHandler Me.ListsCheckedListBox.ItemCheck, AddressOf Me.ListsCheckedListBox_ItemCheck - End Sub - - Private Sub ListRefreshButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListRefreshButton.Click - Dim rslt As String = Me._tw.GetListsApi() - If rslt <> "" Then - MessageBox.Show(String.Format(My.Resources.ListsDeleteFailed, rslt)) - Else - Me.ListsCheckedListBox.Items.Clear() - Me.MyLists_Load(Me, EventArgs.Empty) - End If - End Sub - - Private Sub ListsCheckedListBox_ItemCheck(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles ListsCheckedListBox.ItemCheck - Select Case e.CurrentValue - Case CheckState.Indeterminate - Dim listItem As ListElement = CType(Me.ListsCheckedListBox.Items(e.Index), ListElement) - - Dim ret As Boolean - Dim rslt As String = Me._tw.ContainsUserAtList(listItem.Id.ToString(), contextUserName, ret) - If rslt <> "" Then - MessageBox.Show(String.Format(My.Resources.ListManageOKButton2, rslt)) - e.NewValue = CheckState.Indeterminate - Else - If ret Then - e.NewValue = CheckState.Checked - Else - e.NewValue = CheckState.Unchecked - End If - End If - Case CheckState.Unchecked - Dim list As ListElement = CType(Me.ListsCheckedListBox.Items(e.Index), ListElement) - Dim rslt As String = Me._tw.AddUserToList(list.Id.ToString(), Me.contextUserName.ToString()) - If rslt <> "" Then - MessageBox.Show(String.Format(My.Resources.ListManageOKButton2, rslt)) - e.NewValue = CheckState.Indeterminate - End If - Case CheckState.Checked - Dim list As ListElement = CType(Me.ListsCheckedListBox.Items(e.Index), ListElement) - Dim rslt As String = Me._tw.RemoveUserToList(list.Id.ToString(), Me.contextUserName.ToString()) - If rslt <> "" Then - MessageBox.Show(String.Format(My.Resources.ListManageOKButton2, rslt)) - e.NewValue = CheckState.Indeterminate - End If - End Select - End Sub - - Private Sub ContextMenuStrip1_Opening(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles ContextMenuStrip1.Opening - e.Cancel = Me.ListsCheckedListBox.SelectedItem Is Nothing - End Sub - - Private Sub 追加AToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 追加AToolStripMenuItem.Click - RemoveHandler Me.ListsCheckedListBox.ItemCheck, AddressOf Me.ListsCheckedListBox_ItemCheck - Me.ListsCheckedListBox.SetItemCheckState(Me.ListsCheckedListBox.SelectedIndex, CheckState.Unchecked) - AddHandler Me.ListsCheckedListBox.ItemCheck, AddressOf Me.ListsCheckedListBox_ItemCheck - Me.ListsCheckedListBox.SetItemCheckState(Me.ListsCheckedListBox.SelectedIndex, CheckState.Checked) - End Sub - - Private Sub 削除DToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 削除DToolStripMenuItem.Click - RemoveHandler Me.ListsCheckedListBox.ItemCheck, AddressOf Me.ListsCheckedListBox_ItemCheck - Me.ListsCheckedListBox.SetItemCheckState(Me.ListsCheckedListBox.SelectedIndex, CheckState.Checked) - AddHandler Me.ListsCheckedListBox.ItemCheck, AddressOf Me.ListsCheckedListBox_ItemCheck - Me.ListsCheckedListBox.SetItemCheckState(Me.ListsCheckedListBox.SelectedIndex, CheckState.Unchecked) - End Sub - - Private Sub 更新RToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 更新RToolStripMenuItem.Click - RemoveHandler Me.ListsCheckedListBox.ItemCheck, AddressOf Me.ListsCheckedListBox_ItemCheck - Me.ListsCheckedListBox.SetItemCheckState(Me.ListsCheckedListBox.SelectedIndex, CheckState.Indeterminate) - AddHandler Me.ListsCheckedListBox.ItemCheck, AddressOf Me.ListsCheckedListBox_ItemCheck - Me.ListsCheckedListBox.SetItemCheckState(Me.ListsCheckedListBox.SelectedIndex, CheckState.Checked) - End Sub - - Private Sub ListsCheckedListBox_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListsCheckedListBox.MouseDown - Select Case e.Button - Case MouseButtons.Left - '項目が無い部分をクリックしても、選択されている項目のチェック状態が変更されてしまうので、その対策 - For index As Integer = 0 To Me.ListsCheckedListBox.Items.Count - 1 - If Me.ListsCheckedListBox.GetItemRectangle(index).Contains(e.Location) Then - Return - End If - Next - Me.ListsCheckedListBox.SelectedItem = Nothing - Case MouseButtons.Right - 'コンテキストメニューの項目実行時にSelectedItemプロパティを利用出来るように - For index As Integer = 0 To Me.ListsCheckedListBox.Items.Count - 1 - If Me.ListsCheckedListBox.GetItemRectangle(index).Contains(e.Location) Then - Me.ListsCheckedListBox.SetSelected(index, True) - Return - End If - Next - Me.ListsCheckedListBox.SelectedItem = Nothing - End Select - End Sub - - Private Sub CloseButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseButton.Click - Me.Close() - End Sub -End Class \ No newline at end of file diff --git a/Tween/Tween.vbproj b/Tween/Tween.vbproj index a8974f6d..11a0dd91 100644 --- a/Tween/Tween.vbproj +++ b/Tween/Tween.vbproj @@ -162,12 +162,6 @@ Settings.settings True - - MyLists.vb - - - Form - FilterDialog.vb @@ -248,15 +242,6 @@ Designer - - MyLists.vb - - - MyLists.vb - - - MyLists.vb - FilterDialog.vb Designer diff --git a/TweenCS/MyLists.Designer.cs b/TweenCS/MyLists.Designer.cs new file mode 100644 index 00000000..baebda3b --- /dev/null +++ b/TweenCS/MyLists.Designer.cs @@ -0,0 +1,135 @@ +namespace Tween +{ + partial class MyLists + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MyLists)); + this.更新RToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.ListRefreshButton = new System.Windows.Forms.Button(); + this.ListsCheckedListBox = new System.Windows.Forms.CheckedListBox(); + this.ContextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); + this.追加AToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.削除DToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.ToolStripMenuItem1 = new System.Windows.Forms.ToolStripSeparator(); + this.CloseButton = new System.Windows.Forms.Button(); + this.ContextMenuStrip1.SuspendLayout(); + this.SuspendLayout(); + // + // 更新RToolStripMenuItem + // + this.更新RToolStripMenuItem.Name = "更新RToolStripMenuItem"; + resources.ApplyResources(this.更新RToolStripMenuItem, "更新RToolStripMenuItem"); + this.更新RToolStripMenuItem.Click += new System.EventHandler(this.更新RToolStripMenuItem_Click); + // + // ListRefreshButton + // + resources.ApplyResources(this.ListRefreshButton, "ListRefreshButton"); + this.ListRefreshButton.Name = "ListRefreshButton"; + this.ListRefreshButton.UseVisualStyleBackColor = true; + this.ListRefreshButton.Click += new System.EventHandler(this.ListRefreshButton_Click); + // + // ListsCheckedListBox + // + resources.ApplyResources(this.ListsCheckedListBox, "ListsCheckedListBox"); + this.ListsCheckedListBox.CheckOnClick = true; + this.ListsCheckedListBox.ContextMenuStrip = this.ContextMenuStrip1; + this.ListsCheckedListBox.FormattingEnabled = true; + this.ListsCheckedListBox.Name = "ListsCheckedListBox"; + this.ListsCheckedListBox.ItemCheck += new System.Windows.Forms.ItemCheckEventHandler(this.ListsCheckedListBox_ItemCheck); + this.ListsCheckedListBox.MouseDown += new System.Windows.Forms.MouseEventHandler(this.ListsCheckedListBox_MouseDown); + // + // ContextMenuStrip1 + // + this.ContextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.追加AToolStripMenuItem, + this.削除DToolStripMenuItem, + this.ToolStripMenuItem1, + this.更新RToolStripMenuItem}); + this.ContextMenuStrip1.Name = "ContextMenuStrip1"; + resources.ApplyResources(this.ContextMenuStrip1, "ContextMenuStrip1"); + this.ContextMenuStrip1.Opening += new System.ComponentModel.CancelEventHandler(this.ContextMenuStrip1_Opening); + // + // 追加AToolStripMenuItem + // + this.追加AToolStripMenuItem.Name = "追加AToolStripMenuItem"; + resources.ApplyResources(this.追加AToolStripMenuItem, "追加AToolStripMenuItem"); + this.追加AToolStripMenuItem.Click += new System.EventHandler(this.追加AToolStripMenuItem_Click); + // + // 削除DToolStripMenuItem + // + this.削除DToolStripMenuItem.Name = "削除DToolStripMenuItem"; + resources.ApplyResources(this.削除DToolStripMenuItem, "削除DToolStripMenuItem"); + this.削除DToolStripMenuItem.Click += new System.EventHandler(this.削除DToolStripMenuItem_Click); + // + // ToolStripMenuItem1 + // + this.ToolStripMenuItem1.Name = "ToolStripMenuItem1"; + resources.ApplyResources(this.ToolStripMenuItem1, "ToolStripMenuItem1"); + // + // CloseButton + // + resources.ApplyResources(this.CloseButton, "CloseButton"); + this.CloseButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.CloseButton.Name = "CloseButton"; + this.CloseButton.UseVisualStyleBackColor = true; + this.CloseButton.Click += new System.EventHandler(this.CloseButton_Click); + // + // MyLists + // + this.AcceptButton = this.CloseButton; + resources.ApplyResources(this, "$this"); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.CancelButton = this.CloseButton; + this.Controls.Add(this.ListRefreshButton); + this.Controls.Add(this.ListsCheckedListBox); + this.Controls.Add(this.CloseButton); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "MyLists"; + this.ShowInTaskbar = false; + this.Load += new System.EventHandler(this.MyLists_Load); + this.ContextMenuStrip1.ResumeLayout(false); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + internal System.Windows.Forms.ToolStripMenuItem 更新RToolStripMenuItem; + internal System.Windows.Forms.Button ListRefreshButton; + internal System.Windows.Forms.CheckedListBox ListsCheckedListBox; + internal System.Windows.Forms.ContextMenuStrip ContextMenuStrip1; + internal System.Windows.Forms.ToolStripMenuItem 追加AToolStripMenuItem; + internal System.Windows.Forms.ToolStripMenuItem 削除DToolStripMenuItem; + internal System.Windows.Forms.ToolStripSeparator ToolStripMenuItem1; + internal System.Windows.Forms.Button CloseButton; + } +} \ No newline at end of file diff --git a/TweenCS/MyLists.cs b/TweenCS/MyLists.cs new file mode 100644 index 00000000..1c1e7b6a --- /dev/null +++ b/TweenCS/MyLists.cs @@ -0,0 +1,261 @@ +// Tween - Client of Twitter +// Copyright (c) 2007-2011 kiri_feather (@kiri_feather) +// (c) 2008-2011 Moz (@syo68k) +// (c) 2008-2011 takeshik (@takeshik) +// (c) 2010-2011 anis774 (@anis774) +// (c) 2010-2011 fantasticswallow (@f_swallow) +// (c) 2011 kim_upsilon (@kim_upsilon) +// All rights reserved. +// +// This file is part of Tween. +// +// This program is free software; you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by the Free +// Software Foundation; either version 3 of the License, or (at your option) +// any later version. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program. If not, see , or write to +// the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, +// Boston, MA 02110-1301, USA. + +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Windows.Forms; + +namespace Tween +{ + public partial class MyLists : Form + { + private string contextUserName; + private Twitter _tw; + + public MyLists() + { + InitializeComponent(); + } + + public MyLists(string userName, Twitter tw) + { + this.InitializeComponent(); + + this.contextUserName = userName; + this._tw = tw; + + this.Text = this.contextUserName + Properties.Resources.MyLists1; + } + + private void MyLists_Load(object sender, EventArgs e) + { + this.ListsCheckedListBox.ItemCheck += this.ListsCheckedListBox_ItemCheck; + + this.ListsCheckedListBox.Items.AddRange(TabInformations.GetInstance().SubscribableLists.FindAll((item) => item.Username == this._tw.Username).ToArray()); + + for (int i = 0; i < this.ListsCheckedListBox.Items.Count; i++) + { + ListElement listItem = (ListElement)this.ListsCheckedListBox.Items[i]; + + List listPost = new List(); + List otherPost = new List(); + + foreach (TabClass tab in TabInformations.GetInstance().Tabs.Values) + { + if (tab.TabType == MyCommon.TabUsageType.Lists) + { + if (listItem.Id == tab.ListInfo.Id) + listPost.AddRange(tab.Posts.Values); + else + otherPost.AddRange(tab.Posts.Values); + } + } + + //リストが空の場合は推定不能 + if (listPost.Count == 0) + { + this.ListsCheckedListBox.SetItemCheckState(i, CheckState.Indeterminate); + continue; + } + + //リストに該当ユーザーのポストが含まれていれば、リストにユーザーが含まれているとする。 + if (listPost.Exists((item) => item.ScreenName == contextUserName)) + { + this.ListsCheckedListBox.SetItemChecked(i, true); + continue; + } + + List listPostUserIDs = new List(); + List listPostUserNames = new List(); + DateTime listOlderPostCreatedAt = DateTime.MaxValue; + DateTime listNewistPostCreatedAt = DateTime.MinValue; + + foreach (PostClass post in listPost) + { + if (post.UserId > 0 && !listPostUserIDs.Contains(post.UserId)) + { + listPostUserIDs.Add(post.UserId); + } + if (post.ScreenName != null && !listPostUserNames.Contains(post.ScreenName)) + { + listPostUserNames.Add(post.ScreenName); + } + if (post.CreatedAt < listOlderPostCreatedAt) + { + listOlderPostCreatedAt = post.CreatedAt; + } + if (post.CreatedAt > listNewistPostCreatedAt) + { + listNewistPostCreatedAt = post.CreatedAt; + } + } + + //リスト中のユーザーの人数がlistItem.MemberCount以上で、かつ該当のユーザーが含まれていなければ、リストにユーザーは含まれていないとする。 + if (listItem.MemberCount > 0 && listItem.MemberCount <= listPostUserIDs.Count && (!listPostUserNames.Contains(contextUserName))) + { + this.ListsCheckedListBox.SetItemChecked(i, false); + continue; + } + + otherPost.AddRange(TabInformations.GetInstance().Posts.Values); + + //リストに該当ユーザーのポストが含まれていないのにリスト以外で取得したポストの中にリストに含まれるべきポストがある場合は、リストにユーザーは含まれていないとする。 + if (otherPost.Exists((item) => (item.ScreenName == this.contextUserName) && (item.CreatedAt > listOlderPostCreatedAt) && (item.CreatedAt < listNewistPostCreatedAt) && ((!item.IsReply) || listPostUserNames.Contains(item.InReplyToUser)))) + { + this.ListsCheckedListBox.SetItemChecked(i, false); + continue; + } + + this.ListsCheckedListBox.SetItemCheckState(i, CheckState.Indeterminate); + } + + this.ListsCheckedListBox.ItemCheck += this.ListsCheckedListBox_ItemCheck; + } + + private void ListRefreshButton_Click(object sender, EventArgs e) + { + string rslt = this._tw.GetListsApi(); + if (rslt != "") + { + MessageBox.Show(String.Format(Properties.Resources.ListsDeleteFailed, rslt)); + } + else + { + this.ListsCheckedListBox.Items.Clear(); + this.MyLists_Load(this, EventArgs.Empty); + } + } + + private void ListsCheckedListBox_ItemCheck(object sender, ItemCheckEventArgs e) + { + ListElement list = (ListElement)this.ListsCheckedListBox.Items[e.Index]; + string rslt; + + switch (e.CurrentValue) + { + case CheckState.Indeterminate: + bool ret = false; + rslt = this._tw.ContainsUserAtList(list.Id.ToString(), contextUserName, ref ret); + if (rslt != "") + { + MessageBox.Show(string.Format(Properties.Resources.ListManageOKButton2, rslt)); + e.NewValue = CheckState.Indeterminate; + } + else + { + if (ret) + e.NewValue = CheckState.Checked; + else + e.NewValue = CheckState.Unchecked; + } + break; + case CheckState.Unchecked: + rslt = this._tw.AddUserToList(list.Id.ToString(), this.contextUserName.ToString()); + if (rslt != "") + { + MessageBox.Show(string.Format(Properties.Resources.ListManageOKButton2, rslt)); + e.NewValue = CheckState.Indeterminate; + } + break; + case CheckState.Checked: + rslt = this._tw.RemoveUserToList(list.Id.ToString(), this.contextUserName.ToString()); + if (rslt != "") + { + MessageBox.Show(String.Format(Properties.Resources.ListManageOKButton2, rslt)); + e.NewValue = CheckState.Indeterminate; + } + break; + } + } + + private void ContextMenuStrip1_Opening(object sender, CancelEventArgs e) + { + e.Cancel = this.ListsCheckedListBox.SelectedItem == null; + } + + private void 追加AToolStripMenuItem_Click(object sender, EventArgs e) + { + this.ListsCheckedListBox.ItemCheck -= this.ListsCheckedListBox_ItemCheck; + this.ListsCheckedListBox.SetItemCheckState(this.ListsCheckedListBox.SelectedIndex, CheckState.Unchecked); + this.ListsCheckedListBox.ItemCheck += this.ListsCheckedListBox_ItemCheck; + this.ListsCheckedListBox.SetItemCheckState(this.ListsCheckedListBox.SelectedIndex, CheckState.Checked); + } + + private void 削除DToolStripMenuItem_Click(object sender, EventArgs e) + { + this.ListsCheckedListBox.ItemCheck -= this.ListsCheckedListBox_ItemCheck; + this.ListsCheckedListBox.SetItemCheckState(this.ListsCheckedListBox.SelectedIndex, CheckState.Checked); + this.ListsCheckedListBox.ItemCheck += this.ListsCheckedListBox_ItemCheck; + this.ListsCheckedListBox.SetItemCheckState(this.ListsCheckedListBox.SelectedIndex, CheckState.Unchecked); + } + + private void 更新RToolStripMenuItem_Click(object sender, EventArgs e) + { + this.ListsCheckedListBox.ItemCheck -= this.ListsCheckedListBox_ItemCheck; + this.ListsCheckedListBox.SetItemCheckState(this.ListsCheckedListBox.SelectedIndex, CheckState.Indeterminate); + this.ListsCheckedListBox.ItemCheck += this.ListsCheckedListBox_ItemCheck; + this.ListsCheckedListBox.SetItemCheckState(this.ListsCheckedListBox.SelectedIndex, CheckState.Checked); + } + + private void ListsCheckedListBox_MouseDown(object sender, MouseEventArgs e) + { + switch (e.Button) + { + case MouseButtons.Left: + //項目が無い部分をクリックしても、選択されている項目のチェック状態が変更されてしまうので、その対策 + for (int index = 0; index < this.ListsCheckedListBox.Items.Count; index++) + { + if (this.ListsCheckedListBox.GetItemRectangle(index).Contains(e.Location)) + return; + } + this.ListsCheckedListBox.SelectedItem = null; + break; + case MouseButtons.Right: + //コンテキストメニューの項目実行時にSelectedItemプロパティを利用出来るように + for (int index = 0; index < this.ListsCheckedListBox.Items.Count; index++) + { + if (this.ListsCheckedListBox.GetItemRectangle(index).Contains(e.Location)) + { + this.ListsCheckedListBox.SetSelected(index, true); + return; + } + } + this.ListsCheckedListBox.SelectedItem = null; + break; + } + } + + private void CloseButton_Click(object sender, EventArgs e) + { + this.Close(); + } + } +} diff --git a/Tween/MyLists.en.resx b/TweenCS/MyLists.en.resx similarity index 100% rename from Tween/MyLists.en.resx rename to TweenCS/MyLists.en.resx diff --git a/Tween/MyLists.resx b/TweenCS/MyLists.resx similarity index 100% rename from Tween/MyLists.resx rename to TweenCS/MyLists.resx diff --git a/Tween/MyLists.zh-CHS.resx b/TweenCS/MyLists.zh-CHS.resx similarity index 100% rename from Tween/MyLists.zh-CHS.resx rename to TweenCS/MyLists.zh-CHS.resx diff --git a/TweenCS/TweenCS.csproj b/TweenCS/TweenCS.csproj index 35426cbc..5650f392 100644 --- a/TweenCS/TweenCS.csproj +++ b/TweenCS/TweenCS.csproj @@ -115,6 +115,12 @@ + + Form + + + MyLists.cs + @@ -215,6 +221,15 @@ InputTabName.cs + + MyLists.cs + + + MyLists.cs + + + MyLists.cs + OpenURL.cs -- 2.11.0