Skip to content

Commit

Permalink
Add option to delete all blocks on workspace.
Browse files Browse the repository at this point in the history
  • Loading branch information
NeilFraser committed Dec 3, 2015
1 parent 97e5e12 commit fa279b9
Show file tree
Hide file tree
Showing 147 changed files with 194 additions and 99 deletions.
63 changes: 32 additions & 31 deletions blockly_compressed.js

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions core/block_svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ Blockly.BlockSvg.prototype.showContextMenu_ = function(e) {
}
// Save the current block in a variable for use in closures.
var block = this;
var options = [];
var menuOptions = [];

if (this.isDeletable() && this.isMovable() && !block.isInFlyout) {
// Option to duplicate this block.
Expand All @@ -561,7 +561,7 @@ Blockly.BlockSvg.prototype.showContextMenu_ = function(e) {
if (this.getDescendants().length > this.workspace.remainingCapacity()) {
duplicateOption.enabled = false;
}
options.push(duplicateOption);
menuOptions.push(duplicateOption);

if (this.isEditable() && !this.collapsed_ &&
this.workspace.options.comments) {
Expand All @@ -578,7 +578,7 @@ Blockly.BlockSvg.prototype.showContextMenu_ = function(e) {
block.setCommentText('');
};
}
options.push(commentOption);
menuOptions.push(commentOption);
}

// Option to make block inline.
Expand All @@ -595,7 +595,7 @@ Blockly.BlockSvg.prototype.showContextMenu_ = function(e) {
inlineOption.callback = function() {
block.setInputsInline(!isInline);
};
options.push(inlineOption);
menuOptions.push(inlineOption);
break;
}
}
Expand All @@ -609,14 +609,14 @@ Blockly.BlockSvg.prototype.showContextMenu_ = function(e) {
expandOption.callback = function() {
block.setCollapsed(false);
};
options.push(expandOption);
menuOptions.push(expandOption);
} else {
var collapseOption = {enabled: true};
collapseOption.text = Blockly.Msg.COLLAPSE_BLOCK;
collapseOption.callback = function() {
block.setCollapsed(true);
};
options.push(collapseOption);
menuOptions.push(collapseOption);
}
}

Expand All @@ -630,7 +630,7 @@ Blockly.BlockSvg.prototype.showContextMenu_ = function(e) {
block.setDisabled(!block.disabled);
}
};
options.push(disableOption);
menuOptions.push(disableOption);
}

// Option to delete this block.
Expand All @@ -649,7 +649,7 @@ Blockly.BlockSvg.prototype.showContextMenu_ = function(e) {
block.dispose(true, true);
}
};
options.push(deleteOption);
menuOptions.push(deleteOption);
}

// Option to get help.
Expand All @@ -659,14 +659,14 @@ Blockly.BlockSvg.prototype.showContextMenu_ = function(e) {
helpOption.callback = function() {
block.showHelp_();
};
options.push(helpOption);
menuOptions.push(helpOption);

// Allow the block to add or modify options.
// Allow the block to add or modify menuOptions.
if (this.customContextMenu && !block.isInFlyout) {
this.customContextMenu(options);
this.customContextMenu(menuOptions);
}

Blockly.ContextMenu.show(e, options, this.RTL);
Blockly.ContextMenu.show(e, menuOptions, this.RTL);
Blockly.ContextMenu.currentBlock = this;
};

