fix: account display order is now tracked across all files (fix #1909)
This commit is contained in:
		
							parent
							
								
									3b34987bdd
								
							
						
					
					
						commit
						09d66c5fc1
					
				| @ -199,7 +199,9 @@ instance Show Journal where | |||||||
| -- Note that (<>) is right-biased, so nulljournal is only a left identity. | -- Note that (<>) is right-biased, so nulljournal is only a left identity. | ||||||
| -- In particular, this prevents Journal from being a monoid. | -- In particular, this prevents Journal from being a monoid. | ||||||
| instance Semigroup Journal where | instance Semigroup Journal where | ||||||
|   j1 <> j2 = Journal { |   j1 <> j2 = | ||||||
|  |     journalRenumberAccountDeclarations $ | ||||||
|  |     Journal { | ||||||
|      jparsedefaultyear          = jparsedefaultyear          j2 |      jparsedefaultyear          = jparsedefaultyear          j2 | ||||||
|     ,jparsedefaultcommodity     = jparsedefaultcommodity     j2 |     ,jparsedefaultcommodity     = jparsedefaultcommodity     j2 | ||||||
|     ,jparsedecimalmark          = jparsedecimalmark          j2 |     ,jparsedecimalmark          = jparsedecimalmark          j2 | ||||||
| @ -226,6 +228,14 @@ instance Semigroup Journal where | |||||||
|     ,jlastreadtime              = max (jlastreadtime j1) (jlastreadtime j2) |     ,jlastreadtime              = max (jlastreadtime j1) (jlastreadtime j2) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | -- | Renumber all the account declarations. Call this after combining two journals into one, | ||||||
|  | -- so that account declarations have a total order again. | ||||||
|  | journalRenumberAccountDeclarations :: Journal -> Journal | ||||||
|  | journalRenumberAccountDeclarations j = j{jdeclaredaccounts=jdas'} | ||||||
|  |   where | ||||||
|  |     jdas' = [(a, adi{adideclarationorder=n}) | (n, (a,adi)) <- zip [1..] $ jdeclaredaccounts j] | ||||||
|  |     -- XXX the per-file declaration order saved during parsing is discarded; it seems unneeded | ||||||
|  | 
 | ||||||
| instance Default Journal where | instance Default Journal where | ||||||
|   def = nulljournal |   def = nulljournal | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -401,6 +401,9 @@ addAccountDeclaration (a,cmt,tags) = | |||||||
|                               adicomment          = cmt |                               adicomment          = cmt | ||||||
|                              ,aditags             = tags |                              ,aditags             = tags | ||||||
|                              ,adideclarationorder = length decls + 1 |                              ,adideclarationorder = length decls + 1 | ||||||
|  |                                -- this restarts from 1 in each file, which is not that useful | ||||||
|  |                                -- when there are multiple files; so it gets renumbered | ||||||
|  |                                -- automatically when combining Journals with <> | ||||||
|                              }) |                              }) | ||||||
|              in |              in | ||||||
|                j{jdeclaredaccounts = d:decls}) |                j{jdeclaredaccounts = d:decls}) | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user