Browse Source

Merge branch 'openfile' into syntax

merge-requests/365/head
Jørgen Lien Sellæg 11 years ago
parent
commit
9e0a49b138
  1. 1
      .gitignore
  2. 56
      juci/CMakeLists.txt
  3. 47
      juci/api.cc
  4. 66
      juci/api.h
  5. 3
      juci/api_ext.cc
  6. 193
      juci/config.json
  7. 45
      juci/entry.cc
  8. 43
      juci/entry.h
  9. 5
      juci/juci.cc
  10. 26
      juci/juci.h
  11. 76
      juci/keybindings.cc
  12. 51
      juci/keybindings.h
  13. 214
      juci/menu.cc
  14. 45
      juci/menu.h
  15. 148
      juci/notebook.cc
  16. 44
      juci/notebook.h
  17. 95
      juci/source.cc
  18. 21
      juci/source.h
  19. 92
      juci/sourcefile.cc
  20. 23
      juci/sourcefile.h
  21. 77
      juci/window.cc
  22. 23
      juci/window.h

1
.gitignore vendored

@ -8,3 +8,4 @@
!*.cc !*.cc
!*.h !*.h
!CMakeLists.txt !CMakeLists.txt
!config.json

56
juci/CMakeLists.txt

@ -4,18 +4,19 @@ set(module juci_to_python_api)
project (${project_name}) project (${project_name})
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/cmake/Modules/")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/cmake/Modules/")
INCLUDE(FindPkgConfig) INCLUDE(FindPkgConfig)
#libclang_LIBRARIES message("Searcing for libclang")
#libclang_INCLUDE_DIR #LIBCLANG_FOUND System has libclang.
find_package(Libclang) #LIBCLANG_INCLUDE_DIRS The libclang include directories.
#LIBCLANG_LIBRARIES The libraries needed to use libclang.
#LIBCLANG_LIBRARY_DIR The path to the directory containing libclang.
#LIBCLANG_KNOWN_LLVM_VERSIONS Known LLVM release numbers.
find_package(Testlcl)
message("Libclang libraries ${Libclang_LIBRARIES}")
message("Libclang libraries ${Libclang_LIBRARY}")
message("Libclang include dirs ${Libclang_INCLUDE_DIR}")
#### Finding boost, the variables below is set ##### #### Finding boost, the variables below is set #####
#PYTHONLIBS_FOUND - True if headers and requested libraries were found #PYTHONLIBS_FOUND - True if headers and requested libraries were found
@ -68,36 +69,53 @@ else()
message("Gtkmm link dirs ${GTKMM_LIBRARIES}") message("Gtkmm link dirs ${GTKMM_LIBRARIES}")
message(FATAL_ERROR "The gtkmm libraries are required. Quitting.") message(FATAL_ERROR "The gtkmm libraries are required. Quitting.")
endif() endif()
# name of the executable on Windows will be example.exe # name of the executable on Windows will be example.exe
add_executable(${project_name} add_executable(${project_name}
#list of every needed file to create the executable #list of every needed file to create the executable
juci.h
juci.cc juci.cc
keybindings keybindings
menu menu
source source
sourcefile.h
sourcefile.cc
window window
api api
notebook
entry
#there is no need for extentions #there is no need for extentions
) )
add_library(${module} SHARED add_library(${module} SHARED
api
api.h api_ext
api_ext.cc
) )
# dependencies # dependencies
include_directories(${Boost_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIRS} ${GTKMM_INCLUDE_DIRS} "/home/zalox/bachelor/libclang++/")
link_directories(${GTKMM_LIBRARY_DIRS} ${Boost_LIBRARY_DIRS} ${PYTHON_INCLUDE_DIRS} "/home/zalox/bachelor/libclang++/")
if(${lcl_NOTFOUND})
message("FATAL_ERROR ohh lord!")
else()
message("Found libs!")
endif()
include_directories(
${Boost_INCLUDE_DIRS}
${PYTHON_INCLUDE_DIRS}
${GTKMM_INCLUDE_DIRS}
"/home/zalox/bachelor/libclang++/headers/"
)
link_directories(
${GTKMM_LIBRARY_DIRS}
${Boost_LIBRARY_DIRS}
${PYTHON_INCLUDE_DIRS}
${LCL_LIBRARY_DIRS}
)
#module: #module:
set_target_properties(${module} PROPERTIES PREFIX "") set_target_properties(${module} PROPERTIES PREFIX "")
target_link_libraries(${module} ${PYTHON_LIBRARIES} ${Boost_LIBRARIES}) target_link_libraries(${module} ${PYTHON_LIBRARIES} ${Boost_LIBRARIES})
#executable: #executable:
target_link_libraries(${project_name} ${GTKMM_LIBRARIES} ${Boost_LIBRARIES} ${PYTHON_LIBRARIES} "/home/zalox/bachelor/libclang++/") target_link_libraries(${project_name} ${LCL_LIBRARIES} ${GTKMM_LIBRARIES} ${Boost_LIBRARIES} ${PYTHON_LIBRARIES})

