CtrlLib: FileSelButton now remembers last dir

This commit is contained in:
Mirek Fidler 2025-10-01 15:06:44 +02:00
parent fa325e4a6e
commit a9329d1b48
4 changed files with 43 additions and 35 deletions

View file

@ -431,22 +431,29 @@ void FileSelButton::OnAction()
Ctrl *owner = button.GetParent();
ASSERT(owner);
String old = ~*owner;
if(mode == MODE_DIR) {
for(int i = 0; i < 4; i++) {
if(DirectoryExists(old))
if(IsNull(old))
LoadFromGlobal(old, "FileSelButtonLastPath");
if(mode == MODE_DIR)
for(int i = 0; i < 8 && old.GetCount(); i++) {
if(DirectoryExists(old)) {
ActiveDir(old);
break;
}
old = GetFileFolder(old);
}
ActiveDir(old);
}
else
Set(old);
if(mode == MODE_OPEN ? ExecuteOpen(title) : mode == MODE_SAVE ? ExecuteSaveAs(title) : ExecuteSelectDir(title))
{
*owner <<= Get();
String path;
if(mode == MODE_OPEN ? ExecuteOpen(title) : mode == MODE_SAVE ? ExecuteSaveAs(title) : ExecuteSelectDir(title)) {
path = Get();
*owner <<= path;
owner->Action();
WhenSelected();
}
else
path = GetActiveDir();
if(path.GetCount())
StoreToGlobal(path, "FileSelButtonLastPath");
}
void FileSelButton::Detach()

View file

@ -157,14 +157,17 @@ DirDiffDlg::DirDiffDlg()
Title("Compare directories");
};
void DirDiffDlg::GatherFilesDeep(Index<String>& files, const String& base, const String& path)
void DirDiffDlg::GatherFilesDeep(VectorMap<String, Time>& files, const String& base, const String& path)
{
FindFile ff(AppendFileName(AppendFileName(base, path), "*.*"));
while(ff) {
String p = (path.GetCount() ? path + '/' : String()) + ff.GetName();
if(hidden || !ff.IsHidden()) {
if(ff.IsFile())
files.FindAdd(p);
if(ff.IsFile()) {
Time ftm = ff.GetLastWriteTime();
Time& tm = files.GetAdd(p, ftm);
tm = max(tm, ftm);
}
else
if(ff.IsFolder())
GatherFilesDeep(files, base, p);
@ -173,32 +176,32 @@ void DirDiffDlg::GatherFilesDeep(Index<String>& files, const String& base, const
}
}
bool DirDiffDlg::FileEqual(const String& f1, const String& f2, int& n)
bool DirDiffDlg::FileEqual(const String& f1, const String& f2, int& kind)
{
FileIn in1(f1);
FileIn in2(f2);
if(in1 && in2) {
in1.SetBufferSize(256 * 1024);
in2.SetBufferSize(256 * 1024);
kind = NORMAL_FILE;
if(in1.GetSize() != in2.GetSize())
return false;
while(!in1.IsEof() && !in2.IsEof()) {
String a = in1.GetLine();
String b = in2.GetLine();
String a = in1.Get(64*1024);
String b = in2.Get(64*1024);
if(a != b)
return false;
}
return true;
}
else
{
n = (in1 ? DELETED_FILE : NEW_FILE);
}
kind = in1 ? DELETED_FILE : NEW_FILE;
return false;
}
void DirDiffDlg::Compare()
{
Index<String> fs;
VectorMap<String, Time> fs;
GatherFilesDeep(fs, ~dir1, Null);
GatherFilesDeep(fs, ~dir2, Null);
@ -209,18 +212,18 @@ void DirDiffDlg::Compare()
removeright.Disable();
files.Clear();
Vector<String> f = fs.PickKeys();
Sort(f);
SortByKey(fs);
Progress pi(t_("Comparing.."));
pi.SetTotal(f.GetCount());
pi.SetTotal(fs.GetCount());
list.Clear();
Index<String> exts;
for(int i = 0; i < f.GetCount(); i++) {
for(int i = 0; i < fs.GetCount(); i++) {
if(pi.StepCanceled())
break;
String p1 = AppendFileName(~dir1, f[i]);
String p2 = AppendFileName(~dir2, f[i]);
String p = fs.GetKey(i);
String p1 = AppendFileName(~dir1, p);
String p2 = AppendFileName(~dir2, p);
int kind = NORMAL_FILE;
auto IsGit = [&](const String& path) {
return path.Find("/.git/") >= 0 || path.Find("\\.git/") >= 0 || path.Find("\\.git\\") >= 0 || path.Find("/.git\\") >= 0;
@ -228,11 +231,10 @@ void DirDiffDlg::Compare()
if(!FileEqual(p1, p2, kind) && !IsGit(p1) && !IsGit(p2)) {
exts.FindAdd(GetFileExt(p1));
FileInfo& m = list.Add();
m.file = f[i];
m.file = p;
m.path1 = p1;
m.path2 = p2;
m.time1 = FileGetTime(p1);
m.time2 = FileGetTime(p2);
m.time = fs[i];
m.kind = kind;
}
}
@ -281,7 +283,7 @@ void DirDiffDlg::ShowResult()
const FileInfo& fi = list[i];
int n = fi.kind;
String fn = ToLower(list[i].file);
if((IsNull(dlim) || fi.time1 >= dlim || fi.time2 >= dlim) &&
if((IsNull(dlim) || fi.time >= dlim) &&
(n == NORMAL_FILE && modified ||
n == DELETED_FILE && removed ||
n == NEW_FILE && added ||

View file

@ -160,7 +160,7 @@ bool PatchDiff::Open(const char *patch_path, const Vector<String>& target_dirs0)
fi.file = fn;
fi.path1 = fi.path2 = p;
fi.kind = failed ? FAILED_FILE : pe && x ? NORMAL_FILE : pe ? NEW_FILE : DELETED_FILE;
fi.time1 = fi.time2 = now;
fi.time = now;
if(failed)
failed_count++;
}

View file

@ -316,16 +316,15 @@ protected:
String file;
String path1;
String path2;
Time time1;
Time time2;
Time time;
int kind;
};
Array<FileInfo> list;
static bool FileEqual(const String& f1, const String& f2, int& n);
static bool FileEqual(const String& f1, const String& f2, int& kind);
void GatherFilesDeep(Index<String>& files, const String& base, const String& path);
void GatherFilesDeep(VectorMap<String, Time>& files, const String& base, const String& path);
void Compare();
void ShowResult();
void ClearFiles();