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.
30 using System.Collections.Generic;
31 using System.ComponentModel;
36 using System.Windows.Forms;
40 public partial class SearchWordDialog : OTBaseForm
42 public enum SearchType
55 public record SearchOptions(
58 bool NewTab, // タイムライン内検索のみで使用する
63 private SearchOptions? resultOptions = null;
65 public SearchOptions? ResultOptions
67 get => this.resultOptions;
70 this.resultOptions = value;
80 case SearchType.Timeline:
81 this.tabControl.SelectedTab = this.tabPageTimeline;
82 this.textSearchTimeline.Text = value.Query;
83 this.checkTimelineCaseSensitive.Checked = value.CaseSensitive;
84 this.checkTimelineRegex.Checked = value.UseRegex;
86 case SearchType.Public:
87 this.tabControl.SelectedTab = this.tabPagePublic;
88 this.textSearchTimeline.Text = value.Query;
91 throw new InvalidEnumArgumentException("value", (int)value.Type, typeof(SearchType));
96 private bool disableNetTabButton = false;
98 public bool DisableNewTabButton
100 get => this.disableNetTabButton;
103 this.disableNetTabButton = value;
104 this.buttonSearchTimelineNew.Enabled = !value;
108 public SearchWordDialog()
109 => this.InitializeComponent();
113 this.tabControl.SelectedTab = this.tabPageTimeline;
115 this.textSearchTimeline.ResetText();
116 this.checkTimelineCaseSensitive.Checked = false;
117 this.checkTimelineRegex.Checked = false;
119 this.textSearchPublic.ResetText();
122 private void SearchWordDialog_Shown(object sender, EventArgs e)
123 => this.ActivateSelectedTabPage();
125 private void TabControl_SelectedIndexChanged(object sender, EventArgs e)
126 => this.ActivateSelectedTabPage();
128 private void ActivateSelectedTabPage()
130 if (this.tabControl.SelectedTab == this.tabPageTimeline)
132 this.AcceptButton = this.buttonSearchTimeline;
133 this.textSearchTimeline.SelectAll();
134 this.textSearchTimeline.Focus();
138 this.AcceptButton = this.buttonSearchPublic;
139 this.textSearchPublic.SelectAll();
140 this.textSearchPublic.Focus();
144 private void ButtonSearchTimeline_Click(object sender, EventArgs e)
146 if (MyCommon.IsNullOrEmpty(this.textSearchTimeline.Text))
148 this.DialogResult = DialogResult.Cancel;
152 this.DialogResult = DialogResult.OK;
154 this.ResultOptions = new SearchOptions(
156 this.textSearchTimeline.Text,
158 this.checkTimelineCaseSensitive.Checked,
159 this.checkTimelineRegex.Checked
163 private void ButtonSearchTimelineNew_Click(object sender, EventArgs e)
165 if (MyCommon.IsNullOrEmpty(this.textSearchTimeline.Text))
167 this.DialogResult = DialogResult.Cancel;
171 this.DialogResult = DialogResult.OK;
173 this.ResultOptions = new SearchOptions(
175 this.textSearchTimeline.Text,
177 this.checkTimelineCaseSensitive.Checked,
178 this.checkTimelineRegex.Checked
182 private void ButtonSearchPublic_Click(object sender, EventArgs e)
184 if (MyCommon.IsNullOrEmpty(this.textSearchPublic.Text))
186 this.DialogResult = DialogResult.Cancel;
190 this.DialogResult = DialogResult.OK;
192 this.ResultOptions = new SearchOptions(
194 this.textSearchPublic.Text,
201 private async void LinkLabelSearchHelp_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
203 // 「検索オプションの使い方」ページのURL
204 const string PublicSearchHelpUrl = "https://support.twitter.com/articles/249059";
205 await MyCommon.OpenInBrowserAsync(this, PublicSearchHelpUrl);
208 private void SearchWordDialog_KeyDown(object sender, KeyEventArgs e)
210 if (e.KeyCode == Keys.Escape)
211 this.DialogResult = DialogResult.Cancel;