Browse Source

Larger File Open dialog for larger console/terminal dimensions

Margers 9 months ago
parent
commit
8d7a6cc778

+ 49 - 5
packages/fv/src/stddlg.pas

@@ -1180,6 +1180,35 @@ begin
   EventMask := EventMask or evBroadcast;
 end;
 
+{****************************************************************************}
+{ AdjustNameSize for TFileInfoPane                                           }
+{****************************************************************************}
+function AdjustNameSize(S:String;ASize:sw_integer):String;
+var St: String;
+    NameLen:sw_integer;
+    K,N : sw_integer;
+begin
+  NameLen:=12;
+  Str(NameLen,St);
+  NameLen:=ASize-10-9-3-2-4-2-2-1-2;
+  if NameLen>12 then
+    Str(NameLen,St);
+  k:=1;
+  while k<=length(S) do
+  begin
+    if (S[k] in ['0'..'9']) then break;
+    inc(k);
+  end;
+  N:=K;
+  while N<=length(S) do
+  begin
+    if not (S[N] in ['0'..'9']) then break;
+    inc(N);
+  end;
+  S:=Copy(S,1,K-1)+St+Copy(S,N,length(S));
+  AdjustNameSize:=S;
+end;
+
 {****************************************************************************}
 { TFileInfoPane.Draw                    }
 {****************************************************************************}
@@ -1242,6 +1271,7 @@ begin
     FmtId := sFileLine;
     Params[1] := S.Size;
   end;
+  FmtId:=AdjustNameSize(FmtId,Size.X);
   UnpackTime(S.Time, Time);
   M := Month[Time.Month];
   Params[2] := ptruint(@M);
@@ -1460,6 +1490,7 @@ begin
 
   R.Assign(3,3,31,4);
   FileName := New(PFileInputLine, Init(R, 79));
+  FileName^.GrowMode:=gfGrowHiX;
   FileName^.Data^ := WildCard;
   Insert(FileName);
   R.Assign(2,2,3+CStrLen(InputName),3);
@@ -1467,6 +1498,7 @@ begin
   Insert(Control);
   R.Assign(31,3,34,4);
   FileHistory := New(PFileHistory, Init(R, FileName, HistoryId));
+  FileHistory^.GrowMode:=gfGrowHiX or gfGrowLoX;
   Insert(FileHistory);
 
   R.Assign(3,14,34,15);
@@ -1474,6 +1506,7 @@ begin
   Insert(Control);
   R.Assign(3,6,34,14);
   FileList := New(PFileList, Init(R, PScrollBar(Control)));
+  FileList^.GrowMode:=gfGrowHiX or gfGrowHiY;
   Insert(FileList);
   R.Assign(2,5,8,6);
   Control := New(PLabel, Init(R, slFiles, FileList));
@@ -1483,29 +1516,39 @@ begin
   Opt := bfDefault;
   if AOptions and fdOpenButton <> 0 then
   begin
-    Insert(New(PButton, Init(R,slOpen, cmFileOpen, Opt)));
+    Control:=New(PButton, Init(R,slOpen, cmFileOpen, Opt));
+    Control^.GrowMode:=gfGrowHiX or gfGrowLoX;
+    Insert(Control);
     Opt := bfNormal;
     Inc(R.A.Y,3); Inc(R.B.Y,3);
   end;
   if AOptions and fdOkButton <> 0 then
   begin
-    Insert(New(PButton, Init(R,slOk, cmFileOpen, Opt)));
+    Control:=New(PButton, Init(R,slOk, cmFileOpen, Opt));
+    Control^.GrowMode:=gfGrowHiX or gfGrowLoX;
+    Insert(Control);
     Opt := bfNormal;
     Inc(R.A.Y,3); Inc(R.B.Y,3);
   end;
   if AOptions and fdReplaceButton <> 0 then
   begin
-    Insert(New(PButton, Init(R, slReplace,cmFileReplace, Opt)));
+    Control:=New(PButton, Init(R, slReplace,cmFileReplace, Opt));
+    Control^.GrowMode:=gfGrowHiX or gfGrowLoX;
+    Insert(Control);
     Opt := bfNormal;
     Inc(R.A.Y,3); Inc(R.B.Y,3);
   end;
   if AOptions and fdClearButton <> 0 then
   begin
-    Insert(New(PButton, Init(R, slClear,cmFileClear, Opt)));
+    Control:=New(PButton, Init(R, slClear,cmFileClear, Opt));
+    Control^.GrowMode:=gfGrowHiX or gfGrowLoX;
+    Insert(Control);
     Opt := bfNormal;
     Inc(R.A.Y,3); Inc(R.B.Y,3);
   end;
-  Insert(New(PButton, Init(R, slCancel, cmCancel, bfNormal)));
+  Control:=New(PButton, Init(R, slCancel, cmCancel, bfNormal));
+  Control^.GrowMode:=gfGrowHiX or gfGrowLoX;
+  Insert(Control);
   Inc(R.A.Y,3); Inc(R.B.Y,3);
   if AOptions and fdHelpButton <> 0 then
   begin
