Improved OrganizeFavorites Form, and Organized the code in the explorer form

I added a cancel button to the Organize favorites form. If the user clicks this then his edited favorites will not be saved. Fixed a bug where you couldnt delete the root node under the "favorites" node. Organized all code related to favorites in the ExplorerForm
This commit is contained in:
FiftyShadesOfBlue 2018-03-16 01:36:48 -04:00
parent 4429a5e9ab
commit ba199212a6
3 changed files with 89 additions and 88 deletions

View File

@ -2,6 +2,7 @@
using CodeWalker.GameFiles;
using CodeWalker.Properties;
using CodeWalker.World;
using CodeWalker.Explorer;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@ -16,7 +17,6 @@ using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;
using WeifenLuo.WinFormsUI.Docking;
using CodeWalker.Explorer;
namespace CodeWalker
{
@ -47,8 +47,6 @@ namespace CodeWalker
private bool EditMode = false;
private List<string> FavoritesList = new List<string>();
public ThemeBase Theme { get; private set; }
@ -184,87 +182,6 @@ namespace CodeWalker
});
}
private void AddFavoriteItem(string text)
{
ToolStripMenuItem item = new ToolStripMenuItem();
item.Text = text;
item.Click += new EventHandler(FavoritesItem_Click);
favoritesToolStripMenuItem.DropDownItems.Insert(favoritesToolStripMenuItem.DropDownItems.Count, item);
}
private void FavoritesItem_Click(object sender, EventArgs e)
{
ToolStripMenuItem FavItem = sender as ToolStripMenuItem;
Navigate(FavItem.Text);
}
public void LoadFavorites()
{
favoritesToolStripMenuItem.DropDownItems.Clear();
ToolStripMenuItem AddToFavItem = new ToolStripMenuItem();
AddToFavItem.Text = "Add To Favorites";
AddToFavItem.Click += new EventHandler(addToFavToolStripMenuItem_Click);
favoritesToolStripMenuItem.DropDownItems.Add(AddToFavItem);
ToolStripMenuItem OrganizeFavItem = new ToolStripMenuItem();
OrganizeFavItem.Text = "Organize Favorites";
OrganizeFavItem.Click += new EventHandler(organizeFavoritesMenuItem_Click);
favoritesToolStripMenuItem.DropDownItems.Add(OrganizeFavItem);
favoritesToolStripMenuItem.DropDownItems.Add("-");
XmlDocument xDoc = new XmlDocument();
xDoc.Load(@"C:\Users\Skyler\Documents\GitHub\CodeWalker\Resources\Favorites.xml");
XmlNodeList FavoriteNodes = xDoc.DocumentElement.SelectNodes("Favorite");
foreach(XmlNode FavNode in FavoriteNodes)
{
AddFavoriteItem(FavNode.InnerText);
}
}
private void addToFavToolStripMenuItem_Click(object sender, EventArgs e)
{
if(LocationTextBox.Text != "")
{
XmlDocument xDoc = new XmlDocument();
xDoc.Load(@"C:\Users\Skyler\Documents\GitHub\CodeWalker\Resources\Favorites.xml");
XmlNode FavToAdd = xDoc.CreateElement("Favorite");
FavToAdd.InnerText = LocationTextBox.Text;
xDoc.DocumentElement.AppendChild(FavToAdd);
xDoc.Save(@"C:\Users\Skyler\Documents\GitHub\CodeWalker\Resources\Favorites.xml");
LoadFavorites();
}
else
{
MessageBox.Show("Must be out of root folder to add a favorite.", "Error");
}
}
private void organizeFavoritesMenuItem_Click(object sender, EventArgs e)
{
Form f = new OrganizeFavorites(this);
FormTheme.SetTheme(f, Theme);
f.Show();
}
private void InitFileCache()
{
Task.Run(() =>
@ -3375,6 +3292,72 @@ namespace CodeWalker
}
}
private void AddFavoriteItem(string text)
{
ToolStripMenuItem item = new ToolStripMenuItem();
item.Text = text;
item.Click += new EventHandler(FavoritesItem_Click);
favoritesToolStripMenuItem.DropDownItems.Insert(favoritesToolStripMenuItem.DropDownItems.Count, item);
}
private void FavoritesItem_Click(object sender, EventArgs e)
{
ToolStripMenuItem FavItem = sender as ToolStripMenuItem;
Navigate(FavItem.Text);
}
public void LoadFavorites()
{
favoritesToolStripMenuItem.DropDownItems.Clear();
ToolStripMenuItem AddToFavItem = new ToolStripMenuItem();
AddToFavItem.Text = "Add To Favorites";
AddToFavItem.Click += new EventHandler(addToFavToolStripMenuItem_Click);
favoritesToolStripMenuItem.DropDownItems.Add(AddToFavItem);
ToolStripMenuItem OrganizeFavItem = new ToolStripMenuItem();
OrganizeFavItem.Text = "Organize Favorites";
OrganizeFavItem.Click += new EventHandler(organizeFavoritesMenuItem_Click);
favoritesToolStripMenuItem.DropDownItems.Add(OrganizeFavItem);
favoritesToolStripMenuItem.DropDownItems.Add("-");
XmlDocument xDoc = new XmlDocument();
xDoc.Load(@"C:\Users\Skyler\Documents\GitHub\CodeWalker\Resources\Favorites.xml");
XmlNodeList FavoriteNodes = xDoc.DocumentElement.SelectNodes("Favorite");
foreach (XmlNode FavNode in FavoriteNodes)
{
AddFavoriteItem(FavNode.InnerText);
}
}
private void addToFavToolStripMenuItem_Click(object sender, EventArgs e)
{
if (LocationTextBox.Text != "")
{
XmlDocument xDoc = new XmlDocument();
xDoc.Load(@"C:\Users\Skyler\Documents\GitHub\CodeWalker\Resources\Favorites.xml");
XmlNode FavToAdd = xDoc.CreateElement("Favorite");
FavToAdd.InnerText = LocationTextBox.Text;
xDoc.DocumentElement.AppendChild(FavToAdd);
xDoc.Save(@"C:\Users\Skyler\Documents\GitHub\CodeWalker\Resources\Favorites.xml");
LoadFavorites();
}
else
{
MessageBox.Show("Must be out of root folder to add a favorite.", "Error");
}
}
private void organizeFavoritesMenuItem_Click(object sender, EventArgs e)
{
Form f = new OrganizeFavorites(this);
FormTheme.SetTheme(f, Theme);
f.Show();
}
private void ListContextViewMenu_Click(object sender, EventArgs e)
{
ViewSelected();

View File

@ -34,12 +34,13 @@
this.RemoveFavoriteButton = new System.Windows.Forms.Button();
this.ClearAllFavoritesButton = new System.Windows.Forms.Button();
this.FavoritesTreeView = new System.Windows.Forms.TreeView();
this.CancelButton = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// SaveButton
//
this.SaveButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.SaveButton.Location = new System.Drawing.Point(417, 439);
this.SaveButton.Location = new System.Drawing.Point(324, 439);
this.SaveButton.Name = "SaveButton";
this.SaveButton.Size = new System.Drawing.Size(75, 23);
this.SaveButton.TabIndex = 1;
@ -50,7 +51,7 @@
// RemoveFavoriteButton
//
this.RemoveFavoriteButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.RemoveFavoriteButton.Location = new System.Drawing.Point(322, 439);
this.RemoveFavoriteButton.Location = new System.Drawing.Point(226, 439);
this.RemoveFavoriteButton.Name = "RemoveFavoriteButton";
this.RemoveFavoriteButton.Size = new System.Drawing.Size(75, 23);
this.RemoveFavoriteButton.TabIndex = 2;
@ -61,7 +62,7 @@
// ClearAllFavoritesButton
//
this.ClearAllFavoritesButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.ClearAllFavoritesButton.Location = new System.Drawing.Point(224, 439);
this.ClearAllFavoritesButton.Location = new System.Drawing.Point(130, 439);
this.ClearAllFavoritesButton.Name = "ClearAllFavoritesButton";
this.ClearAllFavoritesButton.Size = new System.Drawing.Size(75, 23);
this.ClearAllFavoritesButton.TabIndex = 3;
@ -84,11 +85,22 @@
this.FavoritesTreeView.Size = new System.Drawing.Size(480, 406);
this.FavoritesTreeView.TabIndex = 4;
//
// CancelButton
//
this.CancelButton.Location = new System.Drawing.Point(419, 439);
this.CancelButton.Name = "CancelButton";
this.CancelButton.Size = new System.Drawing.Size(75, 23);
this.CancelButton.TabIndex = 5;
this.CancelButton.Text = "Cancel";
this.CancelButton.UseVisualStyleBackColor = true;
this.CancelButton.Click += new System.EventHandler(this.CancelButton_Click);
//
// OrganizeFavorites
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(504, 474);
this.Controls.Add(this.CancelButton);
this.Controls.Add(this.FavoritesTreeView);
this.Controls.Add(this.ClearAllFavoritesButton);
this.Controls.Add(this.RemoveFavoriteButton);
@ -108,5 +120,6 @@
private System.Windows.Forms.Button RemoveFavoriteButton;
private System.Windows.Forms.Button ClearAllFavoritesButton;
private System.Windows.Forms.TreeView FavoritesTreeView;
private System.Windows.Forms.Button CancelButton;
}
}

View File

@ -47,7 +47,7 @@ namespace CodeWalker.Explorer
private void RemoveFavoriteButton_Click(object sender, EventArgs e)
{
if (FavoritesTreeView.SelectedNode.Index == 0) return;
if (FavoritesTreeView.SelectedNode == FavoritesTreeView.Nodes[0]) return;
string FavoriteToDelete = FavoritesTreeView.SelectedNode.Text;
FavoritesTreeView.SelectedNode.Remove();
@ -66,5 +66,10 @@ namespace CodeWalker.Explorer
ExploreForm.LoadFavorites();
Close();
}
private void CancelButton_Click(object sender, EventArgs e)
{
Close();
}
}
}