Browse Source

Started cleaning up notebook.*. Fixed copy of Notebook::Controller::source_config.

merge-requests/365/head
eidheim 11 years ago
parent
commit
749e28a259
  1. 2
      juci/juci.cc
  2. 5
      juci/juci.h
  3. 50
      juci/notebook.cc
  4. 11
      juci/notebook.h
  5. 5
      juci/selectiondialog.h
  6. 4
      juci/source.h
  7. 2
      juci/terminal.cc
  8. 4
      juci/window.cc

2
juci/juci.cc

@ -37,7 +37,7 @@ void Juci::on_activate() {
if(directory!="") {
//TODO: use the following instead, window->notebook_.open_directory(directory);
window->notebook_.project_path=directory;
window->notebook_.directories().open_folder(directory);
window->notebook_.directories.open_folder(directory);
}
for(auto &f: files)
window->notebook_.OnOpenFile(f);

5
juci/juci.h

@ -1,3 +1,6 @@
#ifndef JUCI_JUCI_H_
#define JUCI_JUCI_H_
#include "window.h"
#include "logging.h"
@ -13,3 +16,5 @@ private:
std::string directory;
std::vector<std::string> files;
};
#endif // JUCI_JUCI_H_

50
juci/notebook.cc

@ -17,12 +17,12 @@ Notebook::Controller::Controller(Gtk::Window* window,
Keybindings::Controller& keybindings,
Source::Config& source_cfg,
Directories::Config& dir_cfg) :
directories_(dir_cfg),
source_config_(source_cfg) {
directories(dir_cfg),
source_config(source_cfg) {
INFO("Create notebook");
window_ = window;
refClipboard_ = Gtk::Clipboard::get();
view().pack1(directories_.widget(), true, true);
view().pack1(directories.widget(), true, true);
CreateKeybindings(keybindings);
INFO("Notebook Controller Success");
} // Constructor
@ -31,7 +31,7 @@ Notebook::Controller::Controller(Gtk::Window* window,
void Notebook::Controller::CreateKeybindings(Keybindings::Controller
&keybindings) {
INFO("Notebook create signal handlers");
directories().m_TreeView.signal_row_activated()
directories.m_TreeView.signal_row_activated()
.connect(sigc::mem_fun(*this,
&Notebook::Controller::OnDirectoryNavigation));
@ -191,7 +191,7 @@ Gtk::Box& Notebook::Controller::entry_view() {
void Notebook::Controller::OnOpenFile(std::string path) {
INFO("Notebook open file");
INFO("Notebook create page");
text_vec_.emplace_back(new Source::Controller(source_config(), path, project_path));
text_vec_.emplace_back(new Source::Controller(source_config, path, project_path));
scrolledtext_vec_.push_back(new Gtk::ScrolledWindow());
editor_vec_.push_back(new Gtk::HBox());
scrolledtext_vec_.back()->add(*text_vec_.back()->view);
@ -204,7 +204,18 @@ void Notebook::Controller::OnOpenFile(std::string path) {
Notebook().show_all_children();
Notebook().set_current_page(Pages()-1);
Notebook().set_focus_child(*text_vec_.back()->view);
set_source_handlers(*text_vec_.back());
//Add star on tab label when the page is not saved:
text_vec_.back()->buffer()->signal_changed().connect([this]() {
if(text_vec_.at(CurrentPage())->is_saved) {
std::string path=text_vec_.at(CurrentPage())->view->file_path;
size_t pos = path.find_last_of("/\\");
std::string filename=path;
if(pos!=std::string::npos)
filename=path.substr(pos+1);
Notebook().set_tab_label_text(*(Notebook().get_nth_page(CurrentPage())), filename+"*");
}
text_vec_.at(CurrentPage())->is_saved=false;
});
}
void Notebook::Controller::OnCloseCurrentPage() {
@ -310,18 +321,18 @@ void Notebook::Controller
::OnDirectoryNavigation(const Gtk::TreeModel::Path& path,
Gtk::TreeViewColumn* column) {
INFO("Notebook directory navigation");
Gtk::TreeModel::iterator iter = directories().m_refTreeModel->get_iter(path);
Gtk::TreeModel::iterator iter = directories.m_refTreeModel->get_iter(path);
if (iter) {
Gtk::TreeModel::Row row = *iter;
std::string upath = Glib::ustring(row[directories().view().m_col_path]);
std::string upath = Glib::ustring(row[directories.view().m_col_path]);
boost::filesystem::path fs_path(upath);
if (boost::filesystem::is_directory(fs_path)) {
directories().m_TreeView.row_expanded(path) ?
directories().m_TreeView.collapse_row(path) :
directories().m_TreeView.expand_row(path, false);
directories.m_TreeView.row_expanded(path) ?
directories.m_TreeView.collapse_row(path) :
directories.m_TreeView.expand_row(path, false);
} else {
std::stringstream sstm;
sstm << row[directories().view().m_col_path];
sstm << row[directories.view().m_col_path];
std::string file = sstm.str();
OnOpenFile(file);
}
@ -357,21 +368,6 @@ void Notebook::Controller::BufferChangeHandler(Glib::RefPtr<Gtk::TextBuffer>
});
}
void Notebook::Controller::set_source_handlers(Source::Controller& controller) {
//Add star on tab label when the page is not saved:
controller.buffer()->signal_changed().connect([this]() {
if(text_vec_.at(CurrentPage())->is_saved) {
std::string path=text_vec_.at(CurrentPage())->view->file_path;
size_t pos = path.find_last_of("/\\");
std::string filename=path;
if(pos!=std::string::npos)
filename=path.substr(pos+1);
Notebook().set_tab_label_text(*(Notebook().get_nth_page(CurrentPage())), filename+"*");
}
text_vec_.at(CurrentPage())->is_saved=false;
});
}
std::string Notebook::Controller::CurrentPagePath(){
return text_vec_.at(CurrentPage())->view->file_path;
}

11
juci/notebook.h

@ -61,25 +61,20 @@ namespace Notebook {
void OnOpenFile(std::string filename);
bool ScrollEventCallback(GdkEventScroll* scroll_event);
int Pages();
Directories::Controller& directories() { return directories_; }
Gtk::Paned& view();
void Search(bool forward);
Source::Config& source_config() { return source_config_; }
std::string OnSaveFileAs();
bool LegalExtension(std::string extension);
std::string project_path;
protected:
void set_source_handlers(Source::Controller& controller);
Directories::Controller directories;
private:
void CreateKeybindings(Keybindings::Controller& keybindings);
void AskToSaveDialog();
Glib::RefPtr<Gtk::Builder> m_refBuilder;
Glib::RefPtr<Gio::SimpleActionGroup> refActionGroup;
Source::Config source_config_;
Directories::Controller directories_;
Source::Config& source_config;
View view_;
Model model_;
bool is_new_file_;
bool is_new_file_; //TODO: Remove this
Entry::Controller entry_;
std::vector<std::unique_ptr<Source::Controller> > text_vec_;

5
juci/selectiondialog.h

@ -1,3 +1,6 @@
#ifndef JUCI_SELECTIONDIALOG_H_
#define JUCI_SELECTIONDIALOG_H_
#include "gtkmm.h"
#include "logging.h"
#include "source.h"
@ -17,3 +20,5 @@ private:
Gtk::ScrolledWindow scrolled_window;
Gtk::ListViewText list_view_text;
};
#endif // JUCI_SELECTIONDIALOG_H_

4
juci/source.h

@ -11,10 +11,6 @@
#include <atomic>
#include "gtksourceviewmm.h"
namespace Notebook {
class Controller;
}
namespace Source {
class Config {
public:

2
juci/terminal.cc

@ -87,11 +87,9 @@ void Terminal::Controller::ExecuteCommand(std::string command, std::string mode)
FILE* p = NULL;
std::cout << command << std::endl;
p = popen(command.c_str(), mode.c_str());
std::cout << "KJØRTE FINT!" << std::endl;
if (p == NULL) {
PrintMessage("juCi++ ERROR: Failed to run command" + command + "\n");
}else {
std::cout << "SKRIVER UT KOMMANDO RESULAT" << std::endl;
char buffer[1028];
while (fgets(buffer, 1028, p) != NULL) {
PrintMessage(buffer);

4
juci/window.cc

@ -73,7 +73,7 @@ Window::Window() :
terminal_.SetFolderCommand(path);
}
terminal_.Compile();
std::string executable = notebook_.directories().
std::string executable = notebook_.directories.
GetCmakeVarValue(path,"add_executable");
terminal_.Run(executable);
running.unlock();
@ -140,7 +140,7 @@ void Window::OnFileOpenFolder() {
{
std::string project_path=dialog.get_filename();
notebook_.project_path=project_path;
notebook_.directories().open_folder(project_path);
notebook_.directories.open_folder(project_path);
break;
}
case(Gtk::RESPONSE_CANCEL):

Loading…
Cancel
Save