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) 2011 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
8 // All rights reserved.
10 // This file is part of OpenTween.
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)
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
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.
28 using System.Collections.Generic;
29 using System.ComponentModel;
34 using System.Windows.Forms;
38 public partial class SearchWordDialog : OTBaseForm
40 public enum SearchType
52 public class SearchOptions
54 public SearchType Type { get; }
55 public string Query { get; }
58 public bool NewTab { get; }
59 public bool CaseSensitive { get; }
60 public bool UseRegex { get; }
62 public SearchOptions(SearchType type, string query, bool newTab, bool caseSensitive, bool useRegex)
67 this.CaseSensitive = caseSensitive;
68 this.UseRegex = useRegex;
72 private SearchOptions resultOptoins = null;
73 public SearchOptions ResultOptions
75 get => this.resultOptoins;
78 this.resultOptoins = value;
88 case SearchType.Timeline:
89 this.tabControl.SelectedTab = this.tabPageTimeline;
90 this.textSearchTimeline.Text = value.Query;
91 this.checkTimelineCaseSensitive.Checked = value.CaseSensitive;
92 this.checkTimelineRegex.Checked = value.UseRegex;
94 case SearchType.Public:
95 this.tabControl.SelectedTab = this.tabPagePublic;
96 this.textSearchTimeline.Text = value.Query;
99 throw new InvalidEnumArgumentException("value", (int)value.Type, typeof(SearchType));
104 private bool disableNetTabButton = false;
105 public bool DisableNewTabButton
107 get => this.disableNetTabButton;
110 this.disableNetTabButton = value;
111 this.buttonSearchTimelineNew.Enabled = !value;
115 public SearchWordDialog()
116 => this.InitializeComponent();
120 this.tabControl.SelectedTab = this.tabPageTimeline;
122 this.textSearchTimeline.ResetText();
123 this.checkTimelineCaseSensitive.Checked = false;
124 this.checkTimelineRegex.Checked = false;
126 this.textSearchPublic.ResetText();
129 private void SearchWordDialog_Shown(object sender, EventArgs e)
130 => this.ActivateSelectedTabPage();
132 private void tabControl_SelectedIndexChanged(object sender, EventArgs e)
133 => this.ActivateSelectedTabPage();
135 private void ActivateSelectedTabPage()
137 if (this.tabControl.SelectedTab == this.tabPageTimeline)
139 this.AcceptButton = this.buttonSearchTimeline;
140 this.textSearchTimeline.SelectAll();
141 this.textSearchTimeline.Focus();
145 this.AcceptButton = this.buttonSearchPublic;
146 this.textSearchPublic.SelectAll();
147 this.textSearchPublic.Focus();
151 private void buttonSearchTimeline_Click(object sender, EventArgs e)
153 if (string.IsNullOrEmpty(this.textSearchTimeline.Text))
155 this.DialogResult = DialogResult.Cancel;
159 this.DialogResult = DialogResult.OK;
161 this.ResultOptions = new SearchOptions(
163 this.textSearchTimeline.Text,
165 this.checkTimelineCaseSensitive.Checked,
166 this.checkTimelineRegex.Checked
170 private void buttonSearchTimelineNew_Click(object sender, EventArgs e)
172 if (string.IsNullOrEmpty(this.textSearchTimeline.Text))
174 this.DialogResult = DialogResult.Cancel;
178 this.DialogResult = DialogResult.OK;
180 this.ResultOptions = new SearchOptions(
182 this.textSearchTimeline.Text,
184 this.checkTimelineCaseSensitive.Checked,
185 this.checkTimelineRegex.Checked
189 private void buttonSearchPublic_Click(object sender, EventArgs e)
191 if (string.IsNullOrEmpty(this.textSearchPublic.Text))
193 this.DialogResult = DialogResult.Cancel;
197 this.DialogResult = DialogResult.OK;
199 this.ResultOptions = new SearchOptions(
201 this.textSearchPublic.Text,
208 private async void linkLabelSearchHelp_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
210 // 「検索オプションの使い方」ページのURL
211 const string PublicSearchHelpUrl = "https://support.twitter.com/articles/249059";
213 var tweenMain = (TweenMain)this.Owner;
214 await tweenMain.OpenUriInBrowserAsync(PublicSearchHelpUrl);
217 private void SearchWordDialog_KeyDown(object sender, KeyEventArgs e)
219 if (e.KeyCode == Keys.Escape)
220 this.DialogResult = DialogResult.Cancel;