From b333a94ee6450159219a75127dd4d9a046a05559 Mon Sep 17 00:00:00 2001 From: cxl Date: Mon, 2 Nov 2009 16:54:26 +0000 Subject: [PATCH] CtrlLib: FileSel::Types, Select* family of utility FileSel based functions and classes; minor ide bug fixed git-svn-id: svn://ultimatepp.org/upp/trunk@1676 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/Core/src.tpp/CharSet$en-us.tpp | 20 ++++-- uppsrc/CtrlLib/CtrlLib.upp | 1 + uppsrc/CtrlLib/FileSel.cpp | 17 +++++ uppsrc/CtrlLib/FileSel.h | 15 ++++ uppsrc/CtrlLib/FileSelUtil.cpp | 72 +++++++++++++++++++ uppsrc/CtrlLib/init | 2 +- uppsrc/CtrlLib/src.tpp/FileList$en-us.tpp | 2 +- uppsrc/CtrlLib/src.tpp/FileSel$en-us.tpp | 13 ++++ uppsrc/CtrlLib/src.tpp/FileSelUtil$en-us.tpp | 73 ++++++++++++++++++++ uppsrc/RichText/RichText.h | 2 +- uppsrc/ide/Browser/Util.cpp | 2 +- uppsrc/ide/FindInFiles.cpp | 2 +- 12 files changed, 211 insertions(+), 10 deletions(-) create mode 100644 uppsrc/CtrlLib/FileSelUtil.cpp create mode 100644 uppsrc/CtrlLib/src.tpp/FileSelUtil$en-us.tpp diff --git a/uppsrc/Core/src.tpp/CharSet$en-us.tpp b/uppsrc/Core/src.tpp/CharSet$en-us.tpp index 13c6d30b0..d19253180 100644 --- a/uppsrc/Core/src.tpp/CharSet$en-us.tpp +++ b/uppsrc/Core/src.tpp/CharSet$en-us.tpp @@ -266,15 +266,25 @@ onst]_[@(0.0.255) char]_`*[*@3 src], [@(0.0.255) int]_[*@3 n], [_^byte^ byte]_[* in [%-*@3 charset] to UNICODE. [%-*@3 charset] [*/ can] be CHARSET`_UTF8. Invalid bytes are error`-escaped using 0xEExx private range.&] [s3;%% &] +[s4; &] +[s5;:FromUnicodeBuffer`(const wchar`*`,int`,byte`,int`): [_^String^ String]_[* FromUnicod +eBuffer]([@(0.0.255) const]_[_^wchar^ wchar]_`*[*@3 src], [@(0.0.255) int]_[*@3 len], +[_^byte^ byte]_[*@3 charset]_`=_CHARSET`_DEFAULT, [@(0.0.255) int]_[*@3 defchar]_`=_DEFAU +LTCHAR)&] +[s2;%% Converts [%-*@3 len] UNICODE characters from [%-*@3 src] to 8`-bit +encoding [%-*@3 charset]. [%-*@3 charset] [*/ can] be CHARSET`_UTF8. +Error`-escape characters 0xEExx are converted to xx bytes. If +code`-point does not exist in target encoding, [%-*@3 defchar ]is +used as result of conversion.&] +[s3;%% &] [s4;%% &] [s5;:FromUnicode`(const WString`&`,byte`,int`): [_^String^ String]_[* FromUnicode]([@(0.0.255) c onst]_[_^WString^ WString][@(0.0.255) `&]_[*@3 src], [_^byte^ byte]_[*@3 charset]_`=_CHARSE T`_DEFAULT, [@(0.0.255) int]_[*@3 defchar]_`=_DEFAULTCHAR)&] -[s2;%% Converts UNICODE [%-*@3 src] encoded in [%-*@3 charset] to 8`-bit -encoding. [%-*@3 charset] [*/ can] be CHARSET`_UTF8. Error`-escape -characters 0xEExx are converted to xx bytes. If code`-point does -not exist in target encoding, [%-*@3 defchar ]is used as result -of conversion.&] +[s2;%% Converts UNICODE [%-*@3 src] to 8`-bit encoding [%-*@3 charset]. +[%-*@3 charset] [*/ can] be CHARSET`_UTF8. Error`-escape characters +0xEExx are converted to xx bytes. If code`-point does not exist +in target encoding, [%-*@3 defchar ]is used as result of conversion.&] [s3;%% &] [s4;%% &] [s5;:ToCharset`(byte`,const String`&`,byte`,int`): [_^String^ String]_[* ToCharset]([_^byte^ b diff --git a/uppsrc/CtrlLib/CtrlLib.upp b/uppsrc/CtrlLib/CtrlLib.upp index aa15027fd..84cc7c659 100644 --- a/uppsrc/CtrlLib/CtrlLib.upp +++ b/uppsrc/CtrlLib/CtrlLib.upp @@ -82,6 +82,7 @@ file FileSel.h, FileList.cpp, FileSel.cpp, + FileSelUtil.cpp, Utilities readonly separator, CtrlUtil.h, PrinterJob.cpp, diff --git a/uppsrc/CtrlLib/FileSel.cpp b/uppsrc/CtrlLib/FileSel.cpp index cd0afb9fb..cbbc0c970 100644 --- a/uppsrc/CtrlLib/FileSel.cpp +++ b/uppsrc/CtrlLib/FileSel.cpp @@ -976,6 +976,23 @@ FileSel& FileSel::Type(const char *name, const char *ext) { return *this; } +FileSel& FileSel::Types(const char *d) { + Vector s = Split(d, '\n'); + for(int i = 0; i < s.GetCount(); i++) { + Vector h = Split(s[i], '\t'); + if(h.GetCount() == 2) + Type(h[0], h[1]); + } + return *this; +} + +FileSel& FileSel::ClearTypes() +{ + type.Clear(); + mask.Clear(); + return *this; +} + FileSel& FileSel::AllFilesType() { return Type(t_("All files"), "*.*"); } diff --git a/uppsrc/CtrlLib/FileSel.h b/uppsrc/CtrlLib/FileSel.h index d95594f9c..f34d633b9 100644 --- a/uppsrc/CtrlLib/FileSel.h +++ b/uppsrc/CtrlLib/FileSel.h @@ -219,7 +219,9 @@ public: FileSystemInfo& GetFilesystem() const { return *filesystem; } FileSel& Type(const char *name, const char *ext); + FileSel& Types(const char *d); FileSel& AllFilesType(); + FileSel& ClearTypes(); FileSel& ActiveDir(const String& d) { dir <<= d; return *this; } FileSel& ActiveType(int i) { activetype = i; return *this; } FileSel& PreSelect(const String& path); @@ -241,3 +243,16 @@ public: FileSel(); virtual ~FileSel(); }; + +String SelectFileOpen(const char *types); +String SelectFileSaveAs(const char *types); +String SelectLoadFile(const char *types); +bool SelectSaveFile(const char *types, const String& data); + +struct SelectFileIn : FileIn { + SelectFileIn(const char *types); +}; + +struct SelectFileOut : FileOut { + SelectFileOut(const char *types); +}; diff --git a/uppsrc/CtrlLib/FileSelUtil.cpp b/uppsrc/CtrlLib/FileSelUtil.cpp new file mode 100644 index 000000000..2c4de8485 --- /dev/null +++ b/uppsrc/CtrlLib/FileSelUtil.cpp @@ -0,0 +1,72 @@ +#include "CtrlLib.h" + +NAMESPACE_UPP + +FileSel& GFileSel() +{ + static FileSel fs; + ONCELOCK { + fs.ActiveDir(GetHomeDirectory()); + } + return fs; +} + +INITBLOCK { + RegisterGlobalConfig("GlobalFileSelector"); +} + +String SelectFileOpen(const char *types) +{ + FileSel& fs = GFileSel(); + LoadFromGlobal(fs, "GlobalFileSelector"); + fs.ClearTypes(); + fs.Types(types); + bool b = fs.ExecuteOpen(); + StoreToGlobal(fs, "GlobalFileSelector"); + return b ? ~fs : String::GetVoid(); +} + +String SelectFileSaveAs(const char *types) +{ + FileSel& fs = GFileSel(); + LoadFromGlobal(fs, "GlobalFileSelector"); + fs.ClearTypes(); + fs.Types(types); + bool b = fs.ExecuteSaveAs(); + StoreToGlobal(fs, "GlobalFileSelector"); + return b ? ~fs : String::GetVoid(); +} + +SelectFileIn::SelectFileIn(const char *types) +{ + for(;;) { + String p = SelectFileOpen(types); + if(p.GetCount() == 0 || Open(p)) + return; + Exclamation(t_("Unable to open [* \1") + p + t_("\1] for reading!")); + } +} + +SelectFileOut::SelectFileOut(const char *types) +{ + for(;;) { + String p = SelectFileOpen(types); + if(p.GetCount() == 0 || Open(p)) + return; + Exclamation(t_("Unable to open [* \1") + p + t_("\1] for writing!")); + } +} + +String SelectLoadFile(const char *types) +{ + String p = SelectFileOpen(types); + return p.GetCount() ? LoadFile(p) : String::GetVoid(); +} + +bool SelectSaveFile(const char *types, const String& data) +{ + String p = SelectFileSaveAs(types); + return p.GetCount() && SaveFile(p, data); +} + +END_UPP_NAMESPACE diff --git a/uppsrc/CtrlLib/init b/uppsrc/CtrlLib/init index 2acf473cb..c31c44952 100644 --- a/uppsrc/CtrlLib/init +++ b/uppsrc/CtrlLib/init @@ -2,7 +2,7 @@ #define _CtrlLib_icpp_init_stub #include "CtrlCore/init" #include "PdfDraw/init" -#define BLITZ_INDEX__ F772FB1BDED2795578D50B5F523477E45 +#define BLITZ_INDEX__ FBADDEDB113F9895930C5B0B11EFA4E7C #include "CtrlLib.icpp" #undef BLITZ_INDEX__ #endif diff --git a/uppsrc/CtrlLib/src.tpp/FileList$en-us.tpp b/uppsrc/CtrlLib/src.tpp/FileList$en-us.tpp index 0c77803de..06d0b0123 100644 --- a/uppsrc/CtrlLib/src.tpp/FileList$en-us.tpp +++ b/uppsrc/CtrlLib/src.tpp/FileList$en-us.tpp @@ -369,4 +369,4 @@ specifies the file system interface.&] style])&] [s2;%% Returns the OS dependent icon of [%-*@3 drive`_style].&] [s3;%% &] -[s0;%% ] \ No newline at end of file +[s0; ] \ No newline at end of file diff --git a/uppsrc/CtrlLib/src.tpp/FileSel$en-us.tpp b/uppsrc/CtrlLib/src.tpp/FileSel$en-us.tpp index 2701b8e4d..6047214ca 100644 --- a/uppsrc/CtrlLib/src.tpp/FileSel$en-us.tpp +++ b/uppsrc/CtrlLib/src.tpp/FileSel$en-us.tpp @@ -415,10 +415,23 @@ a set of file masks separated by spaces. Example: Type(`"Source files`", `"`*.c `*.h`").&] [s3; &] [s4; &] +[s5;:FileSel`:`:Types`(const char`*`): [_^FileSel^ FileSel][@(0.0.255) `&]_[* Types]([@(0.0.255) c +onst]_[@(0.0.255) char]_`*[*@3 d])&] +[s2;%% Adds a number of file types using simple text format: `'`\n`' +is used to separate types, `'`\t`' is used to separate file type +description and file mask.&] +[s2;%% Examples: Types(`"All files`\t`*.`*`\nText files`\t`*.txt`\nImage +files`\t`*.bmp `*.png `*.jpg `*.gif`")).&] +[s3;%% &] +[s4; &] [s5;:FileSel`:`:AllFilesType`(`): [_^FileSel^ FileSel][@(0.0.255) `&]_[* AllFilesType]()&] [s2;%% Same as Type(`"All files`", `"`*.`*`").&] [s3; &] [s4; &] +[s5;:FileSel`:`:ClearTypes`(`): [_^FileSel^ FileSel][@(0.0.255) `&]_[* ClearTypes]()&] +[s2;%% Removes all file types from FileSel.&] +[s3; &] +[s4; &] [s5;:FileSel`:`:ActiveDir`(const String`&`): [_^FileSel^ FileSel][@(0.0.255) `&]_[* ActiveD ir]([@(0.0.255) const]_[_^String^ String][@(0.0.255) `&]_[*@3 d])&] [s2;%% Sets the active directory of file selector (directory where diff --git a/uppsrc/CtrlLib/src.tpp/FileSelUtil$en-us.tpp b/uppsrc/CtrlLib/src.tpp/FileSelUtil$en-us.tpp new file mode 100644 index 000000000..057aa7d39 --- /dev/null +++ b/uppsrc/CtrlLib/src.tpp/FileSelUtil$en-us.tpp @@ -0,0 +1,73 @@ +topic "FileSel utilities"; +[2 $$0,0#00000000000000000000000000000000:Default] +[i448;a25;kKO9;2 $$1,0#37138531426314131252341829483380:class] +[l288;2 $$2,2#27521748481378242620020725143825:desc] +[0 $$3,0#96390100711032703541132217272105:end] +[H6;0 $$4,0#05600065144404261032431302351956:begin] +[i448;a25;kKO9;2 $$5,0#37138531426314131252341829483370:item] +[l288;a4;*@5;1 $$6,6#70004532496200323422659154056402:requirement] +[l288;i1121;b17;O9;~~~.1408;2 $$7,0#10431211400427159095818037425705:param] +[i448;b42;O9;2 $$8,8#61672508125594000341940100500538:tparam] +[b42;2 $$9,9#13035079074754324216151401829390:normal] +[{_} +[ {{10000@(113.42.0) [s0;%% [*@7;4 FileSel based utility functions]]}}&] +[s0;i448;a25;kKO9;@(0.0.255) &] +[s0;%% These functions simplify opening files using single global +file`-selector. The configuration of file`-selector is stored +into [^topic`:`/`/Core`/src`/SerializationUtils`$en`-us^ global +configuration].&] +[s0;%% &] +[ {{10000F(128)G(128)@1 [s0;%% [* Function List]]}}&] +[s4;H0; &] +[s5;:SelectFileOpen`(const char`*`): [_^String^ String]_[* SelectFileOpen]([@(0.0.255) cons +t]_[@(0.0.255) char]_`*[*@3 types])&] +[s2;%% Selects file for opening, [%-*@3 types] follow rules of [^topic`:`/`/CtrlLib`/src`/FileSel`$en`-us`#FileSel`:`:Types`(const char`*`)^ T +ypes] method of FileSel. If selections is canceled, returns empty +String.&] +[s3;%% &] +[s4;%% &] +[s5;:SelectFileSaveAs`(const char`*`): [_^String^ String]_[* SelectFileSaveAs]([@(0.0.255) c +onst]_[@(0.0.255) char]_`*[*@3 types])&] +[s2;%% Selects file for saving, [%-*@3 types] follow rules of [^topic`:`/`/CtrlLib`/src`/FileSel`$en`-us`#FileSel`:`:Types`(const char`*`)^ T +ypes] method of FileSel. If selections is canceled, returns empty +String.&] +[s3;%% &] +[s4;%% &] +[s5;:SelectLoadFile`(const char`*`): [_^String^ String]_[* SelectLoadFile]([@(0.0.255) cons +t]_[@(0.0.255) char]_`*[*@3 types])&] +[s2;%% Selects file and loads it, [%-*@3 types] follow rules of [^topic`:`/`/CtrlLib`/src`/FileSel`$en`-us`#FileSel`:`:Types`(const char`*`)^ T +ypes] method of FileSel. If selections is canceled or file cannot +be opened, returns empty String`::GetVoid().&] +[s3;%% &] +[s4;%% &] +[s5;:SelectSaveFile`(const char`*`,const String`&`): [@(0.0.255) bool]_[* SelectSaveFile]( +[@(0.0.255) const]_[@(0.0.255) char]_`*[*@3 types], [@(0.0.255) const]_[_^String^ String][@(0.0.255) `& +]_[*@3 data])&] +[s2;%% Selects file and saves [%-*@3 data] to it, [%-*@3 types] follow +rules of [^topic`:`/`/CtrlLib`/src`/FileSel`$en`-us`#FileSel`:`:Types`(const char`*`)^ T +ypes] method of FileSel. Returns true on success.&] +[s0; &] +[ {{10000@(113.42.0) [s0;%% [*@2 SelectFileIn class]]}}&] +[s0; &] +[s0; This class inherits FileIn. Its constructor invokes global FileSel +and opens selected file for reading:&] +[s4;H0; &] +[s5;:SelectFileIn`:`:SelectFileIn`(const char`*`): [* SelectFileIn]([@(0.0.255) const]_[@(0.0.255) c +har]_`*[*@3 types])&] +[s2;%% [%-*@3 types] follow rules of [^topic`:`/`/CtrlLib`/src`/FileSel`$en`-us`#FileSel`:`:Types`(const char`*`)^ T +ypes] method of FileSel. In case of any failure (selection is +canceled, open fails), the resulting object is not in opened +state (can be tested using operator bool).&] +[s0; &] +[ {{10000@(113.42.0) [s0;%% [*@2 SelectFileOut class]]}}&] +[s0; &] +[s0; This class inherits FileOut. Its constructor invokes global +FileSel and opens selected file for writing:&] +[s0; &] +[s5;:SelectFileOut`:`:SelectFileOut`(const char`*`): [* SelectFileOut]([@(0.0.255) const]_ +[@(0.0.255) char]_`*[*@3 types])&] +[s2;%% [%-*@3 types] follow rules of [^topic`:`/`/CtrlLib`/src`/FileSel`$en`-us`#FileSel`:`:Types`(const char`*`)^ T +ypes] method of FileSel. In case of any failure (selection is +canceled, open fails), the resulting object is not in opened +state (can be tested using operator bool).&] +[s0; ] \ No newline at end of file diff --git a/uppsrc/RichText/RichText.h b/uppsrc/RichText/RichText.h index 2bdaf1d8a..0782e428b 100644 --- a/uppsrc/RichText/RichText.h +++ b/uppsrc/RichText/RichText.h @@ -229,7 +229,7 @@ public: RichObject CreateDrawingObject(const Drawing& dwg, Size dot_size, Size size); RichObject CreateDrawingObject(const Drawing& dwg, int cx = 0, int cy = 0); RichObject CreatePNGObject(const Image& img, Size dot_size, Size size); -RichObject CreatePNGObject(const Image& img, int cx, int cy); +RichObject CreatePNGObject(const Image& img, int cx = 0, int cy = 0); RichObject CreateRawImageObject(const String& s, int cx = 0, int cy = 0); enum { diff --git a/uppsrc/ide/Browser/Util.cpp b/uppsrc/ide/Browser/Util.cpp index e2e538509..753974be0 100644 --- a/uppsrc/ide/Browser/Util.cpp +++ b/uppsrc/ide/Browser/Util.cpp @@ -24,7 +24,7 @@ String MakeCodeRef(const String& nest, const String& item) int GetMatchLen(const char *s, const char *t) { int i = 0; - while(s[i] == t[i] && *s) + while(s[i] == t[i] && s[i]) i++; return i; } diff --git a/uppsrc/ide/FindInFiles.cpp b/uppsrc/ide/FindInFiles.cpp index 01c220599..b5f112c35 100644 --- a/uppsrc/ide/FindInFiles.cpp +++ b/uppsrc/ide/FindInFiles.cpp @@ -374,7 +374,7 @@ void Ide::FindFolder() void Ide::ConstructFindInFiles() { ff.find.AddButton().SetMonoImage(CtrlImg::smallright()) <<= THISBACK(FindWildcard); ff.files <<= String("*.cpp *.h *.hpp *.c *.C *.cxx *.cc"); - ff.files.AddList((String)"*.cpp *.h *.hpp *.c *.C *.cxx *.cc"); + ff.files.AddList((String)"*.cpp *.h *.hpp *.c *.C *.cxx *.cc *.icpp"); ff.files.AddList((String)"*.txt"); ff.files.AddList((String)"*.*"); ff.folder.AddButton().SetMonoImage(CtrlImg::smalldown()) <<= THISBACK(FindStdDir);