working on characterlist

This commit is contained in:
Zoe Fenris
2024-06-22 19:31:17 +02:00
parent 82ec7e48c6
commit 75b0d649c3
7 changed files with 308 additions and 40 deletions

View File

@@ -34,11 +34,11 @@
radMenuItem_DeleteChar = new Telerik.WinControls.UI.RadMenuItem();
radMenuItem_OpenChar = new Telerik.WinControls.UI.RadMenuItem();
tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
radTextBoxControl1 = new Telerik.WinControls.UI.RadTextBoxControl();
radTextBoxControl_SearchBox = new Telerik.WinControls.UI.RadTextBoxControl();
((System.ComponentModel.ISupportInitialize)radListView_CharList).BeginInit();
((System.ComponentModel.ISupportInitialize)radMenu1).BeginInit();
tableLayoutPanel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)radTextBoxControl1).BeginInit();
((System.ComponentModel.ISupportInitialize)radTextBoxControl_SearchBox).BeginInit();
SuspendLayout();
//
// radListView_CharList
@@ -80,7 +80,7 @@
tableLayoutPanel1.ColumnCount = 1;
tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
tableLayoutPanel1.Controls.Add(radListView_CharList, 0, 1);
tableLayoutPanel1.Controls.Add(radTextBoxControl1, 0, 0);
tableLayoutPanel1.Controls.Add(radTextBoxControl_SearchBox, 0, 0);
tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
tableLayoutPanel1.Location = new System.Drawing.Point(0, 20);
tableLayoutPanel1.Name = "tableLayoutPanel1";
@@ -90,14 +90,15 @@
tableLayoutPanel1.Size = new System.Drawing.Size(500, 480);
tableLayoutPanel1.TabIndex = 1;
//
// radTextBoxControl1
// radTextBoxControl_SearchBox
//
radTextBoxControl1.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
radTextBoxControl1.Location = new System.Drawing.Point(3, 3);
radTextBoxControl1.Name = "radTextBoxControl1";
radTextBoxControl1.NullText = "Search...";
radTextBoxControl1.Size = new System.Drawing.Size(494, 22);
radTextBoxControl1.TabIndex = 1;
radTextBoxControl_SearchBox.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
radTextBoxControl_SearchBox.Location = new System.Drawing.Point(3, 3);
radTextBoxControl_SearchBox.Name = "radTextBoxControl_SearchBox";
radTextBoxControl_SearchBox.NullText = "Search...";
radTextBoxControl_SearchBox.Size = new System.Drawing.Size(494, 22);
radTextBoxControl_SearchBox.TabIndex = 1;
radTextBoxControl_SearchBox.TextChanged += RadTextBoxControl_SearchBox_TextChanged;
//
// CharacterListControl
//
@@ -110,7 +111,7 @@
((System.ComponentModel.ISupportInitialize)radListView_CharList).EndInit();
((System.ComponentModel.ISupportInitialize)radMenu1).EndInit();
tableLayoutPanel1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)radTextBoxControl1).EndInit();
((System.ComponentModel.ISupportInitialize)radTextBoxControl_SearchBox).EndInit();
ResumeLayout(false);
PerformLayout();
}
@@ -123,6 +124,6 @@
private Telerik.WinControls.UI.RadMenuItem radMenuItem_DeleteChar;
private Telerik.WinControls.UI.RadMenuItem radMenuItem_OpenChar;
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
private Telerik.WinControls.UI.RadTextBoxControl radTextBoxControl1;
private Telerik.WinControls.UI.RadTextBoxControl radTextBoxControl_SearchBox;
}
}

View File

@@ -3,6 +3,7 @@ using OwnChar.App.Desktop.LangRes;
using OwnChar.Model;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Windows.Forms;
using Telerik.WinControls;
using Telerik.WinControls.UI;
@@ -61,18 +62,41 @@ public partial class CharacterListControl : UserControl
{
foreach (Character character in characters)
{
AddCharToList(character);
AddCharToList(character, false);
}
}
radListView_CharList.EndUpdate();
}
private void AddCharToList(Character character)
private void AddCharToList(Character character, bool focus)
{
radListView_CharList.BeginUpdate();
var newItem = new ListViewDataItem();
UpdateCharListViewItem(newItem, character);
newItem.Value = character;
radListView_CharList.EndUpdate();
if (focus)
{
radListView_CharList.SelectedItem = newItem;
radListView_CharList.ListViewElement.ViewElement.Scroller.ScrollToItem(newItem);
}
}
private void RemoveCharFromList(Character character)
{
radListView_CharList.BeginUpdate();
foreach (var item in radListView_CharList.Items.ToArray())
{
if (item.Value == character)
radListView_CharList.Items.Remove(item);
}
radListView_CharList.EndUpdate();
}
private void UpdateCharListViewItem(ListViewDataItem listItem, Character character)
@@ -93,32 +117,30 @@ public partial class CharacterListControl : UserControl
private void NewChar()
{
if (mainApi.Manager?.Characters.AddCharacter() is Character newChar)
AddCharToList(newChar);
if (mainApi.Manager?.Characters.CreateCharacter(CharListControlLangRes.UnnamedChar) is Character newChar)
AddCharToList(newChar, true);
}
private void TryDelChar()
private void DeleteChar()
{
var selChar = GetSelectedChar();
if (selChar != null)
{
if (RadMessageBox.Show(string.Format(CharListControlLangRes.MsgBox_ConfirmDeletion_Text, selChar.Name), CharListControlLangRes.MsgBox_ConfirmDeletion_Title, MessageBoxButtons.YesNo, RadMessageIcon.Exclamation) == DialogResult.Yes)
if (RadMessageBox.Show(string.Format(GeneralLangRes.MsgBox_ConfirmDelete_TextGeneral, string.Format(CharListControlLangRes.MsgBox_ConfirmDelete_TextChar, selChar.Name)), string.Format(GeneralLangRes.MsgBox_ConfirmDelete_TitleGeneral, CharListControlLangRes.MsgBox_ConfirmDelete_TitleChar), MessageBoxButtons.YesNo, RadMessageIcon.Exclamation) == DialogResult.Yes)
{
mainApi.Manager?.Characters.DeleteCharacter(selChar);
RemoveCharFromList(selChar);
}
}
}
else
RadMessageBox.Show(GeneralLangRes.MsgBox_NothingSelected, GeneralLangRes.MsgBox_Error, MessageBoxButtons.OK, RadMessageIcon.Error);
}
private void TryOpenChar(Character? character)
{
if (character != null)
OpenCharTab(character);
}
private void OpenCharTab(Character character)
{
mainApi.OpenTab(new TabCharView(mainApi, character), string.IsNullOrWhiteSpace(character.Name) ? CharListControlLangRes.Tab_UnnamedChar : character.Name);
mainApi.OpenTab(new TabCharView(mainApi, character), string.IsNullOrWhiteSpace(character.Name) ? CharListControlLangRes.UnnamedChar : character.Name);
}
// E V E N T S
@@ -130,11 +152,16 @@ public partial class CharacterListControl : UserControl
private void RadMenuItem_DeleteChar_Click(object sender, System.EventArgs e)
{
TryDelChar();
DeleteChar();
}
private void RadMenuItem_OpenChar_Click(object sender, System.EventArgs e)
{
TryOpenChar(GetSelectedChar());
}
private void RadTextBoxControl_SearchBox_TextChanged(object sender, System.EventArgs e)
{
}
}