This repository has been archived by the owner on Jun 24, 2020. It is now read-only.
/
GTKFileDialog.cpp
71 lines (63 loc) · 2.72 KB
/
GTKFileDialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
* This file is part of GTK++ (libGTK++)
* Copyright © 2012 Rachel Mant (dx-mon@users.sourceforge.net)
*
* GTK++ is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GTK++ is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "stdafx.h"
/***************************************************************\
|* GTKFileDialog implementation *|
\***************************************************************/
char *GTKFileDialog::CWD = NULL;
GTKFileDialog::GTKFileDialog(GtkWindow *Window, const char *Title, GtkFileChooserAction Action, const std::vector<const char *> &FileTypes,
const std::vector<const char *> &FileTypeNames, const char *Button1_Type, int Button1_Result, const char *Button2_Type, int Button2_Result) :
GTKDialog(gtk_file_chooser_dialog_new(Title, Window, Action, Button1_Type, Button1_Result, Button2_Type, Button2_Result, NULL))
{
FileDialog = GTK_FILE_CHOOSER(Dialog);
gtk_file_chooser_set_do_overwrite_confirmation(FileDialog, TRUE);
AddFilters(FileTypes, FileTypeNames);
if (strncmp(Button1_Type, GTK_STOCK_SAVE, 8) == 0 || strncmp(Button2_Type, GTK_STOCK_SAVE, 8) == 0)
AddFilterChooser(FileTypes, FileTypeNames);
if (CWD == NULL)
CWD = gtk_file_chooser_get_current_folder(FileDialog);
gtk_file_chooser_set_current_folder(FileDialog, CWD);
}
void GTKFileDialog::AddFilters(const std::vector<const char *> &FileTypes, const std::vector<const char *> &FileTypeNames)
{
for (uint32_t i = 0; i < FileTypes.size(); i++)
{
Filter = gtk_file_filter_new();
gtk_file_filter_add_pattern(Filter, FileTypes[i]);
gtk_file_filter_set_name(Filter, FileTypeNames[i]);
gtk_file_chooser_add_filter(FileDialog, Filter);
if (i == 0)
gtk_file_chooser_set_filter(FileDialog, Filter);
}
}
void GTKFileDialog::AddFilterChooser(const std::vector<const char *> &/*FileTypes*/, const std::vector<const char *> &/*FileTypeNames*/)
{
/*GtkWidget *dropdown = gtk_combo_box_new();
GtkComboBox *cboFilters = GTK_COMBO_BOX(dropdown);
gtk_combo_box_*/
}
char *GTKFileDialog::GetSelectedFile()
{
g_free(CWD);
CWD = gtk_file_chooser_get_current_folder(FileDialog);
return gtk_file_chooser_get_filename(FileDialog);
}
const char *GTKFileDialog::GetWorkingDir()
{
return CWD;
}