private void SetImagePageCombo(SelectedMedia media = null) { using (ControlTransaction.Update(ImagePageCombo)) { ImagePageCombo.Enabled = false; foreach (SelectedMedia oldMedia in ImagePageCombo.Items) { if (oldMedia == null || oldMedia == media) { continue; } DisposeMediaItem(oldMedia.Item); } ImagePageCombo.Items.Clear(); if (media == null) { media = new SelectedMedia("1"); } ImagePageCombo.Items.Add(media); ImagefilePathText.Text = media.Path; AlternativeTextBox.Text = media.AltText; ImagePageCombo.SelectedIndex = 0; } }
private async void DeleteUserButton_Click(object sender, EventArgs e) { if (this.ListsList.SelectedItem == null || this.UserList.SelectedItem == null) { return; } using (ControlTransaction.Disabled(this)) { ListElement list = (ListElement)this.ListsList.SelectedItem; UserInfo user = (UserInfo)this.UserList.SelectedItem; if (MessageBox.Show(Properties.Resources.ListManageDeleteUser1, ApplicationSettings.ApplicationName, MessageBoxButtons.OKCancel) == DialogResult.OK) { try { await this.tw.Api.ListsMembersDestroy(list.Id, user.ScreenName) .IgnoreResponse(); } catch (WebApiException ex) { MessageBox.Show(string.Format(Properties.Resources.ListManageDeleteUser2, ex.Message)); return; } int idx = ListsList.SelectedIndex; list.Members.Remove(user); this.ListsList_SelectedIndexChanged(this.ListsList, EventArgs.Empty); if (idx < ListsList.Items.Count) { ListsList.SelectedIndex = idx; } } } }
private async void ListManage_Load(object sender, EventArgs e) { using (ControlTransaction.Disabled(this)) { try { var lists = (IReadOnlyList <ListElement>)TabInformations.GetInstance().SubscribableLists; if (lists.Count == 0) { lists = await this.FetchListsAsync(); } this.UpdateListsListBox(lists); } catch (OperationCanceledException) { this.DialogResult = DialogResult.Cancel; return; } catch (WebApiException) { this.DialogResult = DialogResult.Abort; return; } } }
private async void MenuItemDelete_Click(object sender, EventArgs e) { using (ControlTransaction.Disabled(this)) { await this.RemoveFromList((ListElement)this.ListsCheckedListBox.SelectedItem); } }
private async void ButtonUnFollow_Click(object sender, EventArgs e) { if (MessageBox.Show(this._displayUser.ScreenName + Properties.Resources.ButtonUnFollow_ClickText1, Properties.Resources.ButtonUnFollow_ClickText2, MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == DialogResult.Yes) { using (ControlTransaction.Disabled(this.ButtonUnFollow)) { try { await this.twitterApi.FriendshipsDestroy(this._displayUser.ScreenName) .IgnoreResponse(); } catch (WebApiException ex) { MessageBox.Show(Properties.Resources.FRMessage2 + ex.Message); return; } } MessageBox.Show(Properties.Resources.FRMessage3); LabelIsFollowing.Text = Properties.Resources.GetFriendshipInfo2; ButtonFollow.Enabled = true; ButtonUnFollow.Enabled = false; } }
private async void GetMoreUsersButton_Click(object sender, EventArgs e) { using (ControlTransaction.Disabled(this)) { if (this.ListsList.SelectedItem == null) { return; } this.UserList.Items.Clear(); var list = (ListElement)this.ListsList.SelectedItem; try { await list.GetMoreMembers(); } catch (WebApiException ex) { MessageBox.Show(string.Format(Properties.Resources.ListManageGetListMembersCallback1, ex.Message)); return; } this.ListsList_SelectedIndexChanged(this.ListsList, EventArgs.Empty); this.GetMoreUsersButton.Text = Properties.Resources.ListManageGetMoreUsers1; } }
private async void buttonLogin_Click(object sender, EventArgs e) { if (this.LoginCallback == null) { return; } try { using (ControlTransaction.Disabled(this)) { // AcceptButton によって自動でフォームが閉じられるのを抑制する this.AcceptButton = null; this.LoginSuccessed = await this.LoginCallback(); if (this.LoginSuccessed) { this.DialogResult = DialogResult.OK; } } } finally { this.AcceptButton = this.buttonLogin; } }
private void scrollBar_ValueChanged(object sender, EventArgs e) { using (ControlTransaction.Layout(this, false)) { var value = this.scrollBar.Value; for (var i = 0; i < this.pictureBox.Count; i++) { this.pictureBox[i].Visible = (i == value); } } }
private async void ListRefreshButton_Click(object sender, EventArgs e) { using (ControlTransaction.Disabled(this)) { try { await this.RefreshListBox(); } catch (OperationCanceledException) { } catch (WebApiException ex) { MessageBox.Show($"Failed to get lists. ({ex.Message})"); } } }
private void UpdateListsListBox(IEnumerable <ListElement> lists) { using (ControlTransaction.Update(this.ListsList)) { this.ListsList.Items.Clear(); foreach (var listItem in lists.Where(x => x.UserId == this.tw.UserId)) { this.ListsList.Items.Add(listItem); } if (this.ListsList.Items.Count > 0) { this.ListsList.SelectedIndex = 0; } this.ListsList.Focus(); } }
private async void RefreshButton_Click(object sender, EventArgs e) { using (ControlTransaction.Disabled(this)) { try { var lists = await this.FetchListsAsync(); this.UpdateListsListBox(lists); } catch (OperationCanceledException) { } catch (WebApiException ex) { MessageBox.Show("Failed to get lists. (" + ex.Message + ")"); } } }
private async void RefreshListsButton_Click(object sender, EventArgs e) { using (ControlTransaction.Disabled(this)) { try { var lists = await this.FetchListsAsync(); this.UpdateListsListBox(lists); } catch (OperationCanceledException) { } catch (WebApiException ex) { MessageBox.Show(string.Format(Properties.Resources.ListsDeleteFailed, ex.Message)); } } }
/// <summary> /// 表示するサムネイルの数を設定する /// </summary> /// <param name="count">表示するサムネイルの数</param> protected void SetThumbnailCount(int count) { if (count == 0 && this.pictureBox.Count == 0) { return; } using (ControlTransaction.Layout(this.panelPictureBox, false)) { this.panelPictureBox.Controls.Clear(); foreach (var picbox in this.pictureBox) { var memoryImage = picbox.Image; filter.Unregister(picbox); picbox.MouseWheel -= this.pictureBox_MouseWheel; picbox.DoubleClick -= this.pictureBox_DoubleClick; picbox.Dispose(); memoryImage?.Dispose(); // メモリリーク対策 (http://stackoverflow.com/questions/2792427#2793714) picbox.ContextMenuStrip = null; } this.pictureBox.Clear(); this.scrollBar.Maximum = (count > 0) ? count - 1 : 0; this.scrollBar.Value = 0; for (int i = 0; i < count; i++) { var picbox = CreatePictureBox("pictureBox" + i); picbox.Visible = (i == 0); picbox.MouseWheel += this.pictureBox_MouseWheel; picbox.DoubleClick += this.pictureBox_DoubleClick; filter.Register(picbox); this.panelPictureBox.Controls.Add(picbox); this.pictureBox.Add(picbox); } } }
private async void StartAuthButton_Click(object sender, EventArgs e) { using (ControlTransaction.Disabled(this.BasedPanel.StartAuthButton)) { try { this.ApplyNetworkSettings(); var newAccount = await this.PinAuth(); if (newAccount == null) { return; } var authUserCombo = this.BasedPanel.AuthUserCombo; var oldAccount = authUserCombo.Items.Cast <UserAccount>() .FirstOrDefault(x => x.UserId == newAccount.UserId); int idx; if (oldAccount != null) { idx = authUserCombo.Items.IndexOf(oldAccount); authUserCombo.Items[idx] = newAccount; } else { idx = authUserCombo.Items.Add(newAccount); } authUserCombo.SelectedIndex = idx; MessageBox.Show(this, Properties.Resources.AuthorizeButton_Click1, "Authenticate", MessageBoxButtons.OK); } catch (WebApiException ex) { var message = Properties.Resources.AuthorizeButton_Click2 + Environment.NewLine + ex.Message; MessageBox.Show(this, message, "Authenticate", MessageBoxButtons.OK); } } }
private void SetImagePageCombo(SelectedMedia media = null) { using (ControlTransaction.Update(ImagePageCombo)) { ImagePageCombo.Enabled = false; ImagePageCombo.Items.Clear(); if (media != null) { ImagePageCombo.Items.Add(media); ImagefilePathText.Text = media.Path; } else { ImagePageCombo.Items.Add(new SelectedMedia("1")); ImagefilePathText.Text = ""; } ImagePageCombo.SelectedIndex = 0; } }
private async void MyLists_Load(object sender, EventArgs e) { using (ControlTransaction.Disabled(this)) { try { await this.RefreshListBox(); } catch (OperationCanceledException) { this.DialogResult = DialogResult.Cancel; } catch (WebApiException ex) { MessageBox.Show($"Failed to get lists. ({ex.Message})"); this.DialogResult = DialogResult.Abort; } } }
private void SetImageServiceCombo() { using (ControlTransaction.Update(ImageServiceCombo)) { string svc = ""; if (ImageServiceCombo.SelectedIndex > -1) { svc = ImageServiceCombo.Text; } ImageServiceCombo.Items.Clear(); // Add service names to combobox foreach (var key in pictureService.Keys) { ImageServiceCombo.Items.Add(key); } SelectImageServiceComboItem(svc); } }
private async void ButtonFollow_Click(object sender, EventArgs e) { using (ControlTransaction.Disabled(this.ButtonFollow)) { try { await this.twitterApi.FriendshipsCreate(this._displayUser.ScreenName) .IgnoreResponse(); } catch (WebApiException ex) { MessageBox.Show(Properties.Resources.FRMessage2 + ex.Message); return; } } MessageBox.Show(Properties.Resources.FRMessage3); LabelIsFollowing.Text = Properties.Resources.GetFriendshipInfo1; ButtonFollow.Enabled = false; ButtonUnFollow.Enabled = true; }
private void UpdateListsListBox(IEnumerable <ListElement> lists) { using (ControlTransaction.Update(this.ListsList)) { this.ListsList.Items.Clear(); this.ListsList.Items.AddRange(lists.ToArray()); if (this.ListsList.Items.Count > 0) { this.ListsList.SelectedIndex = 0; } else { this.UsernameLabel.Text = ""; this.NameLabel.Text = ""; this.StatusLabel.Text = ""; this.MemberCountLabel.Text = "0"; this.SubscriberCountLabel.Text = "0"; this.DescriptionText.Text = ""; } } }
private void ButtonDelete_Click(object sender, EventArgs e) { var selectedCount = ListFilters.SelectedIndices.Count; if (selectedCount == 0) { return; } string tmp; if (selectedCount == 1) { tmp = string.Format(Properties.Resources.ButtonDelete_ClickText1, Environment.NewLine, ListFilters.SelectedItem.ToString()); } else { tmp = string.Format(Properties.Resources.ButtonDelete_ClickText3, selectedCount.ToString()); } var rslt = MessageBox.Show(tmp, Properties.Resources.ButtonDelete_ClickText2, MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (rslt == DialogResult.Cancel) { return; } var indices = ListFilters.SelectedIndices.Cast <int>().Reverse().ToArray(); // 後ろの要素から削除 var tab = _sts.Tabs[ListTabs.SelectedItem.ToString()]; using (ControlTransaction.Update(ListFilters)) { foreach (var idx in indices) { tab.RemoveFilter((PostFilterRule)ListFilters.Items[idx]); ListFilters.Items.RemoveAt(idx); } } }
private async void ListsCheckedListBox_ItemCheck(object sender, ItemCheckEventArgs e) { // 他のイベント等で操作中の場合は無視する if (!this.Enabled) { return; } using (ControlTransaction.Disabled(this)) { var list = (ListElement)this.ListsCheckedListBox.Items[e.Index]; if (e.CurrentValue == CheckState.Unchecked) { await this.AddToList(list); } else { await this.RemoveFromList(list); } } }
private async void DeleteListButton_Click(object sender, EventArgs e) { if (this.ListsList.SelectedItem == null) { return; } using (ControlTransaction.Disabled(this)) { ListElement list = (ListElement)this.ListsList.SelectedItem; if (MessageBox.Show(Properties.Resources.ListManageDeleteLists1, ApplicationSettings.ApplicationName, MessageBoxButtons.OKCancel) == DialogResult.OK) { try { await this.tw.DeleteList(list.Id); } catch (WebApiException ex) { MessageBox.Show(Properties.Resources.ListManageOKButton2, ex.Message); return; } try { await this.tw.GetListsApi(); } catch (WebApiException ex) { MessageBox.Show(Properties.Resources.ListsDeleteFailed, ex.Message); return; } this.ListsList.Items.Clear(); this.ListManage_Load(this, EventArgs.Empty); } } }
private async void OKEditButton_Click(object sender, EventArgs e) { if (this.ListsList.SelectedItem == null) { return; } using (ControlTransaction.Disabled(this)) { ListElement listItem = (ListElement)this.ListsList.SelectedItem; if (string.IsNullOrEmpty(this.NameTextBox.Text)) { MessageBox.Show(Properties.Resources.ListManageOKButton1); return; } listItem.Name = this.NameTextBox.Text; listItem.IsPublic = this.PublicRadioButton.Checked; listItem.Description = this.DescriptionText.Text; try { await listItem.Refresh(); } catch (WebApiException ex) { MessageBox.Show(string.Format(Properties.Resources.ListManageOKButton2, ex.Message)); return; } this.ListsList.Items.Clear(); this.ListManage_Load(null, EventArgs.Empty); this.EditCheckBox.AutoCheck = true; this.EditCheckBox.Checked = false; } }
private async Task RefreshListBox() { using (var dialog = new WaitingDialog(Properties.Resources.ListsGetting)) { var cancellationToken = dialog.EnableCancellation(); var task = Task.Run(() => this.FetchMembershipListIds()); await dialog.WaitForAsync(this, task); cancellationToken.ThrowIfCancellationRequested(); } using (ControlTransaction.Update(this.ListsCheckedListBox)) { this.ListsCheckedListBox.Items.Clear(); foreach (var list in this.ownedLists) { var added = this.addedListIds.Contains(list.Id); this.ListsCheckedListBox.Items.Add(list, isChecked: added); } } }
private async void ButtonBlockDestroy_Click(object sender, EventArgs e) { if (MessageBox.Show(this._displayUser.ScreenName + Properties.Resources.ButtonBlockDestroy_ClickText1, Properties.Resources.ButtonBlockDestroy_ClickText2, MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == DialogResult.Yes) { using (ControlTransaction.Disabled(this.ButtonBlockDestroy)) { try { await this.twitterApi.BlocksDestroy(this._displayUser.ScreenName) .IgnoreResponse(); } catch (WebApiException ex) { MessageBox.Show("Err:" + ex.Message + Environment.NewLine + Properties.Resources.ButtonBlockDestroy_ClickText3); return; } MessageBox.Show(Properties.Resources.ButtonBlockDestroy_ClickText4); } } }
private void MoveSelectedRules(bool up) { var tabIdx = ListTabs.SelectedIndex; if (tabIdx == -1 || ListFilters.SelectedIndices.Count == 0) { return; } var indices = ListFilters.SelectedIndices.Cast <int>().ToArray(); int diff; if (up) { if (indices[0] <= 0) { return; } diff = -1; } else { if (indices[indices.Length - 1] >= ListFilters.Items.Count - 1) { return; } diff = +1; Array.Reverse(indices); // 逆順にして、下にある要素から処理する } var lastSelIdx = indices[0] + diff; var tab = _sts.Tabs[ListTabs.Items[tabIdx].ToString()]; try { _moveRules = true; // SelectedIndexChanged を無視する using (ControlTransaction.Update(ListFilters)) { ListFilters.SelectedIndices.Clear(); foreach (var idx in indices) { var tidx = idx + diff; var target = (PostFilterRule)ListFilters.Items[tidx]; // 移動先にある要素と位置を入れ替える ListFilters.Items.RemoveAt(tidx); ListFilters.Items.Insert(idx, target); // 移動方向の先頭要素以外なら選択する if (tidx != lastSelIdx) { ListFilters.SelectedIndex = tidx; } } tab.FilterArray = ListFilters.Items.Cast <PostFilterRule>().ToArray(); // 移動方向の先頭要素は最後に選択する // ※移動方向への自動スクロール目的 ListFilters.SelectedIndex = lastSelIdx; } } finally { _moveRules = false; } }
private async void ButtonEdit_Click(object sender, EventArgs e) { // 自分以外のプロフィールは変更できない if (this.twitterApi.CurrentUserId != this._displayUser.Id) { return; } using (ControlTransaction.Disabled(this.ButtonEdit)) { if (!IsEditing) { ButtonEditText = ButtonEdit.Text; ButtonEdit.Text = Properties.Resources.UserInfoButtonEdit_ClickText1; TextBoxName.Text = LabelName.Text; TextBoxName.Enabled = true; TextBoxName.Visible = true; LabelName.Visible = false; TextBoxLocation.Text = LabelLocation.Text; TextBoxLocation.Enabled = true; TextBoxLocation.Visible = true; LabelLocation.Visible = false; TextBoxWeb.Text = this._displayUser.Url; TextBoxWeb.Enabled = true; TextBoxWeb.Visible = true; LinkLabelWeb.Visible = false; TextBoxDescription.Text = this._displayUser.Description; TextBoxDescription.Enabled = true; TextBoxDescription.Visible = true; DescriptionBrowser.Visible = false; TextBoxName.Focus(); TextBoxName.Select(TextBoxName.Text.Length, 0); IsEditing = true; } else { Task showUserTask = null; if (TextBoxName.Modified || TextBoxLocation.Modified || TextBoxWeb.Modified || TextBoxDescription.Modified) { try { var response = await this.twitterApi.AccountUpdateProfile( this.TextBoxName.Text, this.TextBoxWeb.Text, this.TextBoxLocation.Text, this.TextBoxDescription.Text); var user = await response.LoadJsonAsync(); showUserTask = this.ShowUserAsync(user); } catch (WebApiException ex) { MessageBox.Show($"Err:{ex.Message}(AccountUpdateProfile)"); return; } } TextBoxName.Enabled = false; TextBoxName.Visible = false; LabelName.Visible = true; TextBoxLocation.Enabled = false; TextBoxLocation.Visible = false; LabelLocation.Visible = true; TextBoxWeb.Enabled = false; TextBoxWeb.Visible = false; LinkLabelWeb.Visible = true; TextBoxDescription.Enabled = false; TextBoxDescription.Visible = false; DescriptionBrowser.Visible = true; ButtonEdit.Text = ButtonEditText; IsEditing = false; if (showUserTask != null) { await showUserTask; } } } }