CtrlLib: Added some methods to gtk FileSelNative to streamline the interface with Win32

This commit is contained in:
Mirek Fidler 2022-03-20 14:41:11 +01:00
parent a5f6307a49
commit 1cd7636f00
5 changed files with 20 additions and 3 deletions

View file

@ -341,6 +341,11 @@ class FileSelNative {
bool Execute0(int mode, const char *title);
public:
void Serialize(Stream& s);
void New() { path.Clear(); }
bool IsNew() const { return path.IsEmpty(); }
bool Execute(bool open, const char *title = NULL) { return Execute0(open, title); }
bool ExecuteOpen(const char *title = NULL) { return Execute(true, title); }
bool ExecuteSaveAs(const char *title = NULL) { return Execute(false, title); }
@ -357,6 +362,8 @@ public:
int GetCount() const { return path.GetCount(); }
const String& operator[](int i) const { return path[i]; }
String GetActiveDir() const { return ipath; }
FileSelNative& Type(const char *name, const char *ext) { type.Add(MakeTuple(String(name), String(ext))); return *this; }
FileSelNative& AllFilesType();
FileSelNative& Asking(bool b = true) { confirm = b; return *this; }

View file

@ -15,6 +15,12 @@ FileSelNative& FileSelNative::AllFilesType() {
return Type(t_("All files"), "*.*");
}
void FileSelNative::Serialize(Stream& s) {
int version = 1;
s / version;
s / activetype % ipath;
}
bool FileSelNative::Execute0(int mode, const char *title)
{
Ctrl::ReleaseCtrlCapture();
@ -70,6 +76,9 @@ bool FileSelNative::Execute0(int mode, const char *title)
g_slist_free (list);
}
ret = true;
gchar *h = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(fc));
ipath = h;
g_free(h);
}
gtk_widget_destroy(fc);
return ret;

View file

@ -1,4 +1,5 @@
#include "CtrlLib.h"
#include "CtrlLib.h"
#ifdef GUI_WIN
#ifndef PLATFORM_WINCE

View file

@ -7,7 +7,7 @@ GUI_APP_MAIN
FileSelNative sel;
sel.ActiveDir(GetHomeDirectory());
while(sel.ExecuteSelectDir("Just a test"))
PromptOK(sel.Get());
PromptOK(sel.Get() + "&" + "active dir: " + sel.GetActiveDir());
sel.AllFilesType();
sel.Type("Test2", "*.tst");