Browse Source

directories.h and .cc code cleanup

merge-requests/365/head
tedjk 11 years ago
parent
commit
be3cdb1dc1
  1. 48
      juci/directories.cc
  2. 25
      juci/directories.h
  3. 5
      juci/notebook.cc

48
juci/directories.cc

@ -1,12 +1,12 @@
#include "directories.h" #include "directories.h"
Directories::Controller::Controller() { Directories::Controller::Controller() {
m_ScrolledWindow.add(m_TreeView); m_ScrolledWindow.add(m_TreeView);
m_ScrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); m_ScrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
} }
bool Directories::Controller::open_folder(const boost::filesystem::path& dir_path) { bool Directories::Controller::
open_folder(const boost::filesystem::path& dir_path) {
m_refTreeModel = Gtk::TreeStore::create(view()); m_refTreeModel = Gtk::TreeStore::create(view());
m_TreeView.set_model(m_refTreeModel); m_TreeView.set_model(m_refTreeModel);
m_TreeView.remove_all_columns(); m_TreeView.remove_all_columns();
@ -14,12 +14,12 @@ bool Directories::Controller::open_folder(const boost::filesystem::path& dir_pat
m_TreeView.append_column(project_name, view().m_col_name); m_TreeView.append_column(project_name, view().m_col_name);
int row_id = 0; int row_id = 0;
Gtk::TreeModel::Row row; Gtk::TreeModel::Row row;
std::string col_id("a"+dir_path.filename().string());
list_dirs(dir_path, row, row_id); list_dirs(dir_path, row, row_id);
m_refTreeModel->set_sort_column(0, Gtk::SortType::SORT_ASCENDING); m_refTreeModel->set_sort_column(0, Gtk::SortType::SORT_ASCENDING);
} }
bool Directories::Controller::list_dirs( const boost::filesystem::path& dir_path, void Directories::Controller::
list_dirs(const boost::filesystem::path& dir_path,
Gtk::TreeModel::Row &parent, Gtk::TreeModel::Row &parent,
unsigned row_id) { unsigned row_id) {
boost::filesystem::directory_iterator end_itr; boost::filesystem::directory_iterator end_itr;
@ -28,11 +28,11 @@ bool Directories::Controller::list_dirs( const boost::filesystem::path& dir_path
Gtk::TreeModel::Row child; Gtk::TreeModel::Row child;
Gtk::TreeModel::Row row; Gtk::TreeModel::Row row;
//Fill the TreeView's model // Fill the treeview
for ( boost::filesystem::directory_iterator itr( dir_path ); for ( boost::filesystem::directory_iterator itr( dir_path );
itr != end_itr; itr != end_itr;
++itr ) { ++itr ) {
if (boost::filesystem::is_directory(itr->status()) ) { if (boost::filesystem::is_directory(itr->status())) {
if (count(itr->path().string()) > count(dir_path.string())) { if (count(itr->path().string()) > count(dir_path.string())) {
child = *(m_refTreeModel->append(parent.children())); child = *(m_refTreeModel->append(parent.children()));
std::string col_id("a"+itr->path().filename().string()); std::string col_id("a"+itr->path().filename().string());
@ -59,43 +59,39 @@ bool Directories::Controller::list_dirs( const boost::filesystem::path& dir_path
} }
int Directories::Controller::count(const std::string path) { int Directories::Controller::count(const std::string path) {
int count = 0; int count = 0;
for (int i = 0; i < path.size(); i++) for (int i = 0; i < path.size(); i++)
if (path[i] == '/') count++; if (path[i] == '/') count++;
return count; return count;
} }
std::string Directories::Controller::get_project_name(const boost::filesystem::path& dir_path) { std::string Directories::Controller::
get_project_name(const boost::filesystem::path& dir_path) {
std::string project_name; std::string project_name;
std::string project_name_var; std::string project_name_var;
boost::filesystem::directory_iterator end_itr; boost::filesystem::directory_iterator end_itr;
for (boost::filesystem::directory_iterator itr( dir_path ); for (boost::filesystem::directory_iterator itr( dir_path );
itr != end_itr; itr != end_itr;
++itr ) { ++itr ) {
std::cout << "not cmakelists.txt" << itr->path().string() << std::endl; if (itr->path().filename().string() == "CMakeLists.txt") {
if(itr->path().filename().string() == "CMakeLists.txt"){
std::cout << "found cmakeliksts.txt" << std::endl;
std::ifstream ifs(itr->path().string()); std::ifstream ifs(itr->path().string());
std::string line; std::string line;
while(std::getline(ifs, line)) { while (std::getline(ifs, line)) {
if(line.find("project(", 0) != std::string::npos if (line.find("project(", 0) != std::string::npos
|| line.find("project (", 0) != std::string::npos ) { || line.find("project (", 0) != std::string::npos ) {
std::cout << "found the variabel for project name: "<< line << std::endl; size_t variabel_start = line.find("{", 0);
size_t variabel_start = line.find("{",0 ); size_t variabel_end = line.find("}", variabel_start);
size_t variabel_end = line.find("}",variabel_start); project_name_var = line.substr(variabel_start+1,
project_name_var = line.substr(variabel_start+1, (variabel_end)-variabel_start-1); (variabel_end)-variabel_start-1);
std::cout << "it is: "<< project_name_var << std::endl;
break; break;
} }
} }
std::ifstream ifs2(itr->path().string()); std::ifstream ifs2(itr->path().string());
while(std::getline(ifs2, line)) { while (std::getline(ifs2, line)) {
if(line.find("set("+project_name_var, 0) != std::string::npos) { if (line.find("set("+project_name_var, 0) != std::string::npos) {
std::cout << "the variabel value for project name: " << line << std::endl; size_t variabel_start = line.find(project_name_var, 0)
size_t variabel_start = line.find(project_name_var,0) +project_name_var.length(); +project_name_var.length();
size_t variabel_end = line.find(")",variabel_start); size_t variabel_end = line.find(")", variabel_start);
project_name = line.substr(variabel_start, variabel_end-variabel_start); project_name = line.substr(variabel_start,
variabel_end-variabel_start);
return project_name; return project_name;
} }
} }

25
juci/directories.h

@ -1,5 +1,5 @@
#ifndef JUCI_DIRECTIRIES_H_ #ifndef JUCI_DIRECTORIES_H_
#define JUCI_DIRECTIRIES_H_ #define JUCI_DIRECTORIES_H_
#include <gtkmm.h> #include <gtkmm.h>
#include <glib.h> #include <glib.h>
@ -23,35 +23,30 @@ namespace Directories {
class Model { class Model {
}; };
class Controller { class Controller {
public: public:
Controller(); Controller();
View& view() { return view_;}; View& view() { return view_;}
Model& model() { return model_;}; Model& model() { return model_;}
Gtk::ScrolledWindow& widget() {return m_ScrolledWindow;}; Gtk::ScrolledWindow& widget() {return m_ScrolledWindow;}
bool open_folder( const boost::filesystem::path& dir_path); bool open_folder (const boost::filesystem::path& dir_path);
bool list_dirs( const boost::filesystem::path& dir_path, void list_dirs (const boost::filesystem::path& dir_path,
Gtk::TreeModel::Row &row, unsigned depth); Gtk::TreeModel::Row &row, unsigned depth);
std::string get_project_name(const boost::filesystem::path& dir_path); std::string get_project_name(const boost::filesystem::path& dir_path);
int count( const std::string path); int count (const std::string path);
//Child widgets: //Child widgets:
Gtk::Box m_VBox; Gtk::Box m_VBox;
Gtk::ScrolledWindow m_ScrolledWindow; Gtk::ScrolledWindow m_ScrolledWindow;
Gtk::TreeView m_TreeView; Gtk::TreeView m_TreeView;
Glib::RefPtr<Gtk::TreeStore> m_refTreeModel; Glib::RefPtr<Gtk::TreeStore> m_refTreeModel;
private: private:
View view_; View view_;
Model model_; Model model_;
protected: protected:
void on_treeview_row_activated(const Gtk::TreeModel::Path& path, void on_treeview_row_activated(const Gtk::TreeModel::Path& path,
Gtk::TreeViewColumn* column); Gtk::TreeViewColumn* column);
}; };
} } // namespace Directories
#endif // JUCI_DIRECTIRIES_H_ #endif // JUCI_DIRECTORIES_H_

5
juci/notebook.cc

@ -318,7 +318,8 @@ void Notebook::Controller::OnBufferChange() {
delete scroll; delete scroll;
} }
} }
void Notebook::Controller::OnDirectoryNavigation(const Gtk::TreeModel::Path& path, void Notebook::Controller
::OnDirectoryNavigation(const Gtk::TreeModel::Path& path,
Gtk::TreeViewColumn* column) { Gtk::TreeViewColumn* column) {
Gtk::TreeModel::iterator iter = directories().m_refTreeModel->get_iter(path); Gtk::TreeModel::iterator iter = directories().m_refTreeModel->get_iter(path);
if(iter) { if(iter) {
@ -326,7 +327,6 @@ void Notebook::Controller::OnDirectoryNavigation(const Gtk::TreeModel::Path& pat
boost::filesystem::path fs_path(Glib::ustring(row[directories() boost::filesystem::path fs_path(Glib::ustring(row[directories()
.view().m_col_path])); .view().m_col_path]));
if (boost::filesystem::is_directory(fs_path)) { if (boost::filesystem::is_directory(fs_path)) {
std::cout << "Expand folder: " << row[directories().view().m_col_path] << std::endl;
directories().m_TreeView.row_expanded(path) ? directories().m_TreeView.row_expanded(path) ?
directories().m_TreeView.collapse_row(path) : directories().m_TreeView.collapse_row(path) :
directories().m_TreeView.expand_row(path, false); directories().m_TreeView.expand_row(path, false);
@ -334,7 +334,6 @@ void Notebook::Controller::OnDirectoryNavigation(const Gtk::TreeModel::Path& pat
std::stringstream sstm; std::stringstream sstm;
sstm << row[directories().view().m_col_path]; sstm << row[directories().view().m_col_path];
std::string file = sstm.str(); std::string file = sstm.str();
std::cout << "open file: "<< row[directories().view().m_col_path] << std::endl;
OnOpenFile(file); OnOpenFile(file);
} }
} }

Loading…
Cancel
Save