Browse Source

Cleanup of #215

merge-requests/365/head
eidheim 10 years ago
parent
commit
d2beb15277
  1. 2
      src/config.cc
  2. 2
      src/config.h
  3. 6
      src/files.h
  4. 21
      src/source.cc
  5. 2
      src/source.h

2
src/config.cc

@ -186,7 +186,7 @@ void Config::get_source() {
source.font=source_json.get<std::string>("font"); source.font=source_json.get<std::string>("font");
source.cleanup_whitespace_characters=source_json.get<bool>("cleanup_whitespace_characters"); source.cleanup_whitespace_characters=source_json.get<bool>("cleanup_whitespace_characters");
source.draw_spaces=source_json.get<std::string>("draw_spaces"); source.show_whitespace_characters=source_json.get<std::string>("show_whitespace_characters");
source.show_map = source_json.get<bool>("show_map"); source.show_map = source_json.get<bool>("show_map");
source.map_font_size = source_json.get<std::string>("map_font_size"); source.map_font_size = source_json.get<std::string>("map_font_size");

2
src/config.h

@ -56,7 +56,7 @@ public:
std::string spellcheck_language; std::string spellcheck_language;
bool cleanup_whitespace_characters; bool cleanup_whitespace_characters;
std::string draw_spaces; std::string show_whitespace_characters;
bool show_map; bool show_map;
std::string map_font_size; std::string map_font_size;

6
src/files.h

@ -2,7 +2,7 @@
#define JUCI_FILES_H_ #define JUCI_FILES_H_
#include <string> #include <string>
#define JUCI_VERSION "1.1.3-2" #define JUCI_VERSION "1.1.3-3"
const std::string configjson = const std::string configjson =
"{\n" "{\n"
@ -37,8 +37,8 @@ const std::string configjson =
#endif #endif
" \"cleanup_whitespace_characters_comment\": \"Remove trailing whitespace characters on save, and add trailing newline if missing\",\n" " \"cleanup_whitespace_characters_comment\": \"Remove trailing whitespace characters on save, and add trailing newline if missing\",\n"
" \"cleanup_whitespace_characters\": false,\n" " \"cleanup_whitespace_characters\": false,\n"
" \"draw_spaces_comment\": \"Determines what kind of whitespaces should be drawn. Use comma-separated list of: space, tab, newline, nbsp, leading, text, trailing or all\",\n" " \"show_whitespace_characters_comment\": \"Determines what kind of whitespaces should be drawn. Use comma-separated list of: space, tab, newline, nbsp, leading, text, trailing or all\",\n"
" \"draw_spaces\": \"\",\n" " \"show_whitespace_characters\": \"\",\n"
" \"show_map\": true,\n" " \"show_map\": true,\n"
" \"map_font_size\": \"1\",\n" " \"map_font_size\": \"1\",\n"
" \"spellcheck_language_comment\": \"Use \\\"\\\" to set language from your locale settings\",\n" " \"spellcheck_language_comment\": \"Use \\\"\\\" to set language from your locale settings\",\n"

21
src/source.cc

@ -1,17 +1,14 @@
#include "source.h"
#include "config.h" #include "config.h"
#include "filesystem.h" #include "filesystem.h"
#include "source.h"
#include "terminal.h" #include "terminal.h"
#include <gtksourceview/gtksource.h>
#include <boost/property_tree/json_parser.hpp> #include <boost/property_tree/json_parser.hpp>
#include <boost/spirit/home/qi/char.hpp> #include <boost/spirit/home/qi/char.hpp>
#include <boost/spirit/home/qi/operator.hpp> #include <boost/spirit/home/qi/operator.hpp>
#include <boost/spirit/home/qi/string.hpp> #include <boost/spirit/home/qi/string.hpp>
#include <gtksourceview/gtksource.h>
#include <algorithm>
#include <iostream> #include <iostream>
#include <numeric>
#include <set> #include <set>
namespace sigc { namespace sigc {
@ -381,8 +378,7 @@ void Source::View::set_tab_char_and_size(char tab_char, unsigned tab_size) {
tab+=tab_char; tab+=tab_char;
} }
Gsv::DrawSpacesFlags parse_draw_spaces(std::string text) Gsv::DrawSpacesFlags Source::View::parse_show_whitespace_characters(const std::string &text) {
{
namespace qi = boost::spirit::qi; namespace qi = boost::spirit::qi;
qi::symbols<char, Gsv::DrawSpacesFlags> options; qi::symbols<char, Gsv::DrawSpacesFlags> options;
@ -396,15 +392,12 @@ Gsv::DrawSpacesFlags parse_draw_spaces(std::string text)
("trailing", Gsv::DRAW_SPACES_TRAILING) ("trailing", Gsv::DRAW_SPACES_TRAILING)
("all", Gsv::DRAW_SPACES_ALL); ("all", Gsv::DRAW_SPACES_ALL);
auto begin = text.begin();
auto end = text.end();
std::set<Gsv::DrawSpacesFlags> out; std::set<Gsv::DrawSpacesFlags> out;
// parse comma-separated list of options // parse comma-separated list of options
qi::phrase_parse(begin, end, options % ',', qi::space, out); qi::phrase_parse(text.begin(), text.end(), options % ',', qi::space, out);
return out.count(Gsv::DRAW_SPACES_ALL) ? return out.count(Gsv::DRAW_SPACES_ALL)>0 ?
Gsv::DRAW_SPACES_ALL : Gsv::DRAW_SPACES_ALL :
static_cast<Gsv::DrawSpacesFlags>(std::accumulate(out.begin(), out.end(), 0)); static_cast<Gsv::DrawSpacesFlags>(std::accumulate(out.begin(), out.end(), 0));
} }
@ -423,7 +416,7 @@ void Source::View::configure() {
Terminal::get().print("Error: Could not find gtksourceview style: "+Config::get().source.style+'\n', true); Terminal::get().print("Error: Could not find gtksourceview style: "+Config::get().source.style+'\n', true);
} }
set_draw_spaces(parse_draw_spaces(Config::get().source.draw_spaces)); set_draw_spaces(parse_show_whitespace_characters(Config::get().source.show_whitespace_characters));
if(Config::get().source.wrap_lines) if(Config::get().source.wrap_lines)
set_wrap_mode(Gtk::WrapMode::WRAP_CHAR); set_wrap_mode(Gtk::WrapMode::WRAP_CHAR);

2
src/source.h

@ -169,6 +169,8 @@ namespace Source {
guint previous_non_modifier_keyval=0; guint previous_non_modifier_keyval=0;
guint last_keyval=0; guint last_keyval=0;
private: private:
Gsv::DrawSpacesFlags parse_show_whitespace_characters(const std::string &text);
GtkSourceSearchContext *search_context; GtkSourceSearchContext *search_context;
GtkSourceSearchSettings *search_settings; GtkSourceSearchSettings *search_settings;
static void search_occurrences_updated(GtkWidget* widget, GParamSpec* property, gpointer data); static void search_occurrences_updated(GtkWidget* widget, GParamSpec* property, gpointer data);

Loading…
Cancel
Save