编辑器

修正linux下编辑器打开中文名文件的问题
This commit is contained in:
tslediter 2024-03-12 13:59:34 +08:00
parent 8202de23c9
commit 76bc4e3372
6 changed files with 108 additions and 92 deletions

View File

@ -546,11 +546,12 @@ type teditorform = class(TVCform) //
begin begin
if it then if it then
begin begin
if it.fisnewfile then self.Caption := (it.FEditer.ChangedFlag?"*":"")+ " new "; if it.fisnewfile then cp := (it.FEditer.ChangedFlag?"*":"")+ " new ";
else else
self.Caption := (it.FEditer.ChangedFlag?"*":"")+ it.OrigScriptPath; cp := (it.FEditer.ChangedFlag?"*":"")+ it.OrigScriptPath;
end else end else
caption := "-tsl编辑器"; cp := "-tsl编辑器";
Caption := to_ansi_str(cp);
ModifyEnCodeMenu(it); ModifyEnCodeMenu(it);
ModifySynMenu(it); ModifySynMenu(it);
save_opend_file_name(); save_opend_file_name();
@ -560,12 +561,13 @@ type teditorform = class(TVCform) //
cit := FEdter.GetCurrentItem(); cit := FEdter.GetCurrentItem();
if it=cit then if it=cit then
begin begin
if it.fisnewfile then self.Caption := (flg?"*":"")+ " new "//o.Caption;//it.ScriptPath+" -tsl编辑器"; if it.fisnewfile then cp := (flg?"*":"")+ " new "//o.Caption;//it.ScriptPath+" -tsl编辑器";
else else
self.Caption := (flg?"*":"")+ it.OrigScriptPath;//o.Caption;//it.ScriptPath+" -tsl编辑器"; cp := (flg?"*":"")+ it.OrigScriptPath;//o.Caption;//it.ScriptPath+" -tsl编辑器";
ModifyEnCodeMenu(it); ModifyEnCodeMenu(it);
end end
else caption := "-tsl 编辑器"; else cp := "-tsl 编辑器";
caption := to_ansi_str(cp);
end end
function OpenInOtherWnd(o,e) function OpenInOtherWnd(o,e)
begin begin
@ -1366,6 +1368,19 @@ type TBlockManager=class(TVCForm)
Fbtns ; Fbtns ;
FList; FList;
end end
type tdirlistbox = class(TListBox)
uses tslvcl,UtslCodeEditor;
function create(AOwner);
begin
inherited;
end
function getItemText(i);override;
begin
r := inherited;
return to_ansi_str(r); //"["$ i $"]" $
end
end
type tsearchdir = class(TCustomControl) type tsearchdir = class(TCustomControl)
uses tslvcl; uses tslvcl;
function Create(AOwner);override; function Create(AOwner);override;
@ -1388,7 +1403,7 @@ type tsearchdir = class(TCustomControl)
FBtns := array(); FBtns := array();
for i,v in array(array(2,28,120,230),array(148,2,500,230)) do for i,v in array(array(2,28,120,230),array(148,2,500,230)) do
begin begin
ls := new TListBox(self); ls := new tdirlistbox(self);
ls.SetBoundsRect(v); ls.SetBoundsRect(v);
ls.parent := self; ls.parent := self;
ls.Border := true; ls.Border := true;

View File

