public bool ResourceRenamed(IResource res, string newName) { string oldName = res.GetStringProp(Core.Props.Name); if (oldName == null || newName == null || oldName == newName) { return(false); } if (newName.Length == 0 || newName == "New Folder") { MessageBox.Show(Core.MainWindow, "Please specify a name.", "Rename", MessageBoxButtons.OK, MessageBoxIcon.Stop); return(false); } // check duplicates on the same level for some cases IBookmarkProfile profile = _bookmarkService.GetOwnerProfile(res); IResource parent = res.GetLinkProp(_propParent); if (parent != null && (profile == _favoritesProfile || res.Type == "Folder") && BookmarkService.HasSubNodeWithName(parent, newName)) { MessageBox.Show(Core.MainWindow, "The name is already used, please specify another", "Rename", MessageBoxButtons.OK, MessageBoxIcon.Stop); return(false); } if (profile != null) { profile.Rename(res, newName); } new ResourceProxy(res).SetPropAsync(Core.Props.Name, newName); return(true); }
private bool AcceptFolder(IResource folder) { IBookmarkProfile profile = _bookmarkService.GetOwnerProfile(folder); string error; return(profile == null || profile.CanCreate(folder, out error)); }
public bool CanRenameResource(IResource res) { IBookmarkProfile profile = _bookmarkService.GetOwnerProfile(res); string error; return((res.Type == "Weblink" || res.Type == "Folder") && (profile == null || profile.CanRename(res, out error))); }
private void NewWeblink() { bool newWeblink = false; if (_favorite == null) { _favorite = Core.ResourceStore.BeginNewResource("Weblink"); newWeblink = true; } else { _favorite.BeginUpdate(); } try { string url = _URLBox.Text; _favorite.SetProp(Core.Props.Name, _nameBox.Text); _favorite.SetProp(FavoritesPlugin._propURL, url); int updateFreq = 0; if (_updateCheckBox.Checked) { updateFreq = (int)_hoursBox.Value * 60 * 60; int unitIndex = _unitBox.SelectedIndex; if (unitIndex > 0) // days or weeks { updateFreq *= 24; if (unitIndex > 1) // weeks { updateFreq *= 7; } } } _favorite.SetProp(FavoritesPlugin._propUpdateFreq, updateFreq); if (_parent != null) { _favorite.AddLink(FavoritesPlugin._propParent, _parent); } Core.WorkspaceManager.AddToActiveWorkspace(_favorite); } finally { _favorite.EndUpdate(); } if (newWeblink) { IBookmarkProfile profile = _bookmarkService.GetOwnerProfile(_favorite); string error = null; if (profile != null && profile.CanCreate(_favorite, out error)) { profile.Create(_favorite); } else { Core.UserInterfaceAP.QueueJob(new LineDelegate(DisplayError), error); } BookmarkService.ImmediateQueueWeblink(_favorite, _URLBox.Text); } }
public IBookmarkProfile GetOwnerProfile(IResource res) { Guard.NullArgument(res, "res"); IBookmarkProfile result = null; while (res != null && (result = (IBookmarkProfile)_rootResources2Profiles[res]) == null) { res = GetParent(res); } return(result); }
public bool CanDropResources(IResource targetResource, IResourceList dragResources) { if (dragResources.Count > 0) { if (targetResource != _bookmarkService.BookmarksRoot) { if (targetResource.Type != "Folder") { return(false); } IBookmarkProfile targetProfile = _bookmarkService.GetOwnerProfile(targetResource); foreach (IResource dragRes in dragResources) { string error; IBookmarkProfile sourceProfile = _bookmarkService.GetOwnerProfile(dragRes); if (sourceProfile == targetProfile) { if (targetProfile != null && !targetProfile.CanMove(dragRes, targetResource, out error)) { return(false); } } else { if (sourceProfile != null && !sourceProfile.CanDelete(dragRes, out error)) { return(false); } if (targetProfile != null && !targetProfile.CanCreate(dragRes, out error)) { return(false); } } } IResource temp = targetResource; do { if (dragResources.IndexOf(temp) >= 0) { return(false); } temp = BookmarkService.GetParent(temp); } while(temp != null); } string[] types = dragResources.GetAllTypes(); if (types.Length < 3) { return((types[0] == "Weblink" || types[0] == "Folder") && (types.Length == 1 || types[1] == "Weblink" || types[1] == "Folder")); } } return(false); }
public void Execute(IActionContext context) { IResourceList resources = context.SelectedResources; if (resources.Count > 1) { if (MessageBox.Show(Core.MainWindow, "Are you sure you want to delete selected weblinks and/or folders?", "Delete Bookmarks", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } } for (int i = 0; i < resources.Count; ++i) { IResource res = context.SelectedResources[i]; if (res.Type != "Folder" && res.Type != "Weblink") { res = res.GetLinkProp("Source"); } if (res != null && (res.Type == "Folder" || res.Type == "Weblink")) { if (resources.Count == 1) { if (res.Type != "Folder" || res.DisplayName != "New Folder") { if (MessageBox.Show(Core.MainWindow, "Are you sure you want to delete '" + res.DisplayName + "'?", "Delete Bookmark", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } } } IBookmarkService bookmarkService = (IBookmarkService)Core.PluginLoader.GetPluginService(typeof(IBookmarkService)); IBookmarkProfile profile = bookmarkService.GetOwnerProfile(res); string error = null; if (profile != null && profile.CanDelete(res, out error)) { profile.Delete(res); } if (res.Type == "Folder") { bookmarkService.DeleteFolder(res); } else { bookmarkService.DeleteBookmark(res); } } } }
public static void EditFavorite(IResource favorite) { AddFavoriteForm theForm = new AddFavoriteForm(null); using ( theForm ) { if (favorite.Type != "Weblink") { favorite = favorite.GetLinkProp("Source"); if (favorite == null) { return; } } theForm._favorite = favorite; theForm._URLBox.Text = favorite.GetPropText(FavoritesPlugin._propURL); theForm._nameBox.Text = favorite.GetPropText(Core.Props.Name); int freq = favorite.GetIntProp(FavoritesPlugin._propUpdateFreq) / 3600; if (freq <= 0) { theForm._fakeTextBox.Visible = true; } else { if (freq % 24 == 0) { theForm._unitBox.SelectedIndex = 1; freq /= 24; if (freq % 7 == 0) { theForm._unitBox.SelectedIndex = 2; freq /= 7; } } theForm._hoursBox.Value = freq; theForm._updateCheckBox.Checked = true; } theForm._okButton.Enabled = true; theForm.Text = "Bookmark Properties"; theForm._selectFolderPanel.Visible = false; theForm.Height = theForm.MinimumSize.Height; IBookmarkProfile profile = _bookmarkService.GetOwnerProfile(favorite); string error = null; bool readOnly = (profile != null && !profile.CanCreate(null, out error)); if (theForm._URLBox.ReadOnly = theForm._nameBox.ReadOnly = readOnly) { theForm._errorToolTip.SetToolTip(theForm._URLBox, error); theForm._errorToolTip.SetToolTip(theForm._nameBox, error); DisplayError(error); } theForm.ShowDialog(Core.MainWindow); } }
private void NewFolder() { IBookmarkService bookmarkService = (IBookmarkService)Core.PluginLoader.GetPluginService(typeof(IBookmarkService)); IResource newFolder = bookmarkService.FindOrCreateFolder(_parentFolder, "New Folder"); IBookmarkProfile profile = bookmarkService.GetOwnerProfile(newFolder); string error = null; if (profile != null && profile.CanCreate(newFolder, out error)) { profile.Create(newFolder); } Core.WorkspaceManager.AddToActiveWorkspaceRecursive(newFolder); Core.UIManager.QueueUIJob(new ResourceDelegate(FavoritesPlugin._favoritesTreePane.SelectResource), newFolder); Core.UIManager.QueueUIJob(new ResourceDelegate(FavoritesPlugin._favoritesTreePane.EditResourceLabel), newFolder); }
public void RegisterProfile(IBookmarkProfile profile) { Guard.NullArgument(profile, "profile"); string name = NormalizeProfileName(profile.Name); if (_profileNames2RootResources.Contains(name)) { throw new InvalidOperationException("Bookmark profile '" + profile.Name + "' is already registered"); } string[] nameParts = profile.Name.Split('\\', '/'); IResource parent = _rootFolder; IResource interimParent = null; foreach (string namePart in nameParts) { if (namePart.Length == 0) { throw new Exception("Invalid profile name: " + profile.Name); } parent = FindOrCreateFolder(parent, namePart); /** * Register fake all-restricting profile for interim folders which contain * profiles' folders, e.x., for Mozilla->profile1, Mozilla->profile2... etc... */ if (interimParent != null && GetOwnerProfile(interimParent) == null) { FakeRestrictProfile fakeProfile = new FakeRestrictProfile(); _profileNames2RootResources[NormalizeProfileName(fakeProfile.Name)] = interimParent; _rootResources2Profiles[interimParent] = fakeProfile; } interimParent = parent; } if (parent == _rootFolder) { throw new Exception("Invalid profile name: " + profile.Name); } _profileNames2RootResources[name] = parent; _rootResources2Profiles[parent] = profile; if (_rootResources2Profiles.Count != _profileNames2RootResources.Count) { throw new Exception("Root resources and profiles count mismatch. Last added profile name: " + profile.Name); } Trace.WriteLine("Registered bookmark profile: " + profile.Name, "Favorites.Plugin"); }
private RemoteAnnotateForm(IResource weblink) { InitializeComponent(); RestoreSettings(); Icon = FavoritesPlugin.LoadIconFromAssembly("categorize_annotate.ico"); _weblink = weblink; InitializeContent(); IBookmarkService service = (IBookmarkService)Core.PluginLoader.GetPluginService(typeof(IBookmarkService)); IBookmarkProfile profile = service.GetOwnerProfile(_weblink); string error; if (profile == null || profile.CanCreate(_weblink, out error)) { _nameBox.ReadOnly = false; _nameBox.BorderStyle = BorderStyle.Fixed3D; _nameBox.Font = new Font(_nameBox.Font, FontStyle.Regular); } }
private void WeblinkOrFolderChanged(object sender, ResourcePropIndexEventArgs e) { IResource webLink = e.Resource; IPropertyChangeSet set = e.ChangeSet; int propLastModified = Core.ResourceStore.PropTypes["LastModified"].Id; if (BookmarkService.DownloadMethod != 2 && webLink == _lastDisplayedWeblink && ((set.IsPropertyChanged(propLastModified) && webLink.HasProp("Source")) || (set.IsPropertyChanged(Core.Props.LastError) && webLink.HasProp(Core.Props.LastError)))) { // if the displayed web link has changed, redisplay it IResourceBrowser browser = Core.ResourceBrowser; if ((webLink == _favoritesTreePane.SelectedNode && Core.TabManager.CurrentTabId == "Web") || (browser.SelectedResources.Count == 1 && webLink == browser.SelectedResources[0])) { Core.UserInterfaceAP.QueueJobAt(DateTime.Now.AddSeconds(1), "RedisplaySelectedResource", browser.RedisplaySelectedResource); } } string URL = webLink.GetPropText(_propURL); if (URL.Length > 0) { if (set.IsPropertyChanged(_propLastUpdated) || set.IsPropertyChanged(_propUpdateFreq)) { BookmarkService.QueueWeblink(webLink, URL, BookmarkService.BookmarkSynchronizationTime(webLink)); } if (set.IsPropertyChanged(_propURL)) { BookmarkService.ImmediateQueueWeblink(webLink, URL); } } if (set.IsPropertyChanged(Core.PropIds.Name) || set.IsPropertyChanged(_propURL)) { IBookmarkProfile profile = _bookmarkService.GetOwnerProfile(webLink); string error; if (profile != null && profile.CanCreate(webLink, out error)) { profile.Create(webLink); } } }
bool IResourceNodeFilter.AcceptNode(IResource res, int level) { if (res.HasProp(FavoritesPlugin._propInvisible)) { return(false); } IBookmarkService service = (IBookmarkService)Core.PluginLoader.GetPluginService(typeof(IBookmarkService)); if (service != null) { IBookmarkProfile profile = service.GetOwnerProfile(res); if (profile is FakeRestrictProfile) { return(BookmarkService.SubNodes("Folder", res).Minus( Core.ResourceStore.FindResourcesWithProp(null, FavoritesPlugin._propInvisible)).Count > 0); } } return(true); }
public void ResourcesDropped(IResource targetResource, IResourceList droppedResources) { IBookmarkProfile targetProfile = _bookmarkService.GetOwnerProfile(targetResource); foreach (IResource dropRes in droppedResources) { IResource oldParent = BookmarkService.GetParent(dropRes); IBookmarkProfile sourceProfile = _bookmarkService.GetOwnerProfile(dropRes); if (sourceProfile == targetProfile) { if (targetProfile != null) { targetProfile.Move(dropRes, targetResource, oldParent); } new ResourceProxy(dropRes).SetProp(_propParent, targetResource); } else { if (sourceProfile != null) { sourceProfile.Delete(dropRes); } new ResourceProxy(dropRes).SetProp(_propParent, targetResource); if (targetProfile != null) { targetProfile.Create(dropRes); } } // the resource may have been moved from a parent which belonged to a workspace // to the top level (#5066) if (dropRes.Type == "Weblink") { Core.WorkspaceManager.AddToActiveWorkspace(dropRes); } else { Core.WorkspaceManager.AddToActiveWorkspaceRecursive(dropRes); } } }
/** * Replace invalid chars in name of bookmark with dots */ public static string GetSafeBookmarkName(IBookmarkProfile profile, string name) { if (profile.InvalidNameChars.Length == 0) { return(name); } char[] invalidChars = (char[])profile.InvalidNameChars.Clone(); Array.Sort(invalidChars); StringBuilder builder = new StringBuilder(name.Length); for (int i = 0; i < name.Length; ++i) { if (Array.BinarySearch(invalidChars, name[i]) >= 0) { builder.Append('.'); } else { builder.Append(name[i]); } } return(builder.ToString()); }
public void DeRegisterProfile(IBookmarkProfile profile) { Guard.NullArgument(profile, "profile"); using ( profile ) { string name = NormalizeProfileName(profile.Name); HashMap.Entry e = _profileNames2RootResources.GetEntry(name); if (e == null) { throw new InvalidOperationException("Bookmark profile '" + profile.Name + "' was not registered"); } IResource profileRoot = (IResource)e.Value; _profileNames2RootResources.Remove(name); _rootResources2Profiles.Remove(profileRoot); if (_rootResources2Profiles.Count != _profileNames2RootResources.Count) { throw new Exception("Root resources and profiles count mismatch. Last removed profile name: " + profile.Name); } if (profileRoot.HasProp(FavoritesPlugin._propInvisible)) { DeleteFolder(profileRoot); } } }
private void SubmitChanges() { if (!_weblink.IsTransient) { _weblink.BeginUpdate(); } try { string annotation = _edtAnnotation.Text; if (annotation.Length == 0) { _weblink.DeleteProp("Annotation"); } else { _weblink.SetProp("Annotation", annotation); } string name = _nameBox.Text; if (name != _weblink.GetPropText(Core.Props.Name)) { _weblink.SetProp(Core.Props.Name, name); IBookmarkService service = (IBookmarkService)Core.PluginLoader.GetPluginService(typeof(IBookmarkService)); IBookmarkProfile profile = service.GetOwnerProfile(_weblink); string error; if (profile != null && profile.CanCreate(_weblink, out error)) { profile.Create(_weblink); } } } finally { _weblink.EndUpdate(); } }
public IResource GetProfileRoot(IBookmarkProfile profile) { return(GetProfileRoot(profile.Name)); }
public IResourceList GetBookmarks(IBookmarkProfile profile) { return(GetBookmarks(GetProfileRoot(profile))); }
private void OKButton_Click(object sender, System.EventArgs e) { if (_okButton.Enabled) { _okButton.Enabled = false; string url = _URLBox.Text.Trim(); if (url.IndexOf("://") < 0) { if (url.IndexOf('\\') >= 0) { url = "file://" + url; } else { url = "http://" + url; } _URLBox.Text = url; } try { new Uri(url); } catch (Exception exc) { Utils.DisplayException(exc, "Bad URL"); _URLBox.Focus(); _okButton.Enabled = true; return; } string bookmarkName = _nameBox.Text; if (bookmarkName.Length == 0) { bookmarkName = url; } _nameBox.Text = bookmarkName; if (_parent != null) { if (_createInCombo.SelectedItem != null) { _parent = (IResource)_createInCombo.SelectedItem; } IBookmarkProfile profile = _bookmarkService.GetOwnerProfile(_parent); if (profile != null) { bookmarkName = FavoritesTools.GetSafeBookmarkName(profile, bookmarkName); string error = null; IResource tempWeblink = Core.ResourceStore.NewResourceTransient("Weblink"); tempWeblink.SetProp(FavoritesPlugin._propURL, url); tempWeblink.SetProp(Core.Props.Name, bookmarkName); tempWeblink.AddLink(FavoritesPlugin._propParent, _parent); if (!profile.CanCreate(tempWeblink, out error)) { DisplayError(error); _nameBox.Focus(); _okButton.Enabled = true; return; } } } bool newFavorite = _favorite == null; Core.ResourceAP.RunUniqueJob(new MethodInvoker(NewWeblink)); if (newFavorite) { FavoritesPlugin._favoritesTreePane.SelectResource(_favorite); } Close(); } }
private void ProcessResourceStream(IResource resource, IResource source, TextReader reader, IResourceTextConsumer consumer) { _currentIndexedRes = resource; try { using (HTMLParser parser = new HTMLParser(reader)) { parser.CloseReader = false; parser.AddTagHandler("link", LinkHandler); int docID = resource.Id; string fragment; while (!parser.Finished) { fragment = parser.ReadNextFragment(); if (fragment.Length > 0) { if (parser.InHeading) { consumer.AddDocumentHeading(docID, fragment); } else { consumer.AddDocumentFragment(docID, fragment); } } } // check whether source resource is favorite and has non-empty name property // if it hasn't, or has name equyal to URL then set name from the title of HTML stream if (source != null && source.Type == "Weblink") { IBookmarkService service = (IBookmarkService)Core.PluginLoader.GetPluginService(typeof(IBookmarkService)); if (service != null) { string name = source.GetPropText(Core.Props.Name); string url = string.Empty; if (Core.ResourceStore.PropTypes.Exist("URL")) { url = source.GetPropText("URL"); if (url.StartsWith("http://") || url.StartsWith("file://")) { url = url.Substring("http://".Length); } else if (url.StartsWith("ftp://")) { url = url.Substring("ftp://".Length); } } if (url.IndexOfAny(Path.GetInvalidPathChars()) >= 0) { foreach (char invalidChar in Path.GetInvalidPathChars()) { url = url.Replace(invalidChar, '-'); } } if (name.Length == 0 || url.StartsWith(name)) { string title = parser.Title.Trim(); if (title.Length > 0) { IBookmarkProfile profile = service.GetOwnerProfile(source); string error; if (profile != null && profile.CanRename(source, out error)) { profile.Rename(source, title); service.SetName(source, title); } } } } } } } finally { _currentIndexedRes = null; } }
/** * returns action flags for group of weblinks or folders (IAction.Update methods) */ public static void IActionUpdateWeblinksOrFolders( IActionContext context, ref ActionPresentation presentation, ActionType type) { if (context.SelectedResources == null || context.SelectedResources.Count == 0) { presentation.Visible = false; } else { IBookmarkService service = (IBookmarkService)Core.PluginLoader.GetPluginService(typeof(IBookmarkService)); for (int i = 0; i < context.SelectedResources.Count; ++i) { IResource res = context.SelectedResources[i]; if (res.Type != "Folder" && res.Type != "Weblink") { res = res.GetLinkProp("Source"); if (res == null || (res.Type != "Weblink" && res.Type != "Folder")) { presentation.Visible = false; return; } } IBookmarkProfile profile = service.GetOwnerProfile(res); string error = null; if (profile != null) { switch (type) { case ActionType.Create: { if (!profile.CanCreate(null, out error)) { presentation.Visible = false; } break; } case ActionType.Update: { if (!profile.CanRename(res, out error)) { presentation.Visible = false; } break; } case ActionType.Delete: { if (!profile.CanDelete(res, out error)) { presentation.Visible = false; } break; } case ActionType.Edit: { break; } } if (!presentation.Visible && error != null && error.Length > 0) { presentation.ToolTip = error; } } } } }