Skip to content

Commit

Permalink
Progress. Port application component to application service.
Browse files Browse the repository at this point in the history
  • Loading branch information
ggreer committed Aug 26, 2020
1 parent e92bb4a commit 7c4bb5c
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 43 deletions.
11 changes: 2 additions & 9 deletions META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<idea-plugin version="2" url="https://floobits.com">
<idea-plugin url="https://floobits.com">
<id>com.floobits.unique.plugin.id</id>
<name>Floobits</name>
<version>1.6.8</version>
Expand All @@ -23,12 +23,6 @@
on how to target different products -->
<depends>com.intellij.modules.lang</depends>

<application-components>
<component>
<implementation-class>floobits.FloobitsApplication</implementation-class>
</component>
</application-components>

<project-components>
<!-- Add your project components here -->
<component>
Expand Down Expand Up @@ -141,8 +135,7 @@
<add-to-group group-id="WelcomeScreen.QuickStart" anchor="last"/>
</action>
</actions>

<extensions defaultExtensionNs="com.intellij">
<!-- Add your extensions here -->
<applicationService serviceImplementation="floobits.FloobitsApplicationService"/>
</extensions>
</idea-plugin>
7 changes: 3 additions & 4 deletions intellij-plugin.iml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PLUGIN_MODULE" version="4">
<component name="DevKit.ModuleBuildProperties" url="file://$MODULE_DIR$/META-INF/plugin.xml" />
<component name="NewModuleRootManager" inherit-compiler-output="false">
<component name="NewModuleRootManager">
<output url="file://$MODULE_DIR$/out" />
<output-test url="file://$MODULE_DIR$/out-test" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/testresources" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
Expand All @@ -27,5 +27,4 @@
</library>
</orderEntry>
</component>
</module>

</module>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import com.intellij.ide.plugins.IdeaPluginDescriptor;
import com.intellij.ide.plugins.PluginManager;
import com.intellij.openapi.application.ApplicationInfo;
import com.intellij.openapi.components.ApplicationComponent;
import com.intellij.openapi.components.Service;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.extensions.PluginId;
import com.intellij.openapi.fileChooser.impl.FileChooserUtil;
import com.intellij.openapi.project.Project;
Expand All @@ -20,31 +21,26 @@
import floobits.utilities.Flog;
import floobits.utilities.IntelliBrowserOpener;
import floobits.utilities.SelectFolder;
import org.jetbrains.annotations.NotNull;

import java.awt.*;
import java.io.File;
import java.net.URI;

