Hehe Text Editor: so it begins

July 31, 2008

So, today I will start telling you about a very simple text editor I am making just for the fun of it. The thought appeared to me while I was extremely bored just “stumbling” sites. I thought – “Hey, instead of wasting your time doing nthing why don’t you make a simple text editor and log the whole proccess in your blog?”. And that is basically it. I wrote up some code. The main window and stuff and that was it.

Anyway, some thing I want to achieve during this “session”:

  1. Tabbed documents
  2. Support for large documents
  3. Windows context integration (like Noepad++ does)
  4. Code highlighting
  5. Code folding
  6. Code structure
  7. Autocomplete for functions and variables

And maybe something will be added later. This is a very minimalistic feature list for me right now. Next time I’ll show you what I’ve done so far.

Visual Studio 2005 not showing data sources sometimes…

January 9, 2008

For quite a long time I have been bugged by this bug (;)). I have a solution with several projects in it and some of the projects have data sources. The problem is that sometimes when you switch to another project (e.g. by opening this project’s file in the editor) the data sources are empty. Now, there is a simple trick which can help resolving this problem (restarting VS doesn’t help). Open up the .xsd file from your project tree and rename anything there. Save it. Rename it back and save it again. Now your data sources should be once again visible in the data sources view.

Hope this helps someone.

HOW-TO: Creating a simple UserControl for displaying a FlowDocument

September 12, 2007

Hello. This is my first post about WPF.

This how-to will show you how to create a UserControl in which you can show a FlowDocument by passing a string containing the FlowDocument. It also allows Data Binding.

Lets start.

1. Create a UserControl called FlowDocumentViewer in Expression Blend (you can also do this in Visual Studio if you want) and add a FlowDocumentScrollViewer to LayoutRoot. Name it flowDocument (you can name it like you want, but I will be using this name in this guide). Your structure should be as follows:


2. Now, open the project in Visual Studio and add the following code to your FlowDocumentViewer.xaml.cs:

        public static readonly DependencyProperty ContentFlowDocumentStringProperty = DependencyProperty.Register(
            new FrameworkPropertyMetadata(null,
                new PropertyChangedCallback(DescriptionFlowDocumentUI.OnContentChanged)

        private static void OnContentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
            FlowDocumentViewer control = (FlowDocumentViewer)d;
            control.flowDocument.Document =
                    new MemoryStream(System.Text.UTF8Encoding.Default.GetBytes((string)e.NewValue))

        public string ContentFlowDocumentString
            get { return (string)GetValue(ContentFlowDocumentStringProperty); }
            set { SetValue(ContentFlowDocumentStringProperty, value); }

Lets see what this code does.

a) We added a DependencyProperty called ContentFlowDocumentStringProperty to our class. This DependencyProperty “points” at ContentFlowDocumentString property, as well as it tells, that this property of type string and we registered a callback function (OnContentChanged), which will be triggered when ContentFlowDocumentString is changed. Note that FrameworkPropertyMetadataOptions.AffectsRender piece of code. This tells WPF, that when this property is changed it affects the UI looks, so that WPF knows he has to render something.

b) The OnContentChanged function is called whenever our DependencyProperty is changed. Here we do the actual work of changing the FlowDocument in our control. We get the instance as an argument (DependencyObject d, which we cast to FlowDocumentViewer explicilty) and we create a new FlowDocument from the newly assigned string ((string)e.newValue).

c) Finally we added the actual property – ContentFlowDocumentString. See those GetValue and SetValue? Don’t be surprized, it is how DependencyProperties work. You don’t have a special (private) field in your class for them. WPF does all the work for you.

Well, that is pretty much it.

The usage is simple:

FlowDocumentViewer fdv = new FlowDocumentViewer();
fdv.ContentFlowDocumentString = stringContainingFlowDocumentXAML;

Or if you want to use data binding, it is absolutely similar to casual binding in WPF:

Binding b = new Binding();
b.Source = myBindingSource;
b.Path = new PropertyPath("PathToProperty");
FlowDocumentViewer fdv = new FlowDocumentViewer();
fdv.SetBinding(FlowDocumentViewer.ContentFlowDocumentStringProperty, b);

If you have questions / remarks / etc. feel free to post them. I will try to answer.

Linux Application Developement

May 25, 2007

