Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 51f77ec9e030fdb72914f030db497e575c5a94c4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package org.eclipse.cdt.internal.ui.cview;

/*
 * (c) Copyright IBM Corp. 2000, 2001.
 * All Rights Reserved.
 */
 
import java.io.StringWriter;

import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.actions.SelectionProviderAction;
import org.eclipse.ui.dialogs.ListSelectionDialog;

import org.eclipse.cdt.ui.CUIPlugin;
//import org.eclipse.cdt.core.model.CElementFilters;

/**
 * The FilterAction is the class that adds the filter views to a PackagesView.
 */
class FilterSelectionAction extends SelectionProviderAction {

	
	private CView cview; 
	private Shell shell;
	
	/**
	 * Create a new filter action
	 * @param shell the shell that will be used for the list selection
	 * @param packages the PackagesExplorerPart
	 * @param label the label for the action
	 */
	public FilterSelectionAction(Shell shell, CView cview, String label) {
		super(cview.getViewer(), label);
		setToolTipText("Filter Selection Action");
		setEnabled(true);
		this.shell= shell;
		this.cview= cview;
	}

	/**
	 * Implementation of method defined on <code>IAction</code>.
	 */
	public void run() {
		CPatternFilter filter= cview.getPatternFilter();
		FiltersContentProvider contentProvider= new FiltersContentProvider(filter);
	
		ListSelectionDialog dialog =
			new ListSelectionDialog(
				shell,
				cview.getViewer(),
				contentProvider,
				new LabelProvider(),
				"Select the filters to apply (matching files will be hidden):");
	
		dialog.setInitialSelections(contentProvider.getInitialSelections());
		dialog.setTitle("C/C++ File Filters");
		dialog.open();
		if (dialog.getReturnCode() == Window.OK) {
			Object[] results= dialog.getResult();
			String[] selectedPatterns= new String[results.length];
			System.arraycopy(results, 0, selectedPatterns, 0, results.length);
			filter.setPatterns(selectedPatterns);
			CElementFilters.setPatterns(selectedPatterns);
			saveInPreferences(selectedPatterns);
			TreeViewer viewer= cview.getViewer();
			viewer.getControl().setRedraw(false);
			viewer.refresh();
			viewer.getControl().setRedraw(true);
		}
	}
	/**
	 * Save the supplied patterns in the preferences for the UIPlugin.
	 * They are saved in the format patern,pattern,.
	 */
	private void saveInPreferences(String[] patterns) {
		CUIPlugin plugin= CUIPlugin.getDefault();
		StringWriter writer= new StringWriter();
	
		for (int i = 0; i < patterns.length; i++) {
			writer.write(patterns[i]);
			writer.write(CPatternFilter.COMMA_SEPARATOR);
		}
	
		plugin.getPreferenceStore().setValue(
			CPatternFilter.FILTERS_TAG, writer.toString());
	}
}

Back to the top