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 OpenURL : OTBaseForm
42 private string? _selUrl;
45 => this.InitializeComponent();
47 private void OK_Button_Click(object sender, EventArgs e)
49 if (UrlList.SelectedItems.Count == 0)
51 this.DialogResult = DialogResult.Cancel;
55 _selUrl = UrlList.SelectedItem.ToString();
56 this.DialogResult = DialogResult.OK;
61 private void Cancel_Button_Click(object sender, EventArgs e)
63 this.DialogResult = DialogResult.Cancel;
67 public void ClearUrl()
68 => this.UrlList.Items.Clear();
70 public void AddUrl(OpenUrlItem openUrlItem)
71 => this.UrlList.Items.Add(openUrlItem);
73 public string SelectedUrl
77 if (UrlList.SelectedItems.Count == 1)
84 private void OpenURL_Shown(object sender, EventArgs e)
87 if (UrlList.Items.Count > 0)
88 UrlList.SelectedIndex = 0;
91 private void UrlList_DoubleClick(object sender, EventArgs e)
93 if (UrlList.SelectedItem == null)
96 if (UrlList.IndexFromPoint(UrlList.PointToClient(Control.MousePosition)) == ListBox.NoMatches)
99 if (UrlList.Items[UrlList.IndexFromPoint(UrlList.PointToClient(Control.MousePosition))] == null)
101 OK_Button_Click(sender, e);
104 private void UrlList_KeyDown(object sender, KeyEventArgs e)
106 if (e.KeyCode == Keys.J && UrlList.SelectedIndex < UrlList.Items.Count - 1)
108 e.SuppressKeyPress = true;
109 UrlList.SelectedIndex += 1;
111 if (e.KeyCode == Keys.K && UrlList.SelectedIndex > 0)
113 e.SuppressKeyPress = true;
114 UrlList.SelectedIndex -= 1;
116 if (e.Control && e.KeyCode == Keys.Oem4)
118 e.SuppressKeyPress = true;
119 Cancel_Button_Click(this.Cancel_Button, EventArgs.Empty);
124 public class OpenUrlItem
126 private readonly string _linkText;
128 public OpenUrlItem(string linkText, string url, string href)
130 this._linkText = linkText;
139 if (this._linkText.StartsWith("@", StringComparison.Ordinal)
140 || this._linkText.StartsWith("@", StringComparison.Ordinal)
141 || this._linkText.StartsWith("#", StringComparison.Ordinal)
142 || this._linkText.StartsWith("#", StringComparison.Ordinal))
143 return this._linkText;
144 if (this._linkText.TrimEnd('/') == this.Url.TrimEnd('/'))
147 return this._linkText + " >>> " + this.Url;
151 public override string ToString()
154 public string Url { get; }
155 public string Href { get; }