mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-21 06:45:39 -06:00
CtrlLib: FileSel: Improved logic of adding extension
This commit is contained in:
parent
81d06c1b25
commit
9dea38484b
4 changed files with 59 additions and 1 deletions
|
|
@ -1037,7 +1037,12 @@ void FileSel::AddName(Vector<String>& fn, String& f) {
|
||||||
if(f[0] == '\"' && f.GetCount() > 2)
|
if(f[0] == '\"' && f.GetCount() > 2)
|
||||||
f = f.Mid(1, f.GetCount() - 2);
|
f = f.Mid(1, f.GetCount() - 2);
|
||||||
int q = f.ReverseFind('.');
|
int q = f.ReverseFind('.');
|
||||||
if(q < 0 || Filter(f.Mid(q + 1), // "(file.xxx)" should add extension too, allow just some
|
String typed_ext; // typed by user
|
||||||
|
if(q >= 0)
|
||||||
|
typed_ext = f.Mid(q + 1);
|
||||||
|
if(q < 0 || // no extension
|
||||||
|
force_ext && allowed_ext.Find(typed_ext) < 0 ||
|
||||||
|
Filter(f.Mid(q + 1), // "(file.xxx)" should add extension too, allow just some
|
||||||
[](int c) { return IsAlNum(c) || findarg(c, '_', '-') >= 0 ? 0 : c; }
|
[](int c) { return IsAlNum(c) || findarg(c, '_', '-') >= 0 ? 0 : c; }
|
||||||
).GetCount()) {
|
).GetCount()) {
|
||||||
String t = GetMask();
|
String t = GetMask();
|
||||||
|
|
@ -1991,6 +1996,31 @@ bool FileSel::Execute(int _mode) {
|
||||||
}
|
}
|
||||||
if(default_name.GetCount() && mode == SAVEAS)
|
if(default_name.GetCount() && mode == SAVEAS)
|
||||||
file <<= default_name;
|
file <<= default_name;
|
||||||
|
|
||||||
|
force_ext = true;
|
||||||
|
allowed_ext.Clear();
|
||||||
|
for(String mm : mask) {
|
||||||
|
if(!force_ext)
|
||||||
|
break;
|
||||||
|
for(String m : Split(mm, ' ')) {
|
||||||
|
if(!force_ext)
|
||||||
|
break;
|
||||||
|
int q = m.Find('.');
|
||||||
|
if(q < 0)
|
||||||
|
force_ext = false;
|
||||||
|
else {
|
||||||
|
m = m.Mid(q + 1);
|
||||||
|
if(m.Find('*') >= 0 || m.Find('?') >= 0)
|
||||||
|
force_ext = false;
|
||||||
|
else
|
||||||
|
allowed_ext.FindAdd(m);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DDUMP(force_ext);
|
||||||
|
DDUMP(allowed_ext);
|
||||||
|
|
||||||
FileUpdate();
|
FileUpdate();
|
||||||
Update();
|
Update();
|
||||||
int c = TopWindow::Run(appmodal);
|
int c = TopWindow::Run(appmodal);
|
||||||
|
|
|
||||||
|
|
@ -229,6 +229,9 @@ protected:
|
||||||
Ctrl *file_ctrl = NULL;
|
Ctrl *file_ctrl = NULL;
|
||||||
int file_ctrl_cx;
|
int file_ctrl_cx;
|
||||||
|
|
||||||
|
bool force_ext = true; // -> false if there is wildcard mask allowing set of exts
|
||||||
|
Index<String> allowed_ext; // allowed extensions typed by user if force_ext
|
||||||
|
|
||||||
static StaticMutex li_mutex;
|
static StaticMutex li_mutex;
|
||||||
static void (*li_current)(const String& path, Image& result);
|
static void (*li_current)(const String& path, Image& result);
|
||||||
static String li_path;
|
static String li_path;
|
||||||
|
|
|
||||||
9
upptst/FileSelSaveExt/FileSelSaveExt.upp
Normal file
9
upptst/FileSelSaveExt/FileSelSaveExt.upp
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
uses
|
||||||
|
CtrlLib;
|
||||||
|
|
||||||
|
file
|
||||||
|
main.cpp;
|
||||||
|
|
||||||
|
mainconfig
|
||||||
|
"" = "GUI";
|
||||||
|
|
||||||
16
upptst/FileSelSaveExt/main.cpp
Normal file
16
upptst/FileSelSaveExt/main.cpp
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
#include <CtrlLib/CtrlLib.h>
|
||||||
|
|
||||||
|
using namespace Upp;
|
||||||
|
|
||||||
|
GUI_APP_MAIN
|
||||||
|
{
|
||||||
|
FileSel sel;
|
||||||
|
sel.ActiveDir(GetExeFolder());
|
||||||
|
sel.Type("files", "*.txt *.cpp");
|
||||||
|
sel.Type("files", "*.c");
|
||||||
|
sel.ExecuteSaveAs();
|
||||||
|
DDUMP(~sel);
|
||||||
|
sel.Type("all", "*.*");
|
||||||
|
sel.ExecuteSaveAs();
|
||||||
|
DDUMP(~sel);
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue