Browse Source

Fixed crash on Windows, and now uses std::to_string instead of lexical casts.

merge-requests/365/head
U-ole-PC\ole 10 years ago
parent
commit
0149193a39
  1. 21
      src/source.cc
  2. 32
      src/window.cc

21
src/source.cc

@ -6,7 +6,6 @@
#include <algorithm> #include <algorithm>
#include "singletons.h" #include "singletons.h"
#include <gtksourceview/gtksource.h> #include <gtksourceview/gtksource.h>
#include <boost/lexical_cast.hpp>
#include <iostream> #include <iostream>
using namespace std; //TODO: remove using namespace std; //TODO: remove
@ -331,7 +330,7 @@ void Source::View::configure() {
tab_str="<space>"; tab_str="<space>";
else else
tab_str="<tab>"; tab_str="<tab>";
Singleton::terminal()->print("Tab char and size for file "+file_path.string()+" set to: "+tab_str+", "+boost::lexical_cast<std::string>(tab_char_and_size.second)+".\n"); Singleton::terminal()->print("Tab char and size for file "+file_path.string()+" set to: "+tab_str+", "+std::to_string(tab_char_and_size.second)+".\n");
} }
tab_char=tab_char_and_size.first; tab_char=tab_char_and_size.first;
@ -1422,17 +1421,13 @@ void Source::ClangViewParse::update_syntax() {
buffer->remove_tag_by_name(tag, buffer->begin(), buffer->end()); buffer->remove_tag_by_name(tag, buffer->begin(), buffer->end());
last_syntax_tags.clear(); last_syntax_tags.clear();
for (auto &range : ranges) { for (auto &range : ranges) {
auto type = boost::lexical_cast<std::string>(range.kind); auto type_it=Singleton::Config::source()->clang_types.find(std::to_string(range.kind));
try { if(type_it!=Singleton::Config::source()->clang_types.end()) {
last_syntax_tags.emplace(Singleton::Config::source()->clang_types.at(type)); last_syntax_tags.emplace(type_it->second);
} catch (std::exception) { Gtk::TextIter begin_iter = buffer->get_iter_at_line_index(range.offsets.first.line-1, range.offsets.first.index-1);
//cout << range.kind << ": " << range.offsets.first.line << ", " << range.offsets.first.index << endl; //TODO: remove Gtk::TextIter end_iter = buffer->get_iter_at_line_index(range.offsets.second.line-1, range.offsets.second.index-1);
continue; buffer->apply_tag_by_name(type_it->second, begin_iter, end_iter);
} }
Gtk::TextIter begin_iter = buffer->get_iter_at_line_index(range.offsets.first.line-1, range.offsets.first.index-1);
Gtk::TextIter end_iter = buffer->get_iter_at_line_index(range.offsets.second.line-1, range.offsets.second.index-1);
buffer->apply_tag_by_name(Singleton::Config::source()->clang_types.at(type), begin_iter, end_iter);
} }
} }
@ -1950,7 +1945,7 @@ void Source::ClangViewAutocomplete::autocomplete() {
autocomplete_thread=std::thread([this, ac_data, line_nr, column_nr, buffer_map](){ autocomplete_thread=std::thread([this, ac_data, line_nr, column_nr, buffer_map](){
parsing_mutex.lock(); parsing_mutex.lock();
if(!parse_thread_stop) if(!parse_thread_stop)
*ac_data=move(get_autocomplete_suggestions(line_nr, column_nr, *buffer_map)); *ac_data=get_autocomplete_suggestions(line_nr, column_nr, *buffer_map);
if(!parse_thread_stop) if(!parse_thread_stop)
autocomplete_done(); autocomplete_done();
else else

32
src/window.cc

@ -4,7 +4,6 @@
#include "sourcefile.h" #include "sourcefile.h"
#include "config.h" #include "config.h"
//#include "api.h" //#include "api.h"
#include <boost/lexical_cast.hpp>
#include <iostream> //TODO: remove #include <iostream> //TODO: remove
using namespace std; //TODO: remove using namespace std; //TODO: remove
@ -100,7 +99,7 @@ Window::Window() : box(Gtk::ORIENTATION_VERTICAL), notebook(directories), compil
if(notebook.get_current_page()!=-1) { if(notebook.get_current_page()!=-1) {
if(search_entry_shown && entry_box.labels.size()>0) { if(search_entry_shown && entry_box.labels.size()>0) {
notebook.get_current_view()->update_search_occurrences=[this](int number){ notebook.get_current_view()->update_search_occurrences=[this](int number){
entry_box.labels.begin()->update(0, boost::lexical_cast<std::string>(number)); entry_box.labels.begin()->update(0, std::to_string(number));
}; };
notebook.get_current_view()->search_highlight(last_search, case_sensitive_search, regex_search); notebook.get_current_view()->search_highlight(last_search, case_sensitive_search, regex_search);
} }
@ -327,7 +326,7 @@ void Window::create_menu() {
last_char=executable_path_spaces_fixed[c]; last_char=executable_path_spaces_fixed[c];
} }
Singleton::terminal()->async_execute(executable_path_spaces_fixed, project_path, [this, executable_path](int exit_code){ Singleton::terminal()->async_execute(executable_path_spaces_fixed, project_path, [this, executable_path](int exit_code){
Singleton::terminal()->async_print(executable_path.string()+" returned: "+boost::lexical_cast<std::string>(exit_code)+'\n'); Singleton::terminal()->async_print(executable_path.string()+" returned: "+std::to_string(exit_code)+'\n');
}); });
} }
}); });
@ -358,7 +357,7 @@ void Window::create_menu() {
last_run_command=content; last_run_command=content;
Singleton::terminal()->async_print("Running: "+content+'\n'); Singleton::terminal()->async_print("Running: "+content+'\n');
Singleton::terminal()->async_execute(content, directories.current_path, [this, content](int exit_code){ Singleton::terminal()->async_execute(content, directories.current_path, [this, content](int exit_code){
Singleton::terminal()->async_print(content+" returned: "+boost::lexical_cast<std::string>(exit_code)+'\n'); Singleton::terminal()->async_print(content+" returned: "+std::to_string(exit_code)+'\n');
}); });
} }
entry_box.hide(); entry_box.hide();
@ -633,13 +632,16 @@ void Window::search_and_replace_entry() {
auto label_it=entry_box.labels.begin(); auto label_it=entry_box.labels.begin();
label_it->update=[label_it](int state, const std::string& message){ label_it->update=[label_it](int state, const std::string& message){
if(state==0) { if(state==0) {
auto number = boost::lexical_cast<int>(message); try {
if(number==0) auto number = stoi(message);
label_it->set_text(""); if(number==0)
else if(number==1) label_it->set_text("");
label_it->set_text("1 result found"); else if(number==1)
else if(number>1) label_it->set_text("1 result found");
label_it->set_text(boost::lexical_cast<std::string>(number)+" results found"); else if(number>1)
label_it->set_text(message+" results found");
}
catch(const std::exception &e) {}
} }
}; };
entry_box.entries.emplace_back(last_search, [this](const std::string& content){ entry_box.entries.emplace_back(last_search, [this](const std::string& content){
@ -650,7 +652,7 @@ void Window::search_and_replace_entry() {
search_entry_it->set_placeholder_text("Find"); search_entry_it->set_placeholder_text("Find");
if(notebook.get_current_page()!=-1) { if(notebook.get_current_page()!=-1) {
notebook.get_current_view()->update_search_occurrences=[label_it](int number){ notebook.get_current_view()->update_search_occurrences=[label_it](int number){
label_it->update(0, boost::lexical_cast<std::string>(number)); label_it->update(0, std::to_string(number));
}; };
notebook.get_current_view()->search_highlight(search_entry_it->get_text(), case_sensitive_search, regex_search); notebook.get_current_view()->search_highlight(search_entry_it->get_text(), case_sensitive_search, regex_search);
} }
@ -721,8 +723,8 @@ void Window::goto_line_entry() {
if(notebook.get_current_page()!=-1) { if(notebook.get_current_page()!=-1) {
auto buffer=notebook.get_current_view()->get_buffer(); auto buffer=notebook.get_current_view()->get_buffer();
try { try {
auto line = boost::lexical_cast<unsigned>(content); auto line = stoi(content);
if(line>0 && line<=(unsigned long)buffer->get_line_count()) { if(line>0 && line<=buffer->get_line_count()) {
line--; line--;
buffer->place_cursor(buffer->get_iter_at_line(line)); buffer->place_cursor(buffer->get_iter_at_line(line));
while(gtk_events_pending()) while(gtk_events_pending())
@ -762,7 +764,7 @@ void Window::rename_token_entry() {
if(view->rename_similar_tokens) { if(view->rename_similar_tokens) {
auto number=view->rename_similar_tokens(*token, content); auto number=view->rename_similar_tokens(*token, content);
if(number>0) { if(number>0) {
Singleton::terminal()->print("Replaced "+boost::lexical_cast<std::string>(number)+" occurrences in file "+view->file_path.string()+"\n"); Singleton::terminal()->print("Replaced "+std::to_string(number)+" occurrences in file "+view->file_path.string()+"\n");
notebook.save(c); notebook.save(c);
} }
} }

Loading…
Cancel
Save