[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[sc-dev] SF.net SVN: quarks:[2682] Republic/classes/HistoryRepGui.sc



Revision: 2682
          http://sourceforge.net/p/quarks/code/2682
Author:   decampo
Date:     2013-12-30 00:06:32 +0000 (Mon, 30 Dec 2013)
Log Message:
-----------
works with Qt now, many little fixes, copied back to SCClassLibrary. leave it here for compatibility.

Modified Paths:
--------------
    Republic/classes/HistoryRepGui.sc

Modified: Republic/classes/HistoryRepGui.sc
===================================================================
--- Republic/classes/HistoryRepGui.sc	2013-12-29 18:42:23 UTC (rev 2681)
+++ Republic/classes/HistoryRepGui.sc	2013-12-30 00:06:32 UTC (rev 2682)
@@ -1,11 +1,25 @@
-// limit number of lines to show to a maximum?
+/*
+? limit number of lines to show to a maximum ?
 
+// tests
+
+History.start;
+1 + 2;
+3 + 4;
+12 + 14;
+
+h = HistoryRepGui(History.current);
+History.current.lines
+h.postDoc(1);
+h.alignDoc;
+
+*/
 HistoryRepGui : JITGui {
 
 	classvar <>docTitle = "History repeats", <>docHeight=120;
 
-	var <w, <textV;
-	var <startBut, <filtBut, <filTextV, <filtBut, <keyPop, <topBut, listV;
+	var <textV;
+	var <startBut, <filtBut, <filTextV, <keyPop, <topBut, listV;
 	var <doc, <oldDocs, <docFlag = \sameDoc, <>stickMode=0;
 
 	var <filters, <filteredIndices, <filteredShorts, <filtering = false;
@@ -13,11 +27,11 @@
 
 	accepts { |obj| ^obj.isNil or: { obj.isKindOf(History) } }
 
-		// these methods should be overridden in subclasses: 
+		// these methods should be overridden in subclasses:
 	setDefaults { |options|
-		if (parent.isNil) { 
+		if (parent.isNil) {
 			defPos = 10@260
-		} { 
+		} {
 			defPos = skin.margin;
 		};
 		minSize = 300 @ 400;	// calculate later
@@ -29,21 +43,21 @@
 
 		font = Font("Osaka", 9);
 		flow = zone.addFlowLayout(2@2, 1@1);
-		
-		// this should move to JITGui, 
-		// as it is useful for many JITGuis. 
-		if (hasWindow.not) { 
+
+		// this should move to JITGui,
+		// as it is useful for many JITGuis.
+		if (hasWindow.not) {
 			nameView = DragBoth(zone, Rect(0,0, zone.bounds.width - 4, skin.buttonHeight))
 				// .font_(skin.font)
 				.align_(\center)
 				.receiveDragHandler_({ arg obj; this.object = View.currentDrag });
 			listViewHeight = listViewHeight - (skin.buttonHeight + 2);
 		};
-		
+
 		this.name_("History");
-				
+
 		filters = [\all, ""];
-		
+
 		textV = TextView(zone, Rect(0, 0, (zone.bounds.width - 4), 148))
 			.string_("")
 			.enterInterpretsSelection_(false)
@@ -55,14 +69,23 @@
 			})
 			.resize_(2);
 		textV.bounds.postln;
-		
+
 			// to do: disable if history is not current!
-		startBut = Button(zone, Rect(0, 0, 50, 20)) ////
+		startBut = Button(zone, Rect(0, 0, 40, 20)) ////
 			.states_([ ["start"], ["end"]])
 			.canFocus_(false)
-			.action_({ |btn|
+			.action_({ |btn, mod|
+				mod.postln;
 				switch(btn.value,
-					0, { if (object == History.current) { History.end } },
+					0, {
+					if (object == History.current) {
+						if (mod.isAlt) {
+							History.end
+						} {
+							"please alt-click to end history.".postln;
+							btn.value_(1);
+						}
+					} },
 					1, { if (object == History.current) { History.start } }
 				);
 			});
@@ -75,7 +98,7 @@
 				 object.hasMovedOn = true;
 			});
 
-		keyPop = PopUpMenu(zone, Rect(0, 0, 40, 20))
+		keyPop = PopUpMenu(zone, Rect(0, 0, 50, 20))
 			.items_([\all]).value_(0)
 			.action_({ |pop| this.setKeyFilter(pop.items[pop.value]) });
 
@@ -83,9 +106,14 @@
 			.enterInterpretsSelection_(false)
 			.resize_(2)
 			.keyDownAction_({ |txvw, char, mod, uni, keycode|
-				this.setStrFilter(txvw.string);
-				if (this.filtering) { this.filterLines; }
+				defer ({
+					this.setStrFilter(txvw.string);
+					if (this.filtering) {
+						this.updateLines;
+					};
+			}, 0.01)
 			});
+
 		topBut = Button(zone, Rect(0, 0, 32, 20))
 			.states_([["top"], ["keep"]]).value_(0)
 			.resize_(3)
@@ -97,21 +125,22 @@
 			.resize_(3)
 			.canFocus_(false)
 			.action_({ |btn| this.rip(textV.string) });
-		
+
+		// not sure that this still works in Qt as intended
 		Button(zone, Rect(0,0, 16, 20))
 			.states_([["v"], ["^"]])
 			.resize_(3)
-			.action_ { |btn| 
-				var views = w.view.children; 
-				var resizes = [ 
-					[2, 1, 1, 1, 2, 3, 3, 3, 5], 
+			.action_ { |btn|
+				var views = zone.children;
+				var resizes = [
+					[2, 1, 1, 1, 2, 3, 3, 3, 5],
 					[5, 7, 7, 7, 8, 9, 9, 9, 8]
 				][btn.value.asInteger];
-				
-				views.do { |v, i| v.resize_(resizes[i]) };
-			
+
+				views.postln.do { |v, i| v.resize_(resizes[i]) };
+
 			};
-		
+
 		listV = ListView(zone, bounds.copy.insetBy(2).height_(listViewHeight))
 			.font_(font)
 			.items_([])
@@ -140,103 +169,108 @@
 					"execute line from history failed.".postln;
 				};
 			});
-		this.checkUpdate;	
+		this.checkUpdate;
 	}
 
-	getState { 
+	getState {
 		var newState;
 		if (object.isNil) { ^(hasMovedOn: false) };
-		
+
 		newState = (
 			object: object,
-			hasMovedOn: object.hasMovedOn, 
+			hasMovedOn: object.hasMovedOn,
 			isCurrent: object.isCurrent,
-			started: History.started, 
-			
-			filtStr: filTextV.string, 
+			started: History.started,
+
+			filtStr: filTextV.string,
 			numLines: object.lines.size
 		);
 		^newState
 	}
-	
-	resetViews { 
-		[startBut, filtBut, keyPop].do(_.value_(0)); 
+
+	resetViews {
+		[startBut, filtBut, keyPop].do(_.value_(0));
 		textV.string = "";
 		filTextV.string = "";
-		listV.items = [];	
+		listV.items = [];
 	}
 
-		// these three should move to JITGui in general, 
+		// these three should move to JITGui in general,
 		// to simplify the checkUpdate methods
-	updateFunc { |newState, key, func| 
+	updateFunc { |newState, key, func|
 		var val = newState[key];
 		if (val != prevState[key]) { func.value(val) }
 	}
 
-	updateVal { |newState, key, guiThing| 
+	updateVal { |newState, key, guiThing|
 		var val = newState[key];
 		if (val != prevState[key]) { guiThing.value_(val) }
 	}
-	
-	updateBinVal { |newState, key, guiThing| 
+
+	updateBinVal { |newState, key, guiThing|
 		var val = newState[key];
 		if (val != prevState[key]) { guiThing.value_(val.binaryValue) }
 	}
-		
-	checkUpdate { 
+
+	updateLines {
+		var linesToShow, newIndex, selectedLine;
+
+		// remember old selection
+		if (stickMode == 1) {
+			selectedLine = (lastLinesShown ? [])[listV.value];
+		} {
+			// something else here?
+		};
+		linesToShow = if (filtering.not) {
+			object.lineShorts.array
+		} {
+			this.filterLines;
+			filteredShorts;
+		} ? [];
+
+		if (linesToShow != lastLinesShown) {
+			listV.items_(linesToShow);
+			lastLinesShown = linesToShow;
+		};
+
+		newIndex = if (selectedLine.isNil) { 0 }
+		{ linesToShow.indexOf(selectedLine) };
+		listV.value_(newIndex ? 0);
+		// if(stickMode == 0) { listV.action.value(listV) };
+	}
+
+	checkUpdate {
 		var newState = this.getState;
-		var newIndex, selectedLine, linesToShow, keys;
-		
-		if (newState == prevState) { ^this }; 
-		
+		var keys;
+
+		if (newState == prevState) { ^this };
+
 		this.updateFunc(newState, \object, { |obj| zone.enabled_(obj.notNil) });
-		
-		if (newState[\object].isNil) { 
+
+		if (newState[\object].isNil) {
 			this.resetViews;
-			prevState = newState; 
-			^this 
+			prevState = newState;
+			^this
 		};
-		
+
 		this.updateFunc(newState, \isCurrent, { |val| startBut.enabled_(val.binaryValue) });
 		this.updateBinVal(newState, \started, startBut);
 		this.updateBinVal(newState, \filtering, filtBut);
-		
-			 // clumsy, but filTextV has no usable action...
-		if (filTextV.hasFocus and: (newState[\filtStr] != filters[1])) {
-			this.setStrFilter(newState[\filtStr]);
-		};
-		
-			// could be factoerd a bit more
-		if (newState[\hasMovedOn] or: { newState[\numLines] != prevState[\numLines]}) { 
-						
+
+		// // clumsy, but filTextV has no usable action...
+		// if (filTextV.hasFocus and: (newState[\filtStr] != filters[1])) {
+		// 	this.setStrFilter(newState[\filtStr]);
+		// };
+
+			// could be factored a bit more
+		if (newState[\hasMovedOn] or: { newState[\numLines] != prevState[\numLines]}) {
+
 			keys = [\all] ++ object.keys.asArray.sort;
 			keyPop.items_(keys);
 			keyPop.value_(keys.indexOf(filters[0]) ? 0);
-			
-					// remember old selection
-			if (stickMode == 1) {
-				selectedLine = (lastLinesShown ? [])[listV.value];
-			} { 
-					// soemthing else here?
-			};
 
-			linesToShow = if (filtering.not) {
-				object.lineShorts.array.copy
-			} {
-				this.filterLines;
-				filteredShorts;
-			} ? [];
+			this.updateLines;
 
-			if (linesToShow != lastLinesShown) {
-			//	"or updating listview here?".postln;
-				listV.items_(linesToShow);
-				lastLinesShown = linesToShow;
-			};
-			
-			newIndex = if (selectedLine.isNil) { 0 }
-				{ linesToShow.indexOf(selectedLine) };
-			listV.value_(newIndex ? 0);
-			if(stickMode == 0) { listV.action.value(listV) };
 			object.hasMovedOn = false;
 		};
 
@@ -247,8 +281,9 @@
 	setStrFilter { |str| filters.put(1, str); this.filterLines; }
 
 	filtering_ { |flag=true|
-		 filtering = flag;
-		 object.hasMovedOn_(true);
+		filtering = flag;
+		object.hasMovedOn_(true);
+		this.updateLines;
 	}
 	filterOn { this.filtering_(true) }
 	filterOff { this.filtering_(false) }
@@ -258,11 +293,11 @@
 		filteredShorts = object.lineShorts[filteredIndices];
 		defer {
 			keyPop.value_(keyPop.items.indexOf(filters[0] ? 0));
-			filTextV.string_(filters[1]);
+			// filTextV.string_(filters[1]);
 		};
 		if (filtering) { object.hasMovedOn = true; };
 	}
-	
+
 	postInlined { |index|
 		var line;
 		if (object.lines.isNil) { "no history lines yet.".postln; ^this };
@@ -270,20 +305,27 @@
 		if (line.isNil) { "history: no line found!".inform; ^this };
 		textV.string_(line[2]);
 	}
+
 	postDoc { |index|
 		var line;
 		if (object.lines.isNil) { "no history lines yet.".postln; ^this };
 		line = object.lines[index];
 		if (line.isNil) { "history: no line found!".inform; ^this };
-		this.findDoc;
-		doc.string_(line[2]).front;
+		this.setDocStr(line[2]);
+		doc.front;
 		try { this.alignDoc };
-		w.front;
+		// w.front;
 	}
+	setDocStr { |str|
+		this.findDoc;
+		doc.view.children.first.string_(str);
+	}
+
 	alignDoc {
 		var docbounds, winbounds;
+		this.findDoc;
 		docbounds = doc.bounds;
-		winbounds = w.bounds;
+		winbounds = parent.bounds;
 		doc.bounds_(
 			Rect(
 				winbounds.left,
@@ -293,11 +335,11 @@
 			)
 		)
 	}
-	
-	rip { 
-		this.findDoc; doc.view.children.first.string_(textV.string); doc.front;
+
+	rip {
+		this.setDocStr(textV.string); doc.front;
 	}
-	
+
 	findDoc {
 		if (docFlag == \newDoc) { oldDocs = oldDocs.add(doc) };
 		if (docFlag == \newDoc or: doc.isNil or: { Window.allWindows.includes(doc).not }) {
@@ -307,4 +349,4 @@
 		};
 		oldDocs = oldDocs.select {|d| d.notNil and: { d.dataptr.notNil } };
 	}
-}
+}
\ No newline at end of file

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.


_______________________________________________
sc-dev mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: https://listarc.bham.ac.uk/marchives/sc-dev/
search: https://listarc.bham.ac.uk/lists/sc-dev/search/