Browse Source

Merge pull request #110 from cppit/various_fixes

Better auto indent tab char and size setting and link to improved tiny-process-library
merge-requests/365/head
Jørgen Lien Sellæg 10 years ago
parent
commit
e44116e2eb
  1. 2
      .gitmodules
  2. 8
      src/config.cc
  3. 16
      src/directories.cc
  4. 4
      src/directories.h
  5. 2
      src/files.h
  6. 3
      src/juci.cc
  7. 157
      src/source.cc
  8. 5
      src/source_clang.cc
  9. 11
      src/window.cc
  10. 2
      tiny-process-library

2
.gitmodules vendored

@ -5,4 +5,4 @@
[submodule "tiny-process-library"] [submodule "tiny-process-library"]
path = tiny-process-library path = tiny-process-library
url = https://github.com/eidheim/tiny-process-library url = https://github.com/eidheim/tiny-process-library
branch = v1.0.1 branch = v1.0.2

8
src/config.cc

@ -14,10 +14,10 @@ Config::Config() {
for (auto &variable : environment_variables) { for (auto &variable : environment_variables) {
ptr=std::getenv(variable.c_str()); ptr=std::getenv(variable.c_str());
if (ptr!=nullptr && boost::filesystem::exists(ptr)) { if (ptr!=nullptr && boost::filesystem::exists(ptr)) {
home /= ptr; home /= ptr;
home /= ".juci"; home /= ".juci";
break; break;
} }
} }
if(home.empty()) { if(home.empty()) {
std::string searched_envs = "["; std::string searched_envs = "[";

16
src/directories.cc

@ -35,13 +35,13 @@ Directories::Directories() : Gtk::TreeView(), stop_update_thread(false) {
signal_row_activated().connect([this](const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* column){ signal_row_activated().connect([this](const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* column){
auto iter = tree_store->get_iter(path); auto iter = tree_store->get_iter(path);
if (iter) { if (iter) {
auto path_str=iter->get_value(column_record.path); auto filesystem_path=iter->get_value(column_record.path);
if(path_str!="") { if(filesystem_path!="") {
if (boost::filesystem::is_directory(boost::filesystem::path(path_str))) { if (boost::filesystem::is_directory(boost::filesystem::path(filesystem_path))) {
row_expanded(path) ? collapse_row(path) : expand_row(path, false); row_expanded(path) ? collapse_row(path) : expand_row(path, false);
} else { } else {
if(on_row_activated) if(on_row_activated)
on_row_activated(path_str); on_row_activated(filesystem_path);
} }
} }
} }
@ -57,7 +57,7 @@ Directories::Directories() : Gtk::TreeView(), stop_update_thread(false) {
}); });
signal_row_collapsed().connect([this](const Gtk::TreeModel::iterator& iter, const Gtk::TreeModel::Path& path){ signal_row_collapsed().connect([this](const Gtk::TreeModel::iterator& iter, const Gtk::TreeModel::Path& path){
update_mutex.lock(); update_mutex.lock();
last_write_times.erase(iter->get_value(column_record.path)); last_write_times.erase(iter->get_value(column_record.path).string());
update_mutex.unlock(); update_mutex.unlock();
auto children=iter->children(); auto children=iter->children();
if(children) { if(children) {
@ -170,7 +170,7 @@ void Directories::select(const boost::filesystem::path &path) {
for(auto &a_path: paths) { for(auto &a_path: paths) {
tree_store->foreach_iter([this, &a_path](const Gtk::TreeModel::iterator& iter){ tree_store->foreach_iter([this, &a_path](const Gtk::TreeModel::iterator& iter){
if(iter->get_value(column_record.path)==a_path.string()) { if(iter->get_value(column_record.path)==a_path) {
update_mutex.lock(); update_mutex.lock();
add_path(a_path, *iter); add_path(a_path, *iter);
update_mutex.unlock(); update_mutex.unlock();
@ -181,7 +181,7 @@ void Directories::select(const boost::filesystem::path &path) {
} }
tree_store->foreach_iter([this, &path](const Gtk::TreeModel::iterator& iter){ tree_store->foreach_iter([this, &path](const Gtk::TreeModel::iterator& iter){
if(iter->get_value(column_record.path)==path.string()) { if(iter->get_value(column_record.path)==path) {
auto tree_path=Gtk::TreePath(iter); auto tree_path=Gtk::TreePath(iter);
expand_to_path(tree_path); expand_to_path(tree_path);
set_cursor(tree_path); set_cursor(tree_path);
@ -225,7 +225,7 @@ void Directories::add_path(const boost::filesystem::path& dir_path, const Gtk::T
auto child = tree_store->append(*children); auto child = tree_store->append(*children);
not_deleted.emplace(filename); not_deleted.emplace(filename);
child->set_value(column_record.name, filename); child->set_value(column_record.name, filename);
child->set_value(column_record.path, it->path().string()); child->set_value(column_record.path, it->path());
if (boost::filesystem::is_directory(it->path())) { if (boost::filesystem::is_directory(it->path())) {
child->set_value(column_record.id, "a"+filename); child->set_value(column_record.id, "a"+filename);
auto grandchild=tree_store->append(child->children()); auto grandchild=tree_store->append(child->children());

4
src/directories.h

@ -22,7 +22,7 @@ public:
} }
Gtk::TreeModelColumn<std::string> id; Gtk::TreeModelColumn<std::string> id;
Gtk::TreeModelColumn<std::string> name; Gtk::TreeModelColumn<std::string> name;
Gtk::TreeModelColumn<std::string> path; Gtk::TreeModelColumn<boost::filesystem::path> path;
Gtk::TreeModelColumn<Gdk::RGBA> color; Gtk::TreeModelColumn<Gdk::RGBA> color;
}; };
@ -38,7 +38,7 @@ public:
void update(); void update();
void select(const boost::filesystem::path &path); void select(const boost::filesystem::path &path);
std::function<void(const std::string &file)> on_row_activated; std::function<void(const boost::filesystem::path &path)> on_row_activated;
std::unique_ptr<CMake> cmake; std::unique_ptr<CMake> cmake;
boost::filesystem::path current_path; boost::filesystem::path current_path;

2
src/files.h

@ -2,7 +2,7 @@
#define JUCI_FILES_H_ #define JUCI_FILES_H_
#include <string> #include <string>
#define JUCI_VERSION "0.9.6" #define JUCI_VERSION "1.0.0"
const std::string configjson = const std::string configjson =
"{\n" "{\n"

3
src/juci.cc

@ -30,8 +30,7 @@ int Application::on_command_line(const Glib::RefPtr<Gio::ApplicationCommandLine>
boost::system::error_code ec; boost::system::error_code ec;
auto new_p=boost::filesystem::canonical(parent_p, ec); auto new_p=boost::filesystem::canonical(parent_p, ec);
if(!ec && boost::filesystem::is_directory(new_p)) { if(!ec && boost::filesystem::is_directory(new_p)) {
new_p+="/"; new_p/=p.filename();
new_p+=p.filename();
files.emplace_back(new_p); files.emplace_back(new_p);
} }
else else

157
src/source.cc

@ -520,7 +520,7 @@ void Source::View::replace_backward(const std::string &replacement) {
auto &start=selection_bound; auto &start=selection_bound;
Gtk::TextIter match_start, match_end; Gtk::TextIter match_start, match_end;
if(gtk_source_search_context_backward(search_context, start.gobj(), match_start.gobj(), match_end.gobj())) { if(gtk_source_search_context_backward(search_context, start.gobj(), match_start.gobj(), match_end.gobj())) {
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())); get_buffer()->select_range(get_buffer()->get_iter_at_offset(offset), get_buffer()->get_iter_at_offset(offset+replacement.size()));
@ -557,7 +557,7 @@ void Source::View::paste() {
bool first_paste_line=true; bool first_paste_line=true;
size_t paste_line_tabs=-1; size_t paste_line_tabs=-1;
bool first_paste_line_has_tabs=false; bool first_paste_line_has_tabs=false;
for(size_t c=0;c<text.size();c++) {; for(size_t c=0;c<text.size();c++) {
if(text[c]=='\n') { if(text[c]=='\n') {
end_line=c; end_line=c;
paste_line=true; paste_line=true;
@ -1172,36 +1172,141 @@ bool Source::View::on_button_press_event(GdkEventButton *event) {
} }
std::pair<char, unsigned> Source::View::find_tab_char_and_size() { std::pair<char, unsigned> Source::View::find_tab_char_and_size() {
auto size=get_buffer()->get_line_count();
std::unordered_map<char, size_t> tab_chars; std::unordered_map<char, size_t> tab_chars;
std::unordered_map<unsigned, size_t> tab_sizes; std::unordered_map<unsigned, size_t> tab_sizes;
unsigned last_tab_size=0; auto iter=get_buffer()->begin();
for(int c=0;c<size;c++) { long tab_count=-1;
auto tabs_end_iter=get_tabs_end_iter(c); long last_tab_count=0;
if(tabs_end_iter.starts_line() && tabs_end_iter.ends_line()) bool single_quoted=false;
continue; bool double_quoted=false;
std::string str=get_line_before(tabs_end_iter); //For bracket languages, TODO: add more language ids
if(language && (language->get_id()=="chdr" || language->get_id()=="cpphdr" || language->get_id()=="c" ||
long tab_diff=abs(static_cast<long>(str.size()-last_tab_size)); language->get_id()=="cpp" || language->get_id()=="objc" || language->get_id()=="java" ||
if(tab_diff>0) { language->get_id()=="javascript")) {
unsigned tab_diff_unsigned=static_cast<unsigned>(tab_diff); bool line_comment=false;
auto it_size=tab_sizes.find(tab_diff_unsigned); bool comment=false;
if(it_size!=tab_sizes.end()) bool bracket_last_line=false;
it_size->second++; char last_char=0;
else long last_tab_diff=-1;
tab_sizes[tab_diff_unsigned]=1; while(iter) {
} if(iter.starts_line()) {
line_comment=false;
single_quoted=false;
double_quoted=false;
tab_count=0;
if(last_char=='{')
bracket_last_line=true;
else
bracket_last_line=false;
}
if(bracket_last_line && tab_count!=-1) {
if(*iter==' ') {
tab_chars[' ']++;
tab_count++;
}
else if(*iter=='\t') {
tab_chars['\t']++;
tab_count++;
}
else {
auto line_iter=iter;
char last_line_char=0;
while(line_iter && !line_iter.ends_line()) {
if(*line_iter!=' ' && *line_iter!='\t')
last_line_char=*line_iter;
if(*line_iter=='(')
break;
line_iter.forward_char();
}
if(last_line_char==':' || *iter=='#') {
tab_count=0;
if((iter.get_line()+1) < get_buffer()->get_line_count()) {
iter=get_buffer()->get_iter_at_line(iter.get_line()+1);
continue;
}
}
else if(!iter.ends_line()) {
if(tab_count!=last_tab_count)
tab_sizes[abs(tab_count-last_tab_count)]++;
last_tab_diff=abs(tab_count-last_tab_count);
last_tab_count=tab_count;
last_char=0;
}
}
}
last_tab_size=str.size(); auto prev_iter=iter;
prev_iter.backward_char();
auto prev_prev_iter=prev_iter;
prev_prev_iter.backward_char();
if(!double_quoted && *iter=='\'' && !(*prev_iter=='\\' && *prev_prev_iter!='\\'))
single_quoted=!single_quoted;
else if(!single_quoted && *iter=='\"' && !(*prev_iter=='\\' && *prev_prev_iter!='\\'))
double_quoted=!double_quoted;
else if(!single_quoted && !double_quoted) {
auto next_iter=iter;
next_iter.forward_char();
if(*iter=='/' && *next_iter=='/')
line_comment=true;
else if(*iter=='/' && *next_iter=='*')
comment=true;
else if(*iter=='*' && *next_iter=='/') {
iter.forward_char();
iter.forward_char();
comment=false;
}
}
if(!single_quoted && !double_quoted && !comment && !line_comment && *iter!=' ' && *iter!='\t' && !iter.ends_line())
last_char=*iter;
if(!single_quoted && !double_quoted && !comment && !line_comment && *iter=='}' && tab_count!=-1 && last_tab_diff!=-1)
last_tab_count-=last_tab_diff;
if(*iter!=' ' && *iter!='\t')
tab_count=-1;
iter.forward_char();
}
}
else {
long para_count=0;
while(iter) {
if(iter.starts_line())
tab_count=0;
if(tab_count!=-1 && para_count==0 && single_quoted==false && double_quoted==false) {
if(*iter==' ') {
tab_chars[' ']++;
tab_count++;
}
else if(*iter=='\t') {
tab_chars['\t']++;
tab_count++;
}
else if(!iter.ends_line()) {
if(tab_count!=last_tab_count)
tab_sizes[abs(tab_count-last_tab_count)]++;
last_tab_count=tab_count;
}
}
auto prev_iter=iter;
prev_iter.backward_char();
auto prev_prev_iter=prev_iter;
prev_prev_iter.backward_char();
if(!double_quoted && *iter=='\'' && !(*prev_iter=='\\' && *prev_prev_iter!='\\'))
single_quoted=!single_quoted;
else if(!single_quoted && *iter=='\"' && !(*prev_iter=='\\' && *prev_prev_iter!='\\'))
double_quoted=!double_quoted;
else if(!single_quoted && !double_quoted) {
if(*iter=='(')
para_count++;
else if(*iter==')')
para_count--;
}
if(*iter!=' ' && *iter!='\t')
tab_count=-1;
if(str.size()>0) { iter.forward_char();
auto it_char=tab_chars.find(str[0]);
if(it_char!=tab_chars.end())
it_char->second++;
else
tab_chars[str[0]]=1;
} }
} }
char found_tab_char=0; char found_tab_char=0;
size_t occurences=0; size_t occurences=0;
for(auto &tab_char: tab_chars) { for(auto &tab_char: tab_chars) {

5
src/source_clang.cc

@ -664,7 +664,7 @@ Source::ClangViewParse(file_path, project_path, language), autocomplete_state(Au
return false; return false;
}); });
autocomplete_error_connection=autocomplete_done.connect([this](){ autocomplete_done_connection=autocomplete_done.connect([this](){
if(autocomplete_state==AutocompleteState::CANCELED) { if(autocomplete_state==AutocompleteState::CANCELED) {
set_status(""); set_status("");
soft_reparse(); soft_reparse();
@ -932,6 +932,7 @@ bool Source::ClangViewAutocomplete::full_reparse() {
if(!parse_state.compare_exchange_strong(expected, ParseState::RESTARTING)) if(!parse_state.compare_exchange_strong(expected, ParseState::RESTARTING))
return false; return false;
} }
autocomplete_state=AutocompleteState::IDLE;
soft_reparse_needed=false; soft_reparse_needed=false;
full_reparse_running=true; full_reparse_running=true;
if(full_reparse_thread.joinable()) if(full_reparse_thread.joinable())
@ -1397,7 +1398,7 @@ void Source::ClangView::async_delete() {
parse_postprocess_connection.disconnect(); parse_postprocess_connection.disconnect();
parse_preprocess_connection.disconnect(); parse_preprocess_connection.disconnect();
parse_error_connection.disconnect(); parse_error_connection.disconnect();
autocomplete_error_connection.disconnect(); autocomplete_done_connection.disconnect();
autocomplete_restart_connection.disconnect(); autocomplete_restart_connection.disconnect();
autocomplete_error_connection.disconnect(); autocomplete_error_connection.disconnect();
do_restart_parse_connection.disconnect(); do_restart_parse_connection.disconnect();

11
src/window.cc

@ -1,3 +1,4 @@
#include "window.h" #include "window.h"
#include "logging.h" #include "logging.h"
#include "config.h" #include "config.h"
@ -55,8 +56,8 @@ Window::Window() : compiling(false) {
show_all_children(); show_all_children();
Directories::get().on_row_activated=[this](const std::string &file) { Directories::get().on_row_activated=[this](const boost::filesystem::path &path) {
notebook.open(file); notebook.open(path);
}; };
//Scroll to end of terminal whenever info is printed //Scroll to end of terminal whenever info is printed
@ -164,7 +165,7 @@ void Window::set_menu_actions() {
if(filesystem::write(path)) { if(filesystem::write(path)) {
if(Directories::get().current_path!="") if(Directories::get().current_path!="")
Directories::get().update(); Directories::get().update();
notebook.open(path.string()); notebook.open(path);
Terminal::get().print("New file "+path.string()+" created.\n"); Terminal::get().print("New file "+path.string()+" created.\n");
} }
else else
@ -197,9 +198,9 @@ void Window::set_menu_actions() {
project_name[c]='_'; project_name[c]='_';
} }
auto cmakelists_path=project_path; auto cmakelists_path=project_path;
cmakelists_path+="/CMakeLists.txt"; cmakelists_path/="CMakeLists.txt";
auto cpp_main_path=project_path; auto cpp_main_path=project_path;
cpp_main_path+="/main.cpp"; cpp_main_path/="main.cpp";
if(boost::filesystem::exists(cmakelists_path)) { if(boost::filesystem::exists(cmakelists_path)) {
Terminal::get().print("Error: "+cmakelists_path.string()+" already exists.\n", true); Terminal::get().print("Error: "+cmakelists_path.string()+" already exists.\n", true);
return; return;

2
tiny-process-library

@ -1 +1 @@
Subproject commit 3307488fbf733b18de9b274fe3249d9d54497a06 Subproject commit 2805253ae779ac6f8fc28c0c55e96c37b87e571d
Loading…
Cancel
Save