From 72a6de8db64b2839cf1d8e832e6d3128e7c9e0e6 Mon Sep 17 00:00:00 2001 From: cxl Date: Wed, 26 May 2010 09:28:36 +0000 Subject: [PATCH] .CtrlLib: FileSel improved handling of active type git-svn-id: svn://ultimatepp.org/upp/trunk@2423 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/CtrlLib/FileSel.cpp | 32 ++++++++++++++++++++++++-------- uppsrc/CtrlLib/FileSel.h | 6 +++--- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/uppsrc/CtrlLib/FileSel.cpp b/uppsrc/CtrlLib/FileSel.cpp index e3f4958c7..1ea11a824 100644 --- a/uppsrc/CtrlLib/FileSel.cpp +++ b/uppsrc/CtrlLib/FileSel.cpp @@ -1109,6 +1109,14 @@ FileSel& FileSel::ClearTypes() return *this; } +FileSel& FileSel::ActiveType(int i) +{ + activetype.Clear(); + if(i >= 0 && i < type.GetCount()) + activetype = type.GetValue(i); + return *this; +} + FileSel& FileSel::AllFilesType() { return Type(t_("All files"), "*.*"); } @@ -1291,8 +1299,12 @@ bool FileSel::Execute(int _mode) { px += dp; } dir.HSizePos(dr.left, px + 4); - if(activetype >= 0 && activetype < type.GetCount()) - type.SetIndex(activetype); + int q = type.FindValue(activetype); + if(q >= 0) + type <<= q; + else + if(type.GetCount()) + type.SetIndex(0); int dlc = type.GetCount(); Load(); ActiveFocus(file.IsEditable() ? (Ctrl&)file : (Ctrl&)list); @@ -1319,10 +1331,10 @@ bool FileSel::Execute(int _mode) { int c = TopWindow::Run(appmodal); TopWindow::Close(); lastsby = list.GetSbPos(); + int ti = ~type; type.Trim(dlc); - activetype = type.GetIndex(); - if(activetype >= dlc || activetype < 0) - activetype = 0; + if(ti >= 0 && ti < type.GetCount()) + activetype = type.GetValue(ti); if(c == IDOK) { String d = ~dir; if(filesystem->IsWin32()) @@ -1360,10 +1372,15 @@ void FileSel::Serialize(Stream& s) { netstack.Clear(); } #endif - int version = 9; + int version = 10; s / version; String ad = ~dir; - s / activetype % ad; + int dummy; + if(version < 10) + s / dummy; + else + s % activetype; + s % ad; dir <<= ad; if(version < 1) { String n = fn.At(0); @@ -1624,7 +1641,6 @@ FileSel::FileSel() { dir.DisplayAll(); dir.SetDropLines(24); - activetype = 0; readonly.Hide(); lastsby = 0; diff --git a/uppsrc/CtrlLib/FileSel.h b/uppsrc/CtrlLib/FileSel.h index 06880817a..21c8eff00 100644 --- a/uppsrc/CtrlLib/FileSel.h +++ b/uppsrc/CtrlLib/FileSel.h @@ -137,7 +137,7 @@ protected: String olddir; String basedir; - int activetype; + String activetype; String defext; String preselect; Vector fn; @@ -226,7 +226,7 @@ public: bool GetReadOnly() const { return readonly; } String GetActiveDir() const { return dir.GetData(); } - int GetActiveType() const { return activetype; } + int GetActiveType() const { return type.GetIndex(); } void Filesystem(FileSystemInfo& fsys) { filesystem = &fsys;} FileSystemInfo& GetFilesystem() const { return *filesystem; } @@ -236,7 +236,7 @@ public: FileSel& AllFilesType(); FileSel& ClearTypes(); FileSel& ActiveDir(const String& d) { dir <<= d; return *this; } - FileSel& ActiveType(int i) { activetype = i; return *this; } + FileSel& ActiveType(int i); FileSel& PreSelect(const String& path); FileSel& DefaultExt(const char *ext) { defext = ext; return *this; } FileSel& Multi(bool b = true) { multi = b; return *this; }