Skip to content

Commit

Permalink
Merge pull request #35 from SeeSharpSoft/master
Browse files Browse the repository at this point in the history
Release 1.4.1
  • Loading branch information
SeeSharpSoft authored Aug 20, 2019
2 parents 5f2b993 + e1b9ab6 commit b52425d
Show file tree
Hide file tree
Showing 11 changed files with 227 additions and 74 deletions.
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

group 'net.seesharpsoft.intellij.plugins'
version '1.4.0'
version '1.4.1'

sourceCompatibility = 1.8

Expand All @@ -29,6 +29,8 @@ patchPluginXml {
changeNotes """
<pre style="font-family: sans-serif">
[NEW] Editor tab handling reworked
[NEW] Preview tab title pattern customization
[NEW] Option to color the file preview tab #12
[NEW] Keep scroll and cursor position of already previewed files #13
[FIX] Show file/class Structure details while in preview #25
[FIX] Typing in a file to open file in Preview in full Editor feature is a little off #27
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package net.seesharpsoft.intellij.plugins.filepreview;

import com.intellij.openapi.editor.event.DocumentEvent;
import com.intellij.openapi.editor.event.DocumentListener;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;

public class PreviewDocumentListener implements DocumentListener {
protected final Project myProject;

public PreviewDocumentListener(Project project) {
myProject = project;
}

@Override
public void documentChanged(@NotNull DocumentEvent event) {
final VirtualFile file = FileDocumentManager.getInstance().getFile(event.getDocument());
PreviewUtil.disposePreview(myProject, file);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package net.seesharpsoft.intellij.plugins.filepreview;

import com.intellij.openapi.fileEditor.impl.EditorTabColorProvider;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.awt.*;

public class PreviewEditorTabColorProvider implements EditorTabColorProvider {
@Nullable
@Override
public Color getEditorTabColor(@NotNull Project project, @NotNull VirtualFile file) {
if (PreviewUtil.isPreviewed(file)) {
return PreviewSettings.getInstance().getPreviewTabColor();
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,11 @@
import org.jetbrains.annotations.Nullable;

public class PreviewEditorTabTitleProvider implements EditorTabTitleProvider {

public static final String NAME_PREFIX = "<<";
public static final String NAME_SUFFIX = ">>";

@Nullable
@Override
public String getEditorTabTitle(@NotNull Project project, @NotNull VirtualFile file) {
String previewVirtualFile = file.getUserData(PreviewProjectHandler.PREVIEW_VIRTUAL_FILE_KEY);
if (previewVirtualFile != null) {
return String.format("%s%s%s", NAME_PREFIX, file.getName(), NAME_SUFFIX);
if (PreviewUtil.isPreviewed(file)) {
return String.format(PreviewSettings.getInstance().getPreviewTabTitlePattern(), file.getName());
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void mouseClicked(MouseEvent e) {
super.mouseClicked(e);

if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) {
consumeSelectedFile(myProjectViewPane.getTree(), selectedFile -> PreviewUtil.disposePreview(selectedFile));
consumeSelectedFile(myProjectViewPane.getTree(), selectedFile -> PreviewUtil.disposePreview(myProject, selectedFile));
}
}
};
Expand All @@ -90,7 +90,7 @@ public void fileOpened(@NotNull FileEditorManager source, @NotNull VirtualFile f

@Override
public void fileClosed(@NotNull FileEditorManager source, @NotNull VirtualFile file) {
PreviewUtil.disposePreview(file);
PreviewUtil.disposePreview(myProject, file);

if (PreviewSettings.getInstance().isProjectViewFocusSupport()) {
invokeSafe(() -> myProjectViewPane.getTree().grabFocus());
Expand Down Expand Up @@ -189,7 +189,7 @@ public void openPreviewOrEditor(VirtualFile file) {
}
final FileEditorManager fileEditorManager = FileEditorManager.getInstance(myProject);
if (!fileEditorManager.isFileOpen(file)) {
PreviewUtil.preparePreview(file);
PreviewUtil.preparePreview(myProject, file);
}
invokeSafeAndWait(() -> fileEditorManager.openFile(file, false));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private static class PreviewNavigatable implements Navigatable {

@Override
public void navigate(boolean requestFocus) {
PreviewUtil.disposePreview(myDelegate.getFile());
PreviewUtil.disposePreview(myDelegate.getProject(), myDelegate.getFile());
myDelegate.navigate(requestFocus);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.intellij.openapi.components.Storage;
import org.jetbrains.annotations.NotNull;

import java.awt.*;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;

Expand All @@ -32,6 +33,8 @@ static final class OptionSet {
public boolean OPEN_EDITOR_ON_EDIT_PREVIEW = true;
public PreviewBehavior PREVIEW_BEHAVIOR = PreviewBehavior.PREVIEW_BY_DEFAULT;
public boolean PROJECT_VIEW_TOGGLE_ONE_CLICK = true;
public String PREVIEW_TAB_TITLE_PATTERN = "<<%s>>";
public String PREVIEW_TAB_COLOR;
}

private OptionSet myOptions = new OptionSet();
Expand Down Expand Up @@ -123,4 +126,25 @@ public void setProjectViewToggleOneClick(boolean projectViewToggleOneClick) {
getState().PROJECT_VIEW_TOGGLE_ONE_CLICK = projectViewToggleOneClick;
myPropertyChangeSupport.firePropertyChange("ProjectViewToggleOneClick", oldValue, projectViewToggleOneClick);
}

public Color getPreviewTabColor() {
String color = getState().PREVIEW_TAB_COLOR;
try {
return color == null || color.isEmpty() ? null : Color.decode(getState().PREVIEW_TAB_COLOR);
} catch (NumberFormatException exc) {
return null;
}
}

public void setPreviewTabColor(Color color) {
getState().PREVIEW_TAB_COLOR = color == null ? "" : "" + color.getRGB();
}

public String getPreviewTabTitlePattern() {
return getState().PREVIEW_TAB_TITLE_PATTERN;
}

public void setPreviewTabTitlePattern(String titlePattern) {
getState().PREVIEW_TAB_TITLE_PATTERN = titlePattern;
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="net.seesharpsoft.intellij.plugins.filepreview.PreviewSettingsEditor">
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="941" height="400"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="e13a8" layout-manager="GridLayoutManager" row-count="7" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="e13a8" layout-manager="GridLayoutManager" row-count="4" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
Expand All @@ -18,30 +18,6 @@
</properties>
<border type="line" title="Project View"/>
<children>
<component id="8abe3" class="javax.swing.JCheckBox" binding="cbClosePreviewOnEmptySelection">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Close Preview Editor tab if no file is selected (e.g. directory or structure node selected)"/>
</properties>
</component>
<component id="4863d" class="javax.swing.JCheckBox" binding="cbKeyListenerEnabled">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Enable quick navigation key events"/>
</properties>
</component>
<component id="743f2" class="javax.swing.JCheckBox" binding="cbProjectViewFocusSupport">
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Focus Project View after opening/closing file editor"/>
</properties>
</component>
<grid id="daeed" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
Expand Down Expand Up @@ -76,25 +52,25 @@
</hspacer>
</children>
</grid>
<component id="e2cc1" class="javax.swing.JCheckBox" binding="cbOpenEditorOnEditPreview">
<component id="4863d" class="javax.swing.JCheckBox" binding="cbKeyListenerEnabled">
<constraints>
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Open actual editor when editing preview (Preview Editor tab gets closed)"/>
<text value="Enable quick navigation key events"/>
</properties>
</component>
<component id="a5105" class="javax.swing.JCheckBox" binding="cbPreviewClosedOnTabChange">
<component id="743f2" class="javax.swing.JCheckBox" binding="cbProjectViewFocusSupport">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Close Preview Editor tab if other tab is selected"/>
<text value="Focus Project View after opening/closing file editor"/>
</properties>
</component>
<component id="71c74" class="javax.swing.JCheckBox" binding="cbProjectViewOneClickToggle">
<constraints>
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Toggle tree expand/collapse by single click"/>
Expand All @@ -104,9 +80,95 @@
</grid>
<vspacer id="cecf9">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<grid id="745d8" layout-manager="GridLayoutManager" row-count="5" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="line" title="Preview Editor Tab"/>
<children>
<grid id="9af1b" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="99c8e" class="com.intellij.ui.CheckBoxWithColorChooser" binding="cpPreviewTabColor" custom-create="true">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
<hspacer id="e54ad">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
</children>
</grid>
<component id="8abe3" class="javax.swing.JCheckBox" binding="cbClosePreviewOnEmptySelection">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Close tab if no file is selected (e.g. directory or structure node selected)"/>
</properties>
</component>
<component id="a5105" class="javax.swing.JCheckBox" binding="cbPreviewClosedOnTabChange">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Close tab if other tab is selected"/>
</properties>
</component>
<component id="e2cc1" class="javax.swing.JCheckBox" binding="cbOpenEditorOnEditPreview">
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Convert to normal editor tab when editing previewed content"/>
</properties>
</component>
<grid id="53b5a" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="384e4" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Tab title pattern (%s = filename):"/>
</properties>
</component>
<component id="8aa1b" class="javax.swing.JTextField" binding="txtTitlePattern">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="0" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="100" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<hspacer id="d0ffa">
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
</children>
</grid>
</children>
</grid>
</children>
</grid>
</form>
Loading

0 comments on commit b52425d

Please sign in to comment.