Skip to content

Commit

Permalink
Shortcuts for basic actions, context menu in list
Browse files Browse the repository at this point in the history
Adds "Add event…" to the EventListView's selectionless context menu.
  • Loading branch information
JadedCtrl committed Dec 17, 2021
1 parent 3199dab commit 1ae073a
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 26 deletions.
45 changes: 33 additions & 12 deletions src/EventListView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <PopUpMenu.h>
#include <String.h>

#include "App.h"
#include "Event.h"
#include "EventListItem.h"
#include "EventTabView.h"
Expand Down Expand Up @@ -149,12 +150,6 @@ EventListView::MessageReceived(BMessage* message)
void
EventListView::MouseDown(BPoint position)
{
BRect bounds(Bounds());
BRect itemFrame = ItemFrame(CountItems() - 1);
bounds.top = itemFrame.bottom;
if (bounds.Contains(position))
return;

uint32 buttons = 0;
if (Window() != NULL && Window()->CurrentMessage() != NULL)
buttons = Window()->CurrentMessage()->FindInt32("buttons");
Expand Down Expand Up @@ -246,21 +241,30 @@ EventListView::SetPopUpMenuEnabled(bool enable)
void
EventListView::_ShowPopUpMenu(BPoint screen)
{
if (fShowingPopUpMenu || IsEmpty())
if (fShowingPopUpMenu == true)
return;

EventListItem* sItem = dynamic_cast<EventListItem *>
EventListItem* sItem = dynamic_cast<EventListItem*>
(ItemAt(CurrentSelection()));

if (CurrentSelection() < 0 || sItem == NULL) {
_ShowEmptyPopUpMenu(screen);
return;
}

uint16 eventStatus = sItem->GetEvent()->GetStatus();

PopUpMenu* menu = new PopUpMenu("PopUpMenu", this);

BMenuItem* item;
item = new BMenuItem(B_TRANSLATE("Edit"),
item = new BMenuItem(B_TRANSLATE("New" B_UTF8_ELLIPSIS),
new BMessage(kAddEventMessage), 'N');
menu->AddItem(item);
item = new BMenuItem(B_TRANSLATE("Edit" B_UTF8_ELLIPSIS),
new BMessage(kEditActionInvoked), 'E');
menu->AddItem(item);
item = new BMenuItem(B_TRANSLATE("Delete"),
new BMessage(kDeleteActionInvoked), 'D');
new BMessage(kDeleteActionInvoked), 'T');
item->SetMarked(eventStatus & EVENT_DELETED);
menu->AddItem(item);
item = new BMenuItem(B_TRANSLATE("Cancel"),
Expand All @@ -272,11 +276,28 @@ EventListView::_ShowPopUpMenu(BPoint screen)
item->SetMarked(eventStatus & EVENT_HIDDEN);
menu->AddItem(item);

if (!fPopUpMenuEnabled) {
if (fPopUpMenuEnabled == false)
menu->SetEnabled(false);
}

menu->SetTargetForItems(this);
menu->Go(screen, true, true, true);
fShowingPopUpMenu = true;
}


void
EventListView::_ShowEmptyPopUpMenu(BPoint screen)
{
PopUpMenu* menu = new PopUpMenu("PopUpMenu", this);

BMenuItem* item = new BMenuItem(B_TRANSLATE("New event" B_UTF8_ELLIPSIS),
new BMessage(kAddEventMessage), 'N');
item->SetTarget(((App*)be_app)->mainWindow());
menu->AddItem(item);

if (!fPopUpMenuEnabled)
menu->SetEnabled(false);

menu->Go(screen, true, true, true);
fShowingPopUpMenu = true;
}
1 change: 1 addition & 0 deletions src/EventListView.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class EventListView : public BListView {
static const int32 kHideActionInvoked = 1003;

void _ShowPopUpMenu(BPoint screen);
void _ShowEmptyPopUpMenu(BPoint screen);

bool fShowingPopUpMenu;
bool fPopUpMenuEnabled;
Expand Down
35 changes: 22 additions & 13 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ MainWindow::MessageReceived(BMessage* message)
case kMenuAppQuit:
be_app->PostMessage(B_QUIT_REQUESTED);
break;
case kAddEvent:
case kAddEventMessage:
_LaunchEventManager(NULL);
break;
case kEditEventMessage:
Expand Down Expand Up @@ -231,10 +231,12 @@ MainWindow::_InitInterface()
fMenuBar = new BMenuBar("MenuBar");

fAppMenu = new BMenu(B_TRANSLATE("App"));
BMenuItem* item = new BMenuItem(B_TRANSLATE("About"), new BMessage(B_ABOUT_REQUESTED));
BMenuItem* item = new BMenuItem(B_TRANSLATE("About" B_UTF8_ELLIPSIS),
new BMessage(B_ABOUT_REQUESTED));
item->SetTarget(be_app);
fAppMenu->AddItem(item);
fAppMenu->AddItem(new BMenuItem(B_TRANSLATE("Preferences"), new BMessage(kMenuAppPref)));
fAppMenu->AddItem(new BMenuItem(B_TRANSLATE("Settings" B_UTF8_ELLIPSIS),
new BMessage(kMenuAppPref), ',', B_COMMAND_KEY));
//
// Google Calendar support is broken. It should be replaced with a generic solution to
// be able to sync with various calendars. Leaving this here for now to give future
Expand All @@ -244,19 +246,25 @@ MainWindow::_InitInterface()
//fSyncMenu->AddItem(new BMenuItem(B_TRANSLATE("Google Calendar"), new BMessage(kMenuSyncGCAL)));
//fAppMenu->AddItem(fSyncMenu);
fAppMenu->AddSeparatorItem();
fAppMenu->AddItem(new BMenuItem(B_TRANSLATE("Quit"), new BMessage(kMenuAppQuit), 'Q', B_COMMAND_KEY));
fAppMenu->AddItem(new BMenuItem(B_TRANSLATE("Quit"), new BMessage(kMenuAppQuit),
'Q', B_COMMAND_KEY));

fEventMenu = new BMenu(B_TRANSLATE("Event"));
fEventMenu->AddItem(new BMenuItem(B_TRANSLATE("Add event"), new BMessage(kAddEvent)));
fEventMenu->AddItem(new BMenuItem(B_TRANSLATE("Edit event"), new BMessage(kEditEventMessage)));
fEventMenu->AddItem(new BMenuItem(B_TRANSLATE("Remove event"), new BMessage(kDeleteEventMessage)));
fEventMenu->AddItem(new BMenuItem(B_TRANSLATE("Cancel event"), new BMessage(kCancelEventMessage)));
fEventMenu->AddItem(new BMenuItem(B_TRANSLATE("Hide event"), new BMessage(kHideEventMessage)));
fEventMenu->AddItem(new BMenuItem(B_TRANSLATE_CONTEXT("New" B_UTF8_ELLIPSIS, "EventListView"),
new BMessage(kAddEventMessage), 'N', B_COMMAND_KEY));
fEventMenu->AddItem(new BMenuItem(B_TRANSLATE_CONTEXT("Edit" B_UTF8_ELLIPSIS, "EventListView"),
new BMessage(kEditEventMessage), 'E', B_COMMAND_KEY));
fEventMenu->AddItem(new BMenuItem(B_TRANSLATE_CONTEXT("Delete", "EventListView"),
new BMessage(kDeleteEventMessage), 'T', B_COMMAND_KEY));
fEventMenu->AddItem(new BMenuItem(B_TRANSLATE_CONTEXT("Cancel", "EventListView"),
new BMessage(kCancelEventMessage)));
fEventMenu->AddItem(new BMenuItem(B_TRANSLATE_CONTEXT("Hide", "EventListView"),
new BMessage(kHideEventMessage)));
for (int i = 1; i < fEventMenu->CountItems(); i++)
fEventMenu->ItemAt(i)->SetEnabled(false);

fCategoryMenu = new BMenu(B_TRANSLATE("Category"));
fCategoryMenu->AddItem(new BMenuItem(B_TRANSLATE("Manage categories" B_UTF8_ELLIPSIS),
fCategoryMenu->AddItem(new BMenuItem(B_TRANSLATE("Manage" B_UTF8_ELLIPSIS),
new BMessage(kMenuCategoryEdit)));

BMessage* agendaMsg = new BMessage(kChangeListMode);
Expand All @@ -272,10 +280,11 @@ MainWindow::_InitInterface()
monthMsg->AddInt32("tab", kMonthTab);

fViewMenu = new BMenu(B_TRANSLATE("View"));
fViewMenu->AddItem(new BMenuItem(B_TRANSLATE("Day view"), dayMsg));
fViewMenu->AddItem(new BMenuItem(B_TRANSLATE("Week view"), weekMsg));
fViewMenu->AddItem(new BMenuItem(B_TRANSLATE("Month view"), monthMsg));
fViewMenu->AddItem(new BMenuItem(B_TRANSLATE_CONTEXT("Day", "DayView"), dayMsg));
fViewMenu->AddItem(new BMenuItem(B_TRANSLATE_CONTEXT("Week", "DayView"), weekMsg));
fViewMenu->AddItem(new BMenuItem(B_TRANSLATE_CONTEXT("Month", "DayView"), monthMsg));
fViewMenu->AddSeparatorItem();

fViewMenu->AddItem(new BMenuItem(B_TRANSLATE("Agenda mode"), agendaMsg));
fViewMenu->AddItem(new BMenuItem(B_TRANSLATE("Show hidden/deleted events"), hiddenMsg));
fViewMenu->AddSeparatorItem();
Expand Down
3 changes: 2 additions & 1 deletion src/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ static const uint32 kMenuAppPref = 'kmap';
static const uint32 kMenuCategoryEdit = 'kmce';
static const uint32 kMenuSyncGCAL = 'kmsg';

static const int kAddEventMessage = 1005;


class MainWindow: public BWindow {
public:
Expand All @@ -43,7 +45,6 @@ class MainWindow: public BWindow {
void _ToggleEventMenu(BMessage* msg);

static const int kMenuAppQuit = 1000;
static const int kAddEvent = 1005;


MainView* fMainView;
Expand Down

0 comments on commit 1ae073a

Please sign in to comment.