Skip to content

Commit

Permalink
#76 text data of emoticons and images, added into search text scope
Browse files Browse the repository at this point in the history
  • Loading branch information
raydac committed Oct 24, 2020
1 parent 97629e6 commit 80653a4
Show file tree
Hide file tree
Showing 15 changed files with 444 additions and 135 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Initially I developed plugin for NetBeans IDE but because in companies, where I
# Changelog
__1.4.10 (SNAPSHOT)__
- ALL: decreased topic dragging start sensibility [#77](https://github.com/raydac/netbeans-mmd-plugin/issues/77)
- ALL: emoticons and images included into search scope by their names [#76](https://github.com/raydac/netbeans-mmd-plugin/issues/76)
- SR: fixed file rename [#74](https://github.com/raydac/netbeans-mmd-plugin/issues/74)
- SR: embedded JDK version updated to 11.0.9+11
- SR: embedded PlantUml updated to 1.2020.19
Expand Down
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
__1.4.10 (SNAPSHOT)__
- ALL: decreased topic dragging start sensibility [#77](https://github.com/raydac/netbeans-mmd-plugin/issues/77)
- ALL: emoticons and images included into search scope by their names [#76](https://github.com/raydac/netbeans-mmd-plugin/issues/76)
- SR: fixed file rename [#74](https://github.com/raydac/netbeans-mmd-plugin/issues/74)
- SR: embedded JDK version updated to 11.0.9+11
- SR: embedded PlantUml updated to 1.2020.19
Expand Down
2 changes: 1 addition & 1 deletion mind-map/idea-mindmap/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ intellij {
updateSinceUntilBuild false
}

def mindMapModelVersion = project.hasProperty('mm_model_version') ? project.getProperty('mm_model_version') : "1.3.0"
def mindMapModelVersion = project.hasProperty('mm_model_version') ? project.getProperty('mm_model_version') : "1.4.10-SNAPSHOT"
def mindMapCommonVersion = project.hasProperty('mm_ide_common_version') ? project.getProperty('mm_ide_common_version') : project.version
def mindMapPanelVersion = project.hasProperty('mm_panel_version') ? project.getProperty('mm_panel_version') : project.version
def commonsIoVersion = project.hasProperty('commonsio_version') ? project.getProperty('commonsio_version') : "2.5"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@
import com.igormaznitsa.mindmap.model.MMapURI;
import com.igormaznitsa.mindmap.model.MindMap;
import com.igormaznitsa.mindmap.model.Topic;
import com.igormaznitsa.mindmap.model.TopicFinder;
import com.igormaznitsa.mindmap.model.logger.Logger;
import com.igormaznitsa.mindmap.model.logger.LoggerFactory;
import com.igormaznitsa.mindmap.plugins.MindMapPluginRegistry;
import com.igormaznitsa.mindmap.swing.panel.DialogProvider;
import com.igormaznitsa.mindmap.swing.panel.MMDTopicsTransferable;
import com.igormaznitsa.mindmap.swing.panel.MindMapListener;
Expand Down Expand Up @@ -77,7 +79,6 @@
import com.intellij.openapi.fileEditor.FileEditorLocation;
import com.intellij.openapi.fileEditor.FileEditorState;
import com.intellij.openapi.fileEditor.FileEditorStateLevel;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.vfs.LocalFileSystem;
Expand Down Expand Up @@ -145,6 +146,9 @@ public class MindMapDocumentEditor implements AdjustmentListener, DocumentsEdito
private final FindTextPanel findTextPanel;
private boolean dragAcceptableType = false;

private static final Set<TopicFinder> TOPIC_FINDERS = MindMapPluginRegistry.getInstance()
.findAllTopicFinders();

public MindMapDocumentEditor(
final Project project,
final VirtualFile file
Expand Down Expand Up @@ -464,9 +468,11 @@ public boolean findNext(@Nonnull final Pattern pattern, @Nonnull final FindTextS
}
final boolean inTopicText = provider.toSearchIn(FindTextScopeProvider.SearchTextScope.IN_TOPIC_TEXT);

Topic found = this.mindMapPanel.getModel().findNext(projectBaseFolder, startTopic, pattern, inTopicText, extras);
Topic found = this.mindMapPanel.getModel()
.findNext(projectBaseFolder, startTopic, pattern, inTopicText, extras, TOPIC_FINDERS);
if (found == null && startTopic != null) {
found = this.mindMapPanel.getModel().findNext(projectBaseFolder, null, pattern, inTopicText, extras);
found = this.mindMapPanel.getModel()
.findNext(projectBaseFolder, null, pattern, inTopicText, extras, TOPIC_FINDERS);
}

if (found != null) {
Expand Down Expand Up @@ -499,9 +505,11 @@ public boolean findPrev(@Nonnull final Pattern pattern, @Nonnull final FindTextS
}
final boolean inTopicText = provider.toSearchIn(FindTextScopeProvider.SearchTextScope.IN_TOPIC_TEXT);

Topic found = this.mindMapPanel.getModel().findPrev(projectBaseFolder, startTopic, pattern, inTopicText, extras);
Topic found = this.mindMapPanel.getModel()
.findPrev(projectBaseFolder, startTopic, pattern, inTopicText, extras, TOPIC_FINDERS);
if (found == null && startTopic != null) {
found = this.mindMapPanel.getModel().findPrev(projectBaseFolder, null, pattern, inTopicText, extras);
found = this.mindMapPanel.getModel()
.findPrev(projectBaseFolder, null, pattern, inTopicText, extras, TOPIC_FINDERS);
}

if (found != null) {
Expand Down
3 changes: 1 addition & 2 deletions mind-map/mind-map-model/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@

<groupId>com.igormaznitsa</groupId>
<artifactId>mind-map-model</artifactId>
<version>1.3.0</version>
<!--<version>${mindmap.model.version}</version>-->
<version>1.4.10-SNAPSHOT</version>
<packaging>jar</packaging>

<name>NB Mind Map model</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,14 @@ public final class MindMap implements Serializable, Constants, Iterable<Topic> {
private static final long serialVersionUID = 5929181596778047354L;
private static final Logger LOGGER = LoggerFactory.getLogger(MindMap.class);
private static final Pattern PATTERN_ATTRIBUTES = Pattern.compile("^\\s*\\>\\s(.+)$"); //NOI18N
private static final Pattern PATTERN_ATTRIBUTE = Pattern.compile("[,]?\\s*([\\S]+?)\\s*=\\s*(\\`+)(.*?)\\2"); //NOI18N
private static final Pattern PATTERN_ATTRIBUTE =
Pattern.compile("[,]?\\s*([\\S]+?)\\s*=\\s*(\\`+)(.*?)\\2"); //NOI18N
private static final String GENERATOR_VERSION_NAME = "__version__"; //NOI18N
private final transient Lock locker = new ReentrantLock();
private final Map<String, String> attributes = new TreeMap<String, String>(ModelUtils.STRING_COMPARATOR);
private final transient List<MindMapModelEventListener> modelEventListeners = new CopyOnWriteArrayList<MindMapModelEventListener>();
private final Map<String, String> attributes =
new TreeMap<String, String>(ModelUtils.STRING_COMPARATOR);
private final transient List<MindMapModelEventListener> modelEventListeners =
new CopyOnWriteArrayList<MindMapModelEventListener>();

@Nullable
private Topic root;
Expand Down Expand Up @@ -84,7 +87,8 @@ public MindMap(@Nonnull final Reader reader) throws IOException {
while (process) {
final int oldLexerPosition = lexer.getCurrentPosition().getOffset();
lexer.advance();
final boolean lexerPositionWasNotChanged = oldLexerPosition == lexer.getCurrentPosition().getOffset();
final boolean lexerPositionWasNotChanged =
oldLexerPosition == lexer.getCurrentPosition().getOffset();

final MindMapLexer.TokenType token = lexer.getTokenType();
if (token == null || lexerPositionWasNotChanged) {
Expand All @@ -111,7 +115,8 @@ public MindMap(@Nonnull final Reader reader) throws IOException {
this.attributes.put(GENERATOR_VERSION_NAME, FORMAT_VERSION);
}

static boolean fillMapByAttributes(@Nonnull final String line, @Nonnull final Map<String, String> map) {
static boolean fillMapByAttributes(@Nonnull final String line,
@Nonnull final Map<String, String> map) {
final Matcher attrmatcher = PATTERN_ATTRIBUTES.matcher(line);
if (attrmatcher.find()) {
final Matcher attrParser = PATTERN_ATTRIBUTE.matcher(attrmatcher.group(1));
Expand Down Expand Up @@ -145,11 +150,32 @@ public void clear() {
}

@Nullable
public Topic findNext(@Nullable final File baseFolder, @Nullable final Topic start, @Nonnull final Pattern pattern, final boolean findInTopicText, @Nullable final Set<Extra.ExtraType> extrasToFind) {
public Topic findNext(@Nullable final File baseFolder, @Nullable final Topic start,
@Nonnull final Pattern pattern, final boolean findInTopicText,
@Nullable final Set<Extra.ExtraType> extrasToFind) {
return this.findNext(baseFolder, start, pattern, findInTopicText, extrasToFind, null);
}

@Nullable
public Topic findNext(
@Nullable final File baseFolder,
@Nullable final Topic start,
@Nonnull final Pattern pattern,
final boolean findInTopicText,
@Nullable final Set<Extra.ExtraType> extrasToFind,
@Nullable final Set<TopicFinder> topicFinders
) {
if (start != null && start.getMap() != this) {
throw new IllegalArgumentException("Topic doesn't belong to the mind map");
}

final boolean findPluginNote = (extrasToFind != null && !extrasToFind.isEmpty())
&& (topicFinders != null && !topicFinders.isEmpty())
&& extrasToFind.contains(Extra.ExtraType.NOTE);
final boolean findPluginFile = (extrasToFind != null && !extrasToFind.isEmpty())
&& (topicFinders != null && !topicFinders.isEmpty())
&& extrasToFind.contains(Extra.ExtraType.FILE);

Topic result = null;

this.locker.lock();
Expand All @@ -159,6 +185,15 @@ public Topic findNext(@Nullable final File baseFolder, @Nullable final Topic sta
if (startFound) {
if (t.containsPattern(baseFolder, pattern, findInTopicText, extrasToFind)) {
result = t;
} else if (topicFinders != null) {
for (TopicFinder f : topicFinders) {
if (f.doesTopicContentMatches(t, baseFolder, pattern, extrasToFind)) {
result = t;
break;
}
}
}
if (result != null) {
break;
}
} else if (t == start) {
Expand All @@ -173,7 +208,21 @@ public Topic findNext(@Nullable final File baseFolder, @Nullable final Topic sta
}

@Nullable
public Topic findPrev(@Nullable final File baseFolder, @Nullable final Topic start, @Nonnull final Pattern pattern, final boolean findInTopicText, @Nullable final Set<Extra.ExtraType> extrasForSearch) {
public Topic findPrev(@Nullable final File baseFolder, @Nullable final Topic start,
@Nonnull final Pattern pattern, final boolean findInTopicText,
@Nullable final Set<Extra.ExtraType> extrasToFind) {
return this.findPrev(baseFolder, start, pattern, findInTopicText, extrasToFind, null);
}

@Nullable
public Topic findPrev(
@Nullable final File baseFolder,
@Nullable final Topic start,
@Nonnull final Pattern pattern,
final boolean findInTopicText,
@Nullable final Set<Extra.ExtraType> extrasToFind,
@Nullable final Set<TopicFinder> topicFinders
) {
if (start != null && start.getMap() != this) {
throw new IllegalArgumentException("Topic doesn't belong to the mind map");
}
Expand All @@ -188,11 +237,17 @@ public Topic findPrev(@Nullable final File baseFolder, @Nullable final Topic sta
throw new IllegalArgumentException("It looks like that topic doesn't belong to the mind map");
}
if (startIndex > 0) {
while (startIndex > 0) {
while (startIndex > 0 && result == null) {
final Topic candidate = plain.get(--startIndex);
if (candidate.containsPattern(baseFolder, pattern, findInTopicText, extrasForSearch)) {
if (candidate.containsPattern(baseFolder, pattern, findInTopicText, extrasToFind)) {
result = candidate;
break;
} else if (topicFinders != null) {
for (TopicFinder f : topicFinders) {
if (f.doesTopicContentMatches(candidate, baseFolder, pattern, extrasToFind)) {
result = candidate;
break;
}
}
}
}
}
Expand Down Expand Up @@ -270,14 +325,16 @@ public boolean isEmpty() {

private void fireModelChanged() {
final Topic rootTopic = this.root;
final MindMapModelEvent evt = new MindMapModelEvent(this, rootTopic == null ? null : rootTopic.getPath());
final MindMapModelEvent evt =
new MindMapModelEvent(this, rootTopic == null ? null : rootTopic.getPath());
for (final MindMapModelEventListener l : this.modelEventListeners) {
l.onMindMapStructureChanged(evt);
}
}

private void fireTopicChanged(@Nullable final Topic topic) {
final MindMapModelEvent evt = new MindMapModelEvent(this, topic == null ? null : topic.getPath());
final MindMapModelEvent evt =
new MindMapModelEvent(this, topic == null ? null : topic.getPath());
for (final MindMapModelEventListener l : this.modelEventListeners) {
l.onMindMapNodesChanged(evt);
}
Expand Down Expand Up @@ -345,7 +402,8 @@ public Topic findForPositionPath(@Nullable final int[] positions) {

@Nonnull
@MustNotContainNull
public List<Topic> removeNonExistingTopics(@Nonnull @MustNotContainNull final List<Topic> origList) {
public List<Topic> removeNonExistingTopics(
@Nonnull @MustNotContainNull final List<Topic> origList) {
final List<Topic> result = new ArrayList<Topic>();
final Topic rootTopic = this.root;
if (rootTopic != null) {
Expand Down Expand Up @@ -412,7 +470,8 @@ public <T extends Writer> T write(@Nonnull final T out) throws IOException {
out.append("Mind Map generated by NB MindMap plugin").append(NEXT_PARAGRAPH); //NOI18N
this.attributes.put(GENERATOR_VERSION_NAME, FORMAT_VERSION);
if (!this.attributes.isEmpty()) {
out.append("> ").append(MindMap.allAttributesAsString(this.attributes)).append(NEXT_LINE); //NOI18N
out.append("> ").append(MindMap.allAttributesAsString(this.attributes))
.append(NEXT_LINE); //NOI18N
}
out.append("---").append(NEXT_LINE); //NOI18N
final Topic rootTopic = this.root;
Expand Down Expand Up @@ -516,7 +575,9 @@ public List<Topic> findAllTopicsForExtraType(@Nonnull final Extra.ExtraType type
return result;
}

private void _findAllTopicsForExtraType(@Nonnull final Topic topic, @Nonnull final Extra.ExtraType type, @Nonnull @MustNotContainNull final List<Topic> result) {
private void _findAllTopicsForExtraType(@Nonnull final Topic topic,
@Nonnull final Extra.ExtraType type,
@Nonnull @MustNotContainNull final List<Topic> result) {
if (topic.getExtras().containsKey(type)) {
result.add(topic);
}
Expand All @@ -538,7 +599,8 @@ public boolean isLeaf(@Nonnull final Topic node) {
return !node.hasChildren();
}

public void valueForPathChanged(@Nonnull @MustNotContainNull final Topic[] path, @Nullable final String newValue) {
public void valueForPathChanged(@Nonnull @MustNotContainNull final Topic[] path,
@Nullable final String newValue) {
if (path.length > 0) {
final Topic target = path[path.length - 1];
target.setText(GetUtils.ensureNonNull(newValue, ""));
Expand Down Expand Up @@ -589,7 +651,9 @@ public boolean deleteAllLinksToFile(@Nonnull final File baseFolder, @Nonnull fin
return changed;
}

public boolean replaceAllLinksToFile(@Nonnull final File baseFolder, @Nonnull final MMapURI oldFile, @Nonnull final MMapURI newFile) {
public boolean replaceAllLinksToFile(@Nonnull final File baseFolder,
@Nonnull final MMapURI oldFile,
@Nonnull final MMapURI newFile) {
boolean changed = false;
final Topic rootTopic = this.root;
if (rootTopic != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.igormaznitsa.mindmap.model;

import java.io.File;
import java.util.Set;
import java.util.regex.Pattern;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public interface TopicFinder {
/**
* Check that topic contains content matches with pattern.
*
* @param topic topic to be checked
* @param baseFolder base folder for the project
* @param pattern pattern to find
* @param extraTypes types of content
* @return true if text found, false otherwise
* @since 1.4.10
*/
boolean doesTopicContentMatches(@Nonnull Topic topic, @Nullable File baseFolder,
@Nonnull Pattern pattern,
@Nullable Set<Extra.ExtraType> extraTypes);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@


import com.igormaznitsa.meta.annotation.MustNotContainNull;
import com.igormaznitsa.mindmap.model.TopicFinder;
import com.igormaznitsa.mindmap.model.logger.Logger;
import com.igormaznitsa.mindmap.model.logger.LoggerFactory;
import com.igormaznitsa.mindmap.plugins.api.AbstractExporter;
Expand Down Expand Up @@ -61,9 +62,11 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.concurrent.ThreadSafe;
Expand All @@ -74,7 +77,8 @@ public final class MindMapPluginRegistry implements Iterable<MindMapPlugin> {
private static final Logger LOGGER = LoggerFactory.getLogger(MindMapPluginRegistry.class);
private static final MindMapPluginRegistry INSTANCE = new MindMapPluginRegistry();
private final List<MindMapPlugin> pluginList = new ArrayList<MindMapPlugin>();
private final Map<Class<? extends MindMapPlugin>, List<? extends MindMapPlugin>> FIND_CACHE = new HashMap<Class<? extends MindMapPlugin>, List<? extends MindMapPlugin>>();
private final Map<Class<? extends MindMapPlugin>, List<? extends MindMapPlugin>> FIND_CACHE =
new HashMap<Class<? extends MindMapPlugin>, List<? extends MindMapPlugin>>();

private MindMapPluginRegistry() {
registerPlugin(new FreeMindExporter());
Expand Down Expand Up @@ -119,6 +123,18 @@ private MindMapPluginRegistry() {
registerPlugin(new ImageVisualAttributePlugin());
}

@Nonnull
public Set<TopicFinder> findAllTopicFinders() {
final Set<TopicFinder> result = new HashSet<>();
for (final MindMapPlugin p : this.pluginList) {
if (p instanceof TopicFinder) {
result.add((TopicFinder) p);
}
}

return result;
}

@Nonnull
public static MindMapPluginRegistry getInstance() {
return INSTANCE;
Expand All @@ -139,7 +155,8 @@ public void unregisterPluginForClass(@Nonnull final Class<? extends MindMapPlugi
while (iterator.hasNext()) {
final MindMapPlugin plugin = iterator.next();
if (pluginClass.isAssignableFrom(plugin.getClass())) {
LOGGER.info("Unregistered plugin " + plugin.getClass().getName() + " for class " + pluginClass.getName());
LOGGER.info("Unregistered plugin " + plugin.getClass().getName() + " for class " +
pluginClass.getName());
iterator.remove();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@

package com.igormaznitsa.mindmap.plugins.api;

import com.igormaznitsa.mindmap.model.TopicFinder;
import javax.annotation.Nonnull;

/**
* Interface for plug-ins processing attributes of model topics.
*
* @since 1.2
*/
public interface AttributePlugin extends MindMapPlugin {
public interface AttributePlugin extends MindMapPlugin, TopicFinder {

/**
* Attribute name which can be returned if plug-in doesn't process attributes.
Expand Down
Loading

0 comments on commit 80653a4

Please sign in to comment.