diff --git a/src/files.h b/src/files.h index 8912d95..b6f46d2 100644 --- a/src/files.h +++ b/src/files.h @@ -65,6 +65,7 @@ const std::string configjson = " \"edit_undo\": \"z\",\n" " \"edit_redo\": \"z\",\n" " \"edit_find\": \"f\",\n" +" \"edit_set_tab\": \"\",\n" " \"source_spellcheck\": \"\",\n" " \"source_spellcheck_clear\": \"\",\n" " \"source_spellcheck_next_error\": \"e\",\n" diff --git a/src/menu.cc b/src/menu.cc index 8c19df2..fbfe933 100644 --- a/src/menu.cc +++ b/src/menu.cc @@ -43,6 +43,8 @@ Menu::Menu() { " \n" " \n" " \n" + " \n" + " \n" " \n" " \n" " \n" diff --git a/src/source.cc b/src/source.cc index 4ca6811..412e0c3 100644 --- a/src/source.cc +++ b/src/source.cc @@ -260,6 +260,17 @@ Source::View::View(const boost::filesystem::path &file_path, const boost::filesy set_tooltip_events(); } +void Source::View::set_tab_char_and_size(char tab_char, unsigned tab_size) { + this->tab_char=tab_char; + this->tab_size=tab_size; + + tab.clear(); + for(unsigned c=0;c get_tab_char_and_size() {return {tab_char, tab_size};} protected: bool source_readable; Tooltips diagnostic_tooltips; diff --git a/src/window.cc b/src/window.cc index c62ad72..3d167db 100644 --- a/src/window.cc +++ b/src/window.cc @@ -249,6 +249,9 @@ void Window::create_menu() { } } }); + menu.action_group->add(Gtk::Action::create("EditSetTab", "Set Tab Char and Size"), Gtk::AccelKey(menu.key_map["edit_set_tab"]), [this]() { + set_tab_entry(); + }); menu.action_group->add(Gtk::Action::create("SourceSpellCheck", "Spell Check")); menu.action_group->add(Gtk::Action::create("SourceSpellCheckBuffer", "Spell Check Buffer"), Gtk::AccelKey(menu.key_map["source_spellcheck"]), [this]() { @@ -787,6 +790,65 @@ void Window::search_and_replace_entry() { entry_box.show(); } +void Window::set_tab_entry() { + entry_box.clear(); + if(notebook.get_current_page()!=-1) { + auto tab_char_and_size=notebook.get_current_view()->get_tab_char_and_size(); + + entry_box.labels.emplace_back(); + auto label_it=entry_box.labels.begin(); + + entry_box.entries.emplace_back(std::to_string(tab_char_and_size.second)); + auto entry_tab_size_it=entry_box.entries.begin(); + entry_tab_size_it->set_placeholder_text("Tab size"); + + char tab_char=tab_char_and_size.first; + std::string tab_char_string; + if(tab_char==' ') + tab_char_string="space"; + else if(tab_char=='\t') + tab_char_string="tab"; + + entry_box.entries.emplace_back(tab_char_string); + auto entry_tab_char_it=entry_box.entries.rbegin(); + entry_tab_char_it->set_placeholder_text("Tab char"); + + const auto activate_function=[this, entry_tab_char_it, entry_tab_size_it, label_it](const std::string& content){ + if(notebook.get_current_page()!=-1) { + char tab_char=0; + unsigned tab_size=0; + try { + tab_size = static_cast(stoul(entry_tab_size_it->get_text())); + std::string tab_char_string=entry_tab_char_it->get_text(); + std::transform(tab_char_string.begin(), tab_char_string.end(), tab_char_string.begin(), ::tolower); + if(tab_char_string=="space") + tab_char=' '; + else if(tab_char_string=="tab") + tab_char='\t'; + } + catch(const std::exception &e) {} + + if(tab_char!=0 && tab_size>0) { + notebook.get_current_view()->set_tab_char_and_size(tab_char, tab_size); + entry_box.hide(); + } + else { + label_it->set_text("Tab size must be >0 and tab char set to either 'space' or 'tab'"); + } + } + }; + + entry_tab_char_it->on_activate=activate_function; + entry_tab_size_it->on_activate=activate_function; + + entry_box.buttons.emplace_back("Set tab char and size", [this, entry_tab_char_it](){ + entry_tab_char_it->activate(); + }); + + entry_box.show(); + } +} + void Window::goto_line_entry() { entry_box.clear(); if(notebook.get_current_page()!=-1) { diff --git a/src/window.h b/src/window.h index 095e949..4fa0460 100644 --- a/src/window.h +++ b/src/window.h @@ -50,6 +50,7 @@ private: void open_file_dialog(); void save_file_dialog(); void search_and_replace_entry(); + void set_tab_entry(); void goto_line_entry(); void rename_token_entry(); void generate_keybindings();