diff options
| author | lempamo <[email protected]> | 2017-11-05 09:25:55 -0500 |
|---|---|---|
| committer | GitHub <[email protected]> | 2017-11-05 09:25:55 -0500 |
| commit | f0e2d14a959db1e5d35c4dc5f77ed3523c93200a (patch) | |
| tree | 7ae4244e5f5c3dc38f4b228f15efe4ea5be0fe3a /Histacom2/OS/Win98/Win98Apps/AddressBook | |
| parent | 458cc4ee0dbc67f547ea851b5a67a88af119a4c0 (diff) | |
| parent | 55bc23bd3797debcfc461ef23df344d16212f235 (diff) | |
| download | histacom2-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')
3 files changed, 189 insertions, 45 deletions
diff --git a/Histacom2/OS/Win98/Win98Apps/AddressBook/FRMWinClassicAddressBookNewContact.cs b/Histacom2/OS/Win98/Win98Apps/AddressBook/FRMWinClassicAddressBookNewContact.cs index 9facd7b..45384fa 100644 --- a/Histacom2/OS/Win98/Win98Apps/AddressBook/FRMWinClassicAddressBookNewContact.cs +++ b/Histacom2/OS/Win98/Win98Apps/AddressBook/FRMWinClassicAddressBookNewContact.cs @@ -7,12 +7,13 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; - +using Histacom2.Engine; namespace Histacom2.OS.Win95.Win95Apps { public partial class FRMWinClassicAddressBookNewContact : UserControl { + WindowManager wm = new WindowManager(); public AddressBookContact toSet = new AddressBookContact(); public FRMWinClassicAddressBookNewContact() { @@ -37,7 +38,7 @@ namespace Histacom2.OS.Win95.Win95Apps Program.AddressBookSelectedContact = toSet; ((Form)this.TopLevelControl).Close(); } else { - MessageBox.Show("Please fill out the First, Middle and Last name."); + wm.StartInfobox95("Address Book", "Please fill out the First, Middle and Last name.", Engine.Template.InfoboxType.Info, Engine.Template.InfoboxButtons.OK); } } @@ -62,9 +63,6 @@ namespace Histacom2.OS.Win95.Win95Apps emails.Items.Add(email); } } - } else - { - MessageBox.Show("NULL CONTACT!"); } } } diff --git a/Histacom2/OS/Win98/Win98Apps/AddressBook/WinClassicAddressBook.Designer.cs b/Histacom2/OS/Win98/Win98Apps/AddressBook/WinClassicAddressBook.Designer.cs index cbe2600..f76bb99 100644 --- a/Histacom2/OS/Win98/Win98Apps/AddressBook/WinClassicAddressBook.Designer.cs +++ b/Histacom2/OS/Win98/Win98Apps/AddressBook/WinClassicAddressBook.Designer.cs @@ -105,67 +105,69 @@ // newContactToolStripMenuItem // this.newContactToolStripMenuItem.Name = "newContactToolStripMenuItem"; - this.newContactToolStripMenuItem.Size = new System.Drawing.Size(150, 22); + this.newContactToolStripMenuItem.Size = new System.Drawing.Size(152, 22); this.newContactToolStripMenuItem.Text = "New contact..."; this.newContactToolStripMenuItem.Click += new System.EventHandler(this.newContactToolStripMenuItem_Click); // // newFolderToolStripMenuItem // this.newFolderToolStripMenuItem.Name = "newFolderToolStripMenuItem"; - this.newFolderToolStripMenuItem.Size = new System.Drawing.Size(150, 22); + this.newFolderToolStripMenuItem.Size = new System.Drawing.Size(152, 22); this.newFolderToolStripMenuItem.Text = "New folder..."; this.newFolderToolStripMenuItem.Click += new System.EventHandler(this.newFolderToolStripMenuItem_Click); // // toolStripSeparator1 // this.toolStripSeparator1.Name = "toolStripSeparator1"; - this.toolStripSeparator1.Size = new System.Drawing.Size(147, 6); + this.toolStripSeparator1.Size = new System.Drawing.Size(149, 6); // // propertiesToolStripMenuItem // this.propertiesToolStripMenuItem.Name = "propertiesToolStripMenuItem"; - this.propertiesToolStripMenuItem.Size = new System.Drawing.Size(150, 22); + this.propertiesToolStripMenuItem.Size = new System.Drawing.Size(152, 22); this.propertiesToolStripMenuItem.Text = "Properties"; this.propertiesToolStripMenuItem.Click += new System.EventHandler(this.propertiesToolStripMenuItem_Click); // // deleteToolStripMenuItem // this.deleteToolStripMenuItem.Name = "deleteToolStripMenuItem"; - this.deleteToolStripMenuItem.Size = new System.Drawing.Size(150, 22); + this.deleteToolStripMenuItem.Size = new System.Drawing.Size(152, 22); this.deleteToolStripMenuItem.Text = "Delete"; this.deleteToolStripMenuItem.Click += new System.EventHandler(this.deleteToolStripMenuItem_Click); // // toolStripSeparator2 // this.toolStripSeparator2.Name = "toolStripSeparator2"; - this.toolStripSeparator2.Size = new System.Drawing.Size(147, 6); + this.toolStripSeparator2.Size = new System.Drawing.Size(149, 6); // // importToolStripMenuItem // this.importToolStripMenuItem.Name = "importToolStripMenuItem"; - this.importToolStripMenuItem.Size = new System.Drawing.Size(150, 22); + this.importToolStripMenuItem.Size = new System.Drawing.Size(152, 22); this.importToolStripMenuItem.Text = "Import..."; + this.importToolStripMenuItem.Click += new System.EventHandler(this.importToolStripMenuItem_Click); // // exportToolStripMenuItem // this.exportToolStripMenuItem.Name = "exportToolStripMenuItem"; - this.exportToolStripMenuItem.Size = new System.Drawing.Size(150, 22); + this.exportToolStripMenuItem.Size = new System.Drawing.Size(152, 22); this.exportToolStripMenuItem.Text = "Export..."; + this.exportToolStripMenuItem.Click += new System.EventHandler(this.exportToolStripMenuItem_Click); // // toolStripSeparator3 // this.toolStripSeparator3.Name = "toolStripSeparator3"; - this.toolStripSeparator3.Size = new System.Drawing.Size(147, 6); + this.toolStripSeparator3.Size = new System.Drawing.Size(149, 6); // // toolStripSeparator4 // this.toolStripSeparator4.Name = "toolStripSeparator4"; - this.toolStripSeparator4.Size = new System.Drawing.Size(147, 6); + this.toolStripSeparator4.Size = new System.Drawing.Size(149, 6); // // exitToolStripMenuItem // this.exitToolStripMenuItem.Name = "exitToolStripMenuItem"; - this.exitToolStripMenuItem.Size = new System.Drawing.Size(150, 22); + this.exitToolStripMenuItem.Size = new System.Drawing.Size(152, 22); this.exitToolStripMenuItem.Text = "Exit"; this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click); // @@ -247,6 +249,7 @@ this.aboutAddressBookToolStripMenuItem.Name = "aboutAddressBookToolStripMenuItem"; this.aboutAddressBookToolStripMenuItem.Size = new System.Drawing.Size(182, 22); this.aboutAddressBookToolStripMenuItem.Text = "About Address Book"; + this.aboutAddressBookToolStripMenuItem.Click += new System.EventHandler(this.aboutAddressBookToolStripMenuItem_Click); // // contactsView // @@ -304,6 +307,7 @@ this.toolNew.Size = new System.Drawing.Size(43, 39); this.toolNew.TabIndex = 0; this.toolNew.TabStop = false; + this.toolNew.Click += new System.EventHandler(this.toolNew_Click); // // toolDelete // @@ -348,6 +352,7 @@ this.Controls.Add(this.topmenu); this.Name = "WinClassicAddressBook"; this.Size = new System.Drawing.Size(666, 425); + this.Load += new System.EventHandler(this.WinClassicAddressBook_Load); this.topmenu.ResumeLayout(false); this.topmenu.PerformLayout(); this.toolbar.ResumeLayout(false); @@ -378,7 +383,7 @@ private System.Windows.Forms.ToolStripSeparator toolStripSeparator4; private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem; private System.Windows.Forms.ListView contactsView; - private System.Windows.Forms.TreeView treeView1; + public System.Windows.Forms.TreeView treeView1; private System.Windows.Forms.ToolStripMenuItem toolbarToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem foldersToolStripMenuItem; private System.Windows.Forms.Panel toolbar; 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>(); } } |