47
juci/api.cc

@ -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();
}
}
}

66
juci/api.h

@ -1,77 +1,47 @@
#ifndef JUCI_API_H_
#define JUCI_API_H_
#include <boost/python.hpp> #include <boost/python.hpp>
#include <Python.h> #include <Python.h>
#include <string> #include <string>
//
// Plugin API // Plugin API
// //
namespace juci_api{ const std::string g_project_root("/home/forgie/bachelor/app/juci/");
static std::string g_test_string("test");
namespace juci_api {
// //
// calls from python to C++ // calls from python to C++
// //
namespace cpp{ namespace cpp {
//
// Replaceword: // Replaceword:
// replaces a word in the editor with a string // replaces a word in the editor with a string
//
void ReplaceWord(const std::string word_){ void 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;
}
// //
// ReplaceLine: // ReplaceLine:
// Replaces a line in the editor with a string // Replaces a line in the editor with a string
// //
void ReplaceLine(const std::string line_){ void 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;
}
}//namespace cpp }//namespace cpp
// //
// calls from C++ to Python // calls from C++ to Python
// //
namespace py{ namespace py {
const std::string g_project_root("~/bachelor/app/juci/");
//helpers //helpers
boost::python::api::object openPythonScript(const std::string path, boost::python::api::object openPythonScript(const std::string path,
boost::python::api::object python_name_space) { 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 snippet(std::string& word); //void snippet(std::string& word);
void plugin(const std::string& plugin_name){ void 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();
}
}
}// py }// py
}//juci_api }//juci_api
#endif // JUCI_API_H

3
juci/api_ext.cc

@ -1,6 +1,5 @@
#include "api.h" #include "api.h"
BOOST_PYTHON_MODULE(juci_to_python_api) {
BOOST_PYTHON_MODULE(jucy_to_python_api) {
using namespace boost::python; using namespace boost::python;
// text editing // text editing
def("replaceLine", &juci_api::cpp::ReplaceLine); def("replaceLine", &juci_api::cpp::ReplaceLine);

193
juci/config.json

@ -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"
}
}

45
juci/entry.cc

@ -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();
}

43
juci/entry.h

@ -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_

5
juci/juci.cc

@ -1,5 +1,4 @@
#include "juci.h" #include "window.h"
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
@ -7,8 +6,6 @@ int main(int argc, char *argv[]) {
argc, argc,
argv, argv,
"no.sout.juci"); "no.sout.juci");
// app->set_flags(Gio::APPLICATION_NON_UNIQUE);
Window window; Window window;
return app->run(window); return app->run(window);
} }

26
juci/juci.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_

76
juci/keybindings.cc