@ -17,6 +17,7 @@ TPagees; TPageItem
} }
function gettslexe(); function gettslexe();
function to_ansi_str(s);
type TPageItem=class() //±êÇ©Ïî type TPageItem=class() //±êÇ©Ïî
function Create(AOwner); function Create(AOwner);
begin begin
@ -194,7 +195,7 @@ type TPage=class(TCustomControl) //
dc.Stretchdraw(rc1,it.BitmapA);} dc.Stretchdraw(rc1,it.BitmapA);}
end end
rc[0]+= 20; rc[0]+= 20;
dc.DrawText(it.caption,rc,DT_nOPREFIX .| DT_LEFT .| DT_SINGLELINE .| DT_VCENTER); dc.DrawText(to_ansi_str(it.caption),rc,DT_nOPREFIX .| DT_LEFT .| DT_SINGLELINE .| DT_VCENTER);
end end
end end
if FCloseBtn and((FPageItems.Length()>0))then if FCloseBtn and((FPageItems.Length()>0))then
@ -2456,9 +2457,10 @@ type TEditer=class(TCustomcontrol) //
begin begin
if cit=it then if cit=it then
begin begin
if it.fisnewfile then Caption := (flg?"*":"")+" new "; if it.fisnewfile then cp := (flg?"*":"")+" new ";
else else
Caption :=(flg?"*":"")+it.OrigScriptPath; cp :=(flg?"*":"")+it.OrigScriptPath;
Caption := to_ansi_str(cp);
end end
callDatafunction(OnPageEditerChanged,it,flg); callDatafunction(OnPageEditerChanged,it,flg);
it.BitmapA := flg?GetNeedSaveBmp():GetNneedSaveBmp(); it.BitmapA := flg?GetNeedSaveBmp():GetNneedSaveBmp();
@ -2488,12 +2490,13 @@ type TEditer=class(TCustomcontrol) //
FCurrentItemCode[length(FCurrentItemCode)]:= it; FCurrentItemCode[length(FCurrentItemCode)]:= it;
if it.fisnewfile then if it.fisnewfile then
begin begin
Caption :=(it.FEditer.ChangedFlag?"*":"")+" new "; cp :=(it.FEditer.ChangedFlag?"*":"")+" new ";
end end
else else
begin begin
Caption :=(it.FEditer.ChangedFlag?"*":"")+it.OrigScriptPath; cp :=(it.FEditer.ChangedFlag?"*":"")+it.OrigScriptPath;
end end
Caption := to_ansi_str(cp);
CallDatafunction(FOnPageItemSelChanged,self(true),it); CallDatafunction(FOnPageItemSelChanged,self(true),it);
cp := it.FEditer.Completion; cp := it.FEditer.Completion;
if cp and it.FInitCompletion then if cp and it.FInitCompletion then
@ -6364,7 +6367,7 @@ type TMouseMoveList=class(TListBox)
function getItemText(i);override; function getItemText(i);override;
begin begin
r := inherited; r := inherited;
return "["$ i $"]" $ r; return "["$ i $"]" $ to_ansi_str(r);
end end
function PaintIdx(idx,rc_,cvs);virtual; function PaintIdx(idx,rc_,cvs);virtual;
begin begin
@ -6424,7 +6427,11 @@ begin
r["ˢе±Ç°·ûºÅ"]:=getdbugfreshsymbmpinfo(); r["ˢе±Ç°·ûºÅ"]:=getdbugfreshsymbmpinfo();
return r; return r;
end end
function to_ansi_str(s);
begin
if IsTextUTF8(s) then return UTF8toansi(s);
return s;
end
function ReWriteString(fn,d); function ReWriteString(fn,d);
begin begin
if not ifstring(d)then return 0; if not ifstring(d)then return 0;

View File

