Browse Source

Merge branch 'master' of bitbucket.org:cppit/juci into plugin

merge-requests/365/head
tedjk 11 years ago
parent
commit
3074734754
  1. 2
      juci/CMakeLists.txt
  2. 198
      juci/config.json
  3. 46
      juci/source.cc
  4. 3
      juci/source.h

2
juci/CMakeLists.txt

@ -4,7 +4,7 @@ set(module juci_to_python_api)
project (${project_name})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/cmake/Modules/")
INCLUDE(FindPkgConfig)

198
juci/config.json

@ -1,193 +1,19 @@
{
"colors": {
"text_color": "black",
"string" : "green"
"text_color": "#333333",
"string" : "#CC0000",
"namespace_ref" : "#990099",
"type" : "#0066FF",
"keyword": "blue",
"comment": "grey",
"own": "pink"
},
"syntax": {
"1": "text_color",
"2": "text_color",
"2": "text_color",
"3": "text_color",
"4": "text_color",
"5": "text_color",
"6": "text_color",
"7": "text_color",
"8": "text_color",
"9": "text_color",
"10": "text_color",
"11": "text_color",
"12": "text_color",
"13": "text_color",
"14": "text_color",
"15": "text_color",
"16": "text_color",
"17": "text_color",
"18": "text_color",
"19": "text_color",
"20": "text_color",
"21": "text_color",
"22": "text_color",
"23": "text_color",
"24": "text_color",
"25": "text_color",
"26": "text_color",
"27": "text_color",
"28": "text_color",
"29": "text_color",
"30": "text_color",
"31": "text_color",
"32": "text_color",
"33": "text_color",
"34": "text_color",
"35": "text_color",
"36": "text_color",
"37": "text_color",
"38": "text_color",
"39": "text_color",
"40": "text_color",
"41": "text_color",
"42": "text_color",
"43": "text_color",
"44": "text_color",
"45": "text_color",
"46": "text_color",
"47": "text_color",
"48": "text_color",
"49": "text_color",
"50": "text_color",
"51": "text_color",
"70": "text_color",
"70": "text_color",
"71": "text_color",
"72": "text_color",
"73": "text_color",
"100": "text_color",
"100": "text_color",
"101": "text_color",
"102": "text_color",
"103": "text_color",
"104": "text_color",
"105": "text_color",
"106": "text_color",
"107": "text_color",
"108": "text_color",
"43": "type",
"46": "namespace_ref",
"109": "string",
"110": "text_color",
"111": "text_color",
"112": "text_color",
"113": "text_color",
"114": "text_color",
"115": "text_color",
"116": "text_color",
"117": "text_color",
"118": "text_color",
"119": "text_color",
"120": "text_color",
"121": "text_color",
"122": "text_color",
"123": "text_color",
"124": "text_color",
"125": "text_color",
"126": "text_color",
"127": "text_color",
"128": "text_color",
"129": "text_color",
"130": "text_color",
"131": "text_color",
"132": "text_color",
"133": "text_color",
"134": "text_color",
"135": "text_color",
"136": "text_color",
"137": "text_color",
"138": "text_color",
"139": "text_color",
"140": "text_color",
"141": "text_color",
"142": "text_color",
"143": "text_color",
"144": "text_color",
"145": "text_color",
"146": "text_color",
"200": "text_color",
"200": "text_color",
"201": "text_color",
"202": "text_color",
"203": "text_color",
"204": "text_color",
"205": "text_color",
"206": "text_color",
"207": "text_color",
"208": "text_color",
"209": "text_color",
"210": "text_color",
"211": "text_color",
"212": "text_color",
"213": "text_color",
"214": "text_color",
"215": "text_color",
"216": "text_color",
"217": "text_color",
"218": "text_color",
"219": "text_color",
"220": "text_color",
"221": "text_color",
"222": "text_color",
"223": "text_color",
"224": "text_color",
"225": "text_color",
"226": "text_color",
"227": "text_color",
"228": "text_color",
"229": "text_color",
"230": "text_color",
"231": "text_color",
"232": "text_color",
"233": "text_color",
"234": "text_color",
"235": "text_color",
"236": "text_color",
"237": "text_color",
"238": "text_color",
"239": "text_color",
"240": "text_color",
"241": "text_color",
"242": "text_color",
"243": "text_color",
"244": "text_color",
"245": "text_color",
"246": "text_color",
"247": "text_color",
"248": "text_color",
"249": "text_color",
"250": "text_color",
"251": "text_color",
"252": "text_color",
"253": "text_color",
"300": "text_color",
"400": "text_color",
"400": "text_color",
"401": "text_color",
"402": "text_color",
"403": "text_color",
"404": "text_color",
"405": "text_color",
"406": "text_color",
"407": "text_color",
"408": "text_color",
"409": "text_color",
"410": "text_color",
"411": "text_color",
"412": "text_color",
"413": "text_color",
"414": "text_color",
"415": "text_color",
"416": "text_color",
"500": "text_color",
"501": "text_color",
"502": "text_color",
"503": "text_color",
"600": "text_color",
"700": "text_color"
"702": "keyword",
"703": "own",
"705": "comment"
}
}

