show notification instead of throwing an exception on fresh plugin installs
This commit is contained in:
parent
512daedf09
commit
11f72664c7
@ -3,6 +3,9 @@
|
||||
# easy-i18n Changelog
|
||||
|
||||
## [Unreleased]
|
||||
### Changed
|
||||
- Fresh projects will receive a notification instead of an exception to configure the plugin
|
||||
|
||||
### Fixed
|
||||
- Exception on json array value mapping
|
||||
|
||||
|
@ -5,6 +5,7 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.vfs.*;
|
||||
|
||||
import de.marhali.easyi18n.exception.EmptyLocalesDirException;
|
||||
import de.marhali.easyi18n.io.IOHandler;
|
||||
import de.marhali.easyi18n.model.SettingsState;
|
||||
import de.marhali.easyi18n.model.TranslationData;
|
||||
@ -60,8 +61,13 @@ public class DataStore {
|
||||
} catch (Exception ex) {
|
||||
this.data = new TranslationData(settings.isSortKeys());
|
||||
successResult.accept(false);
|
||||
|
||||
if(ex instanceof EmptyLocalesDirException) {
|
||||
NotificationHelper.createEmptyLocalesDirNotification(project);
|
||||
} else {
|
||||
NotificationHelper.createIOError(settings, ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -79,8 +85,13 @@ public class DataStore {
|
||||
|
||||
} catch (Exception ex) {
|
||||
successResult.accept(false);
|
||||
|
||||
if(ex instanceof EmptyLocalesDirException) {
|
||||
NotificationHelper.createEmptyLocalesDirNotification(project);
|
||||
} else {
|
||||
NotificationHelper.createIOError(settings, ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ package de.marhali.easyi18n.io;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
|
||||
import de.marhali.easyi18n.exception.EmptyLocalesDirException;
|
||||
import de.marhali.easyi18n.io.folder.FolderStrategy;
|
||||
import de.marhali.easyi18n.io.parser.ParserStrategy;
|
||||
import de.marhali.easyi18n.io.parser.ParserStrategyType;
|
||||
@ -49,7 +50,7 @@ public class IOHandler {
|
||||
String localesPath = this.settings.getLocalesPath();
|
||||
|
||||
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));
|
||||
@ -82,7 +83,7 @@ public class IOHandler {
|
||||
String localesPath = this.settings.getLocalesPath();
|
||||
|
||||
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 =
|
||||
|
@ -1,6 +1,11 @@
|
||||
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.project.Project;
|
||||
import de.marhali.easyi18n.action.SettingsAction;
|
||||
import de.marhali.easyi18n.io.IOHandler;
|
||||
import de.marhali.easyi18n.model.SettingsState;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -21,4 +26,16 @@ public class NotificationHelper {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
@ -37,6 +37,8 @@
|
||||
<psi.referenceContributor
|
||||
implementation="de.marhali.easyi18n.editor.generic.GenericKeyReferenceContributor" />
|
||||
|
||||
<notificationGroup displayType="BALLOON" id="Easy I18n Notification Group" />
|
||||
|
||||
<errorHandler implementation="de.marhali.easyi18n.service.ErrorReportHandler" />
|
||||
</extensions>
|
||||
</idea-plugin>
|
@ -30,3 +30,4 @@ error.io=An error occurred while processing translation files. \n\
|
||||
Path: {3} \n\
|
||||
Please check examples at https://github.com/marhali/easy-i18n before reporting an issue!
|
||||
error.submit=Open Issue
|
||||
warning.missing-config=Configure your local project structure
|
Loading…
x
Reference in New Issue
Block a user