Exemple #1
0
        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);
        }
Exemple #2
0
 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;
     }
 }