22 changed files with 1087 additions and 419 deletions
@ -0,0 +1,47 @@
|
||||
#include "api.h" |
||||
namespace juci_api{ |
||||
|
||||
void cpp::ReplaceWord(const std::string word) { |
||||
//TODO implement api::ReplaceWord / change string to iter?
|
||||
//some_namespace::controller::replaceWord(word_*);
|
||||
std::cout << "unimplemented function: 'api::ReplaceWord()' called" |
||||
<< std::endl; |
||||
|
||||
std::cout << "The string: " << g_test_string << std::endl; |
||||
} |
||||
|
||||
void cpp::ReplaceLine(const std::string line) { |
||||
//TODO implement api::ReplaceLine / change string to iter?
|
||||
//some_namespace::controller::replaceLine(line_);
|
||||
std::cout << "unimplemented function: 'api::ReplaceLine()' called" |
||||
<< std::endl; |
||||
}
|
||||
|
||||
//helpers
|
||||
boost::python::api::object py::openPythonScript(const std::string path, |
||||
boost::python::api::object python_name_space) { |
||||
std::string temp = g_project_root + path + ".py"; |
||||
boost::python::str the_path(temp); |
||||
return boost::python::exec_file(the_path, python_name_space);//, python_name_space);
|
||||
} |
||||
|
||||
void py::LoadPlugin(const std::string& plugin_name) { |
||||
try{ |
||||
/* initialize python interpreter */ |
||||
Py_Initialize(); |
||||
boost::python::api::object main_module = boost::python::import("__main__"); |
||||
boost::python::api::object main_namespace = main_module.attr("__dict__"); |
||||
|
||||
/* runs script from python */ |
||||
//boost::python::object ignored1 = setPythonVar("word", word, main_namespace);
|
||||
boost::python::api::object ignored2 = openPythonScript(plugin_name, main_namespace);
|
||||
/* extracts desired values */
|
||||
//boost::python::object pySnippet = boost::python::eval("getSnippet()", main_namespace);
|
||||
//word = boost::python::extract<std::string>(pySnippet);
|
||||
/* add snippet to textView */ |
||||
//TODO add snippet
|
||||
}catch(boost::python::error_already_set const&) { |
||||
PyErr_Print(); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,193 @@
|
||||
{ |
||||
"colors": { |
||||
"text_color": "black", |
||||
"string" : "green" |
||||
}, |
||||
"syntax": { |
||||
"1": "text_color", |
||||
"2": "text_color", |
||||
"2": "text_color", |
||||
"3": "text_color", |
||||
"4": "text_color", |
||||
"5": "text_color", |
||||
"6": "text_color", |
||||
"7": "text_color", |
||||
"8": "text_color", |
||||
"9": "text_color", |
||||
"10": "text_color", |
||||
"11": "text_color", |
||||
"12": "text_color", |
||||
"13": "text_color", |
||||
"14": "text_color", |
||||
"15": "text_color", |
||||
"16": "text_color", |
||||
"17": "text_color", |
||||
"18": "text_color", |
||||
"19": "text_color", |
||||
"20": "text_color", |
||||
"21": "text_color", |
||||
"22": "text_color", |
||||
"23": "text_color", |
||||
"24": "text_color", |
||||
"25": "text_color", |
||||
"26": "text_color", |
||||
"27": "text_color", |
||||
"28": "text_color", |
||||
"29": "text_color", |
||||
"30": "text_color", |
||||
"31": "text_color", |
||||
"32": "text_color", |
||||
"33": "text_color", |
||||
"34": "text_color", |
||||
"35": "text_color", |
||||
"36": "text_color", |
||||
"37": "text_color", |
||||
"38": "text_color", |
||||
"39": "text_color", |
||||
"40": "text_color", |
||||
"41": "text_color", |
||||
"42": "text_color", |
||||
"43": "text_color", |
||||
"44": "text_color", |
||||
"45": "text_color", |
||||
"46": "text_color", |
||||
"47": "text_color", |
||||
"48": "text_color", |
||||
"49": "text_color", |
||||
"50": "text_color", |
||||
"51": "text_color", |
||||
"70": "text_color", |
||||
"70": "text_color", |
||||
"71": "text_color", |
||||
"72": "text_color", |
||||
"73": "text_color", |
||||
"100": "text_color", |
||||
"100": "text_color", |
||||
"101": "text_color", |
||||
"102": "text_color", |
||||
"103": "text_color", |
||||
"104": "text_color", |
||||
"105": "text_color", |
||||
"106": "text_color", |
||||
"107": "text_color", |
||||
"108": "text_color", |
||||
"109": "string", |
||||
"110": "text_color", |
||||
"111": "text_color", |
||||
"112": "text_color", |
||||
"113": "text_color", |
||||
"114": "text_color", |
||||
"115": "text_color", |
||||
"116": "text_color", |
||||
"117": "text_color", |
||||
"118": "text_color", |
||||
"119": "text_color", |
||||
"120": "text_color", |
||||
"121": "text_color", |
||||
"122": "text_color", |
||||
"123": "text_color", |
||||
"124": "text_color", |
||||
"125": "text_color", |
||||
"126": "text_color", |
||||
"127": "text_color", |
||||
"128": "text_color", |
||||
"129": "text_color", |
||||
"130": "text_color", |
||||
"131": "text_color", |
||||
"132": "text_color", |
||||
"133": "text_color", |
||||
"134": "text_color", |
||||
"135": "text_color", |
||||
"136": "text_color", |
||||
"137": "text_color", |
||||
"138": "text_color", |
||||
"139": "text_color", |
||||
"140": "text_color", |
||||
"141": "text_color", |
||||
"142": "text_color", |
||||
"143": "text_color", |
||||
"144": "text_color", |
||||
"145": "text_color", |
||||
"146": "text_color", |
||||
"200": "text_color", |
||||
"200": "text_color", |
||||
"201": "text_color", |
||||
"202": "text_color", |
||||
"203": "text_color", |
||||
"204": "text_color", |
||||
"205": "text_color", |
||||
"206": "text_color", |
||||
"207": "text_color", |
||||
"208": "text_color", |
||||
"209": "text_color", |
||||
"210": "text_color", |
||||
"211": "text_color", |
||||
"212": "text_color", |
||||
"213": "text_color", |
||||
"214": "text_color", |
||||
"215": "text_color", |
||||
"216": "text_color", |
||||
"217": "text_color", |
||||
"218": "text_color", |
||||
"219": "text_color", |
||||
"220": "text_color", |
||||
"221": "text_color", |
||||
"222": "text_color", |
||||
"223": "text_color", |
||||
"224": "text_color", |
||||
"225": "text_color", |
||||
"226": "text_color", |
||||
"227": "text_color", |
||||
"228": "text_color", |
||||
"229": "text_color", |
||||
"230": "text_color", |
||||
"231": "text_color", |
||||
"232": "text_color", |
||||
"233": "text_color", |
||||
"234": "text_color", |
||||
"235": "text_color", |
||||
"236": "text_color", |
||||
"237": "text_color", |
||||
"238": "text_color", |
||||
"239": "text_color", |
||||
"240": "text_color", |
||||
"241": "text_color", |
||||
"242": "text_color", |
||||
"243": "text_color", |
||||
"244": "text_color", |
||||
"245": "text_color", |
||||
"246": "text_color", |
||||
"247": "text_color", |
||||
"248": "text_color", |
||||
"249": "text_color", |
||||
"250": "text_color", |
||||
"251": "text_color", |
||||
"252": "text_color", |
||||
"253": "text_color", |
||||
"300": "text_color", |
||||
"400": "text_color", |
||||
"400": "text_color", |
||||
"401": "text_color", |
||||
"402": "text_color", |
||||
"403": "text_color", |
||||
"404": "text_color", |
||||
"405": "text_color", |
||||
"406": "text_color", |
||||
"407": "text_color", |
||||
"408": "text_color", |
||||
"409": "text_color", |
||||
"410": "text_color", |
||||
"411": "text_color", |
||||
"412": "text_color", |
||||
"413": "text_color", |
||||
"414": "text_color", |
||||
"415": "text_color", |
||||
"416": "text_color", |
||||
"500": "text_color", |
||||
"501": "text_color", |
||||
"502": "text_color", |
||||
"503": "text_color", |
||||
"600": "text_color", |
||||
"700": "text_color" |
||||
} |
||||
} |
||||
@ -0,0 +1,45 @@
|
||||
#include "entry.h" |
||||
|
||||
Entry::Model::Model() : |
||||
next_("Next"), |
||||
prev_("Prev"){ |
||||
std::cout<<"Model Entry"<<std::endl; |
||||
} |
||||
Entry::View::View() : |
||||
view_(Gtk::ORIENTATION_HORIZONTAL), |
||||
button_apply_(Gtk::Stock::APPLY), |
||||
button_cancel_(Gtk::Stock::CANCEL){ |
||||
} |
||||
Gtk::Box& Entry::View::view() { |
||||
return view_; |
||||
} |
||||
void Entry::View::OnShowSetFilenName(std::string exstension) { |
||||
entry_.set_max_length(50); |
||||
entry_.set_text(exstension); |
||||
view_.pack_start(entry_); |
||||
view_.pack_end(button_cancel_, Gtk::PACK_SHRINK); |
||||
view_.pack_end(button_apply_, Gtk::PACK_SHRINK);
|
||||
} |
||||
void Entry::View::OnHideEntry() |
||||
{ |
||||
view_.remove(entry_); |
||||
view_.remove(button_cancel_); |
||||
view_.remove(button_apply_); |
||||
} |
||||
Entry::Controller::Controller() {
|
||||
} |
||||
Gtk::Box& Entry::Controller::view() { |
||||
return view_.view(); |
||||
} |
||||
Gtk::Button& Entry::Controller::button_apply(){ |
||||
return view_.button_apply(); |
||||
} |
||||
void Entry::Controller::OnShowSetFilenName(std::string exstension) { |
||||
view_.OnShowSetFilenName(exstension); |
||||
view_.view().show_all(); |
||||
view_.entry().grab_focus(); |
||||
view_.entry().set_position(0); |
||||
} |
||||
void Entry::Controller::OnHideEntries(){ |
||||
view_.OnHideEntry(); |
||||
} |
||||
@ -0,0 +1,43 @@
|
||||
#ifndef JUCI_ENTRY_H_ |
||||
#define JUCI_ENTRY_H_ |
||||
|
||||
#include <iostream> |
||||
#include "gtkmm.h" |
||||
#include "keybindings.h" |
||||
|
||||
namespace Entry { |
||||
class View { |
||||
public: |
||||
View(); |
||||
Gtk::Box& view(); |
||||
Gtk::Entry& entry(){return entry_;} |
||||
Gtk::Button& button_apply(){return button_apply_;}; |
||||
Gtk::Button& button_cancel(){return button_cancel_;}; |
||||
void OnShowSetFilenName(std::string exstension); |
||||
void OnHideEntry(); |
||||
protected: |
||||
Gtk::Box view_; |
||||
Gtk::Entry entry_; |
||||
Gtk::Button button_apply_, button_cancel_; |
||||
}; |
||||
class Model { |
||||
public: |
||||
Model(); |
||||
std::string next(){return next_;}; |
||||
std::string prev(){return prev_;}; |
||||
private: |
||||
std::string next_, prev_;
|
||||
}; |
||||
class Controller { |
||||
public: |
||||
Controller(); |
||||
Gtk::Box& view(); |
||||
Gtk::Button& button_apply(); |
||||
void OnShowSetFilenName(std::string exstension); |
||||
void OnHideEntries(); |
||||
View view_; |
||||
};// class controller
|
||||
} // namespace notebook
|
||||
|
||||
|
||||
#endif // JUCI_ENTRY_H_
|
||||
@ -1,26 +0,0 @@
|
||||
//juCi++ main header file
|
||||
#ifndef JUCI_JUCI_H_ |
||||
#define JUCI_JUCI_H_ |
||||
|
||||
#include <iostream> |
||||
#include "gtkmm.h" |
||||
#include "menu.h" |
||||
#include "source.h" |
||||
|
||||
class Window : public Gtk::Window { |
||||
public: |
||||
Window(); |
||||
virtual ~Window() {} |
||||
|
||||
private: |
||||
Keybindings::Controller keybindings_; |
||||
Menu::Controller menu_; |
||||
Source::Controller& source(); |
||||
Source::Controller source_; |
||||
Gtk::Box window_box_; |
||||
|
||||
/*signal handler*/ |
||||
void OnSystemQuit(); |
||||
}; |
||||
|
||||
#endif // JUCI_JUCI_H_
|
||||
@ -1,21 +1,77 @@
|
||||
#include "keybindings.h" |
||||
|
||||
Keybindings::Model::Model() { |
||||
menu_ui_string_ = |
||||
"<ui> " |
||||
" <menubar name='MenuBar'> " |
||||
" <menu action='FileMenu'> " |
||||
" <menu action='FileNew'> " |
||||
" <menuitem action='FileNewStandard'/> " |
||||
" <menuitem action='FileNewCC'/> " |
||||
" <menuitem action='FileNewH'/> " |
||||
" </menu> " |
||||
" <menuitem action='FileOpenFile'/> " |
||||
" <menuitem action='FileOpenFolder'/> " |
||||
" <separator/> " |
||||
" <menuitem action='FileQuit'/> " |
||||
" </menu> " |
||||
" <menu action='EditMenu'> " |
||||
" <menuitem action='EditCopy'/> " |
||||
" <menuitem action='EditCut'/> " |
||||
" <menuitem action='EditPaste'/> " |
||||
" <separator/> " |
||||
" <menuitem action='EditFind'/> " |
||||
" </menu> " |
||||
" <menu action='WindowMenu'> " |
||||
" <menuitem action='WindowCloseTab'/> " |
||||
" <menuitem action='WindowSplitWindow'/> " |
||||
" </menu> " |
||||
" <menu action='PluginMenu'> " |
||||
" <menu action='PluginSnippet'> " |
||||
" <menuitem action='PluginAddSnippet'/> " |
||||
" </menu> " |
||||
" </menu> " |
||||
" <menu action='HelpMenu'> " |
||||
" <menuitem action='HelpAbout'/> " |
||||
" </menu> " |
||||
" </menubar> " |
||||
"</ui> "; |
||||
|
||||
hidden_ui_string_ = |
||||
"<ui> " |
||||
" <menubar name='MenuBar'> " |
||||
" <menuitem action='Test'/> " |
||||
" </menubar> " |
||||
"</ui> "; |
||||
}; |
||||
|
||||
Keybindings::Model::~Model() { |
||||
} |
||||
|
||||
Keybindings::Controller::Controller() { |
||||
action_group_ = Gtk::ActionGroup::create(); |
||||
ui_manager_ = Gtk::UIManager::create(); |
||||
action_group_menu_ = Gtk::ActionGroup::create(); |
||||
ui_manager_menu_ = Gtk::UIManager::create(); |
||||
action_group_hidden_ = Gtk::ActionGroup::create(); |
||||
ui_manager_hidden_ = Gtk::UIManager::create(); |
||||
} |
||||
Keybindings::Controller::~Controller() { |
||||
|
||||
} |
||||
void Keybindings::Controller::set_ui_manager_action_group(Glib::RefPtr<Gtk::ActionGroup> action_group) { |
||||
ui_manager_->insert_action_group(action_group); |
||||
void Keybindings::Controller::BuildMenu() { |
||||
try { |
||||
ui_manager_menu_->add_ui_from_string(model_.menu_ui_string()); |
||||
} |
||||
void Keybindings::Controller::set_ui_manger_string(std::string ui_string) { |
||||
catch (const Glib::Error &ex) { |
||||
std::cerr << "building menu failed" << ex.what(); |
||||
} |
||||
ui_manager_menu_->insert_action_group(action_group_menu_); |
||||
} |
||||
void Keybindings::Controller::BuildHiddenMenu() { |
||||
try { |
||||
ui_manager_->add_ui_from_string(ui_string); |
||||
ui_manager_hidden_->add_ui_from_string(model_.hidden_ui_string()); |
||||
} |
||||
catch (const Glib::Error &ex) { |
||||
std::cerr << "building menus failed: " << ex.what(); |
||||
std::cerr << "building hidden menu failed" << ex.what(); |
||||
} |
||||
ui_manager_hidden_->insert_action_group(action_group_hidden_); |
||||
} |
||||
|
||||
|
||||
@ -1,28 +1,47 @@
|
||||
//juCi++ class that holds every keybinding.
|
||||
#ifndef JUCI_KEYBINDINGS_H_ |
||||
#define JUCI_KEYBINDINGS_H_ |
||||
|
||||
#include "iostream" |
||||
#include "gtkmm.h" |
||||
|
||||
namespace Keybindings { |
||||
class Model { |
||||
public: |
||||
Model(); |
||||
virtual ~Model(); |
||||
std::string menu_ui_string(){return menu_ui_string_;} |
||||
std::string hidden_ui_string(){return hidden_ui_string_;} |
||||
private: |
||||
std::string menu_ui_string_; |
||||
std::string hidden_ui_string_; |
||||
}; // Model
|
||||
class Controller { |
||||
public: |
||||
Controller(); |
||||
|
||||
virtual ~Controller(); |
||||
|
||||
Glib::RefPtr<Gtk::ActionGroup> action_group() { |
||||
return action_group_; |
||||
Glib::RefPtr<Gtk::ActionGroup> action_group_menu() { |
||||
return action_group_menu_; |
||||
}; |
||||
|
||||
Glib::RefPtr<Gtk::UIManager> ui_manager() { |
||||
return ui_manager_; |
||||
Glib::RefPtr<Gtk::UIManager> ui_manager_menu() { |
||||
return ui_manager_menu_; |
||||
}; |
||||
|
||||
void set_ui_manger_string(std::string ui_string); |
||||
|
||||
void set_ui_manager_action_group(Glib::RefPtr<Gtk::ActionGroup> action_group); |
||||
|
||||
protected: |
||||
Glib::RefPtr<Gtk::UIManager> ui_manager_; |
||||
Glib::RefPtr<Gtk::ActionGroup> action_group_; |
||||
Glib::RefPtr<Gtk::ActionGroup> action_group_hidden() { |
||||
return action_group_hidden_; |
||||
}; |
||||
|
||||
Glib::RefPtr<Gtk::UIManager> ui_manager_hidden() { |
||||
return ui_manager_hidden_; |
||||
}; |
||||
void BuildMenu(); |
||||
void BuildHiddenMenu(); |
||||
protected: |
||||
Glib::RefPtr<Gtk::UIManager> ui_manager_menu_; |
||||
Glib::RefPtr<Gtk::ActionGroup> action_group_menu_; |
||||
Glib::RefPtr<Gtk::UIManager> ui_manager_hidden_; |
||||
Glib::RefPtr<Gtk::ActionGroup> action_group_hidden_; |
||||
private: |
||||
Keybindings::Model model_; |
||||
};//Controller
|
||||
} |
||||
|
||||
#endif // JUCI_KEYBINDINGS_H_
|
||||
|
||||
@ -0,0 +1,148 @@
|
||||
#include "notebook.h" |
||||
|
||||
|
||||
Notebook::View::View() : |
||||
view_(Gtk::ORIENTATION_VERTICAL){ |
||||
|
||||
} |
||||
Gtk::Box& Notebook::View::view() { |
||||
view_.pack_start(notebook_); |
||||
return view_; |
||||
} |
||||
Notebook::Controller::Controller(Keybindings::Controller& keybindings){ |
||||
|
||||
scrolledwindow_vec_.push_back(new Gtk::ScrolledWindow()); |
||||
source_vec_.push_back(new Source::Controller); |
||||
scrolledwindow_vec_.back()->add(source_vec_.back()->view()); |
||||
source_vec_.back()->OnNewEmptyFile(); |
||||
view_.notebook().append_page(*scrolledwindow_vec_.back(), "juCi++"); |
||||
refClipboard = Gtk::Clipboard::get(); |
||||
|
||||
keybindings.action_group_menu()->add(Gtk::Action::create("FileMenu", |
||||
Gtk::Stock::FILE)); |
||||
/* File->New files */ |
||||
|
||||
keybindings.action_group_menu()->add(Gtk::Action::create("FileNewStandard", |
||||
Gtk::Stock::NEW, |
||||
"New empty file", |
||||
"Create a new file"), |
||||
[this]() { |
||||
OnFileNewEmptyfile(); |
||||
}); |
||||
keybindings.action_group_menu()->add(Gtk::Action::create("FileNewCC", |
||||
"New cc file"), |
||||
Gtk::AccelKey("<control><alt>c"), |
||||
[this]() { |
||||
OnFileNewCCFile(); |
||||
}); |
||||
keybindings.action_group_menu()->add(Gtk::Action::create("FileNewH", |
||||
"New h file"), |
||||
Gtk::AccelKey("<control><alt>h"), |
||||
[this]() { |
||||
OnFileNewHeaderFile(); |
||||
}); |
||||
keybindings.action_group_menu()->add(Gtk::Action::create("WindowCloseTab", |
||||
"Close tab"), |
||||
Gtk::AccelKey("<control>w"), |
||||
[this]() { |
||||
OnCloseCurrentPage(); |
||||
}); |
||||
keybindings.action_group_menu()->add(Gtk::Action::create("EditFind", |
||||
Gtk::Stock::FIND), |
||||
[this]() { |
||||
//TODO(Oyvang, Zalox, Forgi)Create function OnEditFind();
|
||||
}); |
||||
keybindings.action_group_menu()->add(Gtk::Action::create("EditCopy", |
||||
Gtk::Stock::COPY),
|
||||
[this]() { |
||||
OnEditCopy(); |
||||
}); |
||||
keybindings.action_group_menu()->add(Gtk::Action::create("EditCut", |
||||
Gtk::Stock::CUT), |
||||
[this]() { |
||||
OnEditCut(); |
||||
}); |
||||
keybindings.action_group_menu()->add(Gtk::Action::create("EditPaste", |
||||
Gtk::Stock::PASTE), |
||||
[this]() { |
||||
OnEditPaste(); |
||||
}); |
||||
entry_.view_.entry().signal_activate().connect( |
||||
[this]() { |
||||
OnNewPage(entry_.view_.entry().get_text()); |
||||
entry_.OnHideEntries(); |
||||
}); |
||||
}//Constructor
|
||||
Gtk::Box& Notebook::Controller::view() { |
||||
return view_.view(); |
||||
} |
||||
Gtk::Box& Notebook::Controller::entry_view(){ |
||||
return entry_.view(); |
||||
} |
||||
void Notebook::Controller::OnNewPage(std::string name) { |
||||
scrolledwindow_vec_.push_back(new Gtk::ScrolledWindow()); |
||||
source_vec_.push_back(new Source::Controller); |
||||
scrolledwindow_vec_.back()->add(source_vec_.back()->view()); |
||||
source_vec_.back()->OnNewEmptyFile(); |
||||
view_.notebook().append_page(*scrolledwindow_vec_.back(), name); |
||||
view_.notebook().show_all_children(); |
||||
view_.notebook().set_focus_child(*scrolledwindow_vec_.back()); |
||||
view_.notebook().set_current_page(view_.notebook().get_n_pages()-1); |
||||
} |
||||
void Notebook::Controller::OnCloseCurrentPage() { |
||||
//TODO (oyvang, zalox, forgi) Save a temp file, in case you close one you dont want to close?
|
||||
int page = view_.notebook().get_current_page(); |
||||
view_.notebook().remove_page(page); |
||||
delete source_vec_.at(page); |
||||
delete scrolledwindow_vec_.at(page); |
||||
source_vec_.erase(source_vec_.begin()+ page); |
||||
scrolledwindow_vec_.erase(scrolledwindow_vec_.begin()+page); |
||||
} |
||||
void Notebook::Controller::OnFileNewEmptyfile() { |
||||
entry_.OnShowSetFilenName(""); |
||||
} |
||||
void Notebook::Controller::OnFileNewCCFile() { |
||||
entry_.OnShowSetFilenName(".cc"); |
||||
} |
||||
void Notebook::Controller::OnFileNewHeaderFile() { |
||||
entry_.OnShowSetFilenName(".h"); |
||||
} |
||||
void Notebook::Controller::OnEditCopy() { |
||||
if (view_.notebook().get_n_pages() != 0) { |
||||
int source_pos = view_.notebook().get_current_page(); |
||||
Glib::RefPtr<Gtk::TextBuffer> buffer = source_vec_.at(source_pos) |
||||
->view().get_buffer(); |
||||
buffer->copy_clipboard(refClipboard); |
||||
} |
||||
} |
||||
void Notebook::Controller::OnEditPaste() { |
||||
if (view_.notebook().get_n_pages() != 0) { |
||||
int source_pos = view_.notebook().get_current_page(); |
||||
Glib::RefPtr<Gtk::TextBuffer> buffer = source_vec_.at(source_pos) |
||||
->view().get_buffer(); |
||||
buffer->paste_clipboard(refClipboard); |
||||
} |
||||
} |
||||
void Notebook::Controller::OnEditCut() { |
||||
if (view_.notebook().get_n_pages() != 0) { |
||||
int source_pos = view_.notebook().get_current_page(); |
||||
Glib::RefPtr<Gtk::TextBuffer> buffer = source_vec_.at(source_pos) |
||||
->view().get_buffer(); |
||||
buffer->cut_clipboard(refClipboard); |
||||
} |
||||
} |
||||
|
||||
void Notebook::Controller::OnOpenFile(std::string filename) { |
||||
scrolledwindow_vec_.push_back(new Gtk::ScrolledWindow()); |
||||
source_vec_.push_back(new Source::Controller); |
||||
scrolledwindow_vec_.back()->add(source_vec_.back()->view()); |
||||
source_vec_.back()->OnOpenFile(filename); |
||||
view_.notebook().append_page(*scrolledwindow_vec_.back(), filename); |
||||
view_.notebook().show_all_children(); |
||||
view_.notebook().set_focus_child(*scrolledwindow_vec_.back()); |
||||
view_.notebook().set_current_page(view_.notebook().get_n_pages()-1); |
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,44 @@
|
||||
#ifndef JUCI_NOTEBOOK_H_ |
||||
#define JUCI_NOTEBOOK_H_ |
||||
|
||||
#include <iostream> |
||||
#include "gtkmm.h" |
||||
#include "entry.h" |
||||
#include "source.h" |
||||
|
||||
namespace Notebook { |
||||
class View { |
||||
public: |
||||
View(); |
||||
Gtk::Box& view(); |
||||
Gtk::Notebook& notebook() { return notebook_; } |
||||
protected: |
||||
Gtk::Box view_; |
||||
Gtk::Notebook notebook_; |
||||
}; |
||||
class Controller { |
||||
public: |
||||
Controller(Keybindings::Controller& keybindings); |
||||
Gtk::Box& view(); |
||||
Gtk::Box& entry_view(); |
||||
void OnNewPage(std::string name); |
||||
void OnCloseCurrentPage(); |
||||
void OnOpenFile(std::string filename); |
||||
private: |
||||
View view_; |
||||
Entry::Controller entry_; |
||||
std::vector<Source::Controller*> source_vec_; |
||||
std::vector<Gtk::ScrolledWindow*> scrolledwindow_vec_; |
||||
Glib::RefPtr<Gtk::Clipboard> refClipboard; |
||||
std::list<Gtk::TargetEntry> listTargets; |
||||
void OnFileNewEmptyfile(); |
||||
void OnFileNewCCFile(); |
||||
void OnFileNewHeaderFile(); |
||||
void OnEditCopy(); |
||||
void OnEditPaste(); |
||||
void OnEditCut(); |
||||
}; // class controller
|
||||
} // namespace Notebook
|
||||
|
||||
|
||||
#endif // JUCI_NOTEBOOK_H_
|
||||
@ -0,0 +1,92 @@
|
||||
#include "sourcefile.h" |
||||
#include <giomm.h> |
||||
#include <string> |
||||
#include <iostream> |
||||
#include <vector> |
||||
|
||||
using namespace std; |
||||
|
||||
sourcefile::sourcefile(const string &input_filename) |
||||
: lines(), filename(input_filename) { |
||||
open(input_filename); |
||||
} |
||||
|
||||
/**
|
||||
*
|
||||
*/ |
||||
void sourcefile::open(const string &filename) { |
||||
Gio::init(); |
||||
|
||||
// Creates/Opens a file specified by the input string.
|
||||
Glib::RefPtr<Gio::File> file = Gio::File::create_for_path(filename); |
||||
|
||||
if (!file) // Gio::File has overloaded operator
|
||||
cerr << "Was not able to open file: " << filename << endl; |
||||
|
||||
// Creates pointer for filestream
|
||||
|
||||
if (!file->query_exists()) { |
||||
file->create_file()->close(); |
||||
} |
||||
|
||||
Glib::RefPtr<Gio::FileInputStream> stream = file->read(); |
||||
|
||||
if (!stream) // error message on stream failure
|
||||
cerr << filename << " returned an empty stream" << endl; |
||||
|
||||
Glib::RefPtr<Gio::DataInputStream> |
||||
datainput = Gio::DataInputStream::create(stream); |
||||
|
||||
string line; |
||||
while (datainput->read_line(line)) { |
||||
lines.push_back(line); |
||||
} |
||||
|
||||
datainput->close(); |
||||
stream->close(); |
||||
} |
||||
|
||||
vector<string> sourcefile::get_lines() { |
||||
return lines; |
||||
} |
||||
|
||||
string sourcefile::get_line(int line_number) { |
||||
return lines[line_number]; |
||||
} |
||||
|
||||
int sourcefile::save(const string &text) { |
||||
Gio::init(); |
||||
|
||||
// Creates/Opens a file specified by the input string.
|
||||
Glib::RefPtr<Gio::File> file = Gio::File::create_for_path(filename); |
||||
|
||||
if (!file) // Gio::File has overloaded operator
|
||||
cerr << "Was not able to open file: " << filename << endl; |
||||
|
||||
// Creates
|
||||
Glib::RefPtr<Gio::FileOutputStream> stream = |
||||
file->query_exists() ? file->replace() : file->create_file(); |
||||
|
||||
if (!stream) // error message on stream failure
|
||||
cerr << filename << " returned an empty stream" << endl; |
||||
|
||||
Glib::RefPtr<Gio::DataOutputStream> |
||||
output = Gio::DataOutputStream::create(stream); |
||||
|
||||
output->put_string(text); |
||||
|
||||
output->close(); |
||||
stream->close(); |
||||
|
||||
|
||||
return 0; |
||||
} |
||||
|
||||
string sourcefile::get_content() { |
||||
string res; |
||||
for (auto line : lines) { |
||||
res.append(line).append("\n"); |
||||
} |
||||
return res; |
||||
} |
||||
|
||||
@ -0,0 +1,23 @@
|
||||
#ifndef JUCI_SOURCEFILE_H_ |
||||
#define JUCI_SOURCEFILE_H_ |
||||
|
||||
#include <string> |
||||
#include <vector> |
||||
|
||||
using namespace std; |
||||
|
||||
class sourcefile { |
||||
public: |
||||
explicit sourcefile(const string &filename); |
||||
vector<string> get_lines(); |
||||
string get_content(); |
||||
string get_line(int line_number); |
||||
int save(const string &text); |
||||
|
||||
private: |
||||
void open(const string &filename); |
||||
vector<string> lines; |
||||
string filename; |
||||
}; |
||||
|
||||
#endif // JUCI_SOURCEFILE_H_
|
||||
@ -1,27 +1,80 @@
|
||||
#include "juci.h" |
||||
#include "window.h" |
||||
|
||||
Window::Window() : |
||||
window_box_(Gtk::ORIENTATION_VERTICAL), |
||||
notebook_(keybindings_), |
||||
menu_(keybindings_){ |
||||
set_title("juCi++"); |
||||
set_default_size(600, 600); |
||||
set_default_size(600, 400); |
||||
add(window_box_); |
||||
keybindings_.action_group()->add(Gtk::Action::create("FileQuit", |
||||
keybindings_.action_group_menu()->add(Gtk::Action::create("FileQuit", |
||||
Gtk::Stock::QUIT), |
||||
[this]() { |
||||
OnSystemQuit(); |
||||
OnWindowHide(); |
||||
}); |
||||
keybindings_.action_group_menu()->add(Gtk::Action::create("FileOpenFile", |
||||
Gtk::Stock::OPEN), |
||||
[this]() { |
||||
OnOpenFile(); |
||||
}); |
||||
add_accel_group(keybindings_.ui_manager_menu()->get_accel_group()); |
||||
add_accel_group(keybindings_.ui_manager_hidden()->get_accel_group()); |
||||
|
||||
add_accel_group(keybindings_.ui_manager()->get_accel_group()); |
||||
window_box_.pack_start(menu_.view(), Gtk::PACK_SHRINK); |
||||
window_box_.pack_start(source().view()); |
||||
window_box_.pack_start(notebook_.entry_view(), Gtk::PACK_SHRINK); |
||||
window_box_.pack_start(notebook_.view()); |
||||
show_all_children(); |
||||
} // Window constructor
|
||||
void Window::OnWindowHide() { |
||||
hide(); |
||||
} |
||||
|
||||
Source::Controller& Window::source() { |
||||
return source_; |
||||
void Window::OnOpenFile() { |
||||
Gtk::FileChooserDialog dialog("Please choose a file", |
||||
Gtk::FILE_CHOOSER_ACTION_OPEN); |
||||
dialog.set_transient_for(*this); |
||||
dialog.set_position(Gtk::WindowPosition::WIN_POS_CENTER_ALWAYS); |
||||
|
||||
//Add response buttons the the dialog:
|
||||
dialog.add_button("_Cancel", Gtk::RESPONSE_CANCEL); |
||||
dialog.add_button("_Open", Gtk::RESPONSE_OK); |
||||
|
||||
//Add filters, so that only certain file types can be selected:
|
||||
Glib::RefPtr<Gtk::FileFilter> filter_text = Gtk::FileFilter::create(); |
||||
filter_text->set_name("Text files"); |
||||
filter_text->add_mime_type("text/plain"); |
||||
dialog.add_filter(filter_text); |
||||
|
||||
Glib::RefPtr<Gtk::FileFilter> filter_cpp = Gtk::FileFilter::create(); |
||||
filter_cpp->set_name("C/C++ files"); |
||||
filter_cpp->add_mime_type("text/x-c"); |
||||
filter_cpp->add_mime_type("text/x-c++"); |
||||
filter_cpp->add_mime_type("text/x-c-header"); |
||||
dialog.add_filter(filter_cpp); |
||||
|
||||
Glib::RefPtr<Gtk::FileFilter> filter_any = Gtk::FileFilter::create(); |
||||
filter_any->set_name("Any files"); |
||||
filter_any->add_pattern("*"); |
||||
dialog.add_filter(filter_any); |
||||
|
||||
int result = dialog.run(); |
||||
|
||||
switch (result) { |
||||
case(Gtk::RESPONSE_OK): { |
||||
std::cout << "Open clicked." << std::endl; |
||||
std::string path = dialog.get_filename(); |
||||
std::cout << "File selected: " << path << std::endl; |
||||
notebook_.OnOpenFile(path); |
||||
break; |
||||
} |
||||
case(Gtk::RESPONSE_CANCEL): { |
||||
std::cout << "Cancel clicked." << std::endl; |
||||
break; |
||||
} |
||||
default: { |
||||
std::cout << "Unexpected button clicked." << std::endl; |
||||
break; |
||||
} |
||||
} |
||||
|
||||
void Window::OnSystemQuit() { |
||||
hide(); |
||||
} |
||||
|
||||
@ -0,0 +1,23 @@
|
||||
#ifndef JUCI_WINDOW_H_ |
||||
#define JUCI_WINDOW_H_ |
||||
|
||||
#include <iostream> |
||||
#include "gtkmm.h" |
||||
#include "menu.h" |
||||
#include "notebook.h" |
||||
|
||||
class Window : public Gtk::Window { |
||||
public: |
||||
Window(); |
||||
Gtk::Box window_box_; |
||||
private: |
||||
Keybindings::Controller keybindings_; |
||||
Menu::Controller menu_; |
||||
Notebook::Controller notebook_; |
||||
|
||||
//signal handlers
|
||||
void OnWindowHide(); |
||||
void OnOpenFile(); |
||||
}; |
||||
|
||||
#endif // JUCI_WINDOW_H_
|
||||
Loading…
Reference in new issue