Browse Source

Added preference option source.format_style_on_save_if_style_file_found

merge-requests/365/head
eidheim 9 years ago
parent
commit
2606bd00a8
  1. 2
      CMakeLists.txt
  2. 1
      src/config.cc
  3. 1
      src/config.h
  4. 2
      src/files.h
  5. 12
      src/source.cc
  6. 2
      src/source.h
  7. 2
      src/window.cc

2
CMakeLists.txt

@ -1,7 +1,7 @@
cmake_minimum_required (VERSION 2.8.8)
project(juci)
set(JUCI_VERSION "1.2.4-1")
set(JUCI_VERSION "1.2.4-2")
set(CPACK_PACKAGE_NAME "jucipp")
set(CPACK_PACKAGE_CONTACT "Ole Christian Eidheim <eidheim@gmail.com>")

1
src/config.cc

@ -172,6 +172,7 @@ void Config::read(const boost::property_tree::ptree &cfg) {
source.cleanup_whitespace_characters=source_json.get<bool>("cleanup_whitespace_characters");
source.show_whitespace_characters=source_json.get<std::string>("show_whitespace_characters");
source.format_style_on_save=source_json.get<bool>("format_style_on_save");
source.format_style_on_save_if_style_file_found=source_json.get<bool>("format_style_on_save_if_style_file_found");
source.smart_brackets=source_json.get<bool>("smart_brackets");
source.smart_inserts=source_json.get<bool>("smart_inserts");
if(source.smart_inserts)

1
src/config.h

@ -73,6 +73,7 @@ public:
std::string show_whitespace_characters;
bool format_style_on_save;
bool format_style_on_save_if_style_file_found;
bool smart_brackets;
bool smart_inserts;

2
src/files.h

@ -46,6 +46,8 @@ R"RAW(
"show_whitespace_characters": "",
"format_style_on_save_comment": "Performs clang-format on save for C/C++ and other curly-bracket languages supported by clang-format",
"format_style_on_save": false,
"format_style_on_save_if_style_file_found_comment": "Format style if format file is found, even if format_style_on_save is false",
"format_style_on_save_if_style_file_found": false,
"smart_brackets_comment": "If smart_inserts is enabled, this option is automatically enabled. When inserting an already closed bracket, the cursor might instead be moved, avoiding the need of arrow keys after autocomplete",
"smart_brackets": true,
"smart_inserts_comment": "When for instance inserting (, () gets inserted. Applies to: (), [], \", '. Also enables pressing ; inside an expression before a final ) to insert ; at the end of line, and deletions of empty insertions",

12
src/source.cc

@ -167,7 +167,7 @@ Source::View::View(const boost::filesystem::path &file_path, Glib::RefPtr<Gsv::L
language->get_id()=="go" || language->get_id()=="scala" || language->get_id()=="opencl")) {
is_bracket_language=true;
format_style=[this]() {
format_style=[this](bool continue_without_style_file) {
auto command=Config::get().terminal.clang_format_command+" -output-replacements-xml -assume-filename="+filesystem::escape_argument(this->file_path.string());
if(get_buffer()->get_has_selection()) {
@ -191,6 +191,8 @@ Source::View::View(const boost::filesystem::path &file_path, Glib::RefPtr<Gsv::L
if(use_style_file)
command+=" -style=file";
else {
if(!continue_without_style_file)
return;
unsigned indent_width;
std::string tab_style;
if(tab_char=='\t') {
@ -499,8 +501,12 @@ bool Source::View::save(const std::vector<Source::View*> &views) {
if(Config::get().source.cleanup_whitespace_characters)
cleanup_whitespace_characters();
if(Config::get().source.format_style_on_save && format_style)
format_style();
if(format_style) {
if(Config::get().source.format_style_on_save)
format_style(true);
else if(Config::get().source.format_style_on_save_if_style_file_found)
format_style(false);
}
if(filesystem::write(file_path, get_buffer())) {
boost::system::error_code ec;

2
src/source.h

@ -66,7 +66,7 @@ namespace Source {
Glib::RefPtr<Gsv::Language> language;
std::function<void()> non_interactive_completion;
std::function<void()> format_style;
std::function<void(bool)> format_style;
std::function<Offset()> get_declaration_location;
std::function<std::vector<Offset>(const std::vector<Source::View*> &views)> get_implementation_locations;
std::function<std::vector<Offset>(const std::vector<Source::View*> &views)> get_declaration_or_implementation_locations;

2
src/window.cc

@ -531,7 +531,7 @@ void Window::set_menu_actions() {
menu.add_action("source_indentation_auto_indent_buffer", [this]() {
auto view=Notebook::get().get_current_view();
if(view && view->format_style)
view->format_style();
view->format_style(true);
});
menu.add_action("source_goto_line", [this]() {

Loading…
Cancel
Save