@ -1,21 +1,77 @@
#include "keybindings.h" #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> ";
Keybindings::Controller::Controller() { hidden_ui_string_ =
action_group_ = Gtk::ActionGroup::create(); "<ui> "
ui_manager_ = Gtk::UIManager::create(); " <menubar name='MenuBar'> "
} " <menuitem action='Test'/> "
Keybindings::Controller::~Controller(){ " </menubar> "
"</ui> ";
};
Keybindings::Model::~Model() {
}
Keybindings::Controller::Controller() {
action_group_menu_ = Gtk::ActionGroup::create();
ui_manager_menu_ = Gtk::UIManager::create();
action_group_hidden_ = Gtk::ActionGroup::create();
ui_manager_hidden_ = Gtk::UIManager::create();
} }
void Keybindings::Controller::set_ui_manager_action_group(Glib::RefPtr<Gtk::ActionGroup> action_group) { Keybindings::Controller::~Controller() {
ui_manager_->insert_action_group(action_group);
} }
void Keybindings::Controller::set_ui_manger_string(std::string ui_string) { void Keybindings::Controller::BuildMenu() {
try { try {
ui_manager_->add_ui_from_string(ui_string); ui_manager_menu_->add_ui_from_string(model_.menu_ui_string());
} }
catch (const Glib::Error &ex) { catch (const Glib::Error &ex) {
std::cerr << "building menus failed: " << ex.what(); std::cerr << "building menu failed" << ex.what();
} }
ui_manager_menu_->insert_action_group(action_group_menu_);
} }
void Keybindings::Controller::BuildHiddenMenu() {
try {
ui_manager_hidden_->add_ui_from_string(model_.hidden_ui_string());
}
catch (const Glib::Error &ex) {
std::cerr << "building hidden menu failed" << ex.what();
}
ui_manager_hidden_->insert_action_group(action_group_hidden_);
}

51
juci/keybindings.h

