2
* @brief Implementation of the file dialog interfaces defined in filedialogimpl.h
8
* Other dudes from The Inkscape Organization
10
* Copyright (C) 2004-2007 Bob Jamison
11
* Copyright (C) 2006 Johan Engelen <johan@shouraizou.nl>
12
* Copyright (C) 2007-2008 Joel Holdsworth
13
* Copyright (C) 2004-2007 The Inkscape Organization
15
* Released under GNU GPL, read the file 'COPYING' for more information
22
#include "filedialogimpl-gtkmm.h"
23
#include "dialogs/dialog-events.h"
24
#include "interface.h"
26
#include "path-prefix.h"
27
#include "preferences.h"
30
# include <libgnomevfs/gnome-vfs.h>
33
//Routines from file.cpp
34
#undef INK_DUMP_FILENAME_CONV
36
#ifdef INK_DUMP_FILENAME_CONV
37
void dump_str( const gchar* str, const gchar* prefix );
38
void dump_ustr( const Glib::ustring& ustr );
54
//########################################################################
56
//########################################################################
59
fileDialogExtensionToPattern(Glib::ustring &pattern,
60
Glib::ustring &extension)
62
for (unsigned int i = 0; i < extension.length(); i++ )
64
Glib::ustring::value_type ch = extension[i];
65
if ( Glib::Unicode::isalpha(ch) )
68
pattern += Glib::Unicode::toupper(ch);
69
pattern += Glib::Unicode::tolower(ch);
81
findEntryWidgets(Gtk::Container *parent,
82
std::vector<Gtk::Entry *> &result)
86
std::vector<Gtk::Widget *> children = parent->get_children();
87
for (unsigned int i=0; i<children.size() ; i++)
89
Gtk::Widget *child = children[i];
90
GtkWidget *wid = child->gobj();
91
if (GTK_IS_ENTRY(wid))
92
result.push_back((Gtk::Entry *)child);
93
else if (GTK_IS_CONTAINER(wid))
94
findEntryWidgets((Gtk::Container *)child, result);
100
findExpanderWidgets(Gtk::Container *parent,
101
std::vector<Gtk::Expander *> &result)
105
std::vector<Gtk::Widget *> children = parent->get_children();
106
for (unsigned int i=0; i<children.size() ; i++)
108
Gtk::Widget *child = children[i];
109
GtkWidget *wid = child->gobj();
110
if (GTK_IS_EXPANDER(wid))
111
result.push_back((Gtk::Expander *)child);
112
else if (GTK_IS_CONTAINER(wid))
113
findExpanderWidgets((Gtk::Container *)child, result);
119
/*#########################################################################
120
### SVG Preview Widget
121
#########################################################################*/
123
bool SVGPreview::setDocument(SPDocument *doc)
126
sp_document_unref(document);
128
sp_document_ref(doc);
131
//This should remove it from the box, and free resources
133
gtk_widget_destroy(viewerGtk);
135
viewerGtk = sp_svg_view_widget_new(doc);
136
GtkWidget *vbox = (GtkWidget *)gobj();
137
gtk_box_pack_start(GTK_BOX(vbox), viewerGtk, TRUE, TRUE, 0);
138
gtk_widget_show(viewerGtk);
144
bool SVGPreview::setFileName(Glib::ustring &theFileName)
146
Glib::ustring fileName = theFileName;
148
fileName = Glib::filename_to_utf8(fileName);
151
* I don't know why passing false to keepalive is bad. But it
152
* prevents the display of an svg with a non-ascii filename
154
SPDocument *doc = sp_document_new (fileName.c_str(), true);
156
g_warning("SVGView: error loading document '%s'\n", fileName.c_str());
162
sp_document_unref(doc);
169
bool SVGPreview::setFromMem(char const *xmlBuffer)
174
gint len = (gint)strlen(xmlBuffer);
175
SPDocument *doc = sp_document_new_from_mem(xmlBuffer, len, 0);
177
g_warning("SVGView: error loading buffer '%s'\n",xmlBuffer);
183
sp_document_unref(doc);
185
Inkscape::GC::request_early_collection();
192
void SVGPreview::showImage(Glib::ustring &theFileName)
194
Glib::ustring fileName = theFileName;
197
/*#####################################
198
# LET'S HAVE SOME FUN WITH SVG!
199
# Instead of just loading an image, why
200
# don't we make a lovely little svg and
202
#####################################*/
204
//Arbitrary size of svg doc -- rather 'portrait' shaped
205
gint previewWidth = 400;
206
gint previewHeight = 600;
208
//Get some image info. Smart pointer does not need to be deleted
209
Glib::RefPtr<Gdk::Pixbuf> img(NULL);
211
img = Gdk::Pixbuf::create_from_file(fileName);
213
catch (const Glib::FileError & e)
215
g_message("caught Glib::FileError in SVGPreview::showImage");
218
catch (const Gdk::PixbufError & e)
220
g_message("Gdk::PixbufError in SVGPreview::showImage");
225
g_message("Caught ... in SVGPreview::showImage");
229
gint imgWidth = img->get_width();
230
gint imgHeight = img->get_height();
232
//Find the minimum scale to fit the image inside the preview area
233
double scaleFactorX = (0.9 *(double)previewWidth) / ((double)imgWidth);
234
double scaleFactorY = (0.9 *(double)previewHeight) / ((double)imgHeight);
235
double scaleFactor = scaleFactorX;
236
if (scaleFactorX > scaleFactorY)
237
scaleFactor = scaleFactorY;
239
//Now get the resized values
240
gint scaledImgWidth = (int) (scaleFactor * (double)imgWidth);
241
gint scaledImgHeight = (int) (scaleFactor * (double)imgHeight);
243
//center the image on the area
244
gint imgX = (previewWidth - scaledImgWidth) / 2;
245
gint imgY = (previewHeight - scaledImgHeight) / 2;
247
//wrap a rectangle around the image
250
gint rectWidth = scaledImgWidth +2;
251
gint rectHeight = scaledImgHeight+2;
253
//Our template. Modify to taste
254
gchar const *xformat =
255
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
257
"xmlns=\"http://www.w3.org/2000/svg\"\n"
258
"xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"
259
"width=\"%d\" height=\"%d\">\n" //# VALUES HERE
261
" style=\"fill:#eeeeee;stroke:none\"\n"
262
" x=\"-100\" y=\"-100\" width=\"4000\" height=\"4000\"/>\n"
263
"<image x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\"\n"
264
"xlink:href=\"%s\"/>\n"
266
" style=\"fill:none;"
267
" stroke:#000000;stroke-width:1.0;"
268
" stroke-linejoin:miter;stroke-opacity:1.0000000;"
269
" stroke-miterlimit:4.0000000;stroke-dasharray:none\"\n"
270
" x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\"/>\n"
272
" style=\"font-size:24.000000;font-style:normal;font-weight:normal;"
273
" fill:#000000;fill-opacity:1.0000000;stroke:none;"
274
" font-family:Bitstream Vera Sans\"\n"
275
" x=\"10\" y=\"26\">%d x %d</text>\n" //# VALUES HERE
278
//if (!Glib::get_charset()) //If we are not utf8
279
fileName = Glib::filename_to_utf8(fileName);
281
//Fill in the template
282
/* FIXME: Do proper XML quoting for fileName. */
283
gchar *xmlBuffer = g_strdup_printf(xformat,
284
previewWidth, previewHeight,
285
imgX, imgY, scaledImgWidth, scaledImgHeight,
287
rectX, rectY, rectWidth, rectHeight,
288
imgWidth, imgHeight);
290
//g_message("%s\n", xmlBuffer);
293
setFromMem(xmlBuffer);
299
void SVGPreview::showNoPreview()
301
//Are we already showing it?
302
if (showingNoPreview)
305
//Arbitrary size of svg doc -- rather 'portrait' shaped
306
gint previewWidth = 300;
307
gint previewHeight = 600;
309
//Our template. Modify to taste
310
gchar const *xformat =
311
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
313
"xmlns=\"http://www.w3.org/2000/svg\"\n"
314
"xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"
315
"width=\"%d\" height=\"%d\">\n" //# VALUES HERE
316
"<g transform=\"translate(-190,24.27184)\" style=\"opacity:0.12\">\n"
318
"style=\"font-size:12;fill:#ffffff;fill-rule:evenodd;stroke:#000000;stroke-width:0.936193pt\"\n"
319
"d=\"M 397.64309 320.25301 L 280.39197 282.517 L 250.74227 124.83447 L 345.08225 "
320
"29.146783 L 393.59996 46.667064 L 483.89679 135.61619 L 397.64309 320.25301 z \"\n"
321
"id=\"whiteSpace\" />\n"
323
"style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
324
"d=\"M 476.95792 339.17168 C 495.78197 342.93607 499.54842 356.11361 495.78197 359.87802 "
325
"C 492.01856 363.6434 482.6065 367.40781 475.07663 361.76014 C 467.54478 "
326
"356.11361 467.54478 342.93607 476.95792 339.17168 z \"\n"
327
"id=\"droplet01\" />\n"
329
"style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
330
"d=\"M 286.46194 340.42914 C 284.6277 340.91835 269.30405 327.71337 257.16909 333.8338 "
331
"C 245.03722 339.95336 236.89276 353.65666 248.22676 359.27982 C 259.56184 364.90298 "
332
"267.66433 358.41867 277.60113 351.44119 C 287.53903 344.46477 "
333
"287.18046 343.1206 286.46194 340.42914 z \"\n"
334
"id=\"droplet02\" />\n"
336
"style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
337
"d=\"M 510.35756 306.92856 C 520.59494 304.36879 544.24333 306.92856 540.47688 321.98634 "
338
"C 536.71354 337.04806 504.71297 331.39827 484.00371 323.87156 C 482.12141 "
339
"308.81083 505.53237 308.13423 510.35756 306.92856 z \"\n"
340
"id=\"droplet03\" />\n"
342
"style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
343
"d=\"M 359.2403 21.362537 C 347.92693 21.362537 336.6347 25.683095 327.96556 34.35223 "
344
"L 173.87387 188.41466 C 165.37697 196.9114 161.1116 207.95813 160.94269 219.04577 "
345
"L 160.88418 219.04577 C 160.88418 219.08524 160.94076 219.12322 160.94269 219.16279 "
346
"C 160.94033 219.34888 160.88418 219.53256 160.88418 219.71865 L 161.14748 219.71865 "
347
"C 164.0966 230.93917 240.29699 245.24198 248.79866 253.74346 C 261.63771 266.58263 "
348
"199.5652 276.01151 212.4041 288.85074 C 225.24316 301.68979 289.99433 313.6933 302.8346 "
349
"326.53254 C 315.67368 339.37161 276.5961 353.04289 289.43532 365.88196 C 302.27439 "
350
"378.72118 345.40201 362.67257 337.5908 396.16198 C 354.92909 413.50026 391.10302 "
351
"405.2208 415.32417 387.88252 C 428.16323 375.04345 390.6948 376.17577 403.53397 "
352
"363.33668 C 416.37304 350.49745 448.78128 350.4282 476.08902 319.71589 C 465.09739 "
353
"302.62116 429.10801 295.34136 441.94719 282.50217 C 454.78625 269.66311 479.74708 "
354
"276.18423 533.60644 251.72479 C 559.89837 239.78398 557.72636 230.71459 557.62567 "
355
"219.71865 C 557.62356 219.48727 557.62567 219.27892 557.62567 219.04577 L 557.56716 "
356
"219.04577 C 557.3983 207.95812 553.10345 196.9114 544.60673 188.41466 L 390.54428 "
357
"34.35223 C 381.87515 25.683095 370.55366 21.362537 359.2403 21.362537 z M 357.92378 "
358
"41.402939 C 362.95327 41.533963 367.01541 45.368018 374.98006 50.530832 L 447.76915 "
359
"104.50827 C 448.56596 105.02498 449.32484 105.564 450.02187 106.11735 C 450.7189 106.67062 "
360
"451.3556 107.25745 451.95277 107.84347 C 452.54997 108.42842 453.09281 109.01553 453.59111 "
361
"109.62808 C 454.08837 110.24052 454.53956 110.86661 454.93688 111.50048 C 455.33532 112.13538 "
362
"455.69164 112.78029 455.9901 113.43137 C 456.28877 114.08363 456.52291 114.75639 456.7215 "
363
"115.42078 C 456.92126 116.08419 457.08982 116.73973 457.18961 117.41019 C 457.28949 "
364
"118.08184 457.33588 118.75535 457.33588 119.42886 L 414.21245 98.598549 L 409.9118 "
365
"131.16055 L 386.18512 120.04324 L 349.55654 144.50131 L 335.54288 96.1703 L 317.4919 "
366
"138.4453 L 267.08369 143.47735 L 267.63956 121.03795 C 267.63956 115.64823 296.69685 "
367
"77.915899 314.39075 68.932902 L 346.77721 45.674327 C 351.55594 42.576634 354.90608 "
368
"41.324327 357.92378 41.402939 z M 290.92738 261.61333 C 313.87149 267.56365 339.40299 "
369
"275.37038 359.88393 275.50997 L 360.76161 284.72563 C 343.2235 282.91785 306.11346 "
370
"274.45012 297.36372 269.98057 L 290.92738 261.61333 z \"\n"
371
"id=\"mountainDroplet\" />\n"
372
"</g> <g transform=\"translate(-20,0)\">\n"
373
"<text xml:space=\"preserve\"\n"
374
"style=\"font-size:32.000000;font-style:normal;font-variant:normal;font-weight:bold;"
375
"font-stretch:normal;fill:#000000;fill-opacity:1.0000000;stroke:none;stroke-width:1.0000000pt;"
376
"stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000;"
377
"font-family:Bitstream Vera Sans;text-anchor:middle;writing-mode:lr\"\n"
378
"x=\"190\" y=\"240\">%s</text></g>\n" //# VALUE HERE
381
//Fill in the template
382
gchar *xmlBuffer = g_strdup_printf(xformat,
383
previewWidth, previewHeight, _("No preview"));
385
//g_message("%s\n", xmlBuffer);
388
setFromMem(xmlBuffer);
390
showingNoPreview = true;
396
* Inform the user that the svg file is too large to be displayed.
397
* This does not check for sizes of embedded images (yet)
399
void SVGPreview::showTooLarge(long fileLength)
402
//Arbitrary size of svg doc -- rather 'portrait' shaped
403
gint previewWidth = 300;
404
gint previewHeight = 600;
406
//Our template. Modify to taste
407
gchar const *xformat =
408
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
410
"xmlns=\"http://www.w3.org/2000/svg\"\n"
411
"xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"
412
"width=\"%d\" height=\"%d\">\n" //# VALUES HERE
413
"<g transform=\"translate(-170,24.27184)\" style=\"opacity:0.12\">\n"
415
"style=\"font-size:12;fill:#ffffff;fill-rule:evenodd;stroke:#000000;stroke-width:0.936193pt\"\n"
416
"d=\"M 397.64309 320.25301 L 280.39197 282.517 L 250.74227 124.83447 L 345.08225 "
417
"29.146783 L 393.59996 46.667064 L 483.89679 135.61619 L 397.64309 320.25301 z \"\n"
418
"id=\"whiteSpace\" />\n"
420
"style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
421
"d=\"M 476.95792 339.17168 C 495.78197 342.93607 499.54842 356.11361 495.78197 359.87802 "
422
"C 492.01856 363.6434 482.6065 367.40781 475.07663 361.76014 C 467.54478 "
423
"356.11361 467.54478 342.93607 476.95792 339.17168 z \"\n"
424
"id=\"droplet01\" />\n"
426
"style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
427
"d=\"M 286.46194 340.42914 C 284.6277 340.91835 269.30405 327.71337 257.16909 333.8338 "
428
"C 245.03722 339.95336 236.89276 353.65666 248.22676 359.27982 C 259.56184 364.90298 "
429
"267.66433 358.41867 277.60113 351.44119 C 287.53903 344.46477 "
430
"287.18046 343.1206 286.46194 340.42914 z \"\n"
431
"id=\"droplet02\" />\n"
433
"style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
434
"d=\"M 510.35756 306.92856 C 520.59494 304.36879 544.24333 306.92856 540.47688 321.98634 "
435
"C 536.71354 337.04806 504.71297 331.39827 484.00371 323.87156 C 482.12141 "
436
"308.81083 505.53237 308.13423 510.35756 306.92856 z \"\n"
437
"id=\"droplet03\" />\n"
439
"style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
440
"d=\"M 359.2403 21.362537 C 347.92693 21.362537 336.6347 25.683095 327.96556 34.35223 "
441
"L 173.87387 188.41466 C 165.37697 196.9114 161.1116 207.95813 160.94269 219.04577 "
442
"L 160.88418 219.04577 C 160.88418 219.08524 160.94076 219.12322 160.94269 219.16279 "
443
"C 160.94033 219.34888 160.88418 219.53256 160.88418 219.71865 L 161.14748 219.71865 "
444
"C 164.0966 230.93917 240.29699 245.24198 248.79866 253.74346 C 261.63771 266.58263 "
445
"199.5652 276.01151 212.4041 288.85074 C 225.24316 301.68979 289.99433 313.6933 302.8346 "
446
"326.53254 C 315.67368 339.37161 276.5961 353.04289 289.43532 365.88196 C 302.27439 "
447
"378.72118 345.40201 362.67257 337.5908 396.16198 C 354.92909 413.50026 391.10302 "
448
"405.2208 415.32417 387.88252 C 428.16323 375.04345 390.6948 376.17577 403.53397 "
449
"363.33668 C 416.37304 350.49745 448.78128 350.4282 476.08902 319.71589 C 465.09739 "
450
"302.62116 429.10801 295.34136 441.94719 282.50217 C 454.78625 269.66311 479.74708 "
451
"276.18423 533.60644 251.72479 C 559.89837 239.78398 557.72636 230.71459 557.62567 "
452
"219.71865 C 557.62356 219.48727 557.62567 219.27892 557.62567 219.04577 L 557.56716 "
453
"219.04577 C 557.3983 207.95812 553.10345 196.9114 544.60673 188.41466 L 390.54428 "
454
"34.35223 C 381.87515 25.683095 370.55366 21.362537 359.2403 21.362537 z M 357.92378 "
455
"41.402939 C 362.95327 41.533963 367.01541 45.368018 374.98006 50.530832 L 447.76915 "
456
"104.50827 C 448.56596 105.02498 449.32484 105.564 450.02187 106.11735 C 450.7189 106.67062 "
457
"451.3556 107.25745 451.95277 107.84347 C 452.54997 108.42842 453.09281 109.01553 453.59111 "
458
"109.62808 C 454.08837 110.24052 454.53956 110.86661 454.93688 111.50048 C 455.33532 112.13538 "
459
"455.69164 112.78029 455.9901 113.43137 C 456.28877 114.08363 456.52291 114.75639 456.7215 "
460
"115.42078 C 456.92126 116.08419 457.08982 116.73973 457.18961 117.41019 C 457.28949 "
461
"118.08184 457.33588 118.75535 457.33588 119.42886 L 414.21245 98.598549 L 409.9118 "
462
"131.16055 L 386.18512 120.04324 L 349.55654 144.50131 L 335.54288 96.1703 L 317.4919 "
463
"138.4453 L 267.08369 143.47735 L 267.63956 121.03795 C 267.63956 115.64823 296.69685 "
464
"77.915899 314.39075 68.932902 L 346.77721 45.674327 C 351.55594 42.576634 354.90608 "
465
"41.324327 357.92378 41.402939 z M 290.92738 261.61333 C 313.87149 267.56365 339.40299 "
466
"275.37038 359.88393 275.50997 L 360.76161 284.72563 C 343.2235 282.91785 306.11346 "
467
"274.45012 297.36372 269.98057 L 290.92738 261.61333 z \"\n"
468
"id=\"mountainDroplet\" />\n"
470
"<text xml:space=\"preserve\"\n"
471
"style=\"font-size:32.000000;font-style:normal;font-variant:normal;font-weight:bold;"
472
"font-stretch:normal;fill:#000000;fill-opacity:1.0000000;stroke:none;stroke-width:1.0000000pt;"
473
"stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000;"
474
"font-family:Bitstream Vera Sans;text-anchor:middle;writing-mode:lr\"\n"
475
"x=\"170\" y=\"215\">%5.1f MB</text>\n" //# VALUE HERE
476
"<text xml:space=\"preserve\"\n"
477
"style=\"font-size:24.000000;font-style:normal;font-variant:normal;font-weight:bold;"
478
"font-stretch:normal;fill:#000000;fill-opacity:1.0000000;stroke:none;stroke-width:1.0000000pt;"
479
"stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000;"
480
"font-family:Bitstream Vera Sans;text-anchor:middle;writing-mode:lr\"\n"
481
"x=\"180\" y=\"245\">%s</text>\n" //# VALUE HERE
484
//Fill in the template
485
double floatFileLength = ((double)fileLength) / 1048576.0;
486
//printf("%ld %f\n", fileLength, floatFileLength);
487
gchar *xmlBuffer = g_strdup_printf(xformat,
488
previewWidth, previewHeight, floatFileLength,
489
_("too large for preview"));
491
//g_message("%s\n", xmlBuffer);
494
setFromMem(xmlBuffer);
499
bool SVGPreview::set(Glib::ustring &fileName, int dialogType)
502
if (!Glib::file_test(fileName, Glib::FILE_TEST_EXISTS))
505
//g_message("fname:%s", fileName.c_str());
507
if (Glib::file_test(fileName, Glib::FILE_TEST_IS_DIR)) {
512
if (Glib::file_test(fileName, Glib::FILE_TEST_IS_REGULAR))
514
Glib::ustring fileNameUtf8 = Glib::filename_to_utf8(fileName);
515
gchar *fName = (gchar *)fileNameUtf8.c_str();
517
if (g_stat(fName, &info))
519
g_warning("SVGPreview::set() : %s : %s",
520
fName, strerror(errno));
523
long fileLen = info.st_size;
524
if (fileLen > 0x150000L)
526
showingNoPreview = false;
527
showTooLarge(fileLen);
532
Glib::ustring svg = ".svg";
533
Glib::ustring svgz = ".svgz";
535
if ((dialogType == SVG_TYPES || dialogType == IMPORT_TYPES) &&
536
(hasSuffix(fileName, svg) || hasSuffix(fileName, svgz) )
538
bool retval = setFileName(fileName);
539
showingNoPreview = false;
541
} else if (isValidImageFile(fileName)) {
543
showingNoPreview = false;
552
SVGPreview::SVGPreview()
555
inkscape_application_init("",false);
558
set_size_request(150,150);
559
showingNoPreview = false;
562
SVGPreview::~SVGPreview()
568
/*#########################################################################
569
### F I L E D I A L O G B A S E C L A S S
570
#########################################################################*/
572
void FileDialogBaseGtk::internalSetup()
574
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
575
bool enablePreview = prefs->getBool( preferenceBase + "/enable_preview", true);
577
previewCheckbox.set_label( Glib::ustring(_("Enable preview")) );
578
previewCheckbox.set_active( enablePreview );
580
previewCheckbox.signal_toggled().connect(
581
sigc::mem_fun(*this, &FileDialogBaseGtk::_previewEnabledCB) );
583
//Catch selection-changed events, so we can adjust the text widget
584
signal_update_preview().connect(
585
sigc::mem_fun(*this, &FileDialogBaseGtk::_updatePreviewCallback) );
587
//###### Add a preview widget
588
set_preview_widget(svgPreview);
589
set_preview_widget_active( enablePreview );
590
set_use_preview_label (false);
595
void FileDialogBaseGtk::cleanup( bool showConfirmed )
597
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
599
prefs->setBool( preferenceBase + "/enable_preview", previewCheckbox.get_active() );
603
void FileDialogBaseGtk::_previewEnabledCB()
605
bool enabled = previewCheckbox.get_active();
606
set_preview_widget_active(enabled);
608
_updatePreviewCallback();
615
* Callback for checking if the preview needs to be redrawn
617
void FileDialogBaseGtk::_updatePreviewCallback()
619
Glib::ustring fileName = get_preview_filename();
621
#ifdef WITH_GNOME_VFS
622
if ( fileName.empty() && gnome_vfs_initialized() ) {
623
fileName = get_preview_uri();
627
if (fileName.empty()) {
631
svgPreview.set(fileName, _dialogType);
635
/*#########################################################################
637
#########################################################################*/
640
* Constructor. Not called directly. Use the factory.
642
FileOpenDialogImplGtk::FileOpenDialogImplGtk(Gtk::Window& parentWindow,
643
const Glib::ustring &dir,
644
FileDialogType fileTypes,
645
const Glib::ustring &title) :
646
FileDialogBaseGtk(parentWindow, title, Gtk::FILE_CHOOSER_ACTION_OPEN, fileTypes, "/dialogs/open")
650
/* One file at a time */
651
/* And also Multiple Files */
652
set_select_multiple(true);
654
#ifdef WITH_GNOME_VFS
655
if (gnome_vfs_initialized()) {
656
set_local_only(false);
660
/* Initalize to Autodetect */
662
/* No filename to start out with */
665
/* Set our dialog type (open, import, etc...)*/
666
_dialogType = fileTypes;
669
/* Set the pwd and/or the filename */
672
Glib::ustring udir(dir);
673
Glib::ustring::size_type len = udir.length();
674
// leaving a trailing backslash on the directory name leads to the infamous
675
// double-directory bug on win32
676
if (len != 0 && udir[len - 1] == '\\') udir.erase(len - 1);
677
set_current_folder(udir.c_str());
681
set_extra_widget( previewCheckbox );
684
//###### Add the file types menu
687
add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
688
set_default(*add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK));
690
//###### Allow easy access to our examples folder
691
if ( Inkscape::IO::file_test(INKSCAPE_EXAMPLESDIR, G_FILE_TEST_EXISTS)
692
&& Inkscape::IO::file_test(INKSCAPE_EXAMPLESDIR, G_FILE_TEST_IS_DIR)
693
&& g_path_is_absolute(INKSCAPE_EXAMPLESDIR)
696
add_shortcut_folder(INKSCAPE_EXAMPLESDIR);
703
FileOpenDialogImplGtk::~FileOpenDialogImplGtk()
708
void FileOpenDialogImplGtk::createFilterMenu()
710
Gtk::FileFilter allInkscapeFilter;
711
allInkscapeFilter.set_name(_("All Inkscape Files"));
712
extensionMap[Glib::ustring(_("All Inkscape Files"))]=NULL;
713
add_filter(allInkscapeFilter);
715
Gtk::FileFilter allFilter;
716
allFilter.set_name(_("All Files"));
717
extensionMap[Glib::ustring(_("All Files"))]=NULL;
718
allFilter.add_pattern("*");
719
add_filter(allFilter);
721
Gtk::FileFilter allImageFilter;
722
allImageFilter.set_name(_("All Images"));
723
extensionMap[Glib::ustring(_("All Images"))]=NULL;
724
add_filter(allImageFilter);
726
Gtk::FileFilter allVectorFilter;
727
allVectorFilter.set_name(_("All Vectors"));
728
extensionMap[Glib::ustring(_("All Vectors"))]=NULL;
729
add_filter(allVectorFilter);
731
Gtk::FileFilter allBitmapFilter;
732
allBitmapFilter.set_name(_("All Bitmaps"));
733
extensionMap[Glib::ustring(_("All Bitmaps"))]=NULL;
734
add_filter(allBitmapFilter);
736
//patterns added dynamically below
737
Inkscape::Extension::DB::InputList extension_list;
738
Inkscape::Extension::db.get_input_list(extension_list);
740
for (Inkscape::Extension::DB::InputList::iterator current_item = extension_list.begin();
741
current_item != extension_list.end(); current_item++)
743
Inkscape::Extension::Input * imod = *current_item;
745
// FIXME: would be nice to grey them out instead of not listing them
746
if (imod->deactivated()) continue;
748
Glib::ustring upattern("*");
749
Glib::ustring extension = imod->get_extension();
750
fileDialogExtensionToPattern(upattern, extension);
752
Gtk::FileFilter filter;
753
Glib::ustring uname(_(imod->get_filetypename()));
754
filter.set_name(uname);
755
filter.add_pattern(upattern);
757
extensionMap[uname] = imod;
759
//g_message("ext %s:%s '%s'\n", ioext->name, ioext->mimetype, upattern.c_str());
760
allInkscapeFilter.add_pattern(upattern);
761
if ( strncmp("image", imod->get_mimetype(), 5)==0 )
762
allImageFilter.add_pattern(upattern);
764
// uncomment this to find out all mime types supported by Inkscape import/open
765
// g_print ("%s\n", imod->get_mimetype());
767
// I don't know of any other way to define "bitmap" formats other than by listing them
769
strncmp("image/png", imod->get_mimetype(), 9)==0 ||
770
strncmp("image/jpeg", imod->get_mimetype(), 10)==0 ||
771
strncmp("image/gif", imod->get_mimetype(), 9)==0 ||
772
strncmp("image/x-icon", imod->get_mimetype(), 12)==0 ||
773
strncmp("image/x-navi-animation", imod->get_mimetype(), 22)==0 ||
774
strncmp("image/x-cmu-raster", imod->get_mimetype(), 18)==0 ||
775
strncmp("image/x-xpixmap", imod->get_mimetype(), 15)==0 ||
776
strncmp("image/bmp", imod->get_mimetype(), 9)==0 ||
777
strncmp("image/vnd.wap.wbmp", imod->get_mimetype(), 18)==0 ||
778
strncmp("image/tiff", imod->get_mimetype(), 10)==0 ||
779
strncmp("image/x-xbitmap", imod->get_mimetype(), 15)==0 ||
780
strncmp("image/x-tga", imod->get_mimetype(), 11)==0 ||
781
strncmp("image/x-pcx", imod->get_mimetype(), 11)==0
783
allBitmapFilter.add_pattern(upattern);
785
allVectorFilter.add_pattern(upattern);
792
* Show this dialog modally. Return true if user hits [OK]
795
FileOpenDialogImplGtk::show()
797
set_modal (TRUE); //Window
798
sp_transientize((GtkWidget *)gobj()); //Make transient
799
gint b = run(); //Dialog
800
svgPreview.showNoPreview();
803
if (b == Gtk::RESPONSE_OK)
805
//This is a hack, to avoid the warning messages that
806
//Gtk::FileChooser::get_filter() returns
807
//should be: Gtk::FileFilter *filter = get_filter();
808
GtkFileChooser *gtkFileChooser = Gtk::FileChooser::gobj();
809
GtkFileFilter *filter = gtk_file_chooser_get_filter(gtkFileChooser);
812
//Get which extension was chosen, if any
813
extension = extensionMap[gtk_file_filter_get_name(filter)];
815
myFilename = get_filename();
816
#ifdef WITH_GNOME_VFS
817
if (myFilename.empty() && gnome_vfs_initialized())
818
myFilename = get_uri();
834
* Get the file extension type that was selected by the user. Valid after an [OK]
836
Inkscape::Extension::Extension *
837
FileOpenDialogImplGtk::getSelectionType()
844
* Get the file name chosen by the user. Valid after an [OK]
847
FileOpenDialogImplGtk::getFilename (void)
854
* To Get Multiple filenames selected at-once.
856
std::vector<Glib::ustring>FileOpenDialogImplGtk::getFilenames()
858
std::vector<Glib::ustring> result = get_filenames();
859
#ifdef WITH_GNOME_VFS
860
if (result.empty() && gnome_vfs_initialized())
866
Glib::ustring FileOpenDialogImplGtk::getCurrentDirectory()
868
return get_current_folder();
874
//########################################################################
876
//########################################################################
881
FileSaveDialogImplGtk::FileSaveDialogImplGtk( Gtk::Window &parentWindow,
882
const Glib::ustring &dir,
883
FileDialogType fileTypes,
884
const Glib::ustring &title,
885
const Glib::ustring &/*default_key*/,
886
const gchar* docTitle) :
887
FileDialogBaseGtk(parentWindow, title, Gtk::FILE_CHOOSER_ACTION_SAVE, fileTypes, "/dialogs/save_as")
889
FileSaveDialog::myDocTitle = docTitle;
891
/* One file at a time */
892
set_select_multiple(false);
894
#ifdef WITH_GNOME_VFS
895
if (gnome_vfs_initialized()) {
896
set_local_only(false);
900
/* Initalize to Autodetect */
902
/* No filename to start out with */
905
/* Set our dialog type (save, export, etc...)*/
906
_dialogType = fileTypes;
908
/* Set the pwd and/or the filename */
911
Glib::ustring udir(dir);
912
Glib::ustring::size_type len = udir.length();
913
// leaving a trailing backslash on the directory name leads to the infamous
914
// double-directory bug on win32
915
if (len != 0 && udir[len - 1] == '\\') udir.erase(len - 1);
919
//###### Add the file types menu
920
//createFilterMenu();
922
//###### Do we want the .xxx extension automatically added?
923
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
924
fileTypeCheckbox.set_label(Glib::ustring(_("Append filename extension automatically")));
925
fileTypeCheckbox.set_active(prefs->getBool("/dialogs/save_as/append_extension", true));
927
createFileTypeMenu();
928
fileTypeComboBox.set_size_request(200,40);
929
fileTypeComboBox.signal_changed().connect(
930
sigc::mem_fun(*this, &FileSaveDialogImplGtk::fileTypeChangedCallback) );
933
childBox.pack_start( checksBox );
934
childBox.pack_end( fileTypeComboBox );
935
checksBox.pack_start( fileTypeCheckbox );
936
checksBox.pack_start( previewCheckbox );
938
set_extra_widget( childBox );
940
//Let's do some customization
941
fileNameEntry = NULL;
942
Gtk::Container *cont = get_toplevel();
943
std::vector<Gtk::Entry *> entries;
944
findEntryWidgets(cont, entries);
945
//g_message("Found %d entry widgets\n", entries.size());
946
if (entries.size() >=1 )
948
//Catch when user hits [return] on the text field
949
fileNameEntry = entries[0];
950
fileNameEntry->signal_activate().connect(
951
sigc::mem_fun(*this, &FileSaveDialogImplGtk::fileNameEntryChangedCallback) );
954
//Let's do more customization
955
std::vector<Gtk::Expander *> expanders;
956
findExpanderWidgets(cont, expanders);
957
//g_message("Found %d expander widgets\n", expanders.size());
958
if (expanders.size() >=1 )
960
//Always show the file list
961
Gtk::Expander *expander = expanders[0];
962
expander->set_expanded(true);
965
// allow easy access to the user's own templates folder
966
gchar *templates = profile_path ("templates");
967
if ( Inkscape::IO::file_test(templates, G_FILE_TEST_EXISTS)
968
&& Inkscape::IO::file_test(templates, G_FILE_TEST_IS_DIR)
969
&& g_path_is_absolute(templates)
972
add_shortcut_folder(templates);
977
//if (extension == NULL)
978
// checkbox.set_sensitive(FALSE);
980
add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
981
set_default(*add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK));
989
FileSaveDialogImplGtk::~FileSaveDialogImplGtk()
994
* Callback for fileNameEntry widget
996
void FileSaveDialogImplGtk::fileNameEntryChangedCallback()
1001
Glib::ustring fileName = fileNameEntry->get_text();
1002
if (!Glib::get_charset()) //If we are not utf8
1003
fileName = Glib::filename_to_utf8(fileName);
1005
//g_message("User hit return. Text is '%s'\n", fileName.c_str());
1007
if (!Glib::path_is_absolute(fileName)) {
1008
//try appending to the current path
1009
// not this way: fileName = get_current_folder() + "/" + fileName;
1010
std::vector<Glib::ustring> pathSegments;
1011
pathSegments.push_back( get_current_folder() );
1012
pathSegments.push_back( fileName );
1013
fileName = Glib::build_filename(pathSegments);
1016
//g_message("path:'%s'\n", fileName.c_str());
1018
if (Glib::file_test(fileName, Glib::FILE_TEST_IS_DIR)) {
1019
set_current_folder(fileName);
1020
} else if (/*Glib::file_test(fileName, Glib::FILE_TEST_IS_REGULAR)*/1) {
1021
//dialog with either (1) select a regular file or (2) cd to dir
1023
set_filename(fileName);
1024
response(Gtk::RESPONSE_OK);
1031
* Callback for fileNameEntry widget
1033
void FileSaveDialogImplGtk::fileTypeChangedCallback()
1035
int sel = fileTypeComboBox.get_active_row_number();
1036
if (sel<0 || sel >= (int)fileTypes.size())
1038
FileType type = fileTypes[sel];
1039
//g_message("selected: %s\n", type.name.c_str());
1041
extension = type.extension;
1042
Gtk::FileFilter filter;
1043
filter.add_pattern(type.pattern);
1046
updateNameAndExtension();
1051
void FileSaveDialogImplGtk::createFileTypeMenu()
1053
Inkscape::Extension::DB::OutputList extension_list;
1054
Inkscape::Extension::db.get_output_list(extension_list);
1055
knownExtensions.clear();
1057
for (Inkscape::Extension::DB::OutputList::iterator current_item = extension_list.begin();
1058
current_item != extension_list.end(); current_item++)
1060
Inkscape::Extension::Output * omod = *current_item;
1062
// FIXME: would be nice to grey them out instead of not listing them
1063
if (omod->deactivated()) continue;
1066
type.name = (_(omod->get_filetypename()));
1068
Glib::ustring extension = omod->get_extension();
1069
knownExtensions.insert( extension.casefold() );
1070
fileDialogExtensionToPattern (type.pattern, extension);
1071
type.extension= omod;
1072
fileTypeComboBox.append_text(type.name);
1073
fileTypes.push_back(type);
1078
guessType.name = _("Guess from extension");
1079
guessType.pattern = "*";
1080
guessType.extension = NULL;
1081
fileTypeComboBox.append_text(guessType.name);
1082
fileTypes.push_back(guessType);
1085
fileTypeComboBox.set_active(0);
1086
fileTypeChangedCallback(); //call at least once to set the filter
1094
* Show this dialog modally. Return true if user hits [OK]
1097
FileSaveDialogImplGtk::show()
1099
change_path(myFilename);
1100
set_modal (TRUE); //Window
1101
sp_transientize((GtkWidget *)gobj()); //Make transient
1102
gint b = run(); //Dialog
1103
svgPreview.showNoPreview();
1104
set_preview_widget_active(false);
1107
if (b == Gtk::RESPONSE_OK) {
1108
updateNameAndExtension();
1109
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1111
// Store changes of the "Append filename automatically" checkbox back to preferences.
1112
prefs->setBool("/dialogs/save_as/append_extension", fileTypeCheckbox.get_active());
1114
// Store the last used save-as filetype to preferences.
1115
prefs->setString("/dialogs/save_as/default", ( extension != NULL ? extension->get_id() : "" ));
1128
* Get the file extension type that was selected by the user. Valid after an [OK]
1130
Inkscape::Extension::Extension *
1131
FileSaveDialogImplGtk::getSelectionType()
1136
void FileSaveDialogImplGtk::setSelectionType( Inkscape::Extension::Extension * key )
1138
// If no pointer to extension is passed in, look up based on filename extension.
1140
// Not quite UTF-8 here.
1141
gchar *filenameLower = g_ascii_strdown(myFilename.c_str(), -1);
1142
for ( int i = 0; !key && (i < (int)fileTypes.size()); i++ ) {
1143
Inkscape::Extension::Output *ext = dynamic_cast<Inkscape::Extension::Output*>(fileTypes[i].extension);
1144
if ( ext && ext->get_extension() ) {
1145
gchar *extensionLower = g_ascii_strdown( ext->get_extension(), -1 );
1146
if ( g_str_has_suffix(filenameLower, extensionLower) ) {
1147
key = fileTypes[i].extension;
1149
g_free(extensionLower);
1152
g_free(filenameLower);
1155
// Ensure the proper entry in the combo box is selected.
1158
gchar const * extensionID = extension->get_id();
1159
if ( extensionID ) {
1160
for ( int i = 0; i < (int)fileTypes.size(); i++ ) {
1161
Inkscape::Extension::Extension *ext = fileTypes[i].extension;
1163
gchar const * id = ext->get_id();
1164
if ( id && ( strcmp(extensionID, id) == 0) ) {
1165
int oldSel = fileTypeComboBox.get_active_row_number();
1166
if ( i != oldSel ) {
1167
fileTypeComboBox.set_active(i);
1177
Glib::ustring FileSaveDialogImplGtk::getCurrentDirectory()
1179
return get_current_folder();
1184
FileSaveDialogImplGtk::change_title(const Glib::ustring& title)
1190
* Change the default save path location.
1193
FileSaveDialogImplGtk::change_path(const Glib::ustring& path)
1197
if (Glib::file_test(myFilename, Glib::FILE_TEST_IS_DIR)) {
1198
//fprintf(stderr,"set_current_folder(%s)\n",myFilename.c_str());
1199
set_current_folder(myFilename);
1201
//fprintf(stderr,"set_filename(%s)\n",myFilename.c_str());
1202
if ( Glib::file_test( myFilename, Glib::FILE_TEST_EXISTS ) ) {
1203
set_filename(myFilename);
1205
std::string dirName = Glib::path_get_dirname( myFilename );
1206
if ( dirName != get_current_folder() ) {
1207
set_current_folder(dirName);
1210
Glib::ustring basename = Glib::path_get_basename(myFilename);
1211
//fprintf(stderr,"set_current_name(%s)\n",basename.c_str());
1213
set_current_name( Glib::filename_to_utf8(basename) );
1214
} catch ( Glib::ConvertError& e ) {
1215
g_warning( "Error converting save filename to UTF-8." );
1217
set_current_name( basename );
1222
void FileSaveDialogImplGtk::updateNameAndExtension()
1224
// Pick up any changes the user has typed in.
1225
Glib::ustring tmp = get_filename();
1226
#ifdef WITH_GNOME_VFS
1227
if ( tmp.empty() && gnome_vfs_initialized() ) {
1231
if ( !tmp.empty() ) {
1235
Inkscape::Extension::Output* newOut = extension ? dynamic_cast<Inkscape::Extension::Output*>(extension) : 0;
1236
if ( fileTypeCheckbox.get_active() && newOut ) {
1237
// Append the file extension if it's not already present
1238
appendExtension(myFilename, newOut);
1243
//########################################################################
1244
//# F I L E E X P O R T
1245
//########################################################################
1248
* Callback for fileNameEntry widget
1250
void FileExportDialogImpl::fileNameEntryChangedCallback()
1255
Glib::ustring fileName = fileNameEntry->get_text();
1256
if (!Glib::get_charset()) //If we are not utf8
1257
fileName = Glib::filename_to_utf8(fileName);
1259
//g_message("User hit return. Text is '%s'\n", fileName.c_str());
1261
if (!Glib::path_is_absolute(fileName)) {
1262
//try appending to the current path
1263
// not this way: fileName = get_current_folder() + "/" + fileName;
1264
std::vector<Glib::ustring> pathSegments;
1265
pathSegments.push_back( get_current_folder() );
1266
pathSegments.push_back( fileName );
1267
fileName = Glib::build_filename(pathSegments);
1270
//g_message("path:'%s'\n", fileName.c_str());
1272
if (Glib::file_test(fileName, Glib::FILE_TEST_IS_DIR)) {
1273
set_current_folder(fileName);
1274
} else if (/*Glib::file_test(fileName, Glib::FILE_TEST_IS_REGULAR)*/1) {
1275
//dialog with either (1) select a regular file or (2) cd to dir
1277
set_filename(fileName);
1278
response(Gtk::RESPONSE_OK);
1285
* Callback for fileNameEntry widget
1287
void FileExportDialogImpl::fileTypeChangedCallback()
1289
int sel = fileTypeComboBox.get_active_row_number();
1290
if (sel<0 || sel >= (int)fileTypes.size())
1292
FileType type = fileTypes[sel];
1293
//g_message("selected: %s\n", type.name.c_str());
1294
Gtk::FileFilter filter;
1295
filter.add_pattern(type.pattern);
1301
void FileExportDialogImpl::createFileTypeMenu()
1303
Inkscape::Extension::DB::OutputList extension_list;
1304
Inkscape::Extension::db.get_output_list(extension_list);
1306
for (Inkscape::Extension::DB::OutputList::iterator current_item = extension_list.begin();
1307
current_item != extension_list.end(); current_item++)
1309
Inkscape::Extension::Output * omod = *current_item;
1311
// FIXME: would be nice to grey them out instead of not listing them
1312
if (omod->deactivated()) continue;
1315
type.name = (_(omod->get_filetypename()));
1317
Glib::ustring extension = omod->get_extension();
1318
fileDialogExtensionToPattern (type.pattern, extension);
1319
type.extension= omod;
1320
fileTypeComboBox.append_text(type.name);
1321
fileTypes.push_back(type);
1326
guessType.name = _("Guess from extension");
1327
guessType.pattern = "*";
1328
guessType.extension = NULL;
1329
fileTypeComboBox.append_text(guessType.name);
1330
fileTypes.push_back(guessType);
1333
fileTypeComboBox.set_active(0);
1334
fileTypeChangedCallback(); //call at least once to set the filter
1341
FileExportDialogImpl::FileExportDialogImpl( Gtk::Window& parentWindow,
1342
const Glib::ustring &dir,
1343
FileDialogType fileTypes,
1344
const Glib::ustring &title,
1345
const Glib::ustring &/*default_key*/ ) :
1346
FileDialogBaseGtk(parentWindow, title, Gtk::FILE_CHOOSER_ACTION_SAVE, fileTypes, "/dialogs/export"),
1347
sourceX0Spinner("X0", _("Left edge of source")),
1348
sourceY0Spinner("Y0", _("Top edge of source")),
1349
sourceX1Spinner("X1", _("Right edge of source")),
1350
sourceY1Spinner("Y1", _("Bottom edge of source")),
1351
sourceWidthSpinner("Width", _("Source width")),
1352
sourceHeightSpinner("Height", _("Source height")),
1353
destWidthSpinner("Width", _("Destination width")),
1354
destHeightSpinner("Height", _("Destination height")),
1355
destDPISpinner("DPI", _("Resolution (dots per inch)"))
1357
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1358
append_extension = prefs->getBool("/dialogs/save_as/append_extension", true);
1360
/* One file at a time */
1361
set_select_multiple(false);
1363
#ifdef WITH_GNOME_VFS
1364
if (gnome_vfs_initialized()) {
1365
set_local_only(false);
1369
/* Initalize to Autodetect */
1371
/* No filename to start out with */
1374
/* Set our dialog type (save, export, etc...)*/
1375
_dialogType = fileTypes;
1377
/* Set the pwd and/or the filename */
1380
Glib::ustring udir(dir);
1381
Glib::ustring::size_type len = udir.length();
1382
// leaving a trailing backslash on the directory name leads to the infamous
1383
// double-directory bug on win32
1384
if (len != 0 && udir[len - 1] == '\\') udir.erase(len - 1);
1385
set_current_folder(udir.c_str());
1388
//#########################################
1389
//## EXTRA WIDGET -- SOURCE SIDE
1390
//#########################################
1392
//##### Export options buttons/spinners, etc
1393
documentButton.set_label(_("Document"));
1394
scopeBox.pack_start(documentButton);
1395
scopeGroup = documentButton.get_group();
1397
pageButton.set_label(_("Page"));
1398
pageButton.set_group(scopeGroup);
1399
scopeBox.pack_start(pageButton);
1401
selectionButton.set_label(_("Selection"));
1402
selectionButton.set_group(scopeGroup);
1403
scopeBox.pack_start(selectionButton);
1405
customButton.set_label(_("Custom"));
1406
customButton.set_group(scopeGroup);
1407
scopeBox.pack_start(customButton);
1409
sourceBox.pack_start(scopeBox);
1414
sourceTable.resize(3,3);
1415
sourceTable.attach(sourceX0Spinner, 0,1,0,1);
1416
sourceTable.attach(sourceY0Spinner, 1,2,0,1);
1417
sourceUnitsSpinner.setUnitType(UNIT_TYPE_LINEAR);
1418
sourceTable.attach(sourceUnitsSpinner, 2,3,0,1);
1419
sourceTable.attach(sourceX1Spinner, 0,1,1,2);
1420
sourceTable.attach(sourceY1Spinner, 1,2,1,2);
1421
sourceTable.attach(sourceWidthSpinner, 0,1,2,3);
1422
sourceTable.attach(sourceHeightSpinner, 1,2,2,3);
1424
sourceBox.pack_start(sourceTable);
1425
sourceFrame.set_label(_("Source"));
1426
sourceFrame.add(sourceBox);
1427
exportOptionsBox.pack_start(sourceFrame);
1430
//#########################################
1431
//## EXTRA WIDGET -- SOURCE SIDE
1432
//#########################################
1435
destTable.resize(3,3);
1436
destTable.attach(destWidthSpinner, 0,1,0,1);
1437
destTable.attach(destHeightSpinner, 1,2,0,1);
1438
destUnitsSpinner.setUnitType(UNIT_TYPE_LINEAR);
1439
destTable.attach(destUnitsSpinner, 2,3,0,1);
1440
destTable.attach(destDPISpinner, 0,1,1,2);
1442
destBox.pack_start(destTable);
1445
cairoButton.set_label(_("Cairo"));
1446
otherOptionBox.pack_start(cairoButton);
1448
antiAliasButton.set_label(_("Antialias"));
1449
otherOptionBox.pack_start(antiAliasButton);
1451
backgroundButton.set_label(_("Background"));
1452
otherOptionBox.pack_start(backgroundButton);
1454
destBox.pack_start(otherOptionBox);
1460
//###### File options
1461
//###### Do we want the .xxx extension automatically added?
1462
fileTypeCheckbox.set_label(Glib::ustring(_("Append filename extension automatically")));
1463
fileTypeCheckbox.set_active(append_extension);
1464
destBox.pack_start(fileTypeCheckbox);
1466
//###### File type menu
1467
createFileTypeMenu();
1468
fileTypeComboBox.set_size_request(200,40);
1469
fileTypeComboBox.signal_changed().connect(
1470
sigc::mem_fun(*this, &FileExportDialogImpl::fileTypeChangedCallback) );
1472
destBox.pack_start(fileTypeComboBox);
1474
destFrame.set_label(_("Destination"));
1475
destFrame.add(destBox);
1476
exportOptionsBox.pack_start(destFrame);
1478
//##### Put the two boxes and their parent onto the dialog
1479
exportOptionsBox.pack_start(sourceFrame);
1480
exportOptionsBox.pack_start(destFrame);
1482
set_extra_widget(exportOptionsBox);
1487
//Let's do some customization
1488
fileNameEntry = NULL;
1489
Gtk::Container *cont = get_toplevel();
1490
std::vector<Gtk::Entry *> entries;
1491
findEntryWidgets(cont, entries);
1492
//g_message("Found %d entry widgets\n", entries.size());
1493
if (entries.size() >=1 )
1495
//Catch when user hits [return] on the text field
1496
fileNameEntry = entries[0];
1497
fileNameEntry->signal_activate().connect(
1498
sigc::mem_fun(*this, &FileExportDialogImpl::fileNameEntryChangedCallback) );
1501
//Let's do more customization
1502
std::vector<Gtk::Expander *> expanders;
1503
findExpanderWidgets(cont, expanders);
1504
//g_message("Found %d expander widgets\n", expanders.size());
1505
if (expanders.size() >=1 )
1507
//Always show the file list
1508
Gtk::Expander *expander = expanders[0];
1509
expander->set_expanded(true);
1513
//if (extension == NULL)
1514
// checkbox.set_sensitive(FALSE);
1516
add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1517
set_default(*add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK));
1519
show_all_children();
1525
FileExportDialogImpl::~FileExportDialogImpl()
1532
* Show this dialog modally. Return true if user hits [OK]
1535
FileExportDialogImpl::show()
1537
Glib::ustring s = Glib::filename_to_utf8 (get_current_folder());
1538
if (s.length() == 0)
1539
s = getcwd (NULL, 0);
1540
set_current_folder(Glib::filename_from_utf8(s)); //hack to force initial dir listing
1541
set_modal (TRUE); //Window
1542
sp_transientize((GtkWidget *)gobj()); //Make transient
1543
gint b = run(); //Dialog
1544
svgPreview.showNoPreview();
1547
if (b == Gtk::RESPONSE_OK)
1549
int sel = fileTypeComboBox.get_active_row_number ();
1550
if (sel>=0 && sel< (int)fileTypes.size())
1552
FileType &type = fileTypes[sel];
1553
extension = type.extension;
1555
myFilename = get_filename();
1556
#ifdef WITH_GNOME_VFS
1557
if ( myFilename.empty() && gnome_vfs_initialized() ) {
1558
myFilename = get_uri();
1564
// FIXME: Why do we have more code
1566
append_extension = checkbox.get_active();
1567
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1568
prefs->setBool("/dialogs/save_as/append_extension", append_extension);
1569
prefs->setBool("/dialogs/save_as/default", ( extension != NULL ? extension->get_id() : "" ));
1581
* Get the file extension type that was selected by the user. Valid after an [OK]
1583
Inkscape::Extension::Extension *
1584
FileExportDialogImpl::getSelectionType()
1591
* Get the file name chosen by the user. Valid after an [OK]
1594
FileExportDialogImpl::getFilename()
1600
} //namespace Dialog
1602
} //namespace Inkscape
1607
c-file-style:"stroustrup"
1608
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
1609
indent-tabs-mode:nil
1613
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :