mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-21 06:45:39 -06:00
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
This commit is contained in:
parent
30b3aaebd1
commit
b333a94ee6
12 changed files with 211 additions and 10 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -82,6 +82,7 @@ file
|
|||
FileSel.h,
|
||||
FileList.cpp,
|
||||
FileSel.cpp,
|
||||
FileSelUtil.cpp,
|
||||
Utilities readonly separator,
|
||||
CtrlUtil.h,
|
||||
PrinterJob.cpp,
|
||||
|
|
|
|||
|
|
@ -976,6 +976,23 @@ FileSel& FileSel::Type(const char *name, const char *ext) {
|
|||
return *this;
|
||||
}
|
||||
|
||||
FileSel& FileSel::Types(const char *d) {
|
||||
Vector<String> s = Split(d, '\n');
|
||||
for(int i = 0; i < s.GetCount(); i++) {
|
||||
Vector<String> 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"), "*.*");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
};
|
||||
|
|
|
|||
72
uppsrc/CtrlLib/FileSelUtil.cpp
Normal file
72
uppsrc/CtrlLib/FileSelUtil.cpp
Normal file
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -369,4 +369,4 @@ specifies the file system interface.&]
|
|||
style])&]
|
||||
[s2;%% Returns the OS dependent icon of [%-*@3 drive`_style].&]
|
||||
[s3;%% &]
|
||||
[s0;%% ]
|
||||
[s0; ]
|
||||
|
|
@ -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
|
||||
|
|
|
|||
73
uppsrc/CtrlLib/src.tpp/FileSelUtil$en-us.tpp
Normal file
73
uppsrc/CtrlLib/src.tpp/FileSelUtil$en-us.tpp
Normal file
|
|
@ -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; ]
|
||||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue