Browse Source

Integration of bracketed paste and OSC 52 in Textmode IDE

Margers 8 months ago
parent
commit
899343f07c
4 changed files with 109 additions and 30 deletions
  1. 4 2
      packages/ide/fpide.pas
  2. 1 1
      packages/ide/globdir.inc
  3. 53 27
      packages/ide/weditor.pas
  4. 51 0
      packages/ide/winclip.pas

+ 4 - 2
packages/ide/fpide.pas

@@ -176,7 +176,7 @@ uses
   WinClip,
 {$endif WinClipSupported}
 {$ifdef Unix}
-  fpKeys,
+  fpKeys,FVClip,
 {$endif Unix}
   FpDpAnsi,WConsts,
   Video,Mouse,Keyboard,
@@ -1475,6 +1475,7 @@ begin
     UserScreen^.SaveIDEScreen;
   DoneSysError;
   DoneEvents;
+  {$ifdef unix}DoneClip;{$endif}
   { DoneKeyboard should be called last to
     restore the keyboard correctly PM }
 {$ifndef go32v2}
@@ -1505,6 +1506,7 @@ begin
     ButtonCount:=0;
   oldH:=ScreenHeight;
   oldW:=ScreenWidth;
+  {$ifdef unix}InitClip(@Self);{$endif}
 {$ifndef go32v2}
   initvideo;
 {$endif ndef go32v2}
@@ -1521,7 +1523,7 @@ begin
 {$ifndef Windows}
   if (oldH<>ScreenHeight) or (oldW<>ScreenWidth) then
   begin
-    { acknowledge new screen dimensions } 
+    { acknowledge new screen dimensions }
     { prevents to draw out of boundaries of new video buffer }
     ResizeApplication(ScreenWidth,ScreenHeight);
   end else

+ 1 - 1
packages/ide/globdir.inc

@@ -39,7 +39,7 @@
 {$ifdef Linux}
   {$undef SUPPORTVESA}
   {$define SUPPORTREDIR}
-  {$undef WinClipSupported}
+  {$define WinClipSupported}
   {$define HasSignal}
   {$define SignalIsCdecl}
   {$define HasSysMsgUnit}

+ 53 - 27
packages/ide/weditor.pas

@@ -718,6 +718,7 @@ type
       procedure PrintBlock; virtual;
       procedure ExpandCodeTemplate; virtual;
       procedure AddChar(C: AnsiChar); virtual;
+      procedure PasteText(P:PAnsiChar; ASize:sw_integer); virtual;
 {$ifdef WinClipSupported}
       function  ClipCopyWin: Boolean; virtual;
       function  ClipPasteWin: Boolean; virtual;
@@ -3743,6 +3744,7 @@ begin
           cmCut         : ClipCut;
           cmCopy        : ClipCopy;
           cmPaste       : ClipPaste;
+          cmPasteText   : PasteText(Event.InfoPtr,Event.Id);
 
           cmSelectAll   : SelectAll(true);
           cmUnselect    : SelectAll(false);
@@ -5947,15 +5949,14 @@ begin
   UnLock;
 end;
 
-{$ifdef WinClipSupported}
-
 const
    linelimit = 200;
 
-function TCustomCodeEditor.ClipPasteWin: Boolean;
+procedure TCustomCodeEditor.PasteText(P:PAnsiChar; ASize:sw_integer);
 var
     StorePos : TPoint;
     first : boolean;
+    IsNewLine: boolean;
 
 procedure InsertStringWrap(const s: string; var i : Longint);
 var
@@ -5965,7 +5966,8 @@ begin
     begin
       { we need to cut the line in two
       if not at end of line PM }
-      InsertNewLine;
+      if IsNewLine then
+        InsertNewLine;
       SetCurPtr(StorePos.X,StorePos.Y);
       InsertText(s);
       first:=false;
@@ -5973,35 +5975,30 @@ begin
   else
     begin
       Inc(i);
-      InsertLine(i,s);
-      BPos.X:=0;BPos.Y:=i;
-      EPOS.X:=Length(s);EPos.Y:=i;
-      AddAction(eaInsertLine,BPos,EPos,GetDisplayText(i),GetFlags);
+      if IsNewLine then
+      begin
+        InsertLine(i,s);
+        BPos.X:=0;BPos.Y:=i;
+        EPOS.X:=Length(s);EPos.Y:=i;
+        AddAction(eaInsertLine,BPos,EPos,GetDisplayText(i),GetFlags);
+      end else
+      begin
+        SetCurPtr(0,i);
+        InsertText(s);
+      end;
     end;
 end;
 
 var
-    OK: boolean;
     l,i,len,len10 : longint;
-    p,p10,p2,p13 : PAnsiChar;
+    p10,p2,p13 : PAnsiChar;
     s : string;
 begin
   Lock;
