View | Details | Raw Unified | Return to bug 25961
Collapse All | Expand All

(-)AbstractTextEditor.java (-19 / +32 lines)
Lines 1124-1132 Link Here
1124
	/** The error message shown in the status line in case of failed information look up. */
1124
	/** The error message shown in the status line in case of failed information look up. */
1125
	protected final String fErrorLabel= EditorMessages.getString("Editor.statusline.error.label"); //$NON-NLS-1$
1125
	protected final String fErrorLabel= EditorMessages.getString("Editor.statusline.error.label"); //$NON-NLS-1$
1126
	private final String fPositionLabelPattern= EditorMessages.getString("Editor.statusline.position.pattern"); //$NON-NLS-1$
1126
	private final String fPositionLabelPattern= EditorMessages.getString("Editor.statusline.position.pattern"); //$NON-NLS-1$
1127
	private final String fSelectionLabelPattern= EditorMessages.getString("Editor.statusline.selection.pattern");
1128
	private final PositionLabelValue fNumOfLinesLabel= new PositionLabelValue();
1127
	private final PositionLabelValue fLineLabel= new PositionLabelValue();
1129
	private final PositionLabelValue fLineLabel= new PositionLabelValue();
1128
	private final PositionLabelValue fColumnLabel= new PositionLabelValue();
1130
	private final PositionLabelValue fColumnLabel= new PositionLabelValue();
1129
	private final Object[] fPositionLabelPatternArguments= new Object[] { fLineLabel, fColumnLabel };
1131
	private final Object[] fPositionLabelPatternArguments= new Object[] { fLineLabel, fColumnLabel, fNumOfLinesLabel };
1130
1132
1131
	
1133
	
1132
	
1134
	
Lines 3721-3745 Link Here
3721
		if (document == null)
3723
		if (document == null)
3722
			return fErrorLabel;
3724
			return fErrorLabel;
3723
	
3725
	
3724
		try {
3726
		ITextSelection selection = (ITextSelection) getSelectionProvider().getSelection();
3725
			
3727
		
3726
			int line= document.getLineOfOffset(caret);
3728
		if (selection == null || selection.getLength() == 0) {
3729
			try {
3730
				int line= document.getLineOfOffset(caret);
3731
	
3732
				int lineOffset= document.getLineOffset(line);
3733
				int tabWidth= styledText.getTabs();
3734
				int column= 0;
3735
				for (int i= lineOffset; i < caret; i++)
3736
					if ('\t' == document.getChar(i))
3737
						column += tabWidth - (column % tabWidth);
3738
					else
3739
						column++;
3740
						
3741
				fLineLabel.fValue= line + 1;
3742
				fColumnLabel.fValue= column + 1;
3743
				return MessageFormat.format(fPositionLabelPattern, fPositionLabelPatternArguments);
3744
			} catch (BadLocationException x) {
3745
				return fErrorLabel;
3746
			}
3747
		} else {
3748
			int start= selection.getStartLine();
3749
			int end= selection.getEndLine();
3727
3750
3728
			int lineOffset= document.getLineOffset(line);
3751
			fLineLabel.fValue= start  + 1;
3729
			int tabWidth= styledText.getTabs();
3752
			fColumnLabel.fValue= end + 1;
3730
			int column= 0;
3753
			fNumOfLinesLabel.fValue= end - start + 1;
3731
			for (int i= lineOffset; i < caret; i++)
3754
3732
				if ('\t' == document.getChar(i))
3755
			return MessageFormat.format(fSelectionLabelPattern, fPositionLabelPatternArguments);			
3733
					column += tabWidth - (column % tabWidth);
3734
				else
3735
					column++;
3736
					
3737
			fLineLabel.fValue= line + 1;
3738
			fColumnLabel.fValue= column + 1;
3739
			return MessageFormat.format(fPositionLabelPattern, fPositionLabelPatternArguments);
3740
			
3741
		} catch (BadLocationException x) {
3742
			return fErrorLabel;
3743
		}
3756
		}
3744
	}
3757
	}
3745
	
3758
	
(-)BasicTextEditorActionContributor.java (-2 / +12 lines)
Lines 73-79 Link Here
73
		ITextEditorActionConstants.STATUS_CATEGORY_INPUT_MODE,
73
		ITextEditorActionConstants.STATUS_CATEGORY_INPUT_MODE,
74
		ITextEditorActionConstants.STATUS_CATEGORY_INPUT_POSITION
74
		ITextEditorActionConstants.STATUS_CATEGORY_INPUT_POSITION
75
	};
75
	};
76
	
76
77
	/** 
78
	 * The sizes of the status fields to be set to the editor
79
	 * @since 2.1
80
	 */
81
	private final static int[] STATUSFIELDS_SIZES= {
82
		9,
83
		9,
84
		14
85
	};
86
		
77
	/** The active editor part */
87
	/** The active editor part */
78
	private IEditorPart fActiveEditorPart;