@@ -1515,6 +1558,7 @@ begin
 
   R.Assign(1,16,48,18);
   Control := New(PFileInfoPane, Init(R));
+  Control^.GrowMode:=gfGrowHiX or gfGrowHiY or gfGrowLoY;
   Insert(Control);
 
   SelectNext(False);

+ 1 - 1
packages/ide/fpmcomp.inc

@@ -97,7 +97,7 @@ end;
 
 procedure TIDEApp.DoPrimaryFile;
 var
-  D : PFileDialog;
+  D : PFPFileDialog;
   FileName : string;
 begin
   New(D, Init('*.pri;*.pas',label_primaryfile_primaryfile,'*.pri;*.pas',fdOpenButton,hidPrimaryFile));

+ 2 - 2
packages/ide/fpmfile.inc

@@ -74,7 +74,7 @@ end;
 
 
 procedure TIDEApp.Open(FileName: string;FileDir:string);
-var D: PFileDialog;
+var D : PFPFileDialog;
     OpenIt: boolean;
     DriveNumber : byte;
     StoreDir,StoreDir2 : DirStr;
@@ -141,7 +141,7 @@ begin
 end;
 
 function TIDEApp.OpenSearch(FileName: string) : boolean;
-var D: PFileDialog;
+var D : PFPFileDialog;
     OpenIt: boolean;
     P : PString;
     Dir,S : String;

+ 1 - 1
packages/ide/fpmhelp.inc

@@ -169,7 +169,7 @@ procedure THelpFilesDialog.HandleEvent(var Event: TEvent);
   StoreHtmlIndexFile := Re <> cmCancel;
   end;
 var I: integer;
-    D: PFileDialog;
+    D : PFPFileDialog;
     FileName: string;
     Re: word;
     S: string;

+ 2 - 2
packages/ide/fpmopts.inc

@@ -1621,7 +1621,7 @@ end;
 {$endif COLORSEL}
 
 procedure TIDEApp.OpenINI;
-var D: PFileDialog;
+var D : PFPFileDialog;
     FileName: string;
 begin
   New(D, Init('*'+ExtOf(INIFileName),dialog_openoptions,dialog_ini_filename,fdOpenButton,hidOpenIniFile));
@@ -1646,7 +1646,7 @@ begin
 end;
 
 procedure TIDEApp.SaveAsINI;
-var D: PFileDialog;
+var D : PFPFileDialog;
     FileName: string;
     CanWrite: boolean;
 begin

+ 135 - 3
packages/ide/weditor.pas

@@ -22,7 +22,7 @@ unit WEditor;
 interface
 {tes}
 uses
-  Dos,Objects,Drivers,Views,Dialogs,Menus,
+  Dos,Objects,Drivers,Views,Dialogs,Menus,Stddlg,
   FVConsts,
   WUtils,WViews;
 
@@ -750,6 +750,18 @@ type
 
     PSearchHelperDialog = ^TSearchHelperDialog;
 
