Browse Source

Merge pull request #171 from eidheim/master

Reopens last folder and files when starting juci without parameters. Also improved debug tooltips.
merge-requests/365/head
Ole Christian Eidheim 10 years ago
parent
commit
20c7f8e98b
  1. 2
      src/debug_clang.cc
  2. 4
      src/directories.cc
  3. 23
      src/juci.cc
  4. 15
      src/notebook.cc
  5. 2
      src/notebook.h
  6. 3
      src/source.cc
  7. 21
      src/source_clang.cc
  8. 32
      src/window.cc

2
src/debug_clang.cc

@ -405,7 +405,7 @@ std::string Debug::Clang::get_value(const std::string &variable, const boost::fi
} }
if(variable_value.empty()) { if(variable_value.empty()) {
//In case a variable is missing file and line number, only do check on name //In case a variable is missing file and line number, only do check on name
auto value=frame.FindVariable(variable.c_str()); auto value=frame.GetValueForVariablePath(variable.c_str());
if(value.IsValid()) { if(value.IsValid()) {
lldb::SBStream stream; lldb::SBStream stream;
value.GetDescription(stream); value.GetDescription(stream);

4
src/directories.cc

@ -95,10 +95,12 @@ bool Directories::TreeStore::drag_data_received_vfunc(const TreeModel::Path &pat
for(;file_it!=view->file_path.end();file_it++) for(;file_it!=view->file_path.end();file_it++)
new_file_path/=*file_it; new_file_path/=*file_it;
view->file_path=new_file_path; view->file_path=new_file_path;
g_signal_emit_by_name(view->get_buffer()->gobj(), "modified_changed");
} }
} }
if(view->file_path==source_path) { else if(view->file_path==source_path) {
view->file_path=target_path; view->file_path=target_path;
g_signal_emit_by_name(view->get_buffer()->gobj(), "modified_changed");
break; break;
} }
} }

23
src/juci.cc

