#ifndef JUCI_SOURCE_H_ #define JUCI_SOURCE_H_ #include #include #include #include "gtkmm.h" #include "clangmm.h" #include #include #include #include #include "gtksourceviewmm.h" namespace Notebook { class Controller; } namespace Source { class Config { public: const std::unordered_map& tagtable() const; const std::unordered_map& typetable() const; std::vector& extensiontable(); void SetTagTable(const std::unordered_map &tagtable); void InsertTag(const std::string &key, const std::string &value); void SetTypeTable(const std::unordered_map &tagtable); void InsertType(const std::string &key, const std::string &value); void InsertExtension(const std::string &ext); std::vector extensiontable_; bool legal_extension(std::string e) const ; // TODO: Have to clean away all the simple setter and getter methods at some point. It creates too much unnecessary code unsigned tab_size; bool show_line_numbers, highlight_current_line; std::string tab, background, font; private: std::unordered_map tagtable_, typetable_; }; // class Config class Location { public: Location(const Location &location); Location(int line_number, int column_offset); int line_number() const { return line_number_; } int column_offset() const { return column_offset_; } private: int line_number_; int column_offset_; }; class Range { public: Range(const Location &start, const Location &end, int kind); Range(const Range &org); const Location& start() const { return start_; } const Location& end() const { return end_; } int kind() const { return kind_; } private: Location start_; Location end_; int kind_; }; class View : public Gsv::View { public: View(); virtual ~View() { } void OnLineEdit(const std::vector &locations, const Config &config); void OnUpdateSyntax(const std::vector &locations, const Config &config); std::string GetLine(size_t line_number); std::string GetLineBeforeInsert(); }; // class View class AutoCompleteChunk { public: explicit AutoCompleteChunk(const clang::CompletionChunk &chunk) : chunk_(chunk.chunk()), kind_(chunk.kind()) { } const std::string& chunk() const { return chunk_; } const clang::CompletionChunkKind& kind() const { return kind_; } private: std::string chunk_; enum clang::CompletionChunkKind kind_; }; class AutoCompleteData { public: explicit AutoCompleteData(const std::vector &chunks) : chunks_(chunks) { } std::vector chunks_; }; class Controller; class Parser{ public: Parser(const std::vector > &controllers): controllers(controllers) {} ~Parser(); // inits the syntax highligthing on file open void InitSyntaxHighlighting(const std::string &filepath, const std::string &project_path, const std::map &buffers, int start_offset, int end_offset, clang::Index *index); std::vector get_autocomplete_suggestions(int line_number, int column); int ReParse(const std::map &buffers); std::vector ExtractTokens(int, int); std::string file_path; std::string project_path; static clang::Index clang_index; std::map get_buffer_map() const; std::mutex parsing_mutex; private: std::unique_ptr tu_; //use unique_ptr since it is not initialized in constructor void HighlightToken(clang::Token *token, std::vector *source_ranges, int token_kind); void HighlightCursor(clang::Token *token, std::vector *source_ranges); std::vector get_compilation_commands(); //controllers is needed here, no way around that I think const std::vector > &controllers; }; class Controller { public: Controller(const Source::Config &config, const std::vector > &controllers); ~Controller(); void OnNewEmptyFile(); void OnOpenFile(const std::string &filename); Glib::RefPtr buffer(); bool OnKeyPress(GdkEventKey* key); bool is_saved = false; //TODO: Is never set to false in Notebook::Controller bool is_changed = false; //TODO: Is never set to true Parser parser; View view; private: void OnLineEdit(); void OnSaveFile(); Glib::Dispatcher parse_done; Glib::Dispatcher parse_start; std::thread parse_thread; std::map parse_thread_buffer_map; std::mutex parse_thread_buffer_map_mutex; std::atomic parse_thread_go; std::atomic parse_thread_mapped; std::atomic parse_thread_stop; const Config& config; }; // class Controller } // namespace Source #endif // JUCI_SOURCE_H_