Skip to content

Commit

Permalink
added configurability of feature Auto Link CamelCase Text to Node Wit…
Browse files Browse the repository at this point in the history
…h Same Name
  • Loading branch information
giuspen committed Dec 23, 2021
1 parent d31565e commit f14a902
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/ct/ct_actions_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ void CtActions::preferences_import()
pConfig->embfileMaxSize = ctConfigImported.embfileMaxSize;
pConfig->lineWrapping = ctConfigImported.lineWrapping;
pConfig->autoSmartQuotes = ctConfigImported.autoSmartQuotes;
pConfig->camelCaseAutoLink = ctConfigImported.camelCaseAutoLink;
pConfig->tripleClickParagraph = ctConfigImported.tripleClickParagraph;
pConfig->enableSymbolAutoreplace = ctConfigImported.enableSymbolAutoreplace;
pConfig->wrappingIndent = ctConfigImported.wrappingIndent;
Expand Down
2 changes: 2 additions & 0 deletions src/ct/ct_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ void CtConfig::_populate_keyfile_from_data()
_uKeyFile->set_integer(_currentGroup, "embfile_max_size", embfileMaxSize);
_uKeyFile->set_boolean(_currentGroup, "line_wrapping", lineWrapping);
_uKeyFile->set_boolean(_currentGroup, "auto_smart_quotes", autoSmartQuotes);
_uKeyFile->set_boolean(_currentGroup, "camelcase_autolink", camelCaseAutoLink);
_uKeyFile->set_boolean(_currentGroup, "triple_click_paragraph", tripleClickParagraph);
_uKeyFile->set_boolean(_currentGroup, "enable_symbol_autoreplace", enableSymbolAutoreplace);
#ifdef MD_AUTO_REPLACEMENT
Expand Down Expand Up @@ -534,6 +535,7 @@ void CtConfig::_populate_data_from_keyfile()
_populate_int_from_keyfile("embfile_max_size", &embfileMaxSize);
_populate_bool_from_keyfile("line_wrapping", &lineWrapping);
_populate_bool_from_keyfile("auto_smart_quotes", &autoSmartQuotes);
_populate_bool_from_keyfile("camelcase_autolink", &camelCaseAutoLink);
_populate_bool_from_keyfile("triple_click_paragraph", &tripleClickParagraph);
_populate_bool_from_keyfile("enable_symbol_autoreplace", &enableSymbolAutoreplace);
#ifdef MD_AUTO_REPLACEMENT
Expand Down
1 change: 1 addition & 0 deletions src/ct/ct_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class CtConfig
int embfileMaxSize{10};
bool lineWrapping{true};
bool autoSmartQuotes{true};
bool camelCaseAutoLink{true};
bool tripleClickParagraph{false};
bool enableSymbolAutoreplace{true};
#ifdef MD_AUTO_REPLACEMENT
Expand Down
6 changes: 6 additions & 0 deletions src/ct/ct_pref_dlg_rich_text.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ Gtk::Widget* CtPrefDlg::build_tab_rich_text()
spinbutton_limit_undoable_steps->set_value(_pConfig->limitUndoableSteps);
hbox_misc_text->pack_start(*label_limit_undoable_steps, false, false);
hbox_misc_text->pack_start(*spinbutton_limit_undoable_steps, false, false);
Gtk::CheckButton* checkbutton_camelcase_autolink = Gtk::manage(new Gtk::CheckButton{_("Auto Link CamelCase Text to Node With Same Name")});
checkbutton_camelcase_autolink->set_active(_pConfig->camelCaseAutoLink);
Gtk::CheckButton* checkbutton_triple_click_sel_paragraph = Gtk::manage(new Gtk::CheckButton(_("At Triple Click Select the Whole Paragraph")));
checkbutton_triple_click_sel_paragraph->set_active(_pConfig->tripleClickParagraph);
#ifdef MD_AUTO_REPLACEMENT
Expand All @@ -100,6 +102,7 @@ Gtk::Widget* CtPrefDlg::build_tab_rich_text()
vbox_misc_text->pack_start(*hbox_embfile_max_size, false, false);
vbox_misc_text->pack_start(*checkbutton_embfile_show_filename, false, false);
vbox_misc_text->pack_start(*hbox_misc_text, false, false);
vbox_misc_text->pack_start(*checkbutton_camelcase_autolink, false, false);
vbox_misc_text->pack_start(*checkbutton_triple_click_sel_paragraph, false, false);
#ifdef MD_AUTO_REPLACEMENT
vbox_misc_text->pack_start(*checkbutton_md_formatting, false, false);
Expand Down Expand Up @@ -164,6 +167,9 @@ Gtk::Widget* CtPrefDlg::build_tab_rich_text()
spinbutton_limit_undoable_steps->signal_value_changed().connect([this, spinbutton_limit_undoable_steps](){
_pConfig->limitUndoableSteps = spinbutton_limit_undoable_steps->get_value_as_int();
});
checkbutton_camelcase_autolink->signal_toggled().connect([this, checkbutton_camelcase_autolink]{
_pConfig->camelCaseAutoLink = checkbutton_camelcase_autolink->get_active();
});
checkbutton_triple_click_sel_paragraph->signal_toggled().connect([this, checkbutton_triple_click_sel_paragraph]{
_pConfig->tripleClickParagraph = checkbutton_triple_click_sel_paragraph->get_active();
});
Expand Down
2 changes: 1 addition & 1 deletion src/ct/ct_text_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ bool CtTextView::_apply_tag_try_link(Gtk::TextIter iter_end, int offset_cursor)
_pCtMainWin->get_ct_actions()->apply_tag(CtConst::TAG_LINK, property_value);
tag_applied = true;
}
else if (num_chars > 2 and CtTextIterUtil::get_is_camel_case(iter_start, num_chars)) {
else if (_pCtMainWin->get_ct_config()->camelCaseAutoLink and num_chars > 2 and CtTextIterUtil::get_is_camel_case(iter_start, num_chars)) {
if (apply_tag_try_node_name(iter_start, iter_end)) {
tag_applied = true;
}
Expand Down
20 changes: 20 additions & 0 deletions tests/tests_misc_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,3 +430,23 @@ TEST(MiscUtilsGroup, get_link_entry)
ASSERT_STREQ("", CtMiscUtil::get_link_entry("/home/foo/bar").type.c_str());
ASSERT_STREQ("", CtMiscUtil::get_link_entry("home https://example.com").type.c_str());
}

TEST(MiscUtilsGroup, get_is_camel_case)
{
Glib::RefPtr<Gtk::TextBuffer> pTextBuffer = Gtk::TextBuffer::create();
{
const std::string notcamelcase{"notcamelcase"};
pTextBuffer->set_text(notcamelcase);
ASSERT_FALSE(CtTextIterUtil::get_is_camel_case(pTextBuffer->begin(), notcamelcase.size()));
}
{
const std::string yesCamel1{"yesCamel1"};
pTextBuffer->set_text(yesCamel1);
ASSERT_TRUE(CtTextIterUtil::get_is_camel_case(pTextBuffer->begin(), yesCamel1.size()));
}
{
const std::string yesCamel2{"YesCamel2"};
pTextBuffer->set_text(yesCamel2);
ASSERT_TRUE(CtTextIterUtil::get_is_camel_case(pTextBuffer->begin(), yesCamel2.size()));
}
}

0 comments on commit f14a902

Please sign in to comment.