Browse Source

Merge pull request #129 from eidheim/master

Fixes some issues
merge-requests/365/head
Ole Christian Eidheim 10 years ago
parent
commit
9c4ae1e18d
  1. 34
      src/cmake.cc
  2. 4
      src/selectiondialog.h
  3. 51
      src/source.cc
  4. 4
      src/source.h
  5. 53
      src/source_clang.cc
  6. 3
      src/source_clang.h
  7. 27
      src/window.cc

34
src/cmake.cc

@ -10,33 +10,28 @@ CMake::CMake(const boost::filesystem::path &path) {
for(auto &line: filesystem::read_lines(cmake_path)) { for(auto &line: filesystem::read_lines(cmake_path)) {
const boost::regex project_regex("^ *project *\\(.*$"); const boost::regex project_regex("^ *project *\\(.*$");
boost::smatch sm; boost::smatch sm;
if(boost::regex_match(line, sm, project_regex)) { if(boost::regex_match(line, sm, project_regex))
return true; return true;
} }
}
return false; return false;
}; };
auto search_path=path; auto search_path=path;
auto search_cmake_path=search_path; while(true) {
search_cmake_path+="/CMakeLists.txt"; auto search_cmake_path=search_path/"CMakeLists.txt";
if(boost::filesystem::exists(search_cmake_path))
paths.emplace(paths.begin(), search_cmake_path);
if(find_cmake_project(search_cmake_path))
project_path=search_path;
else {
do {
search_path=search_path.parent_path();
search_cmake_path=search_path;
search_cmake_path+="/CMakeLists.txt";
if(boost::filesystem::exists(search_cmake_path)) if(boost::filesystem::exists(search_cmake_path))
paths.emplace(paths.begin(), search_cmake_path); paths.emplace(paths.begin(), search_cmake_path);
else
break;
if(find_cmake_project(search_cmake_path)) { if(find_cmake_project(search_cmake_path)) {
project_path=search_path; project_path=search_path;
break; break;
} }
} while(search_path!=search_path.root_directory()); if(search_path==search_path.root_directory())
break;
search_path=search_path.parent_path();
} }
if(!project_path.empty()) { if(!project_path.empty()) {
if(boost::filesystem::exists(project_path/"CMakeLists.txt") && !boost::filesystem::exists(project_path/"compile_commands.json")) if(boost::filesystem::exists(project_path/"CMakeLists.txt") && !boost::filesystem::exists(project_path/"compile_commands.json"))
create_compile_commands(project_path); create_compile_commands(project_path);
@ -140,8 +135,8 @@ void CMake::find_variables() {
end_line=file.size(); end_line=file.size();
if(end_line>start_line) { if(end_line>start_line) {
auto line=file.substr(start_line, end_line-start_line); auto line=file.substr(start_line, end_line-start_line);
const boost::regex set_regex("^ *set *\\( *([A-Za-z_][A-Za-z_0-9]*) +(.*)\\) *$");
boost::smatch sm; boost::smatch sm;
const boost::regex set_regex("^ *set *\\( *([A-Za-z_][A-Za-z_0-9]*) +(.*)\\) *$");
if(boost::regex_match(line, sm, set_regex)) { if(boost::regex_match(line, sm, set_regex)) {
auto data=sm[2].str(); auto data=sm[2].str();
while(data.size()>0 && data.back()==' ') while(data.size()>0 && data.back()==' ')
@ -149,6 +144,15 @@ void CMake::find_variables() {
parse_variable_parameters(data); parse_variable_parameters(data);
variables[sm[1].str()]=data; variables[sm[1].str()]=data;
} }
else {
const boost::regex project_regex("^ *project *\\( *([^ ]+).*\\) *$");
if(boost::regex_match(line, sm, project_regex)) {
auto data=sm[1].str();
parse_variable_parameters(data);
variables["CMAKE_PROJECT_NAME"]=data; //TODO: is this variable deprecated/non-standard?
variables["PROJECT_NAME"]=data;
}
}
} }
pos=end_line+1; pos=end_line+1;
} }

4
src/selectiondialog.h

@ -37,6 +37,8 @@ public:
std::function<void()> on_hide; std::function<void()> on_hide;
std::function<void(const std::string& selected, bool hide_window)> on_select; std::function<void(const std::string& selected, bool hide_window)> on_select;
Glib::RefPtr<Gtk::TextBuffer::Mark> start_mark; Glib::RefPtr<Gtk::TextBuffer::Mark> start_mark;
bool shown=false;
protected: protected:
virtual void resize(); virtual void resize();
virtual void update_tooltips(); virtual void update_tooltips();
@ -50,8 +52,6 @@ protected:
std::unique_ptr<Tooltips> tooltips; std::unique_ptr<Tooltips> tooltips;
std::unordered_map<std::string, std::string> tooltip_texts; std::unordered_map<std::string, std::string> tooltip_texts;
std::string last_row; std::string last_row;
private:
bool shown=false;
}; };
class SelectionDialog : public SelectionDialogBase { class SelectionDialog : public SelectionDialogBase {

51
src/source.cc

@ -8,8 +8,6 @@
#include "filesystem.h" #include "filesystem.h"
#include "terminal.h" #include "terminal.h"
using namespace std; //TODO: remove
namespace sigc { namespace sigc {
#ifndef SIGC_FUNCTORS_DEDUCE_RESULT_TYPE_WITH_DECLTYPE #ifndef SIGC_FUNCTORS_DEDUCE_RESULT_TYPE_WITH_DECLTYPE
template <typename Functor> template <typename Functor>
@ -219,7 +217,7 @@ Source::View::View(const boost::filesystem::path &file_path, const boost::filesy
return; return;
if(mark->get_name()=="insert") { if(mark->get_name()=="insert") {
if(spellcheck_suggestions_dialog_shown) if(spellcheck_suggestions_dialog && spellcheck_suggestions_dialog->shown)
spellcheck_suggestions_dialog->hide(); spellcheck_suggestions_dialog->hide();
delayed_spellcheck_suggestions_connection.disconnect(); delayed_spellcheck_suggestions_connection.disconnect();
delayed_spellcheck_suggestions_connection=Glib::signal_timeout().connect([this]() { delayed_spellcheck_suggestions_connection=Glib::signal_timeout().connect([this]() {
@ -233,9 +231,6 @@ Source::View::View(const boost::filesystem::path &file_path, const boost::filesy
} }
if(need_suggestions) { if(need_suggestions) {
spellcheck_suggestions_dialog=std::unique_ptr<SelectionDialog>(new SelectionDialog(*this, get_buffer()->create_mark(get_buffer()->get_insert()->get_iter()), false)); spellcheck_suggestions_dialog=std::unique_ptr<SelectionDialog>(new SelectionDialog(*this, get_buffer()->create_mark(get_buffer()->get_insert()->get_iter()), false));
spellcheck_suggestions_dialog->on_hide=[this](){
spellcheck_suggestions_dialog_shown=false;
};
auto word=spellcheck_get_word(get_buffer()->get_insert()->get_iter()); auto word=spellcheck_get_word(get_buffer()->get_insert()->get_iter());
auto suggestions=spellcheck_get_suggestions(word.first, word.second); auto suggestions=spellcheck_get_suggestions(word.first, word.second);
if(suggestions.size()==0) if(suggestions.size()==0)
@ -250,7 +245,6 @@ Source::View::View(const boost::filesystem::path &file_path, const boost::filesy
delayed_tooltips_connection.disconnect(); delayed_tooltips_connection.disconnect();
}; };
spellcheck_suggestions_dialog->show(); spellcheck_suggestions_dialog->show();
spellcheck_suggestions_dialog_shown=true;
} }
return false; return false;
}, 500); }, 500);
@ -261,7 +255,7 @@ Source::View::View(const boost::filesystem::path &file_path, const boost::filesy
set_info(info); set_info(info);
}); });
set_tooltip_events(); set_tooltip_and_dialog_events();
tab_char=Config::get().source.default_tab_char; tab_char=Config::get().source.default_tab_char;
tab_size=Config::get().source.default_tab_size; tab_size=Config::get().source.default_tab_size;
@ -386,7 +380,7 @@ void Source::View::configure() {
get_buffer()->remove_tag_by_name("spellcheck_error", get_buffer()->begin(), get_buffer()->end()); get_buffer()->remove_tag_by_name("spellcheck_error", get_buffer()->begin(), get_buffer()->end());
} }
void Source::View::set_tooltip_events() { void Source::View::set_tooltip_and_dialog_events() {
signal_motion_notify_event().connect([this](GdkEventMotion* event) { signal_motion_notify_event().connect([this](GdkEventMotion* event) {
if(on_motion_last_x!=event->x || on_motion_last_y!=event->y) { if(on_motion_last_x!=event->x || on_motion_last_y!=event->y) {
delayed_tooltips_connection.disconnect(); delayed_tooltips_connection.disconnect();
@ -434,6 +428,14 @@ void Source::View::set_tooltip_events() {
}, 500); }, 500);
type_tooltips.hide(); type_tooltips.hide();
diagnostic_tooltips.hide(); diagnostic_tooltips.hide();
if(spellcheck_suggestions_dialog && spellcheck_suggestions_dialog->shown)
spellcheck_suggestions_dialog->hide();
if(autocomplete_dialog && autocomplete_dialog->shown)
autocomplete_dialog->hide();
if(selection_dialog && selection_dialog->shown)
selection_dialog->hide();
set_info(info); set_info(info);
} }
}); });
@ -442,6 +444,13 @@ void Source::View::set_tooltip_events() {
delayed_tooltips_connection.disconnect(); delayed_tooltips_connection.disconnect();
type_tooltips.hide(); type_tooltips.hide();
diagnostic_tooltips.hide(); diagnostic_tooltips.hide();
delayed_spellcheck_suggestions_connection.disconnect();
if(spellcheck_suggestions_dialog && spellcheck_suggestions_dialog->shown)
spellcheck_suggestions_dialog->hide();
if(autocomplete_dialog && autocomplete_dialog->shown)
autocomplete_dialog->hide();
if(selection_dialog && selection_dialog->shown)
selection_dialog->hide();
return false; return false;
}); });
@ -449,6 +458,19 @@ void Source::View::set_tooltip_events() {
delayed_tooltips_connection.disconnect(); delayed_tooltips_connection.disconnect();
type_tooltips.hide(); type_tooltips.hide();
diagnostic_tooltips.hide(); diagnostic_tooltips.hide();
delayed_spellcheck_suggestions_connection.disconnect();
if(spellcheck_suggestions_dialog && spellcheck_suggestions_dialog->shown)
spellcheck_suggestions_dialog->hide();
if(autocomplete_dialog && autocomplete_dialog->shown)
autocomplete_dialog->hide();
return false;
});
signal_leave_notify_event().connect([this](GdkEventCrossing*) {
delayed_tooltips_connection.disconnect();
type_tooltips.hide();
diagnostic_tooltips.hide();
delayed_spellcheck_suggestions_connection.disconnect();
return false; return false;
}); });
} }
@ -509,7 +531,8 @@ void Source::View::replace_forward(const std::string &replacement) {
auto offset=match_start.get_offset(); auto offset=match_start.get_offset();
gtk_source_search_context_replace(search_context, match_start.gobj(), match_end.gobj(), replacement.c_str(), replacement.size(), NULL); gtk_source_search_context_replace(search_context, match_start.gobj(), match_end.gobj(), replacement.c_str(), replacement.size(), NULL);
get_buffer()->select_range(get_buffer()->get_iter_at_offset(offset), get_buffer()->get_iter_at_offset(offset+replacement.size())); Glib::ustring replacement_ustring=replacement;
get_buffer()->select_range(get_buffer()->get_iter_at_offset(offset), get_buffer()->get_iter_at_offset(offset+replacement_ustring.size()));
scroll_to(get_buffer()->get_insert()); scroll_to(get_buffer()->get_insert());
} }
} }
@ -923,7 +946,7 @@ bool Source::View::find_left_bracket_backward(Gtk::TextIter iter, Gtk::TextIter
//Basic indentation //Basic indentation
bool Source::View::on_key_press_event(GdkEventKey* key) { bool Source::View::on_key_press_event(GdkEventKey* key) {
if(spellcheck_suggestions_dialog_shown) { if(spellcheck_suggestions_dialog && spellcheck_suggestions_dialog->shown) {
if(spellcheck_suggestions_dialog->on_key_press(key)) if(spellcheck_suggestions_dialog->on_key_press(key))
return true; return true;
} }
@ -1227,8 +1250,8 @@ std::pair<char, unsigned> Source::View::find_tab_char_and_size() {
} }
else if(!iter.ends_line()) { else if(!iter.ends_line()) {
if(tab_count!=last_tab_count) if(tab_count!=last_tab_count)
tab_sizes[abs(tab_count-last_tab_count)]++; tab_sizes[std::abs(tab_count-last_tab_count)]++;
last_tab_diff=abs(tab_count-last_tab_count); last_tab_diff=std::abs(tab_count-last_tab_count);
last_tab_count=tab_count; last_tab_count=tab_count;
last_char=0; last_char=0;
} }
@ -1282,7 +1305,7 @@ std::pair<char, unsigned> Source::View::find_tab_char_and_size() {
} }
else if(!iter.ends_line()) { else if(!iter.ends_line()) {
if(tab_count!=last_tab_count) if(tab_count!=last_tab_count)
tab_sizes[abs(tab_count-last_tab_count)]++; tab_sizes[std::abs(tab_count-last_tab_count)]++;
last_tab_count=tab_count; last_tab_count=tab_count;
} }
} }