God! I really love Linux (especially Ubuntu), I really do. But! Please, someone tell me how the hell is anyone supposed to develop GUI apps here? I know, I know. There are tons of development tools. Glade, MonoDevelop, Anjuta etc. But! I tried them. The only friendly tool was MonoDevelop. But really, I created a Gtk# program (project to be exact) and just screamed! Why you ask? Because I tried to crate a button. It created. No problem. Then I thought that it would be nicer if the button had a pretty background image. Know what? IT IS NOT POSSIBLE TO SET A BACKGROUND!!! That sucks big time. I do not need this ugly button with no-good design. Oh, oh. And one more thing. I certainly tried to compile the thing and it DIDN’T work. Because the assembly was not found. Now what the hell is that?.. EVERY dev tool in Linux I saw in NOTHING compared to MSVS (which I use all the time). Nothing I tell you. And don’t try telling me stories about real programmers who can make everything possible. I don’t need the freaking routine! I need a good IDE where I can forget about details. I need normal control out-of-the-box. With options. With yummy features and stuff. Look at .NET! You call Mono a .NET analogue? B-u-l-l-s-h-i-t. Mono is a zillion kilometers away from .NET. Not even a bit close. Well, I know, it’s not version 1.0 at all. But what the point PR-ing it so much? Almost full System.Windows.Forms? Where? Oh, oh, MonoDevelop has a VS2005 project import. Yeah. Sure. It imports. With a detail that nothing works. Edit my GUI code in source view? Do I look like crazy? No way I’m going to do that.

Now, the point is, linux REALLY needs something like MSVS. MonoDevelop is, in my opinion, the closest analog, but it is still far-far away from it. No….. MonoDevelop is even ok, compared to framework.

Oh. One more thing. If you are thinking about writing an angry post about not respecting someone’s work – that’s not right. I think that devs are doing a great job. I really do. I complain about the whole situation. I will never switch to Linux development I guess. I always try to support people doing real things in this world, but in this case I just have to admit – Microsoft is doing a far better job than the Linux world.

Zend Studio 5.5 – Antialiasing the font (tested on Ubuntu 7.04

May 18, 2007

Hi! Today I am very happy to announce that I am now running Ubuntu 7.04!

Now, no long preludes, since this post is about “How the <fluffy bunny> do I get those antialiased fonts to word in Zend Studio?!”. That was the question for me about 5 minutes ago. Well, I really thought that Zend was perfect – usually, if they have this checkbox – it works without tweaking. Now here’s the disappointment part – that Tools -> Preferences -> Desktop -> Use Antialised Fonts didn’t really work. I asked my best friend (his name’s Google) -oh, whyyyy?… Google was silent… he didn’t know. Fortunately, Google remembered that Zend has a forum! Yay! Searched the forum and found the answer.

Here goes:

… in <installdir>/bin, edit ZDE.lax adding the following line at the end


restart ZDE and you should have antialiased fonts… ” (c) pkoebbe

That worked like magic. No problems at all! So, I hope that this helps someone and that my friend Google will soon cache this post.

PS The original post on Zend forums is here.

MySQL Connector/Net 1.0.8 & 5.0.3

February 27, 2007

Ok, so here I am working with MySQL Connector/NET. I have the latest version of it (1.0.8). Everything worked properly in 1.0.7, so I thought that the updated version should work properly too. Well, no, actually. I don’t know what are the devs thinking, but I am outraged.

The problem is that I download a mysql dump file and after that using MySQL Connector update the local database. You think it is easy, right? Well, that’s what I thought in the first place, but turns out that it just doesn’t work.If you know C# & .NET then you know that dumps should be inserted with ExecuteNonQuery() function. Ok, sounds easy, right? Worng, all the time this crappy driver threw an exception saying “Query was empty”. Wtf? I even created a breakpoint and inserted an MessageBox.Show(command.CommandText). The query was there. I spent hours on searching the internet about this bug (or feature?). I found one bug report saying, that carriage returns were causing this and that it was fixed in 1.0.7. Screw that, this bug IS PRESENT in 1.0.8 AND 5.0.3. How do I know? Well, because I replaced all returns with spaces and it worked out perfectly! Now why the fuck I should wark around bugs, that were already fixed?? Oh, oh, and by the way – I can not post a bug report either, because on the mysql bug reporting page it says, that “cannot connect to MySQL”. That is freaking awesome – mysql’s bug reporting tool is not working because their mysql is down! In-fucking-credible!!

So, for all you guys in the same situation – you MUST remove all carriage returns in your queried before doing an ExecuteNonQuery()! Otherwise you WILL get an exception.

And for MySQL Connector/NET devs – do something about it ASAP. And by the way – this bug is also present in MySQL Connector/NET 5.0.3 (not only in 1.0.8).

DMN + Intranet

March 15, 2006

На данный момент классовая библиотека для проекта DMN (мой с братом CMS), включающий в себя Intranet, составляет ~3600 строк кода. Это при том учитывая, что Intranet сделан ещё процентов на 10%.

Это самый большой проект, который я когда-либо писал.