Browse Source

Added Project Set Run Arguments

merge-requests/365/head
eidheim 10 years ago
parent
commit
3d74cbba50
  1. 4
      src/files.h
  2. 10
      src/menu.cc
  3. 177
      src/window.cc
  4. 5
      src/window.h

4
src/files.h

@ -2,7 +2,7 @@
#define JUCI_FILES_H_ #define JUCI_FILES_H_
#include <string> #include <string>
#define JUCI_VERSION "1.1.0-1" #define JUCI_VERSION "1.1.0-2"
const std::string configjson = const std::string configjson =
"{\n" "{\n"
@ -92,12 +92,14 @@ const std::string configjson =
" \"source_rename\": \"<primary>r\",\n" " \"source_rename\": \"<primary>r\",\n"
" \"source_goto_next_diagnostic\": \"<primary>e\",\n" " \"source_goto_next_diagnostic\": \"<primary>e\",\n"
" \"source_apply_fix_its\": \"<control>space\",\n" " \"source_apply_fix_its\": \"<control>space\",\n"
" \"project_set_run_arguments\": \"\",\n"
" \"compile_and_run\": \"<primary>Return\",\n" " \"compile_and_run\": \"<primary>Return\",\n"
" \"compile\": \"<primary><shift>Return\",\n" " \"compile\": \"<primary><shift>Return\",\n"
" \"compile_and_run\": \"<primary>Return\",\n" " \"compile_and_run\": \"<primary>Return\",\n"
" \"run_command\": \"<alt>Return\",\n" " \"run_command\": \"<alt>Return\",\n"
" \"kill_last_running\": \"<primary>Escape\",\n" " \"kill_last_running\": \"<primary>Escape\",\n"
" \"force_kill_last_running\": \"<primary><shift>Escape\",\n" " \"force_kill_last_running\": \"<primary><shift>Escape\",\n"
" \"debug_set_run_arguments\": \"\",\n"
" \"debug_start_continue\": \"<primary>y\",\n" " \"debug_start_continue\": \"<primary>y\",\n"
" \"debug_stop\": \"<primary><shift>y\",\n" " \"debug_stop\": \"<primary><shift>y\",\n"
" \"debug_kill\": \"<primary><shift>k\",\n" " \"debug_kill\": \"<primary><shift>k\",\n"

10
src/menu.cc

