Exemplo n.º 1
0
        private void TaskBackgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            if (e.UserState is AddBrowsingItemTask)
            {
                AddBrowsingItemTask task = e.UserState as AddBrowsingItemTask;

                if (browsingTreeView.Visible)
                {
                    if (browsingFilter.ShouldFilter(new KeyValuePair <string, BrowsingItem>(task.Uri, task.Item)))
                    {
                        browsingTreeView.AddItem(task.Uri, task.Item);
                    }
                }
            }
            else if (e.UserState is AddBookmarkItemTask)
            {
                AddBookmarkItemTask task = e.UserState as AddBookmarkItemTask;

                if (bookmarksTreeView.Visible)
                {
                    if (bookmarksFilter.ShouldFilter(task.Item))
                    {
                        bookmarksTreeView.AddItem(task.Path, task.Item);
                    }
                }
            }
        }
Exemplo n.º 2
0
        private static TreeNode FindSearchHistoryNode(TreeNode parentNode, string searchQuery)
        {
            foreach (TreeNode node in parentNode.Nodes)
            {
                AddBrowsingItemTask nodeContent = node.Tag as AddBrowsingItemTask;

                if (searchQuery.Equals(nodeContent.Uri))
                {
                    return(node);
                }
            }

            return(null);
        }
Exemplo n.º 3
0
        private void TreeView_NodeActivated(object sender, TreeViewExEventArgs e)
        {
            AddBrowsingItemTask browsingRecord = e.Node.Tag as AddBrowsingItemTask;

            if (browsingRecord != null)
            {
                SearchHandler.ParseAndExecuteSearchText(browsingRecord.Uri);
            }
            else
            {
                if (e.Action == TreeViewAction.ByKeyboard)
                {
                    e.Node.ToggleCollapse();
                }
            }
        }
Exemplo n.º 4
0
        public int Compare(object x, object y)
        {
            TreeNode lhs = (TreeNode)x;
            TreeNode rhs = (TreeNode)y;

            if (lhs.Level == 0)             // date groupings.
            {
                DateTime date1 = (DateTime)lhs.Tag;
                DateTime date2 = (DateTime)rhs.Tag;

                return((int)((date2 - date1).TotalSeconds));                // descending
            }
            else
            {
                AddBrowsingItemTask date1 = lhs.Tag as AddBrowsingItemTask;
                AddBrowsingItemTask date2 = rhs.Tag as AddBrowsingItemTask;

                if (SortType == BrowsingSortType.CreationTime)
                {
                    if (SortOrder == SortOrder.Descending)
                    {
                        return((int)((date2.Item.CreationTime - date1.Item.CreationTime).TotalSeconds));
                    }
                    else                    // if (SortOrder == SortOrder.Ascending)
                    {
                        return((int)((date1.Item.CreationTime - date2.Item.CreationTime).TotalSeconds));
                    }
                }
                else if (SortType == BrowsingSortType.LastAccessTime)
                {
                    if (SortOrder == SortOrder.Descending)
                    {
                        return((int)((date2.Item.LastAccessTime - date1.Item.LastAccessTime).TotalSeconds));
                    }
                    else                    // if (SortOrder == SortOrder.Ascending)
                    {
                        return((int)((date1.Item.LastAccessTime - date2.Item.LastAccessTime).TotalSeconds));
                    }
                }
                else if (SortType == BrowsingSortType.LastWriteTime)
                {
                    if (SortOrder == SortOrder.Descending)
                    {
                        return((int)((date2.Item.LastWriteTime - date1.Item.LastWriteTime).TotalSeconds));
                    }
                    else                    // if (SortOrder == SortOrder.Ascending)
                    {
                        return((int)((date1.Item.LastWriteTime - date2.Item.LastWriteTime).TotalSeconds));
                    }
                }
                else
                {
                    if (SortOrder == SortOrder.Descending)
                    {
                        return(rhs.Index - lhs.Index);
                    }
                    else                    // if (SortOrder == SortOrder.Ascending)
                    {
                        return(lhs.Index - rhs.Index);
                    }
                }
            }
        }
Exemplo n.º 5
0
        private void BrowsingContentNodeContextMenu_Popup(object sender, EventArgs e)
        {
            ContextMenu         contextMenu    = sender as ContextMenu;
            TreeNode            contentNode    = contextMenu.Tag as TreeNode;
            AddBrowsingItemTask browsingRecord = contentNode.Tag as AddBrowsingItemTask;

            contextMenu.MenuItems.Clear();

            contextMenu.MenuItems.Add(new MenuItem("&Remove from history", (sender2, e2) =>
            {
                contentNode.Remove();
                BrowsingModel.SearchHistory.Remove(browsingRecord.Uri);
            })
            {
                Name = "remove"
            });

            string uri = browsingRecord.Uri;

            if (string.IsNullOrEmpty(uri))
            {
                return;
            }

            string[] parts = uri.Split(new char[] { ':' });

            if (parts.Length == 0)
            {
                //MessageBox.Show("Please enter a valid search.", "Syntax Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            try
            {
                if (parts[0].Equals("search", StringComparison.OrdinalIgnoreCase) ||
                    parts[0].Equals("query", StringComparison.OrdinalIgnoreCase))
                {
                    string query     = parts[1];
                    int    pageIndex = 1;

                    if (!QueryParser.ParseQuerySearch(parts, out query, out pageIndex))
                    {
                        return;
                    }

                    if (File.Exists(SessionManager.GetSessionFileName(query, pageIndex)))
                    {
                        contextMenu.MenuItems.Add(new MenuItem("&Remove from cache", (sender2, e2) =>
                        {
                            SessionManager.ForgetSession(query, pageIndex);
                            SessionManager.DeleteSession(query, pageIndex);
                        })
                        {
                            Name = "removeFromCache"
                        });
                    }
                }
                else if (parts[0].Equals("tag", StringComparison.OrdinalIgnoreCase) ||
                         parts[0].Equals("tagged", StringComparison.OrdinalIgnoreCase))
                {
                    int    tagId;
                    string tagType;
                    string tagName;
                    int    pageIndex;

                    if (!QueryParser.ParseTaggedSearch(parts, out tagId, out tagType, out tagName, out pageIndex))
                    {
                        MessageBox.Show("Please enter a valid search.", "Syntax Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    // TODO? support tag name?
                    if (File.Exists(SessionManager.GetSessionFileName(tagId, pageIndex)))
                    {
                        contextMenu.MenuItems.Add(new MenuItem("&Remove from cache", (sender2, e2) =>
                        {
                            SessionManager.ForgetSession(tagId, pageIndex);
                            SessionManager.DeleteSession(tagId, pageIndex);
                        })
                        {
                            Name = "removeFromCache"
                        });
                    }
                }
                else if (parts[0].Equals("recent", StringComparison.OrdinalIgnoreCase) ||
                         parts[0].Equals("all", StringComparison.OrdinalIgnoreCase))
                {
                    int pageIndex;

                    if (!QueryParser.ParseRecentSearch(parts, out pageIndex))
                    {
                        MessageBox.Show("Please enter a valid search.", "Syntax Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    if (File.Exists(SessionManager.GetSessionFileName(pageIndex)))
                    {
                        contextMenu.MenuItems.Add(new MenuItem("&Remove from cache", (sender2, e2) =>
                        {
                            SessionManager.ForgetSession(pageIndex);
                            SessionManager.DeleteSession(pageIndex);
                        })
                        {
                            Name = "removeFromCache"
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Syntax Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }