Browse Source

Merge pull request #41 from eidheim/master

Theme cleanup
merge-requests/365/head
Jørgen Lien Sellæg 10 years ago
parent
commit
c812f4f06a
  1. 46
      src/config.cc
  2. 1
      src/config.h
  3. 178
      src/files.h
  4. 37
      src/juci.cc
  5. 2
      src/juci.h
  6. 4
      src/notebook.cc
  7. 3
      src/selectiondialog.cc
  8. 4
      src/singletons.cc
  9. 4
      src/singletons.h
  10. 226
      src/source.cc
  11. 26
      src/source.h
  12. 11
      src/sourcefile.cc
  13. 4
      src/terminal.cc
  14. 14
      src/theme.h
  15. 2
      src/tooltips.cc
  16. 20
      src/window.cc
  17. 2
      src/window.h

46
src/config.cc

@ -10,20 +10,14 @@ MainConfig::MainConfig() {
boost::property_tree::json_parser::read_json(Singleton::config_dir() + "config.json", cfg);
Singleton::Config::window()->keybindings = cfg.get_child("keybindings");
GenerateSource();
GenerateTheme();
GenerateDirectoryFilter();
Singleton::Config::window()->theme_name=cfg.get<std::string>("gtk_theme.name");
Singleton::Config::window()->theme_variant=cfg.get<std::string>("gtk_theme.variant");
Singleton::Config::terminal()->make_command=cfg.get<std::string>("project.make_command");
}
void MainConfig::GenerateTheme() {
auto config = Singleton::Config::theme();
auto props = cfg.get_child("theme");
for (auto &prop : props) {
if (prop.first == "theme") config->theme = prop.second.get_value<std::string>();
if (prop.first == "main") config->main = prop.second.get_value<std::string>();
}
}
void MainConfig::find_or_create_config_files() {
std::vector<std::string> files = {"config.json", "menu.xml", "plugins.py"};
boost::filesystem::create_directories(boost::filesystem::path(Singleton::config_dir()));
@ -35,21 +29,35 @@ void MainConfig::find_or_create_config_files() {
if (file == "menu.xml") juci::filesystem::write(path, menuxml);
}
}
boost::filesystem::create_directories(boost::filesystem::path(Singleton::style_dir()));
boost::filesystem::path juci_style_path=Singleton::style_dir();
juci_style_path+="juci-light.xml";
if(!boost::filesystem::exists(juci_style_path))
juci::filesystem::write(juci_style_path, juci_light_style);
juci_style_path=Singleton::style_dir();
juci_style_path+="juci-dark.xml";
if(!boost::filesystem::exists(juci_style_path))
juci::filesystem::write(juci_style_path, juci_dark_style);
}
void MainConfig::GenerateSource() {
auto source_cfg = Singleton::Config::source();
auto source_json = cfg.get_child("source");
auto clang_types_json = source_json.get_child("clang_types");
auto style_json = source_json.get_child("style");
auto gsv_json = source_json.get_child("sourceview");
for (auto &i : gsv_json)
source_cfg->gsv[i.first] = i.second.get_value<std::string>();
for (auto &i : style_json)
source_cfg->tags[i.first] = i.second.get_value<std::string>();
for (auto &i : clang_types_json)
source_cfg->types[i.first] = i.second.get_value<std::string>();
source_cfg->tab_size = source_json.get<unsigned>("tab_size");
source_cfg->tab_char = source_json.get<char>("tab_char");
for(unsigned c=0;c<source_cfg->tab_size;c++)
source_cfg->tab+=source_cfg->tab_char;
source_cfg->highlight_current_line = source_json.get_value<bool>("highlight_current_line");
source_cfg->show_line_numbers = source_json.get_value<bool>("show_line_numbers");
for (auto &i : source_json.get_child("clang_types"))
source_cfg->clang_types[i.first] = i.second.get_value<std::string>();
Singleton::Config::source()->style=source_json.get<std::string>("style");
source_cfg->font=source_json.get<std::string>("font");
}
void MainConfig::GenerateDirectoryFilter() {

1
src/config.h

@ -11,7 +11,6 @@ public:
void PrintMenu();
void GenerateSource();
void GenerateDirectoryFilter();
void GenerateTheme();
private:
boost::property_tree::ptree cfg;
};

178
src/files.h

