aboutsummaryrefslogtreecommitdiff
path: root/Histacom2/OS/Win98/Win98Apps/AddressBook/WinClassicAddressBook.cs
diff options
context:
space:
mode:
authorlempamo <[email protected]>2017-11-05 09:25:55 -0500
committerGitHub <[email protected]>2017-11-05 09:25:55 -0500
commitf0e2d14a959db1e5d35c4dc5f77ed3523c93200a (patch)
tree7ae4244e5f5c3dc38f4b228f15efe4ea5be0fe3a /Histacom2/OS/Win98/Win98Apps/AddressBook/WinClassicAddressBook.cs
parent458cc4ee0dbc67f547ea851b5a67a88af119a4c0 (diff)
parent55bc23bd3797debcfc461ef23df344d16212f235 (diff)
downloadhistacom2-f0e2d14a959db1e5d35c4dc5f77ed3523c93200a.tar.gz
histacom2-f0e2d14a959db1e5d35c4dc5f77ed3523c93200a.tar.bz2
histacom2-f0e2d14a959db1e5d35c4dc5f77ed3523c93200a.zip
Merge pull request #180 from Alex-TIMEHACK/master
ClassicTextBox and ClassicDropDown
Diffstat (limited to 'Histacom2/OS/Win98/Win98Apps/AddressBook/WinClassicAddressBook.cs')
-rw-r--r--Histacom2/OS/Win98/Win98Apps/AddressBook/WinClassicAddressBook.cs197
1 files changed, 169 insertions, 28 deletions
diff --git a/Histacom2/OS/Win98/Win98Apps/AddressBook/WinClassicAddressBook.cs b/Histacom2/OS/Win98/Win98Apps/AddressBook/WinClassicAddressBook.cs
index ccd22f0..fd2bf0f 100644
--- a/Histacom2/OS/Win98/Win98Apps/AddressBook/WinClassicAddressBook.cs
+++ b/Histacom2/OS/Win98/Win98Apps/AddressBook/WinClassicAddressBook.cs
@@ -9,6 +9,9 @@ using System.Threading.Tasks;
using System.Windows.Forms;
using Histacom2.Engine;
using Histacom2.Engine.Template;
+using System.IO;
+using static Histacom2.Engine.SaveSystem;
+using static Histacom2.Engine.FileDialogBoxManager;
namespace Histacom2.OS.Win95.Win95Apps
{
@@ -42,14 +45,30 @@ namespace Histacom2.OS.Win95.Win95Apps
{
new AddressBookContactList()
{
- AttachedNode = treeView1.Nodes[0].Text,
+ NodePath = treeView1.Nodes[0].Text
}
};
+
+ if (File.Exists(Path.Combine(ProfileWindowsDirectory, "Application Data", "Microsoft", "Address Book", $"{ProfileName}.wab")))
+ LoadData();
+ else
+ SaveData();
+
+
}
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
- UpdateContactListFromNodeName(treeView1.SelectedNode.Text);
+ previousParent = treeView1.SelectedNode.Parent;
+ UpdateContactListFromNodeName(treeView1.SelectedNode);
+
+ // Remove the focus from contactsView
+
+ if (contactsView.SelectedItems.Count != 0)
+ contactsView.SelectedItems[0].Selected = false;
+
+ if (contactsView.FocusedItem != null)
+ contactsView.FocusedItem.Focused = false;
}
//AddressBookContactList GetAddressBookContactListFromNode(string NodeText)
@@ -71,28 +90,20 @@ namespace Histacom2.OS.Win95.Win95Apps
// return toReturn;
//}
- public void UpdateContactListFromNodeName(string NodeName)
+ public void UpdateContactListFromNodeName(TreeNode Node)
{
+ previousParent = Node.Parent;
contactsView.Items.Clear();
try
{
foreach (AddressBookContactList ContactList in AddressBookObjects)
{
- if (ContactList.AttachedNode == NodeName)
+ if (ContactList.NodePath == FindNodePath(Node))
{
foreach (AddressBookContact contact in ContactList.Contacts)
{
- if (contact != null)
- {
- if (contact.FirstName != null)
- {
- contactsView.Items.Add(contact.FirstName + " " + contact.MiddleName + " " + contact.LastName);
- }
- }
- else
- {
- MessageBox.Show("Null contact!");
- }
+ if (contact.FirstName != null)
+ contactsView.Items.Add(contact.FirstName + " " + contact.MiddleName + " " + contact.LastName);
}
}
}
@@ -106,15 +117,29 @@ namespace Histacom2.OS.Win95.Win95Apps
{
if (OldTreeNode != null)
{
- OldTreeNode.Nodes.Add(NewNodeName);
+ TreeNode nde = OldTreeNode.Nodes.Add(NewNodeName);
AddressBookObjects.Add(new AddressBookContactList
{
- AttachedNode = NewNodeName,
+ NodePath = FindNodePath(nde)
});
}
}
+ TreeNode previousParent;
+ public string FindNodePath(TreeNode nde)
+ {
+ if (nde != null)
+ {
+ string ret = nde.Text;
+ previousParent = nde.Parent;
+ while (previousParent != null)
+ ret = $"{FindNodePath(nde.Parent)}\\{ret}";
+ return ret;
+ }
+ else return "";
+ }
+
private void newFolderToolStripMenuItem_Click(object sender, EventArgs e)
{
NewFolder();
@@ -154,7 +179,7 @@ namespace Histacom2.OS.Win95.Win95Apps
{
foreach (AddressBookContactList ContactList in AddressBookObjects)
{
- if (ContactList.AttachedNode == treeView1.SelectedNode.Text)
+ if (ContactList.NodePath == FindNodePath(treeView1.SelectedNode))
{
ContactList.Contacts.Add(Program.AddressBookSelectedContact);
contactsView.Items.Add(Program.AddressBookSelectedContact.FirstName + " " + Program.AddressBookSelectedContact.MiddleName + " " + Program.AddressBookSelectedContact.LastName);
@@ -178,13 +203,20 @@ namespace Histacom2.OS.Win95.Win95Apps
{
foreach (AddressBookContactList ContactList in AddressBookObjects)
{
- if (ContactList.AttachedNode == treeView1.SelectedNode.Text)
+ if (ContactList.NodePath == FindNodePath(treeView1.SelectedNode))
{
foreach (AddressBookContact Contact in ContactList.Contacts)
{
- if ((Contact.FirstName + " " + Contact.MiddleName + " " + Contact.LastName) == contactsView.FocusedItem.Text)
+ if (contactsView.FocusedItem == null)
+ { // Most likely they are trying to view a whole folder!
+ wm.StartInfobox95("Properties of a folder", "You cannot view the properties of a contact folder.", InfoboxType.Warning, InfoboxButtons.OK);
+ }
+ else
{
- abnc.toSet = Contact;
+ if ((Contact.FirstName + " " + Contact.MiddleName + " " + Contact.LastName) == contactsView.FocusedItem.Text)
+ {
+ abnc.toSet = Contact;
+ }
}
}
}
@@ -197,7 +229,7 @@ namespace Histacom2.OS.Win95.Win95Apps
{
foreach (AddressBookContactList ContactList in AddressBookObjects)
{
- if (ContactList.AttachedNode == treeView1.SelectedNode.Text)
+ if (ContactList.NodePath == FindNodePath(treeView1.SelectedNode))
{
foreach (AddressBookContact Contact in ContactList.Contacts)
{
@@ -228,22 +260,38 @@ namespace Histacom2.OS.Win95.Win95Apps
void DeleteContact()
{
- if (treeView1.SelectedNode != null)
+ try
{
foreach (AddressBookContactList ContactList in AddressBookObjects)
{
- if (ContactList.AttachedNode == treeView1.SelectedNode.Text)
+ if (ContactList.NodePath == FindNodePath(treeView1.SelectedNode))
{
foreach (AddressBookContact Contact in ContactList.Contacts)
{
- if ((Contact.FirstName + " " + Contact.MiddleName + " " + Contact.LastName) == contactsView.FocusedItem.Text)
+ if (contactsView.FocusedItem == null)
+ { // Most likely they are trying to delete a whole folder!
+ if (treeView1.SelectedNode.Text != "Shared Contacts")
+ if (treeView1.SelectedNode != null)
+ {
+ AddressBookObjects.Remove(ContactList);
+ treeView1.Nodes.Remove(treeView1.SelectedNode);
+ previousParent = null;
+ UpdateContactListFromNodeName(treeView1.Nodes[0]);
+ }
+ }
+ else
{
- ContactList.Contacts.Remove(Contact);
+ if ((Contact.FirstName + " " + Contact.MiddleName + " " + Contact.LastName) == contactsView.FocusedItem.Text)
+ {
+ ContactList.Contacts.Remove(Contact);
+ previousParent = treeView1.SelectedNode.Parent;
+ UpdateContactListFromNodeName(treeView1.SelectedNode);
+ }
}
}
}
}
- }
+ } catch { }
}
private void toolDelete_Click(object sender, EventArgs e)
@@ -275,6 +323,99 @@ namespace Histacom2.OS.Win95.Win95Apps
{
((Form)this.TopLevelControl).Close();
}
+
+ private void toolNew_Click(object sender, EventArgs e)
+ {
+ newContext.Show(MousePosition);
+ }
+
+ private void aboutAddressBookToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+
+ }
+
+ private void WinClassicAddressBook_Load(object sender, EventArgs e)
+ {
+ ((Form)this.TopLevelControl).FormClosed += (sender2, e2) =>
+ {
+ SaveData();
+ };
+ }
+
+ public void SaveData()
+ {
+ string toSave = Newtonsoft.Json.JsonConvert.SerializeObject(AddressBookObjects, Newtonsoft.Json.Formatting.Indented);
+ CreateWindowsFile(Path.Combine(ProfileWindowsDirectory, "Application Data", "Microsoft", "Address Book"), $"{ProfileName}.wab", toSave, 21, toSave.Length);
+ }
+
+ public void SaveDataAs()
+ {
+ try
+ {
+ string toSave = Newtonsoft.Json.JsonConvert.SerializeObject(AddressBookObjects, Newtonsoft.Json.Formatting.Indented);
+
+ ActivateSaveFileDialog(".wab");
+ string selectedPath = Program.OpenFileExplorerAsDialogAndReturnGivenPath();
+ DeactivateFileDialog();
+
+ if (selectedPath != "")
+ CreateWindowsFile(new FileInfo(selectedPath).Directory.FullName, selectedPath.Split('\\').Last(), toSave, 21, toSave.Length);
+ } catch { }
+ }
+
+ public void LoadData()
+ {
+ AddressBookObjects = Newtonsoft.Json.JsonConvert.DeserializeObject<List<AddressBookContactList>>(File.ReadAllText(Path.Combine(ProfileWindowsDirectory, "Application Data", "Microsoft", "Address Book", $"{ProfileName}.wab")));
+
+ foreach (AddressBookContactList lst in AddressBookObjects)
+ UpdateTreeView(lst);
+ }
+
+ public void LoadDataAs()
+ {
+ ActivateOpenFileDialog(".wab");
+ string selectedPath = Program.OpenFileExplorerAsDialogAndReturnGivenPath();
+ DeactivateFileDialog();
+
+ if (selectedPath != "")
+ AddressBookObjects = Newtonsoft.Json.JsonConvert.DeserializeObject<List<AddressBookContactList>>(File.ReadAllText(selectedPath));
+
+ foreach (AddressBookContactList lst in AddressBookObjects)
+ UpdateTreeView(lst);
+ }
+
+ TreeNode UpdatePrevParent;
+ public void UpdateTreeView(AddressBookContactList lst, int count = 0)
+ {
+ try
+ {
+ string[] parts = new string[] { "Shared Contacts" };
+ if (lst.NodePath != null)
+ parts = lst.NodePath.Split('\\');
+
+ if (count == 0) UpdatePrevParent = treeView1.Nodes[0];
+ if (lst.NodePath != FindNodePath(treeView1.Nodes[0]))
+ {
+ if (UpdatePrevParent.Nodes.ContainsKey(parts[count + 1]))
+ UpdatePrevParent.Nodes.RemoveByKey(parts[count + 1]);
+
+ TreeNode newNde = UpdatePrevParent.Nodes.Add(parts[count + 1], parts[count + 1]);
+ UpdatePrevParent = newNde;
+ if (count != parts.Length - 2) UpdateTreeView(lst, ++count);
+ }
+
+ } catch { }
+ }
+
+ private void importToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ LoadDataAs();
+ }
+
+ private void exportToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ SaveDataAs();
+ }
}
public class AddressBookContact
@@ -287,7 +428,7 @@ namespace Histacom2.OS.Win95.Win95Apps
public class AddressBookContactList
{
- public string AttachedNode;
+ public string NodePath;
public List<AddressBookContact> Contacts = new List<AddressBookContact>();
}
}