diff --git a/dialogs/preferencesdialog.cpp b/dialogs/preferencesdialog.cpp index c85724086..8b39fa2b0 100644 --- a/dialogs/preferencesdialog.cpp +++ b/dialogs/preferencesdialog.cpp @@ -31,23 +31,23 @@ KeySequenceEditor::KeySequenceEditor(QWidget* parent, QAction* a) } void KeySequenceEditor::set_action_shortcut() { - action->setShortcut(keySequence()); + action->setShortcut(keySequence()); } void KeySequenceEditor::reset_to_default() { - setKeySequence(action->property("default").toString()); + setKeySequence(action->property("default").toString()); } QString KeySequenceEditor::action_name() { - return action->text().replace("&", ""); + return action->text().replace("&", ""); } QString KeySequenceEditor::export_shortcut() { - QString ks = keySequence().toString(); - if (ks != action->property("default")) { - return action->text().replace("&", "") + "\t" + keySequence().toString(); - } - return 0; + QString ks = keySequence().toString(); + if (ks != action->property("default")) { + return action->text().replace("&", "") + "\t" + keySequence().toString(); + } + return 0; } PreferencesDialog::PreferencesDialog(QWidget *parent) : @@ -69,7 +69,7 @@ void PreferencesDialog::setup_kbd_shortcut_worker(QMenu* menu, QTreeWidgetItem* for (int i=0;iisSeparator()) { + if (!a->isSeparator() && a->property("keyignore").isNull()) { QTreeWidgetItem* item = new QTreeWidgetItem(); item->setText(0, a->text().replace("&", "")); @@ -78,7 +78,7 @@ void PreferencesDialog::setup_kbd_shortcut_worker(QMenu* menu, QTreeWidgetItem* if (a->menu() != NULL) { item->setChildIndicatorPolicy(QTreeWidgetItem::ShowIndicator); setup_kbd_shortcut_worker(a->menu(), item); - } else { + } else { key_shortcut_items.append(item); key_shortcut_actions.append(a); } @@ -129,7 +129,7 @@ void PreferencesDialog::reset_default_shortcut() { QList items = keyboard_tree->selectedItems(); for (int i=0;iselectedItems().at(i); - static_cast(keyboard_tree->itemWidget(item, 1))->reset_to_default(); + static_cast(keyboard_tree->itemWidget(item, 1))->reset_to_default(); } } @@ -170,59 +170,59 @@ bool PreferencesDialog::refine_shortcut_list(const QString &s, QTreeWidgetItem* parent->setHidden(all_children_are_hidden); return all_children_are_hidden; - } - return true; + } + return true; } void PreferencesDialog::load_shortcut_file() { - QString fn = QFileDialog::getOpenFileName(this, "Import Keyboard Shortcuts"); - if (!fn.isEmpty()) { - QFile f(fn); - if (f.exists() && f.open(QFile::ReadOnly)) { - QByteArray ba = f.readAll(); - f.close(); - for (int i=0;iaction_name()); - if (index == 0 || (index > 0 && ba.at(index-1) == '\n')) { - while (index < ba.size() && ba.at(index) != '\t') index++; - QString ks; - index++; - while (index < ba.size() && ba.at(index) != '\n') { - ks.append(ba.at(index)); - index++; - } - dout << "set" << key_shortcut_fields.at(i)->action_name() << "to" << ks; - key_shortcut_fields.at(i)->setKeySequence(ks); - } else { - key_shortcut_fields.at(i)->reset_to_default(); - } - } - } else { - QMessageBox::critical(this, "Error saving shortcuts", "Failed to open file for reading"); - } - } + QString fn = QFileDialog::getOpenFileName(this, "Import Keyboard Shortcuts"); + if (!fn.isEmpty()) { + QFile f(fn); + if (f.exists() && f.open(QFile::ReadOnly)) { + QByteArray ba = f.readAll(); + f.close(); + for (int i=0;iaction_name()); + if (index == 0 || (index > 0 && ba.at(index-1) == '\n')) { + while (index < ba.size() && ba.at(index) != '\t') index++; + QString ks; + index++; + while (index < ba.size() && ba.at(index) != '\n') { + ks.append(ba.at(index)); + index++; + } + dout << "set" << key_shortcut_fields.at(i)->action_name() << "to" << ks; + key_shortcut_fields.at(i)->setKeySequence(ks); + } else { + key_shortcut_fields.at(i)->reset_to_default(); + } + } + } else { + QMessageBox::critical(this, "Error saving shortcuts", "Failed to open file for reading"); + } + } } void PreferencesDialog::save_shortcut_file() { - QString fn = QFileDialog::getSaveFileName(this, "Export Keyboard Shortcuts"); - if (!fn.isEmpty()) { - QFile f(fn); - if (f.open(QFile::WriteOnly)) { - bool start = true; - for (int i=0;iexport_shortcut(); - if (!s.isEmpty()) { - if (!start) f.write("\n"); - f.write(s.toUtf8()); - start = false; - } - } - QMessageBox::information(this, "Export Shortcuts", "Shortcuts exported successfully"); - f.close(); - } else { - QMessageBox::critical(this, "Error saving shortcuts", "Failed to open file for writing"); - } - } + QString fn = QFileDialog::getSaveFileName(this, "Export Keyboard Shortcuts"); + if (!fn.isEmpty()) { + QFile f(fn); + if (f.open(QFile::WriteOnly)) { + bool start = true; + for (int i=0;iexport_shortcut(); + if (!s.isEmpty()) { + if (!start) f.write("\n"); + f.write(s.toUtf8()); + start = false; + } + } + QMessageBox::information(this, "Export Shortcuts", "Shortcuts exported successfully"); + f.close(); + } else { + QMessageBox::critical(this, "Error saving shortcuts", "Failed to open file for writing"); + } + } } void PreferencesDialog::setup_ui() { @@ -313,15 +313,15 @@ void PreferencesDialog::setup_ui() { tree_header->setText(1, "Shortcut"); shortcut_layout->addWidget(keyboard_tree); - QHBoxLayout* reset_shortcut_layout = new QHBoxLayout(); + QHBoxLayout* reset_shortcut_layout = new QHBoxLayout(); - QPushButton* import_shortcut_button = new QPushButton("Import"); - reset_shortcut_layout->addWidget(import_shortcut_button); - connect(import_shortcut_button, SIGNAL(clicked(bool)), this, SLOT(load_shortcut_file())); + QPushButton* import_shortcut_button = new QPushButton("Import"); + reset_shortcut_layout->addWidget(import_shortcut_button); + connect(import_shortcut_button, SIGNAL(clicked(bool)), this, SLOT(load_shortcut_file())); - QPushButton* export_shortcut_button = new QPushButton("Export"); - reset_shortcut_layout->addWidget(export_shortcut_button); - connect(export_shortcut_button, SIGNAL(clicked(bool)), this, SLOT(save_shortcut_file())); + QPushButton* export_shortcut_button = new QPushButton("Export"); + reset_shortcut_layout->addWidget(export_shortcut_button); + connect(export_shortcut_button, SIGNAL(clicked(bool)), this, SLOT(save_shortcut_file())); reset_shortcut_layout->addStretch(); diff --git a/mainwindow.cpp b/mainwindow.cpp index 050b92184..bd94ea924 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -245,85 +245,85 @@ void MainWindow::make_new_menu(QMenu *parent) { void MainWindow::make_inout_menu(QMenu *parent) { parent->addAction("Set In Point", this, SLOT(set_in_point()), QKeySequence("I")); parent->addAction("Set Out Point", this, SLOT(set_out_point()), QKeySequence("O")); - parent->addAction("Clear In/Out Point", this, SLOT(clear_inout()), QKeySequence("G")); + parent->addAction("Clear In/Out Point", this, SLOT(clear_inout()), QKeySequence("G")); } void kbd_shortcut_processor(QByteArray& file, QMenu* menu, bool save, bool first) { - QList actions = menu->actions(); - for (int i=0;imenu() != NULL) { - kbd_shortcut_processor(file, a->menu(), save, first); - } else if (!a->isSeparator()) { - if (save) { - // saving custom shortcuts - if (!a->property("default").isNull()) { - QKeySequence defks(a->property("default").toString()); - if (a->shortcut() != defks) { - // custom shortcut - if (!file.isEmpty()) file.append('\n'); - file.append(a->text().replace("&", "")); - file.append('\t'); - file.append(a->shortcut().toString()); - } - } - } else { - // loading custom shortcuts - if (first) { - // store default shortcut - a->setProperty("default", a->shortcut().toString()); - } else { - // restore default shortcut - a->setShortcut(a->property("default").toString()); - } - QString comp_str = a->text().replace("&", ""); - int shortcut_index = file.indexOf(comp_str); - if (shortcut_index == 0 || (shortcut_index > 0 && file.at(shortcut_index-1) == '\n')) { - shortcut_index += comp_str.size() + 1; - QString shortcut; - while (shortcut_index < file.size() && file.at(shortcut_index) != '\n') { - shortcut.append(file.at(shortcut_index)); - shortcut_index++; - } - QKeySequence ks(shortcut); - if (!ks.isEmpty()) { - a->setShortcut(ks); - } - } - } - } - } + QList actions = menu->actions(); + for (int i=0;imenu() != NULL) { + kbd_shortcut_processor(file, a->menu(), save, first); + } else if (!a->isSeparator()) { + if (save) { + // saving custom shortcuts + if (!a->property("default").isNull()) { + QKeySequence defks(a->property("default").toString()); + if (a->shortcut() != defks) { + // custom shortcut + if (!file.isEmpty()) file.append('\n'); + file.append(a->text().replace("&", "")); + file.append('\t'); + file.append(a->shortcut().toString()); + } + } + } else { + // loading custom shortcuts + if (first) { + // store default shortcut + a->setProperty("default", a->shortcut().toString()); + } else { + // restore default shortcut + a->setShortcut(a->property("default").toString()); + } + QString comp_str = a->text().replace("&", ""); + int shortcut_index = file.indexOf(comp_str); + if (shortcut_index == 0 || (shortcut_index > 0 && file.at(shortcut_index-1) == '\n')) { + shortcut_index += comp_str.size() + 1; + QString shortcut; + while (shortcut_index < file.size() && file.at(shortcut_index) != '\n') { + shortcut.append(file.at(shortcut_index)); + shortcut_index++; + } + QKeySequence ks(shortcut); + if (!ks.isEmpty()) { + a->setShortcut(ks); + } + } + } + } + } } void MainWindow::load_shortcuts(const QString& fn, bool first) { - QByteArray shortcut_bytes; - QFile shortcut_path(fn); - if (shortcut_path.exists() && shortcut_path.open(QFile::ReadOnly)) { - shortcut_bytes = shortcut_path.readAll(); - shortcut_path.close(); - } - QList menus = menuBar()->actions(); - for (int i=0;imenu(); - kbd_shortcut_processor(shortcut_bytes, menu, false, first); - } + QByteArray shortcut_bytes; + QFile shortcut_path(fn); + if (shortcut_path.exists() && shortcut_path.open(QFile::ReadOnly)) { + shortcut_bytes = shortcut_path.readAll(); + shortcut_path.close(); + } + QList menus = menuBar()->actions(); + for (int i=0;imenu(); + kbd_shortcut_processor(shortcut_bytes, menu, false, first); + } } void MainWindow::save_shortcuts(const QString& fn) { - // save main menu actions - QList menus = menuBar()->actions(); - QByteArray shortcut_file; - for (int i=0;imenu(); - kbd_shortcut_processor(shortcut_file, menu, true, false); - } - QFile shortcut_file_io(fn); - if (shortcut_file_io.open(QFile::WriteOnly)) { - shortcut_file_io.write(shortcut_file); - shortcut_file_io.close(); - } else { - dout << "[ERROR] Failed to save shortcut file"; - } + // save main menu actions + QList menus = menuBar()->actions(); + QByteArray shortcut_file; + for (int i=0;imenu(); + kbd_shortcut_processor(shortcut_file, menu, true, false); + } + QFile shortcut_file_io(fn); + if (shortcut_file_io.open(QFile::WriteOnly)) { + shortcut_file_io.write(shortcut_file); + shortcut_file_io.close(); + } else { + dout << "[ERROR] Failed to save shortcut file"; + } } void MainWindow::show_about() { @@ -534,8 +534,13 @@ void MainWindow::setup_menus() { file_menu->addAction("&Open Project", this, SLOT(open_project()), QKeySequence("Ctrl+O")); + clear_open_recent_action = new QAction("Clear Recent List"); + connect(clear_open_recent_action, SIGNAL(triggered()), panel_project, SLOT(clear_recent_projects())); + open_recent = file_menu->addMenu("Open Recent"); + open_recent->addAction(clear_open_recent_action); + file_menu->addAction("&Save Project", this, SLOT(save_project()), QKeySequence("Ctrl+S")); file_menu->addAction("Save Project &As", this, SLOT(save_project_as()), QKeySequence("Ctrl+Shift+S")); @@ -849,7 +854,7 @@ void MainWindow::setup_menus() { help_menu->addAction("&About...", this, SLOT(show_about())); - load_shortcuts(get_config_path() + "/shortcuts", true); + load_shortcuts(get_config_path() + "/shortcuts", true); } void MainWindow::set_bool_action_checked(QAction *a) { @@ -902,7 +907,7 @@ void MainWindow::closeEvent(QCloseEvent *e) { dout << "[ERROR] Failed to save layout"; } - save_shortcuts(config_dir + "/shortcuts"); + save_shortcuts(config_dir + "/shortcuts"); } stop_audio(); @@ -1154,12 +1159,13 @@ void MainWindow::fileMenu_About_To_Be_Shown() { open_recent->setEnabled(true); for (int i=0;iaddAction(recent_projects.at(i)); + action->setProperty("keyignore", true); action->setData(i); connect(action, SIGNAL(triggered()), this, SLOT(load_recent_project())); } open_recent->addSeparator(); - QAction* clear_action = open_recent->addAction("Clear Recent List"); - connect(clear_action, SIGNAL(triggered()), panel_project, SLOT(clear_recent_projects())); + + open_recent->addAction(clear_open_recent_action); } else { open_recent->setEnabled(false); } diff --git a/mainwindow.h b/mainwindow.h index 4b917181e..124b862c5 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -18,10 +18,10 @@ public: void launch_with_project(const QString& s); void make_new_menu(QMenu* parent); - void make_inout_menu(QMenu* parent); + void make_inout_menu(QMenu* parent); - void load_shortcuts(const QString &fn, bool first = false); - void save_shortcuts(const QString &fn); + void load_shortcuts(const QString &fn, bool first = false); + void save_shortcuts(const QString &fn); QString appName; @@ -136,6 +136,7 @@ private: // file menu actions QMenu* open_recent; + QAction* clear_open_recent_action; // view menu actions QAction* track_lines;