    001package org.vishia.commander;
    002
    003import java.io.BufferedReader;
    004import java.io.File;
    005import java.io.FileNotFoundException;
    006import java.io.FileReader;
    007import java.io.IOException;
    008import java.util.Iterator;
    009import java.util.LinkedList;
    010import java.util.List;
    011import java.util.ListIterator;
    012import java.util.Map;
    013
    014import org.vishia.fileRemote.FileCluster;
    015import org.vishia.fileRemote.FileRemote;
    016import org.vishia.gral.base.GralPos;
    017import org.vishia.gral.base.GralWidget;
    018import org.vishia.gral.base.GralMng;
    019import org.vishia.gral.base.GralTabbedPanel;
    020import org.vishia.gral.base.GralWindow;
    021import org.vishia.gral.ifc.GralColor;
    022import org.vishia.gral.ifc.GralTextField_ifc;
    023import org.vishia.gral.ifc.GralUserAction;
    024import org.vishia.gral.ifc.GralWidget_ifc;
    025import org.vishia.gral.ifc.GralWindow_ifc;
    026import org.vishia.gral.widget.GralFileSelector;
    027import org.vishia.mainCmd.MainCmd_ifc;
    028import org.vishia.util.FileWriter;
    029import org.vishia.util.KeyCode;
    030import org.vishia.util.StringPart;
    031
    032/**This class implements the selection functionality of tabs and paths for the whole Java commander.
    033 * It contains all actions which are instantiated one time but affects a special (the current) file panel.
    034 * */
    035class FcmdFavorPathSelector
    036{
    037
    038  /**Version, history and license:
    039   * <ul>
    040   * <li>2012-03-09 Hartmut new menu entry menuBarFolderSync
    041   * <li>2012-02-04 Hartmut new menu entries for refresh and origin dir
    042   * </ul>
    043   *
    044   *
    045   * <b>Copyright/Copyleft</b>:
    046   * For this source the LGPL Lesser General Public License,
    047   * published by the Free Software Foundation is valid.
    048   * It means:
    049   * <ol>
    050   * <li> You can use this source without any restriction for any desired purpose.
    051   * <li> You can redistribute copies of this source to everybody.
    052   * <li> Every user of this source, also the user of redistribute copies
    053   *    with or without payment, must accept this license for further using.
    054   * <li> But the LPGL ist not appropriate for a whole software product,
    055   *    if this source is only a part of them. It means, the user
    056   *    must publish this part of source,
    057   *    but don't need to publish the whole source of the own product.
    058   * <li> You can study and modify (improve) this source
    059   *    for own using or for redistribution, but you have to license the
    060   *    modified sources likewise under this LGPL Lesser General Public License.
    061   *    You mustn't delete this Copyright/Copyleft inscription in this source file.
    062   * </ol>
    063   * If you are intent to use this sources without publishing its usage, you can get
    064   * a second license subscribing a special contract with the author.
    065   *
    066   * @author Hartmut Schorrig = hartmut.schorrig@vishia.de
    067   */
    068  public static final int version = 0x20120204;
    069
    070  /**Entry in the favorite list. */
    071  static class FavorPath
    072  { /**The path of directory to select. */
    073    final String path;
    074    /**The name shown in the list. */
    075    final String selectName;
    076
    077    final FileCluster fileCluster;
    078    /**The label on the tab in tabbed panel. */
    079    //String label;
    080    /**bit 0..2 present this favorite on the designated main panel 1..3 or l, m, r,
    081     * it means, a tab with the label will be created. */
    082    int mMainPanel;
    083
    084    /**Origin dir adequate {@link #path}. It is null on initialization, but build on call of
    085     * {@link #getOriginDir()}. */
    086    private FileRemote dir;
    087
    088    public FavorPath(String selectName, String path, FileCluster fileCluster)
    089    { this.fileCluster = fileCluster;
    090      this.path = path;
    091      this.selectName = selectName;
    092    }
    093
    094
    095    /**Returns the dir instance for the origin path. The dir instance is built only one time
    096     * but only if it is necessary. It means it is built on the first call of this method.
    097     * @return
    098     */
    099    public FileRemote getOriginDir(){
    100      if(dir == null){ //build it only one time, but only if it is necessary.
    101        dir = fileCluster.getFile(path, null);  //new FileRemote(path);
    102      }
    103      return dir;
    104    }
    105
    106
    107    @Override public String toString(){ return path; } //for debug
    108  }
    109
    110
    111  static class FavorFolder
    112  {
    113    /**The label on the tab in tabbed panel. */
    114    final String label;
    115    /**The name shown in the list. */
    116    final String selectNameTab;
    117    /**The associated list of selectInfos. */
    118    final List<FavorPath> listfavorPaths = new LinkedList<FavorPath>();
    119    /**bit 0..2 present this favorite on the designated main panel 1..3 or l, m, r,
    120     * it means, a tab with the label will be created. */
    121    int mMainPanel;
    122
    123    public FavorFolder(String label, String selectNameTab)
    124    { this.label = label;
    125      this.selectNameTab = selectNameTab;
    126    }
    127
    128    @Override public String toString(){ return label; } //for debug
    129
    130  }
    131
    132  /**All entries for the select list for all favorite path folders in the order of the configuration file.
    133   * The elements of this list can be activated to present in cards with tabs. The cards contain the favor paths
    134   * which are contained in {@link FcmdFavorPathSelector.FavorFolder#listfavorPaths}.
    135   * But not all elements should be activated similar in all panels, it may be too much tabs per panel.
    136   * */
    137  List<FcmdFavorPathSelector.FavorFolder> listAllFavorPathFolders = new LinkedList<FcmdFavorPathSelector.FavorFolder>();
    138
    139
    140  File fileCfg;
    141
    142  /**Instance to write the cfgFile. */
    143  FileWriter writerCfg = new FileWriter();
    144
    145  /**The three tabbed panels. */
    146  final FcmdLeftMidRightPanel panelLeft, panelMid, panelRight;
    147
    148  GralFileSelector.WindowConfirmSearch windSearchFiles;
    149
    150  private final GralMng mng;
    151
    152  final Fcmd main;
    153
    154  /**All entries which are shown in all three select lists. */
    155  List<FavorPath> listAllFavorPaths = new LinkedList<FavorPath>();
    156
    157  /**For output messages. */
    158  final MainCmd_ifc console;
    159
    160
    161  /**The last selected SelectInfo. */
    162  FavorPath actFavorPathInfo;
    163
    164  boolean bSyncMidRight;
    165
    166
    167  static class WindowConfirmAddFavorite
    168  {
    169    /**The window for confirming adding a new favorite. */
    170    GralWindow_ifc window;
    171
    172    /**The panel from where the window was opened. It helps to get the current selected line in favorites. */
    173    FcmdLeftMidRightPanel panelInvocation;
    174
    175    /**The short name input field in window confirm add favorite.  */
    176    GralTextField_ifc widgShortName;
    177    /**The tab input field in window confirm add favorite.  */
    178    GralTextField_ifc widgLabel;
    179    /**The path input field in window confirm add favorite.  */
    180    GralTextField_ifc widgPath;
    181    /**A field where "lmr" may be written to make the tab persistent.  */
    182    GralTextField_ifc widgPersistent;
    183  }
    184
    185  WindowConfirmAddFavorite windAddFavorite = new WindowConfirmAddFavorite();
    186
    187  FcmdFavorPathSelector(MainCmd_ifc console, Fcmd main)
    188  { this.main = main;
    189    this.console = console;
    190    this.mng = main._gralMng;
    191    panelLeft = new FcmdLeftMidRightPanel(main, 'l', '1', mng);
    192    panelMid = new FcmdLeftMidRightPanel(main, 'm','2',  mng);
    193    panelRight = new FcmdLeftMidRightPanel(main,'r', '3',  mng);
    194
    195  }
    196
    197
    198
    199
    200
    201  /**Builds the content of the add-favorite window. The window is created static. It is shown
    202   * whenever it is used.  */
    203  void buildWindowAddFavorite(){
    204
    205    windSearchFiles = GralFileSelector.createWindowConfirmSearchGthread(mng);
    206
    207    //main.gui.addMenuItemGThread("menuFileNaviRefresh", main.idents.menuFileNaviRefreshBar, actionRefreshFileTable); // /
    208    //main.gui.addMenuItemGThread("menubarFolderCreate", main.idents.menuConfirmMkdirFileBar, main.mkCmd.actionOpenDialog); // /
    209    //main.gui.addMenuItemGThread("menubarFolderSearch", main.idents.menuBarSearchFiles, actionSearchFiles); // /
    210    main.gui.addMenuBarArea9ItemGThread("menuBarFolderSyncMidRight", main.idents.menuBarFolderSyncMidRight, actionSyncMidRight); // /
    211    //main.gui.addMenuItemGThread("menubarFileProps", main.idents.menuFilePropsBar, main.filePropsCmd.actionOpenDialog);
    212    //main.gui.addMenuItemGThread("test", main.idents.menuFileViewBar, main.viewCmd.actionOpenView);
    213    //main.gui.addMenuItemGThread("test", main.idents.menuFileEditBar, main.actionEdit);
    214    //main.gui.addMenuItemGThread("test", main.idents.menuBarEditIntern, main.editWind.actionOpenEdit);
    215    //main.gui.addMenuItemGThread("test", main.idents.menuConfirmCopyBar, main.copyCmd.actionConfirmCopy);
    216    //main.gui.addMenuItemGThread("test", main.idents.menuConfirmFileDelBar, main.deleteCmd.actionConfirmDelete);
    217    //main.gui.addMenuItemGThread("test", main.idents.menuExecuteBar, main.executer.actionExecuteFileByExtension);
    218    //main.gui.addMenuItemGThread("test", main.idents.menuExecuteCmdBar, main.cmdSelector.actionExecCmdWithFiles);
    219
    220    main.gui.addMenuBarArea9ItemGThread("menuBarCreateFavor", main.idents.menuBarCreateFavor, actionCreateFavor); // /
    221    main.gui.addMenuBarArea9ItemGThread("menuDelTab", main.idents.menuDelTab, actionDelTab); // /
    222    main.gui.addMenuBarArea9ItemGThread("menuSaveFavoriteSel", main.idents.menuSaveFavoriteSel, actionSaveFavoritePathes); // /
    223    main.gui.addMenuBarArea9ItemGThread("menuReadFavoriteSel", main.idents.menuReadFavoriteSel, actionReadFavoritePathes); // /
    224
    225
    226
    227    main._gralMng.selectPanel("primaryWindow"); //"output"); //position relative to the output panel
    228    //panelMng.setPosition(1, 30+GralGridPos.size, 1, 40+GralGridPos.size, 1, 'r');
    229    main._gralMng.setPosition(-19, 0, -47, 0, 1, 'r'); //right buttom, about half less display width and hight.
    230
    231
    232    windAddFavorite.window = main._gralMng.createWindow("addFavoriteWindow", "add favorite", GralWindow.windConcurrently);
    233
    234    main._gralMng.setPosition(4, GralPos.size -4, 1, GralPos.size +34, 0, 'r');
    235    windAddFavorite.widgLabel = main._gralMng.addTextField("addFavoriteTab", true, "label", "t");
    236    windAddFavorite.widgLabel.setHtmlHelp(main.cargs.dirHtmlHelp + "/Fcmd.html#Topic.FcmdHelp.favorpath.favorNew.tab.");
    237    main._gralMng.setPosition(4, GralPos.size -4, 35, GralPos.size +10, 0, 'r');
    238    windAddFavorite.widgPersistent = main._gralMng.addTextField("addFavoriteTab", true, "lmr ?", "t");
    239    windAddFavorite.widgLabel.setHtmlHelp(main.cargs.dirHtmlHelp + "/Fcmd.html#Topic.FcmdHelp.favorpath.favorNew.persist.");
    240
    241    main._gralMng.setPosition(8, GralPos.size -4, 1, GralPos.size +45, 0, 'd');
    242    windAddFavorite.widgShortName = main._gralMng.addTextField("addFavoriteAlias", true, "alias (show in list)", "t");
    243    windAddFavorite.widgShortName.setHtmlHelp(main.cargs.dirHtmlHelp + "/Fcmd.html#Topic.FcmdHelp.favorpath.favorNew.alias.");
    244    windAddFavorite.widgPath = main._gralMng.addTextField("addFavoritePath", true, "the directory path", "t");
    245    windAddFavorite.widgPath.setHtmlHelp(main.cargs.dirHtmlHelp + "/Fcmd.html#Topic.FcmdHelp.favorpath.favorNew.dir.");
    246
    247    main._gralMng.setPosition(-4, -1, 1, 6, 0, 'r');
    248    main._gralMng.addButton("addFavoriteEsc", actionAddFavorite, "esc", null, "esc");
    249    main._gralMng.setPosition(-4, -1, -14, GralPos.size +6, 0, 'r',1);
    250    GralWidget widg = main._gralMng.addButton("addFavoriteOk", actionAddFavorite, "temp", null, "temp");
    251    widg.setHtmlHelp(main.cargs.dirHtmlHelp + "/Fcmd.html#Topic.FcmdHelp.favorpath.favorNew.temp.");
    252    widg = main._gralMng.addButton("addFavoriteOk", actionAddFavorite, "ok", null, "Save");
    253    widg.setHtmlHelp(main.cargs.dirHtmlHelp + "/Fcmd.html#Topic.FcmdHelp.favorpath.favorNew.save.");
    254
    255  }
    256
    257
    258
    259
    260
    261
    262  /**Read the configuration file. It is called on startup of the Java commander.
    263   * @param cfgFile
    264   * @return an error message to output or null
    265   */
    266  String readCfg(File cfgFile)
    267  { this.fileCfg = cfgFile;
    268    String sError = null;
    269    BufferedReader reader = null;
    270    try{
    271      reader = new BufferedReader(new FileReader(cfgFile));
    272    } catch(FileNotFoundException exc){ sError = "TabSelector - cfg file not found; " + cfgFile; }
    273    if(reader !=null){
    274      try{
    275        listAllFavorPathFolders.clear();
    276        String sLine;
    277        int posSep;
    278        //List<FavorPath> list = null;
    279        FcmdFavorPathSelector.FavorFolder favorTabInfo = null;
    280        StringPart spLine = new StringPart();
    281        StringBuilder uLine = new StringBuilder(1000);
    282        //boolean bAll = true;
    283        while( sError == null && (sLine = reader.readLine()) !=null){
    284          if(sLine.contains("$")){
    285            uLine.append(sLine.trim());
    286            spLine.assignReplaceEnv(uLine);
    287            sLine = uLine.toString();
    288          } else {
    289            sLine = sLine.trim();
    290            spLine.assign(sLine);
    291          }
    292          if(sLine.length() >0){
    293            if( sLine.startsWith("==")){
    294              posSep = sLine.indexOf("==", 2);
    295              //a new division
    296              final String sDiv = sLine.substring(2,posSep).trim();
    297              final int pos1 = sDiv.indexOf(':');
    298              final String sLabel = pos1 >=0 ? sDiv.substring(0, pos1).trim() : sDiv;
    299              final int pos2 = sDiv.indexOf(',');
    300              //sDivText is the same as sLabel if pos1 <0
    301              final String sDivText = pos2 >=0 ? sDiv.substring(pos1+1, pos2).trim() : sDiv.substring(pos1+1).trim();
    302              final String sSelect = pos2 >=0 ? sDiv.substring(pos2): "";
    303              favorTabInfo = null; //selectListOverview.get(sDiv);
    304              if(favorTabInfo == null){
    305                favorTabInfo = new FcmdFavorPathSelector.FavorFolder(sLabel, sDivText);
    306                if(sSelect.indexOf('l')>=0){ favorTabInfo.mMainPanel |=1;}
    307                if(sSelect.indexOf('m')>=0){ favorTabInfo.mMainPanel |=2;}
    308                if(sSelect.indexOf('r')>=0){ favorTabInfo.mMainPanel |=4;}
    309                listAllFavorPathFolders.add(favorTabInfo);
    310              }
    311              ///
    312              /*
    313              if(sDiv.equals("left")){ list = panelLeft.selectListAllFavorites; }
    314              else if(sDiv.equals("mid")){ list = panelMid.selectListAllFavorites; }
    315              else if(sDiv.equals("right")){ list = panelRight.selectListAllFavorites; }
    316              else if(sDiv.equals("all")){ list = selectAll; }
    317              else { sError = "Error in cfg file: ==" + sDiv + "=="; }
    318              */
    319            } else if(favorTabInfo !=null){
    320              String[] sParts = sLine.trim().split(",");
    321              if(sParts.length < 2){
    322                sError = "SelectTab format error; " + sLine;
    323              } else {
    324                //info. = sParts[0].trim();
    325                String selectName = sParts[0].trim();
    326                String path = sParts[1].trim();
    327                FavorPath favorPathInfo = new FavorPath(selectName, path, main.fileCluster);
    328                if(sParts.length >2){
    329                  final String actTabEntry = sParts[2].trim();
    330                  //final String actTab;
    331                  /*
    332                  final int posColon = actTabEntry.indexOf(':');
    333                  if(posColon >0){
    334                    String sPanelChars = actTabEntry.substring(0, posColon);
    335                    actTab = actTabEntry.substring(posColon+1).trim();
    336                    if(sPanelChars.indexOf('l')>=0){ info.mMainPanel |= 1; }
    337                    if(sPanelChars.indexOf('m')>=0){ info.mMainPanel |= 2; }
    338                    if(sPanelChars.indexOf('r')>=0){ info.mMainPanel |= 4; }
    339                  } else {
    340                    actTab = actTabEntry.trim();
    341                  }
    342                  info.label = actTab;
    343                  */
    344                }
    345                //info.active = cActive;
    346                //list.add(info);
    347                favorTabInfo.listfavorPaths.add(favorPathInfo);
    348              }
    349            }
    350          }
    351          uLine.setLength(0);
    352        }//while
    353        spLine.close();
    354      }
    355      catch(IOException exc){ sError = "selectTab - cfg file read error; " + cfgFile; }
    356      catch(IllegalArgumentException exc){ sError = "selectTab - cfg file error; " + cfgFile + exc.getMessage(); }
    357      catch(Exception exc){ sError = "selectTab - any exception; " + cfgFile + exc.getMessage(); }
    358      try{ reader.close(); reader = null; } catch(IOException exc){} //close is close.
    359    }
    360    return sError;
    361  }
    362
    363
    364  /**Writes the configuration file. It is called if the configuration should be stored after user invocation.
    365   * @param cfgFile
    366   * @return an error message to output or null
    367   */
    368  void writeCfg(File cfgFile)
    369  { boolean bOk = true;
    370    if(cfgFile.exists()){
    371
    372      String sName = cfgFile.getName() + ".old";
    373      File cfgFileOld = new File(cfgFile.getParentFile(), sName);
    374      if(cfgFileOld.exists()){
    375        bOk = cfgFileOld.delete();
    376        if(!bOk){
    377          main.mainCmd.writeError("can't delete " + cfgFileOld.getAbsolutePath());
    378        }
    379      }
    380      if(bOk){
    381        bOk = cfgFile.renameTo(cfgFileOld);
    382        if(!bOk){
    383          main.mainCmd.writeError("can't rename " + cfgFile.getAbsolutePath());
    384        }
    385      }
    386    }
    387    if(bOk){
    388      bOk = writerCfg.open(cfgFile.getAbsolutePath(), false) ==0;
    389    }
    390    if(bOk){
    391      try{
    392        for(FcmdFavorPathSelector.FavorFolder folder: listAllFavorPathFolders){
    393          writerCfg.append("==").append(folder.label).append(": ").append(folder.selectNameTab);
    394          if((folder.mMainPanel & 7)!=0){ writerCfg.append(", "); }
    395          if((folder.mMainPanel & 1)!=0){ writerCfg.append('l'); }
    396          if((folder.mMainPanel & 2)!=0){ writerCfg.append('m'); }
    397          if((folder.mMainPanel & 4)!=0){ writerCfg.append('r'); }
    398          writerCfg.append("==\n");
    399          for(FavorPath favor: folder.listfavorPaths){
    400            writerCfg.append(favor.selectName).append(", ").append(favor.path).append("\n");
    401          }
    402          writerCfg.append("\n");
    403
    404        }
    405      }
    406      catch(IOException exc){
    407        main.mainCmd.writeError("error writing" , exc);
    408      }
    409    }
    410    writerCfg.close();
    411  }
    412
    413
    414
    415  private void XXXwriteCfgLine(FavorPath favorPathInfo) throws IOException
    416  {
    417    writerCfg.append(favorPathInfo.selectName).append(", ").append(favorPathInfo.path);
    418    /*
    419    if(info.label !=null && info.label.length()>0){
    420      writerCfg.append(", ");
    421      if((info.mMainPanel & 1)!=0){ writerCfg.append('l'); }
    422      if((info.mMainPanel & 2)!=0){ writerCfg.append('m'); }
    423      if((info.mMainPanel & 4)!=0){ writerCfg.append('r'); }
    424      if((info.mMainPanel & 7)!=0){ writerCfg.append(": "); }
    425      writerCfg.append(info.label);
    426    }
    427    */
    428      writerCfg.append("\n");
    429  }
    430
    431
    432
    433
    434  void initActDir(Map<String, File> index, String key, String path)
    435  {
    436    if(index.get(key) == null){
    437      index.put(key, new File(path));
    438    }
    439  }
    440
    441
    442
    443  /**Builds a tab for file or command view from a selected line of selection.
    444   * @param info The selection info
    445   */
    446  void buildTabFromSelection(FcmdFavorPathSelector.FavorPath info, GralTabbedPanel tabPanel)
    447  { assert(false);
    448    /*
    449    tabPanel.addGridPanel(info.tabName1, info.tabName1,1,1,10,10);
    450    mng.setPosition(0, 0, 0, -0, 1, 'd'); //the whole panel.
    451    FileSelector fileSelector = new FileSelector("fileSelector-"+info.tabName1, mng);
    452    fileSelector.setActionOnEnterFile(main.executer.actionExecute);
    453    main.idxFileSelector.put(info.tabName1, fileSelector);
    454    fileSelector.setToPanel(mng, info.tabName1, 5, new int[]{2,20,5,10}, 'A');
    455    fileSelector.fillIn(new File(info.path));
    456    */
    457  }
    458
    459
    460
    461
    462  protected void setSortOrderFiles(char order){
    463    FcmdFileCard fileCard = main.getLastSelectedFileCard();
    464    if(fileCard !=null){
    465      fileCard.setSortOrder(order);
    466      fileCard.fillInCurrentDir();
    467    }
    468  }
    469
    470
    471
    472  void stop(){}
    473
    474
    475  GralUserAction actionSearchFiles = new GralUserAction("actionSearchFiles"){
    476    @Override public boolean userActionGui(int key, GralWidget widgd, Object... params){
    477      if(KeyCode.isControlFunctionMouseUpOrMenu(key)){
    478        FcmdFileCard fileCard = main.lastFavorCard.fileTable;
    479        windSearchFiles.confirmSearchInFiles(fileCard, main.gui.getOutputBox());
    480      }
    481      return true;
    482  } };
    483
    484
    485
    486  GralUserAction actionSyncMidRight = new GralUserAction(""){
    487    @Override public boolean userActionGui(int key, GralWidget widgd, Object... params){
    488      if(KeyCode.isControlFunctionMouseUpOrMenu(key)){
    489        bSyncMidRight = ! bSyncMidRight;
    490        if(bSyncMidRight){
    491          main.statusLine.widgSyncInfo.setBackColor(GralColor.getColor("gn"),0);
    492          main.statusLine.widgSyncInfo.setText("sync mid-right");
    493        } else {
    494          main.statusLine.widgSyncInfo.setBackColor(GralColor.getColor("wh"),0);
    495          main.statusLine.widgSyncInfo.setText("");
    496        }
    497      }
    498      return true;
    499  } };
    500
    501
    502
    503  void confirmCreateNewFavor(){
    504    FcmdLeftMidRightPanel panel = main.lastFilePanels.get(0);
    505    FcmdFileCard fileCard = panel.actFileCard;
    506    windAddFavorite.panelInvocation = panel;
    507    windAddFavorite.widgLabel.setText(fileCard.label);
    508    windAddFavorite.widgShortName.setText("alias");
    509    File directory = fileCard.getCurrentDir();
    510    //String pathDir = FileSystem.getCanonicalPath(lastSelectedFile.getParentFile());
    511    windAddFavorite.widgPath.setText(directory.getPath());
    512    windAddFavorite.window.setFocus(); //WindowVisible(true);
    513
    514  }
    515
    516
    517  GralUserAction actionCreateFavor = new GralUserAction(""){
    518    @Override public boolean userActionGui(int key, GralWidget widgd, Object... params){
    519      if(KeyCode.isControlFunctionMouseUpOrMenu(key)){
    520        confirmCreateNewFavor();
    521      }
    522    return true;
    523  } };
    524
    525
    526
    527
    528  GralUserAction actionDelTab = new GralUserAction(""){
    529    @Override public boolean userActionGui(int key, GralWidget widgd, Object... params){
    530      if(main.lastFavorCard !=null){
    531        FcmdFavorCard favorCard = main.lastFavorCard;
    532        FcmdFileCard fileCard = favorCard.fileTable;
    533        FcmdLeftMidRightPanel panel = fileCard.mainPanel;
    534        if(fileCard !=null){
    535          fileCard.remove();
    536          panel.actFileCard = null;
    537          panel.listTabs.remove(fileCard);
    538        }
    539        String nameWidgFavorCard = FcmdWidgetNames.tabFavorites + fileCard.nameFilePanel;
    540        String nameWidgFileCard = FcmdWidgetNames.tabFile + fileCard.nameFilePanel;
    541        panel.tabbedPanelFavorCards.removePanel(nameWidgFavorCard);
    542        panel.tabbedPanelFileCards.removePanel(nameWidgFileCard);
    543        panel.cardFavorThemes.setFocus();
    544      }
    545      return true;
    546  } };
    547
    548
    549  /**Sets the origin dir of the last focused file table.
    550   * <br>
    551   * Implementation note: The last focused file tab is searched using {@link Fcmd#getLastSelectedFileCards()}.
    552   */
    553  GralUserAction actionSetDirOrigin = new GralUserAction(""){
    554    @Override public boolean userActionGui(int key, GralWidget widgd, Object... params)
    555    { if(KeyCode.isControlFunctionMouseUpOrMenu(key)){
    556        GralFileSelector lastTab = main.getLastSelectedFileCards()[0];
    557        if(lastTab !=null){
    558          lastTab.fillInOriginDir();
    559        } else {
    560          throw new IllegalArgumentException("last file tab not able to found");
    561        }
    562        return true;
    563      } else return false;
    564    }
    565  };
    566
    567
    568
    569  /**Sets the origin dir of the last focused file table.
    570   * <br>
    571   * Implementation note: The last focused file tab is searched using {@link Fcmd#getLastSelectedFileCards()}.
    572   */
    573  GralUserAction actionRefreshFileTable = new GralUserAction(""){
    574    @Override public boolean userActionGui(int key, GralWidget widgd, Object... params){
    575      if(KeyCode.isControlFunctionMouseUpOrMenu(key)){  //supress both mouse up and down reaction
    576      FcmdFileCard lastTab = main.getLastSelectedFileCards()[0];
    577      if(lastTab !=null){
    578        FileRemote dir = lastTab.getCurrentDir();
    579        if(dir !=null){
    580          lastTab.forcefillIn(dir, false);
    581        }
    582      } else {
    583        System.out.println("No filetable found to refresh");
    584        //throw new IllegalArgumentException("last file tab not able to found");
    585      }
    586      return true;
    587      } else return false;
    588    }
    589  };
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599  GralUserAction actionAddFavorite = new GralUserAction("")
    600  { @Override public boolean userActionGui(int key, GralWidget infos, Object... params)
    601    { if(KeyCode.isControlFunctionMouseUpOrMenu(key)){
    602        if(infos.sCmd.equals("ok") || infos.sCmd.equals("temp")){
    603          String path = windAddFavorite.widgPath.getText();
    604          String selectName = windAddFavorite.widgShortName.getText();
    605          FavorPath favorite = new FavorPath(selectName, path, main.fileCluster);
    606          String tablabel = windAddFavorite.widgLabel.getText();
    607          favorite.mMainPanel = 1<< (windAddFavorite.panelInvocation.cNr - '1');
    608          FcmdFavorPathSelector.FavorFolder tabDst = null;
    609          for(FcmdFavorPathSelector.FavorFolder tab:listAllFavorPathFolders){ //note: used break in loop
    610            if(tab.label.equals(tablabel)){
    611              tabDst = tab;
    612              break;
    613            }
    614          }
    615          if(tabDst == null){
    616            //its a new tab
    617            tabDst = new FcmdFavorPathSelector.FavorFolder(tablabel, tablabel);
    618            listAllFavorPathFolders.add(tabDst);
    619          }
    620          tabDst.listfavorPaths.add(favorite);
    621          windAddFavorite.panelInvocation.fillCards();
    622          ///
    623          if(infos.sCmd.equals("ok")){
    624            writeCfg(fileCfg);
    625          }
    626        }
    627        windAddFavorite.window.setVisible(false);
    628      }
    629      return true;
    630    }
    631  };
    632
    633
    634
    635
    636  GralUserAction actionSaveFavoritePathes = new GralUserAction("")
    637  { @Override public boolean userActionGui(int key, GralWidget infos, Object... params)
    638    { writeCfg(fileCfg);
    639      return true;
    640  } };
    641
    642
    643  GralUserAction actionReadFavoritePathes = new GralUserAction("")
    644  { @Override public boolean exec(int key, GralWidget_ifc widg, Object... params) {
    645      readCfg(fileCfg);
    646      panelLeft.fillCards();
    647      panelMid.fillCards();
    648      panelRight.fillCards();
    649      return true;
    650  } };
    651
    652
    653
    654  /**Sort action. Note that the sort action is contained in the {@link GralFileSelector}
    655   * already. But this sort action is available from menu of the Fcmd too. It is some different.
    656   */
    657  GralUserAction actionSortFilePerNameCase = new GralUserAction("")
    658  { @Override public boolean userActionGui(int key, GralWidget infos, Object... params) {
    659      setSortOrderFiles(GralFileSelector.kSortName);
    660      return true;
    661  } };
    662
    663
    664
    665
    666  GralUserAction actionSortFilePerNameNonCase = new GralUserAction("")
    667  { @Override public boolean userActionGui(int key, GralWidget infos, Object... params) {
    668      setSortOrderFiles(GralFileSelector.kSortNameNonCase);
    669      return true;
    670  } };
    671
    672
    673
    674
    675  GralUserAction actionSortFilePerExtensionCase = new GralUserAction("")
    676  { @Override public boolean userActionGui(int key, GralWidget infos, Object... params) {
    677      setSortOrderFiles(GralFileSelector.kSortExtension);
    678      return true;
    679  } };
    680
    681
    682  GralUserAction actionSortFilePerExtensionNonCase = new GralUserAction("")
    683  { @Override public boolean userActionGui(int key, GralWidget infos, Object... params) {
    684      setSortOrderFiles(GralFileSelector.kSortExtensionNonCase);
    685      return true;
    686  } };
    687
    688
    689
    690
    691
    692  GralUserAction actionSortFilePerTimestamp = new GralUserAction("")
    693  { @Override public boolean userActionGui(int key, GralWidget infos, Object... params) {
    694      setSortOrderFiles(GralFileSelector.kSortDateNewest);
    695      return true;
    696  } };
    697
    698
    699
    700
    701  GralUserAction actionSortFilePerTimestampOldestFirst = new GralUserAction("")
    702  { @Override public boolean userActionGui(int key, GralWidget infos, Object... params) {
    703      setSortOrderFiles(GralFileSelector.kSortDateOldest);
    704      return true;
    705  } };
    706
    707
    708
    709
    710
    711
    712  GralUserAction actionSortFilePerLenghLargestFirst = new GralUserAction("")
    713  { @Override public boolean userActionGui(int key, GralWidget infos, Object... params) {
    714      setSortOrderFiles(GralFileSelector.kSortSizeLargest);
    715      return true;
    716  } };
    717
    718
    719
    720
    721  GralUserAction actionSortFilePerLenghSmallestFirst = new GralUserAction("")
    722  { @Override public boolean userActionGui(int key, GralWidget infos, Object... params) {
    723      setSortOrderFiles(GralFileSelector.kSortSizeSmallest);
    724      return true;
    725  } };
    726
    727
    728
    729  GralUserAction actionDeselectDirtree = new GralUserAction("actionDeselectDirtree")
    730  { @Override public boolean exec(int key, GralWidget_ifc widgi, Object... params) {
    731      FcmdFileCard fileCard = main.getLastSelectedFileCard();
    732      FileRemote[] lastFiles = main.getLastSelectedFiles(true, 1);
    733      //if(fileCard !=null){
    734      if(lastFiles[0] !=null){
    735        FileCluster fc = lastFiles[0].itsCluster;
    736        String sStartDir = lastFiles[0].getCanonicalPath();
    737        ListIterator<FileRemote> it = fc.listSubdirs(sStartDir);
    738        while(it.hasNext()){
    739          FileRemote dir1 = it.next();
    740          if(!dir1.getCanonicalPath().startsWith(sStartDir)) { break; }
    741          it.remove();
    742        }
    743        lastFiles[0].resetMarkedRecurs(0xffffffff, null);
    744        main.refreshFilePanel(lastFiles[0].getParentFile());
    745        //fileCard.f  //TODO refresh
    746      }
    747      return true;
    748  } };
    749
    750
    751
    752
    753  GralUserAction actionCleanFileRemote = new GralUserAction("actionCleanFileRemote")
    754  { @Override public boolean exec(int key, GralWidget_ifc widgi, Object... params) {
    755      FcmdFileCard fileCard = main.getLastSelectedFileCard();
    756      FileRemote[] lastFiles = main.getLastSelectedFiles(true, 1);
    757      //if(fileCard !=null){
    758      if(lastFiles[0] !=null){
    759        FileCluster fc = lastFiles[0].itsCluster;
    760        String sStartDir = lastFiles[0].getCanonicalPath();
    761        ListIterator<FileRemote> it = fc.listSubdirs(sStartDir);
    762        while(it.hasNext()){
    763          FileRemote dir1 = it.next();
    764          if(!dir1.getCanonicalPath().startsWith(sStartDir)) { break; }
    765          it.remove();
    766        }
    767        lastFiles[0].resetMarkedRecurs(0xffffffff, null);
    768        lastFiles[0].cleanChildren();
    769        main.refreshFilePanel(lastFiles[0].getParentFile());
    770        //fileCard.f  //TODO refresh
    771      }
    772      return true;
    773  } };
    774
    775
    776
    777
    778}