@ -751,8 +751,8 @@ type ctslctrans = class(tmemoryclass)
if ptr and sz>0 then if ptr and sz>0 then
begin begin
return _tool.readbuf(ptr,sz); return _tool.readbuf(ptr,sz);
//setlength(r,sz); setlength(r,sz);
//for i := 0 to sz-1 do r[i+1]:= _tool.readbyte(ptr+i); for i := 0 to sz-1 do r[i+1]:= _tool.readbyte(ptr+i);
end end
return r; return r;
end end
@ -766,11 +766,17 @@ type ctslctrans = class(tmemoryclass)
sz := _size_(); sz := _size_();
if ifstring(s)and ptr and sz>0 and sz <= length(s)then if ifstring(s)and ptr and sz>0 and sz <= length(s)then
begin begin
_tool.writebuf(ptr,s,min(sz,length(s))); return _tool.writebuf(ptr,s,min(sz,length(s)));
{for i := 0 to min(sz,length(s))-1 do {for i := 0 to min(sz,length(s))-1 do
begin begin
_tool.writebyte(ptr+i,ord(s[i+1])); _tool.writebyte(ptr+i,ord(s[i+1]));
end} end}
bts := array();
for i := 0 to min(sz,length(s))-1 do
begin
bts[i] := ord(s[i+1]);
end
return _tool.writebytes(ptr,length(bts),bts);
end end
end end
end end
@ -1812,7 +1818,7 @@ type t_mem_mgr = class()
begin begin
if not(s and ifstring(s)) then return 0; if not(s and ifstring(s)) then return 0;
if ifnil(n) then n := length(s); if ifnil(n) then n := length(s);
return memcpy2(p,s,n) ; return memcpy2(p,s,min(n,length(s))) ;
end end
private private
function TSL_Malloc(sz:pointer):pointer; function TSL_Malloc(sz:pointer):pointer;
@ -1989,10 +1995,11 @@ type t_mem_mgr = class()
_f_ := static function(var dst:string;src:pointer;size_t:pointer):pointer;cdecl;external getdlsymaddress(get_std_dll(),"memcpy"); _f_ := static function(var dst:string;src:pointer;size_t:pointer):pointer;cdecl;external getdlsymaddress(get_std_dll(),"memcpy");
return ##_f_(dst,src,size_t); return ##_f_(dst,src,size_t);
end end
function memcpy2(dst:pointer ;src:string;size_t:pointer):pointer; function memcpy2(dst:pointer ; src:string;size_t:pointer):pointer;
begin begin
_f_ := static function(dst:pointer ;src:string;size_t:pointer):pointer;cdecl;external getdlsymaddress(get_std_dll(),"memcpy"); _f_ := static function(dst:pointer ; src:string;size_t:pointer):pointer;cdecl;external getdlsymaddress(get_std_dll(),"memcpy");
return ##_f_(dst,src,size_t); r := ##_f_(dst,src,size_t);
return r;
end end
function memcpy3(var dst:string ;var src:string;size_t:pointer):pointer; function memcpy3(var dst:string ;var src:string;size_t:pointer):pointer;
begin begin
@ -2074,7 +2081,7 @@ begin
begin begin
if len>0 then if len>0 then
begin begin
return get_mem_mgr().writebuf(p,s,len); return get_mem_mgr().writebuf(ptr,s,len);
end else end else
return get_mem_mgr().writestr(ptr,s); return get_mem_mgr().writestr(ptr,s);
end end

View File