+    PFPFileInputLine = ^TFPFileInputLine;
+    TFPFileInputLine = object(TFileInputLine)
+      constructor Init(var Bounds: TRect; AMaxLen: Sw_Integer);
+      procedure HandleEvent(var Event: TEvent); virtual;
+    end;
+
+    PFPFileDialog = ^TFPFileDialog;
+    TFPFileDialog = object(TFileDialog)
+      constructor Init(AWildCard: TWildStr; const ATitle,
+        InputName: String; AOptions: Word; HistoryId: Byte);
+    end;
+
 const
      { used for ShiftDel and ShiftIns to avoid
        GetShiftState to be considered for extending
@@ -802,7 +814,7 @@ procedure RegisterWEditor;
 implementation
 
 uses
-  Strings,Video,MsgBox,App,StdDlg,Validate,
+  Strings,Video,MsgBox,App,Validate,
 {$ifdef WinClipSupported}
   WinClip,
 {$endif WinClipSupported}
@@ -7285,6 +7297,14 @@ begin
              inherited HandleEvent(Event);
              ClearEvent(Event);
            end
+         else if ((Event.KeyCode=kbCtrlDel)) then
+           { Cut & discard }
+           begin
+             { now remove the selected part }
+             Event.keyCode:=kbDel;
+             inherited HandleEvent(Event);
+             ClearEvent(Event);
+           end
          else
            Inherited HandleEvent(Event);
        End
@@ -7294,6 +7314,118 @@ begin
   Message(Owner,evBroadCast,cmInputLineLen,pointer(Length(st)));
 end;
 
+constructor TFPFileInputLine.Init(var Bounds: TRect; AMaxLen: Sw_Integer);
+begin
+  inherited Init(Bounds, AMaxLen);
+end;
+
+procedure TFPFileInputLine.HandleEvent(var Event: TEvent);
+var s : sw_astring;
+    i : sw_integer;
+    st: string;
+begin
+     If (Event.What=evKeyDown) then
+       begin
+           if ((Event.KeyCode=kbShiftIns) or (Event.KeyCode=paste_key))  and
+                 Assigned(weditor.Clipboard) and (weditor.Clipboard^.ValidBlock) then
+           { paste from clipboard }
+           begin
+             i:=Clipboard^.SelStart.Y;
+             s:=Clipboard^.GetDisplayText(i);
+             i:=Clipboard^.SelStart.X;
+             if i>0 then
+              s:=copy(s,i+1,length(s));
+             if (Clipboard^.SelStart.Y=Clipboard^.SelEnd.Y) then
+               begin
+                 i:=Clipboard^.SelEnd.X-i;
+                 s:=copy(s,1,i);
+               end;
+             for i:=1 to length(s) do
+               begin
+                 st:=Data^+s[i];
+                 If not assigned(validator) or
+                    Validator^.IsValidInput(st,False)  then
+                   Begin
+                     Event.What:=evKeyDown;
+                     Event.CharCode:=s[i];
+                     Event.Scancode:=0;
+                     Inherited HandleEvent(Event);
+                   End;
+               end;
+             ClearEvent(Event);
+           end
+         else if ((Event.KeyCode=kbCtrlIns) or (Event.KeyCode=copy_key))  and
+                 Assigned(Clipboard) then
+           { Copy to clipboard }
+           begin
+             s:=GetStr(Data);
+             s:=copy(s,selstart+1,selend-selstart);
+             Clipboard^.SelStart:=Clipboard^.CurPos;
+             Clipboard^.InsertText(s);
+             Clipboard^.SelEnd:=Clipboard^.CurPos;
+             ClearEvent(Event);
+           end
+         else if ((Event.KeyCode=kbShiftDel) or (Event.KeyCode=cut_key))  and
+                 Assigned(Clipboard) then
+           { Cut to clipboard }
+           begin
+             s:=GetStr(Data);
+             s:=copy(s,selstart+1,selend-selstart);
+             Clipboard^.SelStart:=Clipboard^.CurPos;
+             Clipboard^.InsertText(s);
+             Clipboard^.SelEnd:=Clipboard^.CurPos;
+             { now remove the selected part }
+             Event.keyCode:=kbDel;
+             inherited HandleEvent(Event);
+             ClearEvent(Event);
+           end
+         else if ((Event.KeyCode=kbCtrlDel)) then
+           { Cut & discard }
+           begin
+             { now remove the selected part }
+             Event.keyCode:=kbDel;
+             inherited HandleEvent(Event);
+             ClearEvent(Event);
+           end
+         else
+           Inherited HandleEvent(Event);
+       End
+     else
+       Inherited HandleEvent(Event);
+  //st:=getstr(data);
+  //Message(Owner,evBroadCast,cmInputLineLen,pointer(Length(st)));
+end;
+
+constructor TFPFileDialog.Init(AWildCard: TWildStr; const ATitle,
+        InputName: String; AOptions: Word; HistoryId: Byte);
+var R: TRect;
+  DInput  : PFPFileInputLine;
+  Control : PView;
+  History : PHistory;
+  S : String;
+begin
+  inherited init(AWildCard,ATitle,InputName,AOptions,HistoryId);
+  FileName^.getData(S);
+  R.Assign(3, 3, 31, 4);
+  DInput := New(PFPFileInputLine, Init(R, 79{FileNameLen+4}));
+  DInput^.SetData(S);
+  InsertBefore(DInput,FileName); {insert before to preserv order as it was}
+  Delete(FileName);
+  Dispose(FileName,done);
+  DInput^.GrowMode:=gfGrowHiX;
+  FileName:=DInput;
+  FileHistory^.Link:=DInput;
+  {resize}
+  if Desktop^.Size.Y > 26 then
+    GrowTo(Size.X,Desktop^.Size.Y-6);
+  if Desktop^.Size.X > 80 then
+    GrowTo(Min(Desktop^.Size.X-(80-Size.X),102),Size.Y);
+  FileList^.NumCols:= Max((FileList^.Size.X-(FileList^.Size.X div 14)) div 14,2);
+  {set focus on the new input line}
+  DInput^.Focus;
+end;
+
+
 procedure TSearchHelperDialog.HandleEvent(var Event : TEvent);
 begin
  case Event.What of
@@ -7595,7 +7727,7 @@ begin
             end;
         else begin Title:='???'; DefExt:=''; end;
         end;
-        Re:=Application^.ExecuteDialog(New(PFileDialog, Init(DefExt,
+        Re:=Application^.ExecuteDialog(New(PFPFileDialog, Init(DefExt,
           Title, label_name, fdOkButton, FileId)), @Name);
         case Dialog of
           edSaveAs     :