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.2 2006-10-21 23:13:54 pombredanne 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 = "net.sourceforge.phpeclipse.ui.editor.tabWidth"; //$NON-NLS-1$
28 /** Preference key for inserting spaces rather than tabs. */
29 public static final String PREFERENCE_SPACES_FOR_TABS = "net.sourceforge.phpeclipse.ui.editor.spacesForTabs"; //$NON-NLS-1$
31 private IPreferenceStore store;
33 public DefaultSourceViewerConfiguration(IPreferenceStore store) {
38 * @see SourceViewerConfiguration#getIndentPrefixes(ISourceViewer, String)
40 public String[] getIndentPrefixes(ISourceViewer sourceViewer,
42 // prefix[0] is either '\t' or ' ' x tabWidth, depending on useSpaces
44 int tabWidth = store.getInt(PREFERENCE_TAB_WIDTH);
45 boolean useSpaces = store.getBoolean(PREFERENCE_SPACES_FOR_TABS);
47 String[] prefixes = new String[tabWidth + 1];
49 for (int i = 0; i <= tabWidth; i++) {
50 StringBuffer prefix = new StringBuffer(tabWidth - 1);
53 for (int j = 0; j + i < tabWidth; j++) {
61 for (int j = 0; j < i; j++) {
70 prefixes[i] = prefix.toString();
73 prefixes[tabWidth] = ""; //$NON-NLS-1$