Browse Source

Merge pull request #14 from cppit/master

Pull from cppit
merge-requests/365/head
Ole Christian Eidheim 10 years ago
parent
commit
729a9d44f2
  1. 1
      WIN-packages/README.md
  2. 11
      WIN-packages/dialogs_win.h
  3. BIN
      WIN-packages/x64/libdialogs.dll
  4. BIN
      WIN-packages/x86/libdialogs.dll
  5. 15
      src/CMakeLists.txt
  6. 4
      src/config.cc
  7. 51
      src/dialogs.cc
  8. 14
      src/dialogs.h
  9. 24
      src/dialogs_win.cc
  10. 14
      src/directories.cc
  11. 2
      src/files.h
  12. 4
      src/juci.cc
  13. 14
      src/logging.h
  14. 7
      src/menu.cc
  15. 30
      src/notebook.cc
  16. 3
      src/notebook.h
  17. 7
      src/singletons.cc
  18. 14
      src/singletons.h
  19. 6
      src/source_clang.cc
  20. 8
      src/terminal.cc
  21. 281
      src/window.cc
  22. 7
      src/window.h

1
WIN-packages/README.md

@ -0,0 +1 @@
Source code for the dll's can be found at https://github.com/cppit/dialogs

11
WIN-packages/dialogs_win.h

@ -0,0 +1,11 @@
extern "C" {
#ifndef JUCI_C_DIALOGS
#define JUCI_C_DIALOGS
__declspec(dllimport) const char* c_select_folder();
__declspec(dllimport) const char* c_select_file();
__declspec(dllimport) const char* c_new_file();
__declspec(dllimport) const char* c_new_folder();
__declspec(dllimport) const char* c_save_file();
#endif // JUCI_C_DIALOGS
};

BIN
WIN-packages/x64/libdialogs.dll

Binary file not shown.

BIN
WIN-packages/x86/libdialogs.dll

Binary file not shown.

15
src/CMakeLists.txt

