Skip to content

Commit

Permalink
Implemented Find-Replace Overlay.
Browse files Browse the repository at this point in the history
In response to issue #1090. Goals for this overlay are a simple
and modern UI/UX for finding/replacing in eclipse.

-- [Modern Find/Replace] Refactor FindReplaceDialog

The FindReplaceDialog's business-logic is now handled in the
FindReplacer.
The FindReplacer communicates using a FindReplaceStatus object which is
polled by FindReplaceDialog as needed and allows for displaying correct
messages in the Interface.

This Refactoring is required so that the business-logic can be reused in
the new FindReplace overlay, as proposed in issue #1090
  • Loading branch information
Wittmaxi committed Dec 8, 2023
1 parent 54e2bcd commit f975bc4
Show file tree
Hide file tree
Showing 36 changed files with 2,996 additions and 1,355 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*******************************************************************************
* Copyright (c) 2023 Vector Informatik GmbH and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Vector Informatik GmbH - initial API and implementation
*******************************************************************************/
package org.eclipse.ui.internal.findandreplace;

public class FindReplaceLogicFindAllStatus implements IFindReplaceLogicStatus {
private int selectCount;

public FindReplaceLogicFindAllStatus(int selectCount) {
if (selectCount <= 0) {
// invalid value - what to do? Throw an exception?! @HeikoKlare
}
this.selectCount = selectCount;
}

public int getSelectCount() {
return selectCount;
}

@Override
public <T> T visit(IFindReplaceLogicStatusVisitor<T> visitor) {
return visitor.visit(this);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*******************************************************************************
* Copyright (c) 2023 Vector Informatik GmbH and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Vector Informatik GmbH - initial API and implementation
*******************************************************************************/
package org.eclipse.ui.internal.findandreplace;

/**
* Avoid using this class. It is used as a glue to correctly map to the
* error-messages generated by RegEx-Errors which are directly displayed in
* plain text.
*
* Prefer using and extending {@link FindReplaceLogicStatus}
*/
public class FindReplaceLogicMessage implements IFindReplaceLogicStatus {

private String message;

public FindReplaceLogicMessage(String message) {
this.message = message;
}

public String getMessage() {
return message;
}

@Override
public <T> T visit(IFindReplaceLogicStatusVisitor<T> visitor) {
return visitor.visit(this);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*******************************************************************************
* Copyright (c) 2023 Vector Informatik GmbH and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Vector Informatik GmbH - initial API and implementation
*******************************************************************************/
package org.eclipse.ui.internal.findandreplace;

import org.eclipse.ui.internal.texteditor.NLSUtility;

public class FindReplaceLogicMessageGenerator implements IFindReplaceLogicStatusVisitor<String> {

@Override
public String visit(IFindReplaceLogicStatus status) {
return ""; //$NON-NLS-1$
}

@Override
public String visit(FindReplaceLogicReplaceAllStatus status) {
int replaceCount = status.getReplaceCount();
if (replaceCount == 1) {
return FindReplaceMessages.FindReplace_Status_replacement_label;
}
return NLSUtility.format(FindReplaceMessages.FindReplace_Status_replacements_label, replaceCount);
}

@Override
public String visit(FindReplaceLogicStatus status) {
FindReplaceLogicStatus.MessageCode messageCode = status.getMessageCode();
String message;
switch (messageCode) {
case NO_MATCH:
message = FindReplaceMessages.FindReplace_Status_noMatch_label;
break;
case WRAPPED:
message = FindReplaceMessages.FindReplace_Status_wrapped_label;
break;
case READONLY:
message = FindReplaceMessages.FindReplaceDialog_read_only;
break;
case NONE:
default:
message = ""; //$NON-NLS-1$
}

return message;
}

@Override
public String visit(FindReplaceLogicMessage status) {
return status.getMessage();
}

@Override
public String visit(FindReplaceLogicFindAllStatus status) {
int selectCount = status.getSelectCount();
if (selectCount == 1) {
return FindReplaceMessages.FindReplace_Status_selection_label;
}
return NLSUtility.format(FindReplaceMessages.FindReplace_Status_selections_label, selectCount);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*******************************************************************************
* Copyright (c) 2023 Vector Informatik GmbH and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Vector Informatik GmbH - initial API and implementation
*******************************************************************************/
package org.eclipse.ui.internal.findandreplace;

public class FindReplaceLogicReplaceAllStatus implements IFindReplaceLogicStatus {
private int replaceCount;

public FindReplaceLogicReplaceAllStatus(int replaceCount) {
this.replaceCount = replaceCount;
}

public int getReplaceCount() {
return replaceCount;
}

@Override
public <T> T visit(IFindReplaceLogicStatusVisitor<T> visitor) {
return visitor.visit(this);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*******************************************************************************
* Copyright (c) 2023 Vector Informatik GmbH and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Vector Informatik GmbH - initial API and implementation
*******************************************************************************/
package org.eclipse.ui.internal.findandreplace;

public class FindReplaceLogicStatus implements IFindReplaceLogicStatus {

public enum MessageCode {
NO_MATCH,
NONE, WRAPPED, READONLY,
}

private MessageCode messageCode;

public FindReplaceLogicStatus(MessageCode errorCode) {
this.messageCode = errorCode;
}

public MessageCode getMessageCode() {
return messageCode;
}

@Override
public <T> T visit(IFindReplaceLogicStatusVisitor<T> visitor) {
return visitor.visit(this);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*******************************************************************************
* Copyright (c) 2023 Vector Informatik GmbH and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Vector Informatik GmbH - initial API and implementation
*******************************************************************************/

package org.eclipse.ui.internal.findandreplace;

import org.eclipse.osgi.util.NLS;

final public class FindReplaceMessages extends NLS {

public static final String BUNDLE_NAME = FindReplaceMessages.class.getName();

private FindReplaceMessages() {
// Do not instantiate
}

static {
NLS.initializeMessages(BUNDLE_NAME, FindReplaceMessages.class);
}

public static String FindReplace_Status_replacement_label;
public static String FindReplace_Status_replacements_label;
public static String FindReplace_Status_noMatchWithValue_label;
public static String FindReplace_Status_wrapped_label;
public static String FindReplaceDialog_read_only;
public static String FindReplace_Status_selections_label;
public static String FindReplace_Status_selection_label;
public static String FindReplace_Status_noMatch_Label;
public static String FindReplace_Status_noMatch_label;
public static String FindNext_Status_noMatch_label;

// The "classic" Find/Replace-Dialog
public static String FindReplace_Dialog_Title;
public static String FindReplace_Find_label;
public static String FindReplace_Replace_label;
public static String FindReplace_Direction;
public static String FindReplace_ForwardRadioButton_label;
public static String FindReplace_BackwardRadioButton_label;
public static String FindReplace_Scope;
public static String FindReplace_GlobalRadioButton_label;
public static String FindReplace_SelectedRangeRadioButton_label;
public static String FindReplace_Options;
public static String FindReplace_CaseCheckBox_label;
public static String FindReplace_WrapCheckBox_label;
public static String FindReplace_WholeWordCheckBox_label;
public static String FindReplace_IncrementalCheckBox_label;
public static String FindReplace_RegExCheckbox_label;
public static String FindReplace_FindNextButton_label;
public static String FindReplace_ReplaceFindButton_label;
public static String FindReplace_ReplaceSelectionButton_label;
public static String FindReplace_ReplaceAllButton_label;
public static String FindReplace_SelectAllButton_label;
public static String FindReplace_CloseButton_label;


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
################################################################################
# Copyright (c) 2023 Vector Informatik GmbH and others_
#
# This program and the accompanying materials
# are made available under the terms of the Eclipse Public License 2_0
# which accompanies this distribution, and is available at
# https://www_eclipse_org/legal/epl-2_0/
#
# SPDX-License-Identifier: EPL-2_0
#
# Contributors:
# Vector Informatik GmbH - initial API and implementation
############################################################################

# FindReplace_Status_noMatch_label=String not found
FindReplace_Status_noMatchWithValue_label=String {0} not found
FindReplace_Status_replacement_label=1 match replaced
FindReplace_Status_replacements_label={0} matches replaced
FindReplace_Status_selection_label=1 match selected
FindReplace_Status_selections_label={0} matches selected
FindReplace_Status_wrapped_label=Wrapped search
FindReplace_Status_noMatch_label=String not found
FindNext_Status_noMatch_label=String {0} not found
FindReplaceDialog_read_only=Cannot replace. File is read-only.

# Messages for the "classic" Find-Replace-Dialog
FindReplace_Dialog_Title= Find/Replace
FindReplace_Find_label=&Find:
FindReplace_Replace_label=R&eplace with:
FindReplace_Direction=Direction
FindReplace_ForwardRadioButton_label=F&orward
FindReplace_BackwardRadioButton_label=&Backward
FindReplace_Scope=Scope
FindReplace_GlobalRadioButton_label=A&ll
FindReplace_SelectedRangeRadioButton_label=Selec&ted lines
FindReplace_Options=Options
FindReplace_CaseCheckBox_label=&Case sensitive
FindReplace_WrapCheckBox_label=Wra&p search
FindReplace_WholeWordCheckBox_label=&Whole word
FindReplace_IncrementalCheckBox_label=&Incremental
FindReplace_RegExCheckbox_label= Regular e&xpressions
FindReplace_FindNextButton_label=Fi&nd
FindReplace_ReplaceFindButton_label=Replace/Fin&d
FindReplace_ReplaceSelectionButton_label=&Replace
FindReplace_ReplaceAllButton_label=Replace &All
FindReplace_SelectAllButton_label=&Select All
FindReplace_CloseButton_label=Close
Loading

0 comments on commit f975bc4

Please sign in to comment.