Browse Source

Fix namespace and add proof of concept

master
Jørgen Lien Sellæg 11 years ago
parent
commit
4d215386ff
  1. 43
      juci/source.cc
  2. 10
      juci/source.h

43
juci/source.cc

@ -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) {
ApplyTheme(theme);
/* ApplyTheme(theme);
Glib::RefPtr<Gtk::TextBuffer> buffer = get_buffer();
for (auto &loc : locations) {
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),
begin_iter, end_iter);
}
}
}*/
}
// Source::View::Theme::tagtable()
// returns a const refrence to the tagtable
@ -108,7 +108,8 @@ void Source::Theme::SetTagTable(
//// Model ////
///////////////
Source::Model::Model() :
theme_() {/*
theme_() {
/*
std::cout << "Model constructor run" << std::endl;
boost::property_tree::ptree 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::
SetSourceLocations(const std::vector<Clang::SourceLocation> &locations) {
SetSourceLocations(const std::vector<clang::SourceLocation> &locations) {
locations_ = locations;
}
////////////////////
@ -178,14 +179,30 @@ void Source::Controller::OnNewEmptyFile() {
s.save("");
}
void Source::Controller::OnOpenFile(const string &filename) {
sourcefile s(filename);
view().get_buffer()->set_text(s.get_content());
int linums = view().get_buffer()->end().get_line();
int offset = view().get_buffer()->end().get_line_offset();
Clang::TranslationUnit tu(filename.c_str(), linums, offset);
model().SetSourceLocations(tu.getSourceLocations());
view().OnOpenFile(model().getSourceLocations(), model().theme());
void Source::Controller::OnOpenFile(const string &filepath) {
sourcefile s(filepath);
buffer()->set_text(s.get_content());
int start_offset = buffer()->begin().get_offset();
int end_offset = buffer()->end().get_offset();
clang::TranslationUnit tu(true, filepath);
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() {

10
juci/source.h

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

Loading…
Cancel
Save