Browse Source

Various smaller fixes and cleanups.

merge-requests/365/head
eidheim 10 years ago
parent
commit
d25c801dd7
  1. 6
      src/CMakeLists.txt
  2. 45
      src/config.cc
  3. 1
      src/config.h
  4. 10
      src/dialogs.cc
  5. 4
      src/files.h
  6. 4
      src/menu.cc

6
src/CMakeLists.txt

@ -16,11 +16,15 @@ if(UNIX) #Checking if compiling on Ubuntu that has a buggy menu system
execute_process(COMMAND ${LSB_RELEASE_BIN} -is
OUTPUT_VARIABLE DISTRIBUTION OUTPUT_STRIP_TRAILING_WHITESPACE)
if((DISTRIBUTION STREQUAL Ubuntu) OR (DISTRIBUTION STREQUAL LinuxMint))
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUBUNTU_BUGGED_MENU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DJUCI_UBUNTU_BUGGED_MENU")
endif()
endif()
endif()
if(MSYS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DJUCI_CMAKE_INSTALL_PREFIX=\\\"${CMAKE_INSTALL_PREFIX}\\\"")
endif()
INCLUDE(FindPkgConfig)
find_package(LibClang REQUIRED)

45
src/config.cc

@ -9,7 +9,24 @@
using namespace std; //TODO: remove
Config::Config() {
init_home_path();
std::vector<std::string> locations = {"JUCI_HOME", "HOME", "AppData"};
char *ptr = nullptr;
for (auto &location : locations) {
ptr=std::getenv(location.c_str());
if (ptr!=nullptr && boost::filesystem::exists(ptr)) {
home /= ptr;
home /= ".juci";
break;
}
}
if(home.empty()) {
std::string searched_envs = "[";
for(auto &location : locations)
searched_envs+=location+", ";
searched_envs.erase(searched_envs.end()-2, searched_envs.end());
searched_envs+="]";
throw std::runtime_error("One of these environment variables needs to point to a writable directory to save configuration: " + searched_envs);
}
}
void Config::load() {
@ -169,29 +186,3 @@ void Config::GenerateDirectoryFilter() {
for ( auto &i : ignore_json )
directories.ignored.emplace_back(i.second.get_value<std::string>());
}
void Config::init_home_path(){
std::vector<std::string> locations = JUCI_ENV_SEARCH_LOCATIONS;
char *ptr = nullptr;
for (auto &env : locations) {
ptr=std::getenv(env.c_str());
if (ptr==nullptr)
continue;
else
if (boost::filesystem::exists(ptr)) {
home /= ptr;
home /= ".juci";
break;
}
}
if(home.empty()) {
std::string searched_envs = "[";
for(auto &env : locations)
searched_envs+=env+", ";
searched_envs.erase(searched_envs.end()-2, searched_envs.end());
searched_envs+="]";
throw std::runtime_error("One of these environment variables needs to point to a writable directory to save configuration: " + searched_envs);
}
return;
}

1
src/config.h

@ -83,7 +83,6 @@ private:
void GenerateSource();
void GenerateDirectoryFilter();
void init_home_path();
boost::property_tree::ptree cfg;
boost::filesystem::path home;
};

10
src/dialogs.cc

@ -26,31 +26,31 @@ std::string open_dialog(const std::string &title,
}
std::string Dialog::open_folder() {
return open_dialog("Please choose a folder",
return open_dialog("Open 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",
return open_dialog("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",
return open_dialog("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::open_file() {
return open_dialog("Please choose a file",
return open_dialog("Open File",
{std::make_pair("Cancel", Gtk::RESPONSE_CANCEL),std::make_pair("Select", Gtk::RESPONSE_OK)},
Gtk::FILE_CHOOSER_ACTION_OPEN);
}
std::string Dialog::save_file_as(const boost::filesystem::path &file_path) {
return open_dialog("Please choose a file",
return open_dialog("Save File As",
{std::make_pair("Cancel", Gtk::RESPONSE_CANCEL),std::make_pair("Save", Gtk::RESPONSE_OK)},
Gtk::FILE_CHOOSER_ACTION_SAVE, file_path.string());
}

4
src/files.h

@ -2,8 +2,6 @@
#define JUCI_VERSION "0.9.4"
#define JUCI_ENV_SEARCH_LOCATIONS {"AppData", "HOME", "JUCI_HOME"}
const std::string configjson =
"{\n"
" \"version\": \""+std::string(JUCI_VERSION)+"\",\n"
@ -100,7 +98,7 @@ const std::string configjson =
" },\n"
" \"project\": {\n"
#ifdef _WIN32
" \"cmake_command\": \"cmake -G\\\"MSYS Makefiles\\\"\",\n"
" \"cmake_command\": \"cmake -G\\\"MSYS Makefiles\\\" -DCMAKE_INSTALL_PREFIX="+JUCI_CMAKE_INSTALL_PREFIX+"\",\n"
#else
" \"cmake_command\": \"cmake\",\n"
#endif

4
src/menu.cc

@ -12,7 +12,7 @@ Menu::Menu() {
void Menu::init() {
auto accels=Singleton::config->menu.keys;
for(auto &accel: accels) {
#ifdef UBUNTU_BUGGED_MENU
#ifdef JUCI_UBUNTU_BUGGED_MENU
size_t pos=0;
std::string second=accel.second;
while((pos=second.find('<', pos))!=std::string::npos) {
@ -69,7 +69,7 @@ void Menu::init() {
+accels["new_file"]+ //For Ubuntu...
" </item>"
" <item>"
" <attribute name='label' translatable='yes'>_New _Directory</attribute>"
" <attribute name='label' translatable='yes'>_New _Folder</attribute>"
" <attribute name='action'>app.new_folder</attribute>"
+accels["new_folder"]+ //For Ubuntu...
" </item>"

Loading…
Cancel
Save