1 /**
2 * Yudit Unicode Editor Source File
3 *
4 * GNU Copyright (C) 1997-2006 Gaspar Sinai <gaspar@yudit.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License, version 2,
8 * dated June 1991. See file COPYYING for details.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #include "swidget/SFileDialog.h"
21 #include "swidget/SIcon.h"
22 #include "swidget/SIconFactory.h"
23 #include "stoolkit/SUtil.h"
24 #include "stoolkit/SEncoder.h"
25
26
27 /**
28 * Hidden Filter Type
29 * Directories Files Types
30 * +--------+ +-------+ +---+
31 * | | | | | |
32 * | | | | | |
33 * | | | | | |
34 * +--------+ +-------+ +---+
35 * ______directory
36 * ______pathname___________
37 * OK CD mkdir Cancel
38 */
SFileDialog(void)39 SFileDialog::SFileDialog (void)
40 {
41 setFrameListener (this);
42 hiddenButton = new SButton (translate ("Show Hidden"),
43 SIconFactory::getIcon("CircleOff"));
44 hiddenButton->setButtonListener (this);
45 hiddenButton->setAlignment (SD_Center);
46 hiddenButton->setIcon(SIconFactory::getIcon("CircleOff"));
47
48 homeButton = new SButton (translate ("Home"), SIconFactory::getIcon("Home"));
49 homeButton->setButtonListener (this);
50 homeButton->setAlignment (SD_Center);
51 add (homeButton);
52
53 isFocused = false;
54 isCancel = true;
55 showHidden = false;
56 setHidden ();
57 add (hiddenButton);
58 yesButton = new SButton (translate ("OK"), SIconFactory::getIcon("Yes"));
59 yesButton->setAlignment (SD_Center);
60 yesButton->setButtonListener (this);
61
62 cdButton = new SButton (translate ("CD to"), SIconFactory::getIcon("Folder"));
63 cdButton->setAlignment (SD_Center);
64 cdButton->setButtonListener (this);
65
66 createButton = new SButton (translate ("Make Folder"), SIconFactory::getIcon("CreateFolder"));
67 createButton->setAlignment (SD_Center);
68 createButton->setButtonListener (this);
69
70 cancelButton = new SButton (translate ("Cancel"), SIconFactory::getIcon("Cancel"));
71 cancelButton->setAlignment (SD_Center);
72 cancelButton->setButtonListener (this);
73 add (yesButton);
74 add (cdButton);
75 add (createButton);
76 add (cancelButton);
77 folderListBox = new SListBox(translate ("Folder"));
78 folderListBox->setListListener (this);
79 add (folderListBox);
80 fileListBox = new SListBox(translate ("File"));
81 fileListBox->setListListener (this);
82 add (fileListBox);
83 fileTypeListBox = new SListBox(translate ("File Type"));
84 fileTypeListBox->setListListener (this);
85 add (fileTypeListBox);
86
87
88 fileTitleLabel = new SLabel (translate ("File:"));
89 add (fileTitleLabel);
90 fileTextEdit = new STextEdit("");
91 fileTextEdit->setMultiline(false);
92 fileTextEdit->setLineEndMark(false);
93 fileTextEdit->addTextEditLS(this);
94 add (fileTextEdit);
95
96 folderTitleLabel = new SLabel (translate ("Folder:"));
97 add (folderTitleLabel);
98 folderNameLabel = new SLabel ("");
99 add (folderNameLabel);
100
101 filterTitleLabel = new SLabel (translate ("Filter:"));
102 add (filterTitleLabel);
103 fileFilter = "*";
104 filterTextEdit = new STextEdit(fileFilter);
105 filterTextEdit->addTextEditLS(this);
106
107 add (filterTextEdit);
108 filterTextEdit->setMultiline(false);
109 filterTextEdit->setLineEndMark(false);
110 fileTypeButton = new SButton (
111 translate ("Best File Type"), SIconFactory::getIcon("Best"));
112 fileTypeButton->setButtonListener (this);
113 add (fileTypeButton);
114 fileTypeLabel = new SLabel ("[]");
115 add (fileTypeLabel);
116 textDialog = new STextDialog();
117 textDialog->setModal (this);
118 recalc();
119 }
120
121 bool
setFileType(const SString & _fileType)122 SFileDialog::setFileType (const SString& _fileType)
123 {
124 bool exists = true;
125 if (!fileTypeListBox->selectText (_fileType))
126 {
127 fileTypeVector.append (_fileType);
128 fileTypeVector.sort ();
129 fileTypeListBox->setText(fileTypeVector);
130 exists = false;
131 }
132 fileTypeListBox->selectText (_fileType);
133 fileTypeChanged (_fileType);
134 return exists;
135 }
136
137 const SStringVector&
getFileTypes() const138 SFileDialog::getFileTypes() const
139 {
140 return fileTypeVector;
141 }
142
143 void
setApplicationImage(const SImage & image)144 SFileDialog::setApplicationImage (const SImage& image)
145 {
146 getComponentWindow()->setApplicationImage (image);
147 textDialog->setApplicationImage (image);
148 }
149
150 void
fileTypeChanged(const SString & _filetype)151 SFileDialog::fileTypeChanged (const SString& _filetype)
152 {
153 if (_filetype == "utf-8") {
154 fileTypeButton->setIcon (SIconFactory::getIcon("Best"));
155 } else {
156 fileTypeButton->setIcon (SIconFactory::getIcon("BestEmpty"));
157 }
158 //SString a="[";
159 SString a;
160 a.append(_filetype);
161 //a.append("]");
162 fileTypeLabel->setText (a);
163 fileTypeText = _filetype;
164 }
165
166 void
rereadDir()167 SFileDialog::rereadDir()
168 {
169 filterChanged ();
170 /* get directories and files */
171 while (!currentDirectory.exists() || !currentDirectory.readable())
172 {
173 currentDirectory.cd ("..");
174 if (currentDirectory.getUnixName() == "/") break;
175 }
176 SStringVector files = currentDirectory.list("*");
177 SStringVector combedFiles;
178 unsigned int i;
179 if (showHidden)
180 {
181 combedFiles = files;
182 }
183 else
184 {
185 for (i=0; i<files.size(); i++)
186 {
187 SString s = files[i];
188 if (s.size() == 0 || s[0] == '.') continue;
189 if (fileFilter.size()==0 || s.match (fileFilter))
190 {
191 combedFiles.append (s);
192 }
193 }
194 }
195 combedFiles.sort();
196 fileListBox->setText(combedFiles);
197
198 SStringVector dirs = currentDirectory.list(SDir::SE_DIR);
199 SStringVector combedDirs;
200 if (showHidden)
201 {
202 combedDirs = dirs;
203 }
204 else
205 {
206 for (i=0; i<dirs.size(); i++)
207 {
208 SString s = dirs[i];
209 if (s.size() == 0 || s[0] == '.') continue;
210 combedDirs.append (s);
211 }
212 }
213 combedDirs.sort();
214 if (currentDirectory.getUnixName () != "/")
215 {
216 combedDirs.insert (0, "..");
217 }
218 folderListBox->setText(combedDirs);
219 folderNameLabel->setText (currentDirectory.getUnixName ());
220 // This bug has been with us for some time now :)
221 fileListBox->selectText (fileTextEdit->getText());
222 }
223
224 void
setFileTypes(const SStringVector & v)225 SFileDialog::setFileTypes(const SStringVector& v)
226 {
227 fileTypeVector = v;
228 fileTypeVector.sort();
229 fileTypeListBox->setText(fileTypeVector);
230 }
231
232
~SFileDialog()233 SFileDialog::~SFileDialog ()
234 {
235 }
236
237
238 /**
239 * recalcualte the geometry
240 * it is based upon 300x200 layout.
241 * preferredSize will be calculated here.
242 */
243 void
recalc()244 SFileDialog::recalc ()
245 {
246 unsigned int bw = 1;
247 if (yesButton->getPreferredSize().width > bw )
248 {
249 bw = yesButton->getPreferredSize().width;
250 }
251 if (cdButton->getPreferredSize().width > bw )
252 {
253 bw = cdButton->getPreferredSize().width;
254 }
255 if (createButton->getPreferredSize().width > bw )
256 {
257 bw = createButton->getPreferredSize().width;
258 }
259 if (cancelButton->getPreferredSize().width > bw )
260 {
261 bw = cancelButton->getPreferredSize().width;
262 }
263 unsigned int bh= cancelButton->getPreferredSize().height;
264 int gap = (300-((int)bw * 4 + 10))/3;
265 int currentx= 5;
266
267 yesButton->setLayout (
268 SLayout (
269 SLocation (currentx, 195-bh),
270 SLocation (currentx+(int)bw, 195),
271 SLocation (0, 100),
272 SLocation (0, 100)
273 )
274 );
275 currentx = currentx + (int) bw + gap;
276 cdButton->setLayout (
277 SLayout (
278 SLocation (currentx, 195-bh),
279 SLocation (currentx+(int)bw, 195),
280 SLocation (33, 100),
281 SLocation (33, 100)
282 )
283 );
284 currentx = currentx + (int) bw + gap;
285 createButton->setLayout (
286 SLayout (
287 SLocation (currentx, 195-bh),
288 SLocation (currentx+(int)bw, 195),
289 SLocation (66, 100),
290 SLocation (66, 100)
291 )
292 );
293 currentx = currentx + (int) bw + gap;
294 cancelButton->setLayout (
295 SLayout (
296 SLocation (currentx, 195-bh),
297 SLocation (currentx+(int)bw, 195),
298 SLocation (100, 100),
299 SLocation (100, 100)
300 )
301 );
302 SDimension hms = homeButton->getPreferredSize();
303 homeButton->setLayout (
304 SLayout (
305 SLocation (5, 5),
306 SLocation ((int)hms.width+5, (int)hms.height+5),
307 SLocation (0, 0),
308 SLocation (0, 0)
309 )
310 );
311 SDimension hs = hiddenButton->getPreferredSize();
312 hiddenButton->setLayout (
313 SLayout (
314 SLocation ((int)hms.width+10, 5),
315 SLocation ((int)hms.width + hs.width+10, (int)hs.height+5),
316 SLocation (0, 0),
317 SLocation (0, 0)
318 )
319 );
320 SDimension bs = fileTypeButton->getPreferredSize();
321 fileTypeButton->setLayout (
322 SLayout (
323 SLocation (295-(int)bs.width, 5),
324 SLocation (295, (int)bs.height+5),
325 SLocation (100, 0),
326 SLocation (100, 0)
327 )
328 );
329 SDimension fs = filterTitleLabel->getPreferredSize();
330 filterTitleLabel->setLayout (
331 SLayout (
332 SLocation ((int)hs.width+(int)hms.width+12, 5),
333 SLocation ((int) fs.width + (int)hs.width+(int)hms.width+12, (int) fs.height+5),
334 SLocation (0, 0),
335 SLocation (0, 0)
336 )
337 );
338 filterTextEdit->setLayout (
339 SLayout (
340 SLocation ((int) fs.width + (int)hs.width+(int)hms.width+12, 5),
341 SLocation ((int) fs.width + 80 + (int)hs.width+(int)hms.width+12,
342 (int) fs.height+5),
343 SLocation (0, 0),
344 SLocation (0, 0)
345 )
346 );
347
348 /* this will be the text field height */
349 unsigned int tfh = fileTextEdit->getPreferredSize().height;
350 unsigned int phw = fileTitleLabel->getPreferredSize().width;
351
352 unsigned int dph = folderTitleLabel->getPreferredSize().height;
353 unsigned int dpw = folderTitleLabel->getPreferredSize().width;
354
355 folderTitleLabel->setLayout (
356 SLayout (
357 SLocation (5, 200-(int)bh-(int)tfh -(int) dph - 10),
358 SLocation (5 + dpw, 200-(int)bh -(int)tfh - 10),
359 SLocation (0, 100),
360 SLocation (0, 100)
361 )
362 );
363
364 folderNameLabel->setLayout (
365 SLayout (
366 SLocation (5+dpw, 200-(int)bh-(int)tfh -(int) dph - 10),
367 SLocation (295, 200-(int)bh -(int)tfh - 10),
368 SLocation (0, 100),
369 SLocation (100, 100)
370 )
371 );
372
373 fileTitleLabel->setLayout (
374 SLayout (
375 SLocation (5, 200-(int)bh-(int)tfh - 10),
376 SLocation (5 + phw, 200-(int)bh - 10),
377 SLocation (0, 100),
378 SLocation (0, 100)
379 )
380 );
381
382 fileTextEdit->setLayout (
383 SLayout (
384 SLocation (5+phw, 200-(int)bh-(int)tfh - 10),
385 SLocation (180, 200-(int)bh - 10),
386 SLocation (0, 100),
387 SLocation (100, 100)
388 )
389 );
390 fileTypeLabel->setLayout (
391 SLayout (
392 SLocation (180, 200-(int)bh-(int)tfh - 10),
393 SLocation (295, 200-(int)bh - 10),
394 SLocation (100, 100),
395 SLocation (100, 100)
396 )
397 );
398
399 unsigned int incr = (300-10)/3;
400 folderListBox->setLayout (
401 SLayout (
402 SLocation (5, (int)hs.height+5+5),
403 SLocation (5+incr-2, 200-(int)bh-(int)tfh -(int) dph - 10),
404 SLocation (0, 0),
405 SLocation (33, 100)
406 )
407 );
408
409 fileListBox->setLayout (
410 SLayout (
411 SLocation (5+incr+1, (int)hs.height+5+5),
412 SLocation (300-5-incr-1, 200-(int)bh-(int)tfh-(int) dph - 10),
413 SLocation (33, 0),
414 SLocation (66, 100)
415 )
416 );
417
418 fileTypeListBox->setLayout (
419 SLayout (
420 SLocation (300-5-incr+2, (int)hs.height+5+5),
421 SLocation (300-5, 200-(int)bh-(int)tfh-(int) dph - 10),
422 SLocation (66, 0),
423 SLocation (100, 100)
424 )
425 );
426 unsigned int bestWidthBottom = bw * 4 + 10 + 15 + 20;
427 /* top */
428 unsigned int bestWidthTop = 5 + hms.width + 5 + hs.width
429 + 5 +fs.width + 80 + bs.width + 5 + 10;
430 unsigned int bestWidth = (bestWidthTop>bestWidthBottom) ?
431 bestWidthTop : bestWidthBottom;
432
433 preferredSize = SDimension (bestWidth+10, 300);
434
435 /* This was out layout... */
436 forceLayout (SLayout (SDimension (300,200)));
437
438 /* But this one is the one that works */
439 setLayout (SLayout (preferredSize));
440
441 setMinimumSize (preferredSize);
442
443 resize (SDimension (preferredSize.width, preferredSize.height));
444
445 }
446
447 SString
getFileName()448 SFileDialog::getFileName ()
449 {
450 SString fn = fileTextEdit->getText();
451 if (fn.size()==0) return SString(fn);
452
453 SString filePath = currentDirectory.getName();
454 if (filePath != "/") filePath.append ("/");
455 filePath.append (fn);
456 return SString(filePath);
457 }
458
459 SString
getUnixFileName()460 SFileDialog::getUnixFileName ()
461 {
462 SString fn = fileTextEdit->getText();
463 if (fn.size()==0) return SString(fn);
464 SString filePath = currentDirectory.getUnixName();
465 if (filePath != "/") filePath.append ("/");
466 filePath.append (fn);
467 return SString(filePath);
468 }
469
470 SString
getFileType()471 SFileDialog::getFileType ()
472 {
473 return fileTypeText;
474 }
475
476 bool
getInput(const SString & titleString,bool shouldExist,bool warnExist)477 SFileDialog::getInput (const SString& titleString,
478 bool shouldExist, bool warnExist)
479 {
480 setTitle (titleString);
481 fileFilter = "*";
482 filterTextEdit->setText (fileFilter);
483 rereadDir ();
484 fileListBox->selectText (fileTextEdit->getText());
485 center();
486 isCancel = true;
487 isFocused = false;
488 show();
489 wait();
490 textDialog->hide();
491 hide();
492 return !isCancel;
493 }
494
495 /**
496 * buttons call this
497 */
498 void
buttonPressedAccel(void * source,const SAccelerator * acc)499 SFileDialog::buttonPressedAccel (void* source, const SAccelerator* acc)
500 {
501 if (source == createButton)
502 {
503 SString before = currentDirectory.getName();
504 SDir d(before);
505 SString s(fileTextEdit->getText());
506 unsigned int ck = 0;
507 bool hasSlash = false;
508 for (ck=0; ck<s.size(); ck++)
509 {
510 if ((int) (unsigned char) s[ck] <= ' ') break;
511 if (s[ck] == '/') hasSlash = true;
512 }
513 if (ck==0 || ck+1 == s.size())
514 {
515 textDialog->getInput ("Error",
516 translate ("Will not create\nspecified folder\n"),
517 STextDialog::SS_ERR);
518 return;
519 }
520 if (hasSlash)
521 {
522 textDialog->getInput ("Error",
523 translate ("Folders can be created\nin current directory only."),
524 STextDialog::SS_ERR);
525 return;
526 }
527 if (d.cd (s))
528 {
529 textDialog->getInput ("Warning",
530 translate ("Specified folder\nalready exists.\n"),
531 STextDialog::SS_WARN);
532 return;
533 }
534 SString cdr = currentDirectory.getName();
535 if (cdr != "/") cdr.append ("/");
536 cdr.append (fileTextEdit->getText());
537 d = SDir (cdr);
538 if (!d.create())
539 {
540 textDialog->getInput ("Error",
541 translate ("Can not create\nspecified folder\n"),
542 STextDialog::SS_ERR);
543 return;
544 }
545 currentDirectory = d;
546 rereadDir ();
547 fileTextEdit->setText("");
548 return;
549 }
550 if (source == cdButton)
551 {
552 SString before = currentDirectory.getName();
553 SDir d(before);
554 if (!d.cd (fileTextEdit->getText()))
555 {
556 textDialog->getInput ("Error",
557 translate ("Can not go to\nspecified folder.\n"),
558 STextDialog::SS_ERR);
559 return;
560 }
561 currentDirectory = d;
562 rereadDir ();
563 fileTextEdit->setText("");
564 return;
565 }
566 if (source == cancelButton)
567 {
568 isCancel = true;
569 hide();
570 return;
571 }
572 if (source == yesButton)
573 {
574 isCancel = false;
575 hide();
576 return;
577 }
578 if (source == fileTypeButton)
579 {
580 setFileType("utf-8");
581 return;
582 }
583 if (source == hiddenButton)
584 {
585 showHidden = !showHidden;
586 setHidden();
587 rereadDir();
588 return;
589 }
590 if (source == homeButton)
591 {
592 currentDirectory.cd (getHome());
593 rereadDir();
594 return;
595 }
596 }
597
598 /**
599 * STextListListener
600 */
601 void
itemSelected(void * source,const SAccelerator * acc)602 SFileDialog::itemSelected (void* source, const SAccelerator* acc)
603 {
604 if (source == folderListBox->textList)
605 {
606 SString s = folderListBox->textList->getLastSelectedText();
607 SString before = currentDirectory.getName();
608 //fprintf (stderr, "before %*.*s [%*.*s]\n", SSARGS (s), SSARGS(before));
609 currentDirectory.cd (s);
610 SString after = currentDirectory.getName();
611 //fprintf (stderr, "after %*.*s [%*.*s]\n", SSARGS (s), SSARGS(after));
612 if (after != before) rereadDir ();
613 return;
614 }
615 if (source == fileListBox->textList)
616 {
617 SString s = fileListBox->textList->getLastSelectedText();
618 if (s != fileTextEdit->getText()) {
619 fileTextEdit->setText (s);
620 }
621 return;
622 }
623 if (source == fileTypeListBox->textList)
624 {
625 SString s = fileTypeListBox->textList->getLastSelectedText();
626 //fprintf (stderr, "typeselected %*.*s\n", SSARGS(s));
627 fileTypeChanged (s);
628 }
629 }
630
631 /**
632 * STextEditLS
633 */
634 void
textEntered(void * source)635 SFileDialog::textEntered (void *source)
636 {
637 if (source == filterTextEdit)
638 {
639 rereadDir ();
640 }
641 /* ok */
642 if (source == fileTextEdit)
643 {
644 isCancel = false;
645 hide();
646 return;
647 }
648 }
649
650 void
textChanged(void * source)651 SFileDialog::textChanged (void *source)
652 {
653 if (source == fileTextEdit)
654 {
655 fileListBox->selectText (fileTextEdit->getText());
656 }
657 }
658
659 void
filterChanged()660 SFileDialog::filterChanged ()
661 {
662 fileFilter = filterTextEdit->getText();
663 /* trim what is not there */
664 while (fileFilter.size()>0 &&
665 (fileFilter[0]==' '||fileFilter[0]=='\t'))
666 {
667 fileFilter.remove (0);
668 }
669 while (fileFilter.size()>0 &&
670 (fileFilter[fileFilter.size()-1] == ' '
671 || fileFilter[fileFilter.size()-1] == '\t'))
672 {
673 fileFilter.truncate (fileFilter.size()-1);
674 }
675 //fprintf (stderr,"filter changed to '%*.*s'\n");
676 }
677
678 /**
679 * set icon accoring to showHidden
680 */
681 void
setHidden()682 SFileDialog::setHidden()
683 {
684 /* create icons here */
685 const char * str = showHidden?"CircleOn" : "CircleOff";
686 hiddenButton->setIcon (SIconFactory::getIcon(str));
687 }
688 bool
close(SPanel * comp)689 SFileDialog::close (SPanel* comp)
690 {
691 isCancel =true;
692 hide();
693 textDialog->hide();
694 return false;
695 }
696
697 void
focusChanged(void * source,bool in)698 SFileDialog::focusChanged (void *source, bool in)
699 {
700 if (!in && source == filterTextEdit)
701 {
702 rereadDir ();
703 }
704 }
705
706 /**
707 * set the filename - cut off the dirpart
708 */
709 void
setFileName(const SString & _filename)710 SFileDialog::setFileName (const SString& _filename)
711 {
712 SDir d;
713 /* this will chop off filename */
714 d.cd (_filename);
715 SStringVector v(_filename, "/");
716 SString fn;
717 if (v.size())
718 {
719 fn.append (v[v.size()-1]);
720 }
721 currentDirectory = d;
722 rereadDir ();
723 fileTextEdit->setText (fn);
724 fileListBox->selectText (fn);
725 }
726
727 void
setTitleForeground(const SColor & fg)728 SFileDialog::setTitleForeground (const SColor& fg)
729 {
730 textDialog->setTitleForeground (fg);
731 fileTypeButton->setForeground (fg);
732 hiddenButton->setForeground (fg);
733 homeButton->setForeground (fg);
734 cdButton->setForeground (fg);
735 yesButton->setForeground (fg);
736 cancelButton->setForeground (fg);
737 createButton->setForeground (fg);
738 folderTitleLabel->setForeground (fg);
739 fileTitleLabel->setForeground (fg);
740 filterTitleLabel->setForeground (fg);
741
742 folderListBox->setLabelForeground (fg);
743 fileListBox->setLabelForeground (fg);
744 fileTypeListBox->setLabelForeground (fg);
745 }
746
747 void
setLabelForeground(const SColor & fg)748 SFileDialog::setLabelForeground (const SColor& fg)
749 {
750 textDialog->setLabelForeground (fg);
751 folderNameLabel->setForeground (fg);
752 fileTypeLabel->setForeground (fg);
753 }
754
755 void
setBackground(const SColor & bg)756 SFileDialog::setBackground (const SColor& bg)
757 {
758 SFrame::setBackground (bg);
759 textDialog->setBackground (bg);
760 fileTextEdit->setTextBackground (SColor("white"));
761 filterTextEdit->setTextBackground (SColor("white"));
762 }
763
764 void
setForeground(const SColor & lrfg,const SColor & rlfg)765 SFileDialog::setForeground (const SColor& lrfg, const SColor& rlfg)
766 {
767 SFrame::setForeground (lrfg, rlfg);
768 setLabelForeground (lrfg);
769 setTitleForeground (lrfg);
770 }
771
772 void
setSliderBackground(const SColor & bg)773 SFileDialog::setSliderBackground (const SColor& bg)
774 {
775 folderListBox->setSliderBackground (bg);
776 fileListBox->setSliderBackground (bg);
777 fileTypeListBox->setSliderBackground (bg);
778 }
779
780 void
setFont(const SString & font,double fontSize)781 SFileDialog::setFont (const SString& font, double fontSize)
782 {
783 textDialog->setFont (font, fontSize);
784 folderNameLabel->setFont (font, fontSize);
785 fileTypeLabel->setFont (font, fontSize);
786 textDialog->setFont (font, fontSize);
787 fileTypeButton->setFont (font, fontSize);
788 hiddenButton->setFont (font, fontSize);
789 homeButton->setFont (font, fontSize);
790 cdButton->setFont (font, fontSize);
791 yesButton->setFont (font, fontSize);
792 cancelButton->setFont (font, fontSize);
793 createButton->setFont (font, fontSize);
794 folderTitleLabel->setFont (font, fontSize);
795 fileTitleLabel->setFont (font, fontSize);
796 filterTitleLabel->setFont (font, fontSize);
797 folderListBox->setFont (font, fontSize);
798 fileListBox->setFont (font, fontSize);
799 fileTypeListBox->setFont (font, fontSize);
800 recalc();
801 }
802
803 void
setFontSize(double fontSize)804 SFileDialog::setFontSize (double fontSize)
805 {
806 textDialog->setFontSize (fontSize);
807 folderNameLabel->setFontSize (fontSize);
808 fileTypeLabel->setFontSize (fontSize);
809 textDialog->setFontSize (fontSize);
810 fileTypeButton->setFontSize (fontSize);
811 hiddenButton->setFontSize (fontSize);
812 cdButton->setFontSize (fontSize);
813 yesButton->setFontSize (fontSize);
814 cancelButton->setFontSize (fontSize);
815 createButton->setFontSize (fontSize);
816 folderTitleLabel->setFontSize (fontSize);
817 fileTitleLabel->setFontSize (fontSize);
818 filterTitleLabel->setFontSize (fontSize);
819 folderListBox->setFontSize (fontSize);
820 fileListBox->setFontSize (fontSize);
821 fileTypeListBox->setFontSize (fontSize);
822 recalc();
823 }
824 /**
825 * keyboard focus gained.
826 */
827 bool
gainedKeyboardFocus(SWindow * w)828 SFileDialog::gainedKeyboardFocus (SWindow* w)
829 {
830 if (isFocused) return true;
831 isFocused = true;
832 fileTextEdit->setFocus();
833 return true;
834 }
835