NBPrg40. FILEWS.PAS. MiniOS. OpenSource.

NBPrg40. FILEWS.PAS. MiniOS. OpenSource.
***************************************

{ Nikita Beloshenko (GNU) filews = w_file(WORK_SYS) }

Unit filews;

(**********************************
 *                                *
 *   FILEWS.PAS                   *
 *                                *
 *   FileWS.                      *
 *                                *
 **********************************)

Interface

Uses crt,dos,graph,work_sys,w_text;

Type
    wfile=Object(work_sys_object)
          End;

    bar_coord=Record
                x,y,x1,y1:integer;
              End;

    file_palete=Object(wfile)
                  color:Array[1..100] Of integer;
                  sourcestr:Array[1..100] Of String;
                  Procedure standart;
                  Procedure restruct;
                  Procedure clear;
                End;

    file_coords=Object(wfile)
                  globalbar:bar_coord;
                  menubar:bar_coord;
                  titlebar:bar_coord;
                  panel1,panel2:bar_coord;
                  Procedure standart;
                  Procedure clear;
                End;

    panel_inspector=Object(wfile)
                      c1,c2:integer;
                      panel1bar,panel2bar:bar_coord;
                      s_p1,s_p2:Array[1..500] Of String[20];
                      panel1_path:String;
                      panel2_path:String;
                      activpanel:boolean;
                      pik_p1,pik_p2:integer;
                      sel_p1,sel_p2:shortint;
                      Procedure clear_all_buf;
                      Procedure initpanel;
                      Procedure printhelp;
                      Procedure printpanel;
                      Procedure panel1;
                      Procedure panel2;
                      Procedure select;
                      Procedure exec_run(var s:String);
                    End;

    file_interface=Object(wfile)
                     p_:file_palete;
                     c_:file_coords;
                     i_:panel_inspector;
                     Constructor init;
                     Procedure run;
                     Procedure changedisk;
                     Procedure build_interface;
                     Destructor done;
                   End;

Procedure file_panel;

Implementation

Var maxx,maxy:integer;
    pf_interf:^file_interface;
    thispath:String;

Procedure file_panel;
Begin
  new(pf_interf,init);
  pf_interf^.run;
  dispose(pf_interf,done);
End;

Procedure file_palete.standart;
Begin
  color[1]:=lightgray;
  color[2]:=red;
  color[3]:=blue;
  color[4]:=yellow;
  color[5]:=red;
  color[6]:=white;
  color[7]:=black;
  color[8]:=darkgray;
  color[9]:=red;

  sourcestr[1]:='File panel system.';
End;

Procedure file_palete.restruct;
Var i:byte;
Begin
  For i:=1 To 100 Do color[i]:=blue;
End;

Procedure file_palete.clear;
Var i:byte;
Begin
  For i:=1 To 100 Do Begin color[i]:=0; sourcestr[i]:=''; End;
End;

Procedure file_coords.standart;
Begin
  With globalbar Do Begin
       x:=maxx Div 5;      y:=maxy Div 5;
       x1:=maxx-x-20;      y1:=maxy-y;
  End;
  With menubar Do Begin
       x:=maxx Div 5 + 3;  y:=maxy Div 5 + 20;
       x1:=maxx-x-20-2;    y1:=y+20;
  End;
  With titlebar Do Begin
       x:=maxx Div 5 + 3;  y:=maxy Div 5 + 3;
       x1:=maxx-x-20-2;    y1:=y+15;
  End;
  With panel1 Do Begin
       x:=maxx Div 5 + 10;
       y:=maxy Div 5 + 50;
       x1:=(x+maxx-maxx Div 5-30-2) Div 2 -10;
       y1:=maxy-maxy Div 5-10;
  End;
  With panel2 Do Begin
       x:=(maxx-maxx Div 5-30-2+maxx Div 5 + 10) Div 2 +10;
       y:=maxy Div 5 + 50;
       x1:=maxx-maxx Div 5-30-2;
       y1:=maxy-maxy Div 5-10;
  End;
