2 * Copyright (c) 2002-2004 Widespace, OU and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://solareclipse.sourceforge.net/legal/cpl-v10.html
9 * Igor Malinin - initial contribution
11 * $Id: DefaultSourceViewerConfiguration.java,v 1.1 2004-09-02 18:26:32 jsurfer Exp $
14 package net.sourceforge.phpeclipse.ui.text.source;
16 import org.eclipse.jface.preference.IPreferenceStore;
17 import org.eclipse.jface.text.source.ISourceViewer;
18 import org.eclipse.jface.text.source.SourceViewerConfiguration;
21 * @author Igor Malinin
23 public class DefaultSourceViewerConfiguration extends SourceViewerConfiguration {
25 /** Preference key used to look up display tab width. */
26 public static final String PREFERENCE_TAB_WIDTH =
27 "net.sourceforge.phpeclipse.ui.editor.tabWidth"; //$NON-NLS-1$
29 /** Preference key for inserting spaces rather than tabs. */
30 public static final String PREFERENCE_SPACES_FOR_TABS =
31 "net.sourceforge.phpeclipse.ui.editor.spacesForTabs"; //$NON-NLS-1$
33 private IPreferenceStore store;
35 public DefaultSourceViewerConfiguration(IPreferenceStore store) {
40 * @see SourceViewerConfiguration#getIndentPrefixes(ISourceViewer, String)
42 public String[] getIndentPrefixes(ISourceViewer sourceViewer,
44 // prefix[0] is either '\t' or ' ' x tabWidth, depending on useSpaces
46 int tabWidth = store.getInt(PREFERENCE_TAB_WIDTH);
47 boolean useSpaces = store.getBoolean(PREFERENCE_SPACES_FOR_TABS);
49 String[] prefixes = new String[tabWidth + 1];
51 for (int i = 0; i <= tabWidth; i++) {
52 StringBuffer prefix = new StringBuffer(tabWidth - 1);
55 for (int j = 0; j + i < tabWidth; j++) {
63 for (int j = 0; j < i; j++) {
72 prefixes[i] = prefix.toString();
75 prefixes[tabWidth] = ""; //$NON-NLS-1$