@@ -24,7 +24,11 @@ public enum CollectionType
2424 SourceCollection ,
2525 }
2626
27- public delegate BookCollection Factory ( string path , CollectionType collectionType ) ; //autofac uses this
27+ public delegate BookCollection Factory (
28+ string path ,
29+ CollectionType collectionType ,
30+ CollectionSettings settings = null
31+ ) ; //autofac uses this
2832
2933 public EventHandler CollectionChanged ;
3034
@@ -37,6 +41,8 @@ public enum CollectionType
3741 private static HashSet < string > _changingFolders = new HashSet < string > ( ) ;
3842 private BloomWebSocketServer _webSocketServer ;
3943
44+ private CollectionSettings _collectionSettings ;
45+
4046 public static event EventHandler CollectionCreated ;
4147
4248 //for moq only
@@ -53,13 +59,15 @@ public BookCollection(
5359 CollectionType collectionType ,
5460 BookSelection bookSelection ,
5561 TeamCollectionManager tcm = null ,
62+ CollectionSettings collectionSettings = null ,
5663 BloomWebSocketServer webSocketServer = null
5764 )
5865 {
5966 _path = path ;
6067 _bookSelection = bookSelection ;
6168 _tcManager = tcm ;
6269 _webSocketServer = webSocketServer ;
70+ _collectionSettings = collectionSettings ;
6371
6472 Type = collectionType ;
6573
@@ -412,7 +420,45 @@ private void AddBookInfo(string folderPath)
412420 )
413421 ? _bookSelection . CurrentSelection . BookInfo
414422 : new BookInfo ( folderPath , editable , sc ) ;
415-
423+ if ( bookInfo . FileNameLocked )
424+ {
425+ // The user has explicitly chosen a name to use for the book, distinct from its titles.
426+ bookInfo . ThumbnailLabel = Path . GetFileName ( folderPath ) ;
427+ }
428+ else
429+ {
430+ bookInfo . ThumbnailLabel = bookInfo . Title ;
431+ }
432+ if (
433+ bookInfo . IsInEditableCollection
434+ && ! bookInfo . FileNameLocked
435+ && String . IsNullOrEmpty ( bookInfo . Title )
436+ )
437+ {
438+ if (
439+ folderPath == _bookSelection . CurrentSelection ? . FolderPath
440+ && _bookSelection . CurrentSelection . BookInfo . SaveContext == sc
441+ )
442+ {
443+ bookInfo . ThumbnailLabel = _bookSelection
444+ . CurrentSelection
445+ . TitleBestForUserDisplay ;
446+ }
447+ else
448+ {
449+ var htmlPath = BookStorage . FindBookHtmlInFolder ( folderPath ) ;
450+ if ( ! String . IsNullOrEmpty ( htmlPath ) && RobustFile . Exists ( htmlPath ) )
451+ {
452+ var dom = HtmlDom . CreateFromHtmlFile ( htmlPath ) ;
453+ var bookData = new BookData ( dom , _collectionSettings , null ) ;
454+ bookInfo . ThumbnailLabel = Book . Book . GetBestTitleForDisplay (
455+ bookData . GetMultiTextVariableOrEmpty ( "bookTitle" ) ,
456+ bookData . GetBasicBookLanguageCodes ( ) . ToList ( ) ,
457+ bookInfo . IsInEditableCollection
458+ ) ;
459+ }
460+ }
461+ }
416462 _bookInfos . Add ( bookInfo ) ;
417463 }
418464 catch ( Exception e )
0 commit comments