Skip to content

Commit

Permalink
Showing and hiding of deleted messages
Browse files Browse the repository at this point in the history
  • Loading branch information
marigostra committed Jan 14, 2023
1 parent c0fa21e commit 2d2f91f
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 19 deletions.
1 change: 1 addition & 0 deletions src/main/java/org/luwrain/app/mail/Conv.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ final class Conv

String newFolderName() { return textNotEmpty(luwrain, strings.newFolderNamePopupName(), strings.newFolderNamePopupPrefix(), ""); }
boolean removeFolder() { return confirmDefaultNo(luwrain, strings.removeFolderPopupName(), strings.removeFolderPopupText()); }
boolean deleteMessageForever() { return confirmDefaultYes(luwrain, strings.deleteMessageForeverPopupName(), strings.deleteMessageForeverPopupText()); }
}
61 changes: 47 additions & 14 deletions src/main/java/org/luwrain/app/mail/MainLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ final class MainLayout extends LayoutBase implements TreeListArea.LeafClickHandl
final ReaderArea messageArea;

private final List<SummaryItem> summaryItems = new ArrayList<>();
private boolean showDeleted = false;
private MailFolder folder = null;
private MailMessage message = null;

MainLayout(App app)
{
super(app);
this.app = app;

final TreeListArea.Params<MailFolder> treeParams = new TreeListArea.Params<>();
treeParams.context = getControlContext();
treeParams.name = app.getStrings().foldersAreaName();
Expand All @@ -73,6 +75,7 @@ final class MainLayout extends LayoutBase implements TreeListArea.LeafClickHandl
}
};
this.foldersArea.requery();

this.summaryArea = new ListArea<>(listParams((params)->{
params.name = app.getStrings().summaryAreaName();
params.model = new ListModel<>(summaryItems);
Expand All @@ -85,16 +88,20 @@ final class MainLayout extends LayoutBase implements TreeListArea.LeafClickHandl
@Override public boolean isSectionItem(SummaryItem item) { return item.type == SummaryItem.Type.SECTION; }
};
}));

final ReaderArea.Params messageParams = new ReaderArea.Params();
messageParams.context = getControlContext();
messageParams.name = app.getStrings().messageAreaName();
this.messageArea = new ReaderArea(messageParams);

final ActionInfo
fetchIncomingBkg = action("fetch-incoming-bkg", app.getStrings().actionFetchIncomingBkg(), new InputEvent(InputEvent.Special.F6), ()->{ getLuwrain().runWorker(org.luwrain.pim.workers.Pop3.NAME); return true;});

setAreaLayout(AreaLayout.LEFT_TOP_BOTTOM, foldersArea, actions(
action("remove-folder", app.getStrings().actionRemoveFolder(), new InputEvent(InputEvent.Special.DELETE), this::actRemoveFolder),
action("new-folder", app.getStrings().actionNewFolder(), new InputEvent(InputEvent.Special.INSERT), MainLayout.this::actNewFolder),
fetchIncomingBkg),

summaryArea, actions(
action("reply", app.getStrings().actionReply(), HOT_KEY_REPLY, this::actSummaryReply),
action("mark", app.getStrings().actionMarkMessage(), new InputEvent(InputEvent.Special.INSERT), this::actMarkMessage, ()->{
Expand All @@ -106,19 +113,40 @@ summaryArea, actions(
return item != null && item.message != null && item.message.getState() == MailMessage.State.MARKED;
}),
action("delete", app.getStrings().actionDeleteMessage(), new InputEvent(InputEvent.Special.DELETE), this::actDeleteMessage),
action("delete-forever", app.getStrings().actionDeleteMessageForever(), new InputEvent(InputEvent.Special.DELETE, EnumSet.of(InputEvent.Modifiers.SHIFT)), this::actDeleteMessage),
fetchIncomingBkg
action("delete-forever", app.getStrings().actionDeleteMessageForever(), new InputEvent(InputEvent.Special.DELETE, EnumSet.of(InputEvent.Modifiers.CONTROL)), this::actDeleteMessageForever),
action("deleted-show", app.getStrings().actionDeletedShow(), new InputEvent('='), ()->{
showDeleted = true;
updateSummary();
getLuwrain().playSound(Sounds.OK);
return true;
}),
action("deleted-hide", app.getStrings().actionDeletedHide(), new InputEvent('-'), ()->{
showDeleted = false;
updateSummary();
getLuwrain().playSound(Sounds.OK);
return true;
}),
fetchIncomingBkg
),

messageArea, actions(
fetchIncomingBkg
));
}