@ -1,36 +1,32 @@
#include <string>
const std::string configjson =
"{\n"
" \"gtk_theme\": {\n"
" \"name\": \"Adwaita\", //Use \"\" for default theme, At least these two exist on all systems: Adwaita, Raleigh\n"
" \"variant\": \"\" //Use \"\" for default variant, and \"dark\" for dark theme variant\n"
" },\n"
" \"source\": {\n"
" \"colors\": {\n"
" \"text_color\": \"black\",\n"
" \"string\": \"#CC0000\",\n"
" \"namespace_ref\": \"#990099\",\n"
" \"type\": \"#0066FF\",\n"
" \"keyword\": \"blue\",\n"
" \"comment\": \"grey\",\n"
" \"own\": \"pink\",\n"
" \"diagnostic_warning\": \"orange\",\n"
" \"diagnostic_error\": \"red\"\n"
" },\n"
" \"syntax\": {\n"
" \"43\": \"type\",\n"
" \"46\": \"namespace_ref\",\n"
" \"109\": \"string\",\n"
" \"702\": \"keyword\",\n"
" \"703\": \"own\",\n"
" \"705\": \"comment\"\n"
" },\n"
" \"visual\": {\n"
" \"background\": \"white\",\n"
" \"background_selected\": \"blue\",\n"
" \"background_tooltips\": \"yellow\",\n"
" \"font\": \"Monospace\",\n"
" \"show_line_numbers\": 1,\n"
" \"highlight_current_line\": 1\n"
" \"style\": \"juci-light\", //Use \"\" for default style, and for instance juci-dark together with dark gtk_theme variant. Styles from normal gtksourceview install: classic, cobalt, kate, oblivion, solarized-dark, solarized-light, tango\n"
" \"font\": \"Monospace\", //Use \"\" for default font, and for instance \"Monospace 12\" to also set size.\n"
" \"clang_types\": {\n"
" \"8\": \"def:function\",\n"
" \"21\": \"def:function\",\n"
" \"22\": \"def:identifier\",\n"
" \"24\": \"def:function\",\n"
" \"25\": \"def:function\",\n"
" \"43\": \"def:type\",\n"
" \"44\": \"def:type\",\n"
" \"45\": \"def:type\",\n"
" \"46\": \"def:identifier\",\n"
" \"109\": \"def:string\",\n"
" \"500\": \"def:preprocessor\",\n"
" \"702\": \"def:statement\",\n"
" \"705\": \"def:comment\"\n"
" },\n"
" \"tab_size\": 2,\n"
" \"tab_char\": \"<space>\"\n"
" \"tab_char\": \" \", //Use \"\\t\" for regular tab\n"
" \"highlight_current_line\": true,\n"
" \"show_line_numbers\": true\n"
" },\n"
" \"keybindings\": {\n"
" \"new_file\": \"<primary>n\",\n"
@ -67,12 +63,10 @@ const std::string configjson =
" \"#\",\n"
" \"~\",\n"
" \".idea\",\n"
" \".so\",\n"
" \"in-lowercase.pls\"\n"
" \".so\"\n"
" ],\n"
" \"exceptions\": [\n"
" \"cmakelists.txt\",\n"
" \"in-lowercase.pls\"\n"
" \"cmakelists.txt\"\n"
" ]\n"
" }\n"
"}\n";
@ -85,21 +79,24 @@ const std::string menuxml =
" <menu action=\"FileNewProject\">\n"
" <menuitem action=\"FileNewProjectCpp\"/>\n"
" </menu>\n"
" <separator/>\n"
" <menuitem action=\"FileOpenFile\"/>\n"
" <menuitem action=\"FileOpenFolder\"/>\n"
" <separator/>\n"
" <menuitem action=\"FileSave\"/>\n"
" <menuitem action=\"FileSaveAs\"/>\n"
" <separator/>\n"
" <menuitem action=\"FileQuit\"/>\n"
" </menu>\n"
" <menu action=\"EditMenu\">\n"
" <menuitem action=\"EditUndo\"/>\n"
" <menuitem action=\"EditRedo\"/>\n"
" <separator/>\n"
" <menuitem action=\"EditCopy\"/>\n"
" <menuitem action=\"EditCut\"/>\n"
" <menuitem action=\"EditPaste\"/>\n"
" <separator/>\n"
" <menuitem action=\"EditFind\"/>\n"
" <menuitem action=\"EditUndo\"/>\n"
" <menuitem action=\"EditRedo\"/>\n"
" </menu>\n"
" <menu action=\"SourceMenu\">\n"
" <menuitem action=\"SourceGotoLine\"/>\n"
@ -112,6 +109,7 @@ const std::string menuxml =
" <menu action=\"ProjectMenu\">\n"
" <menuitem action=\"ProjectCompileAndRun\"/>\n"
" <menuitem action=\"ProjectCompile\"/>\n"
" <separator/>\n"
" <menuitem action=\"ProjectRunCommand\"/>\n"
" <menuitem action=\"ProjectKillLastRunning\"/>\n"
" <menuitem action=\"ProjectForceKillLastRunning\"/>\n"
@ -128,6 +126,120 @@ const std::string menuxml =
" </menubar>\n"
"</ui>\n";
const std::string juci_light_style =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"\n"
"<style-scheme id=\"juci-light\" _name=\"juci\" version=\"1.0\">\n"
" <author>juCi++ team</author>\n"
" <_description>Default juCi++ style</_description>\n"
"\n"
" <!-- Palette -->\n"
" <color name=\"white\" value=\"#FFFFFF\"/>\n"
" <color name=\"black\" value=\"#000000\"/>\n"
" <color name=\"gray\" value=\"#888888\"/>\n"
" <color name=\"red\" value=\"#CC0000\"/>\n"
" <color name=\"green\" value=\"#008800\"/>\n"
" <color name=\"blue\" value=\"#0000FF\"/>\n"
" <color name=\"dark-blue\" value=\"#002299\"/>\n"
" <color name=\"yellow\" value=\"#FFFF00\"/>\n"
" <color name=\"orange\" value=\"#EE7700\"/>\n"
" <color name=\"purple\" value=\"#990099\"/>\n"
"\n"
" <style name=\"text\" foreground=\"#000000\" background=\"#FFFFFF\"/>\n"
" <style name=\"selection\" background=\"#4A90D9\"/>\n"
"\n"
" <!-- Current Line Highlighting -->\n"
" <style name=\"current-line\" background=\"#EEEEEE\"/>\n"
"\n"
" <!-- Bracket Matching -->\n"
" <style name=\"bracket-match\" foreground=\"white\" background=\"gray\" bold=\"true\"/>\n"
" <style name=\"bracket-mismatch\" foreground=\"white\" background=\"#FF0000\" bold=\"true\"/>\n"
"\n"
" <!-- Search Matching -->\n"
" <style name=\"search-match\" background=\"yellow\"/>\n"
"\n"
" <!-- Language specifics -->\n"
" <style name=\"def:builtin\" foreground=\"blue\"/>\n"
" <style name=\"def:constant\" foreground=\"blue\"/>\n"
" <style name=\"def:boolean\" foreground=\"red\"/>\n"
" <style name=\"def:decimal\" foreground=\"red\"/>\n"
" <style name=\"def:base-n-integer\" foreground=\"red\"/>\n"
" <style name=\"def:floating-point\" foreground=\"red\"/>\n"
" <style name=\"def:complex\" foreground=\"red\"/>\n"
" <style name=\"def:character\" foreground=\"red\"/>\n"
" <style name=\"def:special-char\" foreground=\"red\"/>\n"
"\n\n"
" <!-- Language specifics used by clang-parser in default config -->\n"
" <style name=\"def:string\" foreground=\"red\"/>\n"
" <style name=\"def:comment\" foreground=\"gray\"/>\n"
" <style name=\"def:statement\" foreground=\"blue\"/>\n"
" <style name=\"def:type\" foreground=\"blue\"/>\n"
" <style name=\"def:function\" foreground=\"dark-blue\"/>\n"
" <style name=\"def:identifier\" foreground=\"purple\"/>\n"
" <style name=\"def:preprocessor\" foreground=\"green\"/>\n"
" <style name=\"def:error\" foreground=\"red\"/>\n"
" <style name=\"def:warning\" foreground=\"orange\"/>\n"
" <style name=\"def:note\" foreground=\"black\" background=\"yellow\"/>\n"
"\n"
"</style-scheme>\n";
const std::string juci_dark_style =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"\n"
"<style-scheme id=\"juci-dark\" _name=\"juci\" version=\"1.0\">\n"
" <author>juCi++ team</author>\n"
" <_description>Default juCi++ style</_description>\n"
"\n"
" <!-- Palette -->\n"
" <color name=\"white\" value=\"#FFFFFF\"/>\n"
" <color name=\"black\" value=\"#000000\"/>\n"
" <color name=\"gray\" value=\"#888888\"/>\n"
" <color name=\"red\" value=\"#FF8888\"/>\n"
" <color name=\"green\" value=\"#779955\"/>\n"
" <color name=\"blue\" value=\"#8888FF\"/>\n"
" <color name=\"dark-blue\" value=\"#6666CC\"/>\n"
" <color name=\"yellow\" value=\"#555555\"/>\n"
" <color name=\"orange\" value=\"#FF8800\"/>\n"
" <color name=\"purple\" value=\"#DD88DD\"/>\n"
"\n"
" <style name=\"text\" foreground=\"#BBBBBB\" background=\"#222222\"/>\n"
" <style name=\"selection\" background=\"#215D9C\"/>\n"
"\n"
" <!-- Current Line Highlighting -->\n"
" <style name=\"current-line\" background=\"#333333\"/>\n"
"\n"
" <!-- Bracket Matching -->\n"
" <style name=\"bracket-match\" foreground=\"black\" background=\"gray\" bold=\"true\"/>\n"
" <style name=\"bracket-mismatch\" foreground=\"black\" background=\"#FF0000\" bold=\"true\"/>\n"
"\n"
" <!-- Search Matching -->\n"
" <style name=\"search-match\" background=\"yellow\"/>\n"
"\n"
" <!-- Language specifics -->\n"
" <style name=\"def:builtin\" foreground=\"blue\"/>\n"
" <style name=\"def:constant\" foreground=\"blue\"/>\n"
" <style name=\"def:boolean\" foreground=\"red\"/>\n"
" <style name=\"def:decimal\" foreground=\"red\"/>\n"
" <style name=\"def:base-n-integer\" foreground=\"red\"/>\n"
" <style name=\"def:floating-point\" foreground=\"red\"/>\n"
" <style name=\"def:complex\" foreground=\"red\"/>\n"
" <style name=\"def:character\" foreground=\"red\"/>\n"
" <style name=\"def:special-char\" foreground=\"red\"/>\n"
"\n\n"
" <!-- Language specifics used by clang-parser in default config -->\n"
" <style name=\"def:string\" foreground=\"red\"/>\n"
" <style name=\"def:comment\" foreground=\"gray\"/>\n"
" <style name=\"def:statement\" foreground=\"blue\"/>\n"
" <style name=\"def:type\" foreground=\"blue\"/>\n"
" <style name=\"def:function\" foreground=\"dark-blue\"/>\n"
" <style name=\"def:identifier\" foreground=\"purple\"/>\n"
" <style name=\"def:preprocessor\" foreground=\"green\"/>\n"
" <style name=\"def:error\" foreground=\"red\"/>\n"
" <style name=\"def:warning\" foreground=\"orange\"/>\n"
" <style name=\"def:note\" foreground=\"#BBBBBB\" background=\"yellow\"/>\n"
"\n"
"</style-scheme>\n";
const std::string pluginspy =
"#!/usr/bin/python \n"
"import juci_to_python_api as juci \n"