@ -650,11 +650,6 @@ type tsgtkapi = class(tgtkapis)
function MultiByteToWideChar_a(CodePage:integer;dwFlags:integer;lpMultiByteStr:string;cbMultiByte:integer;var lpWideCharStr:string;cchWideChar:integer):integer; function MultiByteToWideChar_a(CodePage:integer;dwFlags:integer;lpMultiByteStr:string;cbMultiByte:integer;var lpWideCharStr:string;cchWideChar:integer):integer;
begin begin
end
function GetEncoderClsid(n:String;ed:pointer):integer;
begin
WriteStringToPtr(ed,n); //±£´æ
return -1;
end end
function EnableWindow(w,c); function EnableWindow(w,c);
begin begin
@ -2483,7 +2478,7 @@ type tsgtkapi = class(tgtkapis)
begin begin
c := gtk_clipboard_get(69); c := gtk_clipboard_get(69);
r := gtk_clipboard_wait_for_text(c); r := gtk_clipboard_wait_for_text(c);
if r then r := GtkStringToTsl(r); //if r then r := GtkStringToTsl(r);
//echo "\r\ncop wire:",writefile(rwraw(),"","/tmp/test12.txt",0,length(r),r); //echo "\r\ncop wire:",writefile(rwraw(),"","/tmp/test12.txt",0,length(r),r);
return r; return r;
end end
@ -2492,8 +2487,9 @@ type tsgtkapi = class(tgtkapis)
c := gtk_clipboard_get(69); c := gtk_clipboard_get(69);
if ifstring(s) and s then if ifstring(s) and s then
begin begin
gs := TslStringToGtk(s); //gs := TslStringToGtk(s);
return gtk_clipboard_set_text(c,gs,length(gs)); //return gtk_clipboard_set_text(c,gs,length(gs));
return gtk_clipboard_set_text(c,s,length(s));
end else end else
if ifnil(s) then gtk_clipboard_set_text(c,"",0); if ifnil(s) then gtk_clipboard_set_text(c,"",0);
return 1; return 1;
@ -2565,7 +2561,8 @@ type tsgtkapi = class(tgtkapis)
df := my_trim( ReadStringFromPtr(dfdir)); df := my_trim( ReadStringFromPtr(dfdir));
if df then if df then
begin begin
gtk_file_chooser_set_filename(cdlg,TslStringToGtk( df)); //gtk_file_chooser_set_filename(cdlg,TslStringToGtk( df));
gtk_file_chooser_set_filename(cdlg, df);
end end
end end
if GTK_RESPONSE_ACCEPT=gtk_dialog_run(cdlg)then if GTK_RESPONSE_ACCEPT=gtk_dialog_run(cdlg)then
@ -2664,14 +2661,16 @@ type tsgtkapi = class(tgtkapis)
end end
if gf then if gf then
begin begin
gf := GtkStringToTsl( gf);
fptr := obj._getvalue_("lpstrfile"); fptr := obj._getvalue_("lpstrfile");
gf+="\0";
WriteStringToPtr(fptr,gf,length(gf));
{//gf := GtkStringToTsl( gf);
bts := zeros(length(gf)+1); bts := zeros(length(gf)+1);
for i := 1 to length(gf) do for i := 1 to length(gf) do
begin begin
bts[i-1] := ord(gf[i]); bts[i-1] := ord(gf[i]);
end end
WriteBytesToPtr(fptr,bts); WriteBytesToPtr(fptr,bts);}
r := true; r := true;
end end
end end
@ -2782,12 +2781,14 @@ type tsgtkapi = class(tgtkapis)
df := (ReadStringFromPtr(dir)); df := (ReadStringFromPtr(dir));
if df then if df then
begin begin
gtk_file_chooser_set_filename(cdlg,TslStringToGtk( df)); //gtk_file_chooser_set_filename(cdlg,TslStringToGtk( df));
gtk_file_chooser_set_filename(cdlg,( df));
end end
end end
if GTK_RESPONSE_ACCEPT=gtk_dialog_run(cdlg) then if GTK_RESPONSE_ACCEPT=gtk_dialog_run(cdlg) then
begin begin
r := GtkStringToTsl( gtk_file_chooser_get_filename(cdlg)); //r := GtkStringToTsl( gtk_file_chooser_get_filename(cdlg));
r := ( gtk_file_chooser_get_filename(cdlg));
end end
gtk_widget_destroy(cdlg); gtk_widget_destroy(cdlg);
return r; return r;
@ -2812,9 +2813,12 @@ type tsgtkapi = class(tgtkapis)
return r; return r;
end end
procedure ILFree(pidl:pointer); procedure ILFree(pidl:pointer);
begin
if pidl>0 or pidl<0 then
begin begin
mt := unit(cstructurelib).get_mem_mgr(); mt := unit(cstructurelib).get_mem_mgr();
mt.tfree(pidl); mt.tfree(pidl);
end
end end
//caret ²åÈë·ûºÅ ´¦Àí //caret ²åÈë·ûºÅ ´¦Àí
function drawcaret(h,xy,f); function drawcaret(h,xy,f);

View File

