OSDN Git Service

7762554ba2be681ea9e682167f3003304d96dc81
[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 using System;
28 using System.Collections.Generic;
29 using System.ComponentModel;
30 using System.Drawing;
31 using System.Data;
32 using System.Linq;
33 using System.Text;
34 using System.Windows.Forms;
35
36 namespace OpenTween.Setting.Panel
37 {
38     public partial class ActionPanel : SettingPanelBase
39     {
40         public ActionPanel()
41             => this.InitializeComponent();
42
43         public void LoadConfig(SettingCommon settingCommon, SettingLocal settingLocal)
44         {
45             this.UReadMng.Checked = settingCommon.UnreadManage;
46             this.PlaySnd.Checked = settingCommon.PlaySound;
47             this.BrowserPathText.Text = settingLocal.BrowserPath;
48             this.CheckCloseToExit.Checked = settingCommon.CloseToExit;
49             this.CheckMinimizeToTray.Checked = settingCommon.MinimizeToTray;
50             this.CheckFavRestrict.Checked = settingCommon.RestrictFavCheck;
51             this.chkReadOwnPost.Checked = settingCommon.ReadOwnPost;
52             this.CheckReadOldPosts.Checked = settingCommon.ReadOldPosts;
53
54             this.HotkeyCheck.Checked = settingCommon.HotkeyEnabled;
55             this.HotkeyAlt.Checked = ((settingCommon.HotkeyModifier & Keys.Alt) == Keys.Alt);
56             this.HotkeyCtrl.Checked = ((settingCommon.HotkeyModifier & Keys.Control) == Keys.Control);
57             this.HotkeyShift.Checked = ((settingCommon.HotkeyModifier & Keys.Shift) == Keys.Shift);
58             this.HotkeyWin.Checked = ((settingCommon.HotkeyModifier & Keys.LWin) == Keys.LWin);
59             this.HotkeyCode.Text = settingCommon.HotkeyValue.ToString();
60             this.HotkeyText.Text = settingCommon.HotkeyKey.ToString();
61             this.HotkeyText.Tag = settingCommon.HotkeyKey;
62             this.HotkeyAlt.Enabled = settingCommon.HotkeyEnabled;
63             this.HotkeyShift.Enabled = settingCommon.HotkeyEnabled;
64             this.HotkeyCtrl.Enabled = settingCommon.HotkeyEnabled;
65             this.HotkeyWin.Enabled = settingCommon.HotkeyEnabled;
66             this.HotkeyText.Enabled = settingCommon.HotkeyEnabled;
67             this.HotkeyCode.Enabled = settingCommon.HotkeyEnabled;
68
69             this.CheckOpenUserTimeline.Checked = settingCommon.OpenUserTimeline;
70             this.ListDoubleClickActionComboBox.SelectedIndex = settingCommon.ListDoubleClickAction;
71             this.TabMouseLockCheck.Checked = settingCommon.TabMouseLock;
72         }
73
74         public void SaveConfig(SettingCommon settingCommon, SettingLocal settingLocal)
75         {
76             settingCommon.PlaySound = this.PlaySnd.Checked;
77             settingCommon.UnreadManage = this.UReadMng.Checked;
78             settingLocal.BrowserPath = this.BrowserPathText.Text.Trim();
79             settingCommon.CloseToExit = this.CheckCloseToExit.Checked;
80             settingCommon.MinimizeToTray = this.CheckMinimizeToTray.Checked;
81             settingCommon.RestrictFavCheck = this.CheckFavRestrict.Checked;
82             settingCommon.ReadOwnPost = this.chkReadOwnPost.Checked;
83             settingCommon.ReadOldPosts = this.CheckReadOldPosts.Checked;
84
85             settingCommon.HotkeyEnabled = this.HotkeyCheck.Checked;
86             settingCommon.HotkeyModifier = Keys.None;
87             if (this.HotkeyAlt.Checked)
88                 settingCommon.HotkeyModifier |= Keys.Alt;
89             if (this.HotkeyShift.Checked)
90                 settingCommon.HotkeyModifier |= Keys.Shift;
91             if (this.HotkeyCtrl.Checked)
92                 settingCommon.HotkeyModifier |= Keys.Control;
93             if (this.HotkeyWin.Checked)
94                 settingCommon.HotkeyModifier |= Keys.LWin;
95             int.TryParse(this.HotkeyCode.Text, out settingCommon.HotkeyValue);
96             settingCommon.HotkeyKey = (Keys)this.HotkeyText.Tag;
97
98             settingCommon.OpenUserTimeline = this.CheckOpenUserTimeline.Checked;
99             settingCommon.ListDoubleClickAction = this.ListDoubleClickActionComboBox.SelectedIndex;
100             settingCommon.TabMouseLock = this.TabMouseLockCheck.Checked;
101         }
102
103         private void Button3_Click(object sender, EventArgs e)
104         {
105             using var filedlg = new OpenFileDialog();
106
107             filedlg.Filter = Properties.Resources.Button3_ClickText1;
108             filedlg.FilterIndex = 1;
109             filedlg.Title = Properties.Resources.Button3_ClickText2;
110             filedlg.RestoreDirectory = true;
111
112             if (filedlg.ShowDialog() == DialogResult.OK)
113             {
114                 BrowserPathText.Text = filedlg.FileName;
115             }
116         }
117
118         private void HotkeyText_KeyDown(object sender, KeyEventArgs e)
119         {
120             //KeyValueで判定する。
121             //表示文字とのテーブルを用意すること
122             HotkeyText.Text = e.KeyCode.ToString();
123             HotkeyCode.Text = e.KeyValue.ToString();
124             HotkeyText.Tag = e.KeyCode;
125             e.Handled = true;
126             e.SuppressKeyPress = true;
127         }
128
129         private void HotkeyCheck_CheckedChanged(object sender, EventArgs e)
130         {
131             HotkeyCtrl.Enabled = HotkeyCheck.Checked;
132             HotkeyAlt.Enabled = HotkeyCheck.Checked;
133             HotkeyShift.Enabled = HotkeyCheck.Checked;
134             HotkeyWin.Enabled = HotkeyCheck.Checked;
135             HotkeyText.Enabled = HotkeyCheck.Checked;
136             HotkeyCode.Enabled = HotkeyCheck.Checked;
137         }
138     }
139 }