88
	private IEditorPart fActiveEditorPart;
79
	/** 
89
	/** 
Lines 121-127 Link Here
121
		
131
		
122
		fStatusFields= new HashMap(3);
132
		fStatusFields= new HashMap(3);
123
		for (int i= 0; i < STATUSFIELDS.length; i++)
133
		for (int i= 0; i < STATUSFIELDS.length; i++)
124
			fStatusFields.put(STATUSFIELDS[i], new StatusLineContributionItem(STATUSFIELDS[i]));
134
			fStatusFields.put(STATUSFIELDS[i], new StatusLineContributionItem(STATUSFIELDS[i], STATUSFIELDS_SIZES[i]));
125
	}
135
	}
126
	
136
	
127
	/**
137
	/**
(-)EditorMessages.properties (+1 lines)
Lines 239-244 Link Here
239
Editor.statusline.mode.insert.label=Insert
239
Editor.statusline.mode.insert.label=Insert
240
Editor.statusline.mode.overwrite.label=Overwrite
240
Editor.statusline.mode.overwrite.label=Overwrite
241
Editor.statusline.position.pattern={0} : {1}
241
Editor.statusline.position.pattern={0} : {1}
242
Editor.statusline.selection.pattern={0} : {1} - {2} line(s)
242
Editor.statusline.error.label=?
243
Editor.statusline.error.label=?
243
244
244
## Others ##
245
## Others ##
(-)StatusLineContributionItem.java (-3 / +31 lines)
Lines 44-56 Link Here
44
		 * Creates a new status line label.
44
		 * Creates a new status line label.
45
		 * @param parent parent control
45
		 * @param parent parent control
46
		 * @param style the swt style bits
46
		 * @param style the swt style bits
47
		 * @param numOfChars the maximum number of characters this label can
48
		 * show
47
		 */
49
		 */
48
		public StatusLineLabel(Composite parent, int style) {
50
		public StatusLineLabel(Composite parent, int style, int numOfChars) {
49
			super(parent, style);
51
			super(parent, style);
50
			
52
			
53
			char[] chs = new char[numOfChars];
54
			
55
			for (int i = numOfChars - 1; i >= 0; i--)
56
				chs[i] = 'M';
57
				 
51
			GC gc= new GC(parent);
58
			GC gc= new GC(parent);
52
			gc.setFont(parent.getFont());
59
			gc.setFont(parent.getFont());
53
			Point extent= gc.textExtent("MMMMMMMMM"); //$NON-NLS-1$
60
			Point extent= gc.textExtent(new String(chs)); //$NON-NLS-1$
54
			gc.dispose();
61
			gc.dispose();
55
			
62
			
56
			fFixedSize= new Point(extent.x + INDENT * 2, 10);
63
			fFixedSize= new Point(extent.x + INDENT * 2, 10);
Lines 71-83 Link Here
71
	/** The status line label widget */
78
	/** The status line label widget */
72
	private StatusLineLabel fLabel;
79
	private StatusLineLabel fLabel;
73
	
80
	
81
	/** The number of characters this status line contribution will show. */ 
82
	private int fNumOfChars;
83
	
84
	/** Default: 9 characters will be shown. */
85
	private static int DEFAULT_NUM_OF_CHARS = 9;
86
74
	/**
87
	/**
75
	 * Creates a new item with the given id.
88
	 * Creates a new item with the given id.
76
	 * 
89
	 * 
77
	 * @param id the item's id
90
	 * @param id the item's id
78
	 */
91
	 */
79
	public StatusLineContributionItem(String id) {
92
	public StatusLineContributionItem(String id) {
93
		this(id, DEFAULT_NUM_OF_CHARS);
94
	}
95
		
96
	/**
97
	 * Creates a new item with the given id and number of characters to be
98
	 * shown.
99
	 * 
100
	 * @param id the item's id
101
	 * @param numOfChars the maximum number of characters this lable can show
102
	 * @since 2.1
103
	 * 
104
	 */
105
	public StatusLineContributionItem(String id, int numOfChars) {
80
		super(id);
106
		super(id);
107
		
108
		fNumOfChars= (numOfChars < 1) ? DEFAULT_NUM_OF_CHARS : numOfChars;
81
	}
109
	}
82
	
110
	
83
	/*
111
	/*
Lines 104-110 Link Here
104
	 * @see IContributionItem#fill(Composite)
132
	 * @see IContributionItem#fill(Composite)
105
	 */
133
	 */
106
	public void fill(Composite parent) {
134
	public void fill(Composite parent) {
107
		fLabel= new StatusLineLabel(parent, SWT.SHADOW_IN);
135
		fLabel= new StatusLineLabel(parent, SWT.SHADOW_IN, fNumOfChars);
108
		fLabel.setData(this);
136
		fLabel.setData(this);
109
		
137
		
110
		if (fText != null)
138
		if (fText != null)

Return to bug 25961