Browse Source

wip

merge-requests/365/head
Jørgen Lien Sellæg 10 years ago
parent
commit
374e0a3a55
  1. 8
      src/config.cc
  2. 10
      src/juci.cc
  3. 25
      src/juci.h
  4. 38
      src/source.cc

8
src/config.cc

@ -32,8 +32,8 @@ void MainConfig::GenerateSource() {
DEBUG("Fetching source cfg"); DEBUG("Fetching source cfg");
// boost::property_tree::ptree // boost::property_tree::ptree
auto source_json = cfg.get_child("source"); auto source_json = cfg.get_child("source");
auto syntax_json = source_json.get_child("syntax"); auto clang_types_json = source_json.get_child("clang_types");
auto colors_json = source_json.get_child("colors"); auto style_json = source_json.get_child("style");
auto visual_json = source_json.get_child("visual"); auto visual_json = source_json.get_child("visual");
for (auto &i : visual_json) { for (auto &i : visual_json) {
if (i.first == "background") if (i.first == "background")
@ -54,9 +54,9 @@ void MainConfig::GenerateSource() {
source_cfg->tab_size = source_json.get<unsigned>("tab_size"); source_cfg->tab_size = source_json.get<unsigned>("tab_size");
for (unsigned c = 0; c < source_cfg->tab_size; c++) for (unsigned c = 0; c < source_cfg->tab_size; c++)
source_cfg->tab+=" "; source_cfg->tab+=" ";
for (auto &i : colors_json) for (auto &i : style_json)
source_cfg->tags[i.first]=i.second.get_value<std::string>(); source_cfg->tags[i.first]=i.second.get_value<std::string>();
for (auto &i : syntax_json) for (auto &i : clang_types_json)
source_cfg->types[i.first]=i.second.get_value<std::string>(); source_cfg->types[i.first]=i.second.get_value<std::string>();
DEBUG("Source cfg fetched"); DEBUG("Source cfg fetched");
} }

10
src/juci.cc

@ -8,7 +8,7 @@ void init_logging() {
INFO("Logging initalized"); INFO("Logging initalized");
} }
int Juci::on_command_line(const Glib::RefPtr<Gio::ApplicationCommandLine> &cmd) { int juci::app::on_command_line(const Glib::RefPtr<Gio::ApplicationCommandLine> &cmd) {
Glib::set_prgname("juci"); Glib::set_prgname("juci");
Glib::OptionContext ctx("[PATH ...]"); Glib::OptionContext ctx("[PATH ...]");
Glib::OptionGroup gtk_group(gtk_get_option_group(true)); Glib::OptionGroup gtk_group(gtk_get_option_group(true));
@ -31,7 +31,7 @@ int Juci::on_command_line(const Glib::RefPtr<Gio::ApplicationCommandLine> &cmd)
return 0; return 0;
} }
void Juci::on_activate() { void juci::app::on_activate() {
window = std::unique_ptr<Window>(new Window()); window = std::unique_ptr<Window>(new Window());
add_window(*window); add_window(*window);
window->show(); window->show();
@ -43,7 +43,11 @@ void Juci::on_activate() {
window->notebook.open(f); window->notebook.open(f);
} }
juci::app::app() : Gtk::Application("no.sout.juci", Gio::APPLICATION_HANDLES_COMMAND_LINE) {
}
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
init_logging(); init_logging();
return Juci().run(argc, argv); return juci::app().run(argc, argv);
} }

25
src/juci.h

@ -3,18 +3,19 @@
#include "window.h" #include "window.h"
#include "logging.h" #include "logging.h"
namespace juci {
class Juci : public Gtk::Application { class app : public Gtk::Application {
public: public:
Juci(): Gtk::Application("no.sout.juci", Gio::APPLICATION_HANDLES_COMMAND_LINE) {} app();
int on_command_line(const Glib::RefPtr<Gio::ApplicationCommandLine> &cmd); int on_command_line(const Glib::RefPtr<Gio::ApplicationCommandLine> &cmd);
void on_activate(); void on_activate();
private: private:
std::unique_ptr<Window> window; std::unique_ptr<Window> window;
std::string directory; std::string directory;
std::vector<std::string> files; std::vector<std::string> files;
}; };
}
#endif // JUCI_JUCI_H_ #endif // JUCI_JUCI_H_

38
src/source.cc