4
src/source.h

@ -85,6 +85,7 @@ namespace Source {
std::function<void()> goto_next_diagnostic; std::function<void()> goto_next_diagnostic;
std::function<void()> apply_fix_its; std::function<void()> apply_fix_its;
std::unique_ptr<CompletionDialog> autocomplete_dialog;
std::unique_ptr<SelectionDialog> selection_dialog; std::unique_ptr<SelectionDialog> selection_dialog;
sigc::connection delayed_tooltips_connection; sigc::connection delayed_tooltips_connection;
@ -114,7 +115,7 @@ namespace Source {
virtual void show_type_tooltips(const Gdk::Rectangle &rectangle) {} virtual void show_type_tooltips(const Gdk::Rectangle &rectangle) {}
gdouble on_motion_last_x; gdouble on_motion_last_x;
gdouble on_motion_last_y; gdouble on_motion_last_y;
void set_tooltip_events(); void set_tooltip_and_dialog_events();
std::string get_line(const Gtk::TextIter &iter); std::string get_line(const Gtk::TextIter &iter);
std::string get_line(Glib::RefPtr<Gtk::TextBuffer::Mark> mark); std::string get_line(Glib::RefPtr<Gtk::TextBuffer::Mark> mark);
@ -143,7 +144,6 @@ namespace Source {
bool spellcheck_all=false; bool spellcheck_all=false;
std::unique_ptr<SelectionDialog> spellcheck_suggestions_dialog; std::unique_ptr<SelectionDialog> spellcheck_suggestions_dialog;
bool spellcheck_suggestions_dialog_shown=false;
bool last_keyval_is_backspace=false; bool last_keyval_is_backspace=false;
bool last_keyval_is_return=false; bool last_keyval_is_return=false;
private: private:

53
src/source_clang.cc

@ -422,7 +422,7 @@ void Source::ClangViewParse::show_type_tooltips(const Gdk::Rectangle &rectangle)
//Clang indentation. //Clang indentation.
bool Source::ClangViewParse::on_key_press_event(GdkEventKey* key) { bool Source::ClangViewParse::on_key_press_event(GdkEventKey* key) {
if(spellcheck_suggestions_dialog_shown) { if(spellcheck_suggestions_dialog && spellcheck_suggestions_dialog->shown) {
if(spellcheck_suggestions_dialog->on_key_press(key)) if(spellcheck_suggestions_dialog->on_key_press(key))
return true; return true;
} }
@ -610,7 +610,7 @@ bool Source::ClangViewParse::on_key_press_event(GdkEventKey* key) {
Source::ClangViewAutocomplete::ClangViewAutocomplete(const boost::filesystem::path &file_path, const boost::filesystem::path& project_path, Glib::RefPtr<Gsv::Language> language): Source::ClangViewAutocomplete::ClangViewAutocomplete(const boost::filesystem::path &file_path, const boost::filesystem::path& project_path, Glib::RefPtr<Gsv::Language> language):
Source::ClangViewParse(file_path, project_path, language), autocomplete_state(AutocompleteState::IDLE) { Source::ClangViewParse(file_path, project_path, language), autocomplete_state(AutocompleteState::IDLE) {
get_buffer()->signal_changed().connect([this](){ get_buffer()->signal_changed().connect([this](){
if(autocomplete_state==AutocompleteState::SHOWN) if(autocomplete_dialog && autocomplete_dialog->shown)
delayed_reparse_connection.disconnect(); delayed_reparse_connection.disconnect();
else { else {
if(!has_focus()) if(!has_focus())
@ -621,7 +621,7 @@ Source::ClangViewParse(file_path, project_path, language), autocomplete_state(Au
autocomplete_check(); autocomplete_check();
} }
else { else {
if(autocomplete_state==AutocompleteState::STARTING) if(autocomplete_state==AutocompleteState::STARTING || autocomplete_state==AutocompleteState::RESTARTING)
autocomplete_state=AutocompleteState::CANCELED; autocomplete_state=AutocompleteState::CANCELED;
else { else {
auto iter=get_buffer()->get_insert()->get_iter(); auto iter=get_buffer()->get_insert()->get_iter();
@ -633,19 +633,12 @@ Source::ClangViewParse(file_path, project_path, language), autocomplete_state(Au
}); });
get_buffer()->signal_mark_set().connect([this](const Gtk::TextBuffer::iterator& iterator, const Glib::RefPtr<Gtk::TextBuffer::Mark>& mark){ get_buffer()->signal_mark_set().connect([this](const Gtk::TextBuffer::iterator& iterator, const Glib::RefPtr<Gtk::TextBuffer::Mark>& mark){
if(mark->get_name()=="insert") { if(mark->get_name()=="insert") {
if(autocomplete_state==AutocompleteState::SHOWN) if(autocomplete_state==AutocompleteState::STARTING || autocomplete_state==AutocompleteState::RESTARTING)
autocomplete_dialog->hide();
if(autocomplete_state==AutocompleteState::STARTING)
autocomplete_state=AutocompleteState::CANCELED; autocomplete_state=AutocompleteState::CANCELED;
} }
}); });
signal_scroll_event().connect([this](GdkEventScroll* event){
if(autocomplete_state==AutocompleteState::SHOWN)
autocomplete_dialog->hide();
return false;
}, false);
signal_key_release_event().connect([this](GdkEventKey* key){ signal_key_release_event().connect([this](GdkEventKey* key){
if(autocomplete_state==AutocompleteState::SHOWN) { if(autocomplete_dialog && autocomplete_dialog->shown) {
if(autocomplete_dialog->on_key_release(key)) if(autocomplete_dialog->on_key_release(key))
return true; return true;
} }
@ -654,9 +647,7 @@ Source::ClangViewParse(file_path, project_path, language), autocomplete_state(Au
}, false); }, false);
signal_focus_out_event().connect([this](GdkEventFocus* event) { signal_focus_out_event().connect([this](GdkEventFocus* event) {
if(autocomplete_state==AutocompleteState::SHOWN) if(autocomplete_state==AutocompleteState::STARTING || autocomplete_state==AutocompleteState::RESTARTING)
autocomplete_dialog->hide();
if(autocomplete_state==AutocompleteState::STARTING)
autocomplete_state=AutocompleteState::CANCELED; autocomplete_state=AutocompleteState::CANCELED;
return false; return false;
}); });
@ -666,6 +657,11 @@ Source::ClangViewParse(file_path, project_path, language), autocomplete_state(Au
set_status(""); set_status("");
soft_reparse(); soft_reparse();
autocomplete_state=AutocompleteState::IDLE; autocomplete_state=AutocompleteState::IDLE;
}
else if(autocomplete_state==AutocompleteState::RESTARTING) {
set_status("");
soft_reparse();
autocomplete_state=AutocompleteState::IDLE;
autocomplete_restart(); autocomplete_restart();
} }
else { else {
@ -693,16 +689,14 @@ Source::ClangViewParse(file_path, project_path, language), autocomplete_state(Au
} }
} }
set_status(""); set_status("");
autocomplete_state=AutocompleteState::IDLE;
if (!autocomplete_dialog_rows.empty()) { if (!autocomplete_dialog_rows.empty()) {
autocomplete_state=AutocompleteState::SHOWN;
get_source_buffer()->begin_user_action(); get_source_buffer()->begin_user_action();
autocomplete_dialog->show(); autocomplete_dialog->show();
} }
else { else
autocomplete_state=AutocompleteState::IDLE;
soft_reparse(); soft_reparse();
} }
}
}); });
autocomplete_restart_connection=autocomplete_restart.connect([this]() { autocomplete_restart_connection=autocomplete_restart.connect([this]() {
@ -728,7 +722,7 @@ Source::ClangViewParse(file_path, project_path, language), autocomplete_state(Au
bool Source::ClangViewAutocomplete::on_key_press_event(GdkEventKey *key) { bool Source::ClangViewAutocomplete::on_key_press_event(GdkEventKey *key) {
last_keyval=key->keyval; last_keyval=key->keyval;
if(autocomplete_state==AutocompleteState::SHOWN) { if(autocomplete_dialog && autocomplete_dialog->shown) {
if(autocomplete_dialog->on_key_press(key)) if(autocomplete_dialog->on_key_press(key))
return true; return true;
} }
@ -743,7 +737,6 @@ void Source::ClangViewAutocomplete::autocomplete_dialog_setup() {
autocomplete_dialog_rows.clear(); autocomplete_dialog_rows.clear();
autocomplete_dialog->on_hide=[this](){ autocomplete_dialog->on_hide=[this](){
get_source_buffer()->end_user_action(); get_source_buffer()->end_user_action();
autocomplete_state=AutocompleteState::IDLE;
parsed=false; parsed=false;
soft_reparse(); soft_reparse();
}; };
@ -759,7 +752,6 @@ void Source::ClangViewAutocomplete::autocomplete_dialog_setup() {
} }
get_buffer()->insert(autocomplete_dialog->start_mark->get_iter(), row); get_buffer()->insert(autocomplete_dialog->start_mark->get_iter(), row);
if(hide_window) { if(hide_window) {
autocomplete_state=AutocompleteState::IDLE;
auto para_pos=row.find('('); auto para_pos=row.find('(');
auto angle_pos=row.find('<'); auto angle_pos=row.find('<');
size_t start_pos=std::string::npos; size_t start_pos=std::string::npos;
@ -793,12 +785,10 @@ void Source::ClangViewAutocomplete::autocomplete_dialog_setup() {
else { else {
//new autocomplete after for instance when selecting "std::" //new autocomplete after for instance when selecting "std::"
auto iter=get_buffer()->get_insert()->get_iter(); auto iter=get_buffer()->get_insert()->get_iter();
if(iter.backward_char() && *iter==':') { if(iter.backward_char() && *iter==':')
autocomplete_state=AutocompleteState::IDLE;
autocomplete_restart(); autocomplete_restart();
} }
} }
}
}; };
} }
@ -815,14 +805,14 @@ void Source::ClangViewAutocomplete::autocomplete_check() {
prefix_mutex.lock(); prefix_mutex.lock();
prefix=sm[3].str(); prefix=sm[3].str();
prefix_mutex.unlock(); prefix_mutex.unlock();
if(autocomplete_state==AutocompleteState::IDLE && (prefix.size()==0 || prefix[0]<'0' || prefix[0]>'9')) if(prefix.size()==0 || prefix[0]<'0' || prefix[0]>'9')
autocomplete(); autocomplete();
} }
else if(boost::regex_match(line, sm, within_namespace)) { else if(boost::regex_match(line, sm, within_namespace)) {
prefix_mutex.lock(); prefix_mutex.lock();
prefix=sm[3].str(); prefix=sm[3].str();
prefix_mutex.unlock(); prefix_mutex.unlock();
if(autocomplete_state==AutocompleteState::IDLE && (prefix.size()==0 || prefix[0]<'0' || prefix[0]>'9')) if(prefix.size()==0 || prefix[0]<'0' || prefix[0]>'9')
autocomplete(); autocomplete();
} }
if(autocomplete_state!=AutocompleteState::IDLE) if(autocomplete_state!=AutocompleteState::IDLE)
@ -832,12 +822,13 @@ void Source::ClangViewAutocomplete::autocomplete_check() {
void Source::ClangViewAutocomplete::autocomplete() { void Source::ClangViewAutocomplete::autocomplete() {
if(parse_state!=ParseState::PROCESSING) if(parse_state!=ParseState::PROCESSING)
return; return;
if(autocomplete_state==AutocompleteState::STARTING) {
autocomplete_state=AutocompleteState::CANCELED;
return;
}
if(autocomplete_state==AutocompleteState::CANCELED) if(autocomplete_state==AutocompleteState::CANCELED)
autocomplete_state=AutocompleteState::RESTARTING;
if(autocomplete_state!=AutocompleteState::IDLE)
return; return;
autocomplete_state=AutocompleteState::STARTING; autocomplete_state=AutocompleteState::STARTING;
autocomplete_data.clear(); autocomplete_data.clear();

3
src/source_clang.h

@ -72,7 +72,7 @@ namespace Source {
class ClangViewAutocomplete : public ClangViewParse { class ClangViewAutocomplete : public ClangViewParse {
protected: protected:
enum class AutocompleteState {IDLE, STARTING, CANCELED, SHOWN}; enum class AutocompleteState {IDLE, STARTING, RESTARTING, CANCELED};
public: public:
class AutoCompleteData { class AutoCompleteData {
public: public:
@ -101,7 +101,6 @@ namespace Source {
void autocomplete_check(); void autocomplete_check();
void autocomplete(); void autocomplete();
std::vector<AutoCompleteData> autocomplete_data; std::vector<AutoCompleteData> autocomplete_data;
std::unique_ptr<CompletionDialog> autocomplete_dialog;
std::unordered_map<std::string, std::string> autocomplete_dialog_rows; std::unordered_map<std::string, std::string> autocomplete_dialog_rows;
std::vector<AutoCompleteData> autocomplete_get_suggestions(const std::string &buffer, int line_number, int column); std::vector<AutoCompleteData> autocomplete_get_suggestions(const std::string &buffer, int line_number, int column);
Glib::Dispatcher autocomplete_done; Glib::Dispatcher autocomplete_done;

27
src/window.cc

@ -1,4 +1,3 @@
#include "window.h" #include "window.h"
#include "logging.h" #include "logging.h"
#include "config.h" #include "config.h"
@ -25,7 +24,7 @@ namespace sigc {
Window::Window() : compiling(false) { Window::Window() : compiling(false) {
JDEBUG("start"); JDEBUG("start");
set_title("juCi++"); set_title("juCi++");
set_events(Gdk::POINTER_MOTION_MASK|Gdk::FOCUS_CHANGE_MASK|Gdk::SCROLL_MASK); set_events(Gdk::POINTER_MOTION_MASK|Gdk::FOCUS_CHANGE_MASK|Gdk::SCROLL_MASK|Gdk::LEAVE_NOTIFY_MASK);
set_menu_actions(); set_menu_actions();
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);
@ -411,6 +410,7 @@ void Window::set_menu_actions() {
if(notebook.get_current_page()!=-1 && notebook.get_current_view()==view) { if(notebook.get_current_page()!=-1 && notebook.get_current_view()==view) {
view->get_buffer()->place_cursor(view->get_buffer()->get_iter_at_line_index(line, index)); view->get_buffer()->place_cursor(view->get_buffer()->get_iter_at_line_index(line, index));
view->scroll_to(view->get_buffer()->get_insert(), 0.0, 1.0, 0.5); view->scroll_to(view->get_buffer()->get_insert(), 0.0, 1.0, 0.5);
view->delayed_tooltips_connection.disconnect();
} }
} }
} }
@ -517,11 +517,26 @@ void Window::set_menu_actions() {
return; return;
CMake cmake(cmake_path); CMake cmake(cmake_path);
auto executables = cmake.get_functions_parameters("add_executable"); auto executables = cmake.get_functions_parameters("add_executable");
//Attempt to find executable based add_executable files and opened tab
boost::filesystem::path executable_path; boost::filesystem::path executable_path;
if(executables.size()>0 && executables[0].second.size()>0) { if(notebook.get_current_page()!=-1) {
executable_path=executables[0].first.parent_path(); for(auto &executable: executables) {
executable_path+="/"+executables[0].second[0]; if(executable.second.size()>1) {
for(size_t c=1;c<executable.second.size();c++) {
if(executable.second[c]==notebook.get_current_view()->file_path.filename()) {
executable_path=executable.first.parent_path()/executable.second[0];
break;
}
} }
}
if(!executable_path.empty())
break;
}
}
if(executable_path.empty() && executables.size()>0 && executables[0].second.size()>0)
executable_path=executables[0].first.parent_path()/executables[0].second[0];
if(cmake.project_path!="") { if(cmake.project_path!="") {
if(executable_path!="") { if(executable_path!="") {
compiling=true; compiling=true;
@ -591,7 +606,7 @@ void Window::set_menu_actions() {
}); });
} }
entry_box.hide(); entry_box.hide();
}); }, 30);
auto entry_it=entry_box.entries.begin(); auto entry_it=entry_box.entries.begin();
entry_it->set_placeholder_text("Command"); entry_it->set_placeholder_text("Command");
entry_box.buttons.emplace_back("Run command", [this, entry_it](){ entry_box.buttons.emplace_back("Run command", [this, entry_it](){

Loading…
Cancel
Save