OSDN Git Service

C# 8.0 のnull許容参照型を有効化
[opentween/open-tween.git] / OpenTween / Setting / Panel / ActionPanel.cs
1 // OpenTween - Client of Twitter
2 // Copyright (c) 2007-2011 kiri_feather (@kiri_feather) <kiri.feather@gmail.com>
3 //           (c) 2008-2011 Moz (@syo68k)
4 //           (c) 2008-2011 takeshik (@takeshik) <http://www.takeshik.org/>
5 //           (c) 2010-2011 anis774 (@anis774) <http://d.hatena.ne.jp/anis774/>
6 //           (c) 2010-2011 fantasticswallow (@f_swallow) <http://twitter.com/f_swallow>
7 //           (c) 2014      kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
8 // All rights reserved.
9 //
10 // This file is part of OpenTween.
11 //
12 // This program is free software; you can redistribute it and/or modify it
13 // under the terms of the GNU General Public License as published by the Free
14 // Software Foundation; either version 3 of the License, or (at your option)
15 // any later version.
16 //
17 // This program is distributed in the hope that it will be useful, but
18 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 // for more details.
21 //
22 // You should have received a copy of the GNU General Public License along
23 // with this program. If not, see <http://www.gnu.org/licenses/>, or write to
24 // the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
25 // Boston, MA 02110-1301, USA.
26
27 #nullable enable
28
29 using System;
30 using System.Collections.Generic;
31 using System.ComponentModel;
32 using System.Drawing;
33 using System.Data;
34 using System.Linq;
35 using System.Text;
36 using System.Windows.Forms;
37
38 namespace OpenTween.Setting.Panel
39 {
40     public partial class ActionPanel : SettingPanelBase
41     {
42         public ActionPanel()
43             => this.InitializeComponent();
44
45         public void LoadConfig(SettingCommon settingCommon, SettingLocal settingLocal)
46         {
47             this.UReadMng.Checked = settingCommon.UnreadManage;
48             this.PlaySnd.Checked = settingCommon.PlaySound;
49             this.BrowserPathText.Text = settingLocal.BrowserPath;
50             this.CheckCloseToExit.Checked = settingCommon.CloseToExit;
51             this.CheckMinimizeToTray.Checked = settingCommon.MinimizeToTray;
52             this.CheckFavRestrict.Checked = settingCommon.RestrictFavCheck;
53             this.chkReadOwnPost.Checked = settingCommon.ReadOwnPost;
54             this.CheckReadOldPosts.Checked = settingCommon.ReadOldPosts;
55
56             this.HotkeyCheck.Checked = settingCommon.HotkeyEnabled;
57             this.HotkeyAlt.Checked = ((settingCommon.HotkeyModifier & Keys.Alt) == Keys.Alt);
58             this.HotkeyCtrl.Checked = ((settingCommon.HotkeyModifier & Keys.Control) == Keys.Control);
59             this.HotkeyShift.Checked = ((settingCommon.HotkeyModifier & Keys.Shift) == Keys.Shift);
60             this.HotkeyWin.Checked = ((settingCommon.HotkeyModifier & Keys.LWin) == Keys.LWin);
61             this.HotkeyCode.Text = settingCommon.HotkeyValue.ToString();
62             this.HotkeyText.Text = settingCommon.HotkeyKey.ToString();
63             this.HotkeyText.Tag = settingCommon.HotkeyKey;
64             this.HotkeyAlt.Enabled = settingCommon.HotkeyEnabled;
65             this.HotkeyShift.Enabled = settingCommon.HotkeyEnabled;
66             this.HotkeyCtrl.Enabled = settingCommon.HotkeyEnabled;
67             this.HotkeyWin.Enabled = settingCommon.HotkeyEnabled;
68             this.HotkeyText.Enabled = settingCommon.HotkeyEnabled;
69             this.HotkeyCode.Enabled = settingCommon.HotkeyEnabled;
70
71             this.CheckOpenUserTimeline.Checked = settingCommon.OpenUserTimeline;
72             this.ListDoubleClickActionComboBox.SelectedIndex = settingCommon.ListDoubleClickAction;
73             this.TabMouseLockCheck.Checked = settingCommon.TabMouseLock;
74         }
75
76         public void SaveConfig(SettingCommon settingCommon, SettingLocal settingLocal)
77         {
78             settingCommon.PlaySound = this.PlaySnd.Checked;
79             settingCommon.UnreadManage = this.UReadMng.Checked;
80             settingLocal.BrowserPath = this.BrowserPathText.Text.Trim();
81             settingCommon.CloseToExit = this.CheckCloseToExit.Checked;
82             settingCommon.MinimizeToTray = this.CheckMinimizeToTray.Checked;
83             settingCommon.RestrictFavCheck = this.CheckFavRestrict.Checked;
84             settingCommon.ReadOwnPost = this.chkReadOwnPost.Checked;
85             settingCommon.ReadOldPosts = this.CheckReadOldPosts.Checked;
86
87             settingCommon.HotkeyEnabled = this.HotkeyCheck.Checked;
88             settingCommon.HotkeyModifier = Keys.None;
89             if (this.HotkeyAlt.Checked)
90                 settingCommon.HotkeyModifier |= Keys.Alt;
91             if (this.HotkeyShift.Checked)
92                 settingCommon.HotkeyModifier |= Keys.Shift;
93             if (this.HotkeyCtrl.Checked)
94                 settingCommon.HotkeyModifier |= Keys.Control;
95             if (this.HotkeyWin.Checked)
96                 settingCommon.HotkeyModifier |= Keys.LWin;
97             int.TryParse(this.HotkeyCode.Text, out settingCommon.HotkeyValue);
98             settingCommon.HotkeyKey = (Keys)this.HotkeyText.Tag;
99
100             settingCommon.OpenUserTimeline = this.CheckOpenUserTimeline.Checked;
101             settingCommon.ListDoubleClickAction = this.ListDoubleClickActionComboBox.SelectedIndex;
102             settingCommon.TabMouseLock = this.TabMouseLockCheck.Checked;
103         }
104
105         private void Button3_Click(object sender, EventArgs e)
106         {
107             using var filedlg = new OpenFileDialog();
108
109             filedlg.Filter = Properties.Resources.Button3_ClickText1;
110             filedlg.FilterIndex = 1;
111             filedlg.Title = Properties.Resources.Button3_ClickText2;
112             filedlg.RestoreDirectory = true;
113
114             if (filedlg.ShowDialog() == DialogResult.OK)
115             {
116                 BrowserPathText.Text = filedlg.FileName;
117             }
118         }
119
120         private void HotkeyText_KeyDown(object sender, KeyEventArgs e)
121         {
122             //KeyValueで判定する。
123             //表示文字とのテーブルを用意すること
124             HotkeyText.Text = e.KeyCode.ToString();
125             HotkeyCode.Text = e.KeyValue.ToString();
126             HotkeyText.Tag = e.KeyCode;
127             e.Handled = true;
128             e.SuppressKeyPress = true;
129         }
130
131         private void HotkeyCheck_CheckedChanged(object sender, EventArgs e)
132         {
133             HotkeyCtrl.Enabled = HotkeyCheck.Checked;
134             HotkeyAlt.Enabled = HotkeyCheck.Checked;
135             HotkeyShift.Enabled = HotkeyCheck.Checked;
136             HotkeyWin.Enabled = HotkeyCheck.Checked;
137             HotkeyText.Enabled = HotkeyCheck.Checked;
138             HotkeyCode.Enabled = HotkeyCheck.Checked;
139         }
140     }
141 }