@ -1,28 +1,47 @@
//juCi++ class that holds every keybinding.
#ifndef JUCI_KEYBINDINGS_H_
#define JUCI_KEYBINDINGS_H_
#include "iostream" #include "iostream"
#include "gtkmm.h" #include "gtkmm.h"
namespace Keybindings { 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 { class Controller {
public: public:
Controller(); Controller();
virtual ~Controller(); virtual ~Controller();
Glib::RefPtr<Gtk::ActionGroup> action_group_menu() {
Glib::RefPtr<Gtk::ActionGroup> action_group() { return action_group_menu_;
return action_group_;
}; };
Glib::RefPtr<Gtk::UIManager> ui_manager_menu() {
Glib::RefPtr<Gtk::UIManager> ui_manager() { return ui_manager_menu_;
return ui_manager_;
}; };
Glib::RefPtr<Gtk::ActionGroup> action_group_hidden() {
void set_ui_manger_string(std::string ui_string); return action_group_hidden_;
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::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_

214
juci/menu.cc

@ -1,232 +1,90 @@
#include "menu.h" #include "menu.h"
/***********************************/
/* MODEL */
/***********************************/
Menu::Model::Model() {
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> ";
}
Menu::Model::~Model() {
}
// VIEW
Menu::View::View(Gtk::Orientation orientation) : Menu::View::View(Gtk::Orientation orientation) :
view_(orientation) { view_(orientation) {
Gtk::MenuBar menutest;
view_.pack_end(menutest);
} }
Gtk::Box &Menu::View::view( Gtk::Box &Menu::View::view(
Glib::RefPtr<Gtk::UIManager> ui_manager) { Glib::RefPtr<Gtk::UIManager> ui_manager) {
view_.pack_start(*ui_manager->get_widget("/MenuBar"), Gtk::PACK_SHRINK); view_.pack_start(*ui_manager->get_widget("/MenuBar"), Gtk::PACK_SHRINK);
return view_; return view_;
} }
Menu::View::~View() { Menu::Controller::Controller(Keybindings::Controller& keybindings) :
}
/***********************************/
/* CONTROLLER */
/***********************************/
Menu::Controller::Controller(Keybindings::Controller keybindings) :
menu_view_(Gtk::ORIENTATION_VERTICAL), menu_view_(Gtk::ORIENTATION_VERTICAL),
menu_model_(),
keybindings_(keybindings) { keybindings_(keybindings) {
/* Add action to menues */ keybindings_.action_group_menu()->add(Gtk::Action::create("FileNew",
/* START file menu */ Gtk::Stock::FILE));
keybindings_.action_group()->add(Gtk::Action::create("FileMenu", Gtk::Stock::FILE));
/* File->New files */ keybindings_.action_group_menu()->add(Gtk::Action::create("FileOpenFolder",
keybindings_.action_group()->add(Gtk::Action::create("FileNew", "New")); "Open folder"),
keybindings_.action_group()->add(Gtk::Action::create("FileNewStandard",
Gtk::Stock::NEW, "New empty file", "Create a new file"),
[this]() {
OnFileNewEmptyfile();
});
keybindings_.action_group()->add(Gtk::Action::create("FileNewCC",
Gtk::Stock::NEW, "New cc file", "Create a new cc file"),
Gtk::AccelKey("<control><alt>c"),
[this]() {
OnFileNewCCFile();
});
keybindings_.action_group()->add(Gtk::Action::create("FileNewH",
Gtk::Stock::NEW, "New h file", "Create a new h file"),
Gtk::AccelKey("<control><alt>h"),
[this]() {
OnFileNewHeaderFile();
});
/* File-> New files end */
keybindings_.action_group()->add(Gtk::Action::create("FileOpenFile", Gtk::Stock::OPEN),
[this]() {
OnFileOpenFile();
});
keybindings_.action_group()->add(Gtk::Action::create("FileOpenFolder", "Open folder"),
[this]() { [this]() {
OnFileOpenFolder(); OnFileOpenFolder();
}); });
/* END file menu */ keybindings_.action_group_menu()->add(Gtk::Action::create("EditMenu",
/* START edit menu */ Gtk::Stock::EDIT));
keybindings_.action_group()->add(Gtk::Action::create("EditMenu", Gtk::Stock::EDIT)); keybindings_.action_group_menu()->add(Gtk::Action::create("WindowMenu",
keybindings_.action_group()->add(Gtk::Action::create("EditCopy", Gtk::Stock::COPY), "_Window"));
[this]() { keybindings_.action_group_menu()->add(Gtk::Action::create("WindowSplitWindow",
OnEditCopy(); "Split window"),
});
keybindings_.action_group()->add(Gtk::Action::create("EditCut", Gtk::Stock::CUT),
[this]() {
OnEditCut();
});
keybindings_.action_group()->add(Gtk::Action::create("EditPaste", Gtk::Stock::PASTE),
[this]() {
OnEditPaste();
});
keybindings_.action_group()->add(Gtk::Action::create("EditFind", Gtk::Stock::FIND),
[this]() {
OnEditFind();
});
/* END edit menu */
/* START window menu */
keybindings_.action_group()->add(Gtk::Action::create("WindowMenu", "_Window"));
keybindings_.action_group()->add(Gtk::Action::create("WindowCloseTab", "Close tab"),
Gtk::AccelKey("<control>w"),
[this]() {
OnWindowCloseTab();
});
keybindings_.action_group()->add(Gtk::Action::create("WindowSplitWindow", "Split window"),
Gtk::AccelKey("<control><alt>S"), Gtk::AccelKey("<control><alt>S"),
[this]() { [this]() {
OnWindowSplitWindow(); OnWindowSplitWindow();
}); });
/* END window menu */ keybindings_.action_group_menu()->add(Gtk::Action::create("PluginMenu",
/* START Plugin menu */ "_Plugins"));
keybindings_.action_group()->add(Gtk::Action::create("PluginMenu", "_Plugins")); keybindings_.action_group_menu()->add(Gtk::Action::create("PluginSnippet",
/*Plugin->snippet*/ "Snippet"));
keybindings_.action_group()->add(Gtk::Action::create("PluginSnippet", "Snippet")); keybindings_.action_group_menu()->add(Gtk::Action::create("PluginAddSnippet",
keybindings_.action_group()->add(Gtk::Action::create("PluginAddSnippet", "Add snippet"), "Add snippet"),
Gtk::AccelKey("<alt>space"), Gtk::AccelKey("<alt>space"),
[this]() { [this]() {
OnPluginAddSnippet(); OnPluginAddSnippet();
}); });
/* End snippet */ keybindings_.action_group_menu()->add(Gtk::Action::create("HelpMenu",
/* END plugin menu */ Gtk::Stock::HELP));
/* START help menu */ keybindings_.action_group_menu()->add(Gtk::Action::create("HelpAbout",
keybindings_.action_group()->add(Gtk::Action::create("HelpMenu", Gtk::Stock::HELP)); Gtk::Stock::ABOUT),
keybindings_.action_group()->add(Gtk::Action::create("HelpAbout", Gtk::Stock::ABOUT),
[this]() { [this]() {
OnHelpAbout(); OnHelpAbout();
}); });
keybindings_.action_group_hidden()->add(Gtk::Action::create("Test"),
Gtk::AccelKey("<control><alt>K"),
/* END help menu */ [this]() {
OnHelpAbout();
});
keybindings_.ui_manager()->add_ui_from_string(menu_model_.ui_string()); keybindings_.BuildMenu();
keybindings_.ui_manager()->insert_action_group(keybindings_.action_group()); keybindings_.BuildHiddenMenu();
} } // Controller
Menu::Controller::~Controller() {
}
Gtk::Box &Menu::Controller::view() { Gtk::Box &Menu::Controller::view() {
return menu_view_.view(keybindings_.ui_manager()); return menu_view_.view(keybindings_.ui_manager_menu());
}
void Menu::Controller::OnFileNewEmptyfile() {
std::cout << "New file clicked" << std::endl;
//TODO(Oyvang) Legg til funksjon
}
void Menu::Controller::OnFileNewCCFile() {
std::cout << "New cc file clicked" << std::endl;
//TODO(Oyvang) Legg til funksjon
}
void Menu::Controller::OnFileNewHeaderFile() {
std::cout << "New header file clicked" << std::endl;
//TODO(Oyvang) Legg til funksjon
} }
void Menu::Controller::OnPluginAddSnippet() { void Menu::Controller::OnPluginAddSnippet() {
std::cout << "Add snipper" << std::endl; //TODO(Forgi add you snippet magic code) //TODO(Forgi add you snippet magic code)
std::cout << "Add snipper" << std::endl;
juci_api::py::LoadPlugin("snippet");
} }
void Menu::Controller::OnFileOpenFile() { void Menu::Controller::OnFileOpenFile() {
std::cout << "Open file clicked" << std::endl; std::cout << "Open file clicked" << std::endl;
//TODO(Oyvang) Legg til funksjon //TODO(Oyvang) Legg til funksjon
} }
void Menu::Controller::OnFileOpenFolder() { void Menu::Controller::OnFileOpenFolder() {
std::cout << "Open folder clicked" << std::endl; std::cout << "Open folder clicked" << std::endl;
//TODO(Oyvang) Legg til funksjon //TODO(Oyvang) Legg til funksjon
} }
void Menu::Controller::OnWindowCloseTab() {
std::cout << "Closing tab clicked" << std::endl;
//TODO(Oyvang) Legg til funksjon
}
void Menu::Controller::OnEditCopy() {
std::cout << "Clicked copy" << std::endl;
//TODO(Oyvang) Legg til funksjon
}
void Menu::Controller::OnEditCut() { void Menu::Controller::OnEditCut() {
std::cout << "Clicked cut" << std::endl; std::cout << "Clicked cut" << std::endl;
//TODO(Oyvang) Legg til funksjon //TODO(Oyvang) Legg til funksjon
} }
void Menu::Controller::OnEditPaste() {
std::cout << "Clicked paste" << std::endl;
//TODO(Oyvang) Legg til funksjon
}
void Menu::Controller::OnEditFind() { void Menu::Controller::OnEditFind() {
std::cout << "Clicked find" << std::endl; std::cout << "Clicked find" << std::endl;
//TODO(Oyvang) Legg til funksjon //TODO(Oyvang) Legg til funksjon
} }
void Menu::Controller::OnWindowSplitWindow() { void Menu::Controller::OnWindowSplitWindow() {
std::cout << "Clicked split window" << std::endl; std::cout << "Clicked split window" << std::endl;
//TODO(Oyvang) Legg til funksjon //TODO(Oyvang) Legg til funksjon
} }
void Menu::Controller::OnHelpAbout() { void Menu::Controller::OnHelpAbout() {
std::cout << "Clicked about" << std::endl; std::cout << "Clicked about" << std::endl;
//TODO(Oyvang) Legg til funksjon //TODO(Oyvang) Legg til funksjon

45
juci/menu.h

@ -4,72 +4,33 @@
#include <iostream> #include <iostream>
#include "gtkmm.h" #include "gtkmm.h"
#include "keybindings.h" #include "keybindings.h"
#include "api.h"
namespace Menu { namespace Menu {
class Model {
public:
Model();
virtual ~Model();
std::string ui_string() {
return ui_string_;
}
private:
std::string ui_string_;
}; // class Model
class View { class View {
public: public:
explicit View(Gtk::Orientation orient); explicit View(Gtk::Orientation orient);
virtual ~View();
Gtk::Box &view(Glib::RefPtr<Gtk::UIManager> ui_manager); Gtk::Box &view(Glib::RefPtr<Gtk::UIManager> ui_manager);
protected: protected:
Gtk::Box view_; Gtk::Box view_;
}; // class View }; // class View
// controller
class Controller { class Controller {
public: public:
explicit Controller(Keybindings::Controller keybindings); explicit Controller(Keybindings::Controller& keybindings);
virtual ~Controller();
Gtk::Box &view(); Gtk::Box &view();
private: private:
Keybindings::Controller keybindings_; Keybindings::Controller &keybindings_;
View menu_view_; View menu_view_;
Model menu_model_;
void OnFileNewEmptyfile(); void OnFileNewEmptyfile();
/*Signal handlers*/
void OnFileNewCCFile(); void OnFileNewCCFile();
void OnFileNewHeaderFile(); void OnFileNewHeaderFile();
void OnFileOpenFile(); void OnFileOpenFile();
void OnFileOpenFolder(); void OnFileOpenFolder();
void OnPluginAddSnippet(); void OnPluginAddSnippet();
void OnWindowCloseTab(); void OnWindowCloseTab();
void OnEditCopy();
void OnEditCut(); void OnEditCut();
void OnEditPaste();
void OnEditFind(); void OnEditFind();
void OnWindowSplitWindow(); void OnWindowSplitWindow();
void OnHelpAbout(); void OnHelpAbout();
}; // class Controller }; // class Controller
} // namespace Menu } // namespace Menu

148
juci/notebook.cc

@ -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);
}

44
juci/notebook.h

@ -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_

95
juci/source.cc

@ -1,5 +1,8 @@
#include "source.h" #include "source.h"
#include <iostream> #include <iostream>
#include "sourcefile.h"
#include <boost/property_tree/json_parser.hpp>
#include <fstream>
////////////// //////////////
//// View //// //// View ////
@ -11,12 +14,12 @@ Source::View::View() {
// returns the new line // returns the new line
string Source::View::UpdateLine() { string Source::View::UpdateLine() {
Gtk::TextIter line(get_buffer()->get_insert()->get_iter()); Gtk::TextIter line(get_buffer()->get_insert()->get_iter());
// std::cout << line.get_line() << std::endl;
// for each word --> check what it is --> apply appropriate tag // for each word --> check what it is --> apply appropriate tag
return "";
// retUrn "";
} }
String Source::View::Getline(const Gtk::TextIter &begin) { string Source::View::GetLine(const Gtk::TextIter &begin) {
Gtk::TextIter end(begin); Gtk::TextIter end(begin);
while (!end.ends_line()) while (!end.ends_line())
end++; end++;
@ -31,12 +34,53 @@ void Source::View::ApplyTheme(const Source::Theme &theme) {
} }
} }
void Source::View::OnOpenFile(std::vector<Clang::SourceLocation> &locations,
const Source::Theme &theme) {
Glib::RefPtr<Gtk::TextBuffer> buffer = get_buffer();
for (auto &loc : locations) {
string type = std::to_string(loc.kind());
int linum = loc.line_number();
int begin = loc.begin();
int end = loc.end();
if(end < 0) end = 0;
if(begin < 0) begin = 0;
// for (auto &i : theme.tagtable()) {
// std::cout << "first: "<< i.first << " second: "<< i.second << std::endl;
// }
// std::cout << "type: " << type << std::endl;
buffer->apply_tag_by_name(theme.typetable().at(type),
buffer->get_iter_at_line_offset(linum, begin),
buffer->get_iter_at_line_offset(linum, end));
// std::cout << "This is a ans" << std::endl;
}
}
// Source::View::Theme::tagtable() // Source::View::Theme::tagtable()
// returns a const refrence to the tagtable // returns a const refrence to the tagtable
const std::unordered_map<string, string>& Source::Theme::tagtable() const { const std::unordered_map<string, string>& Source::Theme::tagtable() const {
return tagtable_; return tagtable_;
} }
// Source::View::Theme::tagtable()
// returns a const refrence to the tagtable
const std::unordered_map<string, string>& Source::Theme::typetable() const {
return typetable_;
}
void Source::Theme::InsertTag(const string &key, const string &value) {
tagtable_[key] = value;
}
// Source::View::Theme::SetTagTable()
// sets the tagtable for the view
void Source::Theme::SetTypeTable(
const std::unordered_map<string, string> &typetable) {
typetable_ = typetable;
}
void Source::Theme::InsertType(const string &key, const string &value) {
typetable_[key] = value;
}
// Source::View::Theme::SetTagTable() // Source::View::Theme::SetTagTable()
// sets the tagtable for the view // sets the tagtable for the view
void Source::Theme::SetTagTable( void Source::Theme::SetTagTable(
@ -47,14 +91,42 @@ void Source::Theme::SetTagTable(
/////////////// ///////////////
//// Model //// //// Model ////
/////////////// ///////////////
Source::Model::Model() { Source::Model::Model() :
theme_() {
std::cout << "Model constructor run" << std::endl; std::cout << "Model constructor run" << std::endl;
boost::property_tree::ptree pt;
boost::property_tree::json_parser::read_json("config.json", pt);
for ( auto &i : pt ) {
boost::property_tree::ptree props = pt.get_child(i.first);
for (auto &pi : props) {
if (i.first.compare("syntax")) { // checks the config-file
theme_.InsertTag(pi.first, pi.second.get_value<std::string>());
// std::cout << "inserting tag. " << pi.first << pi.second.get_value<std::string>() << std::endl;
}
if (i.first.compare("colors")) { // checks the config-file
theme_.InsertType(pi.first, pi.second.get_value<std::string>());
// std::cout << "inserting type. " << pi.first << pi.second.get_value<std::string>() << std::endl;
}
}
}
}
Source::Theme& Source::Model::theme() {
return theme_;
} }
const string Source::Model::filepath() { const string Source::Model::filepath() {
return filepath_; return filepath_;
} }
void Source::Model::SetFilePath(const string &filepath) {
filepath_ = filepath;
}
void Source::Model::
SetSourceLocations(const std::vector<Clang::SourceLocation> &locations) {
locations_ = locations;
}
//////////////////// ////////////////////
//// Controller //// //// Controller ////
//////////////////// ////////////////////
@ -82,3 +154,18 @@ Source::Model& Source::Controller::model() {
void Source::Controller::OnLineEdit() { void Source::Controller::OnLineEdit() {
view().UpdateLine(); view().UpdateLine();
} }
void Source::Controller::OnNewEmptyFile() {
string filename("/tmp/juci_t");
sourcefile s(filename);
model().SetFilePath(filename);
s.save("");
}
void Source::Controller::OnOpenFile(const string &filename) {
sourcefile s(filename);
view().get_buffer()->set_text(s.get_content());
Clang::TranslationUnit tu(filename.c_str());
model().SetSourceLocations(tu.getSourceLocations());
view().OnOpenFile(model().getSourceLocations(), model().theme());
}

21
juci/source.h

@ -5,6 +5,7 @@
#include <vector> #include <vector>
#include <string> #include <string>
#include "gtkmm.h" #include "gtkmm.h"
#include <TranslationUnit.h>
using std::string; using std::string;
@ -12,9 +13,15 @@ namespace Source {
class Theme { class Theme {
public: public:
const std::unordered_map<string, string>& tagtable() const; const std::unordered_map<string, string>& tagtable() const;
const std::unordered_map<string, string>& typetable() const;
void SetTagTable(const std::unordered_map<string, string> &tagtable); void SetTagTable(const std::unordered_map<string, string> &tagtable);
void InsertTag(const string &key, const string &value);
void SetTypeTable(const std::unordered_map<string, string> &tagtable);
void InsertType(const string &key, const string &value);
private: private:
std::unordered_map<string, string> tagtable_; std::unordered_map<string, string> tagtable_;
std::unordered_map<string, string> typetable_;
string background_; string background_;
}; // class Theme }; // class Theme
@ -23,6 +30,8 @@ namespace Source {
View(); View();
string UpdateLine(); string UpdateLine();
void ApplyTheme(const Theme &theme); void ApplyTheme(const Theme &theme);
void OnOpenFile(std::vector<Clang::SourceLocation> &locations,
const Theme &theme);
private: private:
string GetLine(const Gtk::TextIter &begin); string GetLine(const Gtk::TextIter &begin);
}; // class View }; // class View
@ -30,11 +39,18 @@ namespace Source {
class Model{ class Model{
public: public:
Model(); Model();
Theme theme(); Theme& theme();
const string filepath(); const string filepath();
void SetFilePath(const string &filepath);
void SetSourceLocations(const std::vector<Clang::SourceLocation> &locations);
std::vector<Clang::SourceLocation>& getSourceLocations() {
return locations_;
}
private: private:
Theme theme_; Theme theme_;
string filepath_; string filepath_;
std::vector<Clang::SourceLocation> locations_;
}; };
class Controller { class Controller {
@ -42,10 +58,11 @@ namespace Source {
Controller(); Controller();
View& view(); View& view();
Model& model(); Model& model();
void OnNewEmptyFile();
void OnOpenFile(const string &filename);
private: private:
void OnLineEdit(); void OnLineEdit();
void OnOpenFile();
void OnSaveFile(); void OnSaveFile();
protected: protected:

92
juci/sourcefile.cc

@ -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;
}

23
juci/sourcefile.h

@ -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_

77
juci/window.cc

@ -1,27 +1,80 @@
#include "juci.h" #include "window.h"
Window::Window() : Window::Window() :
window_box_(Gtk::ORIENTATION_VERTICAL), window_box_(Gtk::ORIENTATION_VERTICAL),
menu_(keybindings_) { notebook_(keybindings_),
menu_(keybindings_){
set_title("juCi++"); set_title("juCi++");
set_default_size(600, 600); set_default_size(600, 400);
add(window_box_); add(window_box_);
keybindings_.action_group()->add(Gtk::Action::create("FileQuit", keybindings_.action_group_menu()->add(Gtk::Action::create("FileQuit",
Gtk::Stock::QUIT), Gtk::Stock::QUIT),
[this]() { [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(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(); show_all_children();
} // Window constructor
void Window::OnWindowHide() {
hide();
} }
Source::Controller& Window::source() { void Window::OnOpenFile() {
return source_; 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();
} }

23
juci/window.h

@ -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…
Cancel
Save