Merge 94bd5da38b
into fea45b2d5b
This commit is contained in:
commit
75791cf393
|
@ -46,6 +46,20 @@ char *uiOpenFile(uiWindow *parent)
|
||||||
return runSavePanel(windowWindow(parent), o);
|
return runSavePanel(windowWindow(parent), o);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *uiOpenFolder(uiWindow *parent)
|
||||||
|
{
|
||||||
|
NSOpenPanel *o;
|
||||||
|
|
||||||
|
o = [NSOpenPanel openPanel];
|
||||||
|
[o setCanChooseFiles:NO];
|
||||||
|
[o setCanChooseDirectories:YES];
|
||||||
|
[o setResolvesAliases:NO];
|
||||||
|
[o setAllowsMultipleSelection:NO];
|
||||||
|
setupSavePanel(o);
|
||||||
|
// panel is autoreleased
|
||||||
|
return runSavePanel(windowWindow(parent), o);
|
||||||
|
}
|
||||||
|
|
||||||
char *uiSaveFile(uiWindow *parent)
|
char *uiSaveFile(uiWindow *parent)
|
||||||
{
|
{
|
||||||
NSSavePanel *s;
|
NSSavePanel *s;
|
||||||
|
|
|
@ -175,12 +175,26 @@ static void onOpenFileClicked(uiButton *b, void *data)
|
||||||
uiFreeText(filename);
|
uiFreeText(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void onOpenFolderClicked(uiButton *b, void *data)
|
||||||
|
{
|
||||||
|
uiEntry *entry = uiEntry(data);
|
||||||
|
char *filename;
|
||||||
|
|
||||||
|
filename = uiOpenFolder(mainwin);
|
||||||
|
if (filename == NULL) {
|
||||||
|
uiEntrySetText(entry, "(cancelled)");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
uiEntrySetText(entry, filename);
|
||||||
|
uiFreeText(filename);
|
||||||
|
}
|
||||||
|
|
||||||
static void onSaveFileClicked(uiButton *b, void *data)
|
static void onSaveFileClicked(uiButton *b, void *data)
|
||||||
{
|
{
|
||||||
uiEntry *entry = uiEntry(data);
|
uiEntry *entry = uiEntry(data);
|
||||||
char *filename;
|
char *filename;
|
||||||
|
|
||||||
filename = uiSaveFile(mainwin);
|
filename = uiSaveFile(mainwin, "untitled");
|
||||||
if (filename == NULL) {
|
if (filename == NULL) {
|
||||||
uiEntrySetText(entry, "(cancelled)");
|
uiEntrySetText(entry, "(cancelled)");
|
||||||
return;
|
return;
|
||||||
|
@ -259,10 +273,10 @@ static uiControl *makeDataChoosersPage(void)
|
||||||
1, 0, 1, 1,
|
1, 0, 1, 1,
|
||||||
1, uiAlignFill, 0, uiAlignFill);
|
1, uiAlignFill, 0, uiAlignFill);
|
||||||
|
|
||||||
button = uiNewButton("Save File");
|
button = uiNewButton("Open Folder");
|
||||||
entry = uiNewEntry();
|
entry = uiNewEntry();
|
||||||
uiEntrySetReadOnly(entry, 1);
|
uiEntrySetReadOnly(entry, 1);
|
||||||
uiButtonOnClicked(button, onSaveFileClicked, entry);
|
uiButtonOnClicked(button, onOpenFolderClicked, entry);
|
||||||
uiGridAppend(grid, uiControl(button),
|
uiGridAppend(grid, uiControl(button),
|
||||||
0, 1, 1, 1,
|
0, 1, 1, 1,
|
||||||
0, uiAlignFill, 0, uiAlignFill);
|
0, uiAlignFill, 0, uiAlignFill);
|
||||||
|
@ -270,10 +284,21 @@ static uiControl *makeDataChoosersPage(void)
|
||||||
1, 1, 1, 1,
|
1, 1, 1, 1,
|
||||||
1, uiAlignFill, 0, uiAlignFill);
|
1, uiAlignFill, 0, uiAlignFill);
|
||||||
|
|
||||||
|
button = uiNewButton("Save File");
|
||||||
|
entry = uiNewEntry();
|
||||||
|
uiEntrySetReadOnly(entry, 1);
|
||||||
|
uiButtonOnClicked(button, onSaveFileClicked, entry);
|
||||||
|
uiGridAppend(grid, uiControl(button),
|
||||||
|
0, 2, 1, 1,
|
||||||
|
0, uiAlignFill, 0, uiAlignFill);
|
||||||
|
uiGridAppend(grid, uiControl(entry),
|
||||||
|
1, 2, 1, 1,
|
||||||
|
1, uiAlignFill, 0, uiAlignFill);
|
||||||
|
|
||||||
msggrid = uiNewGrid();
|
msggrid = uiNewGrid();
|
||||||
uiGridSetPadded(msggrid, 1);
|
uiGridSetPadded(msggrid, 1);
|
||||||
uiGridAppend(grid, uiControl(msggrid),
|
uiGridAppend(grid, uiControl(msggrid),
|
||||||
0, 2, 2, 1,
|
0, 3, 2, 1,
|
||||||
0, uiAlignCenter, 0, uiAlignStart);
|
0, uiAlignCenter, 0, uiAlignStart);
|
||||||
|
|
||||||
button = uiNewButton("Message Box");
|
button = uiNewButton("Message Box");
|
||||||
|
@ -341,11 +366,24 @@ static void openClicked(uiMenuItem *item, uiWindow *w, void *data)
|
||||||
uiFreeText(filename);
|
uiFreeText(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void openFolderClicked(uiMenuItem *item, uiWindow *w, void *data)
|
||||||
|
{
|
||||||
|
char *filename;
|
||||||
|
|
||||||
|
filename = uiOpenFolder(mainwin);
|
||||||
|
if (filename == NULL) {
|
||||||
|
uiMsgBoxError(mainwin, "No folder selected", "Don't be alarmed!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
uiMsgBox(mainwin, "Folder selected", filename);
|
||||||
|
uiFreeText(filename);
|
||||||
|
}
|
||||||
|
|
||||||
static void saveClicked(uiMenuItem *item, uiWindow *w, void *data)
|
static void saveClicked(uiMenuItem *item, uiWindow *w, void *data)
|
||||||
{
|
{
|
||||||
char *filename;
|
char *filename;
|
||||||
|
|
||||||
filename = uiSaveFile(mainwin);
|
filename = uiSaveFile(mainwin, "untitled");
|
||||||
if (filename == NULL) {
|
if (filename == NULL) {
|
||||||
uiMsgBoxError(mainwin, "No file selected", "Don't be alarmed!");
|
uiMsgBoxError(mainwin, "No file selected", "Don't be alarmed!");
|
||||||
return;
|
return;
|
||||||
|
@ -403,6 +441,8 @@ int main(void)
|
||||||
menu = uiNewMenu("File");
|
menu = uiNewMenu("File");
|
||||||
item = uiMenuAppendItem(menu, "Open");
|
item = uiMenuAppendItem(menu, "Open");
|
||||||
uiMenuItemOnClicked(item, openClicked, NULL);
|
uiMenuItemOnClicked(item, openClicked, NULL);
|
||||||
|
item = uiMenuAppendItem(menu, "Open Folder");
|
||||||
|
uiMenuItemOnClicked(item, openFolderClicked, NULL);
|
||||||
item = uiMenuAppendItem(menu, "Save");
|
item = uiMenuAppendItem(menu, "Save");
|
||||||
uiMenuItemOnClicked(item, saveClicked, NULL);
|
uiMenuItemOnClicked(item, saveClicked, NULL);
|
||||||
item = uiMenuAppendQuitItem(menu);
|
item = uiMenuAppendQuitItem(menu);
|
||||||
|
|
16
test/page5.c
16
test/page5.c
|
@ -16,11 +16,24 @@ static void openFile(uiButton *b, void *data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void openFolder(uiButton *b, void *data)
|
||||||
|
{
|
||||||
|
char *fn;
|
||||||
|
|
||||||
|
fn = uiOpenFolder(parent);
|
||||||
|
if (fn == NULL)
|
||||||
|
uiLabelSetText(uiLabel(data), "(cancelled)");
|
||||||
|
else {
|
||||||
|
uiLabelSetText(uiLabel(data), fn);
|
||||||
|
uiFreeText(fn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void saveFile(uiButton *b, void *data)
|
static void saveFile(uiButton *b, void *data)
|
||||||
{
|
{
|
||||||
char *fn;
|
char *fn;
|
||||||
|
|
||||||
fn = uiSaveFile(parent);
|
fn = uiSaveFile(parent, "untitled");
|
||||||
if (fn == NULL)
|
if (fn == NULL)
|
||||||
uiLabelSetText(uiLabel(data), "(cancelled)");
|
uiLabelSetText(uiLabel(data), "(cancelled)");
|
||||||
else {
|
else {
|
||||||
|
@ -74,6 +87,7 @@ uiBox *makePage5(uiWindow *pw)
|
||||||
uiBoxAppend(page5, uiControl(hbox), 0);
|
uiBoxAppend(page5, uiControl(hbox), 0);
|
||||||
|
|
||||||
D("Open File", openFile);
|
D("Open File", openFile);
|
||||||
|
D("Open Folder", openFolder);
|
||||||
D("Save File", saveFile);
|
D("Save File", saveFile);
|
||||||
|
|
||||||
title = uiNewEntry();
|
title = uiNewEntry();
|
||||||
|
|
4
ui.h
4
ui.h
|
@ -130,6 +130,7 @@ _UI_EXTERN void uiWindowSetBorderless(uiWindow *w, int borderless);
|
||||||
_UI_EXTERN void uiWindowSetChild(uiWindow *w, uiControl *child);
|
_UI_EXTERN void uiWindowSetChild(uiWindow *w, uiControl *child);
|
||||||
_UI_EXTERN int uiWindowMargined(uiWindow *w);
|
_UI_EXTERN int uiWindowMargined(uiWindow *w);
|
||||||
_UI_EXTERN void uiWindowSetMargined(uiWindow *w, int margined);
|
_UI_EXTERN void uiWindowSetMargined(uiWindow *w, int margined);
|
||||||
|
_UI_EXTERN void uiWindowSetTopmost(uiWindow *w, int topmost);
|
||||||
_UI_EXTERN uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar);
|
_UI_EXTERN uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar);
|
||||||
|
|
||||||
typedef struct uiButton uiButton;
|
typedef struct uiButton uiButton;
|
||||||
|
@ -293,7 +294,8 @@ _UI_EXTERN void uiMenuAppendSeparator(uiMenu *m);
|
||||||
_UI_EXTERN uiMenu *uiNewMenu(const char *name);
|
_UI_EXTERN uiMenu *uiNewMenu(const char *name);
|
||||||
|
|
||||||
_UI_EXTERN char *uiOpenFile(uiWindow *parent);
|
_UI_EXTERN char *uiOpenFile(uiWindow *parent);
|
||||||
_UI_EXTERN char *uiSaveFile(uiWindow *parent);
|
_UI_EXTERN char *uiOpenFolder(uiWindow *parent);
|
||||||
|
_UI_EXTERN char *uiSaveFile(uiWindow *parent, const char *filename);
|
||||||
_UI_EXTERN void uiMsgBox(uiWindow *parent, const char *title, const char *description);
|
_UI_EXTERN void uiMsgBox(uiWindow *parent, const char *title, const char *description);
|
||||||
_UI_EXTERN void uiMsgBoxError(uiWindow *parent, const char *title, const char *description);
|
_UI_EXTERN void uiMsgBoxError(uiWindow *parent, const char *title, const char *description);
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
#define windowWindow(w) (GTK_WINDOW(uiControlHandle(uiControl(w))))
|
#define windowWindow(w) (GTK_WINDOW(uiControlHandle(uiControl(w))))
|
||||||
|
|
||||||
static char *filedialog(GtkWindow *parent, GtkFileChooserAction mode, const gchar *confirm)
|
static char *filedialog(GtkWindow *parent, GtkFileChooserAction mode, const gchar *confirm, const char *defaultFilename)
|
||||||
{
|
{
|
||||||
GtkWidget *fcd;
|
GtkWidget *fcd;
|
||||||
GtkFileChooser *fc;
|
GtkFileChooser *fc;
|
||||||
|
@ -23,6 +23,9 @@ static char *filedialog(GtkWindow *parent, GtkFileChooserAction mode, const gcha
|
||||||
gtk_file_chooser_set_show_hidden(fc, TRUE);
|
gtk_file_chooser_set_show_hidden(fc, TRUE);
|
||||||
gtk_file_chooser_set_do_overwrite_confirmation(fc, TRUE);
|
gtk_file_chooser_set_do_overwrite_confirmation(fc, TRUE);
|
||||||
gtk_file_chooser_set_create_folders(fc, TRUE);
|
gtk_file_chooser_set_create_folders(fc, TRUE);
|
||||||
|
if (defaultFilename != NULL) {
|
||||||
|
gtk_file_chooser_set_current_name(fc, defaultFilename);
|
||||||
|
}
|
||||||
response = gtk_dialog_run(GTK_DIALOG(fcd));
|
response = gtk_dialog_run(GTK_DIALOG(fcd));
|
||||||
if (response != GTK_RESPONSE_ACCEPT) {
|
if (response != GTK_RESPONSE_ACCEPT) {
|
||||||
gtk_widget_destroy(fcd);
|
gtk_widget_destroy(fcd);
|
||||||
|
@ -35,12 +38,17 @@ static char *filedialog(GtkWindow *parent, GtkFileChooserAction mode, const gcha
|
||||||
|
|
||||||
char *uiOpenFile(uiWindow *parent)
|
char *uiOpenFile(uiWindow *parent)
|
||||||
{
|
{
|
||||||
return filedialog(windowWindow(parent), GTK_FILE_CHOOSER_ACTION_OPEN, "_Open");
|
return filedialog(windowWindow(parent), GTK_FILE_CHOOSER_ACTION_OPEN, "_Open", NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *uiSaveFile(uiWindow *parent)
|
char *uiOpenFolder(uiWindow *parent)
|
||||||
{
|
{
|
||||||
return filedialog(windowWindow(parent), GTK_FILE_CHOOSER_ACTION_SAVE, "_Save");
|
return filedialog(windowWindow(parent), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, "_Open", NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *uiSaveFile(uiWindow *parent, const char *filename)
|
||||||
|
{
|
||||||
|
return filedialog(windowWindow(parent), GTK_FILE_CHOOSER_ACTION_SAVE, "_Save", filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void msgbox(GtkWindow *parent, const char *title, const char *description, GtkMessageType type, GtkButtonsType buttons)
|
static void msgbox(GtkWindow *parent, const char *title, const char *description, GtkMessageType type, GtkButtonsType buttons)
|
||||||
|
|
|
@ -229,6 +229,11 @@ void uiWindowSetMargined(uiWindow *w, int margined)
|
||||||
uiprivSetMargined(w->childHolderContainer, w->margined);
|
uiprivSetMargined(w->childHolderContainer, w->margined);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void uiWindowSetTopmost(uiWindow *w, int topmost)
|
||||||
|
{
|
||||||
|
gtk_window_set_keep_above(w->window, topmost == 1);
|
||||||
|
}
|
||||||
|
|
||||||
uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar)
|
uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar)
|
||||||
{
|
{
|
||||||
uiWindow *w;
|
uiWindow *w;
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
#define windowHWND(w) ((HWND) uiControlHandle(uiControl(w)))
|
#define windowHWND(w) ((HWND) uiControlHandle(uiControl(w)))
|
||||||
|
|
||||||
char *commonItemDialog(HWND parent, REFCLSID clsid, REFIID iid, FILEOPENDIALOGOPTIONS optsadd)
|
char *commonItemDialog(HWND parent, REFCLSID clsid, REFIID iid, FILEOPENDIALOGOPTIONS optsadd, const char *filename)
|
||||||
{
|
{
|
||||||
IFileDialog *d = NULL;
|
IFileDialog *d = NULL;
|
||||||
FILEOPENDIALOGOPTIONS opts;
|
FILEOPENDIALOGOPTIONS opts;
|
||||||
|
@ -33,6 +33,19 @@ char *commonItemDialog(HWND parent, REFCLSID clsid, REFIID iid, FILEOPENDIALOGOP
|
||||||
// always return NULL on error
|
// always return NULL on error
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// file name
|
||||||
|
if (filename != NULL) {
|
||||||
|
size_t size = strlen(filename) + 1;
|
||||||
|
wchar_t* filenameWchar = new wchar_t[size];
|
||||||
|
|
||||||
|
size_t outSize;
|
||||||
|
mbstowcs_s(&outSize, filenameWchar, size, filename, size - 1);
|
||||||
|
|
||||||
|
LPCWSTR filenameLPCWSTR = filenameWchar;
|
||||||
|
d->SetFileName(filenameLPCWSTR);
|
||||||
|
}
|
||||||
|
|
||||||
hr = d->GetOptions(&opts);
|
hr = d->GetOptions(&opts);
|
||||||
if (hr != S_OK) {
|
if (hr != S_OK) {
|
||||||
logHRESULT(L"error getting current options", hr);
|
logHRESULT(L"error getting current options", hr);
|
||||||
|
@ -83,19 +96,31 @@ char *uiOpenFile(uiWindow *parent)
|
||||||
disableAllWindowsExcept(parent);
|
disableAllWindowsExcept(parent);
|
||||||
res = commonItemDialog(windowHWND(parent),
|
res = commonItemDialog(windowHWND(parent),
|
||||||
CLSID_FileOpenDialog, IID_IFileOpenDialog,
|
CLSID_FileOpenDialog, IID_IFileOpenDialog,
|
||||||
FOS_NOCHANGEDIR | FOS_ALLNONSTORAGEITEMS | FOS_NOVALIDATE | FOS_PATHMUSTEXIST | FOS_FILEMUSTEXIST | FOS_SHAREAWARE | FOS_NOTESTFILECREATE | FOS_NODEREFERENCELINKS | FOS_FORCESHOWHIDDEN | FOS_DEFAULTNOMINIMODE);
|
FOS_NOCHANGEDIR | FOS_ALLNONSTORAGEITEMS | FOS_NOVALIDATE | FOS_PATHMUSTEXIST | FOS_FILEMUSTEXIST | FOS_SHAREAWARE | FOS_NOTESTFILECREATE | FOS_NODEREFERENCELINKS | FOS_FORCESHOWHIDDEN | FOS_DEFAULTNOMINIMODE, NULL);
|
||||||
enableAllWindowsExcept(parent);
|
enableAllWindowsExcept(parent);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *uiSaveFile(uiWindow *parent)
|
char *uiOpenFolder(uiWindow *parent)
|
||||||
|
{
|
||||||
|
char *res;
|
||||||
|
|
||||||
|
disableAllWindowsExcept(parent);
|
||||||
|
res = commonItemDialog(windowHWND(parent),
|
||||||
|
CLSID_FileOpenDialog, IID_IFileOpenDialog,
|
||||||
|
FOS_NOCHANGEDIR | FOS_ALLNONSTORAGEITEMS | FOS_NOVALIDATE | FOS_PATHMUSTEXIST | FOS_PICKFOLDERS | FOS_SHAREAWARE | FOS_NOTESTFILECREATE | FOS_NODEREFERENCELINKS | FOS_FORCESHOWHIDDEN | FOS_DEFAULTNOMINIMODE, NULL);
|
||||||
|
enableAllWindowsExcept(parent);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *uiSaveFile(uiWindow *parent, const char *filename)
|
||||||
{
|
{
|
||||||
char *res;
|
char *res;
|
||||||
|
|
||||||
disableAllWindowsExcept(parent);
|
disableAllWindowsExcept(parent);
|
||||||
res = commonItemDialog(windowHWND(parent),
|
res = commonItemDialog(windowHWND(parent),
|
||||||
CLSID_FileSaveDialog, IID_IFileSaveDialog,
|
CLSID_FileSaveDialog, IID_IFileSaveDialog,
|
||||||
FOS_OVERWRITEPROMPT | FOS_NOCHANGEDIR | FOS_ALLNONSTORAGEITEMS | FOS_NOVALIDATE | FOS_SHAREAWARE | FOS_NOTESTFILECREATE | FOS_NODEREFERENCELINKS | FOS_FORCESHOWHIDDEN | FOS_DEFAULTNOMINIMODE);
|
FOS_OVERWRITEPROMPT | FOS_NOCHANGEDIR | FOS_ALLNONSTORAGEITEMS | FOS_NOVALIDATE | FOS_SHAREAWARE | FOS_NOTESTFILECREATE | FOS_NODEREFERENCELINKS | FOS_FORCESHOWHIDDEN | FOS_DEFAULTNOMINIMODE, filename);
|
||||||
enableAllWindowsExcept(parent);
|
enableAllWindowsExcept(parent);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue