Skip to content

Commit

Permalink
debugging issue with colour picker (#2422)
Browse files Browse the repository at this point in the history
  • Loading branch information
giuspen committed Jan 7, 2024
1 parent 077fe5a commit 4862eb4
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 40 deletions.
6 changes: 3 additions & 3 deletions src/ct/ct_actions_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ void CtActions::preferences_import()
_pCtConfig->nodesOnNodeNameHeader = ctConfigImported.nodesOnNodeNameHeader;
_pCtConfig->maxMatchesInPage = ctConfigImported.maxMatchesInPage;
_pCtConfig->toolbarIconSize = ctConfigImported.toolbarIconSize;
_pCtConfig->currColors['f'] = ctConfigImported.currColors['f'];
_pCtConfig->currColors['b'] = ctConfigImported.currColors['b'];
_pCtConfig->currColors['n'] = ctConfigImported.currColors['n'];
_pCtConfig->currColour_fg = ctConfigImported.currColour_fg;
_pCtConfig->currColour_bg = ctConfigImported.currColour_bg;
_pCtConfig->currColour_nn = ctConfigImported.currColour_nn;
_pCtConfig->restoreExpColl = ctConfigImported.restoreExpColl;
_pCtConfig->nodesBookmExp = ctConfigImported.nodesBookmExp;
_pCtConfig->nodesIcons = ctConfigImported.nodesIcons;
Expand Down
14 changes: 6 additions & 8 deletions src/ct/ct_actions_format.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* ct_actions_format.cc
*
* Copyright 2009-2023
* Copyright 2009-2024
* Giuseppe Penone <giuspen@gmail.com>
* Evgenii Gurianov <https://github.com/txe>
*
Expand Down Expand Up @@ -365,19 +365,17 @@ void CtActions::apply_tag(const Glib::ustring& tag_property,
property_value = _links_entries_post_dialog(_link_entry);
}
else {
gchar color_for = tag_property[0] == 'f' ? 'f' : 'b';
Gdk::RGBA ret_color = Gdk::RGBA(_pCtConfig->currColors.at(color_for));
Glib::ustring title = tag_property[0] == 'f' ? _("Pick a Foreground Color") : _("Pick a Background Color");
auto res = CtDialogs::color_pick_dialog(_pCtMainWin, title, ret_color, true);
Glib::ustring& ret_colour = 'f' == tag_property[0] ? _pCtConfig->currColour_fg : _pCtConfig->currColour_bg;
const Glib::ustring title = 'f' == tag_property[0] ? _("Pick a Foreground Color") : _("Pick a Background Color");
const CtDialogs::CtPickDlgState res = CtDialogs::colour_pick_dialog(_pCtMainWin, title, ret_colour, true/*allow_remove_colour*/);
if (res == CtDialogs::CtPickDlgState::CANCEL) {
return;
}
else if (res == CtDialogs::CtPickDlgState::REMOVE_COLOR) {
if (res == CtDialogs::CtPickDlgState::REMOVE_COLOR) {
property_value = "-"; // don't use empty because `apply prev tag` command brings a color dialog again
}
else {
_pCtConfig->currColors[color_for] = CtRgbUtil::rgb_to_string(ret_color);
property_value = CtRgbUtil::rgb_to_string(ret_color);
property_value = ret_colour;
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/ct/ct_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,9 @@ void CtConfig::_populate_keyfile_from_data()
_uKeyFile->set_integer(_currentGroup, "nodes_on_node_name_header", nodesOnNodeNameHeader);
_uKeyFile->set_integer(_currentGroup, "max_matches_in_page", maxMatchesInPage);
_uKeyFile->set_integer(_currentGroup, "toolbar_icon_size", toolbarIconSize);
if (not currColors['f'].empty()) _uKeyFile->set_string(_currentGroup, "fg", currColors['f']);
if (not currColors['b'].empty()) _uKeyFile->set_string(_currentGroup, "bg", currColors['b']);
if (not currColors['n'].empty()) _uKeyFile->set_string(_currentGroup, "nn", currColors['n']);
if (not currColour_fg.empty()) _uKeyFile->set_string(_currentGroup, "fg", currColour_fg);
if (not currColour_bg.empty()) _uKeyFile->set_string(_currentGroup, "bg", currColour_bg);
if (not currColour_nn.empty()) _uKeyFile->set_string(_currentGroup, "nn", currColour_nn);

// [tree]
_currentGroup = "tree";
Expand Down Expand Up @@ -489,9 +489,9 @@ void CtConfig::_populate_data_from_keyfile()
_populate_int_from_keyfile("nodes_on_node_name_header", &nodesOnNodeNameHeader);
_populate_int_from_keyfile("max_matches_in_page", &maxMatchesInPage);
_populate_int_from_keyfile("toolbar_icon_size", &toolbarIconSize);
_populate_string_from_keyfile("fg", &currColors['f']);
_populate_string_from_keyfile("bg", &currColors['b']);
_populate_string_from_keyfile("nn", &currColors['n']);
_populate_string_from_keyfile("fg", &currColour_fg);
_populate_string_from_keyfile("bg", &currColour_bg);
_populate_string_from_keyfile("nn", &currColour_nn);

// [tree]
_currentGroup = "tree";
Expand Down
4 changes: 3 additions & 1 deletion src/ct/ct_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ class CtConfig
int nodesOnNodeNameHeader{3};
int maxMatchesInPage{500};
int toolbarIconSize{1};
std::unordered_map<gchar, std::string> currColors{{'f', ""}, {'b', ""}, {'n', ""}};
Glib::ustring currColour_fg;
Glib::ustring currColour_bg;
Glib::ustring currColour_nn;

// [tree]
CtRestoreExpColl restoreExpColl{CtRestoreExpColl::FROM_STR};
Expand Down
6 changes: 3 additions & 3 deletions src/ct/ct_dialogs.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* ct_dialogs.h
*
* Copyright 2009-2023
* Copyright 2009-2024
* Giuseppe Penone <giuspen@gmail.com>
* Evgenii Gurianov <https://github.com/txe>
*
Expand Down Expand Up @@ -168,8 +168,8 @@ CtExporting selnode_selnodeandsub_alltree_dialog(Gtk::Window& parent,

// Dialog to select a color, featuring a palette
enum class CtPickDlgState {SELECTED, CANCEL, REMOVE_COLOR };
CtPickDlgState color_pick_dialog(CtMainWin* pCtMainWin, const Glib::ustring& title,
Gdk::RGBA& color, bool allow_remove_color);
CtPickDlgState colour_pick_dialog(CtMainWin* pCtMainWin, const Glib::ustring& title,
Glib::ustring& colour, bool allow_remove_colour);

// The Question dialog, returns True if the user presses OK
bool question_dialog(const Glib::ustring& message,
Expand Down
14 changes: 7 additions & 7 deletions src/ct/ct_dialogs_gen_purp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -211,20 +211,20 @@ std::time_t CtDialogs::date_select_dialog(Gtk::Window& parent,
return new_time;
}

CtDialogs::CtPickDlgState CtDialogs::color_pick_dialog(CtMainWin* pCtMainWin,
const Glib::ustring& title,
Gdk::RGBA& ret_color,
bool allow_remove_color)
CtDialogs::CtPickDlgState CtDialogs::colour_pick_dialog(CtMainWin* pCtMainWin,
const Glib::ustring& title,
Glib::ustring& ret_colour,
bool allow_remove_colour)
{
Gtk::ColorChooserDialog dialog{title};
dialog.set_transient_for(*pCtMainWin);
dialog.set_modal(true);
dialog.property_destroy_with_parent() = true;
dialog.set_position(Gtk::WindowPosition::WIN_POS_CENTER_ON_PARENT);
if (allow_remove_color) {
if (allow_remove_colour) {
dialog.add_button(_("Remove Color"), Gtk::RESPONSE_NONE);
}
dialog.set_rgba(ret_color);
dialog.set_rgba(Gdk::RGBA(ret_colour));

auto on_key_press_dialog = [&](GdkEventKey* pEventKey)->bool{
if (GDK_KEY_Return == pEventKey->keyval or GDK_KEY_KP_Enter == pEventKey->keyval) {
Expand All @@ -245,7 +245,7 @@ CtDialogs::CtPickDlgState CtDialogs::color_pick_dialog(CtMainWin* pCtMainWin,
if (Gtk::RESPONSE_OK != response) {
return CtPickDlgState::CANCEL;
}
ret_color = dialog.get_rgba();
ret_colour = dialog.get_rgba().to_string();
return CtPickDlgState::SELECTED;
}

Expand Down
12 changes: 6 additions & 6 deletions src/ct/ct_dialogs_tree.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* ct_dialogs_tree.cc
*
* Copyright 2009-2023
* Copyright 2009-2024
* Giuseppe Penone <giuspen@gmail.com>
* Evgenii Gurianov <https://github.com/txe>
*
Expand Down Expand Up @@ -52,7 +52,7 @@ bool CtDialogs::node_prop_dialog(const Glib::ustring &title,

Gtk::CheckButton fg_checkbutton{_("Use Selected Color")};
fg_checkbutton.set_active(not nodeData.foregroundRgb24.empty());
Glib::ustring real_fg = not nodeData.foregroundRgb24.empty() ? nodeData.foregroundRgb24 : (not pCtConfig->currColors.at('n').empty() ? pCtConfig->currColors.at('n').c_str() : "red");
Glib::ustring real_fg = not nodeData.foregroundRgb24.empty() ? nodeData.foregroundRgb24 : (not pCtConfig->currColour_nn.empty() ? pCtConfig->currColour_nn.c_str() : "red");
Gtk::ColorButton fg_colorbutton{Gdk::RGBA{real_fg}};
fg_colorbutton.set_sensitive(not nodeData.foregroundRgb24.empty());

Expand Down Expand Up @@ -197,9 +197,9 @@ bool CtDialogs::node_prop_dialog(const Glib::ustring &title,
fg_colorbutton.set_sensitive(fg_checkbutton.get_active());
});
fg_colorbutton.signal_pressed().connect([&pCtMainWin, &fg_colorbutton](){
Gdk::RGBA ret_color = fg_colorbutton.get_rgba();
if (CtDialogs::color_pick_dialog(pCtMainWin, _("Pick a Color"), ret_color, false) == CtPickDlgState::SELECTED) {
fg_colorbutton.set_rgba(ret_color);
Glib::ustring ret_colour = fg_colorbutton.get_rgba().to_string();
if (CtDialogs::colour_pick_dialog(pCtMainWin, _("Pick a Color"), ret_colour, false) == CtPickDlgState::SELECTED) {
fg_colorbutton.set_rgba(Gdk::RGBA(ret_colour));
}
});
c_icon_checkbutton.signal_toggled().connect([&c_icon_checkbutton, &c_icon_button, &nodeData, &currCustomIconId](){
Expand Down Expand Up @@ -285,7 +285,7 @@ bool CtDialogs::node_prop_dialog(const Glib::ustring &title,
nodeData.isBold = is_bold_checkbutton.get_active();
if (fg_checkbutton.get_active()) {
nodeData.foregroundRgb24 = CtRgbUtil::get_rgb24str_from_str_any(fg_colorbutton.get_color().to_string());
pCtConfig->currColors['n'] = nodeData.foregroundRgb24;
pCtConfig->currColour_nn = nodeData.foregroundRgb24;
}
else {
nodeData.foregroundRgb24.clear();
Expand Down
6 changes: 3 additions & 3 deletions src/ct/ct_misc_utils.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* ct_misc_utils.cc
*
* Copyright 2009-2023
* Copyright 2009-2024
* Giuseppe Penone <giuspen@gmail.com>
* Evgenii Gurianov <https://github.com/txe>
*
Expand Down Expand Up @@ -956,14 +956,14 @@ guint32 CtRgbUtil::get_rgb24int_from_str_any(const char* rgbStrAny)
return get_rgb24int_from_rgb24str(rgb24Str);
}

std::string CtRgbUtil::rgb_to_string(Gdk::RGBA color)
std::string CtRgbUtil::rgb_to_string(const Gdk::RGBA& color)
{
char rgbStrOut[16];
sprintf(rgbStrOut, "#%.4x%.4x%.4x", color.get_red_u(), color.get_green_u(), color.get_blue_u());
return rgbStrOut;
}

std::string CtRgbUtil::rgb_any_to_24(Gdk::RGBA color)
std::string CtRgbUtil::rgb_any_to_24(const Gdk::RGBA& color)
{
char rgb24StrOut[16];
set_rgb24str_from_str_any(CtRgbUtil::rgb_to_string(color).c_str(), rgb24StrOut);
Expand Down
6 changes: 3 additions & 3 deletions src/ct/ct_misc_utils.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* ct_misc_utils.h
*
* Copyright 2009-2023
* Copyright 2009-2024
* Giuseppe Penone <giuspen@gmail.com>
* Evgenii Gurianov <https://github.com/txe>
*
Expand Down Expand Up @@ -281,9 +281,9 @@ std::string get_rgb24str_from_str_any(const std::string& rgbStrAny);

guint32 get_rgb24int_from_str_any(const char* rgbStrAny);

std::string rgb_to_string(Gdk::RGBA color);
std::string rgb_to_string(const Gdk::RGBA& color);

std::string rgb_any_to_24(Gdk::RGBA color);
std::string rgb_any_to_24(const Gdk::RGBA& color);

} // namespace CtRgbUtil

Expand Down

0 comments on commit 4862eb4

Please sign in to comment.