-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
146 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#include "groupdialog.hpp" | ||
|
||
using namespace NickvisionMoney::Controllers; | ||
using namespace NickvisionMoney::UI::Views; | ||
|
||
GroupDialog::GroupDialog(GtkWindow* parent, NickvisionMoney::Controllers::GroupDialogController& controller) : m_controller{ controller }, m_gobj{ adw_message_dialog_new(parent, "Group", nullptr) } | ||
{ | ||
//Dialog Settings | ||
gtk_window_set_hide_on_close(GTK_WINDOW(m_gobj), true); | ||
adw_message_dialog_add_responses(ADW_MESSAGE_DIALOG(m_gobj), "cancel", "Cancel", "ok", "OK", nullptr); | ||
adw_message_dialog_set_response_appearance(ADW_MESSAGE_DIALOG(m_gobj), "ok", ADW_RESPONSE_SUGGESTED); | ||
adw_message_dialog_set_default_response(ADW_MESSAGE_DIALOG(m_gobj), "ok"); | ||
adw_message_dialog_set_close_response(ADW_MESSAGE_DIALOG(m_gobj), "cancel"); | ||
g_signal_connect(m_gobj, "response", G_CALLBACK((void (*)(AdwMessageDialog*, gchar*, gpointer))([](AdwMessageDialog*, gchar* response, gpointer data) { reinterpret_cast<GroupDialog*>(data)->setResponse({ response }); })), this); | ||
//Preferences Group | ||
m_preferencesGroup = adw_preferences_group_new(); | ||
//Name | ||
m_rowName = adw_entry_row_new(); | ||
gtk_widget_set_size_request(m_rowName, 420, -1); | ||
adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowName), "Name"); | ||
adw_entry_row_set_activates_default(ADW_ENTRY_ROW(m_rowName), true); | ||
adw_preferences_group_add(ADW_PREFERENCES_GROUP(m_preferencesGroup), m_rowName); | ||
//Description | ||
m_rowDescription = adw_entry_row_new(); | ||
gtk_widget_set_size_request(m_rowDescription, 420, -1); | ||
adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowDescription), "Description"); | ||
adw_entry_row_set_activates_default(ADW_ENTRY_ROW(m_rowDescription), true); | ||
adw_preferences_group_add(ADW_PREFERENCES_GROUP(m_preferencesGroup), m_rowDescription); | ||
//Layout | ||
adw_message_dialog_set_extra_child(ADW_MESSAGE_DIALOG(m_gobj), m_preferencesGroup); | ||
//Load Transaction | ||
gtk_editable_set_text(GTK_EDITABLE(m_rowName), m_controller.getName().c_str()); | ||
gtk_editable_set_text(GTK_EDITABLE(m_rowDescription), m_controller.getDescription().c_str()); | ||
} | ||
|
||
GtkWidget* GroupDialog::gobj() | ||
{ | ||
return m_gobj; | ||
} | ||
|
||
bool GroupDialog::run() | ||
{ | ||
gtk_widget_show(m_gobj); | ||
gtk_widget_grab_focus(m_rowName); | ||
while(gtk_widget_is_visible(m_gobj)) | ||
{ | ||
g_main_context_iteration(g_main_context_default(), false); | ||
} | ||
if(m_controller.getResponse() == "ok") | ||
{ | ||
gtk_widget_hide(m_gobj); | ||
GroupCheckStatus status{ m_controller.updateGroup(gtk_editable_get_text(GTK_EDITABLE(m_rowName)), gtk_editable_get_text(GTK_EDITABLE(m_rowDescription))) }; | ||
//Invalid Group | ||
if(status != GroupCheckStatus::Valid) | ||
{ | ||
//Reset UI | ||
gtk_style_context_remove_class(gtk_widget_get_style_context(m_rowName), "error"); | ||
adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowName), "Name"); | ||
gtk_style_context_remove_class(gtk_widget_get_style_context(m_rowDescription), "error"); | ||
adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowDescription), "Description"); | ||
//Mark Error | ||
if(status == GroupCheckStatus::EmptyName) | ||
{ | ||
gtk_style_context_add_class(gtk_widget_get_style_context(m_rowName), "error"); | ||
adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowName), "Name (Empty)"); | ||
} | ||
else if(status == GroupCheckStatus::EmptyDescription) | ||
{ | ||
gtk_style_context_add_class(gtk_widget_get_style_context(m_rowDescription), "error"); | ||
adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowDescription), "Description (Empty)"); | ||
} | ||
return run(); | ||
} | ||
} | ||
gtk_window_destroy(GTK_WINDOW(m_gobj)); | ||
return m_controller.getResponse() == "ok"; | ||
} | ||
|
||
void GroupDialog::setResponse(const std::string& response) | ||
{ | ||
m_controller.setResponse(response); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
#include <adwaita.h> | ||
#include "../../controllers/groupdialogcontroller.hpp" | ||
|
||
namespace NickvisionMoney::UI::Views | ||
{ | ||
/** | ||
* A dialog for managing a group | ||
*/ | ||
class GroupDialog | ||
{ | ||
public: | ||
/** | ||
* Constructs a GroupDialog | ||
* | ||
* @param parent The parent window for the dialog | ||
* @param controller The GroupDialogController | ||
*/ | ||
GroupDialog(GtkWindow* parent, NickvisionMoney::Controllers::GroupDialogController& controller); | ||
/** | ||
* Gets the GtkWidget* representing the GroupDialog | ||
* | ||
* @returns The GtkWidget* representing the GroupDialog | ||
*/ | ||
GtkWidget* gobj(); | ||
/** | ||
* Run the GroupDialog | ||
* | ||
* @returns True if dialog was accepted, else false | ||
*/ | ||
bool run(); | ||
|
||
private: | ||
NickvisionMoney::Controllers::GroupDialogController& m_controller; | ||
GtkWidget* m_gobj; | ||
GtkWidget* m_preferencesGroup{ nullptr }; | ||
GtkWidget* m_rowName{ nullptr }; | ||
GtkWidget* m_rowDescription{ nullptr }; | ||
/** | ||
* Sets the response | ||
* | ||
* @param The new response | ||
*/ | ||
void setResponse(const std::string& response); | ||
}; | ||
} |