37
src/juci.cc

@ -3,6 +3,8 @@
#include "config.h"
#include <iostream>
using namespace std; //TODO: remove
void init_logging() {
add_common_attributes();
add_file_log(keywords::file_name = Singleton::log_dir() + "juci.log",
@ -25,8 +27,8 @@ int app::on_command_line(const Glib::RefPtr<Gio::ApplicationCommandLine> &cmd) {
p=boost::filesystem::canonical(p);
if(boost::filesystem::is_regular_file(p))
files.emplace_back(p.string());
else if(directory=="" && boost::filesystem::is_directory(p))
directory=p.string();
else if(boost::filesystem::is_directory(p))
directories.emplace_back(p.string());
}
else
std::cerr << "Path " << p << " does not exist." << std::endl;
@ -40,20 +42,39 @@ void app::on_activate() {
window = std::unique_ptr<Window>(new Window());
add_window(*window);
window->show();
if(directory!="") {
window->directories.open_folder(directory);
bool first_directory=true;
for(auto &directory: directories) {
if(first_directory) {
window->directories.open_folder(directory);
first_directory=false;
}
else {
std::string files_in_directory;
for(size_t c=0;c<files.size();c++) {
if(files[c].substr(0, directory.size())==directory) {
files_in_directory+=" "+files[c];
files.erase(files.begin()+c);
c--;
}
}
std::thread another_juci_app([this, directory, files_in_directory](){
Singleton::terminal()->async_print("Executing: juci "+directory+files_in_directory);
Singleton::terminal()->execute("juci "+directory+files_in_directory, ""); //TODO: do not open pipes here, doing this after Juci compiles on Windows
});
another_juci_app.detach();
}
}
for(auto &f: files)
window->notebook.open(f);
for(auto &file: files)
window->notebook.open(file);
}
app::app() : Gtk::Application("no.sout.juci", Gio::APPLICATION_NON_UNIQUE | Gio::APPLICATION_HANDLES_COMMAND_LINE) {
MainConfig(); // Read the configs here
auto css_provider = Gtk::CssProvider::get_default();
auto style_context = Gtk::StyleContext::create();
auto screen = Gdk::Screen::get_default();
auto css_provider = Gtk::CssProvider::get_named(Singleton::Config::window()->theme_name, Singleton::Config::window()->theme_variant);
//TODO: add check if theme exists, or else write error to Singleton::terminal()
style_context->add_provider_for_screen(screen, css_provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
css_provider->load_from_path(Singleton::theme_dir() + Singleton::Config::theme()->current_theme());
}
int main(int argc, char *argv[]) {

2
src/juci.h

@ -11,7 +11,7 @@ class app : public Gtk::Application {
private:
std::unique_ptr<Window> window;
std::string directory;
std::vector<std::string> directories;
std::vector<std::string> files;
};

4
src/notebook.cc

@ -55,7 +55,7 @@ void Notebook::open(const boost::filesystem::path &file_path) {
auto language=Source::guess_language(file_path);
if(language && (language->get_id()=="chdr" || language->get_id()=="c" || language->get_id()=="cpp" || language->get_id()=="objc")) {
boost::filesystem::path project_path;
if(directories.cmake && directories.cmake->project_path!="")
if(directories.cmake && directories.cmake->project_path!="" && file_path.string().substr(0, directories.cmake->project_path.string().size())==directories.cmake->project_path.string())
project_path=directories.cmake->project_path;
else {
project_path=file_path.parent_path();
@ -119,7 +119,7 @@ bool Notebook::save(int page) {
//If CMakeLists.txt have been modified:
//TODO: recreate cmake even without directories open?
if(view->file_path.filename()=="CMakeLists.txt") {
if(directories.cmake && directories.cmake->project_path!="" && view->file_path>=directories.cmake->project_path && CMake::create_compile_commands(directories.cmake->project_path)) {
if(directories.cmake && directories.cmake->project_path!="" && view->file_path.string().substr(0, directories.cmake->project_path.string().size())==directories.cmake->project_path.string() && CMake::create_compile_commands(directories.cmake->project_path)) {
directories.open_folder();
for(auto source_view: source_views) {
if(auto source_clang_view=dynamic_cast<Source::ClangView*>(source_view)) {

3
src/selectiondialog.cc

@ -91,8 +91,7 @@ void SelectionDialogBase::update_tooltips() {
tooltips=std::unique_ptr<Tooltips>(new Tooltips());
auto get_tooltip_buffer=[this, tooltip_text]() {
auto tooltip_buffer=Gtk::TextBuffer::create(text_view.get_buffer()->get_tag_table());
//TODO: Insert newlines to tooltip_text (use 80 chars, then newline?)
tooltip_buffer->insert_at_cursor(tooltip_text);
tooltip_buffer->insert_with_tag(tooltip_buffer->get_insert()->get_iter(), tooltip_text, "def:note");
return tooltip_buffer;
};
tooltips->emplace_back(get_tooltip_buffer, text_view, text_view.get_buffer()->create_mark(start_mark->get_iter()), text_view.get_buffer()->create_mark(text_view.get_buffer()->get_insert()->get_iter()));

4
src/singletons.cc

@ -1,8 +1,8 @@
#include "singletons.h"
std::unique_ptr<Source::Config> Singleton::Config::source_=std::unique_ptr<Source::Config>(new Source::Config());
std::unique_ptr<Directories::Config> Singleton::Config::directories_=std::unique_ptr<Directories::Config>(new Directories::Config());std::unique_ptr<Terminal::Config> Singleton::Config::terminal_=std::unique_ptr<Terminal::Config>(new Terminal::Config());
std::unique_ptr<Theme::Config> Singleton::Config::theme_ = std::unique_ptr<Theme::Config>(new Theme::Config());
std::unique_ptr<Directories::Config> Singleton::Config::directories_=std::unique_ptr<Directories::Config>(new Directories::Config());
std::unique_ptr<Terminal::Config> Singleton::Config::terminal_=std::unique_ptr<Terminal::Config>(new Terminal::Config());
std::unique_ptr<Window::Config> Singleton::Config::window_ = std::unique_ptr<Window::Config>(new Window::Config());
std::unique_ptr<Terminal> Singleton::terminal_=std::unique_ptr<Terminal>();

4
src/singletons.h

@ -7,7 +7,6 @@
#include "directories.h"
#include "terminal.h"
#include "notebook.h"
#include "theme.h"
#include "menu.h"
#include <gtkmm.h>
#include <string>
@ -18,19 +17,16 @@ public:
public:
static Source::Config *source() {return source_.get();}
static Directories::Config *directories() {return directories_.get();}
static Theme::Config *theme() { return theme_.get(); }
static Window::Config *window() { return window_.get(); }
static Terminal::Config *terminal() {return terminal_.get();}
private:
static std::unique_ptr<Source::Config> source_;
static std::unique_ptr<Theme::Config> theme_;
static std::unique_ptr<Window::Config> window_;
static std::unique_ptr<Directories::Config> directories_;
static std::unique_ptr<Terminal::Config> terminal_;
};
static std::string config_dir() { return std::string(getenv("HOME")) + "/.juci/config/"; }
static std::string theme_dir() { return std::string(getenv("HOME")) + "/.juci/gtk-themes/"; }
static std::string log_dir() { return std::string(getenv("HOME")) + "/.juci/log/"; }
static std::string style_dir() { return std::string(getenv("HOME")) + "/.juci/styles/"; }
static Terminal *terminal();

226
src/source.cc

@ -26,9 +26,10 @@ Glib::RefPtr<Gsv::Language> Source::guess_language(const boost::filesystem::path
auto language=language_manager->guess_language(file_path.string(), content_type);
if(!language) {
auto filename=file_path.filename().string();
auto extension=file_path.extension();
if(filename=="CMakeLists.txt")
language=language_manager->get_language("cmake");
else if(filename=="Makefile")
language=language_manager->get_language("makefile");
}
return language;
}
@ -39,7 +40,8 @@ Glib::RefPtr<Gsv::Language> Source::guess_language(const boost::filesystem::path
Source::View::View(const boost::filesystem::path &file_path): file_path(file_path) {
set_smart_home_end(Gsv::SMART_HOME_END_BEFORE);
get_source_buffer()->begin_not_undoable_action();
juci::filesystem::read(file_path, get_buffer());
if(!juci::filesystem::read(file_path, get_buffer()))
Singleton::terminal()->print("Error: "+file_path.string()+" is not a valid UTF-8 file.\n");
get_source_buffer()->end_not_undoable_action();
get_buffer()->place_cursor(get_buffer()->get_iter_at_offset(0));
search_settings = gtk_source_search_settings_new();
@ -56,18 +58,23 @@ Source::View::View(const boost::filesystem::path &file_path): file_path(file_pat
//TODO: (gtkmm's Gtk::Object has connect_property_changed, so subclassing this might be an idea)
g_signal_connect(search_context, "notify::occurrences-count", G_CALLBACK(search_occurrences_updated), this);
// style
//TODO: Move this to notebook? Might take up too much memory doing this for every tab.
auto style_scheme_manager=Gsv::StyleSchemeManager::get_default();
style_scheme_manager->prepend_search_path(Singleton::style_dir());
auto scheme = style_scheme_manager->get_scheme(Singleton::Config::theme()->theme);
if(Singleton::Config::source()->style.size()>0) {
auto scheme = style_scheme_manager->get_scheme(Singleton::Config::source()->style);
if(scheme) {
get_source_buffer()->set_style_scheme(scheme);
if(scheme)
get_source_buffer()->set_style_scheme(scheme);
else
Singleton::terminal()->print("Error: Could not find gtksourceview style: "+Singleton::Config::source()->style+'\n');
}
property_highlight_current_line() = Singleton::Config::source()->gsv["highlight_current_line"] == "true";
property_show_line_numbers() = Singleton::Config::source()->gsv["show_line_numbers"] == "true";
property_highlight_current_line() = Singleton::Config::source()->highlight_current_line;
property_show_line_numbers() = Singleton::Config::source()->show_line_numbers;
if(Singleton::Config::source()->font.size()>0)
override_font(Pango::FontDescription(Singleton::Config::source()->font));
}
void Source::View::search_occurrences_updated(GtkWidget* widget, GParamSpec* property, gpointer data) {
@ -148,7 +155,7 @@ void Source::View::paste() {
auto line=get_line_before_insert();
std::smatch sm;
std::string prefix_tabs;
if(std::regex_match(line, sm, spaces_regex) && sm[2].str().size()==0) {
if(!get_buffer()->get_has_selection() && std::regex_match(line, sm, spaces_regex) && sm[2].str().size()==0) {
prefix_tabs=sm[1].str();
Glib::ustring::size_type start_line=0;
@ -388,50 +395,82 @@ clang::Index Source::ClangViewParse::clang_index(0, 0);
Source::ClangViewParse::ClangViewParse(const boost::filesystem::path &file_path, const boost::filesystem::path& project_path):
Source::View(file_path), project_path(project_path) {
for (auto &item : Singleton::Config::source()->tags) {
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;
}
auto scheme = get_source_buffer()->get_style_scheme();
auto tag_table=get_buffer()->get_tag_table();
for (auto &item : Singleton::Config::source()->clang_types) {
if(!tag_table->lookup(item.second)) {
auto style = scheme->get_style(item.second);
auto tag = get_source_buffer()->create_tag(item.second);
if (style) {
DEBUG("Style " + item.second + " found in style " + scheme->get_name());
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());
}
}
INFO("Tagtable filled");
//Create underline color tags for diagnostic warnings and errors:
auto diagnostic_tag=get_buffer()->get_tag_table()->lookup("diagnostic_warning");
auto diagnostic_tag_underline=Gtk::TextTag::create("diagnostic_warning_underline");
get_buffer()->get_tag_table()->add(diagnostic_tag_underline);
diagnostic_tag_underline->property_underline()=Pango::Underline::UNDERLINE_ERROR;
auto tag_class=G_OBJECT_GET_CLASS(diagnostic_tag_underline->gobj()); //For older GTK+ 3 versions:
auto param_spec=g_object_class_find_property(tag_class, "underline-rgba");
if(param_spec!=NULL) {
diagnostic_tag_underline->set_property("underline-rgba", diagnostic_tag->property_foreground_rgba().get_value());
//Create tags for diagnostic warnings and errors:
auto style=scheme->get_style("def:warning");
auto diagnostic_tag=get_source_buffer()->create_tag("def:warning");
auto diagnostic_tag_underline=get_source_buffer()->create_tag("def:warning_underline");
if(style && (style->property_foreground_set() || style->property_background_set())) {
Glib::ustring warning_property;
if(style->property_foreground_set()) {
warning_property=style->property_foreground().get_value();
diagnostic_tag->property_foreground() = warning_property;
}
else if(style->property_background_set())
warning_property=style->property_background().get_value();
diagnostic_tag_underline->property_underline()=Pango::Underline::UNDERLINE_ERROR;
auto tag_class=G_OBJECT_GET_CLASS(diagnostic_tag_underline->gobj()); //For older GTK+ 3 versions:
auto param_spec=g_object_class_find_property(tag_class, "underline-rgba");
if(param_spec!=NULL) {
diagnostic_tag_underline->set_property("underline-rgba", Gdk::RGBA(warning_property));
}
}
diagnostic_tag=get_buffer()->get_tag_table()->lookup("diagnostic_error");
diagnostic_tag_underline=Gtk::TextTag::create("diagnostic_error_underline");
get_buffer()->get_tag_table()->add(diagnostic_tag_underline);
diagnostic_tag_underline->property_underline()=Pango::Underline::UNDERLINE_ERROR;
tag_class=G_OBJECT_GET_CLASS(diagnostic_tag_underline->gobj()); //For older GTK+ 3 versions:
param_spec=g_object_class_find_property(tag_class, "underline-rgba");
if(param_spec!=NULL) {
diagnostic_tag_underline->set_property("underline-rgba", diagnostic_tag->property_foreground_rgba().get_value());
style=scheme->get_style("def:error");
diagnostic_tag=get_source_buffer()->create_tag("def:error");
diagnostic_tag_underline=get_source_buffer()->create_tag("def:error_underline");
if(style && (style->property_foreground_set() || style->property_background_set())) {
Glib::ustring error_property;
if(style->property_foreground_set()) {
error_property=style->property_foreground().get_value();
diagnostic_tag->property_foreground() = error_property;
}
else if(style->property_background_set())
error_property=style->property_background().get_value();
diagnostic_tag_underline->property_underline()=Pango::Underline::UNDERLINE_ERROR;
auto tag_class=G_OBJECT_GET_CLASS(diagnostic_tag_underline->gobj()); //For older GTK+ 3 versions:
auto param_spec=g_object_class_find_property(tag_class, "underline-rgba");
if(param_spec!=NULL) {
diagnostic_tag_underline->set_property("underline-rgba", Gdk::RGBA(error_property));
}
}
//TODO: clear tag_class and param_spec?
//Add tooltip foreground and background
style = scheme->get_style("def:note");
auto note_tag=get_source_buffer()->create_tag("def:note_background");
if(style->property_background_set()) {
note_tag->property_background()=style->property_background();
}
note_tag=get_source_buffer()->create_tag("def:note");
if(style->property_foreground_set()) {
note_tag->property_foreground()=style->property_foreground();
}
parsing_in_progress=Singleton::terminal()->print_in_progress("Parsing "+file_path.string());
//GTK-calls must happen in main thread, so the parse_thread
//sends signals to the main thread that it is to call the following functions:
@ -482,8 +521,6 @@ void Source::ClangViewParse::init_parse() {
parse_thread_stop=false;
int start_offset = get_source_buffer()->begin().get_offset();
int end_offset = get_source_buffer()->end().get_offset();
auto buffer_map=get_buffer_map();
//Remove includes for first parse for initial syntax highlighting
auto& str=buffer_map[file_path.string()];
@ -498,9 +535,7 @@ void Source::ClangViewParse::init_parse() {
}
pos++;
}
init_syntax_highlighting(buffer_map,
start_offset,
end_offset);
init_syntax_highlighting(buffer_map);
update_syntax();
set_status("parsing...");
@ -527,11 +562,7 @@ void Source::ClangViewParse::init_parse() {
});
}
void Source::ClangViewParse::
init_syntax_highlighting(const std::map<std::string, std::string>
&buffers,
int start_offset,
int end_offset) {
void Source::ClangViewParse::init_syntax_highlighting(const std::map<std::string, std::string> &buffers) {
std::vector<string> arguments = get_compilation_commands();
clang_tu = std::unique_ptr<clang::TranslationUnit>(new clang::TranslationUnit(clang_index,
file_path.string(),
@ -542,7 +573,7 @@ init_syntax_highlighting(const std::map<std::string, std::string>
std::map<std::string, std::string> Source::ClangViewParse::get_buffer_map() const {
std::map<std::string, std::string> buffer_map;
buffer_map[file_path.string()]=get_source_buffer()->get_text().raw();
buffer_map[file_path.string()]=get_source_buffer()->get_text();
return buffer_map;
}
@ -583,16 +614,20 @@ std::vector<std::string> Source::ClangViewParse::get_compilation_commands() {
void Source::ClangViewParse::update_syntax() {
std::vector<Source::Range> ranges;
for (auto &token : *clang_tokens) {
if(token.get_kind()==0) // PunctuationToken
ranges.emplace_back(token.offsets.first, token.offsets.second, (int) token.get_cursor().get_kind());
else if(token.get_kind()==1) // KeywordToken
ranges.emplace_back(token.offsets.first, token.offsets.second, 702);
else if(token.get_kind()==2) // IdentifierToken
ranges.emplace_back(token.offsets.first, token.offsets.second, (int) token.get_cursor().get_kind());
//if(token.get_kind()==0) // PunctuationToken
//ranges.emplace_back(token.offsets, (int) token.get_cursor().get_kind());
if(token.get_kind()==1) // KeywordToken
ranges.emplace_back(token.offsets, 702);
else if(token.get_kind()==2) {// IdentifierToken
auto kind=(int)token.get_cursor().get_kind();
if(kind==101 || kind==102)
kind=(int)token.get_cursor().get_referenced().get_kind();
ranges.emplace_back(token.offsets, kind); //TODO: Need to get type of referenced token if any
}
else if(token.get_kind()==3) // LiteralToken
ranges.emplace_back(token.offsets.first, token.offsets.second, 109);
ranges.emplace_back(token.offsets, 109);
else if(token.get_kind()==4) // CommentToken
ranges.emplace_back(token.offsets.first, token.offsets.second, 705);
ranges.emplace_back(token.offsets, 705);
}
if (ranges.empty() || ranges.size() == 0) {
return;
@ -604,40 +639,39 @@ void Source::ClangViewParse::update_syntax() {
for (auto &range : ranges) {
auto type = boost::lexical_cast<std::string>(range.kind);
try {
last_syntax_tags.emplace(Singleton::Config::source()->types.at(type));
last_syntax_tags.emplace(Singleton::Config::source()->clang_types.at(type));
} catch (std::exception) {
//cout << range.kind << ": " << range.offsets.first.line << ", " << range.offsets.first.index << endl; //TODO: remove
continue;
}
Gtk::TextIter begin_iter = buffer->get_iter_at_offset(range.start_offset);
Gtk::TextIter end_iter = buffer->get_iter_at_offset(range.end_offset);
buffer->apply_tag_by_name(Singleton::Config::source()->types.at(type),
begin_iter, end_iter);
Gtk::TextIter begin_iter = buffer->get_iter_at_line_index(range.offsets.first.line-1, range.offsets.first.index-1);
Gtk::TextIter end_iter = buffer->get_iter_at_line_index(range.offsets.second.line-1, range.offsets.second.index-1);
buffer->apply_tag_by_name(Singleton::Config::source()->clang_types.at(type), begin_iter, end_iter);
}
}
void Source::ClangViewParse::update_diagnostics() {
diagnostic_tooltips.clear();
get_buffer()->remove_tag_by_name("diagnostic_warning_underline", get_buffer()->begin(), get_buffer()->end());
get_buffer()->remove_tag_by_name("diagnostic_error_underline", get_buffer()->begin(), get_buffer()->end());
get_buffer()->remove_tag_by_name("def:warning_underline", get_buffer()->begin(), get_buffer()->end());
get_buffer()->remove_tag_by_name("def:error_underline", get_buffer()->begin(), get_buffer()->end());
auto diagnostics=clang_tu->get_diagnostics();
for(auto &diagnostic: diagnostics) {
if(diagnostic.path==file_path.string()) {
auto start=get_buffer()->get_iter_at_offset(diagnostic.offsets.first);
auto end=get_buffer()->get_iter_at_offset(diagnostic.offsets.second);
auto start=get_buffer()->get_iter_at_line_index(diagnostic.offsets.first.line-1, diagnostic.offsets.first.index-1);
auto end=get_buffer()->get_iter_at_line_index(diagnostic.offsets.second.line-1, diagnostic.offsets.second.index-1);
std::string diagnostic_tag_name;
if(diagnostic.severity<=CXDiagnostic_Warning)
diagnostic_tag_name="diagnostic_warning";
diagnostic_tag_name="def:warning";
else
diagnostic_tag_name="diagnostic_error";
diagnostic_tag_name="def:error";
auto spelling=diagnostic.spelling;
auto severity_spelling=diagnostic.severity_spelling;
auto create_tooltip_buffer=[this, spelling, severity_spelling, diagnostic_tag_name]() {
auto tooltip_buffer=Gtk::TextBuffer::create(get_buffer()->get_tag_table());
tooltip_buffer->insert_with_tag(tooltip_buffer->get_insert()->get_iter(), severity_spelling, diagnostic_tag_name);
tooltip_buffer->insert_at_cursor(":\n"+spelling);
tooltip_buffer->insert_with_tag(tooltip_buffer->get_insert()->get_iter(), ":\n"+spelling, "def:note");
//TODO: Insert newlines to clang_tu->diagnostics[c].spelling (use 80 chars, then newline?)
return tooltip_buffer;
};
@ -652,14 +686,14 @@ void Source::ClangViewParse::update_types() {
type_tooltips.clear();
for(auto &token: *clang_tokens) {
if(token.get_kind()==clang::Token_Identifier && token.has_type()) {
auto start=get_buffer()->get_iter_at_offset(token.offsets.first);
auto end=get_buffer()->get_iter_at_offset(token.offsets.second);
auto start=get_buffer()->get_iter_at_line_index(token.offsets.first.line-1, token.offsets.first.index-1);
auto end=get_buffer()->get_iter_at_line_index(token.offsets.second.line-1, token.offsets.second.index-1);
auto create_tooltip_buffer=[this, &token]() {
auto tooltip_buffer=Gtk::TextBuffer::create(get_buffer()->get_tag_table());
tooltip_buffer->insert_at_cursor("Type: "+token.get_type());
tooltip_buffer->insert_with_tag(tooltip_buffer->get_insert()->get_iter(), "Type: "+token.get_type(), "def:note");
auto brief_comment=token.get_brief_comments();
if(brief_comment!="")
tooltip_buffer->insert_at_cursor("\n\n"+brief_comment);
tooltip_buffer->insert_with_tag(tooltip_buffer->get_insert()->get_iter(), "\n\n"+brief_comment, "def:note");
return tooltip_buffer;
};
@ -1069,10 +1103,12 @@ Source::ClangViewAutocomplete(file_path, project_path) {
get_token=[this]() -> std::string {
if(clang_readable) {
auto iter=get_buffer()->get_insert()->get_iter();
auto line=(unsigned)iter.get_line();
auto index=(unsigned)iter.get_line_index();
for(auto &token: *clang_tokens) {
if(token.get_kind()==clang::Token_Identifier && token.has_type()) {
auto insert_offset=(unsigned)get_buffer()->get_insert()->get_iter().get_offset();
if(insert_offset>=token.offsets.first && insert_offset<=token.offsets.second) {
if(line==token.offsets.first.line-1 && index>=token.offsets.first.index-1 && index <=token.offsets.second.index-1) {
auto referenced=token.get_cursor().get_referenced();
if(referenced)
return referenced.get_usr();
@ -1085,10 +1121,12 @@ Source::ClangViewAutocomplete(file_path, project_path) {
get_token_name=[this]() -> std::string {
if(clang_readable) {
auto iter=get_buffer()->get_insert()->get_iter();
auto line=(unsigned)iter.get_line();
auto index=(unsigned)iter.get_line_index();
for(auto &token: *clang_tokens) {
if(token.get_kind()==clang::Token_Identifier && token.has_type()) {
auto insert_offset=(unsigned)get_buffer()->get_insert()->get_iter().get_offset();
if(insert_offset>=token.offsets.first && insert_offset<=token.offsets.second) {
if(line==token.offsets.first.line-1 && index>=token.offsets.first.index-1 && index <=token.offsets.second.index-1) {
return token.get_spelling();
}
}
@ -1103,7 +1141,7 @@ Source::ClangViewAutocomplete(file_path, project_path) {
get_buffer()->remove_tag(similar_tokens_tag, get_buffer()->begin(), get_buffer()->end());
auto offsets=clang_tokens->get_similar_token_offsets(usr);
for(auto &offset: offsets) {
get_buffer()->apply_tag(similar_tokens_tag, get_buffer()->get_iter_at_offset(offset.first), get_buffer()->get_iter_at_offset(offset.second));
get_buffer()->apply_tag(similar_tokens_tag, get_buffer()->get_iter_at_line_index(offset.first.line-1, offset.first.index-1), get_buffer()->get_iter_at_line_index(offset.second.line-1, offset.second.index-1));
}
last_similar_tokens_tagged=usr;
}
@ -1120,7 +1158,7 @@ Source::ClangViewAutocomplete(file_path, project_path) {
auto offsets=clang_tokens->get_similar_token_offsets(usr);
std::vector<std::pair<Glib::RefPtr<Gtk::TextMark>, Glib::RefPtr<Gtk::TextMark> > > marks;
for(auto &offset: offsets) {
marks.emplace_back(get_buffer()->create_mark(get_buffer()->get_iter_at_offset(offset.first)), get_buffer()->create_mark(get_buffer()->get_iter_at_offset(offset.second)));
marks.emplace_back(get_buffer()->create_mark(get_buffer()->get_iter_at_line_index(offset.first.line-1, offset.first.index-1)), get_buffer()->create_mark(get_buffer()->get_iter_at_line_index(offset.second.line-1, offset.second.index-1)));
number++;
}
get_source_buffer()->begin_user_action();
@ -1145,12 +1183,14 @@ Source::ClangViewAutocomplete(file_path, project_path) {
});
get_declaration_location=[this](){
std::pair<std::string, unsigned> location;
std::pair<std::string, clang::Offset> location;
if(clang_readable) {
auto iter=get_buffer()->get_insert()->get_iter();
auto line=(unsigned)iter.get_line();
auto index=(unsigned)iter.get_line_index();
for(auto &token: *clang_tokens) {
if(token.get_kind()==clang::Token_Identifier && token.has_type()) {
auto insert_offset=(unsigned)get_buffer()->get_insert()->get_iter().get_offset();
if(insert_offset>=token.offsets.first && insert_offset<=token.offsets.second) {
if(line==token.offsets.first.line-1 && index>=token.offsets.first.index-1 && index <=token.offsets.second.index-1) {
auto referenced=token.get_cursor().get_referenced();
if(referenced) {
location.first=referenced.get_source_location().get_path();
@ -1167,7 +1207,7 @@ Source::ClangViewAutocomplete(file_path, project_path) {
goto_method=[this](){
if(clang_readable) {
selection_dialog=std::unique_ptr<SelectionDialog>(new SelectionDialog(*this, get_buffer()->create_mark(get_buffer()->get_insert()->get_iter())));
auto rows=std::make_shared<std::unordered_map<std::string, unsigned> >();
auto rows=std::make_shared<std::unordered_map<std::string, clang::Offset> >();
auto methods=clang_tokens->get_cxx_methods();
if(methods.size()==0)
return;
@ -1178,7 +1218,7 @@ Source::ClangViewAutocomplete(file_path, project_path) {
//TODO see if rows gets destroyed when selection_dialog gets destroyed.
selection_dialog->on_select=[this, rows](const std::string& selected, bool hide_window) {
auto offset=rows->at(selected);
get_buffer()->place_cursor(get_buffer()->get_iter_at_offset(offset));
get_buffer()->place_cursor(get_buffer()->get_iter_at_line_index(offset.line-1, offset.index-1));
scroll_to(get_buffer()->get_insert(), 0.0, 1.0, 0.5);
delayed_tooltips_connection.disconnect();
};

26
src/source.h

@ -20,18 +20,21 @@ namespace Source {
class Config {
public:
unsigned tab_size = 2;
char tab_char = ' ';
std::string tab = " ";
std::unordered_map<std::string, std::string> tags, types, gsv;
std::string style;
std::string font;
unsigned tab_size;
char tab_char;
std::string tab;
bool highlight_current_line;
bool show_line_numbers;
std::unordered_map<std::string, std::string> clang_types;
};
class Range {
public:
Range(unsigned start_offset, unsigned end_offset, int kind):
start_offset(start_offset), end_offset(end_offset), kind(kind) {}
unsigned start_offset;
unsigned end_offset;
Range(std::pair<clang::Offset, clang::Offset> offsets, int kind):
offsets(offsets), kind(kind) {}
std::pair<clang::Offset, clang::Offset> offsets;
int kind;
};
@ -60,7 +63,7 @@ namespace Source {
boost::filesystem::path file_path;
std::function<std::pair<std::string, unsigned>()> get_declaration_location;
std::function<std::pair<std::string, clang::Offset>()> get_declaration_location;
std::function<void()> goto_method;
std::function<std::string()> get_token;
std::function<std::string()> get_token_name;
@ -109,10 +112,7 @@ namespace Source {
private:
std::map<std::string, std::string> get_buffer_map() const;
// inits the syntax highligthing on file open
void init_syntax_highlighting(const std::map<std::string, std::string>
&buffers,
int start_offset,
int end_offset);
void init_syntax_highlighting(const std::map<std::string, std::string> &buffers);
int reparse(const std::map<std::string, std::string> &buffers);
void update_syntax();
std::set<std::string> last_syntax_tags;

11
src/sourcefile.cc

@ -20,8 +20,15 @@ bool juci::filesystem::read(const std::string &path, Glib::RefPtr<Gtk::TextBuffe
if(input) {
std::vector<char> buffer(buffer_size);
size_t read_length;
while((read_length=input.read(&buffer[0], buffer_size).gcount())>0)
text_buffer->insert_at_cursor(&buffer[0], &buffer[read_length]);
while((read_length=input.read(&buffer[0], buffer_size).gcount())>0) {
auto ustr=Glib::ustring(std::string(&buffer[0], read_length));
if(ustr.validate())
text_buffer->insert_at_cursor(ustr);
else {
input.close();
return false;
}
}
input.close();
return true;
}

4
src/terminal.cc

@ -140,7 +140,7 @@ int Terminal::execute(const std::string &command, const boost::filesystem::path
std::string cd_path_and_command;
if(path!="") {
//TODO: Windows...
cd_path_and_command="cd "+path.string()+" && "+command;
cd_path_and_command="cd \""+path.string()+"\" && "+command;
}
else
cd_path_and_command=command;
@ -193,7 +193,7 @@ void Terminal::async_execute(const std::string &command, const boost::filesystem
if(path!="") {
//TODO: Windows...
cd_path_and_command="cd "+path.string()+" && "+command;
cd_path_and_command="cd \""+path.string()+"\" && "+command;
}
else
cd_path_and_command=command;

14
src/theme.h

@ -1,14 +0,0 @@
#ifndef JUCI_THEME_H_
#define JUCI_THEME_H_
#include <string>
namespace Theme {
class Config {
public:
std::string current_theme() { return theme + "/" + main; }
std::string theme, main;
};
}
#endif // JUCI_THEME_H_

2
src/tooltips.cc

@ -54,6 +54,8 @@ void Tooltip::adjust(bool disregard_drawn) {
tooltip_widget=std::unique_ptr<Gtk::TextView>(new Gtk::TextView(create_tooltip_buffer()));
wrap_lines(tooltip_widget->get_buffer());
tooltip_widget->set_editable(false);
auto tag=text_view.get_buffer()->get_tag_table()->lookup("def:note_background");
tooltip_widget->override_background_color(tag->property_background_rgba());
window->add(*tooltip_widget);
auto layout=Pango::Layout::create(tooltip_widget->get_pango_context());

20
src/window.cc

@ -194,7 +194,7 @@ void Window::create_menu() {
auto location=notebook.get_current_view()->get_declaration_location();
if(location.first.size()>0) {
notebook.open(location.first);
notebook.get_current_view()->get_buffer()->place_cursor(notebook.get_current_view()->get_buffer()->get_iter_at_offset(location.second));
notebook.get_current_view()->get_buffer()->place_cursor(notebook.get_current_view()->get_buffer()->get_iter_at_line_index(location.second.line-1, location.second.index-1));
while(gtk_events_pending())
gtk_main_iteration();
notebook.get_current_view()->scroll_to(notebook.get_current_view()->get_buffer()->get_insert(), 0.0, 1.0, 0.5);
@ -235,7 +235,16 @@ void Window::create_menu() {
if(exit_code==EXIT_SUCCESS) {
compile_success();
//TODO: Windows...
Singleton::terminal()->async_execute(executable_path.string(), project_path, [this, executable_path](int exit_code){
auto executable_path_spaces_fixed=executable_path.string();
char last_char=0;
for(size_t c=0;c<executable_path_spaces_fixed.size();c++) {
if(last_char!='\\' && executable_path_spaces_fixed[c]==' ') {
executable_path_spaces_fixed.insert(c, "\\");
c++;
}
last_char=executable_path_spaces_fixed[c];
}
Singleton::terminal()->async_execute(executable_path_spaces_fixed, project_path, [this, executable_path](int exit_code){
Singleton::terminal()->async_print(executable_path.string()+" returned: "+boost::lexical_cast<std::string>(exit_code)+'\n');
});
}
@ -389,10 +398,13 @@ void Window::new_cpp_project_dialog() {
dialog.add_button("Select", Gtk::RESPONSE_OK);
int result = dialog.run();
if(result==Gtk::RESPONSE_OK) {
boost::filesystem::path project_path=dialog.get_filename();
auto project_name=project_path.filename().string();
for(size_t c=0;c<project_name.size();c++) {
if(project_name[c]==' ')
project_name[c]='_';
}
auto cmakelists_path=project_path;
cmakelists_path+="/CMakeLists.txt";
auto cpp_main_path=project_path;
@ -405,7 +417,7 @@ void Window::new_cpp_project_dialog() {
Singleton::terminal()->print("Error: "+cpp_main_path.string()+" already exists.\n");
return;
}
std::string cmakelists="cmake_minimum_required(VERSION 2.8)\n\nproject("+project_name+")\n\nset(CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} -std=c++1y\")\n\nadd_executable("+project_name+" main.cpp)\n";
std::string cmakelists="cmake_minimum_required(VERSION 2.8)\n\nproject("+project_name+")\n\nset(CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} -std=c++1y -Wall\")\n\nadd_executable("+project_name+" main.cpp)\n";
std::string cpp_main="#include <iostream>\n\nusing namespace std;\n\nint main() {\n cout << \"Hello World!\" << endl;\n\n return 0;\n}\n";
if(juci::filesystem::write(cmakelists_path, cmakelists) && juci::filesystem::write(cpp_main_path, cpp_main)) {
directories.open_folder(project_path);

2
src/window.h

@ -16,6 +16,8 @@ public:
Notebook notebook;
class Config {
public:
std::string theme_name;
std::string theme_variant;
boost::property_tree::ptree keybindings;
};

Loading…
Cancel
Save