@ -44,6 +44,26 @@ int Application::on_command_line(const Glib::RefPtr<Gio::ApplicationCommandLine>
void Application::on_activate() { void Application::on_activate() {
add_window(Window::get()); add_window(Window::get());
Window::get().show(); Window::get().show();
std::string last_current_file;
if(directories.empty() && files.empty()) {
try {
boost::property_tree::ptree pt;
boost::property_tree::read_json((Config::get().juci_home_path()/"last_session.json").string(), pt);
auto folder=pt.get<std::string>("folder");
if(!folder.empty())
directories.emplace_back(folder);
for(auto &v: pt.get_child("files")) {
std::string file=v.second.data();
if(!file.empty())
files.emplace_back(file);
}
last_current_file=pt.get<std::string>("current_file");
}
catch(const std::exception &) {}
}
bool first_directory=true; bool first_directory=true;
for(auto &directory: directories) { for(auto &directory: directories) {
if(first_directory) { if(first_directory) {
@ -73,6 +93,9 @@ void Application::on_activate() {
for(auto &error: errors) for(auto &error: errors)
Terminal::get().print(error, true); Terminal::get().print(error, true);
if(!last_current_file.empty())
Notebook::get().open(last_current_file);
} }
void Application::on_startup() { void Application::on_startup() {

15
src/notebook.cc

@ -25,9 +25,10 @@ namespace sigc {
#endif #endif
} }
Notebook::TabLabel::TabLabel(const std::string &title) : Gtk::Box(Gtk::ORIENTATION_HORIZONTAL) { Notebook::TabLabel::TabLabel(const boost::filesystem::path &path) : Gtk::Box(Gtk::ORIENTATION_HORIZONTAL) {
set_can_focus(false); set_can_focus(false);
label.set_text(title+' '); set_tooltip_text(path.string());
label.set_text(path.filename().string()+' ');
label.set_can_focus(false); label.set_can_focus(false);
button.set_image_from_icon_name("window-close-symbolic", Gtk::ICON_SIZE_MENU); button.set_image_from_icon_name("window-close-symbolic", Gtk::ICON_SIZE_MENU);
button.set_can_focus(false); button.set_can_focus(false);
@ -135,8 +136,7 @@ void Notebook::open(const boost::filesystem::path &file_path) {
configure(source_views.size()-1); configure(source_views.size()-1);
//Set up tab label //Set up tab label
std::string title=file_path.filename().string(); tab_labels.emplace_back(new TabLabel(file_path));
tab_labels.emplace_back(new TabLabel(title));
auto source_view=source_views.back(); auto source_view=source_views.back();
tab_labels.back()->button.signal_clicked().connect([this, source_view](){ tab_labels.back()->button.signal_clicked().connect([this, source_view](){
for(int c=0;c<size();c++) { for(int c=0;c<size();c++) {
@ -174,8 +174,11 @@ void Notebook::open(const boost::filesystem::path &file_path) {
break; break;
} }
} }
if(page!=-1) if(page!=-1) {
tab_labels.at(get_index(page))->label.set_text(title); auto &tab_label=tab_labels.at(get_index(page));
tab_label->label.set_text(title);
tab_label->set_tooltip_text(source_view->file_path.string());
}
}); });
JDEBUG("end"); JDEBUG("end");

2
src/notebook.h

@ -12,7 +12,7 @@
class Notebook : public Gtk::Notebook { class Notebook : public Gtk::Notebook {
class TabLabel : public Gtk::Box { class TabLabel : public Gtk::Box {
public: public:
TabLabel(const std::string &title); TabLabel(const boost::filesystem::path &path);
Gtk::Label label; Gtk::Label label;
Gtk::Button button; Gtk::Button button;
}; };

3
src/source.cc

@ -1307,8 +1307,9 @@ bool Source::View::on_key_press_event_basic(GdkEventKey* key) {
return true; return true;
} }
auto stop=Gsv::View::on_key_press_event(key);
get_source_buffer()->end_user_action(); get_source_buffer()->end_user_action();
return Gsv::View::on_key_press_event(key); return stop;
} }
//Bracket language indentation //Bracket language indentation

21
src/source_clang.cc

@ -413,7 +413,26 @@ void Source::ClangViewParse::show_type_tooltips(const Gdk::Rectangle &rectangle)
if(Debug::Clang::get().is_stopped()) { if(Debug::Clang::get().is_stopped()) {
auto location=token.get_cursor().get_referenced().get_source_location(); auto location=token.get_cursor().get_referenced().get_source_location();
Glib::ustring value_type="Value"; Glib::ustring value_type="Value";
Glib::ustring debug_value=Debug::Clang::get().get_value(token.get_spelling(), location.get_path(), location.get_offset().line, location.get_offset().index);
auto start=get_buffer()->get_iter_at_line_index(token.offsets.first.line-1, token.offsets.first.index-1);
auto end=get_buffer()->get_iter_at_line_index(token.offsets.second.line-1, token.offsets.second.index-1);
auto iter=start;
while((*iter>='a' && *iter<='z') || (*iter>='A' && *iter<='Z') || (*iter>='0' && *iter<='9') || *iter=='_' || *iter=='.') {
start=iter;
if(!iter.backward_char())
break;
if(*iter=='>') {
if(!(iter.backward_char() && *iter=='-' && iter.backward_char()))
break;
}
else if(*iter==':') {
if(!(iter.backward_char() && *iter==':' && iter.backward_char()))
break;
}
}
auto spelling=get_buffer()->get_text(start, end).raw();
Glib::ustring debug_value=Debug::Clang::get().get_value(spelling, location.get_path(), location.get_offset().line, location.get_offset().index);
if(debug_value.empty()) { if(debug_value.empty()) {
value_type="Return value"; value_type="Return value";
auto cursor=token.get_cursor(); auto cursor=token.get_cursor();

32
src/window.cc

@ -803,6 +803,21 @@ bool Window::on_key_press_event(GdkEventKey *event) {
} }
bool Window::on_delete_event(GdkEventAny *event) { bool Window::on_delete_event(GdkEventAny *event) {
try {
boost::property_tree::ptree pt_root, pt_files;
pt_root.put("folder", Directories::get().path.string());
for(int c=0;c<notebook.size();c++) {
boost::property_tree::ptree pt_child;
pt_child.put("", notebook.get_view(c)->file_path.string());
pt_files.push_back(std::make_pair("", pt_child));
}
pt_root.add_child("files", pt_files);
if(notebook.get_current_page()!=-1)
pt_root.put("current_file", notebook.get_current_view()->file_path.string());
boost::property_tree::write_json((Config::get().juci_home_path()/"last_session.json").string(), pt_root);
}
catch(const std::exception &) {}
auto size=notebook.size(); auto size=notebook.size();
for(int c=0;c<size;c++) { for(int c=0;c<size;c++) {
if(!notebook.close_current_page()) if(!notebook.close_current_page())
@ -876,34 +891,39 @@ void Window::search_and_replace_entry() {
replace_entry_it->signal_changed().connect([this, replace_entry_it](){ replace_entry_it->signal_changed().connect([this, replace_entry_it](){
last_replace=replace_entry_it->get_text(); last_replace=replace_entry_it->get_text();
}); });
EntryBox::get().buttons.emplace_back("", [this](){ EntryBox::get().buttons.emplace_back("", [this](){
if(notebook.get_current_page()!=-1) if(notebook.get_current_page()!=-1)
notebook.get_current_view()->search_backward(); notebook.get_current_view()->search_backward();
}); });
EntryBox::get().buttons.back().set_tooltip_text("Find previous\n\nShortcut: press Shift+Enter in the search field"); EntryBox::get().buttons.back().set_tooltip_text("Find Previous (shortcut: ⇧Enter in entry)");
EntryBox::get().buttons.emplace_back("", [this, replace_entry_it](){ EntryBox::get().buttons.emplace_back("", [this, replace_entry_it](){
if(notebook.get_current_page()!=-1) { if(notebook.get_current_page()!=-1) {
notebook.get_current_view()->replace_forward(replace_entry_it->get_text()); notebook.get_current_view()->replace_forward(replace_entry_it->get_text());
} }
}); });
EntryBox::get().buttons.back().set_tooltip_text("Replace current selection\n\nShortcut: press Enter in the replacement field"); EntryBox::get().buttons.back().set_tooltip_text("Replace Next (shortcut: Enter in entry)");
EntryBox::get().buttons.emplace_back("", [this](){ EntryBox::get().buttons.emplace_back("", [this](){
if(notebook.get_current_page()!=-1) if(notebook.get_current_page()!=-1)
notebook.get_current_view()->search_forward(); notebook.get_current_view()->search_forward();
}); });
EntryBox::get().buttons.back().set_tooltip_text("Find next\n\nShortcut: press Enter in the search field"); EntryBox::get().buttons.back().set_tooltip_text("Find Next (shortcut: Enter in entry)");
EntryBox::get().buttons.emplace_back("Replace all", [this, replace_entry_it](){ EntryBox::get().buttons.emplace_back("Replace All", [this, replace_entry_it](){
if(notebook.get_current_page()!=-1) if(notebook.get_current_page()!=-1)
notebook.get_current_view()->replace_all(replace_entry_it->get_text()); notebook.get_current_view()->replace_all(replace_entry_it->get_text());
}); });
EntryBox::get().toggle_buttons.emplace_back("Match case"); EntryBox::get().buttons.back().set_tooltip_text("Replace All");
EntryBox::get().toggle_buttons.emplace_back("Aa");
EntryBox::get().toggle_buttons.back().set_tooltip_text("Match Case");
EntryBox::get().toggle_buttons.back().set_active(case_sensitive_search); EntryBox::get().toggle_buttons.back().set_active(case_sensitive_search);
EntryBox::get().toggle_buttons.back().on_activate=[this, search_entry_it](){ EntryBox::get().toggle_buttons.back().on_activate=[this, search_entry_it](){
case_sensitive_search=!case_sensitive_search; case_sensitive_search=!case_sensitive_search;
if(notebook.get_current_page()!=-1) if(notebook.get_current_page()!=-1)
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);
}; };
EntryBox::get().toggle_buttons.emplace_back("Use regex"); EntryBox::get().toggle_buttons.emplace_back(".*");
EntryBox::get().toggle_buttons.back().set_tooltip_text("Use Regex");
EntryBox::get().toggle_buttons.back().set_active(regex_search); EntryBox::get().toggle_buttons.back().set_active(regex_search);
EntryBox::get().toggle_buttons.back().on_activate=[this, search_entry_it](){ EntryBox::get().toggle_buttons.back().on_activate=[this, search_entry_it](){
regex_search=!regex_search; regex_search=!regex_search;

Loading…
Cancel
Save