private bool AcceptFolder(IResource folder) { IBookmarkProfile profile = _bookmarkService.GetOwnerProfile(folder); string error; return(profile == null || profile.CanCreate(folder, 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 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 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); }
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); } } }
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 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(); } }
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(); } }
/** * 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; } } } } }