Browse Source

project_path cleanup.

merge-requests/365/head
eidheim 10 years ago
parent
commit
82ea15ea9f
  1. 18
      src/directories.cc
  2. 4
      src/directories.h
  3. 1
      src/juci.cc
  4. 28
      src/notebook.cc
  5. 1
      src/notebook.h
  6. 7
      src/source.cc
  7. 6
      src/source.h
  8. 21
      src/window.cc

18
src/directories.cc

@ -41,9 +41,16 @@ Directories::Directories() {
} }
void Directories::open_folder(const boost::filesystem::path& dir_path) { void Directories::open_folder(const boost::filesystem::path& dir_path) {
auto new_path=dir_path;
INFO("Open folder"); INFO("Open folder");
if(new_path=="") {
if(current_path=="")
return;
new_path=current_path;
}
std::vector<Gtk::TreeModel::Path> expanded_paths; std::vector<Gtk::TreeModel::Path> expanded_paths;
if(last_dir_path==dir_path) { if(current_path==new_path) {
tree_view.map_expanded_rows([&expanded_paths](Gtk::TreeView* tree_view, const Gtk::TreeModel::Path& path){ tree_view.map_expanded_rows([&expanded_paths](Gtk::TreeView* tree_view, const Gtk::TreeModel::Path& path){
expanded_paths.emplace_back(path); expanded_paths.emplace_back(path);
}); });
@ -51,18 +58,19 @@ void Directories::open_folder(const boost::filesystem::path& dir_path) {
tree_store->clear(); tree_store->clear();
if(last_dir_path!=dir_path) if(current_path!=new_path)
cmake=std::unique_ptr<CMake>(new CMake(dir_path)); cmake=std::unique_ptr<CMake>(new CMake(new_path));
auto project=cmake->get_functions_parameters("project"); auto project=cmake->get_functions_parameters("project");
if(project.size()>0 && project[0].second.size()>0) if(project.size()>0 && project[0].second.size()>0)
tree_view.get_column(0)->set_title(project[0].second[0]); tree_view.get_column(0)->set_title(project[0].second[0]);
else else
tree_view.get_column(0)->set_title(""); tree_view.get_column(0)->set_title("");
add_paths(dir_path, Gtk::TreeModel::Row(), 0); add_paths(new_path, Gtk::TreeModel::Row(), 0);
for(auto &path: expanded_paths) for(auto &path: expanded_paths)
tree_view.expand_row(path, false); tree_view.expand_row(path, false);
last_dir_path=dir_path;
current_path=new_path;
DEBUG("Folder opened"); DEBUG("Folder opened");
} }

4
src/directories.h

@ -28,11 +28,12 @@ public:
}; };
Directories(); Directories();
void open_folder(const boost::filesystem::path& dir_path); void open_folder(const boost::filesystem::path& dir_path="");
void select_path(const std::string &path); void select_path(const std::string &path);
std::function<void(const std::string &file)> on_row_activated; std::function<void(const std::string &file)> on_row_activated;
std::unique_ptr<CMake> cmake; std::unique_ptr<CMake> cmake;
boost::filesystem::path current_path;
private: private:
void add_paths(const boost::filesystem::path& dir_path, const Gtk::TreeModel::Row &row, unsigned depth); void add_paths(const boost::filesystem::path& dir_path, const Gtk::TreeModel::Row &row, unsigned depth);
@ -40,7 +41,6 @@ private:
Gtk::TreeView tree_view; Gtk::TreeView tree_view;
Glib::RefPtr<Gtk::TreeStore> tree_store; Glib::RefPtr<Gtk::TreeStore> tree_store;
ColumnRecord column_record; ColumnRecord column_record;
boost::filesystem::path last_dir_path;
}; };
#endif // JUCI_DIRECTORIES_H_ #endif // JUCI_DIRECTORIES_H_

1
src/juci.cc

