Browse Source

Added possibility to change tab size and char for a buffer.

merge-requests/365/head
eidheim 10 years ago
parent
commit
99908d4e3d
  1. 1
      src/files.h
  2. 2
      src/menu.cc
  3. 17
      src/source.cc
  4. 3
      src/source.h
  5. 62
      src/window.cc
  6. 1
      src/window.h

1
src/files.h

@ -65,6 +65,7 @@ const std::string configjson =
" \"edit_undo\": \"<primary>z\",\n" " \"edit_undo\": \"<primary>z\",\n"
" \"edit_redo\": \"<primary><shift>z\",\n" " \"edit_redo\": \"<primary><shift>z\",\n"
" \"edit_find\": \"<primary>f\",\n" " \"edit_find\": \"<primary>f\",\n"
" \"edit_set_tab\": \"\",\n"
" \"source_spellcheck\": \"\",\n" " \"source_spellcheck\": \"\",\n"
" \"source_spellcheck_clear\": \"\",\n" " \"source_spellcheck_clear\": \"\",\n"
" \"source_spellcheck_next_error\": \"<primary><shift>e\",\n" " \"source_spellcheck_next_error\": \"<primary><shift>e\",\n"

2
src/menu.cc

@ -43,6 +43,8 @@ Menu::Menu() {
" <menuitem action=\"EditPaste\"/>\n" " <menuitem action=\"EditPaste\"/>\n"
" <separator/>\n" " <separator/>\n"
" <menuitem action=\"EditFind\"/>\n" " <menuitem action=\"EditFind\"/>\n"
" <separator/>\n"
" <menuitem action=\"EditSetTab\"/>\n"
" </menu>\n" " </menu>\n"
" <menu action=\"SourceMenu\">\n" " <menu action=\"SourceMenu\">\n"
" <menu action=\"SourceSpellCheck\">\n" " <menu action=\"SourceSpellCheck\">\n"

17
src/source.cc

@ -260,6 +260,17 @@ Source::View::View(const boost::filesystem::path &file_path, const boost::filesy
set_tooltip_events(); 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<tab_size;c++)
tab+=tab_char;
tabs_regex=std::regex("^([ \\t]*)(.*)$");
}
void Source::View::configure() { void Source::View::configure() {
//TODO: Move this to notebook? Might take up too much memory doing this for every tab. //TODO: Move this to notebook? Might take up too much memory doing this for every tab.
auto style_scheme_manager=Gsv::StyleSchemeManager::get_default(); auto style_scheme_manager=Gsv::StyleSchemeManager::get_default();
@ -367,11 +378,7 @@ void Source::View::configure() {
tab_size=tab_char_and_size.second; tab_size=tab_char_and_size.second;
} }
} }
tab.clear(); set_tab_char_and_size(tab_char, tab_size);
for(unsigned c=0;c<tab_size;c++)
tab+=tab_char;
tabs_regex=std::regex("^([ \\t]*)(.*)$");
} }
void Source::View::set_tooltip_events() { void Source::View::set_tooltip_events() {

3
src/source.h

@ -127,6 +127,9 @@ namespace Source {
void spellcheck(); void spellcheck();
void remove_spellcheck_errors(); void remove_spellcheck_errors();
void goto_next_spellcheck_error(); void goto_next_spellcheck_error();
void set_tab_char_and_size(char tab_char, unsigned tab_size);
std::pair<char, unsigned> get_tab_char_and_size() {return {tab_char, tab_size};}
protected: protected:
bool source_readable; bool source_readable;
Tooltips diagnostic_tooltips; Tooltips diagnostic_tooltips;

62
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("SourceSpellCheck", "Spell Check"));
menu.action_group->add(Gtk::Action::create("SourceSpellCheckBuffer", "Spell Check Buffer"), Gtk::AccelKey(menu.key_map["source_spellcheck"]), [this]() { 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(); 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<unsigned>(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() { void Window::goto_line_entry() {
entry_box.clear(); entry_box.clear();
if(notebook.get_current_page()!=-1) { if(notebook.get_current_page()!=-1) {

1
src/window.h

@ -50,6 +50,7 @@ private:
void open_file_dialog(); void open_file_dialog();
void save_file_dialog(); void save_file_dialog();
void search_and_replace_entry(); void search_and_replace_entry();
void set_tab_entry();
void goto_line_entry(); void goto_line_entry();
void rename_token_entry(); void rename_token_entry();
void generate_keybindings(); void generate_keybindings();

Loading…
Cancel
Save