diff --git a/MainForm.cs b/MainForm.cs index 8541d42..a8181aa 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -23,12 +23,33 @@ namespace bzit.bomg New } + public enum LoadFileType + { + None = 0, + Jsnx, + Ryz + } + + protected BackgroundWorker loadFileThread = null; + protected LoadFileType loadFileType = LoadFileType.None; + protected AppMode appMode = AppMode.Clear; protected string sessionFilename = null; + protected string sessionPassword = null; + protected bool usePassword = false; public MainForm() { InitializeComponent(); + + if (loadFileThread == null) + { + loadFileThread = new BackgroundWorker(); + loadFileThread.WorkerReportsProgress = loadFileThread.WorkerSupportsCancellation = true; + } + + loadFileThread.DoWork += loadFileThread_DoWork; + loadFileThread.RunWorkerCompleted += loadFileThread_RunWorkerCompleted; } protected override void OnLoad(EventArgs e) @@ -47,7 +68,8 @@ namespace bzit.bomg } this.ApplicationMode = AppMode.Clear; - sessionFilename = null; + sessionFilename = sessionPassword = null; + usePassword = false; } protected override void OnShown(EventArgs e) @@ -102,6 +124,12 @@ namespace bzit.bomg protected override void OnFormClosing(FormClosingEventArgs e) { + if (this.IsBusy) + { + e.Cancel = true; + return; + } + if (this.ApplicationMode == AppMode.Clear) { // do later @@ -137,7 +165,16 @@ namespace bzit.bomg DialogResult response = MessageBox.Show("Save changes to open bookmarks", "Save?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (response == DialogResult.Yes) { - saveBookmarkFile_ForJSNX(sessionFilename); + if (usePassword) + { + if (string.IsNullOrWhiteSpace(sessionPassword)) + { + TextBoxForm passwordForm = new TextBoxForm("Password", "Password", true); + sessionPassword = passwordForm.ShowDialog(); + } + } + + saveBookmarkFile_ForJSNX(sessionFilename, sessionPassword ?? string.Empty); } else if (response == DialogResult.No) { @@ -160,12 +197,12 @@ namespace bzit.bomg treeView1.Clear(); this.ApplicationMode = AppMode.Clear; - sessionFilename = null; + sessionFilename = sessionPassword = null; Application.Exit(); } - public AppMode ApplicationMode + protected AppMode ApplicationMode { get => appMode; set @@ -206,10 +243,27 @@ namespace bzit.bomg } } - #region Toolbar #1 + protected bool IsBusy + { + get + { + return loadFileThread.IsBusy; + } + set + { + treeView1.Enabled = !value; + } + } + + #region toolbar private void fileNewMenuItem_Click(object sender, EventArgs e) { + if (this.IsBusy) + { + return; + } + if (this.ApplicationMode == AppMode.Clear) { // do later @@ -243,7 +297,16 @@ namespace bzit.bomg DialogResult response = MessageBox.Show("Save changes to open bookmarks", "Save?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (response == DialogResult.Yes) { - saveBookmarkFile_ForJSNX(sessionFilename); + if (usePassword) + { + if (string.IsNullOrWhiteSpace(sessionPassword)) + { + TextBoxForm passwordForm = new TextBoxForm("Password", "Password", true); + sessionPassword = passwordForm.ShowDialog(); + } + } + + saveBookmarkFile_ForJSNX(sessionFilename, sessionPassword ?? string.Empty); } else if (response == DialogResult.No) { @@ -271,11 +334,16 @@ namespace bzit.bomg treeView1.Clear(rv); this.ApplicationMode = AppMode.New; - sessionFilename = null; + sessionFilename = sessionPassword = null; } private void fileOpenMenuItem_Click(object sender, EventArgs e) { + if (this.IsBusy) + { + return; + } + if (this.ApplicationMode == AppMode.Clear) { // do later @@ -309,7 +377,16 @@ namespace bzit.bomg DialogResult response = MessageBox.Show("Save changes to open bookmarks", "Save?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (response == DialogResult.Yes) { - saveBookmarkFile_ForJSNX(sessionFilename); + if (usePassword) + { + if (string.IsNullOrWhiteSpace(sessionPassword)) + { + TextBoxForm passwordForm = new TextBoxForm("Password", "Password", true); + sessionPassword = passwordForm.ShowDialog(); + } + } + + saveBookmarkFile_ForJSNX(sessionFilename, sessionPassword ?? string.Empty); } else if (response == DialogResult.No) { @@ -335,6 +412,11 @@ namespace bzit.bomg private void fileCloseMenuItem_Click(object sender, EventArgs e) { + if (this.IsBusy) + { + return; + } + if (this.ApplicationMode == AppMode.Clear) { // do later @@ -368,7 +450,16 @@ namespace bzit.bomg DialogResult response = MessageBox.Show("Save changes to open bookmarks", "Save?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (response == DialogResult.Yes) { - saveBookmarkFile_ForJSNX(sessionFilename); + if (usePassword) + { + if (string.IsNullOrWhiteSpace(sessionPassword)) + { + TextBoxForm passwordForm = new TextBoxForm("Password", "Password", true); + sessionPassword = passwordForm.ShowDialog(); + } + } + + saveBookmarkFile_ForJSNX(sessionFilename, sessionPassword ?? string.Empty); } else if (response == DialogResult.No) { @@ -388,11 +479,16 @@ namespace bzit.bomg treeView1.Clear(); this.ApplicationMode = AppMode.Clear; - sessionFilename = null; + sessionFilename = sessionPassword = null; } private void fileSaveMenuItem_Click(object sender, EventArgs e) { + if (this.IsBusy) + { + return; + } + if (this.ApplicationMode == AppMode.New) { DialogResult response = MessageBox.Show("Save bookmarks", "Save?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); @@ -415,12 +511,26 @@ namespace bzit.bomg } else if (this.ApplicationMode == AppMode.Open) { - saveBookmarkFile_ForJSNX(sessionFilename); + if (usePassword) + { + if (string.IsNullOrWhiteSpace(sessionPassword)) + { + TextBoxForm passwordForm = new TextBoxForm("Password", "Password", true); + sessionPassword = passwordForm.ShowDialog(); + } + } + + saveBookmarkFile_ForJSNX(sessionFilename, sessionPassword ?? string.Empty); } } private void fileSaveAsMenuItem_Click(object sender, EventArgs e) { + if (this.IsBusy) + { + return; + } + if (this.ApplicationMode == AppMode.Clear) { return; @@ -435,17 +545,32 @@ namespace bzit.bomg private void fileExitMenuItem_Click(object sender, EventArgs e) { + if (this.IsBusy) + { + return; + } + this.Close(); } private void editFindMenuItem_Click(object sender, EventArgs e) { + if (this.IsBusy) + { + return; + } + FindForm findForm = new FindForm(this); findForm.Show(); } private void viewExpandAllMenuItem_Click(object sender, EventArgs e) { + if (this.IsBusy) + { + return; + } + if (this.ApplicationMode == AppMode.Clear) { return; @@ -463,6 +588,11 @@ namespace bzit.bomg private void viewCollapseAllMenuItem_Click(object sender, EventArgs e) { + if (this.IsBusy) + { + return; + } + if (this.ApplicationMode == AppMode.Clear) { return; @@ -485,27 +615,13 @@ namespace bzit.bomg alwaysOnTopToolStripMenuItem1.Checked = this.TopMost; } - /** - * Tools -> Refresh Icons - */ - //private void toolStripMenuItem1_Click(object sender, EventArgs e) - //{ - // if (string.IsNullOrEmpty(sessionFilename)) - // { - // return; - // } - - // if (this.ApplicationMode == AppMode.Clear) - // { - // return; - // } - - // UpdateIconForm frm = new UpdateIconForm(this); - // frm.ShowDialog(); - //} - private void toolsOptionsMenuItem_Click(object sender, EventArgs e) { + if (this.IsBusy) + { + return; + } + //OptionsForm frm = new OptionsForm(this); //frm.ShowDialog(); } @@ -536,11 +652,6 @@ namespace bzit.bomg #endregion - - - - - protected void loadBookmarkFile(string filename, int filterIndex) { switch (filterIndex) @@ -562,8 +673,12 @@ namespace bzit.bomg if (RyzStudio.IO.SharpZipLib.TestZipEncrypted(filename, password)) { sessionFilename = filename; - //this.ApplicationMode = AppMode.Open; - loadBookmarkFile_ForJSNX(filename, password); + sessionPassword = password; + usePassword = true; + + loadFileType = LoadFileType.Jsnx; + + loadFileThread.RunWorkerAsync(); break; } } @@ -571,8 +686,12 @@ namespace bzit.bomg else { sessionFilename = filename; - //this.ApplicationMode = AppMode.Open; - loadBookmarkFile_ForJSNX(filename); + sessionPassword = null; + usePassword = false; + + loadFileType = LoadFileType.Jsnx; + + loadFileThread.RunWorkerAsync(); } break; @@ -592,20 +711,26 @@ namespace bzit.bomg if (RyzStudio.IO.SharpZipLib.TestZipEncrypted(filename, password)) { - loadBookmarkFile_ForRYZ(filename, password); + sessionFilename = filename; + sessionPassword = password; + usePassword = true; - sessionFilename = null; - this.ApplicationMode = AppMode.New; + loadFileType = LoadFileType.Ryz; + + loadFileThread.RunWorkerAsync(); break; } } } else { - loadBookmarkFile_ForRYZ(filename); + sessionFilename = filename; + sessionPassword = null; + usePassword = false; - sessionFilename = null; - this.ApplicationMode = AppMode.New; + loadFileType = LoadFileType.Ryz; + + loadFileThread.RunWorkerAsync(); } break; @@ -673,9 +798,27 @@ namespace bzit.bomg readStream.Dispose(); readStream = null; - treeView1.AddItem(rs); - treeView1.HasChanged = false; - this.ApplicationMode = AppMode.Open; + if (treeView1.InvokeRequired) + { + treeView1.Invoke(new MethodInvoker(() => { + treeView1.AddItem(rs); + })); + } + else + { + treeView1.AddItem(rs); + } + + if (this.InvokeRequired) + { + this.Invoke(new MethodInvoker(() => { + this.ApplicationMode = AppMode.Open; + })); + } + else + { + this.ApplicationMode = AppMode.Open; + } setAppTitle(Path.GetFileNameWithoutExtension(filename)); } @@ -805,13 +948,62 @@ namespace bzit.bomg readStream.Dispose(); readStream = null; - treeView1.AddItem(rs); - treeView1.HasChanged = false; - //this.ApplicationMode = AppMode.New; + if (treeView1.InvokeRequired) + { + treeView1.Invoke(new MethodInvoker(() => { + treeView1.AddItem(rs); + })); + } + else + { + treeView1.AddItem(rs); + } + + sessionFilename = sessionPassword = null; + usePassword = !string.IsNullOrWhiteSpace(password); + + if (this.InvokeRequired) + { + this.Invoke(new MethodInvoker(() => { + this.ApplicationMode = AppMode.New; + })); + } + else + { + this.ApplicationMode = AppMode.New; + } setAppTitle(Path.GetFileNameWithoutExtension(filename)); } + protected void openBookmark(TreeNode node) + { + if (treeView1.GetNodeType(node) != RyzStudio.Windows.Forms.BookmarkTreeView.NodeType.Page) + { + return; + } + + BookmarkItemViewModel viewModel = (BookmarkItemViewModel)node.Tag; + if (viewModel == null) + { + return; + } + + if (string.IsNullOrWhiteSpace(viewModel.SiteAddress)) + { + return; + } + + try + { + System.Diagnostics.Process.Start(viewModel.SiteAddress); + } + catch + { + // do nothing + } + } + protected bool saveAsBookmarkFile() { if (saveFileDialog.ShowDialog() == DialogResult.OK) @@ -824,6 +1016,7 @@ namespace bzit.bomg setAppTitle(Path.GetFileNameWithoutExtension(saveFileDialog.FileName)); sessionFilename = saveFileDialog.FileName; + usePassword = false; this.ApplicationMode = AppMode.Open; treeView1.HasChanged = false; break; @@ -836,6 +1029,8 @@ namespace bzit.bomg setAppTitle(Path.GetFileNameWithoutExtension(saveFileDialog.FileName)); sessionFilename = saveFileDialog.FileName; + sessionPassword = password; + usePassword = true; this.ApplicationMode = AppMode.Open; treeView1.HasChanged = false; break; @@ -895,7 +1090,16 @@ namespace bzit.bomg protected void setAppTitle(string title) { - this.Text = title + " - " + Properties.Resources.app_name; + if (this.InvokeRequired) + { + this.Invoke(new MethodInvoker(() => { + this.Text = title + " - " + Properties.Resources.app_name; + })); + } + else + { + this.Text = title + " - " + Properties.Resources.app_name; + } } protected void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) @@ -961,113 +1165,15 @@ namespace bzit.bomg } } - protected void openBookmark(TreeNode node) - { - if (treeView1.GetNodeType(node) != RyzStudio.Windows.Forms.BookmarkTreeView.NodeType.Page) - { - return; - } - - BookmarkItemViewModel viewModel = (BookmarkItemViewModel)node.Tag; - if (viewModel == null) - { - return; - } - - if (string.IsNullOrWhiteSpace(viewModel.SiteAddress)) - { - return; - } - - try - { - System.Diagnostics.Process.Start(viewModel.SiteAddress); - } - catch - { - // do nothing - } - - - - - - - //if (node == null) - //{ - // return; - //} - - //if (node.Tag == null) - //{ - // return; - //} - - //if (!(node.Tag is BookmarkItem)) - //{ - // return; - //} - - //BookmarkItem item = (BookmarkItem)node.Tag; - //if (item == null) - //{ - // return; - //} - - //if (string.IsNullOrEmpty(item.SiteAddress)) - //{ - // return; - //} - - //int bookmarkAction; - //if (!int.TryParse(this.IconDatabase.GetConfig("core.bookmark.action", string.Empty), out bookmarkAction)) - //{ - // bookmarkAction = 0; - //} - - //string bookmarkCustom1 = this.IconDatabase.GetConfig("core.bookmark.customcommand1", string.Empty).Trim(); - //string bookmarkCustom2 = this.IconDatabase.GetConfig("core.bookmark.customcommand2", string.Empty).Trim(); - - //switch (bookmarkAction) - //{ - // case 1: - // if (string.IsNullOrEmpty(bookmarkCustom1)) - // { - // return; - // } - - // bookmarkCustom1 = bookmarkCustom1.Replace("%1", item.SiteAddress); - // bookmarkCustom2 = bookmarkCustom2.Replace("%1", item.SiteAddress); - - // try - // { - // System.Diagnostics.Process.Start(bookmarkCustom1, bookmarkCustom2); - // } - // catch - // { - // // do nothing - // } - - // break; - // default: - // try - // { - // System.Diagnostics.Process.Start(item.SiteAddress); - // } - // catch - // { - // // do nothing - // } - - // break; - //} - } #region root context menu private void addPageContextMenu_Click(object sender, EventArgs e) => (new BookmarkEditForm(treeView1)).ShowDialog(); + private void addFolderContextMenu_Click(object sender, EventArgs e) => treeView1.SelectedNode = treeView1.SNode.AddFolder(); + private void editContextMenu_Click(object sender, EventArgs e) => treeView1.SNode.Edit(); + private void sortContextMenu_Click(object sender, EventArgs e) => treeView1.SNode.Sort(); #endregion @@ -1075,6 +1181,7 @@ namespace bzit.bomg #region folder context menu private void addPageContextMenu2_Click(object sender, EventArgs e) => (new BookmarkEditForm(treeView1)).ShowDialog(); + private void addFolderContextMenu2_Click(object sender, EventArgs e) => treeView1.SelectedNode = treeView1.SNode.AddFolder(); private void openAllContextMenu_Click(object sender, EventArgs e) @@ -1096,9 +1203,13 @@ namespace bzit.bomg } private void editContextMenu2_Click(object sender, EventArgs e) => treeView1.SNode.Edit(); + private void deleteContextMenu_Click(object sender, EventArgs e) => treeView1.SNode.Delete(); + private void sortContextMenu2_Click(object sender, EventArgs e) => treeView1.SNode.Sort(); + private void moveUpContextMenu_Click(object sender, EventArgs e) => treeView1.SNode.MoveUp(); + private void moveDownContextMenu_Click(object sender, EventArgs e) => treeView1.SNode.MoveDown(); #endregion @@ -1106,12 +1217,48 @@ namespace bzit.bomg #region page context menu private void openContextMenu_Click(object sender, EventArgs e) => openBookmark(treeView1.SelectedNode); + private void editContextMenu3_Click(object sender, EventArgs e) => (new BookmarkEditForm(treeView1)).ShowDialog(); + private void deleteContextMenu2_Click(object sender, EventArgs e) => treeView1.SNode.Delete(); + private void moveUpContextMenu2_Click(object sender, EventArgs e) => treeView1.SNode.MoveUp(); + private void moveDownContextMenu2_Click(object sender, EventArgs e) => treeView1.SNode.MoveDown(); #endregion + private void loadFileThread_DoWork(object sender, DoWorkEventArgs e) + { + if (loadFileType == LoadFileType.Jsnx) + { + if (usePassword) + { + loadBookmarkFile_ForJSNX(sessionFilename, sessionPassword); + } + else + { + loadBookmarkFile_ForJSNX(sessionFilename); + } + } + else if (loadFileType == LoadFileType.Ryz) + { + if (usePassword) + { + loadBookmarkFile_ForRYZ(sessionFilename, sessionPassword); + } + else + { + loadBookmarkFile_ForRYZ(sessionFilename); + } + + sessionFilename = sessionPassword = null; + } + } + + private void loadFileThread_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) + { + this.IsBusy = false; + } } } diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index 87e3ca7..c0f53bc 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -8,7 +8,7 @@ using System.Runtime.InteropServices; [assembly: AssemblyTitle("Bookmark Manager")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] +[assembly: AssemblyCompany("Hi, I'm Ray")] [assembly: AssemblyProduct("Bookmark Manager")] [assembly: AssemblyCopyright("Copyright © Ray Lam 2012")] [assembly: AssemblyTrademark("")] diff --git a/RyzStudio/Windows/ThemedForms/TextBoxForm.cs b/RyzStudio/Windows/ThemedForms/TextBoxForm.cs index 7bbca82..a4b7a9b 100644 --- a/RyzStudio/Windows/ThemedForms/TextBoxForm.cs +++ b/RyzStudio/Windows/ThemedForms/TextBoxForm.cs @@ -64,6 +64,7 @@ namespace RyzStudio.Windows.ThemedForms switch (e.KeyCode) { case Keys.Escape: + textBox1.Text = string.Empty; this.Close(); break; default: break; diff --git a/Windows/Forms/BookmarkTreeView.cs b/Windows/Forms/BookmarkTreeView.cs index cf067fb..f76dc69 100644 --- a/Windows/Forms/BookmarkTreeView.cs +++ b/Windows/Forms/BookmarkTreeView.cs @@ -153,6 +153,8 @@ namespace RyzStudio.Windows.Forms { AddItem(item); } + + this.HasChanged = false; } public void AddItem(BookmarkItemViewModel viewModel) diff --git a/bomg.csproj b/bomg.csproj index 58c79b5..1dea1c9 100644 --- a/bomg.csproj +++ b/bomg.csproj @@ -155,12 +155,6 @@ - - Form - - - UpdateIconForm.cs - Form @@ -192,18 +186,6 @@ - - UserControl - - - BigButton.cs - - - UserControl - - - BigUserControl.cs - Component @@ -225,9 +207,6 @@ ProgressBarInner.cs - - UpdateIconForm.cs - BookmarkEditForm.cs @@ -250,9 +229,6 @@ MainForm.cs - - BigButton.cs - SettingsSingleFileGenerator