@ -41,6 +41,7 @@ set(source_files juci.h
sourcefile.cc sourcefile.cc
window.cc window.cc
window.h window.h
dialogs.h
# api.h # api.h
# api.cc # api.cc
notebook.cc notebook.cc
@ -74,8 +75,17 @@ set(source_files juci.h
if(MSYS) if(MSYS)
list(APPEND source_files terminal_win.cc) list(APPEND source_files terminal_win.cc)
list(APPEND source_files dialogs_win.cc)
set(DIALOGS_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/WIN-packages/")
# if (64 bit)
set(DIALOGS_LIBRARIES "${CMAKE_SOURCE_DIR}/WIN-packages/x64/libdialogs.dll")
message(${DIALOGS_LIBRARIES})
# else
# set(DIALOGS_LIBRARIES "${CMAKE_SOURCE_DIR}/WIN-packages/x32/libdialogs.dll")
#TODO figure out how to do this....
else() else()
list(APPEND source_files terminal.cc) list(APPEND source_files terminal.cc)
list(APPEND source_files dialogs.cc)
endif() endif()
add_executable(${project_name} ${source_files}) add_executable(${project_name} ${source_files})
@ -89,9 +99,9 @@ include_directories(
# ${PYTHON_INCLUDE_DIRS} # ${PYTHON_INCLUDE_DIRS}
${GTKMM_INCLUDE_DIRS} ${GTKMM_INCLUDE_DIRS}
${GTKSVMM_INCLUDE_DIRS} ${GTKSVMM_INCLUDE_DIRS}
${LCL_INCLUDE_DIRS}
${LIBCLANG_INCLUDE_DIRS} ${LIBCLANG_INCLUDE_DIRS}
${ASPELL_INCLUDE_DIR} ${ASPELL_INCLUDE_DIR}
${DIALOGS_INCLUDE_DIRS}
../libclangmm/src ../libclangmm/src
) )
@ -100,7 +110,6 @@ link_directories(
${GTKSVMM_LIBRARY_DIRS} ${GTKSVMM_LIBRARY_DIRS}
${Boost_LIBRARY_DIRS} ${Boost_LIBRARY_DIRS}
# ${PYTHON_INCLUDE_DIRS} # ${PYTHON_INCLUDE_DIRS}
${LCL_LIBRARY_DIRS}
${LIBCLANG_LIBRARY_DIRS} ${LIBCLANG_LIBRARY_DIRS}
) )
@ -113,11 +122,11 @@ link_directories(
target_link_libraries(${project_name} target_link_libraries(${project_name}
${LIBCLANG_LIBRARIES} ${LIBCLANG_LIBRARIES}
${LCL_LIBRARIES}
${GTKMM_LIBRARIES} ${GTKMM_LIBRARIES}
${GTKSVMM_LIBRARIES} ${GTKSVMM_LIBRARIES}
${Boost_LIBRARIES} ${Boost_LIBRARIES}
${ASPELL_LIBRARIES} ${ASPELL_LIBRARIES}
${DIALOGS_LIBRARIES}
# ${PYTHON_LIBRARIES} # ${PYTHON_LIBRARIES}
) )

4
src/config.cc

@ -147,7 +147,7 @@ void MainConfig::GenerateSource() {
void MainConfig::GenerateDirectoryFilter() { void MainConfig::GenerateDirectoryFilter() {
auto dir_cfg=Singleton::Config::directories(); auto dir_cfg=Singleton::Config::directories();
DEBUG("Fetching directory filter"); JDEBUG("Fetching directory filter");
boost::property_tree::ptree dir_json = cfg.get_child("directoryfilter"); boost::property_tree::ptree dir_json = cfg.get_child("directoryfilter");
boost::property_tree::ptree ignore_json = dir_json.get_child("ignore"); boost::property_tree::ptree ignore_json = dir_json.get_child("ignore");
boost::property_tree::ptree except_json = dir_json.get_child("exceptions"); boost::property_tree::ptree except_json = dir_json.get_child("exceptions");
@ -155,5 +155,5 @@ void MainConfig::GenerateDirectoryFilter() {
dir_cfg->exceptions.emplace_back(i.second.get_value<std::string>()); dir_cfg->exceptions.emplace_back(i.second.get_value<std::string>());
for ( auto &i : ignore_json ) for ( auto &i : ignore_json )
dir_cfg->ignored.emplace_back(i.second.get_value<std::string>()); dir_cfg->ignored.emplace_back(i.second.get_value<std::string>());
DEBUG("Directory filter fetched"); JDEBUG("Directory filter fetched");
} }

51
src/dialogs.cc

@ -0,0 +1,51 @@
#include "dialogs.h"
#include "singletons.h"
#include <gtkmm.h>
#include <vector>
std::string open_dialog(const std::string &title,
const std::vector<std::pair<std::string, Gtk::ResponseType>> &buttons,
Gtk::FileChooserAction gtk_options) {
Gtk::FileChooserDialog dialog(title, gtk_options);
if(Singleton::directories()->current_path!="")
gtk_file_chooser_set_current_folder((GtkFileChooser*)dialog.gobj(), Singleton::directories()->current_path.string().c_str());
else
gtk_file_chooser_set_current_folder((GtkFileChooser*)dialog.gobj(), boost::filesystem::current_path().string().c_str());
dialog.set_position(Gtk::WindowPosition::WIN_POS_CENTER_ALWAYS);
// dialog.set_transient_for(parent); TODO add parent
for (auto &button : buttons)
dialog.add_button(button.first, button.second);
return dialog.run() == Gtk::RESPONSE_OK ? dialog.get_filename() : "";
}
std::string Dialog::select_folder() {
return open_dialog("Please choose a folder",
{std::make_pair("Cancel", Gtk::RESPONSE_CANCEL),std::make_pair("Open", Gtk::RESPONSE_OK)},
Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
}
std::string Dialog::new_file() {
return open_dialog("Please create a new file",
{std::make_pair("Cancel", Gtk::RESPONSE_CANCEL), std::make_pair("Save", Gtk::RESPONSE_OK)},
Gtk::FILE_CHOOSER_ACTION_SAVE);
}
std::string Dialog::new_folder() {
return open_dialog("Please create a new folder",
{std::make_pair("Cancel", Gtk::RESPONSE_CANCEL),std::make_pair("Create", Gtk::RESPONSE_OK)},
Gtk::FILE_CHOOSER_ACTION_CREATE_FOLDER);
}
std::string Dialog::select_file() {
return open_dialog("Please choose a folder",
{std::make_pair("Cancel", Gtk::RESPONSE_CANCEL),std::make_pair("Select", Gtk::RESPONSE_OK)},
Gtk::FILE_CHOOSER_ACTION_OPEN);
}
std::string Dialog::save_file() {
return open_dialog("Please choose a file",
{std::make_pair("Cancel", Gtk::RESPONSE_CANCEL),std::make_pair("Save", Gtk::RESPONSE_OK)},
Gtk::FILE_CHOOSER_ACTION_SAVE);
}

14
src/dialogs.h

@ -0,0 +1,14 @@
#ifndef JUCI_DIALOG_H_
#define JUCI_DIALOG_H_
#include <string>
class Dialog {
public:
static std::string select_folder();
static std::string select_file();
static std::string new_file();
static std::string new_folder();
static std::string save_file();
}; // namespace Dialog
#endif // JUCI_DIALOG_H_

24
src/dialogs_win.cc

@ -0,0 +1,24 @@
#ifdef _WIN32
#include "dialogs.h"
#include <dialogs_win.h>
std::string Dialog::select_folder() {
return c_select_folder();
}
std::string Dialog::new_file() {
return c_new_file();
}
std::string Dialog::new_folder() {
return c_new_folder();
}
std::string Dialog::select_file() {
return c_select_file();
}
std::string Dialog::save_file() {
return c_save_file();
}
#endif

14
src/directories.cc

@ -23,7 +23,7 @@ namespace sigc {
} }
Directories::Directories() : stop_update_thread(false) { Directories::Directories() : stop_update_thread(false) {
DEBUG("start"); JDEBUG("start");
add(tree_view); add(tree_view);
set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
tree_store = Gtk::TreeStore::create(column_record); tree_store = Gtk::TreeStore::create(column_record);
@ -120,7 +120,7 @@ Directories::~Directories() {
} }
void Directories::open(const boost::filesystem::path& dir_path) { void Directories::open(const boost::filesystem::path& dir_path) {
DEBUG("start"); JDEBUG("start");
if(dir_path=="") if(dir_path=="")
return; return;
@ -142,21 +142,21 @@ void Directories::open(const boost::filesystem::path& dir_path) {
current_path=dir_path; current_path=dir_path;
DEBUG("end"); JDEBUG("end");
} }
void Directories::update() { void Directories::update() {
DEBUG("start"); JDEBUG("start");
update_mutex.lock(); update_mutex.lock();
for(auto &last_write_time: last_write_times) { for(auto &last_write_time: last_write_times) {
add_path(last_write_time.first, last_write_time.second.first); add_path(last_write_time.first, last_write_time.second.first);
} }
update_mutex.unlock(); update_mutex.unlock();
DEBUG("end"); JDEBUG("end");
} }
void Directories::select(const boost::filesystem::path &path) { void Directories::select(const boost::filesystem::path &path) {
DEBUG("start"); JDEBUG("start");
if(current_path=="") if(current_path=="")
return; return;
@ -196,7 +196,7 @@ void Directories::select(const boost::filesystem::path &path) {
} }
return false; return false;
}); });
DEBUG("end"); JDEBUG("end");
} }
bool Directories::ignored(std::string path) { bool Directories::ignored(std::string path) {

2
src/files.h

@ -69,6 +69,8 @@ const std::string configjson =
" \"source_spellcheck\": \"\",\n" " \"source_spellcheck\": \"\",\n"
" \"source_spellcheck_clear\": \"\",\n" " \"source_spellcheck_clear\": \"\",\n"
" \"source_spellcheck_next_error\": \"<primary><shift>e\",\n" " \"source_spellcheck_next_error\": \"<primary><shift>e\",\n"
" \"source_indentation_set_buffer_tab\": \"\",\n"
" \"source_indentation_auto_indent_buffer\": \"\",\n"
" \"source_goto_line\": \"<primary>g\",\n" " \"source_goto_line\": \"<primary>g\",\n"
" \"source_center_cursor\": \"<primary>l\",\n" " \"source_center_cursor\": \"<primary>l\",\n"
" \"source_goto_declaration\": \"<primary>d\",\n" " \"source_goto_declaration\": \"<primary>d\",\n"

4
src/juci.cc

@ -8,7 +8,7 @@ void init_logging() {
boost::log::add_common_attributes(); boost::log::add_common_attributes();
boost::log::add_file_log(boost::log::keywords::file_name = Singleton::log_dir() + "juci.log", boost::log::add_file_log(boost::log::keywords::file_name = Singleton::log_dir() + "juci.log",
boost::log::keywords::auto_flush = true); boost::log::keywords::auto_flush = true);
INFO("Logging initalized"); JINFO("Logging initalized");
} }
int app::on_command_line(const Glib::RefPtr<Gio::ApplicationCommandLine> &cmd) { int app::on_command_line(const Glib::RefPtr<Gio::ApplicationCommandLine> &cmd) {
@ -44,7 +44,7 @@ void app::on_activate() {
bool first_directory=true; bool first_directory=true;
for(auto &directory: directories) { for(auto &directory: directories) {
if(first_directory) { if(first_directory) {
window->directories.open(directory); Singleton::directories()->open(directory);
first_directory=false; first_directory=false;
} }
else { else {

14
src/logging.h

@ -15,12 +15,12 @@
#define INFO_VAR(x) BOOST_LOG_TRIVIAL(info) << "** Info: " << __FILE__ << "@" << __func__ << "(" << __LINE__ << "): " << #x << "=<" << x << ">"; #define INFO_VAR(x) BOOST_LOG_TRIVIAL(info) << "** Info: " << __FILE__ << "@" << __func__ << "(" << __LINE__ << "): " << #x << "=<" << x << ">";
#define WARNING_VAR(x) BOOST_LOG_TRIVIAL(warning) << "** Warning: " << __FILE__ << "@" << __func__ << "(" << __LINE__ << "): " << #x << "=<" << x << ">"; #define WARNING_VAR(x) BOOST_LOG_TRIVIAL(warning) << "** Warning: " << __FILE__ << "@" << __func__ << "(" << __LINE__ << "): " << #x << "=<" << x << ">";
#define FATAL_VAR(x) BOOST_LOG_TRIVIAL(fatal) << "** Fatal: " << __FILE__ << "@" << __func__ << "(" << __LINE__ << "): " << #x << "=<" << x << ">"; #define FATAL_VAR(x) BOOST_LOG_TRIVIAL(fatal) << "** Fatal: " << __FILE__ << "@" << __func__ << "(" << __LINE__ << "): " << #x << "=<" << x << ">";
#define ERROR_VAR(x) BOOST_LOG_TRIVIAL(error) << "** Error: " << __FILE__ << "@" << __func__ << "(" << __LINE__ << "): " << #x << "=<" << x << ">"; #define JERROR_VAR(x) BOOST_LOG_TRIVIAL(error) << "** Error: " << __FILE__ << "@" << __func__ << "(" << __LINE__ << "): " << #x << "=<" << x << ">";
#define TRACE(x) BOOST_LOG_TRIVIAL(trace) << "** Trace: " << __FILE__ << "@" << __func__ << "(" << __LINE__ << "): \"" << x << "\""; #define JTRACE(x) BOOST_LOG_TRIVIAL(trace) << "** Trace: " << __FILE__ << "@" << __func__ << "(" << __LINE__ << "): \"" << x << "\"";
#define DEBUG(x) BOOST_LOG_TRIVIAL(debug) << "** Debug: " << __FILE__ << "@" << __func__ << "(" << __LINE__ << "): \"" << x << "\""; #define JDEBUG(x) BOOST_LOG_TRIVIAL(debug) << "** Debug: " << __FILE__ << "@" << __func__ << "(" << __LINE__ << "): \"" << x << "\"";
#define INFO(x) BOOST_LOG_TRIVIAL(info) << "** Info: " << __FILE__ << "@" << __func__ << "(" << __LINE__ << "): \"" << x << "\""; #define JINFO(x) BOOST_LOG_TRIVIAL(info) << "** Info: " << __FILE__ << "@" << __func__ << "(" << __LINE__ << "): \"" << x << "\"";
#define WARNING(x) BOOST_LOG_TRIVIAL(warning) << "** Warning: " << __FILE__ << "@" << __func__ << "(" << __LINE__ << "): \"" << x << "\""; #define JWARNING(x) BOOST_LOG_TRIVIAL(warning) << "** Warning: " << __FILE__ << "@" << __func__ << "(" << __LINE__ << "): \"" << x << "\"";
#define FATAL(x) BOOST_LOG_TRIVIAL(fatal) << "** Fatal: " << __FILE__ << "@" << __func__ << "(" << __LINE__ << "): \"" << x << "\""; #define JFATAL(x) BOOST_LOG_TRIVIAL(fatal) << "** Fatal: " << __FILE__ << "@" << __func__ << "(" << __LINE__ << "): \"" << x << "\"";
#define ERROR(x) BOOST_LOG_TRIVIAL(error) << "** Error: " << __FILE__ << "@" << __func__ << "(" << __LINE__ << "): \"" << x << "\""; #define JERROR(x) BOOST_LOG_TRIVIAL(error) << "** Error: " << __FILE__ << "@" << __func__ << "(" << __LINE__ << "): \"" << x << "\"";
#endif // JUCI_LOGGING_H_ #endif // JUCI_LOGGING_H_

7
src/menu.cc

@ -43,8 +43,6 @@ Menu::Menu() {
" <menuitem action=\"EditPaste\"/>\n" " <menuitem action=\"EditPaste\"/>\n"
" <separator/>\n" " <separator/>\n"
" <menuitem action=\"EditFind\"/>\n" " <menuitem action=\"EditFind\"/>\n"
" <separator/>\n"
" <menuitem action=\"EditSetTab\"/>\n"
" </menu>\n" " </menu>\n"
" <menu action=\"SourceMenu\">\n" " <menu action=\"SourceMenu\">\n"
" <menu action=\"SourceSpellCheck\">\n" " <menu action=\"SourceSpellCheck\">\n"
@ -53,6 +51,11 @@ Menu::Menu() {
" <menuitem action=\"SourceSpellCheckNextError\"/>\n" " <menuitem action=\"SourceSpellCheckNextError\"/>\n"
" </menu>\n" " </menu>\n"
" <separator/>\n" " <separator/>\n"
" <menu action=\"SourceIndentation\">\n"
" <menuitem action=\"SourceIndentationSetBufferTab\"/>\n"
" <menuitem action=\"SourceIndentationAutoIndentBuffer\"/>\n"
" </menu>\n"
" <separator/>\n"
" <menuitem action=\"SourceGotoLine\"/>\n" " <menuitem action=\"SourceGotoLine\"/>\n"
" <menuitem action=\"SourceCenterCursor\"/>\n" " <menuitem action=\"SourceCenterCursor\"/>\n"
" <separator/>\n" " <separator/>\n"

30
src/notebook.cc

@ -27,7 +27,7 @@ namespace sigc {
#endif #endif
} }
Notebook::Notebook(Directories &directories) : Gtk::Notebook(), directories(directories) { Notebook::Notebook() : Gtk::Notebook() {
Gsv::init(); Gsv::init();
} }
@ -52,7 +52,7 @@ Source::View* Notebook::get_current_view() {
} }
void Notebook::open(const boost::filesystem::path &file_path) { void Notebook::open(const boost::filesystem::path &file_path) {
DEBUG("start"); JDEBUG("start");
for(int c=0;c<size();c++) { for(int c=0;c<size();c++) {
if(file_path==get_view(c)->file_path) { if(file_path==get_view(c)->file_path) {
set_current_page(c); set_current_page(c);
@ -70,8 +70,9 @@ void Notebook::open(const boost::filesystem::path &file_path) {
auto language=Source::guess_language(file_path); auto language=Source::guess_language(file_path);
boost::filesystem::path project_path; boost::filesystem::path project_path;
if(directories.cmake && directories.cmake->project_path!="" && file_path.generic_string().substr(0, directories.cmake->project_path.generic_string().size()+1)==directories.cmake->project_path.generic_string()+'/') auto directories=Singleton::directories();
project_path=directories.cmake->project_path; if(directories->cmake && directories->cmake->project_path!="" && file_path.generic_string().substr(0, directories->cmake->project_path.generic_string().size()+1)==directories->cmake->project_path.generic_string()+'/')
project_path=directories->cmake->project_path;
else { else {
project_path=file_path.parent_path(); project_path=file_path.parent_path();
CMake cmake(project_path); CMake cmake(project_path);
@ -134,7 +135,7 @@ void Notebook::open(const boost::filesystem::path &file_path) {
set_tab_label_text(*(get_nth_page(page)), title); set_tab_label_text(*(get_nth_page(page)), title);
}); });
DEBUG("end"); JDEBUG("end");
} }
void Notebook::configure(int view_nr) { void Notebook::configure(int view_nr) {
@ -152,9 +153,9 @@ void Notebook::configure(int view_nr) {
} }
bool Notebook::save(int page, bool reparse_needed) { bool Notebook::save(int page, bool reparse_needed) {
DEBUG("start"); JDEBUG("start");
if(page>=size()) { if(page>=size()) {
DEBUG("end false"); JDEBUG("end false");
return false; return false;
} }
auto view=get_view(page); auto view=get_view(page);
@ -179,8 +180,9 @@ bool Notebook::save(int page, bool reparse_needed) {
//If CMakeLists.txt have been modified: //If CMakeLists.txt have been modified:
boost::filesystem::path project_path; boost::filesystem::path project_path;
if(view->file_path.filename()=="CMakeLists.txt") { if(view->file_path.filename()=="CMakeLists.txt") {
if(directories.cmake && directories.cmake->project_path!="" && view->file_path.generic_string().substr(0, directories.cmake->project_path.generic_string().size()+1)==directories.cmake->project_path.generic_string()+'/' && CMake::create_compile_commands(directories.cmake->project_path)) { auto directories=Singleton::directories();
project_path=directories.cmake->project_path; if(directories->cmake && directories->cmake->project_path!="" && view->file_path.generic_string().substr(0, directories->cmake->project_path.generic_string().size()+1)==directories->cmake->project_path.generic_string()+'/' && CMake::create_compile_commands(directories->cmake->project_path)) {
project_path=directories->cmake->project_path;
} }
else { else {
CMake cmake(view->file_path.parent_path()); CMake cmake(view->file_path.parent_path());
@ -201,12 +203,12 @@ bool Notebook::save(int page, bool reparse_needed) {
} }
} }
} }
DEBUG("end true"); JDEBUG("end true");
return true; return true;
} }
Singleton::terminal()->print("Error: could not save file " +view->file_path.string()+"\n"); Singleton::terminal()->print("Error: could not save file " +view->file_path.string()+"\n");
} }
DEBUG("end false"); JDEBUG("end false");
return false; return false;
} }
@ -217,11 +219,11 @@ bool Notebook::save_current() {
} }
bool Notebook::close_current_page() { bool Notebook::close_current_page() {
DEBUG("start"); JDEBUG("start");
if (get_current_page()!=-1) { if (get_current_page()!=-1) {
if(get_current_view()->get_buffer()->get_modified()){ if(get_current_view()->get_buffer()->get_modified()){
if(!save_modified_dialog()) { if(!save_modified_dialog()) {
DEBUG("end false"); JDEBUG("end false");
return false; return false;
} }
} }
@ -240,7 +242,7 @@ bool Notebook::close_current_page() {
scrolled_windows.erase(scrolled_windows.begin()+index); scrolled_windows.erase(scrolled_windows.begin()+index);
hboxes.erase(hboxes.begin()+index); hboxes.erase(hboxes.begin()+index);
} }
DEBUG("end true"); JDEBUG("end true");
return true; return true;
} }

3
src/notebook.h

@ -12,7 +12,7 @@
class Notebook : public Gtk::Notebook { class Notebook : public Gtk::Notebook {
public: public:
Notebook(Directories &directories); Notebook();
Source::View* get_view(int page); Source::View* get_view(int page);
size_t get_index(int page); size_t get_index(int page);
int size(); int size();
@ -25,7 +25,6 @@ public:
private: private:
bool save_modified_dialog(); bool save_modified_dialog();
Directories &directories;
std::vector<Source::View*> source_views; //Is NOT freed in destructor, this is intended for quick program exit. std::vector<Source::View*> source_views; //Is NOT freed in destructor, this is intended for quick program exit.
std::vector<std::unique_ptr<Gtk::Widget> > source_maps; std::vector<std::unique_ptr<Gtk::Widget> > source_maps;
std::vector<std::unique_ptr<Gtk::ScrolledWindow> > scrolled_windows; std::vector<std::unique_ptr<Gtk::ScrolledWindow> > scrolled_windows;

7
src/singletons.cc

@ -5,12 +5,19 @@ std::unique_ptr<Directories::Config> Singleton::Config::directories_=std::unique
std::unique_ptr<Terminal::Config> Singleton::Config::terminal_=std::unique_ptr<Terminal::Config>(new Terminal::Config()); std::unique_ptr<Terminal::Config> Singleton::Config::terminal_=std::unique_ptr<Terminal::Config>(new Terminal::Config());
std::unique_ptr<Window::Config> Singleton::Config::window_ = std::unique_ptr<Window::Config>(new Window::Config()); std::unique_ptr<Window::Config> Singleton::Config::window_ = std::unique_ptr<Window::Config>(new Window::Config());
std::unique_ptr<Terminal> Singleton::terminal_=std::unique_ptr<Terminal>(); std::unique_ptr<Terminal> Singleton::terminal_=std::unique_ptr<Terminal>();
std::unique_ptr<Directories> Singleton::directories_=std::unique_ptr<Directories>();
Terminal *Singleton::terminal() { Terminal *Singleton::terminal() {
if(!terminal_) if(!terminal_)
terminal_=std::unique_ptr<Terminal>(new Terminal()); terminal_=std::unique_ptr<Terminal>(new Terminal());
return terminal_.get(); return terminal_.get();
} }
Directories *Singleton::directories() {
if(!directories_)
directories_=std::unique_ptr<Directories>(new Directories());
return directories_.get();
}
std::unique_ptr<Gtk::Label> Singleton::status_=std::unique_ptr<Gtk::Label>(); std::unique_ptr<Gtk::Label> Singleton::status_=std::unique_ptr<Gtk::Label>();
Gtk::Label *Singleton::status() { Gtk::Label *Singleton::status() {
if(!status_) if(!status_)

14
src/singletons.h

@ -11,6 +11,12 @@
#include <gtkmm.h> #include <gtkmm.h>
#include <string> #include <string>
#ifdef _WIN32
#define HOME "AppData"
#else
#define HOME "HOME"
#endif
class Singleton { class Singleton {
public: public:
class Config { class Config {
@ -26,16 +32,18 @@ public:
static std::unique_ptr<Directories::Config> directories_; static std::unique_ptr<Directories::Config> directories_;
static std::unique_ptr<Terminal::Config> terminal_; static std::unique_ptr<Terminal::Config> terminal_;
}; };
static std::string config_dir() { return std::string(getenv("HOME")) + "/.juci/config/"; } static std::string config_dir() { return std::string(getenv(HOME)) + "/.juci/config/"; }
static std::string log_dir() { return std::string(getenv("HOME")) + "/.juci/log/"; } static std::string log_dir() { return std::string(getenv(HOME)) + "/.juci/log/"; }
static std::string style_dir() { return std::string(getenv("HOME")) + "/.juci/styles/"; } static std::string style_dir() { return std::string(getenv(HOME)) + "/.juci/styles/"; }
static Terminal *terminal(); static Terminal *terminal();
static Directories *directories();
static Gtk::Label *status(); static Gtk::Label *status();
static Gtk::Label *info(); static Gtk::Label *info();
private: private:
static std::unique_ptr<Terminal> terminal_; static std::unique_ptr<Terminal> terminal_;
static std::unique_ptr<Gtk::Label> status_; static std::unique_ptr<Gtk::Label> status_;
static std::unique_ptr<Gtk::Label> info_; static std::unique_ptr<Gtk::Label> info_;
static std::unique_ptr<Directories> directories_;
}; };
#endif // JUCI_SINGLETONS_H_ #endif // JUCI_SINGLETONS_H_

6
src/source_clang.cc

@ -22,7 +22,7 @@ clang::Index Source::ClangViewParse::clang_index(0, 0);
Source::ClangViewParse::ClangViewParse(const boost::filesystem::path &file_path, const boost::filesystem::path& project_path, Glib::RefPtr<Gsv::Language> language): Source::ClangViewParse::ClangViewParse(const boost::filesystem::path &file_path, const boost::filesystem::path& project_path, Glib::RefPtr<Gsv::Language> language):
Source::View(file_path, project_path, language), parse_error(false) { Source::View(file_path, project_path, language), parse_error(false) {
DEBUG("start"); JDEBUG("start");
auto tag_table=get_buffer()->get_tag_table(); auto tag_table=get_buffer()->get_tag_table();
for (auto &item : Singleton::Config::source()->clang_types) { for (auto &item : Singleton::Config::source()->clang_types) {
@ -72,7 +72,7 @@ Source::View(file_path, project_path, language), parse_error(false) {
diagnostic_tooltips.hide(); diagnostic_tooltips.hide();
}); });
DEBUG("end"); JDEBUG("end");
} }
void Source::ClangViewParse::configure() { void Source::ClangViewParse::configure() {
@ -96,7 +96,7 @@ void Source::ClangViewParse::configure() {
// // if (style->property_line_background_set()) tag->property_line_background() = style->property_line_background(); // // if (style->property_line_background_set()) tag->property_line_background() = style->property_line_background();
// // if (style->property_underline_set()) tag->property_underline() = style->property_underline(); // // if (style->property_underline_set()) tag->property_underline() = style->property_underline();
} else } else
INFO("Style " + item.second + " not found in " + scheme->get_name()); JINFO("Style " + item.second + " not found in " + scheme->get_name());
} }
} }

8
src/terminal.cc

@ -145,7 +145,7 @@ Terminal::Terminal() {
} }
int Terminal::execute(const std::string &command, const boost::filesystem::path &path) { int Terminal::execute(const std::string &command, const boost::filesystem::path &path) {
DEBUG("start"); JDEBUG("start");
int stdin_fd, stdout_fd, stderr_fd; int stdin_fd, stdout_fd, stderr_fd;
auto pid=popen3(command, path.string(), &stdin_fd, &stdout_fd, &stderr_fd); auto pid=popen3(command, path.string(), &stdin_fd, &stdout_fd, &stderr_fd);
@ -183,14 +183,14 @@ int Terminal::execute(const std::string &command, const boost::filesystem::path
close(stdout_fd); close(stdout_fd);
close(stderr_fd); close(stderr_fd);
DEBUG("end"); JDEBUG("end");
return exit_code; return exit_code;
} }
} }
void Terminal::async_execute(const std::string &command, const boost::filesystem::path &path, std::function<void(int exit_code)> callback) { void Terminal::async_execute(const std::string &command, const boost::filesystem::path &path, std::function<void(int exit_code)> callback) {
std::thread async_execute_thread([this, command, path, callback](){ std::thread async_execute_thread([this, command, path, callback](){
DEBUG("start"); JDEBUG("start");
int stdin_fd, stdout_fd, stderr_fd; int stdin_fd, stdout_fd, stderr_fd;
async_executes_mutex.lock(); async_executes_mutex.lock();
stdin_buffer.clear(); stdin_buffer.clear();
@ -245,7 +245,7 @@ void Terminal::async_execute(const std::string &command, const boost::filesystem
if(callback) if(callback)
callback(exit_code); callback(exit_code);
DEBUG("end"); JDEBUG("end");
} }
}); });
async_execute_thread.detach(); async_execute_thread.detach();

281
src/window.cc

@ -4,6 +4,7 @@
#include "sourcefile.h" #include "sourcefile.h"
#include "config.h" #include "config.h"
//#include "api.h" //#include "api.h"
#include "dialogs.h"
#include <iostream> //TODO: remove #include <iostream> //TODO: remove
using namespace std; //TODO: remove using namespace std; //TODO: remove
@ -29,8 +30,8 @@ void Window::generate_keybindings() {
} }
} }
Window::Window() : box(Gtk::ORIENTATION_VERTICAL), notebook(directories), compiling(false) { Window::Window() : box(Gtk::ORIENTATION_VERTICAL), compiling(false) {
DEBUG("start"); JDEBUG("start");
set_title("juCi++"); set_title("juCi++");
set_events(Gdk::POINTER_MOTION_MASK|Gdk::FOCUS_CHANGE_MASK|Gdk::SCROLL_MASK); set_events(Gdk::POINTER_MOTION_MASK|Gdk::FOCUS_CHANGE_MASK|Gdk::SCROLL_MASK);
configure(); configure();
@ -47,7 +48,7 @@ Window::Window() : box(Gtk::ORIENTATION_VERTICAL), notebook(directories), compil
add_accel_group(menu.ui_manager->get_accel_group()); add_accel_group(menu.ui_manager->get_accel_group());
box.pack_start(menu.get_widget(), Gtk::PACK_SHRINK); box.pack_start(menu.get_widget(), Gtk::PACK_SHRINK);
directory_and_notebook_panes.pack1(directories, Gtk::SHRINK); directory_and_notebook_panes.pack1(*Singleton::directories(), Gtk::SHRINK);
notebook_vbox.pack_start(notebook); notebook_vbox.pack_start(notebook);
notebook_vbox.pack_end(entry_box, Gtk::PACK_SHRINK); notebook_vbox.pack_end(entry_box, Gtk::PACK_SHRINK);
directory_and_notebook_panes.pack2(notebook_vbox, Gtk::SHRINK); directory_and_notebook_panes.pack2(notebook_vbox, Gtk::SHRINK);
@ -66,7 +67,7 @@ Window::Window() : box(Gtk::ORIENTATION_VERTICAL), notebook(directories), compil
box.pack_end(vpaned); box.pack_end(vpaned);
show_all_children(); show_all_children();
directories.on_row_activated=[this](const std::string &file) { Singleton::directories()->on_row_activated=[this](const std::string &file) {
notebook.open(file); notebook.open(file);
}; };
@ -122,7 +123,7 @@ Window::Window() : box(Gtk::ORIENTATION_VERTICAL), notebook(directories), compil
if(auto menu_item=dynamic_cast<Gtk::MenuItem*>(menu.ui_manager->get_widget("/MenuBar/SourceMenu/SourceFindDocumentation"))) if(auto menu_item=dynamic_cast<Gtk::MenuItem*>(menu.ui_manager->get_widget("/MenuBar/SourceMenu/SourceFindDocumentation")))
menu_item->set_sensitive((bool)notebook.get_current_view()->get_token_data); menu_item->set_sensitive((bool)notebook.get_current_view()->get_token_data);
directories.select(notebook.get_current_view()->file_path); Singleton::directories()->select(notebook.get_current_view()->file_path);
if(auto source_view=dynamic_cast<Source::ClangView*>(notebook.get_current_view())) { if(auto source_view=dynamic_cast<Source::ClangView*>(notebook.get_current_view())) {
if(source_view->reparse_needed) { if(source_view->reparse_needed) {
@ -154,7 +155,7 @@ Window::Window() : box(Gtk::ORIENTATION_VERTICAL), notebook(directories), compil
about.set_comments("This is an open source IDE with high-end features to make your programming experience juicy"); about.set_comments("This is an open source IDE with high-end features to make your programming experience juicy");
about.set_license_type(Gtk::License::LICENSE_MIT_X11); about.set_license_type(Gtk::License::LICENSE_MIT_X11);
about.set_transient_for(*this); about.set_transient_for(*this);
DEBUG("end"); JDEBUG("end");
} // Window constructor } // Window constructor
void Window::configure() { void Window::configure() {
@ -171,24 +172,93 @@ void Window::create_menu() {
hide(); hide();
}); });
menu.action_group->add(Gtk::Action::create("FileNewFile", "New File"), Gtk::AccelKey(menu.key_map["new_file"]), [this]() { menu.action_group->add(Gtk::Action::create("FileNewFile", "New File"), Gtk::AccelKey(menu.key_map["new_file"]), [this]() {
new_file_dialog(); boost::filesystem::path path = Dialog::new_file();
if(path!="") {
if(boost::filesystem::exists(path)) {
Singleton::terminal()->print("Error: "+path.string()+" already exists.\n");
}
else {
if(juci::filesystem::write(path)) {
if(Singleton::directories()->current_path!="")
Singleton::directories()->update();
notebook.open(path.string());
Singleton::terminal()->print("New file "+path.string()+" created.\n");
}
else
Singleton::terminal()->print("Error: could not create new file "+path.string()+".\n");
}
}
}); });
menu.action_group->add(Gtk::Action::create("FileNewFolder", "New Folder"), Gtk::AccelKey(menu.key_map["new_folder"]), [this]() { menu.action_group->add(Gtk::Action::create("FileNewFolder", "New Folder"), Gtk::AccelKey(menu.key_map["new_folder"]), [this]() {
new_folder_dialog(); auto time_now=std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
boost::filesystem::path path = Dialog::new_folder();
if(path!="" && boost::filesystem::exists(path)) {
if(boost::filesystem::last_write_time(path)>=time_now) {
if(Singleton::directories()->current_path!="")
Singleton::directories()->update();
Singleton::terminal()->print("New folder "+path.string()+" created.\n");
}
else
Singleton::terminal()->print("Error: "+path.string()+" already exists.\n");
}
Singleton::directories()->select(path);
}); });
menu.action_group->add(Gtk::Action::create("FileNewProject", "New Project")); menu.action_group->add(Gtk::Action::create("FileNewProject", "New Project"));
menu.action_group->add(Gtk::Action::create("FileNewProjectCpp", "C++"), [this]() { menu.action_group->add(Gtk::Action::create("FileNewProjectCpp", "C++"), [this]() {
new_cpp_project_dialog(); boost::filesystem::path project_path = Dialog::new_folder();
if(project_path=="")
return;
auto project_name=project_path.filename().string();
for(size_t c=0;c<project_name.size();c++) {
if(project_name[c]==' ')
project_name[c]='_';
}
auto cmakelists_path=project_path;
cmakelists_path+="/CMakeLists.txt";
auto cpp_main_path=project_path;
cpp_main_path+="/main.cpp";
if(boost::filesystem::exists(cmakelists_path)) {
Singleton::terminal()->print("Error: "+cmakelists_path.string()+" already exists.\n");
return;
}
if(boost::filesystem::exists(cpp_main_path)) {
Singleton::terminal()->print("Error: "+cpp_main_path.string()+" already exists.\n");
return;
}
std::string cmakelists="cmake_minimum_required(VERSION 2.8)\n\nproject("+project_name+")\n\nset(CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} -std=c++1y -Wall\")\n\nadd_executable("+project_name+" main.cpp)\n";
std::string cpp_main="#include <iostream>\n\nusing namespace std;\n\nint main() {\n cout << \"Hello World!\" << endl;\n\n return 0;\n}\n";
if(juci::filesystem::write(cmakelists_path, cmakelists) && juci::filesystem::write(cpp_main_path, cpp_main)) {
Singleton::directories()->open(project_path);
notebook.open(cpp_main_path);
Singleton::terminal()->print("C++ project "+project_name+" created.\n");
}
else
Singleton::terminal()->print("Error: Could not create project "+project_path.string()+"\n");
}); });
menu.action_group->add(Gtk::Action::create("FileOpenFile", "Open File"), Gtk::AccelKey(menu.key_map["open_file"]), [this]() { menu.action_group->add(Gtk::Action::create("FileOpenFile", "Open File"), Gtk::AccelKey(menu.key_map["open_file"]), [this]() {
open_file_dialog(); notebook.open(Dialog::select_file());
}); });
menu.action_group->add(Gtk::Action::create("FileOpenFolder", "Open Folder"), Gtk::AccelKey(menu.key_map["open_folder"]), [this]() { menu.action_group->add(Gtk::Action::create("FileOpenFolder", "Open Folder"), Gtk::AccelKey(menu.key_map["open_folder"]), [this]() {
open_folder_dialog(); auto path = Dialog::select_folder();
if (path!="" && boost::filesystem::exists(path))
Singleton::directories()->open(path);
}); });
menu.action_group->add(Gtk::Action::create("FileSaveAs", "Save As"), Gtk::AccelKey(menu.key_map["save_as"]), [this]() { menu.action_group->add(Gtk::Action::create("FileSaveAs", "Save As"), Gtk::AccelKey(menu.key_map["save_as"]), [this]() {
save_file_dialog(); auto path = Dialog::save_file();
}); if(path!="") {
std::ofstream file(path);
if(file) {
file << notebook.get_current_view()->get_buffer()->get_text();
file.close();
if(Singleton::directories()->current_path!="")
Singleton::directories()->update();
notebook.open(path);
Singleton::terminal()->print("File saved to: " + notebook.get_current_view()->file_path.string()+"\n");
}
else
Singleton::terminal()->print("Error saving file\n");
}
});
menu.action_group->add(Gtk::Action::create("Preferences", "Preferences..."), Gtk::AccelKey(menu.key_map["preferences"]), [this]() { menu.action_group->add(Gtk::Action::create("Preferences", "Preferences..."), Gtk::AccelKey(menu.key_map["preferences"]), [this]() {
notebook.open(Singleton::config_dir()+"config.json"); notebook.open(Singleton::config_dir()+"config.json");
}); });
@ -249,9 +319,6 @@ void Window::create_menu() {
} }
} }
}); });
menu.action_group->add(Gtk::Action::create("EditSetTab", "Set Tab in Current Buffer"), Gtk::AccelKey(menu.key_map["edit_set_tab"]), [this]() {
set_tab_entry();
});
menu.action_group->add(Gtk::Action::create("SourceSpellCheck", "Spell Check")); menu.action_group->add(Gtk::Action::create("SourceSpellCheck", "Spell Check"));
menu.action_group->add(Gtk::Action::create("SourceSpellCheckBuffer", "Spell Check Buffer"), Gtk::AccelKey(menu.key_map["source_spellcheck"]), [this]() { menu.action_group->add(Gtk::Action::create("SourceSpellCheckBuffer", "Spell Check Buffer"), Gtk::AccelKey(menu.key_map["source_spellcheck"]), [this]() {
@ -266,6 +333,13 @@ void Window::create_menu() {
if(notebook.get_current_page()!=-1) if(notebook.get_current_page()!=-1)
notebook.get_current_view()->goto_next_spellcheck_error(); notebook.get_current_view()->goto_next_spellcheck_error();
}); });
menu.action_group->add(Gtk::Action::create("SourceIndentation", "Indentation"));
menu.action_group->add(Gtk::Action::create("SourceIndentationSetBufferTab", "Set Current Buffer Tab"), Gtk::AccelKey(menu.key_map["source_indentation_set_buffer_tab"]), [this]() {
set_tab_entry();
});
menu.action_group->add(Gtk::Action::create("SourceIndentationAutoIndentBuffer", "Auto-Indent Current Buffer"), Gtk::AccelKey(menu.key_map["source_indentation_auto_indent_buffer"]), [this]() {
Singleton::terminal()->print("Auto-Indent Current Buffer will soon be implemented.\n");
});
menu.action_group->add(Gtk::Action::create("SourceGotoLine", "Go to Line"), Gtk::AccelKey(menu.key_map["source_goto_line"]), [this]() { menu.action_group->add(Gtk::Action::create("SourceGotoLine", "Go to Line"), Gtk::AccelKey(menu.key_map["source_goto_line"]), [this]() {
goto_line_entry(); goto_line_entry();
}); });
@ -428,8 +502,9 @@ void Window::create_menu() {
run_path=notebook.get_current_view()->file_path.parent_path(); run_path=notebook.get_current_view()->file_path.parent_path();
} }
else else
run_path=directories.current_path; run_path=Singleton::directories()->current_path;
Singleton::terminal()->async_print("Running: "+content+'\n'); Singleton::terminal()->async_print("Running: "+content+'\n');
Singleton::terminal()->async_execute(content, run_path, [this, content](int exit_code){ Singleton::terminal()->async_execute(content, run_path, [this, content](int exit_code){
Singleton::terminal()->async_print(content+" returned: "+std::to_string(exit_code)+'\n'); Singleton::terminal()->async_print(content+" returned: "+std::to_string(exit_code)+'\n');
}); });
@ -528,178 +603,6 @@ void Window::hide() {
Gtk::Window::hide(); Gtk::Window::hide();
} }
void Window::new_file_dialog() {
Gtk::FileChooserDialog dialog("Please create a new file", Gtk::FILE_CHOOSER_ACTION_SAVE);
if(directories.current_path!="")
gtk_file_chooser_set_current_folder((GtkFileChooser*)dialog.gobj(), directories.current_path.string().c_str());
else
gtk_file_chooser_set_current_folder((GtkFileChooser*)dialog.gobj(), boost::filesystem::current_path().string().c_str());
dialog.set_transient_for(*this);
dialog.set_position(Gtk::WindowPosition::WIN_POS_CENTER_ALWAYS);
dialog.add_button("Cancel", Gtk::RESPONSE_CANCEL);
dialog.add_button("Save", Gtk::RESPONSE_OK);
int result = dialog.run();
if(result==Gtk::RESPONSE_OK) {
boost::filesystem::path path = dialog.get_filename();
if(path!="") {
if(boost::filesystem::exists(path)) {
Singleton::terminal()->print("Error: "+path.string()+" already exists.\n");
}
else {
if(juci::filesystem::write(path)) {
if(directories.current_path!="")
directories.update();
notebook.open(path.string());
Singleton::terminal()->print("New file "+path.string()+" created.\n");
}
else
Singleton::terminal()->print("Error: could not create new file "+path.string()+".\n");
}
}
}
}
void Window::new_folder_dialog() {
auto time_now=std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
Gtk::FileChooserDialog dialog("Please create a new folder", Gtk::FILE_CHOOSER_ACTION_CREATE_FOLDER);
if(directories.current_path!="")
gtk_file_chooser_set_current_folder((GtkFileChooser*)dialog.gobj(), directories.current_path.string().c_str());
else
gtk_file_chooser_set_current_folder((GtkFileChooser*)dialog.gobj(), boost::filesystem::current_path().string().c_str());
dialog.set_transient_for(*this);
dialog.set_position(Gtk::WindowPosition::WIN_POS_CENTER_ALWAYS);
dialog.add_button("Cancel", Gtk::RESPONSE_CANCEL);
dialog.add_button("Create", Gtk::RESPONSE_OK);
int result = dialog.run();
if(result==Gtk::RESPONSE_OK) {
boost::filesystem::path path=dialog.get_filename();
if(boost::filesystem::last_write_time(path)>=time_now) {
if(directories.current_path!="")
directories.update();
Singleton::terminal()->print("New folder "+path.string()+" created.\n");
}
else
Singleton::terminal()->print("Error: "+path.string()+" already exists.\n");
directories.select(path);
}
}
void Window::new_cpp_project_dialog() {
Gtk::FileChooserDialog dialog("Please create and/or choose a folder", Gtk::FILE_CHOOSER_ACTION_CREATE_FOLDER);
if(directories.current_path!="")
gtk_file_chooser_set_current_folder((GtkFileChooser*)dialog.gobj(), directories.current_path.string().c_str());
else
gtk_file_chooser_set_current_folder((GtkFileChooser*)dialog.gobj(), boost::filesystem::current_path().string().c_str());
dialog.set_transient_for(*this);
dialog.set_position(Gtk::WindowPosition::WIN_POS_CENTER_ALWAYS);
dialog.add_button("Cancel", Gtk::RESPONSE_CANCEL);
dialog.add_button("Create", Gtk::RESPONSE_OK);
int result = dialog.run();
if(result==Gtk::RESPONSE_OK) {
boost::filesystem::path project_path=dialog.get_filename();
auto project_name=project_path.filename().string();
for(size_t c=0;c<project_name.size();c++) {
if(project_name[c]==' ')
project_name[c]='_';
}
auto cmakelists_path=project_path;
cmakelists_path+="/CMakeLists.txt";
auto cpp_main_path=project_path;
cpp_main_path+="/main.cpp";
if(boost::filesystem::exists(cmakelists_path)) {
Singleton::terminal()->print("Error: "+cmakelists_path.string()+" already exists.\n");
return;
}
if(boost::filesystem::exists(cpp_main_path)) {
Singleton::terminal()->print("Error: "+cpp_main_path.string()+" already exists.\n");
return;
}
auto tab_char=Singleton::Config::source()->default_tab_char;
auto tab_size=Singleton::Config::source()->default_tab_size;
std::string tab;
for(unsigned c=0;c<tab_size;c++)
tab+=tab_char;
std::string cmakelists="cmake_minimum_required(VERSION 2.8)\n\nproject("+project_name+")\n\nset(CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} -std=c++1y -Wall\")\n\nadd_executable("+project_name+" main.cpp)\n";
std::string cpp_main="#include <iostream>\n\nusing namespace std;\n\nint main() {\n"+tab+"cout << \"Hello World!\" << endl;\n\n"+tab+"return 0;\n}\n";
if(juci::filesystem::write(cmakelists_path, cmakelists) && juci::filesystem::write(cpp_main_path, cpp_main)) {
directories.open(project_path);
notebook.open(cpp_main_path);
Singleton::terminal()->print("C++ project "+project_name+" created.\n");
}
else
Singleton::terminal()->print("Error: Could not create project "+project_path.string()+"\n");
}
}
void Window::open_folder_dialog() {
Gtk::FileChooserDialog dialog("Please choose a folder", Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
if(directories.current_path!="")
gtk_file_chooser_set_current_folder((GtkFileChooser*)dialog.gobj(), directories.current_path.string().c_str());
else
gtk_file_chooser_set_current_folder((GtkFileChooser*)dialog.gobj(), boost::filesystem::current_path().string().c_str());
dialog.set_transient_for(*this);
dialog.set_position(Gtk::WindowPosition::WIN_POS_CENTER_ALWAYS);
dialog.add_button("Cancel", Gtk::RESPONSE_CANCEL);
dialog.add_button("Open", Gtk::RESPONSE_OK);
int result = dialog.run();
if(result==Gtk::RESPONSE_OK) {
std::string project_path=dialog.get_filename();
directories.open(project_path);
}
}
void Window::open_file_dialog() {
Gtk::FileChooserDialog dialog("Please choose a file", Gtk::FILE_CHOOSER_ACTION_OPEN);
if(directories.current_path!="")
gtk_file_chooser_set_current_folder((GtkFileChooser*)dialog.gobj(), directories.current_path.string().c_str());
else
gtk_file_chooser_set_current_folder((GtkFileChooser*)dialog.gobj(), boost::filesystem::current_path().string().c_str());
dialog.set_transient_for(*this);
dialog.set_position(Gtk::WindowPosition::WIN_POS_CENTER_ALWAYS);
dialog.add_button("Cancel", Gtk::RESPONSE_CANCEL);
dialog.add_button("Open", Gtk::RESPONSE_OK);
int result = dialog.run();
if(result==Gtk::RESPONSE_OK) {
std::string path = dialog.get_filename();
notebook.open(path);
}
}
void Window::save_file_dialog() {
if(notebook.get_current_page()==-1)
return;
Gtk::FileChooserDialog dialog(*this, "Please choose a file", Gtk::FILE_CHOOSER_ACTION_SAVE);
gtk_file_chooser_set_filename((GtkFileChooser*)dialog.gobj(), notebook.get_current_view()->file_path.string().c_str());
dialog.set_position(Gtk::WindowPosition::WIN_POS_CENTER_ALWAYS);
dialog.add_button("Cancel", Gtk::RESPONSE_CANCEL);
dialog.add_button("Save", Gtk::RESPONSE_OK);
int result = dialog.run();
if(result==Gtk::RESPONSE_OK) {
auto path = dialog.get_filename();
if(path.size()>0) {
std::ofstream file(path);
if(file) {
file << notebook.get_current_view()->get_buffer()->get_text();
file.close();
if(directories.current_path!="")
directories.update();
notebook.open(path);
Singleton::terminal()->print("File saved to: " + notebook.get_current_view()->file_path.string()+"\n");
}
else
Singleton::terminal()->print("Error saving file\n");
}
}
}
void Window::search_and_replace_entry() { void Window::search_and_replace_entry() {
entry_box.clear(); entry_box.clear();
entry_box.labels.emplace_back(); entry_box.labels.emplace_back();

7
src/window.h

@ -11,7 +11,6 @@
class Window : public Gtk::Window { class Window : public Gtk::Window {
public: public:
Window(); Window();
Directories directories;
Notebook notebook; Notebook notebook;
class Config { class Config {
public: public:
@ -42,12 +41,6 @@ private:
void configure(); void configure();
void create_menu(); void create_menu();
void hide(); void hide();
void new_file_dialog();
void new_folder_dialog();
void new_cpp_project_dialog();
void open_folder_dialog();
void open_file_dialog();
void save_file_dialog();
void search_and_replace_entry(); void search_and_replace_entry();
void set_tab_entry(); void set_tab_entry();
void goto_line_entry(); void goto_line_entry();

Loading…
Cancel
Save