From 279fecd0459f6b7e9112e7b3542c2d5300943d39 Mon Sep 17 00:00:00 2001 From: Niels De Graef Date: Sat, 13 Jan 2018 18:28:28 +0100 Subject: Window: Implement the UI as an FSM. This way it's clear what parts of the UI should be active when selecting, editing, ... It also allows us to get rid of a hard to follow combo of edit_mode/selection_mode/new_contact variables. --- src/contacts-ui-state.vala | 60 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/contacts-ui-state.vala (limited to 'src/contacts-ui-state.vala') diff --git a/src/contacts-ui-state.vala b/src/contacts-ui-state.vala new file mode 100644 index 0000000..ad7230b --- /dev/null +++ b/src/contacts-ui-state.vala @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2018 Niels De Graef + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * Roughly put, the behaviour of the UI of Contacts can be divided in several + * categories. We represent this with the UiState enum, which can be shared + * (and sync-ed) between the different parts of the app. + * + * Note that there is one exception to this: the initial setup is handled + * completely separately in the {@link SetupWindow}. + */ +public enum Contacts.UiState { + /** + * The start state: no contact is selected/displayed. + */ + NORMAL, + + /** + * A contact has been selected and is displayed. + */ + SHOWING, + + /** + * Zero or more contacts are selected (but this can be changed). + * No contact should be displayed. + */ + SELECTING, + + /** + * The selected contact is being edited. + */ + UPDATING, + + /** + * A new contact is being created. + */ + CREATING; + + /** + * Returns whether we're editing a contact, either by changing an existing + * one, or by creating a new one. + */ + public bool editing () { + return this == UiState.UPDATING || this == UiState.CREATING; + } +} -- cgit v1.2.1