gtkIOStream  1.7.0
GTK+ << C++ IOStream operators for GTK+. Now with ORBing, numerical computation, audio client and more ...
FileDialog.H
Go to the documentation of this file.
1 /* Copyright 2000-2018 Matt Flax <flatmax@flatmax.org>
2  This file is part of GTK+ IOStream class set
3 
4  GTK+ IOStream is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  GTK+ IOStream is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You have received a copy of the GNU General Public License
15  along with GTK+ IOStream
16  */
17 #ifndef FILEDIALOG_H_
18 #define FILEDIALOG_H_
19 
20 #include "Container.H"
21 
24 class FileDialog : public Container {
25 public:
28  widget = gtk_file_chooser_dialog_new ("File", NULL, GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL);
29  }
30 
33  FileDialog(const std::string title, GtkWindow *parent, GtkFileChooserAction action, const char *stockImageName) {
34  widget = gtk_file_chooser_dialog_new (title.c_str(), parent, action, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, stockImageName, GTK_RESPONSE_ACCEPT, NULL);
35  }
36 
38  virtual ~FileDialog() {}
39 
43  void setDirectory(const std::string name){
44  gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(widget), name.c_str());
45  }
46 
51  void setFileName(const std::string name) {
52  gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(widget), name.c_str());
53  }
54 
58  std::string getName(){
59  char *fn=gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(widget));
60  std::string res;
61  if (fn!=NULL){
62  res=fn;
63  g_free(fn);
64  }
65  return res;
66  }
67 
68 // /* Allow setting the filename using the = operator.
69 // \param name The name to set the dialog entry box to.
70 // \return A reference to this class.
71 // */
72 // FileDialog &operator=(const std::string name) {
73 // setName(name);
74 // return *this;
75 // }
76 //
77 // /* Allow setting the filename using the = operator.
78 // \param name The name to set the dialog entry box to.
79 // \return A reference to this class.
80 // */
81 // FileDialog &operator=(const char *name) {
82 // setName(std::string(name));
83 // return *this;
84 // }
85 
89  gint run(){
90  return gtk_dialog_run(GTK_DIALOG(widget));
91  }
92 };
93 
94 class FileOpenDialog : public FileDialog {
95 public:
96  FileOpenDialog() : FileDialog("", NULL, GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_OPEN) {}
97  FileOpenDialog(const std::string title) : FileDialog(title, NULL, GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_OPEN) {}
98 };
99 
100 class FileSaveDialog : public FileDialog {
101  void init(){
102  gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(widget), TRUE); // set the dialog to warn on overwrite
103  }
104 public:
105  FileSaveDialog() : FileDialog("", NULL, GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_SAVE) {
106  init();
107  }
108  FileSaveDialog(const std::string title) : FileDialog(title, NULL, GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_SAVE) {
109  init();
110  }
111 };
112 
114 public:
115  FolderSelectDialog() : FileDialog("", NULL, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, GTK_STOCK_OPEN) {}
116  FolderSelectDialog(const std::string title) : FileDialog(title, NULL, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, GTK_STOCK_OPEN) {}
117 };
118 
120 public:
121  FolderCreateDialog() : FileDialog("", NULL, GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER, GTK_STOCK_NEW) {}
122  FolderCreateDialog(const std::string title) : FileDialog(title, NULL, GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER, GTK_STOCK_NEW) {}
123 };
124 
125 #endif // FILEDIALOG_H_
FileOpenDialog(const std::string title)
Definition: FileDialog.H:97
FileSaveDialog(const std::string title)
Definition: FileDialog.H:108
FileDialog()
Constructor.
Definition: FileDialog.H:27
virtual ~FileDialog()
Destructor.
Definition: FileDialog.H:38
FolderCreateDialog(const std::string title)
Definition: FileDialog.H:122
void setDirectory(const std::string name)
Definition: FileDialog.H:43
FolderSelectDialog(const std::string title)
Definition: FileDialog.H:116
GtkWidget * widget
The container based widget.
Definition: Widget.H:33
FileDialog(const std::string title, GtkWindow *parent, GtkFileChooserAction action, const char *stockImageName)
Definition: FileDialog.H:33
gint run()
Definition: FileDialog.H:89
void setFileName(const std::string name)
Definition: FileDialog.H:51
std::string getName()
Definition: FileDialog.H:58
gtkIOStream: /tmp/gtkiostream/include/FileDialog.H Source File
GTK+ IOStream  Beta