Browse Source

Fix namespace and add proof of concept

merge-requests/365/head
Jørgen Lien Sellæg 11 years ago
parent
commit
4d215386ff
  1. 49
      juci/source.cc
  2. 10
      juci/source.h

49
juci/source.cc

@ -15,7 +15,7 @@ Source::View::View() {
// returns the new line // returns the new line
string Source::View::UpdateLine() { string Source::View::UpdateLine() {
Gtk::TextIter line(get_buffer()->get_insert()->get_iter()); Gtk::TextIter line(get_buffer()->get_insert()->get_iter());
//std::cout << line.get_line() << std::endl; // std::cout << line.get_line() << std::endl;
// for each word --> check what it is --> apply appropriate tag // for each word --> check what it is --> apply appropriate tag
return ""; return "";
} }
@ -37,9 +37,9 @@ void Source::View::ApplyTheme(const Source::Theme &theme) {
} }
} }
void Source::View::OnOpenFile(std::vector<Clang::SourceLocation> &locations, void Source::View::OnOpenFile(std::vector<clang::SourceLocation> &locations,
const Source::Theme &theme) { const Source::Theme &theme) {
ApplyTheme(theme); /* ApplyTheme(theme);
Glib::RefPtr<Gtk::TextBuffer> buffer = get_buffer(); Glib::RefPtr<Gtk::TextBuffer> buffer = get_buffer();
for (auto &loc : locations) { for (auto &loc : locations) {
string type = std::to_string(loc.kind()); string type = std::to_string(loc.kind());
@ -69,7 +69,7 @@ void Source::View::OnOpenFile(std::vector<Clang::SourceLocation> &locations,
buffer->apply_tag_by_name(theme.typetable().at(type), buffer->apply_tag_by_name(theme.typetable().at(type),
begin_iter, end_iter); begin_iter, end_iter);
} }
} }*/
} }
// Source::View::Theme::tagtable() // Source::View::Theme::tagtable()
// returns a const refrence to the tagtable // returns a const refrence to the tagtable
@ -108,7 +108,8 @@ void Source::Theme::SetTagTable(
//// Model //// //// Model ////
/////////////// ///////////////
Source::Model::Model() : Source::Model::Model() :
theme_() {/* theme_() {
/*
std::cout << "Model constructor run" << std::endl; std::cout << "Model constructor run" << std::endl;
boost::property_tree::ptree pt; boost::property_tree::ptree pt;
boost::property_tree::json_parser::read_json("config.json", pt); boost::property_tree::json_parser::read_json("config.json", pt);
@ -140,7 +141,7 @@ void Source::Model::SetFilePath(const string &filepath) {
} }
void Source::Model:: void Source::Model::
SetSourceLocations(const std::vector<Clang::SourceLocation> &locations) { SetSourceLocations(const std::vector<clang::SourceLocation> &locations) {
locations_ = locations; locations_ = locations;
} }
//////////////////// ////////////////////
@ -150,7 +151,7 @@ SetSourceLocations(const std::vector<Clang::SourceLocation> &locations) {
// Source::Controller::Controller() // Source::Controller::Controller()
// Constructor for Controller // Constructor for Controller
Source::Controller::Controller() { Source::Controller::Controller() {
//std::cout << "Controller constructor run" << std::endl; // std::cout << "Controller constructor run" << std::endl;
view().get_buffer()->signal_changed().connect([this](){ view().get_buffer()->signal_changed().connect([this](){
this->OnLineEdit(); this->OnLineEdit();
}); });
@ -178,16 +179,32 @@ void Source::Controller::OnNewEmptyFile() {
s.save(""); s.save("");
} }
void Source::Controller::OnOpenFile(const string &filename) { void Source::Controller::OnOpenFile(const string &filepath) {
sourcefile s(filename); sourcefile s(filepath);
view().get_buffer()->set_text(s.get_content()); buffer()->set_text(s.get_content());
int linums = view().get_buffer()->end().get_line(); int start_offset = buffer()->begin().get_offset();
int offset = view().get_buffer()->end().get_line_offset(); int end_offset = buffer()->end().get_offset();
Clang::TranslationUnit tu(filename.c_str(), linums, offset);
model().SetSourceLocations(tu.getSourceLocations()); clang::TranslationUnit tu(true, filepath);
view().OnOpenFile(model().getSourceLocations(), model().theme()); clang::SourceLocation start(&tu, filepath, start_offset);
clang::SourceLocation end(&tu, filepath, end_offset);
clang::SourceRange range(&start, &end);
clang::Tokens tokens(&tu, &range);
std::vector<clang::Token> tks = tokens.tokens();
for (auto &t : tks) {
clang::SourceLocation loc = t.get_source_location(&tu);
unsigned line;
unsigned column;
loc.get_location_info(NULL, &line, &column, NULL);
std::cout << "Token line: " << line;
std::cout << ", column: " << column;
std::cout << ", kind: " << t.kind() << std::endl;
}
// model().SetSourceLocations(tu.getSourceLocations());
// view().OnOpenFile(model().getSourceLocations(), model().theme());
} }
Glib::RefPtr<Gtk::TextBuffer> Source::Controller::buffer(){ Glib::RefPtr<Gtk::TextBuffer> Source::Controller::buffer() {
return view().get_buffer(); return view().get_buffer();
} }

10
juci/source.h

@ -5,7 +5,7 @@
#include <vector> #include <vector>
#include <string> #include <string>
#include "gtkmm.h" #include "gtkmm.h"
#include <TranslationUnit.h> #include "clangmm.h"
using std::string; using std::string;
@ -30,7 +30,7 @@ namespace Source {
View(); View();
string UpdateLine(); string UpdateLine();
void ApplyTheme(const Theme &theme); void ApplyTheme(const Theme &theme);
void OnOpenFile(std::vector<Clang::SourceLocation> &locations, void OnOpenFile(std::vector<clang::SourceLocation> &locations,
const Theme &theme); const Theme &theme);
private: private:
string GetLine(const Gtk::TextIter &begin); string GetLine(const Gtk::TextIter &begin);
@ -43,15 +43,15 @@ namespace Source {
const string filepath(); const string filepath();
void SetFilePath(const string &filepath); void SetFilePath(const string &filepath);
void SetSourceLocations( void SetSourceLocations(
const std::vector<Clang::SourceLocation> &locations); const std::vector<clang::SourceLocation> &locations);
std::vector<Clang::SourceLocation>& getSourceLocations() { std::vector<clang::SourceLocation>& getSourceLocations() {
return locations_; return locations_;
} }
private: private:
Theme theme_; Theme theme_;
string filepath_; string filepath_;
std::vector<Clang::SourceLocation> locations_; std::vector<clang::SourceLocation> locations_;
}; };
class Controller { class Controller {

Loading…
Cancel
Save