@ -239,6 +239,11 @@ Menu::Menu() {
" <attribute name='label' translatable='yes'>_Project</attribute>" " <attribute name='label' translatable='yes'>_Project</attribute>"
" <section>" " <section>"
" <item>" " <item>"
" <attribute name='label' translatable='yes'>_Set _Run _Arguments</attribute>"
" <attribute name='action'>app.project_set_run_arguments</attribute>"
+accels["project_set_run_arguments"]+ //For Ubuntu...
" </item>"
" <item>"
" <attribute name='label' translatable='yes'>_Compile _and _Run</attribute>" " <attribute name='label' translatable='yes'>_Compile _and _Run</attribute>"
" <attribute name='action'>app.compile_and_run</attribute>" " <attribute name='action'>app.compile_and_run</attribute>"
+accels["compile_and_run"]+ //For Ubuntu... +accels["compile_and_run"]+ //For Ubuntu...
@ -272,6 +277,11 @@ Menu::Menu() {
" <attribute name='label' translatable='yes'>_Debug</attribute>" " <attribute name='label' translatable='yes'>_Debug</attribute>"
" <section>" " <section>"
" <item>" " <item>"
" <attribute name='label' translatable='yes'>_Set _Run _Arguments</attribute>"
" <attribute name='action'>app.debug_set_run_arguments</attribute>"
+accels["debug_set_run_arguments"]+ //For Ubuntu...
" </item>"
" <item>"
" <attribute name='label' translatable='yes'>_Start/_Continue</attribute>" " <attribute name='label' translatable='yes'>_Start/_Continue</attribute>"
" <attribute name='action'>app.debug_start_continue</attribute>" " <attribute name='action'>app.debug_start_continue</attribute>"
+accels["debug_start_continue"]+ //For Ubuntu... +accels["debug_start_continue"]+ //For Ubuntu...

177
src/window.cc

@ -167,6 +167,17 @@ Window::Window() : compiling(false), debugging(false) {
JDEBUG("end"); JDEBUG("end");
} // Window constructor } // Window constructor
std::unique_ptr<CMake> Window::get_cmake() {
boost::filesystem::path path;
if(notebook.get_current_page()!=-1)
path=notebook.get_current_view()->file_path.parent_path();
else
path=Directories::get().current_path;
if(path.empty())
return nullptr;
return std::unique_ptr<CMake>(new CMake(path));
}
void Window::configure() { void Window::configure() {
Config::get().load(); Config::get().load();
auto style_context = Gtk::StyleContext::create(); auto style_context = Gtk::StyleContext::create();
@ -546,9 +557,19 @@ void Window::set_menu_actions() {
} }
}); });
menu.add_action("compile_and_run", [this]() { menu.add_action("project_set_run_arguments", [this]() {
if(compiling) auto cmake=get_cmake();
if(!cmake)
return; return;
auto project_path=std::make_shared<boost::filesystem::path>(cmake->project_path);
if(project_path->empty())
return;
auto run_arguments_it=project_run_arguments.find(project_path->string());
std::string run_arguments;
if(run_arguments_it!=project_run_arguments.end())
run_arguments=run_arguments_it->second;
if(run_arguments.empty()) {
boost::filesystem::path cmake_path; boost::filesystem::path cmake_path;
if(notebook.get_current_page()!=-1) if(notebook.get_current_page()!=-1)
cmake_path=notebook.get_current_view()->file_path.parent_path(); cmake_path=notebook.get_current_view()->file_path.parent_path();
@ -564,40 +585,84 @@ void Window::set_menu_actions() {
if(executable_path!="") { if(executable_path!="") {
auto project_path=cmake.project_path; auto project_path=cmake.project_path;
auto default_build_path=CMake::get_default_build_path(project_path); auto default_build_path=CMake::get_default_build_path(project_path);
if(default_build_path.empty()) if(!default_build_path.empty()) {
return;
compiling=true;
auto executable_path_string=executable_path.string(); auto executable_path_string=executable_path.string();
size_t pos=executable_path_string.find(project_path.string()); size_t pos=executable_path_string.find(project_path.string());
if(pos!=std::string::npos) { if(pos!=std::string::npos) {
executable_path_string.replace(pos, project_path.string().size(), default_build_path.string()); executable_path_string.replace(pos, project_path.string().size(), default_build_path.string());
executable_path=executable_path_string; executable_path=executable_path_string;
} }
Terminal::get().print("Compiling and running "+executable_path.string()+"\n");
Terminal::get().async_process(Config::get().terminal.make_command, default_build_path, [this, executable_path, default_build_path](int exit_status){
compiling=false;
if(exit_status==EXIT_SUCCESS) {
auto executable_path_spaces_fixed=executable_path.string();
char last_char=0;
for(size_t c=0;c<executable_path_spaces_fixed.size();c++) {
if(last_char!='\\' && executable_path_spaces_fixed[c]==' ') {
executable_path_spaces_fixed.insert(c, "\\");
c++;
} }
last_char=executable_path_spaces_fixed[c]; run_arguments=executable_path.string();
} }
Terminal::get().async_process(executable_path_spaces_fixed, default_build_path, [this, executable_path](int exit_status){
Terminal::get().async_print(executable_path.string()+" returned: "+std::to_string(exit_status)+'\n');
});
} }
entry_box.clear();
entry_box.labels.emplace_back();
auto label_it=entry_box.labels.begin();
label_it->update=[label_it](int state, const std::string& message){
label_it->set_text("testing");
};
label_it->update(0, "");
entry_box.entries.emplace_back(run_arguments, [this, project_path](const std::string& content){
project_run_arguments[project_path->string()]=content;
entry_box.hide();
}, 50);
auto entry_it=entry_box.entries.begin();
entry_it->set_placeholder_text("Project: Set Run Arguments");
entry_box.buttons.emplace_back("Project: set run arguments", [this, entry_it](){
entry_it->activate();
});
entry_box.show();
}); });
menu.add_action("compile_and_run", [this]() {
if(compiling)
return;
auto cmake=get_cmake();
if(!cmake)
return;
auto project_path=cmake->project_path;
if(project_path.empty())
return;
auto default_build_path=CMake::get_default_build_path(project_path);
if(default_build_path.empty())
return;
auto run_arguments_it=project_run_arguments.find(project_path.string());
std::string run_arguments;
if(run_arguments_it!=project_run_arguments.end())
run_arguments=run_arguments_it->second;
std::string command;
if(!run_arguments.empty()) {
command=run_arguments;
} }
else { else {
command=cmake->get_executable(notebook.get_current_page()!=-1?notebook.get_current_view()->file_path:"").string();
if(command.empty()) {
Terminal::get().print("Could not find add_executable in the following paths:\n"); Terminal::get().print("Could not find add_executable in the following paths:\n");
for(auto &path: cmake.paths) for(auto &path: cmake->paths)
Terminal::get().print(" "+path.string()+"\n"); Terminal::get().print(" "+path.string()+"\n");
return;
}
size_t pos=command.find(project_path.string());
if(pos!=std::string::npos)
command.replace(pos, project_path.string().size(), default_build_path.string());
}
compiling=true;
Terminal::get().print("Compiling and running "+command+"\n");
Terminal::get().async_process(Config::get().terminal.make_command, default_build_path, [this, command, default_build_path](int exit_status){
compiling=false;
if(exit_status==EXIT_SUCCESS) {
Terminal::get().async_process(command, default_build_path, [this, command](int exit_status){
Terminal::get().async_print(command+" returned: "+std::to_string(exit_status)+'\n');
});
} }
}); });
});
menu.add_action("compile", [this]() { menu.add_action("compile", [this]() {
if(compiling) if(compiling)
return; return;
@ -659,38 +724,44 @@ void Window::set_menu_actions() {
#ifdef JUCI_ENABLE_DEBUG #ifdef JUCI_ENABLE_DEBUG
menu.add_action("debug_start_continue", [this](){ menu.add_action("debug_start_continue", [this](){
if(debugging) { if(debugging) {
//Continue
if(notebook.get_current_page()!=-1) {
Debug::get().continue_debug(); Debug::get().continue_debug();
}
return; return;
} }
boost::filesystem::path cmake_path;
if(notebook.get_current_page()!=-1) auto cmake=get_cmake();
cmake_path=notebook.get_current_view()->file_path.parent_path(); if(!cmake)
else
cmake_path=Directories::get().current_path;
if(cmake_path.empty())
return; return;
CMake cmake(cmake_path); auto project_path=cmake->project_path;
if(cmake.project_path.empty()) if(project_path.empty())
return; return;
auto executable_path=cmake.get_executable(notebook.get_current_page()!=-1?notebook.get_current_view()->file_path:"");
if(executable_path!="") {
auto project_path=cmake.project_path;
auto debug_build_path=CMake::get_debug_build_path(project_path); auto debug_build_path=CMake::get_debug_build_path(project_path);
if(debug_build_path.empty()) if(debug_build_path.empty())
return; return;
if(!CMake::create_debug_build(project_path)) if(!CMake::create_debug_build(project_path))
return; return;
debugging=true;
auto executable_path_string=executable_path.string(); /*auto run_arguments_it=project_run_arguments.find(project_path.string());
size_t pos=executable_path_string.find(project_path.string()); std::string run_arguments;
if(pos!=std::string::npos) { if(run_arguments_it!=project_run_arguments.end())
executable_path_string.replace(pos, project_path.string().size(), debug_build_path.string()); run_arguments=run_arguments_it->second;*/
executable_path=executable_path_string;
std::string command;
/*if(!run_arguments.empty()) {
command=run_arguments;
}
else {*/
command=cmake->get_executable(notebook.get_current_page()!=-1?notebook.get_current_view()->file_path:"").string();
if(command.empty()) {
Terminal::get().print("Could not find add_executable in the following paths:\n");
for(auto &path: cmake->paths)
Terminal::get().print(" "+path.string()+"\n");
return;
} }
size_t pos=command.find(project_path.string());
if(pos!=std::string::npos)
command.replace(pos, project_path.string().size(), debug_build_path.string());
//}
auto breakpoints=std::make_shared<std::vector<std::pair<boost::filesystem::path, int> > >(); auto breakpoints=std::make_shared<std::vector<std::pair<boost::filesystem::path, int> > >();
for(int c=0;c<notebook.size();c++) { for(int c=0;c<notebook.size();c++) {
@ -703,24 +774,16 @@ void Window::set_menu_actions() {
breakpoints->emplace_back(view->file_path, iter.get_line()+1); breakpoints->emplace_back(view->file_path, iter.get_line()+1);
} }
} }
Terminal::get().print("Compiling and debugging "+executable_path.string()+"\n");
Terminal::get().async_process(Config::get().terminal.make_command, debug_build_path, [this, breakpoints, executable_path, debug_build_path](int exit_status){ debugging=true;
Terminal::get().print("Compiling and debugging "+command+"\n");
Terminal::get().async_process(Config::get().terminal.make_command, debug_build_path, [this, breakpoints, command, debug_build_path](int exit_status){
if(exit_status!=EXIT_SUCCESS) if(exit_status!=EXIT_SUCCESS)
debugging=false; debugging=false;
else { else {
auto executable_path_spaces_fixed=executable_path.string(); Debug::get().start(breakpoints, command, debug_build_path, [this, command](int exit_status){
char last_char=0;
for(size_t c=0;c<executable_path_spaces_fixed.size();c++) {
if(last_char!='\\' && executable_path_spaces_fixed[c]==' ') {
executable_path_spaces_fixed.insert(c, "\\");
c++;
}
last_char=executable_path_spaces_fixed[c];
}
Debug::get().start(breakpoints, executable_path_spaces_fixed, debug_build_path, [this, executable_path](int exit_status){
debugging=false; debugging=false;
Terminal::get().async_print(executable_path.string()+" returned: "+std::to_string(exit_status)+'\n'); Terminal::get().async_print(command+" returned: "+std::to_string(exit_status)+'\n');
}, [this](const std::string &status) { }, [this](const std::string &status) {
debug_status_mutex.lock(); debug_status_mutex.lock();
debug_status=status; debug_status=status;
@ -737,12 +800,6 @@ void Window::set_menu_actions() {
}); });
} }
}); });
}
else {
Terminal::get().print("Could not find add_executable in the following paths:\n");
for(auto &path: cmake.paths)
Terminal::get().print(" "+path.string()+"\n");
}
}); });
menu.add_action("debug_stop", [this]() { menu.add_action("debug_stop", [this]() {
if(debugging) { if(debugging) {

5
src/window.h

@ -4,6 +4,7 @@
#include "gtkmm.h" #include "gtkmm.h"
#include "entrybox.h" #include "entrybox.h"
#include "notebook.h" #include "notebook.h"
#include "cmake.h"
#include <atomic> #include <atomic>
class Window : public Gtk::ApplicationWindow { class Window : public Gtk::ApplicationWindow {
@ -45,6 +46,10 @@ private:
std::mutex debug_status_mutex; std::mutex debug_status_mutex;
Glib::Dispatcher debug_update_status; Glib::Dispatcher debug_update_status;
std::unique_ptr<CMake> get_cmake();
std::unordered_map<std::string, std::string> project_run_arguments;
std::unordered_map<std::string, std::string> debug_run_arguments;
void configure(); void configure();
void set_menu_actions(); void set_menu_actions();
void activate_menu_items(bool activate=true); void activate_menu_items(bool activate=true);

Loading…
Cancel
Save