@ -888,19 +888,6 @@ type tcustomimage=class(TSLUIBASE)
else t := lowercase(t_); else t := lowercase(t_);
if not(t in array("png","jpeg","bmp","gif","tiff"))then exit; if not(t in array("png","jpeg","bmp","gif","tiff"))then exit;
return FImageTypes[t]; //дúÂë return FImageTypes[t]; //дúÂë
vp := FImageTypes[t];
if vp then return vp;
dt := MemoryAlignmentCalculate(array((0,"byte[20]",array())),1,nil,nil);
vp := new tslcstructureobj(dt,nil);
//messagebox("image/"+t,"123",0);
nt := _wapi.AnsiToWidChar("image/"+t);
vvp := _wapi.GetEncoderClsid(nt,vp._getptr_);
if vvp <>-1 then
begin
FImageTypes[t]:= vp;
end
return vp;
end end
function IFhandle(h); function IFhandle(h);
begin begin
@ -938,12 +925,6 @@ type tcustomimage=class(TSLUIBASE)
return ; return ;
{$endif} {$endif}
FImageTypes := GetEncoderClsid(); FImageTypes := GetEncoderClsid();
return ;
FImageTypes := array();
for i,v in array("png","jpeg","bmp","gif","tiff") do
begin
GetFileType(v);
end
end end
end end
function create(); function create();
@ -1013,6 +994,12 @@ type tcustomimage=class(TSLUIBASE)
@param(t)(string)ÀàÐÍ ,"png" "bmp" "gif" @param(t)(string)ÀàÐÍ ,"png" "bmp" "gif"
**} **}
if not ifstring(p)then return -1; if not ifstring(p)then return -1;
s := ImageToString(t);
if ifstring(s) then
begin
return 1=writefile(rwraw(),"",p,0,length(s),s);
end else return -1;
///////////////µ÷Õû//////////////////////////////////
if not ifstring(t)then t := "png"; if not ifstring(t)then t := "png";
if not FHandle then return -1; if not FHandle then return -1;
vp := GetFileType(t); vp := GetFileType(t);
@ -1026,6 +1013,7 @@ type tcustomimage=class(TSLUIBASE)
@param(t)(string) png bmp %% @param(t)(string) png bmp %%
**} **}
if not FHandle then exit; if not FHandle then exit;
if not ifstring(t)then t := "png";
/////////ÕûÀíimagetostring////////// /////////ÕûÀíimagetostring//////////
vp := GetFileType(t); vp := GetFileType(t);
s := gdi.imagetostring(FHandle,vp); s := gdi.imagetostring(FHandle,vp);
@ -3446,8 +3434,8 @@ begin
return vs[v]; return vs[v];
end end
function GdipGetImageEncodersSize(var numencoders:integer;var size:integer):integer;stdcall ;external "Gdiplus.dll" name "GdipGetImageEncodersSize"; function GdipGetImageEncodersSize(var numencoders:integer;var size:integer):integer;stdcall ;external "Gdiplus.dll" name "GdipGetImageEncodersSize";
Function GdipGetImageEncoders(numEncoders:integer;size:integer;encoders:pointer):pointer;stdcall;external "gdiplus.dll" name "GdipGetImageEncoders"; Function GdipGetImageEncoders(numEncoders:integer;size:integer;encoders:pointer):pointer;stdcall;external "Gdiplus.dll" name "GdipGetImageEncoders";
function GetEncoderClsid(); function GetEncoderClsid(); //tslvclgetencoderclsid
begin begin
num := 0; // number of image encoders num := 0; // number of image encoders
size := 0; // size of the image encoder array in bytes size := 0; // size of the image encoder array in bytes

View File

@ -65,11 +65,6 @@ type twindowsapi = class()
MultiByteToWideChar_a(0, 0, c , -1, pwszUnicode , iSize-1); MultiByteToWideChar_a(0, 0, c , -1, pwszUnicode , iSize-1);
return pwszUnicode; return pwszUnicode;
end end
function GetEncoderClsid(n:String;ed:pointer);
begin
r := tslvclgetencoderclsid(n,ed);
return r;
end;
function GetSystemDirectory(); //»ñµÃwindowssystemĿ¼ function GetSystemDirectory(); //»ñµÃwindowssystemĿ¼
begin begin
s := ""; s := "";