Browse Source

Added status messages when parsing and autocompleting a ClangView.

merge-requests/365/head
eidheim 11 years ago
parent
commit
93f014c8af
  1. 5
      src/notebook.cc
  2. 6
      src/singletons.cc
  3. 3
      src/singletons.h
  4. 15
      src/source.cc
  5. 13
      src/source.h
  6. 10
      src/window.cc
  7. 4
      src/window.h

5
src/notebook.cc

@ -87,6 +87,11 @@ void Notebook::open(std::string path) {
if(page!=-1)
set_tab_label_text(*(get_nth_page(page)), title);
});
get_current_view()->on_update_status=[this](Source::View* view, const std::string &status) {
if(get_current_view()==view)
Singleton::status()->set_text(status);
};
}
bool Notebook::save(int page) {

6
src/singletons.cc

@ -10,3 +10,9 @@ Terminal *Singleton::terminal() {
terminal_=std::unique_ptr<Terminal>(new Terminal());
return terminal_.get();
}
std::unique_ptr<Gtk::Label> Singleton::status_=std::unique_ptr<Gtk::Label>();
Gtk::Label *Singleton::status() {
if(!status_)
status_=std::unique_ptr<Gtk::Label>(new Gtk::Label());
return status_.get();
}

3
src/singletons.h

@ -6,6 +6,7 @@
#include "terminal.h"
#include "notebook.h"
#include "menu.h"
#include <gtkmm.h>
#include <string>
class Singleton {
@ -23,8 +24,10 @@ public:
static std::string config_dir() { return std::string(getenv("HOME")) + "/.juci/config/"; }
static std::string log_dir() { return std::string(getenv("HOME")) + "/.juci/log/"; }
static Terminal *terminal();
static Gtk::Label *status();
private:
static std::unique_ptr<Terminal> terminal_;
static std::unique_ptr<Gtk::Label> status_;
};
#endif // JUCI_SINGLETONS_H_

15
src/source.cc

@ -134,6 +134,12 @@ void Source::View::replace_all(const std::string &replacement) {
gtk_source_search_context_replace_all(search_context, replacement.c_str(), replacement.size(), NULL);
}
void Source::View::set_status(const std::string &status) {
this->status=status;
if(on_update_status)
on_update_status(this, status);
}
string Source::View::get_line(size_t line_number) {
Gtk::TextIter line_it = get_source_buffer()->get_iter_at_line(line_number);
Gtk::TextIter line_end_it = line_it;
@ -343,6 +349,7 @@ parse_thread_go(true), parse_thread_mapped(false), parse_thread_stop(false) {
update_diagnostics();
update_types();
clang_readable=true;
set_status("");
parsing_mutex.unlock();
INFO("Syntax updated");
}
@ -353,6 +360,7 @@ parse_thread_go(true), parse_thread_mapped(false), parse_thread_stop(false) {
}
});
set_status("parsing...");
parse_thread=std::thread([this]() {
while(true) {
while(!parse_thread_go && !parse_thread_stop)
@ -418,6 +426,7 @@ void Source::ClangViewParse::start_reparse() {
delayed_reparse_connection=Glib::signal_timeout().connect([this]() {
clang_readable=false;
parse_thread_go=true;
set_status("parsing...");
return false;
}, 1000);
}
@ -838,14 +847,17 @@ void Source::ClangViewAutocomplete::autocomplete() {
completion_dialog->add_row(ss.str() + " --> " + return_value, data.brief_comments);
}
}
set_status("");
if (!rows->empty()) {
completion_dialog_shown=true;
get_source_buffer()->begin_user_action();
completion_dialog->show();
}
}
else
else {
set_status("");
start_autocomplete();
}
});
std::shared_ptr<std::map<std::string, std::string> > buffer_map=std::make_shared<std::map<std::string, std::string> >();
@ -859,6 +871,7 @@ void Source::ClangViewAutocomplete::autocomplete() {
column_nr--;
}
buffer+="\n";
set_status("autocomplete...");
std::thread autocomplete_thread([this, ac_data, line_nr, column_nr, buffer_map](){
parsing_mutex.lock();
*ac_data=move(get_autocomplete_suggestions(line_nr, column_nr, *buffer_map));

13
src/source.h

@ -56,10 +56,7 @@ namespace Source {
void replace_forward(const std::string &replacement);
void replace_backward(const std::string &replacement);
void replace_all(const std::string &replacement);
std::string get_line(size_t line_number);
std::string get_line_before_insert();
std::string file_path;
std::string project_path;
@ -69,7 +66,15 @@ namespace Source {
std::function<std::string()> get_token_name;
std::function<void(const std::string &token)> tag_similar_tokens;
std::function<size_t(const std::string &token, const std::string &text)> rename_similar_tokens;
std::function<void(View* view, const std::string &status)> on_update_status;
std::string status;
protected:
void set_status(const std::string &status);
std::string get_line(size_t line_number);
std::string get_line_before_insert();
bool on_key_press_event(GdkEventKey* key);
private:
GtkSourceSearchContext *search_context;

10
src/window.cc

@ -26,10 +26,14 @@ Window::Window() : box(Gtk::ORIENTATION_VERTICAL) {
directory_and_notebook_panes.pack1(directories, true, true);
directory_and_notebook_panes.pack2(notebook);
directory_and_notebook_panes.set_position(120);
vpaned.set_position(300);
vpaned.pack1(directory_and_notebook_panes, true, false);
vpaned.pack2(*Singleton::terminal(), true, true);
terminal_vbox.pack_start(*Singleton::terminal());
status_hbox.pack_end(*Singleton::status(), Gtk::PACK_SHRINK);
terminal_vbox.pack_end(status_hbox, Gtk::PACK_SHRINK);
vpaned.pack2(terminal_vbox, true, true);
box.pack_end(vpaned);
show_all_children();
@ -70,6 +74,8 @@ Window::Window() : box(Gtk::ORIENTATION_VERTICAL) {
menu_item->set_sensitive((bool)notebook.get_current_view()->rename_similar_tokens);
directories.select_path(notebook.get_current_view()->file_path);
Singleton::status()->set_text(notebook.get_current_view()->status);
}
});
INFO("Window created");

4
src/window.h

@ -1,7 +1,7 @@
#ifndef JUCI_WINDOW_H_
#define JUCI_WINDOW_H_
#include <cstddef>
#include "gtkmm.h"
#include "directories.h"
#include "entrybox.h"
#include "notebook.h"
@ -19,6 +19,8 @@ private:
Gtk::Box box;
Gtk::VPaned vpaned;
Gtk::Paned directory_and_notebook_panes;
Gtk::VBox terminal_vbox;
Gtk::HBox status_hbox;
EntryBox entry_box;
std::mutex running;
Menu menu;

Loading…
Cancel
Save