Expand Down
45 changes: 43 additions & 2 deletions core/workspace_svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ Blockly.WorkspaceSvg.prototype.showContextMenu_ = function(e) {
menuOptions.push(cleanOption);

// Add a little animation to collapsing and expanding.
var COLLAPSE_DELAY = 10;
var DELAY = 10;
if (this.options.collapse) {
var hasCollapsedBlocks = false;
var hasExpandedBlocks = false;
Expand Down Expand Up @@ -731,7 +731,7 @@ Blockly.WorkspaceSvg.prototype.showContextMenu_ = function(e) {
while (block) {
setTimeout(block.setCollapsed.bind(block, shouldCollapse), ms);
block = block.getNextBlock();
ms += COLLAPSE_DELAY;
ms += DELAY;
}
}
};
Expand All @@ -753,6 +753,47 @@ Blockly.WorkspaceSvg.prototype.showContextMenu_ = function(e) {
menuOptions.push(expandOption);
}

// Option to delete all blocks.
// Count the number of blocks that are deletable.
var deleteList = [];
function addDeletableBlocks(block) {
if (block.isDeletable()) {
deleteList = deleteList.concat(block.getDescendants());
} else {
var children = block.getChildren();
for (var i = 0; i < children.length; i++) {
addDeletableBlocks(children[i]);
}
}
}
for (var i = 0; i < topBlocks.length; i++) {
addDeletableBlocks(topBlocks[i]);
}
var deleteOption = {
text: deleteList.length <= 1 ? Blockly.Msg.DELETE_BLOCK :
Blockly.Msg.DELETE_X_BLOCKS.replace('%1', String(deleteList.length)),
enabled: deleteList.length > 0,
callback: function() {
if (deleteList.length < 2 ||
window.confirm(Blockly.Msg.DELETE_ALL_BLOCKS.replace('%1',
String(deleteList.length)))) {
deleteNext();
}
}
};
function deleteNext() {
var block = deleteList.shift();
if (block) {
if (block.workspace) {
block.dispose(false, true);
setTimeout(deleteNext, DELAY);
} else {
deleteNext();
}
}
}
menuOptions.push(deleteOption);

Blockly.ContextMenu.show(e, menuOptions, this.RTL);
};

