Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

less coupling between controller and windows in example pokedit

  • Loading branch information...
commit 424f9ff2eb4c4dd6aefa503db4b61921faaed27c 1 parent 1e22980
NotFound authored
Showing with 26 additions and 12 deletions.
  1. +26 −12 examples/pokedit.winxed
38 examples/pokedit.winxed
View
@@ -400,8 +400,8 @@ class PokeditWindow : TopLevelWindow
self.SetWMProtocols( [ WM_DELETE_WINDOW_s, WM_TAKE_FOCUS_s ] );
- self.OnDestroy += eventhandler(self, "ondestroy");
self.OnConfigure += eventhandler(self, "onconfigure");
+ self.OnMap += eventhandler(self, "onmap");
self.OnClientMessage += eventhandler(self, "onclientmessage");
var menubar = new MenuBar(display, menufont);
@@ -420,10 +420,6 @@ class PokeditWindow : TopLevelWindow
menubarw.Map();
//textwindow.Map();
}
- function ondestroy(event)
- {
- self.controller.pokeditclosed(self);
- }
function onconfigure(event)
{
int width = event.width();
@@ -436,6 +432,11 @@ class PokeditWindow : TopLevelWindow
self.width = width;
self.height = height;
}
+ function onmap(event)
+ {
+ if (self.textwindow != null)
+ self.textwindow.Map();
+ }
function onclientmessage(event)
{
string type = self.GetAtomName(event.message_type());
@@ -489,15 +490,16 @@ class PokeditWindow : TopLevelWindow
self.menubarw = null;
menubarw.Destroy();
}
+ // If the text window is still here, destroy it.
+ // Its OnDentroy handler will call this method again.
+ // In the following call, destroy self.
var textwindow = self.textwindow;
if (textwindow != null) {
self.textwindow = null;
self.controller.pushaction(method_fun(textwindow, "close"));
}
- else {
- cry("destroy");
+ else
self.Destroy();
- }
}
}
@@ -509,6 +511,19 @@ class PokeditController : Controller
{
self.Controller();
}
+ function pokeditnew()
+ {
+ var pokedit = new PokeditWindow(self);
+ pokedit.OnDestroy += function (event) { self.pokeditclosed(pokedit); };
+ pokedit.Map();
+ }
+ function pokeditopen(string filename)
+ {
+ var pokedit = new PokeditWindow(self);
+ pokedit.openfile(filename);
+ pokedit.OnDestroy += function (event) { self.pokeditclosed(pokedit); };
+ pokedit.Map();
+ }
function pokeditclosed(window)
{
self.pushaction(method_fun(self, "Quit"));
@@ -520,11 +535,10 @@ class PokeditController : Controller
function main [main] (args)
{
var controller = new PokeditController();
- var pokedit = new PokeditWindow(controller);
if (elements(args) > 1)
- pokedit.openfile(args[1]);
- pokedit.textwindow.Map();
- pokedit.Map();
+ controller.pokeditopen(args[1]);
+ else
+ controller.pokeditnew();
controller.MainLoop();
controller.Close();
}
Please sign in to comment.
Something went wrong with that request. Please try again.