SharpDevelop Community

Get your problems solved!
Welcome to SharpDevelop Community Sign in | Join | Help
in Search

Laputa

This is a mirror of http://laputa.sharpdevelop.net/, the core team's central news blog.

Oktober 2007 - Posts

  • Help Wanted: WPF Designer Tasks

    Daniel is currently working on areas such as project subsystem or code completion (aside from fixing bugs). Therefore, work on the WPF designer is stalled. But Daniel put together a list of tasks (hard, medium & easy) that you could be helping us with. So if you are interested in helping, and want to be part of writing an open source WPF designer, please do get in touch with me at christophw at icsharcode.net!

    WPF Designer mini tasks

    Here are some jobs to do on the WPF Designer broken into small parts.

    Apart from this list, there are also big jobs to do: Data Binding support, support using Styles, support defining resources.

    Components to be used by multiple designer parts

    Create “Choose Class” dialog

    The data binding UI will need a dialog that allows choosing a class from the referenced assemblies. This will be implemented in WpfDesigner.AddIn and made available to WpfDesign.Designer through a service. The referenced assemblies should be inspected using ICSharpCode.SharpDevelop.Dom

    This will be used by the “Content” property editor and by the data binding UI.

    Support ‘Virtual Design Root Element’

    This means that instead of displaying the designed component, the designer is able to display another component as if it was the root component. The designer should provide a “Back” button on the design surface to allow the user to go back to the real root component.

    This feature is required for designing elements that cannot be designed directly on the main design surface, e.g. Tooltips

    Write menu designer

    Priority: High

    The menu designer might be a dialog box that allows editing the menu in a tree view; or it might be an in-place menu designer like the Windows.Forms designer.

    Property editing support

    Here I’m listing properties that could need improved editing support.

    When implementing property editors, take care that the editor should also work when multiple components with different property values are selected, so you always need a way to represent the ‘ambiguous’ value.

    Properties of type Brush (e.g. Control.Background / Control.BorderBrush)

    Priority: High

    Change ICSharpCode.WpfDesign.Designer.Controls.TypeEditors.BrushEditor to include a little drop down button, the drop down should allow to choose the brush type (SolidColorBrush, etc., we don't need to support all of them at the beginning) and allow the user to edit the brush according to the chosen type.

    Properties of type BitmapEffect / BitmapEffectInput (e.g. UIElement.BitmapEffect / UIElement.BitmapEffectInput)

    Priority: Low

    Implement a TypeEditor (similar to BrushEditor) for the types BitmapEffect and BitmapEffectInput. Could be as simple as a combo box with the most commonly used effects.

    Properties of type ICommand (e.g. ButtonBase.Command)

    Priority: Medium

    There should be a way to choose the command to use from some kind of list.

    ContentControl.Content

    Priority: High

    ICSharpCode.WpfDesign.Designer.Controls.TypeEditors.ContentEditor
    The “C” button should be made a drop down button (like the one used for the Brush editor), it should present “null”, “string”, and menu items for creating commonly used child configurations (e.g. StackPanel with Image and Text when the parent is a button), and “choose class” to create arbitrary objects. This depends on “Create Choose Class Dialog”.

    Properties of type ContextMenu (e.g. FrameworkElement.ContextMenu)

    Priority: Medium

    Provide a way to create and edit a context menu inside the designer.

    Properties of type InputScope

    Priority: Low

    Research what an InputScope is and if/how we should allow the user to edit it.

    Properties of type Transform

    Priority: Low

    Similar to the BrushEditor, provide a drop down to choose from the different available transforms and allow editing the transform properties.

    FrameworkElement.ToolTip

    Priority: Medium (setting string tool tips), Low (designing complex tool tips)

    Should be editable similar to ContentControl.Content, but has to allow the user to design complex tooltips. Depends on “Support ‘Virtual Design Root Element’”

    Properties of type FontStretch / FontStyle / FontWeight

    Priority: Low

    Provide a drop down with the available settings

    Properties of type FontFamily

    Priority: Low

    Use a dialog to allow the user to choose the font to use.

    Properties of type Nullable<bool> (e.g. ToggleButton.IsChecked)

    Priority: Low

    ItemsControl.ItemsSource

    Priority: Low

    There are two main usage scenarios: this property is specified using data binding (this doesn’t need to be handled by the type editor), or there are some hard coded values.

    Write a type editor to support entering string values.

    Label.Target

    Priority: Low

    Label.Target is set to the control described by the label (the control getting focus when Alt+Access Key is pressed). This is done using data binding, but choosing the target from the data binding dialog is too tedious – drag’n’drop of a crosshair on the target control would be much easier. Depends on data binding support.

    Properties of type ImageSource (e.g. Image.Source)

    Priority: High

    Allow choosing a “Resource” element already part of the project, or choose a file and it will get added to the project. This TypeEditor would be implemented in WpfDesign.AddIn and not WpfDesign.Designer because it needs access to the project in SharpDevelop

    Properties of type ViewBase (e.g. ListView.View)

    Priority: Low

    Provide a drop down with the most commonly used views.

    Posted Okt 24 2007, 08:01 PM by Laputa
    Filed under:
  • IViewContent refactoring explained (SD2-1234)

    SD2-1234, titled "Create common way to handle in-memory representations of files that have multiple views" is the issue tracker entry behind a major refactoring of the IViewContent interface.

    The major new feature introduced is that now it is possible to open a file in multiple view contents at the same file (using "Open with"). Both IViewContent instances will edit the same underlying file - when you switch between them, one view content will display the unsaved changes of the other; pressing Ctrl+S in one of them will save both.

    Now how is this possible? There must be some data structure shared by both view contents. Since the view contents might not know anything about each other (both could be independently developed AddIns), this data structure must work on the lowest possible level: bytes. It's simply a MemoryStream.

    Of course the view contents cannot serialize their content on every change; so a view content may have local changes in a higher-level data structure (text editor buffer, list of entries in resource file, etc). To ensure that such changes are correctly synchronized between view contents showing the same file, I introduced the concept of an active view content. The active view content is the only view content that may have such local changes. Thus, the active view content always has the most recent version of the file, and it is the only view content that is guaranteed to have the most recent version.

    To represent files, I created the OpenedFile class. This class knows which view contents have opened it and knows which of them is the active view content. Usually every OpenedFile can have a different active view content; though it is possible for multiple OpenedFiles to have the same active view content if that view content opens multiple files - the refactoring also added support for view contents that are editing multiple files at the same time.

    Now a quick overview of the SharpDevelop UI: The SharpDevelop main window is composed of a main menu, a tool bar, and the DockPanel of Weifen Luo's DockPanel Suite. In the dockable area, there are pads, which can be docked in groups at the sides of the SharpDevelop window; or can float somewhere (e.g. on a second monitor).
    In the remaining space (not occupied by pads), workbench windows are displayed. The active workbench window can be chosen using the tabs at the top. There can be multiple visible workbench windows if a user drags a tab and docks it to the side of the remaining space.
    Finally, each workbench window contains at least one view content. The active view content can be chosen using the tabs at the bottom.

    So if you create a new Windows Application and open Program.cs and MainForm.cs, there are two workbench windows titled "Program.cs" and "MainForm.cs", but three view contents - "Program.cs - Source", "MainForm.cs - Source" and "MainForm.cs - Design".

    Note that in the new IViewContent architecture, there are no secondary view contents. Now all view contents are equal, and they shouldn't care if they share a workbench window or not. Whether they will share a workbench window or not depends on how the view contents were created - there is still the difference between primary and secondary display bindings, which are responsible for creating view contents.

    Now how do changes get from one view content to the other? It's quite simple: Whenever the user activates a view content (by clicking a tab at the top, by clicking a tab at the bottom, or by setting focus into another workbench window after the user docked a window to the side), that view content becomes the active view content for all files it has opened. The old active view content will be asked to save its content to a MemoryStream and the new active view content will be asked to load from that MemoryStream. This way, unsaved changes are transferred from one view content to another.

    When the active view content for a file is closed, but there are other open view contents for that file, SharpDevelop will not ask the user to save the file. Instead, it will save the data from the view content being closed into a MemoryStream. After that, the OpenedFile has no active content. Only when one of the other view contents that have opened that file get activated by the user, that view content will load from the MemoryStream and thus will preserve unsaved changes from the closed view content. However, if the user closes all other view contents for that file without making them active (by middle-clicking, or using Window>Close all), SharpDevelop will ask the user if the file should be saved and write the MemoryStream content to disk if required.

    The system sounds simple for view contents: they just have to be able to load and save; and it'll just work.

    But it isn't that easy. The view contents must be able to load and save reliably at any time.

    The user just did something invalid which cannot be saved and then switches to another view of the file? The view content is forced to save. It's not possible say "I don't want to save".

    The user loads a .resx file in the text editor, changes something by hand that renders the file invalid XML, opens it in the resource editor, gets an error message, switches back to the text editor. Here the file is saved by the text editor, loaded in the resource editor, the user gets the error and switches back, the resource editor must save and the text editor will load again. The resource editor view content must support loading and saving invalid files unless you want this kind of round-trip to result in loss of user data.

    If your view content is editing multiple files, it gets even more complicated: you must support loading and saving individual files reliably at any time, in any order. Sounds fun, right?

    Well, if you don't get this right, the user looses data only when editing a file in multiple views simultaneously. In SharpDevelop 2.x, view contents were simply overwriting each other's data; in SharpDevelop 3.0 there's at least a chance that it works if all view contents are implemented correctly.

    However, be warned that I didn't have the time to update all view contents in SharpDevelop to make use of the new model. There's still a class AbstractSecondaryViewContent that implements Load and Save so that they run through an underlying "primary" view content, so existing secondary view contents do not have to be completely rewritten (although they still need several changes). The text and resource editors are fine; use them to see how it should work. The forms designer does not yet use the new model, it uses AbstractSecondaryViewContent and still touches the Designer.cs file directly, resulting in bugs like SD2-1175.

    But if you are writing a new view content, try to design it so that you can support loading and saving at any time. The AbstractViewContentHandlingLoadErrors class (which both the resource editor and the WPF designer use) can help you handling invalid files.

    If your view content edits multiple files, it can get tricky to support loading and saving those independently. But if it is likely that a user will want to edit one that files separately while also using your multi-file view content, you will have to do it. It is possible in SharpDevelop 3.0, so that's an improvement over SharpDevelop 2.x.

    By the way: the reason for all this is the settings designer (still not implemented): it edits both a .settings XML file and app.config, and it's very likely that the user has opened the app.config at the same time.

     

    Post by Daniel Grunwald (we use the category to mark the author on this blog, but I'll repeat it from now on at the bottom of the post because some feed readers like Google Reader don't show the category)

    Posted Okt 01 2007, 09:41 PM by Laputa
    Filed under:
Powered by Community Server (Commercial Edition), by Telligent Systems
Don't contact us via this (fleischfalle@alphasierrapapa.com) email address.