1/*************************************************************************
2 *
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
6 *
7 * OpenOffice.org - a multi-platform office productivity suite
8 *
9 * This file is part of OpenOffice.org.
10 *
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
14 *
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
20 *
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org.  If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
25 *
26 ************************************************************************/
27#include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
28#include <com/sun/star/uno/Any.hxx>
29
30#ifndef _SALAQUAFILEPICKER_HXX_
31#include "SalAquaFilePicker.hxx"
32#endif
33
34#ifndef _FILTERHELPER_HXX_
35#include "FilterHelper.hxx"
36#endif
37
38#include "AquaFilePickerDelegate.hxx"
39
40@implementation AquaFilePickerDelegate
41
42- (id)initWithFilePicker:(SalAquaFilePicker*)fPicker
43{
44    if ((self = [super init])) {
45        filePicker = fPicker;
46        filterHelper = NULL;
47        return self;
48    }
49    return nil;
50}
51
52- (void)setFilterHelper:(FilterHelper*)helper
53{
54    filterHelper = helper;
55}
56
57#pragma mark NSSavePanel delegate methods
58
59- (BOOL)panel:(id)sender shouldShowFilename:(NSString *)filename
60{
61    if( filterHelper == NULL )
62        return true;
63    if( filename == nil )
64        return false;
65    return filterHelper->filenameMatchesFilter(filename);
66}
67
68- (void)panelSelectionDidChange:(id)sender
69{
70    if (filePicker != NULL) {
71        ::com::sun::star::ui::dialogs::FilePickerEvent evt;
72        filePicker->fileSelectionChanged(evt);
73    }
74}
75
76- (void)panel:(id)sender directoryDidChange:(NSString *)path
77{
78    if (filePicker != NULL) {
79        ::com::sun::star::ui::dialogs::FilePickerEvent evt;
80        filePicker->directoryChanged(evt);
81    }
82}
83
84
85#pragma mark UIActions
86- (void)filterSelectedAtIndex:(id)sender
87{
88    if (sender == nil) {
89        return;
90    }
91
92    if ([sender class] != [NSPopUpButton class]) {
93        return;
94    }
95
96    if (filterHelper == NULL) {
97        return;
98    }
99
100    NSPopUpButton *popup = (NSPopUpButton*)sender;
101    unsigned int selectedIndex = [popup indexOfSelectedItem];
102
103    filterHelper->SetFilterAtIndex(selectedIndex);
104
105    filePicker->filterControlChanged();
106}
107
108- (void)autoextensionChanged:(id)sender
109{
110    if (sender == nil) {
111        return;
112    }
113
114    if ([sender class] != [NSButton class]) {
115        return;
116    }
117    uno::Any aValue;
118    aValue <<= ([((NSButton*)sender) state] == NSOnState);
119
120    filePicker->setValue(::com::sun::star::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, 0, aValue);
121}
122
123@end
124