1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /** @file 3 * @brief Implementation of the file dialog interfaces defined in filedialogimpl.h 4 */ 5 /* Authors: 6 * Bob Jamison 7 * Johan Engelen <johan@shouraizou.nl> 8 * Joel Holdsworth 9 * Bruno Dilly 10 * Other dudes from The Inkscape Organization 11 * 12 * Copyright (C) 2004-2008 Authors 13 * Copyright (C) 2004-2007 The Inkscape Organization 14 * 15 * Released under GNU GPL v2+, read the file 'COPYING' for more information. 16 */ 17 18 #ifndef __FILE_DIALOGIMPL_H__ 19 #define __FILE_DIALOGIMPL_H__ 20 21 //Gtk includes 22 #include <gtkmm/filechooserdialog.h> 23 #include <glib/gstdio.h> 24 25 #include "filedialog.h" 26 #include "svg-preview.h" 27 28 namespace Gtk { 29 class CheckButton; 30 class ComboBoxText; 31 class Expander; 32 } 33 34 namespace Inkscape { 35 class URI; 36 37 namespace UI { 38 39 namespace View { 40 class SVGViewWidget; 41 } 42 43 namespace Dialog { 44 45 /*######################################################################### 46 ### Utility 47 #########################################################################*/ 48 void 49 fileDialogExtensionToPattern(Glib::ustring &pattern, 50 Glib::ustring &extension); 51 52 void 53 findEntryWidgets(Gtk::Container *parent, 54 std::vector<Gtk::Entry *> &result); 55 56 void 57 findExpanderWidgets(Gtk::Container *parent, 58 std::vector<Gtk::Expander *> &result); 59 60 class FileType 61 { 62 public: FileType()63 FileType(): name(), pattern(),extension(nullptr) {} 64 ~FileType() = default; 65 Glib::ustring name; 66 Glib::ustring pattern; 67 Inkscape::Extension::Extension *extension; 68 }; 69 70 /*######################################################################### 71 ### F I L E D I A L O G B A S E C L A S S 72 #########################################################################*/ 73 74 /** 75 * This class is the base implementation for the others. This 76 * reduces redundancies and bugs. 77 */ 78 class FileDialogBaseGtk : public Gtk::FileChooserDialog 79 { 80 public: 81 82 /** 83 * 84 */ FileDialogBaseGtk(Gtk::Window & parentWindow,const Glib::ustring & title,Gtk::FileChooserAction dialogType,FileDialogType type,gchar const * preferenceBase)85 FileDialogBaseGtk(Gtk::Window& parentWindow, const Glib::ustring &title, 86 Gtk::FileChooserAction dialogType, FileDialogType type, gchar const* preferenceBase) : 87 Gtk::FileChooserDialog(parentWindow, title, dialogType), 88 preferenceBase(preferenceBase ? preferenceBase : "unknown"), 89 _dialogType(type) 90 { 91 internalSetup(); 92 } 93 94 /** 95 * 96 */ FileDialogBaseGtk(Gtk::Window & parentWindow,const char * title,Gtk::FileChooserAction dialogType,FileDialogType type,gchar const * preferenceBase)97 FileDialogBaseGtk(Gtk::Window& parentWindow, const char *title, 98 Gtk::FileChooserAction dialogType, FileDialogType type, gchar const* preferenceBase) : 99 Gtk::FileChooserDialog(parentWindow, title, dialogType), 100 preferenceBase(preferenceBase ? preferenceBase : "unknown"), 101 _dialogType(type) 102 { 103 internalSetup(); 104 } 105 106 /** 107 * 108 */ 109 ~FileDialogBaseGtk() override 110 = default; 111 112 protected: 113 void cleanup( bool showConfirmed ); 114 115 Glib::ustring const preferenceBase; 116 /** 117 * What type of 'open' are we? (open, import, place, etc) 118 */ 119 FileDialogType _dialogType; 120 121 /** 122 * Our svg preview widget 123 */ 124 SVGPreview svgPreview; 125 126 /** 127 * Child widgets 128 */ 129 Gtk::CheckButton previewCheckbox; 130 Gtk::CheckButton svgexportCheckbox; 131 132 private: 133 void internalSetup(); 134 135 /** 136 * Callback for user changing preview checkbox 137 */ 138 void _previewEnabledCB(); 139 140 /** 141 * Callback for seeing if the preview needs to be drawn 142 */ 143 void _updatePreviewCallback(); 144 145 /** 146 * Callback to for SVG 2 to SVG 1.1 export. 147 */ 148 void _svgexportEnabledCB(); 149 }; 150 151 152 153 154 /*######################################################################### 155 ### F I L E O P E N 156 #########################################################################*/ 157 158 /** 159 * Our implementation class for the FileOpenDialog interface.. 160 */ 161 class FileOpenDialogImplGtk : public FileOpenDialog, public FileDialogBaseGtk 162 { 163 public: 164 165 FileOpenDialogImplGtk(Gtk::Window& parentWindow, 166 const Glib::ustring &dir, 167 FileDialogType fileTypes, 168 const Glib::ustring &title); 169 170 ~FileOpenDialogImplGtk() override; 171 172 bool show() override; 173 174 Inkscape::Extension::Extension *getSelectionType() override; 175 176 Glib::ustring getFilename(); 177 178 std::vector<Glib::ustring> getFilenames() override; 179 180 Glib::ustring getCurrentDirectory() override; 181 182 /// Add a custom file filter menu item 183 /// @param name - Name of the filter (such as "Javscript") 184 /// @param pattern - File filtering patter (such as "*.js") 185 /// Use the FileDialogType::CUSTOM_TYPE in constructor to not include other file types 186 void addFilterMenu(Glib::ustring name, Glib::ustring pattern) override; 187 188 private: 189 190 /** 191 * Create a filter menu for this type of dialog 192 */ 193 void createFilterMenu(); 194 195 196 /** 197 * Filter name->extension lookup 198 */ 199 std::map<Glib::ustring, Inkscape::Extension::Extension *> extensionMap; 200 201 /** 202 * The extension to use to write this file 203 */ 204 Inkscape::Extension::Extension *extension; 205 206 }; 207 208 209 210 //######################################################################## 211 //# F I L E S A V E 212 //######################################################################## 213 214 /** 215 * Our implementation of the FileSaveDialog interface. 216 */ 217 class FileSaveDialogImplGtk : public FileSaveDialog, public FileDialogBaseGtk 218 { 219 220 public: 221 FileSaveDialogImplGtk(Gtk::Window &parentWindow, 222 const Glib::ustring &dir, 223 FileDialogType fileTypes, 224 const Glib::ustring &title, 225 const Glib::ustring &default_key, 226 const gchar* docTitle, 227 const Inkscape::Extension::FileSaveMethod save_method); 228 229 ~FileSaveDialogImplGtk() override; 230 231 bool show() override; 232 233 Inkscape::Extension::Extension *getSelectionType() override; 234 void setSelectionType( Inkscape::Extension::Extension * key ) override; 235 236 Glib::ustring getCurrentDirectory() override; 237 void addFileType(Glib::ustring name, Glib::ustring pattern) override; 238 239 private: 240 //void change_title(const Glib::ustring& title); 241 void change_path(const Glib::ustring& path); 242 void updateNameAndExtension(); 243 244 /** 245 * The file save method (essentially whether the dialog was invoked by "Save as ..." or "Save a 246 * copy ..."), which is used to determine file extensions and save paths. 247 */ 248 Inkscape::Extension::FileSaveMethod save_method; 249 250 /** 251 * Fix to allow the user to type the file name 252 */ 253 Gtk::Entry *fileNameEntry; 254 255 256 /** 257 * Allow the specification of the output file type 258 */ 259 Gtk::ComboBoxText fileTypeComboBox; 260 261 262 /** 263 * Data mirror of the combo box 264 */ 265 std::vector<FileType> fileTypes; 266 267 //# Child widgets 268 Gtk::Box childBox; 269 Gtk::Box checksBox; 270 271 Gtk::CheckButton fileTypeCheckbox; 272 273 /** 274 * Callback for user input into fileNameEntry 275 */ 276 void fileTypeChangedCallback(); 277 278 /** 279 * Create a filter menu for this type of dialog 280 */ 281 void createFilterMenu(); 282 283 /** 284 * The extension to use to write this file 285 */ 286 Inkscape::Extension::Extension *extension; 287 288 /** 289 * Callback for user input into fileNameEntry 290 */ 291 void fileNameEntryChangedCallback(); 292 void fileNameChanged(); 293 bool fromCB; 294 }; 295 296 297 } // namespace Dialog 298 } // namespace UI 299 } // namespace Inkscape 300 301 #endif /*__FILE_DIALOGIMPL_H__*/ 302 303 /* 304 Local Variables: 305 mode:c++ 306 c-file-style:"stroustrup" 307 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 308 indent-tabs-mode:nil 309 fill-column:99 310 End: 311 */ 312 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 313