@ -36,7 +36,6 @@ void Juci::on_activate() {
add_window(*window); add_window(*window);
window->show(); window->show();
if(directory!="") { if(directory!="") {
window->notebook.project_path=directory;
window->directories.open_folder(directory); window->directories.open_folder(directory);
} }
for(auto &f: files) for(auto &f: files)

28
src/notebook.cc

@ -54,28 +54,24 @@ void Notebook::open(std::string path) {
auto language=Source::guess_language(path); auto language=Source::guess_language(path);
if(language && (language->get_id()=="chdr" || language->get_id()=="c" || language->get_id()=="cpp" || language->get_id()=="objc")) { if(language && (language->get_id()=="chdr" || language->get_id()=="c" || language->get_id()=="cpp" || language->get_id()=="objc")) {
auto view_project_path=project_path; std::string project_path;
if(directories.cmake && directories.cmake->project_path!="") if(directories.cmake && directories.cmake->project_path!="")
view_project_path=directories.cmake->project_path.string(); project_path=directories.cmake->project_path.string();
if(view_project_path=="") { else {
auto parent_path=boost::filesystem::path(path).parent_path(); auto parent_path=boost::filesystem::path(path).parent_path();
view_project_path=parent_path.string(); project_path=parent_path.string();
CMake cmake(parent_path); CMake cmake(parent_path);
if(cmake.project_path!="") { if(cmake.project_path!="") {
view_project_path=cmake.project_path.string(); project_path=cmake.project_path.string();
Singleton::terminal()->print("Project path for "+path+" set to "+view_project_path+"\n"); Singleton::terminal()->print("Project path for "+path+" set to "+project_path+"\n");
} }
else else
Singleton::terminal()->print("Error: could not find project path for "+path+"\n"); Singleton::terminal()->print("Error: could not find project path for "+path+"\n");
} }
source_views.emplace_back(new Source::ClangView(path, view_project_path)); source_views.emplace_back(new Source::ClangView(path, project_path));
}
else {
auto view_project_path=project_path;
if(view_project_path=="")
view_project_path=boost::filesystem::path(path).parent_path().string();
source_views.emplace_back(new Source::GenericView(path, view_project_path, language));
} }
else
source_views.emplace_back(new Source::GenericView(path, language));
scrolled_windows.emplace_back(new Gtk::ScrolledWindow()); scrolled_windows.emplace_back(new Gtk::ScrolledWindow());
hboxes.emplace_back(new Gtk::HBox()); hboxes.emplace_back(new Gtk::HBox());
@ -125,11 +121,11 @@ bool Notebook::save(int page) {
//If CMakeLists.txt have been modified: //If CMakeLists.txt have been modified:
if(boost::filesystem::path(view->file_path).filename().string()=="CMakeLists.txt") { if(boost::filesystem::path(view->file_path).filename().string()=="CMakeLists.txt") {
if(project_path!="" && directories.cmake && directories.cmake->project_path!="" && CMake::create_compile_commands(directories.cmake->project_path.string())) { if(directories.cmake && directories.cmake->project_path!="" && CMake::create_compile_commands(directories.cmake->project_path.string())) {
directories.open_folder(project_path); directories.open_folder();
for(auto source_view: source_views) { for(auto source_view: source_views) {
if(auto source_clang_view=dynamic_cast<Source::ClangView*>(source_view)) { if(auto source_clang_view=dynamic_cast<Source::ClangView*>(source_view)) {
if(project_path==source_view->project_path) { if(directories.cmake->project_path.string()==source_clang_view->project_path) {
if(source_clang_view->restart_parse()) if(source_clang_view->restart_parse())
Singleton::terminal()->print("Reparsing "+source_clang_view->file_path+"\n"); Singleton::terminal()->print("Reparsing "+source_clang_view->file_path+"\n");
else else

1
src/notebook.h

@ -20,7 +20,6 @@ public:
void open(std::string filename); void open(std::string filename);
bool save(int page); bool save(int page);
bool save_current(); bool save_current();
std::string project_path; //TODO: remove, and also remove Source::View::project_path (project_path only needed in Source::ClangView)
private: private:
bool make_compile_commands(const std::string &path); bool make_compile_commands(const std::string &path);

7
src/source.cc

@ -36,8 +36,7 @@ Glib::RefPtr<Gsv::Language> Source::guess_language(const std::string &file_path)
////////////// //////////////
//// View //// //// View ////
////////////// //////////////
Source::View::View(const std::string& file_path, const std::string& project_path): Source::View::View(const std::string& file_path): file_path(file_path) {
file_path(file_path), project_path(project_path) {
set_smart_home_end(Gsv::SMART_HOME_END_BEFORE); set_smart_home_end(Gsv::SMART_HOME_END_BEFORE);
set_show_line_numbers(Singleton::Config::source()->show_line_numbers); set_show_line_numbers(Singleton::Config::source()->show_line_numbers);
set_highlight_current_line(Singleton::Config::source()->highlight_current_line); set_highlight_current_line(Singleton::Config::source()->highlight_current_line);
@ -248,7 +247,7 @@ bool Source::View::on_key_press_event(GdkEventKey* key) {
///////////////////// /////////////////////
//// GenericView //// //// GenericView ////
///////////////////// /////////////////////
Source::GenericView::GenericView(const std::string& file_path, const std::string& project_path, Glib::RefPtr<Gsv::Language> language) : View(file_path, project_path) { Source::GenericView::GenericView(const std::string& file_path, Glib::RefPtr<Gsv::Language> language) : View(file_path) {
auto style_scheme_manager=Gsv::StyleSchemeManager::get_default(); auto style_scheme_manager=Gsv::StyleSchemeManager::get_default();
//TODO: add?: style_scheme_manager->prepend_search_path("~/.juci/"); //TODO: add?: style_scheme_manager->prepend_search_path("~/.juci/");
auto scheme=style_scheme_manager->get_scheme("classic"); auto scheme=style_scheme_manager->get_scheme("classic");
@ -278,7 +277,7 @@ Source::GenericView::GenericView(const std::string& file_path, const std::string
clang::Index Source::ClangViewParse::clang_index(0, 0); clang::Index Source::ClangViewParse::clang_index(0, 0);
Source::ClangViewParse::ClangViewParse(const std::string& file_path, const std::string& project_path): Source::ClangViewParse::ClangViewParse(const std::string& file_path, const std::string& project_path):
Source::View(file_path, project_path) { Source::View(file_path), project_path(project_path) {
override_font(Pango::FontDescription(Singleton::Config::source()->font)); override_font(Pango::FontDescription(Singleton::Config::source()->font));
override_background_color(Gdk::RGBA(Singleton::Config::source()->background)); override_background_color(Gdk::RGBA(Singleton::Config::source()->background));
override_background_color(Gdk::RGBA(Singleton::Config::source()->background_selected), Gtk::StateFlags::STATE_FLAG_SELECTED); override_background_color(Gdk::RGBA(Singleton::Config::source()->background_selected), Gtk::StateFlags::STATE_FLAG_SELECTED);

6
src/source.h

@ -46,7 +46,7 @@ namespace Source {
class View : public Gsv::View { class View : public Gsv::View {
public: public:
View(const std::string& file_path, const std::string& project_path); View(const std::string& file_path);
~View(); ~View();
void search_highlight(const std::string &text, bool case_sensitive, bool regex); void search_highlight(const std::string &text, bool case_sensitive, bool regex);
@ -58,7 +58,6 @@ namespace Source {
void replace_all(const std::string &replacement); void replace_all(const std::string &replacement);
std::string file_path; std::string file_path;
std::string project_path;
std::function<std::pair<std::string, unsigned>()> get_declaration_location; std::function<std::pair<std::string, unsigned>()> get_declaration_location;
std::function<void()> goto_method; std::function<void()> goto_method;
@ -84,12 +83,13 @@ namespace Source {
class GenericView : public View { class GenericView : public View {
public: public:
GenericView(const std::string& file_path, const std::string& project_path, Glib::RefPtr<Gsv::Language> language); GenericView(const std::string& file_path, Glib::RefPtr<Gsv::Language> language);
}; };
class ClangViewParse : public View { class ClangViewParse : public View {
public: public:
ClangViewParse(const std::string& file_path, const std::string& project_path); ClangViewParse(const std::string& file_path, const std::string& project_path);
std::string project_path;
protected: protected:
void init_parse(); void init_parse();
void start_reparse(); void start_reparse();

21
src/window.cc

@ -294,16 +294,16 @@ void Window::new_file_entry() {
entry_box.entries.emplace_back("untitled", [this](const std::string& content){ entry_box.entries.emplace_back("untitled", [this](const std::string& content){
std::string filename=content; std::string filename=content;
if(filename!="") { if(filename!="") {
if(notebook.project_path!="" && !boost::filesystem::path(filename).is_absolute()) if(directories.current_path!="" && !boost::filesystem::path(filename).is_absolute())
filename=notebook.project_path+"/"+filename; filename=directories.current_path.string()+"/"+filename;
boost::filesystem::path p(filename); boost::filesystem::path p(filename);
if(boost::filesystem::exists(p)) { if(boost::filesystem::exists(p)) {
Singleton::terminal()->print("Error: "+p.string()+" already exists.\n"); Singleton::terminal()->print("Error: "+p.string()+" already exists.\n");
} }
else { else {
if(juci::filesystem::write(p)) { if(juci::filesystem::write(p)) {
if(notebook.project_path!="") if(directories.current_path!="")
directories.open_folder(notebook.project_path); directories.open_folder();
notebook.open(boost::filesystem::canonical(p).string()); notebook.open(boost::filesystem::canonical(p).string());
Singleton::terminal()->print("New file "+p.string()+" created.\n"); Singleton::terminal()->print("New file "+p.string()+" created.\n");
} }
@ -322,8 +322,8 @@ void Window::new_file_entry() {
void Window::open_folder_dialog() { void Window::open_folder_dialog() {
Gtk::FileChooserDialog dialog("Please choose a folder", Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER); Gtk::FileChooserDialog dialog("Please choose a folder", Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
if(notebook.project_path.size()>0) if(directories.current_path!="")
gtk_file_chooser_set_current_folder((GtkFileChooser*)dialog.gobj(), notebook.project_path.c_str()); gtk_file_chooser_set_current_folder((GtkFileChooser*)dialog.gobj(), directories.current_path.string().c_str());
else else
gtk_file_chooser_set_current_folder((GtkFileChooser*)dialog.gobj(), boost::filesystem::current_path().string().c_str()); gtk_file_chooser_set_current_folder((GtkFileChooser*)dialog.gobj(), boost::filesystem::current_path().string().c_str());
dialog.set_transient_for(*this); dialog.set_transient_for(*this);
@ -335,7 +335,6 @@ void Window::open_folder_dialog() {
if(result==Gtk::RESPONSE_OK) { if(result==Gtk::RESPONSE_OK) {
std::string project_path=dialog.get_filename(); std::string project_path=dialog.get_filename();
notebook.project_path=project_path;
directories.open_folder(project_path); directories.open_folder(project_path);
if(notebook.get_current_page()!=-1) if(notebook.get_current_page()!=-1)
directories.select_path(notebook.get_current_view()->file_path); directories.select_path(notebook.get_current_view()->file_path);
@ -344,8 +343,8 @@ void Window::open_folder_dialog() {
void Window::open_file_dialog() { void Window::open_file_dialog() {
Gtk::FileChooserDialog dialog("Please choose a file", Gtk::FILE_CHOOSER_ACTION_OPEN); Gtk::FileChooserDialog dialog("Please choose a file", Gtk::FILE_CHOOSER_ACTION_OPEN);
if(notebook.project_path.size()>0) if(directories.current_path!="")
gtk_file_chooser_set_current_folder((GtkFileChooser*)dialog.gobj(), notebook.project_path.c_str()); gtk_file_chooser_set_current_folder((GtkFileChooser*)dialog.gobj(), directories.current_path.string().c_str());
else else
gtk_file_chooser_set_current_folder((GtkFileChooser*)dialog.gobj(), boost::filesystem::current_path().string().c_str()); gtk_file_chooser_set_current_folder((GtkFileChooser*)dialog.gobj(), boost::filesystem::current_path().string().c_str());
dialog.set_transient_for(*this); dialog.set_transient_for(*this);
@ -399,8 +398,8 @@ void Window::save_file_dialog() {
if(file) { if(file) {
file << notebook.get_current_view()->get_buffer()->get_text(); file << notebook.get_current_view()->get_buffer()->get_text();
file.close(); file.close();
if(notebook.project_path!="") if(directories.current_path!="")
directories.open_folder(notebook.project_path); directories.open_folder();
notebook.open(path); notebook.open(path);
Singleton::terminal()->print("File saved to: " + notebook.get_current_view()->file_path+"\n"); Singleton::terminal()->print("File saved to: " + notebook.get_current_view()->file_path+"\n");
} }

Loading…
Cancel
Save