//*
//* SHOW MENU
//*
byte auia_menu(AUI_VARSP v) {
  byte common_cmd = 0;
  byte cstate = *v->state;
  
  if ((cstate == 1) || (cstate == 2)) {
    AWMENUITEM mi[5];
    int cp = 0;
    
    if (cstate == 1) {
      aw_menuset(mi, cp++, "tools.unselect", 19);
    }
    
    aw_menuset(mi, cp++, "tools.delete", 4);
    aw_menuset(mi, cp++, "settings", 17);
    aw_menuset(mi, cp++, "about", 9);
    aw_menuset(mi, cp++, "exit", 0);
    byte ret = aw_menu(v->hWin, NULL, mi, cp);
    
    if ((cstate == 2) && (ret > 0)) {
      ret++;
    }
    
    if (ret == 5) {
      common_cmd = 1;
    }
    else if (ret == 3) {
      common_cmd = 2;
    }
    else if (ret == 4) {
      common_cmd = 3;
    }
    else if (ret == 2) {
      //-- Delete
      auia_setclipboard(v, 3);
      return auia_do_delete(v);
    }
    else if (ret == 1) {
      afbox_setcheckall(v->hFile, 0);
    }
  }
  else {
    int cp = 0;
    AWMENUITEM mi[7];
    
    if (cstate == 3) {
      aw_menuset(mi, cp++, "tools.newfolder", 11);
    }
    
    byte isonfav = auifav_isfav(v->path);
    
    if (isonfav) {
      aw_menuset(mi, cp++, "tools.favorite.del", 8);
    }
    else {
      aw_menuset(mi, cp++, "tools.favorite.add", 7);
    }
    
    aw_menuset(mi, cp++,
               (auic()->showhidden ? "tools.hiddenfile" :
                "tools.hiddenfile.show"), 18);
    aw_menuset(mi, cp++, "tools.terminal", 40);
    aw_menuset(mi, cp++, "settings", 17);
    aw_menuset(mi, cp++, "about", 9);
    aw_menuset(mi, cp++, "exit", 0);
    byte ret = aw_menu(v->hWin, NULL, mi, cp);
    
    if ((cstate != 3) && (ret > 0)) {
      ret++;
    }
    
    if (ret == 7) { /* EXIT */
      common_cmd = 1;
    }
    else if (ret == 6) { /* ABOUT */
      common_cmd = 3;
    }
    else if (ret == 4) { /* TERMINAL */
      common_cmd = 4;
    }
    else if (ret == 5) { /* SETTING */
      common_cmd = 2;
    }
    else if (ret == 3) {
      auic()->showhidden = (auic()->showhidden ? 0 : 1);
      aui_cfg_save();
      v->reshow = 1;
      return 0;
    }
    else if (ret == 2) {
      //-- Add Remove Favorite
      if (isonfav) {
        auifav_del(v->path);
      }
      else {
        auifav_add(v->path);
      }
    }
    else if (ret == 1) {
      //-- Show New Folder
      return auia_newfolder(v);
    }
  }
  
  //-- Common command
  if (common_cmd == 1) {  //-- Exit
    AWMENUITEM mi[2];
    aw_menuset(mi, 0, "yes", 33);
    aw_menuset(mi, 1, "no", 0);
    byte ovr = aw_multiconfirm_ex(v->hWin, alang_get("exit"),
                                  alang_get("exit.message"),
                                  aui_icons(39), mi, 2,
                                  1);
                                  
    if (ovr == 0) {
      return 0;
    }
  }
  else if (common_cmd == 2) { //-- Settings
    v->reshow = 2;
    return 0;
  }
  else if (common_cmd == 3) { //-- About
    auido_about_dialog(v->hWin);
  }
  else if (common_cmd == 4) { //-- Terminal
    v->reshow = 6;
    return 0;
  }
  
  return 1;
}
byte
auifav_win(CANVAS * bg, char *path, char **out_char, int titY, int titH,
	   int boxY, int boxH, byte first)
{
	int btnS = agdp() * 20;
	int btnP = agdp() * 2;

	AWINDOWP hWin = aw(bg);
	ACONTROLP title =
	    aclabel(hWin, btnS + btnP, titY, agw() - ((btnS + btnP) * 2), titH,
		    alang_get("tools.favorite"), 1, 1, 2, acfg()->winfg);
	ACONTROLP addthis =
	    imgbtn(hWin, btnP, titY + btnP, btnS, btnS, aui_icons(6), NULL, 1,
		   55);
	ACONTROLP cancel =
	    imgbtn(hWin, agw() - (btnS + btnP), titY + btnP, btnS, btnS,
		   aui_icons(0), NULL, 1, 5);
	ACONTROLP hFile = afbox(hWin, 0, boxY, agw(), boxH, 7, 8, 2, 6);
	auifav_fetch(hFile);

	aw_show_ex(hWin, first ? 1 : 100, titY, hFile);
	byte ondispatch = 1;
	byte reshow = 0;
	do {
		dword msg = aw_dispatch_ex(hWin, titY);
		switch (aw_gm(msg)) {
		case 5:
			{
				//-- DONE
				ondispatch = 0;
			}
			break;
		case 55:
			{
				//-- REFRESH
				ondispatch = 0;
				reshow = 1;
			}
			break;

			//-- ITEM CLICK
		case 7:
			{
				dword fl = afbox_ddata(hFile);
				char *fpath = auifav_getpath(fl);
				if (fpath != NULL) {
					aui_setpath(out_char, fpath, "", 0);
					free(fpath);
					ondispatch = 0;
				}
			}
			break;

			//-- ITEM TAP & HOLD
		case 8:
			{
				dword fl = afbox_ddata(hFile);
				char *fpath = auifav_getpath(fl);
				if (fpath != NULL) {
					int cp = 0;
					AWMENUITEM mi[2];
					aw_menuset(mi, cp++, "select", 33);
					aw_menuset(mi, cp++,
						   "tools.favorite.del", 8);
					byte ret = aw_menu(hWin, NULL, mi, cp);
					if (ret == 2) {
						auifav_del(fpath);
						reshow = 1;
						free(fpath);
						ondispatch = 0;
					} else if (ret == 1) {
						aui_setpath(out_char, fpath, "",
							    0);
						ondispatch = 0;
					}
					free(fpath);
				}
			}
			break;
		}
	}
	while (ondispatch);
	aw_destroy(hWin);
	return reshow;
}
byte auia_hold(AUI_VARSP v) {
  char * fl = afbox_getselectedfile(v->hFile);
  byte dtype = afbox_dtype(v->hFile);
  
  if (fl != NULL) {
    AWMENUITEM mi[6];
    int cp = 0;
    byte onfav = 0;
    byte isonfav = 0;
    
    if ((dtype == 4) || (dtype == 24)) {
      isonfav = auifav_isfav(fl);
      
      if (isonfav) {
        aw_menuset(mi, cp++, "tools.favorite.del", 8);
      }
      else {
        aw_menuset(mi, cp++, "tools.favorite.add", 7);
      }
      
      onfav = 1;
    }
    
    aw_menuset(mi, cp++, "tools.rename", 15);
    aw_menuset(mi, cp++, "tools.copy", 2);
    aw_menuset(mi, cp++, "tools.cut", 3);
    aw_menuset(mi, cp++, "tools.delete", 4);
    aw_menuset(mi, cp++, "tools.chmod", 1);
    byte ret = aw_menu(v->hWin, fl, mi, cp);
    
    if ((!onfav) && (ret > 0)) {
      ret++;
    }
    
    if (ret == 2) {
      //-- Rename
      return auia_hold_rename(v, fl);
    }
    else if (ret == 6) {
      //-- Rename
      return auia_hold_perm(v, fl);
    }
    else if ((ret == 3) || (ret == 4)) {
      //-- Copy / cut
      ag_setbusy();
      auic_init(ret - 2, 1, v->path);
      auic_add(fl);
      *v->state = aui_tbstate(v, 3, *v->state);
      afbox_changeboxtype(v->hFile, 1);
      aui_changetitle(v, alang_get("paste.location"));
      afbox_setcheckall(v->hFile, 0);
    }
    else if (ret == 5) {
      //-- Copy / cut
      ag_setbusy();
      auic_init(3, 1, v->path);
      auic_add(fl);
      return auia_do_delete(v);
    }
    else if (ret == 1) {
      //-- Add Remove Favorite
      char * full_fl = NULL;
      aui_setpath(&full_fl, v->path, fl, 1);
      
      if (full_fl != NULL) {
        if (isonfav) {
          auifav_del(full_fl);
        }
        else {
          auifav_add(full_fl);
        }
        
        LOGS("Add To Favorite: %s\n", full_fl);
        free(full_fl);
      }
    }
  }
  
  return 1;
}