public class FloobitsApplication implements ApplicationComponent {
public static FloobitsApplication self;
@Service
public class FloobitsApplicationService {
private Boolean createAccount = true;

public FloobitsApplication() {
self = this;
public static FloobitsApplicationService getInstance() {
return ServiceManager.getService(FloobitsApplicationService.class);
}

public void initComponent() {
public void constructor() {
BrowserOpener.replaceSingleton(new IntelliBrowserOpener());
ApplicationInfo instance = ApplicationInfo.getInstance();
IdeaPluginDescriptor plugin = PluginManager.getPlugin(PluginId.getId("com.floobits.unique.plugin.id"));
createAccount = Bootstrap.bootstrap(instance.getVersionName(), instance.getMajorVersion(), instance.getMinorVersion(), plugin != null ? plugin.getVersion() : "???");
}

public void disposeComponent() {
// TODO: insert component disposal logic here
}

public synchronized void projectOpened(ContextImpl context) {
if (!createAccount) {
return;
Expand All @@ -60,11 +56,6 @@ public synchronized void projectOpened(ContextImpl context) {
createAccountDialog.show();
}

@NotNull
public String getComponentName() {
return "FloobitsApplication";
}

public void joinWorkspace(final String url) {
final FlooUrl f;
try {
Expand Down Expand Up @@ -175,7 +166,8 @@ private Project getProject(String path) {
VirtualFile file = LocalFileSystem.getInstance().findFileByIoFile(new File(path));
Project openedProject;
if (ProjectAttachProcessor.canAttachToProject() && file != null) {
openedProject = PlatformProjectOpenProcessor.doOpenProject(file, null, false, -1, null, false);
PlatformProjectOpenProcessor platformProjectOpenProcessor = PlatformProjectOpenProcessor.getInstance();
openedProject = platformProjectOpenProcessor.doOpenProject(file, null, false);
} else {
openedProject = ProjectUtil.openOrImport(path, null, false);
}
Expand All @@ -197,5 +189,4 @@ private Project getProject(String path) {
FileChooserUtil.setLastOpenedFile(openedProject, file);
return openedProject;
}

}
4 changes: 3 additions & 1 deletion src/floobits/FloobitsPlugin.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package floobits;

import com.intellij.openapi.components.ProjectComponent;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.project.Project;
import floobits.impl.ContextImpl;
import floobits.utilities.Flog;
Expand All @@ -23,7 +24,8 @@ public FloobitsPlugin(Project project) {

@Override
public void projectOpened() {
FloobitsApplication.self.projectOpened(context);
FloobitsApplicationService floobitsApplicationService = ServiceManager.getService(FloobitsApplicationService.class);
floobitsApplicationService.projectOpened(context);
context.loadFloobitsWindow();
}

Expand Down
8 changes: 5 additions & 3 deletions src/floobits/actions/OpenProjectInWorkspace.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package floobits.actions;

import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.project.Project;
import floobits.FloobitsApplication;
import floobits.FloobitsApplicationService;
import floobits.FloobitsPlugin;
import floobits.common.*;
import floobits.dialogs.HandleNoWorkspaceJoin;
Expand All @@ -16,8 +17,9 @@
public class OpenProjectInWorkspace extends CanFloobits {
public void actionPerformed(AnActionEvent actionEvent, Project project, FloobitsPlugin plugin, ContextImpl context) {
FlooUrl flooUrl = DotFloo.read(project.getBasePath());
FloobitsApplicationService floobitsApplicationService = ServiceManager.getService(FloobitsApplicationService.class);
if (flooUrl != null) {
FloobitsApplication.self.joinWorkspace(context, flooUrl.toString());
floobitsApplicationService.joinWorkspace(context, flooUrl.toString());
return;
}

Expand All @@ -34,7 +36,7 @@ public void actionPerformed(AnActionEvent actionEvent, Project project, Floobits
Flog.error(e);
continue;
}
FloobitsApplication.self.joinWorkspace(context, flooUrl.toString());
floobitsApplicationService.joinWorkspace(context, flooUrl.toString());
return;
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/floobits/actions/QuickStartJoin.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package floobits.actions;

import com.intellij.openapi.actionSystem.AnActionEvent;
import floobits.FloobitsApplication;
import com.intellij.openapi.components.ServiceManager;
import floobits.FloobitsApplicationService;

import javax.swing.*;

Expand All @@ -11,7 +12,7 @@ public void actionPerformedHasAccount(AnActionEvent e) {
if (inputValue == null) {
return;
}

FloobitsApplication.self.joinWorkspace(inputValue);
FloobitsApplicationService applicationService = ServiceManager.getService(FloobitsApplicationService.class);
applicationService.joinWorkspace(inputValue);
}
}
6 changes: 4 additions & 2 deletions src/floobits/dialogs/JoinWorkspaceDialog.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package floobits.dialogs;

import floobits.FloobitsApplication;
import com.intellij.openapi.components.ServiceManager;
import floobits.FloobitsApplicationService;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
Expand All @@ -23,7 +24,8 @@ public void run() {
if (inputValue == null) {
return;
}
FloobitsApplication.self.joinWorkspace(inputValue);
FloobitsApplicationService applicationService = ServiceManager.getService(FloobitsApplicationService.class);
applicationService.joinWorkspace(inputValue);
}
});
joinAction.putValue(FOCUSED_ACTION, true);
Expand Down
8 changes: 5 additions & 3 deletions src/floobits/dialogs/SelectRecentWorkspace.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package floobits.dialogs;

import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import floobits.FloobitsApplication;
import floobits.FloobitsApplicationService;
import floobits.FloobitsPlugin;
import floobits.impl.ContextImpl;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -46,12 +47,13 @@ public void doCancelAction() {
@Override
protected void doOKAction() {
super.doOKAction();
FloobitsApplicationService floobitsApplicationService = ServiceManager.getService(FloobitsApplicationService.class);
if (project != null) {
ContextImpl context = project.getComponent(FloobitsPlugin.class).context;
FloobitsApplication.self.joinWorkspace(context, selectWorkspace.getSelectedItem());
floobitsApplicationService.joinWorkspace(context, selectWorkspace.getSelectedItem());
return;
}
FloobitsApplication.self.joinWorkspace(null, selectWorkspace.getSelectedItem());
floobitsApplicationService.joinWorkspace(null, selectWorkspace.getSelectedItem());

}
}

0 comments on commit 7c4bb5c

Please sign in to comment.