Skip to content

Commit

Permalink
ユーザー・Listタブのヘッダー部分をGeneralTimelineHeaderPanelに分離
Browse files Browse the repository at this point in the history
  • Loading branch information
upsilon committed Apr 29, 2024
1 parent 7bcbd57 commit 696462e
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 26 deletions.
34 changes: 34 additions & 0 deletions OpenTween.Tests/Controls/GeneralTimelineHeaderPanelTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// OpenTween - Client of Twitter
// Copyright (c) 2024 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
// All rights reserved.
//
// This file is part of OpenTween.
//
// 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 <http://www.gnu.org/licenses/>, or write to
// the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
// Boston, MA 02110-1301, USA.

using Xunit;

namespace OpenTween.Controls
{
public class GeneralTimelineHeaderPanelTest
{
[WinFormsFact]
public void Initialize_Test()
{
using var panel = new GeneralTimelineHeaderPanel();
}
}
}
54 changes: 54 additions & 0 deletions OpenTween/Controls/GeneralTimelineHeaderPanel.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions OpenTween/Controls/GeneralTimelineHeaderPanel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// OpenTween - Client of Twitter
// Copyright (c) 2007-2011 kiri_feather (@kiri_feather) <[email protected]>
// (c) 2008-2011 Moz (@syo68k)
// (c) 2008-2011 takeshik (@takeshik) <http://www.takeshik.org/>
// (c) 2010-2011 anis774 (@anis774) <http://d.hatena.ne.jp/anis774/>
// (c) 2010-2011 fantasticswallow (@f_swallow) <http://twitter.com/f_swallow>
// (c) 2011 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
// All rights reserved.
//
// This file is part of OpenTween.
//
// 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 <http://www.gnu.org/licenses/>, or write to
// the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
// Boston, MA 02110-1301, USA.

#nullable enable

using System.Windows.Forms;

namespace OpenTween.Controls
{
public partial class GeneralTimelineHeaderPanel : UserControl
{
public string HeaderText
{
get => this.headerText;
set
{
this.headerText = value;
this.UpdateLabelUser();
}
}

private string headerText = "";

public GeneralTimelineHeaderPanel()
=> this.InitializeComponent();

private void UpdateLabelUser()
=> this.labelHeader.Text = this.headerText;
}
}
25 changes: 25 additions & 0 deletions OpenTween/Controls/GeneralTimelineHeaderPanel.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?><root xml:space="preserve">
<resheader name="resmimetype"><value>text/microsoft-resx</value></resheader>
<resheader name="version"><value>2.0</value></resheader>
<resheader name="reader"><value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value></resheader>
<resheader name="writer"><value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value></resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<assembly alias="mscorlib" name="mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

<data name="$this.AutoScaleDimensions" type="System.Drawing.SizeF, System.Drawing"><value>96, 96</value></data>
<metadata name="$this.Localizable" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"><value>True</value></metadata>
<data name="$this.Size" type="System.Drawing.Size, System.Drawing"><value>400, 22</value></data>
<data name="&gt;&gt;$this.Name"><value>GeneralTimelineHeaderPanel</value></data>
<data name="&gt;&gt;$this.Type"><value>System.Windows.Forms.UserControl, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value></data>
<data name="&gt;&gt;labelHeader.Name"><value>labelHeader</value></data>
<data name="&gt;&gt;labelHeader.Parent"><value>$this</value></data>
<data name="&gt;&gt;labelHeader.Type"><value>System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value></data>
<data name="&gt;&gt;labelHeader.ZOrder"><value>0</value></data>
<data name="labelHeader.Dock" type="System.Windows.Forms.DockStyle, System.Windows.Forms"><value>Fill</value></data>
<data name="labelHeader.Location" type="System.Drawing.Point, System.Drawing"><value>0, 0</value></data>
<data name="labelHeader.Size" type="System.Drawing.Size, System.Drawing"><value>400, 22</value></data>
<data name="labelHeader.TabIndex" type="System.Int32, mscorlib"><value>0</value></data>
<data name="labelHeader.Text"><value>labelHeader</value></data>
<data name="labelHeader.TextAlign" type="System.Drawing.ContentAlignment, System.Drawing"><value>MiddleLeft</value></data>
</root>
9 changes: 9 additions & 0 deletions OpenTween/OpenTween.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@
<Compile Update="Controls\PublicSearchHeaderPanel.Designer.cs">
<DependentUpon>PublicSearchHeaderPanel.cs</DependentUpon>
</Compile>
<Compile Update="Controls\GeneralTimelineHeaderPanel.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Update="Controls\GeneralTimelineHeaderPanel.Designer.cs">
<DependentUpon>GeneralTimelineHeaderPanel.cs</DependentUpon>
</Compile>
<Compile Update="AppendSettingDialog.cs">
<SubType>Form</SubType>
</Compile>
Expand Down Expand Up @@ -343,6 +349,9 @@
<EmbeddedResource Update="Controls\PublicSearchHeaderPanel.resx">
<DependentUpon>PublicSearchHeaderPanel.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Update="Controls\GeneralTimelineHeaderPanel.resx">
<DependentUpon>GeneralTimelineHeaderPanel.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Update="EncryptApiKeyDialog.resx">
<DependentUpon>EncryptApiKeyDialog.cs</DependentUpon>
</EmbeddedResource>
Expand Down
40 changes: 14 additions & 26 deletions OpenTween/Tween.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2842,33 +2842,21 @@ public bool AddNewTab(TabModel tab, bool startup)

Control? headerPanel = null;

// UserTimeline関連
var userTab = tab as UserTimelineTabModel;
var listTab = tab as ListTimelineTabModel;

if (userTab != null || listTab != null)
if (tab is UserTimelineTabModel userTab)
{
var label = new Label
headerPanel = new GeneralTimelineHeaderPanel
{
Dock = DockStyle.Top,
Name = "labelUser",
TabIndex = 0,
HeaderText = $"{userTab.ScreenName}'s Timeline",
};

if (listTab != null)
{
label.Text = listTab.ListInfo.ToString();
}
else if (userTab != null)
{
label.Text = userTab.ScreenName + "'s Timeline";
}
label.TextAlign = ContentAlignment.MiddleLeft;
using (var tmpComboBox = new ComboBox())
}
else if (tab is ListTimelineTabModel listTab)
{
headerPanel = new GeneralTimelineHeaderPanel
{
label.Height = tmpComboBox.Height;
}
tabPage.Controls.Add(label);
Dock = DockStyle.Top,
HeaderText = listTab.ListInfo.ToString(),
};
}
// 検索関連の準備
else if (tab is PublicSearchTabModel searchTab)
Expand Down Expand Up @@ -2994,11 +2982,11 @@ public bool RemoveSpecifiedTab(string tabName, bool confirm)
this.ListTab.Controls.Remove(tabPage);

// 後付けのコントロールを破棄
if (tabInfo.TabType == MyCommon.TabUsageType.UserTimeline || tabInfo.TabType == MyCommon.TabUsageType.Lists)
if (tabInfo.TabType == MyCommon.TabUsageType.UserTimeline ||
tabInfo.TabType == MyCommon.TabUsageType.Lists)
{
using var label = tabPage.Controls["labelUser"];
tabPage.Controls.Remove(label);
listCustom = (DetailsListView)tabPage.Tag;
using var panel = tabPage.Controls.OfType<GeneralTimelineHeaderPanel>().First();
tabPage.Controls.Remove(panel);
}
else if (tabInfo.TabType == MyCommon.TabUsageType.PublicSearch)
{
Expand Down

0 comments on commit 696462e

Please sign in to comment.