-  OK:=WinClipboardSupported;
-  if OK then
-    begin
-
-      first:=true;
-      StorePos:=CurPos;
-      i:=CurPos.Y;
-      l:=GetTextWinClipboardSize;
-      if l=0 then
-        OK:=false
-      else
-        OK:=GetTextWinClipBoardData(p,l);
-      if OK then
-        begin
-          if l>500 then
+  first:=true;
+  StorePos:=CurPos;
+  i:=CurPos.Y;
+          if ASize>500 then
             PushInfo(msg_readingwinclipboard);
           AddGroupedAction(eaPasteWin);
           if not (Clipboard=@Self) and IsFlagSet(efOverwriteBlocks) and InSelectionArea then
@@ -6013,10 +6010,16 @@ begin
           repeat
             p13:=strpos(p2,#13);
             p10:=strpos(p2,#10);
+{$if sizeof(sw_astring)>8  only if ShortString lines}
             if len> linelimit then
               len:=linelimit;
+{$endif}
+            if not assigned(p10) and assigned(p13) then
+              p10:=p13;
+            IsNewLine:=false;
             if assigned(p10) then
               begin
+               IsNewLine:=true;
                len10:=p10-p2;
                if len10<len then
                  begin
@@ -6044,11 +6047,34 @@ begin
           UpdateAttrs(StorePos.Y,attrAll);
           CloseGroupedAction(eaPasteWin);
           Update;
-          if l>500 then
+          if ASize>500 then
             PopInfo;
+          DrawView;
+  UnLock;
+end;
+
+{$ifdef WinClipSupported}
+
+function TCustomCodeEditor.ClipPasteWin: Boolean;
+var
+    OK: boolean;
+    l : longint;
+    p : PAnsiChar;
+begin
+  Lock;
+  OK:=WinClipboardSupported;
+  if OK then
+    begin
+      l:=GetTextWinClipboardSize;
+      if l=0 then
+        OK:=false
+      else
+        OK:=GetTextWinClipBoardData(p,l);
+      if OK then
+        begin
+          PasteText(p,l);
           { we must free the allocated memory }
           freemem(p,l);
-          DrawView;
         end;
     end;
   ClipPasteWin:=OK;

+ 51 - 0
packages/ide/winclip.pas

@@ -41,6 +41,11 @@ implementation
     dos;
 {$endif DOS}
 
+{$ifdef linux}
+  uses
+    baseUnix,base64,keyboard,Objects,fvclip;
+{$endif linux}
+
 {$ifdef Windows}
   uses
     strings,windows;
@@ -100,6 +105,39 @@ begin
 end;
 {$endif DOS}
 
+{$ifdef linux}
+function WinClipboardSupported : boolean;
+begin
+  WinClipboardSupported:=true;
+end;
+
+function OpenWinClipboard : boolean;
+begin
+  OpenWinClipboard:=true;
+end;
+
+function EmptyWinClipboard : boolean;
+begin
+  EmptyWinClipboard:=true;
+end;
+
+function CloseWinClipboard : boolean;
+begin
+  CloseWinClipboard:=true;
+end;
+
+function InternGetDataSize : longint;
+begin
+  InternGetDataSize:=1; {there has to be something in order for menu to be active}
+end;
+
+function GetTextLinuxClipBoardData(var p : PAnsiChar;var l : longint) : boolean;
+begin
+  GetTextLinuxClipBoardData:=false;
+  GetGlobalClipboardData;
+end;
+{$endif linux}
+
 {$ifdef Windows}
 function WinClipboardSupported : boolean;
 begin
@@ -179,6 +217,9 @@ var
   r : Registers;
   M : MemPtr;
 {$endif DOS}
+{$ifdef linux}
+  rez : boolean; {one variable needed to satifay compiler}
+{$endif linux}
 {$ifdef Windows}
   h : HGlobal;
   pp : PAnsiChar;
@@ -209,6 +250,10 @@ begin
   RealIntr($2F,r);
   GetTextWinClipBoardData:=(r.ax<>0);
 {$endif DOS}
+{$ifdef linux}
+  rez:=GetTextLinuxClipBoardData(p,l);
+  GetTextWinClipBoardData:=rez;
+{$endif linux}
 {$ifdef Windows}
   h:=GetClipboardData(CF_OEMTEXT);
   if h<>0 then
@@ -242,6 +287,9 @@ var
   r : Registers;
   M : MemPtr;
 {$endif DOS}
+{$ifdef linux}
+  st : AnsiString;
+{$endif linux}
 {$ifdef Windows}
   h : HGlobal;
   pp : PAnsiChar;
@@ -278,6 +326,9 @@ begin
   RealIntr($2F,r);
   FreeDosMem(M);
 {$endif DOS}
+{$ifdef linux}
+  SetTextWinClipBoardData:=SetGlobalClipboardData(p,l);
+{$endif linux}
 {$ifdef Windows}
   h:=GlobalAlloc(GMEM_MOVEABLE or GMEM_DDESHARE,l+1);
   pp:=PAnsiChar(GlobalLock(h));