Browse Source

Merge branch 'master' of github.com:eidheim/jucipp into cppit-master

merge-requests/365/head
Jørgen Lien Sellæg 10 years ago
parent
commit
bcc219354e
  1. 2
      src/CMakeLists.txt
  2. 2
      src/debug_clang.cc
  3. 2
      src/directories.cc
  4. 52
      src/info.cc
  5. 22
      src/info.h
  6. 2
      src/notebook.cc
  7. 5
      src/project_build.cc
  8. 8
      src/selectiondialog.cc
  9. 4
      src/source.cc
  10. 392
      src/source_clang.cc
  11. 7
      src/terminal.cc
  12. 30
      src/window.cc
  13. 5
      src/window.h

2
src/CMakeLists.txt

@ -84,6 +84,8 @@ set(project_files
files.h files.h
filesystem.cc filesystem.cc
filesystem.h filesystem.h
info.h
info.cc
juci.cc juci.cc
juci.h juci.h
menu.cc menu.cc

2
src/debug_clang.cc

@ -98,7 +98,7 @@ void Debug::Clang::start(const std::string &command, const boost::filesystem::pa
} }
lldb::SBError error; lldb::SBError error;
process = std::unique_ptr<lldb::SBProcess>(new lldb::SBProcess(target.Launch(*listener, argv, (const char**)environ, nullptr, nullptr, nullptr, path.string().c_str(), lldb::eLaunchFlagNone, false, error))); process = std::unique_ptr<lldb::SBProcess>(new lldb::SBProcess(target.Launch(*listener, argv, const_cast<const char**>(environ), nullptr, nullptr, nullptr, path.string().c_str(), lldb::eLaunchFlagNone, false, error)));
if(error.Fail()) { if(error.Fail()) {
Terminal::get().async_print(std::string("Error (debug): ")+error.GetCString()+'\n', true); Terminal::get().async_print(std::string("Error (debug): ")+error.GetCString()+'\n', true);
if(callback) if(callback)

2
src/directories.cc

@ -365,7 +365,7 @@ Directories::Directories() : Gtk::TreeView(), stop_update_thread(false) {
menu_item_delete.signal_activate().connect([this] { menu_item_delete.signal_activate().connect([this] {
if(menu_popup_row_path.empty()) if(menu_popup_row_path.empty())
return; return;
Gtk::MessageDialog dialog((Gtk::Window&)(*get_toplevel()), "Delete!", false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO); Gtk::MessageDialog dialog(*static_cast<Gtk::Window*>(get_toplevel()), "Delete!", false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO);
dialog.set_default_response(Gtk::RESPONSE_NO); dialog.set_default_response(Gtk::RESPONSE_NO);
dialog.set_secondary_text("Are you sure you want to delete "+menu_popup_row_path.string()+"?"); dialog.set_secondary_text("Are you sure you want to delete "+menu_popup_row_path.string()+"?");
int result = dialog.run(); int result = dialog.run();

52
src/info.cc

@ -0,0 +1,52 @@
#include "info.h"
namespace sigc {
#ifndef SIGC_FUNCTORS_DEDUCE_RESULT_TYPE_WITH_DECLTYPE
template <typename Functor>
struct functor_trait<Functor, false> {
typedef decltype (::sigc::mem_fun(std::declval<Functor&>(),
&Functor::operator())) _intermediate;
typedef typename _intermediate::result_type result_type;
typedef Functor functor_type;
};
#else
SIGC_FUNCTORS_DEDUCE_RESULT_TYPE_WITH_DECLTYPE
#endif
}
Info::Info() {
set_hexpand(false);
set_halign(Gtk::Align::ALIGN_END);
auto content_area=dynamic_cast<Gtk::Container*>(get_content_area());
label.set_max_width_chars(40);
label.set_line_wrap(true);
content_area->add(label);
auto provider = Gtk::CssProvider::create();
provider->load_from_data("* {border-radius: 5px;}");
get_style_context()->add_provider(provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
//Workaround from https://bugzilla.gnome.org/show_bug.cgi?id=710888
//Issue described at the same issue report
//TODO: remove later
auto revealer = gtk_widget_get_template_child (GTK_WIDGET (gobj()), GTK_TYPE_INFO_BAR, "revealer");
if (revealer) {
gtk_revealer_set_transition_type (GTK_REVEALER (revealer), GTK_REVEALER_TRANSITION_TYPE_NONE);
gtk_revealer_set_transition_duration (GTK_REVEALER (revealer), 0);
}
}
void Info::print(const std::string &text) {
if(!enabled)
return;
timeout_connection.disconnect();
timeout_connection=Glib::signal_timeout().connect([this]() {
hide();
return false;
}, 3000);
label.set_text(text);
show();
}

22
src/info.h

@ -0,0 +1,22 @@
#ifndef JUCI_INFO_H_
#define JUCI_INFO_H_
#include <gtkmm.h>
class Info : public Gtk::InfoBar {
Info();
public:
static Info &get() {
static Info instance;
return instance;
}
void print(const std::string &text);
bool enabled=true;
private:
Gtk::Label label;
sigc::connection timeout_connection;
};
#endif // JUCI_INFO_H_

2
src/notebook.cc

@ -308,7 +308,7 @@ boost::filesystem::path Notebook::get_current_folder() {
} }
bool Notebook::save_modified_dialog(int page) { bool Notebook::save_modified_dialog(int page) {
Gtk::MessageDialog dialog((Gtk::Window&)(*get_toplevel()), "Save file!", false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO); Gtk::MessageDialog dialog(*static_cast<Gtk::Window*>(get_toplevel()), "Save file!", false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO);
dialog.set_default_response(Gtk::RESPONSE_YES); dialog.set_default_response(Gtk::RESPONSE_YES);
dialog.set_secondary_text("Do you want to save: " + get_view(page)->file_path.string()+" ?"); dialog.set_secondary_text("Do you want to save: " + get_view(page)->file_path.string()+" ?");
int result = dialog.run(); int result = dialog.run();

5
src/project_build.cc

@ -1,12 +1,15 @@
#include "project_build.h" #include "project_build.h"
#include "config.h" #include "config.h"
#include "info.h"
std::unique_ptr<Project::Build> Project::get_build(const boost::filesystem::path &path) { std::unique_ptr<Project::Build> Project::get_build(const boost::filesystem::path &path) {
std::unique_ptr<Project::Build> cmake(new CMake(path)); std::unique_ptr<Project::Build> cmake(new CMake(path));
if(!cmake->project_path.empty()) if(!cmake->project_path.empty())
return cmake; return cmake;
else else {
Info::get().print("Could not find a supported project");
return std::unique_ptr<Project::Build>(new Project::Build()); return std::unique_ptr<Project::Build>(new Project::Build());
}
} }
boost::filesystem::path Project::Build::get_default_build_path() { boost::filesystem::path Project::Build::get_default_build_path() {

8
src/selectiondialog.cc

@ -75,10 +75,10 @@ list_view_text(use_markup), start_mark(start_mark), show_search_entry(show_searc
if(!show_search_entry) if(!show_search_entry)
window->add(scrolled_window); window->add(scrolled_window);
else { else {
auto dialog=(Gtk::Dialog*)window.get(); auto dialog=static_cast<Gtk::Dialog*>(window.get());
dialog->get_vbox()->pack_start(search_entry, false, false); dialog->get_vbox()->pack_start(search_entry, false, false);
dialog->get_vbox()->pack_start(scrolled_window, true, true); dialog->get_vbox()->pack_start(scrolled_window, true, true);
dialog->set_transient_for((Gtk::Window&)(*text_view.get_toplevel())); dialog->set_transient_for(*static_cast<Gtk::Window*>(text_view.get_toplevel()));
} }
} }
@ -153,7 +153,7 @@ void SelectionDialogBase::resize() {
else else
scrolled_window.set_policy(Gtk::PolicyType::POLICY_NEVER, Gtk::PolicyType::POLICY_AUTOMATIC); scrolled_window.set_policy(Gtk::PolicyType::POLICY_NEVER, Gtk::PolicyType::POLICY_AUTOMATIC);
int window_height=std::min(row_height*(int)list_view_text.get_model()->children().size(), row_height*10); int window_height=std::min(row_height*static_cast<int>(list_view_text.get_model()->children().size()), row_height*10);
if(show_search_entry) if(show_search_entry)
window_height+=search_entry.get_height(); window_height+=search_entry.get_height();
window->resize(row_width+1, window_height); window->resize(row_width+1, window_height);
@ -201,7 +201,7 @@ SelectionDialog::SelectionDialog(Gtk::TextView& text_view, Glib::RefPtr<Gtk::Tex
search_entry.signal_event().connect([this](GdkEvent* event) { search_entry.signal_event().connect([this](GdkEvent* event) {
if(event->type==GDK_KEY_PRESS) { if(event->type==GDK_KEY_PRESS) {
auto key=(GdkEventKey*)event; auto key=reinterpret_cast<GdkEventKey*>(event);
if(key->keyval==GDK_KEY_Down && list_view_text.get_model()->children().size()>0) { if(key->keyval==GDK_KEY_Down && list_view_text.get_model()->children().size()>0) {
auto it=list_view_text.get_selection()->get_selected(); auto it=list_view_text.get_selection()->get_selected();
if(it) { if(it) {

4
src/source.cc

@ -591,7 +591,7 @@ void Source::View::set_tooltip_and_dialog_events() {
} }
void Source::View::search_occurrences_updated(GtkWidget* widget, GParamSpec* property, gpointer data) { void Source::View::search_occurrences_updated(GtkWidget* widget, GParamSpec* property, gpointer data) {
auto view=(Source::View*)data; auto view=static_cast<Source::View*>(data);
if(view->update_search_occurrences) if(view->update_search_occurrences)
view->update_search_occurrences(gtk_source_search_context_get_occurrences_count(view->search_context)); view->update_search_occurrences(gtk_source_search_context_get_occurrences_count(view->search_context));
} }
@ -730,7 +730,7 @@ void Source::View::paste() {
paste_line=false; paste_line=false;
} }
} }
if(paste_line_tabs==(size_t)-1) if(paste_line_tabs==static_cast<size_t>(-1))
paste_line_tabs=0; paste_line_tabs=0;
start_line=0; start_line=0;
end_line=0; end_line=0;

392
src/source_clang.cc

@ -5,6 +5,7 @@
#ifdef JUCI_ENABLE_DEBUG #ifdef JUCI_ENABLE_DEBUG
#include "debug_clang.h" #include "debug_clang.h"
#endif #endif
#include "info.h"
namespace sigc { namespace sigc {
#ifndef SIGC_FUNCTORS_DEDUCE_RESULT_TYPE_WITH_DECLTYPE #ifndef SIGC_FUNCTORS_DEDUCE_RESULT_TYPE_WITH_DECLTYPE
@ -222,9 +223,9 @@ void Source::ClangViewParse::update_syntax() {
if(token.get_kind()==1) // KeywordToken if(token.get_kind()==1) // KeywordToken
ranges.emplace_back(token.offsets, 702); ranges.emplace_back(token.offsets, 702);
else if(token.get_kind()==2) {// IdentifierToken else if(token.get_kind()==2) {// IdentifierToken
auto kind=(int)token.get_cursor().get_kind(); auto kind=static_cast<int>(token.get_cursor().get_kind());
if(kind==101 || kind==102) if(kind==101 || kind==102)
kind=(int)token.get_cursor().get_referenced().get_kind(); kind=static_cast<int>(token.get_cursor().get_referenced().get_kind());
if(kind!=500) if(kind!=500)
ranges.emplace_back(token.offsets, kind); ranges.emplace_back(token.offsets, kind);
} }
@ -859,20 +860,22 @@ Source::ClangViewAutocomplete(file_path, language) {
}); });
get_token=[this]() -> Token { get_token=[this]() -> Token {
if(parsed) { if(!parsed) {
auto iter=get_buffer()->get_insert()->get_iter(); Info::get().print("Buffer is parsing");
auto line=(unsigned)iter.get_line(); return Token();
auto index=(unsigned)iter.get_line_index(); }
for(auto &token: *clang_tokens) { auto iter=get_buffer()->get_insert()->get_iter();
auto cursor=token.get_cursor(); auto line=static_cast<unsigned>(iter.get_line());
if(token.get_kind()==clang::Token_Identifier && cursor.has_type()) { auto index=static_cast<unsigned>(iter.get_line_index());
if(line==token.offsets.first.line-1 && index>=token.offsets.first.index-1 && index <=token.offsets.second.index-1) { for(auto &token: *clang_tokens) {
if(static_cast<unsigned>(token.get_cursor().get_kind())==103) //These cursors are buggy auto cursor=token.get_cursor();
continue; if(token.get_kind()==clang::Token_Identifier && cursor.has_type()) {
auto referenced=cursor.get_referenced(); if(line==token.offsets.first.line-1 && index>=token.offsets.first.index-1 && index <=token.offsets.second.index-1) {
if(referenced) if(static_cast<unsigned>(token.get_cursor().get_kind())==103) //These cursors are buggy
return Token(this->language, static_cast<int>(referenced.get_kind()), token.get_spelling(), referenced.get_usr()); continue;
} auto referenced=cursor.get_referenced();
if(referenced)
return Token(this->language, static_cast<int>(referenced.get_kind()), token.get_spelling(), referenced.get_usr());
} }
} }
} }
@ -907,7 +910,9 @@ Source::ClangViewAutocomplete(file_path, language) {
if(mark->get_name()=="insert") { if(mark->get_name()=="insert") {
delayed_tag_similar_tokens_connection.disconnect(); delayed_tag_similar_tokens_connection.disconnect();
delayed_tag_similar_tokens_connection=Glib::signal_timeout().connect([this]() { delayed_tag_similar_tokens_connection=Glib::signal_timeout().connect([this]() {
Info::get().enabled=false;
auto token=get_token(); auto token=get_token();
Info::get().enabled=true;
tag_similar_tokens(token); tag_similar_tokens(token);
return false; return false;
}, 100); }, 100);
@ -916,22 +921,24 @@ Source::ClangViewAutocomplete(file_path, language) {
get_declaration_location=[this](){ get_declaration_location=[this](){
Offset location; Offset location;
if(parsed) { if(!parsed) {
auto iter=get_buffer()->get_insert()->get_iter(); Info::get().print("Buffer is parsing");
auto line=(unsigned)iter.get_line(); return location;
auto index=(unsigned)iter.get_line_index(); }
for(auto &token: *clang_tokens) { auto iter=get_buffer()->get_insert()->get_iter();
auto cursor=token.get_cursor(); auto line=static_cast<unsigned>(iter.get_line());
if(token.get_kind()==clang::Token_Identifier && cursor.has_type()) { auto index=static_cast<unsigned>(iter.get_line_index());
if(line==token.offsets.first.line-1 && index>=token.offsets.first.index-1 && index <=token.offsets.second.index-1) { for(auto &token: *clang_tokens) {
auto referenced=cursor.get_referenced(); auto cursor=token.get_cursor();
if(referenced) { if(token.get_kind()==clang::Token_Identifier && cursor.has_type()) {
location.file_path=referenced.get_source_location().get_path(); if(line==token.offsets.first.line-1 && index>=token.offsets.first.index-1 && index <=token.offsets.second.index-1) {
auto clang_offset=referenced.get_source_location().get_offset(); auto referenced=cursor.get_referenced();
location.line=clang_offset.line; if(referenced) {
location.index=clang_offset.index; location.file_path=referenced.get_source_location().get_path();
break; auto clang_offset=referenced.get_source_location().get_offset();
} location.line=clang_offset.line;
location.index=clang_offset.index;
break;
} }
} }
} }
@ -965,7 +972,6 @@ Source::ClangViewAutocomplete(file_path, language) {
get_usages=[this](const Token &token) { get_usages=[this](const Token &token) {
std::vector<std::pair<Offset, std::string> > usages; std::vector<std::pair<Offset, std::string> > usages;
if(parsed && token.language && if(parsed && token.language &&
(token.language->get_id()=="chdr" || token.language->get_id()=="cpphdr" || token.language->get_id()=="c" || token.language->get_id()=="cpp" || token.language->get_id()=="objc")) { (token.language->get_id()=="chdr" || token.language->get_id()=="cpphdr" || token.language->get_id()=="c" || token.language->get_id()=="cpp" || token.language->get_id()=="objc")) {
auto offsets=clang_tokens->get_similar_token_offsets(static_cast<clang::CursorKind>(token.type), token.spelling, token.usr); auto offsets=clang_tokens->get_similar_token_offsets(static_cast<clang::CursorKind>(token.type), token.spelling, token.usr);
@ -1006,55 +1012,57 @@ Source::ClangViewAutocomplete(file_path, language) {
return usages; return usages;
}; };
goto_method=[this](){ goto_method=[this](){
if(parsed) { if(!parsed) {
auto iter=get_iter_for_dialog(); Info::get().print("Buffer is parsing");
selection_dialog=std::unique_ptr<SelectionDialog>(new SelectionDialog(*this, get_buffer()->create_mark(iter), true, true)); return;
auto rows=std::make_shared<std::unordered_map<std::string, clang::Offset> >(); }
auto methods=clang_tokens->get_cxx_methods(); auto iter=get_iter_for_dialog();
if(methods.size()==0) selection_dialog=std::unique_ptr<SelectionDialog>(new SelectionDialog(*this, get_buffer()->create_mark(iter), true, true));
return; auto rows=std::make_shared<std::unordered_map<std::string, clang::Offset> >();
for(auto &method: methods) { auto methods=clang_tokens->get_cxx_methods();
std::string row=std::to_string(method.second.line)+": "+Glib::Markup::escape_text(method.first); if(methods.size()==0)
//Add bold method token return;
size_t token_end_pos=row.find('('); for(auto &method: methods) {
if(token_end_pos==0 || token_end_pos==std::string::npos) std::string row=std::to_string(method.second.line)+": "+Glib::Markup::escape_text(method.first);
continue; //Add bold method token
if(token_end_pos>8 && row.substr(token_end_pos-4, 4)=="&gt;") { size_t token_end_pos=row.find('(');
token_end_pos-=8; if(token_end_pos==0 || token_end_pos==std::string::npos)
size_t angle_bracket_count=1; continue;
do { if(token_end_pos>8 && row.substr(token_end_pos-4, 4)=="&gt;") {
if(row.substr(token_end_pos-4, 4)=="&gt;") { token_end_pos-=8;
angle_bracket_count++; size_t angle_bracket_count=1;
token_end_pos-=4;
}
else if(row.substr(token_end_pos-4, 4)=="&lt;") {
angle_bracket_count--;
token_end_pos-=4;
}
else
token_end_pos--;
} while(angle_bracket_count>0 && token_end_pos>4);
}
auto pos=token_end_pos;
do { do {
pos--; if(row.substr(token_end_pos-4, 4)=="&gt;") {
} while(((row[pos]>='a' && row[pos]<='z') || angle_bracket_count++;
(row[pos]>='A' && row[pos]<='Z') || token_end_pos-=4;
(row[pos]>='0' && row[pos]<='9') || row[pos]=='_' || row[pos]=='~') && pos>0); }
row.insert(token_end_pos, "</b>"); else if(row.substr(token_end_pos-4, 4)=="&lt;") {
row.insert(pos+1, "<b>"); angle_bracket_count--;
(*rows)[row]=method.second; token_end_pos-=4;
selection_dialog->add_row(row); }
else
token_end_pos--;
} while(angle_bracket_count>0 && token_end_pos>4);
} }
selection_dialog->on_select=[this, rows](const std::string& selected, bool hide_window) { auto pos=token_end_pos;
auto offset=rows->at(selected); do {
get_buffer()->place_cursor(get_buffer()->get_iter_at_line_index(offset.line-1, offset.index-1)); pos--;
scroll_to(get_buffer()->get_insert(), 0.0, 1.0, 0.5); } while(((row[pos]>='a' && row[pos]<='z') ||
delayed_tooltips_connection.disconnect(); (row[pos]>='A' && row[pos]<='Z') ||
}; (row[pos]>='0' && row[pos]<='9') || row[pos]=='_' || row[pos]=='~') && pos>0);
selection_dialog->show(); row.insert(token_end_pos, "</b>");
row.insert(pos+1, "<b>");
(*rows)[row]=method.second;
selection_dialog->add_row(row);
} }
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_line_index(offset.line-1, offset.index-1));
scroll_to(get_buffer()->get_insert(), 0.0, 1.0, 0.5);
delayed_tooltips_connection.disconnect();
};
selection_dialog->show();
}; };
get_token_data=[this]() { get_token_data=[this]() {
@ -1070,85 +1078,87 @@ Source::ClangViewAutocomplete(file_path, language) {
}; };
std::vector<std::string> data; std::vector<std::string> data;
if(parsed) { if(!parsed) {
auto iter=get_buffer()->get_insert()->get_iter(); Info::get().print("Buffer is parsing");
auto line=(unsigned)iter.get_line(); return data;
auto index=(unsigned)iter.get_line_index(); }
for(auto &token: *clang_tokens) { auto iter=get_buffer()->get_insert()->get_iter();
auto cursor=token.get_cursor(); auto line=static_cast<unsigned>(iter.get_line());
if(token.get_kind()==clang::Token_Identifier && cursor.has_type()) { auto index=static_cast<unsigned>(iter.get_line_index());
if(line==token.offsets.first.line-1 && index>=token.offsets.first.index-1 && index <=token.offsets.second.index-1) { for(auto &token: *clang_tokens) {
auto referenced=cursor.get_referenced(); auto cursor=token.get_cursor();
if(referenced) { if(token.get_kind()==clang::Token_Identifier && cursor.has_type()) {
auto usr=referenced.get_usr(); if(line==token.offsets.first.line-1 && index>=token.offsets.first.index-1 && index <=token.offsets.second.index-1) {
auto referenced=cursor.get_referenced();
data.emplace_back("clang"); if(referenced) {
auto usr=referenced.get_usr();
//namespace
size_t pos1, pos2=0; data.emplace_back("clang");
while((pos1=usr.find('@', pos2))!=std::string::npos && pos1+1<usr.size() && usr[pos1+1]=='N') {
pos1+=3; //namespace
pos2=find_non_word_char(usr, pos1); size_t pos1, pos2=0;
if(pos2!=std::string::npos) { while((pos1=usr.find('@', pos2))!=std::string::npos && pos1+1<usr.size() && usr[pos1+1]=='N') {
auto ns=usr.substr(pos1, pos2-pos1); pos1+=3;
if(ns=="__1") pos2=find_non_word_char(usr, pos1);
break; if(pos2!=std::string::npos) {
data.emplace_back(ns); auto ns=usr.substr(pos1, pos2-pos1);
} if(ns=="__1")
else
break;
}
if(data.size()==1)
data.emplace_back("");
//template arguments
size_t template_pos=usr.find('$');
bool found_type_or_function=false;
//type
pos2=0;
while(((pos1=usr.find("T@", pos2))!=std::string::npos || (pos1=usr.find("S@", pos2))!=std::string::npos) && pos1<template_pos) {
found_type_or_function=true;
pos1+=2;
pos2=find_non_word_char(usr, pos1);
if(pos2!=std::string::npos)
data.emplace_back(usr.substr(pos1, pos2-pos1));
else {
data.emplace_back(usr.substr(pos1));
break; break;
} data.emplace_back(ns);
}
//function/constant//variable
pos1=usr.find("F@");
if(pos1==std::string::npos)
pos1=usr.find("C@");
if(pos1==std::string::npos)
pos1=usr.find("I@");
if(pos1!=std::string::npos) {
pos1+=2;
pos2=find_non_word_char(usr, pos1);
} }
if(pos1!=std::string::npos) { else
found_type_or_function=true; break;
if(pos2!=std::string::npos) }
data.emplace_back(usr.substr(pos1, pos2-pos1)); if(data.size()==1)
else data.emplace_back("");
data.emplace_back(usr.substr(pos1));
} //template arguments
size_t template_pos=usr.find('$');
//Sometimes a method is at end without a identifier it seems:
if(!found_type_or_function && (pos1=usr.rfind('@'))!=std::string::npos) { bool found_type_or_function=false;
pos1++; //type
pos2=find_non_word_char(usr, pos1); pos2=0;
if(pos2!=std::string::npos) while(((pos1=usr.find("T@", pos2))!=std::string::npos || (pos1=usr.find("S@", pos2))!=std::string::npos) && pos1<template_pos) {
data.emplace_back(usr.substr(pos1, pos2-pos1)); found_type_or_function=true;
else pos1+=2;
data.emplace_back(usr.substr(pos1)); pos2=find_non_word_char(usr, pos1);
if(pos2!=std::string::npos)
data.emplace_back(usr.substr(pos1, pos2-pos1));
else {
data.emplace_back(usr.substr(pos1));
break;
} }
break;
} }
//function/constant//variable
pos1=usr.find("F@");
if(pos1==std::string::npos)
pos1=usr.find("C@");
if(pos1==std::string::npos)
pos1=usr.find("I@");
if(pos1!=std::string::npos) {
pos1+=2;
pos2=find_non_word_char(usr, pos1);
}
if(pos1!=std::string::npos) {
found_type_or_function=true;
if(pos2!=std::string::npos)
data.emplace_back(usr.substr(pos1, pos2-pos1));
else
data.emplace_back(usr.substr(pos1));
}
//Sometimes a method is at end without a identifier it seems:
if(!found_type_or_function && (pos1=usr.rfind('@'))!=std::string::npos) {
pos1++;
pos2=find_non_word_char(usr, pos1);
if(pos2!=std::string::npos)
data.emplace_back(usr.substr(pos1, pos2-pos1));
else
data.emplace_back(usr.substr(pos1));
}
break;
} }
} }
} }
@ -1157,52 +1167,56 @@ Source::ClangViewAutocomplete(file_path, language) {
}; };
goto_next_diagnostic=[this]() { goto_next_diagnostic=[this]() {
if(parsed) { if(!parsed) {
auto insert_offset=get_buffer()->get_insert()->get_iter().get_offset(); Info::get().print("Buffer is parsing");
for(auto offset: diagnostic_offsets) { return;
if(offset>insert_offset) { }
get_buffer()->place_cursor(get_buffer()->get_iter_at_offset(offset)); auto insert_offset=get_buffer()->get_insert()->get_iter().get_offset();
scroll_to(get_buffer()->get_insert(), 0.0, 1.0, 0.5); for(auto offset: diagnostic_offsets) {
return; if(offset>insert_offset) {
} get_buffer()->place_cursor(get_buffer()->get_iter_at_offset(offset));
}
if(diagnostic_offsets.size()>0) {
auto iter=get_buffer()->get_iter_at_offset(*diagnostic_offsets.begin());
get_buffer()->place_cursor(iter);
scroll_to(get_buffer()->get_insert(), 0.0, 1.0, 0.5); scroll_to(get_buffer()->get_insert(), 0.0, 1.0, 0.5);
return;
} }
} }
if(diagnostic_offsets.size()>0) {
auto iter=get_buffer()->get_iter_at_offset(*diagnostic_offsets.begin());
get_buffer()->place_cursor(iter);
scroll_to(get_buffer()->get_insert(), 0.0, 1.0, 0.5);
}
}; };
apply_fix_its=[this]() { apply_fix_its=[this]() {
if(!parsed) {
Info::get().print("Buffer is parsing");
return;
}
std::vector<std::pair<Glib::RefPtr<Gtk::TextMark>, Glib::RefPtr<Gtk::TextMark> > > fix_it_marks; std::vector<std::pair<Glib::RefPtr<Gtk::TextMark>, Glib::RefPtr<Gtk::TextMark> > > fix_it_marks;
if(parsed) { for(auto &fix_it: fix_its) {
for(auto &fix_it: fix_its) { auto start_iter=get_buffer()->get_iter_at_line_index(fix_it.offsets.first.line-1, fix_it.offsets.first.index-1);
auto start_iter=get_buffer()->get_iter_at_line_index(fix_it.offsets.first.line-1, fix_it.offsets.first.index-1); auto end_iter=get_buffer()->get_iter_at_line_index(fix_it.offsets.second.line-1, fix_it.offsets.second.index-1);
auto end_iter=get_buffer()->get_iter_at_line_index(fix_it.offsets.second.line-1, fix_it.offsets.second.index-1); fix_it_marks.emplace_back(get_buffer()->create_mark(start_iter), get_buffer()->create_mark(end_iter));
fix_it_marks.emplace_back(get_buffer()->create_mark(start_iter), get_buffer()->create_mark(end_iter)); }
size_t c=0;
get_source_buffer()->begin_user_action();
for(auto &fix_it: fix_its) {
if(fix_it.type==FixIt::Type::INSERT) {
get_buffer()->insert(fix_it_marks[c].first->get_iter(), fix_it.source);
} }
size_t c=0; if(fix_it.type==FixIt::Type::REPLACE) {
get_source_buffer()->begin_user_action(); get_buffer()->erase(fix_it_marks[c].first->get_iter(), fix_it_marks[c].second->get_iter());
for(auto &fix_it: fix_its) { get_buffer()->insert(fix_it_marks[c].first->get_iter(), fix_it.source);
if(fix_it.type==FixIt::Type::INSERT) {
get_buffer()->insert(fix_it_marks[c].first->get_iter(), fix_it.source);
}
if(fix_it.type==FixIt::Type::REPLACE) {
get_buffer()->erase(fix_it_marks[c].first->get_iter(), fix_it_marks[c].second->get_iter());
get_buffer()->insert(fix_it_marks[c].first->get_iter(), fix_it.source);
}
if(fix_it.type==FixIt::Type::ERASE) {
get_buffer()->erase(fix_it_marks[c].first->get_iter(), fix_it_marks[c].second->get_iter());
}
c++;
} }
for(auto &mark_pair: fix_it_marks) { if(fix_it.type==FixIt::Type::ERASE) {
get_buffer()->delete_mark(mark_pair.first); get_buffer()->erase(fix_it_marks[c].first->get_iter(), fix_it_marks[c].second->get_iter());
get_buffer()->delete_mark(mark_pair.second);
} }
get_source_buffer()->end_user_action(); c++;
} }
for(auto &mark_pair: fix_it_marks) {
get_buffer()->delete_mark(mark_pair.first);
get_buffer()->delete_mark(mark_pair.second);
}
get_source_buffer()->end_user_action();
}; };
} }

7
src/terminal.cc

@ -2,6 +2,7 @@
#include <iostream> #include <iostream>
#include "config.h" #include "config.h"
#include "project.h" #include "project.h"
#include "info.h"
Terminal::InProgress::InProgress(const std::string& start_msg): stop(false) { Terminal::InProgress::InProgress(const std::string& start_msg): stop(false) {
start(start_msg); start(start_msg);
@ -138,7 +139,9 @@ void Terminal::async_process(const std::string &command, const boost::filesystem
void Terminal::kill_last_async_process(bool force) { void Terminal::kill_last_async_process(bool force) {
std::unique_lock<std::mutex> lock(processes_mutex); std::unique_lock<std::mutex> lock(processes_mutex);
if(processes.size()>0) if(processes.empty())
Info::get().print("No running processes");
else
processes.back()->kill(force); processes.back()->kill(force);
} }
@ -276,7 +279,7 @@ bool Terminal::on_key_press_event(GdkEventKey *event) {
if(processes.size()>0 || debug_is_running) { if(processes.size()>0 || debug_is_running) {
get_buffer()->place_cursor(get_buffer()->end()); get_buffer()->place_cursor(get_buffer()->end());
auto unicode=gdk_keyval_to_unicode(event->keyval); auto unicode=gdk_keyval_to_unicode(event->keyval);
char chr=(char)unicode; char chr=static_cast<char>(unicode);
if(unicode>=32 && unicode<=126) { if(unicode>=32 && unicode<=126) {
stdin_buffer+=chr; stdin_buffer+=chr;
get_buffer()->insert_at_cursor(stdin_buffer.substr(stdin_buffer.size()-1)); get_buffer()->insert_at_cursor(stdin_buffer.substr(stdin_buffer.size()-1));

30
src/window.cc

@ -7,6 +7,7 @@
#include "filesystem.h" #include "filesystem.h"
#include "project.h" #include "project.h"
#include "entrybox.h" #include "entrybox.h"
#include "info.h"
namespace sigc { namespace sigc {
#ifndef SIGC_FUNCTORS_DEDUCE_RESULT_TYPE_WITH_DECLTYPE #ifndef SIGC_FUNCTORS_DEDUCE_RESULT_TYPE_WITH_DECLTYPE
@ -31,10 +32,6 @@ Window::Window() : notebook(Notebook::get()) {
configure(); configure();
set_default_size(Config::get().window.default_size.first, Config::get().window.default_size.second); set_default_size(Config::get().window.default_size.first, Config::get().window.default_size.second);
//PluginApi(&this->notebook, &this->menu);
add(vpaned);
directories_scrolled_window.add(Directories::get()); directories_scrolled_window.add(Directories::get());
directory_and_notebook_panes.pack1(directories_scrolled_window, Gtk::SHRINK); directory_and_notebook_panes.pack1(directories_scrolled_window, Gtk::SHRINK);
notebook_vbox.pack_start(notebook); notebook_vbox.pack_start(notebook);
@ -59,7 +56,19 @@ Window::Window() : notebook(Notebook::get()) {
terminal_vbox.pack_end(info_and_status_hbox, Gtk::PACK_SHRINK); terminal_vbox.pack_end(info_and_status_hbox, Gtk::PACK_SHRINK);
vpaned.pack2(terminal_vbox, true, true); vpaned.pack2(terminal_vbox, true, true);
#if GTKMM_MAJOR_VERSION>3 || (GTKMM_MAJOR_VERSION>=3 && GTKMM_MINOR_VERSION>=18)
overlay_vbox.pack_start(Info::get(), Gtk::PACK_SHRINK, 20);
overlay_hbox.pack_end(overlay_vbox, Gtk::PACK_SHRINK, 20);
overlay.add(vpaned);
overlay.add_overlay(overlay_hbox);
overlay.set_overlay_pass_through(overlay_hbox, true);
add(overlay);
#else
add(vpaned);
#endif
show_all_children(); show_all_children();
Info::get().hide();
Directories::get().on_row_activated=[this](const boost::filesystem::path &path) { Directories::get().on_row_activated=[this](const boost::filesystem::path &path) {
notebook.open(path); notebook.open(path);
@ -481,6 +490,7 @@ void Window::set_menu_actions() {
} }
} }
} }
Info::get().print("Could not find implementation");
} }
} }
} }
@ -590,8 +600,10 @@ void Window::set_menu_actions() {
EntryBox::get().show(); EntryBox::get().show();
}); });
menu.add_action("compile_and_run", [this]() { menu.add_action("compile_and_run", [this]() {
if(Project::compiling || Project::debugging) if(Project::compiling || Project::debugging) {
Info::get().print("Compile or debug in progress");
return; return;
}
Project::current_language=Project::get_language(); Project::current_language=Project::get_language();
@ -601,8 +613,10 @@ void Window::set_menu_actions() {
Project::current_language->compile_and_run(); Project::current_language->compile_and_run();
}); });
menu.add_action("compile", [this]() { menu.add_action("compile", [this]() {
if(Project::compiling || Project::debugging) if(Project::compiling || Project::debugging) {
Info::get().print("Compile or debug in progress");
return; return;
}
Project::current_language=Project::get_language(); Project::current_language=Project::get_language();
@ -673,8 +687,10 @@ void Window::set_menu_actions() {
EntryBox::get().show(); EntryBox::get().show();
}); });
menu.add_action("debug_start_continue", [this](){ menu.add_action("debug_start_continue", [this](){
if(Project::compiling) if(Project::compiling) {
Info::get().print("Compile in progress");
return; return;
}
else if(Project::debugging) { else if(Project::debugging) {
Project::current_language->debug_continue(); Project::current_language->debug_continue();
return; return;

5
src/window.h

@ -27,6 +27,11 @@ private:
Gtk::ScrolledWindow directories_scrolled_window; Gtk::ScrolledWindow directories_scrolled_window;
Gtk::ScrolledWindow terminal_scrolled_window; Gtk::ScrolledWindow terminal_scrolled_window;
Gtk::HBox info_and_status_hbox; Gtk::HBox info_and_status_hbox;
Gtk::VBox overlay_vbox;
Gtk::HBox overlay_hbox;
#if GTKMM_MAJOR_VERSION>3 || (GTKMM_MAJOR_VERSION>=3 && GTKMM_MINOR_VERSION>=18)
Gtk::Overlay overlay;
#endif
Gtk::AboutDialog about; Gtk::AboutDialog about;
Glib::RefPtr<Gtk::CssProvider> css_provider; Glib::RefPtr<Gtk::CssProvider> css_provider;

Loading…
Cancel
Save