package eg;

//--Eadgyth--/
import eg.edittools.AddableEditTool;
import eg.document.FileDocument;
import eg.ui.MainWin;

/**
 * Holds objects that need to be updated when the viewed document
 * changes or when a new file is assigned to the viewed document
 */
public class DocumentUpdate {

   private final MainWin mw;
   private final Edit edit;
   private final CurrentProject currProj;
   private final FileDocument[] fDoc;

   /**
    * @param mw  the reference to {@link MainWin}
    * @param fDoc  the array of {@link FileDocument}
    */
   public DocumentUpdate(MainWin mw, FileDocument[] fDoc) {
      this.mw = mw;
      this.fDoc = fDoc;
      edit = new Edit();
      currProj = new CurrentProject(mw, fDoc);
      mw.setEditTextActions(edit);
      mw.setProjectActions(currProj);
   }

   /**
    * Does updates when the viewed document changes
    *
    * @param i  the index of the element in this <code>FileDocument</code>
    * array
    * @param nTabs  the number of open tabs
    */
   public void updateForChangedDoc(int i, int nTabs) {
      edit.setFileDocument(fDoc[i]);
      currProj.setFileDocumentAt(i);
      mw.editTools().forEach((t) -> {
         t.setFileDocument(fDoc[i]);
      });
      mw.displayFrameTitle(fDoc[i].filepath());
      mw.enableShowTabbar(nTabs == 1);
      mw.setLanguageSelected(fDoc[i].language(), fDoc[i].filename().length() == 0);
      fDoc[i].setFocused();
   }

   /**
    * Does updates when a new file is assigned to the viewed document
    *
    * @param i  the index of the element in this <code>FileDocument</code>
    * array
    * @param updateFiletree  if the file tree needs to be updated
    */
   public void updateForChangedFile(int i, boolean updateFiletree) {
      retrieveProject(i);
      mw.setLanguageSelected(fDoc[i].language(), false);
      mw.displayFrameTitle(fDoc[i].filepath());
      if (updateFiletree) {
         currProj.updateFileTree();
      }
   }

   //
   //--private--/
   //

   private void retrieveProject(int i) {
      currProj.setFileDocumentAt(i);
      currProj.retrieveProject();
   }
}

@@ -20,16 +20,17 @@
 dgyth--/
+/
 %0Aimport 
@@ -1735,16 +1735,62 @@
 %7B%0A      
+currProj.setFileDocumentAt(i);%0A      currProj.
 retrieve
@@ -1797,17 +1797,16 @@
 Project(
-i
 );%0A     
@@ -1985,156 +1985,7 @@
    %7D
-%0A%0A   //%0A   //--private--/%0A   //%0A%0A   private void retrieveProject(int i) %7B%0A      currProj.setFileDocumentAt(i);%0A      currProj.retrieveProject();%0A   %7D
 %0A%7D%0A

remove unnecessary method