@Override public boolean onLeafClick(TreeListArea<MailFolder> area, MailFolder folder)
void updateSummary()
{
this.folder = folder;
this.summaryItems.clear();
this.summaryItems.addAll(app.getHooks().organizeSummary(app.getStoring().getMessages().load(folder, (m)->{ return m.getState() != MailMessage.State.DELETED; })));
if (showDeleted)
this.summaryItems.addAll(app.getHooks().organizeSummary(app.getStoring().getMessages().load(folder))); else
this.summaryItems.addAll(app.getHooks().organizeSummary(app.getStoring().getMessages().load(folder, (m)->{ return m.getState() != MailMessage.State.DELETED; })));
summaryArea.refresh();
}

@Override public boolean onLeafClick(TreeListArea<MailFolder> area, MailFolder folder)
{
this.folder = folder;
updateSummary();
summaryArea.reset(false);
setActiveArea(summaryArea);
return true;
Expand Down Expand Up @@ -227,9 +255,23 @@ private boolean actDeleteMessage()
return false;
item.message.setState(MailMessage.State.DELETED);
app.getStoring().getMessages().update(item.message);
updateSummary();
return true;
}

private boolean actDeleteMessageForever()
{
final SummaryItem item = summaryArea.selected();
if (item == null || item.message == null)
return false;
if (!app.getConv().deleteMessageForever())
return true;
app.getStoring().getMessages().delete(item.message);
updateSummary();
return true;
}


private void announceSummaryMessage(SummaryItem summaryItem)
{
final MailMessage m = summaryItem.message;
Expand All @@ -256,15 +298,6 @@ private void announceSummaryMessage(SummaryItem summaryItem)
}
}

private boolean actDeleteMessageForever()
{
final SummaryItem item = summaryArea.selected();
if (item == null || item.message == null)
return false;
item.message.setState(MailMessage.State.DELETED);
app.getStoring().getMessages().delete(item.message);
return true;
}

boolean saveAttachment(String fileName)
{
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/luwrain/app/mail/Strings.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,15 @@ public interface Strings
String actionReplyAll();
String actionDeleteMessage();
String actionDeleteMessageForever();
String deleteMessageForeverPopupName();
String deleteMessageForeverPopupText();
String actionMarkMessage();
String messageMarked();
String actionUnmarkMessage();
String messageUnmarked();
String actionDeletedShow();
String actionDeletedHide();



String messageAreaAttachment();
Expand Down
11 changes: 6 additions & 5 deletions src/main/resources/org/luwrain/app/mail/strings-mail.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,20 @@ ActionRemoveFolder = Удалить группу
RemoveFolderPopupName = Удалить группу
RemoveFolderPopupText = Вы действительно хотите удалить группу электронной почты?





SummaryAreaName = Сообщения
ActionDeleteMessage = Удалить сообщение
ActionReply = Ответить
ActionReplyAll = Ответить всем
ActionForward = Переслать
ActionDeleteMessage = Удалить сообщение
ActionDeleteMessageForever = Удалить сообщение навсегда
DeleteMessageForeverPopupName = Удаление сообщения
DeleteMessageForeverPopupText = Вы действительно хотите удалить сообщение навсегда?
ActionMarkMessage = Пометить
ActionUnmarkMessage = Снять отметку
MessageMarked = Помечено
MessageUnmarked = Пометка снята
ActionDeletedShow = Показать удалённые сообщения
ActionDeleteHide = Скрыть удалённые сообщения



Expand Down

0 comments on commit 2d2f91f

Please sign in to comment.