Not only your schema is ugly,
it won't really work at all, because it will lead to duplicates, if a user closes not the last file.
You can use the following: increment the number every time, per file name. You only need to have unique identification of file buffers, not really a continues set of numbers. If the user removes some number less then the last one, do the same. For example, you have 1, 2, 3, 4. The user removes 2. You have 1, 3, 4. Then you add one more copy of the same file. Make it 1, 3, 4, 5. Then number 2 will keep missing. In all example, I take into account only the numbers per one full file name, of for all these numbers.
But! On each file closed by the user, do the following: check up if it closes all of the copies of some file. In this case, your counter will be reset to, say 1. Probably you should not show this 1 until you have 2. That solves the problem.
To support the schema of mapping the files and numbers of their copies, use the dictionary like
System.Collections.Generic.Dictionary<string, FileCopyDescriptor>
, where
FileCopyDescriptor
can be some data class storing the copy number and reference to the file buffer object or its form. But don't go with forms. Keep reading…
Here is the idea: who needs MDI, ever? Why torturing yourself and scaring off your users?
Do yourself a great favor: do not use MDI at all. You can do much easier to implement design without it, with much better quality. MDI is highly discouraged even by Microsoft, in fact, Microsoft dropped it out of WPF and will hardly support it. More importantly, you will scare off all your users if you use MDI. Just don't. Please see:
http://en.wikipedia.org/wiki/Multiple_document_interface#Disadvantages[
^],
How to Create MDI Parent Window in WPF?[
^].
I can explain what to do instead. Please see my past answers:
How to Create MDI Parent Window in WPF? [
Solution 2],
Question on using MDI windows in WPF[
^],
MDIContainer giving error[
^],
How to set child forms maximized, last childform minimized[
^].
—SA