mirror of https://gitlab.com/cppit/jucipp
16 changed files with 653 additions and 215 deletions
@ -0,0 +1,155 @@
|
||||
#include "directories.h" |
||||
|
||||
Directories::Controller::Controller(Directories::Config& cfg) : |
||||
config_(cfg) { |
||||
m_ScrolledWindow.add(m_TreeView); |
||||
m_ScrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); |
||||
} |
||||
|
||||
bool Directories::Controller:: |
||||
open_folder(const boost::filesystem::path& dir_path) { |
||||
m_refTreeModel = Gtk::TreeStore::create(view()); |
||||
m_TreeView.set_model(m_refTreeModel); |
||||
m_TreeView.remove_all_columns(); |
||||
std::string project_name = get_project_name(dir_path); |
||||
m_TreeView.append_column(project_name, view().m_col_name); |
||||
int row_id = 0; |
||||
Gtk::TreeModel::Row row; |
||||
list_dirs(dir_path, row, row_id); |
||||
m_refTreeModel->set_sort_column(0, Gtk::SortType::SORT_ASCENDING); |
||||
} |
||||
|
||||
bool Directories::Controller::IsIgnored(std::string path) { |
||||
std::transform(path.begin(), path.end(), path.begin(), ::tolower); |
||||
// std::cout << "ignored?: " << path << std::endl;
|
||||
if (config().IsException(path)) { |
||||
return false; |
||||
} |
||||
if (config().IsIgnored(path)) { |
||||
return true; |
||||
} |
||||
return false; |
||||
} |
||||
void Directories::Controller:: |
||||
list_dirs(const boost::filesystem::path& dir_path, |
||||
Gtk::TreeModel::Row &parent, |
||||
unsigned row_id) {
|
||||
boost::filesystem::directory_iterator end_itr; |
||||
unsigned dir_counter = row_id; |
||||
unsigned file_counter = 0; |
||||
Gtk::TreeModel::Row child; |
||||
Gtk::TreeModel::Row row; |
||||
|
||||
// Fill the treeview
|
||||
for ( boost::filesystem::directory_iterator itr( dir_path ); |
||||
itr != end_itr; |
||||
++itr ) { |
||||
if (!IsIgnored(itr->path().filename().string())) { |
||||
if (boost::filesystem::is_directory(itr->status())) { |
||||
if (count(itr->path().string()) > count(dir_path.string())) { // is child
|
||||
child = *(m_refTreeModel->append(parent.children())); |
||||
std::string col_id("a"+itr->path().filename().string()); |
||||
child[view().m_col_id] = col_id; |
||||
child[view().m_col_name] = itr->path().filename().string(); |
||||
child[view().m_col_path] = itr->path().string(); |
||||
list_dirs(itr->path(), child, row_id); |
||||
} else { |
||||
row = *(m_refTreeModel->append()); |
||||
std::string col_id("a"+itr->path().filename().string()); |
||||
row[view().m_col_path] = itr->path().string(); |
||||
row[view().m_col_id] = col_id; |
||||
row[view().m_col_name] = itr->path().filename().string(); |
||||
list_dirs(itr->path(), parent, row_id); |
||||
} |
||||
} else { // is a file
|
||||
child = *(m_refTreeModel->append(parent.children())); |
||||
std::string col_id("b"+itr->path().filename().string()); |
||||
child[view().m_col_id] = col_id; |
||||
child[view().m_col_name] = itr->path().filename().string(); |
||||
child[view().m_col_path] = itr->path().string(); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
int Directories::Controller::count(const std::string path) { |
||||
int count = 0; |
||||
for (int i = 0; i < path.size(); i++) |
||||
if (path[i] == '/') count++; |
||||
return count; |
||||
} |
||||
std::string Directories::Controller:: |
||||
get_project_name(const boost::filesystem::path& dir_path) { |
||||
std::string project_name; |
||||
std::string project_name_var; |
||||
boost::filesystem::directory_iterator end_itr; |
||||
for (boost::filesystem::directory_iterator itr( dir_path ); |
||||
itr != end_itr; |
||||
++itr ) { |
||||
if (itr->path().filename().string() == "CMakeLists.txt") { |
||||
std::ifstream ifs(itr->path().string()); |
||||
std::string line; |
||||
while (std::getline(ifs, line)) { |
||||
if (line.find("project(", 0) != std::string::npos |
||||
|| line.find("project (", 0) != std::string::npos ) { |
||||
size_t variabel_start = line.find("{", 0); |
||||
size_t variabel_end = line.find("}", variabel_start); |
||||
project_name_var = line.substr(variabel_start+1, |
||||
(variabel_end)-variabel_start-1); |
||||
boost::algorithm::trim(project_name_var); |
||||
if (variabel_start == std::string::npos) { // not a variabel
|
||||
variabel_start = line.find("(", 0); |
||||
variabel_end = line.find(")", variabel_start); |
||||
return line.substr(variabel_start+1, |
||||
(variabel_end)-variabel_start-1); |
||||
} |
||||
break; |
||||
} |
||||
} |
||||
std::ifstream ifs2(itr->path().string()); |
||||
while (std::getline(ifs2, line)) { |
||||
if (line.find("set(", 0) != std::string::npos |
||||
|| line.find("set (", 0) != std::string::npos) { |
||||
if( line.find(project_name_var, 0) != std::string::npos) { |
||||
size_t variabel_start = line.find(project_name_var, 0) |
||||
+project_name_var.length(); |
||||
size_t variabel_end = line.find(")", variabel_start); |
||||
project_name = line.substr(variabel_start+1, |
||||
variabel_end-variabel_start-1); |
||||
boost::algorithm::trim(project_name); |
||||
return project_name; |
||||
} |
||||
} |
||||
} |
||||
break; |
||||
} |
||||
} |
||||
return "no project name"; |
||||
} |
||||
|
||||
Directories::Config::Config() { |
||||
} |
||||
Directories::Config::Config(Directories::Config& cfg) : |
||||
ignore_list_(cfg.ignore_list()), exception_list_(cfg.exception_list()) { |
||||
} |
||||
|
||||
void Directories::Config::AddIgnore(std::string filter) { |
||||
ignore_list_.push_back(filter); |
||||
} |
||||
|
||||
void Directories::Config::AddException(std::string filter) { |
||||
exception_list_.push_back(filter); |
||||
} |
||||
|
||||
bool Directories::Config::IsIgnored(std::string str) { |
||||
for ( auto &i : ignore_list() ) |
||||
if (str.find(i, 0) != std::string::npos) |
||||
return true; |
||||
return false; |
||||
} |
||||
|
||||
bool Directories::Config::IsException(std::string str) { |
||||
for ( std::string &i : exception_list() ) |
||||
if (i == str) |
||||
return true; |
||||
return false; |
||||
} |
||||
@ -0,0 +1,75 @@
|
||||
#ifndef JUCI_DIRECTORIES_H_ |
||||
#define JUCI_DIRECTORIES_H_ |
||||
|
||||
#include <gtkmm.h> |
||||
#include <glib.h> |
||||
#include "boost/filesystem.hpp" |
||||
#include "boost/algorithm/string.hpp" |
||||
#include <utility> |
||||
#include <algorithm> |
||||
#include <iostream> |
||||
#include <fstream> |
||||
|
||||
namespace Directories { |
||||
|
||||
class Config { |
||||
public: |
||||
Config(Config &original); |
||||
Config(); |
||||
std::vector<std::string> ignore_list() { return ignore_list_; } |
||||
std::vector<std::string> exception_list() { return exception_list_; } |
||||
void AddIgnore(std::string filter); |
||||
void AddException(std::string filter); |
||||
bool IsException(std::string path); |
||||
bool IsIgnored(std::string path); |
||||
private: |
||||
std::vector<std::string> ignore_list_; |
||||
std::vector<std::string> exception_list_; |
||||
}; |
||||
class View : public Gtk::TreeModel::ColumnRecord { |
||||
public: |
||||
View() { |
||||
add(m_col_id); |
||||
add(m_col_name); |
||||
add(m_col_path); |
||||
} |
||||
Gtk::TreeModelColumn<Glib::ustring> m_col_id; |
||||
Gtk::TreeModelColumn<Glib::ustring> m_col_name; |
||||
Gtk::TreeModelColumn<Glib::ustring> m_col_path; |
||||
}; |
||||
|
||||
class Model { }; |
||||
|
||||
class Controller { |
||||
public: |
||||
Controller(); |
||||
Controller(Directories::Config& cfg); |
||||
View& view() { return view_;} |
||||
Model& model() { return model_;} |
||||
Directories::Config& config() { return config_;} |
||||
Gtk::ScrolledWindow& widget() {return m_ScrolledWindow;} |
||||
bool open_folder(const boost::filesystem::path& dir_path); |
||||
void list_dirs(const boost::filesystem::path& dir_path, |
||||
Gtk::TreeModel::Row &row, unsigned depth); |
||||
std::string get_project_name(const boost::filesystem::path& dir_path); |
||||
int count(const std::string path); |
||||
|
||||
// Child widgets:
|
||||
Gtk::Box m_VBox; |
||||
Gtk::ScrolledWindow m_ScrolledWindow; |
||||
Gtk::TreeView m_TreeView; |
||||
Glib::RefPtr<Gtk::TreeStore> m_refTreeModel; |
||||
bool IsIgnored(std::string path); |
||||
|
||||
private: |
||||
View view_; |
||||
Model model_; |
||||
Directories::Config config_; |
||||
|
||||
protected: |
||||
void on_treeview_row_activated(const Gtk::TreeModel::Path& path, |
||||
Gtk::TreeViewColumn* column); |
||||
}; |
||||
} // namespace Directories
|
||||
|
||||
#endif // JUCI_DIRECTORIES_H_
|
||||
@ -0,0 +1,27 @@
|
||||
|
||||
#ifndef JUCI_NOTEBOOK_H_ |
||||
#define JUCI_NOTEBOOK_H_ |
||||
|
||||
#include <iostream> |
||||
#include "gtkmm.h" |
||||
|
||||
namespace Terminal { |
||||
|
||||
class View { |
||||
public: |
||||
View();
|
||||
//Gtk::HBox view() {return view_;}
|
||||
private: |
||||
Gtk::HBox view_; |
||||
Gtk::TextBuffer buffer_; |
||||
Gtk::TextView textview_; |
||||
}; // class view
|
||||
|
||||
class Controller { |
||||
public: |
||||
|
||||
|
||||
}; // class controller
|
||||
} // namespace Terminal
|
||||
|
||||
#endif // JUCI_NOTEBOOK_H_
|
||||
Loading…
Reference in new issue