Subversion Repositories Kolibri OS

Rev

Rev 4098 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. //Leency 2013
  2.  
  3. void ShowOpenWithDialog()
  4. {
  5.         SwitchToAnotherThread();
  6.         CreateThread(#OpenWith,#open_with_stak+4092);  
  7. }
  8.  
  9. llist app_list;
  10. struct app_list_string { char item[1024]; char ext[5]; };
  11. app_list_string app_paths[100];
  12.  
  13. int GetListOfPrograms()
  14. {
  15.         byte section[32], parametr[32], option[256], InfType=0;
  16.         char bukva[2];
  17.         int tj, ti;
  18.         static dword buff, fsize;
  19.  
  20.         free(buff);
  21.         if (!GetFile(#buff, #fsize, abspath("Eolite.ini")))
  22.         {
  23.                 notify("Eolite.ini not found. Don't know any programm.");
  24.                 return -1;
  25.         }
  26.  
  27.         for (tj=0; tj<fsize; tj++;)
  28.         {  
  29.                 bukva = ESBYTE[buff+tj];
  30.                 switch (bukva)
  31.                 {
  32.                         case ';': InfType=COMMENT; break;                              
  33.                         case '[': InfType=SECTION; section=NULL; break;
  34.                         case ']': InfType=PARAM; break;
  35.                         case '=': InfType=OPTION; break;
  36.                         case 0x0a:
  37.                         case 0x0d:
  38.                                 if (!strcmp(#section,"Associations")) && (option) && (InfType!=COMMENT)
  39.                                 {
  40.                                         for (ti=0; ti<app_list.count; ti++) //do not add duplications
  41.                                         {
  42.                                                 if (strcmp(#app_paths[ti].item, #option)==0) goto _OUT;
  43.                                         }
  44.                                         if (kolibrios_drive==false) && (strstr(#option,"kolibrios/")!=0) goto _OUT;
  45.                                         strcpy(#app_paths[app_list.count].item, #option);
  46.                                         if (strlen(#parametr)<=5) && (parametr[0]) strcpy(#app_paths[app_list.count].ext, #parametr);
  47.                                         else strcpy(#app_paths[app_list.count].ext, "kex");
  48.                                         app_list.count++;
  49.                                 }
  50.                                 _OUT:
  51.                                 InfType=PARAM;
  52.                                 parametr=option=NULL;
  53.                                 break;
  54.                         default:
  55.                                 IF (InfType==SECTION) chrcat(#section, bukva);
  56.                                 IF (InfType==PARAM) chrcat(#parametr, bukva);
  57.                                 IF (InfType==OPTION) chrcat(#option, bukva);
  58.                 }
  59.         }
  60. }
  61.  
  62.  
  63.  
  64. void OpenWith()
  65. {
  66.         #define WIN_W 290
  67.         #define OPEN_LIST_VISIBLE_N 12
  68.         #define OPEN_LIST_LINE_H 20
  69.         #define PANEL_H 40
  70.         #define PADDING 8
  71.         int WIN_H;
  72.         mouse mm;
  73.         word key;
  74.         proc_info MenuForm;
  75.  
  76.         app_list.ClearList();
  77.         if (!app_list.count) if (GetListOfPrograms()==-1) return;
  78.         app_list.SetSizes(PADDING,PANEL_H+1,WIN_W-PADDING-PADDING,OPEN_LIST_VISIBLE_N*OPEN_LIST_LINE_H,150,OPEN_LIST_LINE_H);
  79.         SetEventMask(100111b);
  80.         goto _APP_LIST_DRAW;
  81.  
  82.         loop() switch(WaitEvent())
  83.         {
  84.                 case evMouse:
  85.                                 if (!CheckActiveProcess(MenuForm.ID)) ExitProcess();
  86.                                 mm.get();
  87.                                 if (mm.vert) && (app_list.MouseScroll(mm.vert)) DrawAppList();
  88.                                 if (app_list.ProcessMouse(mm.x, mm.y)) DrawAppList();
  89.                                 if (app_list.MouseOver(mm.x, mm.y)) && (mm.lkm)
  90.                                 {
  91.                                         RunProgram(#app_paths[app_list.current].item, #file_path);
  92.                                         ExitProcess();
  93.                                 }
  94.  
  95.                                 break;
  96.                                
  97.                 case evKey:
  98.                                 key = GetKey();
  99.                                 if (key==27) ExitProcess();
  100.                                 if (key==13) { RunProgram(#app_paths[app_list.current].item, #file_path); ExitProcess(); }
  101.                                 if (app_list.ProcessKey(key)) DrawAppList();
  102.                                 break;
  103.                                
  104.                 case evReDraw: _APP_LIST_DRAW:
  105.                                 WIN_H = app_list.h+PANEL_H+PADDING+2;
  106.                                 DefineAndDrawWindow(files.w-WIN_W/2+files.x+Form.left+6,
  107.                                 files.h-WIN_H/2+files.y+Form.top+GetSkinHeight(),WIN_W+1,WIN_H,0x01, 0, 0, 0x01fffFFF);
  108.                                 GetProcessInfo(#MenuForm, SelfInfo);
  109.                                 DrawPopup(0,0,MenuForm.width-2,MenuForm.height-2,0, sc.work, sc.work_graph);
  110.                                 DrawRectangle(app_list.x-1, app_list.y-2, app_list.w+1, app_list.h+2, sc.work_graph);
  111.  
  112.                                 Put_icon(#file_name+_strrchr(#file_name,'.'), 10, 13, sc.work, 0);
  113.                                 WriteText(35,10, 0x80, sc.work_text, T_SELECT_APP_TO_OPEN_WITH);
  114.                                 WriteText(35,23, 0x80, sc.work_text, #file_name);
  115.  
  116.                                 DrawAppList();
  117.         }
  118. }
  119.  
  120. void DrawAppList()
  121. {
  122.         #define SCROLL_WIDTH 5
  123.         llist tiny_scroll;
  124.         dword index, col_bg;
  125.         for (index = 0; (index<app_list.visible) && (index+app_list.first<app_list.count); index++)
  126.         {
  127.                 if (index+app_list.first==app_list.current) col_bg = col_selec; else col_bg = 0xFFFfff;
  128.                 DrawBar(app_list.x, index*app_list.line_h+app_list.y, app_list.w, app_list.line_h, col_bg);
  129.                 Put_icon(#app_paths[index+app_list.first].ext, app_list.x+4, index*app_list.line_h+app_list.y+2, col_bg, 6);
  130.                 WriteText(app_list.x+25, index*app_list.line_h+app_list.y+7, 0x80, 0, #app_paths[index+app_list.first].item);
  131.         }
  132.         tiny_scroll.x = app_list.x+app_list.w-SCROLL_WIDTH-1;
  133.         tiny_scroll.h = app_list.h * app_list.visible / app_list.count;
  134.         tiny_scroll.y = app_list.h * app_list.first / app_list.count + app_list.y;
  135.         if (tiny_scroll.y + tiny_scroll.h - app_list.y - app_list.h >= 0) tiny_scroll.y = app_list.y + app_list.h - tiny_scroll.h-1;
  136.         DrawBar(tiny_scroll.x, tiny_scroll.y, SCROLL_WIDTH, tiny_scroll.h, 0x555555); //scroll
  137. }