mirror of
				https://github.com/Nioux/AideDeJeu.git
				synced 2025-10-31 15:36:07 +00:00 
			
		
		
		
	Bookmarks en markdown
This commit is contained in:
		
							parent
							
								
									ef5df06d02
								
							
						
					
					
						commit
						6413830117
					
				
					 7 changed files with 120 additions and 64 deletions
				
			
		|  | @ -9,6 +9,14 @@ namespace AideDeJeuLib | ||||||
| { | { | ||||||
|     public class LinkItem : Item |     public class LinkItem : Item | ||||||
|     { |     { | ||||||
|  |         public override string Markdown | ||||||
|  |         { | ||||||
|  |             get | ||||||
|  |             { | ||||||
|  |                 return $"\n\n<!--LinkItem-->\n\n{new string('#', NameLevel + 1)} {NameLink}\n\n<!--/LinkItem-->\n\n"; | ||||||
|  |             } | ||||||
|  |             set => base.Markdown = value; | ||||||
|  |         } | ||||||
|         public string Link { get; set; } |         public string Link { get; set; } | ||||||
|         public string NameLink |         public string NameLink | ||||||
|         { |         { | ||||||
|  | @ -16,7 +24,7 @@ namespace AideDeJeuLib | ||||||
|             { |             { | ||||||
|                 if (Name != null && Link != null) |                 if (Name != null && Link != null) | ||||||
|                 { |                 { | ||||||
|                     return $"[{Name}]({Link})"; |                     return $"<!--NameLink-->[{Name}]({Link})<!--/NameLink-->"; | ||||||
|                 } |                 } | ||||||
|                 return null; |                 return null; | ||||||
|             } |             } | ||||||
|  |  | ||||||
|  | @ -87,17 +87,19 @@ namespace AideDeJeu.Tools | ||||||
|         public static string IdFromName(string name) |         public static string IdFromName(string name) | ||||||
|         { |         { | ||||||
|             string id = string.Empty; |             string id = string.Empty; | ||||||
|             foreach(var c in name) |             if (name != null) | ||||||
|             { |             { | ||||||
|                 if(c >= 'A' && c <= 'Z') |                 foreach (var c in name) | ||||||
|  |                 { | ||||||
|  |                     if (c >= 'A' && c <= 'Z') | ||||||
|                     { |                     { | ||||||
|                         id += c.ToString().ToLower(); |                         id += c.ToString().ToLower(); | ||||||
|                     } |                     } | ||||||
|                 else if(c == ' ') |                     else if (c == ' ') | ||||||
|                     { |                     { | ||||||
|                         id += '-'; |                         id += '-'; | ||||||
|                     } |                     } | ||||||
|                 else if(c== '\'' || c == '/' || c == '(' || c ==')' || c == ':' || c == '+' || c == ',') |                     else if (c == '\'' || c == '/' || c == '(' || c == ')' || c == ':' || c == '+' || c == ',') | ||||||
|                     { |                     { | ||||||
|                         // vide |                         // vide | ||||||
|                     } |                     } | ||||||
|  | @ -106,6 +108,7 @@ namespace AideDeJeu.Tools | ||||||
|                         id += c; |                         id += c; | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|  |             } | ||||||
|             return id; |             return id; | ||||||
|             //return name.ToLower().Replace(" ", "-").Replace("\'","").Replace("/",""); |             //return name.ToLower().Replace(" ", "-").Replace("\'","").Replace("/",""); | ||||||
|             //return RemoveDiacritics(name.ToLower().Replace(" ", "-").Replace("\'", "")); |             //return RemoveDiacritics(name.ToLower().Replace(" ", "-").Replace("\'", "")); | ||||||
|  |  | ||||||
|  | @ -3,6 +3,7 @@ using System; | ||||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||||
| using System.Collections.ObjectModel; | using System.Collections.ObjectModel; | ||||||
| using System.IO; | using System.IO; | ||||||
|  | using System.Linq; | ||||||
| using System.Runtime.Serialization.Json; | using System.Runtime.Serialization.Json; | ||||||
| using System.Text; | using System.Text; | ||||||
| using System.Threading.Tasks; | using System.Threading.Tasks; | ||||||
|  | @ -91,6 +92,30 @@ namespace AideDeJeu.ViewModels | ||||||
|             await App.Current.SavePropertiesAsync(); |             await App.Current.SavePropertiesAsync(); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |         public string ToString(List<Item> items) | ||||||
|  |         { | ||||||
|  |             string md = string.Empty; | ||||||
|  |             md += "\n<!--Items-->\n\n"; | ||||||
|  |             foreach(var item in items) | ||||||
|  |             { | ||||||
|  |                 md += item.Markdown; | ||||||
|  |             } | ||||||
|  |             md += "\n\n<!--/Items-->\n"; | ||||||
|  |             return md; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         public List<Item> ToItems(string md) | ||||||
|  |         { | ||||||
|  |             var item = Store.ToItem("", md); | ||||||
|  |             if(item is Items) | ||||||
|  |             { | ||||||
|  |                 var items = item as Items; | ||||||
|  |                 return items.ToList(); | ||||||
|  |             } | ||||||
|  |             return new List<Item> { item }; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |             /* | ||||||
|             public string ToString(List<Item> items) |             public string ToString(List<Item> items) | ||||||
|             { |             { | ||||||
|                 var serializer = ItemJsonSerializer; |                 var serializer = ItemJsonSerializer; | ||||||
|  | @ -136,5 +161,6 @@ namespace AideDeJeu.ViewModels | ||||||
|                     return new DataContractJsonSerializer(typeof(List<Item>), settings); |                     return new DataContractJsonSerializer(typeof(List<Item>), settings); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|  |             */ | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| } |  | ||||||
|  |  | ||||||
|  | @ -140,7 +140,7 @@ namespace AideDeJeu.ViewModels | ||||||
|         { |         { | ||||||
|             if (s != null) |             if (s != null) | ||||||
|             { |             { | ||||||
|                 var regex = new Regex("/(?<file>.*?)(_with_(?<with>.*))?\\.md(#(?<anchor>.*))?"); |                 var regex = new Regex("/?(?<file>.*?)(_with_(?<with>.*))?\\.md(#(?<anchor>.*))?"); | ||||||
|                 var match = regex.Match(s); |                 var match = regex.Match(s); | ||||||
|                 var file = match.Groups["file"].Value; |                 var file = match.Groups["file"].Value; | ||||||
|                 var anchor = match.Groups["anchor"].Value; |                 var anchor = match.Groups["anchor"].Value; | ||||||
|  | @ -181,6 +181,10 @@ namespace AideDeJeu.ViewModels | ||||||
|                     { |                     { | ||||||
|                         await GotoItemDetailPageAsync(item); |                         await GotoItemDetailPageAsync(item); | ||||||
|                     } |                     } | ||||||
|  |                     var tabbedPage = App.Current.MainPage as MainTabbedPage; | ||||||
|  |                     tabbedPage.SelectedItem = null; | ||||||
|  |                     tabbedPage.SelectedItem = tabbedPage.MainNavigationPage; | ||||||
|  | 
 | ||||||
|                 } |                 } | ||||||
|                 else |                 else | ||||||
|                 { |                 { | ||||||
|  |  | ||||||
|  | @ -64,7 +64,10 @@ namespace AideDeJeu.ViewModels | ||||||
|                         if (IsClosingItem(block)) |                         if (IsClosingItem(block)) | ||||||
|                         { |                         { | ||||||
|                             currentItem.Id = GetNewAnchorId(source, currentItem.Name); |                             currentItem.Id = GetNewAnchorId(source, currentItem.Name); | ||||||
|  |                             if (currentItem.Id != null) | ||||||
|  |                             { | ||||||
|                                 _AllItems[currentItem.Id] = currentItem; |                                 _AllItems[currentItem.Id] = currentItem; | ||||||
|  |                             } | ||||||
|                             return currentItem; |                             return currentItem; | ||||||
|                         } |                         } | ||||||
|                         else if (IsNewItem(block)) |                         else if (IsNewItem(block)) | ||||||
|  | @ -226,6 +229,8 @@ namespace AideDeJeu.ViewModels | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|         public string GetNewAnchorId(string source, string name) |         public string GetNewAnchorId(string source, string name) | ||||||
|  |         { | ||||||
|  |             if (name != null) | ||||||
|             { |             { | ||||||
|                 var baseid = Helpers.IdFromName(name); |                 var baseid = Helpers.IdFromName(name); | ||||||
|                 var id = $"{source}.md#{baseid}"; |                 var id = $"{source}.md#{baseid}"; | ||||||
|  | @ -240,6 +245,8 @@ namespace AideDeJeu.ViewModels | ||||||
|                     name = $"{source}.md#{baseid}{index}"; |                     name = $"{source}.md#{baseid}{index}"; | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|  |             return null; | ||||||
|  |         } | ||||||
|         /* |         /* | ||||||
|         void AddAnchor(string source, Dictionary<string, Item> anchors, Item item) |         void AddAnchor(string source, Dictionary<string, Item> anchors, Item item) | ||||||
|         { |         { | ||||||
|  |  | ||||||
|  | @ -20,13 +20,13 @@ | ||||||
| 
 | 
 | ||||||
|             <Label Grid.Column="0" Grid.Row="1" HorizontalOptions="Center" VerticalOptions="Center" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" Margin="15,0,15,0" Style="{StaticResource subsubsection}" Text="Cette liste est vide, ajoutez des éléments à partir de la bibliothèque !" IsVisible="{Binding BookmarkCollection.Count, Converter={StaticResource IntToBooleanConverter}}" /> |             <Label Grid.Column="0" Grid.Row="1" HorizontalOptions="Center" VerticalOptions="Center" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" Margin="15,0,15,0" Style="{StaticResource subsubsection}" Text="Cette liste est vide, ajoutez des éléments à partir de la bibliothèque !" IsVisible="{Binding BookmarkCollection.Count, Converter={StaticResource IntToBooleanConverter}}" /> | ||||||
| 
 | 
 | ||||||
|             <ListView Grid.Column="0" Grid.Row="1" x:Name="ItemsListView" ItemsSource="{Binding BookmarkCollection}" VerticalOptions="FillAndExpand" HasUnevenRows="true" CachingStrategy="RecycleElement" SelectedItem="{Binding SelectedItem}"> |             <ListView Grid.Column="0" Grid.Row="1" x:Name="ItemsListView" ItemsSource="{Binding BookmarkCollection}" VerticalOptions="FillAndExpand" HasUnevenRows="true" CachingStrategy="RecycleElement" SelectedItem="{Binding SelectedItem}" ItemTapped="ItemsListView_ItemTapped"> | ||||||
|                 <ListView.ItemTemplate> |                 <ListView.ItemTemplate> | ||||||
|                     <DataTemplate> |                     <DataTemplate> | ||||||
|                         <ViewCell AutomationProperties.IsInAccessibleTree="True" AutomationId="machin" AutomationProperties.Name="hop"> |                         <ViewCell AutomationProperties.IsInAccessibleTree="True" AutomationId="machin" AutomationProperties.Name="hop"> | ||||||
|                             <StackLayout Padding="10" Orientation="Vertical"> |                             <StackLayout Padding="10" Orientation="Vertical"> | ||||||
|                                 <Label Text="{Binding Name}" LineBreakMode="WordWrap" Style="{DynamicResource subsubsection}" FontSize="16" /> |                                 <Label Text="{Binding Name}" LineBreakMode="WordWrap" Style="{DynamicResource subsubsection}" FontSize="16" /> | ||||||
|                                 <Label Text="{Binding Id}" LineBreakMode="WordWrap" Style="{DynamicResource subsubsection}" FontSize="12" /> |                                 <Label Text="{Binding Link}" LineBreakMode="WordWrap" Style="{DynamicResource subsubsection}" FontSize="12" /> | ||||||
|                             </StackLayout> |                             </StackLayout> | ||||||
|                         </ViewCell> |                         </ViewCell> | ||||||
|                     </DataTemplate> |                     </DataTemplate> | ||||||
|  |  | ||||||
|  | @ -1,4 +1,5 @@ | ||||||
| using AideDeJeu.ViewModels; | using AideDeJeu.ViewModels; | ||||||
|  | using AideDeJeuLib; | ||||||
| using System; | using System; | ||||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||||
| using System.Linq; | using System.Linq; | ||||||
|  | @ -19,5 +20,12 @@ namespace AideDeJeu.Views | ||||||
| 
 | 
 | ||||||
|             BindingContext = DependencyService.Get<BookmarksViewModel>(); |             BindingContext = DependencyService.Get<BookmarksViewModel>(); | ||||||
| 		} | 		} | ||||||
|  | 
 | ||||||
|  |         private async void ItemsListView_ItemTapped(object sender, ItemTappedEventArgs e) | ||||||
|  |         { | ||||||
|  |             var item = e.Item as LinkItem; | ||||||
|  |             var Main = DependencyService.Get<MainViewModel>(); | ||||||
|  |             await Main.Navigator.NavigateToLinkAsync(item.Link); | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Yan Maniez
						Yan Maniez