@ -38,14 +38,10 @@ Glib::RefPtr<Gsv::Language> Source::guess_language(const std::string &file_path)
////////////// //////////////
Source::View::View(const std::string& file_path, const std::string& project_path): Source::View::View(const std::string& file_path, const std::string& project_path):
file_path(file_path), project_path(project_path) { file_path(file_path), project_path(project_path) {
set_smart_home_end(Gsv::SMART_HOME_END_BEFORE); set_smart_home_end(Gsv::SMART_HOME_END_BEFORE);
set_show_line_numbers(Singleton::Config::source()->show_line_numbers);
set_highlight_current_line(Singleton::Config::source()->highlight_current_line);
get_source_buffer()->begin_not_undoable_action(); get_source_buffer()->begin_not_undoable_action();
juci::filesystem::read(file_path, get_buffer()); juci::filesystem::read(file_path, get_buffer());
get_source_buffer()->end_not_undoable_action(); get_source_buffer()->end_not_undoable_action();
get_buffer()->place_cursor(get_buffer()->get_iter_at_offset(0)); get_buffer()->place_cursor(get_buffer()->get_iter_at_offset(0));
search_settings = gtk_source_search_settings_new(); search_settings = gtk_source_search_settings_new();
gtk_source_search_settings_set_wrap_around(search_settings, true); gtk_source_search_settings_set_wrap_around(search_settings, true);
@ -66,8 +62,8 @@ file_path(file_path), project_path(project_path) {
style_scheme_manager->prepend_search_path(Singleton::style_dir()); style_scheme_manager->prepend_search_path(Singleton::style_dir());
auto scheme = style_scheme_manager->get_scheme(Singleton::Config::source()->theme); auto scheme = style_scheme_manager->get_scheme(Singleton::Config::source()->theme);
if(scheme) { if(scheme) {
scheme->_cpp_destruction_is_in_progress()
get_source_buffer()->set_style_scheme(scheme); get_source_buffer()->set_style_scheme(scheme);
} }
} }
@ -279,12 +275,29 @@ clang::Index Source::ClangViewParse::clang_index(0, 0);
Source::ClangViewParse::ClangViewParse(const std::string& file_path, const std::string& project_path): Source::ClangViewParse::ClangViewParse(const std::string& file_path, const std::string& project_path):
Source::View(file_path, project_path) { Source::View(file_path, project_path) {
override_font(Pango::FontDescription(Singleton::Config::source()->font)); INFO("Tagtable beeing filled");
override_background_color(Gdk::RGBA(Singleton::Config::source()->background));
override_background_color(Gdk::RGBA(Singleton::Config::source()->background_selected), Gtk::StateFlags::STATE_FLAG_SELECTED);
for (auto &item : Singleton::Config::source()->tags) { for (auto &item : Singleton::Config::source()->tags) {
get_source_buffer()->create_tag(item.first)->property_foreground() = item.second; auto scheme = get_source_buffer()->get_style_scheme();
auto style = scheme->get_style(item.second);
if (style) {
DEBUG("Style " + item.second + " found in style " + scheme->get_name());
auto tag = get_source_buffer()->create_tag(item.first);
if (style->property_foreground_set())
tag->property_foreground() = style->property_foreground();
if (style->property_background_set())
tag->property_background() = style->property_background();
if (style->property_strikethrough_set())
tag->property_strikethrough() = style->property_strikethrough();
// // if (style->property_bold_set()) tag->property_weight() = style->property_bold();
// // if (style->property_italic_set()) tag->property_italic() = style->property_italic();
// // if (style->property_line_background_set()) tag->property_line_background() = style->property_line_background();
// // if (style->property_underline_set()) tag->property_underline() = style->property_underline();
} else {
DEBUG("Style " + item.second + " not found in " + scheme->get_name());
get_source_buffer()->create_tag(item.first)->property_foreground() = item.second;
}
} }
INFO("Tagtable filled");
//Create underline color tags for diagnostic warnings and errors: //Create underline color tags for diagnostic warnings and errors:
auto diagnostic_tag=get_buffer()->get_tag_table()->lookup("diagnostic_warning"); auto diagnostic_tag=get_buffer()->get_tag_table()->lookup("diagnostic_warning");
@ -479,7 +492,7 @@ void Source::ClangViewParse::update_syntax() {
buffer->remove_tag_by_name(tag, buffer->begin(), buffer->end()); buffer->remove_tag_by_name(tag, buffer->begin(), buffer->end());
last_syntax_tags.clear(); last_syntax_tags.clear();
for (auto &range : ranges) { for (auto &range : ranges) {
std::string type = std::to_string(range.kind); auto type = std::to_string(range.kind);
try { try {
last_syntax_tags.emplace(Singleton::Config::source()->types.at(type)); last_syntax_tags.emplace(Singleton::Config::source()->types.at(type));
} catch (std::exception) { } catch (std::exception) {
@ -490,6 +503,7 @@ void Source::ClangViewParse::update_syntax() {
Gtk::TextIter end_iter = buffer->get_iter_at_offset(range.end_offset); Gtk::TextIter end_iter = buffer->get_iter_at_offset(range.end_offset);
buffer->apply_tag_by_name(Singleton::Config::source()->types.at(type), buffer->apply_tag_by_name(Singleton::Config::source()->types.at(type),
begin_iter, end_iter); begin_iter, end_iter);
} }
} }
@ -1099,4 +1113,4 @@ bool Source::ClangView::restart_parse() {
return true; return true;
} }
return false; return false;
} }

Loading…
Cancel
Save