46
juci/source.cc

@ -9,12 +9,13 @@
//////////////
Source::View::View() {
std::cout << "View constructor run" << std::endl;
override_font(Pango::FontDescription("Monospace"));
}
// Source::View::UpdateLine
// returns the new line
string Source::View::UpdateLine() {
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
return "";
}
@ -30,30 +31,44 @@ string Source::View::GetLine(const Gtk::TextIter &begin) {
// Applies theme in textview
void Source::View::ApplyTheme(const Source::Theme &theme) {
for (auto &item : theme.tagtable()) {
std::cout << "Apply: f: " << item.first << ", s: " <<
item.second << std::endl;
get_buffer()->create_tag(item.first)->property_foreground() = item.second;
}
}
void Source::View::OnOpenFile(std::vector<Clang::SourceLocation> &locations,
const Source::Theme &theme) {
ApplyTheme(theme);
Glib::RefPtr<Gtk::TextBuffer> buffer = get_buffer();
for (auto &loc : locations) {
string type = std::to_string(loc.kind());
int linum = loc.line_number();
try {
theme.typetable().at(type);
} catch (std::exception) {
continue;
}
int linum_start = loc.line_number_begin();
int linum_end = loc.line_number_end();
int begin = loc.begin();
int end = loc.end();
if(end < 0) end = 0;
if(begin < 0) begin = 0;
// for (auto &i : theme.tagtable()) {
// std::cout << "first: "<< i.first << " second: "<< i.second << std::endl;
// }
// std::cout << "type: " << type << std::endl;
if (end < 0) end = 0;
if (begin < 0) begin = 0;
std::cout << "Libc: ";
std::cout << "type: " << type;
std::cout << " linum_s: " << linum_start+1 << " linum_e: " << linum_end+1;
std::cout << ", begin: " << begin << ", end: " << end << std::endl;
Gtk::TextIter begin_iter = buffer->get_iter_at_line_offset(linum_start,
begin);
Gtk::TextIter end_iter = buffer->get_iter_at_line_offset(linum_end, end);
std::cout << get_buffer()->get_text(begin_iter, end_iter) << std::endl;
if (begin_iter.get_line() == end_iter.get_line()) {
buffer->apply_tag_by_name(theme.typetable().at(type),
buffer->get_iter_at_line_offset(linum, begin),
buffer->get_iter_at_line_offset(linum, end));
// std::cout << "This is a ans" << std::endl;
begin_iter, end_iter);
}
}
}
// Source::View::Theme::tagtable()
@ -68,6 +83,7 @@ const std::unordered_map<string, string>& Source::Theme::typetable() const {
return typetable_;
}
void Source::Theme::InsertTag(const string &key, const string &value) {
tagtable_[key] = value;
}
@ -165,7 +181,9 @@ void Source::Controller::OnNewEmptyFile() {
void Source::Controller::OnOpenFile(const string &filename) {
sourcefile s(filename);
view().get_buffer()->set_text(s.get_content());
Clang::TranslationUnit tu(filename.c_str());
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());
}

3
juci/source.h

@ -42,7 +42,8 @@ namespace Source {
Theme& theme();
const string filepath();
void SetFilePath(const string &filepath);
void SetSourceLocations(const std::vector<Clang::SourceLocation> &locations);
void SetSourceLocations(
const std::vector<Clang::SourceLocation> &locations);
std::vector<Clang::SourceLocation>& getSourceLocations() {
return locations_;
}

Loading…
Cancel
Save