Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save current tab and mode, keyboard shortcuts #110

Merged
merged 2 commits into from
Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
9 changes: 6 additions & 3 deletions src/EventTabView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ EventTabView::EventTabView(const BDate& date)
_AddEventList("Week", B_TRANSLATE("Week"), kWeekTab);
_AddEventList("Month", B_TRANSLATE("Month"), kMonthTab);

fMode = 0;
fMode = ((App*)be_app)->GetPreferences()->fViewMode;
fPopUpEnabled = true;
fEventList = new BList();
fDBManager = new QueryDBManager();
Expand All @@ -39,8 +39,8 @@ EventTabView::EventTabView(const BDate& date)
void
EventTabView::AttachedToWindow()
{
if (Selection() < 0)
Select(0);
Select(((App*)be_app)->GetPreferences()->fSelectedTab);
Window()->MessageReceived(new BMessage(kListModeChanged));

EventListView* list = ListAt(Selection());
if (list != NULL)
Expand Down Expand Up @@ -154,6 +154,8 @@ EventTabView::Select(int32 index)
ListAt(index)->SetPopUpMenuEnabled(fPopUpEnabled);
LoadEvents();

((App*)be_app)->GetPreferences()->fSelectedTab = index;
((App*)be_app)->GetPreferences()->fViewMode = fMode;
Window()->MessageReceived(new BMessage(kListTabChanged));
}

Expand All @@ -172,6 +174,7 @@ EventTabView::ToggleMode(uint8 flag)
fMode ^= flag;
_PopulateList();

((App*)be_app)->GetPreferences()->fViewMode = fMode;
Window()->MessageReceived(new BMessage(kListModeChanged));
}

Expand Down
1 change: 1 addition & 0 deletions src/EventTabView.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class EventTabView : public BTabView {
virtual void Select(int32 index);

void SetDate(const BDate& date);

void ToggleMode(uint8 flag);
uint8 Mode();

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
2 changes: 1 addition & 1 deletion src/PreferenceWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#define B_TRANSLATION_CONTEXT "PreferenceWindow"

PreferenceWindow::PreferenceWindow(Preferences* preferences)
:BWindow(BRect(), B_TRANSLATE("Preferences"), B_TITLED_WINDOW,
:BWindow(BRect(), B_TRANSLATE("Settings"), B_TITLED_WINDOW,
B_NOT_ZOOMABLE | B_NOT_RESIZABLE| B_AUTO_UPDATE_SIZE_LIMITS)
{
fCurrentPreferences = preferences;
Expand Down
4 changes: 4 additions & 0 deletions src/Preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ Preferences::Load(const char* filename)
if(result == B_OK)
storage.Unflatten(file);
fStartOfWeekOffset = storage.GetInt32("startOfWeekOffset", 0);
fSelectedTab = storage.GetInt32("selectedTab", 0);
fViewMode = storage.GetInt32("viewMode", 0);
fHeaderVisible = storage.GetBool("headerVisible", false);
fFirstDeletion = storage.GetBool("firstDeletion", true);
fDefaultCategory = storage.GetString("defaultCategory", B_TRANSLATE("Default"));
Expand Down Expand Up @@ -122,6 +124,8 @@ Preferences::Save(const char* filename)

BMessage storage;
storage.AddInt32("startOfWeekOffset", fStartOfWeekOffset);
storage.AddInt32("selectedTab", fSelectedTab);
storage.AddInt32("viewMode", fViewMode);
storage.AddBool("headerVisible", fHeaderVisible);
storage.AddBool("firstDeletion", fFirstDeletion);
storage.AddString("defaultCategory", fDefaultCategory);
Expand Down
9 changes: 3 additions & 6 deletions src/Preferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
#ifndef PREFERENCES_H
#define PREFERENCES_H


#include <string>

#include <Path.h>
#include <String.h>

Expand All @@ -24,13 +21,13 @@ class Preferences {
BPath fSettingsPath;

int32 fStartOfWeekOffset;
int32 fViewMode;
int32 fSelectedTab;
bool fHeaderVisible;
bool fFirstDeletion;
BString fDefaultCategory;
BRect fMainWindowRect;
BRect fEventWindowRect;

bool fFirstDeletion;
};


#endif