Compare commits

..

5 Commits

  1. 5
      CMakeLists.txt
  2. 1
      src/CMakeLists.txt
  3. 4
      src/config.cpp
  4. 1
      src/config.hpp
  5. 17
      src/dialog.cpp
  6. 6
      src/dialog.hpp
  7. 8
      src/directories.cpp
  8. 39
      src/mutex.cpp
  9. 41
      src/mutex.hpp
  10. 23
      src/notebook.cpp
  11. 4
      src/project.cpp
  12. 2
      src/terminal.cpp
  13. 1
      src/window.cpp

5
CMakeLists.txt

@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.10)
project(juci)
set(JUCI_VERSION "1.8.1")
set(JUCI_VERSION "1.8.1.1")
set(CPACK_PACKAGE_NAME "jucipp")
set(CPACK_PACKAGE_CONTACT "Ole Christian Eidheim <eidheim@gmail.com>")
@ -40,6 +40,9 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options("-Wno-#warnings")
add_compile_options(-Wthread-safety -Wno-deprecated -Wstring-conversion -Wliteral-conversion)
if(APPLE)
add_link_options(-Wl,-no_warn_duplicate_libraries)
endif()
endif()
if(APPLE)

1
src/CMakeLists.txt

@ -14,6 +14,7 @@ set(JUCI_SHARED_FILES
json.cpp
menu.cpp
meson.cpp
mutex.cpp
project_build.cpp
snippets.cpp
source.cpp

4
src/config.cpp

@ -205,6 +205,7 @@ void Config::read(const JSON &cfg) {
terminal.clear_on_compile = terminal_json.boolean("clear_on_compile", JSON::ParseOptions::accept_string);
terminal.clear_on_run_command = terminal_json.boolean("clear_on_run_command", JSON::ParseOptions::accept_string);
terminal.hide_entry_on_run_command = terminal_json.boolean("hide_entry_on_run_command", JSON::ParseOptions::accept_string);
terminal.word_wrap = terminal_json.boolean("word_wrap", JSON::ParseOptions::accept_string);
auto log_json = cfg.object("log");
log.libclang = log_json.boolean("libclang", JSON::ParseOptions::accept_string);
@ -319,7 +320,8 @@ std::string Config::default_config() {
"font": "",
"clear_on_compile": true,
"clear_on_run_command": false,
"hide_entry_on_run_command": true
"hide_entry_on_run_command": true,
"word_wrap": false
},
"project": {
"default_build_path_comment": "Use <project_directory_name> to insert the project top level directory name",

1
src/config.hpp

@ -28,6 +28,7 @@ public:
bool clear_on_compile;
bool clear_on_run_command;
bool hide_entry_on_run_command;
bool word_wrap;
};
class Project {

17
src/dialog.cpp

@ -1,6 +1,7 @@
#include "dialog.hpp"
#include "filesystem.hpp"
#include <cmath>
#include <iostream>
Dialog::Message::Message(const std::string &text, std::function<void()> &&on_cancel, bool show_progress_bar) : Gtk::Window(Gtk::WindowType::WINDOW_POPUP) {
set_transient_for(*Glib::RefPtr<Gtk::Application>::cast_dynamic(Gtk::Application::get_default())->get_active_window());
@ -52,6 +53,15 @@ bool Dialog::Message::on_delete_event(GdkEventAny *event) {
return true;
}
Dialog::MessageDialog::MessageDialog(Gtk::Window &parent, const Glib::ustring &message, bool use_markup, Gtk::MessageType type, Gtk::ButtonsType buttons, bool modal)
: Gtk::MessageDialog(parent, message, use_markup, type, buttons, modal) {}
int Dialog::MessageDialog::run() {
auto response = Gtk::MessageDialog::run();
Glib::RefPtr<Gtk::Application>::cast_dynamic(Gtk::Application::get_default())->get_active_window()->present();
return response;
}
std::string Dialog::gtk_dialog(const boost::filesystem::path &path, const std::string &title,
const std::vector<std::pair<std::string, Gtk::ResponseType>> &buttons,
Gtk::FileChooserAction action) {
@ -95,7 +105,12 @@ std::string Dialog::gtk_dialog(const boost::filesystem::path &path, const std::s
for(auto &button : buttons)
dialog.add_button(button.first, button.second);
return dialog.run() == Gtk::RESPONSE_OK ? dialog.get_filename() : "";
dialog.show_all();
dialog.present();
auto response = dialog.run();
Glib::RefPtr<Gtk::Application>::cast_dynamic(Gtk::Application::get_default())->get_active_window()->present();
return response == Gtk::RESPONSE_OK ? dialog.get_filename() : "";
}
std::string Dialog::open_folder(const boost::filesystem::path &path) {

6
src/dialog.hpp

@ -18,6 +18,12 @@ public:
Gtk::ProgressBar progress_bar;
};
class MessageDialog : public Gtk::MessageDialog {
public:
MessageDialog(Gtk::Window &parent, const Glib::ustring &message, bool use_markup = false, Gtk::MessageType type = Gtk::MESSAGE_INFO, Gtk::ButtonsType buttons = Gtk::BUTTONS_OK, bool modal = false);
int run();
};
private:
static std::string gtk_dialog(const boost::filesystem::path &path, const std::string &title,
const std::vector<std::pair<std::string, Gtk::ResponseType>> &buttons,

8
src/directories.cpp

@ -1,5 +1,6 @@
#include "directories.hpp"
#include "config.hpp"
#include "dialog.hpp"
#include "entrybox.hpp"
#include "filesystem.hpp"
#include "info.hpp"
@ -352,15 +353,16 @@ Directories::Directories() : Gtk::ListViewText(1) {
menu_item_delete.signal_activate().connect([this] {
if(menu_popup_row_path.empty())
return;
Gtk::MessageDialog dialog(*static_cast<Gtk::Window *>(get_toplevel()), "Delete?", false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO);
Dialog::MessageDialog dialog(*static_cast<Gtk::Window *>(get_toplevel()), "Delete?", false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO);
Gtk::Image image;
image.set_from_icon_name("dialog-warning", Gtk::BuiltinIconSize::ICON_SIZE_DIALOG);
dialog.set_image(image);
dialog.set_default_response(Gtk::RESPONSE_NO);
dialog.set_secondary_text("Are you sure you want to delete " + filesystem::get_short_path(menu_popup_row_path).string() + "?");
dialog.show_all();
int result = dialog.run();
if(result == Gtk::RESPONSE_YES) {
dialog.present();
int response = dialog.run();
if(response == Gtk::RESPONSE_YES) {
boost::system::error_code ec;
bool is_directory = boost::filesystem::is_directory(menu_popup_row_path, ec);

39
src/mutex.cpp

@ -0,0 +1,39 @@
#include "mutex.hpp"
#if defined(__clang__) && (!defined(SWIG))
#pragma GCC diagnostic ignored "-Wthread-safety"
#endif
void Mutex::lock() {
mutex.lock();
}
bool Mutex::try_lock() {
return mutex.try_lock();
}
void Mutex::unlock() {
mutex.unlock();
}
const Mutex &Mutex::operator!() const { return *this; }
LockGuard::LockGuard(Mutex &mutex_) : mutex(mutex_) {
mutex.lock();
locked = true;
}
void LockGuard::lock() {
mutex.lock();
locked = true;
}
void LockGuard::unlock() {
mutex.unlock();
locked = false;
}
LockGuard::~LockGuard() {
if(locked)
mutex.unlock();
}

41
src/mutex.hpp

@ -3,8 +3,8 @@
#include <mutex>
// Enable thread safety attributes only with clang. Exclude Apple Clang since it is too old.
#if defined(__clang__) && !defined(SWIG) && !defined(__apple_build_version__)
// Enable thread safety attributes only with clang.
#if defined(__clang__) && (!defined(SWIG))
#define THREAD_ANNOTATION_ATTRIBUTE__(x) __attribute__((x))
#else
#define THREAD_ANNOTATION_ATTRIBUTE__(x) // no-op
@ -72,19 +72,10 @@ class CAPABILITY("mutex") Mutex {
std::mutex mutex;
public:
void lock() ACQUIRE() {
mutex.lock();
}
bool try_lock() TRY_ACQUIRE(true) {
return mutex.try_lock();
}
void unlock() RELEASE() {
mutex.unlock();
}
const Mutex &operator!() const { return *this; }
void lock() ACQUIRE();
bool try_lock() TRY_ACQUIRE(true);
void unlock() RELEASE();
const Mutex &operator!() const;
};
/// Use this class instead of std::lock_guard and std::unique_lock
@ -93,20 +84,8 @@ class SCOPED_CAPABILITY LockGuard {
bool locked;
public:
LockGuard(Mutex &mutex_) ACQUIRE(mutex_) : mutex(mutex_) {
mutex.lock();
locked = true;
}
void lock() ACQUIRE() {
mutex.lock();
locked = true;
}
void unlock() RELEASE() {
mutex.unlock();
locked = false;
}
~LockGuard() RELEASE() {
if(locked)
mutex.unlock();
}
LockGuard(Mutex &mutex_) ACQUIRE(mutex_);
void lock() ACQUIRE();
void unlock() RELEASE();
~LockGuard() RELEASE();
};

23
src/notebook.cpp

@ -238,16 +238,17 @@ bool Notebook::open(const boost::filesystem::path &file_path_, Position position
if(show_dialog) {
show_dialog = false;
// Install rust-analyzer
Gtk::MessageDialog dialog(*static_cast<Gtk::Window *>(get_toplevel()), "Install Rust language server?", false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO);
Dialog::MessageDialog dialog(*static_cast<Gtk::Window *>(get_toplevel()), "Install Rust language server?", false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO);
Gtk::Image image;
image.set_from_icon_name("dialog-question", Gtk::BuiltinIconSize::ICON_SIZE_DIALOG);
dialog.set_image(image);
dialog.set_default_response(Gtk::RESPONSE_YES);
dialog.set_secondary_text("Rust language server not found. Would you like to install rust-analyzer?");
dialog.show_all();
int result = dialog.run();
dialog.present();
int response = dialog.run();
dialog.hide();
if(result == Gtk::RESPONSE_YES) {
if(response == Gtk::RESPONSE_YES) {
bool canceled = false;
Dialog::Message message("Installing rust-analyzer", [&canceled] {
canceled = true;
@ -611,16 +612,17 @@ void Notebook::install_rust() {
static bool show_dialog = true;
if(show_dialog) {
show_dialog = false;
Gtk::MessageDialog dialog(*static_cast<Gtk::Window *>(get_toplevel()), "Install Rust?", false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO);
Dialog::MessageDialog dialog(*static_cast<Gtk::Window *>(get_toplevel()), "Install Rust?", false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO);
Gtk::Image image;
image.set_from_icon_name("dialog-question", Gtk::BuiltinIconSize::ICON_SIZE_DIALOG);
dialog.set_image(image);
dialog.set_default_response(Gtk::RESPONSE_YES);
dialog.set_secondary_text("Rust not found. Would you like to install Rust?");
dialog.show_all();
int result = dialog.run();
dialog.present();
int response = dialog.run();
dialog.hide();
if(result == Gtk::RESPONSE_YES) {
if(response == Gtk::RESPONSE_YES) {
bool canceled = false;
Dialog::Message message("Installing Rust", [&canceled] {
canceled = true;
@ -924,17 +926,18 @@ void Notebook::set_current_view(Source::View *view) {
}
bool Notebook::save_modified_dialog(size_t index) {
Gtk::MessageDialog dialog(*static_cast<Gtk::Window *>(get_toplevel()), "Save file?", false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO);
Dialog::MessageDialog dialog(*static_cast<Gtk::Window *>(get_toplevel()), "Save file?", false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO);
Gtk::Image image;
image.set_from_icon_name("document-save", Gtk::BuiltinIconSize::ICON_SIZE_DIALOG);
dialog.set_image(image);
dialog.set_default_response(Gtk::RESPONSE_YES);
dialog.set_secondary_text("Do you want to save " + filesystem::get_short_path(get_view(index)->file_path).string() + "?");
dialog.show_all();
int result = dialog.run();
if(result == Gtk::RESPONSE_YES)
dialog.present();
int response = dialog.run();
if(response == Gtk::RESPONSE_YES)
return save(index);
else if(result == Gtk::RESPONSE_NO)
else if(response == Gtk::RESPONSE_NO)
return true;
return false;
}

4
src/project.cpp

@ -1,6 +1,7 @@
#include "project.hpp"
#include "commands.hpp"
#include "config.hpp"
#include "dialog.hpp"
#include "directories.hpp"
#include "filesystem.hpp"
#include "menu.hpp"
@ -799,7 +800,7 @@ void Project::Clang::recreate_build() {
bool has_debug_build = !debug_build_path.empty() && boost::filesystem::exists(debug_build_path, ec);
if(has_default_build || has_debug_build) {
Gtk::MessageDialog dialog(*static_cast<Gtk::Window *>(Notebook::get().get_toplevel()), "Recreate Build?", false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO);
Dialog::MessageDialog dialog(*static_cast<Gtk::Window *>(Notebook::get().get_toplevel()), "Recreate Build?", false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO);
Gtk::Image image;
image.set_from_icon_name("dialog-question", Gtk::BuiltinIconSize::ICON_SIZE_DIALOG);
dialog.set_image(image);
@ -814,6 +815,7 @@ void Project::Clang::recreate_build() {
}
dialog.set_secondary_text(message + "?");
dialog.show_all();
dialog.present();
if(dialog.run() != Gtk::RESPONSE_YES)
return;
Usages::Clang::erase_all_caches_for_project(build->project_path, default_build_path);

2
src/terminal.cpp

@ -590,6 +590,8 @@ void Terminal::async_print(std::string message, bool bold) {
}
void Terminal::configure() {
set_wrap_mode(Config::get().terminal.word_wrap ? Gtk::WrapMode::WRAP_WORD_CHAR : Gtk::WrapMode::WRAP_NONE);
link_tag->property_foreground_rgba() = get_style_context()->get_color(Gtk::StateFlags::STATE_FLAG_LINK);
auto normal_color = get_style_context()->get_color(Gtk::StateFlags::STATE_FLAG_NORMAL);

1
src/window.cpp

@ -156,6 +156,7 @@ Window::Window() {
about.signal_response().connect([this](int d) {
about.hide();
present();
});
about.set_logo_icon_name("juci");

Loading…
Cancel
Save