diff options
author | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2008-03-14 12:24:19 +0000 |
---|---|---|
committer | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2008-03-14 12:24:19 +0000 |
commit | ac9f0769fc3e837c82ad07c16a1d16d2dc180f1d (patch) | |
tree | b4d9a81be44b1d09fb71b7f194be590148c5c78d /src | |
parent | 777cd7fe27ccbbffb69519829442a03e9c28d2d4 (diff) | |
download | fpGUI-ac9f0769fc3e837c82ad07c16a1d16d2dc180f1d.tar.xz |
* Applied various patch from Vladimir which implements locale file encoding support and improves the file dialog.
Diffstat (limited to 'src')
-rw-r--r-- | src/build.bat | 2 | ||||
-rwxr-xr-x | src/build.sh | 2 | ||||
-rw-r--r-- | src/corelib/gdi/gfx_gdi.pas | 18 | ||||
-rw-r--r-- | src/corelib/gdi/gfx_utils_impl.inc | 33 | ||||
-rw-r--r-- | src/corelib/gfx_utils.pas | 16 | ||||
-rw-r--r-- | src/corelib/gfxbase.pas | 24 | ||||
-rw-r--r-- | src/corelib/x11/gfx_utils_impl.inc | 34 | ||||
-rw-r--r-- | src/corelib/x11/gfx_x11.pas | 8 | ||||
-rw-r--r-- | src/extrafpc.cfg | 5 | ||||
-rw-r--r-- | src/gui/gui_basegrid.pas | 22 | ||||
-rw-r--r-- | src/gui/gui_dialogs.pas | 45 |
11 files changed, 145 insertions, 64 deletions
diff --git a/src/build.bat b/src/build.bat index 1fe4669e..3043df3a 100644 --- a/src/build.bat +++ b/src/build.bat @@ -1,2 +1,2 @@ -fpc @extrafpc.cfg gui\fpgui_package.pas -dRELEASE -dGDI +fpc -dRELEASE -dGDI @extrafpc.cfg gui\fpgui_package.pas diff --git a/src/build.sh b/src/build.sh index b0aeae39..910f80fa 100755 --- a/src/build.sh +++ b/src/build.sh @@ -1,2 +1,2 @@ -fpc @extrafpc.cfg gui/fpgui_package.pas -dRELEASE -dX11 +fpc -dRELEASE -dX11 @extrafpc.cfg gui/fpgui_package.pas diff --git a/src/corelib/gdi/gfx_gdi.pas b/src/corelib/gdi/gfx_gdi.pas index b198fa24..41505413 100644 --- a/src/corelib/gdi/gfx_gdi.pas +++ b/src/corelib/gdi/gfx_gdi.pas @@ -210,8 +210,7 @@ type { TfpgFileListImpl } TfpgFileListImpl = class(TfpgFileListBase) - function InitializeEntry(sr: TSearchRec): TFileEntry; override; - function UpdateDirectory(const aDirectory: TfpgString): TfpgString; override; + procedure PopulateSpecialDirs(const aDirectory: TfpgString); override; end; implementation @@ -1999,18 +1998,7 @@ end; { TfpgFileListImpl } -function TfpgFileListImpl.InitializeEntry(sr: TSearchRec): TFileEntry; -begin - Result := inherited InitializeEntry(sr); - if Assigned(Result) then - begin - Result.Name := UTF8Encode(Result.Name); - Result.Extention := UTF8Encode(Result.Extention); - end; -end; - -function TfpgFileListImpl.UpdateDirectory(const aDirectory: TfpgString - ): TfpgString; +procedure TfpgFileListImpl.PopulateSpecialDirs(const aDirectory: TfpgString); var n: integer; drvs: string; @@ -2035,7 +2023,7 @@ begin end; end; - Result := inherited UpdateDirectory(aDirectory); + inherited PopulateSpecialDirs(aDirectory); end; initialization diff --git a/src/corelib/gdi/gfx_utils_impl.inc b/src/corelib/gdi/gfx_utils_impl.inc index f9ee80b3..2597d977 100644 --- a/src/corelib/gdi/gfx_utils_impl.inc +++ b/src/corelib/gdi/gfx_utils_impl.inc @@ -2,5 +2,38 @@ // GDI specific implementations of RTL wrapper functions +function fpgFindFirst(const Path: TfpgString; Attr: Longint; out + Rslt: TSearchRec): Longint; +begin + Result := FindFirst(Utf8ToAnsi(Path), Attr, Rslt); + Rslt.Name := AnsiToUtf8(Rslt.Name); +end; + +function fpgFindNext(var Rslt: TSearchRec): Longint; +begin + Result := FindNext(Rslt); + Rslt.Name := AnsiToUtf8(Rslt.Name); +end; + +function fpgGetCurrentDir: TfpgString; +begin + Result := AnsiToUtf8(GetCurrentDir); +end; + +function fpgSetCurrentDir(const NewDir: TfpgString): Boolean; +begin + Result := SetCurrentDir(Utf8ToAnsi(NewDir)); +end; + +function fpgExpandFileName(const FileName: TfpgString): TfpgString; +begin + Result := AnsiToUtf8(ExpandFileName(Utf8ToAnsi(FileName))); +end; + +function fpgFileExists(const FileName: TfpgString): Boolean; +begin + Result := FileExists(Utf8ToAnsi(FileName)); +end; + diff --git a/src/corelib/gfx_utils.pas b/src/corelib/gfx_utils.pas index 205a0e79..584c888b 100644 --- a/src/corelib/gfx_utils.pas +++ b/src/corelib/gfx_utils.pas @@ -7,21 +7,20 @@ interface uses Classes, SysUtils, gfxbase; - // Common functions for all platforms function fpgAddTrailingValue(const ALine, AValue: TfpgString; ADuplicates: boolean = true): TfpgString; - - // RTL wrapper filesystem functions with platform specific encodings -// function fpgFindFirst(const Path: TfpgString; Attr: Longint; out Rslt: TSearchRec): Longint; - +function fpgFindFirst(const Path: TfpgString; Attr: Longint; out Rslt: TSearchRec): Longint; +function fpgFindNext(var Rslt: TSearchRec): Longint; +function fpgGetCurrentDir: TfpgString; +function fpgSetCurrentDir(const NewDir: TfpgString): Boolean; +function fpgExpandFileName(const FileName: TfpgString): TfpgString; +function fpgFileExists(const FileName: TfpgString): Boolean; { *** Examples of others we could do *** } -// function fpgGetCurrentDir: TfpgString; -// function fpgSetCurrentDir(const NewDir: TfpgString): Boolean; // function fpgCreateDir(const NewDir: TfpgString): Boolean; // function fpgRemoveDir(const Dir: TfpgString): Boolean; // function fpgForceDirectories(const Dir: TfpgString): Boolean; @@ -61,8 +60,5 @@ begin end; - - - end. diff --git a/src/corelib/gfxbase.pas b/src/corelib/gfxbase.pas index 627955b8..0fa7dfeb 100644 --- a/src/corelib/gfxbase.pas +++ b/src/corelib/gfxbase.pas @@ -467,7 +467,7 @@ type protected FSpecialDirs: TStringList; function InitializeEntry(sr: TSearchRec): TFileEntry; virtual; - function UpdateDirectory(const aDirectory: TfpgString): TfpgString virtual; + procedure PopulateSpecialDirs(const aDirectory: TfpgString); virtual; public constructor Create; destructor Destroy; override; @@ -1899,7 +1899,7 @@ begin Result := e; end; -function TfpgFileListBase.UpdateDirectory(const aDirectory: TfpgString): TfpgString; +procedure TfpgFileListBase.PopulateSpecialDirs(const aDirectory: TfpgString); {Sets up FSpecialDirs list} var i, n: integer; @@ -1924,10 +1924,8 @@ begin inc(n); end; - FSpecialDirs.Insert(i, aDirectory); + FSpecialDirs.Insert(i, ExcludeTrailingPathDelimiter(aDirectory)); FCurrentSpecialDir := i; - - Result := aDirectory; end; constructor TfpgFileListBase.Create; @@ -1963,29 +1961,29 @@ var begin // default parameter value is current directory if aDirectory <> '' then - dir := ExpandFileName(aDirectory) + dir := fpgExpandFileName(aDirectory) else - GetDir(0, dir); + dir := fpgGetCurrentDir; // vvzh: now we have to use SetCurrentDir in order to make ExpandFileName work - if not SetCurrentDir(dir) then + if not fpgSetCurrentDir(dir) then begin Result := False; Exit; //==> end; - FDirectoryName := UpdateDirectory(dir); // Add PathDelim to end if it doesn't yet exist - FDirectoryName := IncludeTrailingPathDelimiter(FDirectoryName); - + FDirectoryName := IncludeTrailingPathDelimiter(dir); + PopulateSpecialDirs(FDirectoryName); + Clear; try // The extra 'or' includes Normal attribute files under Windows. faAnyFile doesn't return those. // Reported to FPC as bug 9440 in Mantis. - if SysUtils.FindFirst(FDirectoryName + '*', faAnyFile or $00000080, SearchRec) = 0 then + if fpgFindFirst(FDirectoryName + '*', faAnyFile or $00000080, SearchRec) = 0 then begin AddEntry(SearchRec); - while SysUtils.FindNext(SearchRec) = 0 do + while fpgFindNext(SearchRec) = 0 do begin AddEntry(SearchRec); end; diff --git a/src/corelib/x11/gfx_utils_impl.inc b/src/corelib/x11/gfx_utils_impl.inc index 316d7c09..607579cf 100644 --- a/src/corelib/x11/gfx_utils_impl.inc +++ b/src/corelib/x11/gfx_utils_impl.inc @@ -2,11 +2,35 @@ // X11 specific filesystem implementations of RTL wrapper functions -// Example +function fpgFindFirst(const Path: TfpgString; Attr: Longint; out + Rslt: TSearchRec): Longint; +begin + Result := FindFirst(Path, Attr, Rslt); +end; + +function fpgFindNext(var Rslt: TSearchRec): Longint; +begin + Result := FindNext(Rslt); +end; + +function fpgGetCurrentDir: TfpgString; +begin + Result := GetCurrentDir; +end; -{ -function fpgFindFirst(const Path: TfpgString; Attr: Longint; out Rslt: TSearchRec): Longint; +function fpgSetCurrentDir(const NewDir: TfpgString): Boolean; begin - Result := FindFirst(Path, Attr, Rstl); + Result := SetCurrentDir(NewDir); end; -} + +function fpgExpandFileName(const FileName: TfpgString): TfpgString; +begin + Result := ExpandFileName(FileName); +end; + +function fpgFileExists(const FileName: TfpgString): Boolean; +begin + Result := FileExists(FileName); +end; + + diff --git a/src/corelib/x11/gfx_x11.pas b/src/corelib/x11/gfx_x11.pas index 3f26072b..d737eaf2 100644 --- a/src/corelib/x11/gfx_x11.pas +++ b/src/corelib/x11/gfx_x11.pas @@ -205,7 +205,7 @@ type TfpgFileListImpl = class(TfpgFileListBase) function InitializeEntry(sr: TSearchRec): TFileEntry; override; - function UpdateDirectory(const aDirectory: TfpgString): TfpgString; override; + procedure PopulateSpecialDirs(const aDirectory: TfpgString); override; end; implementation @@ -2095,8 +2095,7 @@ begin end; end; -function TfpgFileListImpl.UpdateDirectory(const aDirectory: TfpgString - ): TfpgString; +procedure TfpgFileListImpl.PopulateSpecialDirs(const aDirectory: TfpgString); var ds: string; begin @@ -2106,9 +2105,10 @@ begin if Copy(ds, 1, 1) <> DirectorySeparator then ds := DirectorySeparator + ds; - Result := inherited UpdateDirectory(ds); + inherited PopulateSpecialDirs(ds); end; + initialization xapplication := nil; diff --git a/src/extrafpc.cfg b/src/extrafpc.cfg index 2808af57..66abc58b 100644 --- a/src/extrafpc.cfg +++ b/src/extrafpc.cfg @@ -8,7 +8,6 @@ # -u is the same as #UNDEF # - # * * * I M P O R T A N T * * * # You need to specify which backend you are compiling for # @@ -53,10 +52,10 @@ # searchpath for includefiles -Ficorelib #IFDEF X11 --Ficorelib/x11 + -Ficorelib/x11/ #ENDIF #IFDEF GDI --Ficorelib/gdi + -Ficorelib/gdi/ #ENDIF diff --git a/src/gui/gui_basegrid.pas b/src/gui/gui_basegrid.pas index d0760afd..90961d09 100644 --- a/src/gui/gui_basegrid.pas +++ b/src/gui/gui_basegrid.pas @@ -736,7 +736,16 @@ begin keyHome: begin - if (FFocusCol <> 1) and CanSelectCell(FFocusRow, 1) then + if FRowSelect then + begin + if (FFocusRow <> 1) and CanSelectCell(1, FFocusCol) then + begin + FFocusRow := 1; + FollowFocus; + RePaint; + end; + end + else if (FFocusCol <> 1) and CanSelectCell(FFocusRow, 1) then begin FFocusCol := 1; FollowFocus; @@ -746,7 +755,16 @@ begin keyEnd: begin - if (FFocusCol <> ColumnCount) and CanSelectCell(FFocusRow, ColumnCount) then + if FRowSelect then + begin + if (FFocusRow <> RowCount) and CanSelectCell(RowCount, FFocusCol) then + begin + FFocusRow := RowCount; + FollowFocus; + RePaint; + end; + end + else if (FFocusCol <> ColumnCount) and CanSelectCell(FFocusRow, ColumnCount) then begin FFocusCol := ColumnCount; FollowFocus; diff --git a/src/gui/gui_dialogs.pas b/src/gui/gui_dialogs.pas index 1437a492..002a24cd 100644 --- a/src/gui/gui_dialogs.pas +++ b/src/gui/gui_dialogs.pas @@ -207,6 +207,7 @@ implementation uses gfx_widget, + gfx_utils, gfx_utf8utils {$IFDEF MSWINDOWS} ,Windows // used by File Dialog @@ -898,7 +899,7 @@ begin e := grid.CurrentEntry; if (e = nil) then Exit; //==> - + if (e.EntryType = etDir) then SetCurrentDirectory(e.Name) else if (e.EntryType = etFile) then @@ -1053,13 +1054,26 @@ var begin if not consumed then begin - if (keycode = keyReturn) and (ActiveWidget = grid) then + if (ActiveWidget = grid) then begin - e := grid.CurrentEntry; - if (e <> nil) and (e.EntryType = etDir) then - begin - SetCurrentDirectory(e.Name); - consumed := True; + case keycode of + keyReturn: + begin + e := grid.CurrentEntry; + if (e <> nil) then + begin + if (e.EntryType = etDir) then + SetCurrentDirectory(e.Name) + else if (e.EntryType = etFile) then + btnOKClick(btnOK); + consumed := True; + end; + end; + keyBackSpace: + begin + SetCurrentDirectory('..'); + consumed := True; + end; end; end; end; @@ -1068,14 +1082,24 @@ begin end; procedure TfpgFileDialog.btnOKClick(Sender: TObject); +var + e: TFileEntry; begin - if not FOpenMode or SysUtils.FileExists(edFileName.Text) then + e := grid.CurrentEntry; + if e.EntryType = etDir then + begin + SetCurrentDirectory(e.Name); + Exit; //==> + end; + + if not FOpenMode or fpgFileExists(edFileName.Text) then begin ModalResult := 1; end; if ModalResult = 1 then - FileName := ExpandFileName(edFileName.Text); + // FileName := fpgExpandFileName(edFileName.Text); + FileName := grid.FileList.DirectoryName + edFileName.Text; end; constructor TfpgFileDialog.Create(AOwner: TComponent); @@ -1150,7 +1174,7 @@ end; procedure TfpgFileDialog.UpdateButtonState; begin if FOpenMode then - btnOK.Enabled := grid.CurrentEntry.EntryType = etFile + // btnOK.Enabled := grid.CurrentEntry.EntryType = etFile else btnOK.Enabled := edFileName.Text <> ''; end; @@ -1185,6 +1209,7 @@ begin grid.FocusRow := 1; grid.Update; + grid.SetFocus; end; function TfpgFileDialog.SelectFile(const AFilename: string): boolean; |