End;

Procedure file_coords.clear;
Begin
  With globalbar Do Begin x:=0; y:=0; x1:=0; y1:=0; End;
  With menubar Do Begin x:=0; y:=0; x1:=0; y1:=0; End;
  With titlebar Do Begin x:=0; y:=0; x1:=0; y1:=0; End;
  With panel1 Do Begin x:=0; y:=0; x1:=0; y1:=0; End;
  With panel2 Do Begin x:=0; y:=0; x1:=0; y1:=0; End;
End;

Constructor file_interface.init;
Begin
  maxx:=getmaxx;   maxy:=getmaxy;
  p_.clear;        c_.clear;
  p_.standart;     c_.standart;
  build_interface;
End;

Procedure file_interface.run;
Var key_command:char; i:byte;
Begin
  With c_.panel1 Do Begin
       i_.panel1bar.x:=x;   i_.panel1bar.y:=y;
       i_.panel1bar.x1:=x1; i_.panel1bar.y1:=y1;
  End;
  With c_.panel2 Do Begin
       i_.panel2bar.x:=x;   i_.panel2bar.y:=y;
       i_.panel2bar.x1:=x1; i_.panel2bar.y1:=y1;
  End;
  With i_ Do Begin c1:=p_.color[6]; c2:=p_.color[9]; End;
  i_.pik_p1:=1; i_.pik_p2:=1;
  i_.clear_all_buf;  getdir(0,thispath);
  key_command:=' ';
  i_.panel1_path:=thispath; i_.panel2_path:=thispath;
  i_.activpanel:=true;
  While ord(key_command)<>27 Do With i_ Do Begin
        printhelp;
        If pik_p1+9>500 Then pik_p1:=1;  If pik_p2+9>500 Then pik_p2:=1;
        If pik_p1<1 Then pik_p1:=1;      If pik_p2<1 Then pik_p2:=1;
        clear_all_buf;
        initpanel;
        If activpanel Then chdir(panel1_path) Else chdir(panel2_path);
        printpanel;
        key_command:=readkey;
        If ord(key_command)=9 Then activpanel:=Not activpanel;
        If ord(key_command)=80 Then
           If activpanel Then inc(pik_p1) Else inc(pik_p2);
        If ord(key_command)=72 Then
           If activpanel Then dec(pik_p1) Else dec(pik_p2);
        If ord(key_command)=115 Then select;
        If ord(key_command)=100 Then changedisk;
  End;
  chdir(thispath);
End;

Procedure file_interface.changedisk;
Var x,y,x1,y1:integer;
    ch:char;
Begin
  x:=maxx Div 20; y:=maxy Div 5; x1:=x+85; y1:=y+100;
  setfillstyle(solidfill,cyan); setcolor(red);
  settextstyle(smallfont,horizdir,5);
  bar(x,y,x1,y1); rectangle(x,y,x1,y1);
  x:=x+5; y:=y+5;
  outtextxy(x,y,'Disk name?');
  While (ch<>'A') And (ch<>'B') And (ch<>'C') And (ch<>'D') And
        (ch<>'E') And (ch<>'F') And (ch<>'G') And (ch<>'H') Do
        ch:=readkey;
  y:=y+10; outtextxy(x,y,ch);
  With i_ Do
  If activpanel Then panel1_path:=ch+':\' else panel2_path:=ch+':\';
  x:=x-5; y:=y-15;
  setfillstyle(solidfill,blue); setcolor(blue);
  bar(x,y,x1,y1); rectangle(x,y,x1,y1);
End;