Expand Down
2 changes: 1 addition & 1 deletion demos/code/code.js
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ Code.runJS = function() {
Code.discard = function() {
var count = Code.workspace.getAllBlocks().length;
if (count < 2 ||
window.confirm(MSG['discard'].replace('%1', count))) {
window.confirm(Blockly.Msg.DELETE_ALL_BLOCKS.replace('%1', count))) {
Code.workspace.clear();
window.location.hash = '';
}
Expand Down
1 change: 0 additions & 1 deletion demos/code/msg/ar.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ var MSG = {
runTooltip: "شغل البرنامج المعرف بواسطة البلوكات في مساحة العمل.",
badCode: "خطأ في البرنامج:\n %1",
timeout: "تم تجاوز الحد الأقصى لتكرارات التنفيذ .",
discard: "حذف كل بلوكات %1؟",
trashTooltip: "تجاهل كل البلوكات.",
catLogic: "منطق",
catLoops: "الحلقات",
Expand Down
1 change: 0 additions & 1 deletion demos/code/msg/be-tarask.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ var MSG = {
runTooltip: "Запусьціце праграму, вызначаную блёкамі ў працоўнай вобласьці.",
badCode: "Памылка праграмы:\n%1",
timeout: "Перавышана максымальная колькасьць ітэрацыяў.",
discard: "Выдаліць усе блёкі %1?",
trashTooltip: "Выдаліць усе блёкі.",
catLogic: "Лёгіка",
catLoops: "Петлі",
Expand Down
1 change: 0 additions & 1 deletion demos/code/msg/br.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ var MSG = {
runTooltip: "Lañsañ ar programm termenet gant ar bloc'hadoù en takad labour.",
badCode: "Fazi programm :\n%1",
timeout: "Tizhet eo bet an niver brasañ a iteradurioù seveniñ aotreet.",
discard: "Diverkañ an holl vloc'hoù %1 ?",
trashTooltip: "Disteurel an holl vloc'hoù.",
catLogic: "Poell",
catLoops: "Boukloù",
Expand Down
1 change: 0 additions & 1 deletion demos/code/msg/ca.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ var MSG = {
runTooltip: "Executa el programa definit pels blocs de l'àrea de treball.",
badCode: "Error de programa:\n %1",
timeout: "S'ha superat el nombre màxim d'iteracions d'execució.",
discard: "Esborrar els %1 blocs?",
trashTooltip: "Descarta tots els blocs.",
catLogic: "Lògica",
catLoops: "Bucles",
Expand Down
1 change: 0 additions & 1 deletion demos/code/msg/cs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ var MSG = {
runTooltip: "",
badCode: "Chyba programu:\n%1",
timeout: "Maximum execution iterations exceeded.",
discard: "Odstranit všechny bloky %1?",
trashTooltip: "Zahodit všechny bloky.",
catLogic: "Logika",
catLoops: "Smyčky",
Expand Down
1 change: 0 additions & 1 deletion demos/code/msg/da.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ var MSG = {
runTooltip: "Kør programmet, der er defineret af blokkene i arbejdsområdet.",
badCode: "Programfejl:\n%1",
timeout: "Maksimale antal udførelsesgentagelser overskredet.",
discard: "Slet alle %1 blokke?",
trashTooltip: "Kassér alle blokke.",
catLogic: "Logik",
catLoops: "Løkker",
Expand Down
1 change: 0 additions & 1 deletion demos/code/msg/de.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ var MSG = {
runTooltip: "Das Programm ausführen, das von den Bausteinen im Arbeitsbereich definiert ist.",
badCode: "Programmfehler:\n%1",
timeout: "Die maximalen Ausführungswiederholungen wurden überschritten.",
discard: "Alle %1 Bausteine löschen?",
trashTooltip: "Alle Bausteine verwerfen.",
catLogic: "Logik",
catLoops: "Schleifen",
Expand Down
1 change: 0 additions & 1 deletion demos/code/msg/el.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ var MSG = {
runTooltip: "Εκτελεί το πρόγραμμα που ορίζεται από τα μπλοκ στον χώρο εργασίας.",
badCode: "Σφάλμα προγράμματος:\n%1",
timeout: "Υπέρβαση μέγιστου αριθμού επαναλήψεων.",
discard: "Να διαγραφούν και τα %1 μπλοκ?",
trashTooltip: "Απόρριψη όλων των μπλοκ.",
catLogic: "Λογική",
catLoops: "Επαναλήψεις",
Expand Down
1 change: 0 additions & 1 deletion demos/code/msg/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ var MSG = {
runTooltip: "Run the program defined by the blocks in the workspace.",
badCode: "Program error:\n%1",
timeout: "Maximum execution iterations exceeded.",
discard: "Delete all %1 blocks?",
trashTooltip: "Discard all blocks.",
catLogic: "Logic",
catLoops: "Loops",
Expand Down
1 change: 0 additions & 1 deletion demos/code/msg/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ var MSG = {
runTooltip: "Ejecute el programa definido por los bloques en el área de trabajo.",
badCode: "Error del programa:\n%1",
timeout: "Se excedio el máximo de iteraciones ejecutadas permitidas.",
discard: "¿Eliminar todos los bloques %1?",
trashTooltip: "Descartar todos los bloques.",
catLogic: "Lógica",
catLoops: "Secuencias",
Expand Down
1 change: 0 additions & 1 deletion demos/code/msg/fa.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ var MSG = {
runTooltip: "اجرای برنامهٔ تعریف‌شده توسط بلوک‌ها در فضای کار.",
badCode: "خطای برنامه:\n%1",
timeout: "حداکثر تکرارهای اجرا رد شده‌است.",
discard: "حذف همهٔ بلاک‌های %1؟",
trashTooltip: "دورریختن همهٔ بلوک‌ها.",
catLogic: "منطق",
catLoops: "حلقه‌ها",
Expand Down
1 change: 0 additions & 1 deletion demos/code/msg/fr.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ var MSG = {
runTooltip: "Lancer le programme défini par les blocs dans l’espace de travail.",
badCode: "Erreur du programme :\n%1",
timeout: "Nombre maximum d’itérations d’exécution dépassé.",
discard: "Supprimer tous les %1 blocs ?",
trashTooltip: "Jeter tous les blocs.",
catLogic: "Logique",
catLoops: "Boucles",
Expand Down
1 change: 0 additions & 1 deletion demos/code/msg/he.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ var MSG = {
runTooltip: "הרצת התכנית שהוגדרה על ידי קטעי הקוד שבמרחב העבודה.",
badCode: "שגיאה בתכנית: %1",
timeout: "חריגה ממספר פעולות חוזרות אפשריות.",
discard: "האם למחוק את כל %1 קטעי הקוד?",
trashTooltip: "השלך את כל קטעי הקוד.",
catLogic: "לוגיקה",
catLoops: "לולאות",
Expand Down
1 change: 0 additions & 1 deletion demos/code/msg/hrx.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ var MSG = {
runTooltip: "Das Programm ausfüahre, das von den Bausten im Oorweitsbereich definiert ist.",
badCode: "Programmfehler:\n%1",
timeout: "Die maximale Ausführungswiederholunge woore üwerschritt.",
discard: "All %1 Bausten lösche?",
trashTooltip: "All Bausten verwerfe.",
catLogic: "Logik",
catLoops: "Schleife",
Expand Down
1 change: 0 additions & 1 deletion demos/code/msg/hu.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ var MSG = {
runTooltip: "Program futtatása.",
badCode: "Program hiba:\n%1",
timeout: "A program elérte a maximális végrehajtási időt.",
discard: "Az összes %1 blokk törlése?",
trashTooltip: "Összes blokk törlése.",
catLogic: "Logikai műveletek",
catLoops: "Ciklusok",
Expand Down
1 change: 0 additions & 1 deletion demos/code/msg/ia.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ var MSG = {
runTooltip: "Executar le programma definite per le blocos in le spatio de travalio.",
badCode: "Error del programma:\n%1",
timeout: "Le numero de iterationes executate ha excedite le maximo.",
discard: "Deler tote le %1 blocos?",
trashTooltip: "Abandonar tote le blocos.",
catLogic: "Logica",
catLoops: "Buclas",
Expand Down
1 change: 0 additions & 1 deletion demos/code/msg/is.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ var MSG = {
runTooltip: "Keyra forritið sem kubbarnir á vinnusvæðinu mynda.",
badCode: "Villa í forriti:\n%1",
timeout: "Forritið hefur endurtekið sig of oft.",
discard: "Eyða öllum %1 kubbunum?",
trashTooltip: "Fleygja öllum kubbum.",
catLogic: "Rökvísi",
catLoops: "Lykkjur",
Expand Down
1 change: 0 additions & 1 deletion demos/code/msg/it.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ var MSG = {
runTooltip: "Esegui il programma definito dai blocchi nell'area di lavoro.",
badCode: "Errore programma:\n%1",
timeout: "È stato superato il numero massimo consentito di interazioni eseguite.",
discard: "Cancellare tutti i %1 blocchi?",
trashTooltip: "Elimina tutti i blocchi.",
catLogic: "Logica",
catLoops: "Cicli",
Expand Down
1 change: 0 additions & 1 deletion demos/code/msg/ja.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ var MSG = {
runTooltip: "ブロックで作成したプログラムを実行します。",
badCode: "プログラムのエラー:\n%1",
timeout: "命令の実行回数が制限値を超えました。",
discard: "%1 個すべてのブロックを消しますか?",
trashTooltip: "すべてのブロックを消します。",
catLogic: "論理",
catLoops: "繰り返し",
Expand Down
1 change: 0 additions & 1 deletion demos/code/msg/ko.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ var MSG = {
runTooltip: "작업 공간에서 블록으로 정의된 프로그램을 실행합니다.",
badCode: "프로그램 오류:\n%1",
timeout: "최대 실행 반복을 초과했습니다.",
discard: "모든 블록 %1개를 삭제하겠습니까?",
trashTooltip: "모든 블록을 버립니다.",
catLogic: "논리",
catLoops: "반복",
Expand Down
1 change: 0 additions & 1 deletion demos/code/msg/mk.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ var MSG = {
runTooltip: "Пушти го програмот определен од блокчињата во работниот простор.",
badCode: "Грешка во програмот:\n%1",
timeout: "Го надминавте допуштениот број на повторувања во извршувањето.",
discard: "Да ги избришам сите %1 блокчиња?",
trashTooltip: "Отстрани ги сите блокчиња.",
catLogic: "Логика",
catLoops: "Јамки",
Expand Down
3 changes: 1 addition & 2 deletions demos/code/msg/ms.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ var MSG = {
runTooltip: "Jalankan aturcara yang ditetapkan oleh blok-blok di dalam ruang kerja.",
badCode: "Ralat atur cara:\n%1",
timeout: "Takat maksimum lelaran pelaksanaan dicecah.",
discard: "Hapuskan kesemua %1 blok?",
trashTooltip: "Buang semua blok.",
trashTooltip: "Buang semua Blok.",
catLogic: "Logik",
catLoops: "Gelung",
catMath: "Matematik",
Expand Down
1 change: 0 additions & 1 deletion demos/code/msg/nb.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ var MSG = {
runTooltip: "Kjør programmet definert av blokken i arbeidsområdet.",
badCode: "Programfeil:\n%1",
timeout: "Det maksimale antallet utførte looper er oversteget.",
discard: "Slett alle %1 blokker?",
trashTooltip: "Fjern alle blokker",
catLogic: "Logikk",
catLoops: "Looper",
Expand Down
1 change: 0 additions & 1 deletion demos/code/msg/nl.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ var MSG = {
runTooltip: "Voer het programma uit dat met de blokken in de werkruimte is gemaakt.",
badCode: "Programmafout:\n%1",
timeout: "Het maximale aantal iteraties is overschreden.",
discard: "Alle %1 blokken verwijderen?",
trashTooltip: "Alle blokken verwijderen",
catLogic: "Logica",
catLoops: "Lussen",
Expand Down
1 change: 0 additions & 1 deletion demos/code/msg/oc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ var MSG = {
runTooltip: "Aviar lo programa definit pels blòts dins l’espaci de trabalh.",
badCode: "Error del programa :\n%1",
timeout: "Nombre maximum d’iteracions d’execucion depassat.",
discard: "Suprimir totes los %1 blòts ?",
trashTooltip: "Getar totes los blòts.",
catLogic: "Logic",
catLoops: "Boclas",
Expand Down
1 change: 0 additions & 1 deletion demos/code/msg/pl.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ var MSG = {
runTooltip: "Uruchom program zdefinowany przez bloki w obszarze roboczym",
badCode: "Błąd programu:\n%1",
timeout: "Maksymalna liczba iteracji wykonywań przekroczona",
discard: "Usunąć wszystkie %1 bloki?",
trashTooltip: "Odrzuć wszystkie bloki.",
catLogic: "Logika",
catLoops: "Pętle",
Expand Down
1 change: 0 additions & 1 deletion demos/code/msg/pms.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ var MSG = {
runTooltip: "Fé andé ël programa definì dai blòch ant lë spassi ëd travaj.",
badCode: "Eror dël programa:\n%1",
timeout: "Nùmer màssim d'arpetission d'esecussion sorpassà.",
discard: "Scancelé tuti ij %1 blòch?",
trashTooltip: "Scarté tuti ij blòch.",
catLogic: "Lògica",
catLoops: "Liasse",
Expand Down
1 change: 0 additions & 1 deletion demos/code/msg/pt-br.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ var MSG = {
runTooltip: "Execute o programa definido pelos blocos na área de trabalho.",
badCode: "Erro no programa:\n%1",
timeout: "Máximo de iterações de execução excedido.",
discard: "Apagar todos os %1 blocos?",
trashTooltip: "Descartar todos os blocos.",
catLogic: "Lógica",
catLoops: "Laços",
Expand Down
1 change: 0 additions & 1 deletion demos/code/msg/ro.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ var MSG = {
runTooltip: "Execută programul definit de către blocuri în spațiul de lucru.",
badCode: "Eroare de program:\n%1",
timeout: "Numărul maxim de iterații a fost depășit.",
discard: "Ștergi toate cele %1 (de) blocuri?",
trashTooltip: "Șterge toate blocurile.",
catLogic: "Logic",
catLoops: "Bucle",
Expand Down
Loading

0 comments on commit fa279b9

Please sign in to comment.