show notification instead of throwing an exception on fresh plugin installs

This commit is contained in:
marhali 2022-02-07 20:42:21 +01:00
parent 512daedf09
commit 11f72664c7
7 changed files with 51 additions and 5 deletions

View File

@ -3,6 +3,9 @@
# easy-i18n Changelog # easy-i18n Changelog
## [Unreleased] ## [Unreleased]
### Changed
- Fresh projects will receive a notification instead of an exception to configure the plugin
### Fixed ### Fixed
- Exception on json array value mapping - Exception on json array value mapping

View File

@ -5,6 +5,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.vfs.*; import com.intellij.openapi.vfs.*;
import de.marhali.easyi18n.exception.EmptyLocalesDirException;
import de.marhali.easyi18n.io.IOHandler; import de.marhali.easyi18n.io.IOHandler;
import de.marhali.easyi18n.model.SettingsState; import de.marhali.easyi18n.model.SettingsState;
import de.marhali.easyi18n.model.TranslationData; import de.marhali.easyi18n.model.TranslationData;
@ -60,8 +61,13 @@ public class DataStore {
} catch (Exception ex) { } catch (Exception ex) {
this.data = new TranslationData(settings.isSortKeys()); this.data = new TranslationData(settings.isSortKeys());
successResult.accept(false); successResult.accept(false);
if(ex instanceof EmptyLocalesDirException) {
NotificationHelper.createEmptyLocalesDirNotification(project);
} else {
NotificationHelper.createIOError(settings, ex); NotificationHelper.createIOError(settings, ex);
} }
}
}); });
} }
@ -79,8 +85,13 @@ public class DataStore {
} catch (Exception ex) { } catch (Exception ex) {
successResult.accept(false); successResult.accept(false);
if(ex instanceof EmptyLocalesDirException) {
NotificationHelper.createEmptyLocalesDirNotification(project);
} else {
NotificationHelper.createIOError(settings, ex); NotificationHelper.createIOError(settings, ex);
} }
}
}); });
} }
} }

View File

@ -0,0 +1,11 @@
package de.marhali.easyi18n.exception;
/**
* Indicates that the translation's directory has not been configured yet
* @author marhali
*/
public class EmptyLocalesDirException extends IllegalArgumentException {
public EmptyLocalesDirException(String message) {
super(message);
}
}

View File

@ -3,6 +3,7 @@ package de.marhali.easyi18n.io;
import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFile;
import de.marhali.easyi18n.exception.EmptyLocalesDirException;
import de.marhali.easyi18n.io.folder.FolderStrategy; import de.marhali.easyi18n.io.folder.FolderStrategy;
import de.marhali.easyi18n.io.parser.ParserStrategy; import de.marhali.easyi18n.io.parser.ParserStrategy;
import de.marhali.easyi18n.io.parser.ParserStrategyType; import de.marhali.easyi18n.io.parser.ParserStrategyType;
@ -49,7 +50,7 @@ public class IOHandler {
String localesPath = this.settings.getLocalesPath(); String localesPath = this.settings.getLocalesPath();
if(localesPath == null || localesPath.isEmpty()) { if(localesPath == null || localesPath.isEmpty()) {
throw new IllegalArgumentException("Locales path must not be empty"); throw new EmptyLocalesDirException("Locales path must not be empty");
} }
VirtualFile localesDirectory = LocalFileSystem.getInstance().findFileByIoFile(new File(localesPath)); VirtualFile localesDirectory = LocalFileSystem.getInstance().findFileByIoFile(new File(localesPath));
@ -82,7 +83,7 @@ public class IOHandler {
String localesPath = this.settings.getLocalesPath(); String localesPath = this.settings.getLocalesPath();
if(localesPath == null || localesPath.isEmpty()) { if(localesPath == null || localesPath.isEmpty()) {
throw new IllegalArgumentException("Locales path must not be empty"); throw new EmptyLocalesDirException("Locales path must not be empty");
} }
List<TranslationFile> translationFiles = List<TranslationFile> translationFiles =

View File

@ -1,6 +1,11 @@
package de.marhali.easyi18n.util; package de.marhali.easyi18n.util;
import com.intellij.notification.Notification;
import com.intellij.notification.NotificationGroupManager;
import com.intellij.notification.NotificationType;
import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import de.marhali.easyi18n.action.SettingsAction;
import de.marhali.easyi18n.io.IOHandler; import de.marhali.easyi18n.io.IOHandler;
import de.marhali.easyi18n.model.SettingsState; import de.marhali.easyi18n.model.SettingsState;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -21,4 +26,16 @@ public class NotificationHelper {
Logger.getInstance(IOHandler.class).error(message, ex); Logger.getInstance(IOHandler.class).error(message, ex);
} }
public static void createEmptyLocalesDirNotification(Project project) {
ResourceBundle bundle = ResourceBundle.getBundle("messages");
Notification notification = NotificationGroupManager.getInstance()
.getNotificationGroup("Easy I18n Notification Group")
.createNotification("Easy I18n", bundle.getString("warning.missing-config"),
NotificationType.WARNING);
notification.addAction(new SettingsAction());
notification.notify(project);
}
} }

View File

@ -37,6 +37,8 @@
<psi.referenceContributor <psi.referenceContributor
implementation="de.marhali.easyi18n.editor.generic.GenericKeyReferenceContributor" /> implementation="de.marhali.easyi18n.editor.generic.GenericKeyReferenceContributor" />
<notificationGroup displayType="BALLOON" id="Easy I18n Notification Group" />
<errorHandler implementation="de.marhali.easyi18n.service.ErrorReportHandler" /> <errorHandler implementation="de.marhali.easyi18n.service.ErrorReportHandler" />
</extensions> </extensions>
</idea-plugin> </idea-plugin>

View File

@ -30,3 +30,4 @@ error.io=An error occurred while processing translation files. \n\
Path: {3} \n\ Path: {3} \n\
Please check examples at https://github.com/marhali/easy-i18n before reporting an issue! Please check examples at https://github.com/marhali/easy-i18n before reporting an issue!
error.submit=Open Issue error.submit=Open Issue
warning.missing-config=Configure your local project structure