Procedure file_interface.build_interface;
Begin
  With p_ Do Begin setfillstyle(solidfill,color[1]); setcolor(color[2]); End;
  With c_ Do Begin
   With globalbar Do Begin bar(x+1,y+1,x1-1,y1-1); rectangle(x,y,x1,y1); End;
   With globalbar Do
        Begin line(x+2,y-2,x1+2,y-2); line(x1+2,y-2,x1+2,y1-2); End;
   With p_ Do setfillstyle(solidfill,color[3]);
   With titlebar Do bar(x,y,x1+1,y1); settextstyle(smallfont,horizdir,4);
   With p_ Do setcolor(color[4]);
   With p_ Do With titlebar Do outtextxy(x+3,y1-12,sourcestr[1]);
   With p_ Do Begin setcolor(color[7]);setfillstyle(solidfill,color[8]); End;
   With menubar Do Begin bar(x+1,y+1,x1-1,y1-1); rectangle(x,y,x1,y1); End;
   With p_ Do Begin setcolor(color[5]);setfillstyle(solidfill,color[6]); End;
   With panel1 Do Begin bar(x+1,y+1,x1-1,y1-1); rectangle(x,y,x1,y1); End;
   With panel2 Do Begin bar(x+1,y+1,x1-1,y1-1); rectangle(x,y,x1,y1); End;
  End;
End;

Destructor file_interface.done;
Begin
  p_.restruct; build_interface; i_.printhelp;
  p_.clear; c_.clear; i_.clear_all_buf;
End;


Procedure panel_inspector.clear_all_buf;
Var i:word;
Begin
  For i:=1 To 500 Do Begin s_p1[i]:=''; s_p2[i]:=''; End;
End;

Procedure panel_inspector.initpanel;
Begin
  panel1; panel2;
End;

Procedure panel_inspector.panel1;
Var i:byte;
    dirinfo: searchrec;
Begin i:=0;
  chdir(panel1_path);
  findfirst('*.*', anyfile, dirinfo);
  While doserror = 0 Do
  Begin
    inc(i); s_p1[i]:=dirinfo.name;
    If dirinfo.attr=directory Then s_p1[i]:=s_p1[i]+' (DIR)';
    findnext(dirinfo);
  End;
End;

Procedure panel_inspector.panel2;
Var i:word;
    dirinfo: searchrec;
Begin i:=0;
  If panel2_path<>panel1_path Then Begin
  chdir(panel2_path);
  findfirst('*.*', anyfile, dirinfo);
  While doserror = 0 Do
  Begin
    inc(i); s_p2[i]:=dirinfo.name;
    If dirinfo.attr=directory Then s_p2[i]:=s_p2[i]+' (DIR)';
    findnext(dirinfo);
  End; End;
  If panel2_path=panel1_path Then Begin
     For i:=1 To 500 Do s_p2[i]:=s_p1[i];
  End;
End;

Procedure panel_inspector.printpanel;
Var i:byte;
    x_,y_,x1_,y1_:integer;
Begin
  setfillstyle(solidfill,c1);
  setcolor(c2);

  With panel1bar Do Begin x_:=x+5; y_:=y+5; End;
  settextstyle(smallfont,horizdir,4);
  With panel1bar Do bar(x+1,y+1,x1-1,y1-1);
  For i:=pik_p1 To 9+pik_p1 Do Begin
      inc(y_,15);
      outtextxy(x_,y_,s_p1[i]);
  End;

  With panel2bar Do Begin x1_:=x+5; y1_:=y+5; End;
  settextstyle(smallfont,horizdir,4);
  With panel2bar Do bar(x+1,y+1,x1-1,y1-1);
  For i:=pik_p2 To 9+pik_p2 Do Begin
      inc(y1_,15);
      outtextxy(x1_,y1_,s_p2[i]);
  End;
End;

Procedure panel_inspector.printhelp;
Var x,y,x1,y1:integer;
Begin
  setcolor(pf_interf^.p_.color[2]);
  setfillstyle(solidfill,pf_interf^.p_.color[1]);
  settextstyle(smallfont,horizdir,4);
  x:=maxx Div 20; x1:=x+85;
  y:=maxy Div 5;  y1:=maxy-y;
  rectangle(x,y,x1,y1);
  bar(x+1,y+1,x1-1,y1-1);
  inc(x,10);
  inc(y,10); outtextxy(x,y,'help:');
  inc(y,10); outtextxy(x,y,'s=select');
  inc(y,10); outtextxy(x,y,'d=disk');
  inc(y,10); outtextxy(x,y,'esc=exit');
  inc(y,10); outtextxy(x,y,'');
  inc(y,10); outtextxy(x,y,'enter=');
  inc(y,10); outtextxy(x,y,'=select');
  inc(y,10); outtextxy(x,y,'this;');
  inc(y,10); outtextxy(x,y,'F5-copy');
  inc(y,10); outtextxy(x,y,'F8-delete');
  inc(y,10); outtextxy(x,y,'F7-mkdir');
  inc(y,15); line(x-10,y,x1,y);
  dec(x,9); inc(y); dec(x1); dec(y1);
  bar(x,y,x1,y1);
End;

Procedure panel_inspector.select;
Var sel_command:char;
    x_,y_,x1_:integer;

Procedure enter_command;
Var position:word;
    s:String;
    i,l,j:byte;
Begin
  If activpanel Then position:=pik_p1+sel_p1
                Else position:=pik_p2+sel_p2;
  If activpanel Then s:=s_p1[position]
                Else s:=s_p2[position];
  If pos(' (DIR)',s)<>0 Then Begin
     i:=pos(' (DIR)',s); delete(s,i,6);
     If s='..' Then Begin
        If activpanel Then Begin
           If pos('\',panel1_path)<>0 Then Begin
              l:=length(panel1_path); j:=l;
              If panel1_path[j]='\' Then dec(j);
              While panel1_path[j]<>'\' Do dec(j);
              delete(panel1_path,j+1,l-j);
           End End Else Begin
           If pos('\',panel2_path)<>0 Then Begin
              l:=length(panel2_path); j:=l;
              If panel2_path[j]='\' Then dec(j);
              While panel2_path[j]<>'\' Do dec(j);
              delete(panel2_path,j+1,l-j);
           End; End;
     End Else Begin
         If s='.' Then Else Begin
            If activpanel Then Begin
               l:=length(panel1_path);
               If panel1_path[l]='\' Then delete(panel1_path,l,1);
            End Else Begin
               l:=length(panel2_path);
               If panel2_path[l]='\' Then delete(panel2_path,l,1);
            End;
            If activpanel Then panel1_path:=panel1_path+'\'+s
                          Else panel2_path:=panel2_path+'\'+s;
         End;
     End;
  End;
  If (pos('.EXE',s)<>0) Then exec_run(s);
  If (pos('.COM',s)<>0) Then exec_run(s);
  sel_command:=chr(27);
End;

Procedure copy_file;
Var x_,y_:integer; l:byte;
    ch:char; s:String;
    t1,t2:text; path1,path2:String;
    flag_:boolean; n:byte;
Begin
  With pf_interf^.c_.menubar Do Begin x_:=x; y_:=y; End;
  inc(x_,10); inc(y_,5); s:='';
  setcolor(pf_interf^.p_.color[2]);
  settextstyle(smallfont,horizdir,4); n:=0;
  outtextxy(x_,y_,'Input copy name: '); inc(x_,160);
  While (ord(ch)<>13) And (n<=12) Do Begin
        ch:=readkey; inc(n);
        If ((ord(ch)>=48) And (ord(ch)<=122)) Or (ch='.') Then Begin
           inc(x_,7); s:=s+ch; outtextxy(x_,y_,ch);
        End;
  End; flag_:=false;
  With pf_interf^.i_ Do Begin
       If activpanel Then Begin
          l:=length(panel1_path);
          If panel1_path[l]<>'\' Then panel1_path:=panel1_path+'\';
          l:=length(panel2_path);
          If panel2_path[l]<>'\' Then panel2_path:=panel2_path+'\';
          path1:=panel1_path+s_p1[pik_p1+sel_p1];
          path2:=panel2_path+s;
          assign(t1,path1); assign(t2,path2);
          s:=fsearch(s,panel2_path);
          If s='' Then flag_:=true;
          If flag_ Then Begin
             reset(t1); rewrite(t2);
             While Not eof(t1) Do Begin
                   read(t1,ch); write(t2,ch);
             End;
             close(t1); close(t2);
          End;
       End Else Begin
          l:=length(panel1_path);
          If panel1_path[l]<>'\' Then panel1_path:=panel1_path+'\';
          l:=length(panel2_path);
          If panel2_path[l]<>'\' Then panel2_path:=panel2_path+'\';
          path1:=panel2_path+s_p2[pik_p2+sel_p2];
          path2:=panel1_path+s;
          assign(t1,path1); assign(t2,path2);
          s:=fsearch(s,panel2_path);
          If s='' Then flag_:=true;
          If flag_ Then Begin
             reset(t1); rewrite(t2);
             While Not eof(t1) Do Begin
                   read(t1,ch); write(t2,ch);
             End;
             close(t1); close(t2);
          End;
       End;
  End;
  setfillstyle(solidfill,pf_interf^.p_.color[8]);
  With pf_interf^.c_.menubar Do bar(x+1,y+1,x1-1,y1-1);
End;

Procedure make_dir;
Var x_,y_:integer; l:byte;
    ch:char; s:String; n:byte;
Begin
  With pf_interf^.c_.menubar Do Begin x_:=x; y_:=y; End;
  inc(x_,10); inc(y_,5); s:='';
  setcolor(pf_interf^.p_.color[2]);
  settextstyle(smallfont,horizdir,4); n:=0;
  outtextxy(x_,y_,'Input directory name: '); inc(x_,160);
  While (ord(ch)<>13) And (n<=12) Do Begin
        ch:=readkey; inc(n);
        If ((ord(ch)>=48) And (ord(ch)<=122)) Or (ch='.') Then Begin
           inc(x_,7); s:=s+ch; outtextxy(x_,y_,ch);
        End;
  End;
  {Dodelat}
  setfillstyle(solidfill,pf_interf^.p_.color[8]);
  With pf_interf^.c_.menubar Do bar(x+1,y+1,x1-1,y1-1);
End;

Begin
  If activpanel Then
     With panel1bar Do Begin x_:=x+4; y_:=y+20; x1_:=x1-5; End Else
     With panel2bar Do Begin x_:=x+4; y_:=y+20; x1_:=x1-5; End;
  sel_p1:=0; sel_p2:=0;
  sel_command:=' ';
  While ord(sel_command)<>27 Do Begin
        setcolor(blue);
        If activpanel Then rectangle(x_,y_+15*sel_p1+1,x1_,y_+9+15*sel_p1+1)
                      Else rectangle(x_,y_+15*sel_p2+1,x1_,y_+9+15*sel_p2+1);
        sel_command:=readkey;
        setcolor(white);
        If activpanel Then rectangle(x_,y_+15*sel_p1+1,x1_,y_+9+15*sel_p1+1)
                      Else rectangle(x_,y_+15*sel_p2+1,x1_,y_+9+15*sel_p2+1);
        If ord(sel_command)=80 Then
           If activpanel Then inc(sel_p1) Else inc(sel_p2);
        If ord(sel_command)=72 Then
           If activpanel Then dec(sel_p1) Else dec(sel_p2);
        If sel_p1>9 Then sel_p1:=0;        If sel_p2>9 Then sel_p2:=0;
        If sel_p1<0 Then sel_p1:=0;        If sel_p2<0 Then sel_p2:=0;
        If ord(sel_command)=13 Then enter_command;
        If ord(sel_command)=63 Then copy_file;
        If ord(sel_command)=65 Then make_dir;
  End;
End;

Procedure panel_inspector.exec_run(Var s:String);
Begin
End;


End.